From 1ca2ea4f60d990a4240a387fdde78a87f77f30f1 Mon Sep 17 00:00:00 2001 From: notaz Date: Mon, 24 Mar 2008 23:11:47 +0000 Subject: [PATCH] bugfixes, new config system and messed code for it git-svn-id: file:///home/notaz/opt/svn/PicoDrive@393 be3aeb3a-fb24-0410-a615-afba39da0efa --- Pico/Cart.c | 10 +- Pico/carthw/svp/compiler.c | 48 ++++---- Pico/carthw/svp/compiler.h | 10 +- Pico/carthw/svp/stub_arm.S | 15 ++- Pico/carthw/svp/svp.c | 19 +-- platform/common/config.c | 229 +++++++++++++++++++++++++++++++------ platform/common/config.h | 4 +- platform/common/emu.c | 53 ++++----- platform/common/emu.h | 4 +- platform/common/menu.c | 18 +++ platform/common/menu.h | 13 ++- platform/gizmondo/menu.c | 30 +---- platform/gp2x/emu.c | 5 +- platform/gp2x/main.c | 1 + platform/gp2x/menu.c | 59 ++++------ platform/psp/menu.c | 26 +---- 16 files changed, 352 insertions(+), 192 deletions(-) diff --git a/Pico/Cart.c b/Pico/Cart.c index 4b94b478..25bb9610 100644 --- a/Pico/Cart.c +++ b/Pico/Cart.c @@ -655,17 +655,17 @@ void PicoCartDetect(void) } // Detect 12-in-1 mapper - else if ((name_cmp("ROBOCOP 3") && Pico.romsize == 0x200000) || - (rom_strcmp(0x160, "FLICKY") && Pico.romsize >= 0x200000)) + else if ((name_cmp("ROBOCOP 3") == 0 && Pico.romsize == 0x200000) || + (rom_strcmp(0x160, "FLICKY") == 0 && Pico.romsize >= 0x200000)) { carthw_12in1_startup(); } // Realtec mapper else if (Pico.romsize == 512*1024 && ( - rom_strcmp(0x94, "THE EARTH DEFEND") || - rom_strcmp(0xfe, "WISEGAME 11-03-1993") || // Funny World - rom_strcmp(0x95, "MALLET LEGEND "))) // Whac-A-Critter + rom_strcmp(0x94, "THE EARTH DEFEND") == 0 || + rom_strcmp(0xfe, "WISEGAME 11-03-1993") == 0 || // Funny World + rom_strcmp(0x95, "MALLET LEGEND ") == 0)) // Whac-A-Critter { carthw_realtec_startup(); } diff --git a/Pico/carthw/svp/compiler.c b/Pico/carthw/svp/compiler.c index dc053d44..f8bece39 100644 --- a/Pico/carthw/svp/compiler.c +++ b/Pico/carthw/svp/compiler.c @@ -4,8 +4,6 @@ #define u32 unsigned int -static u32 *block_table[0x5090/2]; -static u32 *block_table_iram[15][0x800/2]; static u32 *tcache_ptr = NULL; static int nblocks = 0; @@ -21,7 +19,9 @@ extern ssp1601_t *ssp; #ifndef ARM #define DUMP_BLOCK 0x0c9a -unsigned int tcache[512*1024]; +u32 *ssp_block_table[0x5090/2]; +u32 *ssp_block_table_iram[15][0x800/2]; +u32 tcache[SSP_TCACHE_SIZE/4]; void ssp_drc_next(void){} void ssp_drc_next_patch(void){} void ssp_drc_end(void){} @@ -1676,7 +1676,7 @@ static void emit_block_epilogue(int cycles, int cond, int pc, int end_pc) emit_jump(A_COND_AL, ssp_drc_next); } else if (cond == A_COND_AL) { - u32 *target = (pc < 0x400) ? block_table_iram[ssp->drc.iram_context][pc] : block_table[pc]; + u32 *target = (pc < 0x400) ? ssp_block_table_iram[ssp->drc.iram_context][pc] : ssp_block_table[pc]; if (target != NULL) emit_jump(A_COND_AL, target); else { @@ -1686,8 +1686,8 @@ static void emit_block_epilogue(int cycles, int cond, int pc, int end_pc) } } else { - u32 *target1 = (pc < 0x400) ? block_table_iram[ssp->drc.iram_context][pc] : block_table[pc]; - u32 *target2 = (end_pc < 0x400) ? block_table_iram[ssp->drc.iram_context][end_pc] : block_table[end_pc]; + u32 *target1 = (pc < 0x400) ? ssp_block_table_iram[ssp->drc.iram_context][pc] : ssp_block_table[pc]; + u32 *target2 = (end_pc < 0x400) ? ssp_block_table_iram[ssp->drc.iram_context][end_pc] : ssp_block_table[end_pc]; if (target1 != NULL) emit_jump(cond, target1); else emit_call(cond, ssp_drc_next_patch); @@ -1743,7 +1743,7 @@ void *ssp_translate_block(int pc) tr_flush_dirty_pmcrs(); emit_block_epilogue(ccount, end_cond, jump_pc, pc); - if (tcache_ptr - tcache > TCACHE_SIZE/4) { + if (tcache_ptr - tcache > SSP_TCACHE_SIZE/4) { printf("tcache overflow!\n"); fflush(stdout); exit(1); @@ -1780,9 +1780,9 @@ static void ssp1601_state_load(void) int ssp1601_dyn_startup(void) { - memset(tcache, 0, TCACHE_SIZE); - memset(block_table, 0, sizeof(block_table)); - memset(block_table_iram, 0, sizeof(block_table_iram)); + memset(tcache, 0, SSP_TCACHE_SIZE); + memset(ssp_block_table, 0, sizeof(ssp_block_table)); + memset(ssp_block_table_iram, 0, sizeof(ssp_block_table_iram)); tcache_ptr = tcache; PicoLoadStateHook = ssp1601_state_load; @@ -1790,14 +1790,14 @@ int ssp1601_dyn_startup(void) n_in_ops = 0; #ifdef ARM // hle'd blocks - block_table[0x800/2] = (void *) ssp_hle_800; - block_table[0x902/2] = (void *) ssp_hle_902; - block_table_iram[ 7][0x030/2] = (void *) ssp_hle_07_030; - block_table_iram[ 7][0x036/2] = (void *) ssp_hle_07_036; - block_table_iram[ 7][0x6d6/2] = (void *) ssp_hle_07_6d6; - block_table_iram[11][0x12c/2] = (void *) ssp_hle_11_12c; - block_table_iram[11][0x384/2] = (void *) ssp_hle_11_384; - block_table_iram[11][0x38a/2] = (void *) ssp_hle_11_38a; + ssp_block_table[0x800/2] = (void *) ssp_hle_800; + ssp_block_table[0x902/2] = (void *) ssp_hle_902; + ssp_block_table_iram[ 7][0x030/2] = (void *) ssp_hle_07_030; + ssp_block_table_iram[ 7][0x036/2] = (void *) ssp_hle_07_036; + ssp_block_table_iram[ 7][0x6d6/2] = (void *) ssp_hle_07_6d6; + ssp_block_table_iram[11][0x12c/2] = (void *) ssp_hle_11_12c; + ssp_block_table_iram[11][0x384/2] = (void *) ssp_hle_11_384; + ssp_block_table_iram[11][0x38a/2] = (void *) ssp_hle_11_38a; #endif return 0; @@ -1814,12 +1814,12 @@ void ssp1601_dyn_reset(ssp1601_t *ssp) fclose(f); for (i = 0; i < 0x5090/2; i++) - if (block_table[i]) - printf("%06x -> __:%04x\n", (block_table[i] - tcache)*4, i<<1); + if (ssp_block_table[i]) + printf("%06x -> __:%04x\n", (ssp_block_table[i] - tcache)*4, i<<1); for (u = 1; u < 15; u++) for (i = 0; i < 0x800/2; i++) - if (block_table_iram[u][i]) - printf("%06x -> %02i:%04x\n", (block_table_iram[u][i] - tcache)*4, u, i<<1); + if (ssp_block_table_iram[u][i]) + printf("%06x -> %02i:%04x\n", (ssp_block_table_iram[u][i] - tcache)*4, u, i<<1); } ssp1601_reset(ssp); @@ -1829,8 +1829,8 @@ void ssp1601_dyn_reset(ssp1601_t *ssp) ssp->drc.ptr_rom = (u32) Pico.rom; ssp->drc.ptr_iram_rom = (u32) svp->iram_rom; ssp->drc.ptr_dram = (u32) svp->dram; - ssp->drc.ptr_btable = (u32) block_table; - ssp->drc.ptr_btable_iram = (u32) block_table_iram; + ssp->drc.ptr_btable = (u32) ssp_block_table; + ssp->drc.ptr_btable_iram = (u32) ssp_block_table_iram; // prevent new versions of IRAM from appearing memset(svp->iram_rom, 0, 0x800); diff --git a/Pico/carthw/svp/compiler.h b/Pico/carthw/svp/compiler.h index 2e4b2727..f2d51feb 100644 --- a/Pico/carthw/svp/compiler.h +++ b/Pico/carthw/svp/compiler.h @@ -1,6 +1,12 @@ -#define TCACHE_SIZE (1024*1024) +#define SSP_TCACHE_SIZE (512*1024) +#define SSP_BLOCKTAB_SIZE (0x5090/2*4) +#define SSP_BLOCKTAB_IRAM_SIZE (15*0x800/2*4) +#define SSP_BLOCKTAB_ALIGN_SIZE 3808 +#define SSP_DRC_SIZE (SSP_TCACHE_SIZE + SSP_BLOCKTAB_SIZE + SSP_BLOCKTAB_IRAM_SIZE + SSP_BLOCKTAB_ALIGN_SIZE) -extern unsigned int tcache[]; +extern unsigned int tcache[SSP_TCACHE_SIZE/4]; +extern unsigned int *ssp_block_table[0x5090/2]; +extern unsigned int *ssp_block_table_iram[15][0x800/2]; int ssp_drc_entry(int cycles); void ssp_drc_next(void); diff --git a/Pico/carthw/svp/stub_arm.S b/Pico/carthw/svp/stub_arm.S index 245c1079..cbfa52eb 100644 --- a/Pico/carthw/svp/stub_arm.S +++ b/Pico/carthw/svp/stub_arm.S @@ -5,6 +5,8 @@ .endif .global tcache +.global ssp_block_table +.global ssp_block_table_iram .global flush_inval_caches .global ssp_drc_entry @@ -20,12 +22,19 @@ .global ssp_hle_11_384 .global ssp_hle_11_38a -@ translation cache buffer +@ translation cache buffer + pointer table .text .align 12 @ 4096 -.size tcache, TCACHE_SIZE +.size tcache, SSP_TCACHE_SIZE +.size ssp_block_table, SSP_BLOCKTAB_SIZE +.size ssp_block_table_iram, SSP_BLOCKTAB_IRAM_SIZE tcache: - .space TCACHE_SIZE + .space SSP_TCACHE_SIZE +ssp_block_table: + .space SSP_BLOCKTAB_SIZE +ssp_block_table_iram: + .space SSP_BLOCKTAB_IRAM_SIZE + .space SSP_BLOCKTAB_ALIGN_SIZE .text diff --git a/Pico/carthw/svp/svp.c b/Pico/carthw/svp/svp.c index 4b960418..c7b6551c 100644 --- a/Pico/carthw/svp/svp.c +++ b/Pico/carthw/svp/svp.c @@ -14,6 +14,7 @@ svp_t *svp = NULL; int PicoSVPCycles = 820; // cycles/line, just a guess +static int svp_dyn_ready = 0; /* save state stuff */ typedef enum { @@ -37,17 +38,17 @@ static void PicoSVPReset(void) memcpy(svp->iram_rom + 0x800, Pico.rom + 0x800, 0x20000 - 0x800); ssp1601_reset(&svp->ssp1601); - if (!(PicoOpt&0x20000)) + if ((PicoOpt&0x20000) && svp_dyn_ready) ssp1601_dyn_reset(&svp->ssp1601); } static void PicoSVPLine(int count) { - if (PicoOpt&0x20000) - ssp1601_run(PicoSVPCycles * count); - else + if ((PicoOpt&0x20000) && svp_dyn_ready) ssp1601_dyn_run(PicoSVPCycles * count); + else + ssp1601_run(PicoSVPCycles * count); // test mode //if (Pico.m.frame_count == 13) PicoPad[0] |= 0xff; @@ -83,7 +84,7 @@ void PicoSVPInit(void) { #ifdef __GP2X__ int ret; - ret = munmap(tcache, TCACHE_SIZE); + ret = munmap(tcache, SSP_DRC_SIZE); printf("munmap tcache: %i\n", ret); #endif } @@ -111,19 +112,21 @@ void PicoSVPStartup(void) return; } - //PicoOpt |= 0x20000; + //PicoOpt &= ~0x20000; Pico.rom = tmp; svp = (void *) ((char *)tmp + 0x200000); memset(svp, 0, sizeof(*svp)); #ifdef __GP2X__ - tmp = mmap(tcache, TCACHE_SIZE, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_SHARED|MAP_ANONYMOUS, -1, 0); + tmp = mmap(tcache, SSP_DRC_SIZE, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_SHARED|MAP_ANONYMOUS, -1, 0); printf("mmap tcache: %p, asked %p\n", tmp, tcache); #endif // init SVP compiler - if (!(PicoOpt&0x20000)) { + svp_dyn_ready = 0; + if (PicoOpt&0x20000) { if (ssp1601_dyn_startup()) return; + svp_dyn_ready = 1; } // init ok, setup hooks.. diff --git a/platform/common/config.c b/platform/common/config.c index 2f987e81..534fb400 100644 --- a/platform/common/config.c +++ b/platform/common/config.c @@ -24,6 +24,21 @@ static const int *cfg_opt_counts[] = { &opt_entry_count, &opt2_entry_count, &cdo #define NL "\n" +static void mystrip(char *str) +{ + int i, len; + + len = strlen(str); + for (i = 0; i < len; i++) + if (str[i] != ' ') break; + if (i > 0) memmove(str, str + i, len - i + 1); + len = strlen(str); + for (i = len - 1; i >= 0; i--) + if (str[i] != ' ') break; + str[i+1] = 0; +} + + static int seek_sect(FILE *f, const char *section) { char line[128], *tmp; @@ -126,6 +141,52 @@ static void custom_write(FILE *f, const menu_entry *me, int no_def) fprintf(f, NL); } + +static const char *joyKeyNames[32] = +{ + "UP", "DOWN", "LEFT", "RIGHT", "b1", "b2", "b3", "b4", + "b5", "b6", "b7", "b8", "b9", "b10", "b11", "b12", + "b13", "b14", "b15", "b16", "b17", "b19", "b19", "b20", + "b21", "b22", "b23", "b24", "b25", "b26", "b27", "b28" +}; + +static void keys_write(FILE *fn, const char *bind_str, const int binds[32], + const int def_binds[32], const char *names[32], int no_defaults) +{ + int t, i; + char act[48]; + + for (t = 0; t < 32; t++) + { + act[0] = act[31] = 0; + if (no_defaults && binds[t] == def_binds[t]) + continue; + if (strcmp(names[t], "???") == 0) continue; +#ifdef __GP2X__ + if (strcmp(names[t], "SELECT") == 0) continue; +#endif + for (i = 0; i < sizeof(me_ctrl_actions) / sizeof(me_ctrl_actions[0]); i++) { + if (me_ctrl_actions[i].mask & binds[t]) { + sprintf(act, "player%i ", ((binds[t]>>16)&1)+1); + strncpy(act + 8, me_ctrl_actions[i].name, 31); + break; + } + } + if (act[0] == 0) + { + for (i = 0; emuctrl_actions[i].name != NULL; i++) + if (emuctrl_actions[i].mask & binds[t]) { + strncpy(act, emuctrl_actions[i].name, 31); + break; + } + } + mystrip(act); + + fprintf(fn, "%s %s = %s" NL, bind_str, names[t], act); + } +} + + static int default_var(const menu_entry *me) { switch (me->id) @@ -137,6 +198,7 @@ static int default_var(const menu_entry *me) case MA_OPT2_ENABLE_Z80: case MA_OPT2_ENABLE_YM2612: case MA_OPT2_ENABLE_SN76496: + case MA_OPT2_SVP_DYNAREC: case MA_CDOPT_CDDA: case MA_CDOPT_PCM: case MA_CDOPT_SAVERAM: @@ -253,6 +315,14 @@ write: } } } + + // save key config + keys_write(fn, "bind", currentConfig.KeyBinds, defaultConfig.KeyBinds, keyNames, no_defaults); + keys_write(fn, "bind_joy0", currentConfig.JoyBinds[0], defaultConfig.JoyBinds[0], joyKeyNames, 1); + keys_write(fn, "bind_joy1", currentConfig.JoyBinds[1], defaultConfig.JoyBinds[1], joyKeyNames, 1); + keys_write(fn, "bind_joy2", currentConfig.JoyBinds[2], defaultConfig.JoyBinds[2], joyKeyNames, 1); + keys_write(fn, "bind_joy3", currentConfig.JoyBinds[3], defaultConfig.JoyBinds[3], joyKeyNames, 1); + fprintf(fn, NL); if (fo != NULL) @@ -274,21 +344,6 @@ write: } -static void mystrip(char *str) -{ - int i, len; - - len = strlen(str); - for (i = 0; i < len; i++) - if (str[i] != ' ') break; - if (i > 0) memmove(str, str + i, len - i + 1); - len = strlen(str); - for (i = len - 1; i >= 0; i--) - if (str[i] != ' ') break; - str[i+1] = 0; -} - - int config_writelrom(const char *fname) { char line[128], *tmp, *optr = NULL; @@ -296,7 +351,7 @@ int config_writelrom(const char *fname) int size; FILE *f; - if (strlen(currentConfig.lastRomFile) == 0) return 0; + if (strlen(lastRomFile) == 0) return 0; f = fopen(fname, "r"); if (f != NULL) @@ -329,11 +384,47 @@ int config_writelrom(const char *fname) fwrite(old_data, 1, optr - old_data, f); free(old_data); } - fprintf(f, "LastUsedROM = %s" NL, currentConfig.lastRomFile); + fprintf(f, "LastUsedROM = %s" NL, lastRomFile); fclose(f); return 0; } +/* --------------------------------------------------------------------------*/ + +int config_readlrom(const char *fname) +{ + char line[128], *tmp; + int i, len, ret = -1; + FILE *f; + + f = fopen(fname, "r"); + if (f == NULL) return -1; + + // seek to the section needed + while (!feof(f)) + { + tmp = fgets(line, sizeof(line), f); + if (tmp == NULL) break; + + if (strncasecmp(line, "LastUsedROM", 11) != 0) continue; + len = strlen(line); + for (i = 0; i < len; i++) + if (line[i] == '#' || line[i] == '\r' || line[i] == '\n') { line[i] = 0; break; } + tmp = strchr(line, '='); + if (tmp == NULL) break; + tmp++; + mystrip(tmp); + + len = sizeof(lastRomFile); + strncpy(lastRomFile, tmp, len); + lastRomFile[len-1] = 0; + ret = 0; + break; + } + fclose(f); + return ret; +} + static int custom_read(menu_entry *me, const char *var, const char *val) { @@ -432,16 +523,16 @@ static int custom_read(menu_entry *me, const char *var, const char *val) case MA_OPT_CONFIRM_STATES: if (strcasecmp(var, "Confirm savestate") != 0) return 0; if (strcasecmp(val, "OFF") == 0) { - currentConfig.EmuOpt &= 5<<9; + currentConfig.EmuOpt &= ~(5<<9); } else if (strcasecmp(val, "writes") == 0) { - currentConfig.EmuOpt &= 5<<9; - currentConfig.EmuOpt |= 1<<9; + currentConfig.EmuOpt &= ~(5<<9); + currentConfig.EmuOpt |= 1<<9; } else if (strcasecmp(val, "loads") == 0) { - currentConfig.EmuOpt &= 5<<9; - currentConfig.EmuOpt |= 4<<9; + currentConfig.EmuOpt &= ~(5<<9); + currentConfig.EmuOpt |= 4<<9; } else if (strcasecmp(val, "both") == 0) { - currentConfig.EmuOpt &= 5<<9; - currentConfig.EmuOpt |= 5<<9; + currentConfig.EmuOpt &= ~(5<<9); + currentConfig.EmuOpt |= 5<<9; } else return 0; return 1; @@ -469,23 +560,82 @@ static int custom_read(menu_entry *me, const char *var, const char *val) return 1; default: - if (strcasecmp(var, "LastUsedROM") == 0) { - tmpi = sizeof(currentConfig.lastRomFile); - strncpy(currentConfig.lastRomFile, val, tmpi); - currentConfig.lastRomFile[tmpi-1] = 0; - return 1; - } lprintf("unhandled custom_read: %i\n", me->id); return 0; } } +static void keys_parse(const char *var, const char *val, int binds[32], const char *names[32]) +{ + int t, i, keys_encountered = 0; + unsigned int player; + + for (t = 0; t < 32; t++) + { + if (strcmp(names[t], var) == 0) break; + } + if (t == 32) { + lprintf("unhandled bind \"%s\"\n", var); + return; + } + + if (!(keys_encountered & (1< 1) goto fail; + for (i = 0; i < sizeof(me_ctrl_actions) / sizeof(me_ctrl_actions[0]); i++) { + if (strncasecmp(me_ctrl_actions[i].name, val + 8, strlen(val + 8)) == 0) { + binds[t] |= me_ctrl_actions[i].mask | (player<<16); + return; + } + } + } + for (i = 0; emuctrl_actions[i].name != NULL; i++) { + if (strncasecmp(emuctrl_actions[i].name, val, strlen(val)) == 0) { + binds[t] |= emuctrl_actions[i].mask; + return; + } + } + +fail: + lprintf("unhandled action \"%s\"\n", val); + return; + +} + + +#define try_joy_parse(num) { \ + if (strncasecmp(var, "bind_joy"#num " ", 10) == 0) { \ + keys_parse(var + 10, val, currentConfig.JoyBinds[num], joyKeyNames); \ + return; \ + } \ +} + static void parse(const char *var, const char *val) { menu_entry *me; int t, i, tlen, tmp, ret = 0; + if (strcasecmp(var, "LastUsedROM") == 0) + return; /* handled elsewhere */ + + // key binds + if (strncasecmp(var, "bind ", 5) == 0) { + keys_parse(var + 5, val, currentConfig.KeyBinds, keyNames); + return; + } + try_joy_parse(0) + try_joy_parse(1) + try_joy_parse(2) + try_joy_parse(3) + for (t = 0; t < sizeof(cfg_opts) / sizeof(cfg_opts[0]) && ret == 0; t++) { me = cfg_opts[t]; @@ -515,12 +665,27 @@ static void parse(const char *var, const char *val) } +int config_havesect(const char *fname, const char *section) +{ + FILE *f; + int ret; + + f = fopen(fname, "r"); + if (f == NULL) return 0; + + ret = seek_sect(f, section); + fclose(f); + return ret; +} + + int config_readsect(const char *fname, const char *section) { char line[128], *var, *val, *tmp; - FILE *f = fopen(fname, "r"); int len, i, ret; + FILE *f; + f = fopen(fname, "r"); if (f == NULL) return 0; if (section != NULL) @@ -560,7 +725,7 @@ int config_readsect(const char *fname, const char *section) val = &line[i+1]; mystrip(var); mystrip(val); - if (strlen(var) == 0 || strlen(val) == 0) { + if (strlen(var) == 0 || (strlen(val) == 0 && strncasecmp(var, "bind", 4) != 0)) { lprintf("config_readsect: something's empty: \"%s\" = \"%s\"\n", var, val); continue; } diff --git a/platform/common/config.h b/platform/common/config.h index 8fab6d4a..2d8a3032 100644 --- a/platform/common/config.h +++ b/platform/common/config.h @@ -1,6 +1,6 @@ -#include - int config_writesect(const char *fname, const char *section); int config_writelrom(const char *fname); int config_readsect(const char *fname, const char *section); +int config_readlrom(const char *fname); +int config_havesect(const char *fname, const char *section); diff --git a/platform/common/emu.c b/platform/common/emu.c index 9d573bf3..936665b5 100644 --- a/platform/common/emu.c +++ b/platform/common/emu.c @@ -40,6 +40,7 @@ int rom_loaded = 0; char noticeMsg[64]; int state_slot = 0; int config_slot = 0, config_slot_current = 0; +char lastRomFile[512]; unsigned char *movie_data = NULL; static int movie_size = 0; @@ -139,6 +140,7 @@ int emu_findBios(int region, char **bios_file) } /* check if the name begins with BIOS name */ +/* static int emu_isBios(const char *name) { int i; @@ -150,8 +152,9 @@ static int emu_isBios(const char *name) if (strstr(name, biosfiles_jp[i]) != NULL) return 1; return 0; } +*/ -static unsigned char scd_id_header[0x100]; +static unsigned char id_header[0x100]; /* checks if romFileName points to valid MegaCD image * if so, checks for suitable BIOS */ @@ -177,7 +180,7 @@ int emu_cdCheck(int *pregion) } pm_seek(cd_f, (type == 1) ? 0x100 : 0x110, SEEK_SET); - pm_read(scd_id_header, sizeof(scd_id_header), cd_f); + pm_read(id_header, sizeof(id_header), cd_f); /* it seems we have a CD image here. Try to detect region now.. */ pm_seek(cd_f, (type == 1) ? 0x100+0x10B : 0x110+0x10B, SEEK_SET); @@ -229,21 +232,11 @@ static int extract_text(char *dest, unsigned char *src, int len, int swab) char *emu_makeRomId(void) { static char id_string[3+0x11+0x11+0x30+16]; - unsigned char *id_header; int pos; - if (Pico.rom == NULL) { - id_string[0] = 0; - return id_string; - } - - if (PicoMCD & 1) { - id_header = scd_id_header; - strcpy(id_string, "CD|"); - } else { - id_header = Pico.rom + 0x100; - strcpy(id_string, "MD|"); - } + if (PicoMCD & 1) + strcpy(id_string, "CD|"); + else strcpy(id_string, "MD|"); pos = 3; pos += extract_text(id_string + pos, id_header + 0x80, 0x0e, 1); // serial @@ -253,7 +246,6 @@ char *emu_makeRomId(void) pos += extract_text(id_string + pos, id_header + 0x50, 0x30, 1); // overseas name id_string[pos] = 0; - printf("id_string: %s\n", id_string); return id_string; } @@ -391,6 +383,8 @@ int emu_ReloadRom(void) } // load config for this ROM (do this before insert to get correct region) + if (!(PicoMCD&1)) + memcpy(id_header, rom_data + 0x100, sizeof(id_header)); if (!cfg_loaded) { ret = emu_ReadConfig(1, 1); if (!ret) emu_ReadConfig(0, 1); @@ -418,13 +412,6 @@ int emu_ReloadRom(void) menu_romload_end(); - if (!emu_isBios(romFileName)) - { - // emu_ReadConfig() might have messed currentConfig.lastRomFile - strncpy(currentConfig.lastRomFile, romFileName, sizeof(currentConfig.lastRomFile)-1); - currentConfig.lastRomFile[sizeof(currentConfig.lastRomFile)-1] = 0; - } - if (PicoPatches) { PicoPatchPrepare(); PicoPatchApply(); @@ -463,6 +450,8 @@ int emu_ReloadRom(void) if (currentConfig.EmuOpt & 1) emu_SaveLoadGame(1, 1); + strncpy(lastRomFile, romFileName, sizeof(lastRomFile)-1); + lastRomFile[sizeof(lastRomFile)-1] = 0; rom_loaded = 1; return 1; } @@ -509,14 +498,18 @@ int emu_ReadConfig(int game, int no_defaults) } else { - if (!no_defaults) - emu_setDefaultConfig(); + char *sect = emu_makeRomId(); // try new .cfg way if (config_slot != 0) sprintf(cfg, "game.%i.cfg", config_slot); else strcpy(cfg, "game.cfg"); - ret = config_readsect(cfg, emu_makeRomId()); + + ret = -1; + if (config_havesect(cfg, sect)) { + emu_setDefaultConfig(); + ret = config_readsect(cfg, sect); + } if (ret != 0) { @@ -532,7 +525,9 @@ int emu_ReadConfig(int game, int no_defaults) f = fopen(cfg, "rb"); } if (f) { - int bread = fread(¤tConfig, 1, sizeof(currentConfig), f); + int bread; + fseek(f, 512, SEEK_SET); // skip unused lrom buffer + bread = fread(¤tConfig, 1, sizeof(currentConfig), f); lprintf("emu_ReadConfig: %s %s\n", cfg, bread > 0 ? "(ok)" : "(failed)"); fclose(f); ret = 0; @@ -548,7 +543,7 @@ int emu_ReadConfig(int game, int no_defaults) } else { - lprintf("loaded cf from game sect\n"); + lprintf("loaded cfg from sect \"%s\"\n", sect); } } @@ -593,10 +588,12 @@ int emu_WriteConfig(int is_game) sprintf(cfg, "game.%i.cfg", config_slot); else strcpy(cfg, "game.cfg"); game_sect = emu_makeRomId(); + lprintf("emu_WriteConfig: sect \"%s\"\n", game_sect); } lprintf("emu_WriteConfig: %s ", cfg); ret = config_writesect(cfg, game_sect); + if (write_lrom) config_writelrom(cfg); #ifndef NO_SYNC sync(); #endif diff --git a/platform/common/emu.h b/platform/common/emu.h index 484080a4..93a88233 100644 --- a/platform/common/emu.h +++ b/platform/common/emu.h @@ -4,7 +4,7 @@ // For commercial use, separate licencing terms must be obtained. typedef struct { - char lastRomFile[512]; + // char lastRomFile[512]; int EmuOpt; // LSb->MSb: use_sram, show_fps, enable_sound, gzip_saves, // squidgehack, no_save_cfg_on_exit, , 16_bit_mode // craigix_ram, confirm_save, show_cd_leds, confirm_load @@ -33,6 +33,7 @@ extern char noticeMsg[64]; extern int state_slot; extern int config_slot, config_slot_current; extern unsigned char *movie_data; +extern char lastRomFile[512]; int emu_ReloadRom(void); @@ -49,4 +50,5 @@ void emu_textOut8 (int x, int y, const char *text); void emu_textOut16(int x, int y, const char *text); char *emu_makeRomId(void); +extern const char *keyNames[]; void emu_prepareDefaultConfig(void); diff --git a/platform/common/menu.c b/platform/common/menu.c index 16d4342d..359517a8 100644 --- a/platform/common/menu.c +++ b/platform/common/menu.c @@ -30,6 +30,24 @@ char menuErrorMsg[64] = { 0, }; +// PicoPad[] format: MXYZ SACB RLDU +me_bind_action me_ctrl_actions[12] = +{ + { "UP ", 0x001 }, + { "DOWN ", 0x002 }, + { "LEFT ", 0x004 }, + { "RIGHT ", 0x008 }, + { "A ", 0x040 }, + { "B ", 0x010 }, + { "C ", 0x020 }, + { "START ", 0x080 }, + { "MODE ", 0x800 }, + { "X ", 0x400 }, + { "Y ", 0x200 }, + { "Z ", 0x100 } +}; + + static unsigned char menu_font_data[10240]; static int menu_text_color = 0xffff; // default to white static int menu_sel_color = -1; // disabled diff --git a/platform/common/menu.h b/platform/common/menu.h index 0b5aac30..1a4ded2e 100644 --- a/platform/common/menu.h +++ b/platform/common/menu.h @@ -1,4 +1,4 @@ -// (c) Copyright 2006,2007 notaz, All rights reserved. +// (c) Copyright 2006-2008 notaz, All rights reserved. void menu_init(void); @@ -9,7 +9,6 @@ void menu_draw_selection(int x, int y, int w); extern char menuErrorMsg[64]; - typedef enum { MB_NONE = 1, /* no auto processing */ @@ -65,6 +64,7 @@ typedef enum MA_OPT2_SQUIDGEHACK, /* gp2x */ MA_OPT2_STATUS_LINE, /* psp */ MA_OPT2_NO_FRAME_LIMIT, /* psp */ + MA_OPT2_SVP_DYNAREC, MA_OPT2_DONE, MA_OPT3_SCALE, /* psp (all OPT3) */ MA_OPT3_HSCALE32, @@ -102,6 +102,15 @@ typedef struct char need_to_save; } menu_entry; +typedef struct +{ + char *name; + int mask; +} me_bind_action; + +extern me_bind_action me_ctrl_actions[12]; +extern me_bind_action emuctrl_actions[]; // platform code + typedef void (me_draw_custom_f)(const menu_entry *entry, int x, int y, void *param); diff --git a/platform/gizmondo/menu.c b/platform/gizmondo/menu.c index 09520a98..ce8e92f9 100644 --- a/platform/gizmondo/menu.c +++ b/platform/gizmondo/menu.c @@ -687,9 +687,7 @@ static int count_bound_keys(int action, int pl_idx) 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; @@ -723,7 +721,7 @@ static void draw_key_config(const bind_action_t *opts, int opt_cnt, int player_i 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; @@ -777,27 +775,10 @@ static void draw_kc_sel(int menu_sel) } -// 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 }, @@ -806,6 +787,7 @@ static bind_action_t emuctrl_actions[] = { "Switch Renderer", 1<<26 }, { "Volume Down ", 1<<30 }, { "Volume Up ", 1<<29 }, + { NULL, 0 } }; static void kc_sel_loop(void) @@ -822,8 +804,8 @@ static void kc_sel_loop(void) 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 0: key_config_loop(me_ctrl_actions, is_6button ? 12 : 8, 0); return; + case 1: key_config_loop(me_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_loaded) emu_WriteConfig(0); return; diff --git a/platform/gp2x/emu.c b/platform/gp2x/emu.c index bd4253d3..74bcde89 100644 --- a/platform/gp2x/emu.c +++ b/platform/gp2x/emu.c @@ -179,9 +179,8 @@ void emu_Deinit(void) void emu_prepareDefaultConfig(void) { memset(&defaultConfig, 0, sizeof(defaultConfig)); - defaultConfig.lastRomFile[0] = 0; - defaultConfig.EmuOpt = 0x1f | 0x600; // | confirm_save, cd_leds - defaultConfig.s_PicoOpt = 0x0f | 0xe00; // | use_940, cd_pcm, cd_cdda + defaultConfig.EmuOpt = 0x1d | 0x00700; // | <- ram_tmng, confirm_save, cd_leds + defaultConfig.s_PicoOpt = 0x0f | 0x20e00; // | <- use_940, cd_pcm, cd_cdda, svp drc defaultConfig.s_PsndRate = 44100; defaultConfig.s_PicoRegion = 0; // auto defaultConfig.s_PicoAutoRgnOrder = 0x184; // US, EU, JP diff --git a/platform/gp2x/main.c b/platform/gp2x/main.c index 3728685d..f016411d 100644 --- a/platform/gp2x/main.c +++ b/platform/gp2x/main.c @@ -84,6 +84,7 @@ int main(int argc, char *argv[]) emu_prepareDefaultConfig(); emu_ReadConfig(0, 0); + config_readlrom(PicoConfigFile); gp2x_init(); if (currentConfig.EmuOpt&0x10) { diff --git a/platform/gp2x/menu.c b/platform/gp2x/menu.c index b3c1d75b..06abac6f 100644 --- a/platform/gp2x/menu.c +++ b/platform/gp2x/menu.c @@ -30,7 +30,7 @@ extern int mmuhack_status; -static const char *gp2xKeyNames[] = { +const char *keyNames[] = { "UP", "???", "LEFT", "???", "DOWN", "???", "RIGHT", "???", "START", "SELECT", "L", "R", "A", "B", "X", "Y", "???", "???", "???", "???", "???", "???", "VOL DOWN", "VOL UP", @@ -121,6 +121,10 @@ static unsigned long wait_for_input_usbjoy(unsigned long interesting, int *joy) inp_prev = ret; inp_prevjoy = *joy; + // handle only 1 event at a time + for (i = 1; i != 0; i <<= 1) + if (ret & i) { ret &= i; break; } + return ret; } @@ -614,8 +618,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, gp2xKeyNames[i]); break; } - else strcpy(strkeys, gp2xKeyNames[i]); + if (strkeys[0]) { strcat(strkeys, " + "); strcat(strkeys, keyNames[i]); break; } + else strcpy(strkeys, keyNames[i]); } } for (joy = 0; joy < num_of_joys; joy++) @@ -689,9 +693,7 @@ static int count_bound_keys(int action, int pl_idx, int joy) 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; @@ -725,7 +727,7 @@ static void draw_key_config(const bind_action_t *opts, int opt_cnt, int player_i menu_flip(); } -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 joy = 0, sel = 0, menu_sel_max = opt_cnt, prev_select = 0, i; unsigned long inp = 0; @@ -768,12 +770,12 @@ static void key_config_loop(const bind_action_t *opts, int opt_cnt, int player_i if (inp & (1 << i)) { int *bind = ¤tConfig.JoyBinds[joy-1][i]; if ((*bind & opts[sel].mask) && (player_idx < 0 || player_idx == ((*bind>>16)&3))) - currentConfig.JoyBinds[joy-1][i] &= ~opts[sel].mask; + *bind &= ~opts[sel].mask; else { // override unbind_action(opts[sel].mask, player_idx, joy); *bind = opts[sel].mask; - if (player_idx >= 0) *bind |= player_idx << 16; + if (player_idx > 0) *bind |= player_idx << 16; } } } @@ -809,27 +811,10 @@ static void draw_kc_sel(int menu_sel) } -// 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 }, @@ -840,6 +825,7 @@ static bind_action_t emuctrl_actions[] = { "Volume Up ", 1<<29 }, { "Fast forward ", 1<<22 }, { "Enter Menu ", 1<<23 }, + { NULL, 0 } }; static void kc_sel_loop(void) @@ -856,8 +842,8 @@ static void kc_sel_loop(void) if (inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; } if (inp & GP2X_B) { 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 0: key_config_loop(me_ctrl_actions, is_6button ? 12 : 8, 0); return; + case 1: key_config_loop(me_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_loaded) emu_WriteConfig(0); return; @@ -1027,14 +1013,15 @@ menu_entry opt2_entries[] = { NULL, MB_NONE, MA_OPT2_GAMMA, NULL, 0, 0, 0, 1, 1 }, { "A_SN's gamma curve", MB_ONOFF, MA_OPT2_A_SN_GAMMA, ¤tConfig.EmuOpt, 0x1000, 0, 0, 1, 1 }, { "Perfect vsync", MB_ONOFF, MA_OPT2_VSYNC, ¤tConfig.EmuOpt, 0x2000, 0, 0, 1, 1 }, - { "Emulate Z80", MB_ONOFF, MA_OPT2_ENABLE_Z80, &PicoOpt, 0x0004, 0, 0, 1, 1 }, - { "Emulate YM2612 (FM)", MB_ONOFF, MA_OPT2_ENABLE_YM2612, &PicoOpt, 0x0001, 0, 0, 1, 1 }, - { "Emulate SN76496 (PSG)", MB_ONOFF, MA_OPT2_ENABLE_SN76496,&PicoOpt, 0x0002, 0, 0, 1, 1 }, + { "Emulate Z80", MB_ONOFF, MA_OPT2_ENABLE_Z80, &PicoOpt, 0x00004, 0, 0, 1, 1 }, + { "Emulate YM2612 (FM)", MB_ONOFF, MA_OPT2_ENABLE_YM2612, &PicoOpt, 0x00001, 0, 0, 1, 1 }, + { "Emulate SN76496 (PSG)", MB_ONOFF, MA_OPT2_ENABLE_SN76496,&PicoOpt, 0x00002, 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 }, { "needs restart:", MB_NONE, MA_NONE, NULL, 0, 0, 0, 1, 0 }, { "craigix's RAM timings", MB_ONOFF, MA_OPT2_RAMTIMINGS, ¤tConfig.EmuOpt, 0x0100, 0, 0, 1, 1 }, { NULL, MB_ONOFF, MA_OPT2_SQUIDGEHACK, ¤tConfig.EmuOpt, 0x0010, 0, 0, 1, 1 }, + { "SVP dynarec", MB_ONOFF, MA_OPT2_SVP_DYNAREC, &PicoOpt, 0x20000, 0, 0, 1, 1 }, { "done", MB_NONE, MA_OPT2_DONE, NULL, 0, 0, 0, 1, 0 }, }; @@ -1522,10 +1509,10 @@ static void menu_loop_root(void) { char curr_path[PATH_MAX], *selfname; FILE *tstf; - if ( (tstf = fopen(currentConfig.lastRomFile, "rb")) ) + if ( (tstf = fopen(lastRomFile, "rb")) ) { fclose(tstf); - strcpy(curr_path, currentConfig.lastRomFile); + strcpy(curr_path, lastRomFile); } else getcwd(curr_path, PATH_MAX); @@ -1665,10 +1652,10 @@ int menu_loop_tray(void) gp2x_memset_all_buffers(0, 0, 320*240*2); menu_gfx_prepare(); - if ( (tstf = fopen(currentConfig.lastRomFile, "rb")) ) + if ( (tstf = fopen(lastRomFile, "rb")) ) { fclose(tstf); - strcpy(curr_path, currentConfig.lastRomFile); + strcpy(curr_path, lastRomFile); } else { diff --git a/platform/psp/menu.c b/platform/psp/menu.c index 15c01c90..b5f3203f 100644 --- a/platform/psp/menu.c +++ b/platform/psp/menu.c @@ -699,8 +699,6 @@ static int count_bound_keys(int action, int pl_idx) 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) { int x, y, tl_y = 16+40, i; @@ -789,33 +787,17 @@ static void draw_kc_sel(int menu_sel) } -// 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 }, { "Prev Save Slot ", 1<<25 }, { "Next Save Slot ", 1<<24 }, { "Switch Renderer", 1<<26 }, + { NULL, 0 } }; static void kc_sel_loop(void) @@ -832,8 +814,8 @@ static void kc_sel_loop(void) if (inp & BTN_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; } if (inp & BTN_CIRCLE) { 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 0: key_config_loop(me_ctrl_actions, is_6button ? 12 : 8, 0); return; + case 1: key_config_loop(me_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_loaded) emu_WriteConfig(0); return; -- 2.39.5