From f6b5f60399ee06e3f9ced96d2a8b3635b46ea212 Mon Sep 17 00:00:00 2001 From: NewRisingSun <8vytz1+dhp372pv94ebg@sharklasers.com> Date: Thu, 29 Dec 2022 23:12:47 +0100 Subject: [PATCH] Add submapper 1 to mapper 452 --- src/boards/452.c | 108 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 73 insertions(+), 35 deletions(-) diff --git a/src/boards/452.c b/src/boards/452.c index 5b8b3c9..bd83f51 100644 --- a/src/boards/452.c +++ b/src/boards/452.c @@ -18,44 +18,85 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ - + /* DS-9-27. Absolutely insane PCB that overlays 8 KiB of WRAM into a selectable position between $8000 and $E000. */ - + #include "mapinc.h" static uint8 *WRAM; static uint32 WRAMSIZE; static uint16 latch[2]; +static uint8 submapper; +static void SetWRAM(uint16 A) { + setprg8r(0x10, A, 0); + SetWriteHandler(A, A |0x1FFF, CartBW); +} + +static DECLFW(Mapper452_WriteLatch); static void Mapper452_Sync(void) { - uint8 wramBank = latch[1] >>3 &6 |8; - if (latch[1] &2) { - setprg8(0x8000, latch[0] >>1); - setprg8(0xA000, latch[0] >>1); - setprg8(0xC000, latch[0] >>1); - setprg8(0xE000, latch[0] >>1); - setprg8r(0x10, (wramBank ^4) <<12, 0); - } else - if (latch[1] &8) { - setprg8(0x8000, latch[0] >>1 &~1 |0); - setprg8(0xA000, latch[0] >>1 &~1 |1); - setprg8(0xC000, latch[0] >>1 &~1 |2); - setprg8(0xE000, latch[0] >>1 &~1 |3 | latch[1] &4 | (latch[1] &0x04 && latch[1] &0x40? 8: 0)); + SetWriteHandler(0x8000, 0xFFFF, Mapper452_WriteLatch); + if (submapper ==1) { + switch(latch[0] &0xF000) { + case 0xA000: + setprg16(0x8000, latch[0] >>1); + setprg8 (0xC000, 0); + SetWRAM(latch[0] <<4 &0x6000 |0x8000); + break; + case 0xC000: + setprg16(0x8000, latch[0] >>1 |0); + setprg16(0xC000, latch[0] >>1 |1); + SetWRAM(latch[0] <<4 &0x6000 |0x8000); + break; + case 0xD000: + setprg8(0x8000, latch[0]); + setprg8(0xA000, latch[0]); + setprg8(0xC000, latch[0]); + setprg8(0xE000, latch[0]); + SetWRAM(latch[0] <<4 &0x2000 |0x8000); + SetWRAM(latch[0] <<4 &0x2000 |0xC000); + break; + case 0xE000: + setprg16(0x8000, latch[0] >>1); + setprg16(0xC000, latch[0] &0x100? (latch[0] >>1 |7): 0); + SetWRAM(latch[0] <<4 &0x6000 |0x8000); + break; + default: + setprg16(0x8000, latch[0] >>1); + setprg16(0xC000, 0); + break; + } + setchr8(0); + setmirror(latch[0] &0x800? MI_H: MI_V); } else { - setprg16(0x8000, latch[0] >>2); - setprg16(0xC000, 0); + uint8 wramBank = latch[1] >>3 &6 |8; + if (latch[1] &2) { + setprg8(0x8000, latch[0] >>1); + setprg8(0xA000, latch[0] >>1); + setprg8(0xC000, latch[0] >>1); + setprg8(0xE000, latch[0] >>1); + SetWRAM((wramBank ^4) <<12); + } else + if (latch[1] &8) { + setprg8(0x8000, latch[0] >>1 &~1 |0); + setprg8(0xA000, latch[0] >>1 &~1 |1); + setprg8(0xC000, latch[0] >>1 &~1 |2); + setprg8(0xE000, latch[0] >>1 &~1 |3 | latch[1] &4 | (latch[1] &0x04 && latch[1] &0x40? 8: 0)); + } else { + setprg16(0x8000, latch[0] >>2); + setprg16(0xC000, 0); + } + SetWRAM(wramBank <<12); + setchr8(0); + setmirror(latch [1] &1 ^1); } - setprg8r(0x10, wramBank <<12, 0); - setchr8(0); - setmirror(latch [1] &1 ^1); - } static DECLFW(Mapper452_WriteLatch) { - latch[0] =A &0xFFF; + CartBW(A, V); + latch[0] =A &0xFFFF; latch[1] =V; Mapper452_Sync(); - /* Do not relay to CartBW, as RAM mapped to locations other than $8000-$DFFF are not write-enabled. */ } static void Mapper452_Reset(void) { @@ -64,35 +105,32 @@ static void Mapper452_Reset(void) { } static void Mapper452_Power(void) { - latch[0] =latch[1] =0; + SetReadHandler(0x6000, 0xFFFF, CartBR); Mapper452_Sync(); - SetReadHandler(0x8000, 0xFFFF, CartBR); - SetWriteHandler(0x8000, 0xDFFF, Mapper452_WriteLatch); - SetWriteHandler(0xE000, 0xFFFF, CartBW); - FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); } static void Mapper452_Close(void) { - if (WRAM) - FCEU_gfree(WRAM); - WRAM = NULL; + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; } static void StateRestore(int version) { - Mapper452_Sync(); + Mapper452_Sync(); } void Mapper452_Init(CartInfo *info) { + submapper =info->submapper; info->Reset = Mapper452_Reset; info->Power = Mapper452_Power; info->Close = Mapper452_Close; GameStateRestore = StateRestore; - WRAMSIZE = 8192; - WRAM = (uint8*) FCEU_gmalloc(WRAMSIZE); + WRAMSIZE =8192; + WRAM =(uint8*) FCEU_gmalloc(WRAMSIZE); SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); AddExState(WRAM, WRAMSIZE, 0, "WRAM"); - AddExState(&latch, 4, 0, "LATC"); }