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
20 #include "../common/arm_utils.h"
\r
21 #include "../common/menu.h"
\r
22 #include "../common/emu.h"
\r
23 #include "../common/readpng.h"
\r
24 #include "version.h"
\r
25 #include "kgsdk/Framework.h"
\r
26 #include "kgsdk/Framework2D.h"
\r
28 #include <Pico/PicoInt.h>
\r
29 #include <Pico/Patch.h>
\r
30 #include <zlib/zlib.h>
\r
33 #define gizKeyUnkn "???"
\r
34 static const char * const gizKeyNames[] = {
\r
35 "LEFT", "RIGHT", "UP", "DOWN", "STOP", "PLAY", "FORWARD", "REWIND",
\r
36 "L", "R", "HOME", "VOLUME", "BRIGHTNESS", "ALARM", "POWER", gizKeyUnkn,
\r
37 gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn,
\r
38 gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn
\r
41 static unsigned char *bg_buffer = gfx_buffer + 321*240*2;
\r
42 unsigned char *menu_screen = gfx_buffer; /* draw here and blit later, to avoid flicker */
\r
44 static void menu_darken_bg(void *dst, const void *src, int pixels, int darker);
\r
45 static void menu_prepare_bg(int use_game_bg);
\r
47 static unsigned int inp_prev = 0;
\r
49 static unsigned long wait_for_input(unsigned int interesting)
\r
52 static int repeats = 0, wait = 50;
\r
55 if (repeats == 2 || repeats == 4) wait /= 2;
\r
56 if (repeats == 6) wait = 15;
\r
58 for (i = 0; i < 6 && inp_prev == Framework_PollGetButtons(); i++) {
\r
59 if (i == 0) repeats++;
\r
63 while ( !((ret = Framework_PollGetButtons()) & interesting) ) {
\r
68 if (release || ret != inp_prev) {
\r
74 // we don't need diagonals in menus
\r
75 if ((ret&BTN_UP) && (ret&BTN_LEFT)) ret &= ~BTN_LEFT;
\r
76 if ((ret&BTN_UP) && (ret&BTN_RIGHT)) ret &= ~BTN_RIGHT;
\r
77 if ((ret&BTN_DOWN) && (ret&BTN_LEFT)) ret &= ~BTN_LEFT;
\r
78 if ((ret&BTN_DOWN) && (ret&BTN_RIGHT)) ret &= ~BTN_RIGHT;
\r
84 static void menu_draw_begin(int use_bgbuff)
\r
87 memcpy32((int *)menu_screen, (int *)bg_buffer, 321*240*2/4);
\r
91 static void menu_draw_end(void)
\r
93 giz_screen = Framework2D_LockBuffer(0);
\r
94 if (giz_screen == NULL)
\r
96 lprintf_al("%s: Framework2D_LockBuffer() returned NULL\n", __FUNCTION__);
\r
99 memcpy32(giz_screen, (int *)menu_screen, 321*240*2/4);
\r
100 Framework2D_UnlockBuffer();
\r
102 Framework2D_Flip(1);
\r
106 // --------- loading ROM screen ----------
\r
108 static void load_progress_cb(int percent)
\r
110 int ln, len = percent * 320 / 100;
\r
111 unsigned short *dst;
\r
113 menu_draw_begin(0);
\r
114 dst = (unsigned short *)menu_screen + 321*20;
\r
116 if (len > 320) len = 320;
\r
117 for (ln = 10; ln > 0; ln--, dst += 321)
\r
118 memset(dst, 0xff, len*2);
\r
122 void menu_romload_prepare(const char *rom_name)
\r
124 const char *p = rom_name + strlen(rom_name);
\r
125 while (p > rom_name && *p != '/') p--;
\r
128 memset(menu_screen, 0, 321*240*2);
\r
129 menu_draw_begin(1);
\r
131 smalltext_out16(1, 1, "Loading", 0xffff);
\r
132 smalltext_out16_lim(1, 10, p, 0xffff, 53);
\r
134 PicoCartLoadProgressCB = load_progress_cb;
\r
137 void menu_romload_end(void)
\r
139 PicoCartLoadProgressCB = NULL;
\r
140 menu_draw_begin(0);
\r
141 smalltext_out16(1, 30, "Starting emulation...", 0xffff);
\r
145 // -------------- ROM selector --------------
\r
152 unsigned char d_type;
\r
156 // rrrr rggg gggb bbbb
\r
158 static unsigned short file2color(const char *fname)
\r
160 const char *ext = fname + strlen(fname) - 3;
\r
161 static const char *rom_exts[] = { "zip", "bin", "smd", "gen", "iso", "cso" };
\r
162 static const char *other_exts[] = { "gmv", "pat" };
\r
165 if (ext < fname) ext = fname;
\r
166 for (i = 0; i < sizeof(rom_exts)/sizeof(rom_exts[0]); i++)
\r
167 if (strcasecmp(ext, rom_exts[i]) == 0) return 0xbdff;
\r
168 for (i = 0; i < sizeof(other_exts)/sizeof(other_exts[0]); i++)
\r
169 if (strcasecmp(ext, other_exts[i]) == 0) return 0xaff5;
\r
173 static void draw_dirlist(char *curdir, struct my_dirent **namelist, int n, int sel)
\r
178 n--; // exclude current dir (".")
\r
180 menu_draw_begin(1);
\r
183 menu_darken_bg(menu_screen, menu_screen, 321*240, 0);
\r
186 menu_darken_bg((char *)menu_screen + 321*120*2, (char *)menu_screen + 321*120*2, 321*8, 0);
\r
189 smalltext_out16_lim(14, (start - 2)*10, curdir, 0xffff, 53-2);
\r
190 for (i = 0; i < n; i++) {
\r
192 if (pos < 0) continue;
\r
193 if (pos > 23) break;
\r
194 if (namelist[i+1]->d_type == DT_DIR) {
\r
195 smalltext_out16_lim(14, pos*10, "/", 0xfff6, 1);
\r
196 smalltext_out16_lim(14+6, pos*10, namelist[i+1]->d_name, 0xfff6, 53-3);
\r
198 unsigned short color = file2color(namelist[i+1]->d_name);
\r
199 smalltext_out16_lim(14, pos*10, namelist[i+1]->d_name, color, 53-2);
\r
202 text_out16(5, 120, ">");
\r
206 static int scandir_cmp(const void *p1, const void *p2)
\r
208 struct my_dirent **d1 = (struct my_dirent **)p1, **d2 = (struct my_dirent **)p2;
\r
209 if ((*d1)->d_type == (*d2)->d_type) return strcasecmp((*d1)->d_name, (*d2)->d_name);
\r
210 if ((*d1)->d_type == DT_DIR) return -1; // put before
\r
211 if ((*d2)->d_type == DT_DIR) return 1;
\r
212 return strcasecmp((*d1)->d_name, (*d2)->d_name);
\r
215 static char *filter_exts[] = {
\r
216 ".mp3", ".srm", ".brm", "s.gz", ".mds", "bcfg", ".txt", ".htm", "html",
\r
217 ".jpg", ".cue", ".exe", ".dll"
\r
220 static int scandir_filter(const struct my_dirent *ent)
\r
225 if (ent == NULL || ent->d_name == NULL) return 0;
\r
226 if (strlen(ent->d_name) < 5) return 1;
\r
228 p = ent->d_name + strlen(ent->d_name) - 4;
\r
230 for (i = 0; i < sizeof(filter_exts)/sizeof(filter_exts[0]); i++)
\r
232 if (strcasecmp(p, filter_exts[i]) == 0) return 0;
\r
238 static int cstr2wstr(wchar_t *dst, const char *src)
\r
241 for (i = len = strlen(src); i >= 0; i--)
\r
246 static void wstr2cstr(char *dst, const wchar_t *src)
\r
249 for (i = wcslen(src); i >= 0; i--)
\r
253 static int my_scandir(const char *dir, struct my_dirent ***namelist_out,
\r
254 int(*filter)(const struct my_dirent *),
\r
255 int(*compar)(const void *, const void *))
\r
258 int i, len, ret = -1, name_alloc = 4, name_count = 0;
\r
259 struct my_dirent **namelist = NULL, *ent;
\r
260 WIN32_FIND_DATA finddata;
\r
261 HANDLE fh = INVALID_HANDLE_VALUE;
\r
264 wdir = malloc(sizeof(wdir[0]) * MAX_PATH);
\r
265 if (wdir == NULL) { lprintf_al("%s:%i: OOM\n", __FILE__, __LINE__); goto fail; }
\r
267 namelist = malloc(sizeof(*namelist) * name_alloc);
\r
268 if (namelist == NULL) { lprintf_al("%s:%i: OOM\n", __FILE__, __LINE__); goto fail; }
\r
270 // try to read first..
\r
271 len = cstr2wstr(wdir, dir);
\r
272 for (i = 0; i < len; i++)
\r
273 if (wdir[i] == '/') wdir[i] = '\\';
\r
274 if (wdir[len-1] != '\\') wdir[len++] = '\\';
\r
277 /*if (wdir[len-1] == '\\') wdir[len-1] = 0;*/
\r
280 fh = FindFirstFile(wdir, &finddata);
\r
281 if (fh == INVALID_HANDLE_VALUE)
\r
283 if (GetLastError() != ERROR_NO_MORE_FILES)
\r
285 lprintf("FindFirstFile(\"%s\") failed with %lu\n", dir, GetLastError());
\r
291 // add "." and ".."
\r
292 ent = malloc(sizeof(*ent) + 3);
\r
293 ent->d_type = DT_DIR; strcpy(ent->d_name, ".");
\r
294 namelist[name_count++] = ent;
\r
295 ent = malloc(sizeof(*ent) + 3);
\r
296 ent->d_type = DT_DIR; strcpy(ent->d_name, "..");
\r
297 namelist[name_count++] = ent;
\r
301 ent = malloc(sizeof(*ent) + wcslen(finddata.cFileName) + 1);
\r
302 ent->d_type = (finddata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? DT_DIR : DT_REG;
\r
303 wstr2cstr(ent->d_name, finddata.cFileName);
\r
304 if (filter == NULL || filter(ent))
\r
305 namelist[name_count++] = ent;
\r
308 if (name_count >= name_alloc)
\r
312 tmp = realloc(namelist, sizeof(*namelist) * name_alloc);
\r
313 if (tmp == NULL) { lprintf_al("%s:%i: OOM\n", __FILE__, __LINE__); goto fail; }
\r
317 bRet = FindNextFile(fh, &finddata);
\r
321 if (compar != NULL && name_count > 3) qsort(&namelist[2], name_count - 2, sizeof(namelist[0]), compar);
\r
325 *namelist_out = namelist;
\r
329 if (namelist != NULL)
\r
331 while (name_count--)
\r
332 free(namelist[name_count]);
\r
336 if (fh != INVALID_HANDLE_VALUE) FindClose(fh);
\r
337 if (wdir != NULL) free(wdir);
\r
342 static char *romsel_loop(char *curr_path)
\r
344 struct my_dirent **namelist;
\r
347 unsigned long inp = 0;
\r
348 char *ret = NULL, *fname = NULL;
\r
350 // is this a dir or a full path?
\r
351 if ((dir = opendir(curr_path))) {
\r
355 for (p = curr_path + strlen(curr_path) - 1; p > curr_path && *p != '/'; p--);
\r
360 n = my_scandir(curr_path, &namelist, scandir_filter, scandir_cmp);
\r
363 n = my_scandir("/", &namelist, scandir_filter, scandir_cmp);
\r
366 lprintf("scandir failed, dir: "); lprintf(curr_path); lprintf("\n");
\r
372 if (fname != NULL) {
\r
374 for (i = 1; i < n; i++) {
\r
375 if (strcmp(namelist[i]->d_name, fname) == 0) {
\r
384 draw_dirlist(curr_path, namelist, n, sel);
\r
385 inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_LEFT|BTN_RIGHT|BTN_L|BTN_R|BTN_PLAY|BTN_STOP);
\r
386 if(inp & BTN_UP ) { sel--; if (sel < 0) sel = n-2; }
\r
387 if(inp & BTN_DOWN) { sel++; if (sel > n-2) sel = 0; }
\r
388 if(inp & BTN_LEFT) { sel-=10; if (sel < 0) sel = 0; }
\r
389 if(inp & BTN_L) { sel-=24; if (sel < 0) sel = 0; }
\r
390 if(inp & BTN_RIGHT) { sel+=10; if (sel > n-2) sel = n-2; }
\r
391 if(inp & BTN_R) { sel+=24; if (sel > n-2) sel = n-2; }
\r
392 if(inp & BTN_PLAY) { // enter dir/select
\r
393 if (namelist[sel+1]->d_type == DT_REG) {
\r
394 strcpy(romFileName, curr_path);
\r
395 strcat(romFileName, "/");
\r
396 strcat(romFileName, namelist[sel+1]->d_name);
\r
399 } else if (namelist[sel+1]->d_type == DT_DIR) {
\r
400 int newlen = strlen(curr_path) + strlen(namelist[sel+1]->d_name) + 2;
\r
401 char *p, *newdir = malloc(newlen);
\r
402 if (strcmp(namelist[sel+1]->d_name, "..") == 0) {
\r
403 char *start = curr_path;
\r
404 p = start + strlen(start) - 1;
\r
405 while (*p == '/' && p > start) p--;
\r
406 while (*p != '/' && p > start) p--;
\r
407 if (p <= start) strcpy(newdir, "/");
\r
408 else { strncpy(newdir, start, p-start); newdir[p-start] = 0; }
\r
410 strcpy(newdir, curr_path);
\r
411 p = newdir + strlen(newdir) - 1;
\r
412 while (*p == '/' && p >= newdir) *p-- = 0;
\r
413 strcat(newdir, "/");
\r
414 strcat(newdir, namelist[sel+1]->d_name);
\r
416 ret = romsel_loop(newdir);
\r
421 if(inp & BTN_STOP) break; // cancel
\r
425 while(n--) free(namelist[n]);
\r
432 static char *romsel_loop(char *curr_path)
\r
438 // ------------ debug menu ------------
\r
440 char *debugString(void);
\r
442 static void draw_debug(void)
\r
444 char *p, *str = debugString();
\r
447 menu_draw_begin(1);
\r
450 for (line = 0; line < 24; line++)
\r
452 while (*p && *p != '\n') p++;
\r
454 if (len > 55) len = 55;
\r
455 smalltext_out16_lim(1, line*10, str, 0xffff, len);
\r
456 if (*p == 0) break;
\r
462 static void debug_menu_loop(void)
\r
465 wait_for_input(BTN_PLAY|BTN_STOP);
\r
468 // ------------ patch/gg menu ------------
\r
470 static void draw_patchlist(int sel)
\r
472 int start, i, pos, active;
\r
476 menu_draw_begin(1);
\r
478 for (i = 0; i < PicoPatchCount; i++) {
\r
480 if (pos < 0) continue;
\r
481 if (pos > 23) break;
\r
482 active = PicoPatches[i].active;
\r
483 smalltext_out16_lim(14, pos*10, active ? "ON " : "OFF", active ? 0xfff6 : 0xffff, 3);
\r
484 smalltext_out16_lim(14+6*4, pos*10, PicoPatches[i].name, active ? 0xfff6 : 0xffff, 53-6);
\r
487 if (pos < 24) smalltext_out16_lim(14, pos*10, "done", 0xffff, 4);
\r
489 text_out16(5, 120, ">");
\r
494 static void patches_menu_loop(void)
\r
497 unsigned long inp = 0;
\r
501 draw_patchlist(menu_sel);
\r
502 inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_LEFT|BTN_RIGHT|BTN_L|BTN_R|BTN_PLAY|BTN_STOP);
\r
503 if(inp & BTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = PicoPatchCount; }
\r
504 if(inp & BTN_DOWN) { menu_sel++; if (menu_sel > PicoPatchCount) menu_sel = 0; }
\r
505 if(inp &(BTN_LEFT|BTN_L)) { menu_sel-=10; if (menu_sel < 0) menu_sel = 0; }
\r
506 if(inp &(BTN_RIGHT|BTN_R)) { menu_sel+=10; if (menu_sel > PicoPatchCount) menu_sel = PicoPatchCount; }
\r
507 if(inp & BTN_PLAY) { // action
\r
508 if (menu_sel < PicoPatchCount)
\r
509 PicoPatches[menu_sel].active = !PicoPatches[menu_sel].active;
\r
512 if(inp & BTN_STOP) return;
\r
517 // ------------ savestate loader ------------
\r
519 static int state_slot_flags = 0;
\r
521 static void state_check_slots(void)
\r
525 state_slot_flags = 0;
\r
527 for (slot = 0; slot < 10; slot++)
\r
529 if (emu_checkSaveFile(slot))
\r
531 state_slot_flags |= 1 << slot;
\r
536 static void draw_savestate_bg(int slot)
\r
538 struct PicoVideo tmp_pv;
\r
539 unsigned short tmp_cram[0x40];
\r
540 unsigned short tmp_vsram[0x40];
\r
541 void *tmp_vram, *file;
\r
544 fname = emu_GetSaveFName(1, 0, slot);
\r
545 if (!fname) return;
\r
547 tmp_vram = malloc(sizeof(Pico.vram));
\r
548 if (tmp_vram == NULL) return;
\r
550 memcpy(tmp_vram, Pico.vram, sizeof(Pico.vram));
\r
551 memcpy(tmp_cram, Pico.cram, sizeof(Pico.cram));
\r
552 memcpy(tmp_vsram, Pico.vsram, sizeof(Pico.vsram));
\r
553 memcpy(&tmp_pv, &Pico.video, sizeof(Pico.video));
\r
555 if (strcmp(fname + strlen(fname) - 3, ".gz") == 0) {
\r
556 file = gzopen(fname, "rb");
\r
557 emu_setSaveStateCbs(1);
\r
559 file = fopen(fname, "rb");
\r
560 emu_setSaveStateCbs(0);
\r
565 PicoCdLoadStateGfx(file);
\r
567 areaSeek(file, 0x10020, SEEK_SET); // skip header and RAM in state file
\r
568 areaRead(Pico.vram, 1, sizeof(Pico.vram), file);
\r
569 areaSeek(file, 0x2000, SEEK_CUR);
\r
570 areaRead(Pico.cram, 1, sizeof(Pico.cram), file);
\r
571 areaRead(Pico.vsram, 1, sizeof(Pico.vsram), file);
\r
572 areaSeek(file, 0x221a0, SEEK_SET);
\r
573 areaRead(&Pico.video, 1, sizeof(Pico.video), file);
\r
579 menu_prepare_bg(1);
\r
581 memcpy(Pico.vram, tmp_vram, sizeof(Pico.vram));
\r
582 memcpy(Pico.cram, tmp_cram, sizeof(Pico.cram));
\r
583 memcpy(Pico.vsram, tmp_vsram, sizeof(Pico.vsram));
\r
584 memcpy(&Pico.video, &tmp_pv, sizeof(Pico.video));
\r
588 static void draw_savestate_menu(int menu_sel, int is_loading)
\r
590 int tl_x = 25, tl_y = 60, y, i;
\r
592 if (state_slot_flags & (1 << menu_sel))
\r
593 draw_savestate_bg(menu_sel);
\r
594 menu_draw_begin(1);
\r
596 text_out16(tl_x, 30, is_loading ? "Load state" : "Save state");
\r
598 menu_draw_selection(tl_x - 16, tl_y + menu_sel*10, 108);
\r
600 /* draw all 10 slots */
\r
602 for (i = 0; i < 10; i++, y+=10)
\r
604 text_out16(tl_x, y, "SLOT %i (%s)", i, (state_slot_flags & (1 << i)) ? "USED" : "free");
\r
606 text_out16(tl_x, y, "back");
\r
611 static int savestate_menu_loop(int is_loading)
\r
613 static int menu_sel = 10;
\r
614 int menu_sel_max = 10;
\r
615 unsigned long inp = 0;
\r
617 state_check_slots();
\r
621 draw_savestate_menu(menu_sel, is_loading);
\r
622 inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_PLAY|BTN_STOP);
\r
623 if(inp & BTN_UP ) {
\r
625 menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max;
\r
626 } while (!(state_slot_flags & (1 << menu_sel)) && menu_sel != menu_sel_max && is_loading);
\r
628 if(inp & BTN_DOWN) {
\r
630 menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0;
\r
631 } while (!(state_slot_flags & (1 << menu_sel)) && menu_sel != menu_sel_max && is_loading);
\r
633 if(inp & BTN_PLAY) { // save/load
\r
634 if (menu_sel < 10) {
\r
635 state_slot = menu_sel;
\r
636 PicoStateProgressCB = emu_stateCb; /* also suitable for menu */
\r
637 if (emu_SaveLoadGame(is_loading, 0)) {
\r
638 strcpy(menuErrorMsg, is_loading ? "Load failed" : "Save failed");
\r
644 if(inp & BTN_STOP) return 1;
\r
648 // -------------- key config --------------
\r
650 static char *action_binds(int player_idx, int action_mask)
\r
652 static char strkeys[32*5];
\r
656 for (i = 0; i < 32; i++) // i is key index
\r
658 if (currentConfig.KeyBinds[i] & action_mask)
\r
660 if (player_idx >= 0 && ((currentConfig.KeyBinds[i] >> 16) & 3) != player_idx) continue;
\r
661 if (strkeys[0]) { strcat(strkeys, " + "); strcat(strkeys, gizKeyNames[i]); break; }
\r
662 else strcpy(strkeys, gizKeyNames[i]);
\r
669 static void unbind_action(int action)
\r
673 for (i = 0; i < 32; i++)
\r
674 currentConfig.KeyBinds[i] &= ~action;
\r
677 static int count_bound_keys(int action, int pl_idx)
\r
681 for (i = 0; i < 32; i++)
\r
683 if (pl_idx >= 0 && (currentConfig.KeyBinds[i]&0x30000) != (pl_idx<<16)) continue;
\r
684 if (currentConfig.KeyBinds[i] & action) keys++;
\r
690 static void draw_key_config(const me_bind_action *opts, int opt_cnt, int player_idx, int sel)
\r
692 int x, y, tl_y = 40, i;
\r
694 menu_draw_begin(1);
\r
695 if (player_idx >= 0) {
\r
696 text_out16(80, 20, "Player %i controls", player_idx + 1);
\r
699 text_out16(80, 20, "Emulator controls");
\r
703 menu_draw_selection(x - 16, tl_y + sel*10, (player_idx >= 0) ? 66 : 130);
\r
706 for (i = 0; i < opt_cnt; i++, y+=10)
\r
707 text_out16(x, y, "%s : %s", opts[i].name, action_binds(player_idx, opts[i].mask));
\r
709 text_out16(x, y, "Done");
\r
711 if (sel < opt_cnt) {
\r
712 text_out16(30, 180, "Press a button to bind/unbind");
\r
713 text_out16(30, 190, "Use HOME to clear");
\r
714 text_out16(30, 200, "To bind UP/DOWN, hold HOME");
\r
715 text_out16(30, 210, "Select \"Done\" to exit");
\r
717 text_out16(30, 190, "Use Options -> Save cfg");
\r
718 text_out16(30, 200, "to save controls");
\r
719 text_out16(30, 210, "Press PLAY or STOP to exit");
\r
724 static void key_config_loop(const me_bind_action *opts, int opt_cnt, int player_idx)
\r
726 int sel = 0, menu_sel_max = opt_cnt, prev_select = 0, i;
\r
727 unsigned long inp = 0;
\r
731 draw_key_config(opts, opt_cnt, player_idx, sel);
\r
732 inp = wait_for_input(CONFIGURABLE_KEYS|BTN_HOME);
\r
733 if (!(inp & BTN_HOME)) {
\r
735 if(inp & BTN_UP ) { sel--; if (sel < 0) sel = menu_sel_max; continue; }
\r
736 if(inp & BTN_DOWN) { sel++; if (sel > menu_sel_max) sel = 0; continue; }
\r
738 if (sel >= opt_cnt) {
\r
739 if (inp & (BTN_PLAY|BTN_STOP)) break;
\r
742 // if we are here, we want to bind/unbind something
\r
743 if ((inp & BTN_HOME) && !prev_select)
\r
744 unbind_action(opts[sel].mask);
\r
745 prev_select = inp & BTN_HOME;
\r
746 inp &= CONFIGURABLE_KEYS;
\r
748 for (i = 0; i < 32; i++)
\r
749 if (inp & (1 << i)) {
\r
750 if (count_bound_keys(opts[sel].mask, player_idx) >= 2)
\r
751 currentConfig.KeyBinds[i] &= ~opts[sel].mask; // allow to unbind only
\r
752 else currentConfig.KeyBinds[i] ^= opts[sel].mask;
\r
753 if (player_idx >= 0 && (currentConfig.KeyBinds[i] & opts[sel].mask)) {
\r
754 currentConfig.KeyBinds[i] &= ~(3 << 16);
\r
755 currentConfig.KeyBinds[i] |= player_idx << 16;
\r
761 static void draw_kc_sel(int menu_sel)
\r
763 int tl_x = 25+40, tl_y = 60, y;
\r
766 menu_draw_begin(1);
\r
767 menu_draw_selection(tl_x - 16, tl_y + menu_sel*10, 138);
\r
769 text_out16(tl_x, y, "Player 1");
\r
770 text_out16(tl_x, (y+=10), "Player 2");
\r
771 text_out16(tl_x, (y+=10), "Emulator controls");
\r
772 text_out16(tl_x, (y+=10), "Done");
\r
778 // player2_flag, ?, ?, ?, ?, ?, ?, menu
\r
779 // "NEXT SAVE SLOT", "PREV SAVE SLOT", "SWITCH RENDERER", "SAVE STATE",
\r
780 // "LOAD STATE", "VOLUME UP", "VOLUME DOWN", "DONE"
\r
781 me_bind_action emuctrl_actions[] =
\r
783 { "Load State ", 1<<28 },
\r
784 { "Save State ", 1<<27 },
\r
785 { "Prev Save Slot ", 1<<25 },
\r
786 { "Next Save Slot ", 1<<24 },
\r
787 { "Switch Renderer", 1<<26 },
\r
788 { "Volume Down ", 1<<30 },
\r
789 { "Volume Up ", 1<<29 },
\r
793 static void kc_sel_loop(void)
\r
795 int menu_sel = 3, menu_sel_max = 3;
\r
796 unsigned long inp = 0;
\r
797 int is_6button = currentConfig.PicoOpt & 0x020;
\r
801 draw_kc_sel(menu_sel);
\r
802 inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_PLAY|BTN_STOP);
\r
803 if (inp & BTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }
\r
804 if (inp & BTN_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }
\r
805 if (inp & BTN_PLAY) {
\r
806 switch (menu_sel) {
\r
807 case 0: key_config_loop(me_ctrl_actions, is_6button ? 12 : 8, 0); return;
\r
808 case 1: key_config_loop(me_ctrl_actions, is_6button ? 12 : 8, 1); return;
\r
809 case 2: key_config_loop(emuctrl_actions,
\r
810 sizeof(emuctrl_actions)/sizeof(emuctrl_actions[0]) - 1, -1); return;
\r
811 case 3: if (!rom_loaded) emu_WriteConfig(0); return;
\r
815 if (inp & BTN_STOP) return;
\r
820 // --------- sega/mega cd options ----------
\r
822 menu_entry cdopt_entries[] =
\r
824 { NULL, MB_NONE, MA_CDOPT_TESTBIOS_USA, NULL, 0, 0, 0, 1 },
\r
825 { NULL, MB_NONE, MA_CDOPT_TESTBIOS_EUR, NULL, 0, 0, 0, 1 },
\r
826 { NULL, MB_NONE, MA_CDOPT_TESTBIOS_JAP, NULL, 0, 0, 0, 1 },
\r
827 { "CD LEDs", MB_ONOFF, MA_CDOPT_LEDS, ¤tConfig.EmuOpt, 0x0400, 0, 0, 1 },
\r
828 { "CDDA audio (using mp3s)", MB_ONOFF, MA_CDOPT_CDDA, ¤tConfig.PicoOpt, 0x0800, 0, 0, 1 },
\r
829 { "PCM audio", MB_ONOFF, MA_CDOPT_PCM, ¤tConfig.PicoOpt, 0x0400, 0, 0, 1 },
\r
830 { NULL, MB_NONE, MA_CDOPT_READAHEAD, NULL, 0, 0, 0, 1 },
\r
831 { "SaveRAM cart", MB_ONOFF, MA_CDOPT_SAVERAM, ¤tConfig.PicoOpt, 0x8000, 0, 0, 1 },
\r
832 { "Scale/Rot. fx (slow)", MB_ONOFF, MA_CDOPT_SCALEROT_CHIP,¤tConfig.PicoOpt, 0x1000, 0, 0, 1 },
\r
833 { "Better sync (slow)", MB_ONOFF, MA_CDOPT_BETTER_SYNC, ¤tConfig.PicoOpt, 0x2000, 0, 0, 1 },
\r
834 { "done", MB_NONE, MA_CDOPT_DONE, NULL, 0, 0, 0, 1 },
\r
837 #define CDOPT_ENTRY_COUNT (sizeof(cdopt_entries) / sizeof(cdopt_entries[0]))
\r
840 struct bios_names_t
\r
842 char us[32], eu[32], jp[32];
\r
845 static void menu_cdopt_cust_draw(const menu_entry *entry, int x, int y, void *param)
\r
847 struct bios_names_t *bios_names = param;
\r
852 case MA_CDOPT_TESTBIOS_USA: text_out16(x, y, "USA BIOS: %s", bios_names->us); break;
\r
853 case MA_CDOPT_TESTBIOS_EUR: text_out16(x, y, "EUR BIOS: %s", bios_names->eu); break;
\r
854 case MA_CDOPT_TESTBIOS_JAP: text_out16(x, y, "JAP BIOS: %s", bios_names->jp); break;
\r
855 case MA_CDOPT_READAHEAD:
\r
856 if (PicoCDBuffers > 1) sprintf(ra_buff, "%5iK", PicoCDBuffers * 2);
\r
857 else strcpy(ra_buff, " OFF");
\r
858 text_out16(x, y, "ReadAhead buffer %s", ra_buff);
\r
864 static void draw_cd_menu_options(int menu_sel, struct bios_names_t *bios_names)
\r
866 int tl_x = 25, tl_y = 60;
\r
867 menu_id selected_id;
\r
870 if (PicoCDBuffers > 1) sprintf(ra_buff, "%5iK", PicoCDBuffers * 2);
\r
871 else strcpy(ra_buff, " OFF");
\r
873 menu_draw_begin(1);
\r
875 menu_draw_selection(tl_x - 16, tl_y + menu_sel*10, 246);
\r
877 me_draw(cdopt_entries, CDOPT_ENTRY_COUNT, tl_x, tl_y, menu_cdopt_cust_draw, bios_names);
\r
879 selected_id = me_index2id(cdopt_entries, CDOPT_ENTRY_COUNT, menu_sel);
\r
880 if ((selected_id == MA_CDOPT_TESTBIOS_USA && strcmp(bios_names->us, "NOT FOUND")) ||
\r
881 (selected_id == MA_CDOPT_TESTBIOS_EUR && strcmp(bios_names->eu, "NOT FOUND")) ||
\r
882 (selected_id == MA_CDOPT_TESTBIOS_JAP && strcmp(bios_names->jp, "NOT FOUND")))
\r
883 text_out16(tl_x, 210, "Press start to test selected BIOS");
\r
888 static void cd_menu_loop_options(void)
\r
890 static int menu_sel = 0;
\r
891 int menu_sel_max = 10;
\r
892 unsigned long inp = 0;
\r
893 struct bios_names_t bios_names;
\r
894 menu_id selected_id;
\r
897 if (emu_findBios(4, &bios)) { // US
\r
898 for (p = bios+strlen(bios)-1; p > bios && *p != '/'; p--); p++;
\r
899 strncpy(bios_names.us, p, sizeof(bios_names.us)); bios_names.us[sizeof(bios_names.us)-1] = 0;
\r
900 } else strcpy(bios_names.us, "NOT FOUND");
\r
902 if (emu_findBios(8, &bios)) { // EU
\r
903 for (p = bios+strlen(bios)-1; p > bios && *p != '/'; p--); p++;
\r
904 strncpy(bios_names.eu, p, sizeof(bios_names.eu)); bios_names.eu[sizeof(bios_names.eu)-1] = 0;
\r
905 } else strcpy(bios_names.eu, "NOT FOUND");
\r
907 if (emu_findBios(1, &bios)) { // JP
\r
908 for (p = bios+strlen(bios)-1; p > bios && *p != '/'; p--); p++;
\r
909 strncpy(bios_names.jp, p, sizeof(bios_names.jp)); bios_names.jp[sizeof(bios_names.jp)-1] = 0;
\r
910 } else strcpy(bios_names.jp, "NOT FOUND");
\r
914 draw_cd_menu_options(menu_sel, &bios_names);
\r
915 inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_LEFT|BTN_RIGHT|BTN_PLAY|BTN_STOP|BTN_REW);
\r
916 if (inp & BTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }
\r
917 if (inp & BTN_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }
\r
918 selected_id = me_index2id(cdopt_entries, CDOPT_ENTRY_COUNT, menu_sel);
\r
919 if (inp & (BTN_LEFT|BTN_RIGHT)) { // multi choise
\r
920 if (!me_process(cdopt_entries, CDOPT_ENTRY_COUNT, selected_id, (inp&BTN_RIGHT) ? 1 : 0) &&
\r
921 selected_id == MA_CDOPT_READAHEAD) {
\r
922 if (inp & BTN_LEFT) {
\r
923 PicoCDBuffers >>= 1;
\r
924 if (PicoCDBuffers < 2) PicoCDBuffers = 0;
\r
926 if (PicoCDBuffers < 2) PicoCDBuffers = 2;
\r
927 else PicoCDBuffers <<= 1;
\r
928 if (PicoCDBuffers > 8*1024) PicoCDBuffers = 8*1024; // 16M
\r
932 if (inp & BTN_PLAY) { // toggleable options
\r
933 if (!me_process(cdopt_entries, CDOPT_ENTRY_COUNT, selected_id, 1) &&
\r
934 selected_id == MA_CDOPT_DONE) {
\r
937 switch (selected_id) { // BIOS testers
\r
938 case MA_CDOPT_TESTBIOS_USA:
\r
939 if (emu_findBios(4, &bios)) { // test US
\r
940 strcpy(romFileName, bios);
\r
941 engineState = PGS_ReloadRom;
\r
945 case MA_CDOPT_TESTBIOS_EUR:
\r
946 if (emu_findBios(8, &bios)) { // test EU
\r
947 strcpy(romFileName, bios);
\r
948 engineState = PGS_ReloadRom;
\r
952 case MA_CDOPT_TESTBIOS_JAP:
\r
953 if (emu_findBios(1, &bios)) { // test JP
\r
954 strcpy(romFileName, bios);
\r
955 engineState = PGS_ReloadRom;
\r
963 if (inp & (BTN_STOP|BTN_REW)) return;
\r
968 // --------- advanced options ----------
\r
970 menu_entry opt2_entries[] =
\r
972 { "Emulate Z80", MB_ONOFF, MA_OPT2_ENABLE_Z80, ¤tConfig.PicoOpt,0x0004, 0, 0, 1 },
\r
973 { "Emulate YM2612 (FM)", MB_ONOFF, MA_OPT2_ENABLE_YM2612, ¤tConfig.PicoOpt,0x0001, 0, 0, 1 },
\r
974 { "Emulate SN76496 (PSG)", MB_ONOFF, MA_OPT2_ENABLE_SN76496,¤tConfig.PicoOpt,0x0002, 0, 0, 1 },
\r
975 { "Double buffering", MB_ONOFF, MA_OPT2_DBLBUFF, ¤tConfig.EmuOpt, 0x8000, 0, 0, 1 },
\r
976 { "Wait for V-sync (slow)", MB_ONOFF, MA_OPT2_VSYNC, ¤tConfig.EmuOpt, 0x2000, 0, 0, 1 },
\r
977 { "gzip savestates", MB_ONOFF, MA_OPT2_GZIP_STATES, ¤tConfig.EmuOpt, 0x0008, 0, 0, 1 },
\r
978 { "Don't save last used ROM", MB_ONOFF, MA_OPT2_NO_LAST_ROM, ¤tConfig.EmuOpt, 0x0020, 0, 0, 1 },
\r
979 { "done", MB_NONE, MA_OPT2_DONE, NULL, 0, 0, 0, 1 },
\r
982 #define OPT2_ENTRY_COUNT (sizeof(opt2_entries) / sizeof(opt2_entries[0]))
\r
985 static void draw_amenu_options(int menu_sel)
\r
987 int tl_x = 25, tl_y = 50;
\r
989 menu_draw_begin(1);
\r
991 menu_draw_selection(tl_x - 16, tl_y + menu_sel*10, 252);
\r
993 me_draw(opt2_entries, OPT2_ENTRY_COUNT, tl_x, tl_y, NULL, NULL);
\r
998 static void amenu_loop_options(void)
\r
1000 static int menu_sel = 0;
\r
1002 unsigned long inp = 0;
\r
1003 menu_id selected_id;
\r
1005 menu_sel_max = me_count_enabled(opt2_entries, OPT2_ENTRY_COUNT) - 1;
\r
1009 draw_amenu_options(menu_sel);
\r
1010 inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_LEFT|BTN_RIGHT|BTN_PLAY|BTN_STOP|BTN_REW);
\r
1011 if (inp & BTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }
\r
1012 if (inp & BTN_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }
\r
1013 selected_id = me_index2id(opt2_entries, OPT2_ENTRY_COUNT, menu_sel);
\r
1014 if (inp & (BTN_LEFT|BTN_RIGHT)) { // multi choise
\r
1015 if (!me_process(opt2_entries, OPT2_ENTRY_COUNT, selected_id, (inp&BTN_RIGHT) ? 1 : 0) &&
\r
1016 selected_id == MA_OPT2_GAMMA) {
\r
1017 while ((inp = Framework_PollGetButtons()) & (BTN_LEFT|BTN_RIGHT)) {
\r
1018 currentConfig.gamma += (inp & BTN_LEFT) ? -1 : 1;
\r
1019 if (currentConfig.gamma < 1) currentConfig.gamma = 1;
\r
1020 if (currentConfig.gamma > 300) currentConfig.gamma = 300;
\r
1021 draw_amenu_options(menu_sel);
\r
1026 if (inp & BTN_PLAY) { // toggleable options
\r
1027 if (!me_process(opt2_entries, OPT2_ENTRY_COUNT, selected_id, 1) &&
\r
1028 selected_id == MA_OPT2_DONE) {
\r
1032 if (inp & (BTN_STOP|BTN_REW)) return;
\r
1036 // -------------- options --------------
\r
1039 menu_entry opt_entries[] =
\r
1041 { NULL, MB_NONE, MA_OPT_RENDERER, NULL, 0, 0, 0, 1 },
\r
1042 { "Scanline mode (faster)", MB_ONOFF, MA_OPT_INTERLACED, ¤tConfig.EmuOpt, 0x4000, 0, 0, 1 },
\r
1043 { "Scale low res mode", MB_ONOFF, MA_OPT_SCALING, ¤tConfig.scaling, 0x0001, 0, 3, 1 },
\r
1044 { "Accurate timing (slower)", MB_ONOFF, MA_OPT_ACC_TIMING, ¤tConfig.PicoOpt, 0x0040, 0, 0, 1 },
\r
1045 { "Accurate sprites (slower)", MB_ONOFF, MA_OPT_ACC_SPRITES, ¤tConfig.PicoOpt, 0x0080, 0, 0, 1 },
\r
1046 { "Show FPS", MB_ONOFF, MA_OPT_SHOW_FPS, ¤tConfig.EmuOpt, 0x0002, 0, 0, 1 },
\r
1047 { NULL, MB_RANGE, MA_OPT_FRAMESKIP, ¤tConfig.Frameskip, 0, -1, 16, 1 },
\r
1048 { "Enable sound", MB_ONOFF, MA_OPT_ENABLE_SOUND, ¤tConfig.EmuOpt, 0x0004, 0, 0, 1 },
\r
1049 { NULL, MB_NONE, MA_OPT_SOUND_QUALITY, NULL, 0, 0, 0, 1 },
\r
1050 { "6 button pad", MB_ONOFF, MA_OPT_6BUTTON_PAD, ¤tConfig.PicoOpt, 0x0020, 0, 0, 1 },
\r
1051 { NULL, MB_NONE, MA_OPT_REGION, NULL, 0, 0, 0, 1 },
\r
1052 { "Use SRAM/BRAM savestates", MB_ONOFF, MA_OPT_SRAM_STATES, ¤tConfig.EmuOpt, 0x0001, 0, 0, 1 },
\r
1053 { NULL, MB_NONE, MA_OPT_CONFIRM_STATES,NULL, 0, 0, 0, 1 },
\r
1054 { "Save slot", MB_RANGE, MA_OPT_SAVE_SLOT, &state_slot, 0, 0, 9, 1 },
\r
1055 { "[Sega/Mega CD options]", MB_NONE, MA_OPT_SCD_OPTS, NULL, 0, 0, 0, 1 },
\r
1056 { "[advanced options]", MB_NONE, MA_OPT_ADV_OPTS, NULL, 0, 0, 0, 1 },
\r
1057 { NULL, MB_NONE, MA_OPT_SAVECFG, NULL, 0, 0, 0, 1 },
\r
1058 { "Save cfg for current game only",MB_NONE,MA_OPT_SAVECFG_GAME,NULL, 0, 0, 0, 1 },
\r
1059 { NULL, MB_NONE, MA_OPT_LOADCFG, NULL, 0, 0, 0, 1 },
\r
1062 #define OPT_ENTRY_COUNT (sizeof(opt_entries) / sizeof(opt_entries[0]))
\r
1065 static void menu_opt_cust_draw(const menu_entry *entry, int x, int y, void *param)
\r
1067 char *str, str24[24];
\r
1069 switch (entry->id)
\r
1071 case MA_OPT_RENDERER:
\r
1072 if (currentConfig.PicoOpt&0x10)
\r
1073 str = " 8bit fast";
\r
1074 else if (currentConfig.EmuOpt&0x80)
\r
1075 str = "16bit accurate";
\r
1077 str = " 8bit accurate";
\r
1078 text_out16(x, y, "Renderer: %s", str);
\r
1080 case MA_OPT_FRAMESKIP:
\r
1081 if (currentConfig.Frameskip < 0)
\r
1082 strcpy(str24, "Auto");
\r
1083 else sprintf(str24, "%i", currentConfig.Frameskip);
\r
1084 text_out16(x, y, "Frameskip %s", str24);
\r
1086 case MA_OPT_SOUND_QUALITY:
\r
1087 str = (currentConfig.PicoOpt&0x08)?"stereo":"mono";
\r
1088 text_out16(x, y, "Sound Quality: %5iHz %s", currentConfig.PsndRate, str);
\r
1090 case MA_OPT_REGION:
\r
1091 text_out16(x, y, "Region: %s", me_region_name(PicoRegionOverride, PicoAutoRgnOrder));
\r
1093 case MA_OPT_CONFIRM_STATES:
\r
1094 switch ((currentConfig.EmuOpt >> 9) & 5) {
\r
1095 default: str = "OFF"; break;
\r
1096 case 1: str = "writes"; break;
\r
1097 case 4: str = "loads"; break;
\r
1098 case 5: str = "both"; break;
\r
1100 text_out16(x, y, "Confirm savestate %s", str);
\r
1102 case MA_OPT_SAVECFG:
\r
1104 if (config_slot != 0) sprintf(str24, " (profile: %i)", config_slot);
\r
1105 text_out16(x, y, "Save cfg as default%s", str24);
\r
1107 case MA_OPT_LOADCFG:
\r
1108 text_out16(x, y, "Load cfg from profile %i", config_slot);
\r
1111 lprintf("%s: unimplemented (%i)\n", __FUNCTION__, entry->id);
\r
1118 static void draw_menu_options(int menu_sel)
\r
1120 int tl_x = 25, tl_y = 24;
\r
1122 menu_draw_begin(1);
\r
1124 menu_draw_selection(tl_x - 16, tl_y + menu_sel*10, 284);
\r
1126 me_draw(opt_entries, OPT_ENTRY_COUNT, tl_x, tl_y, menu_opt_cust_draw, NULL);
\r
1131 static int sndrate_prevnext(int rate, int dir)
\r
1133 int i, rates[] = { 11025, 22050, 44100 };
\r
1135 for (i = 0; i < 5; i++)
\r
1136 if (rates[i] == rate) break;
\r
1138 i += dir ? 1 : -1;
\r
1139 if (i > 2) return dir ? 44100 : 22050;
\r
1140 if (i < 0) return dir ? 22050 : 11025;
\r
1144 static void region_prevnext(int right)
\r
1146 // jp_ntsc=1, jp_pal=2, usa=4, eu=8
\r
1147 static int rgn_orders[] = { 0x148, 0x184, 0x814, 0x418, 0x841, 0x481 };
\r
1150 if (!PicoRegionOverride) {
\r
1151 for (i = 0; i < 6; i++)
\r
1152 if (rgn_orders[i] == PicoAutoRgnOrder) break;
\r
1153 if (i < 5) PicoAutoRgnOrder = rgn_orders[i+1];
\r
1154 else PicoRegionOverride=1;
\r
1156 else PicoRegionOverride<<=1;
\r
1157 if (PicoRegionOverride > 8) PicoRegionOverride = 8;
\r
1159 if (!PicoRegionOverride) {
\r
1160 for (i = 0; i < 6; i++)
\r
1161 if (rgn_orders[i] == PicoAutoRgnOrder) break;
\r
1162 if (i > 0) PicoAutoRgnOrder = rgn_orders[i-1];
\r
1164 else PicoRegionOverride>>=1;
\r
1168 static void menu_options_save(void)
\r
1170 PicoOpt = currentConfig.PicoOpt;
\r
1171 PsndRate = currentConfig.PsndRate;
\r
1172 if (PicoRegionOverride) {
\r
1173 // force setting possibly changed..
\r
1174 Pico.m.pal = (PicoRegionOverride == 2 || PicoRegionOverride == 8) ? 1 : 0;
\r
1176 if (!(PicoOpt & 0x20)) {
\r
1177 // unbind XYZ MODE, just in case
\r
1178 unbind_action(0xf00);
\r
1182 static int menu_loop_options(void)
\r
1184 static int menu_sel = 0;
\r
1185 int menu_sel_max, ret;
\r
1186 unsigned long inp = 0;
\r
1187 menu_id selected_id;
\r
1189 currentConfig.PicoOpt = PicoOpt;
\r
1190 currentConfig.PsndRate = PsndRate;
\r
1192 me_enable(opt_entries, OPT_ENTRY_COUNT, MA_OPT_SAVECFG_GAME, rom_loaded);
\r
1193 me_enable(opt_entries, OPT_ENTRY_COUNT, MA_OPT_LOADCFG, config_slot != config_slot_current);
\r
1194 menu_sel_max = me_count_enabled(opt_entries, OPT_ENTRY_COUNT) - 1;
\r
1195 if (menu_sel > menu_sel_max) menu_sel = menu_sel_max;
\r
1199 draw_menu_options(menu_sel);
\r
1200 inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_LEFT|BTN_RIGHT|BTN_PLAY|BTN_STOP|BTN_REW);
\r
1201 if (inp & BTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }
\r
1202 if (inp & BTN_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }
\r
1203 selected_id = me_index2id(opt_entries, OPT_ENTRY_COUNT, menu_sel);
\r
1204 if (inp & (BTN_LEFT|BTN_RIGHT)) { // multi choise
\r
1205 if (!me_process(opt_entries, OPT_ENTRY_COUNT, selected_id, (inp&BTN_RIGHT) ? 1 : 0)) {
\r
1206 switch (selected_id) {
\r
1207 case MA_OPT_RENDERER:
\r
1208 if (inp & BTN_LEFT) {
\r
1209 if ((currentConfig.PicoOpt&0x10) || !(currentConfig.EmuOpt &0x80)) {
\r
1210 currentConfig.PicoOpt&= ~0x10;
\r
1211 currentConfig.EmuOpt |= 0x80;
\r
1214 if (!(currentConfig.PicoOpt&0x10) || (currentConfig.EmuOpt &0x80)) {
\r
1215 currentConfig.PicoOpt|= 0x10;
\r
1216 currentConfig.EmuOpt &= ~0x80;
\r
1220 case MA_OPT_SOUND_QUALITY:
\r
1221 if ((inp & BTN_RIGHT) && currentConfig.PsndRate == 44100 &&
\r
1222 !(currentConfig.PicoOpt&0x08))
\r
1224 currentConfig.PsndRate = 11025;
\r
1225 currentConfig.PicoOpt |= 8;
\r
1226 } else if ((inp & BTN_LEFT) && currentConfig.PsndRate == 11025 &&
\r
1227 (currentConfig.PicoOpt&0x08) && !(PicoMCD&1))
\r
1229 currentConfig.PsndRate = 44100;
\r
1230 currentConfig.PicoOpt &= ~8;
\r
1232 currentConfig.PsndRate = sndrate_prevnext(currentConfig.PsndRate, inp & BTN_RIGHT);
\r
1234 case MA_OPT_REGION:
\r
1235 region_prevnext(inp & BTN_RIGHT);
\r
1237 case MA_OPT_CONFIRM_STATES: {
\r
1238 int n = ((currentConfig.EmuOpt>>9)&1) | ((currentConfig.EmuOpt>>10)&2);
\r
1239 n += (inp & BTN_LEFT) ? -1 : 1;
\r
1240 if (n < 0) n = 0; else if (n > 3) n = 3;
\r
1241 n |= n << 1; n &= ~2;
\r
1242 currentConfig.EmuOpt &= ~0xa00;
\r
1243 currentConfig.EmuOpt |= n << 9;
\r
1246 case MA_OPT_SAVE_SLOT:
\r
1247 if (inp & BTN_RIGHT) {
\r
1248 state_slot++; if (state_slot > 9) state_slot = 0;
\r
1249 } else {state_slot--; if (state_slot < 0) state_slot = 9;
\r
1252 case MA_OPT_SAVECFG:
\r
1253 case MA_OPT_SAVECFG_GAME:
\r
1254 case MA_OPT_LOADCFG:
\r
1255 config_slot += (inp&BTN_RIGHT) ? 1 : -1;
\r
1256 if (config_slot > 9) config_slot = 0;
\r
1257 if (config_slot < 0) config_slot = 9;
\r
1258 me_enable(opt_entries, OPT_ENTRY_COUNT, MA_OPT_LOADCFG, config_slot != config_slot_current);
\r
1259 menu_sel_max = me_count_enabled(opt_entries, OPT_ENTRY_COUNT) - 1;
\r
1260 if (menu_sel > menu_sel_max) menu_sel = menu_sel_max;
\r
1263 //lprintf("%s: something unknown selected (%i)\n", __FUNCTION__, selected_id);
\r
1268 if (inp & BTN_PLAY) {
\r
1269 if (!me_process(opt_entries, OPT_ENTRY_COUNT, selected_id, 1))
\r
1271 switch (selected_id)
\r
1273 case MA_OPT_SCD_OPTS:
\r
1274 cd_menu_loop_options();
\r
1275 if (engineState == PGS_ReloadRom)
\r
1276 return 0; // test BIOS
\r
1278 case MA_OPT_ADV_OPTS:
\r
1279 amenu_loop_options();
\r
1281 case MA_OPT_SAVECFG: // done (update and write)
\r
1282 menu_options_save();
\r
1283 if (emu_WriteConfig(0)) strcpy(menuErrorMsg, "config saved");
\r
1284 else strcpy(menuErrorMsg, "failed to write config");
\r
1286 case MA_OPT_SAVECFG_GAME: // done (update and write for current game)
\r
1287 menu_options_save();
\r
1288 if (emu_WriteConfig(1)) strcpy(menuErrorMsg, "config saved");
\r
1289 else strcpy(menuErrorMsg, "failed to write config");
\r
1291 case MA_OPT_LOADCFG:
\r
1292 ret = emu_ReadConfig(1, 1);
\r
1293 if (!ret) ret = emu_ReadConfig(0, 1);
\r
1294 if (ret) strcpy(menuErrorMsg, "config loaded");
\r
1295 else strcpy(menuErrorMsg, "failed to load config");
\r
1298 //lprintf("%s: something unknown selected (%i)\n", __FUNCTION__, selected_id);
\r
1303 if(inp & (BTN_STOP|BTN_REW)) {
\r
1304 menu_options_save();
\r
1305 return 0; // done (update, no write)
\r
1310 // -------------- credits --------------
\r
1312 static void draw_menu_credits(void)
\r
1314 int tl_x = 15, tl_y = 64, y;
\r
1315 menu_draw_begin(1);
\r
1317 text_out16(tl_x, 20, "PicoDrive v" VERSION " (c) notaz, 2006,2007");
\r
1320 text_out16(tl_x, y, "Credits:");
\r
1321 text_out16(tl_x, (y+=10), "fDave: Cyclone 68000 core,");
\r
1322 text_out16(tl_x, (y+=10), " base code of PicoDrive");
\r
1323 text_out16(tl_x, (y+=10), "Reesy & FluBBa: DrZ80 core");
\r
1324 text_out16(tl_x, (y+=10), "MAME devs: YM2612 and SN76496 cores");
\r
1325 text_out16(tl_x, (y+=10), "Charles MacDonald: Genesis hw docs");
\r
1326 text_out16(tl_x, (y+=10), "Stephane Dallongeville:");
\r
1327 text_out16(tl_x, (y+=10), " opensource Gens");
\r
1328 text_out16(tl_x, (y+=10), "Haze: Genesis hw info");
\r
1329 text_out16(tl_x, (y+=10), "Reesy: kgsdk wrapper, sound code");
\r
1330 text_out16(tl_x, (y+=10), "jens.l: gizmondo hardware");
\r
1331 text_out16(tl_x, (y+=10), "ketchupgun: skin design");
\r
1337 // -------------- root menu --------------
\r
1339 menu_entry main_entries[] =
\r
1341 { "Resume game", MB_NONE, MA_MAIN_RESUME_GAME, NULL, 0, 0, 0, 0 },
\r
1342 { "Save State", MB_NONE, MA_MAIN_SAVE_STATE, NULL, 0, 0, 0, 0 },
\r
1343 { "Load State", MB_NONE, MA_MAIN_LOAD_STATE, NULL, 0, 0, 0, 0 },
\r
1344 { "Reset game", MB_NONE, MA_MAIN_RESET_GAME, NULL, 0, 0, 0, 0 },
\r
1345 { "Load new ROM/ISO", MB_NONE, MA_MAIN_LOAD_ROM, NULL, 0, 0, 0, 1 },
\r
1346 { "Change options", MB_NONE, MA_MAIN_OPTIONS, NULL, 0, 0, 0, 1 },
\r
1347 { "Configure controls", MB_NONE, MA_MAIN_CONTROLS, NULL, 0, 0, 0, 1 },
\r
1348 { "Credits", MB_NONE, MA_MAIN_CREDITS, NULL, 0, 0, 0, 1 },
\r
1349 { "Patches / GameGenie",MB_NONE, MA_MAIN_PATCHES, NULL, 0, 0, 0, 0 },
\r
1350 { "Exit", MB_NONE, MA_MAIN_EXIT, NULL, 0, 0, 0, 1 }
\r
1353 #define MAIN_ENTRY_COUNT (sizeof(main_entries) / sizeof(main_entries[0]))
\r
1355 static void draw_menu_root(int menu_sel)
\r
1357 const int tl_x = 70, tl_y = 70;
\r
1359 menu_draw_begin(1);
\r
1361 text_out16(tl_x, 20, "PicoDrive v" VERSION);
\r
1363 menu_draw_selection(tl_x - 16, tl_y + menu_sel*10, 146);
\r
1365 me_draw(main_entries, MAIN_ENTRY_COUNT, tl_x, tl_y, NULL, NULL);
\r
1368 if (menuErrorMsg[0]) {
\r
1369 memset((char *)menu_screen + 321*224*2, 0, 321*16*2);
\r
1370 text_out16(5, 226, menuErrorMsg);
\r
1376 static void menu_loop_root(void)
\r
1378 static int menu_sel = 0;
\r
1379 int ret, menu_sel_max;
\r
1380 unsigned long inp = 0;
\r
1382 me_enable(main_entries, MAIN_ENTRY_COUNT, MA_MAIN_RESUME_GAME, rom_loaded);
\r
1383 me_enable(main_entries, MAIN_ENTRY_COUNT, MA_MAIN_SAVE_STATE, rom_loaded);
\r
1384 me_enable(main_entries, MAIN_ENTRY_COUNT, MA_MAIN_LOAD_STATE, rom_loaded);
\r
1385 me_enable(main_entries, MAIN_ENTRY_COUNT, MA_MAIN_RESET_GAME, rom_loaded);
\r
1386 me_enable(main_entries, MAIN_ENTRY_COUNT, MA_MAIN_PATCHES, PicoPatches != NULL);
\r
1388 menu_sel_max = me_count_enabled(main_entries, MAIN_ENTRY_COUNT) - 1;
\r
1389 if (menu_sel > menu_sel_max) menu_sel = menu_sel_max;
\r
1391 /* make sure action buttons are not pressed on entering menu */
\r
1392 draw_menu_root(menu_sel);
\r
1394 while (Framework_PollGetButtons() & (BTN_PLAY|BTN_STOP|BTN_HOME)) Sleep(50);
\r
1398 draw_menu_root(menu_sel);
\r
1399 inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_PLAY|BTN_STOP|BTN_HOME|BTN_L|BTN_R);
\r
1400 if(inp & BTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }
\r
1401 if(inp & BTN_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }
\r
1402 if((inp & (BTN_L|BTN_R)) == (BTN_L|BTN_R)) debug_menu_loop();
\r
1403 if( inp & (BTN_HOME|BTN_STOP)) {
\r
1405 while (Framework_PollGetButtons() & (BTN_HOME|BTN_STOP)) Sleep(50); // wait until released
\r
1406 engineState = PGS_Running;
\r
1410 if(inp & BTN_PLAY) {
\r
1411 switch (me_index2id(main_entries, MAIN_ENTRY_COUNT, menu_sel))
\r
1413 case MA_MAIN_RESUME_GAME:
\r
1415 while (Framework_PollGetButtons() & BTN_PLAY) Sleep(50);
\r
1416 engineState = PGS_Running;
\r
1420 case MA_MAIN_SAVE_STATE:
\r
1422 if(savestate_menu_loop(0))
\r
1424 engineState = PGS_Running;
\r
1428 case MA_MAIN_LOAD_STATE:
\r
1430 if(savestate_menu_loop(1))
\r
1432 engineState = PGS_Running;
\r
1436 case MA_MAIN_RESET_GAME:
\r
1439 engineState = PGS_Running;
\r
1443 case MA_MAIN_LOAD_ROM:
\r
1445 char curr_path[MAX_PATH], *selfname;
\r
1447 if ( (tstf = fopen(currentConfig.lastRomFile, "rb")) )
\r
1450 strcpy(curr_path, currentConfig.lastRomFile);
\r
1453 getcwd(curr_path, MAX_PATH);
\r
1454 selfname = romsel_loop(curr_path);
\r
1456 lprintf("selected file: %s\n", selfname);
\r
1457 engineState = PGS_ReloadRom;
\r
1462 case MA_MAIN_OPTIONS:
\r
1463 ret = menu_loop_options();
\r
1464 if (ret == 1) continue; // status update
\r
1465 if (engineState == PGS_ReloadRom)
\r
1466 return; // BIOS test
\r
1468 case MA_MAIN_CONTROLS:
\r
1471 case MA_MAIN_CREDITS:
\r
1472 draw_menu_credits();
\r
1474 inp = wait_for_input(BTN_PLAY|BTN_STOP);
\r
1476 case MA_MAIN_EXIT:
\r
1477 engineState = PGS_Quit;
\r
1479 case MA_MAIN_PATCHES:
\r
1480 if (rom_loaded && PicoPatches) {
\r
1481 patches_menu_loop();
\r
1483 strcpy(menuErrorMsg, "Patches applied");
\r
1488 lprintf("%s: something unknown selected\n", __FUNCTION__);
\r
1492 menuErrorMsg[0] = 0; // clear error msg
\r
1496 // warning: alignment
\r
1497 static void menu_darken_bg(void *dst, const void *src, int pixels, int darker)
\r
1499 unsigned int *dest = dst;
\r
1500 const unsigned int *srce = src;
\r
1506 unsigned int p = *srce++;
\r
1507 *dest++ = ((p&0xf79ef79e)>>1) - ((p&0xc618c618)>>3);
\r
1514 unsigned int p = *srce++;
\r
1515 *dest++ = (p&0xf79ef79e)>>1;
\r
1520 static void menu_prepare_bg(int use_game_bg)
\r
1524 // darken the active framebuffer
\r
1525 if (giz_screen == NULL)
\r
1526 giz_screen = Framework2D_LockBuffer(1);
\r
1527 memset(bg_buffer, 0, 321*8*2);
\r
1528 menu_darken_bg(bg_buffer + 321*8*2, (char *)giz_screen + 321*8*2, 321*224, 1);
\r
1529 memset(bg_buffer + 321*232*2, 0, 321*8*2);
\r
1530 Framework2D_UnlockBuffer();
\r
1531 giz_screen = NULL;
\r
1536 // should really only happen once, on startup..
\r
1537 readpng(bg_buffer, "skin/background.png", READPNG_BG);
\r
1538 // adjust 320 width to 321
\r
1539 for (i = 239; i > 0; i--)
\r
1540 memmove(bg_buffer + 321*2*i, bg_buffer + 320*2*i, 320*2);
\r
1544 static void menu_gfx_prepare(void)
\r
1546 menu_prepare_bg(rom_loaded);
\r
1548 menu_draw_begin(1);
\r
1553 void menu_loop(void)
\r
1555 menu_gfx_prepare();
\r
1559 menuErrorMsg[0] = 0;
\r
1563 // --------- CD tray close menu ----------
\r
1565 static void draw_menu_tray(int menu_sel)
\r
1567 int tl_x = 70, tl_y = 90, y;
\r
1569 menu_draw_begin(1);
\r
1571 text_out16(tl_x, 20, "The unit is about to");
\r
1572 text_out16(tl_x, 30, "close the CD tray.");
\r
1575 text_out16(tl_x, y, "Load new CD image");
\r
1576 text_out16(tl_x, (y+=10), "Insert nothing");
\r
1579 text_out16(tl_x - 16, tl_y + menu_sel*10, ">");
\r
1581 if (menuErrorMsg[0]) text_out16(5, 226, menuErrorMsg);
\r
1586 int menu_loop_tray(void)
\r
1588 int menu_sel = 0, menu_sel_max = 1;
\r
1589 unsigned long inp = 0;
\r
1590 char curr_path[MAX_PATH], *selfname;
\r
1593 menu_gfx_prepare();
\r
1595 if ( (tstf = fopen(currentConfig.lastRomFile, "rb")) )
\r
1598 strcpy(curr_path, currentConfig.lastRomFile);
\r
1602 getcwd(curr_path, MAX_PATH);
\r
1605 /* make sure action buttons are not pressed on entering menu */
\r
1606 draw_menu_tray(menu_sel);
\r
1607 while (Framework_PollGetButtons() & BTN_PLAY) Sleep(50);
\r
1611 draw_menu_tray(menu_sel);
\r
1612 inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_PLAY);
\r
1613 if(inp & BTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }
\r
1614 if(inp & BTN_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }
\r
1615 if(inp & BTN_PLAY ) {
\r
1616 switch (menu_sel) {
\r
1617 case 0: // select image
\r
1618 selfname = romsel_loop(curr_path);
\r
1620 int ret = -1, cd_type;
\r
1621 cd_type = emu_cdCheck(NULL);
\r
1623 ret = Insert_CD(romFileName, cd_type == 2);
\r
1625 sprintf(menuErrorMsg, "Load failed, invalid CD image?");
\r
1626 lprintf("%s\n", menuErrorMsg);
\r
1629 engineState = PGS_RestartRun;
\r
1633 case 1: // insert nothing
\r
1634 engineState = PGS_RestartRun;
\r
1638 menuErrorMsg[0] = 0; // clear error msg
\r