1 // (c) Copyright 2006,2007 notaz, All rights reserved.
\r
2 // Free for non-commercial use.
\r
4 // For commercial use, separate licencing terms must be obtained.
\r
6 // don't like to use loads of #ifdefs, so duplicating GP2X code
\r
13 #include <unistd.h> // for getcwd cegcc implementation
\r
14 #include <dirent.h> // for opendir
\r
15 #include <windows.h>
\r
17 #include "kgsdk/Framework.h"
\r
18 #include "kgsdk/Framework2D.h"
\r
23 #include "../common/arm_utils.h"
\r
24 #include "../common/menu.h"
\r
25 #include "../common/emu.h"
\r
26 #include "../common/readpng.h"
\r
27 #include "../common/input.h"
\r
28 #include "version.h"
\r
30 #include <pico/pico_int.h>
\r
31 #include <pico/patch.h>
\r
32 #include <zlib/zlib.h>
\r
35 #define gizKeyUnkn "???"
\r
36 const char * const keyNames[] = {
\r
37 "LEFT", "RIGHT", "UP", "DOWN", "STOP", "PLAY", "FORWARD", "REWIND",
\r
38 "L", "R", "HOME", "VOLUME", "BRIGHTNESS", "ALARM", "POWER", gizKeyUnkn,
\r
39 gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn,
\r
40 gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn
\r
43 static unsigned char *bg_buffer = gfx_buffer + 321*240*2;
\r
44 unsigned char *menu_screen = gfx_buffer; /* draw here and blit later, to avoid flicker */
\r
46 void menu_darken_bg(void *dst, const void *src, int pixels, int darker);
\r
47 static void menu_prepare_bg(int use_game_bg);
\r
49 static unsigned int inp_prev = 0;
\r
51 void menu_draw_begin(int use_bgbuff)
\r
54 memcpy32((int *)menu_screen, (int *)bg_buffer, 321*240*2/4);
\r
58 void menu_draw_end(void)
\r
60 giz_screen = fb_lock(0);
\r
61 if (giz_screen == NULL)
\r
63 lprintf("%s: Framework2D_LockBuffer() returned NULL\n", __FUNCTION__);
\r
66 memcpy32(giz_screen, (int *)menu_screen, 321*240*2/4);
\r
73 // --------- loading ROM screen ----------
\r
75 static void load_progress_cb(int percent)
\r
77 int ln, len = percent * 320 / 100;
\r
78 unsigned short *dst;
\r
81 dst = (unsigned short *)menu_screen + 321*20;
\r
83 if (len > 320) len = 320;
\r
84 for (ln = 10; ln > 0; ln--, dst += 321)
\r
85 memset(dst, 0xff, len*2);
\r
89 void menu_romload_prepare(const char *rom_name)
\r
91 const char *p = rom_name + strlen(rom_name);
\r
92 while (p > rom_name && *p != '/') p--;
\r
95 memset(menu_screen, 0, 321*240*2);
\r
98 smalltext_out16(1, 1, "Loading", 0xffff);
\r
99 smalltext_out16_lim(1, 10, p, 0xffff, 53);
\r
101 PicoCartLoadProgressCB = load_progress_cb;
\r
104 void menu_romload_end(void)
\r
106 PicoCartLoadProgressCB = NULL;
\r
107 menu_draw_begin(0);
\r
108 smalltext_out16(1, 30, "Starting emulation...", 0xffff);
\r
112 // -------------- ROM selector --------------
\r
119 unsigned char d_type;
\r
123 // rrrr rggg gggb bbbb
\r
125 static unsigned short file2color(const char *fname)
\r
127 const char *ext = fname + strlen(fname) - 3;
\r
128 static const char *rom_exts[] = { "zip", "bin", "smd", "gen", "iso", "cso" };
\r
129 static const char *other_exts[] = { "gmv", "pat" };
\r
132 if (ext < fname) ext = fname;
\r
133 for (i = 0; i < sizeof(rom_exts)/sizeof(rom_exts[0]); i++)
\r
134 if (strcasecmp(ext, rom_exts[i]) == 0) return 0xbdff;
\r
135 for (i = 0; i < sizeof(other_exts)/sizeof(other_exts[0]); i++)
\r
136 if (strcasecmp(ext, other_exts[i]) == 0) return 0xaff5;
\r
140 static void draw_dirlist(char *curdir, struct my_dirent **namelist, int n, int sel)
\r
145 n--; // exclude current dir (".")
\r
147 menu_draw_begin(1);
\r
150 menu_darken_bg(menu_screen, menu_screen, 321*240, 0);
\r
153 menu_darken_bg((char *)menu_screen + 321*120*2, (char *)menu_screen + 321*120*2, 321*8, 0);
\r
156 smalltext_out16_lim(14, (start - 2)*10, curdir, 0xffff, 53-2);
\r
157 for (i = 0; i < n; i++) {
\r
159 if (pos < 0) continue;
\r
160 if (pos > 23) break;
\r
161 if (namelist[i+1]->d_type == DT_DIR) {
\r
162 smalltext_out16_lim(14, pos*10, "/", 0xfff6, 1);
\r
163 smalltext_out16_lim(14+6, pos*10, namelist[i+1]->d_name, 0xfff6, 53-3);
\r
165 unsigned short color = file2color(namelist[i+1]->d_name);
\r
166 smalltext_out16_lim(14, pos*10, namelist[i+1]->d_name, color, 53-2);
\r
169 text_out16(5, 120, ">");
\r
173 static int scandir_cmp(const void *p1, const void *p2)
\r
175 struct my_dirent **d1 = (struct my_dirent **)p1, **d2 = (struct my_dirent **)p2;
\r
176 if ((*d1)->d_type == (*d2)->d_type) return strcasecmp((*d1)->d_name, (*d2)->d_name);
\r
177 if ((*d1)->d_type == DT_DIR) return -1; // put before
\r
178 if ((*d2)->d_type == DT_DIR) return 1;
\r
179 return strcasecmp((*d1)->d_name, (*d2)->d_name);
\r
182 static char *filter_exts[] = {
\r
183 ".mp3", ".srm", ".brm", "s.gz", ".mds", "bcfg", ".txt", ".htm", "html",
\r
184 ".jpg", ".cue", ".exe", ".dll"
\r
187 static int scandir_filter(const struct my_dirent *ent)
\r
192 if (ent == NULL || ent->d_name == NULL) return 0;
\r
193 if (strlen(ent->d_name) < 5) return 1;
\r
195 p = ent->d_name + strlen(ent->d_name) - 4;
\r
197 for (i = 0; i < sizeof(filter_exts)/sizeof(filter_exts[0]); i++)
\r
199 if (strcasecmp(p, filter_exts[i]) == 0) return 0;
\r
205 static int cstr2wstr(wchar_t *dst, const char *src)
\r
208 for (i = len = strlen(src); i >= 0; i--)
\r
213 static void wstr2cstr(char *dst, const wchar_t *src)
\r
216 for (i = wcslen(src); i >= 0; i--)
\r
220 static int my_scandir(const char *dir, struct my_dirent ***namelist_out,
\r
221 int(*filter)(const struct my_dirent *),
\r
222 int(*compar)(const void *, const void *))
\r
225 int i, len, ret = -1, name_alloc = 4, name_count = 0;
\r
226 struct my_dirent **namelist = NULL, *ent;
\r
227 WIN32_FIND_DATA finddata;
\r
228 HANDLE fh = INVALID_HANDLE_VALUE;
\r
231 wdir = malloc(sizeof(wdir[0]) * MAX_PATH);
\r
232 if (wdir == NULL) { lprintf("%s:%i: OOM\n", __FILE__, __LINE__); goto fail; }
\r
234 namelist = malloc(sizeof(*namelist) * name_alloc);
\r
235 if (namelist == NULL) { lprintf("%s:%i: OOM\n", __FILE__, __LINE__); goto fail; }
\r
237 // try to read first..
\r
238 len = cstr2wstr(wdir, dir);
\r
239 for (i = 0; i < len; i++)
\r
240 if (wdir[i] == '/') wdir[i] = '\\';
\r
241 if (wdir[len-1] != '\\') wdir[len++] = '\\';
\r
244 /*if (wdir[len-1] == '\\') wdir[len-1] = 0;*/
\r
247 fh = FindFirstFile(wdir, &finddata);
\r
248 if (fh == INVALID_HANDLE_VALUE)
\r
250 if (GetLastError() != ERROR_NO_MORE_FILES)
\r
252 lprintf("FindFirstFile(\"%s\") failed with %lu\n", dir, GetLastError());
\r
258 // add "." and ".."
\r
259 ent = malloc(sizeof(*ent) + 3);
\r
260 ent->d_type = DT_DIR; strcpy(ent->d_name, ".");
\r
261 namelist[name_count++] = ent;
\r
262 ent = malloc(sizeof(*ent) + 3);
\r
263 ent->d_type = DT_DIR; strcpy(ent->d_name, "..");
\r
264 namelist[name_count++] = ent;
\r
268 ent = malloc(sizeof(*ent) + wcslen(finddata.cFileName) + 1);
\r
269 ent->d_type = (finddata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? DT_DIR : DT_REG;
\r
270 wstr2cstr(ent->d_name, finddata.cFileName);
\r
271 if (filter == NULL || filter(ent))
\r
272 namelist[name_count++] = ent;
\r
275 if (name_count >= name_alloc)
\r
279 tmp = realloc(namelist, sizeof(*namelist) * name_alloc);
\r
280 if (tmp == NULL) { lprintf("%s:%i: OOM\n", __FILE__, __LINE__); goto fail; }
\r
284 bRet = FindNextFile(fh, &finddata);
\r
288 if (compar != NULL && name_count > 3) qsort(&namelist[2], name_count - 2, sizeof(namelist[0]), compar);
\r
292 *namelist_out = namelist;
\r
296 if (namelist != NULL)
\r
298 while (name_count--)
\r
299 free(namelist[name_count]);
\r
303 if (fh != INVALID_HANDLE_VALUE) FindClose(fh);
\r
304 if (wdir != NULL) free(wdir);
\r
309 static char *romsel_loop(char *curr_path)
\r
311 struct my_dirent **namelist;
\r
314 unsigned long inp = 0;
\r
315 char *ret = NULL, *fname = NULL;
\r
317 // is this a dir or a full path?
\r
318 if ((dir = opendir(curr_path))) {
\r
322 for (p = curr_path + strlen(curr_path) - 1; p > curr_path && *p != '/'; p--);
\r
327 n = my_scandir(curr_path, &namelist, scandir_filter, scandir_cmp);
\r
330 n = my_scandir("/", &namelist, scandir_filter, scandir_cmp);
\r
333 lprintf("scandir failed, dir: "); lprintf(curr_path); lprintf("\n");
\r
339 if (fname != NULL) {
\r
341 for (i = 1; i < n; i++) {
\r
342 if (strcmp(namelist[i]->d_name, fname) == 0) {
\r
351 draw_dirlist(curr_path, namelist, n, sel);
\r
352 inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|PBTN_L|PBTN_R|PBTN_PLAY|PBTN_STOP);
\r
353 if(inp & PBTN_UP ) { sel--; if (sel < 0) sel = n-2; }
\r
354 if(inp & PBTN_DOWN) { sel++; if (sel > n-2) sel = 0; }
\r
355 if(inp & PBTN_LEFT) { sel-=10; if (sel < 0) sel = 0; }
\r
356 if(inp & PBTN_L) { sel-=24; if (sel < 0) sel = 0; }
\r
357 if(inp & PBTN_RIGHT) { sel+=10; if (sel > n-2) sel = n-2; }
\r
358 if(inp & PBTN_R) { sel+=24; if (sel > n-2) sel = n-2; }
\r
359 if(inp & PBTN_PLAY) { // enter dir/select
\r
360 if (namelist[sel+1]->d_type == DT_REG) {
\r
361 strcpy(romFileName, curr_path);
\r
362 strcat(romFileName, "/");
\r
363 strcat(romFileName, namelist[sel+1]->d_name);
\r
366 } else if (namelist[sel+1]->d_type == DT_DIR) {
\r
367 int newlen = strlen(curr_path) + strlen(namelist[sel+1]->d_name) + 2;
\r
368 char *p, *newdir = malloc(newlen);
\r
369 if (strcmp(namelist[sel+1]->d_name, "..") == 0) {
\r
370 char *start = curr_path;
\r
371 p = start + strlen(start) - 1;
\r
372 while (*p == '/' && p > start) p--;
\r
373 while (*p != '/' && p > start) p--;
\r
374 if (p <= start) strcpy(newdir, "/");
\r
375 else { strncpy(newdir, start, p-start); newdir[p-start] = 0; }
\r
377 strcpy(newdir, curr_path);
\r
378 p = newdir + strlen(newdir) - 1;
\r
379 while (*p == '/' && p >= newdir) *p-- = 0;
\r
380 strcat(newdir, "/");
\r
381 strcat(newdir, namelist[sel+1]->d_name);
\r
383 ret = romsel_loop(newdir);
\r
388 if(inp & PBTN_STOP) break; // cancel
\r
392 while(n--) free(namelist[n]);
\r
399 static char *romsel_loop(char *curr_path)
\r
405 // ------------ patch/gg menu ------------
\r
407 static void draw_patchlist(int sel)
\r
409 int start, i, pos, active;
\r
413 menu_draw_begin(1);
\r
415 for (i = 0; i < PicoPatchCount; i++) {
\r
417 if (pos < 0) continue;
\r
418 if (pos > 23) break;
\r
419 active = PicoPatches[i].active;
\r
420 smalltext_out16_lim(14, pos*10, active ? "ON " : "OFF", active ? 0xfff6 : 0xffff, 3);
\r
421 smalltext_out16_lim(14+6*4, pos*10, PicoPatches[i].name, active ? 0xfff6 : 0xffff, 53-6);
\r
424 if (pos < 24) smalltext_out16_lim(14, pos*10, "done", 0xffff, 4);
\r
426 text_out16(5, 120, ">");
\r
431 static void patches_menu_loop(void)
\r
434 unsigned long inp = 0;
\r
438 draw_patchlist(menu_sel);
\r
439 inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|PBTN_L|PBTN_R|PBTN_PLAY|PBTN_STOP);
\r
440 if(inp & PBTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = PicoPatchCount; }
\r
441 if(inp & PBTN_DOWN) { menu_sel++; if (menu_sel > PicoPatchCount) menu_sel = 0; }
\r
442 if(inp &(PBTN_LEFT|PBTN_L)) { menu_sel-=10; if (menu_sel < 0) menu_sel = 0; }
\r
443 if(inp &(PBTN_RIGHT|PBTN_R)) { menu_sel+=10; if (menu_sel > PicoPatchCount) menu_sel = PicoPatchCount; }
\r
444 if(inp & PBTN_PLAY) { // action
\r
445 if (menu_sel < PicoPatchCount)
\r
446 PicoPatches[menu_sel].active = !PicoPatches[menu_sel].active;
\r
449 if(inp & PBTN_STOP) return;
\r
454 // ------------ savestate loader ------------
\r
456 static int state_slot_flags = 0;
\r
458 static void state_check_slots(void)
\r
462 state_slot_flags = 0;
\r
464 for (slot = 0; slot < 10; slot++)
\r
466 if (emu_checkSaveFile(slot))
\r
468 state_slot_flags |= 1 << slot;
\r
473 static void draw_savestate_bg(int slot)
\r
475 struct PicoVideo tmp_pv;
\r
476 unsigned short tmp_cram[0x40];
\r
477 unsigned short tmp_vsram[0x40];
\r
478 void *tmp_vram, *file;
\r
481 fname = emu_GetSaveFName(1, 0, slot);
\r
482 if (!fname) return;
\r
484 tmp_vram = malloc(sizeof(Pico.vram));
\r
485 if (tmp_vram == NULL) return;
\r
487 memcpy(tmp_vram, Pico.vram, sizeof(Pico.vram));
\r
488 memcpy(tmp_cram, Pico.cram, sizeof(Pico.cram));
\r
489 memcpy(tmp_vsram, Pico.vsram, sizeof(Pico.vsram));
\r
490 memcpy(&tmp_pv, &Pico.video, sizeof(Pico.video));
\r
492 if (strcmp(fname + strlen(fname) - 3, ".gz") == 0) {
\r
493 file = gzopen(fname, "rb");
\r
494 emu_setSaveStateCbs(1);
\r
496 file = fopen(fname, "rb");
\r
497 emu_setSaveStateCbs(0);
\r
502 PicoCdLoadStateGfx(file);
\r
504 areaSeek(file, 0x10020, SEEK_SET); // skip header and RAM in state file
\r
505 areaRead(Pico.vram, 1, sizeof(Pico.vram), file);
\r
506 areaSeek(file, 0x2000, SEEK_CUR);
\r
507 areaRead(Pico.cram, 1, sizeof(Pico.cram), file);
\r
508 areaRead(Pico.vsram, 1, sizeof(Pico.vsram), file);
\r
509 areaSeek(file, 0x221a0, SEEK_SET);
\r
510 areaRead(&Pico.video, 1, sizeof(Pico.video), file);
\r
515 emu_forcedFrame(POPT_EN_SOFTSCALE);
\r
516 menu_prepare_bg(1);
\r
518 memcpy(Pico.vram, tmp_vram, sizeof(Pico.vram));
\r
519 memcpy(Pico.cram, tmp_cram, sizeof(Pico.cram));
\r
520 memcpy(Pico.vsram, tmp_vsram, sizeof(Pico.vsram));
\r
521 memcpy(&Pico.video, &tmp_pv, sizeof(Pico.video));
\r
525 static void draw_savestate_menu(int menu_sel, int is_loading)
\r
527 int tl_x = 25, tl_y = 60, y, i;
\r
529 if (state_slot_flags & (1 << menu_sel))
\r
530 draw_savestate_bg(menu_sel);
\r
531 menu_draw_begin(1);
\r
533 text_out16(tl_x, 30, is_loading ? "Load state" : "Save state");
\r
535 menu_draw_selection(tl_x - 16, tl_y + menu_sel*10, 108);
\r
537 /* draw all 10 slots */
\r
539 for (i = 0; i < 10; i++, y+=10)
\r
541 text_out16(tl_x, y, "SLOT %i (%s)", i, (state_slot_flags & (1 << i)) ? "USED" : "free");
\r
543 text_out16(tl_x, y, "back");
\r
548 static int savestate_menu_loop(int is_loading)
\r
550 static int menu_sel = 10;
\r
551 int menu_sel_max = 10;
\r
552 unsigned long inp = 0;
\r
554 state_check_slots();
\r
558 draw_savestate_menu(menu_sel, is_loading);
\r
559 inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_PLAY|PBTN_STOP);
\r
560 if(inp & PBTN_UP ) {
\r
562 menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max;
\r
563 } while (!(state_slot_flags & (1 << menu_sel)) && menu_sel != menu_sel_max && is_loading);
\r
565 if(inp & PBTN_DOWN) {
\r
567 menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0;
\r
568 } while (!(state_slot_flags & (1 << menu_sel)) && menu_sel != menu_sel_max && is_loading);
\r
570 if(inp & PBTN_PLAY) { // save/load
\r
571 if (menu_sel < 10) {
\r
572 state_slot = menu_sel;
\r
573 PicoStateProgressCB = emu_stateCb; /* also suitable for menu */
\r
574 if (emu_SaveLoadGame(is_loading, 0)) {
\r
575 strcpy(menuErrorMsg, is_loading ? "Load failed" : "Save failed");
\r
581 if(inp & PBTN_STOP) return 1;
\r
585 // -------------- key config --------------
\r
587 static char *action_binds(int player_idx, int action_mask)
\r
589 static char strkeys[32*5];
\r
593 for (i = 0; i < 32; i++) // i is key index
\r
595 if (currentConfig.KeyBinds[i] & action_mask)
\r
597 if (player_idx >= 0 && ((currentConfig.KeyBinds[i] >> 16) & 3) != player_idx) continue;
\r
598 if (strkeys[0]) { strcat(strkeys, " + "); strcat(strkeys, keyNames[i]); break; }
\r
599 else strcpy(strkeys, keyNames[i]);
\r
606 static void unbind_action(int action)
\r
610 for (i = 0; i < 32; i++)
\r
611 currentConfig.KeyBinds[i] &= ~action;
\r
614 static int count_bound_keys(int action, int pl_idx)
\r
618 for (i = 0; i < 32; i++)
\r
620 if (pl_idx >= 0 && (currentConfig.KeyBinds[i]&0x30000) != (pl_idx<<16)) continue;
\r
621 if (currentConfig.KeyBinds[i] & action) keys++;
\r
627 static void draw_key_config(const me_bind_action *opts, int opt_cnt, int player_idx, int sel)
\r
629 int x, y, tl_y = 30, i;
\r
631 menu_draw_begin(1);
\r
632 if (player_idx >= 0) {
\r
633 text_out16(80, 10, "Player %i controls", player_idx + 1);
\r
636 text_out16(80, 10, "Emulator controls");
\r
640 menu_draw_selection(x - 16, tl_y + sel*10, (player_idx >= 0) ? 66 : 130);
\r
643 for (i = 0; i < opt_cnt; i++, y+=10)
\r
644 text_out16(x, y, "%s : %s", opts[i].name, action_binds(player_idx, opts[i].mask));
\r
646 text_out16(x, y, "Done");
\r
648 if (sel < opt_cnt) {
\r
649 text_out16(30, 195, "Press a button to bind/unbind");
\r
650 text_out16(30, 205, "Use HOME to clear");
\r
651 text_out16(30, 215, "To bind UP/DOWN, hold HOME");
\r
652 text_out16(30, 225, "Select \"Done\" to exit");
\r
654 text_out16(30, 205, "Use Options -> Save cfg");
\r
655 text_out16(30, 215, "to save controls");
\r
656 text_out16(30, 225, "Press PLAY or STOP to exit");
\r
661 static void key_config_loop(const me_bind_action *opts, int opt_cnt, int player_idx)
\r
663 int sel = 0, menu_sel_max = opt_cnt, prev_select = 0, i;
\r
664 unsigned long inp = 0;
\r
668 draw_key_config(opts, opt_cnt, player_idx, sel);
\r
669 inp = in_menu_wait(CONFIGURABLE_KEYS|PBTN_HOME);
\r
670 if (!(inp & PBTN_HOME)) {
\r
672 if(inp & PBTN_UP ) { sel--; if (sel < 0) sel = menu_sel_max; continue; }
\r
673 if(inp & PBTN_DOWN) { sel++; if (sel > menu_sel_max) sel = 0; continue; }
\r
675 if (sel >= opt_cnt) {
\r
676 if (inp & (PBTN_PLAY|PBTN_STOP)) break;
\r
679 // if we are here, we want to bind/unbind something
\r
680 if ((inp & PBTN_HOME) && !prev_select)
\r
681 unbind_action(opts[sel].mask);
\r
682 prev_select = inp & PBTN_HOME;
\r
683 inp &= CONFIGURABLE_KEYS;
\r
685 for (i = 0; i < 32; i++)
\r
686 if (inp & (1 << i)) {
\r
687 if (count_bound_keys(opts[sel].mask, player_idx) >= 2)
\r
688 currentConfig.KeyBinds[i] &= ~opts[sel].mask; // allow to unbind only
\r
689 else currentConfig.KeyBinds[i] ^= opts[sel].mask;
\r
690 if (player_idx >= 0 && (currentConfig.KeyBinds[i] & opts[sel].mask)) {
\r
691 currentConfig.KeyBinds[i] &= ~(3 << 16);
\r
692 currentConfig.KeyBinds[i] |= player_idx << 16;
\r
698 menu_entry ctrlopt_entries[] =
\r
700 { "Player 1", MB_NONE, MA_CTRL_PLAYER1, NULL, 0, 0, 0, 1, 0 },
\r
701 { "Player 2", MB_NONE, MA_CTRL_PLAYER2, NULL, 0, 0, 0, 1, 0 },
\r
702 { "Emulator controls", MB_NONE, MA_CTRL_EMU, NULL, 0, 0, 0, 1, 0 },
\r
703 { "6 button pad", MB_ONOFF, MA_OPT_6BUTTON_PAD, &PicoOpt, 0x020, 0, 0, 1, 1 },
\r
704 { "Turbo rate", MB_RANGE, MA_CTRL_TURBO_RATE, ¤tConfig.turbo_rate, 0, 1, 30, 1, 1 },
\r
705 { "Done", MB_NONE, MA_CTRL_DONE, NULL, 0, 0, 0, 1, 0 },
\r
708 #define CTRLOPT_ENTRY_COUNT (sizeof(ctrlopt_entries) / sizeof(ctrlopt_entries[0]))
\r
709 const int ctrlopt_entry_count = CTRLOPT_ENTRY_COUNT;
\r
711 static void draw_kc_sel(int menu_sel)
\r
713 int tl_x = 25+40, tl_y = 60, y;
\r
716 menu_draw_begin(1);
\r
717 menu_draw_selection(tl_x - 16, tl_y + menu_sel*10, 138);
\r
719 me_draw(ctrlopt_entries, ctrlopt_entry_count, tl_x, tl_y, NULL, NULL);
\r
725 // player2_flag, ?, ?, ?, ?, ?, ?, menu
\r
726 // "NEXT SAVE SLOT", "PREV SAVE SLOT", "SWITCH RENDERER", "SAVE STATE",
\r
727 // "LOAD STATE", "VOLUME UP", "VOLUME DOWN", "DONE"
\r
728 me_bind_action emuctrl_actions[] =
\r
730 { "Load State ", 1<<28 },
\r
731 { "Save State ", 1<<27 },
\r
732 { "Prev Save Slot ", 1<<25 },
\r
733 { "Next Save Slot ", 1<<24 },
\r
734 { "Switch Renderer", 1<<26 },
\r
735 { "Volume Down ", 1<<30 },
\r
736 { "Volume Up ", 1<<29 },
\r
740 static void kc_sel_loop(void)
\r
742 int menu_sel = 5, menu_sel_max = 5;
\r
743 unsigned long inp = 0;
\r
744 menu_id selected_id;
\r
748 draw_kc_sel(menu_sel);
\r
749 inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_PLAY|PBTN_STOP);
\r
750 selected_id = me_index2id(ctrlopt_entries, CTRLOPT_ENTRY_COUNT, menu_sel);
\r
751 if (inp & (PBTN_LEFT|PBTN_RIGHT)) // multi choise
\r
752 me_process(ctrlopt_entries, CTRLOPT_ENTRY_COUNT, selected_id, (inp&PBTN_RIGHT) ? 1 : 0);
\r
753 if (inp & PBTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }
\r
754 if (inp & PBTN_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }
\r
755 if (inp & PBTN_PLAY) {
\r
756 int is_6button = PicoOpt & 0x020;
\r
757 switch (selected_id) {
\r
758 case MA_CTRL_PLAYER1: key_config_loop(me_ctrl_actions, is_6button ? 15 : 11, 0); return;
\r
759 case MA_CTRL_PLAYER2: key_config_loop(me_ctrl_actions, is_6button ? 15 : 11, 1); return;
\r
760 case MA_CTRL_EMU: key_config_loop(emuctrl_actions,
\r
761 sizeof(emuctrl_actions)/sizeof(emuctrl_actions[0]) - 1, -1); return;
\r
762 case MA_CTRL_DONE: if (!rom_loaded) emu_WriteConfig(0); return;
\r
766 if (inp & PBTN_STOP) return;
\r
771 // --------- sega/mega cd options ----------
\r
773 menu_entry cdopt_entries[] =
\r
775 { NULL, MB_NONE, MA_CDOPT_TESTBIOS_USA, NULL, 0, 0, 0, 1, 0 },
\r
776 { NULL, MB_NONE, MA_CDOPT_TESTBIOS_EUR, NULL, 0, 0, 0, 1, 0 },
\r
777 { NULL, MB_NONE, MA_CDOPT_TESTBIOS_JAP, NULL, 0, 0, 0, 1, 0 },
\r
778 { "CD LEDs", MB_ONOFF, MA_CDOPT_LEDS, ¤tConfig.EmuOpt, 0x0400, 0, 0, 1, 1 },
\r
779 { "CDDA audio", MB_ONOFF, MA_CDOPT_CDDA, &PicoOpt, 0x0800, 0, 0, 1, 1 },
\r
780 { "PCM audio", MB_ONOFF, MA_CDOPT_PCM, &PicoOpt, 0x0400, 0, 0, 1, 1 },
\r
781 { NULL, MB_NONE, MA_CDOPT_READAHEAD, NULL, 0, 0, 0, 1, 1 },
\r
782 { "SaveRAM cart", MB_ONOFF, MA_CDOPT_SAVERAM, &PicoOpt, 0x8000, 0, 0, 1, 1 },
\r
783 { "Scale/Rot. fx (slow)", MB_ONOFF, MA_CDOPT_SCALEROT_CHIP,&PicoOpt, 0x1000, 0, 0, 1, 1 },
\r
784 { "Better sync (slow)", MB_ONOFF, MA_CDOPT_BETTER_SYNC, &PicoOpt, 0x2000, 0, 0, 1, 1 },
\r
785 { "done", MB_NONE, MA_CDOPT_DONE, NULL, 0, 0, 0, 1, 0 },
\r
788 #define CDOPT_ENTRY_COUNT (sizeof(cdopt_entries) / sizeof(cdopt_entries[0]))
\r
789 const int cdopt_entry_count = CDOPT_ENTRY_COUNT;
\r
792 struct bios_names_t
\r
794 char us[32], eu[32], jp[32];
\r
797 static void menu_cdopt_cust_draw(const menu_entry *entry, int x, int y, void *param)
\r
799 struct bios_names_t *bios_names = param;
\r
804 case MA_CDOPT_TESTBIOS_USA: text_out16(x, y, "USA BIOS: %s", bios_names->us); break;
\r
805 case MA_CDOPT_TESTBIOS_EUR: text_out16(x, y, "EUR BIOS: %s", bios_names->eu); break;
\r
806 case MA_CDOPT_TESTBIOS_JAP: text_out16(x, y, "JAP BIOS: %s", bios_names->jp); break;
\r
807 case MA_CDOPT_READAHEAD:
\r
808 if (PicoCDBuffers > 1) sprintf(ra_buff, "%5iK", PicoCDBuffers * 2);
\r
809 else strcpy(ra_buff, " OFF");
\r
810 text_out16(x, y, "ReadAhead buffer %s", ra_buff);
\r
816 static void draw_cd_menu_options(int menu_sel, struct bios_names_t *bios_names)
\r
818 int tl_x = 25, tl_y = 60;
\r
819 menu_id selected_id;
\r
822 if (PicoCDBuffers > 1) sprintf(ra_buff, "%5iK", PicoCDBuffers * 2);
\r
823 else strcpy(ra_buff, " OFF");
\r
825 menu_draw_begin(1);
\r
827 menu_draw_selection(tl_x - 16, tl_y + menu_sel*10, 246);
\r
829 me_draw(cdopt_entries, CDOPT_ENTRY_COUNT, tl_x, tl_y, menu_cdopt_cust_draw, bios_names);
\r
831 selected_id = me_index2id(cdopt_entries, CDOPT_ENTRY_COUNT, menu_sel);
\r
832 if ((selected_id == MA_CDOPT_TESTBIOS_USA && strcmp(bios_names->us, "NOT FOUND")) ||
\r
833 (selected_id == MA_CDOPT_TESTBIOS_EUR && strcmp(bios_names->eu, "NOT FOUND")) ||
\r
834 (selected_id == MA_CDOPT_TESTBIOS_JAP && strcmp(bios_names->jp, "NOT FOUND")))
\r
835 text_out16(tl_x, 210, "Press start to test selected BIOS");
\r
840 static void cd_menu_loop_options(void)
\r
842 static int menu_sel = 0;
\r
843 int menu_sel_max = 10;
\r
844 unsigned long inp = 0;
\r
845 struct bios_names_t bios_names;
\r
846 menu_id selected_id;
\r
849 if (emu_findBios(4, &bios)) { // US
\r
850 for (p = bios+strlen(bios)-1; p > bios && *p != '/'; p--);
\r
851 if (*p == '/') p++;
\r
852 strncpy(bios_names.us, p, sizeof(bios_names.us)); bios_names.us[sizeof(bios_names.us)-1] = 0;
\r
853 } else strcpy(bios_names.us, "NOT FOUND");
\r
855 if (emu_findBios(8, &bios)) { // EU
\r
856 for (p = bios+strlen(bios)-1; p > bios && *p != '/'; p--);
\r
857 if (*p == '/') p++;
\r
858 strncpy(bios_names.eu, p, sizeof(bios_names.eu)); bios_names.eu[sizeof(bios_names.eu)-1] = 0;
\r
859 } else strcpy(bios_names.eu, "NOT FOUND");
\r
861 if (emu_findBios(1, &bios)) { // JP
\r
862 for (p = bios+strlen(bios)-1; p > bios && *p != '/'; p--);
\r
863 if (*p == '/') p++;
\r
864 strncpy(bios_names.jp, p, sizeof(bios_names.jp)); bios_names.jp[sizeof(bios_names.jp)-1] = 0;
\r
865 } else strcpy(bios_names.jp, "NOT FOUND");
\r
869 draw_cd_menu_options(menu_sel, &bios_names);
\r
870 inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|PBTN_PLAY|PBTN_STOP|PBTN_REW);
\r
871 if (inp & PBTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }
\r
872 if (inp & PBTN_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }
\r
873 selected_id = me_index2id(cdopt_entries, CDOPT_ENTRY_COUNT, menu_sel);
\r
874 if (inp & (PBTN_LEFT|PBTN_RIGHT)) { // multi choise
\r
875 if (!me_process(cdopt_entries, CDOPT_ENTRY_COUNT, selected_id, (inp&PBTN_RIGHT) ? 1 : 0) &&
\r
876 selected_id == MA_CDOPT_READAHEAD) {
\r
877 if (inp & PBTN_LEFT) {
\r
878 PicoCDBuffers >>= 1;
\r
879 if (PicoCDBuffers < 2) PicoCDBuffers = 0;
\r
881 if (PicoCDBuffers < 2) PicoCDBuffers = 2;
\r
882 else PicoCDBuffers <<= 1;
\r
883 if (PicoCDBuffers > 8*1024) PicoCDBuffers = 8*1024; // 16M
\r
887 if (inp & PBTN_PLAY) { // toggleable options
\r
888 if (!me_process(cdopt_entries, CDOPT_ENTRY_COUNT, selected_id, 1) &&
\r
889 selected_id == MA_CDOPT_DONE) {
\r
892 switch (selected_id) { // BIOS testers
\r
893 case MA_CDOPT_TESTBIOS_USA:
\r
894 if (emu_findBios(4, &bios)) { // test US
\r
895 strcpy(romFileName, bios);
\r
896 engineState = PGS_ReloadRom;
\r
900 case MA_CDOPT_TESTBIOS_EUR:
\r
901 if (emu_findBios(8, &bios)) { // test EU
\r
902 strcpy(romFileName, bios);
\r
903 engineState = PGS_ReloadRom;
\r
907 case MA_CDOPT_TESTBIOS_JAP:
\r
908 if (emu_findBios(1, &bios)) { // test JP
\r
909 strcpy(romFileName, bios);
\r
910 engineState = PGS_ReloadRom;
\r
918 if (inp & (PBTN_STOP|PBTN_REW)) return;
\r
923 // --------- advanced options ----------
\r
925 menu_entry opt2_entries[] =
\r
927 { "Disable sprite limit", MB_ONOFF, MA_OPT2_NO_SPRITE_LIM, &PicoOpt, 0x40000, 0, 0, 1, 1 },
\r
928 { "Emulate Z80", MB_ONOFF, MA_OPT2_ENABLE_Z80, &PicoOpt, 0x00004, 0, 0, 1, 1 },
\r
929 { "Emulate YM2612 (FM)", MB_ONOFF, MA_OPT2_ENABLE_YM2612, &PicoOpt, 0x00001, 0, 0, 1, 1 },
\r
930 { "Emulate SN76496 (PSG)", MB_ONOFF, MA_OPT2_ENABLE_SN76496,&PicoOpt, 0x00002, 0, 0, 1, 1 },
\r
931 { "Double buffering", MB_ONOFF, MA_OPT2_DBLBUFF, ¤tConfig.EmuOpt, 0x8000, 0, 0, 1, 1 },
\r
932 { "Wait for V-sync (slow)", MB_ONOFF, MA_OPT2_VSYNC, ¤tConfig.EmuOpt, 0x2000, 0, 0, 1, 1 },
\r
933 { "gzip savestates", MB_ONOFF, MA_OPT2_GZIP_STATES, ¤tConfig.EmuOpt, 0x0008, 0, 0, 1, 1 },
\r
934 { "Don't save last used ROM", MB_ONOFF, MA_OPT2_NO_LAST_ROM, ¤tConfig.EmuOpt, 0x0020, 0, 0, 1, 1 },
\r
935 { "SVP dynarec", MB_ONOFF, MA_OPT2_SVP_DYNAREC, &PicoOpt, 0x20000, 0, 0, 1, 1 },
\r
936 { "Disable idle loop patching",MB_ONOFF, MA_OPT2_NO_IDLE_LOOPS, &PicoOpt, 0x80000, 0, 0, 1, 1 },
\r
937 { "done", MB_NONE, MA_OPT2_DONE, NULL, 0, 0, 0, 1, 0 },
\r
940 #define OPT2_ENTRY_COUNT (sizeof(opt2_entries) / sizeof(opt2_entries[0]))
\r
941 const int opt2_entry_count = OPT2_ENTRY_COUNT;
\r
944 static void draw_amenu_options(int menu_sel)
\r
946 int tl_x = 25, tl_y = 50;
\r
948 menu_draw_begin(1);
\r
950 menu_draw_selection(tl_x - 16, tl_y + menu_sel*10, 252);
\r
952 me_draw(opt2_entries, OPT2_ENTRY_COUNT, tl_x, tl_y, NULL, NULL);
\r
957 static void amenu_loop_options(void)
\r
959 static int menu_sel = 0;
\r
961 unsigned long inp = 0;
\r
962 menu_id selected_id;
\r
964 menu_sel_max = me_count_enabled(opt2_entries, OPT2_ENTRY_COUNT) - 1;
\r
968 draw_amenu_options(menu_sel);
\r
969 inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|PBTN_PLAY|PBTN_STOP|PBTN_REW);
\r
970 if (inp & PBTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }
\r
971 if (inp & PBTN_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }
\r
972 selected_id = me_index2id(opt2_entries, OPT2_ENTRY_COUNT, menu_sel);
\r
973 if (inp & (PBTN_LEFT|PBTN_RIGHT)) { // multi choise
\r
974 if (!me_process(opt2_entries, OPT2_ENTRY_COUNT, selected_id, (inp&PBTN_RIGHT) ? 1 : 0) &&
\r
975 selected_id == MA_OPT2_GAMMA) {
\r
976 while ((inp = Framework_PollGetButtons()) & (PBTN_LEFT|PBTN_RIGHT)) {
\r
977 currentConfig.gamma += (inp & PBTN_LEFT) ? -1 : 1;
\r
978 if (currentConfig.gamma < 1) currentConfig.gamma = 1;
\r
979 if (currentConfig.gamma > 300) currentConfig.gamma = 300;
\r
980 draw_amenu_options(menu_sel);
\r
985 if (inp & PBTN_PLAY) { // toggleable options
\r
986 if (!me_process(opt2_entries, OPT2_ENTRY_COUNT, selected_id, 1) &&
\r
987 selected_id == MA_OPT2_DONE) {
\r
991 if (inp & (PBTN_STOP|PBTN_REW)) return;
\r
995 // -------------- options --------------
\r
998 menu_entry opt_entries[] =
\r
1000 { NULL, MB_NONE, MA_OPT_RENDERER, NULL, 0, 0, 0, 1, 1 },
\r
1001 { "Accurate sprites", MB_ONOFF, MA_OPT_ACC_SPRITES, &PicoOpt, 0x080, 0, 0, 0, 1 },
\r
1002 { "Scanline mode (faster)", MB_ONOFF, MA_OPT_INTERLACED, ¤tConfig.EmuOpt, 0x4000, 0, 0, 1, 1 },
\r
1003 { "Scale low res mode", MB_ONOFF, MA_OPT_SCALING, ¤tConfig.scaling, 0x0001, 0, 3, 1, 1 },
\r
1004 { "Show FPS", MB_ONOFF, MA_OPT_SHOW_FPS, ¤tConfig.EmuOpt, 0x0002, 0, 0, 1, 1 },
\r
1005 { NULL, MB_RANGE, MA_OPT_FRAMESKIP, ¤tConfig.Frameskip, 0, -1, 16, 1, 1 },
\r
1006 { "Enable sound", MB_ONOFF, MA_OPT_ENABLE_SOUND, ¤tConfig.EmuOpt, 0x0004, 0, 0, 1, 1 },
\r
1007 { NULL, MB_NONE, MA_OPT_SOUND_QUALITY, NULL, 0, 0, 0, 1, 1 },
\r
1008 { NULL, MB_NONE, MA_OPT_REGION, NULL, 0, 0, 0, 1, 1 },
\r
1009 { "Use SRAM/BRAM savestates", MB_ONOFF, MA_OPT_SRAM_STATES, ¤tConfig.EmuOpt, 0x0001, 0, 0, 1, 1 },
\r
1010 { NULL, MB_NONE, MA_OPT_CONFIRM_STATES,NULL, 0, 0, 0, 1, 1 },
\r
1011 { "Save slot", MB_RANGE, MA_OPT_SAVE_SLOT, &state_slot, 0, 0, 9, 1, 1 },
\r
1012 { "[Sega/Mega CD options]", MB_NONE, MA_OPT_SCD_OPTS, NULL, 0, 0, 0, 1, 0 },
\r
1013 { "[advanced options]", MB_NONE, MA_OPT_ADV_OPTS, NULL, 0, 0, 0, 1, 0 },
\r
1014 { NULL, MB_NONE, MA_OPT_SAVECFG, NULL, 0, 0, 0, 1, 0 },
\r
1015 { "Save cfg for current game only",MB_NONE,MA_OPT_SAVECFG_GAME,NULL, 0, 0, 0, 1, 0 },
\r
1016 { NULL, MB_NONE, MA_OPT_LOADCFG, NULL, 0, 0, 0, 1, 0 },
\r
1019 #define OPT_ENTRY_COUNT (sizeof(opt_entries) / sizeof(opt_entries[0]))
\r
1020 const int opt_entry_count = OPT_ENTRY_COUNT;
\r
1023 static void menu_opt_cust_draw(const menu_entry *entry, int x, int y, void *param)
\r
1025 char *str, str24[24];
\r
1027 switch (entry->id)
\r
1029 case MA_OPT_RENDERER:
\r
1031 str = " 8bit fast";
\r
1032 else if (currentConfig.EmuOpt&0x80)
\r
1033 str = "16bit accurate";
\r
1035 str = " 8bit accurate";
\r
1036 text_out16(x, y, "Renderer: %s", str);
\r
1038 case MA_OPT_FRAMESKIP:
\r
1039 if (currentConfig.Frameskip < 0)
\r
1040 strcpy(str24, "Auto");
\r
1041 else sprintf(str24, "%i", currentConfig.Frameskip);
\r
1042 text_out16(x, y, "Frameskip %s", str24);
\r
1044 case MA_OPT_SOUND_QUALITY:
\r
1045 str = (PicoOpt&0x08)?"stereo":"mono";
\r
1046 text_out16(x, y, "Sound Quality: %5iHz %s", PsndRate, str);
\r
1048 case MA_OPT_REGION:
\r
1049 text_out16(x, y, "Region: %s", me_region_name(PicoRegionOverride, PicoAutoRgnOrder));
\r
1051 case MA_OPT_CONFIRM_STATES:
\r
1052 switch ((currentConfig.EmuOpt >> 9) & 5) {
\r
1053 default: str = "OFF"; break;
\r
1054 case 1: str = "writes"; break;
\r
1055 case 4: str = "loads"; break;
\r
1056 case 5: str = "both"; break;
\r
1058 text_out16(x, y, "Confirm savestate %s", str);
\r
1060 case MA_OPT_SAVECFG:
\r
1062 if (config_slot != 0) sprintf(str24, " (profile: %i)", config_slot);
\r
1063 text_out16(x, y, "Save cfg as default%s", str24);
\r
1065 case MA_OPT_LOADCFG:
\r
1066 text_out16(x, y, "Load cfg from profile %i", config_slot);
\r
1069 lprintf("%s: unimplemented (%i)\n", __FUNCTION__, entry->id);
\r
1076 static void draw_menu_options(int menu_sel)
\r
1078 int tl_x = 25, tl_y = 24;
\r
1080 menu_draw_begin(1);
\r
1082 menu_draw_selection(tl_x - 16, tl_y + menu_sel*10, 284);
\r
1084 me_draw(opt_entries, OPT_ENTRY_COUNT, tl_x, tl_y, menu_opt_cust_draw, NULL);
\r
1089 static int sndrate_prevnext(int rate, int dir)
\r
1091 int i, rates[] = { 11025, 22050, 44100 };
\r
1093 for (i = 0; i < 5; i++)
\r
1094 if (rates[i] == rate) break;
\r
1096 i += dir ? 1 : -1;
\r
1097 if (i > 2) return dir ? 44100 : 22050;
\r
1098 if (i < 0) return dir ? 22050 : 11025;
\r
1102 static void region_prevnext(int right)
\r
1104 // jp_ntsc=1, jp_pal=2, usa=4, eu=8
\r
1105 static int rgn_orders[] = { 0x148, 0x184, 0x814, 0x418, 0x841, 0x481 };
\r
1108 if (!PicoRegionOverride) {
\r
1109 for (i = 0; i < 6; i++)
\r
1110 if (rgn_orders[i] == PicoAutoRgnOrder) break;
\r
1111 if (i < 5) PicoAutoRgnOrder = rgn_orders[i+1];
\r
1112 else PicoRegionOverride=1;
\r
1114 else PicoRegionOverride<<=1;
\r
1115 if (PicoRegionOverride > 8) PicoRegionOverride = 8;
\r
1117 if (!PicoRegionOverride) {
\r
1118 for (i = 0; i < 6; i++)
\r
1119 if (rgn_orders[i] == PicoAutoRgnOrder) break;
\r
1120 if (i > 0) PicoAutoRgnOrder = rgn_orders[i-1];
\r
1122 else PicoRegionOverride>>=1;
\r
1126 static void menu_options_save(void)
\r
1128 if (PicoRegionOverride) {
\r
1129 // force setting possibly changed..
\r
1130 Pico.m.pal = (PicoRegionOverride == 2 || PicoRegionOverride == 8) ? 1 : 0;
\r
1132 if (!(PicoOpt & 0x20)) {
\r
1133 // unbind XYZ MODE, just in case
\r
1134 unbind_action(0xf00);
\r
1138 static int menu_loop_options(void)
\r
1140 static int menu_sel = 0;
\r
1141 int menu_sel_max, ret;
\r
1142 unsigned long inp = 0;
\r
1143 menu_id selected_id;
\r
1145 me_enable(opt_entries, OPT_ENTRY_COUNT, MA_OPT_SAVECFG_GAME, rom_loaded);
\r
1146 me_enable(opt_entries, OPT_ENTRY_COUNT, MA_OPT_LOADCFG, config_slot != config_slot_current);
\r
1147 menu_sel_max = me_count_enabled(opt_entries, OPT_ENTRY_COUNT) - 1;
\r
1148 if (menu_sel > menu_sel_max) menu_sel = menu_sel_max;
\r
1152 draw_menu_options(menu_sel);
\r
1153 inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|PBTN_PLAY|PBTN_STOP|PBTN_REW);
\r
1154 if (inp & PBTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }
\r
1155 if (inp & PBTN_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }
\r
1156 selected_id = me_index2id(opt_entries, OPT_ENTRY_COUNT, menu_sel);
\r
1157 if (inp & (PBTN_LEFT|PBTN_RIGHT)) { // multi choise
\r
1158 if (!me_process(opt_entries, OPT_ENTRY_COUNT, selected_id, (inp&PBTN_RIGHT) ? 1 : 0)) {
\r
1159 switch (selected_id) {
\r
1160 case MA_OPT_RENDERER:
\r
1161 if (inp & PBTN_LEFT) {
\r
1162 if ((PicoOpt&0x10) || !(currentConfig.EmuOpt &0x80)) {
\r
1164 currentConfig.EmuOpt |= 0x80;
\r
1167 if (!(PicoOpt&0x10) || (currentConfig.EmuOpt &0x80)) {
\r
1169 currentConfig.EmuOpt &= ~0x80;
\r
1173 case MA_OPT_SOUND_QUALITY:
\r
1174 if ((inp & PBTN_RIGHT) && PsndRate == 44100 &&
\r
1179 } else if ((inp & PBTN_LEFT) && PsndRate == 11025 &&
\r
1180 (PicoOpt&0x08) && !(PicoAHW&1))
\r
1185 PsndRate = sndrate_prevnext(PsndRate, inp & PBTN_RIGHT);
\r
1187 case MA_OPT_REGION:
\r
1188 region_prevnext(inp & PBTN_RIGHT);
\r
1190 case MA_OPT_CONFIRM_STATES: {
\r
1191 int n = ((currentConfig.EmuOpt>>9)&1) | ((currentConfig.EmuOpt>>10)&2);
\r
1192 n += (inp & PBTN_LEFT) ? -1 : 1;
\r
1193 if (n < 0) n = 0; else if (n > 3) n = 3;
\r
1194 n |= n << 1; n &= ~2;
\r
1195 currentConfig.EmuOpt &= ~0xa00;
\r
1196 currentConfig.EmuOpt |= n << 9;
\r
1199 case MA_OPT_SAVE_SLOT:
\r
1200 if (inp & PBTN_RIGHT) {
\r
1201 state_slot++; if (state_slot > 9) state_slot = 0;
\r
1202 } else {state_slot--; if (state_slot < 0) state_slot = 9;
\r
1205 case MA_OPT_SAVECFG:
\r
1206 case MA_OPT_SAVECFG_GAME:
\r
1207 case MA_OPT_LOADCFG:
\r
1208 config_slot += (inp&PBTN_RIGHT) ? 1 : -1;
\r
1209 if (config_slot > 9) config_slot = 0;
\r
1210 if (config_slot < 0) config_slot = 9;
\r
1211 me_enable(opt_entries, OPT_ENTRY_COUNT, MA_OPT_LOADCFG, config_slot != config_slot_current);
\r
1212 menu_sel_max = me_count_enabled(opt_entries, OPT_ENTRY_COUNT) - 1;
\r
1213 if (menu_sel > menu_sel_max) menu_sel = menu_sel_max;
\r
1216 //lprintf("%s: something unknown selected (%i)\n", __FUNCTION__, selected_id);
\r
1221 if (inp & PBTN_PLAY) {
\r
1222 if (!me_process(opt_entries, OPT_ENTRY_COUNT, selected_id, 1))
\r
1224 switch (selected_id)
\r
1226 case MA_OPT_SCD_OPTS:
\r
1227 cd_menu_loop_options();
\r
1228 if (engineState == PGS_ReloadRom)
\r
1229 return 0; // test BIOS
\r
1231 case MA_OPT_ADV_OPTS:
\r
1232 amenu_loop_options();
\r
1234 case MA_OPT_SAVECFG: // done (update and write)
\r
1235 menu_options_save();
\r
1236 if (emu_WriteConfig(0)) strcpy(menuErrorMsg, "config saved");
\r
1237 else strcpy(menuErrorMsg, "failed to write config");
\r
1239 case MA_OPT_SAVECFG_GAME: // done (update and write for current game)
\r
1240 menu_options_save();
\r
1241 if (emu_WriteConfig(1)) strcpy(menuErrorMsg, "config saved");
\r
1242 else strcpy(menuErrorMsg, "failed to write config");
\r
1244 case MA_OPT_LOADCFG:
\r
1245 ret = emu_ReadConfig(1, 1);
\r
1246 if (!ret) ret = emu_ReadConfig(0, 1);
\r
1247 if (ret) strcpy(menuErrorMsg, "config loaded");
\r
1248 else strcpy(menuErrorMsg, "failed to load config");
\r
1251 //lprintf("%s: something unknown selected (%i)\n", __FUNCTION__, selected_id);
\r
1256 if(inp & (PBTN_STOP|PBTN_REW)) {
\r
1257 menu_options_save();
\r
1258 return 0; // done (update, no write)
\r
1263 // -------------- credits --------------
\r
1265 static void draw_menu_credits(void)
\r
1267 int tl_x = 15, tl_y = 56, y;
\r
1268 menu_draw_begin(1);
\r
1270 text_out16(tl_x, 20, "PicoDrive v" VERSION " (c) notaz, 2006-2008");
\r
1273 text_out16(tl_x, y, "Credits:");
\r
1274 text_out16(tl_x, (y+=10), "fDave: Cyclone 68000 core,");
\r
1275 text_out16(tl_x, (y+=10), " base code of PicoDrive");
\r
1276 text_out16(tl_x, (y+=10), "Reesy & FluBBa: DrZ80 core");
\r
1277 text_out16(tl_x, (y+=10), "MAME devs: YM2612 and SN76496 cores");
\r
1278 text_out16(tl_x, (y+=10), "Reesy: kgsdk wrapper, sound code");
\r
1279 text_out16(tl_x, (y+=10), "jens.l: gizmondo hardware");
\r
1280 text_out16(tl_x, (y+=10), "ketchupgun: skin design");
\r
1282 text_out16(tl_x, (y+=20), "special thanks (for docs, ideas)");
\r
1283 text_out16(tl_x, (y+=10), " Charles MacDonald, Haze,");
\r
1284 text_out16(tl_x, (y+=10), " Stephane Dallongeville,");
\r
1285 text_out16(tl_x, (y+=10), " Lordus, Exophase, Rokas,");
\r
1286 text_out16(tl_x, (y+=10), " Nemesis, Tasco Deluxe");
\r
1292 // -------------- root menu --------------
\r
1294 menu_entry main_entries[] =
\r
1296 { "Resume game", MB_NONE, MA_MAIN_RESUME_GAME, NULL, 0, 0, 0, 0, 0 },
\r
1297 { "Save State", MB_NONE, MA_MAIN_SAVE_STATE, NULL, 0, 0, 0, 0, 0 },
\r
1298 { "Load State", MB_NONE, MA_MAIN_LOAD_STATE, NULL, 0, 0, 0, 0, 0 },
\r
1299 { "Reset game", MB_NONE, MA_MAIN_RESET_GAME, NULL, 0, 0, 0, 0, 0 },
\r
1300 { "Load new ROM/ISO", MB_NONE, MA_MAIN_LOAD_ROM, NULL, 0, 0, 0, 1, 0 },
\r
1301 { "Change options", MB_NONE, MA_MAIN_OPTIONS, NULL, 0, 0, 0, 1, 0 },
\r
1302 { "Configure controls", MB_NONE, MA_MAIN_CONTROLS, NULL, 0, 0, 0, 1, 0 },
\r
1303 { "Credits", MB_NONE, MA_MAIN_CREDITS, NULL, 0, 0, 0, 1, 0 },
\r
1304 { "Patches / GameGenie",MB_NONE, MA_MAIN_PATCHES, NULL, 0, 0, 0, 0, 0 },
\r
1305 { "Exit", MB_NONE, MA_MAIN_EXIT, NULL, 0, 0, 0, 1, 0 }
\r
1308 #define MAIN_ENTRY_COUNT (sizeof(main_entries) / sizeof(main_entries[0]))
\r
1310 static void draw_menu_root(int menu_sel)
\r
1312 const int tl_x = 70, tl_y = 70;
\r
1314 menu_draw_begin(1);
\r
1316 text_out16(tl_x, 20, "PicoDrive v" VERSION);
\r
1318 menu_draw_selection(tl_x - 16, tl_y + menu_sel*10, 146);
\r
1320 me_draw(main_entries, MAIN_ENTRY_COUNT, tl_x, tl_y, NULL, NULL);
\r
1323 if (menuErrorMsg[0]) {
\r
1324 memset((char *)menu_screen + 321*224*2, 0, 321*16*2);
\r
1325 text_out16(5, 226, menuErrorMsg);
\r
1331 static void menu_loop_root(void)
\r
1333 static int menu_sel = 0;
\r
1334 int ret, menu_sel_max;
\r
1335 unsigned long inp = 0;
\r
1337 me_enable(main_entries, MAIN_ENTRY_COUNT, MA_MAIN_RESUME_GAME, rom_loaded);
\r
1338 me_enable(main_entries, MAIN_ENTRY_COUNT, MA_MAIN_SAVE_STATE, rom_loaded);
\r
1339 me_enable(main_entries, MAIN_ENTRY_COUNT, MA_MAIN_LOAD_STATE, rom_loaded);
\r
1340 me_enable(main_entries, MAIN_ENTRY_COUNT, MA_MAIN_RESET_GAME, rom_loaded);
\r
1341 me_enable(main_entries, MAIN_ENTRY_COUNT, MA_MAIN_PATCHES, PicoPatches != NULL);
\r
1343 menu_sel_max = me_count_enabled(main_entries, MAIN_ENTRY_COUNT) - 1;
\r
1344 if (menu_sel > menu_sel_max) menu_sel = menu_sel_max;
\r
1346 /* make sure action buttons are not pressed on entering menu */
\r
1347 draw_menu_root(menu_sel);
\r
1349 while (Framework_PollGetButtons() & (PBTN_PLAY|PBTN_STOP|PBTN_HOME)) Sleep(50);
\r
1353 draw_menu_root(menu_sel);
\r
1354 inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_PLAY|PBTN_STOP|PBTN_HOME|PBTN_L|PBTN_R);
\r
1355 if(inp & PBTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }
\r
1356 if(inp & PBTN_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }
\r
1357 if((inp & (PBTN_L|PBTN_R)) == (PBTN_L|PBTN_R)) debug_menu_loop();
\r
1358 if( inp & (PBTN_HOME|PBTN_STOP)) {
\r
1360 while (Framework_PollGetButtons() & (PBTN_HOME|PBTN_STOP)) Sleep(50); // wait until released
\r
1361 engineState = PGS_Running;
\r
1365 if(inp & PBTN_PLAY) {
\r
1366 switch (me_index2id(main_entries, MAIN_ENTRY_COUNT, menu_sel))
\r
1368 case MA_MAIN_RESUME_GAME:
\r
1370 while (Framework_PollGetButtons() & PBTN_PLAY) Sleep(50);
\r
1371 engineState = PGS_Running;
\r
1375 case MA_MAIN_SAVE_STATE:
\r
1377 if(savestate_menu_loop(0))
\r
1379 engineState = PGS_Running;
\r
1383 case MA_MAIN_LOAD_STATE:
\r
1385 if(savestate_menu_loop(1))
\r
1387 while (Framework_PollGetButtons() & PBTN_PLAY) Sleep(50);
\r
1388 engineState = PGS_Running;
\r
1392 case MA_MAIN_RESET_GAME:
\r
1395 while (Framework_PollGetButtons() & PBTN_PLAY) Sleep(50);
\r
1396 engineState = PGS_Running;
\r
1400 case MA_MAIN_LOAD_ROM:
\r
1402 char curr_path[MAX_PATH], *selfname;
\r
1404 if ( (tstf = fopen(loadedRomFName, "rb")) )
\r
1407 strcpy(curr_path, loadedRomFName);
\r
1410 getcwd(curr_path, MAX_PATH);
\r
1411 selfname = romsel_loop(curr_path);
\r
1413 lprintf("selected file: %s\n", selfname);
\r
1414 engineState = PGS_ReloadRom;
\r
1419 case MA_MAIN_OPTIONS:
\r
1420 ret = menu_loop_options();
\r
1421 if (ret == 1) continue; // status update
\r
1422 if (engineState == PGS_ReloadRom)
\r
1423 return; // BIOS test
\r
1425 case MA_MAIN_CONTROLS:
\r
1428 case MA_MAIN_CREDITS:
\r
1429 draw_menu_credits();
\r
1431 inp = in_menu_wait(PBTN_PLAY|PBTN_STOP);
\r
1433 case MA_MAIN_EXIT:
\r
1434 engineState = PGS_Quit;
\r
1436 case MA_MAIN_PATCHES:
\r
1437 if (rom_loaded && PicoPatches) {
\r
1438 patches_menu_loop();
\r
1440 strcpy(menuErrorMsg, "Patches applied");
\r
1445 lprintf("%s: something unknown selected\n", __FUNCTION__);
\r
1449 menuErrorMsg[0] = 0; // clear error msg
\r
1453 // warning: alignment
\r
1454 void menu_darken_bg(void *dst, const void *src, int pixels, int darker)
\r
1456 unsigned int *dest = dst;
\r
1457 const unsigned int *srce = src;
\r
1463 unsigned int p = *srce++;
\r
1464 *dest++ = ((p&0xf79ef79e)>>1) - ((p&0xc618c618)>>3);
\r
1471 unsigned int p = *srce++;
\r
1472 *dest++ = (p&0xf79ef79e)>>1;
\r
1477 static void menu_prepare_bg(int use_game_bg)
\r
1481 // darken the active framebuffer
\r
1482 if (giz_screen == NULL)
\r
1483 giz_screen = fb_lock(1);
\r
1484 memset(bg_buffer, 0, 321*8*2);
\r
1485 menu_darken_bg(bg_buffer + 321*8*2, (char *)giz_screen + 321*8*2, 321*224, 1);
\r
1486 memset(bg_buffer + 321*232*2, 0, 321*8*2);
\r
1488 giz_screen = NULL;
\r
1493 // should really only happen once, on startup..
\r
1494 readpng(bg_buffer, "skin/background.png", READPNG_BG);
\r
1495 // adjust 320 width to 321
\r
1496 for (i = 239; i > 0; i--)
\r
1497 memmove(bg_buffer + 321*2*i, bg_buffer + 320*2*i, 320*2);
\r
1501 static void menu_gfx_prepare(void)
\r
1503 menu_prepare_bg(rom_loaded);
\r
1505 menu_draw_begin(1);
\r
1510 void menu_loop(void)
\r
1512 menu_gfx_prepare();
\r
1516 menuErrorMsg[0] = 0;
\r
1520 // --------- CD tray close menu ----------
\r
1522 static void draw_menu_tray(int menu_sel)
\r
1524 int tl_x = 70, tl_y = 90, y;
\r
1526 menu_draw_begin(1);
\r
1528 text_out16(tl_x, 20, "The unit is about to");
\r
1529 text_out16(tl_x, 30, "close the CD tray.");
\r
1532 text_out16(tl_x, y, "Load new CD image");
\r
1533 text_out16(tl_x, (y+=10), "Insert nothing");
\r
1536 text_out16(tl_x - 16, tl_y + menu_sel*10, ">");
\r
1538 if (menuErrorMsg[0]) text_out16(5, 226, menuErrorMsg);
\r
1543 int menu_loop_tray(void)
\r
1545 int menu_sel = 0, menu_sel_max = 1;
\r
1546 unsigned long inp = 0;
\r
1547 char curr_path[MAX_PATH], *selfname;
\r
1550 menu_gfx_prepare();
\r
1552 if ( (tstf = fopen(loadedRomFName, "rb")) )
\r
1555 strcpy(curr_path, loadedRomFName);
\r
1559 getcwd(curr_path, MAX_PATH);
\r
1562 /* make sure action buttons are not pressed on entering menu */
\r
1563 draw_menu_tray(menu_sel);
\r
1564 while (Framework_PollGetButtons() & PBTN_PLAY) Sleep(50);
\r
1568 draw_menu_tray(menu_sel);
\r
1569 inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_PLAY);
\r
1570 if(inp & PBTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }
\r
1571 if(inp & PBTN_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }
\r
1572 if(inp & PBTN_PLAY) {
\r
1573 switch (menu_sel) {
\r
1574 case 0: // select image
\r
1575 selfname = romsel_loop(curr_path);
\r
1578 cd_img_type cd_type;
\r
1579 cd_type = emu_cdCheck(NULL, romFileName);
\r
1580 if (cd_type != CIT_NOT_CD)
\r
1581 ret = Insert_CD(romFileName, cd_type);
\r
1583 sprintf(menuErrorMsg, "Load failed, invalid CD image?");
\r
1584 lprintf("%s\n", menuErrorMsg);
\r
1587 engineState = PGS_RestartRun;
\r
1591 case 1: // insert nothing
\r
1592 engineState = PGS_RestartRun;
\r
1596 menuErrorMsg[0] = 0; // clear error msg
\r