Commit | Line | Data |
---|---|---|
42171343 | 1 | #include <stdio.h> |
2 | #include <stdlib.h> | |
1fb0dd88 | 3 | #include <string.h> |
75a30842 | 4 | #include <linux/input.h> |
1fb0dd88 | 5 | |
e2de9939 | 6 | #include "../common/emu.h" |
75a30842 | 7 | #include "../common/menu_pico.h" |
8 | #include "../common/input_pico.h" | |
9 | #include "../libpicofe/input.h" | |
10 | #include "../libpicofe/plat.h" | |
11 | #include "../libpicofe/linux/in_evdev.h" | |
12 | #include "../libpicofe/gp2x/soc.h" | |
13 | #include "../libpicofe/gp2x/plat_gp2x.h" | |
14 | #include "../libpicofe/gp2x/in_gp2x.h" | |
15 | #include "940ctl.h" | |
16 | #include "warm.h" | |
17 | #include "plat.h" | |
1fb0dd88 | 18 | |
74bd7040 | 19 | #include <pico/pico_int.h> |
ee2a3bdf | 20 | |
42171343 | 21 | /* GP2X local */ |
f4750ee0 | 22 | int gp2x_current_bpp; |
42171343 | 23 | void *gp2x_screens[4]; |
24 | ||
75a30842 | 25 | void (*gp2x_video_flip)(void); |
26 | void (*gp2x_video_flip2)(void); | |
31f944ea | 27 | void (*gp2x_video_changemode_ll)(int bpp, int is_pal); |
75a30842 | 28 | void (*gp2x_video_setpalette)(int *pal, int len); |
29 | void (*gp2x_video_RGB_setscaling)(int ln_offs, int W, int H); | |
30 | void (*gp2x_video_wait_vsync)(void); | |
45285368 | 31 | |
75a30842 | 32 | static struct in_default_bind in_evdev_defbinds[] = |
21ebcfd3 | 33 | { |
34 | /* MXYZ SACB RLDU */ | |
75a30842 | 35 | { KEY_UP, IN_BINDTYPE_PLAYER12, GBTN_UP }, |
36 | { KEY_DOWN, IN_BINDTYPE_PLAYER12, GBTN_DOWN }, | |
37 | { KEY_LEFT, IN_BINDTYPE_PLAYER12, GBTN_LEFT }, | |
38 | { KEY_RIGHT, IN_BINDTYPE_PLAYER12, GBTN_RIGHT }, | |
39 | { KEY_A, IN_BINDTYPE_PLAYER12, GBTN_A }, | |
40 | { KEY_S, IN_BINDTYPE_PLAYER12, GBTN_B }, | |
41 | { KEY_D, IN_BINDTYPE_PLAYER12, GBTN_C }, | |
42 | { KEY_ENTER, IN_BINDTYPE_PLAYER12, GBTN_START }, | |
21ebcfd3 | 43 | { KEY_BACKSLASH, IN_BINDTYPE_EMU, PEVB_MENU }, |
44 | /* Caanoo */ | |
75a30842 | 45 | { BTN_TRIGGER, IN_BINDTYPE_PLAYER12, GBTN_A }, |
46 | { BTN_THUMB, IN_BINDTYPE_PLAYER12, GBTN_B }, | |
47 | { BTN_THUMB2, IN_BINDTYPE_PLAYER12, GBTN_C }, | |
48 | { BTN_BASE3, IN_BINDTYPE_PLAYER12, GBTN_START }, | |
21ebcfd3 | 49 | { BTN_TOP2, IN_BINDTYPE_EMU, PEVB_STATE_SAVE }, |
50 | { BTN_PINKIE, IN_BINDTYPE_EMU, PEVB_STATE_LOAD }, | |
51 | { BTN_BASE, IN_BINDTYPE_EMU, PEVB_MENU }, | |
52 | { 0, 0, 0 } | |
53 | }; | |
54 | ||
75a30842 | 55 | static struct in_default_bind in_gp2x_defbinds[] = |
56 | { | |
57 | { GP2X_BTN_UP, IN_BINDTYPE_PLAYER12, GBTN_UP }, | |
58 | { GP2X_BTN_DOWN, IN_BINDTYPE_PLAYER12, GBTN_DOWN }, | |
59 | { GP2X_BTN_LEFT, IN_BINDTYPE_PLAYER12, GBTN_LEFT }, | |
60 | { GP2X_BTN_RIGHT, IN_BINDTYPE_PLAYER12, GBTN_RIGHT }, | |
61 | { GP2X_BTN_A, IN_BINDTYPE_PLAYER12, GBTN_A }, | |
62 | { GP2X_BTN_X, IN_BINDTYPE_PLAYER12, GBTN_B }, | |
63 | { GP2X_BTN_B, IN_BINDTYPE_PLAYER12, GBTN_C }, | |
64 | { GP2X_BTN_START, IN_BINDTYPE_PLAYER12, GBTN_START }, | |
65 | { GP2X_BTN_Y, IN_BINDTYPE_EMU, PEVB_SWITCH_RND }, | |
66 | { GP2X_BTN_L, IN_BINDTYPE_EMU, PEVB_STATE_SAVE }, | |
67 | { GP2X_BTN_R, IN_BINDTYPE_EMU, PEVB_STATE_LOAD }, | |
68 | { GP2X_BTN_VOL_DOWN, IN_BINDTYPE_EMU, PEVB_VOL_DOWN }, | |
69 | { GP2X_BTN_VOL_UP, IN_BINDTYPE_EMU, PEVB_VOL_UP }, | |
70 | { GP2X_BTN_SELECT, IN_BINDTYPE_EMU, PEVB_MENU }, | |
71 | { 0, 0, 0 } | |
72 | }; | |
73 | ||
4e3551a5 PC |
74 | static const struct menu_keymap key_pbtn_map[] = |
75 | { | |
76 | { KEY_UP, PBTN_UP }, | |
77 | { KEY_DOWN, PBTN_DOWN }, | |
78 | { KEY_LEFT, PBTN_LEFT }, | |
79 | { KEY_RIGHT, PBTN_RIGHT }, | |
80 | /* Caanoo */ | |
81 | { BTN_THUMB2, PBTN_MOK }, | |
82 | { BTN_THUMB, PBTN_MBACK }, | |
83 | { BTN_TRIGGER, PBTN_MA2 }, | |
84 | { BTN_TOP, PBTN_MA3 }, | |
85 | { BTN_BASE, PBTN_MENU }, | |
86 | { BTN_TOP2, PBTN_L }, | |
87 | { BTN_PINKIE, PBTN_R }, | |
88 | /* "normal" keyboards */ | |
89 | { KEY_ENTER, PBTN_MOK }, | |
90 | { KEY_ESC, PBTN_MBACK }, | |
91 | { KEY_SEMICOLON, PBTN_MA2 }, | |
92 | { KEY_APOSTROPHE, PBTN_MA3 }, | |
93 | { KEY_BACKSLASH, PBTN_MENU }, | |
94 | { KEY_LEFTBRACE, PBTN_L }, | |
95 | { KEY_RIGHTBRACE, PBTN_R }, | |
96 | }; | |
97 | ||
9770f531 | 98 | static const struct in_pdata gp2x_evdev_pdata = { |
99 | .defbinds = in_evdev_defbinds, | |
4e3551a5 PC |
100 | .key_map = key_pbtn_map, |
101 | .kmap_size = sizeof(key_pbtn_map) / sizeof(key_pbtn_map[0]), | |
102 | }; | |
103 | ||
31f944ea | 104 | void gp2x_video_changemode(int bpp, int is_pal) |
42171343 | 105 | { |
31f944ea | 106 | gp2x_video_changemode_ll(bpp, is_pal); |
42171343 | 107 | |
f4750ee0 | 108 | gp2x_current_bpp = bpp < 0 ? -bpp : bpp; |
42171343 | 109 | } |
110 | ||
111 | static void gp2x_memcpy_buffers(int buffers, void *data, int offset, int len) | |
112 | { | |
113 | char *dst; | |
114 | if (buffers & (1<<0)) { dst = (char *)gp2x_screens[0] + offset; if (dst != data) memcpy(dst, data, len); } | |
115 | if (buffers & (1<<1)) { dst = (char *)gp2x_screens[1] + offset; if (dst != data) memcpy(dst, data, len); } | |
116 | if (buffers & (1<<2)) { dst = (char *)gp2x_screens[2] + offset; if (dst != data) memcpy(dst, data, len); } | |
117 | if (buffers & (1<<3)) { dst = (char *)gp2x_screens[3] + offset; if (dst != data) memcpy(dst, data, len); } | |
118 | } | |
119 | ||
120 | void gp2x_memcpy_all_buffers(void *data, int offset, int len) | |
121 | { | |
122 | gp2x_memcpy_buffers(0xf, data, offset, len); | |
123 | } | |
124 | ||
125 | void gp2x_memset_all_buffers(int offset, int byte, int len) | |
126 | { | |
127 | memset((char *)gp2x_screens[0] + offset, byte, len); | |
128 | memset((char *)gp2x_screens[1] + offset, byte, len); | |
129 | memset((char *)gp2x_screens[2] + offset, byte, len); | |
130 | memset((char *)gp2x_screens[3] + offset, byte, len); | |
131 | } | |
132 | ||
0d9bf4fc | 133 | void gp2x_make_fb_bufferable(int yes) |
134 | { | |
135 | int ret = 0; | |
136 | ||
137 | yes = yes ? 1 : 0; | |
138 | ret |= warm_change_cb_range(WCB_B_BIT, yes, gp2x_screens[0], 320*240*2); | |
139 | ret |= warm_change_cb_range(WCB_B_BIT, yes, gp2x_screens[1], 320*240*2); | |
140 | ret |= warm_change_cb_range(WCB_B_BIT, yes, gp2x_screens[2], 320*240*2); | |
141 | ret |= warm_change_cb_range(WCB_B_BIT, yes, gp2x_screens[3], 320*240*2); | |
142 | ||
143 | if (ret) | |
144 | fprintf(stderr, "could not make fb buferable.\n"); | |
145 | else | |
146 | printf("made fb buferable.\n"); | |
147 | } | |
148 | ||
42171343 | 149 | /* common */ |
1fb0dd88 | 150 | void plat_video_menu_enter(int is_rom_loaded) |
151 | { | |
f4750ee0 | 152 | if (gp2x_current_bpp != 16 || gp2x_dev_id == GP2X_DEV_WIZ) { |
153 | /* try to switch nicely avoiding glitches */ | |
154 | gp2x_video_wait_vsync(); | |
155 | memset(gp2x_screens[0], 0, 320*240*2); | |
156 | memset(gp2x_screens[1], 0, 320*240*2); | |
157 | gp2x_video_flip2(); // might flip to fb2/3 | |
158 | gp2x_video_flip2(); // ..so we do it again | |
f4750ee0 | 159 | } |
45285368 | 160 | else |
161 | gp2x_video_flip2(); | |
cc41eb4f | 162 | |
1fb0dd88 | 163 | // switch to 16bpp |
31f944ea | 164 | gp2x_video_changemode_ll(16, 0); |
1fb0dd88 | 165 | gp2x_video_RGB_setscaling(0, 320, 240); |
1fb0dd88 | 166 | } |
167 | ||
168 | void plat_video_menu_begin(void) | |
169 | { | |
c7eb229a | 170 | g_menuscreen_ptr = g_screen_ptr; |
1fb0dd88 | 171 | } |
172 | ||
173 | void plat_video_menu_end(void) | |
174 | { | |
1fb0dd88 | 175 | gp2x_video_flip2(); |
176 | } | |
177 | ||
75a30842 | 178 | void plat_video_menu_leave(void) |
42171343 | 179 | { |
75a30842 | 180 | } |
f4750ee0 | 181 | |
759c9d38 | 182 | void *plat_mem_get_for_drc(size_t size) |
183 | { | |
184 | return NULL; | |
185 | } | |
186 | ||
58fc34b1 | 187 | int plat_parse_arg(int argc, char *argv[], int *x) |
188 | { | |
189 | return 1; | |
190 | } | |
191 | ||
75a30842 | 192 | void plat_early_init(void) |
193 | { | |
45285368 | 194 | // just use gettimeofday until plat_init() |
195 | gp2x_get_ticks_ms = plat_get_ticks_ms_good; | |
196 | gp2x_get_ticks_us = plat_get_ticks_us_good; | |
ee2a3bdf | 197 | } |
198 | ||
199 | void plat_init(void) | |
200 | { | |
75a30842 | 201 | warm_init(); |
ee2a3bdf | 202 | |
75a30842 | 203 | switch (gp2x_dev_id) { |
204 | case GP2X_DEV_GP2X: | |
205 | sharedmem940_init(); | |
206 | vid_mmsp2_init(); | |
ee2a3bdf | 207 | break; |
75a30842 | 208 | case GP2X_DEV_WIZ: |
209 | case GP2X_DEV_CAANOO: | |
210 | vid_pollux_init(); | |
ee2a3bdf | 211 | break; |
212 | } | |
42171343 | 213 | |
75a30842 | 214 | g_menuscreen_w = 320; |
215 | g_menuscreen_h = 240; | |
9cdfc191 | 216 | g_menuscreen_pp = g_menuscreen_w; |
42171343 | 217 | gp2x_memset_all_buffers(0, 0, 320*240*2); |
218 | ||
75a30842 | 219 | gp2x_make_fb_bufferable(1); |
220 | ||
205bc456 | 221 | // use buffer2 for menubg to save mem (using only buffers 0, 1 in menu) |
697746df | 222 | g_menubg_ptr = gp2x_screens[2]; |
223 | ||
b7d64dbd | 224 | flip_after_sync = 1; |
45285368 | 225 | gp2x_menu_init(); |
75a30842 | 226 | |
4e3551a5 | 227 | in_evdev_init(&gp2x_evdev_pdata); |
75a30842 | 228 | in_gp2x_init(in_gp2x_defbinds); |
229 | in_probe(); | |
230 | plat_target_setup_input(); | |
42171343 | 231 | } |
232 | ||
233 | void plat_finish(void) | |
234 | { | |
0d9bf4fc | 235 | warm_finish(); |
236 | ||
75a30842 | 237 | switch (gp2x_dev_id) { |
238 | case GP2X_DEV_GP2X: | |
239 | sharedmem940_finish(); | |
240 | vid_mmsp2_finish(); | |
42171343 | 241 | break; |
75a30842 | 242 | case GP2X_DEV_WIZ: |
243 | case GP2X_DEV_CAANOO: | |
244 | vid_pollux_finish(); | |
274f95a9 | 245 | break; |
42171343 | 246 | } |
42171343 | 247 | } |