diff --git a/src/boards/285.c b/src/boards/285.c new file mode 100644 index 0000000..9c90393 --- /dev/null +++ b/src/boards/285.c @@ -0,0 +1,78 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * 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 + * 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" +#include "asic_latch.h" + +static uint8 pad; + +static void sync_submapper0 () { + if (Latch_data &0x40) + setprg32(0x8000, Latch_data >>1); + else { + setprg16(0x8000, Latch_data); + setprg16(0xC000, Latch_data |7); + } + setchr8(0); + if (Latch_data &0x80) + setmirror(Latch_data &0x20? MI_1: MI_0); + else + setmirror(Latch_data &0x20? MI_H: MI_V); +} + +static void sync_submapper1 () { + if (Latch_data &0x40) + setprg32(0x8000, Latch_data >>1 &0x03 | Latch_data >>2 &~0x03); + else { + setprg16(0x8000, Latch_data >>1 &~0x07 | Latch_data &0x07); + setprg16(0xC000, Latch_data >>1 | 0x07); + } + setchr8(0); + if (Latch_data &0x80) + setmirror(Latch_data &0x20? MI_1: MI_0); + else + setmirror(Latch_data &0x08? MI_H: MI_V); +} + +static DECLFR (readPad) { + if (A &0x80) return pad >= 20? (4 | pad % 20): 0; else + if (A &0x40) return pad >= 16? (4 | pad % 16): 0; else + if (A &0x20) return pad >= 12? (4 | pad % 12): 0; else + if (A &0x10) return pad >= 8? (4 | pad % 8): 0; else + return pad >= 8? 0: pad &7; +} + +static void power() { + pad = 0; + Latch_power(); + SetReadHandler(0x5000, 0x5FFF, readPad); +} + +static void reset() { + pad = ++pad %24; + Latch_clear(); +} + +void Mapper285_Init (CartInfo *info) { + Latch_init(info, info->submapper ==1? sync_submapper1: sync_submapper0, 0x8000, 0xFFFF, NULL); + info->Power = power; + info->Reset = reset; + AddExState(&pad, 1, 0, "DIPS"); +} diff --git a/src/boards/573.c b/src/boards/573.c index c49243d..9829cce 100644 --- a/src/boards/573.c +++ b/src/boards/573.c @@ -44,5 +44,5 @@ static void trapLatchWrite (uint16 *newAddress, uint8 *newValue, uint8 romValue) void Mapper573_Init (CartInfo *info) { Latch_init(info, sync, 0x8000, 0xFFFF, trapLatchWrite); - info->Reset = Latch_power; + info->Reset = Latch_clear; } diff --git a/src/boards/579.c b/src/boards/579.c index 8490691..2170c21 100644 --- a/src/boards/579.c +++ b/src/boards/579.c @@ -45,5 +45,5 @@ static void trapLatchWrite (uint16 *newAddress, uint8 *newValue, uint8 romValue) void Mapper579_Init (CartInfo *info) { Latch_init(info, sync, 0x8000, 0xFFFF, trapLatchWrite); - info->Reset = Latch_power; + info->Reset = Latch_clear; } diff --git a/src/boards/580.c b/src/boards/580.c index 963c8ae..724c297 100644 --- a/src/boards/580.c +++ b/src/boards/580.c @@ -35,5 +35,5 @@ static void sync () { void Mapper580_Init (CartInfo *info) { Latch_init(info, sync, 0x8000, 0xFFFF, NULL); - info->Reset = Latch_power; + info->Reset = Latch_clear; } diff --git a/src/boards/581.c b/src/boards/581.c index 54dbce4..e35c8ac 100644 --- a/src/boards/581.c +++ b/src/boards/581.c @@ -44,5 +44,5 @@ static void trapLatchWrite (uint16 *newAddress, uint8 *newValue, uint8 romValue) void Mapper581_Init (CartInfo *info) { Latch_init(info, sync, 0x8000, 0xFFFF, trapLatchWrite); - info->Reset = Latch_power; + info->Reset = Latch_clear; } diff --git a/src/boards/583.c b/src/boards/583.c index 483e3ed..37ef1f4 100644 --- a/src/boards/583.c +++ b/src/boards/583.c @@ -46,5 +46,5 @@ static void trapLatchWrite (uint16 *newAddress, uint8 *newValue, uint8 romValue) void Mapper583_Init (CartInfo *info) { Latch_init(info, sync, 0x8000, 0xFFFF, trapLatchWrite); - info->Reset = Latch_power; + info->Reset = Latch_clear; } diff --git a/src/boards/584.c b/src/boards/584.c new file mode 100644 index 0000000..45519aa --- /dev/null +++ b/src/boards/584.c @@ -0,0 +1,59 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * 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 + * 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 void sync () { + if (reg[0] &0x20) + setprg32(0x8000, reg[0] >>1); + else { + setprg16(0x8000, reg[0]); + setprg16(0xC000, reg[0]); + } + setchr8(reg[1]); + setmirror(reg[1] &0x20? MI_V: MI_H); +} + +static DECLFW(writeReg) { + if (A &0x100) { + reg[A >>13 &1] = V; + sync(); + } +} + +static void power() { + SetReadHandler(0x6000, 0xFFFF, CartBR); + SetWriteHandler(0x4020, 0x7FFF, writeReg); + reg[0] = reg[1] = 0; + sync(); +} + +static void stateRestore(int version) { + sync(); +} + +void Mapper584_Init (CartInfo *info) { + info->Reset = power; + info->Power = power; + GameStateRestore = stateRestore; + AddExState(reg, 2, 0, "REGS"); +} diff --git a/src/boards/585.c b/src/boards/585.c index 52dbdd0..0e60577 100644 --- a/src/boards/585.c +++ b/src/boards/585.c @@ -46,8 +46,7 @@ static void power() { static void reset() { pad += 0x20; - Latch_address = 0; - sync(); + Latch_clear(); } void Mapper585_Init (CartInfo *info) { diff --git a/src/boards/586.c b/src/boards/586.c index 2cf2bfc..3872a9b 100644 --- a/src/boards/586.c +++ b/src/boards/586.c @@ -33,5 +33,5 @@ static void sync () { void Mapper586_Init (CartInfo *info) { Latch_init(info, sync, 0x8000, 0xFFFF, NULL); - info->Reset = Latch_power; + info->Reset = Latch_clear; } diff --git a/src/boards/589.c b/src/boards/589.c index a613f08..6610761 100644 --- a/src/boards/589.c +++ b/src/boards/589.c @@ -39,5 +39,5 @@ static void trapLatchWrite (uint16 *newAddress, uint8 *newValue, uint8 romValue) void Mapper589_Init (CartInfo *info) { Latch_init(info, sync, 0x8000, 0xFFFF, trapLatchWrite); - info->Reset = Latch_power; + info->Reset = Latch_clear; } diff --git a/src/boards/590.c b/src/boards/590.c index e77b6dd..2d90cb1 100644 --- a/src/boards/590.c +++ b/src/boards/590.c @@ -33,5 +33,5 @@ static void sync () { void Mapper590_Init (CartInfo *info) { Latch_init(info, sync, 0x8000, 0xFFFF, NULL); - info->Reset = Latch_power; + info->Reset = Latch_clear; } diff --git a/src/boards/591.c b/src/boards/591.c index d2f3ad1..dc417d2 100644 --- a/src/boards/591.c +++ b/src/boards/591.c @@ -34,5 +34,5 @@ static void sync () { void Mapper591_Init (CartInfo *info) { Latch_init(info, sync, 0x8000, 0xFFFF, NULL); - info->Reset = Latch_power; + info->Reset = Latch_clear; } diff --git a/src/boards/592.c b/src/boards/592.c index 6464e04..3c91f35 100644 --- a/src/boards/592.c +++ b/src/boards/592.c @@ -30,5 +30,5 @@ static void sync () { void Mapper592_Init (CartInfo *info) { Latch_init(info, sync, 0x8000, 0xFFFF, NULL); - info->Reset = Latch_power; + info->Reset = Latch_clear; } diff --git a/src/boards/asic_latch.c b/src/boards/asic_latch.c index 4eebcfd..f94286b 100644 --- a/src/boards/asic_latch.c +++ b/src/boards/asic_latch.c @@ -41,7 +41,7 @@ DECLFW(Latch_write) { Latch_cbSync(); } -static void Latch_clear () { +void Latch_clear () { Latch_address = 0; Latch_data = 0; Latch_cbSync(); diff --git a/src/boards/asic_latch.h b/src/boards/asic_latch.h index 07e4c87..80c9ef2 100644 --- a/src/boards/asic_latch.h +++ b/src/boards/asic_latch.h @@ -27,6 +27,7 @@ extern uint8 Latch_data; DECLFW (Latch_write); void Latch_addExState (); void Latch_restore (int); +void Latch_clear (); void Latch_power (); void Latch_activate (uint8, void (*)(), uint16, uint16, void (*)(uint16*, uint8*, uint8)); void Latch6_activate (uint8, void (*)(), uint16, uint16, void (*)(uint16*, uint8*, uint8)); diff --git a/src/boards/datalatch.c b/src/boards/datalatch.c index 09a0da6..32d3d92 100644 --- a/src/boards/datalatch.c +++ b/src/boards/datalatch.c @@ -507,53 +507,6 @@ void Mapper538_Init(CartInfo *info) { info->Power = M538Power; } -/* ------------------ A65AS --------------------------- */ - -/* actually, there is two cart in one... First have extra mirroring - * mode (one screen) and 32K bankswitching, second one have only - * 16 bankswitching mode and normal mirroring... But there is no any - * correlations between modes and they can be used in one mapper code. - * - * Submapper 0 - 3-in-1 (N068) - * Submapper 0 - 3-in-1 (N080) - * Submapper 1 - 4-in-1 (JY-066) - */ - -static int A65ASsubmapper; -static void BMCA65ASSync(void) { - if (latche & 0x40) - setprg32(0x8000, (latche >> 1) & 0x0F); - else { - if (A65ASsubmapper == 1) { - setprg16(0x8000, ((latche & 0x30) >> 1) | (latche & 7)); - setprg16(0xC000, ((latche & 0x30) >> 1) | 7); - } else { - setprg16(0x8000, latche & 0x0F); - setprg16(0xC000, latche & 0x0F | 7); - } - } - setchr8(0); - if (latche & 0x80) - setmirror(MI_0 + (((latche >> 5) & 1))); - else { - if (A65ASsubmapper == 1) - setmirror(latche &0x08? MI_H: MI_V); - else - setmirror(latche &0x20? MI_H: MI_V); - } -} - -void BMCA65AS_Reset() { - latche =0; - BMCA65ASSync(); -} - -void BMCA65AS_Init(CartInfo *info) { - A65ASsubmapper = info->submapper; - info->Reset = BMCA65AS_Reset; - Latch_Init(info, BMCA65ASSync, 0, 0x8000, 0xFFFF, 0, 0); -} - /*------------------ BMC-11160 ---------------------------*/ /* Simple BMC discrete mapper by TXC */ diff --git a/src/ines.c b/src/ines.c index 79a2696..bab8f75 100644 --- a/src/ines.c +++ b/src/ines.c @@ -734,7 +734,7 @@ INES_BOARD_BEGIN() INES_BOARD( "YY860417C", 281, Mapper281_Init ) INES_BOARD( "860224C", 282, Mapper282_Init ) INES_BOARD( "GS-2004/GS-2013", 283, Mapper283_Init ) - INES_BOARD( "A65AS", 285, BMCA65AS_Init ) + INES_BOARD( "A65AS", 285, Mapper285_Init ) INES_BOARD( "BS-5", 286, BMCBS5_Init ) INES_BOARD( "411120-C, 811120-C", 287, BMC411120C_Init ) INES_BOARD( "GKCX1", 288, Mapper288_Init ) @@ -960,6 +960,7 @@ INES_BOARD_BEGIN() INES_BOARD( "ET-156", 580, Mapper580_Init ) INES_BOARD( "ET-82", 581, Mapper581_Init ) INES_BOARD( "8203", 583, Mapper583_Init ) + INES_BOARD( "ST-32", 584, Mapper584_Init ) INES_BOARD( "FE-01-1", 585, Mapper585_Init ) INES_BOARD( "HN-02", 586, Mapper586_Init ) INES_BOARD( "3355", 587, Mapper587_Init ) diff --git a/src/ines.h b/src/ines.h index 2a33021..ee54f1d 100644 --- a/src/ines.h +++ b/src/ines.h @@ -425,6 +425,7 @@ void Mapper579_Init(CartInfo *); void Mapper580_Init(CartInfo *); void Mapper581_Init(CartInfo *); void Mapper583_Init(CartInfo *); +void Mapper584_Init(CartInfo *); void Mapper585_Init(CartInfo *); void Mapper586_Init(CartInfo *); void Mapper587_Init(CartInfo *); diff --git a/src/unif.c b/src/unif.c index a022ec8..7260b1e 100644 --- a/src/unif.c +++ b/src/unif.c @@ -437,7 +437,7 @@ static BMAPPING bmap[] = { { "8237", 215, UNL8237_Init, 0 }, { "8237A", 215, UNL8237A_Init, 0 }, { "830118C", 348, BMC830118C_Init, 0 }, - { "A65AS", 285, BMCA65AS_Init, 0 }, + { "A65AS", 285, Mapper285_Init, 0 }, { "AB-G1L", 428, Mapper428_Init, 0 }, { "WELL-NO-DG450", 428, Mapper428_Init, 0 }, { "TF2740", 428, Mapper428_Init, 0 }, diff --git a/src/unif.h b/src/unif.h index 353235a..4a07fe4 100644 --- a/src/unif.h +++ b/src/unif.h @@ -30,7 +30,7 @@ void BMC411120C_Init(CartInfo *info); void BMC64in1nr_Init(CartInfo *info); void BMC810544CA1_Init(CartInfo *info); void BMC830118C_Init(CartInfo *info); -void BMCA65AS_Init(CartInfo *info); +void Mapper285_Init(CartInfo *info); void BMCBS5_Init(CartInfo *info); void BMCD1038_Init(CartInfo *info); void BMCFK23CA_Init(CartInfo *info);