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