pal_utils.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. #include "main.h"
  2. #include <fat.h>
  3. #include <ogcsys.h>
  4. #include <gccore.h>
  5. #include <fcntl.h>
  6. #include <network.h>
  7. #include <debug.h>
  8. #include <errno.h>
  9. #include <unistd.h>
  10. #ifdef DEBUG
  11. extern "C"{
  12. # include <net_print.h>
  13. }
  14. #endif
  15. static int input_event_filter(const SDL_Event *lpEvent, volatile PALINPUTSTATE *state)
  16. {
  17. switch (lpEvent->type)
  18. {
  19. case SDL_JOYHATMOTION:
  20. switch (lpEvent->jhat.value)
  21. {
  22. case SDL_HAT_LEFT:
  23. case SDL_HAT_LEFTUP:
  24. state->prevdir = (gpGlobals->fInBattle ? kDirUnknown : state->dir);
  25. state->dir = kDirWest;
  26. state->dwKeyPress = kKeyLeft;
  27. break;
  28. case SDL_HAT_RIGHT:
  29. case SDL_HAT_RIGHTDOWN:
  30. state->prevdir = (gpGlobals->fInBattle ? kDirUnknown : state->dir);
  31. state->dir = kDirEast;
  32. state->dwKeyPress = kKeyRight;
  33. break;
  34. case SDL_HAT_UP:
  35. case SDL_HAT_RIGHTUP:
  36. state->prevdir = (gpGlobals->fInBattle ? kDirUnknown : state->dir);
  37. state->dir = kDirNorth;
  38. state->dwKeyPress = kKeyUp;
  39. break;
  40. case SDL_HAT_DOWN:
  41. case SDL_HAT_LEFTDOWN:
  42. state->prevdir = (gpGlobals->fInBattle ? kDirUnknown : state->dir);
  43. state->dir = kDirSouth;
  44. state->dwKeyPress = kKeyDown;
  45. break;
  46. case SDL_HAT_CENTERED:
  47. state->prevdir = (gpGlobals->fInBattle ? kDirUnknown : state->dir);
  48. state->dir = kDirUnknown;
  49. state->dwKeyPress = kKeyNone;
  50. break;
  51. }
  52. return 1;
  53. case SDL_JOYBUTTONDOWN:
  54. switch (lpEvent->jbutton.button)
  55. {
  56. case 2:
  57. state->dwKeyPress |= kKeyMenu;
  58. return 1;
  59. case 3:
  60. state->dwKeyPress |= kKeySearch;
  61. return 1;
  62. }
  63. }
  64. return 0;
  65. }
  66. BOOL
  67. UTIL_GetScreenSize(
  68. DWORD *pdwScreenWidth,
  69. DWORD *pdwScreenHeight
  70. )
  71. {
  72. return (pdwScreenWidth && pdwScreenHeight && *pdwScreenWidth && *pdwScreenHeight);
  73. }
  74. BOOL
  75. UTIL_IsAbsolutePath(
  76. LPCSTR lpszFileName
  77. )
  78. {
  79. return FALSE;
  80. }
  81. int UTIL_Platform_Startup(
  82. int argc,
  83. char* argv[]
  84. )
  85. {
  86. #if defined(DEBUG)
  87. VIDEO_SetBlack(FALSE);
  88. VIDEO_Flush();
  89. VIDEO_WaitVSync();
  90. char localip[16] = {0};
  91. char gateway[16] = {0};
  92. char netmask[16] = {0};
  93. int ret = if_config ( localip, netmask, gateway, TRUE);
  94. if (ret>=0) {
  95. printf ("\n network configured, ip: %s, gw: %s, mask %s\n", localip, gateway, netmask);
  96. net_print_init(NULL,0);
  97. printf("net_print_init() called.\n");
  98. net_print_string(__FILE__,__LINE__, "initial net_print from %s...\n",localip);
  99. DEBUG_Init(100,5656);
  100. printf("after DEBUG_Init()...\n");
  101. printf("Before _break() is called.\n");
  102. _break();
  103. printf("After _break() is called.\n");
  104. }
  105. #endif
  106. fatInitDefault();
  107. return 0;
  108. }
  109. INT
  110. UTIL_Platform_Init(
  111. int argc,
  112. char* argv[]
  113. )
  114. {
  115. #ifdef DEBUG
  116. UTIL_LogAddOutputCallback([](LOGLEVEL, const char* str, const char*)->void {
  117. net_print_string(__FILE__,__LINE__, "%s\n",str);
  118. }, PAL_DEFAULT_LOGLEVEL);
  119. #endif
  120. UTIL_LogOutput(LOGLEVEL_WARNING, "try net_print logout");
  121. PAL_RegisterInputFilter(NULL, input_event_filter, NULL);
  122. gConfig.fLaunchSetting = FALSE;
  123. return 0;
  124. }
  125. VOID
  126. UTIL_Platform_Quit(
  127. VOID
  128. )
  129. {
  130. }