pal_utils.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. #include "main.h"
  2. #include <fat.h>
  3. #include <ogcsys.h>
  4. #include <wiiuse/wpad.h>
  5. #include <gccore.h>
  6. #include <fcntl.h>
  7. #include <network.h>
  8. #include <debug.h>
  9. #include <errno.h>
  10. #include <unistd.h>
  11. #ifdef DEBUG
  12. extern "C"{
  13. # include <net_print.h>
  14. }
  15. #endif
  16. static BOOL isNunChuckConnected(int joystick)
  17. {
  18. u32 exp_type;
  19. if (WPAD_Probe(joystick, &exp_type) != 0)
  20. exp_type = WPAD_EXP_NONE;
  21. return exp_type == WPAD_EXP_NUNCHUK;
  22. }
  23. static int input_event_filter(const SDL_Event *lpEvent, volatile PALINPUTSTATE *state)
  24. {
  25. int button, which;
  26. switch (lpEvent->type)
  27. {
  28. case SDL_JOYHATMOTION:
  29. switch (lpEvent->jhat.value)
  30. {
  31. case SDL_HAT_LEFT:
  32. case SDL_HAT_LEFTUP:
  33. state->prevdir = (gpGlobals->fInBattle ? kDirUnknown : state->dir);
  34. state->dir = kDirWest;
  35. state->dwKeyPress = kKeyLeft;
  36. break;
  37. case SDL_HAT_RIGHT:
  38. case SDL_HAT_RIGHTDOWN:
  39. state->prevdir = (gpGlobals->fInBattle ? kDirUnknown : state->dir);
  40. state->dir = kDirEast;
  41. state->dwKeyPress = kKeyRight;
  42. break;
  43. case SDL_HAT_UP:
  44. case SDL_HAT_RIGHTUP:
  45. state->prevdir = (gpGlobals->fInBattle ? kDirUnknown : state->dir);
  46. state->dir = kDirNorth;
  47. state->dwKeyPress = kKeyUp;
  48. break;
  49. case SDL_HAT_DOWN:
  50. case SDL_HAT_LEFTDOWN:
  51. state->prevdir = (gpGlobals->fInBattle ? kDirUnknown : state->dir);
  52. state->dir = kDirSouth;
  53. state->dwKeyPress = kKeyDown;
  54. break;
  55. case SDL_HAT_CENTERED:
  56. state->prevdir = (gpGlobals->fInBattle ? kDirUnknown : state->dir);
  57. state->dir = kDirUnknown;
  58. state->dwKeyPress = kKeyNone;
  59. break;
  60. }
  61. return 1;
  62. case SDL_JOYBUTTONDOWN:
  63. button = lpEvent->jbutton.button;
  64. which = lpEvent->jbutton.which;
  65. reswitchbutton:
  66. switch (button)
  67. {
  68. case 1: //wiimote B
  69. if( !isNunChuckConnected(which) ) { button = 14; goto reswitchbutton; }
  70. case 9: //wii classic A
  71. state->dwKeyPress |= kKeyMenu;
  72. return 1;
  73. case 0: //wiimote A
  74. if( !isNunChuckConnected(which) ) { button = 13; goto reswitchbutton; }
  75. case 10: //wii classic B
  76. state->dwKeyPress |= kKeySearch;
  77. return 1;
  78. case 4: //wiimote -
  79. if( isNunChuckConnected(which) ) { button = 14; goto reswitchbutton; }
  80. case 7: //nunchuk z
  81. case 11: //wii classic X
  82. state->dwKeyPress |= kKeyRepeat;
  83. return 1;
  84. case 5: //wiimote +
  85. if( isNunChuckConnected(which) ) { button = 13; goto reswitchbutton; }
  86. case 8: //nunchuk c
  87. case 12: //wii classic Y
  88. state->dwKeyPress |= kKeyForce;
  89. return 1;
  90. case 13: //wii classic L1
  91. state->dwKeyPress |= kKeyAuto;
  92. return 1;
  93. case 14: //wii classic R1
  94. state->dwKeyPress |= kKeyDefend;
  95. return 1;
  96. case 15: //wii classic L2
  97. state->dwKeyPress |= kKeyPgUp;
  98. return 1;
  99. case 16: //wii classic R2
  100. state->dwKeyPress |= kKeyPgDn;
  101. return 1;
  102. case 2: //wiimote 1
  103. if( !isNunChuckConnected(which) ) { button = 9; goto reswitchbutton; }
  104. case 17: //wii classic select
  105. state->dwKeyPress |= kKeyUseItem;
  106. return 1;
  107. case 3: //wiimote 2
  108. if( !isNunChuckConnected(which) ) { button = 10; goto reswitchbutton; }
  109. case 18: //wii classic start
  110. state->dwKeyPress |= kKeyThrowItem;
  111. return 1;
  112. case 6: //wiimote home
  113. case 19: //wii classic home
  114. state->dwKeyPress |= kKeyFlee;
  115. return 1;
  116. }
  117. }
  118. return 0;
  119. }
  120. BOOL
  121. UTIL_GetScreenSize(
  122. DWORD *pdwScreenWidth,
  123. DWORD *pdwScreenHeight
  124. )
  125. {
  126. return (pdwScreenWidth && pdwScreenHeight && *pdwScreenWidth && *pdwScreenHeight);
  127. }
  128. BOOL
  129. UTIL_IsAbsolutePath(
  130. LPCSTR lpszFileName
  131. )
  132. {
  133. return FALSE;
  134. }
  135. int UTIL_Platform_Startup(
  136. int argc,
  137. char* argv[]
  138. )
  139. {
  140. #if defined(DEBUG)
  141. VIDEO_SetBlack(FALSE);
  142. VIDEO_Flush();
  143. VIDEO_WaitVSync();
  144. char localip[16] = {0};
  145. char gateway[16] = {0};
  146. char netmask[16] = {0};
  147. int ret = if_config ( localip, netmask, gateway, TRUE);
  148. if (ret>=0) {
  149. printf ("\n network configured, ip: %s, gw: %s, mask %s\n", localip, gateway, netmask);
  150. net_print_init(NULL,0);
  151. printf("net_print_init() called.\n");
  152. net_print_string(__FILE__,__LINE__, "initial net_print from %s...\n",localip);
  153. DEBUG_Init(100,5656);
  154. printf("after DEBUG_Init()...\n");
  155. printf("Before _break() is called.\n");
  156. _break();
  157. printf("After _break() is called.\n");
  158. }
  159. #endif
  160. fatInitDefault();
  161. return 0;
  162. }
  163. INT
  164. UTIL_Platform_Init(
  165. int argc,
  166. char* argv[]
  167. )
  168. {
  169. #ifdef DEBUG
  170. UTIL_LogAddOutputCallback([](LOGLEVEL, const char* str, const char*)->void {
  171. net_print_string(__FILE__,__LINE__, "%s\n",str);
  172. }, PAL_DEFAULT_LOGLEVEL);
  173. #endif
  174. PAL_RegisterInputFilter(NULL, input_event_filter, NULL);
  175. gConfig.fLaunchSetting = FALSE;
  176. return 0;
  177. }
  178. VOID
  179. UTIL_Platform_Quit(
  180. VOID
  181. )
  182. {
  183. }