63b796ca |
1 | // (c) Copyright 2007 notaz, All rights reserved. |
2951214e |
2 | // Free for non-commercial use. |
3 | |
4 | // For commercial use, separate licencing terms must be obtained. |
5 | |
6 | // don't like to use loads of #ifdefs, so duplicating GP2X code |
7 | // horribly instead |
8 | |
2951214e |
9 | #include <string.h> |
10 | #include <stdlib.h> |
11 | #include <wchar.h> |
12 | #include <unistd.h> |
2951214e |
13 | #include <sys/syslimits.h> // PATH_MAX |
14 | |
15 | #include <pspdisplay.h> |
16 | #include <pspgu.h> |
17 | #include <pspiofilemgr.h> |
6f748c47 |
18 | #include <psputils.h> |
2951214e |
19 | |
20 | #include "psp.h" |
21 | #include "emu.h" |
22 | #include "menu.h" |
a6df06b7 |
23 | #include "mp3.h" |
2951214e |
24 | #include "../common/menu.h" |
25 | #include "../common/emu.h" |
26 | #include "../common/readpng.h" |
27 | #include "../common/lprintf.h" |
28 | #include "version.h" |
29 | |
30 | #include <Pico/PicoInt.h> |
31 | #include <Pico/Patch.h> |
32 | #include <zlib/zlib.h> |
33 | |
34 | |
35 | #define pspKeyUnkn "???" |
960a8e27 |
36 | const char * const keyNames[] = { |
16e89bed |
37 | "SELECT", pspKeyUnkn, pspKeyUnkn, "START", "UP", "RIGHT", "DOWN", "LEFT", |
38 | "L", "R", pspKeyUnkn, pspKeyUnkn, "TRIANGLE", "CIRCLE", "X", "SQUARE", |
39 | "HOME", "HOLD", "WLAN_UP", "REMOTE", "VOLUP", "VOLDOWN", "SCREEN", "NOTE", |
40 | pspKeyUnkn, pspKeyUnkn, pspKeyUnkn, pspKeyUnkn, "NUB UP", "NUB RIGHT", "NUB DOWN", "NUB LEFT" // fake |
2951214e |
41 | }; |
42 | |
6f748c47 |
43 | static unsigned short bg_buffer[480*272] __attribute__((aligned(16))); |
2951214e |
44 | #define menu_screen psp_screen |
45 | |
b8464531 |
46 | void menu_darken_bg(void *dst, const void *src, int pixels, int darker); |
a52e1f62 |
47 | static void menu_prepare_bg(int use_game_bg, int use_fg); |
2951214e |
48 | |
49 | |
50 | static unsigned int inp_prev = 0; |
51 | |
b8464531 |
52 | unsigned long wait_for_input(unsigned int interesting, int is_key_config) |
2951214e |
53 | { |
54 | unsigned int ret; |
6af8fee5 |
55 | static int repeats = 0, wait = 20; |
16e89bed |
56 | int release = 0, count, i; |
57 | |
58 | if (!is_key_config) |
59 | interesting |= (interesting & 0xf0) << 24; // also use analog |
2951214e |
60 | |
6850f9ec |
61 | if (repeats == 2) wait = 3; |
62 | else if (repeats == 4) wait = 2; |
63 | else if (repeats == 6) wait = 1; |
2951214e |
64 | |
6850f9ec |
65 | for (i = 0; i < wait && inp_prev == psp_pad_read(1); i++) { |
2951214e |
66 | if (i == 0) repeats++; |
6850f9ec |
67 | psp_msleep(30); |
2951214e |
68 | } |
69 | |
16e89bed |
70 | for (count = 0; !((ret = psp_pad_read(1)) & interesting) && count < 100; count++) { |
2951214e |
71 | psp_msleep(50); |
72 | release = 1; |
73 | } |
74 | |
75 | if (release || ret != inp_prev) { |
76 | repeats = 0; |
6af8fee5 |
77 | wait = 20; |
2951214e |
78 | } |
79 | inp_prev = ret; |
80 | |
16e89bed |
81 | if (!is_key_config) |
82 | ret |= (ret & 0xf0000000) >> 24; // use analog as d-pad |
260f1bcc |
83 | if (wait > 6 && (ret&(BTN_UP|BTN_LEFT|BTN_DOWN|BTN_RIGHT|BTN_L|BTN_R))) |
6af8fee5 |
84 | wait = 6; |
16e89bed |
85 | |
2951214e |
86 | // we don't need diagonals in menus |
87 | if ((ret&BTN_UP) && (ret&BTN_LEFT)) ret &= ~BTN_LEFT; |
88 | if ((ret&BTN_UP) && (ret&BTN_RIGHT)) ret &= ~BTN_RIGHT; |
89 | if ((ret&BTN_DOWN) && (ret&BTN_LEFT)) ret &= ~BTN_LEFT; |
90 | if ((ret&BTN_DOWN) && (ret&BTN_RIGHT)) ret &= ~BTN_RIGHT; |
91 | |
92 | return ret; |
93 | } |
94 | |
b8464531 |
95 | void menu_draw_begin(void) |
2951214e |
96 | { |
97 | // short *src = (short *)bg_buffer, *dst = (short *)menu_screen; |
98 | // int i; |
99 | |
100 | // for (i = 272; i >= 0; i--, dst += 512, src += 480) |
101 | // memcpy32((int *)dst, (int *)src, 480*2/4); |
102 | |
db298784 |
103 | sceGuSync(0,0); // sync with prev |
2951214e |
104 | sceGuStart(GU_DIRECT, guCmdList); |
105 | sceGuCopyImage(GU_PSM_5650, 0, 0, 480, 272, 480, bg_buffer, 0, 0, 512, menu_screen); |
106 | sceGuFinish(); |
db298784 |
107 | sceGuSync(0,0); |
2951214e |
108 | } |
109 | |
110 | |
b8464531 |
111 | void menu_draw_end(void) |
2951214e |
112 | { |
703e4c7b |
113 | psp_video_flip(1); |
2951214e |
114 | } |
115 | |
116 | |
117 | // --------- loading ROM screen ---------- |
118 | |
a6df06b7 |
119 | static int lcdr_line = 0; |
120 | |
2951214e |
121 | static void load_progress_cb(int percent) |
122 | { |
123 | int ln, len = percent * 480 / 100; |
124 | unsigned short *dst; |
125 | |
a6df06b7 |
126 | //sceDisplayWaitVblankStart(); |
127 | |
128 | dst = (unsigned short *)menu_screen + 512*10*lcdr_line; |
129 | |
130 | if (len > 480) len = 480; |
131 | for (ln = 8; ln > 0; ln--, dst += 512) |
132 | memset(dst, 0xff, len*2); |
133 | } |
134 | |
135 | static void cdload_progress_cb(int percent) |
136 | { |
137 | int ln, len = percent * 480 / 100; |
138 | unsigned short *dst; |
139 | |
140 | if (lcdr_line <= 2) { |
141 | lcdr_line++; |
142 | smalltext_out16(1, lcdr_line++ * 10, "Processing CD image / MP3s", 0xffff); |
143 | smalltext_out16_lim(1, lcdr_line++ * 10, romFileName, 0xffff, 80); |
144 | } |
2951214e |
145 | |
a6df06b7 |
146 | dst = (unsigned short *)menu_screen + 512*10*lcdr_line; |
2951214e |
147 | |
148 | if (len > 480) len = 480; |
a6df06b7 |
149 | for (ln = 8; ln > 0; ln--, dst += 512) |
2951214e |
150 | memset(dst, 0xff, len*2); |
151 | } |
152 | |
153 | void menu_romload_prepare(const char *rom_name) |
154 | { |
155 | const char *p = rom_name + strlen(rom_name); |
156 | while (p > rom_name && *p != '/') p--; |
157 | |
158 | psp_video_switch_to_single(); |
144a28a0 |
159 | if (rom_loaded) menu_draw_begin(); |
5ecedd0c |
160 | else memset32_uncached(psp_screen, 0, 512*272*2/4); |
2951214e |
161 | |
162 | smalltext_out16(1, 1, "Loading", 0xffff); |
163 | smalltext_out16_lim(1, 10, p, 0xffff, 80); |
164 | PicoCartLoadProgressCB = load_progress_cb; |
a6df06b7 |
165 | PicoCDLoadProgressCB = cdload_progress_cb; |
166 | lcdr_line = 2; |
2951214e |
167 | } |
168 | |
169 | void menu_romload_end(void) |
170 | { |
a6df06b7 |
171 | PicoCartLoadProgressCB = PicoCDLoadProgressCB = NULL; |
172 | smalltext_out16(1, ++lcdr_line*10, "Starting emulation...", 0xffff); |
2951214e |
173 | } |
174 | |
175 | // -------------- ROM selector -------------- |
176 | |
177 | // SceIoDirent |
178 | #define DT_DIR FIO_SO_IFDIR |
179 | #define DT_REG FIO_SO_IFREG |
180 | |
181 | struct my_dirent |
182 | { |
183 | unsigned char d_type; |
184 | char d_name[255]; |
185 | }; |
186 | |
703e4c7b |
187 | // bbbb bggg gggr rrrr |
2951214e |
188 | static unsigned short file2color(const char *fname) |
189 | { |
190 | const char *ext = fname + strlen(fname) - 3; |
1ceda417 |
191 | static const char *rom_exts[] = { "zip", "bin", "smd", "gen", "iso", "cso", "cue" }; |
2951214e |
192 | static const char *other_exts[] = { "gmv", "pat" }; |
193 | int i; |
194 | |
195 | if (ext < fname) ext = fname; |
196 | for (i = 0; i < sizeof(rom_exts)/sizeof(rom_exts[0]); i++) |
703e4c7b |
197 | if (strcasecmp(ext, rom_exts[i]) == 0) return 0xfdf7; |
2951214e |
198 | for (i = 0; i < sizeof(other_exts)/sizeof(other_exts[0]); i++) |
199 | if (strcasecmp(ext, other_exts[i]) == 0) return 0xaff5; |
200 | return 0xffff; |
201 | } |
202 | |
203 | static void draw_dirlist(char *curdir, struct my_dirent **namelist, int n, int sel) |
204 | { |
205 | int start, i, pos; |
206 | |
207 | start = 13 - sel; |
208 | n--; // exclude current dir (".") |
209 | |
210 | menu_draw_begin(); |
211 | |
144a28a0 |
212 | if (!rom_loaded) { |
2951214e |
213 | // menu_darken_bg(menu_screen, menu_screen, 321*240, 0); |
214 | } |
215 | |
216 | menu_darken_bg((char *)menu_screen + 512*129*2, (char *)menu_screen + 512*129*2, 512*10, 0); |
217 | |
218 | if (start - 2 >= 0) |
219 | smalltext_out16_lim(14, (start - 2)*10, curdir, 0xffff, 53-2); |
220 | for (i = 0; i < n; i++) { |
221 | pos = start + i; |
222 | if (pos < 0) continue; |
223 | if (pos > 26) break; |
224 | if (namelist[i+1]->d_type & DT_DIR) { |
703e4c7b |
225 | smalltext_out16_lim(14, pos*10, "/", 0xd7ff, 1); |
a52e1f62 |
226 | smalltext_out16_lim(14+6, pos*10, namelist[i+1]->d_name, 0xd7ff, 80-3); |
2951214e |
227 | } else { |
228 | unsigned short color = file2color(namelist[i+1]->d_name); |
a52e1f62 |
229 | smalltext_out16_lim(14, pos*10, namelist[i+1]->d_name, color, 80-2); |
2951214e |
230 | } |
231 | } |
232 | text_out16(5, 130, ">"); |
233 | menu_draw_end(); |
234 | } |
235 | |
236 | static int scandir_cmp(const void *p1, const void *p2) |
237 | { |
238 | struct my_dirent **d1 = (struct my_dirent **)p1, **d2 = (struct my_dirent **)p2; |
239 | if ((*d1)->d_type == (*d2)->d_type) return strcasecmp((*d1)->d_name, (*d2)->d_name); |
240 | if ((*d1)->d_type & DT_DIR) return -1; // put before |
241 | if ((*d2)->d_type & DT_DIR) return 1; |
242 | return strcasecmp((*d1)->d_name, (*d2)->d_name); |
243 | } |
244 | |
245 | static char *filter_exts[] = { |
246 | ".mp3", ".srm", ".brm", "s.gz", ".mds", "bcfg", ".txt", ".htm", "html", |
1ceda417 |
247 | ".jpg", ".pbp" |
2951214e |
248 | }; |
249 | |
250 | static int scandir_filter(const struct my_dirent *ent) |
251 | { |
252 | const char *p; |
253 | int i; |
254 | |
255 | if (ent == NULL || ent->d_name == NULL) return 0; |
256 | if (strlen(ent->d_name) < 5) return 1; |
257 | |
258 | p = ent->d_name + strlen(ent->d_name) - 4; |
259 | |
260 | for (i = 0; i < sizeof(filter_exts)/sizeof(filter_exts[0]); i++) |
261 | { |
262 | if (strcasecmp(p, filter_exts[i]) == 0) return 0; |
263 | } |
264 | |
265 | return 1; |
266 | } |
267 | |
268 | static int my_scandir(const char *dir, struct my_dirent ***namelist_out, |
269 | int(*filter)(const struct my_dirent *), |
270 | int(*compar)(const void *, const void *)) |
271 | { |
272 | int ret = -1, dir_uid = -1, name_alloc = 4, name_count = 0; |
273 | struct my_dirent **namelist = NULL, *ent; |
274 | SceIoDirent sce_ent; |
275 | |
276 | namelist = malloc(sizeof(*namelist) * name_alloc); |
277 | if (namelist == NULL) { lprintf("%s:%i: OOM\n", __FILE__, __LINE__); goto fail; } |
278 | |
279 | // try to read first.. |
280 | dir_uid = sceIoDopen(dir); |
281 | if (dir_uid >= 0) |
282 | { |
703e4c7b |
283 | /* it is very important to clear SceIoDirent to be passed to sceIoDread(), */ |
284 | /* or else it may crash, probably misinterpreting something in it. */ |
285 | memset(&sce_ent, 0, sizeof(sce_ent)); |
2951214e |
286 | ret = sceIoDread(dir_uid, &sce_ent); |
287 | if (ret < 0) |
288 | { |
289 | lprintf("sceIoDread(\"%s\") failed with %i\n", dir, ret); |
290 | goto fail; |
291 | } |
292 | } |
293 | else |
294 | lprintf("sceIoDopen(\"%s\") failed with %i\n", dir, dir_uid); |
295 | |
296 | while (ret > 0) |
297 | { |
298 | ent = malloc(sizeof(*ent)); |
299 | if (ent == NULL) { lprintf("%s:%i: OOM\n", __FILE__, __LINE__); goto fail; } |
300 | ent->d_type = sce_ent.d_stat.st_attr; |
301 | strncpy(ent->d_name, sce_ent.d_name, sizeof(ent->d_name)); |
703e4c7b |
302 | ent->d_name[sizeof(ent->d_name)-1] = 0; |
2951214e |
303 | if (filter == NULL || filter(ent)) |
304 | namelist[name_count++] = ent; |
305 | else free(ent); |
306 | |
307 | if (name_count >= name_alloc) |
308 | { |
309 | void *tmp; |
310 | name_alloc *= 2; |
311 | tmp = realloc(namelist, sizeof(*namelist) * name_alloc); |
312 | if (tmp == NULL) { lprintf("%s:%i: OOM\n", __FILE__, __LINE__); goto fail; } |
313 | namelist = tmp; |
314 | } |
315 | |
703e4c7b |
316 | memset(&sce_ent, 0, sizeof(sce_ent)); |
2951214e |
317 | ret = sceIoDread(dir_uid, &sce_ent); |
318 | } |
319 | |
320 | // sort |
321 | if (compar != NULL && name_count > 3) qsort(&namelist[2], name_count - 2, sizeof(namelist[0]), compar); |
322 | |
323 | // all done. |
324 | ret = name_count; |
325 | *namelist_out = namelist; |
326 | goto end; |
327 | |
328 | fail: |
329 | if (namelist != NULL) |
330 | { |
331 | while (name_count--) |
332 | free(namelist[name_count]); |
333 | free(namelist); |
334 | } |
335 | end: |
336 | if (dir_uid >= 0) sceIoDclose(dir_uid); |
337 | return ret; |
338 | } |
339 | |
340 | |
c6334564 |
341 | static SceIoStat cpstat; |
342 | |
2951214e |
343 | static char *romsel_loop(char *curr_path) |
344 | { |
345 | struct my_dirent **namelist; |
703e4c7b |
346 | int n, iret, sel = 0; |
2951214e |
347 | unsigned long inp = 0; |
348 | char *ret = NULL, *fname = NULL; |
349 | |
350 | // is this a dir or a full path? |
703e4c7b |
351 | memset(&cpstat, 0, sizeof(cpstat)); |
352 | iret = sceIoGetstat(curr_path, &cpstat); |
353 | if (iret >= 0 && (cpstat.st_attr & FIO_SO_IFREG)) { // file |
2951214e |
354 | char *p; |
355 | for (p = curr_path + strlen(curr_path) - 1; p > curr_path && *p != '/'; p--); |
c6334564 |
356 | if (p > curr_path) { |
357 | *p = 0; |
358 | fname = p+1; |
359 | } |
360 | else strcpy(curr_path, "ms0:/"); |
2951214e |
361 | } |
703e4c7b |
362 | else if (iret >= 0 && (cpstat.st_attr & FIO_SO_IFDIR)); // dir |
363 | else strcpy(curr_path, "ms0:/"); // something else |
2951214e |
364 | |
365 | n = my_scandir(curr_path, &namelist, scandir_filter, scandir_cmp); |
366 | if (n < 0) { |
367 | // try root.. |
703e4c7b |
368 | n = my_scandir("ms0:/", &namelist, scandir_filter, scandir_cmp); |
2951214e |
369 | if (n < 0) { |
370 | // oops, we failed |
371 | lprintf("scandir failed, dir: "); lprintf(curr_path); lprintf("\n"); |
372 | return NULL; |
373 | } |
374 | } |
375 | |
376 | // try to find sel |
377 | if (fname != NULL) { |
378 | int i; |
379 | for (i = 1; i < n; i++) { |
380 | if (strcmp(namelist[i]->d_name, fname) == 0) { |
381 | sel = i - 1; |
382 | break; |
383 | } |
384 | } |
385 | } |
386 | |
387 | for (;;) |
388 | { |
389 | draw_dirlist(curr_path, namelist, n, sel); |
16e89bed |
390 | inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_LEFT|BTN_RIGHT|BTN_L|BTN_R|BTN_X|BTN_CIRCLE, 0); |
2951214e |
391 | if(inp & BTN_UP ) { sel--; if (sel < 0) sel = n-2; } |
392 | if(inp & BTN_DOWN) { sel++; if (sel > n-2) sel = 0; } |
393 | if(inp & BTN_LEFT) { sel-=10; if (sel < 0) sel = 0; } |
394 | if(inp & BTN_L) { sel-=24; if (sel < 0) sel = 0; } |
395 | if(inp & BTN_RIGHT) { sel+=10; if (sel > n-2) sel = n-2; } |
396 | if(inp & BTN_R) { sel+=24; if (sel > n-2) sel = n-2; } |
16e89bed |
397 | if(inp & BTN_CIRCLE) { // enter dir/select |
2951214e |
398 | if (namelist[sel+1]->d_type & DT_REG) { |
399 | strcpy(romFileName, curr_path); |
400 | strcat(romFileName, "/"); |
401 | strcat(romFileName, namelist[sel+1]->d_name); |
402 | ret = romFileName; |
403 | break; |
404 | } else if (namelist[sel+1]->d_type & DT_DIR) { |
405 | int newlen = strlen(curr_path) + strlen(namelist[sel+1]->d_name) + 2; |
406 | char *p, *newdir = malloc(newlen); |
407 | if (strcmp(namelist[sel+1]->d_name, "..") == 0) { |
408 | char *start = curr_path; |
409 | p = start + strlen(start) - 1; |
410 | while (*p == '/' && p > start) p--; |
703e4c7b |
411 | while (*p != '/' && *p != ':' && p > start) p--; |
c6334564 |
412 | if (p <= start || *p == ':') strcpy(newdir, "ms0:/"); |
2951214e |
413 | else { strncpy(newdir, start, p-start); newdir[p-start] = 0; } |
414 | } else { |
415 | strcpy(newdir, curr_path); |
416 | p = newdir + strlen(newdir) - 1; |
417 | while (*p == '/' && p >= newdir) *p-- = 0; |
418 | strcat(newdir, "/"); |
419 | strcat(newdir, namelist[sel+1]->d_name); |
420 | } |
421 | ret = romsel_loop(newdir); |
422 | free(newdir); |
423 | break; |
424 | } |
425 | } |
16e89bed |
426 | if(inp & BTN_X) break; // cancel |
2951214e |
427 | } |
428 | |
429 | if (n > 0) { |
430 | while(n--) free(namelist[n]); |
431 | free(namelist); |
432 | } |
433 | |
434 | return ret; |
435 | } |
436 | |
2951214e |
437 | // ------------ patch/gg menu ------------ |
438 | |
439 | static void draw_patchlist(int sel) |
440 | { |
441 | int start, i, pos, active; |
442 | |
443 | start = 13 - sel; |
444 | |
445 | menu_draw_begin(); |
446 | |
447 | for (i = 0; i < PicoPatchCount; i++) { |
448 | pos = start + i; |
449 | if (pos < 0) continue; |
450 | if (pos > 26) break; |
451 | active = PicoPatches[i].active; |
452 | smalltext_out16_lim(14, pos*10, active ? "ON " : "OFF", active ? 0xfff6 : 0xffff, 3); |
453 | smalltext_out16_lim(14+6*4, pos*10, PicoPatches[i].name, active ? 0xfff6 : 0xffff, 53-6); |
454 | } |
455 | pos = start + i; |
456 | if (pos < 27) smalltext_out16_lim(14, pos*10, "done", 0xffff, 4); |
457 | |
458 | text_out16(5, 130, ">"); |
459 | menu_draw_end(); |
460 | } |
461 | |
462 | |
463 | static void patches_menu_loop(void) |
464 | { |
465 | int menu_sel = 0; |
466 | unsigned long inp = 0; |
467 | |
468 | for(;;) |
469 | { |
470 | draw_patchlist(menu_sel); |
16e89bed |
471 | inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_LEFT|BTN_RIGHT|BTN_L|BTN_R|BTN_X|BTN_CIRCLE, 0); |
2951214e |
472 | if(inp & BTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = PicoPatchCount; } |
473 | if(inp & BTN_DOWN) { menu_sel++; if (menu_sel > PicoPatchCount) menu_sel = 0; } |
474 | if(inp &(BTN_LEFT|BTN_L)) { menu_sel-=10; if (menu_sel < 0) menu_sel = 0; } |
475 | if(inp &(BTN_RIGHT|BTN_R)) { menu_sel+=10; if (menu_sel > PicoPatchCount) menu_sel = PicoPatchCount; } |
16e89bed |
476 | if(inp & BTN_CIRCLE) { // action |
2951214e |
477 | if (menu_sel < PicoPatchCount) |
478 | PicoPatches[menu_sel].active = !PicoPatches[menu_sel].active; |
479 | else return; |
480 | } |
16e89bed |
481 | if(inp & BTN_X) return; |
2951214e |
482 | } |
483 | |
484 | } |
485 | |
486 | // ------------ savestate loader ------------ |
487 | |
488 | static int state_slot_flags = 0; |
489 | |
490 | static void state_check_slots(void) |
491 | { |
492 | int slot; |
493 | |
494 | state_slot_flags = 0; |
495 | |
496 | for (slot = 0; slot < 10; slot++) |
497 | { |
498 | if (emu_checkSaveFile(slot)) |
499 | { |
500 | state_slot_flags |= 1 << slot; |
501 | } |
502 | } |
503 | } |
504 | |
6f748c47 |
505 | static void *get_oldstate_for_preview(void) |
506 | { |
507 | unsigned char *ptr = malloc(sizeof(Pico.vram) + sizeof(Pico.cram) + sizeof(Pico.vsram) + sizeof(Pico.video)); |
508 | if (ptr == NULL) return NULL; |
509 | |
510 | memcpy(ptr, Pico.vram, sizeof(Pico.vram)); |
511 | memcpy(ptr + sizeof(Pico.vram), Pico.cram, sizeof(Pico.cram)); |
512 | memcpy(ptr + sizeof(Pico.vram) + sizeof(Pico.cram), Pico.vsram, sizeof(Pico.vsram)); |
513 | memcpy(ptr + sizeof(Pico.vram) + sizeof(Pico.cram) + sizeof(Pico.vsram), &Pico.video, sizeof(Pico.video)); |
514 | return ptr; |
515 | } |
516 | |
517 | static void restore_oldstate(void *ptrx) |
518 | { |
519 | unsigned char *ptr = ptrx; |
520 | memcpy(Pico.vram, ptr, sizeof(Pico.vram)); |
521 | memcpy(Pico.cram, ptr + sizeof(Pico.vram), sizeof(Pico.cram)); |
522 | memcpy(Pico.vsram, ptr + sizeof(Pico.vram) + sizeof(Pico.cram), sizeof(Pico.vsram)); |
523 | memcpy(&Pico.video,ptr + sizeof(Pico.vram) + sizeof(Pico.cram) + sizeof(Pico.vsram), sizeof(Pico.video)); |
524 | free(ptrx); |
525 | } |
526 | |
2951214e |
527 | static void draw_savestate_bg(int slot) |
528 | { |
6f748c47 |
529 | void *file, *oldstate; |
2951214e |
530 | char *fname; |
531 | |
532 | fname = emu_GetSaveFName(1, 0, slot); |
533 | if (!fname) return; |
534 | |
6f748c47 |
535 | oldstate = get_oldstate_for_preview(); |
536 | if (oldstate == NULL) return; |
2951214e |
537 | |
538 | if (strcmp(fname + strlen(fname) - 3, ".gz") == 0) { |
539 | file = gzopen(fname, "rb"); |
540 | emu_setSaveStateCbs(1); |
541 | } else { |
542 | file = fopen(fname, "rb"); |
543 | emu_setSaveStateCbs(0); |
544 | } |
545 | |
546 | if (file) { |
dd5fd477 |
547 | if (PicoAHW & PAHW_MCD) { |
2951214e |
548 | PicoCdLoadStateGfx(file); |
549 | } else { |
550 | areaSeek(file, 0x10020, SEEK_SET); // skip header and RAM in state file |
551 | areaRead(Pico.vram, 1, sizeof(Pico.vram), file); |
552 | areaSeek(file, 0x2000, SEEK_CUR); |
553 | areaRead(Pico.cram, 1, sizeof(Pico.cram), file); |
554 | areaRead(Pico.vsram, 1, sizeof(Pico.vsram), file); |
555 | areaSeek(file, 0x221a0, SEEK_SET); |
556 | areaRead(&Pico.video, 1, sizeof(Pico.video), file); |
557 | } |
558 | areaClose(file); |
559 | } |
560 | |
8a091e48 |
561 | emu_forcedFrame(0); |
a52e1f62 |
562 | menu_prepare_bg(1, 0); |
2951214e |
563 | |
6f748c47 |
564 | restore_oldstate(oldstate); |
2951214e |
565 | } |
566 | |
567 | static void draw_savestate_menu(int menu_sel, int is_loading) |
568 | { |
569 | int tl_x = 80+25, tl_y = 16+60, y, i; |
570 | |
571 | if (state_slot_flags & (1 << menu_sel)) |
572 | draw_savestate_bg(menu_sel); |
573 | menu_draw_begin(); |
574 | |
575 | text_out16(tl_x, 16+30, is_loading ? "Load state" : "Save state"); |
576 | |
577 | menu_draw_selection(tl_x - 16, tl_y + menu_sel*10, 108); |
578 | |
579 | /* draw all 10 slots */ |
580 | y = tl_y; |
581 | for (i = 0; i < 10; i++, y+=10) |
582 | { |
583 | text_out16(tl_x, y, "SLOT %i (%s)", i, (state_slot_flags & (1 << i)) ? "USED" : "free"); |
584 | } |
585 | text_out16(tl_x, y, "back"); |
586 | |
587 | menu_draw_end(); |
588 | } |
589 | |
590 | static int savestate_menu_loop(int is_loading) |
591 | { |
592 | static int menu_sel = 10; |
593 | int menu_sel_max = 10; |
594 | unsigned long inp = 0; |
595 | |
596 | state_check_slots(); |
597 | |
598 | for(;;) |
599 | { |
600 | draw_savestate_menu(menu_sel, is_loading); |
16e89bed |
601 | inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_X|BTN_CIRCLE, 0); |
2951214e |
602 | if(inp & BTN_UP ) { |
603 | do { |
604 | menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; |
605 | } while (!(state_slot_flags & (1 << menu_sel)) && menu_sel != menu_sel_max && is_loading); |
606 | } |
607 | if(inp & BTN_DOWN) { |
608 | do { |
609 | menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; |
610 | } while (!(state_slot_flags & (1 << menu_sel)) && menu_sel != menu_sel_max && is_loading); |
611 | } |
16e89bed |
612 | if(inp & BTN_CIRCLE) { // save/load |
2951214e |
613 | if (menu_sel < 10) { |
614 | state_slot = menu_sel; |
6f748c47 |
615 | PicoStateProgressCB = emu_msg_cb; /* also suitable for menu */ |
2951214e |
616 | if (emu_SaveLoadGame(is_loading, 0)) { |
617 | strcpy(menuErrorMsg, is_loading ? "Load failed" : "Save failed"); |
618 | return 1; |
619 | } |
620 | return 0; |
621 | } else return 1; |
622 | } |
16e89bed |
623 | if(inp & BTN_X) return 1; |
2951214e |
624 | } |
625 | } |
626 | |
627 | // -------------- key config -------------- |
628 | |
629 | static char *action_binds(int player_idx, int action_mask) |
630 | { |
631 | static char strkeys[32*5]; |
632 | int i; |
633 | |
634 | strkeys[0] = 0; |
635 | for (i = 0; i < 32; i++) // i is key index |
636 | { |
637 | if (currentConfig.KeyBinds[i] & action_mask) |
638 | { |
639 | if (player_idx >= 0 && ((currentConfig.KeyBinds[i] >> 16) & 3) != player_idx) continue; |
16e89bed |
640 | if (strkeys[0]) { |
641 | strcat(strkeys, i >= 28 ? ", " : " + "); // nub "buttons" don't create combos |
960a8e27 |
642 | strcat(strkeys, keyNames[i]); |
16e89bed |
643 | break; |
644 | } |
960a8e27 |
645 | else strcpy(strkeys, keyNames[i]); |
2951214e |
646 | } |
647 | } |
648 | |
649 | return strkeys; |
650 | } |
651 | |
652 | static void unbind_action(int action) |
653 | { |
654 | int i; |
655 | |
656 | for (i = 0; i < 32; i++) |
657 | currentConfig.KeyBinds[i] &= ~action; |
658 | } |
659 | |
660 | static int count_bound_keys(int action, int pl_idx) |
661 | { |
662 | int i, keys = 0; |
663 | |
664 | for (i = 0; i < 32; i++) |
665 | { |
666 | if (pl_idx >= 0 && (currentConfig.KeyBinds[i]&0x30000) != (pl_idx<<16)) continue; |
667 | if (currentConfig.KeyBinds[i] & action) keys++; |
668 | } |
669 | |
670 | return keys; |
671 | } |
672 | |
960a8e27 |
673 | static void draw_key_config(const me_bind_action *opts, int opt_cnt, int player_idx, int sel) |
2951214e |
674 | { |
675 | int x, y, tl_y = 16+40, i; |
676 | |
677 | menu_draw_begin(); |
678 | if (player_idx >= 0) { |
679 | text_out16(80+80, 16+20, "Player %i controls", player_idx + 1); |
680 | x = 80+80; |
681 | } else { |
682 | text_out16(80+80, 16+20, "Emulator controls"); |
683 | x = 80+40; |
684 | } |
685 | |
686 | menu_draw_selection(x - 16, tl_y + sel*10, (player_idx >= 0) ? 66 : 130); |
687 | |
688 | y = tl_y; |
689 | for (i = 0; i < opt_cnt; i++, y+=10) |
690 | text_out16(x, y, "%s : %s", opts[i].name, action_binds(player_idx, opts[i].mask)); |
691 | |
692 | text_out16(x, y, "Done"); |
693 | |
694 | if (sel < opt_cnt) { |
16e89bed |
695 | text_out16(80+30, 220, "Press a button to bind/unbind"); |
696 | text_out16(80+30, 230, "Use SELECT to clear"); |
697 | text_out16(80+30, 240, "To bind UP/DOWN, hold SELECT"); |
698 | text_out16(80+30, 250, "Select \"Done\" to exit"); |
2951214e |
699 | } else { |
16e89bed |
700 | text_out16(80+30, 230, "Use Options -> Save cfg"); |
701 | text_out16(80+30, 240, "to save controls"); |
702 | text_out16(80+30, 250, "Press X or O to exit"); |
2951214e |
703 | } |
704 | menu_draw_end(); |
705 | } |
706 | |
960a8e27 |
707 | static void key_config_loop(const me_bind_action *opts, int opt_cnt, int player_idx) |
2951214e |
708 | { |
709 | int sel = 0, menu_sel_max = opt_cnt, prev_select = 0, i; |
710 | unsigned long inp = 0; |
711 | |
712 | for (;;) |
713 | { |
714 | draw_key_config(opts, opt_cnt, player_idx, sel); |
16e89bed |
715 | inp = wait_for_input(CONFIGURABLE_KEYS|BTN_SELECT, 1); |
2951214e |
716 | if (!(inp & BTN_SELECT)) { |
717 | prev_select = 0; |
718 | if(inp & BTN_UP ) { sel--; if (sel < 0) sel = menu_sel_max; continue; } |
719 | if(inp & BTN_DOWN) { sel++; if (sel > menu_sel_max) sel = 0; continue; } |
720 | } |
721 | if (sel >= opt_cnt) { |
722 | if (inp & (BTN_X|BTN_CIRCLE)) break; |
723 | else continue; |
724 | } |
725 | // if we are here, we want to bind/unbind something |
726 | if ((inp & BTN_SELECT) && !prev_select) |
727 | unbind_action(opts[sel].mask); |
728 | prev_select = inp & BTN_SELECT; |
729 | inp &= CONFIGURABLE_KEYS; |
730 | inp &= ~BTN_SELECT; |
731 | for (i = 0; i < 32; i++) |
732 | if (inp & (1 << i)) { |
733 | if (count_bound_keys(opts[sel].mask, player_idx) >= 2) |
734 | currentConfig.KeyBinds[i] &= ~opts[sel].mask; // allow to unbind only |
735 | else currentConfig.KeyBinds[i] ^= opts[sel].mask; |
736 | if (player_idx >= 0 && (currentConfig.KeyBinds[i] & opts[sel].mask)) { |
737 | currentConfig.KeyBinds[i] &= ~(3 << 16); |
738 | currentConfig.KeyBinds[i] |= player_idx << 16; |
739 | } |
740 | } |
741 | } |
742 | } |
743 | |
744 | static void draw_kc_sel(int menu_sel) |
745 | { |
746 | int tl_x = 80+25+40, tl_y = 16+60, y; |
747 | |
748 | y = tl_y; |
749 | menu_draw_begin(); |
750 | menu_draw_selection(tl_x - 16, tl_y + menu_sel*10, 138); |
751 | |
752 | text_out16(tl_x, y, "Player 1"); |
753 | text_out16(tl_x, (y+=10), "Player 2"); |
754 | text_out16(tl_x, (y+=10), "Emulator controls"); |
755 | text_out16(tl_x, (y+=10), "Done"); |
756 | |
757 | menu_draw_end(); |
758 | } |
759 | |
760 | |
2951214e |
761 | // player2_flag, ?, ?, ?, ?, ?, ?, menu |
762 | // "NEXT SAVE SLOT", "PREV SAVE SLOT", "SWITCH RENDERER", "SAVE STATE", |
763 | // "LOAD STATE", "VOLUME UP", "VOLUME DOWN", "DONE" |
367b6f1f |
764 | me_bind_action emuctrl_actions[] = |
2951214e |
765 | { |
8a091e48 |
766 | { "Load State ", 1<<28 }, |
767 | { "Save State ", 1<<27 }, |
768 | { "Prev Save Slot ", 1<<25 }, |
769 | { "Next Save Slot ", 1<<24 }, |
770 | { "Switch Renderer ", 1<<26 }, |
771 | { "Fast forward ", 1<<22 }, |
772 | { "Pico Next page ", 1<<21 }, |
773 | { "Pico Prev page ", 1<<20 }, |
774 | { "Pico Switch input", 1<<19 }, |
775 | { NULL, 0 } |
2951214e |
776 | }; |
777 | |
778 | static void kc_sel_loop(void) |
779 | { |
780 | int menu_sel = 3, menu_sel_max = 3; |
781 | unsigned long inp = 0; |
960a8e27 |
782 | int is_6button = PicoOpt & POPT_6BTN_PAD; |
2951214e |
783 | |
784 | while (1) |
785 | { |
786 | draw_kc_sel(menu_sel); |
16e89bed |
787 | inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_X|BTN_CIRCLE, 0); |
2951214e |
788 | if (inp & BTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; } |
789 | if (inp & BTN_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; } |
16e89bed |
790 | if (inp & BTN_CIRCLE) { |
2951214e |
791 | switch (menu_sel) { |
367b6f1f |
792 | case 0: key_config_loop(me_ctrl_actions, is_6button ? 12 : 8, 0); return; |
793 | case 1: key_config_loop(me_ctrl_actions, is_6button ? 12 : 8, 1); return; |
2951214e |
794 | case 2: key_config_loop(emuctrl_actions, |
8e708f92 |
795 | sizeof(emuctrl_actions)/sizeof(emuctrl_actions[0]) - 1, -1); return; |
144a28a0 |
796 | case 3: if (!rom_loaded) emu_WriteConfig(0); return; |
2951214e |
797 | default: return; |
798 | } |
799 | } |
16e89bed |
800 | if (inp & BTN_X) return; |
2951214e |
801 | } |
802 | } |
803 | |
804 | |
805 | // --------- sega/mega cd options ---------- |
806 | |
807 | menu_entry cdopt_entries[] = |
808 | { |
960a8e27 |
809 | { NULL, MB_NONE, MA_CDOPT_TESTBIOS_USA, NULL, 0, 0, 0, 1, 0 }, |
810 | { NULL, MB_NONE, MA_CDOPT_TESTBIOS_EUR, NULL, 0, 0, 0, 1, 0 }, |
811 | { NULL, MB_NONE, MA_CDOPT_TESTBIOS_JAP, NULL, 0, 0, 0, 1, 0 }, |
812 | { "CD LEDs", MB_ONOFF, MA_CDOPT_LEDS, ¤tConfig.EmuOpt, 0x0400, 0, 0, 1, 1 }, |
813 | { "CDDA audio (using mp3s)", MB_ONOFF, MA_CDOPT_CDDA, &PicoOpt, 0x0800, 0, 0, 1, 1 }, |
814 | { "PCM audio", MB_ONOFF, MA_CDOPT_PCM, &PicoOpt, 0x0400, 0, 0, 1, 1 }, |
815 | { NULL, MB_NONE, MA_CDOPT_READAHEAD, NULL, 0, 0, 0, 1, 1 }, |
816 | { "SaveRAM cart", MB_ONOFF, MA_CDOPT_SAVERAM, &PicoOpt, 0x8000, 0, 0, 1, 1 }, |
817 | { "Scale/Rot. fx (slow)", MB_ONOFF, MA_CDOPT_SCALEROT_CHIP,&PicoOpt, 0x1000, 0, 0, 1, 1 }, |
818 | { "Better sync (slow)", MB_ONOFF, MA_CDOPT_BETTER_SYNC, &PicoOpt, 0x2000, 0, 0, 1, 1 }, |
819 | { "done", MB_NONE, MA_CDOPT_DONE, NULL, 0, 0, 0, 1, 0 }, |
2951214e |
820 | }; |
821 | |
822 | #define CDOPT_ENTRY_COUNT (sizeof(cdopt_entries) / sizeof(cdopt_entries[0])) |
960a8e27 |
823 | const int cdopt_entry_count = CDOPT_ENTRY_COUNT; |
2951214e |
824 | |
825 | |
826 | struct bios_names_t |
827 | { |
828 | char us[32], eu[32], jp[32]; |
829 | }; |
830 | |
831 | static void menu_cdopt_cust_draw(const menu_entry *entry, int x, int y, void *param) |
832 | { |
833 | struct bios_names_t *bios_names = param; |
834 | char ra_buff[16]; |
835 | |
836 | switch (entry->id) |
837 | { |
838 | case MA_CDOPT_TESTBIOS_USA: text_out16(x, y, "USA BIOS: %s", bios_names->us); break; |
839 | case MA_CDOPT_TESTBIOS_EUR: text_out16(x, y, "EUR BIOS: %s", bios_names->eu); break; |
840 | case MA_CDOPT_TESTBIOS_JAP: text_out16(x, y, "JAP BIOS: %s", bios_names->jp); break; |
841 | case MA_CDOPT_READAHEAD: |
842 | if (PicoCDBuffers > 1) sprintf(ra_buff, "%5iK", PicoCDBuffers * 2); |
843 | else strcpy(ra_buff, " OFF"); |
844 | text_out16(x, y, "ReadAhead buffer %s", ra_buff); |
845 | break; |
846 | default:break; |
847 | } |
848 | } |
849 | |
850 | static void draw_cd_menu_options(int menu_sel, struct bios_names_t *bios_names) |
851 | { |
852 | int tl_x = 80+25, tl_y = 16+60; |
853 | menu_id selected_id; |
854 | char ra_buff[16]; |
855 | |
856 | if (PicoCDBuffers > 1) sprintf(ra_buff, "%5iK", PicoCDBuffers * 2); |
857 | else strcpy(ra_buff, " OFF"); |
858 | |
859 | menu_draw_begin(); |
860 | |
861 | menu_draw_selection(tl_x - 16, tl_y + menu_sel*10, 246); |
862 | |
863 | me_draw(cdopt_entries, CDOPT_ENTRY_COUNT, tl_x, tl_y, menu_cdopt_cust_draw, bios_names); |
864 | |
865 | selected_id = me_index2id(cdopt_entries, CDOPT_ENTRY_COUNT, menu_sel); |
866 | if ((selected_id == MA_CDOPT_TESTBIOS_USA && strcmp(bios_names->us, "NOT FOUND")) || |
867 | (selected_id == MA_CDOPT_TESTBIOS_EUR && strcmp(bios_names->eu, "NOT FOUND")) || |
868 | (selected_id == MA_CDOPT_TESTBIOS_JAP && strcmp(bios_names->jp, "NOT FOUND"))) |
16e89bed |
869 | text_out16(tl_x, 250, "Press start to test selected BIOS"); |
2951214e |
870 | |
871 | menu_draw_end(); |
872 | } |
873 | |
874 | static void cd_menu_loop_options(void) |
875 | { |
876 | static int menu_sel = 0; |
877 | int menu_sel_max = 10; |
878 | unsigned long inp = 0; |
879 | struct bios_names_t bios_names; |
880 | menu_id selected_id; |
881 | char *bios, *p; |
882 | |
883 | if (emu_findBios(4, &bios)) { // US |
60a10527 |
884 | for (p = bios+strlen(bios)-1; p > bios && *p != '/'; p--); |
885 | if (*p == '/') p++; |
2951214e |
886 | strncpy(bios_names.us, p, sizeof(bios_names.us)); bios_names.us[sizeof(bios_names.us)-1] = 0; |
887 | } else strcpy(bios_names.us, "NOT FOUND"); |
888 | |
889 | if (emu_findBios(8, &bios)) { // EU |
60a10527 |
890 | for (p = bios+strlen(bios)-1; p > bios && *p != '/'; p--); |
891 | if (*p == '/') p++; |
2951214e |
892 | strncpy(bios_names.eu, p, sizeof(bios_names.eu)); bios_names.eu[sizeof(bios_names.eu)-1] = 0; |
893 | } else strcpy(bios_names.eu, "NOT FOUND"); |
894 | |
895 | if (emu_findBios(1, &bios)) { // JP |
60a10527 |
896 | for (p = bios+strlen(bios)-1; p > bios && *p != '/'; p--); |
897 | if (*p == '/') p++; |
2951214e |
898 | strncpy(bios_names.jp, p, sizeof(bios_names.jp)); bios_names.jp[sizeof(bios_names.jp)-1] = 0; |
899 | } else strcpy(bios_names.jp, "NOT FOUND"); |
900 | |
a6df06b7 |
901 | menuErrorMsg[0] = 0; |
902 | |
903 | for (;;) |
2951214e |
904 | { |
905 | draw_cd_menu_options(menu_sel, &bios_names); |
fe9e3b25 |
906 | inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_LEFT|BTN_RIGHT|BTN_X|BTN_CIRCLE|BTN_START, 0); |
2951214e |
907 | if (inp & BTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; } |
908 | if (inp & BTN_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; } |
909 | selected_id = me_index2id(cdopt_entries, CDOPT_ENTRY_COUNT, menu_sel); |
910 | if (inp & (BTN_LEFT|BTN_RIGHT)) { // multi choise |
911 | if (!me_process(cdopt_entries, CDOPT_ENTRY_COUNT, selected_id, (inp&BTN_RIGHT) ? 1 : 0) && |
912 | selected_id == MA_CDOPT_READAHEAD) { |
913 | if (inp & BTN_LEFT) { |
914 | PicoCDBuffers >>= 1; |
88bfc63d |
915 | if (PicoCDBuffers < 2) PicoCDBuffers = 0; |
2951214e |
916 | } else { |
88bfc63d |
917 | if (PicoCDBuffers < 2) PicoCDBuffers = 2; |
2951214e |
918 | else PicoCDBuffers <<= 1; |
919 | if (PicoCDBuffers > 8*1024) PicoCDBuffers = 8*1024; // 16M |
920 | } |
921 | } |
922 | } |
fe9e3b25 |
923 | if (inp & BTN_CIRCLE) // toggleable options |
2951214e |
924 | if (!me_process(cdopt_entries, CDOPT_ENTRY_COUNT, selected_id, 1) && |
925 | selected_id == MA_CDOPT_DONE) { |
926 | return; |
927 | } |
fe9e3b25 |
928 | if (inp & BTN_START) { |
2951214e |
929 | switch (selected_id) { // BIOS testers |
930 | case MA_CDOPT_TESTBIOS_USA: |
931 | if (emu_findBios(4, &bios)) { // test US |
932 | strcpy(romFileName, bios); |
933 | engineState = PGS_ReloadRom; |
934 | return; |
935 | } |
936 | break; |
937 | case MA_CDOPT_TESTBIOS_EUR: |
938 | if (emu_findBios(8, &bios)) { // test EU |
939 | strcpy(romFileName, bios); |
940 | engineState = PGS_ReloadRom; |
941 | return; |
942 | } |
943 | break; |
944 | case MA_CDOPT_TESTBIOS_JAP: |
945 | if (emu_findBios(1, &bios)) { // test JP |
946 | strcpy(romFileName, bios); |
947 | engineState = PGS_ReloadRom; |
948 | return; |
949 | } |
950 | break; |
951 | default: |
952 | break; |
953 | } |
954 | } |
16e89bed |
955 | if (inp & BTN_X) return; |
2951214e |
956 | } |
957 | } |
958 | |
6f748c47 |
959 | // --------- display options ---------- |
960 | |
961 | menu_entry opt3_entries[] = |
962 | { |
960a8e27 |
963 | { NULL, MB_NONE, MA_OPT3_SCALE, NULL, 0, 0, 0, 1, 1 }, |
964 | { NULL, MB_NONE, MA_OPT3_HSCALE32, NULL, 0, 0, 0, 1, 1 }, |
965 | { NULL, MB_NONE, MA_OPT3_HSCALE40, NULL, 0, 0, 0, 1, 1 }, |
966 | { NULL, MB_ONOFF, MA_OPT3_FILTERING, ¤tConfig.scaling, 1, 0, 0, 1, 1 }, |
967 | { NULL, MB_RANGE, MA_OPT3_GAMMAA, ¤tConfig.gamma, 0, -4, 16, 1, 1 }, |
968 | { NULL, MB_RANGE, MA_OPT3_BLACKLVL, ¤tConfig.gamma2, 0, 0, 2, 1, 1 }, |
969 | { NULL, MB_NONE, MA_OPT3_VSYNC, NULL, 0, 0, 0, 1, 1 }, |
970 | { "Set to unscaled centered", MB_NONE, MA_OPT3_PRES_NOSCALE, NULL, 0, 0, 0, 1, 0 }, |
971 | { "Set to 4:3 scaled", MB_NONE, MA_OPT3_PRES_SCALE43, NULL, 0, 0, 0, 1, 0 }, |
972 | { "Set to fullscreen", MB_NONE, MA_OPT3_PRES_FULLSCR, NULL, 0, 0, 0, 1, 0 }, |
973 | { "done", MB_NONE, MA_OPT3_DONE, NULL, 0, 0, 0, 1, 0 }, |
6f748c47 |
974 | }; |
975 | |
976 | #define OPT3_ENTRY_COUNT (sizeof(opt3_entries) / sizeof(opt3_entries[0])) |
960a8e27 |
977 | const int opt3_entry_count = OPT3_ENTRY_COUNT; |
6f748c47 |
978 | |
979 | |
980 | static void menu_opt3_cust_draw(const menu_entry *entry, int x, int y, void *param) |
981 | { |
982 | switch (entry->id) |
983 | { |
984 | case MA_OPT3_SCALE: |
985 | text_out16(x, y, "Scale factor: %.2f", currentConfig.scale); |
986 | break; |
987 | case MA_OPT3_HSCALE32: |
988 | text_out16(x, y, "Hor. scale (for low res. games): %.2f", currentConfig.hscale32); |
989 | break; |
990 | case MA_OPT3_HSCALE40: |
991 | text_out16(x, y, "Hor. scale (for hi res. games): %.2f", currentConfig.hscale40); |
992 | break; |
993 | case MA_OPT3_FILTERING: |
994 | text_out16(x, y, "Bilinear filtering %s", currentConfig.scaling?"ON":"OFF"); |
995 | break; |
93c0d147 |
996 | case MA_OPT3_GAMMAA: |
997 | text_out16(x, y, "Gamma adjustment %2i", currentConfig.gamma); |
998 | break; |
960a8e27 |
999 | case MA_OPT3_BLACKLVL: |
1000 | text_out16(x, y, "Black level %2i", currentConfig.gamma2); |
1001 | break; |
4b8f4f3c |
1002 | case MA_OPT3_VSYNC: { |
1003 | char *val = " never"; |
1004 | if (currentConfig.EmuOpt & 0x2000) |
1005 | val = (currentConfig.EmuOpt & 0x10000) ? "sometimes" : " always"; |
c93fb19e |
1006 | text_out16(x, y, "Wait for vsync (slow) %s", val); |
4b8f4f3c |
1007 | break; |
1008 | } |
6f748c47 |
1009 | default: break; |
1010 | } |
1011 | } |
1012 | |
1013 | static void menu_opt3_preview(int is_32col) |
1014 | { |
1015 | void *oldstate = NULL; |
1016 | |
144a28a0 |
1017 | if (!rom_loaded || ((Pico.video.reg[12]&1)^1) != is_32col) |
6f748c47 |
1018 | { |
1019 | extern char bgdatac32_start[], bgdatac40_start[]; |
1020 | extern int bgdatac32_size, bgdatac40_size; |
1021 | void *bgdata = is_32col ? bgdatac32_start : bgdatac40_start; |
1022 | unsigned long insize = is_32col ? bgdatac32_size : bgdatac40_size, outsize = 65856; |
1023 | int ret; |
6f748c47 |
1024 | ret = uncompress((Bytef *)bg_buffer, &outsize, bgdata, insize); |
1025 | if (ret == 0) |
1026 | { |
144a28a0 |
1027 | if (rom_loaded) oldstate = get_oldstate_for_preview(); |
6f748c47 |
1028 | memcpy(Pico.vram, bg_buffer, sizeof(Pico.vram)); |
1029 | memcpy(Pico.cram, (char *)bg_buffer + 0x10000, 0x40*2); |
1030 | memcpy(Pico.vsram, (char *)bg_buffer + 0x10080, 0x40*2); |
1031 | memcpy(&Pico.video,(char *)bg_buffer + 0x10100, 0x40); |
1032 | } |
1033 | else |
1034 | lprintf("uncompress returned %i\n", ret); |
1035 | } |
1036 | |
5ecedd0c |
1037 | memset32_uncached(psp_screen, 0, 512*272*2/4); |
8a091e48 |
1038 | emu_forcedFrame(0); |
a52e1f62 |
1039 | menu_prepare_bg(1, 0); |
6f748c47 |
1040 | |
1041 | if (oldstate) restore_oldstate(oldstate); |
1042 | } |
1043 | |
1044 | static void draw_dispmenu_options(int menu_sel) |
1045 | { |
4b8f4f3c |
1046 | int tl_x = 80, tl_y = 16+50; |
6f748c47 |
1047 | |
1048 | menu_draw_begin(); |
1049 | |
4b8f4f3c |
1050 | menu_draw_selection(tl_x - 16, tl_y + menu_sel*10, 316); |
6f748c47 |
1051 | |
1052 | me_draw(opt3_entries, OPT3_ENTRY_COUNT, tl_x, tl_y, menu_opt3_cust_draw, NULL); |
1053 | |
1054 | menu_draw_end(); |
1055 | } |
1056 | |
1057 | static void dispmenu_loop_options(void) |
1058 | { |
1059 | static int menu_sel = 0; |
c93fb19e |
1060 | int menu_sel_max, is_32col = (Pico.video.reg[12]&1)^1; |
6f748c47 |
1061 | unsigned long inp = 0; |
1062 | menu_id selected_id; |
1063 | |
1064 | menu_sel_max = me_count_enabled(opt3_entries, OPT3_ENTRY_COUNT) - 1; |
1065 | |
4b8f4f3c |
1066 | for (;;) |
6f748c47 |
1067 | { |
1068 | draw_dispmenu_options(menu_sel); |
16e89bed |
1069 | inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_LEFT|BTN_RIGHT|BTN_X|BTN_CIRCLE, 0); |
6f748c47 |
1070 | if (inp & BTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; } |
1071 | if (inp & BTN_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; } |
1072 | selected_id = me_index2id(opt3_entries, OPT3_ENTRY_COUNT, menu_sel); |
1073 | if (selected_id == MA_OPT3_HSCALE40 && is_32col) { is_32col = 0; menu_opt3_preview(is_32col); } |
1074 | if (selected_id == MA_OPT3_HSCALE32 && !is_32col) { is_32col = 1; menu_opt3_preview(is_32col); } |
1075 | |
1076 | if (inp & (BTN_LEFT|BTN_RIGHT)) // multi choise |
1077 | { |
1078 | float *setting = NULL; |
4b8f4f3c |
1079 | int tmp; |
6f748c47 |
1080 | me_process(opt3_entries, OPT3_ENTRY_COUNT, selected_id, (inp&BTN_RIGHT) ? 1 : 0); |
1081 | switch (selected_id) { |
93c0d147 |
1082 | case MA_OPT3_SCALE: setting = ¤tConfig.scale; break; |
1083 | case MA_OPT3_HSCALE40: setting = ¤tConfig.hscale40; is_32col = 0; break; |
1084 | case MA_OPT3_HSCALE32: setting = ¤tConfig.hscale32; is_32col = 1; break; |
1085 | case MA_OPT3_FILTERING: |
960a8e27 |
1086 | case MA_OPT3_GAMMAA: |
1087 | case MA_OPT3_BLACKLVL: menu_opt3_preview(is_32col); break; |
1088 | case MA_OPT3_VSYNC: |
1089 | tmp = ((currentConfig.EmuOpt>>13)&1) | ((currentConfig.EmuOpt>>15)&2); |
4b8f4f3c |
1090 | tmp = (inp & BTN_LEFT) ? (tmp>>1) : ((tmp<<1)|1); |
1091 | if (tmp > 3) tmp = 3; |
1092 | currentConfig.EmuOpt &= ~0x12000; |
1093 | currentConfig.EmuOpt |= ((tmp&2)<<15) | ((tmp&1)<<13); |
1094 | break; |
6f748c47 |
1095 | default: break; |
1096 | } |
1097 | if (setting != NULL) { |
1098 | while ((inp = psp_pad_read(0)) & (BTN_LEFT|BTN_RIGHT)) { |
1099 | *setting += (inp & BTN_LEFT) ? -0.01 : 0.01; |
5ecedd0c |
1100 | if (*setting <= 0) *setting = 0.01; |
6f748c47 |
1101 | menu_opt3_preview(is_32col); |
1102 | draw_dispmenu_options(menu_sel); // will wait vsync |
1103 | } |
1104 | } |
1105 | } |
16e89bed |
1106 | if (inp & BTN_CIRCLE) { // toggleable options |
6f748c47 |
1107 | me_process(opt3_entries, OPT3_ENTRY_COUNT, selected_id, 1); |
1108 | switch (selected_id) { |
1109 | case MA_OPT3_DONE: |
1110 | return; |
1111 | case MA_OPT3_PRES_NOSCALE: |
1112 | currentConfig.scale = currentConfig.hscale40 = currentConfig.hscale32 = 1.0; |
1113 | menu_opt3_preview(is_32col); |
1114 | break; |
c6334564 |
1115 | case MA_OPT3_PRES_SCALE43: |
1116 | currentConfig.scale = 1.20; |
1117 | currentConfig.hscale40 = 1.00; |
1118 | currentConfig.hscale32 = 1.25; |
1119 | menu_opt3_preview(is_32col); |
1120 | break; |
6f748c47 |
1121 | case MA_OPT3_PRES_FULLSCR: |
1122 | currentConfig.scale = 1.20; |
1123 | currentConfig.hscale40 = 1.25; |
1124 | currentConfig.hscale32 = 1.56; |
1125 | menu_opt3_preview(is_32col); |
1126 | break; |
1127 | case MA_OPT3_FILTERING: |
1128 | menu_opt3_preview(is_32col); |
1129 | break; |
1130 | default: break; |
1131 | } |
1132 | } |
16e89bed |
1133 | if (inp & BTN_X) return; |
6f748c47 |
1134 | } |
1135 | } |
1136 | |
2951214e |
1137 | |
1138 | // --------- advanced options ---------- |
1139 | |
1140 | menu_entry opt2_entries[] = |
1141 | { |
960a8e27 |
1142 | { "Disable sprite limit", MB_ONOFF, MA_OPT2_NO_SPRITE_LIM, &PicoOpt, 0x40000, 0, 0, 1, 1 }, |
1143 | { "Emulate Z80", MB_ONOFF, MA_OPT2_ENABLE_Z80, &PicoOpt, 0x00004, 0, 0, 1, 1 }, |
1144 | { "Emulate YM2612 (FM)", MB_ONOFF, MA_OPT2_ENABLE_YM2612, &PicoOpt, 0x00001, 0, 0, 1, 1 }, |
1145 | { "Emulate SN76496 (PSG)", MB_ONOFF, MA_OPT2_ENABLE_SN76496, &PicoOpt, 0x00002, 0, 0, 1, 1 }, |
1146 | { "gzip savestates", MB_ONOFF, MA_OPT2_GZIP_STATES, ¤tConfig.EmuOpt, 0x00008, 0, 0, 1, 1 }, |
1147 | { "Don't save last used ROM", MB_ONOFF, MA_OPT2_NO_LAST_ROM, ¤tConfig.EmuOpt, 0x00020, 0, 0, 1, 1 }, |
1148 | { "Status line in main menu", MB_ONOFF, MA_OPT2_STATUS_LINE, ¤tConfig.EmuOpt, 0x20000, 0, 0, 1, 1 }, |
8a091e48 |
1149 | { "Disable frame limiter", MB_ONOFF, MA_OPT2_NO_FRAME_LIMIT, ¤tConfig.EmuOpt, 0x40000, 0, 0, 1, 1 }, |
960a8e27 |
1150 | { "done", MB_NONE, MA_OPT2_DONE, NULL, 0, 0, 0, 1, 0 }, |
2951214e |
1151 | }; |
1152 | |
1153 | #define OPT2_ENTRY_COUNT (sizeof(opt2_entries) / sizeof(opt2_entries[0])) |
960a8e27 |
1154 | const int opt2_entry_count = OPT2_ENTRY_COUNT; |
2951214e |
1155 | |
1156 | |
1157 | static void draw_amenu_options(int menu_sel) |
1158 | { |
1159 | int tl_x = 80+25, tl_y = 16+50; |
1160 | |
1161 | menu_draw_begin(); |
1162 | |
1163 | menu_draw_selection(tl_x - 16, tl_y + menu_sel*10, 252); |
1164 | |
1165 | me_draw(opt2_entries, OPT2_ENTRY_COUNT, tl_x, tl_y, NULL, NULL); |
1166 | |
1167 | menu_draw_end(); |
1168 | } |
1169 | |
1170 | static void amenu_loop_options(void) |
1171 | { |
1172 | static int menu_sel = 0; |
1173 | int menu_sel_max; |
1174 | unsigned long inp = 0; |
1175 | menu_id selected_id; |
1176 | |
1177 | menu_sel_max = me_count_enabled(opt2_entries, OPT2_ENTRY_COUNT) - 1; |
1178 | |
1179 | for(;;) |
1180 | { |
1181 | draw_amenu_options(menu_sel); |
16e89bed |
1182 | inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_LEFT|BTN_RIGHT|BTN_X|BTN_CIRCLE, 0); |
2951214e |
1183 | if (inp & BTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; } |
1184 | if (inp & BTN_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; } |
1185 | selected_id = me_index2id(opt2_entries, OPT2_ENTRY_COUNT, menu_sel); |
1186 | if (inp & (BTN_LEFT|BTN_RIGHT)) { // multi choise |
1187 | if (!me_process(opt2_entries, OPT2_ENTRY_COUNT, selected_id, (inp&BTN_RIGHT) ? 1 : 0) && |
1188 | selected_id == MA_OPT2_GAMMA) { |
6f748c47 |
1189 | // TODO? |
2951214e |
1190 | } |
1191 | } |
16e89bed |
1192 | if (inp & BTN_CIRCLE) { // toggleable options |
2951214e |
1193 | if (!me_process(opt2_entries, OPT2_ENTRY_COUNT, selected_id, 1) && |
1194 | selected_id == MA_OPT2_DONE) { |
1195 | return; |
1196 | } |
1197 | } |
16e89bed |
1198 | if (inp & BTN_X) return; |
2951214e |
1199 | } |
1200 | } |
1201 | |
1202 | // -------------- options -------------- |
1203 | |
1204 | |
1205 | menu_entry opt_entries[] = |
1206 | { |
960a8e27 |
1207 | { NULL, MB_NONE, MA_OPT_RENDERER, NULL, 0, 0, 0, 1, 1 }, |
8a091e48 |
1208 | { "Accurate sprites", MB_ONOFF, MA_OPT_ACC_SPRITES, &PicoOpt, 0x0080, 0, 0, 0, 1 }, |
960a8e27 |
1209 | { "Show FPS", MB_ONOFF, MA_OPT_SHOW_FPS, ¤tConfig.EmuOpt, 0x0002, 0, 0, 1, 1 }, |
1210 | { NULL, MB_RANGE, MA_OPT_FRAMESKIP, ¤tConfig.Frameskip, 0, -1, 16, 1, 1 }, |
1211 | { "Enable sound", MB_ONOFF, MA_OPT_ENABLE_SOUND, ¤tConfig.EmuOpt, 0x0004, 0, 0, 1, 1 }, |
1212 | { NULL, MB_NONE, MA_OPT_SOUND_QUALITY, NULL, 0, 0, 0, 1, 1 }, |
1213 | { "6 button pad", MB_ONOFF, MA_OPT_6BUTTON_PAD, &PicoOpt, 0x0020, 0, 0, 1, 1 }, |
1214 | { NULL, MB_NONE, MA_OPT_REGION, NULL, 0, 0, 0, 1, 1 }, |
1215 | { "Use SRAM/BRAM savestates", MB_ONOFF, MA_OPT_SRAM_STATES, ¤tConfig.EmuOpt, 0x0001, 0, 0, 1, 1 }, |
1216 | { NULL, MB_NONE, MA_OPT_CONFIRM_STATES,NULL, 0, 0, 0, 1, 1 }, |
1217 | { "Save slot", MB_RANGE, MA_OPT_SAVE_SLOT, &state_slot, 0, 0, 9, 1, 1 }, |
1218 | { NULL, MB_NONE, MA_OPT_CPU_CLOCKS, NULL, 0, 0, 0, 1, 1 }, |
1219 | { "[Display options]", MB_NONE, MA_OPT_DISP_OPTS, NULL, 0, 0, 0, 1, 0 }, |
1220 | { "[Sega/Mega CD options]", MB_NONE, MA_OPT_SCD_OPTS, NULL, 0, 0, 0, 1, 0 }, |
1221 | { "[Advanced options]", MB_NONE, MA_OPT_ADV_OPTS, NULL, 0, 0, 0, 1, 0 }, |
1222 | { NULL, MB_NONE, MA_OPT_SAVECFG, NULL, 0, 0, 0, 1, 0 }, |
1223 | { "Save cfg for current game only",MB_NONE,MA_OPT_SAVECFG_GAME,NULL, 0, 0, 0, 1, 0 }, |
1224 | { NULL, MB_NONE, MA_OPT_LOADCFG, NULL, 0, 0, 0, 1, 0 }, |
2951214e |
1225 | }; |
1226 | |
1227 | #define OPT_ENTRY_COUNT (sizeof(opt_entries) / sizeof(opt_entries[0])) |
960a8e27 |
1228 | const int opt_entry_count = OPT_ENTRY_COUNT; |
2951214e |
1229 | |
1230 | |
2951214e |
1231 | static void menu_opt_cust_draw(const menu_entry *entry, int x, int y, void *param) |
1232 | { |
1233 | char *str, str24[24]; |
1234 | |
1235 | switch (entry->id) |
1236 | { |
1237 | case MA_OPT_RENDERER: |
960a8e27 |
1238 | if (PicoOpt & 0x10) |
2aea862d |
1239 | str = "fast"; |
960a8e27 |
1240 | else if (currentConfig.EmuOpt & 0x80) |
2aea862d |
1241 | str = "accurate"; |
2951214e |
1242 | else |
2aea862d |
1243 | str = " 8bit accurate"; // n/a |
1244 | text_out16(x, y, "Renderer: %s", str); |
2951214e |
1245 | break; |
1246 | case MA_OPT_FRAMESKIP: |
1247 | if (currentConfig.Frameskip < 0) |
1248 | strcpy(str24, "Auto"); |
1249 | else sprintf(str24, "%i", currentConfig.Frameskip); |
1250 | text_out16(x, y, "Frameskip %s", str24); |
1251 | break; |
1252 | case MA_OPT_SOUND_QUALITY: |
960a8e27 |
1253 | str = (PicoOpt&0x08)?"stereo":"mono"; |
1254 | text_out16(x, y, "Sound Quality: %5iHz %s", PsndRate, str); |
2951214e |
1255 | break; |
1256 | case MA_OPT_REGION: |
0ae25549 |
1257 | text_out16(x, y, "Region: %s", me_region_name(PicoRegionOverride, PicoAutoRgnOrder)); |
2951214e |
1258 | break; |
1259 | case MA_OPT_CONFIRM_STATES: |
1260 | switch ((currentConfig.EmuOpt >> 9) & 5) { |
1261 | default: str = "OFF"; break; |
1262 | case 1: str = "writes"; break; |
1263 | case 4: str = "loads"; break; |
1264 | case 5: str = "both"; break; |
1265 | } |
1266 | text_out16(x, y, "Confirm savestate %s", str); |
1267 | break; |
2b90fc61 |
1268 | case MA_OPT_CPU_CLOCKS: |
1269 | text_out16(x, y, "CPU/bus clock %3i/%3iMHz", currentConfig.CPUclock, currentConfig.CPUclock/2); |
1270 | break; |
2951214e |
1271 | case MA_OPT_SAVECFG: |
1272 | str24[0] = 0; |
1273 | if (config_slot != 0) sprintf(str24, " (profile: %i)", config_slot); |
1274 | text_out16(x, y, "Save cfg as default%s", str24); |
1275 | break; |
1276 | case MA_OPT_LOADCFG: |
1277 | text_out16(x, y, "Load cfg from profile %i", config_slot); |
1278 | break; |
1279 | default: |
1280 | lprintf("%s: unimplemented (%i)\n", __FUNCTION__, entry->id); |
1281 | break; |
1282 | } |
1283 | } |
1284 | |
1285 | |
2951214e |
1286 | static void draw_menu_options(int menu_sel) |
1287 | { |
1288 | int tl_x = 80+25, tl_y = 16+24; |
1289 | |
1290 | menu_draw_begin(); |
1291 | |
1292 | menu_draw_selection(tl_x - 16, tl_y + menu_sel*10, 284); |
1293 | |
1294 | me_draw(opt_entries, OPT_ENTRY_COUNT, tl_x, tl_y, menu_opt_cust_draw, NULL); |
1295 | |
1296 | menu_draw_end(); |
1297 | } |
1298 | |
1299 | static int sndrate_prevnext(int rate, int dir) |
1300 | { |
1301 | int i, rates[] = { 11025, 22050, 44100 }; |
1302 | |
1303 | for (i = 0; i < 5; i++) |
1304 | if (rates[i] == rate) break; |
1305 | |
1306 | i += dir ? 1 : -1; |
1307 | if (i > 2) return dir ? 44100 : 22050; |
1308 | if (i < 0) return dir ? 22050 : 11025; |
1309 | return rates[i]; |
1310 | } |
1311 | |
1312 | static void region_prevnext(int right) |
1313 | { |
1314 | // jp_ntsc=1, jp_pal=2, usa=4, eu=8 |
1315 | static int rgn_orders[] = { 0x148, 0x184, 0x814, 0x418, 0x841, 0x481 }; |
1316 | int i; |
1317 | if (right) { |
0ae25549 |
1318 | if (!PicoRegionOverride) { |
2951214e |
1319 | for (i = 0; i < 6; i++) |
1320 | if (rgn_orders[i] == PicoAutoRgnOrder) break; |
1321 | if (i < 5) PicoAutoRgnOrder = rgn_orders[i+1]; |
0ae25549 |
1322 | else PicoRegionOverride=1; |
2951214e |
1323 | } |
0ae25549 |
1324 | else PicoRegionOverride<<=1; |
1325 | if (PicoRegionOverride > 8) PicoRegionOverride = 8; |
2951214e |
1326 | } else { |
0ae25549 |
1327 | if (!PicoRegionOverride) { |
2951214e |
1328 | for (i = 0; i < 6; i++) |
1329 | if (rgn_orders[i] == PicoAutoRgnOrder) break; |
1330 | if (i > 0) PicoAutoRgnOrder = rgn_orders[i-1]; |
1331 | } |
0ae25549 |
1332 | else PicoRegionOverride>>=1; |
2951214e |
1333 | } |
1334 | } |
1335 | |
1336 | static void menu_options_save(void) |
1337 | { |
426ecc58 |
1338 | if (PicoRegionOverride) { |
1339 | // force setting possibly changed.. |
1340 | Pico.m.pal = (PicoRegionOverride == 2 || PicoRegionOverride == 8) ? 1 : 0; |
1341 | } |
960a8e27 |
1342 | if (!(PicoOpt & POPT_6BTN_PAD)) { |
2951214e |
1343 | // unbind XYZ MODE, just in case |
1344 | unbind_action(0xf00); |
1345 | } |
1346 | } |
1347 | |
1348 | static int menu_loop_options(void) |
1349 | { |
1350 | static int menu_sel = 0; |
1351 | int menu_sel_max, ret; |
1352 | unsigned long inp = 0; |
1353 | menu_id selected_id; |
1354 | |
144a28a0 |
1355 | me_enable(opt_entries, OPT_ENTRY_COUNT, MA_OPT_SAVECFG_GAME, rom_loaded); |
2951214e |
1356 | me_enable(opt_entries, OPT_ENTRY_COUNT, MA_OPT_LOADCFG, config_slot != config_slot_current); |
1357 | menu_sel_max = me_count_enabled(opt_entries, OPT_ENTRY_COUNT) - 1; |
1358 | if (menu_sel > menu_sel_max) menu_sel = menu_sel_max; |
1359 | |
1360 | while (1) |
1361 | { |
1362 | draw_menu_options(menu_sel); |
16e89bed |
1363 | inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_LEFT|BTN_RIGHT|BTN_X|BTN_CIRCLE, 0); |
2951214e |
1364 | if (inp & BTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; } |
1365 | if (inp & BTN_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; } |
1366 | selected_id = me_index2id(opt_entries, OPT_ENTRY_COUNT, menu_sel); |
1367 | if (inp & (BTN_LEFT|BTN_RIGHT)) { // multi choise |
1368 | if (!me_process(opt_entries, OPT_ENTRY_COUNT, selected_id, (inp&BTN_RIGHT) ? 1 : 0)) { |
1369 | switch (selected_id) { |
1370 | case MA_OPT_RENDERER: |
960a8e27 |
1371 | if ((PicoOpt & 0x10) || !(currentConfig.EmuOpt & 0x80)) { |
1372 | PicoOpt &= ~0x10; |
2aea862d |
1373 | currentConfig.EmuOpt |= 0x80; |
2951214e |
1374 | } else { |
960a8e27 |
1375 | PicoOpt |= 0x10; |
2aea862d |
1376 | currentConfig.EmuOpt &= ~0x80; |
2951214e |
1377 | } |
1378 | break; |
1379 | case MA_OPT_SOUND_QUALITY: |
960a8e27 |
1380 | PsndRate = sndrate_prevnext(PsndRate, inp & BTN_RIGHT); |
2951214e |
1381 | break; |
1382 | case MA_OPT_REGION: |
1383 | region_prevnext(inp & BTN_RIGHT); |
1384 | break; |
1385 | case MA_OPT_CONFIRM_STATES: { |
1386 | int n = ((currentConfig.EmuOpt>>9)&1) | ((currentConfig.EmuOpt>>10)&2); |
1387 | n += (inp & BTN_LEFT) ? -1 : 1; |
1388 | if (n < 0) n = 0; else if (n > 3) n = 3; |
1389 | n |= n << 1; n &= ~2; |
1390 | currentConfig.EmuOpt &= ~0xa00; |
1391 | currentConfig.EmuOpt |= n << 9; |
1392 | break; |
1393 | } |
1394 | case MA_OPT_SAVE_SLOT: |
1395 | if (inp & BTN_RIGHT) { |
1396 | state_slot++; if (state_slot > 9) state_slot = 0; |
1397 | } else {state_slot--; if (state_slot < 0) state_slot = 9; |
1398 | } |
1399 | break; |
2b90fc61 |
1400 | case MA_OPT_CPU_CLOCKS: |
1401 | while ((inp = psp_pad_read(0)) & (BTN_LEFT|BTN_RIGHT)) { |
1402 | currentConfig.CPUclock += (inp & BTN_LEFT) ? -1 : 1; |
1403 | if (currentConfig.CPUclock < 19) currentConfig.CPUclock = 19; |
1404 | if (currentConfig.CPUclock > 333) currentConfig.CPUclock = 333; |
1405 | draw_menu_options(menu_sel); // will wait vsync |
1406 | } |
1407 | break; |
2951214e |
1408 | case MA_OPT_SAVECFG: |
1409 | case MA_OPT_SAVECFG_GAME: |
1410 | case MA_OPT_LOADCFG: |
1411 | config_slot += (inp&BTN_RIGHT) ? 1 : -1; |
1412 | if (config_slot > 9) config_slot = 0; |
1413 | if (config_slot < 0) config_slot = 9; |
1414 | me_enable(opt_entries, OPT_ENTRY_COUNT, MA_OPT_LOADCFG, config_slot != config_slot_current); |
1415 | menu_sel_max = me_count_enabled(opt_entries, OPT_ENTRY_COUNT) - 1; |
1416 | if (menu_sel > menu_sel_max) menu_sel = menu_sel_max; |
1417 | break; |
1418 | default: |
1419 | //lprintf("%s: something unknown selected (%i)\n", __FUNCTION__, selected_id); |
1420 | break; |
1421 | } |
1422 | } |
1423 | } |
16e89bed |
1424 | if (inp & BTN_CIRCLE) { |
2951214e |
1425 | if (!me_process(opt_entries, OPT_ENTRY_COUNT, selected_id, 1)) |
1426 | { |
1427 | switch (selected_id) |
1428 | { |
6f748c47 |
1429 | case MA_OPT_DISP_OPTS: |
1430 | dispmenu_loop_options(); |
1431 | break; |
2951214e |
1432 | case MA_OPT_SCD_OPTS: |
1433 | cd_menu_loop_options(); |
1434 | if (engineState == PGS_ReloadRom) |
1435 | return 0; // test BIOS |
1436 | break; |
1437 | case MA_OPT_ADV_OPTS: |
1438 | amenu_loop_options(); |
1439 | break; |
1440 | case MA_OPT_SAVECFG: // done (update and write) |
1441 | menu_options_save(); |
1442 | if (emu_WriteConfig(0)) strcpy(menuErrorMsg, "config saved"); |
1443 | else strcpy(menuErrorMsg, "failed to write config"); |
1444 | return 1; |
1445 | case MA_OPT_SAVECFG_GAME: // done (update and write for current game) |
1446 | menu_options_save(); |
1447 | if (emu_WriteConfig(1)) strcpy(menuErrorMsg, "config saved"); |
1448 | else strcpy(menuErrorMsg, "failed to write config"); |
1449 | return 1; |
1450 | case MA_OPT_LOADCFG: |
1451 | ret = emu_ReadConfig(1, 1); |
1452 | if (!ret) ret = emu_ReadConfig(0, 1); |
1453 | if (ret) strcpy(menuErrorMsg, "config loaded"); |
1454 | else strcpy(menuErrorMsg, "failed to load config"); |
1455 | return 1; |
1456 | default: |
1457 | //lprintf("%s: something unknown selected (%i)\n", __FUNCTION__, selected_id); |
1458 | break; |
1459 | } |
1460 | } |
1461 | } |
16e89bed |
1462 | if(inp & BTN_X) { |
2951214e |
1463 | menu_options_save(); |
1464 | return 0; // done (update, no write) |
1465 | } |
1466 | } |
1467 | } |
1468 | |
1469 | // -------------- credits -------------- |
1470 | |
1471 | static void draw_menu_credits(void) |
1472 | { |
1473 | int tl_x = 80+15, tl_y = 16+64, y; |
1474 | menu_draw_begin(); |
1475 | |
960a8e27 |
1476 | text_out16(tl_x, 16+20, "PicoDrive v" VERSION " (c) notaz, 2006-2008"); |
2951214e |
1477 | |
1478 | y = tl_y; |
1479 | text_out16(tl_x, y, "Credits:"); |
4b8f4f3c |
1480 | text_out16(tl_x, (y+=10), "fDave: base code of PicoDrive"); |
1481 | text_out16(tl_x, (y+=10), "Chui: Fame/C"); |
1482 | text_out16(tl_x, (y+=10), "NJ: CZ80"); |
2951214e |
1483 | text_out16(tl_x, (y+=10), "MAME devs: YM2612 and SN76496 cores"); |
4b8f4f3c |
1484 | text_out16(tl_x, (y+=10), "ps2dev.org people: PSP SDK/code"); |
2951214e |
1485 | text_out16(tl_x, (y+=10), "ketchupgun: skin design"); |
1486 | |
7a938d57 |
1487 | text_out16(tl_x, (y+=20), "special thanks (for docs, ideas):"); |
260f1bcc |
1488 | text_out16(tl_x, (y+=10), " Charles MacDonald, Haze,"); |
1489 | text_out16(tl_x, (y+=10), " Stephane Dallongeville,"); |
1490 | text_out16(tl_x, (y+=10), " Lordus, Exophase, Rokas,"); |
1491 | text_out16(tl_x, (y+=10), " Nemesis, Tasco Deluxe"); |
1492 | |
2951214e |
1493 | menu_draw_end(); |
1494 | } |
1495 | |
1496 | |
1497 | // -------------- root menu -------------- |
1498 | |
1499 | menu_entry main_entries[] = |
1500 | { |
1501 | { "Resume game", MB_NONE, MA_MAIN_RESUME_GAME, NULL, 0, 0, 0, 0 }, |
1502 | { "Save State", MB_NONE, MA_MAIN_SAVE_STATE, NULL, 0, 0, 0, 0 }, |
1503 | { "Load State", MB_NONE, MA_MAIN_LOAD_STATE, NULL, 0, 0, 0, 0 }, |
1504 | { "Reset game", MB_NONE, MA_MAIN_RESET_GAME, NULL, 0, 0, 0, 0 }, |
1505 | { "Load new ROM/ISO", MB_NONE, MA_MAIN_LOAD_ROM, NULL, 0, 0, 0, 1 }, |
1506 | { "Change options", MB_NONE, MA_MAIN_OPTIONS, NULL, 0, 0, 0, 1 }, |
1507 | { "Configure controls", MB_NONE, MA_MAIN_CONTROLS, NULL, 0, 0, 0, 1 }, |
1508 | { "Credits", MB_NONE, MA_MAIN_CREDITS, NULL, 0, 0, 0, 1 }, |
1509 | { "Patches / GameGenie",MB_NONE, MA_MAIN_PATCHES, NULL, 0, 0, 0, 0 }, |
1510 | { "Exit", MB_NONE, MA_MAIN_EXIT, NULL, 0, 0, 0, 1 } |
1511 | }; |
1512 | |
1513 | #define MAIN_ENTRY_COUNT (sizeof(main_entries) / sizeof(main_entries[0])) |
1514 | |
1515 | static void draw_menu_root(int menu_sel) |
1516 | { |
16e89bed |
1517 | const int tl_x = 86+70, tl_y = 16+70; |
1518 | char *stat = NULL; |
2951214e |
1519 | |
1520 | menu_draw_begin(); |
1521 | |
16e89bed |
1522 | if ((currentConfig.EmuOpt&0x20000) && (stat = psp_get_status_line())) |
1523 | text_out16(287, 12, "%s", stat); |
1524 | |
1525 | text_out16(tl_x, 48, "PicoDrive v" VERSION); |
2951214e |
1526 | |
1527 | menu_draw_selection(tl_x - 16, tl_y + menu_sel*10, 146); |
1528 | |
1529 | me_draw(main_entries, MAIN_ENTRY_COUNT, tl_x, tl_y, NULL, NULL); |
1530 | |
1531 | // error |
6f748c47 |
1532 | if (menuErrorMsg[0]) |
1533 | text_out16(10, 252, menuErrorMsg); |
2951214e |
1534 | menu_draw_end(); |
1535 | } |
1536 | |
1537 | |
1538 | static void menu_loop_root(void) |
1539 | { |
1540 | static int menu_sel = 0; |
1541 | int ret, menu_sel_max; |
1542 | unsigned long inp = 0; |
1543 | |
144a28a0 |
1544 | me_enable(main_entries, MAIN_ENTRY_COUNT, MA_MAIN_RESUME_GAME, rom_loaded); |
1545 | me_enable(main_entries, MAIN_ENTRY_COUNT, MA_MAIN_SAVE_STATE, rom_loaded); |
1546 | me_enable(main_entries, MAIN_ENTRY_COUNT, MA_MAIN_LOAD_STATE, rom_loaded); |
1547 | me_enable(main_entries, MAIN_ENTRY_COUNT, MA_MAIN_RESET_GAME, rom_loaded); |
2951214e |
1548 | me_enable(main_entries, MAIN_ENTRY_COUNT, MA_MAIN_PATCHES, PicoPatches != NULL); |
1549 | |
1550 | menu_sel_max = me_count_enabled(main_entries, MAIN_ENTRY_COUNT) - 1; |
1551 | if (menu_sel > menu_sel_max) menu_sel = menu_sel_max; |
1552 | |
a6df06b7 |
1553 | // mp3 errors? |
1554 | if (mp3_last_error != 0) { |
1555 | if (mp3_last_error == -1) |
1556 | sprintf(menuErrorMsg, "Unsupported mp3 format, use 44kHz stereo"); |
1557 | else sprintf(menuErrorMsg, "mp3 init failed, code %08x", mp3_last_error); |
1558 | mp3_last_error = 0; |
1559 | } |
1560 | |
2951214e |
1561 | /* make sure action buttons are not pressed on entering menu */ |
1562 | draw_menu_root(menu_sel); |
1563 | |
703e4c7b |
1564 | while (psp_pad_read(1) & (BTN_X|BTN_CIRCLE|BTN_SELECT)) psp_msleep(50); |
2951214e |
1565 | |
1566 | for (;;) |
1567 | { |
1568 | draw_menu_root(menu_sel); |
16e89bed |
1569 | inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_X|BTN_CIRCLE|BTN_SELECT|BTN_L|BTN_R, 0); |
2951214e |
1570 | if(inp & BTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; } |
1571 | if(inp & BTN_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; } |
1572 | if((inp & (BTN_L|BTN_R)) == (BTN_L|BTN_R)) debug_menu_loop(); |
16e89bed |
1573 | if( inp & (BTN_SELECT|BTN_X)) { |
144a28a0 |
1574 | if (rom_loaded) { |
16e89bed |
1575 | while (psp_pad_read(1) & (BTN_SELECT|BTN_X)) psp_msleep(50); // wait until released |
2951214e |
1576 | engineState = PGS_Running; |
1577 | break; |
1578 | } |
1579 | } |
16e89bed |
1580 | if(inp & BTN_CIRCLE) { |
a6df06b7 |
1581 | menuErrorMsg[0] = 0; // clear error msg |
2951214e |
1582 | switch (me_index2id(main_entries, MAIN_ENTRY_COUNT, menu_sel)) |
1583 | { |
1584 | case MA_MAIN_RESUME_GAME: |
144a28a0 |
1585 | if (rom_loaded) { |
16e89bed |
1586 | while (psp_pad_read(1) & BTN_CIRCLE) psp_msleep(50); |
2951214e |
1587 | engineState = PGS_Running; |
1588 | return; |
1589 | } |
1590 | break; |
1591 | case MA_MAIN_SAVE_STATE: |
144a28a0 |
1592 | if (rom_loaded) { |
2951214e |
1593 | if(savestate_menu_loop(0)) |
1594 | continue; |
1595 | engineState = PGS_Running; |
1596 | return; |
1597 | } |
1598 | break; |
1599 | case MA_MAIN_LOAD_STATE: |
144a28a0 |
1600 | if (rom_loaded) { |
2951214e |
1601 | if(savestate_menu_loop(1)) |
1602 | continue; |
446b090c |
1603 | while (psp_pad_read(1) & BTN_CIRCLE) psp_msleep(50); |
2951214e |
1604 | engineState = PGS_Running; |
1605 | return; |
1606 | } |
1607 | break; |
1608 | case MA_MAIN_RESET_GAME: |
144a28a0 |
1609 | if (rom_loaded) { |
2951214e |
1610 | emu_ResetGame(); |
446b090c |
1611 | while (psp_pad_read(1) & BTN_CIRCLE) psp_msleep(50); |
2951214e |
1612 | engineState = PGS_Running; |
1613 | return; |
1614 | } |
1615 | break; |
1616 | case MA_MAIN_LOAD_ROM: |
1617 | { |
1618 | char curr_path[PATH_MAX], *selfname; |
1619 | FILE *tstf; |
960a8e27 |
1620 | if ( (tstf = fopen(lastRomFile, "rb")) ) |
2951214e |
1621 | { |
1622 | fclose(tstf); |
960a8e27 |
1623 | strcpy(curr_path, lastRomFile); |
2951214e |
1624 | } |
1625 | else |
1626 | getcwd(curr_path, PATH_MAX); |
1627 | selfname = romsel_loop(curr_path); |
1628 | if (selfname) { |
1629 | lprintf("selected file: %s\n", selfname); |
1630 | engineState = PGS_ReloadRom; |
1631 | return; |
1632 | } |
1633 | break; |
1634 | } |
1635 | case MA_MAIN_OPTIONS: |
1636 | ret = menu_loop_options(); |
1637 | if (ret == 1) continue; // status update |
1638 | if (engineState == PGS_ReloadRom) |
1639 | return; // BIOS test |
1640 | break; |
1641 | case MA_MAIN_CONTROLS: |
1642 | kc_sel_loop(); |
1643 | break; |
1644 | case MA_MAIN_CREDITS: |
1645 | draw_menu_credits(); |
1646 | psp_msleep(500); |
16e89bed |
1647 | inp = 0; |
1648 | while (!(inp & (BTN_X|BTN_CIRCLE))) |
1649 | inp = wait_for_input(BTN_X|BTN_CIRCLE, 0); |
2951214e |
1650 | break; |
1651 | case MA_MAIN_EXIT: |
1652 | engineState = PGS_Quit; |
1653 | return; |
1654 | case MA_MAIN_PATCHES: |
144a28a0 |
1655 | if (rom_loaded && PicoPatches) { |
2951214e |
1656 | patches_menu_loop(); |
1657 | PicoPatchApply(); |
1658 | strcpy(menuErrorMsg, "Patches applied"); |
1659 | continue; |
1660 | } |
1661 | break; |
1662 | default: |
1663 | lprintf("%s: something unknown selected\n", __FUNCTION__); |
1664 | break; |
1665 | } |
1666 | } |
2951214e |
1667 | } |
1668 | } |
1669 | |
b8464531 |
1670 | void menu_darken_bg(void *dst, const void *src, int pixels, int darker) |
2951214e |
1671 | { |
1672 | unsigned int *dest = dst; |
1673 | const unsigned int *srce = src; |
1674 | pixels /= 2; |
1675 | if (darker) |
1676 | { |
1677 | while (pixels--) |
1678 | { |
1679 | unsigned int p = *srce++; |
1680 | *dest++ = ((p&0xf79ef79e)>>1) - ((p&0xc618c618)>>3); |
1681 | } |
1682 | } |
1683 | else |
1684 | { |
1685 | while (pixels--) |
1686 | { |
1687 | unsigned int p = *srce++; |
1688 | *dest++ = (p&0xf79ef79e)>>1; |
1689 | } |
1690 | } |
1691 | } |
1692 | |
a52e1f62 |
1693 | static void menu_prepare_bg(int use_game_bg, int use_fg) |
2951214e |
1694 | { |
2951214e |
1695 | if (use_game_bg) |
1696 | { |
1697 | // darken the active framebuffer |
6f748c47 |
1698 | unsigned short *dst = bg_buffer; |
a52e1f62 |
1699 | unsigned short *src = use_fg ? psp_video_get_active_fb() : psp_screen; |
6f748c47 |
1700 | int i; |
1701 | for (i = 272; i > 0; i--, dst += 480, src += 512) |
1702 | menu_darken_bg(dst, src, 480, 1); |
5ecedd0c |
1703 | //memset32_uncached((int *)(bg_buffer + 480*264), 0, 480*8*2/4); |
2951214e |
1704 | } |
1705 | else |
1706 | { |
1707 | // should really only happen once, on startup.. |
5ecedd0c |
1708 | memset32_uncached((int *)(void *)bg_buffer, 0, sizeof(bg_buffer)/4); |
2951214e |
1709 | readpng(bg_buffer, "skin/background.png", READPNG_BG); |
1710 | } |
6f748c47 |
1711 | sceKernelDcacheWritebackAll(); |
2951214e |
1712 | } |
1713 | |
1714 | static void menu_gfx_prepare(void) |
1715 | { |
144a28a0 |
1716 | menu_prepare_bg(rom_loaded, 1); |
2951214e |
1717 | |
1718 | menu_draw_begin(); |
1719 | menu_draw_end(); |
1720 | } |
1721 | |
1722 | |
1723 | void menu_loop(void) |
1724 | { |
1725 | menu_gfx_prepare(); |
1726 | |
1727 | menu_loop_root(); |
1728 | |
1729 | menuErrorMsg[0] = 0; |
1730 | } |
1731 | |
1732 | |
1733 | // --------- CD tray close menu ---------- |
1734 | |
1735 | static void draw_menu_tray(int menu_sel) |
1736 | { |
1737 | int tl_x = 70, tl_y = 90, y; |
1738 | |
1739 | menu_draw_begin(); |
1740 | |
1741 | text_out16(tl_x, 20, "The unit is about to"); |
1742 | text_out16(tl_x, 30, "close the CD tray."); |
1743 | |
1744 | y = tl_y; |
1745 | text_out16(tl_x, y, "Load new CD image"); |
1746 | text_out16(tl_x, (y+=10), "Insert nothing"); |
1747 | |
1748 | // draw cursor |
1749 | text_out16(tl_x - 16, tl_y + menu_sel*10, ">"); |
1750 | // error |
1751 | if (menuErrorMsg[0]) text_out16(5, 226, menuErrorMsg); |
1752 | menu_draw_end(); |
1753 | } |
1754 | |
1755 | |
1756 | int menu_loop_tray(void) |
1757 | { |
1758 | int menu_sel = 0, menu_sel_max = 1; |
1759 | unsigned long inp = 0; |
1760 | char curr_path[PATH_MAX], *selfname; |
1761 | FILE *tstf; |
1762 | |
1763 | menu_gfx_prepare(); |
1764 | |
960a8e27 |
1765 | if ( (tstf = fopen(lastRomFile, "rb")) ) |
2951214e |
1766 | { |
1767 | fclose(tstf); |
960a8e27 |
1768 | strcpy(curr_path, lastRomFile); |
2951214e |
1769 | } |
1770 | else |
1771 | { |
1772 | getcwd(curr_path, PATH_MAX); |
1773 | } |
1774 | |
1775 | /* make sure action buttons are not pressed on entering menu */ |
1776 | draw_menu_tray(menu_sel); |
16e89bed |
1777 | while (psp_pad_read(1) & BTN_CIRCLE) psp_msleep(50); |
2951214e |
1778 | |
1779 | for (;;) |
1780 | { |
1781 | draw_menu_tray(menu_sel); |
5ecedd0c |
1782 | inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_CIRCLE, 0); |
2951214e |
1783 | if(inp & BTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; } |
1784 | if(inp & BTN_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; } |
16e89bed |
1785 | if(inp & BTN_CIRCLE) { |
2951214e |
1786 | switch (menu_sel) { |
1787 | case 0: // select image |
1788 | selfname = romsel_loop(curr_path); |
1789 | if (selfname) { |
1ceda417 |
1790 | int ret = -1; |
1791 | cd_img_type cd_type; |
2951214e |
1792 | cd_type = emu_cdCheck(NULL); |
1ceda417 |
1793 | if (cd_type != CIT_NOT_CD) |
1794 | ret = Insert_CD(romFileName, cd_type); |
2951214e |
1795 | if (ret != 0) { |
1796 | sprintf(menuErrorMsg, "Load failed, invalid CD image?"); |
1797 | lprintf("%s\n", menuErrorMsg); |
1798 | continue; |
1799 | } |
1800 | engineState = PGS_RestartRun; |
1801 | return 1; |
1802 | } |
1803 | break; |
1804 | case 1: // insert nothing |
1805 | engineState = PGS_RestartRun; |
1806 | return 0; |
1807 | } |
1808 | } |
1809 | menuErrorMsg[0] = 0; // clear error msg |
1810 | } |
1811 | } |
1812 | |
1813 | |