#include "input.h"\r
#include "emu.h"\r
#include "plat.h"\r
+#include "posix.h"\r
\r
+#include <pico/pico_int.h>\r
#include <pico/patch.h>\r
+#include <zlib/zlib.h>\r
\r
-char menuErrorMsg[64] = { 0, };\r
+#define array_size(x) (sizeof(x) / sizeof(x[0]))\r
\r
-// PicoPad[] format: MXYZ SACB RLDU\r
-me_bind_action me_ctrl_actions[15] =\r
-{\r
- { "UP ", 0x0001 },\r
- { "DOWN ", 0x0002 },\r
- { "LEFT ", 0x0004 },\r
- { "RIGHT ", 0x0008 },\r
- { "A ", 0x0040 },\r
- { "B ", 0x0010 },\r
- { "C ", 0x0020 },\r
- { "A turbo", 0x4000 },\r
- { "B turbo", 0x1000 },\r
- { "C turbo", 0x2000 },\r
- { "START ", 0x0080 },\r
- { "MODE ", 0x0800 },\r
- { "X ", 0x0400 },\r
- { "Y ", 0x0200 },\r
- { "Z ", 0x0100 }\r
-};\r
+static char static_buff[64];\r
+char menuErrorMsg[64] = { 0, };\r
\r
\r
#ifndef UIQ3\r
len = 1;\r
}\r
else\r
- len = strlen(text);\r
+ {\r
+ const char *p;\r
+ for (p = text; *p != 0 && *p != '\n'; p++)\r
+ ;\r
+ len = p - text;\r
+ }\r
\r
for (i = 0; i < len; i++)\r
{\r
}\r
\r
\r
-void smalltext_out16(int x, int y, const char *texto, int color)\r
+static void smalltext_out16_(int x, int y, const char *texto, int color)\r
{\r
int i;\r
unsigned char *src;\r
}\r
}\r
\r
-void smalltext_out16_lim(int x, int y, const char *texto, int color, int max)\r
+void smalltext_out16(int x, int y, const char *texto, int color)\r
{\r
- char buffer[SCREEN_WIDTH/6+1];\r
+ char buffer[SCREEN_WIDTH/6+1];\r
\r
- strncpy(buffer, texto, SCREEN_WIDTH/6);\r
- if (max > SCREEN_WIDTH/6) max = SCREEN_WIDTH/6;\r
- if (max < 0) max = 0;\r
- buffer[max] = 0;\r
+ strncpy(buffer, texto, sizeof(buffer));\r
+ buffer[sizeof(buffer) - 1] = 0;\r
\r
- smalltext_out16(x, y, buffer, color);\r
+ smalltext_out16_(x, y, buffer, color);\r
}\r
\r
-void menu_draw_selection(int x, int y, int w)\r
+static void menu_draw_selection(int x, int y, int w)\r
{\r
int i, h;\r
unsigned short *dst, *dest;\r
}\r
\r
\r
-int me_id2offset(const menu_entry *ent, menu_id id)\r
+static int me_id2offset(const menu_entry *ent, menu_id id)\r
{\r
int i;\r
for (i = 0; ent->name; ent++, i++)\r
return 0;\r
}\r
\r
-void me_enable(menu_entry *entries, menu_id id, int enable)\r
+static void me_enable(menu_entry *entries, menu_id id, int enable)\r
{\r
int i = me_id2offset(entries, id);\r
entries[i].enabled = enable;\r
}\r
\r
-int me_count(const menu_entry *ent)\r
+static int me_count(const menu_entry *ent)\r
{\r
int ret;\r
\r
return ret;\r
}\r
\r
-menu_id me_index2id(const menu_entry *ent, int index)\r
-{\r
- const menu_entry *last;\r
-\r
- for (; ent->name; ent++)\r
- {\r
- if (ent->enabled)\r
- {\r
- if (index == 0) break;\r
- index--;\r
- }\r
- last = ent;\r
- }\r
- if (ent->name == NULL)\r
- ent = last;\r
- return ent->id;\r
-}\r
-\r
-/* TODO rm */\r
-void me_draw(const menu_entry *entries, int count, int x, int y, me_draw_custom_f *cust_draw, void *param)\r
-{\r
- int i, y1 = y;\r
-\r
- for (i = 0; i < count; i++)\r
- {\r
- if (!entries[i].enabled) continue;\r
- if (entries[i].name == NULL)\r
- {\r
- if (cust_draw != NULL)\r
- cust_draw(&entries[i], x, y1, param);\r
- y1 += 10;\r
- continue;\r
- }\r
- text_out16(x, y1, entries[i].name);\r
- if (entries[i].beh == MB_OPT_ONOFF)\r
- text_out16(x + 27*8, y1, (*(int *)entries[i].var & entries[i].mask) ? "ON" : "OFF");\r
- else if (entries[i].beh == MB_OPT_RANGE)\r
- text_out16(x + 27*8, y1, "%i", *(int *)entries[i].var);\r
- y1 += 10;\r
- }\r
-\r
-}\r
-\r
-static void me_draw2(const menu_entry *entries, int sel)\r
+static void me_draw(const menu_entry *entries, int sel)\r
{\r
const menu_entry *ent;\r
int x, y, w = 0, h = 0;\r
- int opt_offs = 27*8;\r
+ int offs, opt_offs = 27*8;\r
const char *name;\r
int asel = 0;\r
int i, n;\r
name = NULL;\r
wt = strlen(ent->name) * 8; /* FIXME: unhardcode font width */\r
if (wt == 0 && ent->generate_name)\r
- name = ent->generate_name(1);\r
+ name = ent->generate_name(ent->id, &offs);\r
if (name != NULL)\r
wt = strlen(name) * 8;\r
\r
case MB_OPT_ONOFF:\r
case MB_OPT_RANGE: wt += 8*3; break;\r
case MB_OPT_CUSTOM:\r
+ case MB_OPT_CUSTONOFF:\r
+ case MB_OPT_CUSTRANGE:\r
name = NULL;\r
+ offs = 0;\r
if (ent->generate_name != NULL)\r
- name = ent->generate_name(0);\r
+ name = ent->generate_name(ent->id, &offs);\r
if (name != NULL)\r
- wt += strlen(name) * 8;\r
+ wt += (strlen(name) + offs) * 8;\r
break;\r
}\r
}\r
name = ent->name;\r
if (strlen(name) == 0) {\r
if (ent->generate_name)\r
- name = ent->generate_name(1);\r
+ name = ent->generate_name(ent->id, &offs);\r
}\r
if (name != NULL)\r
text_out16(x + 16, y, name);\r
text_out16(x + 16 + opt_offs, y, "%i", *(int *)ent->var);\r
break;\r
case MB_OPT_CUSTOM:\r
+ case MB_OPT_CUSTONOFF:\r
+ case MB_OPT_CUSTRANGE:\r
name = NULL;\r
+ offs = 0;\r
if (ent->generate_name)\r
- name = ent->generate_name(0);\r
+ name = ent->generate_name(ent->id, &offs);\r
if (name != NULL)\r
- text_out16(x + 16 + opt_offs, y, "%s", name);\r
+ text_out16(x + 16 + opt_offs + offs * 8, y, "%s", name);\r
break;\r
}\r
\r
y += 10;\r
}\r
\r
+ /* display message if we have one */\r
+ if (menuErrorMsg[0] != 0) {\r
+ static int msg_redraws = 0;\r
+ if (SCREEN_HEIGHT - h >= 2*10)\r
+ text_out16(5, 226, menuErrorMsg);\r
+ else\r
+ lprintf("menu msg doesn't fit!\n");\r
+\r
+ if (++msg_redraws > 4) {\r
+ menuErrorMsg[0] = 0;\r
+ msg_redraws = 0;\r
+ }\r
+ }\r
+\r
plat_video_menu_end();\r
}\r
\r
-int me_process(menu_entry *entries, menu_id id, int is_next)\r
+static int me_process(menu_entry *entry, int is_next)\r
{\r
- int i = me_id2offset(entries, id);\r
- menu_entry *entry = &entries[i];\r
switch (entry->beh)\r
{\r
case MB_OPT_ONOFF:\r
+ case MB_OPT_CUSTONOFF:\r
*(int *)entry->var ^= entry->mask;\r
return 1;\r
case MB_OPT_RANGE:\r
+ case MB_OPT_CUSTRANGE:\r
*(int *)entry->var += is_next ? 1 : -1;\r
- if (*(int *)entry->var < (int)entry->min) *(int *)entry->var = (int)entry->min;\r
- if (*(int *)entry->var > (int)entry->max) *(int *)entry->var = (int)entry->max;\r
+ if (*(int *)entry->var < (int)entry->min)\r
+ *(int *)entry->var = (int)entry->max;\r
+ if (*(int *)entry->var > (int)entry->max)\r
+ *(int *)entry->var = (int)entry->min;\r
return 1;\r
default:\r
return 0;\r
}\r
}\r
\r
+static void debug_menu_loop(void);\r
+\r
static void me_loop(menu_entry *menu, int *menu_sel)\r
{\r
int ret, inp, sel = *menu_sel, menu_sel_max;\r
sel++;\r
\r
/* make sure action buttons are not pressed on entering menu */\r
- me_draw2(menu, sel);\r
+ me_draw(menu, sel);\r
while (in_menu_wait_any(50) & (PBTN_MOK|PBTN_MBACK|PBTN_MENU));\r
\r
for (;;)\r
{\r
- me_draw2(menu, sel);\r
- inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_MOK|PBTN_MBACK|PBTN_MENU|PBTN_L|PBTN_R);\r
+ me_draw(menu, sel);\r
+ inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|\r
+ PBTN_MOK|PBTN_MBACK|PBTN_MENU|PBTN_L|PBTN_R, 70);\r
+ if (inp & (PBTN_MENU|PBTN_MBACK))\r
+ break;\r
+\r
if (inp & PBTN_UP ) {\r
do {\r
sel--;\r
if (sel < 0)\r
sel = menu_sel_max;\r
}\r
- while (!menu[sel].enabled);\r
+ while (!menu[sel].enabled || !menu[sel].selectable);\r
}\r
if (inp & PBTN_DOWN) {\r
do {\r
if (sel > menu_sel_max)\r
sel = 0;\r
}\r
- while (!menu[sel].enabled);\r
+ while (!menu[sel].enabled || !menu[sel].selectable);\r
+ }\r
+\r
+ /* a bit hacky but oh well */\r
+ if ((inp & (PBTN_L|PBTN_R)) == (PBTN_L|PBTN_R))\r
+ debug_menu_loop();\r
+\r
+ if (inp & (PBTN_LEFT|PBTN_RIGHT)) { /* multi choice */\r
+ if (me_process(&menu[sel], (inp & PBTN_RIGHT) ? 1 : 0))\r
+ continue;\r
}\r
-// if ((inp & (PBTN_L|PBTN_R)) == (PBTN_L|PBTN_R)) debug_menu_loop(); // TODO\r
- if (inp & (PBTN_MENU|PBTN_MBACK))\r
- break;\r
\r
- if (inp & PBTN_MOK)\r
+ if (inp & (PBTN_MOK|PBTN_LEFT|PBTN_RIGHT))\r
{\r
- if (menu[sel].submenu_handler != NULL) {\r
- ret = menu[sel].submenu_handler(menu[sel].id);\r
+ if (menu[sel].handler != NULL) {\r
+ ret = menu[sel].handler(menu[sel].id, inp);\r
if (ret) break;\r
+ menu_sel_max = me_count(menu) - 1; /* might change */\r
}\r
}\r
-// menuErrorMsg[0] = 0; // TODO: clear error msg\r
}\r
*menu_sel = sel;\r
}\r
\r
/* ***************************************** */\r
\r
-/* TODO s */\r
-int menu_loop_tray(void) { return 0; }\r
-void menu_romload_prepare(const char *rom_name) {}\r
-void menu_romload_end(void) {}\r
-me_bind_action emuctrl_actions[1];\r
-menu_entry opt_entries[1];\r
-menu_entry opt2_entries[1];\r
-menu_entry cdopt_entries[1];\r
-menu_entry ctrlopt_entries[1];\r
-const int opt_entry_count = 0;\r
-const int opt2_entry_count = 0;\r
-const int cdopt_entry_count = 0;\r
-const int ctrlopt_entry_count = 0;\r
-\r
-extern int engineState;\r
-\r
-int savestate_menu_loop(int a) { return 1; }\r
-int menu_loop_options() { return 1; }\r
-void kc_sel_loop() {}\r
-void draw_menu_credits() {}\r
-void patches_menu_loop() {}\r
+static void draw_menu_credits(void)\r
+{\r
+ const char *creds, *p;\r
+ int x, y, h, w, wt;\r
\r
-// ------------ main menu ------------\r
+ p = creds = plat_get_credits();\r
\r
-static int main_menu_handler(menu_id id)\r
-{\r
- int ret;\r
+ for (h = 1, w = 0; *p != 0; h++) {\r
+ for (wt = 0; *p != 0 && *p != '\n'; p++)\r
+ wt++;\r
\r
- switch (id)\r
- {\r
- case MA_MAIN_RESUME_GAME:\r
- if (rom_loaded) {\r
- while (in_menu_wait_any(50) & PBTN_MOK);\r
- engineState = PGS_Running;\r
- return 1;\r
- }\r
- break;\r
- case MA_MAIN_SAVE_STATE:\r
- if (rom_loaded) {\r
- if (savestate_menu_loop(0))\r
- break;\r
- engineState = PGS_Running;\r
- return 1;\r
- }\r
- break;\r
- case MA_MAIN_LOAD_STATE:\r
- if (rom_loaded) {\r
- if (savestate_menu_loop(1))\r
- break;\r
- while (in_menu_wait_any(50) & PBTN_MOK);\r
- engineState = PGS_Running;\r
- return 1;\r
- }\r
- break;\r
- case MA_MAIN_RESET_GAME:\r
- if (rom_loaded) {\r
- emu_ResetGame();\r
- while (in_menu_wait_any(50) & PBTN_MOK);\r
- engineState = PGS_Running;\r
- return 1;\r
- }\r
- break;\r
- case MA_MAIN_LOAD_ROM:\r
- {\r
-/* char curr_path[PATH_MAX], *selfname;\r
- FILE *tstf;\r
- if ( (tstf = fopen(loadedRomFName, "rb")) )\r
- {\r
- fclose(tstf);\r
- strcpy(curr_path, loadedRomFName);\r
- }\r
- else\r
- getcwd(curr_path, PATH_MAX);\r
- selfname = romsel_loop(curr_path);\r
- if (selfname) {\r
- printf("selected file: %s\n", selfname);\r
- engineState = PGS_ReloadRom;\r
- return;\r
- }*/\r
+ if (wt > w)\r
+ w = wt;\r
+ if (*p == 0)\r
break;\r
- }\r
- case MA_MAIN_OPTIONS:\r
- ret = menu_loop_options();\r
- if (ret == 1) break; // status update\r
- if (engineState == PGS_ReloadRom)\r
- return 1; // BIOS test\r
- break;\r
- case MA_MAIN_CONTROLS:\r
- kc_sel_loop();\r
- break;\r
- case MA_MAIN_CREDITS:\r
- draw_menu_credits();\r
- usleep(500*1000); /* FIXME */\r
- in_menu_wait(PBTN_MOK|PBTN_MBACK);\r
- break;\r
- case MA_MAIN_EXIT:\r
- engineState = PGS_Quit;\r
- return 1;\r
- case MA_MAIN_PATCHES:\r
- if (rom_loaded && PicoPatches) {\r
- patches_menu_loop();\r
- PicoPatchApply();\r
- strcpy(menuErrorMsg, "Patches applied");\r
- }\r
- break;\r
- default:\r
- lprintf("%s: something unknown selected\n", __FUNCTION__);\r
- break;\r
+ p++;\r
}\r
\r
- return 0;\r
+ x = SCREEN_WIDTH / 2 - w * 8 / 2;\r
+ y = SCREEN_HEIGHT / 2 - h * 10 / 2;\r
+ if (x < 0) x = 0;\r
+ if (y < 0) y = 0;\r
+\r
+ plat_video_menu_begin();\r
+\r
+ for (p = creds; *p != 0 && y <= SCREEN_HEIGHT - 10; y += 10) {\r
+ text_out16(x, y, p);\r
+\r
+ for (; *p != 0 && *p != '\n'; p++)\r
+ ;\r
+ if (*p != 0)\r
+ p++;\r
+ }\r
+\r
+ plat_video_menu_end();\r
}\r
\r
-menu_entry e_main_menu[] =\r
+// --------- loading ROM screen ----------\r
+\r
+static int cdload_called = 0;\r
+\r
+static void load_progress_cb(int percent)\r
{\r
- mee_submenu_id("Resume game", MA_MAIN_RESUME_GAME, main_menu_handler),\r
- mee_submenu_id("Save State", MA_MAIN_SAVE_STATE, main_menu_handler),\r
- mee_submenu_id("Load State", MA_MAIN_LOAD_STATE, main_menu_handler),\r
- mee_submenu_id("Reset game", MA_MAIN_RESET_GAME, main_menu_handler),\r
- mee_submenu_id("Load new ROM/ISO", MA_MAIN_LOAD_ROM, main_menu_handler),\r
- mee_submenu_id("Change options", MA_MAIN_OPTIONS, main_menu_handler),\r
- mee_submenu_id("Credits", MA_MAIN_CREDITS, main_menu_handler),\r
- mee_submenu_id("Patches / GameGenie",MA_MAIN_PATCHES, main_menu_handler),\r
- mee_submenu_id("Exit", MA_MAIN_EXIT, main_menu_handler),\r
- mee_end,\r
-};\r
+ int ln, len = percent * SCREEN_WIDTH / 100;\r
+ unsigned short *dst = (unsigned short *)SCREEN_BUFFER + SCREEN_WIDTH * 10 * 2;\r
\r
-void menu_loop(void)\r
+ if (len > SCREEN_WIDTH)\r
+ len = SCREEN_WIDTH;\r
+ for (ln = 10 - 2; ln > 0; ln--, dst += SCREEN_WIDTH)\r
+ memset(dst, 0xff, len * 2);\r
+ plat_video_menu_end();\r
+}\r
+\r
+static void cdload_progress_cb(int percent)\r
{\r
- static int sel = 0;\r
+ int ln, len = percent * SCREEN_WIDTH / 100;\r
+ unsigned short *dst = (unsigned short *)SCREEN_BUFFER + SCREEN_WIDTH * 10 * 2;\r
\r
- me_enable(e_main_menu, MA_MAIN_RESUME_GAME, rom_loaded);\r
- me_enable(e_main_menu, MA_MAIN_SAVE_STATE, rom_loaded);\r
- me_enable(e_main_menu, MA_MAIN_LOAD_STATE, rom_loaded);\r
- me_enable(e_main_menu, MA_MAIN_RESET_GAME, rom_loaded);\r
- me_enable(e_main_menu, MA_MAIN_PATCHES, PicoPatches != NULL);\r
+ memset(dst, 0xff, SCREEN_WIDTH * (10 - 2) * 2);\r
\r
- plat_video_menu_enter(rom_loaded);\r
- in_set_blocking(1);\r
- me_loop(e_main_menu, &sel);\r
- in_set_blocking(0);\r
+ smalltext_out16(1, 3 * 10, "Processing CD image / MP3s", 0xffff);\r
+ smalltext_out16(1, 4 * 10, rom_fname_loaded, 0xffff);\r
+ dst += SCREEN_WIDTH * 30;\r
\r
- if (rom_loaded) {\r
- while (in_menu_wait_any(50) & (PBTN_MENU|PBTN_MBACK)); // wait until select is released\r
- engineState = PGS_Running;\r
- }\r
+ if (len > SCREEN_WIDTH)\r
+ len = SCREEN_WIDTH;\r
+ for (ln = (10 - 2); ln > 0; ln--, dst += SCREEN_WIDTH)\r
+ memset(dst, 0xff, len * 2);\r
\r
+ plat_video_menu_end();\r
+ cdload_called = 1;\r
}\r
\r
-// ------------ debug menu ------------\r
+void menu_romload_prepare(const char *rom_name)\r
+{\r
+ const char *p = rom_name + strlen(rom_name);\r
\r
-#include <sys/stat.h>\r
-#include <sys/types.h>\r
+ plat_video_menu_begin();\r
\r
-#include <pico/pico.h>\r
-#include <pico/debug.h>\r
+ while (p > rom_name && *p != '/')\r
+ p--;\r
\r
-void SekStepM68k(void);\r
+ /* fill both buffers, callbacks won't update in full */\r
+ smalltext_out16(1, 1, "Loading", 0xffff);\r
+ smalltext_out16(1, 10, p, 0xffff);\r
+ plat_video_menu_end();\r
\r
-static void mplayer_loop(void)\r
+ smalltext_out16(1, 1, "Loading", 0xffff);\r
+ smalltext_out16(1, 10, p, 0xffff);\r
+ plat_video_menu_end();\r
+\r
+ PicoCartLoadProgressCB = load_progress_cb;\r
+ PicoCDLoadProgressCB = cdload_progress_cb;\r
+ cdload_called = 0;\r
+}\r
+\r
+void menu_romload_end(void)\r
{\r
- emu_startSound();\r
+ PicoCartLoadProgressCB = PicoCDLoadProgressCB = NULL;\r
+ smalltext_out16(1, (cdload_called ? 6 : 3) * 10,\r
+ "Starting emulation...", 0xffff);\r
+ plat_video_menu_end();\r
+}\r
\r
- while (1)\r
- {\r
- PDebugZ80Frame();\r
- if (in_menu_wait_any(0) & PBTN_NORTH) break;\r
- emu_waitSound();\r
- }\r
+// -------------- ROM selector --------------\r
\r
- emu_endSound();\r
+// rrrr rggg gggb bbbb\r
+static unsigned short file2color(const char *fname)\r
+{\r
+ const char *ext = fname + strlen(fname) - 3;\r
+ static const char *rom_exts[] = { "zip", "bin", "smd", "gen", "iso", "cso", "cue" };\r
+ static const char *other_exts[] = { "gmv", "pat" };\r
+ int i;\r
+\r
+ if (ext < fname) ext = fname;\r
+ for (i = 0; i < array_size(rom_exts); i++)\r
+ if (strcasecmp(ext, rom_exts[i]) == 0) return 0xbdff; // FIXME: mk defines\r
+ for (i = 0; i < array_size(other_exts); i++)\r
+ if (strcasecmp(ext, other_exts[i]) == 0) return 0xaff5;\r
+ return 0xffff;\r
}\r
\r
-static void draw_text_debug(const char *str, int skip, int from)\r
+static void draw_dirlist(char *curdir, struct dirent **namelist, int n, int sel)\r
{\r
- const char *p;\r
- int len, line;\r
+ int max_cnt, start, i, pos;\r
\r
- p = str;\r
- while (skip-- > 0)\r
- {\r
- while (*p && *p != '\n') p++;\r
- if (*p == 0 || p[1] == 0) return;\r
- p++;\r
- }\r
+ max_cnt = SCREEN_HEIGHT / 10;\r
+ start = max_cnt / 2 - sel;\r
+ n--; // exclude current dir (".")\r
\r
- str = p;\r
- for (line = from; line < SCREEN_HEIGHT/10; line++)\r
- {\r
- while (*p && *p != '\n') p++;\r
- len = p - str;\r
- if (len > 55) len = 55;\r
- smalltext_out16_lim(1, line*10, str, 0xffff, len);\r
- if (*p == 0) break;\r
- p++; str = p;\r
+ plat_video_menu_begin();\r
+\r
+// if (!rom_loaded)\r
+// menu_darken_bg(gp2x_screen, 320*240, 0);\r
+\r
+ menu_darken_bg((short *)SCREEN_BUFFER + SCREEN_WIDTH * max_cnt/2 * 10, SCREEN_WIDTH * 8, 0);\r
+\r
+ if (start - 2 >= 0)\r
+ smalltext_out16(14, (start - 2)*10, curdir, 0xffff);\r
+ for (i = 0; i < n; i++) {\r
+ pos = start + i;\r
+ if (pos < 0) continue;\r
+ if (pos >= max_cnt) break;\r
+ if (namelist[i+1]->d_type == DT_DIR) {\r
+ smalltext_out16(14, pos*10, "/", 0xfff6);\r
+ smalltext_out16(14+6, pos*10, namelist[i+1]->d_name, 0xfff6);\r
+ } else {\r
+ unsigned short color = file2color(namelist[i+1]->d_name);\r
+ smalltext_out16(14, pos*10, namelist[i+1]->d_name, color);\r
+ }\r
}\r
+ text_out16(5, max_cnt/2 * 10, ">");\r
+ plat_video_menu_end();\r
}\r
\r
-static void draw_frame_debug(void)\r
+static int scandir_cmp(const void *p1, const void *p2)\r
{\r
- char layer_str[48] = "layers: ";\r
- if (PicoDrawMask & PDRAW_LAYERB_ON) memcpy(layer_str + 8, "B", 1);\r
- if (PicoDrawMask & PDRAW_LAYERA_ON) memcpy(layer_str + 10, "A", 1);\r
- if (PicoDrawMask & PDRAW_SPRITES_LOW_ON) memcpy(layer_str + 12, "spr_lo", 6);\r
- if (PicoDrawMask & PDRAW_SPRITES_HI_ON) memcpy(layer_str + 19, "spr_hi", 6);\r
+ struct dirent **d1 = (struct dirent **)p1, **d2 = (struct dirent **)p2;\r
+ if ((*d1)->d_type == (*d2)->d_type) return alphasort(d1, d2);\r
+ if ((*d1)->d_type == DT_DIR) return -1; // put before\r
+ if ((*d2)->d_type == DT_DIR) return 1;\r
+ return alphasort(d1, d2);\r
+}\r
\r
- clear_screen();\r
- emu_forcedFrame(0);\r
- smalltext_out16(4, SCREEN_HEIGHT-8, layer_str, 0xffff);\r
+static const char *filter_exts[] = {\r
+ ".mp3", ".MP3", ".srm", ".brm", "s.gz", ".mds", "bcfg", ".txt", ".htm", "html",\r
+ ".jpg", ".gpe"\r
+};\r
+\r
+static int scandir_filter(const struct dirent *ent)\r
+{\r
+ const char *p;\r
+ int i;\r
+\r
+ if (ent == NULL || ent->d_name == NULL) return 0;\r
+ if (strlen(ent->d_name) < 5) return 1;\r
+\r
+ p = ent->d_name + strlen(ent->d_name) - 4;\r
+\r
+ for (i = 0; i < array_size(filter_exts); i++)\r
+ if (strcmp(p, filter_exts[i]) == 0)\r
+ return 0;\r
+\r
+ return 1;\r
}\r
\r
-void debug_menu_loop(void)\r
+static char *menu_loop_romsel(char *curr_path, int len)\r
{\r
- int inp, mode = 0;\r
- int spr_offs = 0, dumped = 0;\r
- char *tmp;\r
+ struct dirent **namelist;\r
+ int n, inp, sel = 0;\r
+ char *ret = NULL, *fname = NULL;\r
+\r
+rescan:\r
+ // is this a dir or a full path?\r
+ if (!plat_is_dir(curr_path)) {\r
+ char *p = curr_path + strlen(curr_path) - 1;\r
+ for (; p > curr_path && *p != '/'; p--)\r
+ ;\r
+ *p = 0;\r
+ fname = p+1;\r
+ }\r
\r
- while (1)\r
- {\r
- switch (mode)\r
- {\r
- case 0: plat_video_menu_begin();\r
- tmp = PDebugMain();\r
- emu_platformDebugCat(tmp);\r
- draw_text_debug(tmp, 0, 0);\r
- if (dumped) {\r
- smalltext_out16(SCREEN_WIDTH-6*10, SCREEN_HEIGHT-8, "dumped", 0xffff);\r
- dumped = 0;\r
- }\r
- break;\r
- case 1: draw_frame_debug(); break;\r
- case 2: clear_screen();\r
- emu_forcedFrame(0);\r
- darken_screen();\r
- PDebugShowSpriteStats((unsigned short *)SCREEN_BUFFER + (SCREEN_HEIGHT/2 - 240/2)*SCREEN_WIDTH +\r
- SCREEN_WIDTH/2 - 320/2, SCREEN_WIDTH); break;\r
- case 3: clear_screen();\r
- PDebugShowPalette(SCREEN_BUFFER, SCREEN_WIDTH);\r
- PDebugShowSprite((unsigned short *)SCREEN_BUFFER + SCREEN_WIDTH*120+SCREEN_WIDTH/2+16,\r
- SCREEN_WIDTH, spr_offs);\r
- draw_text_debug(PDebugSpriteList(), spr_offs, 6);\r
+ n = scandir(curr_path, &namelist, scandir_filter, scandir_cmp);\r
+ if (n < 0) {\r
+ lprintf("menu_loop_romsel failed, dir: %s\n", curr_path);\r
+\r
+ // try root\r
+ getcwd(curr_path, len);\r
+ n = scandir(curr_path, &namelist, scandir_filter, scandir_cmp);\r
+ if (n < 0) {\r
+ // oops, we failed\r
+ lprintf("menu_loop_romsel failed, dir: %s\n", curr_path);\r
+ return NULL;\r
+ }\r
+ }\r
+\r
+ // try to find sel\r
+ if (fname != NULL) {\r
+ int i;\r
+ for (i = 1; i < n; i++) {\r
+ if (strcmp(namelist[i]->d_name, fname) == 0) {\r
+ sel = i - 1;\r
break;\r
+ }\r
}\r
- plat_video_menu_end();\r
+ }\r
\r
- inp = in_menu_wait(PBTN_EAST|PBTN_MBACK|PBTN_WEST|PBTN_NORTH|PBTN_L|PBTN_R|PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT);\r
- if (inp & PBTN_MBACK) return;\r
- if (inp & PBTN_L) { mode--; if (mode < 0) mode = 3; }\r
- if (inp & PBTN_R) { mode++; if (mode > 3) mode = 0; }\r
- switch (mode)\r
+ for (;;)\r
+ {\r
+ draw_dirlist(curr_path, namelist, n, sel);\r
+ inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|\r
+ PBTN_L|PBTN_R|PBTN_WEST|PBTN_MOK|PBTN_MBACK|PBTN_MENU, 33); // TODO L R\r
+ if (inp & PBTN_UP ) { sel--; if (sel < 0) sel = n-2; }\r
+ if (inp & PBTN_DOWN) { sel++; if (sel > n-2) sel = 0; }\r
+ if (inp & PBTN_LEFT) { sel-=10; if (sel < 0) sel = 0; }\r
+ if (inp & PBTN_L) { sel-=24; if (sel < 0) sel = 0; }\r
+ if (inp & PBTN_RIGHT) { sel+=10; if (sel > n-2) sel = n-2; }\r
+ if (inp & PBTN_R) { sel+=24; if (sel > n-2) sel = n-2; }\r
+ if ((inp & PBTN_MOK) || (inp & (PBTN_MENU|PBTN_WEST)) == (PBTN_MENU|PBTN_WEST)) // enter dir/select || delete\r
{\r
- case 0:\r
- if (inp & PBTN_EAST) SekStepM68k();\r
- if (inp & PBTN_NORTH) {\r
- while (inp & PBTN_NORTH) inp = in_menu_wait_any(-1);\r
- mplayer_loop();\r
+ again:\r
+ if (namelist[sel+1]->d_type == DT_REG)\r
+ {\r
+ strcpy(rom_fname_reload, curr_path);\r
+ strcat(rom_fname_reload, "/");\r
+ strcat(rom_fname_reload, namelist[sel+1]->d_name);\r
+ if (inp & PBTN_MOK) { // return sel\r
+ ret = rom_fname_reload;\r
+ break;\r
}\r
- if ((inp & (PBTN_WEST|PBTN_LEFT)) == (PBTN_WEST|PBTN_LEFT)) {\r
- mkdir("dumps", 0777);\r
- PDebugDumpMem();\r
- while (inp & PBTN_WEST) inp = in_menu_wait_any(-1);\r
- dumped = 1;\r
+// do_delete(rom_fname_reload, namelist[sel+1]->d_name); // TODO\r
+ if (n > 0) {\r
+ while (n--) free(namelist[n]);\r
+ free(namelist);\r
+ }\r
+ goto rescan;\r
+ }\r
+ else if (namelist[sel+1]->d_type == DT_DIR)\r
+ {\r
+ int newlen;\r
+ char *p, *newdir;\r
+ if (!(inp & PBTN_MOK)) continue;\r
+ newlen = strlen(curr_path) + strlen(namelist[sel+1]->d_name) + 2;\r
+ newdir = malloc(newlen);\r
+ if (strcmp(namelist[sel+1]->d_name, "..") == 0) {\r
+ char *start = curr_path;\r
+ p = start + strlen(start) - 1;\r
+ while (*p == '/' && p > start) p--;\r
+ while (*p != '/' && p > start) p--;\r
+ if (p <= start) strcpy(newdir, "/");\r
+ else { strncpy(newdir, start, p-start); newdir[p-start] = 0; }\r
+ } else {\r
+ strcpy(newdir, curr_path);\r
+ p = newdir + strlen(newdir) - 1;\r
+ while (*p == '/' && p >= newdir) *p-- = 0;\r
+ strcat(newdir, "/");\r
+ strcat(newdir, namelist[sel+1]->d_name);\r
}\r
+ ret = menu_loop_romsel(newdir, newlen);\r
+ free(newdir);\r
break;\r
- case 1:\r
- if (inp & PBTN_LEFT) PicoDrawMask ^= PDRAW_LAYERB_ON;\r
- if (inp & PBTN_RIGHT) PicoDrawMask ^= PDRAW_LAYERA_ON;\r
- if (inp & PBTN_DOWN) PicoDrawMask ^= PDRAW_SPRITES_LOW_ON;\r
+ }\r
+ else\r
+ {\r
+ // unknown file type, happens on NTFS mounts. Try to guess.\r
+ FILE *tstf; int tmp;\r
+ strcpy(rom_fname_reload, curr_path);\r
+ strcat(rom_fname_reload, "/");\r
+ strcat(rom_fname_reload, namelist[sel+1]->d_name);\r
+ tstf = fopen(rom_fname_reload, "rb");\r
+ if (tstf != NULL)\r
+ {\r
+ if (fread(&tmp, 1, 1, tstf) > 0 || ferror(tstf) == 0)\r
+ namelist[sel+1]->d_type = DT_REG;\r
+ else namelist[sel+1]->d_type = DT_DIR;\r
+ fclose(tstf);\r
+ goto again;\r
+ }\r
+ }\r
+ }\r
+ if (inp & PBTN_MBACK)\r
+ break;\r
+ }\r
+\r
+ if (n > 0) {\r
+ while (n--) free(namelist[n]);\r
+ free(namelist);\r
+ }\r
+\r
+ return ret;\r
+}\r
+\r
+// ------------ patch/gg menu ------------\r
+\r
+static void draw_patchlist(int sel)\r
+{\r
+ int max_cnt, start, i, pos, active;\r
+\r
+ max_cnt = SCREEN_HEIGHT / 10;\r
+ start = max_cnt / 2 - sel;\r
+\r
+ plat_video_menu_begin();\r
+\r
+ for (i = 0; i < PicoPatchCount; i++) {\r
+ pos = start + i;\r
+ if (pos < 0) continue;\r
+ if (pos >= max_cnt) break;\r
+ active = PicoPatches[i].active;\r
+ smalltext_out16(14, pos*10, active ? "ON " : "OFF", active ? 0xfff6 : 0xffff);\r
+ smalltext_out16(14+6*4, pos*10, PicoPatches[i].name, active ? 0xfff6 : 0xffff);\r
+ }\r
+ pos = start + i;\r
+ if (pos < max_cnt)\r
+ smalltext_out16(14, pos * 10, "done", 0xffff);\r
+\r
+ text_out16(5, max_cnt / 2 * 10, ">");\r
+ plat_video_menu_end();\r
+}\r
+\r
+static void menu_loop_patches(void)\r
+{\r
+ static int menu_sel = 0;\r
+ int inp;\r
+\r
+ for (;;)\r
+ {\r
+ draw_patchlist(menu_sel);\r
+ inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|PBTN_L|PBTN_R|PBTN_MOK|PBTN_MBACK, 33);\r
+ if (inp & PBTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = PicoPatchCount; }\r
+ if (inp & PBTN_DOWN) { menu_sel++; if (menu_sel > PicoPatchCount) menu_sel = 0; }\r
+ if (inp &(PBTN_LEFT|PBTN_L)) { menu_sel-=10; if (menu_sel < 0) menu_sel = 0; }\r
+ if (inp &(PBTN_RIGHT|PBTN_R)) { menu_sel+=10; if (menu_sel > PicoPatchCount) menu_sel = PicoPatchCount; }\r
+ if (inp & PBTN_MOK) { // action\r
+ if (menu_sel < PicoPatchCount)\r
+ PicoPatches[menu_sel].active = !PicoPatches[menu_sel].active;\r
+ else break;\r
+ }\r
+ if (inp & PBTN_MBACK)\r
+ break;\r
+ }\r
+}\r
+\r
+// ------------ savestate loader ------------\r
+\r
+static int state_slot_flags = 0;\r
+\r
+static void state_check_slots(void)\r
+{\r
+ int slot;\r
+\r
+ state_slot_flags = 0;\r
+\r
+ for (slot = 0; slot < 10; slot++) {\r
+ if (emu_checkSaveFile(slot))\r
+ state_slot_flags |= 1 << slot;\r
+ }\r
+}\r
+\r
+static void draw_savestate_bg(int slot)\r
+{\r
+ struct PicoVideo tmp_pv;\r
+ unsigned short tmp_cram[0x40];\r
+ unsigned short tmp_vsram[0x40];\r
+ void *tmp_vram, *file;\r
+ char *fname;\r
+\r
+ fname = emu_GetSaveFName(1, 0, slot);\r
+ if (!fname) return;\r
+\r
+ tmp_vram = malloc(sizeof(Pico.vram));\r
+ if (tmp_vram == NULL) return;\r
+\r
+ memcpy(tmp_vram, Pico.vram, sizeof(Pico.vram));\r
+ memcpy(tmp_cram, Pico.cram, sizeof(Pico.cram));\r
+ memcpy(tmp_vsram, Pico.vsram, sizeof(Pico.vsram));\r
+ memcpy(&tmp_pv, &Pico.video, sizeof(Pico.video));\r
+\r
+ if (strcmp(fname + strlen(fname) - 3, ".gz") == 0) {\r
+ file = gzopen(fname, "rb");\r
+ emu_setSaveStateCbs(1);\r
+ } else {\r
+ file = fopen(fname, "rb");\r
+ emu_setSaveStateCbs(0);\r
+ }\r
+\r
+ if (file) {\r
+ if (PicoAHW & PAHW_MCD) {\r
+ PicoCdLoadStateGfx(file);\r
+ } else {\r
+ areaSeek(file, 0x10020, SEEK_SET); // skip header and RAM in state file\r
+ areaRead(Pico.vram, 1, sizeof(Pico.vram), file);\r
+ areaSeek(file, 0x2000, SEEK_CUR);\r
+ areaRead(Pico.cram, 1, sizeof(Pico.cram), file);\r
+ areaRead(Pico.vsram, 1, sizeof(Pico.vsram), file);\r
+ areaSeek(file, 0x221a0, SEEK_SET);\r
+ areaRead(&Pico.video, 1, sizeof(Pico.video), file);\r
+ }\r
+ areaClose(file);\r
+ }\r
+\r
+ /* do a frame and fetch menu bg */\r
+ emu_forcedFrame(POPT_EN_SOFTSCALE);\r
+ plat_video_menu_enter(1);\r
+\r
+ memcpy(Pico.vram, tmp_vram, sizeof(Pico.vram));\r
+ memcpy(Pico.cram, tmp_cram, sizeof(Pico.cram));\r
+ memcpy(Pico.vsram, tmp_vsram, sizeof(Pico.vsram));\r
+ memcpy(&Pico.video, &tmp_pv, sizeof(Pico.video));\r
+ free(tmp_vram);\r
+}\r
+\r
+static void draw_savestate_menu(int menu_sel, int is_loading)\r
+{\r
+ int i, x, y, w, h;\r
+\r
+ if (state_slot_flags & (1 << menu_sel))\r
+ draw_savestate_bg(menu_sel);\r
+\r
+ w = 13 * 8 + 16;\r
+ h = (1+2+10+1) * 10;\r
+ x = SCREEN_WIDTH / 2 - w / 2;\r
+ if (x < 0) x = 0;\r
+ y = SCREEN_HEIGHT / 2 - h / 2;\r
+ if (y < 0) y = 0;\r
+\r
+ plat_video_menu_begin();\r
+\r
+ text_out16(x, y, is_loading ? "Load state" : "Save state");\r
+ y += 3*10;\r
+\r
+ menu_draw_selection(x - 16, y + menu_sel * 10, 13 * 8 + 4);\r
+\r
+ /* draw all 10 slots */\r
+ y += 10;\r
+ for (i = 0; i < 10; i++, y += 10)\r
+ {\r
+ text_out16(x, y, "SLOT %i (%s)", i, (state_slot_flags & (1 << i)) ? "USED" : "free");\r
+ }\r
+ text_out16(x, y, "back");\r
+\r
+ plat_video_menu_end();\r
+}\r
+\r
+static int menu_loop_savestate(int is_loading)\r
+{\r
+ static int menu_sel = 10;\r
+ int menu_sel_max = 10;\r
+ unsigned long inp = 0;\r
+\r
+ state_check_slots();\r
+\r
+ for (;;)\r
+ {\r
+ draw_savestate_menu(menu_sel, is_loading);\r
+ inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_MOK|PBTN_MBACK, 100);\r
+ if (inp & PBTN_UP) {\r
+ do {\r
+ menu_sel--;\r
+ if (menu_sel < 0)\r
+ menu_sel = menu_sel_max;\r
+ } while (!(state_slot_flags & (1 << menu_sel)) && menu_sel != menu_sel_max && is_loading);\r
+ }\r
+ if (inp & PBTN_DOWN) {\r
+ do {\r
+ menu_sel++;\r
+ if (menu_sel > menu_sel_max)\r
+ menu_sel = 0;\r
+ } while (!(state_slot_flags & (1 << menu_sel)) && menu_sel != menu_sel_max && is_loading);\r
+ }\r
+ if (inp & PBTN_MOK) { // save/load\r
+ if (menu_sel < 10) {\r
+ state_slot = menu_sel;\r
+ if (emu_SaveLoadGame(is_loading, 0)) {\r
+ strcpy(menuErrorMsg, is_loading ? "Load failed" : "Save failed");\r
+ return 0;\r
+ }\r
+ return 1;\r
+ }\r
+ return 0;\r
+ }\r
+ if (inp & PBTN_MBACK)\r
+ return 0;\r
+ }\r
+}\r
+\r
+// -------------- key config --------------\r
+\r
+static char *action_binds(int player_idx, int action_mask, int dev_id)\r
+{\r
+ const int *binds;\r
+ int k, count;\r
+\r
+ static_buff[0] = 0;\r
+\r
+ binds = in_get_dev_binds(dev_id);\r
+ if (binds == NULL)\r
+ return static_buff;\r
+\r
+ count = in_get_dev_bind_count(dev_id);\r
+ for (k = 0; k < count; k++)\r
+ {\r
+ const char *xname;\r
+ if (!(binds[k] & action_mask))\r
+ continue;\r
+\r
+ if (player_idx >= 0 && ((binds[k] >> 16) & 3) != player_idx)\r
+ continue;\r
+\r
+ xname = in_get_key_name(dev_id, k);\r
+ if (static_buff[0])\r
+ strncat(static_buff, " + ", sizeof(static_buff));\r
+ strncat(static_buff, xname, sizeof(static_buff));\r
+ }\r
+\r
+ return static_buff;\r
+}\r
+\r
+static int count_bound_keys(int dev_id, int action_mask, int player_idx)\r
+{\r
+ const int *binds;\r
+ int k, keys = 0;\r
+ int count;\r
+\r
+ binds = in_get_dev_binds(dev_id);\r
+ if (binds == NULL)\r
+ return 0;\r
+\r
+ count = in_get_dev_bind_count(dev_id);\r
+ for (k = 0; k < count; k++)\r
+ {\r
+ if (!(binds[k] & action_mask))\r
+ continue;\r
+\r
+ if (player_idx >= 0 && ((binds[k] >> 16) & 3) != player_idx)\r
+ continue;\r
+\r
+ keys++;\r
+ }\r
+\r
+ return keys;\r
+}\r
+\r
+static void draw_key_config(const me_bind_action *opts, int opt_cnt, int player_idx,\r
+ int sel, int dev_id, int dev_count, int is_bind)\r
+{\r
+ int x, y = 30, w, i;\r
+ const char *dev_name;\r
+\r
+ x = SCREEN_WIDTH / 2 - 32*8 / 2;\r
+ if (x < 0) x = 0;\r
+\r
+ plat_video_menu_begin();\r
+ if (player_idx >= 0)\r
+ text_out16(x, 10, "Player %i controls", player_idx + 1);\r
+ else\r
+ text_out16(x, 10, "Emulator controls");\r
+\r
+ menu_draw_selection(x - 16, y + sel*10, (player_idx >= 0) ? 66 : 140);\r
+\r
+ for (i = 0; i < opt_cnt; i++, y+=10)\r
+ text_out16(x, y, "%s : %s", opts[i].name,\r
+ action_binds(player_idx, opts[i].mask, dev_id));\r
+\r
+ dev_name = in_get_dev_name(dev_id, 1, 1);\r
+ w = strlen(dev_name) * 8;\r
+ if (w < 30 * 8)\r
+ w = 30 * 8;\r
+ if (w > SCREEN_WIDTH)\r
+ w = SCREEN_WIDTH;\r
+\r
+ x = SCREEN_WIDTH / 2 - w / 2;\r
+\r
+ if (dev_count > 1) {\r
+ text_out16(x, SCREEN_HEIGHT - 4*10, "Viewing binds for:");\r
+ text_out16(x, SCREEN_HEIGHT - 3*10, dev_name);\r
+ }\r
+\r
+ if (is_bind)\r
+ text_out16(x, SCREEN_HEIGHT - 2*10, "Press a button to bind/unbind");\r
+ else if (dev_count > 1)\r
+ text_out16(x, SCREEN_HEIGHT - 2*10, "Press left/right for other devs");\r
+\r
+ plat_video_menu_end();\r
+}\r
+\r
+static void key_config_loop(const me_bind_action *opts, int opt_cnt, int player_idx)\r
+{\r
+ int i, sel = 0, menu_sel_max = opt_cnt - 1;\r
+ int dev_id, dev_count, kc, is_down, mkey, unbind;\r
+\r
+ for (i = 0, dev_id = -1, dev_count = 0; i < IN_MAX_DEVS; i++) {\r
+ if (in_get_dev_name(i, 1, 0) != NULL) {\r
+ dev_count++;\r
+ if (dev_id < 0)\r
+ dev_id = i;\r
+ }\r
+ }\r
+\r
+ if (dev_id == -1) {\r
+ lprintf("no devs, can't do config\n");\r
+ return;\r
+ }\r
+\r
+ for (;;)\r
+ {\r
+ draw_key_config(opts, opt_cnt, player_idx, sel, dev_id, dev_count, 0);\r
+ mkey = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|PBTN_MBACK|PBTN_MOK, 100);\r
+ switch (mkey) {\r
+ case PBTN_UP: sel--; if (sel < 0) sel = menu_sel_max; continue;\r
+ case PBTN_DOWN: sel++; if (sel > menu_sel_max) sel = 0; continue;\r
+ case PBTN_LEFT:\r
+ for (i = 0, dev_id--; i < IN_MAX_DEVS; i++, dev_id--) {\r
+ if (dev_id < 0)\r
+ dev_id = IN_MAX_DEVS - 1;\r
+ if (in_get_dev_name(dev_id, 1, 0) != NULL)\r
+ break;\r
+ }\r
+ continue;\r
+ case PBTN_RIGHT:\r
+ for (i = 0, dev_id++; i < IN_MAX_DEVS; i++, dev_id++) {\r
+ if (dev_id >= IN_MAX_DEVS)\r
+ dev_id = 0;\r
+ if (in_get_dev_name(dev_id, 1, 0) != NULL)\r
+ break;\r
+ }\r
+ continue;\r
+ case PBTN_MBACK: return;\r
+ case PBTN_MOK:\r
+ if (sel >= opt_cnt)\r
+ return;\r
+ while (in_menu_wait_any(30) & PBTN_MOK);\r
+ break;\r
+ default:continue;\r
+ }\r
+\r
+ draw_key_config(opts, opt_cnt, player_idx, sel, dev_id, dev_count, 1);\r
+\r
+ /* wait for some up event */\r
+ for (is_down = 1; is_down; )\r
+ kc = in_update_keycode(&dev_id, &is_down, -1);\r
+\r
+ unbind = count_bound_keys(dev_id, opts[sel].mask, player_idx) >= 2;\r
+\r
+ in_bind_key(dev_id, kc, opts[sel].mask, unbind);\r
+ if (player_idx >= 0) {\r
+ /* FIXME */\r
+ in_bind_key(dev_id, kc, 3 << 16, 1);\r
+ in_bind_key(dev_id, kc, player_idx << 16, 0);\r
+ }\r
+ }\r
+}\r
+\r
+// PicoPad[] format: MXYZ SACB RLDU\r
+me_bind_action me_ctrl_actions[15] =\r
+{\r
+ { "UP ", 0x0001 },\r
+ { "DOWN ", 0x0002 },\r
+ { "LEFT ", 0x0004 },\r
+ { "RIGHT ", 0x0008 },\r
+ { "A ", 0x0040 },\r
+ { "B ", 0x0010 },\r
+ { "C ", 0x0020 },\r
+ { "A turbo", 0x4000 },\r
+ { "B turbo", 0x1000 },\r
+ { "C turbo", 0x2000 },\r
+ { "START ", 0x0080 },\r
+ { "MODE ", 0x0800 },\r
+ { "X ", 0x0400 },\r
+ { "Y ", 0x0200 },\r
+ { "Z ", 0x0100 }\r
+};\r
+\r
+// player2_flag, reserved, ?, ?,\r
+// ?, ?, fast forward, menu\r
+// "NEXT SAVE SLOT", "PREV SAVE SLOT", "SWITCH RENDERER", "SAVE STATE",\r
+// "LOAD STATE", "VOLUME UP", "VOLUME DOWN", "DONE"\r
+me_bind_action emuctrl_actions[] =\r
+{\r
+ { "Load State ", 1<<28 },\r
+ { "Save State ", 1<<27 },\r
+ { "Prev Save Slot ", 1<<25 },\r
+ { "Next Save Slot ", 1<<24 },\r
+ { "Switch Renderer ", 1<<26 },\r
+ { "Volume Down ", 1<<30 },\r
+ { "Volume Up ", 1<<29 },\r
+ { "Fast forward ", 1<<22 },\r
+ { "Enter Menu ", 1<<23 },\r
+ { "Pico Next page ", 1<<21 },\r
+ { "Pico Prev page ", 1<<20 },\r
+ { "Pico Switch input", 1<<19 },\r
+ { NULL, 0 }\r
+};\r
+\r
+static int key_config_loop_wrap(menu_id id, int keys)\r
+{\r
+ switch (id) {\r
+ case MA_CTRL_PLAYER1:\r
+ key_config_loop(me_ctrl_actions, array_size(me_ctrl_actions), 0);\r
+ break;\r
+ case MA_CTRL_PLAYER2:\r
+ key_config_loop(me_ctrl_actions, array_size(me_ctrl_actions), 1);\r
+ break;\r
+ case MA_CTRL_EMU:\r
+ key_config_loop(emuctrl_actions, array_size(emuctrl_actions) - 1, -1);\r
+ break;\r
+ default:\r
+ break;\r
+ }\r
+ return 0;\r
+}\r
+\r
+static const char *mgn_dev_name(menu_id id, int *offs)\r
+{\r
+ const char *name = NULL;\r
+ static int it = 0;\r
+\r
+ if (id == MA_CTRL_DEV_FIRST)\r
+ it = 0;\r
+\r
+ for (; it < IN_MAX_DEVS; it++) {\r
+ name = in_get_dev_name(it, 1, 1);\r
+ if (name != NULL)\r
+ break;\r
+ }\r
+\r
+ it++;\r
+ return name;\r
+}\r
+\r
+static int mh_saveloadcfg(menu_id id, int keys);\r
+static const char *mgn_savecfg(menu_id id, int *offs);\r
+\r
+static menu_entry e_menu_keyconfig[] =\r
+{\r
+ mee_handler_id("Player 1", MA_CTRL_PLAYER1, key_config_loop_wrap),\r
+ mee_handler_id("Player 2", MA_CTRL_PLAYER2, key_config_loop_wrap),\r
+ mee_handler_id("Emulator controls", MA_CTRL_EMU, key_config_loop_wrap),\r
+ mee_onoff ("6 button pad", MA_OPT_6BUTTON_PAD, PicoOpt, POPT_6BTN_PAD),\r
+ mee_range ("Turbo rate", MA_CTRL_TURBO_RATE, currentConfig.turbo_rate, 1, 30),\r
+ mee_handler_mkname_id(MA_OPT_SAVECFG, mh_saveloadcfg, mgn_savecfg),\r
+ mee_handler_id("Save cfg for loaded game", MA_OPT_SAVECFG_GAME, mh_saveloadcfg),\r
+ mee_label (""),\r
+ mee_label ("Input devices:"),\r
+ mee_label_mk (MA_CTRL_DEV_FIRST, mgn_dev_name),\r
+ mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),\r
+ mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),\r
+ mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),\r
+ mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),\r
+ mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),\r
+ mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),\r
+ mee_end,\r
+};\r
+\r
+static int menu_loop_keyconfig(menu_id id, int keys)\r
+{\r
+ static int sel = 0;\r
+ me_loop(e_menu_keyconfig, &sel);\r
+ return 0;\r
+}\r
+\r
+// ------------ SCD options menu ------------\r
+\r
+static const char *mgn_cdopt_ra(menu_id id, int *offs)\r
+{\r
+ *offs = -5;\r
+ if (PicoCDBuffers <= 0)\r
+ return " OFF";\r
+ sprintf(static_buff, "%5iK", PicoCDBuffers * 2);\r
+ return static_buff;\r
+}\r
+\r
+static int mh_cdopt_ra(menu_id id, int keys)\r
+{\r
+ if (keys & PBTN_LEFT) {\r
+ PicoCDBuffers >>= 1;\r
+ if (PicoCDBuffers < 2)\r
+ PicoCDBuffers = 0;\r
+ } else {\r
+ if (PicoCDBuffers <= 0)\r
+ PicoCDBuffers = 1;\r
+ PicoCDBuffers <<= 1;\r
+ if (PicoCDBuffers > 8*1024)\r
+ PicoCDBuffers = 8*1024; // 16M\r
+ }\r
+ return 0;\r
+}\r
+\r
+static menu_entry e_menu_cd_options[] =\r
+{\r
+ mee_onoff("CD LEDs", MA_CDOPT_LEDS, currentConfig.EmuOpt, 0x0400),\r
+ mee_onoff("CDDA audio", MA_CDOPT_CDDA, PicoOpt, POPT_EN_MCD_CDDA),\r
+ mee_onoff("PCM audio", MA_CDOPT_PCM, PicoOpt, POPT_EN_MCD_PCM),\r
+ mee_cust ("ReadAhead buffer", MA_CDOPT_READAHEAD, mh_cdopt_ra, mgn_cdopt_ra),\r
+ mee_onoff("SaveRAM cart", MA_CDOPT_SAVERAM, PicoOpt, POPT_EN_MCD_RAMCART),\r
+ mee_onoff("Scale/Rot. fx (slow)", MA_CDOPT_SCALEROT_CHIP, PicoOpt, POPT_EN_MCD_GFX),\r
+ mee_onoff("Better sync (slow)", MA_CDOPT_BETTER_SYNC, PicoOpt, POPT_EN_MCD_PSYNC),\r
+ mee_end,\r
+};\r
+\r
+static int menu_loop_cd_options(menu_id id, int keys)\r
+{\r
+ static int sel = 0;\r
+ me_loop(e_menu_cd_options, &sel);\r
+ return 0;\r
+}\r
+\r
+// ------------ adv options menu ------------\r
+\r
+// TODO FIXME fix if and mv\r
+static const char *mgn_aopt_sqhack(menu_id id, int *offs)\r
+{\r
+ *offs = -10;\r
+ sprintf(static_buff, "%s, %s", 111 ? " active" : "inactive",\r
+ (currentConfig.EmuOpt & 0x10) ? "ON" : "OFF");\r
+ return static_buff;\r
+}\r
+\r
+static menu_entry e_menu_adv_options[] =\r
+{\r
+ mee_onoff ("SRAM/BRAM saves", MA_OPT_SRAM_STATES, currentConfig.EmuOpt, EOPT_USE_SRAM),\r
+ mee_onoff ("Disable sprite limit", MA_OPT2_NO_SPRITE_LIM, PicoOpt, POPT_DIS_SPRITE_LIM),\r
+ mee_onoff ("Use second CPU for sound", MA_OPT_ARM940_SOUND, PicoOpt, POPT_EXT_FM),\r
+ mee_onoff ("Emulate Z80", MA_OPT2_ENABLE_Z80, PicoOpt, POPT_EN_Z80),\r
+ mee_onoff ("Emulate YM2612 (FM)", MA_OPT2_ENABLE_YM2612, PicoOpt, POPT_EN_FM),\r
+ mee_onoff ("Emulate SN76496 (PSG)", MA_OPT2_ENABLE_SN76496,PicoOpt, POPT_EN_PSG),\r
+ mee_onoff ("gzip savestates", MA_OPT2_GZIP_STATES, currentConfig.EmuOpt, EOPT_GZIP_SAVES),\r
+ mee_onoff ("Don't save last used ROM", MA_OPT2_NO_LAST_ROM, currentConfig.EmuOpt, EOPT_NO_AUTOSVCFG),\r
+ mee_label ("- needs restart -"),\r
+ mee_onoff ("craigix's RAM timings", MA_OPT2_RAMTIMINGS, currentConfig.EmuOpt, 0x0100),\r
+ mee_onoff_cust("Squidgehack", MA_OPT2_SQUIDGEHACK, currentConfig.EmuOpt, 0x0010, mgn_aopt_sqhack),\r
+ mee_onoff ("SVP dynarec", MA_OPT2_SVP_DYNAREC, PicoOpt, POPT_EN_SVP_DRC),\r
+ mee_onoff ("Disable idle loop patching",MA_OPT2_NO_IDLE_LOOPS,PicoOpt, POPT_DIS_IDLE_DET),\r
+ mee_end,\r
+};\r
+\r
+static int menu_loop_adv_options(menu_id id, int keys)\r
+{\r
+ static int sel = 0;\r
+ me_loop(e_menu_adv_options, &sel);\r
+ return 0;\r
+}\r
+\r
+// ------------ gfx options menu ------------\r
+\r
+static const char *mgn_opt_scaling(menu_id id, int *offs)\r
+{\r
+ *offs = -12;\r
+ switch (currentConfig.scaling) {\r
+ default: return " OFF";\r
+ case 1: return "hw horizontal";\r
+ case 2: return "hw horiz. + vert.";\r
+ case 3: return "sw horizontal";\r
+ }\r
+}\r
+\r
+static const char *mgn_aopt_gamma(menu_id id, int *offs)\r
+{\r
+ sprintf(static_buff, "%i.%02i", currentConfig.gamma / 100, currentConfig.gamma%100);\r
+ return static_buff;\r
+}\r
+\r
+static menu_entry e_menu_gfx_options[] =\r
+{\r
+ mee_range_cust("Scaling", MA_OPT_SCALING, currentConfig.scaling, 0, 3, mgn_opt_scaling),\r
+ mee_range_cust("Gamma correction", MA_OPT2_GAMMA, currentConfig.gamma, 1, 300, mgn_aopt_gamma),\r
+ mee_onoff ("A_SN's gamma curve", MA_OPT2_A_SN_GAMMA, currentConfig.EmuOpt, 0x1000),\r
+ mee_onoff ("Perfect vsync", MA_OPT2_VSYNC, currentConfig.EmuOpt, 0x2000),\r
+ mee_end,\r
+};\r
+\r
+static int menu_loop_gfx_options(menu_id id, int keys)\r
+{\r
+ static int sel = 0;\r
+ me_loop(e_menu_gfx_options, &sel);\r
+ return 0;\r
+}\r
+\r
+// ------------ options menu ------------\r
+\r
+static menu_entry e_menu_options[];\r
+\r
+/* TODO: move to plat */\r
+static int mh_opt_render(menu_id id, int keys)\r
+{\r
+ if (keys & PBTN_LEFT) {\r
+ if (PicoOpt&0x10) PicoOpt&= ~0x10;\r
+ else if (!(currentConfig.EmuOpt &0x80))currentConfig.EmuOpt |= 0x80;\r
+ } else {\r
+ if (PicoOpt&0x10) return 0;\r
+ else if (!(currentConfig.EmuOpt &0x80))PicoOpt|= 0x10;\r
+ else if ( currentConfig.EmuOpt &0x80) currentConfig.EmuOpt &= ~0x80;\r
+ }\r
+ return 0;\r
+}\r
+\r
+static int sndrate_prevnext(int rate, int dir)\r
+{\r
+ static const int rates[] = { 8000, 11025, 16000, 22050, 44100 };\r
+ int i;\r
+\r
+ for (i = 0; i < 5; i++)\r
+ if (rates[i] == rate) break;\r
+\r
+ i += dir ? 1 : -1;\r
+ if (i > 4) {\r
+ if (!(PicoOpt & POPT_EN_STEREO)) {\r
+ PicoOpt |= POPT_EN_STEREO;\r
+ return rates[0];\r
+ }\r
+ return rates[4];\r
+ }\r
+ if (i < 0) {\r
+ if (PicoOpt & POPT_EN_STEREO) {\r
+ PicoOpt &= ~POPT_EN_STEREO;\r
+ return rates[4];\r
+ }\r
+ return rates[0];\r
+ }\r
+ return rates[i];\r
+}\r
+\r
+static void region_prevnext(int right)\r
+{\r
+ // jp_ntsc=1, jp_pal=2, usa=4, eu=8\r
+ static const int rgn_orders[] = { 0x148, 0x184, 0x814, 0x418, 0x841, 0x481 };\r
+ int i;\r
+\r
+ if (right) {\r
+ if (!PicoRegionOverride) {\r
+ for (i = 0; i < 6; i++)\r
+ if (rgn_orders[i] == PicoAutoRgnOrder) break;\r
+ if (i < 5) PicoAutoRgnOrder = rgn_orders[i+1];\r
+ else PicoRegionOverride=1;\r
+ }\r
+ else\r
+ PicoRegionOverride <<= 1;\r
+ if (PicoRegionOverride > 8)\r
+ PicoRegionOverride = 8;\r
+ } else {\r
+ if (!PicoRegionOverride) {\r
+ for (i = 0; i < 6; i++)\r
+ if (rgn_orders[i] == PicoAutoRgnOrder) break;\r
+ if (i > 0) PicoAutoRgnOrder = rgn_orders[i-1];\r
+ }\r
+ else\r
+ PicoRegionOverride >>= 1;\r
+ }\r
+}\r
+\r
+static int mh_opt_misc(menu_id id, int keys)\r
+{\r
+ int i;\r
+\r
+ switch (id) {\r
+ case MA_OPT_SOUND_QUALITY:\r
+ PsndRate = sndrate_prevnext(PsndRate, keys & PBTN_RIGHT);\r
+ break;\r
+ case MA_OPT_REGION:\r
+ region_prevnext(keys & PBTN_RIGHT);\r
+ break;\r
+ case MA_OPT_CONFIRM_STATES:\r
+ i = ((currentConfig.EmuOpt>>9)&1) | ((currentConfig.EmuOpt>>10)&2);\r
+ i += (keys & PBTN_LEFT) ? -1 : 1;\r
+ if (i < 0) i = 0; else if (i > 3) i = 3;\r
+ i |= i << 1; i &= ~2;\r
+ currentConfig.EmuOpt &= ~0xa00;\r
+ currentConfig.EmuOpt |= i << 9;\r
+ break;\r
+ default:\r
+ break;\r
+ }\r
+ return 0;\r
+}\r
+\r
+static int mh_saveloadcfg(menu_id id, int keys)\r
+{\r
+ int ret;\r
+\r
+ if (keys & (PBTN_LEFT|PBTN_RIGHT)) { // multi choice\r
+ config_slot += (keys & PBTN_LEFT) ? -1 : 1;\r
+ if (config_slot < 0) config_slot = 9;\r
+ else if (config_slot > 9) config_slot = 0;\r
+ me_enable(e_menu_options, MA_OPT_LOADCFG, config_slot != config_slot_current);\r
+ return 0;\r
+ }\r
+\r
+ switch (id) {\r
+ case MA_OPT_SAVECFG:\r
+ case MA_OPT_SAVECFG_GAME:\r
+ if (emu_WriteConfig(id == MA_OPT_SAVECFG_GAME ? 1 : 0))\r
+ strcpy(menuErrorMsg, "config saved");\r
+ else\r
+ strcpy(menuErrorMsg, "failed to write config");\r
+ break;\r
+ case MA_OPT_LOADCFG:\r
+ ret = emu_ReadConfig(1, 1);\r
+ if (!ret) ret = emu_ReadConfig(0, 1);\r
+ if (ret) strcpy(menuErrorMsg, "config loaded");\r
+ else strcpy(menuErrorMsg, "failed to load config");\r
+ break;\r
+ default:\r
+ return 0;\r
+ }\r
+\r
+ return 1;\r
+}\r
+\r
+static const char *mgn_opt_renderer(menu_id id, int *offs)\r
+{\r
+ *offs = -6;\r
+ if (PicoOpt & POPT_ALT_RENDERER)\r
+ return " 8bit fast";\r
+ else if (currentConfig.EmuOpt & 0x80)\r
+ return "16bit accurate";\r
+ else\r
+ return " 8bit accurate";\r
+}\r
+\r
+static const char *mgn_opt_fskip(menu_id id, int *offs)\r
+{\r
+ if (currentConfig.Frameskip < 0)\r
+ return "Auto";\r
+ sprintf(static_buff, "%d", currentConfig.Frameskip);\r
+ return static_buff;\r
+}\r
+\r
+static const char *mgn_opt_sound(menu_id id, int *offs)\r
+{\r
+ const char *str2;\r
+ *offs = -8;\r
+ str2 = (PicoOpt & POPT_EN_STEREO) ? "stereo" : "mono";\r
+ sprintf(static_buff, "%5iHz %s", PsndRate, str2);\r
+ return static_buff;\r
+}\r
+\r
+static const char *mgn_opt_region(menu_id id, int *offs)\r
+{\r
+ static const char *names[] = { "Auto", " Japan NTSC", " Japan PAL", " USA", " Europe" };\r
+ static const char *names_short[] = { "", " JP", " JP", " US", " EU" };\r
+ int code = PicoRegionOverride;\r
+ int u, i = 0;\r
+\r
+ *offs = -6;\r
+ if (code) {\r
+ code <<= 1;\r
+ while ((code >>= 1)) i++;\r
+ if (i > 4)\r
+ return "unknown";\r
+ return names[i];\r
+ } else {\r
+ strcpy(static_buff, "Auto:");\r
+ for (u = 0; u < 3; u++) {\r
+ code = (PicoAutoRgnOrder >> u*4) & 0xf;\r
+ for (i = 0; code; code >>= 1, i++)\r
+ ;\r
+ strcat(static_buff, names_short[i]);\r
+ }\r
+ return static_buff;\r
+ }\r
+}\r
+\r
+static const char *mgn_opt_c_saves(menu_id id, int *offs)\r
+{\r
+ switch ((currentConfig.EmuOpt >> 9) & 5) {\r
+ default: return "OFF";\r
+ case 1: return "writes";\r
+ case 4: return "loads";\r
+ case 5: return "both";\r
+ }\r
+}\r
+\r
+static const char *mgn_savecfg(menu_id id, int *offs)\r
+{\r
+ strcpy(static_buff, "Save global config");\r
+ if (config_slot != 0)\r
+ sprintf(static_buff + strlen(static_buff), " (profile: %i)", config_slot);\r
+ return static_buff;\r
+}\r
+\r
+static const char *mgn_loadcfg(menu_id id, int *offs)\r
+{\r
+ sprintf(static_buff, "Load cfg from profile %i", config_slot);\r
+ return static_buff;\r
+}\r
+\r
+static menu_entry e_menu_options[] =\r
+{\r
+ mee_range ("Save slot", MA_OPT_SAVE_SLOT, state_slot, 0, 9),\r
+ mee_range_cust("Frameskip", MA_OPT_FRAMESKIP, currentConfig.Frameskip, -1, 16, mgn_opt_fskip),\r
+ mee_cust ("Region", MA_OPT_REGION, mh_opt_misc, mgn_opt_region),\r
+ mee_cust ("Renderer", MA_OPT_RENDERER, mh_opt_render, mgn_opt_renderer),\r
+ mee_onoff ("Show FPS", MA_OPT_SHOW_FPS, currentConfig.EmuOpt, 0x002),\r
+ mee_onoff ("Enable sound", MA_OPT_ENABLE_SOUND, currentConfig.EmuOpt, 0x004),\r
+ mee_cust ("Sound Quality", MA_OPT_SOUND_QUALITY, mh_opt_misc, mgn_opt_sound),\r
+ mee_cust ("Confirm savestate", MA_OPT_CONFIRM_STATES,mh_opt_misc, mgn_opt_c_saves),\r
+#if defined(__GP2X__)\r
+ mee_range ("GP2X CPU clocks", MA_OPT_CPU_CLOCKS, currentConfig.CPUclock, 20, 400),\r
+#elif defined(PSP)\r
+ mee_range ("PSP CPU clock", MA_OPT_CPU_CLOCKS, currentConfig.CPUclock, )\r
+#endif\r
+ mee_handler ("[Display options]", menu_loop_gfx_options),\r
+ mee_handler ("[Advanced options]", menu_loop_adv_options),\r
+ mee_handler ("[Sega/Mega CD options]", menu_loop_cd_options),\r
+ mee_handler_mkname_id(MA_OPT_SAVECFG, mh_saveloadcfg, mgn_savecfg),\r
+ mee_handler_id("Save cfg for current game only", MA_OPT_SAVECFG_GAME, mh_saveloadcfg),\r
+ mee_handler_mkname_id(MA_OPT_LOADCFG, mh_saveloadcfg, mgn_loadcfg),\r
+ mee_end,\r
+};\r
+\r
+static int menu_loop_options(menu_id id, int keys)\r
+{\r
+ static int sel = 0;\r
+\r
+ me_enable(e_menu_options, MA_OPT_SAVECFG_GAME, rom_loaded);\r
+ me_enable(e_menu_options, MA_OPT_LOADCFG, config_slot != config_slot_current);\r
+\r
+ me_loop(e_menu_options, &sel);\r
+\r
+ if (PicoRegionOverride)\r
+ // force setting possibly changed..\r
+ Pico.m.pal = (PicoRegionOverride == 2 || PicoRegionOverride == 8) ? 1 : 0;\r
+\r
+ return 0;\r
+}\r
+\r
+// ------------ debug menu ------------\r
+\r
+#include <sys/stat.h>\r
+#include <sys/types.h>\r
+\r
+#include <pico/debug.h>\r
+\r
+extern void SekStepM68k(void);\r
+\r
+static void mplayer_loop(void)\r
+{\r
+ emu_startSound();\r
+\r
+ while (1)\r
+ {\r
+ PDebugZ80Frame();\r
+ if (in_menu_wait_any(0) & PBTN_NORTH) break;\r
+ emu_waitSound();\r
+ }\r
+\r
+ emu_endSound();\r
+}\r
+\r
+static void draw_text_debug(const char *str, int skip, int from)\r
+{\r
+ const char *p;\r
+ int line;\r
+\r
+ p = str;\r
+ while (skip-- > 0)\r
+ {\r
+ while (*p && *p != '\n') p++;\r
+ if (*p == 0 || p[1] == 0) return;\r
+ p++;\r
+ }\r
+\r
+ str = p;\r
+ for (line = from; line < SCREEN_HEIGHT/10; line++)\r
+ {\r
+ while (*p && *p != '\n') p++;\r
+ smalltext_out16(1, line*10, str, 0xffff);\r
+ if (*p == 0) break;\r
+ p++; str = p;\r
+ }\r
+}\r
+\r
+static void draw_frame_debug(void)\r
+{\r
+ char layer_str[48] = "layers: ";\r
+ if (PicoDrawMask & PDRAW_LAYERB_ON) memcpy(layer_str + 8, "B", 1);\r
+ if (PicoDrawMask & PDRAW_LAYERA_ON) memcpy(layer_str + 10, "A", 1);\r
+ if (PicoDrawMask & PDRAW_SPRITES_LOW_ON) memcpy(layer_str + 12, "spr_lo", 6);\r
+ if (PicoDrawMask & PDRAW_SPRITES_HI_ON) memcpy(layer_str + 19, "spr_hi", 6);\r
+\r
+ clear_screen();\r
+ emu_forcedFrame(0);\r
+ smalltext_out16(4, SCREEN_HEIGHT-8, layer_str, 0xffff);\r
+}\r
+\r
+static void debug_menu_loop(void)\r
+{\r
+ int inp, mode = 0;\r
+ int spr_offs = 0, dumped = 0;\r
+ char *tmp;\r
+\r
+ while (1)\r
+ {\r
+ switch (mode)\r
+ {\r
+ case 0: plat_video_menu_begin();\r
+ tmp = PDebugMain();\r
+ emu_platformDebugCat(tmp);\r
+ draw_text_debug(tmp, 0, 0);\r
+ if (dumped) {\r
+ smalltext_out16(SCREEN_WIDTH-6*10, SCREEN_HEIGHT-8, "dumped", 0xffff);\r
+ dumped = 0;\r
+ }\r
+ break;\r
+ case 1: draw_frame_debug(); break;\r
+ case 2: clear_screen();\r
+ emu_forcedFrame(0);\r
+ darken_screen();\r
+ PDebugShowSpriteStats((unsigned short *)SCREEN_BUFFER + (SCREEN_HEIGHT/2 - 240/2)*SCREEN_WIDTH +\r
+ SCREEN_WIDTH/2 - 320/2, SCREEN_WIDTH); break;\r
+ case 3: clear_screen();\r
+ PDebugShowPalette(SCREEN_BUFFER, SCREEN_WIDTH);\r
+ PDebugShowSprite((unsigned short *)SCREEN_BUFFER + SCREEN_WIDTH*120+SCREEN_WIDTH/2+16,\r
+ SCREEN_WIDTH, spr_offs);\r
+ draw_text_debug(PDebugSpriteList(), spr_offs, 6);\r
+ break;\r
+ }\r
+ plat_video_menu_end();\r
+\r
+ inp = in_menu_wait(PBTN_EAST|PBTN_MBACK|PBTN_WEST|PBTN_NORTH|PBTN_L|PBTN_R |\r
+ PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT, 70);\r
+ if (inp & PBTN_MBACK) return;\r
+ if (inp & PBTN_L) { mode--; if (mode < 0) mode = 3; }\r
+ if (inp & PBTN_R) { mode++; if (mode > 3) mode = 0; }\r
+ switch (mode)\r
+ {\r
+ case 0:\r
+ if (inp & PBTN_EAST) SekStepM68k();\r
+ if (inp & PBTN_NORTH) {\r
+ while (inp & PBTN_NORTH) inp = in_menu_wait_any(-1);\r
+ mplayer_loop();\r
+ }\r
+ if ((inp & (PBTN_WEST|PBTN_LEFT)) == (PBTN_WEST|PBTN_LEFT)) {\r
+ mkdir("dumps", 0777);\r
+ PDebugDumpMem();\r
+ while (inp & PBTN_WEST) inp = in_menu_wait_any(-1);\r
+ dumped = 1;\r
+ }\r
+ break;\r
+ case 1:\r
+ if (inp & PBTN_LEFT) PicoDrawMask ^= PDRAW_LAYERB_ON;\r
+ if (inp & PBTN_RIGHT) PicoDrawMask ^= PDRAW_LAYERA_ON;\r
+ if (inp & PBTN_DOWN) PicoDrawMask ^= PDRAW_SPRITES_LOW_ON;\r
if (inp & PBTN_UP) PicoDrawMask ^= PDRAW_SPRITES_HI_ON;\r
if (inp & PBTN_EAST) {\r
PsndOut = NULL; // just in case\r
}\r
}\r
\r
-#endif // !UIQ3\r
+// ------------ main menu ------------\r
\r
-// ------------ util ------------\r
+static char *romsel_run(void)\r
+{\r
+ char *ret, *sel_name;\r
+\r
+ sel_name = malloc(sizeof(rom_fname_loaded));\r
+ if (sel_name == NULL)\r
+ return NULL;\r
+ strcpy(sel_name, rom_fname_loaded);\r
+\r
+ ret = menu_loop_romsel(sel_name, sizeof(rom_fname_loaded));\r
+ free(sel_name);\r
+ return ret;\r
+}\r
\r
-const char *me_region_name(unsigned int code, int auto_order)\r
+static int main_menu_handler(menu_id id, int keys)\r
{\r
- static const char *names[] = { "Auto", " Japan NTSC", " Japan PAL", " USA", " Europe" };\r
- static const char *names_short[] = { "", " JP", " JP", " US", " EU" };\r
- int u, i = 0;\r
- if (code) {\r
- code <<= 1;\r
- while((code >>= 1)) i++;\r
- if (i > 4) return "unknown";\r
- return names[i];\r
- } else {\r
- static char name[24];\r
- strcpy(name, "Auto:");\r
- for (u = 0; u < 3; u++) {\r
- i = 0; code = ((auto_order >> u*4) & 0xf) << 1;\r
- while((code >>= 1)) i++;\r
- strcat(name, names_short[i]);\r
+ char *ret_name;\r
+\r
+ switch (id)\r
+ {\r
+ case MA_MAIN_RESUME_GAME:\r
+ if (rom_loaded)\r
+ return 1;\r
+ break;\r
+ case MA_MAIN_SAVE_STATE:\r
+ if (rom_loaded)\r
+ return menu_loop_savestate(0);\r
+ break;\r
+ case MA_MAIN_LOAD_STATE:\r
+ if (rom_loaded)\r
+ return menu_loop_savestate(1);\r
+ break;\r
+ case MA_MAIN_RESET_GAME:\r
+ if (rom_loaded) {\r
+ emu_ResetGame();\r
+ return 1;\r
+ }\r
+ break;\r
+ case MA_MAIN_LOAD_ROM:\r
+ ret_name = romsel_run();\r
+ if (ret_name != NULL) {\r
+ lprintf("selected file: %s\n", ret_name);\r
+ engineState = PGS_ReloadRom;\r
+ return 1;\r
+ }\r
+ break;\r
+ case MA_MAIN_CREDITS:\r
+ draw_menu_credits();\r
+ in_menu_wait(PBTN_MOK|PBTN_MBACK, 70);\r
+ break;\r
+ case MA_MAIN_EXIT:\r
+ engineState = PGS_Quit;\r
+ return 1;\r
+ case MA_MAIN_PATCHES:\r
+ if (rom_loaded && PicoPatches) {\r
+ menu_loop_patches();\r
+ PicoPatchApply();\r
+ strcpy(menuErrorMsg, "Patches applied");\r
}\r
- return name;\r
+ break;\r
+ default:\r
+ lprintf("%s: something unknown selected\n", __FUNCTION__);\r
+ break;\r
+ }\r
+\r
+ return 0;\r
+}\r
+\r
+static menu_entry e_menu_main[] =\r
+{\r
+ mee_handler_id("Resume game", MA_MAIN_RESUME_GAME, main_menu_handler),\r
+ mee_handler_id("Save State", MA_MAIN_SAVE_STATE, main_menu_handler),\r
+ mee_handler_id("Load State", MA_MAIN_LOAD_STATE, main_menu_handler),\r
+ mee_handler_id("Reset game", MA_MAIN_RESET_GAME, main_menu_handler),\r
+ mee_handler_id("Load new ROM/ISO", MA_MAIN_LOAD_ROM, main_menu_handler),\r
+ mee_handler_id("Change options", MA_MAIN_OPTIONS, menu_loop_options),\r
+ mee_handler_id("Configure controls", MA_MAIN_OPTIONS, menu_loop_keyconfig),\r
+ mee_handler_id("Credits", MA_MAIN_CREDITS, main_menu_handler),\r
+ mee_handler_id("Patches / GameGenie",MA_MAIN_PATCHES, main_menu_handler),\r
+ mee_handler_id("Exit", MA_MAIN_EXIT, main_menu_handler),\r
+ mee_end,\r
+};\r
+\r
+void menu_loop(void)\r
+{\r
+ static int sel = 0;\r
+\r
+ me_enable(e_menu_main, MA_MAIN_RESUME_GAME, rom_loaded);\r
+ me_enable(e_menu_main, MA_MAIN_SAVE_STATE, rom_loaded);\r
+ me_enable(e_menu_main, MA_MAIN_LOAD_STATE, rom_loaded);\r
+ me_enable(e_menu_main, MA_MAIN_RESET_GAME, rom_loaded);\r
+ me_enable(e_menu_main, MA_MAIN_PATCHES, PicoPatches != NULL);\r
+\r
+ plat_video_menu_enter(rom_loaded);\r
+ in_set_blocking(1);\r
+ me_loop(e_menu_main, &sel);\r
+ in_set_blocking(0);\r
+\r
+ if (rom_loaded && engineState == PGS_Menu) {\r
+ /* wait until menu, ok, back is released */\r
+ while (in_menu_wait_any(50) & (PBTN_MENU|PBTN_MOK|PBTN_MBACK));\r
+ engineState = PGS_Running;\r
+ }\r
+}\r
+\r
+// --------- CD tray close menu ----------\r
+\r
+static int mh_tray_load_cd(menu_id id, int keys)\r
+{\r
+ cd_img_type cd_type;\r
+ char *ret_name;\r
+ int ret = -1;\r
+\r
+ ret_name = romsel_run();\r
+ if (ret_name == NULL)\r
+ return 0;\r
+\r
+ cd_type = emu_cdCheck(NULL, ret_name);\r
+ if (cd_type != CIT_NOT_CD)\r
+ ret = Insert_CD(ret_name, cd_type);\r
+ if (ret != 0) {\r
+ sprintf(menuErrorMsg, "Load failed, invalid CD image?");\r
+ lprintf("%s\n", menuErrorMsg);\r
+ return 0;\r
+ }\r
+\r
+ engineState = PGS_RestartRun;\r
+ return 1;\r
+}\r
+\r
+static int mh_tray_nothing(menu_id id, int keys)\r
+{\r
+ return 1;\r
+}\r
+\r
+static menu_entry e_menu_tray[] =\r
+{\r
+ mee_label ("The unit is about to"),\r
+ mee_label ("close the CD tray."),\r
+ mee_label (""),\r
+ mee_label (""),\r
+ mee_handler("Load CD image", mh_tray_load_cd),\r
+ mee_handler("Insert nothing", mh_tray_nothing),\r
+};\r
+\r
+int menu_loop_tray(void)\r
+{\r
+ int ret = 1, sel = 0;\r
+\r
+ plat_video_menu_enter(rom_loaded);\r
+\r
+ in_set_blocking(1);\r
+ me_loop(e_menu_tray, &sel);\r
+ in_set_blocking(0);\r
+\r
+ if (engineState != PGS_RestartRun) {\r
+ engineState = PGS_RestartRun;\r
+ ret = 0; /* no CD inserted */\r
}\r
+\r
+ while (in_menu_wait_any(50) & (PBTN_MENU|PBTN_MOK|PBTN_MBACK));\r
+\r
+ return ret;\r
}\r
\r
+#endif // !UIQ3\r
+\r
+// ------------ util ------------\r
+\r
/* TODO: rename */\r
void menu_darken_bg(void *dst, int pixels, int darker)\r
{\r
}\r
}\r
\r
+/* hidden options for config engine only */\r
+static menu_entry e_menu_hidden[] =\r
+{\r
+ mee_onoff("Accurate sprites", MA_OPT_ACC_SPRITES, PicoOpt, 0x080),\r
+ mee_end,\r
+};\r
+\r
+static menu_entry *e_menu_table[] =\r
+{\r
+ e_menu_options,\r
+ e_menu_gfx_options,\r
+ e_menu_adv_options,\r
+ e_menu_cd_options,\r
+ e_menu_keyconfig,\r
+ e_menu_hidden,\r
+};\r
+\r
+static menu_entry *me_list_table = NULL;\r
+static menu_entry *me_list_i = NULL;\r
+\r
+menu_entry *me_list_get_first(void)\r
+{\r
+ me_list_table = me_list_i = e_menu_table[0];\r
+ return me_list_i;\r
+}\r
+\r
+menu_entry *me_list_get_next(void)\r
+{\r
+ int i;\r
+\r
+ me_list_i++;\r
+ if (me_list_i->name != NULL)\r
+ return me_list_i;\r
+\r
+ for (i = 0; i < array_size(e_menu_table); i++)\r
+ if (me_list_table == e_menu_table[i])\r
+ break;\r
+\r
+ if (i + 1 < array_size(e_menu_table))\r
+ me_list_table = me_list_i = e_menu_table[i + 1];\r
+ else\r
+ me_list_table = me_list_i = NULL;\r
+\r
+ return me_list_i;\r
+}\r
+\r