SHARE
TWEET

SH4 patch

ziqumu Apr 17th, 2013 555 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define __KEYBIOS_H__
  2. #include "fxlib.h"
  3. #define KEY_CHAR_0 71
  4. #define KEY_CHAR_1 72
  5. #define KEY_CHAR_2 62
  6. #define KEY_CHAR_3 52
  7. #define KEY_CHAR_4 73
  8. #define KEY_CHAR_5 63
  9. #define KEY_CHAR_6 53
  10. #define KEY_CHAR_7 74
  11. #define KEY_CHAR_8 64
  12. #define KEY_CHAR_9 54
  13. #define KEY_CHAR_DP 61
  14. #define KEY_CHAR_EXP 51
  15. #define KEY_CHAR_PMINUS 41
  16. #define KEY_CHAR_PLUS 42
  17. #define KEY_CHAR_MINUS 32
  18. #define KEY_CHAR_MULT 43
  19. #define KEY_CHAR_DIV 33
  20. #define KEY_CHAR_FRAC 75
  21. #define KEY_CHAR_LPAR 55
  22. #define KEY_CHAR_RPAR 45
  23. #define KEY_CHAR_COMMA 35
  24. #define KEY_CHAR_STORE 25
  25. #define KEY_CHAR_LOG 66
  26. #define KEY_CHAR_LN 56
  27. #define KEY_CHAR_SIN 46
  28. #define KEY_CHAR_COS 36
  29. #define KEY_CHAR_TAN 26
  30. #define KEY_CHAR_SQUARE 67
  31. #define KEY_CHAR_POW 57
  32. #define KEY_CTRL_EXE 31
  33. #define KEY_CTRL_DEL 44
  34. #define KEY_CTRL_AC 32
  35. #define KEY_CTRL_FD 65
  36. #define KEY_CTRL_EXIT 47
  37. #define KEY_CTRL_SHIFT 78
  38. #define KEY_CTRL_ALPHA 77
  39. #define KEY_CTRL_OPTN 68
  40. #define KEY_CTRL_VARS 58
  41. #define KEY_CTRL_UP 28
  42. #define KEY_CTRL_DOWN 37
  43. #define KEY_CTRL_LEFT 38
  44. #define KEY_CTRL_RIGHT 27
  45. #define KEY_CTRL_F1 79
  46. #define KEY_CTRL_F2 69
  47. #define KEY_CTRL_F3 59
  48. #define KEY_CTRL_F4 49
  49. #define KEY_CTRL_F5 39
  50. #define KEY_CTRL_F6 29
  51. #define KEY_CTRL_MENU 48
  52. #ifndef OS2Change
  53. #define OS2Change
  54. #ifndef OS2Change_GetOS2
  55. #define OS2Change_GetOS2
  56. typedef int(*sc_i2cp2sip)(char*, char*, short int*, short int*);
  57. const unsigned int sc0015[] = { 0xD201D002, 0x422B0009, 0x80010070, 0x0015 };
  58. #define GlibGetOSVersionInfo (*(sc_i2cp2sip)sc0015)
  59. int OSVersionAsInt(void)
  60. {
  61. unsigned char mainversion;
  62. unsigned char minorversion;
  63. unsigned short release;
  64. unsigned short build;
  65. GlibGetOSVersionInfo( &mainversion, &minorversion, &release, &build );
  66. return ( ( mainversion << 24 ) & 0xFF000000 ) | ( ( minorversion << 16 ) & 0x00FF0000 ) | ( release & 0x0000FFFF );
  67. }
  68. #define isOS2 (OSVersionAsInt() >= 0x02020000)
  69. #define OS2(x,y) ((OSVersionAsInt() >= 0x02020000)?y:x)
  70. #endif
  71. #ifndef OS2Change_Keyboard
  72. #define OS2Change_Keyboard
  73. void delay(void)
  74. {
  75. char i;
  76. for (i=0; i<5; i++){};
  77. }
  78. unsigned char CheckKeyRow(unsigned char code)
  79. {
  80. unsigned char result=0;
  81. short*PORTB_CTRL=(void*)0xA4000102;
  82. short*PORTM_CTRL=(void*)0xA4000118;
  83. char*PORTB=(void*)0xA4000122;
  84. char*PORTM=(void*)0xA4000138;
  85. char*PORTA=(void*)0xA4000120;
  86. short smask;
  87. char cmask;
  88. unsigned char column, row;
  89. column = code>>4;
  90. row = code &0x0F;
  91. smask = 0x0003 << (( row %8)*2);
  92. cmask = ~( 1 << ( row %8) );
  93. if(row <8)
  94. {
  95.   *PORTB_CTRL = 0xAAAA ^ smask;
  96.   *PORTM_CTRL = (*PORTM_CTRL & 0xFF00 ) | 0x00AA;
  97.   delay();
  98.   *PORTB = cmask;
  99.   *PORTM = (*PORTM & 0xF0 ) | 0x0F;
  100. }
  101. else
  102. {
  103.   *PORTB_CTRL = 0xAAAA;
  104.   *PORTM_CTRL = ((*PORTM_CTRL & 0xFF00 ) | 0x00AA)  ^ smask;
  105.   delay();
  106.   *PORTB = 0xFF;
  107.   *PORTM = (*PORTM & 0xF0 ) | cmask;
  108. }
  109.  
  110. delay();
  111. result = (~(*PORTA))>>column & 1;
  112. delay();
  113. *PORTB_CTRL = 0xAAAA;
  114. *PORTM_CTRL = (*PORTM_CTRL & 0xFF00 ) | 0x00AA;
  115. delay();
  116. *PORTB_CTRL = 0x5555;
  117. *PORTM_CTRL = (*PORTM_CTRL & 0xFF00 ) | 0x0055;
  118. delay();
  119.  
  120. return result;
  121. }
  122.  
  123. unsigned char KeyDown(unsigned char keycode)
  124. {
  125. unsigned short key[8];
  126. const unsigned short* keyboardregister = (unsigned short*)0xA44B0000;
  127. if(isOS2)
  128. {
  129.   unsigned char row = keycode%10;
  130.   memcpy(key, keyboardregister, sizeof(unsigned short) << 3);
  131.  
  132.   return (0 != (key[row >> 1] & 1 << keycode / 10 - 1 + ((row & 1) << 3)));
  133. }
  134. else
  135. {
  136.   return CheckKeyRow((keycode % 10) + ((keycode / 10 - 1) << 4));
  137. }
  138. }
  139. unsigned char GetKeyMod(unsigned int *key)
  140. {
  141. unsigned char x, ret;
  142.  
  143. ret = GetKey(key);
  144.  
  145. for(x = 0; x < 80; x++)
  146. {
  147.   if(KeyDown(x))
  148.   {
  149.    *key = x;
  150.    break;
  151.   }
  152. }
  153. return ret;
  154. }
  155. #define IsKeyDown(x) KeyDown(x)
  156. #define IsKeyUp(x) !KeyDown(x)
  157. #define GetKey(x) GetKeyMod(x)
  158. #endif
  159. #endif
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top