From fcdefcf62cb71969b456a6f27688adbeb5890bb9 Mon Sep 17 00:00:00 2001 From: notaz Date: Fri, 29 Jan 2010 17:26:40 +0000 Subject: [PATCH] sh2 overclock and logging stuff, menu refactoring git-svn-id: file:///home/notaz/opt/svn/PicoDrive@869 be3aeb3a-fb24-0410-a615-afba39da0efa --- cpu/sh2/compiler.c | 71 ++++++------ pico/32x/32x.c | 11 +- pico/pico.h | 8 ++ platform/common/config.c | 227 +++++++++++++++------------------------ platform/common/emu.c | 119 +++++++++++--------- platform/common/emu.h | 12 ++- platform/common/main.c | 2 +- platform/common/menu.c | 202 +++++++++++++++++++--------------- platform/common/menu.h | 45 +++++--- platform/common/plat.h | 4 +- platform/gp2x/emu.c | 8 +- platform/gp2x/menu.c | 17 +-- platform/linux/emu.c | 6 +- platform/pandora/emu.c | 6 +- platform/win32/main.c | 2 +- platform/win32/plat.c | 4 +- 16 files changed, 379 insertions(+), 365 deletions(-) diff --git a/cpu/sh2/compiler.c b/cpu/sh2/compiler.c index 9861a859..6f08e7b8 100644 --- a/cpu/sh2/compiler.c +++ b/cpu/sh2/compiler.c @@ -66,7 +66,7 @@ static int insns_compiled, hash_collisions, host_insn_count; #define dbg(...) #endif -#if (DRC_DEBUG & 2) +#if (DRC_DEBUG & 4) static u8 *tcache_dsm_ptrs[3]; static char sh2dasm_buff[64]; #define do_host_disasm(tcid) \ @@ -76,11 +76,11 @@ static char sh2dasm_buff[64]; #define do_host_disasm(x) #endif -#if (DRC_DEBUG & 4) || defined(PDB) +#if (DRC_DEBUG & 8) || defined(PDB) static void REGPARM(3) *sh2_drc_log_entry(void *block, SH2 *sh2, u32 sr) { if (block != NULL) { - dbg(4, "= %csh2 enter %08x %p, c=%d", sh2->is_slave ? 's' : 'm', + dbg(8, "= %csh2 enter %08x %p, c=%d", sh2->is_slave ? 's' : 'm', sh2->pc, block, (signed int)sr >> 12); pdb_step(sh2, sh2->pc); } @@ -111,7 +111,7 @@ typedef struct block_desc_ { u32 addr; // SH2 PC address void *tcache_ptr; // translated block for above PC struct block_desc_ *next; // next block with the same PC hash -#if (DRC_DEBUG & 1) +#if (DRC_DEBUG & 2) int refcount; #endif } block_desc; @@ -344,7 +344,7 @@ static void REGPARM(1) flush_tcache(int tcid) } else memset(Pico32xMem->drcblk_da[tcid - 1], 0, sizeof(Pico32xMem->drcblk_da[0])); -#if (DRC_DEBUG & 2) +#if (DRC_DEBUG & 4) tcache_dsm_ptrs[tcid] = tcache_bases[tcid]; #endif } @@ -357,7 +357,7 @@ static int dr_add_block_link(u32 target_pc, void *jump, int tcache_id) int cnt = block_link_counts[tcache_id]; if (cnt >= block_max_counts[tcache_id] * 2) { - printf("bl overflow for tcache %d\n", tcache_id); + dbg(1, "bl overflow for tcache %d\n", tcache_id); return -1; } @@ -377,7 +377,7 @@ static block_desc *dr_add_block(u32 addr, int is_slave, int *blk_id) bd = dr_get_bd(addr, is_slave, &tcache_id); if (bd != NULL) { - dbg(1, "block override for %08x", addr); + dbg(2, "block override for %08x", addr); bd->tcache_ptr = tcache_ptr; *blk_id = bd - block_tables[tcache_id]; return bd; @@ -385,7 +385,7 @@ static block_desc *dr_add_block(u32 addr, int is_slave, int *blk_id) bcount = &block_counts[tcache_id]; if (*bcount >= block_max_counts[tcache_id]) { - printf("bd overflow for tcache %d\n", tcache_id); + dbg(1, "bd overflow for tcache %d", tcache_id); return NULL; } if (*bcount == 0) @@ -400,7 +400,7 @@ static block_desc *dr_add_block(u32 addr, int is_slave, int *blk_id) if ((addr & 0xc6000000) == 0x02000000) { // ROM bd->next = HASH_FUNC(hash_table, addr); HASH_FUNC(hash_table, addr) = bd; -#if (DRC_DEBUG & 1) +#if (DRC_DEBUG & 2) if (bd->next != NULL) { printf(" hash collision with %08x\n", bd->next->addr); hash_collisions++; @@ -420,7 +420,7 @@ static void REGPARM(3) *dr_lookup_block(u32 pc, int is_slave, int *tcache_id) if (bd != NULL) block = bd->tcache_ptr; -#if (DRC_DEBUG & 1) +#if (DRC_DEBUG & 2) if (bd != NULL) bd->refcount++; #endif @@ -459,7 +459,7 @@ static void dr_link_blocks(void *target, u32 pc, int tcache_id) for (i = 0; i < cnt; i++) { if (bl[i].target_pc == pc) { - dbg(1, "- link from %p", bl[i].jump); + dbg(2, "- link from %p", bl[i].jump); emith_jump_patch(bl[i].jump, target); // XXX: sync ARM caches (old jump should be fine)? } @@ -470,7 +470,7 @@ static void dr_link_blocks(void *target, u32 pc, int tcache_id) #define ADD_TO_ARRAY(array, count, item, failcode) \ array[count++] = item; \ if (count >= ARRAY_SIZE(array)) { \ - printf("warning: " #array " overflow\n"); \ + dbg(1, "warning: " #array " overflow"); \ failcode; \ } @@ -1128,7 +1128,7 @@ static void emit_block_entry(void) host_arg2reg(arg1, 1); host_arg2reg(arg2, 2); -#if (DRC_DEBUG & 4) || defined(PDB) +#if (DRC_DEBUG & 8) || defined(PDB) emit_do_static_regs(1, arg2); emith_move_r_r(arg1, CONTEXT_REG); emith_move_r_r(arg2, rcache_get_reg(SHR_SR, RC_GR_READ)); @@ -1237,12 +1237,12 @@ static void REGPARM(2) *sh2_translate(SH2 *sh2, int tcache_id) // predict tcache overflow tmp = tcache_ptr - tcache_bases[tcache_id]; if (tmp > tcache_sizes[tcache_id] - MAX_BLOCK_SIZE) { - printf("tcache %d overflow\n", tcache_id); + dbg(1, "tcache %d overflow", tcache_id); return NULL; } block_entry = tcache_ptr; - dbg(1, "== %csh2 block #%d,%d %08x -> %p", sh2->is_slave ? 's' : 'm', + dbg(2, "== %csh2 block #%d,%d %08x -> %p", sh2->is_slave ? 's' : 'm', tcache_id, blkid_main, base_pc, block_entry); dr_link_blocks(tcache_ptr, base_pc, tcache_id); @@ -1327,7 +1327,7 @@ static void REGPARM(2) *sh2_translate(SH2 *sh2, int tcache_id) rcache_flush(); do_host_disasm(tcache_id); - dbg(1, "-- %csh2 subblock #%d,%d %08x -> %p", sh2->is_slave ? 's' : 'm', + dbg(2, "-- %csh2 subblock #%d,%d %08x -> %p", sh2->is_slave ? 's' : 'm', tcache_id, branch_target_blkid[i], pc, tcache_ptr); subblock = dr_add_block(pc, sh2->is_slave, &branch_target_blkid[i]); @@ -1352,9 +1352,9 @@ static void REGPARM(2) *sh2_translate(SH2 *sh2, int tcache_id) rcache_unlock_all(); } -#if (DRC_DEBUG & 3) - insns_compiled++; #if (DRC_DEBUG & 2) + insns_compiled++; +#if (DRC_DEBUG & 4) DasmSH2(sh2dasm_buff, pc, op); printf("%08x %04x %s\n", pc, op, sh2dasm_buff); #endif @@ -2512,7 +2512,7 @@ end_op: branch_patch_count++; if (branch_patch_count == MAX_LOCAL_BRANCHES) { - printf("warning: too many local branches\n"); + dbg(1, "warning: too many local branches"); break; } } @@ -2578,8 +2578,8 @@ end_op: t = find_in_array(branch_target_pc, branch_target_count, branch_patch_pc[i]); target = branch_target_ptr[t]; if (target == NULL) { - // flush pc and go back to dispatcher (should no longer happen) - printf("stray branch to %08x %p\n", branch_patch_pc[i], tcache_ptr); + // flush pc and go back to dispatcher (this should no longer happen) + dbg(1, "stray branch to %08x %p", branch_patch_pc[i], tcache_ptr); target = tcache_ptr; emit_move_r_imm32(SHR_PC, branch_patch_pc[i]); rcache_flush(); @@ -2623,7 +2623,6 @@ end_op: // mark literals for (i = 0; i < literal_addr_count; i++) { tmp = literal_addr[i]; - //printf("marking literal %08x\n", tmp); drc_ram_blk[(tmp >> shift) & mask] = blkid_main << 1; if (!(tmp & 3)) // assume long drc_ram_blk[((tmp + 2) >> shift) & mask] = blkid_main << 1; @@ -2635,12 +2634,12 @@ end_op: host_instructions_updated(block_entry, tcache_ptr); do_host_disasm(tcache_id); - dbg(1, " block #%d,%d tcache %d/%d, insns %d -> %d %.3f", + dbg(2, " block #%d,%d tcache %d/%d, insns %d -> %d %.3f", tcache_id, block_counts[tcache_id], tcache_ptr - tcache_bases[tcache_id], tcache_sizes[tcache_id], insns_compiled, host_insn_count, (double)host_insn_count / insns_compiled); if ((sh2->pc & 0xc6000000) == 0x02000000) // ROM - dbg(1, " hash collisions %d/%d", hash_collisions, block_counts[tcache_id]); + dbg(2, " hash collisions %d/%d", hash_collisions, block_counts[tcache_id]); /* printf("~~~\n"); tcache_dsm_ptrs[tcache_id] = block_entry; @@ -2648,7 +2647,7 @@ end_op: printf("~~~\n"); */ -#if (DRC_DEBUG & 2) +#if (DRC_DEBUG & 4) fflush(stdout); #endif @@ -2841,7 +2840,7 @@ static void sh2_generate_utils(void) MAKE_WRITE_WRAPPER(sh2_drc_write16); MAKE_WRITE_WRAPPER(sh2_drc_write16_slot); MAKE_WRITE_WRAPPER(sh2_drc_write32); -#if (DRC_DEBUG & 2) +#if (DRC_DEBUG & 4) host_dasm_new_symbol(sh2_drc_read8); host_dasm_new_symbol(sh2_drc_read16); host_dasm_new_symbol(sh2_drc_read32); @@ -2850,7 +2849,7 @@ static void sh2_generate_utils(void) #endif rcache_invalidate(); -#if (DRC_DEBUG & 2) +#if (DRC_DEBUG & 4) host_dasm_new_symbol(sh2_drc_entry); host_dasm_new_symbol(sh2_drc_dispatcher); host_dasm_new_symbol(sh2_drc_exit); @@ -2869,9 +2868,9 @@ static void *sh2_smc_rm_block_entry(block_desc *bd, int tcache_id) void *tmp; // XXX: kill links somehow? - dbg(1, " killing entry %08x, blkid %d", bd->addr, bd - block_tables[tcache_id]); + dbg(2, " killing entry %08x, blkid %d", bd->addr, bd - block_tables[tcache_id]); if (bd->addr == 0 || bd->tcache_ptr == NULL) { - printf(" killing dead block!? %08x\n", bd->addr); + dbg(1, " killing dead block!? %08x", bd->addr); return bd->tcache_ptr; } @@ -2917,7 +2916,7 @@ static void sh2_smc_rm_block(u32 a, u16 *drc_ram_blk, int tcache_id, u32 shift, break; if (!(*p & 1)) { - printf("smc rm: missing block start for %08x?\n", a); + dbg(1, "smc rm: missing block start for %08x?", a); p = pt; } @@ -2950,13 +2949,13 @@ static void sh2_smc_rm_block(u32 a, u16 *drc_ram_blk, int tcache_id, u32 shift, void sh2_drc_wcheck_ram(unsigned int a, int val, int cpuid) { - dbg(1, "%csh2 smc check @%08x", cpuid ? 's' : 'm', a); + dbg(2, "%csh2 smc check @%08x", cpuid ? 's' : 'm', a); sh2_smc_rm_block(a, Pico32xMem->drcblk_ram, 0, SH2_DRCBLK_RAM_SHIFT, 0x3ffff); } void sh2_drc_wcheck_da(unsigned int a, int val, int cpuid) { - dbg(1, "%csh2 smc check @%08x", cpuid ? 's' : 'm', a); + dbg(2, "%csh2 smc check @%08x", cpuid ? 's' : 'm', a); sh2_smc_rm_block(a, Pico32xMem->drcblk_da[cpuid], 1 + cpuid, SH2_DRCBLK_DA_SHIFT, 0xfff); } @@ -2979,12 +2978,12 @@ void sh2_execute(SH2 *sh2c, int cycles) // TODO: irq cycles ret_cycles = (signed int)sh2c->sr >> 12; if (ret_cycles > 0) - printf("warning: drc returned with cycles: %d\n", ret_cycles); + dbg(1, "warning: drc returned with cycles: %d", ret_cycles); sh2c->cycles_done += cycles - ret_cycles; } -#if (DRC_DEBUG & 1) +#if (DRC_DEBUG & 2) void block_stats(void) { int c, b, i, total = 0; @@ -3069,7 +3068,7 @@ int sh2_drc_init(SH2 *sh2) // tmp PicoOpt |= POPT_DIS_VDP_FIFO; -#if (DRC_DEBUG & 2) +#if (DRC_DEBUG & 4) for (i = 0; i < ARRAY_SIZE(block_tables); i++) tcache_dsm_ptrs[i] = tcache_bases[i]; // disasm the utils @@ -3102,7 +3101,7 @@ void sh2_drc_finish(SH2 *sh2) block_stats(); for (i = 0; i < TCACHE_BUFFERS; i++) { -#if (DRC_DEBUG & 2) +#if (DRC_DEBUG & 4) printf("~~~ tcache %d\n", i); tcache_dsm_ptrs[i] = tcache_bases[i]; tcache_ptr = tcache_ptrs[i]; diff --git a/pico/32x/32x.c b/pico/32x/32x.c index e7779b9f..ffd4f1f4 100644 --- a/pico/32x/32x.c +++ b/pico/32x/32x.c @@ -4,6 +4,9 @@ struct Pico32x Pico32x; SH2 sh2s[2]; +int p32x_msh2_multiplier = MSH2_MULTI_DEFAULT; +int p32x_ssh2_multiplier = SSH2_MULTI_DEFAULT; + static int REGPARM(2) sh2_irq_cb(SH2 *sh2, int level) { if (sh2->pending_irl > sh2->pending_int_irq) { @@ -194,6 +197,7 @@ static __inline void run_m68k(int cyc) { pprof_start(m68k); +p32x_poll_event(3, 0); #if defined(EMU_C68K) PicoCpuCM68k.cycles = cyc; CycloneRun(&PicoCpuCM68k); @@ -210,7 +214,8 @@ static __inline void run_m68k(int cyc) // ~1463.8, but due to cache misses and slow mem // it's much lower than that //#define SH2_LINE_CYCLES 735 -#define CYCLES_M68K2SH2(x) ((x) * 6 / 4) +#define CYCLES_M68K2MSH2(x) (((x) * p32x_msh2_multiplier) >> 10) +#define CYCLES_M68K2SSH2(x) (((x) * p32x_ssh2_multiplier) >> 10) #define PICO_32X #define CPUS_RUN_SIMPLE(m68k_cycles,s68k_cycles) \ @@ -227,12 +232,12 @@ static __inline void run_m68k(int cyc) elprintf(EL_32X, "slice %d", slice); \ if (!(Pico32x.emu_flags & (P32XF_SSH2POLL|P32XF_SSH2VPOLL))) { \ pprof_start(ssh2); \ - sh2_execute(&ssh2, CYCLES_M68K2SH2(slice)); \ + sh2_execute(&ssh2, CYCLES_M68K2SSH2(slice)); \ pprof_end(ssh2); \ } \ if (!(Pico32x.emu_flags & (P32XF_MSH2POLL|P32XF_MSH2VPOLL))) { \ pprof_start(msh2); \ - sh2_execute(&msh2, CYCLES_M68K2SH2(slice)); \ + sh2_execute(&msh2, CYCLES_M68K2MSH2(slice)); \ pprof_end(msh2); \ } \ pprof_start(dummy); \ diff --git a/pico/pico.h b/pico/pico.h index 870444ae..bde9a5a8 100644 --- a/pico/pico.h +++ b/pico/pico.h @@ -209,6 +209,14 @@ extern unsigned char *PicoDraw2FB; // buffer for fast renderer in format (8+32 extern unsigned short *PicoCramHigh; // pointer to CRAM buff (0x40 shorts), converted to native device color (works only with 16bit for now) extern void (*PicoPrepareCram)(); // prepares PicoCramHigh for renderer to use +// 32x/32x.c +// multipliers against 68k clock +extern int p32x_msh2_multiplier; +extern int p32x_ssh2_multiplier; +#define SH2_MULTI_SHIFT 10 +#define MSH2_MULTI_DEFAULT ((1 << SH2_MULTI_SHIFT) * 3 / 2) +#define SSH2_MULTI_DEFAULT ((1 << SH2_MULTI_SHIFT) * 3 / 2) + // 32x/draw.c void PicoDraw32xSetFrameMode(int is_on, int only_32x); extern int (*PicoScan32xBegin)(unsigned int num); diff --git a/platform/common/config.c b/platform/common/config.c index 42920001..bf1f5cf8 100644 --- a/platform/common/config.c +++ b/platform/common/config.c @@ -50,53 +50,6 @@ static int seek_sect(FILE *f, const char *section) } -static void custom_write(FILE *f, const menu_entry *me, int no_def) -{ - char str24[24]; - - switch (me->id) - { - /* TODO: this should be rm'd when PSP menu is converted */ - case MA_OPT3_SCALE: - if (no_def && defaultConfig.scale == currentConfig.scale) return; - fprintf(f, "Scale factor = %.2f", currentConfig.scale); - break; - case MA_OPT3_HSCALE32: - if (no_def && defaultConfig.hscale32 == currentConfig.hscale32) return; - fprintf(f, "Hor. scale (for low res. games) = %.2f", currentConfig.hscale32); - break; - case MA_OPT3_HSCALE40: - if (no_def && defaultConfig.hscale40 == currentConfig.hscale40) return; - fprintf(f, "Hor. scale (for hi res. games) = %.2f", currentConfig.hscale40); - break; - case MA_OPT3_FILTERING: - if (no_def && defaultConfig.scaling == currentConfig.scaling) return; - fprintf(f, "Bilinear filtering = %i", currentConfig.scaling); - break; - case MA_OPT3_GAMMAA: - if (no_def && defaultConfig.gamma == currentConfig.gamma) return; - fprintf(f, "Gamma adjustment = %i", currentConfig.gamma); - break; - case MA_OPT3_BLACKLVL: - if (no_def && defaultConfig.gamma2 == currentConfig.gamma2) return; - fprintf(f, "Black level = %i", currentConfig.gamma2); - break; - case MA_OPT3_VSYNC: - if (no_def && (defaultConfig.EmuOpt&0x12000) == (currentConfig.gamma2&0x12000)) return; - strcpy(str24, "never"); - if (currentConfig.EmuOpt & 0x2000) - strcpy(str24, (currentConfig.EmuOpt & 0x10000) ? "sometimes" : "always"); - fprintf(f, "Wait for vsync = %s", str24); - break; - - default: - lprintf("unhandled custom_write: %i\n", me->id); - return; - } - fprintf(f, NL); -} - - static void keys_write(FILE *fn, const char *bind_str, int dev_id, const int *binds, int no_defaults) { char act[48]; @@ -170,6 +123,8 @@ static int default_var(const menu_entry *me) case MA_CDOPT_SCALEROT_CHIP: case MA_CDOPT_BETTER_SYNC: case MA_CDOPT_SAVERAM: + case MA_32XOPT_ENABLE_32X: + case MA_32XOPT_PWM: case MA_OPT2_SVP_DYNAREC: case MA_OPT2_NO_SPRITE_LIM: case MA_OPT2_NO_IDLE_LOOPS: @@ -197,11 +152,16 @@ static int default_var(const menu_entry *me) case MA_OPT_ROTATION: return defaultConfig.rotation; case MA_OPT2_GAMMA: return defaultConfig.gamma; case MA_OPT_FRAMESKIP: return defaultConfig.Frameskip; + case MA_OPT_CONFIRM_STATES: return defaultConfig.confirm_save; case MA_OPT_CPU_CLOCKS: return defaultConfig.CPUclock; case MA_OPT_RENDERER: return defaultConfig.renderer; + case MA_32XOPT_RENDERER: return defaultConfig.renderer32x; case MA_OPT_SAVE_SLOT: + return 0; + default: + lprintf("missing default for %d\n", me->id); return 0; } } @@ -216,11 +176,12 @@ static int is_cust_val_default(const menu_entry *me) case MA_OPT_SOUND_QUALITY: return defaultConfig.s_PsndRate == PsndRate && ((defaultConfig.s_PicoOpt ^ PicoOpt) & POPT_EN_STEREO) == 0; - case MA_OPT_CONFIRM_STATES: - return !((defaultConfig.EmuOpt ^ currentConfig.EmuOpt) & - (EOPT_CONFIRM_LOAD|EOPT_CONFIRM_SAVE)) == 0; case MA_CDOPT_READAHEAD: return defaultConfig.s_PicoCDBuffers == PicoCDBuffers; + case MA_32XOPT_MSH2_CYCLES: + return p32x_msh2_multiplier == MSH2_MULTI_DEFAULT; + case MA_32XOPT_SSH2_CYCLES: + return p32x_ssh2_multiplier == SSH2_MULTI_DEFAULT; default:break; } @@ -302,29 +263,42 @@ write: if (section != NULL) fprintf(fn, "[%s]" NL, section); - me = me_list_get_first(); - while (me != NULL) + for (me = me_list_get_first(); me != NULL; me = me_list_get_next()) { int dummy; if (!me->need_to_save) - goto next; + continue; + if (me->beh == MB_OPT_ONOFF || me->beh == MB_OPT_CUSTONOFF) { if (!no_defaults || ((*(int *)me->var ^ default_var(me)) & me->mask)) fprintf(fn, "%s = %i" NL, me->name, (*(int *)me->var & me->mask) ? 1 : 0); - } else if (me->beh == MB_OPT_RANGE || me->beh == MB_OPT_CUSTRANGE) { + } + else if (me->beh == MB_OPT_RANGE || me->beh == MB_OPT_CUSTRANGE) { if (!no_defaults || (*(int *)me->var ^ default_var(me))) fprintf(fn, "%s = %i" NL, me->name, *(int *)me->var); - } else if (me->name != NULL && me->generate_name != NULL) { + } + else if (me->beh == MB_OPT_ENUM && me->data != NULL) { + const char **names = (const char **)me->data; + for (t = 0; names[t] != NULL; t++) + if (*(int *)me->var == t && (!no_defaults || (*(int *)me->var ^ default_var(me)))) { + strncpy(line, names[t], sizeof(line)); + goto write_line; + } + } + else if (me->name != NULL && me->generate_name != NULL) { if (!no_defaults || !is_cust_val_default(me)) { strncpy(line, me->generate_name(0, &dummy), sizeof(line)); - line[sizeof(line) - 1] = 0; - mystrip(line); - fprintf(fn, "%s = %s" NL, me->name, line); + goto write_line; } - } else - custom_write(fn, me, no_defaults); -next: - me = me_list_get_next(); + } + else + lprintf("config: unhandled write: %i\n", me->id); + continue; + +write_line: + line[sizeof(line) - 1] = 0; + mystrip(line); + fprintf(fn, "%s = %s" NL, me->name, line); } /* input: save device names */ @@ -467,40 +441,9 @@ int config_readlrom(const char *fname) static int custom_read(menu_entry *me, const char *var, const char *val) { char *tmp; - int i; switch (me->id) { - case MA_OPT_RENDERER: - if (strcasecmp(var, "Renderer") != 0 || renderer_names == NULL) - return 0; - - for (i = 0; renderer_names[i] != NULL; i++) { - if (strcasecmp(val, renderer_names[i]) == 0) { - currentConfig.renderer = i; - return 1; - } - } - return 0; - - case MA_OPT_SCALING: -#ifdef __GP2X__ - if (strcasecmp(var, "Scaling") != 0) return 0; - if (strcasecmp(val, "OFF") == 0) { - currentConfig.scaling = EOPT_SCALE_NONE; - } else if (strcasecmp(val, "hw horizontal") == 0) { - currentConfig.scaling = EOPT_SCALE_HW_H; - } else if (strcasecmp(val, "hw horiz. + vert.") == 0) { - currentConfig.scaling = EOPT_SCALE_HW_HV; - } else if (strcasecmp(val, "sw horizontal") == 0) { - currentConfig.scaling = EOPT_SCALE_SW_H; - } else - currentConfig.scaling = atoi(val); - return 1; -#else - return 0; -#endif - case MA_OPT_FRAMESKIP: if (strcasecmp(var, "Frameskip") != 0) return 0; if (strcasecmp(val, "Auto") == 0) @@ -559,40 +502,23 @@ static int custom_read(menu_entry *me, const char *var, const char *val) return 0; return 1; - case MA_OPT_CONFIRM_STATES: - if (strcasecmp(var, "Confirm savestate") != 0) return 0; - if (strcasecmp(val, "OFF") == 0) { - currentConfig.EmuOpt &= ~(5<<9); - } else if (strcasecmp(val, "writes") == 0) { - currentConfig.EmuOpt &= ~(5<<9); - currentConfig.EmuOpt |= 1<<9; - } else if (strcasecmp(val, "loads") == 0) { - currentConfig.EmuOpt &= ~(5<<9); - currentConfig.EmuOpt |= 4<<9; - } else if (strcasecmp(val, "both") == 0) { - currentConfig.EmuOpt &= ~(5<<9); - currentConfig.EmuOpt |= 5<<9; - } else - return 0; - return 1; - case MA_OPT2_GAMMA: if (strcasecmp(var, "Gamma correction") != 0) return 0; currentConfig.gamma = (int) (atof(val) * 100.0); return 1; - case MA_OPT2_SQUIDGEHACK: - if (strcasecmp(var, "Squidgehack") != 0) return 0; - i = atoi(val); - if (i) *(int *)me->var |= me->mask; - else *(int *)me->var &= ~me->mask; - return 1; - case MA_CDOPT_READAHEAD: if (strcasecmp(var, "ReadAhead buffer") != 0) return 0; PicoCDBuffers = atoi(val) / 2; return 1; + case MA_32XOPT_MSH2_CYCLES: + case MA_32XOPT_SSH2_CYCLES: { + int *mul = (me->id == MA_32XOPT_MSH2_CYCLES) ? &p32x_msh2_multiplier : &p32x_ssh2_multiplier; + *mul = ((unsigned int)atoi(val) << SH2_MULTI_SHIFT) / 7670; + return 1; + } + /* PSP */ case MA_OPT3_SCALE: if (strcasecmp(var, "Scale factor") != 0) return 0; @@ -606,19 +532,8 @@ static int custom_read(menu_entry *me, const char *var, const char *val) if (strcasecmp(var, "Hor. scale (for hi res. games)") != 0) return 0; currentConfig.hscale40 = atof(val); return 1; - case MA_OPT3_FILTERING: - if (strcasecmp(var, "Bilinear filtering") != 0) return 0; - currentConfig.scaling = atoi(val); - return 1; - case MA_OPT3_GAMMAA: - if (strcasecmp(var, "Gamma adjustment") != 0) return 0; - currentConfig.gamma = atoi(val); - return 1; - case MA_OPT3_BLACKLVL: - if (strcasecmp(var, "Black level") != 0) return 0; - currentConfig.gamma2 = atoi(val); - return 1; case MA_OPT3_VSYNC: + // XXX: use enum if (strcasecmp(var, "Wait for vsync") != 0) return 0; if (strcasecmp(val, "never") == 0) { currentConfig.EmuOpt &= ~0x12000; @@ -632,7 +547,7 @@ static int custom_read(menu_entry *me, const char *var, const char *val) return 1; default: - lprintf("unhandled custom_read: %i\n", me->id); + lprintf("unhandled custom_read %i: %s\n", me->id, var); return 0; } } @@ -708,7 +623,7 @@ static unsigned char input_dev_map[IN_MAX_DEVS]; static void parse(const char *var, const char *val) { menu_entry *me; - int tmp, ret = 0; + int tmp; if (strcasecmp(var, "LastUsedROM") == 0) return; /* handled elsewhere */ @@ -749,32 +664,60 @@ static void parse(const char *var, const char *val) return; } - me = me_list_get_first(); - while (me != NULL && ret == 0) + for (me = me_list_get_first(); me != NULL; me = me_list_get_next()) { + char *p; + if (!me->need_to_save) - goto next; + continue; if (me->name != NULL && me->name[0] != 0) { if (strcasecmp(var, me->name) != 0) - goto next; /* surely not this one */ + continue; /* surely not this one */ if (me->beh == MB_OPT_ONOFF) { - tmp = atoi(val); + tmp = strtol(val, &p, 0); + if (*p != 0) + goto bad_val; if (tmp) *(int *)me->var |= me->mask; else *(int *)me->var &= ~me->mask; return; - } else if (me->beh == MB_OPT_RANGE) { - tmp = atoi(val); + } + else if (me->beh == MB_OPT_RANGE) { + tmp = strtol(val, &p, 0); + if (*p != 0) + goto bad_val; if (tmp < me->min) tmp = me->min; if (tmp > me->max) tmp = me->max; *(int *)me->var = tmp; return; } + else if (me->beh == MB_OPT_ENUM) { + const char **names, *p1; + int i; + + names = (const char **)me->data; + if (names == NULL) + goto bad_val; + for (i = 0; names[i] != NULL; i++) { + for (p1 = names[i]; *p1 == ' '; p1++) + ; + if (strcasecmp(p1, val) == 0) { + *(int *)me->var = i; + return; + } + } + goto bad_val; + } } - ret = custom_read(me, var, val); -next: - me = me_list_get_next(); + if (!custom_read(me, var, val)) + break; + return; } - if (!ret) lprintf("config_readsect: unhandled var: \"%s\"\n", var); + + lprintf("config_readsect: unhandled var: \"%s\"\n", var); + return; + +bad_val: + lprintf("config_readsect: unhandled val for \"%s\": %s\n", var, val); } diff --git a/platform/common/emu.c b/platform/common/emu.c index 1e836941..a075abdf 100644 --- a/platform/common/emu.c +++ b/platform/common/emu.c @@ -92,6 +92,36 @@ static void get_ext(const char *file, char *ext) strlwr_(ext); } +static void fname_ext(char *dst, int dstlen, const char *prefix, const char *ext, const char *fname) +{ + int prefix_len = 0; + const char *p; + + *dst = 0; + if (prefix) { + int len = plat_get_root_dir(dst, dstlen); + strcpy(dst + len, prefix); + prefix_len = len + strlen(prefix); + } + + p = fname + strlen(fname) - 1; + for (; p >= fname && *p != PATH_SEP_C; p--) + ; + p++; + strncpy(dst + prefix_len, p, dstlen - prefix_len - 1); + + dst[dstlen - 8] = 0; + if (dst[strlen(dst) - 4] == '.') + dst[strlen(dst) - 4] = 0; + if (ext) + strcat(dst, ext); +} + +static void romfname_ext(char *dst, int dstlen, const char *prefix, const char *ext) +{ + fname_ext(dst, dstlen, prefix, ext, rom_fname_loaded); +} + void emu_status_msg(const char *format, ...) { va_list vl; @@ -365,7 +395,7 @@ static int extract_text(char *dest, const unsigned char *src, int len, int swab) return p - dest; } -static char *emu_make_rom_id(void) +static char *emu_make_rom_id(const char *fname) { static char id_string[3+0xe*3+0x3*3+0x30*3+3]; int pos, swab = 1; @@ -374,15 +404,25 @@ static char *emu_make_rom_id(void) strcpy(id_string, "CD|"); swab = 0; } - else strcpy(id_string, "MD|"); + else if (PicoAHW & PAHW_SMS) + strcpy(id_string, "MS|"); + else strcpy(id_string, "MD|"); pos = 3; - pos += extract_text(id_string + pos, id_header + 0x80, 0x0e, swab); // serial - id_string[pos] = '|'; pos++; - pos += extract_text(id_string + pos, id_header + 0xf0, 0x03, swab); // region - id_string[pos] = '|'; pos++; - pos += extract_text(id_string + pos, id_header + 0x50, 0x30, swab); // overseas name - id_string[pos] = 0; + if (!(PicoAHW & PAHW_SMS)) { + pos += extract_text(id_string + pos, id_header + 0x80, 0x0e, swab); // serial + id_string[pos] = '|'; pos++; + pos += extract_text(id_string + pos, id_header + 0xf0, 0x03, swab); // region + id_string[pos] = '|'; pos++; + pos += extract_text(id_string + pos, id_header + 0x50, 0x30, swab); // overseas name + id_string[pos] = 0; + if (pos > 5) + return id_string; + pos = 3; + } + + // can't find name in ROM, use filename + fname_ext(id_string + 3, sizeof(id_string) - 3, NULL, NULL, fname); return id_string; } @@ -530,8 +570,8 @@ int emu_reload_rom(char *rom_fname) // valid CD image, check for BIOS.. // we need to have config loaded at this point - ret = emu_read_config(1, 0); - if (!ret) emu_read_config(0, 0); + ret = emu_read_config(rom_fname, 0); + if (!ret) emu_read_config(NULL, 0); cfg_loaded = 1; if (PicoRegionOverride) { @@ -593,8 +633,8 @@ int emu_reload_rom(char *rom_fname) if (!(PicoAHW & PAHW_MCD)) memcpy(id_header, rom_data + 0x100, sizeof(id_header)); if (!cfg_loaded) { - ret = emu_read_config(1, 0); - if (!ret) emu_read_config(0, 0); + ret = emu_read_config(rom_fname, 0); + if (!ret) emu_read_config(NULL, 0); } emu_make_path(static_buff, "carthw.cfg", sizeof(static_buff)); @@ -681,29 +721,6 @@ int emu_swap_cd(const char *fname) return 1; } -static void romfname_ext(char *dst, const char *prefix, const char *ext) -{ - char *p; - int prefix_len = 0; - - // make save filename - p = rom_fname_loaded + strlen(rom_fname_loaded) - 1; - for (; p >= rom_fname_loaded && *p != PATH_SEP_C; p--); p++; - *dst = 0; - if (prefix) { - int len = plat_get_root_dir(dst, 512); - strcpy(dst + len, prefix); - prefix_len = len + strlen(prefix); - } -#ifdef UIQ3 - else p = rom_fname_loaded; // backward compatibility -#endif - strncpy(dst + prefix_len, p, 511-prefix_len); - dst[511-8] = 0; - if (dst[strlen(dst)-4] == '.') dst[strlen(dst)-4] = 0; - if (ext) strcat(dst, ext); -} - // void emu_make_path(char *buff, const char *end, int size) { @@ -733,7 +750,7 @@ static void make_config_cfg(char *cfg_buff_512) void emu_prep_defconfig(void) { memset(&defaultConfig, 0, sizeof(defaultConfig)); - defaultConfig.EmuOpt = 0x9d | EOPT_RAM_TIMINGS|EOPT_CONFIRM_SAVE|EOPT_EN_CD_LEDS; + defaultConfig.EmuOpt = 0x9d | EOPT_RAM_TIMINGS|EOPT_EN_CD_LEDS; defaultConfig.s_PicoOpt = POPT_EN_STEREO|POPT_EN_FM|POPT_EN_PSG|POPT_EN_Z80 | POPT_EN_MCD_PCM|POPT_EN_MCD_CDDA|POPT_EN_SVP_DRC|POPT_ACC_SPRITES | POPT_EN_32X|POPT_EN_PWM; @@ -741,6 +758,7 @@ void emu_prep_defconfig(void) defaultConfig.s_PicoRegion = 0; // auto defaultConfig.s_PicoAutoRgnOrder = 0x184; // US, EU, JP defaultConfig.s_PicoCDBuffers = 0; + defaultConfig.confirm_save = EOPT_CONFIRM_SAVE; defaultConfig.Frameskip = -1; // auto defaultConfig.volume = 50; defaultConfig.gamma = 100; @@ -759,9 +777,11 @@ void emu_set_defconfig(void) PicoRegionOverride = currentConfig.s_PicoRegion; PicoAutoRgnOrder = currentConfig.s_PicoAutoRgnOrder; PicoCDBuffers = currentConfig.s_PicoCDBuffers; + p32x_msh2_multiplier = MSH2_MULTI_DEFAULT; + p32x_ssh2_multiplier = SSH2_MULTI_DEFAULT; } -int emu_read_config(int game, int no_defaults) +int emu_read_config(const char *rom_fname, int no_defaults) { char cfg[512]; int ret; @@ -769,16 +789,16 @@ int emu_read_config(int game, int no_defaults) if (!no_defaults) emu_set_defconfig(); - if (!game) + if (rom_fname == NULL) { + // global config make_config_cfg(cfg); ret = config_readsect(cfg, NULL); } else { - char *sect = emu_make_rom_id(); + char *sect = emu_make_rom_id(rom_fname); - // try new .cfg way if (config_slot != 0) sprintf(cfg, "game.%i.cfg", config_slot); else strcpy(cfg, "game.cfg"); @@ -839,7 +859,7 @@ int emu_write_config(int is_game) if (config_slot != 0) sprintf(cfg, "game.%i.cfg", config_slot); else strcpy(cfg, "game.cfg"); - game_sect = emu_make_rom_id(); + game_sect = emu_make_rom_id(rom_fname_loaded); lprintf("emu_write_config: sect \"%s\"\n", game_sect); } @@ -939,14 +959,15 @@ char *emu_get_save_fname(int load, int is_sram, int slot) if (is_sram) { strcpy(ext, (PicoAHW & PAHW_MCD) ? ".brm" : ".srm"); - romfname_ext(saveFname, (PicoAHW & PAHW_MCD) ? "brm"PATH_SEP : "srm"PATH_SEP, ext); + romfname_ext(saveFname, sizeof(static_buff), + (PicoAHW & PAHW_MCD) ? "brm"PATH_SEP : "srm"PATH_SEP, ext); if (!load) return saveFname; if (try_ropen_file(saveFname)) return saveFname; - romfname_ext(saveFname, NULL, ext); + romfname_ext(saveFname, sizeof(static_buff), NULL, ext); if (try_ropen_file(saveFname)) return saveFname; } @@ -960,15 +981,15 @@ char *emu_get_save_fname(int load, int is_sram, int slot) strcat(ext, ext_main); if (!load) { - romfname_ext(saveFname, "mds" PATH_SEP, ext); + romfname_ext(saveFname, sizeof(static_buff), "mds" PATH_SEP, ext); return saveFname; } else { - romfname_ext(saveFname, "mds" PATH_SEP, ext); + romfname_ext(saveFname, sizeof(static_buff), "mds" PATH_SEP, ext); if (try_ropen_file(saveFname)) return saveFname; - romfname_ext(saveFname, NULL, ext); + romfname_ext(saveFname, sizeof(static_buff), NULL, ext); if (try_ropen_file(saveFname)) return saveFname; @@ -978,7 +999,7 @@ char *emu_get_save_fname(int load, int is_sram, int slot) sprintf(ext, ".%i", slot); strcat(ext, ext_othr); - romfname_ext(saveFname, "mds"PATH_SEP, ext); + romfname_ext(saveFname, sizeof(static_buff), "mds"PATH_SEP, ext); if (try_ropen_file(saveFname)) return saveFname; } @@ -1212,8 +1233,8 @@ static void run_events_ui(unsigned int which) { int do_it = 1; if ( emu_check_save_file(state_slot) && - (((which & PEV_STATE_LOAD) && (currentConfig.EmuOpt & EOPT_CONFIRM_LOAD)) || - ((which & PEV_STATE_SAVE) && (currentConfig.EmuOpt & EOPT_CONFIRM_SAVE))) ) + (((which & PEV_STATE_LOAD) && (currentConfig.confirm_save & EOPT_CONFIRM_LOAD)) || + ((which & PEV_STATE_SAVE) && (currentConfig.confirm_save & EOPT_CONFIRM_SAVE))) ) { const char *nm; char tmp[64]; diff --git a/platform/common/emu.h b/platform/common/emu.h index 518d5fdd..f51907ff 100644 --- a/platform/common/emu.h +++ b/platform/common/emu.h @@ -30,9 +30,7 @@ extern int g_screen_height; #define EOPT_NO_AUTOSVCFG (1<<5) #define EOPT_16BPP (1<<7) // depreceted for .renderer #define EOPT_RAM_TIMINGS (1<<8) -#define EOPT_CONFIRM_SAVE (1<<9) #define EOPT_EN_CD_LEDS (1<<10) -#define EOPT_CONFIRM_LOAD (1<<11) #define EOPT_A_SN_GAMMA (1<<12) #define EOPT_VSYNC (1<<13) #define EOPT_GIZ_SCANLN (1<<14) @@ -50,6 +48,13 @@ enum { EOPT_SCALE_HW_HV, }; +enum { + EOPT_CONFIRM_NONE = 0, + EOPT_CONFIRM_SAVE = 1, + EOPT_CONFIRM_LOAD = 2, + EOPT_CONFIRM_BOTH = 3, +}; + typedef struct _currentConfig_t { int EmuOpt; int s_PicoOpt; @@ -58,6 +63,7 @@ typedef struct _currentConfig_t { int s_PicoAutoRgnOrder; int s_PicoCDBuffers; int Frameskip; + int confirm_save; int CPUclock; int volume; int gamma; @@ -121,7 +127,7 @@ void emu_reset_game(void); void emu_prep_defconfig(void); void emu_set_defconfig(void); -int emu_read_config(int game, int no_defaults); +int emu_read_config(const char *rom_fname, int no_defaults); int emu_write_config(int game); char *emu_get_save_fname(int load, int is_sram, int slot); diff --git a/platform/common/main.c b/platform/common/main.c index 7167df29..072fcfd2 100644 --- a/platform/common/main.c +++ b/platform/common/main.c @@ -77,7 +77,7 @@ int main(int argc, char *argv[]) /* in_init() must go before config, config accesses in_ fwk */ in_init(); emu_prep_defconfig(); - emu_read_config(0, 0); + emu_read_config(NULL, 0); config_readlrom(PicoConfigFile); plat_init(); diff --git a/platform/common/menu.c b/platform/common/menu.c index 5b0474a3..94027962 100644 --- a/platform/common/menu.c +++ b/platform/common/menu.c @@ -423,6 +423,9 @@ static void me_draw(const menu_entry *entries, int sel, void (*draw_more)(void)) if (name != NULL) wt += (strlen(name) + offs) * me_mfont_w; break; + case MB_OPT_ENUM: + wt += 10 * me_mfont_w; + break; } } @@ -452,6 +455,9 @@ static void me_draw(const menu_entry *entries, int sel, void (*draw_more)(void)) for (ent = entries; ent->name; ent++) { + const char **names; + int len; + if (!ent->enabled) continue; @@ -482,14 +488,28 @@ static void me_draw(const menu_entry *entries, int sel, void (*draw_more)(void)) if (name != NULL) text_out16(x + col2_offs + offs * me_mfont_w, y, "%s", name); break; + case MB_OPT_ENUM: + names = (const char **)ent->data; + offs = 0; + for (i = 0; names[i] != NULL; i++) { + len = strlen(names[i]); + if (len > 10) + offs = 10 - len - 2; + if (i == *(int *)ent->var) { + text_out16(x + col2_offs + offs * me_mfont_w, y, "%s", names[i]); + break; + } + } + break; } y += me_mfont_h; } - /* display message if we have one */ + /* display help or message if we have one */ + h = (g_screen_height - h) / 2; // bottom area height if (menu_error_msg[0] != 0) { - if (g_screen_height - h >= 2 * me_mfont_h) + if (h >= me_mfont_h + 4) text_out16(5, g_screen_height - me_mfont_h - 4, menu_error_msg); else lprintf("menu msg doesn't fit!\n"); @@ -497,6 +517,15 @@ static void me_draw(const menu_entry *entries, int sel, void (*draw_more)(void)) if (plat_get_ticks_ms() - menu_error_time > 2048) menu_error_msg[0] = 0; } + else if (entries[asel].help != NULL) { + const char *tmp = entries[asel].help; + int l; + for (l = 0; tmp != NULL && *tmp != 0; l++) + tmp = strchr(tmp + 1, '\n'); + if (h >= l * me_sfont_h + 4) + for (tmp = entries[asel].help; l > 0; l--, tmp = strchr(tmp, '\n') + 1) + smalltext_out16(5, g_screen_height - (l * me_sfont_h + 4), tmp, 0xffff); + } if (draw_more != NULL) draw_more(); @@ -506,6 +535,7 @@ static void me_draw(const menu_entry *entries, int sel, void (*draw_more)(void)) static int me_process(menu_entry *entry, int is_next, int is_lr) { + const char **names; int c; switch (entry->beh) { @@ -522,6 +552,16 @@ static int me_process(menu_entry *entry, int is_next, int is_lr) if (*(int *)entry->var > (int)entry->max) *(int *)entry->var = (int)entry->min; return 1; + case MB_OPT_ENUM: + names = (const char **)entry->data; + for (c = 0; names[c] != NULL; c++) + ; + *(int *)entry->var += is_next ? 1 : -1; + if (*(int *)entry->var < 0) + *(int *)entry->var = 0; + if (*(int *)entry->var >= c) + *(int *)entry->var = c - 1; + return 1; default: return 0; } @@ -581,12 +621,13 @@ static void me_loop(menu_entry *menu, int *menu_sel, void (*draw_more)(void)) continue; } - if (inp & (PBTN_MOK|PBTN_LEFT|PBTN_RIGHT)) + if (inp & (PBTN_MOK|PBTN_LEFT|PBTN_RIGHT|PBTN_L|PBTN_R)) { - if (menu[sel].handler != NULL) { + /* require PBTN_MOK for MB_NONE */ + if (menu[sel].handler != NULL && (menu[sel].beh != MB_NONE || (inp & PBTN_MOK))) { ret = menu[sel].handler(menu[sel].id, inp); if (ret) break; - menu_sel_max = me_count(menu) - 1; /* might change */ + menu_sel_max = me_count(menu) - 1; /* might change, so update */ } } } @@ -1405,7 +1446,7 @@ static const char *mgn_dev_name(menu_id id, int *offs) } static int mh_saveloadcfg(menu_id id, int keys); -static const char *mgn_savecfg(menu_id id, int *offs); +static const char *mgn_saveloadcfg(menu_id id, int *offs); static menu_entry e_menu_keyconfig[] = { @@ -1414,8 +1455,8 @@ static menu_entry e_menu_keyconfig[] = mee_handler_id("Emulator controls", MA_CTRL_EMU, key_config_loop_wrap), mee_onoff ("6 button pad", MA_OPT_6BUTTON_PAD, PicoOpt, POPT_6BTN_PAD), mee_range ("Turbo rate", MA_CTRL_TURBO_RATE, currentConfig.turbo_rate, 1, 30), - mee_handler_mkname_id(MA_OPT_SAVECFG, mh_saveloadcfg, mgn_savecfg), - mee_handler_id("Save cfg for loaded game", MA_OPT_SAVECFG_GAME, mh_saveloadcfg), + mee_cust_nosave("Save global config", MA_OPT_SAVECFG, mh_saveloadcfg, mgn_saveloadcfg), + mee_cust_nosave("Save cfg for loaded game", MA_OPT_SAVECFG_GAME, mh_saveloadcfg, mgn_saveloadcfg), mee_label (""), mee_label ("Input devices:"), mee_label_mk (MA_CTRL_DEV_FIRST, mgn_dev_name), @@ -1464,15 +1505,25 @@ static int mh_cdopt_ra(menu_id id, int keys) return 0; } +static const char h_cdleds[] = "Show power/CD LEDs of emulated console"; +static const char h_cdda[] = "Play audio tracks from mp3s/wavs/bins"; +static const char h_cdpcm[] = "Emulate PCM audio chip for effects/voices/music"; +static const char h_srcart[] = "Emulate the save RAM cartridge accessory\n" + "most games don't need this"; +static const char h_scfx[] = "Emulate scale/rotate ASIC chip for graphics effects\n" + "disable to improve performance"; +static const char h_bsync[] = "More accurate mode for CPUs (needed for some games)\n" + "disable to improve performance"; + static menu_entry e_menu_cd_options[] = { - mee_onoff("CD LEDs", MA_CDOPT_LEDS, currentConfig.EmuOpt, EOPT_EN_CD_LEDS), - mee_onoff("CDDA audio", MA_CDOPT_CDDA, PicoOpt, POPT_EN_MCD_CDDA), - mee_onoff("PCM audio", MA_CDOPT_PCM, PicoOpt, POPT_EN_MCD_PCM), - mee_cust ("ReadAhead buffer", MA_CDOPT_READAHEAD, mh_cdopt_ra, mgn_cdopt_ra), - mee_onoff("SaveRAM cart", MA_CDOPT_SAVERAM, PicoOpt, POPT_EN_MCD_RAMCART), - mee_onoff("Scale/Rot. fx (slow)", MA_CDOPT_SCALEROT_CHIP, PicoOpt, POPT_EN_MCD_GFX), - mee_onoff("Better sync (slow)", MA_CDOPT_BETTER_SYNC, PicoOpt, POPT_EN_MCD_PSYNC), + mee_onoff_h("CD LEDs", MA_CDOPT_LEDS, currentConfig.EmuOpt, EOPT_EN_CD_LEDS, h_cdleds), + mee_onoff_h("CDDA audio", MA_CDOPT_CDDA, PicoOpt, POPT_EN_MCD_CDDA, h_cdda), + mee_onoff_h("PCM audio", MA_CDOPT_PCM, PicoOpt, POPT_EN_MCD_PCM, h_cdpcm), + mee_cust ("ReadAhead buffer", MA_CDOPT_READAHEAD, mh_cdopt_ra, mgn_cdopt_ra), + mee_onoff_h("SaveRAM cart", MA_CDOPT_SAVERAM, PicoOpt, POPT_EN_MCD_RAMCART, h_srcart), + mee_onoff_h("Scale/Rot. fx (slow)", MA_CDOPT_SCALEROT_CHIP, PicoOpt, POPT_EN_MCD_GFX, h_scfx), + mee_onoff_h("Better sync (slow)", MA_CDOPT_BETTER_SYNC, PicoOpt, POPT_EN_MCD_PSYNC, h_bsync), mee_end, }; @@ -1485,48 +1536,55 @@ static int menu_loop_cd_options(menu_id id, int keys) // ------------ 32X options menu ------------ -static const char *get_rname(const char **rn, int val, int *offs) +// convert from multiplier of VClk +static int mh_opt_sh2cycles(menu_id id, int keys) { - int i, len, found = -1, maxlen = 0; + int *mul = (id == MA_32XOPT_MSH2_CYCLES) ? &p32x_msh2_multiplier : &p32x_ssh2_multiplier; - for (i = 0; rn[i] != NULL; i++) { - len = strlen(rn[i]); - if (len > maxlen) - maxlen = len; - if (i == val) - found = i; - } + if (keys & (PBTN_LEFT|PBTN_RIGHT)) + *mul += (keys & PBTN_LEFT) ? -10 : 10; + if (keys & (PBTN_L|PBTN_R)) + *mul += (keys & PBTN_L) ? -100 : 100; + + if (*mul < 1) + *mul = 1; + else if (*mul > (10 << SH2_MULTI_SHIFT)) + *mul = 10 << SH2_MULTI_SHIFT; - *offs = 3 - maxlen; - if (found >= 0) - return rn[found]; - return "???"; + return 0; } -static const char *mgn_opt_renderer32x(menu_id id, int *offs) +static const char *mgn_opt_sh2cycles(menu_id id, int *offs) { - return get_rname(renderer_names32x, currentConfig.renderer32x, offs); + int mul = (id == MA_32XOPT_MSH2_CYCLES) ? p32x_msh2_multiplier : p32x_ssh2_multiplier; + + sprintf(static_buff, "%d", 7670 * mul >> SH2_MULTI_SHIFT); + return static_buff; } +static const char h_32x_enable[] = "Enable emulation of the 32X addon"; +static const char h_pwm[] = "Disabling may improve performance, but break sound"; +static const char h_sh2cycles[] = "Cycles/millisecond (similar to DOSBox)\n" + "lower values speed up emulation but break games\n" + "at least 11000 recommended for compatibility"; + static menu_entry e_menu_32x_options[] = { - mee_onoff ("32X enabled", MA_32XOPT_ENABLE_32X, PicoOpt, POPT_EN_32X), - mee_range_cust("32X renderer", MA_32XOPT_RENDERER, currentConfig.renderer32x, 0, 0, mgn_opt_renderer32x), - mee_onoff ("PWM sound", MA_32XOPT_PWM, PicoOpt, POPT_EN_PWM), + mee_onoff_h ("32X enabled", MA_32XOPT_ENABLE_32X, PicoOpt, POPT_EN_32X, h_32x_enable), + mee_enum ("32X renderer", MA_32XOPT_RENDERER, currentConfig.renderer32x, renderer_names32x), + mee_onoff_h ("PWM sound", MA_32XOPT_PWM, PicoOpt, POPT_EN_PWM, h_pwm), + mee_cust_h ("Master SH2 cycles", MA_32XOPT_MSH2_CYCLES, mh_opt_sh2cycles, mgn_opt_sh2cycles, h_sh2cycles), + mee_cust_h ("Slave SH2 cycles", MA_32XOPT_SSH2_CYCLES, mh_opt_sh2cycles, mgn_opt_sh2cycles, h_sh2cycles), mee_end, }; static int menu_loop_32x_options(menu_id id, int keys) { static int sel = 0; - int i, c; - - for (c = 0; renderer_names32x != NULL && renderer_names32x[c] != NULL; ) - c++; - i = me_id2offset(e_menu_32x_options, MA_32XOPT_RENDERER); - e_menu_32x_options[i].max = c > 0 ? (c - 1) : 0; + me_enable(e_menu_32x_options, MA_32XOPT_RENDERER, renderer_names32x != NULL); me_loop(e_menu_32x_options, &sel, NULL); + return 0; } @@ -1556,14 +1614,9 @@ static int menu_loop_adv_options(menu_id id, int keys) // ------------ gfx options menu ------------ -static const char *mgn_opt_renderer(menu_id id, int *offs) -{ - return get_rname(renderer_names, currentConfig.renderer, offs); -} - static menu_entry e_menu_gfx_options[] = { - mee_range_cust("Renderer", MA_OPT_RENDERER, currentConfig.renderer, 0, 0, mgn_opt_renderer), + mee_enum("Renderer", MA_OPT_RENDERER, currentConfig.renderer, renderer_names), MENU_OPTIONS_GFX mee_end, }; @@ -1571,15 +1624,10 @@ static menu_entry e_menu_gfx_options[] = static int menu_loop_gfx_options(menu_id id, int keys) { static int sel = 0; - int i, c; - - for (c = 0; renderer_names != NULL && renderer_names[c] != NULL; ) - c++; - i = me_id2offset(e_menu_gfx_options, MA_OPT_RENDERER); - e_menu_gfx_options[i].max = c > 0 ? (c - 1) : 0; - me_enable(e_menu_gfx_options, MA_OPT_RENDERER, renderer_names != NULL); + me_enable(e_menu_gfx_options, MA_OPT_RENDERER, renderer_names[0] != NULL); me_loop(e_menu_gfx_options, &sel, NULL); + return 0; } @@ -1643,8 +1691,6 @@ static void region_prevnext(int right) static int mh_opt_misc(menu_id id, int keys) { - int i; - switch (id) { case MA_OPT_SOUND_QUALITY: PsndRate = sndrate_prevnext(PsndRate, keys & PBTN_RIGHT); @@ -1652,14 +1698,6 @@ static int mh_opt_misc(menu_id id, int keys) case MA_OPT_REGION: region_prevnext(keys & PBTN_RIGHT); break; - case MA_OPT_CONFIRM_STATES: - i = ((currentConfig.EmuOpt>>9)&1) | ((currentConfig.EmuOpt>>10)&2); - i += (keys & PBTN_LEFT) ? -1 : 1; - if (i < 0) i = 0; else if (i > 3) i = 3; - i |= i << 1; i &= ~2; - currentConfig.EmuOpt &= ~0xa00; - currentConfig.EmuOpt |= i << 9; - break; default: break; } @@ -1687,8 +1725,8 @@ static int mh_saveloadcfg(menu_id id, int keys) me_update_msg("failed to write config"); break; case MA_OPT_LOADCFG: - ret = emu_read_config(1, 1); - if (!ret) ret = emu_read_config(0, 1); + ret = emu_read_config(rom_fname_loaded, 1); + if (!ret) ret = emu_read_config(NULL, 1); if (ret) me_update_msg("config loaded"); else me_update_msg("failed to load config"); break; @@ -1749,29 +1787,17 @@ static const char *mgn_opt_region(menu_id id, int *offs) } } -static const char *mgn_opt_c_saves(menu_id id, int *offs) +static const char *mgn_saveloadcfg(menu_id id, int *offs) { - switch ((currentConfig.EmuOpt >> 9) & 5) { - default: return "OFF"; - case 1: return "writes"; - case 4: return "loads"; - case 5: return "both"; - } -} - -static const char *mgn_savecfg(menu_id id, int *offs) -{ - strcpy(static_buff, "Save global config"); + static_buff[0] = 0; if (config_slot != 0) - sprintf(static_buff + strlen(static_buff), " (profile: %i)", config_slot); + sprintf(static_buff, "[%i]", config_slot); return static_buff; } -static const char *mgn_loadcfg(menu_id id, int *offs) -{ - sprintf(static_buff, "Load cfg from profile %i", config_slot); - return static_buff; -} +static const char *men_confirm_save[] = { "OFF", "writes", "loads", "both", NULL }; +static const char h_confirm_save[] = "Ask for confirmation when overwriting save,\n" + "loading state or both"; static menu_entry e_menu_options[] = { @@ -1781,15 +1807,15 @@ static menu_entry e_menu_options[] = mee_onoff ("Show FPS", MA_OPT_SHOW_FPS, currentConfig.EmuOpt, EOPT_SHOW_FPS), mee_onoff ("Enable sound", MA_OPT_ENABLE_SOUND, currentConfig.EmuOpt, EOPT_EN_SOUND), mee_cust ("Sound Quality", MA_OPT_SOUND_QUALITY, mh_opt_misc, mgn_opt_sound), - mee_cust ("Confirm savestate", MA_OPT_CONFIRM_STATES,mh_opt_misc, mgn_opt_c_saves), + mee_enum_h ("Confirm savestate", MA_OPT_CONFIRM_STATES,currentConfig.confirm_save, men_confirm_save, h_confirm_save), mee_range (cpu_clk_name, MA_OPT_CPU_CLOCKS, currentConfig.CPUclock, 20, 900), mee_handler ("[Display options]", menu_loop_gfx_options), mee_handler ("[Sega/Mega CD options]", menu_loop_cd_options), mee_handler ("[32X options]", menu_loop_32x_options), mee_handler ("[Advanced options]", menu_loop_adv_options), - mee_handler_mkname_id(MA_OPT_SAVECFG, mh_saveloadcfg, mgn_savecfg), - mee_handler_id("Save cfg for current game only", MA_OPT_SAVECFG_GAME, mh_saveloadcfg), - mee_handler_mkname_id(MA_OPT_LOADCFG, mh_saveloadcfg, mgn_loadcfg), + mee_cust_nosave("Save global config", MA_OPT_SAVECFG, mh_saveloadcfg, mgn_saveloadcfg), + mee_cust_nosave("Save cfg for loaded game",MA_OPT_SAVECFG_GAME, mh_saveloadcfg, mgn_saveloadcfg), + mee_cust_nosave("Load cfg from profile", MA_OPT_LOADCFG, mh_saveloadcfg, mgn_saveloadcfg), mee_handler ("Restore defaults", mh_restore_defaults), mee_end, }; @@ -2040,8 +2066,8 @@ static menu_entry e_menu_main[] = mee_handler_id("Load State", MA_MAIN_LOAD_STATE, main_menu_handler), mee_handler_id("Reset game", MA_MAIN_RESET_GAME, main_menu_handler), mee_handler_id("Load new ROM/ISO", MA_MAIN_LOAD_ROM, main_menu_handler), - mee_handler_id("Change options", MA_MAIN_OPTIONS, menu_loop_options), - mee_handler_id("Configure controls", MA_MAIN_OPTIONS, menu_loop_keyconfig), + mee_handler ("Change options", menu_loop_options), + mee_handler ("Configure controls", menu_loop_keyconfig), mee_handler_id("Credits", MA_MAIN_CREDITS, main_menu_handler), mee_handler_id("Patches / GameGenie",MA_MAIN_PATCHES, main_menu_handler), mee_handler_id("Exit", MA_MAIN_EXIT, main_menu_handler), diff --git a/platform/common/menu.h b/platform/common/menu.h index 83cb9c22..74bf8e68 100644 --- a/platform/common/menu.h +++ b/platform/common/menu.h @@ -8,6 +8,7 @@ typedef enum MB_OPT_CUSTOM, /* custom value */ MB_OPT_CUSTONOFF, MB_OPT_CUSTRANGE, + MB_OPT_ENUM, } menu_behavior; typedef enum @@ -18,7 +19,6 @@ typedef enum MA_MAIN_LOAD_STATE, MA_MAIN_RESET_GAME, MA_MAIN_LOAD_ROM, - MA_MAIN_OPTIONS, MA_MAIN_CONTROLS, MA_MAIN_CREDITS, MA_MAIN_PATCHES, @@ -88,6 +88,8 @@ typedef enum MA_32XOPT_ENABLE_32X, MA_32XOPT_RENDERER, MA_32XOPT_PWM, + MA_32XOPT_MSH2_CYCLES, + MA_32XOPT_SSH2_CYCLES, MA_CTRL_PLAYER1, MA_CTRL_PLAYER2, MA_CTRL_EMU, @@ -111,40 +113,57 @@ typedef struct int selectable:1; int (*handler)(menu_id id, int keys); const char * (*generate_name)(menu_id id, int *offs); + const void *data; + const char *help; } menu_entry; #define mee_handler_id(name, id, handler) \ - { name, MB_NONE, id, NULL, 0, 0, 0, 1, 0, 1, handler, NULL } + { name, MB_NONE, id, NULL, 0, 0, 0, 1, 0, 1, handler, NULL, NULL, NULL } #define mee_handler(name, handler) \ mee_handler_id(name, MA_NONE, handler) -#define mee_handler_mkname_id(id, handler, name_func) \ - { "", MB_NONE, id, NULL, 0, 0, 0, 1, 0, 1, handler, name_func } - #define mee_label(name) \ - { name, MB_NONE, MA_NONE, NULL, 0, 0, 0, 1, 0, 0, NULL, NULL } + { name, MB_NONE, MA_NONE, NULL, 0, 0, 0, 1, 0, 0, NULL, NULL, NULL, NULL } #define mee_label_mk(id, name_func) \ - { "", MB_NONE, id, NULL, 0, 0, 0, 1, 0, 0, NULL, name_func } + { "", MB_NONE, id, NULL, 0, 0, 0, 1, 0, 0, NULL, name_func, NULL, NULL } + +#define mee_onoff_h(name, id, var, mask, help) \ + { name, MB_OPT_ONOFF, id, &(var), mask, 0, 0, 1, 1, 1, NULL, NULL, NULL, help } #define mee_onoff(name, id, var, mask) \ - { name, MB_OPT_ONOFF, id, &(var), mask, 0, 0, 1, 1, 1, NULL, NULL } + mee_onoff_h(name, id, var, mask, NULL) #define mee_range(name, id, var, min, max) \ - { name, MB_OPT_RANGE, id, &(var), 0, min, max, 1, 1, 1, NULL, NULL } + { name, MB_OPT_RANGE, id, &(var), 0, min, max, 1, 1, 1, NULL, NULL, NULL, NULL } + +#define mee_cust_s_h(name, id, need_save, handler, name_func, help) \ + { name, MB_OPT_CUSTOM, id, NULL, 0, 0, 0, 1, need_save, 1, handler, name_func, NULL, help } + +#define mee_cust_h(name, id, handler, name_func, help) \ + mee_cust_s_h(name, id, 1, handler, name_func, help) #define mee_cust(name, id, handler, name_func) \ - { name, MB_OPT_CUSTOM, id, NULL, 0, 0, 0, 1, 1, 1, handler, name_func } + mee_cust_h(name, id, handler, name_func, NULL) + +#define mee_cust_nosave(name, id, handler, name_func) \ + mee_cust_s_h(name, id, 0, handler, name_func, NULL) #define mee_onoff_cust(name, id, var, mask, name_func) \ - { name, MB_OPT_CUSTONOFF, id, &(var), mask, 0, 0, 1, 1, 1, NULL, name_func } + { name, MB_OPT_CUSTONOFF, id, &(var), mask, 0, 0, 1, 1, 1, NULL, name_func, NULL, NULL } #define mee_range_cust(name, id, var, min, max, name_func) \ - { name, MB_OPT_CUSTRANGE, id, &(var), 0, min, max, 1, 1, 1, NULL, name_func } + { name, MB_OPT_CUSTRANGE, id, &(var), 0, min, max, 1, 1, 1, NULL, name_func, NULL, NULL } + +#define mee_enum_h(name, id, var, names_list, help) \ + { name, MB_OPT_ENUM, id, &(var), 0, 0, 0, 1, 1, 1, NULL, NULL, names_list, help } + +#define mee_enum(name, id, var, names_list) \ + mee_enum_h(name, id, var, names_list, NULL) #define mee_end \ - { NULL, 0, 0, NULL, 0, 0, 0, 0, 0, 0, NULL, NULL } + { NULL, 0, 0, NULL, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL } typedef struct { diff --git a/platform/common/plat.h b/platform/common/plat.h index 4f89b2ce..99557da3 100644 --- a/platform/common/plat.h +++ b/platform/common/plat.h @@ -4,8 +4,8 @@ extern "C" { /* stuff to be implemented by platform code */ extern char cpu_clk_name[]; -extern const char **renderer_names; -extern const char **renderer_names32x; +extern const char *renderer_names[]; +extern const char *renderer_names32x[]; void pemu_prep_defconfig(void); void pemu_validate_config(void); diff --git a/platform/gp2x/emu.c b/platform/gp2x/emu.c index ccb5e87d..1f60e161 100644 --- a/platform/gp2x/emu.c +++ b/platform/gp2x/emu.c @@ -43,10 +43,8 @@ static short __attribute__((aligned(4))) sndBuffer[2*(44100+100)/50]; static unsigned char PicoDraw2FB_[(8+320) * (8+240+8)]; unsigned char *PicoDraw2FB = PicoDraw2FB_; static int osd_fps_x, osd_y; -const char *renderer_names_[] = { "16bit accurate", " 8bit accurate", " 8bit fast", NULL }; -const char *renderer_names32x_[] = { "accurate", "faster ", "fastest ", NULL }; -const char **renderer_names = renderer_names_; -const char **renderer_names32x = renderer_names32x_; +const char *renderer_names[] = { "16bit accurate", " 8bit accurate", " 8bit fast", NULL }; +const char *renderer_names32x[] = { "accurate", "faster", "fastest", NULL }; enum renderer_types { RT_16BIT, RT_8BIT_ACC, RT_8BIT_FAST, RT_COUNT }; extern void *gp2x_screens[4]; @@ -902,7 +900,7 @@ void pemu_loop_end(void) const char *plat_get_credits(void) { - return "PicoDrive v" VERSION " (c) notaz, 2006-2009\n\n\n" + return "PicoDrive v" VERSION " (c) notaz, 2006-2010\n\n\n" "Credits:\n" "fDave: Cyclone 68000 core,\n" " base code of PicoDrive\n" diff --git a/platform/gp2x/menu.c b/platform/gp2x/menu.c index fb9d24a2..9dbabe46 100644 --- a/platform/gp2x/menu.c +++ b/platform/gp2x/menu.c @@ -53,26 +53,17 @@ static void menu_main_plat_draw(void) // ------------ gfx options menu ------------ -static const char *mgn_opt_scaling(menu_id id, int *offs) -{ - *offs = -13; - switch (currentConfig.scaling) { - default: return " OFF"; - case EOPT_SCALE_HW_H: return " hw horizontal"; - case EOPT_SCALE_HW_HV: return "hw horiz. + vert"; - case EOPT_SCALE_SW_H: return " sw horizontal"; - } -} - static const char *mgn_aopt_gamma(menu_id id, int *offs) { - sprintf(static_buff, "%i.%02i", currentConfig.gamma / 100, currentConfig.gamma%100); + sprintf(static_buff, "%i.%02i", currentConfig.gamma / 100, currentConfig.gamma % 100); return static_buff; } +const char *men_scaling_opts[] = { "OFF", "sw horizontal", "hw horizontal", "hw horiz. + vert", NULL }; + #define MENU_OPTIONS_GFX \ - mee_range_cust("Scaling", MA_OPT_SCALING, currentConfig.scaling, 0, 3, mgn_opt_scaling), \ + mee_enum ("Scaling", MA_OPT_SCALING, currentConfig.scaling, men_scaling_opts), \ mee_onoff ("Tearing Fix", MA_OPT_TEARING_FIX, currentConfig.EmuOpt, EOPT_WIZ_TEAR_FIX), \ mee_range_cust("Gamma correction", MA_OPT2_GAMMA, currentConfig.gamma, 1, 300, mgn_aopt_gamma), \ mee_onoff ("A_SN's gamma curve", MA_OPT2_A_SN_GAMMA, currentConfig.EmuOpt, EOPT_A_SN_GAMMA), \ diff --git a/platform/linux/emu.c b/platform/linux/emu.c index 0ef599d6..08421fae 100644 --- a/platform/linux/emu.c +++ b/platform/linux/emu.c @@ -18,10 +18,8 @@ static short __attribute__((aligned(4))) sndBuffer[2*44100/50]; char cpu_clk_name[] = "unused"; -const char *renderer_names_[] = { "16bit accurate", " 8bit accurate", " 8bit fast", NULL }; -const char *renderer_names32x_[] = { "accurate", "faster ", "fastest ", NULL }; -const char **renderer_names = renderer_names_; -const char **renderer_names32x = renderer_names32x_; +const char *renderer_names[] = { "16bit accurate", " 8bit accurate", " 8bit fast", NULL }; +const char *renderer_names32x[] = { "accurate", "faster", "fastest", NULL }; enum renderer_types { RT_16BIT, RT_8BIT_ACC, RT_8BIT_FAST, RT_COUNT }; diff --git a/platform/pandora/emu.c b/platform/pandora/emu.c index 2bd8be8e..951d85ee 100644 --- a/platform/pandora/emu.c +++ b/platform/pandora/emu.c @@ -23,8 +23,8 @@ static short __attribute__((aligned(4))) sndBuffer[2*44100/50]; static unsigned char temp_frame[g_screen_width * g_screen_height * 2]; unsigned char *PicoDraw2FB = temp_frame; -const char **renderer_names = NULL; -const char **renderer_names32x = NULL; +const char *renderer_names[] = { NULL }; +const char *renderer_names32x[] = { NULL }; char cpu_clk_name[] = "unused"; @@ -406,7 +406,7 @@ void plat_wait_till_us(unsigned int us_to) const char *plat_get_credits(void) { - return "PicoDrive v" VERSION " (c) notaz, 2006-2009\n\n\n" + return "PicoDrive v" VERSION " (c) notaz, 2006-2010\n\n\n" "Credits:\n" "fDave: Cyclone 68000 core,\n" " base code of PicoDrive\n" diff --git a/platform/win32/main.c b/platform/win32/main.c index d43149c8..85d153be 100644 --- a/platform/win32/main.c +++ b/platform/win32/main.c @@ -566,7 +566,7 @@ void xxinit(void) /* in_init() must go before config, config accesses in_ fwk */ in_init(); emu_prep_defconfig(); - emu_read_config(0, 0); + emu_read_config(NULL, 0); config_readlrom(PicoConfigFile); plat_init(); diff --git a/platform/win32/plat.c b/platform/win32/plat.c index 4173da3f..ecf47198 100644 --- a/platform/win32/plat.c +++ b/platform/win32/plat.c @@ -13,8 +13,8 @@ static unsigned short screen_buff[320 * 240]; static unsigned char PicoDraw2FB_[(8+320) * (8+240+8)]; unsigned char *PicoDraw2FB = PicoDraw2FB_; -const char **renderer_names = NULL; -const char **renderer_names32x = NULL; +const char *renderer_names[] = { NULL }; +const char *renderer_names32x[] = { NULL }; char cpu_clk_name[] = "unused"; -- 2.39.5