From a12b1b29cc7e394128da59614c2efe8f5d182741 Mon Sep 17 00:00:00 2001 From: notaz Date: Fri, 7 Mar 2008 19:05:37 +0000 Subject: [PATCH] 12-in-1 + realtec mapper git-svn-id: file:///home/notaz/opt/svn/PicoDrive@374 be3aeb3a-fb24-0410-a615-afba39da0efa --- Pico/Cart.c | 25 ++++++++--- Pico/Pico.c | 7 +-- Pico/Pico.h | 2 +- Pico/carthw/carthw.c | 100 ++++++++++++++++++++++++++++++++++++++++--- Pico/carthw/carthw.h | 4 +- 5 files changed, 122 insertions(+), 16 deletions(-) diff --git a/Pico/Cart.c b/Pico/Cart.c index 6eb7fc7..52f5cf5 100644 --- a/Pico/Cart.c +++ b/Pico/Cart.c @@ -521,9 +521,12 @@ int PicoCartInsert(unsigned char *rom,unsigned int romsize) return PicoReset(1); } -int PicoUnloadCart(unsigned char* romdata) +int PicoCartUnload(void) { - free(romdata); + if (Pico.rom != NULL) { + free(Pico.rom); + Pico.rom=NULL; + } return 0; } @@ -542,7 +545,10 @@ static int name_cmp(const char *name) return rom_strcmp(0x150, name); } -/* various cart-specific things, which can't be handled by generic code */ +/* + * various cart-specific things, which can't be handled by generic code + * (maybe I should start using CRC for this stuff?) + */ void PicoCartDetect(void) { int sram_size = 0, csum; @@ -647,13 +653,22 @@ void PicoCartDetect(void) PicoSVPStartup(); } - // Detect 4-in-1 and 12-in-1 + // Detect 12-in-1 mapper else if ((name_cmp("ROBOCOP 3") && Pico.romsize == 0x200000) || - (rom_strcmp(0x160, "FLICKY") && Pico.romsize == 0x200000)) + (rom_strcmp(0x160, "FLICKY") && 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 + { + carthw_realtec_startup(); + } + // Some games malfunction if SRAM is not filled with 0xff if (name_cmp("DINO DINI'S SOCCER") == 0 || name_cmp("MICRO MACHINES II") == 0) diff --git a/Pico/Pico.c b/Pico/Pico.c index c47cf19..a76c9e4 100644 --- a/Pico/Pico.c +++ b/Pico/Pico.c @@ -64,6 +64,9 @@ int PicoReset(int hard) if (Pico.romsize<=0) return 1; + /* must call now, so that banking is reset, and correct vectors get fetched */ + if (PicoResetHook) PicoResetHook(); + PicoMemReset(); SekReset(); // s68k doesn't have the TAS quirk, so we just globally set normal TAS handler in MCD mode (used by Batman games). @@ -79,7 +82,7 @@ int PicoReset(int hard) Pico.video.pending_ints=0; emustatus = 0; - if(hard) { + if (hard) { // clear all memory of the emulated machine memset(&Pico.ram,0,(unsigned int)&Pico.rom-(unsigned int)&Pico.ram); } @@ -142,8 +145,6 @@ int PicoReset(int hard) PsndReset(); // pal must be known here - if (PicoResetHook) PicoResetHook(); - if (PicoMCD & 1) { PicoResetMCD(hard); return 0; diff --git a/Pico/Pico.h b/Pico/Pico.h index f3db4a3..52ea63e 100644 --- a/Pico/Pico.h +++ b/Pico/Pico.h @@ -103,7 +103,7 @@ int pm_close(pm_file *fp); int PicoCartLoad(pm_file *f,unsigned char **prom,unsigned int *psize); int PicoCartInsert(unsigned char *rom,unsigned int romsize); void Byteswap(unsigned char *data,int len); -int PicoUnloadCart(unsigned char* romdata); +int PicoCartUnload(void); extern void (*PicoCartLoadProgressCB)(int percent); extern void (*PicoCDLoadProgressCB)(int percent); diff --git a/Pico/carthw/carthw.c b/Pico/carthw/carthw.c index 1e92e86..c3e80f8 100644 --- a/Pico/carthw/carthw.c +++ b/Pico/carthw/carthw.c @@ -1,6 +1,12 @@ +/* + * should better do some pointer stuff here. But as none of these bankswitch + * while the game runs, memcpy will suffice. + */ + #include "../PicoInt.h" -/* 12-in-1 */ + +/* 12-in-1 and 4-in-1. Assuming 2MB ROMs here. */ static unsigned int carthw_12in1_read16(unsigned int a, int realsize) { // ?? @@ -13,7 +19,11 @@ static void carthw_12in1_write8(unsigned int a, unsigned int d, int realsize) int len; if (a < 0xA13000 || a >= 0xA13040) { - elprintf(EL_ANOMALY, "12-in-1: unexpected write [%06x] %02x @ %06x", a, d, SekPc); + /* 4-in-1 has Real Deal Boxing, which uses serial eeprom, + * but I really doubt that pirate cart had it */ + if (a != 0x200001) + elprintf(EL_ANOMALY, "12-in-1: unexpected write [%06x] %02x @ %06x", a, d, SekPc); + return; } a &= 0x3f; a <<= 16; @@ -23,7 +33,7 @@ static void carthw_12in1_write8(unsigned int a, unsigned int d, int realsize) return; } - memcpy(Pico.rom, Pico.rom + 0x200000 + a, len); + memcpy(Pico.rom, Pico.rom + Pico.romsize + a, len); } static void carthw_12in1_reset(void) @@ -37,16 +47,96 @@ void carthw_12in1_startup(void) elprintf(EL_STATUS, "12-in-1 mapper detected"); - tmp = realloc(Pico.rom, 0x200000 + 0x200000); + tmp = realloc(Pico.rom, Pico.romsize * 2); if (tmp == NULL) { elprintf(EL_STATUS, "OOM"); return; } - memcpy(Pico.rom + 0x200000, Pico.rom, 0x200000); + Pico.rom = tmp; + memcpy(Pico.rom + Pico.romsize, Pico.rom, Pico.romsize); PicoRead16Hook = carthw_12in1_read16; PicoWrite8Hook = carthw_12in1_write8; PicoResetHook = carthw_12in1_reset; } + +/* Realtec, based on TascoDLX doc + * http://www.sharemation.com/TascoDLX/REALTEC%20Cart%20Mapper%20-%20description%20v1.txt + */ +static int realtec_bank = 0x80000000, realtec_size = 0x80000000; +static int realtec_romsize = 0; + +static void carthw_realtec_write8(unsigned int a, unsigned int d, int realsize) +{ + int i, bank_old = realtec_bank, size_old = realtec_size; + + if (a == 0x400000) + { + realtec_bank &= 0x0e0000; + realtec_bank |= 0x300000 & (d << 19); + if (realtec_bank != bank_old) + elprintf(EL_ANOMALY, "write [%06x] %02x @ %06x", a, d, SekPc); + } + else if (a == 0x402000) + { + realtec_size = (d << 17) & 0x3e0000; + if (realtec_size != size_old) + elprintf(EL_ANOMALY, "write [%06x] %02x @ %06x", a, d, SekPc); + } + else if (a == 0x404000) + { + realtec_bank &= 0x300000; + realtec_bank |= 0x0e0000 & (d << 17); + if (realtec_bank != bank_old) + elprintf(EL_ANOMALY, "write [%06x] %02x @ %06x", a, d, SekPc); + } + else + elprintf(EL_ANOMALY, "realtec: unexpected write [%06x] %02x @ %06x", a, d, SekPc); + + if (realtec_bank >= 0 && realtec_size >= 0 && + (realtec_bank != bank_old || realtec_size != size_old)) + { + elprintf(EL_ANOMALY, "realtec: new bank %06x, size %06x", realtec_bank, realtec_size, SekPc); + if (realtec_size > realtec_romsize - realtec_bank || realtec_bank >= realtec_romsize) + { + elprintf(EL_ANOMALY, "realtec: bank too large / out of range?"); + return; + } + + for (i = 0; i < 0x400000; i += realtec_size) + memcpy(Pico.rom + i, Pico.rom + 0x400000 + realtec_bank, realtec_size); + } +} + +void carthw_realtec_reset(void) +{ + int i; + /* map boot code */ + for (i = 0; i < 0x400000; i += 0x2000) + memcpy(Pico.rom + i, Pico.rom + 0x400000 + realtec_romsize - 0x2000, 0x2000); + realtec_bank = realtec_size = 0x80000000; +} + +void carthw_realtec_startup(void) +{ + void *tmp; + + elprintf(EL_STATUS, "Realtec mapper detected"); + + realtec_romsize = Pico.romsize; + Pico.romsize = 0x400000; + tmp = realloc(Pico.rom, 0x400000 + realtec_romsize); + if (tmp == NULL) + { + elprintf(EL_STATUS, "OOM"); + return; + } + Pico.rom = tmp; + memcpy(Pico.rom + 0x400000, Pico.rom, realtec_romsize); + + PicoWrite8Hook = carthw_realtec_write8; + PicoResetHook = carthw_realtec_reset; +} + diff --git a/Pico/carthw/carthw.h b/Pico/carthw/carthw.h index 3138168..29ec7b6 100644 --- a/Pico/carthw/carthw.h +++ b/Pico/carthw/carthw.h @@ -17,6 +17,6 @@ unsigned int PicoSVPRead16(unsigned int a, int realsize); void PicoSVPWrite8 (unsigned int a, unsigned int d, int realsize); void PicoSVPWrite16(unsigned int a, unsigned int d, int realsize); -/* 12-in-1 */ +/* misc */ void carthw_12in1_startup(void); - +void carthw_realtec_startup(void); -- 2.39.2