X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=platform%2Fgizmondo%2Fmenu.c;h=232701ad4a333f4553926c310267a9ee4198ac58;hb=93f9619ed819dee07948416c98ca2f1c70a22666;hp=c4ecd0b5fefa52125b07c7ea5cbe06f6fb2740fa;hpb=e5f426aa2e86d56357b8af2795e73cc0c9b17e8f;p=picodrive.git diff --git a/platform/gizmondo/menu.c b/platform/gizmondo/menu.c index c4ecd0b..232701a 100644 --- a/platform/gizmondo/menu.c +++ b/platform/gizmondo/menu.c @@ -1,7 +1,10 @@ -// (c) Copyright 2006,2007 notaz, All rights reserved. -// Free for non-commercial use. - -// For commercial use, separate licencing terms must be obtained. +/* + * PicoDrive + * (C) notaz, 2006-2008 + * + * This work is licensed under the terms of MAME license. + * See COPYING file in the top-level directory. + */ // don't like to use loads of #ifdefs, so duplicating GP2X code // horribly instead @@ -9,100 +12,64 @@ #include #include #include +#include #include // for getcwd cegcc implementation +#include // for opendir #include +#include "kgsdk/Framework.h" +#include "kgsdk/Framework2D.h" + #include "giz.h" #include "emu.h" #include "menu.h" #include "../common/arm_utils.h" #include "../common/menu.h" +#include "../common/emu.h" #include "../common/readpng.h" +#include "../common/input.h" #include "version.h" -#include "kgsdk/Framework.h" -#include "kgsdk/Framework2D.h" -#include -#include -#include +#include +#include +#include -extern char romFileName[MAX_PATH]; -extern char *rom_data; -extern int state_slot; -extern int config_slot, config_slot_current; #define gizKeyUnkn "???" -static const char * const gizKeyNames[] = { +const char * const keyNames[] = { "LEFT", "RIGHT", "UP", "DOWN", "STOP", "PLAY", "FORWARD", "REWIND", - "LEFT_SHOULDER", "RIGHT_SHOULDER", "HOME", "VOLUME", "BRIGHTNESS", "ALARM", "POWER", gizKeyUnkn, - gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, + "L", "R", "HOME", "VOLUME", "BRIGHTNESS", "ALARM", "POWER", gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, + gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn }; -static unsigned char bg_buffer[321*240*2]; -char menuErrorMsg[40] = {0, }; +static unsigned char *bg_buffer = gfx_buffer + 321*240*2; +unsigned char *menu_screen = gfx_buffer; /* draw here and blit later, to avoid flicker */ -static void menu_darken_bg(void *dst, const void *src, int pixels, int darker); +void menu_darken_bg(void *dst, const void *src, int pixels, int darker); static void menu_prepare_bg(int use_game_bg); static unsigned int inp_prev = 0; -static int inp_prevjoy = 0; -static unsigned long wait_for_input(unsigned int interesting) +void menu_draw_begin(int use_bgbuff) { - unsigned int ret; - static int repeats = 0, wait = 50; - int release = 0, i; - - if (repeats == 2 || repeats == 4) wait /= 2; - if (repeats == 6) wait = 15; - - for (i = 0; i < 6 && inp_prev == Framework_PollGetButtons(); i++) { - if (i == 0) repeats++; - Sleep(wait); - } - - while ( !((ret = Framework_PollGetButtons()) & interesting) ) { - Sleep(50); - release = 1; - } - - if (release || ret != inp_prev) { - repeats = 0; - wait = 50; - } - inp_prev = ret; - inp_prevjoy = 0; - - // we don't need diagonals in menus - if ((ret&BTN_UP) && (ret&BTN_LEFT)) ret &= ~BTN_LEFT; - if ((ret&BTN_UP) && (ret&BTN_RIGHT)) ret &= ~BTN_RIGHT; - if ((ret&BTN_DOWN) && (ret&BTN_LEFT)) ret &= ~BTN_LEFT; - if ((ret&BTN_DOWN) && (ret&BTN_RIGHT)) ret &= ~BTN_RIGHT; - - return ret; + if (use_bgbuff) + memcpy32((int *)menu_screen, (int *)bg_buffer, 321*240*2/4); } -static void menu_draw_begin(int use_bgbuff) +void menu_draw_end(void) { + giz_screen = fb_lock(0); if (giz_screen == NULL) { - Framework2D_WaitVSync(); - giz_screen = Framework2D_LockBuffer(); + lprintf("%s: Framework2D_LockBuffer() returned NULL\n", __FUNCTION__); + return; } - else - { - lprintf("%s: screen was not NULL\n", __FUNCTION__); - } - memcpy32(giz_screen, (int *)bg_buffer, 321*240*2/4); -} - - -static void menu_draw_end(void) -{ - Framework2D_UnlockBuffer(); + memcpy32(giz_screen, (int *)menu_screen, 321*240*2/4); + fb_unlock(); giz_screen = NULL; + fb_flip(); } @@ -114,10 +81,10 @@ static void load_progress_cb(int percent) unsigned short *dst; menu_draw_begin(0); - dst = (unsigned short *)giz_screen + 321*20; + dst = (unsigned short *)menu_screen + 321*20; if (len > 320) len = 320; - for (ln = 10; ln > 0; ln--, dst += 320) + for (ln = 10; ln > 0; ln--, dst += 321) memset(dst, 0xff, len*2); menu_draw_end(); } @@ -127,8 +94,8 @@ void menu_romload_prepare(const char *rom_name) const char *p = rom_name + strlen(rom_name); while (p > rom_name && *p != '/') p--; - if (rom_data == NULL) - memset(giz_screen, 0, 321*240*2); + if (!rom_loaded) + memset(menu_screen, 0, 321*240*2); menu_draw_begin(1); smalltext_out16(1, 1, "Loading", 0xffff); @@ -147,12 +114,21 @@ void menu_romload_end(void) // -------------- ROM selector -------------- +#define DT_DIR 1 +#define DT_REG 2 + +struct my_dirent +{ + unsigned char d_type; + char d_name[0]; +}; + // rrrr rggg gggb bbbb -#if 0 +#if 1 static unsigned short file2color(const char *fname) { const char *ext = fname + strlen(fname) - 3; - static const char *rom_exts[] = { "zip", "bin", "smd", "gen", "iso" }; + static const char *rom_exts[] = { "zip", "bin", "smd", "gen", "iso", "cso" }; static const char *other_exts[] = { "gmv", "pat" }; int i; @@ -164,7 +140,7 @@ static unsigned short file2color(const char *fname) return 0xffff; } -static void draw_dirlist(char *curdir, struct dirent **namelist, int n, int sel) +static void draw_dirlist(char *curdir, struct my_dirent **namelist, int n, int sel) { int start, i, pos; @@ -173,11 +149,11 @@ static void draw_dirlist(char *curdir, struct dirent **namelist, int n, int sel) menu_draw_begin(1); - if (rom_data == NULL) { - menu_darken_bg(giz_screen, giz_screen, 321*240, 0); + if (!rom_loaded) { + menu_darken_bg(menu_screen, menu_screen, 321*240, 0); } - menu_darken_bg((char *)giz_screen + 321*120*2, (char *)giz_screen + 321*120*2, 321*8, 0); + menu_darken_bg((char *)menu_screen + 321*120*2, (char *)menu_screen + 321*120*2, 321*8, 0); if(start - 2 >= 0) smalltext_out16_lim(14, (start - 2)*10, curdir, 0xffff, 53-2); @@ -199,19 +175,19 @@ static void draw_dirlist(char *curdir, struct dirent **namelist, int n, int sel) static int scandir_cmp(const void *p1, const void *p2) { - struct dirent **d1 = (struct dirent **)p1, **d2 = (struct dirent **)p2; - if ((*d1)->d_type == (*d2)->d_type) return alphasort(d1, d2); + struct my_dirent **d1 = (struct my_dirent **)p1, **d2 = (struct my_dirent **)p2; + if ((*d1)->d_type == (*d2)->d_type) return strcasecmp((*d1)->d_name, (*d2)->d_name); if ((*d1)->d_type == DT_DIR) return -1; // put before if ((*d2)->d_type == DT_DIR) return 1; - return alphasort(d1, d2); + return strcasecmp((*d1)->d_name, (*d2)->d_name); } static char *filter_exts[] = { - ".mp3", ".MP3", ".srm", ".brm", "s.gz", ".mds", "bcfg", ".txt", ".htm", "html", - ".jpg", ".gpe", ".cue" + ".mp3", ".srm", ".brm", "s.gz", ".mds", "bcfg", ".txt", ".htm", "html", + ".jpg", ".cue", ".exe", ".dll" }; -static int scandir_filter(const struct dirent *ent) +static int scandir_filter(const struct my_dirent *ent) { const char *p; int i; @@ -223,15 +199,119 @@ static int scandir_filter(const struct dirent *ent) for (i = 0; i < sizeof(filter_exts)/sizeof(filter_exts[0]); i++) { - if (strcmp(p, filter_exts[i]) == 0) return 0; + if (strcasecmp(p, filter_exts[i]) == 0) return 0; } return 1; } +static int cstr2wstr(wchar_t *dst, const char *src) +{ + int i, len; + for (i = len = strlen(src); i >= 0; i--) + dst[i] = src[i]; + return len; +} + +static void wstr2cstr(char *dst, const wchar_t *src) +{ + int i; + for (i = wcslen(src); i >= 0; i--) + dst[i] = src[i]; +} + +static int my_scandir(const char *dir, struct my_dirent ***namelist_out, + int(*filter)(const struct my_dirent *), + int(*compar)(const void *, const void *)) +{ + wchar_t *wdir; + int i, len, ret = -1, name_alloc = 4, name_count = 0; + struct my_dirent **namelist = NULL, *ent; + WIN32_FIND_DATA finddata; + HANDLE fh = INVALID_HANDLE_VALUE; + BOOL bRet; + + wdir = malloc(sizeof(wdir[0]) * MAX_PATH); + if (wdir == NULL) { lprintf("%s:%i: OOM\n", __FILE__, __LINE__); goto fail; } + + namelist = malloc(sizeof(*namelist) * name_alloc); + if (namelist == NULL) { lprintf("%s:%i: OOM\n", __FILE__, __LINE__); goto fail; } + + // try to read first.. + len = cstr2wstr(wdir, dir); + for (i = 0; i < len; i++) + if (wdir[i] == '/') wdir[i] = '\\'; + if (wdir[len-1] != '\\') wdir[len++] = '\\'; + wdir[len++] = '*'; + wdir[len++] = 0; + /*if (wdir[len-1] == '\\') wdir[len-1] = 0;*/ + + bRet = 1; + fh = FindFirstFile(wdir, &finddata); + if (fh == INVALID_HANDLE_VALUE) + { + if (GetLastError() != ERROR_NO_MORE_FILES) + { + lprintf("FindFirstFile(\"%s\") failed with %lu\n", dir, GetLastError()); + goto fail; + } + bRet = 0; + } + + // add "." and ".." + ent = malloc(sizeof(*ent) + 3); + ent->d_type = DT_DIR; strcpy(ent->d_name, "."); + namelist[name_count++] = ent; + ent = malloc(sizeof(*ent) + 3); + ent->d_type = DT_DIR; strcpy(ent->d_name, ".."); + namelist[name_count++] = ent; + + while (bRet) + { + ent = malloc(sizeof(*ent) + wcslen(finddata.cFileName) + 1); + ent->d_type = (finddata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? DT_DIR : DT_REG; + wstr2cstr(ent->d_name, finddata.cFileName); + if (filter == NULL || filter(ent)) + namelist[name_count++] = ent; + else free(ent); + + if (name_count >= name_alloc) + { + void *tmp; + name_alloc *= 2; + tmp = realloc(namelist, sizeof(*namelist) * name_alloc); + if (tmp == NULL) { lprintf("%s:%i: OOM\n", __FILE__, __LINE__); goto fail; } + namelist = tmp; + } + + bRet = FindNextFile(fh, &finddata); + } + + // sort + if (compar != NULL && name_count > 3) qsort(&namelist[2], name_count - 2, sizeof(namelist[0]), compar); + + // all done. + ret = name_count; + *namelist_out = namelist; + goto end; + +fail: + if (namelist != NULL) + { + while (name_count--) + free(namelist[name_count]); + free(namelist); + } +end: + if (fh != INVALID_HANDLE_VALUE) FindClose(fh); + if (wdir != NULL) free(wdir); + return ret; +} + + static char *romsel_loop(char *curr_path) { - struct dirent **namelist; + struct my_dirent **namelist; DIR *dir; int n, sel = 0; unsigned long inp = 0; @@ -247,14 +327,13 @@ static char *romsel_loop(char *curr_path) fname = p+1; } - n = scandir(curr_path, &namelist, scandir_filter, scandir_cmp); + n = my_scandir(curr_path, &namelist, scandir_filter, scandir_cmp); if (n < 0) { - // try root - n = scandir("/", &namelist, scandir_filter, scandir_cmp); + // try root.. + n = my_scandir("/", &namelist, scandir_filter, scandir_cmp); if (n < 0) { // oops, we failed - lprintf("dir: "); lprintf(curr_path); lprintf("\n"); - perror("scandir"); + lprintf("scandir failed, dir: "); lprintf(curr_path); lprintf("\n"); return NULL; } } @@ -273,15 +352,14 @@ static char *romsel_loop(char *curr_path) for (;;) { draw_dirlist(curr_path, namelist, n, sel); - inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_LEFT|BTN_RIGHT|BTN_L|BTN_R|BTN_PLAY|BTN_STOP); - if(inp & BTN_UP ) { sel--; if (sel < 0) sel = n-2; } - if(inp & BTN_DOWN) { sel++; if (sel > n-2) sel = 0; } - if(inp & BTN_LEFT) { sel-=10; if (sel < 0) sel = 0; } - if(inp & BTN_L) { sel-=24; if (sel < 0) sel = 0; } - if(inp & BTN_RIGHT) { sel+=10; if (sel > n-2) sel = n-2; } - if(inp & BTN_R) { sel+=24; if (sel > n-2) sel = n-2; } - if(inp & BTN_PLAY) { // enter dir/select - again: + inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|PBTN_L|PBTN_R|PBTN_PLAY|PBTN_STOP); + if(inp & PBTN_UP ) { sel--; if (sel < 0) sel = n-2; } + if(inp & PBTN_DOWN) { sel++; if (sel > n-2) sel = 0; } + if(inp & PBTN_LEFT) { sel-=10; if (sel < 0) sel = 0; } + if(inp & PBTN_L) { sel-=24; if (sel < 0) sel = 0; } + if(inp & PBTN_RIGHT) { sel+=10; if (sel > n-2) sel = n-2; } + if(inp & PBTN_R) { sel+=24; if (sel > n-2) sel = n-2; } + if(inp & PBTN_PLAY) { // enter dir/select if (namelist[sel+1]->d_type == DT_REG) { strcpy(romFileName, curr_path); strcat(romFileName, "/"); @@ -308,24 +386,9 @@ static char *romsel_loop(char *curr_path) ret = romsel_loop(newdir); free(newdir); break; - } else { - // unknown file type, happens on NTFS mounts. Try to guess. - FILE *tstf; int tmp; - strcpy(romFileName, curr_path); - strcat(romFileName, "/"); - strcat(romFileName, namelist[sel+1]->d_name); - tstf = fopen(romFileName, "rb"); - if (tstf != NULL) - { - if (fread(&tmp, 1, 1, tstf) > 0 || ferror(tstf) == 0) - namelist[sel+1]->d_type = DT_REG; - else namelist[sel+1]->d_type = DT_DIR; - fclose(tstf); - goto again; - } } } - if(inp & BTN_STOP) break; // cancel + if(inp & PBTN_STOP) break; // cancel } if (n > 0) { @@ -335,11 +398,12 @@ static char *romsel_loop(char *curr_path) return ret; } -#endif +#else static char *romsel_loop(char *curr_path) { return NULL; } +#endif // ------------ patch/gg menu ------------ @@ -375,17 +439,17 @@ static void patches_menu_loop(void) for(;;) { draw_patchlist(menu_sel); - inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_LEFT|BTN_RIGHT|BTN_L|BTN_R|BTN_PLAY|BTN_STOP); - if(inp & BTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = PicoPatchCount; } - if(inp & BTN_DOWN) { menu_sel++; if (menu_sel > PicoPatchCount) menu_sel = 0; } - if(inp &(BTN_LEFT|BTN_L)) { menu_sel-=10; if (menu_sel < 0) menu_sel = 0; } - if(inp &(BTN_RIGHT|BTN_R)) { menu_sel+=10; if (menu_sel > PicoPatchCount) menu_sel = PicoPatchCount; } - if(inp & BTN_PLAY) { // action + inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|PBTN_L|PBTN_R|PBTN_PLAY|PBTN_STOP); + if(inp & PBTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = PicoPatchCount; } + if(inp & PBTN_DOWN) { menu_sel++; if (menu_sel > PicoPatchCount) menu_sel = 0; } + if(inp &(PBTN_LEFT|PBTN_L)) { menu_sel-=10; if (menu_sel < 0) menu_sel = 0; } + if(inp &(PBTN_RIGHT|PBTN_R)) { menu_sel+=10; if (menu_sel > PicoPatchCount) menu_sel = PicoPatchCount; } + if(inp & PBTN_PLAY) { // action if (menu_sel < PicoPatchCount) PicoPatches[menu_sel].active = !PicoPatches[menu_sel].active; else return; } - if(inp & BTN_STOP) return; + if(inp & PBTN_STOP) return; } } @@ -402,7 +466,7 @@ static void state_check_slots(void) for (slot = 0; slot < 10; slot++) { - if (emu_check_save_file(slot)) + if (emu_checkSaveFile(slot)) { state_slot_flags |= 1 << slot; } @@ -430,14 +494,14 @@ static void draw_savestate_bg(int slot) if (strcmp(fname + strlen(fname) - 3, ".gz") == 0) { file = gzopen(fname, "rb"); - emu_set_save_cbs(1); + emu_setSaveStateCbs(1); } else { file = fopen(fname, "rb"); - emu_set_save_cbs(0); + emu_setSaveStateCbs(0); } if (file) { - if (PicoMCD & 1) { + if (PicoIn.AHW & 1) { PicoCdLoadStateGfx(file); } else { areaSeek(file, 0x10020, SEEK_SET); // skip header and RAM in state file @@ -451,7 +515,7 @@ static void draw_savestate_bg(int slot) areaClose(file); } - emu_forced_frame(); + emu_forcedFrame(POPT_EN_SOFTSCALE); menu_prepare_bg(1); memcpy(Pico.vram, tmp_vram, sizeof(Pico.vram)); @@ -495,20 +559,21 @@ static int savestate_menu_loop(int is_loading) for(;;) { draw_savestate_menu(menu_sel, is_loading); - inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_PLAY|BTN_STOP); - if(inp & BTN_UP ) { + inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_PLAY|PBTN_STOP); + if(inp & PBTN_UP ) { do { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; } while (!(state_slot_flags & (1 << menu_sel)) && menu_sel != menu_sel_max && is_loading); } - if(inp & BTN_DOWN) { + if(inp & PBTN_DOWN) { do { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; } while (!(state_slot_flags & (1 << menu_sel)) && menu_sel != menu_sel_max && is_loading); } - if(inp & BTN_PLAY) { // save/load + if(inp & PBTN_PLAY) { // save/load if (menu_sel < 10) { state_slot = menu_sel; + PicoStateProgressCB = emu_stateCb; /* also suitable for menu */ if (emu_SaveLoadGame(is_loading, 0)) { strcpy(menuErrorMsg, is_loading ? "Load failed" : "Save failed"); return 1; @@ -516,7 +581,7 @@ static int savestate_menu_loop(int is_loading) return 0; } else return 1; } - if(inp & BTN_STOP) return 1; + if(inp & PBTN_STOP) return 1; } } @@ -533,8 +598,8 @@ static char *action_binds(int player_idx, int action_mask) if (currentConfig.KeyBinds[i] & action_mask) { if (player_idx >= 0 && ((currentConfig.KeyBinds[i] >> 16) & 3) != player_idx) continue; - if (strkeys[0]) { strcat(strkeys, " + "); strcat(strkeys, gizKeyNames[i]); break; } - else strcpy(strkeys, gizKeyNames[i]); + if (strkeys[0]) { strcat(strkeys, " + "); strcat(strkeys, keyNames[i]); break; } + else strcpy(strkeys, keyNames[i]); } } @@ -549,28 +614,29 @@ static void unbind_action(int action) currentConfig.KeyBinds[i] &= ~action; } -static int count_bound_keys(int action) +static int count_bound_keys(int action, int pl_idx) { int i, keys = 0; for (i = 0; i < 32; i++) + { + if (pl_idx >= 0 && (currentConfig.KeyBinds[i]&0x30000) != (pl_idx<<16)) continue; if (currentConfig.KeyBinds[i] & action) keys++; + } return keys; } -typedef struct { char *name; int mask; } bind_action_t; - -static void draw_key_config(const bind_action_t *opts, int opt_cnt, int player_idx, int sel) +static void draw_key_config(const me_bind_action *opts, int opt_cnt, int player_idx, int sel) { - int x, y, tl_y = 40, i; + int x, y, tl_y = 30, i; menu_draw_begin(1); if (player_idx >= 0) { - text_out16(80, 20, "Player %i controls", player_idx + 1); - x = 100; + text_out16(80, 10, "Player %i controls", player_idx + 1); + x = 80; } else { - text_out16(80, 20, "Emulator controls"); + text_out16(80, 10, "Emulator controls"); x = 40; } @@ -583,19 +649,19 @@ static void draw_key_config(const bind_action_t *opts, int opt_cnt, int player_i text_out16(x, y, "Done"); if (sel < opt_cnt) { - text_out16(30, 180, "Press a button to bind/unbind"); - text_out16(30, 190, "Use SELECT to clear"); - text_out16(30, 200, "To bind UP/DOWN, hold SELECT"); - text_out16(30, 210, "Select \"Done\" to exit"); + text_out16(30, 195, "Press a button to bind/unbind"); + text_out16(30, 205, "Use HOME to clear"); + text_out16(30, 215, "To bind UP/DOWN, hold HOME"); + text_out16(30, 225, "Select \"Done\" to exit"); } else { - text_out16(30, 190, "Use Options -> Save cfg"); - text_out16(30, 200, "to save controls"); - text_out16(30, 210, "Press B or X to exit"); + text_out16(30, 205, "Use Options -> Save cfg"); + text_out16(30, 215, "to save controls"); + text_out16(30, 225, "Press PLAY or STOP to exit"); } menu_draw_end(); } -static void key_config_loop(const bind_action_t *opts, int opt_cnt, int player_idx) +static void key_config_loop(const me_bind_action *opts, int opt_cnt, int player_idx) { int sel = 0, menu_sel_max = opt_cnt, prev_select = 0, i; unsigned long inp = 0; @@ -603,28 +669,28 @@ static void key_config_loop(const bind_action_t *opts, int opt_cnt, int player_i for (;;) { draw_key_config(opts, opt_cnt, player_idx, sel); - inp = wait_for_input(CONFIGURABLE_KEYS); - if (!(inp & BTN_HOME)) { + inp = in_menu_wait(CONFIGURABLE_KEYS|PBTN_HOME); + if (!(inp & PBTN_HOME)) { prev_select = 0; - if(inp & BTN_UP ) { sel--; if (sel < 0) sel = menu_sel_max; continue; } - if(inp & BTN_DOWN) { sel++; if (sel > menu_sel_max) sel = 0; continue; } + if(inp & PBTN_UP ) { sel--; if (sel < 0) sel = menu_sel_max; continue; } + if(inp & PBTN_DOWN) { sel++; if (sel > menu_sel_max) sel = 0; continue; } } if (sel >= opt_cnt) { - if (inp & (BTN_PLAY|BTN_STOP)) break; + if (inp & (PBTN_PLAY|PBTN_STOP)) break; else continue; } // if we are here, we want to bind/unbind something - if ((inp & BTN_HOME) && !prev_select) + if ((inp & PBTN_HOME) && !prev_select) unbind_action(opts[sel].mask); - prev_select = inp & BTN_HOME; + prev_select = inp & PBTN_HOME; inp &= CONFIGURABLE_KEYS; - inp &= ~BTN_HOME; + inp &= ~PBTN_HOME; for (i = 0; i < 32; i++) if (inp & (1 << i)) { - if (count_bound_keys(opts[sel].mask) >= 2) - currentConfig.KeyBinds[i] &= ~opts[sel].mask; // allow to unbind only + if (count_bound_keys(opts[sel].mask, player_idx) >= 2) + currentConfig.KeyBinds[i] &= ~opts[sel].mask; // allow to unbind only else currentConfig.KeyBinds[i] ^= opts[sel].mask; - if (player_idx >= 0) { + if (player_idx >= 0 && (currentConfig.KeyBinds[i] & opts[sel].mask)) { currentConfig.KeyBinds[i] &= ~(3 << 16); currentConfig.KeyBinds[i] |= player_idx << 16; } @@ -632,6 +698,19 @@ static void key_config_loop(const bind_action_t *opts, int opt_cnt, int player_i } } +menu_entry ctrlopt_entries[] = +{ + { "Player 1", MB_NONE, MA_CTRL_PLAYER1, NULL, 0, 0, 0, 1, 0 }, + { "Player 2", MB_NONE, MA_CTRL_PLAYER2, NULL, 0, 0, 0, 1, 0 }, + { "Emulator controls", MB_NONE, MA_CTRL_EMU, NULL, 0, 0, 0, 1, 0 }, + { "6 button pad", MB_ONOFF, MA_OPT_6BUTTON_PAD, &PicoIn.opt, 0x020, 0, 0, 1, 1 }, + { "Turbo rate", MB_RANGE, MA_CTRL_TURBO_RATE, ¤tConfig.turbo_rate, 0, 1, 30, 1, 1 }, + { "Done", MB_NONE, MA_CTRL_DONE, NULL, 0, 0, 0, 1, 0 }, +}; + +#define CTRLOPT_ENTRY_COUNT (sizeof(ctrlopt_entries) / sizeof(ctrlopt_entries[0])) +const int ctrlopt_entry_count = CTRLOPT_ENTRY_COUNT; + static void draw_kc_sel(int menu_sel) { int tl_x = 25+40, tl_y = 60, y; @@ -640,36 +719,16 @@ static void draw_kc_sel(int menu_sel) menu_draw_begin(1); menu_draw_selection(tl_x - 16, tl_y + menu_sel*10, 138); - text_out16(tl_x, y, "Player 1"); - text_out16(tl_x, (y+=10), "Player 2"); - text_out16(tl_x, (y+=10), "Emulator controls"); - text_out16(tl_x, (y+=10), "Done"); + me_draw(ctrlopt_entries, ctrlopt_entry_count, tl_x, tl_y, NULL, NULL); menu_draw_end(); } -// PicoPad[] format: MXYZ SACB RLDU -static bind_action_t ctrl_actions[] = -{ - { "UP ", 0x001 }, - { "DOWN ", 0x002 }, - { "LEFT ", 0x004 }, - { "RIGHT ", 0x008 }, - { "A ", 0x040 }, - { "B ", 0x010 }, - { "C ", 0x020 }, - { "START ", 0x080 }, - { "MODE ", 0x800 }, - { "X ", 0x400 }, - { "Y ", 0x200 }, - { "Z ", 0x100 }, -}; - // player2_flag, ?, ?, ?, ?, ?, ?, menu // "NEXT SAVE SLOT", "PREV SAVE SLOT", "SWITCH RENDERER", "SAVE STATE", // "LOAD STATE", "VOLUME UP", "VOLUME DOWN", "DONE" -static bind_action_t emuctrl_actions[] = +me_bind_action emuctrl_actions[] = { { "Load State ", 1<<28 }, { "Save State ", 1<<27 }, @@ -678,32 +737,36 @@ static bind_action_t emuctrl_actions[] = { "Switch Renderer", 1<<26 }, { "Volume Down ", 1<<30 }, { "Volume Up ", 1<<29 }, - { "Enter Menu ", 1<<23 }, + { NULL, 0 } }; static void kc_sel_loop(void) { - int menu_sel = 3, menu_sel_max = 3; + int menu_sel = 5, menu_sel_max = 5; unsigned long inp = 0; - int is_6button = currentConfig.PicoOpt & 0x020; + menu_id selected_id; while (1) { draw_kc_sel(menu_sel); - inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_PLAY|BTN_STOP); - if (inp & BTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; } - if (inp & BTN_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; } - if (inp & BTN_PLAY) { - switch (menu_sel) { - case 0: key_config_loop(ctrl_actions, is_6button ? 12 : 8, 0); return; - case 1: key_config_loop(ctrl_actions, is_6button ? 12 : 8, 1); return; - case 2: key_config_loop(emuctrl_actions, - sizeof(emuctrl_actions)/sizeof(emuctrl_actions[0]), -1); return; - case 3: if (rom_data == NULL) emu_WriteConfig(0); return; + inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_PLAY|PBTN_STOP); + selected_id = me_index2id(ctrlopt_entries, CTRLOPT_ENTRY_COUNT, menu_sel); + if (inp & (PBTN_LEFT|PBTN_RIGHT)) // multi choise + me_process(ctrlopt_entries, CTRLOPT_ENTRY_COUNT, selected_id, (inp&PBTN_RIGHT) ? 1 : 0); + if (inp & PBTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; } + if (inp & PBTN_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; } + if (inp & PBTN_PLAY) { + int is_6button = PicoIn.opt & 0x020; + switch (selected_id) { + case MA_CTRL_PLAYER1: key_config_loop(me_ctrl_actions, is_6button ? 15 : 11, 0); return; + case MA_CTRL_PLAYER2: key_config_loop(me_ctrl_actions, is_6button ? 15 : 11, 1); return; + case MA_CTRL_EMU: key_config_loop(emuctrl_actions, + sizeof(emuctrl_actions)/sizeof(emuctrl_actions[0]) - 1, -1); return; + case MA_CTRL_DONE: if (!rom_loaded) emu_WriteConfig(0); return; default: return; } } - if (inp & BTN_STOP) return; + if (inp & PBTN_STOP) return; } } @@ -712,20 +775,21 @@ static void kc_sel_loop(void) menu_entry cdopt_entries[] = { - { NULL, MB_NONE, MA_CDOPT_TESTBIOS_USA, NULL, 0, 0, 0, 1 }, - { NULL, MB_NONE, MA_CDOPT_TESTBIOS_EUR, NULL, 0, 0, 0, 1 }, - { NULL, MB_NONE, MA_CDOPT_TESTBIOS_JAP, NULL, 0, 0, 0, 1 }, - { "CD LEDs", MB_ONOFF, MA_CDOPT_LEDS, ¤tConfig.EmuOpt, 0x0400, 0, 0, 1 }, - { "CDDA audio (using mp3s)", MB_ONOFF, MA_CDOPT_CDDA, ¤tConfig.PicoOpt, 0x0800, 0, 0, 1 }, - { "PCM audio", MB_ONOFF, MA_CDOPT_PCM, ¤tConfig.PicoOpt, 0x0400, 0, 0, 1 }, - { NULL, MB_NONE, MA_CDOPT_READAHEAD, NULL, 0, 0, 0, 1 }, - { "SaveRAM cart", MB_ONOFF, MA_CDOPT_SAVERAM, ¤tConfig.PicoOpt, 0x8000, 0, 0, 1 }, - { "Scale/Rot. fx (slow)", MB_ONOFF, MA_CDOPT_SCALEROT_CHIP,¤tConfig.PicoOpt, 0x1000, 0, 0, 1 }, - { "Better sync (slow)", MB_ONOFF, MA_CDOPT_BETTER_SYNC, ¤tConfig.PicoOpt, 0x2000, 0, 0, 1 }, - { "done", MB_NONE, MA_CDOPT_DONE, NULL, 0, 0, 0, 1 }, + { NULL, MB_NONE, MA_CDOPT_TESTBIOS_USA, NULL, 0, 0, 0, 1, 0 }, + { NULL, MB_NONE, MA_CDOPT_TESTBIOS_EUR, NULL, 0, 0, 0, 1, 0 }, + { NULL, MB_NONE, MA_CDOPT_TESTBIOS_JAP, NULL, 0, 0, 0, 1, 0 }, + { "CD LEDs", MB_ONOFF, MA_CDOPT_LEDS, ¤tConfig.EmuOpt, 0x0400, 0, 0, 1, 1 }, + { "CDDA audio", MB_ONOFF, MA_CDOPT_CDDA, &PicoIn.opt, 0x0800, 0, 0, 1, 1 }, + { "PCM audio", MB_ONOFF, MA_CDOPT_PCM, &PicoIn.opt, 0x0400, 0, 0, 1, 1 }, + { NULL, MB_NONE, MA_CDOPT_READAHEAD, NULL, 0, 0, 0, 1, 1 }, + { "SaveRAM cart", MB_ONOFF, MA_CDOPT_SAVERAM, &PicoIn.opt, 0x8000, 0, 0, 1, 1 }, + { "Scale/Rot. fx (slow)", MB_ONOFF, MA_CDOPT_SCALEROT_CHIP,&PicoIn.opt, 0x1000, 0, 0, 1, 1 }, + { "Better sync (slow)", MB_ONOFF, MA_CDOPT_BETTER_SYNC, &PicoIn.opt, 0x2000, 0, 0, 1, 1 }, + { "done", MB_NONE, MA_CDOPT_DONE, NULL, 0, 0, 0, 1, 0 }, }; #define CDOPT_ENTRY_COUNT (sizeof(cdopt_entries) / sizeof(cdopt_entries[0])) +const int cdopt_entry_count = CDOPT_ENTRY_COUNT; struct bios_names_t @@ -785,63 +849,66 @@ static void cd_menu_loop_options(void) menu_id selected_id; char *bios, *p; - if (find_bios(4, &bios)) { // US - for (p = bios+strlen(bios)-1; p > bios && *p != '/'; p--); p++; + if (emu_findBios(4, &bios)) { // US + for (p = bios+strlen(bios)-1; p > bios && *p != '/'; p--); + if (*p == '/') p++; strncpy(bios_names.us, p, sizeof(bios_names.us)); bios_names.us[sizeof(bios_names.us)-1] = 0; } else strcpy(bios_names.us, "NOT FOUND"); - if (find_bios(8, &bios)) { // EU - for (p = bios+strlen(bios)-1; p > bios && *p != '/'; p--); p++; + if (emu_findBios(8, &bios)) { // EU + for (p = bios+strlen(bios)-1; p > bios && *p != '/'; p--); + if (*p == '/') p++; strncpy(bios_names.eu, p, sizeof(bios_names.eu)); bios_names.eu[sizeof(bios_names.eu)-1] = 0; } else strcpy(bios_names.eu, "NOT FOUND"); - if (find_bios(1, &bios)) { // JP - for (p = bios+strlen(bios)-1; p > bios && *p != '/'; p--); p++; + if (emu_findBios(1, &bios)) { // JP + for (p = bios+strlen(bios)-1; p > bios && *p != '/'; p--); + if (*p == '/') p++; strncpy(bios_names.jp, p, sizeof(bios_names.jp)); bios_names.jp[sizeof(bios_names.jp)-1] = 0; } else strcpy(bios_names.jp, "NOT FOUND"); for(;;) { draw_cd_menu_options(menu_sel, &bios_names); - inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_LEFT|BTN_RIGHT|BTN_PLAY|BTN_STOP|BTN_REW); - if (inp & BTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; } - if (inp & BTN_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; } + inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|PBTN_PLAY|PBTN_STOP|PBTN_REW); + if (inp & PBTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; } + if (inp & PBTN_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; } selected_id = me_index2id(cdopt_entries, CDOPT_ENTRY_COUNT, menu_sel); - if (inp & (BTN_LEFT|BTN_RIGHT)) { // multi choise - if (!me_process(cdopt_entries, CDOPT_ENTRY_COUNT, selected_id, (inp&BTN_RIGHT) ? 1 : 0) && + if (inp & (PBTN_LEFT|PBTN_RIGHT)) { // multi choise + if (!me_process(cdopt_entries, CDOPT_ENTRY_COUNT, selected_id, (inp&PBTN_RIGHT) ? 1 : 0) && selected_id == MA_CDOPT_READAHEAD) { - if (inp & BTN_LEFT) { + if (inp & PBTN_LEFT) { PicoCDBuffers >>= 1; - if (PicoCDBuffers < 64) PicoCDBuffers = 0; + if (PicoCDBuffers < 2) PicoCDBuffers = 0; } else { - if (PicoCDBuffers < 64) PicoCDBuffers = 64; + if (PicoCDBuffers < 2) PicoCDBuffers = 2; else PicoCDBuffers <<= 1; if (PicoCDBuffers > 8*1024) PicoCDBuffers = 8*1024; // 16M } } } - if (inp & BTN_PLAY) { // toggleable options + if (inp & PBTN_PLAY) { // toggleable options if (!me_process(cdopt_entries, CDOPT_ENTRY_COUNT, selected_id, 1) && selected_id == MA_CDOPT_DONE) { return; } switch (selected_id) { // BIOS testers case MA_CDOPT_TESTBIOS_USA: - if (find_bios(4, &bios)) { // test US + if (emu_findBios(4, &bios)) { // test US strcpy(romFileName, bios); engineState = PGS_ReloadRom; return; } break; case MA_CDOPT_TESTBIOS_EUR: - if (find_bios(8, &bios)) { // test EU + if (emu_findBios(8, &bios)) { // test EU strcpy(romFileName, bios); engineState = PGS_ReloadRom; return; } break; case MA_CDOPT_TESTBIOS_JAP: - if (find_bios(1, &bios)) { // test JP + if (emu_findBios(1, &bios)) { // test JP strcpy(romFileName, bios); engineState = PGS_ReloadRom; return; @@ -851,7 +918,7 @@ static void cd_menu_loop_options(void) break; } } - if (inp & (BTN_STOP|BTN_REW)) return; + if (inp & (PBTN_STOP|PBTN_REW)) return; } } @@ -860,15 +927,21 @@ static void cd_menu_loop_options(void) menu_entry opt2_entries[] = { - { "Emulate Z80", MB_ONOFF, MA_OPT2_ENABLE_Z80, ¤tConfig.PicoOpt,0x0004, 0, 0, 1 }, - { "Emulate YM2612 (FM)", MB_ONOFF, MA_OPT2_ENABLE_YM2612, ¤tConfig.PicoOpt,0x0001, 0, 0, 1 }, - { "Emulate SN76496 (PSG)", MB_ONOFF, MA_OPT2_ENABLE_SN76496,¤tConfig.PicoOpt,0x0002, 0, 0, 1 }, - { "gzip savestates", MB_ONOFF, MA_OPT2_GZIP_STATES, ¤tConfig.EmuOpt, 0x0008, 0, 0, 1 }, - { "Don't save last used ROM", MB_ONOFF, MA_OPT2_NO_LAST_ROM, ¤tConfig.EmuOpt, 0x0020, 0, 0, 1 }, - { "done", MB_NONE, MA_OPT2_DONE, NULL, 0, 0, 0, 1 }, + { "Disable sprite limit", MB_ONOFF, MA_OPT2_NO_SPRITE_LIM, &PicoIn.opt, 0x40000, 0, 0, 1, 1 }, + { "Emulate Z80", MB_ONOFF, MA_OPT2_ENABLE_Z80, &PicoIn.opt, 0x00004, 0, 0, 1, 1 }, + { "Emulate YM2612 (FM)", MB_ONOFF, MA_OPT2_ENABLE_YM2612, &PicoIn.opt, 0x00001, 0, 0, 1, 1 }, + { "Emulate SN76496 (PSG)", MB_ONOFF, MA_OPT2_ENABLE_SN76496,&PicoIn.opt, 0x00002, 0, 0, 1, 1 }, + { "Double buffering", MB_ONOFF, MA_OPT2_DBLBUFF, ¤tConfig.EmuOpt, 0x8000, 0, 0, 1, 1 }, + { "Wait for V-sync (slow)", MB_ONOFF, MA_OPT2_VSYNC, ¤tConfig.EmuOpt, 0x2000, 0, 0, 1, 1 }, + { "gzip savestates", MB_ONOFF, MA_OPT2_GZIP_STATES, ¤tConfig.EmuOpt, 0x0008, 0, 0, 1, 1 }, + { "Don't save last used ROM", MB_ONOFF, MA_OPT2_NO_LAST_ROM, ¤tConfig.EmuOpt, 0x0020, 0, 0, 1, 1 }, + { "SVP dynarec", MB_ONOFF, MA_OPT2_SVP_DYNAREC, &PicoIn.opt, 0x20000, 0, 0, 1, 1 }, + { "Disable idle loop patching",MB_ONOFF, MA_OPT2_NO_IDLE_LOOPS, &PicoIn.opt, 0x80000, 0, 0, 1, 1 }, + { "done", MB_NONE, MA_OPT2_DONE, NULL, 0, 0, 0, 1, 0 }, }; #define OPT2_ENTRY_COUNT (sizeof(opt2_entries) / sizeof(opt2_entries[0])) +const int opt2_entry_count = OPT2_ENTRY_COUNT; static void draw_amenu_options(int menu_sel) @@ -896,15 +969,15 @@ static void amenu_loop_options(void) for(;;) { draw_amenu_options(menu_sel); - inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_LEFT|BTN_RIGHT|BTN_PLAY|BTN_STOP|BTN_REW); - if (inp & BTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; } - if (inp & BTN_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; } + inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|PBTN_PLAY|PBTN_STOP|PBTN_REW); + if (inp & PBTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; } + if (inp & PBTN_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; } selected_id = me_index2id(opt2_entries, OPT2_ENTRY_COUNT, menu_sel); - if (inp & (BTN_LEFT|BTN_RIGHT)) { // multi choise - if (!me_process(opt2_entries, OPT2_ENTRY_COUNT, selected_id, (inp&BTN_RIGHT) ? 1 : 0) && + if (inp & (PBTN_LEFT|PBTN_RIGHT)) { // multi choise + if (!me_process(opt2_entries, OPT2_ENTRY_COUNT, selected_id, (inp&PBTN_RIGHT) ? 1 : 0) && selected_id == MA_OPT2_GAMMA) { - while ((inp = Framework_PollGetButtons(1)) & (BTN_LEFT|BTN_RIGHT)) { - currentConfig.gamma += (inp & BTN_LEFT) ? -1 : 1; + while ((inp = Framework_PollGetButtons()) & (PBTN_LEFT|PBTN_RIGHT)) { + currentConfig.gamma += (inp & PBTN_LEFT) ? -1 : 1; if (currentConfig.gamma < 1) currentConfig.gamma = 1; if (currentConfig.gamma > 300) currentConfig.gamma = 300; draw_amenu_options(menu_sel); @@ -912,13 +985,13 @@ static void amenu_loop_options(void) } } } - if (inp & BTN_PLAY) { // toggleable options + if (inp & PBTN_PLAY) { // toggleable options if (!me_process(opt2_entries, OPT2_ENTRY_COUNT, selected_id, 1) && selected_id == MA_OPT2_DONE) { return; } } - if (inp & (BTN_STOP|BTN_REW)) return; + if (inp & (PBTN_STOP|PBTN_REW)) return; } } @@ -927,50 +1000,27 @@ static void amenu_loop_options(void) menu_entry opt_entries[] = { - { NULL, MB_NONE, MA_OPT_RENDERER, NULL, 0, 0, 0, 1 }, - { "Scale low res mode", MB_ONOFF, MA_OPT_SCALING, ¤tConfig.scaling, 0x001, 0, 3, 1 }, - { "Accurate timing (slower)", MB_ONOFF, MA_OPT_ACC_TIMING, ¤tConfig.PicoOpt, 0x040, 0, 0, 1 }, - { "Accurate sprites (slower)", MB_ONOFF, MA_OPT_ACC_SPRITES, ¤tConfig.PicoOpt, 0x080, 0, 0, 1 }, - { "Show FPS", MB_ONOFF, MA_OPT_SHOW_FPS, ¤tConfig.EmuOpt, 0x002, 0, 0, 1 }, - { NULL, MB_RANGE, MA_OPT_FRAMESKIP, ¤tConfig.Frameskip, 0, -1, 16, 1 }, - { "Enable sound", MB_ONOFF, MA_OPT_ENABLE_SOUND, ¤tConfig.EmuOpt, 0x004, 0, 0, 1 }, - { NULL, MB_NONE, MA_OPT_SOUND_QUALITY, NULL, 0, 0, 0, 1 }, - { "6 button pad", MB_ONOFF, MA_OPT_6BUTTON_PAD, ¤tConfig.PicoOpt, 0x020, 0, 0, 1 }, - { NULL, MB_NONE, MA_OPT_REGION, NULL, 0, 0, 0, 1 }, - { "Use SRAM/BRAM savestates", MB_ONOFF, MA_OPT_SRAM_STATES, ¤tConfig.EmuOpt, 0x001, 0, 0, 1 }, - { NULL, MB_NONE, MA_OPT_CONFIRM_STATES,NULL, 0, 0, 0, 1 }, - { "Save slot", MB_RANGE, MA_OPT_SAVE_SLOT, &state_slot, 0, 0, 9, 1 }, - { "[Sega/Mega CD options]", MB_NONE, MA_OPT_SCD_OPTS, NULL, 0, 0, 0, 1 }, - { "[advanced options]", MB_NONE, MA_OPT_ADV_OPTS, NULL, 0, 0, 0, 1 }, - { NULL, MB_NONE, MA_OPT_SAVECFG, NULL, 0, 0, 0, 1 }, - { "Save cfg for current game only",MB_NONE,MA_OPT_SAVECFG_GAME,NULL, 0, 0, 0, 1 }, - { NULL, MB_NONE, MA_OPT_LOADCFG, NULL, 0, 0, 0, 1 }, + { NULL, MB_NONE, MA_OPT_RENDERER, NULL, 0, 0, 0, 1, 1 }, + { "Accurate sprites", MB_ONOFF, MA_OPT_ACC_SPRITES, &PicoIn.opt, 0x080, 0, 0, 0, 1 }, + { "Scanline mode (faster)", MB_ONOFF, MA_OPT_INTERLACED, ¤tConfig.EmuOpt, 0x4000, 0, 0, 1, 1 }, + { "Scale low res mode", MB_ONOFF, MA_OPT_SCALING, ¤tConfig.scaling, 0x0001, 0, 3, 1, 1 }, + { "Show FPS", MB_ONOFF, MA_OPT_SHOW_FPS, ¤tConfig.EmuOpt, 0x0002, 0, 0, 1, 1 }, + { NULL, MB_RANGE, MA_OPT_FRAMESKIP, ¤tConfig.Frameskip, 0, -1, 16, 1, 1 }, + { "Enable sound", MB_ONOFF, MA_OPT_ENABLE_SOUND, ¤tConfig.EmuOpt, 0x0004, 0, 0, 1, 1 }, + { NULL, MB_NONE, MA_OPT_SOUND_QUALITY, NULL, 0, 0, 0, 1, 1 }, + { NULL, MB_NONE, MA_OPT_REGION, NULL, 0, 0, 0, 1, 1 }, + { "Use SRAM/BRAM savestates", MB_ONOFF, MA_OPT_SRAM_STATES, ¤tConfig.EmuOpt, 0x0001, 0, 0, 1, 1 }, + { NULL, MB_NONE, MA_OPT_CONFIRM_STATES,NULL, 0, 0, 0, 1, 1 }, + { "Save slot", MB_RANGE, MA_OPT_SAVE_SLOT, &state_slot, 0, 0, 9, 1, 1 }, + { "[Sega/Mega CD options]", MB_NONE, MA_OPT_SCD_OPTS, NULL, 0, 0, 0, 1, 0 }, + { "[advanced options]", MB_NONE, MA_OPT_ADV_OPTS, NULL, 0, 0, 0, 1, 0 }, + { NULL, MB_NONE, MA_OPT_SAVECFG, NULL, 0, 0, 0, 1, 0 }, + { "Save cfg for current game only",MB_NONE,MA_OPT_SAVECFG_GAME,NULL, 0, 0, 0, 1, 0 }, + { NULL, MB_NONE, MA_OPT_LOADCFG, NULL, 0, 0, 0, 1, 0 }, }; #define OPT_ENTRY_COUNT (sizeof(opt_entries) / sizeof(opt_entries[0])) - - -static const char *region_name(unsigned int code) -{ - static const char *names[] = { "Auto", " Japan NTSC", " Japan PAL", " USA", " Europe" }; - static const char *names_short[] = { "", " JP", " JP", " US", " EU" }; - int u, i = 0; - if (code) { - code <<= 1; - while((code >>= 1)) i++; - if (i > 4) return "unknown"; - return names[i]; - } else { - static char name[24]; - strcpy(name, "Auto:"); - for (u = 0; u < 3; u++) { - i = 0; code = ((PicoAutoRgnOrder >> u*4) & 0xf) << 1; - while((code >>= 1)) i++; - strcat(name, names_short[i]); - } - return name; - } -} +const int opt_entry_count = OPT_ENTRY_COUNT; static void menu_opt_cust_draw(const menu_entry *entry, int x, int y, void *param) @@ -980,7 +1030,7 @@ static void menu_opt_cust_draw(const menu_entry *entry, int x, int y, void *para switch (entry->id) { case MA_OPT_RENDERER: - if (currentConfig.PicoOpt&0x10) + if (PicoIn.opt&0x10) str = " 8bit fast"; else if (currentConfig.EmuOpt&0x80) str = "16bit accurate"; @@ -995,11 +1045,11 @@ static void menu_opt_cust_draw(const menu_entry *entry, int x, int y, void *para text_out16(x, y, "Frameskip %s", str24); break; case MA_OPT_SOUND_QUALITY: - str = (currentConfig.PicoOpt&0x08)?"stereo":"mono"; - text_out16(x, y, "Sound Quality: %5iHz %s", currentConfig.PsndRate, str); + str = (PicoIn.opt&0x08)?"stereo":"mono"; + text_out16(x, y, "Sound Quality: %5iHz %s", PsndRate, str); break; case MA_OPT_REGION: - text_out16(x, y, "Region: %s", region_name(currentConfig.PicoRegion)); + text_out16(x, y, "Region: %s", me_region_name(PicoIn.regionOverride, PicoIn.autoRgnOrder)); break; case MA_OPT_CONFIRM_STATES: switch ((currentConfig.EmuOpt >> 9) & 5) { @@ -1041,14 +1091,14 @@ static void draw_menu_options(int menu_sel) static int sndrate_prevnext(int rate, int dir) { - int i, rates[] = { 8000, 11025, 16000, 22050, 44100 }; + int i, rates[] = { 11025, 22050, 44100 }; for (i = 0; i < 5; i++) if (rates[i] == rate) break; i += dir ? 1 : -1; - if (i > 4) return dir ? 44100 : 22050; - if (i < 0) return dir ? 11025 : 8000; + if (i > 2) return dir ? 44100 : 22050; + if (i < 0) return dir ? 22050 : 11025; return rates[i]; } @@ -1058,34 +1108,34 @@ static void region_prevnext(int right) static int rgn_orders[] = { 0x148, 0x184, 0x814, 0x418, 0x841, 0x481 }; int i; if (right) { - if (!currentConfig.PicoRegion) { + if (!PicoIn.regionOverride) { for (i = 0; i < 6; i++) - if (rgn_orders[i] == PicoAutoRgnOrder) break; - if (i < 5) PicoAutoRgnOrder = rgn_orders[i+1]; - else currentConfig.PicoRegion=1; + if (rgn_orders[i] == PicoIn.autoRgnOrder) break; + if (i < 5) PicoIn.autoRgnOrder = rgn_orders[i+1]; + else PicoIn.regionOverride=1; } - else currentConfig.PicoRegion<<=1; - if (currentConfig.PicoRegion > 8) currentConfig.PicoRegion = 8; + else PicoIn.regionOverride<<=1; + if (PicoIn.regionOverride > 8) PicoIn.regionOverride = 8; } else { - if (!currentConfig.PicoRegion) { + if (!PicoIn.regionOverride) { for (i = 0; i < 6; i++) - if (rgn_orders[i] == PicoAutoRgnOrder) break; - if (i > 0) PicoAutoRgnOrder = rgn_orders[i-1]; + if (rgn_orders[i] == PicoIn.autoRgnOrder) break; + if (i > 0) PicoIn.autoRgnOrder = rgn_orders[i-1]; } - else currentConfig.PicoRegion>>=1; + else PicoIn.regionOverride>>=1; } } static void menu_options_save(void) { - PicoOpt = currentConfig.PicoOpt; - PsndRate = currentConfig.PsndRate; - PicoRegionOverride = currentConfig.PicoRegion; - if (!(PicoOpt & 0x20)) { + if (PicoIn.regionOverride) { + // force setting possibly changed.. + Pico.m.pal = (PicoIn.regionOverride == 2 || PicoIn.regionOverride == 8) ? 1 : 0; + } + if (!(PicoIn.opt & 0x20)) { // unbind XYZ MODE, just in case unbind_action(0xf00); } - scaling_update(); } static int menu_loop_options(void) @@ -1095,11 +1145,7 @@ static int menu_loop_options(void) unsigned long inp = 0; menu_id selected_id; - currentConfig.PicoOpt = PicoOpt; - currentConfig.PsndRate = PsndRate; - currentConfig.PicoRegion = PicoRegionOverride; - - me_enable(opt_entries, OPT_ENTRY_COUNT, MA_OPT_SAVECFG_GAME, rom_data != NULL); + me_enable(opt_entries, OPT_ENTRY_COUNT, MA_OPT_SAVECFG_GAME, rom_loaded); me_enable(opt_entries, OPT_ENTRY_COUNT, MA_OPT_LOADCFG, config_slot != config_slot_current); menu_sel_max = me_count_enabled(opt_entries, OPT_ENTRY_COUNT) - 1; if (menu_sel > menu_sel_max) menu_sel = menu_sel_max; @@ -1107,37 +1153,46 @@ static int menu_loop_options(void) while (1) { draw_menu_options(menu_sel); - inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_LEFT|BTN_RIGHT|BTN_PLAY|BTN_STOP|BTN_REW); - if (inp & BTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; } - if (inp & BTN_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; } + inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|PBTN_PLAY|PBTN_STOP|PBTN_REW); + if (inp & PBTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; } + if (inp & PBTN_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; } selected_id = me_index2id(opt_entries, OPT_ENTRY_COUNT, menu_sel); - if (inp & (BTN_LEFT|BTN_RIGHT)) { // multi choise - if (!me_process(opt_entries, OPT_ENTRY_COUNT, selected_id, (inp&BTN_RIGHT) ? 1 : 0)) { + if (inp & (PBTN_LEFT|PBTN_RIGHT)) { // multi choise + if (!me_process(opt_entries, OPT_ENTRY_COUNT, selected_id, (inp&PBTN_RIGHT) ? 1 : 0)) { switch (selected_id) { case MA_OPT_RENDERER: - if (inp & BTN_LEFT) { - if ( currentConfig.PicoOpt&0x10) currentConfig.PicoOpt&= ~0x10; - else if (!(currentConfig.EmuOpt &0x80))currentConfig.EmuOpt |= 0x80; - else if ( currentConfig.EmuOpt &0x80) break; + if (inp & PBTN_LEFT) { + if ((PicoIn.opt&0x10) || !(currentConfig.EmuOpt &0x80)) { + PicoIn.opt&= ~0x10; + currentConfig.EmuOpt |= 0x80; + } } else { - if ( currentConfig.PicoOpt&0x10) break; - else if (!(currentConfig.EmuOpt &0x80))currentConfig.PicoOpt|= 0x10; - else if ( currentConfig.EmuOpt &0x80) currentConfig.EmuOpt &= ~0x80; + if (!(PicoIn.opt&0x10) || (currentConfig.EmuOpt &0x80)) { + PicoIn.opt|= 0x10; + currentConfig.EmuOpt &= ~0x80; + } } break; case MA_OPT_SOUND_QUALITY: - if ((inp & BTN_RIGHT) && currentConfig.PsndRate == 44100 && !(currentConfig.PicoOpt&0x08)) { - currentConfig.PsndRate = 8000; currentConfig.PicoOpt|= 0x08; - } else if ((inp & BTN_LEFT) && currentConfig.PsndRate == 8000 && (currentConfig.PicoOpt&0x08)) { - currentConfig.PsndRate = 44100; currentConfig.PicoOpt&=~0x08; - } else currentConfig.PsndRate = sndrate_prevnext(currentConfig.PsndRate, inp & BTN_RIGHT); + if ((inp & PBTN_RIGHT) && PsndRate == 44100 && + !(PicoIn.opt&0x08)) + { + PsndRate = 11025; + PicoIn.opt |= 8; + } else if ((inp & PBTN_LEFT) && PsndRate == 11025 && + (PicoIn.opt&0x08) && !(PicoIn.AHW&1)) + { + PsndRate = 44100; + PicoIn.opt &= ~8; + } else + PsndRate = sndrate_prevnext(PsndRate, inp & PBTN_RIGHT); break; case MA_OPT_REGION: - region_prevnext(inp & BTN_RIGHT); + region_prevnext(inp & PBTN_RIGHT); break; case MA_OPT_CONFIRM_STATES: { int n = ((currentConfig.EmuOpt>>9)&1) | ((currentConfig.EmuOpt>>10)&2); - n += (inp & BTN_LEFT) ? -1 : 1; + n += (inp & PBTN_LEFT) ? -1 : 1; if (n < 0) n = 0; else if (n > 3) n = 3; n |= n << 1; n &= ~2; currentConfig.EmuOpt &= ~0xa00; @@ -1145,7 +1200,7 @@ static int menu_loop_options(void) break; } case MA_OPT_SAVE_SLOT: - if (inp & BTN_RIGHT) { + if (inp & PBTN_RIGHT) { state_slot++; if (state_slot > 9) state_slot = 0; } else {state_slot--; if (state_slot < 0) state_slot = 9; } @@ -1153,7 +1208,7 @@ static int menu_loop_options(void) case MA_OPT_SAVECFG: case MA_OPT_SAVECFG_GAME: case MA_OPT_LOADCFG: - config_slot += (inp&BTN_RIGHT) ? 1 : -1; + config_slot += (inp&PBTN_RIGHT) ? 1 : -1; if (config_slot > 9) config_slot = 0; if (config_slot < 0) config_slot = 9; me_enable(opt_entries, OPT_ENTRY_COUNT, MA_OPT_LOADCFG, config_slot != config_slot_current); @@ -1166,7 +1221,7 @@ static int menu_loop_options(void) } } } - if (inp & BTN_PLAY) { + if (inp & PBTN_PLAY) { if (!me_process(opt_entries, OPT_ENTRY_COUNT, selected_id, 1)) { switch (selected_id) @@ -1201,7 +1256,7 @@ static int menu_loop_options(void) } } } - if(inp & (BTN_STOP|BTN_REW)) { + if(inp & (PBTN_STOP|PBTN_REW)) { menu_options_save(); return 0; // done (update, no write) } @@ -1212,24 +1267,27 @@ static int menu_loop_options(void) static void draw_menu_credits(void) { - int tl_x = 15, tl_y = 64, y; + int tl_x = 15, tl_y = 56, y; menu_draw_begin(1); - text_out16(tl_x, 20, "PicoDrive v" VERSION " (c) notaz, 2006,2007"); + text_out16(tl_x, 20, "PicoDrive v" VERSION " (c) notaz, 2006-2008"); + y = tl_y; text_out16(tl_x, y, "Credits:"); - text_out16(tl_x, (y+=10), "Dave: Cyclone 68000 core,"); + text_out16(tl_x, (y+=10), "fDave: Cyclone 68000 core,"); text_out16(tl_x, (y+=10), " base code of PicoDrive"); text_out16(tl_x, (y+=10), "Reesy & FluBBa: DrZ80 core"); text_out16(tl_x, (y+=10), "MAME devs: YM2612 and SN76496 cores"); - text_out16(tl_x, (y+=10), "Charles MacDonald: Genesis hw docs"); - text_out16(tl_x, (y+=10), "Stephane Dallongeville:"); - text_out16(tl_x, (y+=10), " opensource Gens"); - text_out16(tl_x, (y+=10), "Haze: Genesis hw info"); - text_out16(tl_x, (y+=10), "Reesy: TODO"); - text_out16(tl_x, (y+=10), "TODO: gizmondo hardware"); + text_out16(tl_x, (y+=10), "Reesy: kgsdk wrapper, sound code"); + text_out16(tl_x, (y+=10), "jens.l: gizmondo hardware"); text_out16(tl_x, (y+=10), "ketchupgun: skin design"); + text_out16(tl_x, (y+=20), "special thanks (for docs, ideas)"); + text_out16(tl_x, (y+=10), " Charles MacDonald, Haze,"); + text_out16(tl_x, (y+=10), " Stephane Dallongeville,"); + text_out16(tl_x, (y+=10), " Lordus, Exophase, Rokas,"); + text_out16(tl_x, (y+=10), " Nemesis, Tasco Deluxe"); + menu_draw_end(); } @@ -1238,16 +1296,16 @@ static void draw_menu_credits(void) menu_entry main_entries[] = { - { "Resume game", MB_NONE, MA_MAIN_RESUME_GAME, NULL, 0, 0, 0, 0 }, - { "Save State", MB_NONE, MA_MAIN_SAVE_STATE, NULL, 0, 0, 0, 0 }, - { "Load State", MB_NONE, MA_MAIN_LOAD_STATE, NULL, 0, 0, 0, 0 }, - { "Reset game", MB_NONE, MA_MAIN_RESET_GAME, NULL, 0, 0, 0, 0 }, - { "Load new ROM/ISO", MB_NONE, MA_MAIN_LOAD_ROM, NULL, 0, 0, 0, 1 }, - { "Change options", MB_NONE, MA_MAIN_OPTIONS, NULL, 0, 0, 0, 1 }, - { "Configure controls", MB_NONE, MA_MAIN_CONTROLS, NULL, 0, 0, 0, 1 }, - { "Credits", MB_NONE, MA_MAIN_CREDITS, NULL, 0, 0, 0, 1 }, - { "Patches / GameGenie",MB_NONE, MA_MAIN_PATCHES, NULL, 0, 0, 0, 0 }, - { "Exit", MB_NONE, MA_MAIN_EXIT, NULL, 0, 0, 0, 1 } + { "Resume game", MB_NONE, MA_MAIN_RESUME_GAME, NULL, 0, 0, 0, 0, 0 }, + { "Save State", MB_NONE, MA_MAIN_SAVE_STATE, NULL, 0, 0, 0, 0, 0 }, + { "Load State", MB_NONE, MA_MAIN_LOAD_STATE, NULL, 0, 0, 0, 0, 0 }, + { "Reset game", MB_NONE, MA_MAIN_RESET_GAME, NULL, 0, 0, 0, 0, 0 }, + { "Load new ROM/ISO", MB_NONE, MA_MAIN_LOAD_ROM, NULL, 0, 0, 0, 1, 0 }, + { "Change options", MB_NONE, MA_MAIN_OPTIONS, NULL, 0, 0, 0, 1, 0 }, + { "Configure controls", MB_NONE, MA_MAIN_CONTROLS, NULL, 0, 0, 0, 1, 0 }, + { "Credits", MB_NONE, MA_MAIN_CREDITS, NULL, 0, 0, 0, 1, 0 }, + { "Patches / GameGenie",MB_NONE, MA_MAIN_PATCHES, NULL, 0, 0, 0, 0, 0 }, + { "Exit", MB_NONE, MA_MAIN_EXIT, NULL, 0, 0, 0, 1, 0 } }; #define MAIN_ENTRY_COUNT (sizeof(main_entries) / sizeof(main_entries[0])) @@ -1266,7 +1324,7 @@ static void draw_menu_root(int menu_sel) // error if (menuErrorMsg[0]) { - memset((char *)giz_screen + 321*224*2, 0, 321*16*2); + memset((char *)menu_screen + 321*224*2, 0, 321*16*2); text_out16(5, 226, menuErrorMsg); } menu_draw_end(); @@ -1279,10 +1337,10 @@ static void menu_loop_root(void) int ret, menu_sel_max; unsigned long inp = 0; - me_enable(main_entries, MAIN_ENTRY_COUNT, MA_MAIN_RESUME_GAME, rom_data != NULL); - me_enable(main_entries, MAIN_ENTRY_COUNT, MA_MAIN_SAVE_STATE, rom_data != NULL); - me_enable(main_entries, MAIN_ENTRY_COUNT, MA_MAIN_LOAD_STATE, rom_data != NULL); - me_enable(main_entries, MAIN_ENTRY_COUNT, MA_MAIN_RESET_GAME, rom_data != NULL); + me_enable(main_entries, MAIN_ENTRY_COUNT, MA_MAIN_RESUME_GAME, rom_loaded); + me_enable(main_entries, MAIN_ENTRY_COUNT, MA_MAIN_SAVE_STATE, rom_loaded); + me_enable(main_entries, MAIN_ENTRY_COUNT, MA_MAIN_LOAD_STATE, rom_loaded); + me_enable(main_entries, MAIN_ENTRY_COUNT, MA_MAIN_RESET_GAME, rom_loaded); me_enable(main_entries, MAIN_ENTRY_COUNT, MA_MAIN_PATCHES, PicoPatches != NULL); menu_sel_max = me_count_enabled(main_entries, MAIN_ENTRY_COUNT) - 1; @@ -1290,33 +1348,35 @@ static void menu_loop_root(void) /* make sure action buttons are not pressed on entering menu */ draw_menu_root(menu_sel); - while (Framework_PollGetButtons(1) & (BTN_PLAY|BTN_STOP|BTN_HOME)) Sleep(50); + + while (Framework_PollGetButtons() & (PBTN_PLAY|PBTN_STOP|PBTN_HOME)) Sleep(50); for (;;) { draw_menu_root(menu_sel); - inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_PLAY|BTN_STOP|BTN_HOME|BTN_L|BTN_R); - if(inp & BTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; } - if(inp & BTN_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; } - if(inp &(BTN_HOME|BTN_STOP)){ - if (rom_data) { - while (Framework_PollGetButtons(1) & (BTN_HOME|BTN_STOP)) Sleep(50); // wait until select is released + inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_PLAY|PBTN_STOP|PBTN_HOME|PBTN_L|PBTN_R); + if(inp & PBTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; } + if(inp & PBTN_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; } + if((inp & (PBTN_L|PBTN_R)) == (PBTN_L|PBTN_R)) debug_menu_loop(); + if( inp & (PBTN_HOME|PBTN_STOP)) { + if (rom_loaded) { + while (Framework_PollGetButtons() & (PBTN_HOME|PBTN_STOP)) Sleep(50); // wait until released engineState = PGS_Running; break; } } - if(inp & BTN_PLAY) { + if(inp & PBTN_PLAY) { switch (me_index2id(main_entries, MAIN_ENTRY_COUNT, menu_sel)) { case MA_MAIN_RESUME_GAME: - if (rom_data) { - while (Framework_PollGetButtons(1) & BTN_PLAY) Sleep(50); + if (rom_loaded) { + while (Framework_PollGetButtons() & PBTN_PLAY) Sleep(50); engineState = PGS_Running; return; } break; case MA_MAIN_SAVE_STATE: - if (rom_data) { + if (rom_loaded) { if(savestate_menu_loop(0)) continue; engineState = PGS_Running; @@ -1324,16 +1384,18 @@ static void menu_loop_root(void) } break; case MA_MAIN_LOAD_STATE: - if (rom_data) { + if (rom_loaded) { if(savestate_menu_loop(1)) continue; + while (Framework_PollGetButtons() & PBTN_PLAY) Sleep(50); engineState = PGS_Running; return; } break; case MA_MAIN_RESET_GAME: - if (rom_data) { + if (rom_loaded) { emu_ResetGame(); + while (Framework_PollGetButtons() & PBTN_PLAY) Sleep(50); engineState = PGS_Running; return; } @@ -1342,10 +1404,10 @@ static void menu_loop_root(void) { char curr_path[MAX_PATH], *selfname; FILE *tstf; - if ( (tstf = fopen(currentConfig.lastRomFile, "rb")) ) + if ( (tstf = fopen(loadedRomFName, "rb")) ) { fclose(tstf); - strcpy(curr_path, currentConfig.lastRomFile); + strcpy(curr_path, loadedRomFName); } else getcwd(curr_path, MAX_PATH); @@ -1369,13 +1431,13 @@ static void menu_loop_root(void) case MA_MAIN_CREDITS: draw_menu_credits(); Sleep(500); - inp = wait_for_input(BTN_PLAY|BTN_STOP); + inp = in_menu_wait(PBTN_PLAY|PBTN_STOP); break; case MA_MAIN_EXIT: engineState = PGS_Quit; return; case MA_MAIN_PATCHES: - if (rom_data && PicoPatches) { + if (rom_loaded && PicoPatches) { patches_menu_loop(); PicoPatchApply(); strcpy(menuErrorMsg, "Patches applied"); @@ -1392,7 +1454,7 @@ static void menu_loop_root(void) } // warning: alignment -static void menu_darken_bg(void *dst, const void *src, int pixels, int darker) +void menu_darken_bg(void *dst, const void *src, int pixels, int darker) { unsigned int *dest = dst; const unsigned int *srce = src; @@ -1420,20 +1482,28 @@ static void menu_prepare_bg(int use_game_bg) if (use_game_bg) { // darken the active framebuffer + if (giz_screen == NULL) + giz_screen = fb_lock(1); memset(bg_buffer, 0, 321*8*2); menu_darken_bg(bg_buffer + 321*8*2, (char *)giz_screen + 321*8*2, 321*224, 1); memset(bg_buffer + 321*232*2, 0, 321*8*2); + fb_unlock(); + giz_screen = NULL; } else { + int i; // should really only happen once, on startup.. readpng(bg_buffer, "skin/background.png", READPNG_BG); + // adjust 320 width to 321 + for (i = 239; i > 0; i--) + memmove(bg_buffer + 321*2*i, bg_buffer + 320*2*i, 320*2); } } static void menu_gfx_prepare(void) { - menu_prepare_bg(rom_data != NULL); + menu_prepare_bg(rom_loaded); menu_draw_begin(1); menu_draw_end(); @@ -1482,10 +1552,10 @@ int menu_loop_tray(void) menu_gfx_prepare(); - if ( (tstf = fopen(currentConfig.lastRomFile, "rb")) ) + if ( (tstf = fopen(loadedRomFName, "rb")) ) { fclose(tstf); - strcpy(curr_path, currentConfig.lastRomFile); + strcpy(curr_path, loadedRomFName); } else { @@ -1494,23 +1564,24 @@ int menu_loop_tray(void) /* make sure action buttons are not pressed on entering menu */ draw_menu_tray(menu_sel); - while (Framework_PollGetButtons(1) & BTN_PLAY) Sleep(50); + while (Framework_PollGetButtons() & PBTN_PLAY) Sleep(50); for (;;) { draw_menu_tray(menu_sel); - inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_PLAY); - if(inp & BTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; } - if(inp & BTN_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; } - if(inp & BTN_PLAY ) { + inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_PLAY); + if(inp & PBTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; } + if(inp & PBTN_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; } + if(inp & PBTN_PLAY) { switch (menu_sel) { case 0: // select image selfname = romsel_loop(curr_path); if (selfname) { - int ret = -1, cd_type; - cd_type = emu_cd_check(NULL); - if (cd_type > 0) - ret = Insert_CD(romFileName, cd_type == 2); + int ret = -1; + cd_img_type cd_type; + cd_type = emu_cdCheck(NULL, romFileName); + if (cd_type != CIT_NOT_CD) + ret = Insert_CD(romFileName, cd_type); if (ret != 0) { sprintf(menuErrorMsg, "Load failed, invalid CD image?"); lprintf("%s\n", menuErrorMsg);