From bdec53c90b6e53990fc206cabaec31b844f34d1e Mon Sep 17 00:00:00 2001 From: notaz Date: Tue, 25 Mar 2008 19:23:07 +0000 Subject: [PATCH] bugfixes, refactoring git-svn-id: file:///home/notaz/opt/svn/PicoDrive@394 be3aeb3a-fb24-0410-a615-afba39da0efa --- Pico/Area.c | 1 - Pico/carthw/carthw.c | 16 ++++++++++ Pico/cd/Area.c | 2 ++ platform/base_readme.txt | 17 +++++++++-- platform/common/config.c | 36 +++++++++++----------- platform/common/emu.c | 60 ++++++++++++++++++++++++++++++++----- platform/common/emu.h | 2 ++ platform/gizmondo/emu.c | 57 ++++++----------------------------- platform/gizmondo/menu.c | 2 +- platform/gp2x/emu.c | 64 ++++++++-------------------------------- platform/gp2x/menu.c | 2 +- platform/psp/emu.c | 56 ++++++----------------------------- platform/psp/menu.c | 2 +- 13 files changed, 139 insertions(+), 178 deletions(-) diff --git a/Pico/Area.c b/Pico/Area.c index 0ec25ecc..293c2614 100644 --- a/Pico/Area.c +++ b/Pico/Area.c @@ -138,7 +138,6 @@ static int PicoAreaScan(int PmovAction,unsigned int ver, void *PmovFile) // Pack, scan and unpack the cpu data: if((PmovAction&3)==1) PicoAreaPackCpu(cpu, 0); - //SekInit(); // notaz: do we really have to do this here? //PicoMemInit(); SCAN_VAR(cpu,"cpu") if((PmovAction&3)==2) PicoAreaUnpackCpu(cpu, 0); diff --git a/Pico/carthw/carthw.c b/Pico/carthw/carthw.c index c3e80f83..d22a2357 100644 --- a/Pico/carthw/carthw.c +++ b/Pico/carthw/carthw.c @@ -7,6 +7,14 @@ /* 12-in-1 and 4-in-1. Assuming 2MB ROMs here. */ +static unsigned int carthw_12in1_baddr = 0; + +static carthw_state_chunk carthw_12in1_state[] = +{ + { CHUNK_CARTHW, sizeof(carthw_12in1_baddr), &carthw_12in1_baddr }, + { 0, 0, NULL } +}; + static unsigned int carthw_12in1_read16(unsigned int a, int realsize) { // ?? @@ -26,6 +34,7 @@ static void carthw_12in1_write8(unsigned int a, unsigned int d, int realsize) return; } + carthw_12in1_baddr = a; a &= 0x3f; a <<= 16; len = Pico.romsize - a; if (len <= 0) { @@ -41,6 +50,11 @@ static void carthw_12in1_reset(void) carthw_12in1_write8(0xA13000, 0, 0); } +static void carthw_12in1_statef(void) +{ + carthw_12in1_write8(carthw_12in1_baddr, 0, 0); +} + void carthw_12in1_startup(void) { void *tmp; @@ -59,6 +73,8 @@ void carthw_12in1_startup(void) PicoRead16Hook = carthw_12in1_read16; PicoWrite8Hook = carthw_12in1_write8; PicoResetHook = carthw_12in1_reset; + PicoLoadStateHook = carthw_12in1_statef; + carthw_chunks = carthw_12in1_state; } diff --git a/Pico/cd/Area.c b/Pico/cd/Area.c index 4eab260c..c8c1d916 100644 --- a/Pico/cd/Area.c +++ b/Pico/cd/Area.c @@ -153,6 +153,8 @@ PICO_INTERNAL int PicoCdSaveState(void *file) if (carthw_chunks != NULL) { carthw_state_chunk *chwc; + if (PicoStateProgressCB) + PicoStateProgressCB("Saving.. cart hw state"); for (chwc = carthw_chunks; chwc->ptr != NULL; chwc++) CHECKED_WRITE(chwc->chunk, chwc->size, chwc->ptr); } diff --git a/platform/base_readme.txt b/platform/base_readme.txt index 0c637523..947ac98a 100644 --- a/platform/base_readme.txt +++ b/platform/base_readme.txt @@ -538,11 +538,13 @@ bram (internal backup RAM): yes Problems / limitations ---------------------- -* 32x and SVP are not emulated. +* 32x is not emulated. +#ifdef PSP +* SVP is not emulated. +#endif * Various VDP quirks (window bug, scroll size 2, etc.) are not emulated, as very few games use this (if any at all). -* Some games don't work or have glitches because of inaccurate timing and sync - between the emulated chips. +* The emulator is not 100% accurate, so some things may not work as expected. Credits @@ -600,6 +602,7 @@ Additional thanks * Charles MacDonald (http://cgfm2.emuviews.com/) for old but still very useful info about genesis hardware. * Steve Snake for all that he has done for Genesis emulation scene. +* Tasco Deluxe for his reverse engineering work on SVP and some mappers. * Bart Trzynadlowski for his SSFII and 68000 docs. * Haze for his research (http://haze.mameworld.info). * Mark and Jean-loup for zlib library. @@ -633,6 +636,14 @@ Additional thanks Changelog --------- +1.40 + + Added support for SVP (Sega Virtua Processor) to emulate Virtua Racing, + wrote ARM recompiler and some HLE code for VR. + * Changed config file format, files are now human-readable. Game specific + configs are now held in single file (but old game config files are still + read). + * Fixed a bug where some key combos didn't work. + 1.35b * PSP: mp3 code should no longer fail on 1.5 firmware. + PSP: added gamma adjustment option. diff --git a/platform/common/config.c b/platform/common/config.c index 534fb400..c117fb90 100644 --- a/platform/common/config.c +++ b/platform/common/config.c @@ -24,7 +24,7 @@ static const int *cfg_opt_counts[] = { &opt_entry_count, &opt2_entry_count, &cdo #define NL "\n" -static void mystrip(char *str) +static char *mystrip(char *str) { int i, len; @@ -32,10 +32,13 @@ static void mystrip(char *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; + + return str; } @@ -167,22 +170,18 @@ static void keys_write(FILE *fn, const char *bind_str, const int binds[32], #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; + strncpy(act, me_ctrl_actions[i].name, 31); + fprintf(fn, "%s %s = player%i %s" NL, bind_str, names[t], + ((binds[t]>>16)&1)+1, mystrip(act)); } } - 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); + for (i = 0; emuctrl_actions[i].name != NULL; i++) { + if (emuctrl_actions[i].mask & binds[t]) { + strncpy(act, emuctrl_actions[i].name, 31); + fprintf(fn, "%s %s = %s" NL, bind_str, names[t], mystrip(act)); + } + } } } @@ -566,9 +565,11 @@ static int custom_read(menu_entry *me, const char *var, const char *val) } +static unsigned int keys_encountered = 0; + static void keys_parse(const char *var, const char *val, int binds[32], const char *names[32]) { - int t, i, keys_encountered = 0; + int t, i; unsigned int player; for (t = 0; t < 32; t++) @@ -580,7 +581,7 @@ static void keys_parse(const char *var, const char *val, int binds[32], const ch return; } - if (!(keys_encountered & (1< 0) { + PicoMCD |= 1; // valid CD image, check for BIOS.. // we need to have config loaded at this point @@ -341,10 +345,10 @@ int emu_ReloadRom(void) } if (!emu_findBios(cd_region, &used_rom_name)) { // bios_help() ? + PicoMCD &= ~1; return 0; } - PicoMCD |= 1; get_ext(used_rom_name, ext); } else @@ -651,6 +655,47 @@ void emu_textOut16(int x, int y, const char *text) } } +void emu_findKeyBindCombos(void) +{ + int act, u; + + // find out which keys and actions are combos + kb_combo_keys = kb_combo_acts = 0; + for (act = 0; act < 32; act++) + { + int keyc = 0, keyc2 = 0; + if (act == 16 || act == 17) continue; // player2 flag + if (act > 17) + { + for (u = 0; u < 32; u++) + if (currentConfig.KeyBinds[u] & (1 << act)) keyc++; + } + else + { + for (u = 0; u < 32; u++) + if ((currentConfig.KeyBinds[u] & 0x30000) == 0 && // pl. 1 + (currentConfig.KeyBinds[u] & (1 << act))) keyc++; + for (u = 0; u < 32; u++) + if ((currentConfig.KeyBinds[u] & 0x30000) == 1 && // pl. 2 + (currentConfig.KeyBinds[u] & (1 << act))) keyc2++; + if (keyc2 > keyc) keyc = keyc2; + } + if (keyc > 1) + { + // loop again and mark those keys and actions as combo + for (u = 0; u < 32; u++) + { + if (currentConfig.KeyBinds[u] & (1 << act)) { + kb_combo_keys |= 1 << u; + kb_combo_acts |= 1 << act; + } + } + } + } + + // printf("combo keys/acts: %08x %08x\n", kb_combo_keys, kb_combo_acts); +} + void emu_updateMovie(void) { @@ -876,3 +921,4 @@ int emu_SaveLoadGame(int load, int sram) return ret; } } + diff --git a/platform/common/emu.h b/platform/common/emu.h index 93a88233..90c93500 100644 --- a/platform/common/emu.h +++ b/platform/common/emu.h @@ -34,6 +34,7 @@ extern int state_slot; extern int config_slot, config_slot_current; extern unsigned char *movie_data; extern char lastRomFile[512]; +extern int kb_combo_keys, kb_combo_acts; // keys and actions which need button combos int emu_ReloadRom(void); @@ -49,6 +50,7 @@ int emu_findBios(int region, char **bios_file); void emu_textOut8 (int x, int y, const char *text); void emu_textOut16(int x, int y, const char *text); char *emu_makeRomId(void); +void emu_findKeyBindCombos(void); extern const char *keyNames[]; void emu_prepareDefaultConfig(void); diff --git a/platform/gizmondo/emu.c b/platform/gizmondo/emu.c index 9a285536..82c3dddb 100644 --- a/platform/gizmondo/emu.c +++ b/platform/gizmondo/emu.c @@ -31,7 +31,6 @@ int engineState; unsigned char *PicoDraw2FB = gfx_buffer; // temporary buffer for alt renderer ( (8+320)*(8+240+8) ) int reset_timing = 0; -static int combo_keys = 0, combo_acts = 0; // keys and actions which need button combos static DWORD noticeMsgTime = 0; static short *snd_cbuff = NULL; static int snd_cbuf_samples = 0, snd_all_samples = 0; @@ -457,20 +456,21 @@ static void updateKeys(void) int pl, acts = currentConfig.KeyBinds[i]; if (!acts) continue; pl = (acts >> 16) & 1; - if (combo_keys & (1 << i)) + if (kb_combo_keys & (1 << i)) { - int u = i+1, acts_c = acts & combo_acts; + int u, acts_c = acts & kb_combo_acts; // let's try to find the other one - if (acts_c) - for (; u < 32; u++) - if ( (currentConfig.KeyBinds[u] & acts_c) && (keys & (1 << u)) ) { - allActions[pl] |= acts_c; + if (acts_c) { + for (u = i + 1; u < 32; u++) + if ( (keys & (1 << u)) && (currentConfig.KeyBinds[u] & acts_c) ) { + allActions[pl] |= acts_c & currentConfig.KeyBinds[u]; keys &= ~((1 << i) | (1 << u)); break; } + } // add non-combo actions if combo ones were not found if (!acts_c || u == 32) - allActions[pl] |= acts & ~combo_acts; + allActions[pl] |= acts & ~kb_combo_acts; } else { allActions[pl] |= acts; } @@ -504,45 +504,6 @@ static void updateKeys(void) prevEvents = (allActions[0] | allActions[1]) >> 16; } -static void find_combos(void) -{ - int act, u; - - // find out which keys and actions are combos - combo_keys = combo_acts = 0; - for (act = 0; act < 32; act++) - { - int keyc = 0, keyc2 = 0; - if (act == 16 || act == 17) continue; // player2 flag - if (act > 17) - { - for (u = 0; u < 32; u++) - if (currentConfig.KeyBinds[u] & (1 << act)) keyc++; - } - else - { - for (u = 0; u < 32; u++) - if ((currentConfig.KeyBinds[u] & 0x30000) == 0 && // pl. 1 - (currentConfig.KeyBinds[u] & (1 << act))) keyc++; - for (u = 0; u < 32; u++) - if ((currentConfig.KeyBinds[u] & 0x30000) == 1 && // pl. 2 - (currentConfig.KeyBinds[u] & (1 << act))) keyc2++; - if (keyc2 > keyc) keyc = keyc2; - } - if (keyc > 1) - { - // loop again and mark those keys and actions as combo - for (u = 0; u < 32; u++) - { - if (currentConfig.KeyBinds[u] & (1 << act)) { - combo_keys |= 1 << u; - combo_acts |= 1 << act; - } - } - } - } -} - static void simpleWait(DWORD until) { @@ -577,7 +538,7 @@ void emu_Loop(void) else PicoOpt&=~0x4000; Pico.m.dirtyPal = 1; oldmodes = ((Pico.video.reg[12]&1)<<2) ^ 0xc; - find_combos(); + emu_findKeyBindCombos(); // pal/ntsc might have changed, reset related stuff target_fps = Pico.m.pal ? 50 : 60; diff --git a/platform/gizmondo/menu.c b/platform/gizmondo/menu.c index ce8e92f9..d4612869 100644 --- a/platform/gizmondo/menu.c +++ b/platform/gizmondo/menu.c @@ -807,7 +807,7 @@ static void kc_sel_loop(void) 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; + sizeof(emuctrl_actions)/sizeof(emuctrl_actions[0]) - 1, -1); return; case 3: if (!rom_loaded) emu_WriteConfig(0); return; default: return; } diff --git a/platform/gp2x/emu.c b/platform/gp2x/emu.c index 74bcde89..0375a7ff 100644 --- a/platform/gp2x/emu.c +++ b/platform/gp2x/emu.c @@ -48,7 +48,6 @@ extern int crashed_940; static short __attribute__((aligned(4))) sndBuffer[2*44100/50]; static struct timeval noticeMsgTime = { 0, 0 }; // when started showing static int osd_fps_x; -static int combo_keys = 0, combo_acts = 0; // keys and actions which need button combos static int gp2x_old_gamma = 100; char noticeMsg[64]; // notice msg to draw unsigned char *PicoDraw2FB = NULL; // temporary buffer for alt renderer @@ -98,48 +97,6 @@ void emu_Init(void) } -static void find_combos(void) -{ - int act, u; - - // find out which keys and actions are combos - combo_keys = combo_acts = 0; - for (act = 0; act < 32; act++) - { - int keyc = 0, keyc2 = 0; - if (act == 16 || act == 17) continue; // player2 flag - if (act > 17) - { - for (u = 0; u < 32; u++) - if (currentConfig.KeyBinds[u] & (1 << act)) keyc++; - } - else - { - for (u = 0; u < 32; u++) - if ((currentConfig.KeyBinds[u] & 0x30000) == 0 && // pl. 1 - (currentConfig.KeyBinds[u] & (1 << act))) keyc++; - for (u = 0; u < 32; u++) - if ((currentConfig.KeyBinds[u] & 0x30000) == 1 && // pl. 2 - (currentConfig.KeyBinds[u] & (1 << act))) keyc2++; - if (keyc2 > keyc) keyc = keyc2; - } - if (keyc > 1) - { - // loop again and mark those keys and actions as combo - for (u = 0; u < 32; u++) - { - if (currentConfig.KeyBinds[u] & (1 << act)) { - combo_keys |= 1 << u; - combo_acts |= 1 << act; - } - } - } - } - - // printf("combo keys/acts: %08x %08x\n", combo_keys, combo_acts); -} - - static void scaling_update(void) { PicoOpt &= ~0x4100; @@ -577,23 +534,26 @@ static void updateKeys(void) for (i = 0; i < 32; i++) { - if (keys & (1 << i)) { + if (keys & (1 << i)) + { int pl, acts = currentConfig.KeyBinds[i]; if (!acts) continue; pl = (acts >> 16) & 1; - if (combo_keys & (1 << i)) { - int u = i+1, acts_c = acts & combo_acts; + if (kb_combo_keys & (1 << i)) + { + int u, acts_c = acts & kb_combo_acts; // let's try to find the other one - if (acts_c) - for (; u < 32; u++) - if ( (currentConfig.KeyBinds[u] & acts_c) && (keys & (1 << u)) ) { - allActions[pl] |= acts_c; + if (acts_c) { + for (u = i + 1; u < 32; u++) + if ( (keys & (1 << u)) && (currentConfig.KeyBinds[u] & acts_c) ) { + allActions[pl] |= acts_c & currentConfig.KeyBinds[u]; keys &= ~((1 << i) | (1 << u)); break; } + } // add non-combo actions if combo ones were not found if (!acts_c || u == 32) - allActions[pl] |= acts & ~combo_acts; + allActions[pl] |= acts & ~kb_combo_acts; } else { allActions[pl] |= acts; } @@ -740,7 +700,7 @@ void emu_Loop(void) scaling_update(); Pico.m.dirtyPal = 1; oldmodes = ((Pico.video.reg[12]&1)<<2) ^ 0xc; - find_combos(); + emu_findKeyBindCombos(); // pal/ntsc might have changed, reset related stuff target_fps = Pico.m.pal ? 50 : 60; diff --git a/platform/gp2x/menu.c b/platform/gp2x/menu.c index 06abac6f..df5ff8a4 100644 --- a/platform/gp2x/menu.c +++ b/platform/gp2x/menu.c @@ -845,7 +845,7 @@ static void kc_sel_loop(void) 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; + sizeof(emuctrl_actions)/sizeof(emuctrl_actions[0]) - 1, -1); return; case 3: if (!rom_loaded) emu_WriteConfig(0); return; default: return; } diff --git a/platform/psp/emu.c b/platform/psp/emu.c index 4af44b98..2ea26732 100644 --- a/platform/psp/emu.c +++ b/platform/psp/emu.c @@ -35,7 +35,6 @@ char romFileName[PATH_MAX]; unsigned char *PicoDraw2FB = (unsigned char *)VRAM_CACHED_STUFF + 8; // +8 to be able to skip border with 1 quadword.. int engineState = PGS_Menu; -static int combo_keys = 0, combo_acts = 0; // keys and actions which need button combos static unsigned int noticeMsgTime = 0; int reset_timing = 0; // do we need this? @@ -764,20 +763,21 @@ static void updateKeys(void) int pl, acts = currentConfig.KeyBinds[i]; if (!acts) continue; pl = (acts >> 16) & 1; - if (combo_keys & (1 << i)) + if (kb_combo_keys & (1 << i)) { - int u = i+1, acts_c = acts & combo_acts; + int u, acts_c = acts & kb_combo_acts; // let's try to find the other one - if (acts_c) - for (; u < 32; u++) - if ( (currentConfig.KeyBinds[u] & acts_c) && (keys & (1 << u)) ) { - allActions[pl] |= acts_c; + if (acts_c) { + for (u = i + 1; u < 32; u++) + if ( (keys & (1 << u)) && (currentConfig.KeyBinds[u] & acts_c) ) { + allActions[pl] |= acts_c & currentConfig.KeyBinds[u]; keys &= ~((1 << i) | (1 << u)); break; } + } // add non-combo actions if combo ones were not found if (!acts_c || u == 32) - allActions[pl] |= acts & ~combo_acts; + allActions[pl] |= acts & ~kb_combo_acts; } else { allActions[pl] |= acts; } @@ -811,44 +811,6 @@ static void updateKeys(void) prevEvents = (allActions[0] | allActions[1]) >> 16; } -static void find_combos(void) -{ - int act, u; - - // find out which keys and actions are combos - combo_keys = combo_acts = 0; - for (act = 0; act < 32; act++) - { - int keyc = 0, keyc2 = 0; - if (act == 16 || act == 17) continue; // player2 flag - if (act > 17) - { - for (u = 0; u < 28; u++) // 28 because nub can't produce combos - if (currentConfig.KeyBinds[u] & (1 << act)) keyc++; - } - else - { - for (u = 0; u < 28; u++) - if ((currentConfig.KeyBinds[u] & 0x30000) == 0 && // pl. 1 - (currentConfig.KeyBinds[u] & (1 << act))) keyc++; - for (u = 0; u < 28; u++) - if ((currentConfig.KeyBinds[u] & 0x30000) == 1 && // pl. 2 - (currentConfig.KeyBinds[u] & (1 << act))) keyc2++; - } - if (keyc > 1 || keyc2 > 1) - { - // loop again and mark those keys and actions as combo - for (u = 0; u < 28; u++) - { - if (currentConfig.KeyBinds[u] & (1 << act)) { - combo_keys |= 1 << u; - combo_acts |= 1 << act; - } - } - } - } -} - static void simpleWait(unsigned int until) { @@ -886,7 +848,7 @@ void emu_Loop(void) clearArea(1); Pico.m.dirtyPal = 1; oldmodes = ((Pico.video.reg[12]&1)<<2) ^ 0xc; - find_combos(); + emu_findKeyBindCombos(); // pal/ntsc might have changed, reset related stuff target_fps = Pico.m.pal ? 50 : 60; diff --git a/platform/psp/menu.c b/platform/psp/menu.c index b5f3203f..19151cc1 100644 --- a/platform/psp/menu.c +++ b/platform/psp/menu.c @@ -817,7 +817,7 @@ static void kc_sel_loop(void) 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; + sizeof(emuctrl_actions)/sizeof(emuctrl_actions[0]) - 1, -1); return; case 3: if (!rom_loaded) emu_WriteConfig(0); return; default: return; } -- 2.39.5