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 = 20;
\r
55 if (repeats == 2) wait = 3;
\r
56 else if (repeats == 4) wait = 2;
\r
57 else if (repeats == 6) wait = 1;
\r
59 for (i = 0; i < wait && inp_prev == Framework_PollGetButtons(); i++) {
\r
60 if (i == 0) repeats++;
\r
64 while ( !((ret = Framework_PollGetButtons()) & interesting) ) {
\r
69 if (release || ret != inp_prev) {
\r
73 if (wait > 6 && (ret&(BTN_UP|BTN_LEFT|BTN_DOWN|BTN_RIGHT|BTN_L|BTN_R)))
\r
77 // we don't need diagonals in menus
\r
78 if ((ret&BTN_UP) && (ret&BTN_LEFT)) ret &= ~BTN_LEFT;
\r
79 if ((ret&BTN_UP) && (ret&BTN_RIGHT)) ret &= ~BTN_RIGHT;
\r
80 if ((ret&BTN_DOWN) && (ret&BTN_LEFT)) ret &= ~BTN_LEFT;
\r
81 if ((ret&BTN_DOWN) && (ret&BTN_RIGHT)) ret &= ~BTN_RIGHT;
\r
87 static void menu_draw_begin(int use_bgbuff)
\r
90 memcpy32((int *)menu_screen, (int *)bg_buffer, 321*240*2/4);
\r
94 static void menu_draw_end(void)
\r
96 giz_screen = Framework2D_LockBuffer(0);
\r
97 if (giz_screen == NULL)
\r
99 lprintf_al("%s: Framework2D_LockBuffer() returned NULL\n", __FUNCTION__);
\r
102 memcpy32(giz_screen, (int *)menu_screen, 321*240*2/4);
\r
103 Framework2D_UnlockBuffer();
\r
105 Framework2D_Flip(1);
\r
109 // --------- loading ROM screen ----------
\r
111 static void load_progress_cb(int percent)
\r
113 int ln, len = percent * 320 / 100;
\r
114 unsigned short *dst;
\r
116 menu_draw_begin(0);
\r
117 dst = (unsigned short *)menu_screen + 321*20;
\r
119 if (len > 320) len = 320;
\r
120 for (ln = 10; ln > 0; ln--, dst += 321)
\r
121 memset(dst, 0xff, len*2);
\r
125 void menu_romload_prepare(const char *rom_name)
\r
127 const char *p = rom_name + strlen(rom_name);
\r
128 while (p > rom_name && *p != '/') p--;
\r
131 memset(menu_screen, 0, 321*240*2);
\r
132 menu_draw_begin(1);
\r
134 smalltext_out16(1, 1, "Loading", 0xffff);
\r
135 smalltext_out16_lim(1, 10, p, 0xffff, 53);
\r
137 PicoCartLoadProgressCB = load_progress_cb;
\r
140 void menu_romload_end(void)
\r
142 PicoCartLoadProgressCB = NULL;
\r
143 menu_draw_begin(0);
\r
144 smalltext_out16(1, 30, "Starting emulation...", 0xffff);
\r
148 // -------------- ROM selector --------------
\r
155 unsigned char d_type;
\r
159 // rrrr rggg gggb bbbb
\r
161 static unsigned short file2color(const char *fname)
\r
163 const char *ext = fname + strlen(fname) - 3;
\r
164 static const char *rom_exts[] = { "zip", "bin", "smd", "gen", "iso", "cso" };
\r
165 static const char *other_exts[] = { "gmv", "pat" };
\r
168 if (ext < fname) ext = fname;
\r
169 for (i = 0; i < sizeof(rom_exts)/sizeof(rom_exts[0]); i++)
\r
170 if (strcasecmp(ext, rom_exts[i]) == 0) return 0xbdff;
\r
171 for (i = 0; i < sizeof(other_exts)/sizeof(other_exts[0]); i++)
\r
172 if (strcasecmp(ext, other_exts[i]) == 0) return 0xaff5;
\r
176 static void draw_dirlist(char *curdir, struct my_dirent **namelist, int n, int sel)
\r
181 n--; // exclude current dir (".")
\r
183 menu_draw_begin(1);
\r
186 menu_darken_bg(menu_screen, menu_screen, 321*240, 0);
\r
189 menu_darken_bg((char *)menu_screen + 321*120*2, (char *)menu_screen + 321*120*2, 321*8, 0);
\r
192 smalltext_out16_lim(14, (start - 2)*10, curdir, 0xffff, 53-2);
\r
193 for (i = 0; i < n; i++) {
\r
195 if (pos < 0) continue;
\r
196 if (pos > 23) break;
\r
197 if (namelist[i+1]->d_type == DT_DIR) {
\r
198 smalltext_out16_lim(14, pos*10, "/", 0xfff6, 1);
\r
199 smalltext_out16_lim(14+6, pos*10, namelist[i+1]->d_name, 0xfff6, 53-3);
\r
201 unsigned short color = file2color(namelist[i+1]->d_name);
\r
202 smalltext_out16_lim(14, pos*10, namelist[i+1]->d_name, color, 53-2);
\r
205 text_out16(5, 120, ">");
\r
209 static int scandir_cmp(const void *p1, const void *p2)
\r
211 struct my_dirent **d1 = (struct my_dirent **)p1, **d2 = (struct my_dirent **)p2;
\r
212 if ((*d1)->d_type == (*d2)->d_type) return strcasecmp((*d1)->d_name, (*d2)->d_name);
\r
213 if ((*d1)->d_type == DT_DIR) return -1; // put before
\r
214 if ((*d2)->d_type == DT_DIR) return 1;
\r
215 return strcasecmp((*d1)->d_name, (*d2)->d_name);
\r
218 static char *filter_exts[] = {
\r
219 ".mp3", ".srm", ".brm", "s.gz", ".mds", "bcfg", ".txt", ".htm", "html",
\r
220 ".jpg", ".cue", ".exe", ".dll"
\r
223 static int scandir_filter(const struct my_dirent *ent)
\r
228 if (ent == NULL || ent->d_name == NULL) return 0;
\r
229 if (strlen(ent->d_name) < 5) return 1;
\r
231 p = ent->d_name + strlen(ent->d_name) - 4;
\r
233 for (i = 0; i < sizeof(filter_exts)/sizeof(filter_exts[0]); i++)
\r
235 if (strcasecmp(p, filter_exts[i]) == 0) return 0;
\r
241 static int cstr2wstr(wchar_t *dst, const char *src)
\r
244 for (i = len = strlen(src); i >= 0; i--)
\r
249 static void wstr2cstr(char *dst, const wchar_t *src)
\r
252 for (i = wcslen(src); i >= 0; i--)
\r
256 static int my_scandir(const char *dir, struct my_dirent ***namelist_out,
\r
257 int(*filter)(const struct my_dirent *),
\r
258 int(*compar)(const void *, const void *))
\r
261 int i, len, ret = -1, name_alloc = 4, name_count = 0;
\r
262 struct my_dirent **namelist = NULL, *ent;
\r
263 WIN32_FIND_DATA finddata;
\r
264 HANDLE fh = INVALID_HANDLE_VALUE;
\r
267 wdir = malloc(sizeof(wdir[0]) * MAX_PATH);
\r
268 if (wdir == NULL) { lprintf_al("%s:%i: OOM\n", __FILE__, __LINE__); goto fail; }
\r
270 namelist = malloc(sizeof(*namelist) * name_alloc);
\r
271 if (namelist == NULL) { lprintf_al("%s:%i: OOM\n", __FILE__, __LINE__); goto fail; }
\r
273 // try to read first..
\r
274 len = cstr2wstr(wdir, dir);
\r
275 for (i = 0; i < len; i++)
\r
276 if (wdir[i] == '/') wdir[i] = '\\';
\r
277 if (wdir[len-1] != '\\') wdir[len++] = '\\';
\r
280 /*if (wdir[len-1] == '\\') wdir[len-1] = 0;*/
\r
283 fh = FindFirstFile(wdir, &finddata);
\r
284 if (fh == INVALID_HANDLE_VALUE)
\r
286 if (GetLastError() != ERROR_NO_MORE_FILES)
\r
288 lprintf("FindFirstFile(\"%s\") failed with %lu\n", dir, GetLastError());
\r
294 // add "." and ".."
\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
298 ent = malloc(sizeof(*ent) + 3);
\r
299 ent->d_type = DT_DIR; strcpy(ent->d_name, "..");
\r
300 namelist[name_count++] = ent;
\r
304 ent = malloc(sizeof(*ent) + wcslen(finddata.cFileName) + 1);
\r
305 ent->d_type = (finddata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? DT_DIR : DT_REG;
\r
306 wstr2cstr(ent->d_name, finddata.cFileName);
\r
307 if (filter == NULL || filter(ent))
\r
308 namelist[name_count++] = ent;
\r
311 if (name_count >= name_alloc)
\r
315 tmp = realloc(namelist, sizeof(*namelist) * name_alloc);
\r
316 if (tmp == NULL) { lprintf_al("%s:%i: OOM\n", __FILE__, __LINE__); goto fail; }
\r
320 bRet = FindNextFile(fh, &finddata);
\r
324 if (compar != NULL && name_count > 3) qsort(&namelist[2], name_count - 2, sizeof(namelist[0]), compar);
\r
328 *namelist_out = namelist;
\r
332 if (namelist != NULL)
\r
334 while (name_count--)
\r
335 free(namelist[name_count]);
\r
339 if (fh != INVALID_HANDLE_VALUE) FindClose(fh);
\r
340 if (wdir != NULL) free(wdir);
\r
345 static char *romsel_loop(char *curr_path)
\r
347 struct my_dirent **namelist;
\r
350 unsigned long inp = 0;
\r
351 char *ret = NULL, *fname = NULL;
\r
353 // is this a dir or a full path?
\r
354 if ((dir = opendir(curr_path))) {
\r
358 for (p = curr_path + strlen(curr_path) - 1; p > curr_path && *p != '/'; p--);
\r
363 n = my_scandir(curr_path, &namelist, scandir_filter, scandir_cmp);
\r
366 n = my_scandir("/", &namelist, scandir_filter, scandir_cmp);
\r
369 lprintf("scandir failed, dir: "); lprintf(curr_path); lprintf("\n");
\r
375 if (fname != NULL) {
\r
377 for (i = 1; i < n; i++) {
\r
378 if (strcmp(namelist[i]->d_name, fname) == 0) {
\r
387 draw_dirlist(curr_path, namelist, n, sel);
\r
388 inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_LEFT|BTN_RIGHT|BTN_L|BTN_R|BTN_PLAY|BTN_STOP);
\r
389 if(inp & BTN_UP ) { sel--; if (sel < 0) sel = n-2; }
\r
390 if(inp & BTN_DOWN) { sel++; if (sel > n-2) sel = 0; }
\r
391 if(inp & BTN_LEFT) { sel-=10; if (sel < 0) sel = 0; }
\r
392 if(inp & BTN_L) { sel-=24; if (sel < 0) sel = 0; }
\r
393 if(inp & BTN_RIGHT) { sel+=10; if (sel > n-2) sel = n-2; }
\r
394 if(inp & BTN_R) { sel+=24; if (sel > n-2) sel = n-2; }
\r
395 if(inp & BTN_PLAY) { // enter dir/select
\r
396 if (namelist[sel+1]->d_type == DT_REG) {
\r
397 strcpy(romFileName, curr_path);
\r
398 strcat(romFileName, "/");
\r
399 strcat(romFileName, namelist[sel+1]->d_name);
\r
402 } else if (namelist[sel+1]->d_type == DT_DIR) {
\r
403 int newlen = strlen(curr_path) + strlen(namelist[sel+1]->d_name) + 2;
\r
404 char *p, *newdir = malloc(newlen);
\r
405 if (strcmp(namelist[sel+1]->d_name, "..") == 0) {
\r
406 char *start = curr_path;
\r
407 p = start + strlen(start) - 1;
\r
408 while (*p == '/' && p > start) p--;
\r
409 while (*p != '/' && p > start) p--;
\r
410 if (p <= start) strcpy(newdir, "/");
\r
411 else { strncpy(newdir, start, p-start); newdir[p-start] = 0; }
\r
413 strcpy(newdir, curr_path);
\r
414 p = newdir + strlen(newdir) - 1;
\r
415 while (*p == '/' && p >= newdir) *p-- = 0;
\r
416 strcat(newdir, "/");
\r
417 strcat(newdir, namelist[sel+1]->d_name);
\r
419 ret = romsel_loop(newdir);
\r
424 if(inp & BTN_STOP) break; // cancel
\r
428 while(n--) free(namelist[n]);
\r
435 static char *romsel_loop(char *curr_path)
\r
441 // ------------ patch/gg menu ------------
\r
443 static void draw_patchlist(int sel)
\r
445 int start, i, pos, active;
\r
449 menu_draw_begin(1);
\r
451 for (i = 0; i < PicoPatchCount; i++) {
\r
453 if (pos < 0) continue;
\r
454 if (pos > 23) break;
\r
455 active = PicoPatches[i].active;
\r
456 smalltext_out16_lim(14, pos*10, active ? "ON " : "OFF", active ? 0xfff6 : 0xffff, 3);
\r
457 smalltext_out16_lim(14+6*4, pos*10, PicoPatches[i].name, active ? 0xfff6 : 0xffff, 53-6);
\r
460 if (pos < 24) smalltext_out16_lim(14, pos*10, "done", 0xffff, 4);
\r
462 text_out16(5, 120, ">");
\r
467 static void patches_menu_loop(void)
\r
470 unsigned long inp = 0;
\r
474 draw_patchlist(menu_sel);
\r
475 inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_LEFT|BTN_RIGHT|BTN_L|BTN_R|BTN_PLAY|BTN_STOP);
\r
476 if(inp & BTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = PicoPatchCount; }
\r
477 if(inp & BTN_DOWN) { menu_sel++; if (menu_sel > PicoPatchCount) menu_sel = 0; }
\r
478 if(inp &(BTN_LEFT|BTN_L)) { menu_sel-=10; if (menu_sel < 0) menu_sel = 0; }
\r
479 if(inp &(BTN_RIGHT|BTN_R)) { menu_sel+=10; if (menu_sel > PicoPatchCount) menu_sel = PicoPatchCount; }
\r
480 if(inp & BTN_PLAY) { // action
\r
481 if (menu_sel < PicoPatchCount)
\r
482 PicoPatches[menu_sel].active = !PicoPatches[menu_sel].active;
\r
485 if(inp & BTN_STOP) return;
\r
490 // ------------ savestate loader ------------
\r
492 static int state_slot_flags = 0;
\r
494 static void state_check_slots(void)
\r
498 state_slot_flags = 0;
\r
500 for (slot = 0; slot < 10; slot++)
\r
502 if (emu_checkSaveFile(slot))
\r
504 state_slot_flags |= 1 << slot;
\r
509 static void draw_savestate_bg(int slot)
\r
511 struct PicoVideo tmp_pv;
\r
512 unsigned short tmp_cram[0x40];
\r
513 unsigned short tmp_vsram[0x40];
\r
514 void *tmp_vram, *file;
\r
517 fname = emu_GetSaveFName(1, 0, slot);
\r
518 if (!fname) return;
\r
520 tmp_vram = malloc(sizeof(Pico.vram));
\r
521 if (tmp_vram == NULL) return;
\r
523 memcpy(tmp_vram, Pico.vram, sizeof(Pico.vram));
\r
524 memcpy(tmp_cram, Pico.cram, sizeof(Pico.cram));
\r
525 memcpy(tmp_vsram, Pico.vsram, sizeof(Pico.vsram));
\r
526 memcpy(&tmp_pv, &Pico.video, sizeof(Pico.video));
\r
528 if (strcmp(fname + strlen(fname) - 3, ".gz") == 0) {
\r
529 file = gzopen(fname, "rb");
\r
530 emu_setSaveStateCbs(1);
\r
532 file = fopen(fname, "rb");
\r
533 emu_setSaveStateCbs(0);
\r
538 PicoCdLoadStateGfx(file);
\r
540 areaSeek(file, 0x10020, SEEK_SET); // skip header and RAM in state file
\r
541 areaRead(Pico.vram, 1, sizeof(Pico.vram), file);
\r
542 areaSeek(file, 0x2000, SEEK_CUR);
\r
543 areaRead(Pico.cram, 1, sizeof(Pico.cram), file);
\r
544 areaRead(Pico.vsram, 1, sizeof(Pico.vsram), file);
\r
545 areaSeek(file, 0x221a0, SEEK_SET);
\r
546 areaRead(&Pico.video, 1, sizeof(Pico.video), file);
\r
551 emu_forcedFrame(POPT_EN_SOFTSCALE);
\r
552 menu_prepare_bg(1);
\r
554 memcpy(Pico.vram, tmp_vram, sizeof(Pico.vram));
\r
555 memcpy(Pico.cram, tmp_cram, sizeof(Pico.cram));
\r
556 memcpy(Pico.vsram, tmp_vsram, sizeof(Pico.vsram));
\r
557 memcpy(&Pico.video, &tmp_pv, sizeof(Pico.video));
\r
561 static void draw_savestate_menu(int menu_sel, int is_loading)
\r
563 int tl_x = 25, tl_y = 60, y, i;
\r
565 if (state_slot_flags & (1 << menu_sel))
\r
566 draw_savestate_bg(menu_sel);
\r
567 menu_draw_begin(1);
\r
569 text_out16(tl_x, 30, is_loading ? "Load state" : "Save state");
\r
571 menu_draw_selection(tl_x - 16, tl_y + menu_sel*10, 108);
\r
573 /* draw all 10 slots */
\r
575 for (i = 0; i < 10; i++, y+=10)
\r
577 text_out16(tl_x, y, "SLOT %i (%s)", i, (state_slot_flags & (1 << i)) ? "USED" : "free");
\r
579 text_out16(tl_x, y, "back");
\r
584 static int savestate_menu_loop(int is_loading)
\r
586 static int menu_sel = 10;
\r
587 int menu_sel_max = 10;
\r
588 unsigned long inp = 0;
\r
590 state_check_slots();
\r
594 draw_savestate_menu(menu_sel, is_loading);
\r
595 inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_PLAY|BTN_STOP);
\r
596 if(inp & BTN_UP ) {
\r
598 menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max;
\r
599 } while (!(state_slot_flags & (1 << menu_sel)) && menu_sel != menu_sel_max && is_loading);
\r
601 if(inp & BTN_DOWN) {
\r
603 menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0;
\r
604 } while (!(state_slot_flags & (1 << menu_sel)) && menu_sel != menu_sel_max && is_loading);
\r
606 if(inp & BTN_PLAY) { // save/load
\r
607 if (menu_sel < 10) {
\r
608 state_slot = menu_sel;
\r
609 PicoStateProgressCB = emu_stateCb; /* also suitable for menu */
\r
610 if (emu_SaveLoadGame(is_loading, 0)) {
\r
611 strcpy(menuErrorMsg, is_loading ? "Load failed" : "Save failed");
\r
617 if(inp & BTN_STOP) return 1;
\r
621 // -------------- key config --------------
\r
623 static char *action_binds(int player_idx, int action_mask)
\r
625 static char strkeys[32*5];
\r
629 for (i = 0; i < 32; i++) // i is key index
\r
631 if (currentConfig.KeyBinds[i] & action_mask)
\r
633 if (player_idx >= 0 && ((currentConfig.KeyBinds[i] >> 16) & 3) != player_idx) continue;
\r
634 if (strkeys[0]) { strcat(strkeys, " + "); strcat(strkeys, gizKeyNames[i]); break; }
\r
635 else strcpy(strkeys, gizKeyNames[i]);
\r
642 static void unbind_action(int action)
\r
646 for (i = 0; i < 32; i++)
\r
647 currentConfig.KeyBinds[i] &= ~action;
\r
650 static int count_bound_keys(int action, int pl_idx)
\r
654 for (i = 0; i < 32; i++)
\r
656 if (pl_idx >= 0 && (currentConfig.KeyBinds[i]&0x30000) != (pl_idx<<16)) continue;
\r
657 if (currentConfig.KeyBinds[i] & action) keys++;
\r
663 static void draw_key_config(const me_bind_action *opts, int opt_cnt, int player_idx, int sel)
\r
665 int x, y, tl_y = 30, i;
\r
667 menu_draw_begin(1);
\r
668 if (player_idx >= 0) {
\r
669 text_out16(80, 10, "Player %i controls", player_idx + 1);
\r
672 text_out16(80, 10, "Emulator controls");
\r
676 menu_draw_selection(x - 16, tl_y + sel*10, (player_idx >= 0) ? 66 : 130);
\r
679 for (i = 0; i < opt_cnt; i++, y+=10)
\r
680 text_out16(x, y, "%s : %s", opts[i].name, action_binds(player_idx, opts[i].mask));
\r
682 text_out16(x, y, "Done");
\r
684 if (sel < opt_cnt) {
\r
685 text_out16(30, 195, "Press a button to bind/unbind");
\r
686 text_out16(30, 205, "Use HOME to clear");
\r
687 text_out16(30, 215, "To bind UP/DOWN, hold HOME");
\r
688 text_out16(30, 225, "Select \"Done\" to exit");
\r
690 text_out16(30, 205, "Use Options -> Save cfg");
\r
691 text_out16(30, 215, "to save controls");
\r
692 text_out16(30, 225, "Press PLAY or STOP to exit");
\r
697 static void key_config_loop(const me_bind_action *opts, int opt_cnt, int player_idx)
\r
699 int sel = 0, menu_sel_max = opt_cnt, prev_select = 0, i;
\r
700 unsigned long inp = 0;
\r
704 draw_key_config(opts, opt_cnt, player_idx, sel);
\r
705 inp = wait_for_input(CONFIGURABLE_KEYS|BTN_HOME);
\r
706 if (!(inp & BTN_HOME)) {
\r
708 if(inp & BTN_UP ) { sel--; if (sel < 0) sel = menu_sel_max; continue; }
\r
709 if(inp & BTN_DOWN) { sel++; if (sel > menu_sel_max) sel = 0; continue; }
\r
711 if (sel >= opt_cnt) {
\r
712 if (inp & (BTN_PLAY|BTN_STOP)) break;
\r
715 // if we are here, we want to bind/unbind something
\r
716 if ((inp & BTN_HOME) && !prev_select)
\r
717 unbind_action(opts[sel].mask);
\r
718 prev_select = inp & BTN_HOME;
\r
719 inp &= CONFIGURABLE_KEYS;
\r
721 for (i = 0; i < 32; i++)
\r
722 if (inp & (1 << i)) {
\r
723 if (count_bound_keys(opts[sel].mask, player_idx) >= 2)
\r
724 currentConfig.KeyBinds[i] &= ~opts[sel].mask; // allow to unbind only
\r
725 else currentConfig.KeyBinds[i] ^= opts[sel].mask;
\r
726 if (player_idx >= 0 && (currentConfig.KeyBinds[i] & opts[sel].mask)) {
\r
727 currentConfig.KeyBinds[i] &= ~(3 << 16);
\r
728 currentConfig.KeyBinds[i] |= player_idx << 16;
\r
734 menu_entry ctrlopt_entries[] =
\r
736 { "Player 1", MB_NONE, MA_CTRL_PLAYER1, NULL, 0, 0, 0, 1, 0 },
\r
737 { "Player 2", MB_NONE, MA_CTRL_PLAYER2, NULL, 0, 0, 0, 1, 0 },
\r
738 { "Emulator controls", MB_NONE, MA_CTRL_EMU, NULL, 0, 0, 0, 1, 0 },
\r
739 { "6 button pad", MB_ONOFF, MA_OPT_6BUTTON_PAD, &PicoOpt, 0x020, 0, 0, 1, 1 },
\r
740 { "Turbo rate", MB_RANGE, MA_CTRL_TURBO_RATE, ¤tConfig.turbo_rate, 0, 1, 30, 1, 1 },
\r
741 { "Done", MB_NONE, MA_CTRL_DONE, NULL, 0, 0, 0, 1, 0 },
\r
744 #define CTRLOPT_ENTRY_COUNT (sizeof(ctrlopt_entries) / sizeof(ctrlopt_entries[0]))
\r
745 const int ctrlopt_entry_count = CTRLOPT_ENTRY_COUNT;
\r
747 static void draw_kc_sel(int menu_sel)
\r
749 int tl_x = 25+40, tl_y = 60, y;
\r
752 menu_draw_begin(1);
\r
753 menu_draw_selection(tl_x - 16, tl_y + menu_sel*10, 138);
\r
755 me_draw(ctrlopt_entries, ctrlopt_entry_count, tl_x, tl_y, NULL, NULL);
\r
761 // player2_flag, ?, ?, ?, ?, ?, ?, menu
\r
762 // "NEXT SAVE SLOT", "PREV SAVE SLOT", "SWITCH RENDERER", "SAVE STATE",
\r
763 // "LOAD STATE", "VOLUME UP", "VOLUME DOWN", "DONE"
\r
764 me_bind_action emuctrl_actions[] =
\r
766 { "Load State ", 1<<28 },
\r
767 { "Save State ", 1<<27 },
\r
768 { "Prev Save Slot ", 1<<25 },
\r
769 { "Next Save Slot ", 1<<24 },
\r
770 { "Switch Renderer", 1<<26 },
\r
771 { "Volume Down ", 1<<30 },
\r
772 { "Volume Up ", 1<<29 },
\r
776 static void kc_sel_loop(void)
\r
778 int menu_sel = 5, menu_sel_max = 5;
\r
779 unsigned long inp = 0;
\r
780 menu_id selected_id;
\r
784 draw_kc_sel(menu_sel);
\r
785 inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_PLAY|BTN_STOP);
\r
786 selected_id = me_index2id(ctrlopt_entries, CTRLOPT_ENTRY_COUNT, menu_sel);
\r
787 if (inp & (BTN_LEFT|BTN_RIGHT)) // multi choise
\r
788 me_process(ctrlopt_entries, CTRLOPT_ENTRY_COUNT, selected_id, (inp&BTN_RIGHT) ? 1 : 0);
\r
789 if (inp & BTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }
\r
790 if (inp & BTN_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }
\r
791 if (inp & BTN_PLAY) {
\r
792 int is_6button = currentConfig.PicoOpt & 0x020;
\r
793 switch (selected_id) {
\r
794 case MA_CTRL_PLAYER1: key_config_loop(me_ctrl_actions, is_6button ? 15 : 11, 0); return;
\r
795 case MA_CTRL_PLAYER2: key_config_loop(me_ctrl_actions, is_6button ? 15 : 11, 1); return;
\r
796 case MA_CTRL_EMU: key_config_loop(emuctrl_actions,
\r
797 sizeof(emuctrl_actions)/sizeof(emuctrl_actions[0]) - 1, -1); return;
\r
798 case MA_CTRL_DONE: if (!rom_loaded) emu_WriteConfig(0); return;
\r
802 if (inp & BTN_STOP) return;
\r
807 // --------- sega/mega cd options ----------
\r
809 menu_entry cdopt_entries[] =
\r
811 { NULL, MB_NONE, MA_CDOPT_TESTBIOS_USA, NULL, 0, 0, 0, 1 },
\r
812 { NULL, MB_NONE, MA_CDOPT_TESTBIOS_EUR, NULL, 0, 0, 0, 1 },
\r
813 { NULL, MB_NONE, MA_CDOPT_TESTBIOS_JAP, NULL, 0, 0, 0, 1 },
\r
814 { "CD LEDs", MB_ONOFF, MA_CDOPT_LEDS, ¤tConfig.EmuOpt, 0x0400, 0, 0, 1 },
\r
815 { "CDDA audio (using mp3s)", MB_ONOFF, MA_CDOPT_CDDA, ¤tConfig.PicoOpt, 0x0800, 0, 0, 1 },
\r
816 { "PCM audio", MB_ONOFF, MA_CDOPT_PCM, ¤tConfig.PicoOpt, 0x0400, 0, 0, 1 },
\r
817 { NULL, MB_NONE, MA_CDOPT_READAHEAD, NULL, 0, 0, 0, 1 },
\r
818 { "SaveRAM cart", MB_ONOFF, MA_CDOPT_SAVERAM, ¤tConfig.PicoOpt, 0x8000, 0, 0, 1 },
\r
819 { "Scale/Rot. fx (slow)", MB_ONOFF, MA_CDOPT_SCALEROT_CHIP,¤tConfig.PicoOpt, 0x1000, 0, 0, 1 },
\r
820 { "Better sync (slow)", MB_ONOFF, MA_CDOPT_BETTER_SYNC, ¤tConfig.PicoOpt, 0x2000, 0, 0, 1 },
\r
821 { "done", MB_NONE, MA_CDOPT_DONE, NULL, 0, 0, 0, 1 },
\r
824 #define CDOPT_ENTRY_COUNT (sizeof(cdopt_entries) / sizeof(cdopt_entries[0]))
\r
827 struct bios_names_t
\r
829 char us[32], eu[32], jp[32];
\r
832 static void menu_cdopt_cust_draw(const menu_entry *entry, int x, int y, void *param)
\r
834 struct bios_names_t *bios_names = param;
\r
839 case MA_CDOPT_TESTBIOS_USA: text_out16(x, y, "USA BIOS: %s", bios_names->us); break;
\r
840 case MA_CDOPT_TESTBIOS_EUR: text_out16(x, y, "EUR BIOS: %s", bios_names->eu); break;
\r
841 case MA_CDOPT_TESTBIOS_JAP: text_out16(x, y, "JAP BIOS: %s", bios_names->jp); break;
\r
842 case MA_CDOPT_READAHEAD:
\r
843 if (PicoCDBuffers > 1) sprintf(ra_buff, "%5iK", PicoCDBuffers * 2);
\r
844 else strcpy(ra_buff, " OFF");
\r
845 text_out16(x, y, "ReadAhead buffer %s", ra_buff);
\r
851 static void draw_cd_menu_options(int menu_sel, struct bios_names_t *bios_names)
\r
853 int tl_x = 25, tl_y = 60;
\r
854 menu_id selected_id;
\r
857 if (PicoCDBuffers > 1) sprintf(ra_buff, "%5iK", PicoCDBuffers * 2);
\r
858 else strcpy(ra_buff, " OFF");
\r
860 menu_draw_begin(1);
\r
862 menu_draw_selection(tl_x - 16, tl_y + menu_sel*10, 246);
\r
864 me_draw(cdopt_entries, CDOPT_ENTRY_COUNT, tl_x, tl_y, menu_cdopt_cust_draw, bios_names);
\r
866 selected_id = me_index2id(cdopt_entries, CDOPT_ENTRY_COUNT, menu_sel);
\r
867 if ((selected_id == MA_CDOPT_TESTBIOS_USA && strcmp(bios_names->us, "NOT FOUND")) ||
\r
868 (selected_id == MA_CDOPT_TESTBIOS_EUR && strcmp(bios_names->eu, "NOT FOUND")) ||
\r
869 (selected_id == MA_CDOPT_TESTBIOS_JAP && strcmp(bios_names->jp, "NOT FOUND")))
\r
870 text_out16(tl_x, 210, "Press start to test selected BIOS");
\r
875 static void cd_menu_loop_options(void)
\r
877 static int menu_sel = 0;
\r
878 int menu_sel_max = 10;
\r
879 unsigned long inp = 0;
\r
880 struct bios_names_t bios_names;
\r
881 menu_id selected_id;
\r
884 if (emu_findBios(4, &bios)) { // US
\r
885 for (p = bios+strlen(bios)-1; p > bios && *p != '/'; p--); p++;
\r
886 strncpy(bios_names.us, p, sizeof(bios_names.us)); bios_names.us[sizeof(bios_names.us)-1] = 0;
\r
887 } else strcpy(bios_names.us, "NOT FOUND");
\r
889 if (emu_findBios(8, &bios)) { // EU
\r
890 for (p = bios+strlen(bios)-1; p > bios && *p != '/'; p--); p++;
\r
891 strncpy(bios_names.eu, p, sizeof(bios_names.eu)); bios_names.eu[sizeof(bios_names.eu)-1] = 0;
\r
892 } else strcpy(bios_names.eu, "NOT FOUND");
\r
894 if (emu_findBios(1, &bios)) { // JP
\r
895 for (p = bios+strlen(bios)-1; p > bios && *p != '/'; p--); p++;
\r
896 strncpy(bios_names.jp, p, sizeof(bios_names.jp)); bios_names.jp[sizeof(bios_names.jp)-1] = 0;
\r
897 } else strcpy(bios_names.jp, "NOT FOUND");
\r
901 draw_cd_menu_options(menu_sel, &bios_names);
\r
902 inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_LEFT|BTN_RIGHT|BTN_PLAY|BTN_STOP|BTN_REW);
\r
903 if (inp & BTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }
\r
904 if (inp & BTN_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }
\r
905 selected_id = me_index2id(cdopt_entries, CDOPT_ENTRY_COUNT, menu_sel);
\r
906 if (inp & (BTN_LEFT|BTN_RIGHT)) { // multi choise
\r
907 if (!me_process(cdopt_entries, CDOPT_ENTRY_COUNT, selected_id, (inp&BTN_RIGHT) ? 1 : 0) &&
\r
908 selected_id == MA_CDOPT_READAHEAD) {
\r
909 if (inp & BTN_LEFT) {
\r
910 PicoCDBuffers >>= 1;
\r
911 if (PicoCDBuffers < 2) PicoCDBuffers = 0;
\r
913 if (PicoCDBuffers < 2) PicoCDBuffers = 2;
\r
914 else PicoCDBuffers <<= 1;
\r
915 if (PicoCDBuffers > 8*1024) PicoCDBuffers = 8*1024; // 16M
\r
919 if (inp & BTN_PLAY) { // toggleable options
\r
920 if (!me_process(cdopt_entries, CDOPT_ENTRY_COUNT, selected_id, 1) &&
\r
921 selected_id == MA_CDOPT_DONE) {
\r
924 switch (selected_id) { // BIOS testers
\r
925 case MA_CDOPT_TESTBIOS_USA:
\r
926 if (emu_findBios(4, &bios)) { // test US
\r
927 strcpy(romFileName, bios);
\r
928 engineState = PGS_ReloadRom;
\r
932 case MA_CDOPT_TESTBIOS_EUR:
\r
933 if (emu_findBios(8, &bios)) { // test EU
\r
934 strcpy(romFileName, bios);
\r
935 engineState = PGS_ReloadRom;
\r
939 case MA_CDOPT_TESTBIOS_JAP:
\r
940 if (emu_findBios(1, &bios)) { // test JP
\r
941 strcpy(romFileName, bios);
\r
942 engineState = PGS_ReloadRom;
\r
950 if (inp & (BTN_STOP|BTN_REW)) return;
\r
955 // --------- advanced options ----------
\r
957 menu_entry opt2_entries[] =
\r
959 { "Disable sprite limit", MB_ONOFF, MA_OPT2_NO_SPRITE_LIM, &PicoOpt, 0x40000, 0, 0, 1, 1 },
\r
960 { "Emulate Z80", MB_ONOFF, MA_OPT2_ENABLE_Z80, ¤tConfig.PicoOpt,0x0004, 0, 0, 1 },
\r
961 { "Emulate YM2612 (FM)", MB_ONOFF, MA_OPT2_ENABLE_YM2612, ¤tConfig.PicoOpt,0x0001, 0, 0, 1 },
\r
962 { "Emulate SN76496 (PSG)", MB_ONOFF, MA_OPT2_ENABLE_SN76496,¤tConfig.PicoOpt,0x0002, 0, 0, 1 },
\r
963 { "Double buffering", MB_ONOFF, MA_OPT2_DBLBUFF, ¤tConfig.EmuOpt, 0x8000, 0, 0, 1 },
\r
964 { "Wait for V-sync (slow)", MB_ONOFF, MA_OPT2_VSYNC, ¤tConfig.EmuOpt, 0x2000, 0, 0, 1 },
\r
965 { "gzip savestates", MB_ONOFF, MA_OPT2_GZIP_STATES, ¤tConfig.EmuOpt, 0x0008, 0, 0, 1 },
\r
966 { "Don't save last used ROM", MB_ONOFF, MA_OPT2_NO_LAST_ROM, ¤tConfig.EmuOpt, 0x0020, 0, 0, 1 },
\r
967 { "done", MB_NONE, MA_OPT2_DONE, NULL, 0, 0, 0, 1 },
\r
970 #define OPT2_ENTRY_COUNT (sizeof(opt2_entries) / sizeof(opt2_entries[0]))
\r
973 static void draw_amenu_options(int menu_sel)
\r
975 int tl_x = 25, tl_y = 50;
\r
977 menu_draw_begin(1);
\r
979 menu_draw_selection(tl_x - 16, tl_y + menu_sel*10, 252);
\r
981 me_draw(opt2_entries, OPT2_ENTRY_COUNT, tl_x, tl_y, NULL, NULL);
\r
986 static void amenu_loop_options(void)
\r
988 static int menu_sel = 0;
\r
990 unsigned long inp = 0;
\r
991 menu_id selected_id;
\r
993 menu_sel_max = me_count_enabled(opt2_entries, OPT2_ENTRY_COUNT) - 1;
\r
997 draw_amenu_options(menu_sel);
\r
998 inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_LEFT|BTN_RIGHT|BTN_PLAY|BTN_STOP|BTN_REW);
\r
999 if (inp & BTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }
\r
1000 if (inp & BTN_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }
\r
1001 selected_id = me_index2id(opt2_entries, OPT2_ENTRY_COUNT, menu_sel);
\r
1002 if (inp & (BTN_LEFT|BTN_RIGHT)) { // multi choise
\r
1003 if (!me_process(opt2_entries, OPT2_ENTRY_COUNT, selected_id, (inp&BTN_RIGHT) ? 1 : 0) &&
\r
1004 selected_id == MA_OPT2_GAMMA) {
\r
1005 while ((inp = Framework_PollGetButtons()) & (BTN_LEFT|BTN_RIGHT)) {
\r
1006 currentConfig.gamma += (inp & BTN_LEFT) ? -1 : 1;
\r
1007 if (currentConfig.gamma < 1) currentConfig.gamma = 1;
\r
1008 if (currentConfig.gamma > 300) currentConfig.gamma = 300;
\r
1009 draw_amenu_options(menu_sel);
\r
1014 if (inp & BTN_PLAY) { // toggleable options
\r
1015 if (!me_process(opt2_entries, OPT2_ENTRY_COUNT, selected_id, 1) &&
\r
1016 selected_id == MA_OPT2_DONE) {
\r
1020 if (inp & (BTN_STOP|BTN_REW)) return;
\r
1024 // -------------- options --------------
\r
1027 menu_entry opt_entries[] =
\r
1029 { NULL, MB_NONE, MA_OPT_RENDERER, NULL, 0, 0, 0, 1 },
\r
1030 { "Accurate sprites", MB_ONOFF, MA_OPT_ACC_SPRITES, &PicoOpt, 0x080, 0, 0, 0, 1 },
\r
1031 { "Scanline mode (faster)", MB_ONOFF, MA_OPT_INTERLACED, ¤tConfig.EmuOpt, 0x4000, 0, 0, 1 },
\r
1032 { "Scale low res mode", MB_ONOFF, MA_OPT_SCALING, ¤tConfig.scaling, 0x0001, 0, 3, 1 },
\r
1033 { "Show FPS", MB_ONOFF, MA_OPT_SHOW_FPS, ¤tConfig.EmuOpt, 0x0002, 0, 0, 1 },
\r
1034 { NULL, MB_RANGE, MA_OPT_FRAMESKIP, ¤tConfig.Frameskip, 0, -1, 16, 1 },
\r
1035 { "Enable sound", MB_ONOFF, MA_OPT_ENABLE_SOUND, ¤tConfig.EmuOpt, 0x0004, 0, 0, 1 },
\r
1036 { NULL, MB_NONE, MA_OPT_SOUND_QUALITY, NULL, 0, 0, 0, 1 },
\r
1037 { NULL, MB_NONE, MA_OPT_REGION, NULL, 0, 0, 0, 1 },
\r
1038 { "Use SRAM/BRAM savestates", MB_ONOFF, MA_OPT_SRAM_STATES, ¤tConfig.EmuOpt, 0x0001, 0, 0, 1 },
\r
1039 { NULL, MB_NONE, MA_OPT_CONFIRM_STATES,NULL, 0, 0, 0, 1 },
\r
1040 { "Save slot", MB_RANGE, MA_OPT_SAVE_SLOT, &state_slot, 0, 0, 9, 1 },
\r
1041 { "[Sega/Mega CD options]", MB_NONE, MA_OPT_SCD_OPTS, NULL, 0, 0, 0, 1 },
\r
1042 { "[advanced options]", MB_NONE, MA_OPT_ADV_OPTS, NULL, 0, 0, 0, 1 },
\r
1043 { NULL, MB_NONE, MA_OPT_SAVECFG, NULL, 0, 0, 0, 1 },
\r
1044 { "Save cfg for current game only",MB_NONE,MA_OPT_SAVECFG_GAME,NULL, 0, 0, 0, 1 },
\r
1045 { NULL, MB_NONE, MA_OPT_LOADCFG, NULL, 0, 0, 0, 1 },
\r
1048 #define OPT_ENTRY_COUNT (sizeof(opt_entries) / sizeof(opt_entries[0]))
\r
1051 static void menu_opt_cust_draw(const menu_entry *entry, int x, int y, void *param)
\r
1053 char *str, str24[24];
\r
1055 switch (entry->id)
\r
1057 case MA_OPT_RENDERER:
\r
1058 if (currentConfig.PicoOpt&0x10)
\r
1059 str = " 8bit fast";
\r
1060 else if (currentConfig.EmuOpt&0x80)
\r
1061 str = "16bit accurate";
\r
1063 str = " 8bit accurate";
\r
1064 text_out16(x, y, "Renderer: %s", str);
\r
1066 case MA_OPT_FRAMESKIP:
\r
1067 if (currentConfig.Frameskip < 0)
\r
1068 strcpy(str24, "Auto");
\r
1069 else sprintf(str24, "%i", currentConfig.Frameskip);
\r
1070 text_out16(x, y, "Frameskip %s", str24);
\r
1072 case MA_OPT_SOUND_QUALITY:
\r
1073 str = (currentConfig.PicoOpt&0x08)?"stereo":"mono";
\r
1074 text_out16(x, y, "Sound Quality: %5iHz %s", currentConfig.PsndRate, str);
\r
1076 case MA_OPT_REGION:
\r
1077 text_out16(x, y, "Region: %s", me_region_name(PicoRegionOverride, PicoAutoRgnOrder));
\r
1079 case MA_OPT_CONFIRM_STATES:
\r
1080 switch ((currentConfig.EmuOpt >> 9) & 5) {
\r
1081 default: str = "OFF"; break;
\r
1082 case 1: str = "writes"; break;
\r
1083 case 4: str = "loads"; break;
\r
1084 case 5: str = "both"; break;
\r
1086 text_out16(x, y, "Confirm savestate %s", str);
\r
1088 case MA_OPT_SAVECFG:
\r
1090 if (config_slot != 0) sprintf(str24, " (profile: %i)", config_slot);
\r
1091 text_out16(x, y, "Save cfg as default%s", str24);
\r
1093 case MA_OPT_LOADCFG:
\r
1094 text_out16(x, y, "Load cfg from profile %i", config_slot);
\r
1097 lprintf("%s: unimplemented (%i)\n", __FUNCTION__, entry->id);
\r
1104 static void draw_menu_options(int menu_sel)
\r
1106 int tl_x = 25, tl_y = 24;
\r
1108 menu_draw_begin(1);
\r
1110 menu_draw_selection(tl_x - 16, tl_y + menu_sel*10, 284);
\r
1112 me_draw(opt_entries, OPT_ENTRY_COUNT, tl_x, tl_y, menu_opt_cust_draw, NULL);
\r
1117 static int sndrate_prevnext(int rate, int dir)
\r
1119 int i, rates[] = { 11025, 22050, 44100 };
\r
1121 for (i = 0; i < 5; i++)
\r
1122 if (rates[i] == rate) break;
\r
1124 i += dir ? 1 : -1;
\r
1125 if (i > 2) return dir ? 44100 : 22050;
\r
1126 if (i < 0) return dir ? 22050 : 11025;
\r
1130 static void region_prevnext(int right)
\r
1132 // jp_ntsc=1, jp_pal=2, usa=4, eu=8
\r
1133 static int rgn_orders[] = { 0x148, 0x184, 0x814, 0x418, 0x841, 0x481 };
\r
1136 if (!PicoRegionOverride) {
\r
1137 for (i = 0; i < 6; i++)
\r
1138 if (rgn_orders[i] == PicoAutoRgnOrder) break;
\r
1139 if (i < 5) PicoAutoRgnOrder = rgn_orders[i+1];
\r
1140 else PicoRegionOverride=1;
\r
1142 else PicoRegionOverride<<=1;
\r
1143 if (PicoRegionOverride > 8) PicoRegionOverride = 8;
\r
1145 if (!PicoRegionOverride) {
\r
1146 for (i = 0; i < 6; i++)
\r
1147 if (rgn_orders[i] == PicoAutoRgnOrder) break;
\r
1148 if (i > 0) PicoAutoRgnOrder = rgn_orders[i-1];
\r
1150 else PicoRegionOverride>>=1;
\r
1154 static void menu_options_save(void)
\r
1156 PicoOpt = currentConfig.PicoOpt;
\r
1157 PsndRate = currentConfig.PsndRate;
\r
1158 if (PicoRegionOverride) {
\r
1159 // force setting possibly changed..
\r
1160 Pico.m.pal = (PicoRegionOverride == 2 || PicoRegionOverride == 8) ? 1 : 0;
\r
1162 if (!(PicoOpt & 0x20)) {
\r
1163 // unbind XYZ MODE, just in case
\r
1164 unbind_action(0xf00);
\r
1168 static int menu_loop_options(void)
\r
1170 static int menu_sel = 0;
\r
1171 int menu_sel_max, ret;
\r
1172 unsigned long inp = 0;
\r
1173 menu_id selected_id;
\r
1175 currentConfig.PicoOpt = PicoOpt;
\r
1176 currentConfig.PsndRate = PsndRate;
\r
1178 me_enable(opt_entries, OPT_ENTRY_COUNT, MA_OPT_SAVECFG_GAME, rom_loaded);
\r
1179 me_enable(opt_entries, OPT_ENTRY_COUNT, MA_OPT_LOADCFG, config_slot != config_slot_current);
\r
1180 menu_sel_max = me_count_enabled(opt_entries, OPT_ENTRY_COUNT) - 1;
\r
1181 if (menu_sel > menu_sel_max) menu_sel = menu_sel_max;
\r
1185 draw_menu_options(menu_sel);
\r
1186 inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_LEFT|BTN_RIGHT|BTN_PLAY|BTN_STOP|BTN_REW);
\r
1187 if (inp & BTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }
\r
1188 if (inp & BTN_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }
\r
1189 selected_id = me_index2id(opt_entries, OPT_ENTRY_COUNT, menu_sel);
\r
1190 if (inp & (BTN_LEFT|BTN_RIGHT)) { // multi choise
\r
1191 if (!me_process(opt_entries, OPT_ENTRY_COUNT, selected_id, (inp&BTN_RIGHT) ? 1 : 0)) {
\r
1192 switch (selected_id) {
\r
1193 case MA_OPT_RENDERER:
\r
1194 if (inp & BTN_LEFT) {
\r
1195 if ((currentConfig.PicoOpt&0x10) || !(currentConfig.EmuOpt &0x80)) {
\r
1196 currentConfig.PicoOpt&= ~0x10;
\r
1197 currentConfig.EmuOpt |= 0x80;
\r
1200 if (!(currentConfig.PicoOpt&0x10) || (currentConfig.EmuOpt &0x80)) {
\r
1201 currentConfig.PicoOpt|= 0x10;
\r
1202 currentConfig.EmuOpt &= ~0x80;
\r
1206 case MA_OPT_SOUND_QUALITY:
\r
1207 if ((inp & BTN_RIGHT) && currentConfig.PsndRate == 44100 &&
\r
1208 !(currentConfig.PicoOpt&0x08))
\r
1210 currentConfig.PsndRate = 11025;
\r
1211 currentConfig.PicoOpt |= 8;
\r
1212 } else if ((inp & BTN_LEFT) && currentConfig.PsndRate == 11025 &&
\r
1213 (currentConfig.PicoOpt&0x08) && !(PicoAHW&1))
\r
1215 currentConfig.PsndRate = 44100;
\r
1216 currentConfig.PicoOpt &= ~8;
\r
1218 currentConfig.PsndRate = sndrate_prevnext(currentConfig.PsndRate, inp & BTN_RIGHT);
\r
1220 case MA_OPT_REGION:
\r
1221 region_prevnext(inp & BTN_RIGHT);
\r
1223 case MA_OPT_CONFIRM_STATES: {
\r
1224 int n = ((currentConfig.EmuOpt>>9)&1) | ((currentConfig.EmuOpt>>10)&2);
\r
1225 n += (inp & BTN_LEFT) ? -1 : 1;
\r
1226 if (n < 0) n = 0; else if (n > 3) n = 3;
\r
1227 n |= n << 1; n &= ~2;
\r
1228 currentConfig.EmuOpt &= ~0xa00;
\r
1229 currentConfig.EmuOpt |= n << 9;
\r
1232 case MA_OPT_SAVE_SLOT:
\r
1233 if (inp & BTN_RIGHT) {
\r
1234 state_slot++; if (state_slot > 9) state_slot = 0;
\r
1235 } else {state_slot--; if (state_slot < 0) state_slot = 9;
\r
1238 case MA_OPT_SAVECFG:
\r
1239 case MA_OPT_SAVECFG_GAME:
\r
1240 case MA_OPT_LOADCFG:
\r
1241 config_slot += (inp&BTN_RIGHT) ? 1 : -1;
\r
1242 if (config_slot > 9) config_slot = 0;
\r
1243 if (config_slot < 0) config_slot = 9;
\r
1244 me_enable(opt_entries, OPT_ENTRY_COUNT, MA_OPT_LOADCFG, config_slot != config_slot_current);
\r
1245 menu_sel_max = me_count_enabled(opt_entries, OPT_ENTRY_COUNT) - 1;
\r
1246 if (menu_sel > menu_sel_max) menu_sel = menu_sel_max;
\r
1249 //lprintf("%s: something unknown selected (%i)\n", __FUNCTION__, selected_id);
\r
1254 if (inp & BTN_PLAY) {
\r
1255 if (!me_process(opt_entries, OPT_ENTRY_COUNT, selected_id, 1))
\r
1257 switch (selected_id)
\r
1259 case MA_OPT_SCD_OPTS:
\r
1260 cd_menu_loop_options();
\r
1261 if (engineState == PGS_ReloadRom)
\r
1262 return 0; // test BIOS
\r
1264 case MA_OPT_ADV_OPTS:
\r
1265 amenu_loop_options();
\r
1267 case MA_OPT_SAVECFG: // done (update and write)
\r
1268 menu_options_save();
\r
1269 if (emu_WriteConfig(0)) strcpy(menuErrorMsg, "config saved");
\r
1270 else strcpy(menuErrorMsg, "failed to write config");
\r
1272 case MA_OPT_SAVECFG_GAME: // done (update and write for current game)
\r
1273 menu_options_save();
\r
1274 if (emu_WriteConfig(1)) strcpy(menuErrorMsg, "config saved");
\r
1275 else strcpy(menuErrorMsg, "failed to write config");
\r
1277 case MA_OPT_LOADCFG:
\r
1278 ret = emu_ReadConfig(1, 1);
\r
1279 if (!ret) ret = emu_ReadConfig(0, 1);
\r
1280 if (ret) strcpy(menuErrorMsg, "config loaded");
\r
1281 else strcpy(menuErrorMsg, "failed to load config");
\r
1284 //lprintf("%s: something unknown selected (%i)\n", __FUNCTION__, selected_id);
\r
1289 if(inp & (BTN_STOP|BTN_REW)) {
\r
1290 menu_options_save();
\r
1291 return 0; // done (update, no write)
\r
1296 // -------------- credits --------------
\r
1298 static void draw_menu_credits(void)
\r
1300 int tl_x = 15, tl_y = 56, y;
\r
1301 menu_draw_begin(1);
\r
1303 text_out16(tl_x, 20, "PicoDrive v" VERSION " (c) notaz, 2006-2008");
\r
1306 text_out16(tl_x, y, "Credits:");
\r
1307 text_out16(tl_x, (y+=10), "fDave: Cyclone 68000 core,");
\r
1308 text_out16(tl_x, (y+=10), " base code of PicoDrive");
\r
1309 text_out16(tl_x, (y+=10), "Reesy & FluBBa: DrZ80 core");
\r
1310 text_out16(tl_x, (y+=10), "MAME devs: YM2612 and SN76496 cores");
\r
1311 text_out16(tl_x, (y+=10), "Reesy: kgsdk wrapper, sound code");
\r
1312 text_out16(tl_x, (y+=10), "jens.l: gizmondo hardware");
\r
1313 text_out16(tl_x, (y+=10), "ketchupgun: skin design");
\r
1315 text_out16(tl_x, (y+=20), "special thanks (for docs, ideas)");
\r
1316 text_out16(tl_x, (y+=10), " Charles MacDonald, Haze,");
\r
1317 text_out16(tl_x, (y+=10), " Stephane Dallongeville,");
\r
1318 text_out16(tl_x, (y+=10), " Lordus, Exophase, Rokas,");
\r
1319 text_out16(tl_x, (y+=10), " Nemesis, Tasco Deluxe");
\r
1325 // -------------- root menu --------------
\r
1327 menu_entry main_entries[] =
\r
1329 { "Resume game", MB_NONE, MA_MAIN_RESUME_GAME, NULL, 0, 0, 0, 0 },
\r
1330 { "Save State", MB_NONE, MA_MAIN_SAVE_STATE, NULL, 0, 0, 0, 0 },
\r
1331 { "Load State", MB_NONE, MA_MAIN_LOAD_STATE, NULL, 0, 0, 0, 0 },
\r
1332 { "Reset game", MB_NONE, MA_MAIN_RESET_GAME, NULL, 0, 0, 0, 0 },
\r
1333 { "Load new ROM/ISO", MB_NONE, MA_MAIN_LOAD_ROM, NULL, 0, 0, 0, 1 },
\r
1334 { "Change options", MB_NONE, MA_MAIN_OPTIONS, NULL, 0, 0, 0, 1 },
\r
1335 { "Configure controls", MB_NONE, MA_MAIN_CONTROLS, NULL, 0, 0, 0, 1 },
\r
1336 { "Credits", MB_NONE, MA_MAIN_CREDITS, NULL, 0, 0, 0, 1 },
\r
1337 { "Patches / GameGenie",MB_NONE, MA_MAIN_PATCHES, NULL, 0, 0, 0, 0 },
\r
1338 { "Exit", MB_NONE, MA_MAIN_EXIT, NULL, 0, 0, 0, 1 }
\r
1341 #define MAIN_ENTRY_COUNT (sizeof(main_entries) / sizeof(main_entries[0]))
\r
1343 static void draw_menu_root(int menu_sel)
\r
1345 const int tl_x = 70, tl_y = 70;
\r
1347 menu_draw_begin(1);
\r
1349 text_out16(tl_x, 20, "PicoDrive v" VERSION);
\r
1351 menu_draw_selection(tl_x - 16, tl_y + menu_sel*10, 146);
\r
1353 me_draw(main_entries, MAIN_ENTRY_COUNT, tl_x, tl_y, NULL, NULL);
\r
1356 if (menuErrorMsg[0]) {
\r
1357 memset((char *)menu_screen + 321*224*2, 0, 321*16*2);
\r
1358 text_out16(5, 226, menuErrorMsg);
\r
1364 static void menu_loop_root(void)
\r
1366 static int menu_sel = 0;
\r
1367 int ret, menu_sel_max;
\r
1368 unsigned long inp = 0;
\r
1370 me_enable(main_entries, MAIN_ENTRY_COUNT, MA_MAIN_RESUME_GAME, rom_loaded);
\r
1371 me_enable(main_entries, MAIN_ENTRY_COUNT, MA_MAIN_SAVE_STATE, rom_loaded);
\r
1372 me_enable(main_entries, MAIN_ENTRY_COUNT, MA_MAIN_LOAD_STATE, rom_loaded);
\r
1373 me_enable(main_entries, MAIN_ENTRY_COUNT, MA_MAIN_RESET_GAME, rom_loaded);
\r
1374 me_enable(main_entries, MAIN_ENTRY_COUNT, MA_MAIN_PATCHES, PicoPatches != NULL);
\r
1376 menu_sel_max = me_count_enabled(main_entries, MAIN_ENTRY_COUNT) - 1;
\r
1377 if (menu_sel > menu_sel_max) menu_sel = menu_sel_max;
\r
1379 /* make sure action buttons are not pressed on entering menu */
\r
1380 draw_menu_root(menu_sel);
\r
1382 while (Framework_PollGetButtons() & (BTN_PLAY|BTN_STOP|BTN_HOME)) Sleep(50);
\r
1386 draw_menu_root(menu_sel);
\r
1387 inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_PLAY|BTN_STOP|BTN_HOME|BTN_L|BTN_R);
\r
1388 if(inp & BTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }
\r
1389 if(inp & BTN_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }
\r
1390 if((inp & (BTN_L|BTN_R)) == (BTN_L|BTN_R)) debug_menu_loop();
\r
1391 if( inp & (BTN_HOME|BTN_STOP)) {
\r
1393 while (Framework_PollGetButtons() & (BTN_HOME|BTN_STOP)) Sleep(50); // wait until released
\r
1394 engineState = PGS_Running;
\r
1398 if(inp & BTN_PLAY) {
\r
1399 switch (me_index2id(main_entries, MAIN_ENTRY_COUNT, menu_sel))
\r
1401 case MA_MAIN_RESUME_GAME:
\r
1403 while (Framework_PollGetButtons() & BTN_PLAY) Sleep(50);
\r
1404 engineState = PGS_Running;
\r
1408 case MA_MAIN_SAVE_STATE:
\r
1410 if(savestate_menu_loop(0))
\r
1412 engineState = PGS_Running;
\r
1416 case MA_MAIN_LOAD_STATE:
\r
1418 if(savestate_menu_loop(1))
\r
1420 while (Framework_PollGetButtons() & BTN_PLAY) Sleep(50);
\r
1421 engineState = PGS_Running;
\r
1425 case MA_MAIN_RESET_GAME:
\r
1428 while (Framework_PollGetButtons() & BTN_PLAY) Sleep(50);
\r
1429 engineState = PGS_Running;
\r
1433 case MA_MAIN_LOAD_ROM:
\r
1435 char curr_path[MAX_PATH], *selfname;
\r
1437 if ( (tstf = fopen(currentConfig.lastRomFile, "rb")) )
\r
1440 strcpy(curr_path, currentConfig.lastRomFile);
\r
1443 getcwd(curr_path, MAX_PATH);
\r
1444 selfname = romsel_loop(curr_path);
\r
1446 lprintf("selected file: %s\n", selfname);
\r
1447 engineState = PGS_ReloadRom;
\r
1452 case MA_MAIN_OPTIONS:
\r
1453 ret = menu_loop_options();
\r
1454 if (ret == 1) continue; // status update
\r
1455 if (engineState == PGS_ReloadRom)
\r
1456 return; // BIOS test
\r
1458 case MA_MAIN_CONTROLS:
\r
1461 case MA_MAIN_CREDITS:
\r
1462 draw_menu_credits();
\r
1464 inp = wait_for_input(BTN_PLAY|BTN_STOP);
\r
1466 case MA_MAIN_EXIT:
\r
1467 engineState = PGS_Quit;
\r
1469 case MA_MAIN_PATCHES:
\r
1470 if (rom_loaded && PicoPatches) {
\r
1471 patches_menu_loop();
\r
1473 strcpy(menuErrorMsg, "Patches applied");
\r
1478 lprintf("%s: something unknown selected\n", __FUNCTION__);
\r
1482 menuErrorMsg[0] = 0; // clear error msg
\r
1486 // warning: alignment
\r
1487 static void menu_darken_bg(void *dst, const void *src, int pixels, int darker)
\r
1489 unsigned int *dest = dst;
\r
1490 const unsigned int *srce = src;
\r
1496 unsigned int p = *srce++;
\r
1497 *dest++ = ((p&0xf79ef79e)>>1) - ((p&0xc618c618)>>3);
\r
1504 unsigned int p = *srce++;
\r
1505 *dest++ = (p&0xf79ef79e)>>1;
\r
1510 static void menu_prepare_bg(int use_game_bg)
\r
1514 // darken the active framebuffer
\r
1515 if (giz_screen == NULL)
\r
1516 giz_screen = Framework2D_LockBuffer(1);
\r
1517 memset(bg_buffer, 0, 321*8*2);
\r
1518 menu_darken_bg(bg_buffer + 321*8*2, (char *)giz_screen + 321*8*2, 321*224, 1);
\r
1519 memset(bg_buffer + 321*232*2, 0, 321*8*2);
\r
1520 Framework2D_UnlockBuffer();
\r
1521 giz_screen = NULL;
\r
1526 // should really only happen once, on startup..
\r
1527 readpng(bg_buffer, "skin/background.png", READPNG_BG);
\r
1528 // adjust 320 width to 321
\r
1529 for (i = 239; i > 0; i--)
\r
1530 memmove(bg_buffer + 321*2*i, bg_buffer + 320*2*i, 320*2);
\r
1534 static void menu_gfx_prepare(void)
\r
1536 menu_prepare_bg(rom_loaded);
\r
1538 menu_draw_begin(1);
\r
1543 void menu_loop(void)
\r
1545 menu_gfx_prepare();
\r
1549 menuErrorMsg[0] = 0;
\r
1553 // --------- CD tray close menu ----------
\r
1555 static void draw_menu_tray(int menu_sel)
\r
1557 int tl_x = 70, tl_y = 90, y;
\r
1559 menu_draw_begin(1);
\r
1561 text_out16(tl_x, 20, "The unit is about to");
\r
1562 text_out16(tl_x, 30, "close the CD tray.");
\r
1565 text_out16(tl_x, y, "Load new CD image");
\r
1566 text_out16(tl_x, (y+=10), "Insert nothing");
\r
1569 text_out16(tl_x - 16, tl_y + menu_sel*10, ">");
\r
1571 if (menuErrorMsg[0]) text_out16(5, 226, menuErrorMsg);
\r
1576 int menu_loop_tray(void)
\r
1578 int menu_sel = 0, menu_sel_max = 1;
\r
1579 unsigned long inp = 0;
\r
1580 char curr_path[MAX_PATH], *selfname;
\r
1583 menu_gfx_prepare();
\r
1585 if ( (tstf = fopen(currentConfig.lastRomFile, "rb")) )
\r
1588 strcpy(curr_path, currentConfig.lastRomFile);
\r
1592 getcwd(curr_path, MAX_PATH);
\r
1595 /* make sure action buttons are not pressed on entering menu */
\r
1596 draw_menu_tray(menu_sel);
\r
1597 while (Framework_PollGetButtons() & BTN_PLAY) Sleep(50);
\r
1601 draw_menu_tray(menu_sel);
\r
1602 inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_PLAY);
\r
1603 if(inp & BTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }
\r
1604 if(inp & BTN_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }
\r
1605 if(inp & BTN_PLAY ) {
\r
1606 switch (menu_sel) {
\r
1607 case 0: // select image
\r
1608 selfname = romsel_loop(curr_path);
\r
1611 cd_img_type cd_type;
\r
1612 cd_type = emu_cdCheck(NULL);
\r
1613 if (cd_type != CIT_NOT_CD)
\r
1614 ret = Insert_CD(romFileName, cd_type);
\r
1616 sprintf(menuErrorMsg, "Load failed, invalid CD image?");
\r
1617 lprintf("%s\n", menuErrorMsg);
\r
1620 engineState = PGS_RestartRun;
\r
1624 case 1: // insert nothing
\r
1625 engineState = PGS_RestartRun;
\r
1629 menuErrorMsg[0] = 0; // clear error msg
\r