From ea17977c20e87b9ae058a4d9101c55405b828353 Mon Sep 17 00:00:00 2001 From: NewRisingSun <8vytz1+dhp372pv94ebg@sharklasers.com> Date: Sun, 14 Nov 2021 17:01:55 +0100 Subject: [PATCH] Mapper 319: Use hp898f.c only for the old incorrect UNIF bank order, and 319.c for all NES 2.0 ROMs. Add CNROM mode and solder pad switch to the latter. --- src/boards/319.c | 86 +++++++++++++++++++++++++++++++++++++++++++++ src/boards/57.c | 1 + src/boards/hp898f.c | 56 +++++++---------------------- src/ines.c | 2 +- src/ines.h | 1 + 5 files changed, 102 insertions(+), 44 deletions(-) create mode 100644 src/boards/319.c diff --git a/src/boards/319.c b/src/boards/319.c new file mode 100644 index 0000000..d7288b6 --- /dev/null +++ b/src/boards/319.c @@ -0,0 +1,86 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 CaH4e3 + * + * 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 + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include "mapinc.h" + +static uint8 reg[2]; +static uint8 latch; +static uint8 pad; + +static SFORMAT StateRegs[] = +{ + { reg, 2, "REG" }, + { &latch, 1, "LATC" }, + { &pad, 1, "PAD" }, + { 0 } +}; + +static void M319Sync (void) { + if (reg[1] &0x40) + setprg32(0x8000, reg[1] >>3 &3); + else + { + setprg16(0x8000, reg[1] >>2 &6 | reg[1] >>5 &1); + setprg16(0xC000, reg[1] >>2 &6 | reg[1] >>5 &1); + } + setchr8(reg[0] >>4 &~(reg[0] <<2 &4) | latch <<2 &(reg[0] <<2 &4)); + setmirror(reg[1] >>7); +} + +static void StateRestore(int version) { + M319Sync(); +} + +static DECLFR(M319ReadPad) { + return pad; +} + +static DECLFW(M319WriteReg) { + reg[A >>2 &1] =V; + M319Sync(); +} + +static DECLFW(M319WriteLatch) { + latch =V; + M319Sync(); +} + +static void M319Reset(void) { + reg[0] =reg[1] =latch =0; + pad ^=0x40; + M319Sync(); +} + +static void M319Power(void) { + reg[0] =reg[1] =latch =pad =0; + M319Sync(); + SetReadHandler(0x5000, 0x5FFF, M319ReadPad); + SetReadHandler(0x6000, 0xFFFF, CartBR); + SetWriteHandler(0x6000, 0x7FFF, M319WriteReg); + SetWriteHandler(0x8000, 0xFFFF, M319WriteLatch); +} + +void Mapper319_Init(CartInfo *info) { + info->Power = M319Power; + info->Reset = M319Reset; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/57.c b/src/boards/57.c index a2a7c8e..ffd6c8c 100644 --- a/src/boards/57.c +++ b/src/boards/57.c @@ -54,6 +54,7 @@ static DECLFW(M57Write) { } static void M57Power(void) { + regs[1] = regs[0] = 0; /* Always reset to menu */ hrd_flag = 1; /* YH-xxx "Olympic" multicarts disable the menu after one selection */ SetReadHandler(0x8000, 0xFFFF, CartBR); SetWriteHandler(0x8000, 0xFFFF, M57Write); diff --git a/src/boards/hp898f.c b/src/boards/hp898f.c index a3ace3f..43ba53d 100644 --- a/src/boards/hp898f.c +++ b/src/boards/hp898f.c @@ -20,45 +20,25 @@ #include "mapinc.h" +/* This source code file only applies to Sanchez' original UNIF file with the incorrect bank order. + The correctly-specified mapper, used for all NES 2.0 ROM files, is implemented in 319.c. */ + static uint8 regs[2]; -static uint8 _submapper = 0; static SFORMAT StateRegs[] = { { regs, 2, "REGS" }, - { &_submapper ,1, "SUBM"}, { 0 } }; -/* submapper 1 The code for the original fceux - * submapper 0 new HP898F code by dragon2snow,loong2snow from www.nesbbs.com - */ -static void Sync(void) { - - if (_submapper == 1) - { - uint8 chr = (regs[0] >> 4) & 7; - uint8 prg = (regs[1] >> 3) & 7; - uint8 dec = (regs[1] >> 4) & 4; - setchr8(chr & (~(((regs[0] & 1) << 2) | (regs[0] & 2)))); - setprg16(0x8000, prg & (~dec)); - setprg16(0xC000, prg | dec); - setmirror(regs[1] >> 7); - } - else - { - if (regs[1] & 0x40) - setprg32(0x8000, regs[1] >> 1); - else { - setprg16(0x8000, regs[1]); - setprg16(0xC000, regs[1]); - } - setchr8((regs[0] >> 4) &~(((regs[0] & 1) ? 4 : 0) | (regs[0] & 2))); - if (regs[1] & 0x80) - setmirror(1); - else - setmirror(0); - } +static void Sync(void) { + uint8 chr = (regs[0] >> 4) & 7; + uint8 prg = (regs[1] >> 3) & 7; + uint8 dec = (regs[1] >> 4) & 4; + setchr8(chr & (~(((regs[0] & 1) << 2) | (regs[0] & 2)))); + setprg16(0x8000, prg & (~dec)); + setprg16(0xC000, prg | dec); + setmirror(regs[1] >> 7); } static DECLFW(HP898FWrite) { @@ -78,17 +58,8 @@ static DECLFW(HP898FWriteEx) { static void HP898FPower(void) { regs[0] = regs[1] = 0; Sync(); - if (_submapper == 1) - { - SetReadHandler(0x8000, 0xFFFF, CartBR); - SetWriteHandler(0x6000, 0xFFFF, HP898FWrite); - } - else - { - SetReadHandler(0x8000, 0xFFFF, CartBR); - SetWriteHandler(0x6000, 0x7FFF, HP898FWriteEx); - SetWriteHandler(0xE000, 0xFFFF, HP898FWriteEx); - } + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x6000, 0xFFFF, HP898FWrite); } static void HP898FReset(void) { @@ -101,7 +72,6 @@ static void StateRestore(int version) { } void BMCHP898F_Init(CartInfo *info) { - _submapper = info->submapper; info->Reset = HP898FReset; info->Power = HP898FPower; GameStateRestore = StateRestore; diff --git a/src/ines.c b/src/ines.c index 4d3b8a7..795784f 100644 --- a/src/ines.c +++ b/src/ines.c @@ -758,7 +758,7 @@ INES_BOARD_BEGIN() INES_BOARD( "RESET-TXROM", 313, BMCRESETTXROM_Init ) INES_BOARD( "64in1NoRepeat", 314, BMC64in1nr_Init ) INES_BOARD( "830134C", 315, BMC830134C_Init ) - INES_BOARD( "HP898F", 319, BMCHP898F_Init ) + INES_BOARD( "HP898F", 319, Mapper319_Init ) INES_BOARD( "830425C-4391T", 320, BMC830425C4391T_Init ) INES_BOARD( "K-3033", 322, BMCK3033_Init ) INES_BOARD( "FARID_SLROM_8-IN-1", 323, FARIDSLROM8IN1_Init ) diff --git a/src/ines.h b/src/ines.h index 1d4278d..6f36333 100644 --- a/src/ines.h +++ b/src/ines.h @@ -260,6 +260,7 @@ void Mapper269_Init(CartInfo *); void Mapper288_Init(CartInfo *); void Mapper293_Init(CartInfo *); void Mapper297_Init(CartInfo *); +void Mapper319_Init(CartInfo *); void Mapper353_Init(CartInfo *); void Mapper356_Init(CartInfo *); void Mapper357_Init(CartInfo *);