From 2d55ac5532452ec80b9ab256bce3796180d8cdaf Mon Sep 17 00:00:00 2001 From: NewRisingSun <8vytz1+dhp372pv94ebg@sharklasers.com> Date: Tue, 9 Sep 2025 10:57:02 +0200 Subject: [PATCH] Mapper 449: Distinguish three circuit boards that differ in their menu selection mechanism via submapper. --- src/boards/449.c | 129 ++++++++++++++++++++--------------------------- 1 file changed, 56 insertions(+), 73 deletions(-) diff --git a/src/boards/449.c b/src/boards/449.c index 72e4b4c..6fcefc2 100644 --- a/src/boards/449.c +++ b/src/boards/449.c @@ -1,7 +1,7 @@ -/* FCEUmm - NES/Famicom Emulator +/* FCE Ultra - NES/Famicom Emulator * * Copyright notice for this file: - * Copyright (C) 2022 + * Copyright (C) 2025 NewRisingSun * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,88 +19,71 @@ */ #include "mapinc.h" +#include "asic_latch.h" -static uint16 latchAddr; -static uint8 latchData; -static uint8 dipswitch; -static uint8 dipselect; +uint8 submapper; +uint8 pad; +uint8 padSelect; -static SFORMAT StateRegs[] = -{ - { &latchAddr, 2, "ADDR" }, - { &latchData, 1, "DATA" }, - { &latchData, 1, "DIPS" }, - { &dipselect, 1, "DSEL" }, - { 0 } -}; - -static void Mapper449_Sync(void) -{ - int prg =latchAddr >>2 &0x1F | latchAddr >>3 &0x20; - if (~latchAddr &0x080) - { - setprg16(0x8000, prg); - setprg16(0xC000, prg |7); - } - else - { - if (latchAddr &0x001) - { - setprg32(0x8000, prg >>1); - } - else - { - setprg16(0x8000, prg); - setprg16(0xC000, prg); - } - } - setchr8(latchData); - setmirror(latchAddr &0x002? MI_H: MI_V); +static DECLFR(readPad_submapper0) { + return CartBR(A &~0xF | pad &0xF); } -static DECLFR(Mapper449_Read) -{ - if (dipselect) - return dipswitch &0x3; - else - if (latchAddr &0x200) - return CartBR(A | dipswitch &0xF); - else - return CartBR(A); +static DECLFR(readPad_submapper1) { + return pad; } -static DECLFW(Mapper449_WriteDIPSelect) -{ - dipselect =V &1; +static DECLFR(readPad_submapper2) { + return CartBR(A &~0x3 | pad &0x3); } -static DECLFW(Mapper449_WriteLatch) -{ - latchData =V; - latchAddr =A &0xFFFF; - Mapper449_Sync(); +static void sync () { + int prg = Latch_address >>2 &0x1F | Latch_address >>3 &0x20 | Latch_address >>4 &0x40; + if (Latch_address &0x080) { + if (Latch_address &0x001) + setprg32(0x8000, prg >>1); + else { + setprg16(0x8000, prg); + setprg16(0xC000, prg); + } + setmirror(Latch_data &0x10? MI_1: MI_0); + } else { + setprg16(0x8000, prg); + setprg16(0xC000, prg | 7); + } + SetupCartCHRMapping(0, CHRptr[0], CHRsize[0], submapper == 0 && Latch_address &0x80? 0: 1); + setchr8(Latch_data); + setmirror(Latch_address &0x002? MI_H: MI_V); + SetReadHandler(0x8000, 0xFFFF, submapper == 0 && Latch_address &0x200? readPad_submapper0: submapper == 2 && padSelect &1? readPad_submapper2: CartBR); } -static void Mapper449_Reset(void) -{ - dipswitch++; - latchAddr =latchData =0; - Mapper449_Sync(); +static DECLFW(writePad_submapper2) { + padSelect = V; + sync(); } -static void Mapper449_Power(void) -{ - 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); +static void power () { + pad = padSelect = 0; + Latch_power(); + if (submapper == 1) + SetReadHandler(0x5000, 0x5FFF, readPad_submapper1); + else + if (submapper == 2) + SetWriteHandler(0x6000, 0x7FFF, writePad_submapper2); } -void Mapper449_Init(CartInfo *info) -{ - info->Power = Mapper449_Power; - info->Reset = Mapper449_Reset; - AddExState(StateRegs, ~0, 0, 0); -} \ No newline at end of file +static void reset () { + pad++; + padSelect = 0; + Latch_address = 0; + sync(); +} + +void Mapper449_Init (CartInfo *info) { + submapper = info->submapper; + Latch_init(info, sync, 0x8000, 0xFFFF, NULL); + info->Power = power; + info->Reset = reset; + AddExState(&pad, 1, 0, "DIPS"); + if (submapper == 2) AddExState(&padSelect, 1, 0, "DIPE"); +}