plat.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <linux/input.h>
  5. #include "../common/emu.h"
  6. #include "../common/menu_pico.h"
  7. #include "../common/input_pico.h"
  8. #include "../libpicofe/input.h"
  9. #include "../libpicofe/plat.h"
  10. #include "../libpicofe/linux/in_evdev.h"
  11. #include "../libpicofe/gp2x/soc.h"
  12. #include "../libpicofe/gp2x/plat_gp2x.h"
  13. #include "../libpicofe/gp2x/in_gp2x.h"
  14. #include "940ctl.h"
  15. #include "warm.h"
  16. #include "plat.h"
  17. #include <pico/pico.h>
  18. /* GP2X local */
  19. int gp2x_current_bpp;
  20. void *gp2x_screens[4];
  21. void (*gp2x_video_flip)(void);
  22. void (*gp2x_video_flip2)(void);
  23. void (*gp2x_video_changemode_ll)(int bpp, int is_pal);
  24. void (*gp2x_video_setpalette)(int *pal, int len);
  25. void (*gp2x_video_RGB_setscaling)(int ln_offs, int W, int H);
  26. void (*gp2x_video_wait_vsync)(void);
  27. static struct in_default_bind in_evdev_defbinds[] =
  28. {
  29. /* MXYZ SACB RLDU */
  30. { KEY_UP, IN_BINDTYPE_PLAYER12, GBTN_UP },
  31. { KEY_DOWN, IN_BINDTYPE_PLAYER12, GBTN_DOWN },
  32. { KEY_LEFT, IN_BINDTYPE_PLAYER12, GBTN_LEFT },
  33. { KEY_RIGHT, IN_BINDTYPE_PLAYER12, GBTN_RIGHT },
  34. { KEY_A, IN_BINDTYPE_PLAYER12, GBTN_A },
  35. { KEY_S, IN_BINDTYPE_PLAYER12, GBTN_B },
  36. { KEY_D, IN_BINDTYPE_PLAYER12, GBTN_C },
  37. { KEY_ENTER, IN_BINDTYPE_PLAYER12, GBTN_START },
  38. { KEY_BACKSLASH, IN_BINDTYPE_EMU, PEVB_MENU },
  39. /* Caanoo */
  40. { BTN_TRIGGER, IN_BINDTYPE_PLAYER12, GBTN_A },
  41. { BTN_THUMB, IN_BINDTYPE_PLAYER12, GBTN_B },
  42. { BTN_THUMB2, IN_BINDTYPE_PLAYER12, GBTN_C },
  43. { BTN_BASE3, IN_BINDTYPE_PLAYER12, GBTN_START },
  44. { BTN_TOP2, IN_BINDTYPE_EMU, PEVB_STATE_SAVE },
  45. { BTN_PINKIE, IN_BINDTYPE_EMU, PEVB_STATE_LOAD },
  46. { BTN_BASE, IN_BINDTYPE_EMU, PEVB_MENU },
  47. { 0, 0, 0 }
  48. };
  49. static struct in_default_bind in_gp2x_defbinds[] =
  50. {
  51. { GP2X_BTN_UP, IN_BINDTYPE_PLAYER12, GBTN_UP },
  52. { GP2X_BTN_DOWN, IN_BINDTYPE_PLAYER12, GBTN_DOWN },
  53. { GP2X_BTN_LEFT, IN_BINDTYPE_PLAYER12, GBTN_LEFT },
  54. { GP2X_BTN_RIGHT, IN_BINDTYPE_PLAYER12, GBTN_RIGHT },
  55. { GP2X_BTN_A, IN_BINDTYPE_PLAYER12, GBTN_A },
  56. { GP2X_BTN_X, IN_BINDTYPE_PLAYER12, GBTN_B },
  57. { GP2X_BTN_B, IN_BINDTYPE_PLAYER12, GBTN_C },
  58. { GP2X_BTN_START, IN_BINDTYPE_PLAYER12, GBTN_START },
  59. { GP2X_BTN_Y, IN_BINDTYPE_EMU, PEVB_SWITCH_RND },
  60. { GP2X_BTN_L, IN_BINDTYPE_EMU, PEVB_STATE_SAVE },
  61. { GP2X_BTN_R, IN_BINDTYPE_EMU, PEVB_STATE_LOAD },
  62. { GP2X_BTN_VOL_DOWN, IN_BINDTYPE_EMU, PEVB_VOL_DOWN },
  63. { GP2X_BTN_VOL_UP, IN_BINDTYPE_EMU, PEVB_VOL_UP },
  64. { GP2X_BTN_SELECT, IN_BINDTYPE_EMU, PEVB_MENU },
  65. { 0, 0, 0 }
  66. };
  67. void gp2x_video_changemode(int bpp, int is_pal)
  68. {
  69. gp2x_video_changemode_ll(bpp, is_pal);
  70. gp2x_current_bpp = bpp < 0 ? -bpp : bpp;
  71. }
  72. static void gp2x_memcpy_buffers(int buffers, void *data, int offset, int len)
  73. {
  74. char *dst;
  75. if (buffers & (1<<0)) { dst = (char *)gp2x_screens[0] + offset; if (dst != data) memcpy(dst, data, len); }
  76. if (buffers & (1<<1)) { dst = (char *)gp2x_screens[1] + offset; if (dst != data) memcpy(dst, data, len); }
  77. if (buffers & (1<<2)) { dst = (char *)gp2x_screens[2] + offset; if (dst != data) memcpy(dst, data, len); }
  78. if (buffers & (1<<3)) { dst = (char *)gp2x_screens[3] + offset; if (dst != data) memcpy(dst, data, len); }
  79. }
  80. void gp2x_memcpy_all_buffers(void *data, int offset, int len)
  81. {
  82. gp2x_memcpy_buffers(0xf, data, offset, len);
  83. }
  84. void gp2x_memset_all_buffers(int offset, int byte, int len)
  85. {
  86. memset((char *)gp2x_screens[0] + offset, byte, len);
  87. memset((char *)gp2x_screens[1] + offset, byte, len);
  88. memset((char *)gp2x_screens[2] + offset, byte, len);
  89. memset((char *)gp2x_screens[3] + offset, byte, len);
  90. }
  91. void gp2x_make_fb_bufferable(int yes)
  92. {
  93. int ret = 0;
  94. yes = yes ? 1 : 0;
  95. ret |= warm_change_cb_range(WCB_B_BIT, yes, gp2x_screens[0], 320*240*2);
  96. ret |= warm_change_cb_range(WCB_B_BIT, yes, gp2x_screens[1], 320*240*2);
  97. ret |= warm_change_cb_range(WCB_B_BIT, yes, gp2x_screens[2], 320*240*2);
  98. ret |= warm_change_cb_range(WCB_B_BIT, yes, gp2x_screens[3], 320*240*2);
  99. if (ret)
  100. fprintf(stderr, "could not make fb buferable.\n");
  101. else
  102. printf("made fb buferable.\n");
  103. }
  104. /* common */
  105. void plat_video_menu_enter(int is_rom_loaded)
  106. {
  107. if (gp2x_current_bpp != 16 || gp2x_dev_id == GP2X_DEV_WIZ) {
  108. /* try to switch nicely avoiding glitches */
  109. gp2x_video_wait_vsync();
  110. memset(gp2x_screens[0], 0, 320*240*2);
  111. memset(gp2x_screens[1], 0, 320*240*2);
  112. gp2x_video_flip2(); // might flip to fb2/3
  113. gp2x_video_flip2(); // ..so we do it again
  114. }
  115. else
  116. gp2x_video_flip2();
  117. // switch to 16bpp
  118. gp2x_video_changemode_ll(16, 0);
  119. gp2x_video_RGB_setscaling(0, 320, 240);
  120. }
  121. void plat_video_menu_begin(void)
  122. {
  123. g_menuscreen_ptr = g_screen_ptr;
  124. }
  125. void plat_video_menu_end(void)
  126. {
  127. gp2x_video_flip2();
  128. }
  129. void plat_video_menu_leave(void)
  130. {
  131. }
  132. void plat_early_init(void)
  133. {
  134. // just use gettimeofday until plat_init()
  135. gp2x_get_ticks_ms = plat_get_ticks_ms_good;
  136. gp2x_get_ticks_us = plat_get_ticks_us_good;
  137. }
  138. void plat_init(void)
  139. {
  140. warm_init();
  141. switch (gp2x_dev_id) {
  142. case GP2X_DEV_GP2X:
  143. sharedmem940_init();
  144. vid_mmsp2_init();
  145. break;
  146. case GP2X_DEV_WIZ:
  147. case GP2X_DEV_CAANOO:
  148. vid_pollux_init();
  149. break;
  150. }
  151. g_menuscreen_w = 320;
  152. g_menuscreen_h = 240;
  153. gp2x_memset_all_buffers(0, 0, 320*240*2);
  154. gp2x_make_fb_bufferable(1);
  155. // use buffer2 for menubg to save mem (using only buffers 0, 1 in menu)
  156. g_menubg_ptr = gp2x_screens[2];
  157. flip_after_sync = 1;
  158. gp2x_menu_init();
  159. in_evdev_init(in_evdev_defbinds);
  160. in_gp2x_init(in_gp2x_defbinds);
  161. in_probe();
  162. plat_target_setup_input();
  163. }
  164. void plat_finish(void)
  165. {
  166. warm_finish();
  167. switch (gp2x_dev_id) {
  168. case GP2X_DEV_GP2X:
  169. sharedmem940_finish();
  170. vid_mmsp2_finish();
  171. break;
  172. case GP2X_DEV_WIZ:
  173. case GP2X_DEV_CAANOO:
  174. vid_pollux_finish();
  175. break;
  176. }
  177. }