Advertisement
Guest User

Code SH4 compatiblité

a guest
Jan 4th, 2013
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.92 KB | None | 0 0
  1. #define __KEYBIOS_H__
  2. #include "fxlib.h"
  3.  
  4.  
  5. #define KEY_CHAR_0 OS2(0x30,71)
  6. #define KEY_CHAR_1 OS2(0x31,72)
  7. #define KEY_CHAR_2 OS2(0x32,62)
  8. #define KEY_CHAR_3 OS2(0x33,52)
  9. #define KEY_CHAR_4 OS2(0x34,73)
  10. #define KEY_CHAR_5 OS2(0x35,63)
  11. #define KEY_CHAR_6 OS2(0x36,53)
  12. #define KEY_CHAR_7 OS2(0x37,74)
  13. #define KEY_CHAR_8 OS2(0x38,64)
  14. #define KEY_CHAR_9 OS2(0x39,54)
  15. #define KEY_CHAR_DP OS2(0x2e,61)
  16. #define KEY_CHAR_EXP OS2(0x0f,51)
  17. #define KEY_CHAR_PMINUS OS2(0x87,41)
  18. #define KEY_CHAR_PLUS OS2(0x89,42)
  19. #define KEY_CHAR_MINUS OS2(0x99,32)
  20. #define KEY_CHAR_MULT OS2(0xa9,43)
  21. #define KEY_CHAR_DIV OS2(0xb9,33)
  22. #define KEY_CHAR_FRAC OS2(0xbb,75)
  23. #define KEY_CHAR_LPAR OS2(0x28,55)
  24. #define KEY_CHAR_RPAR OS2(0x29,45)
  25. #define KEY_CHAR_COMMA OS2(0x2c,35)
  26. #define KEY_CHAR_STORE OS2(0x0e,25)
  27. #define KEY_CHAR_LOG OS2(0x95,66)
  28. #define KEY_CHAR_LN OS2(0x85,56)
  29. #define KEY_CHAR_SIN OS2(0x81,46)
  30. #define KEY_CHAR_COS OS2(0x82,36)
  31. #define KEY_CHAR_TAN OS2(0x83,26)
  32. #define KEY_CHAR_SQUARE OS2(0x8b,67)
  33. #define KEY_CHAR_POW OS2(0xa8,57)
  34. #define KEY_CTRL_EXE OS2(30004,31)
  35. #define KEY_CTRL_DEL OS2(30025,44)
  36. #define KEY_CTRL_AC OS2(30015,32)
  37. #define KEY_CTRL_FD OS2(30046,65)
  38. #define KEY_CTRL_EXIT OS2(30002,47)
  39. #define KEY_CTRL_SHIFT OS2(30006,78)
  40. #define KEY_CTRL_ALPHA OS2(30007,77)
  41. #define KEY_CTRL_OPTN OS2(30008,68)
  42. #define KEY_CTRL_VARS OS2(30016,58)
  43. #define KEY_CTRL_UP OS2(30018,28)
  44. #define KEY_CTRL_DOWN OS2(30023,37)
  45. #define KEY_CTRL_LEFT OS2(30020,38)
  46. #define KEY_CTRL_RIGHT OS2(30021,27)
  47. #define KEY_CTRL_F1 OS2(30009,79)
  48. #define KEY_CTRL_F2 OS2(30010,69)
  49. #define KEY_CTRL_F3 OS2(30011,59)
  50. #define KEY_CTRL_F4 OS2(30012,49)
  51. #define KEY_CTRL_F5 OS2(30013,39)
  52. #define KEY_CTRL_F6 OS2(30014,29)
  53. #define KEY_CTRL_MENU OS2(30003,48)
  54.  
  55. #ifndef isOS2// This is new
  56.  
  57. typedef int(*sc_i2cp2sip)(char*, char*, short int*, short int*);
  58. const unsigned int sc0015[] = { 0xD201D002, 0x422B0009, 0x80010070, 0x0015 };
  59. #define GlibGetOSVersionInfo (*(sc_i2cp2sip)sc0015)
  60.  
  61. int OSVersionAsInt(void)
  62. {
  63. unsigned char mainversion;
  64. unsigned char minorversion;
  65. unsigned short release;
  66. unsigned short build;
  67. GlibGetOSVersionInfo( &mainversion, &minorversion, &release, &build );
  68. return ( ( mainversion << 24 ) & 0xFF000000 ) | ( ( minorversion << 16 ) & 0x00FF0000 ) | ( release & 0x0000FFFF );
  69. }
  70.  
  71. #define isOS2 (OSVersionAsInt() >= 0x02020000)
  72. #define OS2(x,y) ((OSVersionAsInt() >= 0x02020000)?y:x)
  73.  
  74. #endif
  75.  
  76. const unsigned short* keyboardregister = (unsigned short*)0xA44B0000;
  77.  
  78. unsigned short key[8] = {0};
  79.  
  80. int KeyDown(int keycode)
  81. {
  82. if(isOS2)
  83. {
  84. int row, col, word, bit;
  85. row = keycode%10;
  86. col = keycode/10-1;
  87. word = row>>1;
  88. bit = col + 8*(row&1);
  89. memcpy(key, keyboardregister, sizeof(unsigned short) << 3);
  90.  
  91. Sleep(1); //slow down, this function is faster than IsKeyDown() :-P
  92.  
  93. return (0 != (key[word] & 1<<bit));
  94. }
  95. else
  96. {
  97. return IsKeyDown(keycode);
  98. }
  99. }
  100.  
  101. #define IsKeyDown(x) KeyDown(x)
  102. #define IsKeyUp(x) !KeyDown(x)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement