From: notaz Date: Sun, 30 Mar 2008 20:24:17 +0000 (+0000) Subject: reset behavior changed, Puggsy detection added X-Git-Tag: v1.85~526 X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1cb1584b86a5679b8d32ccfc190f6e76c920810f;p=picodrive.git reset behavior changed, Puggsy detection added git-svn-id: file:///home/notaz/opt/svn/PicoDrive@405 be3aeb3a-fb24-0410-a615-afba39da0efa --- diff --git a/Pico/Cart.c b/Pico/Cart.c index 47ea1cca..f2683ca8 100644 --- a/Pico/Cart.c +++ b/Pico/Cart.c @@ -530,7 +530,8 @@ int PicoCartInsert(unsigned char *rom,unsigned int romsize) else PicoMemSetup(); PicoMemReset(); - return PicoReset(1); + PicoPower(); + return 0; } int PicoCartUnload(void) @@ -597,6 +598,12 @@ static void PicoCartDetect(void) sram_size = 0x004000; } + // this game actually doesn't have SRAM, but some weird protection + if (rom_strcmp(0x120, "PUGGSY") == 0) + { + SRam.start = SRam.end = sram_size = 0; + } + if (sram_size) { SRam.data = (unsigned char *) calloc(sram_size, 1); diff --git a/Pico/Pico.c b/Pico/Pico.c index 2ebe9c9b..7978fede 100644 --- a/Pico/Pico.c +++ b/Pico/Pico.c @@ -52,10 +52,32 @@ void PicoExit(void) PicoExitMCD(); z80_exit(); - if(SRam.data) free(SRam.data); SRam.data=0; + if (SRam.data) free(SRam.data); SRam.data=0; } -int PicoReset(int hard) +void PicoPower(void) +{ + // clear all memory of the emulated machine + memset(&Pico.ram,0,(unsigned int)&Pico.rom-(unsigned int)&Pico.ram); + + memset(&Pico.video,0,sizeof(Pico.video)); + memset(&Pico.m,0,sizeof(Pico.m)); + + Pico.video.pending_ints=0; + z80_reset(); + + // default VDP register values (based on Fusion) + Pico.video.reg[0] = Pico.video.reg[1] = 0x04; + Pico.video.reg[0xc] = 0x81; + Pico.video.reg[0xf] = 0x02; + + if (PicoMCD & 1) + PicoPowerMCD(); + + PicoReset(); +} + +int PicoReset(void) { unsigned int region=0; int support=0,hw=0,i=0; @@ -72,25 +94,12 @@ int PicoReset(int hard) // s68k doesn't have the TAS quirk, so we just globally set normal TAS handler in MCD mode (used by Batman games). SekSetRealTAS(PicoMCD & 1); SekCycleCntT=0; - z80_reset(); - // reset VDP state, VRAM and PicoMisc - //memset(&Pico.video,0,sizeof(Pico.video)); - //memset(&Pico.vram,0,sizeof(Pico.vram)); - memset(Pico.ioports,0,sizeof(Pico.ioports)); // needed for MCD to reset properly - memset(&Pico.m,0,sizeof(Pico.m)); - Pico.video.pending_ints=0; + if (PicoMCD & 1) + // needed for MCD to reset properly, probably some bug hides behind this.. + memset(Pico.ioports,0,sizeof(Pico.ioports)); emustatus = 0; - if (hard) { - // clear all memory of the emulated machine - memset(&Pico.ram,0,(unsigned int)&Pico.rom-(unsigned int)&Pico.ram); - } - - // default VDP register values (based on Fusion) - Pico.video.reg[0] = Pico.video.reg[1] = 0x04; - Pico.video.reg[0xc] = 0x81; - Pico.video.reg[0xf] = 0x02; Pico.m.dirtyPal = 1; if(PicoRegionOverride) @@ -141,12 +150,16 @@ int PicoReset(int hard) Pico.m.hardware=(unsigned char)(hw|0x20); // No disk attached Pico.m.pal=pal; - Pico.video.status = 0x3408 | pal; // always set bits | vblank | pal + Pico.video.status = 0x3408 | pal; // 'always set' bits | vblank | pal PsndReset(); // pal must be known here + // create an empty "dma" to cause 68k exec start at random frame location + if (Pico.m.dma_xfers == 0 && !(PicoOpt&0x10000)) + Pico.m.dma_xfers = rand() & 0x1fff; + if (PicoMCD & 1) { - PicoResetMCD(hard); + PicoResetMCD(); return 0; } diff --git a/Pico/Pico.h b/Pico/Pico.h index 9dae8dfe..946d98ef 100644 --- a/Pico/Pico.h +++ b/Pico/Pico.h @@ -43,7 +43,8 @@ extern int PicoAutoRgnOrder; // packed priority list of regions, for example 0x1 extern int PicoSVPCycles; int PicoInit(void); void PicoExit(void); -int PicoReset(int hard); +void PicoPower(void); +int PicoReset(void); int PicoFrame(void); void PicoFrameDrawOnly(void); extern int PicoPad[2]; // Joypads, format is MXYZ SACB RLDU diff --git a/Pico/PicoInt.h b/Pico/PicoInt.h index 06a50a03..cd4d00e8 100644 --- a/Pico/PicoInt.h +++ b/Pico/PicoInt.h @@ -425,7 +425,8 @@ PICO_INTERNAL int CheckDMA(void); // cd/Pico.c PICO_INTERNAL int PicoInitMCD(void); PICO_INTERNAL void PicoExitMCD(void); -PICO_INTERNAL int PicoResetMCD(int hard); +PICO_INTERNAL void PicoPowerMCD(void); +PICO_INTERNAL int PicoResetMCD(void); PICO_INTERNAL int PicoFrameMCD(void); // Sek.c diff --git a/Pico/cd/Pico.c b/Pico/cd/Pico.c index 9d028b49..02cad9b5 100644 --- a/Pico/cd/Pico.c +++ b/Pico/cd/Pico.c @@ -48,16 +48,18 @@ PICO_INTERNAL void PicoExitMCD(void) //dump_ram(Pico.ram, "ram.bin"); } -PICO_INTERNAL int PicoResetMCD(int hard) +PICO_INTERNAL void PicoPowerMCD(void) +{ + int fmt_size = sizeof(formatted_bram); + memset(Pico_mcd->prg_ram, 0, sizeof(Pico_mcd->prg_ram)); + memset(Pico_mcd->word_ram2M, 0, sizeof(Pico_mcd->word_ram2M)); + memset(Pico_mcd->pcm_ram, 0, sizeof(Pico_mcd->pcm_ram)); + memset(Pico_mcd->bram, 0, sizeof(Pico_mcd->bram)); + memcpy(Pico_mcd->bram + sizeof(Pico_mcd->bram) - fmt_size, formatted_bram, fmt_size); +} + +PICO_INTERNAL int PicoResetMCD(void) { - if (hard) { - int fmt_size = sizeof(formatted_bram); - memset(Pico_mcd->prg_ram, 0, sizeof(Pico_mcd->prg_ram)); - memset(Pico_mcd->word_ram2M, 0, sizeof(Pico_mcd->word_ram2M)); - memset(Pico_mcd->pcm_ram, 0, sizeof(Pico_mcd->pcm_ram)); - memset(Pico_mcd->bram, 0, sizeof(Pico_mcd->bram)); - memcpy(Pico_mcd->bram + sizeof(Pico_mcd->bram) - fmt_size, formatted_bram, fmt_size); - } memset(Pico_mcd->s68k_regs, 0, sizeof(Pico_mcd->s68k_regs)); memset(&Pico_mcd->pcm, 0, sizeof(Pico_mcd->pcm)); memset(&Pico_mcd->m, 0, sizeof(Pico_mcd->m)); diff --git a/platform/common/emu.c b/platform/common/emu.c index c2e4075d..14cc52ae 100644 --- a/platform/common/emu.c +++ b/platform/common/emu.c @@ -434,7 +434,7 @@ int emu_ReloadRom(void) } else { PicoRegionOverride = 4; } - PicoReset(0); + PicoReset(); // TODO: bits 6 & 5 } movie_data[0x18+30] = 0; diff --git a/platform/gizmondo/emu.c b/platform/gizmondo/emu.c index 523da879..b9116068 100644 --- a/platform/gizmondo/emu.c +++ b/platform/gizmondo/emu.c @@ -775,7 +775,7 @@ void emu_Loop(void) void emu_ResetGame(void) { - PicoReset(0); + PicoReset(); reset_timing = 1; } diff --git a/platform/gp2x/emu.c b/platform/gp2x/emu.c index f2867fc9..05d22f68 100644 --- a/platform/gp2x/emu.c +++ b/platform/gp2x/emu.c @@ -977,7 +977,7 @@ void emu_Loop(void) void emu_ResetGame(void) { - PicoReset(0); + PicoReset(); reset_timing = 1; } diff --git a/platform/psp/emu.c b/platform/psp/emu.c index acbe643b..99d16dae 100644 --- a/platform/psp/emu.c +++ b/platform/psp/emu.c @@ -1022,7 +1022,7 @@ void emu_Loop(void) void emu_ResetGame(void) { - PicoReset(0); + PicoReset(); reset_timing = 1; } diff --git a/platform/uiq2/SimpleServer.cpp b/platform/uiq2/SimpleServer.cpp index 6a58306d..d220b3fd 100644 --- a/platform/uiq2/SimpleServer.cpp +++ b/platform/uiq2/SimpleServer.cpp @@ -114,7 +114,7 @@ void CPicoServSession::DispatchMessageL(const RMessage &aMessage) case PicoMsgReset: if(rom_data) { - PicoReset(0); + PicoReset(); pico_was_reset = 1; gamestate = PGS_Running; } diff --git a/platform/uiq3/Engine.cpp b/platform/uiq3/Engine.cpp index 08b81246..5e21b913 100644 --- a/platform/uiq3/Engine.cpp +++ b/platform/uiq3/Engine.cpp @@ -63,7 +63,7 @@ TInt CPicoGameSession::Do(const TPicoServRqst what, TAny *param) case PicoMsgReset: if(rom_data) { - PicoReset(0); + PicoReset(); pico_was_reset = 1; return ChangeRunState(PGS_Running); } diff --git a/platform/win32/GenaDrive/Input.cpp b/platform/win32/GenaDrive/Input.cpp index 92abe2b0..86fa94f5 100644 --- a/platform/win32/GenaDrive/Input.cpp +++ b/platform/win32/GenaDrive/Input.cpp @@ -92,7 +92,7 @@ static int DeviceRead() static int sblobked = 0; if (!sblobked && GetAsyncKeyState(VK_TAB)) { - PicoReset(0); + PicoReset(); sblobked = 1; } else if (!sblobked && GetAsyncKeyState(VK_ESCAPE))