From 9877d3e2277effc98f9db2c4574bebb0233e8bee Mon Sep 17 00:00:00 2001 From: NewRisingSun <8vytz1+dhp372pv94ebg@sharklasers.com> Date: Mon, 27 Mar 2023 21:24:28 +0200 Subject: [PATCH] M227/242/449: Added DIP switch. --- src/boards/449.c | 17 ++++++++++++++--- src/boards/addrlatch.c | 36 ++++++++++++++++++++++++++++++++++-- 2 files changed, 48 insertions(+), 5 deletions(-) diff --git a/src/boards/449.c b/src/boards/449.c index f07ebb4..72e4b4c 100644 --- a/src/boards/449.c +++ b/src/boards/449.c @@ -23,12 +23,14 @@ static uint16 latchAddr; static uint8 latchData; static uint8 dipswitch; +static uint8 dipselect; static SFORMAT StateRegs[] = { { &latchAddr, 2, "ADDR" }, { &latchData, 1, "DATA" }, { &latchData, 1, "DIPS" }, + { &dipselect, 1, "DSEL" }, { 0 } }; @@ -58,12 +60,20 @@ static void Mapper449_Sync(void) static DECLFR(Mapper449_Read) { + if (dipselect) + return dipswitch &0x3; + else if (latchAddr &0x200) - return CartBR(A | dipswitch); + return CartBR(A | dipswitch &0xF); else return CartBR(A); } +static DECLFW(Mapper449_WriteDIPSelect) +{ + dipselect =V &1; +} + static DECLFW(Mapper449_WriteLatch) { latchData =V; @@ -73,15 +83,16 @@ static DECLFW(Mapper449_WriteLatch) static void Mapper449_Reset(void) { - dipswitch =(dipswitch +1) &0xF; + dipswitch++; latchAddr =latchData =0; Mapper449_Sync(); } static void Mapper449_Power(void) { - dipswitch =latchAddr =latchData =0; + dipselect =dipswitch =latchAddr =latchData =0; Mapper449_Sync(); + SetWriteHandler(0x6000, 0x7FFF, Mapper449_WriteDIPSelect); SetWriteHandler(0x8000, 0xFFFF, Mapper449_WriteLatch); SetReadHandler(0x6000, 0x7FFF, CartBR); SetReadHandler(0x8000, 0xFFFF, Mapper449_Read); diff --git a/src/boards/addrlatch.c b/src/boards/addrlatch.c index 4cf0df1..a86d426 100644 --- a/src/boards/addrlatch.c +++ b/src/boards/addrlatch.c @@ -415,9 +415,25 @@ static void M227Sync(void) { setprg8r(0x10, 0x6000, 0); } +static DECLFR(M227Read) { + if (latche &0x0400) + return CartBR(A | dipswitch); + else + return CartBR(A); +} + +static void Mapper227_Reset(void) { + dipswitch++; + dipswitch &= 15; + latche = 0; + M227Sync(); +} + void Mapper227_Init(CartInfo *info) { submapper =info->submapper; - Latch_Init(info, M227Sync, NULL, 0x0000, 0x8000, 0xFFFF, 1); + Latch_Init(info, M227Sync, M227Read, 0x0000, 0x8000, 0xFFFF, info->iNES2 && (info->PRGRamSize || info->PRGRamSaveSize) || info->battery); + info->Reset = Mapper227_Reset; + AddExState(&dipswitch, 1, 0, "DIPSW"); } /*------------------ Map 229 ---------------------------*/ @@ -511,9 +527,25 @@ static void M242Sync(void) { setprg8r(0x10, 0x6000, 0); } +static DECLFR(M242Read) { + if (latche &0x0100) + return CartBR(A | dipswitch); + else + return CartBR(A); +} + +static void Mapper242_Reset(void) { + dipswitch++; + dipswitch &= 31; + latche = 0; + M242Sync(); +} + void Mapper242_Init(CartInfo *info) { M242TwoChips = info->PRGRomSize &0x20000 && info->PRGRomSize >0x20000; - Latch_Init(info, M242Sync, NULL, 0x0000, 0x8000, 0xFFFF, 1); + Latch_Init(info, M242Sync, M242Read, 0x0000, 0x8000, 0xFFFF, info->iNES2 && (info->PRGRamSize || info->PRGRamSaveSize) || info->battery); + info->Reset = Mapper242_Reset; + AddExState(&dipswitch, 1, 0, "DIPSW"); } /*------------------ Map 288 ---------------------------*/