8 #include "../common/plat.h"
9 #include "../common/readpng.h"
10 #include "../common/menu.h"
11 #include "../common/emu.h"
12 #include "../common/input.h"
13 #include "../linux/sndout_oss.h"
15 #include <pico/pico.h>
18 int default_cpu_clock;
21 void *gp2x_screens[4];
23 #include <linux/input.h>
25 static const char * const caanoo_keys[KEY_MAX + 1] = {
26 [0 ... KEY_MAX] = NULL,
29 [KEY_RIGHT] = "Right",
44 struct in_default_bind in_evdev_defbinds[] =
47 { KEY_UP, IN_BINDTYPE_PLAYER12, 0 },
48 { KEY_DOWN, IN_BINDTYPE_PLAYER12, 1 },
49 { KEY_LEFT, IN_BINDTYPE_PLAYER12, 2 },
50 { KEY_RIGHT, IN_BINDTYPE_PLAYER12, 3 },
51 { KEY_S, IN_BINDTYPE_PLAYER12, 4 }, /* B */
52 { KEY_D, IN_BINDTYPE_PLAYER12, 5 }, /* C */
53 { KEY_A, IN_BINDTYPE_PLAYER12, 6 }, /* A */
54 { KEY_ENTER, IN_BINDTYPE_PLAYER12, 7 },
55 { KEY_BACKSLASH, IN_BINDTYPE_EMU, PEVB_MENU },
57 { BTN_THUMB, IN_BINDTYPE_PLAYER12, 4 }, /* B */
58 { BTN_THUMB2, IN_BINDTYPE_PLAYER12, 5 }, /* C */
59 { BTN_TRIGGER, IN_BINDTYPE_PLAYER12, 6 }, /* A */
60 { BTN_BASE3, IN_BINDTYPE_PLAYER12, 7 },
61 { BTN_TOP2, IN_BINDTYPE_EMU, PEVB_STATE_SAVE },
62 { BTN_PINKIE, IN_BINDTYPE_EMU, PEVB_STATE_LOAD },
63 { BTN_BASE, IN_BINDTYPE_EMU, PEVB_MENU },
67 void gp2x_video_changemode(int bpp)
69 gp2x_video_changemode_ll(bpp);
71 gp2x_current_bpp = bpp < 0 ? -bpp : bpp;
74 static void gp2x_memcpy_buffers(int buffers, void *data, int offset, int len)
77 if (buffers & (1<<0)) { dst = (char *)gp2x_screens[0] + offset; if (dst != data) memcpy(dst, data, len); }
78 if (buffers & (1<<1)) { dst = (char *)gp2x_screens[1] + offset; if (dst != data) memcpy(dst, data, len); }
79 if (buffers & (1<<2)) { dst = (char *)gp2x_screens[2] + offset; if (dst != data) memcpy(dst, data, len); }
80 if (buffers & (1<<3)) { dst = (char *)gp2x_screens[3] + offset; if (dst != data) memcpy(dst, data, len); }
83 void gp2x_memcpy_all_buffers(void *data, int offset, int len)
85 gp2x_memcpy_buffers(0xf, data, offset, len);
88 void gp2x_memset_all_buffers(int offset, int byte, int len)
90 memset((char *)gp2x_screens[0] + offset, byte, len);
91 memset((char *)gp2x_screens[1] + offset, byte, len);
92 memset((char *)gp2x_screens[2] + offset, byte, len);
93 memset((char *)gp2x_screens[3] + offset, byte, len);
96 void gp2x_make_fb_bufferable(int yes)
101 ret |= warm_change_cb_range(WCB_B_BIT, yes, gp2x_screens[0], 320*240*2);
102 ret |= warm_change_cb_range(WCB_B_BIT, yes, gp2x_screens[1], 320*240*2);
103 ret |= warm_change_cb_range(WCB_B_BIT, yes, gp2x_screens[2], 320*240*2);
104 ret |= warm_change_cb_range(WCB_B_BIT, yes, gp2x_screens[3], 320*240*2);
107 fprintf(stderr, "could not make fb buferable.\n");
109 printf("made fb buferable.\n");
113 void plat_video_menu_enter(int is_rom_loaded)
115 if (gp2x_current_bpp != 16 || gp2x_dev_id == GP2X_DEV_WIZ) {
116 /* try to switch nicely avoiding glitches */
117 gp2x_video_wait_vsync();
118 memset(gp2x_screens[0], 0, 320*240*2);
119 memset(gp2x_screens[1], 0, 320*240*2);
120 gp2x_video_flip2(); // might flip to fb2/3
121 gp2x_video_flip2(); // ..so we do it again
127 gp2x_video_changemode_ll(16);
128 gp2x_video_RGB_setscaling(0, 320, 240);
131 void plat_video_menu_begin(void)
133 g_menuscreen_ptr = g_screen_ptr;
136 void plat_video_menu_end(void)
141 void plat_early_init(void)
150 default_cpu_clock = 200;
151 gp2x_dev_id = GP2X_DEV_GP2X;
154 default_cpu_clock = 533;
155 f = fopen("/dev/accel", "rb");
157 printf("detected Caanoo\n");
158 gp2x_dev_id = GP2X_DEV_CAANOO;
162 printf("detected Wiz\n");
163 gp2x_dev_id = GP2X_DEV_WIZ;
167 printf("could not recognize SoC, running in dummy mode.\n");
171 // just use gettimeofday until plat_init()
172 gp2x_get_ticks_ms = plat_get_ticks_ms_good;
173 gp2x_get_ticks_us = plat_get_ticks_us_good;
196 gp2x_memset_all_buffers(0, 0, 320*240*2);
198 // use buffer2 for menubg to save mem (using only buffers 0, 1 in menu)
199 g_menubg_ptr = gp2x_screens[2];
201 if (gp2x_dev_id == GP2X_DEV_CAANOO)
202 in_set_config(in_name_to_id("evdev:pollux-analog"), IN_CFG_KEY_NAMES,
203 caanoo_keys, sizeof(caanoo_keys));
209 void plat_finish(void)