From a09293bcc0998dc0f13fff85c99a54a02343862f Mon Sep 17 00:00:00 2001 From: negativeExponent Date: Sat, 21 Mar 2020 20:11:03 +0800 Subject: [PATCH 1/4] Add mapper 389 (Caltron 9-in-1) --- src/boards/389.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++ src/ines-correct.h | 2 ++ src/ines.c | 1 + src/ines.h | 1 + 4 files changed, 88 insertions(+) create mode 100644 src/boards/389.c diff --git a/src/boards/389.c b/src/boards/389.c new file mode 100644 index 0000000..b90beae --- /dev/null +++ b/src/boards/389.c @@ -0,0 +1,84 @@ +/* FCEUmm - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2020 negativeExponent + * + * 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. + */ + +/* Mapper 389 - Caltron 9-in-1 multicart */ + +#include "mapinc.h" + +static uint8 regs[3]; + +static SFORMAT StateRegs[] = { + { ®s, 3, "REGS" }, + { 0 } +}; + +static void Sync(void) +{ + if (regs[1] & 0x02) + { + /* UNROM-064 */ + setprg16(0x8000, (regs[0] >> 2) | ((regs[2] >> 2) & 0x03)); + setprg16(0xC000, (regs[0] >> 2) | 0x03); + } + else + { + /* NROM-256 */ + setprg32(0x8000, regs[0] >> 3); + } + setchr8(((regs[1] >> 1) & 0x1C) | (regs[2] & 0x03)); + setmirror((regs[0] & 0x01) ^ 1); +} + +static DECLFW(M389Write) +{ + switch (A & 0xF000) + { + case 0x8000: regs[0] = (A & 0xFF); Sync(); break; + case 0x9000: regs[1] = (A & 0xFF); Sync(); break; + default: regs[2] = (A & 0xFF); Sync(); break; + } +} + +static void M389Reset(void) +{ + regs[0] = regs[1] = regs[2] = 0; + Sync(); +} + +static void M389Power(void) +{ + regs[0] = regs[1] = regs[2] = 0; + Sync(); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, M389Write); +} + +static void StateRestore(int version) +{ + Sync(); +} + +void Mapper389_Init(CartInfo *info) +{ + info->Power = M389Power; + info->Reset = M389Reset; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/ines-correct.h b/src/ines-correct.h index c30e505..937a154 100644 --- a/src/ines-correct.h +++ b/src/ines-correct.h @@ -133,6 +133,7 @@ { 0x4c7c1af3, 34, 1 }, /* Caesar's Palace */ { 0x932ff06e, 34, 1 }, /* Classic Concentration */ { 0xf46ef39a, 37, -1 }, /* Super Mario Bros. + Tetris + Nintendo World Cup (E) [!] */ + { 0x4686C5DD, 41, -1 }, /* Caltron - 6 in 1 (USA) (Unl).nes */ { 0x090C0C17, 42, 1 }, /* Ai Senshi Nicol (FDS Conversion) [p1][!].nes */ { 0x4DF84825, 42, 1 }, /* Ai Senshi Nicol (FDS Conversion) [p2][!].nes */ { 0x579E5BC5, 42, 1 }, /* Ai Senshi Nicol (FDS Conversion) [p3].nes */ @@ -397,6 +398,7 @@ { 0xf6b9d088, 366, 0 }, /* 4-in-1 (K-3131GS, GN-45) [p1][!] */ { 0x503566b2, 366, 0 }, /* 4-in-1 (K-3131SS, GN-45) [p1][!] */ { 0xDB2D2D88, 369, -1 }, /* Super Mario Bros. Party.nes */ + { 0xC4B94BD5, 389, -1 }, /* Caltron - 9 in 1 (USA) (Proto) */ /* ines mappers that uses unif boards */ diff --git a/src/ines.c b/src/ines.c index 197dfd4..2399220 100644 --- a/src/ines.c +++ b/src/ines.c @@ -672,6 +672,7 @@ INES_BOARD_BEGIN() INES_BOARD( "95/96 Super HiK 4-in-1", 374, Mapper374_Init ) INES_BOARD( "KN-42", 381, Mapper381_Init ) INES_BOARD( "830928C", 382, Mapper382_Init ) + INES_BOARD( "Caltron 9-in-1", 389, Mapper389_Init ) INES_BOARD( "Realtec 8031", 390, Mapper390_Init ) INES_BOARD( "Brilliant Com Cocoma Pack", 516, Mapper516_Init ) INES_BOARD( "Sachen 3014", 533, Mapper533_Init ) diff --git a/src/ines.h b/src/ines.h index 5637c7f..4219a7f 100644 --- a/src/ines.h +++ b/src/ines.h @@ -262,6 +262,7 @@ void Mapper372_Init(CartInfo *); void Mapper374_Init(CartInfo *); void Mapper382_Init(CartInfo *); void Mapper381_Init(CartInfo *); +void Mapper389_Init(CartInfo *); void Mapper390_Init(CartInfo *); void Mapper516_Init(CartInfo *); void Mapper533_Init(CartInfo *); From a9f679ef1512caa6d54f134b99119c419778f52a Mon Sep 17 00:00:00 2001 From: negativeExponent Date: Tue, 24 Mar 2020 01:34:03 +0800 Subject: [PATCH 2/4] Add 42-in-80000 multicart (m380) --- src/boards/380.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++ src/ines-correct.h | 1 + src/ines.c | 1 + src/ines.h | 3 +- 4 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 src/boards/380.c diff --git a/src/boards/380.c b/src/boards/380.c new file mode 100644 index 0000000..a6bf1be --- /dev/null +++ b/src/boards/380.c @@ -0,0 +1,96 @@ +/* FCEUmm - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2020 negativeExponent + * + * 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. + */ + +/* NES 2.0 Mapper 380 denotes the 970630C circuit board, + * used on a 512 KiB multicart having 42 to 80,000 listed NROM and UNROM games. */ + +#include "mapinc.h" + +static uint16 latche; +static uint8 dipswitch; + +static SFORMAT StateRegs[] = { + { &latche, 2 | FCEUSTATE_RLSB, "LATC" }, + { &dipswitch, 1, "DPSW" }, + { 0 } +}; + +static void Sync(void) +{ + if (latche & 0x200) + { + if (latche & 1) /* NROM 128 */ + { + setprg16(0x8000, latche >> 2); + setprg16(0xC000, latche >> 2); + } + else /* NROM-256 */ + setprg32(0x8000, latche >> 3); + } + else /* UxROM */ + { + setprg16(0x8000, latche >> 2); + setprg16(0xC000, (latche >> 2) | 7); + } + setmirror(((latche >> 1) & 1) ^ 1); +} + +static DECLFR(M380Read) +{ + if (latche & 0x100) + return dipswitch; + return CartBR(A); +} + +static DECLFW(M380Write) +{ + latche = A; + Sync(); +} + +static void M380Reset(void) +{ + dipswitch = (dipswitch + 1) & 0xF; + latche = 0; + Sync(); +} + +static void M380Power(void) +{ + dipswitch = 0; + latche = 0; + Sync(); + setchr8(0); + SetReadHandler(0x8000, 0xFFFF, M380Read); + SetWriteHandler(0x8000, 0xFFFF, M380Write); +} + +static void StateRestore(int version) +{ + Sync(); +} + +void Mapper380_Init(CartInfo *info) +{ + info->Power = M380Power; + info->Reset = M380Reset; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/ines-correct.h b/src/ines-correct.h index 937a154..c34ad79 100644 --- a/src/ines-correct.h +++ b/src/ines-correct.h @@ -398,6 +398,7 @@ { 0xf6b9d088, 366, 0 }, /* 4-in-1 (K-3131GS, GN-45) [p1][!] */ { 0x503566b2, 366, 0 }, /* 4-in-1 (K-3131SS, GN-45) [p1][!] */ { 0xDB2D2D88, 369, -1 }, /* Super Mario Bros. Party.nes */ + { 0x87F83EA2, 380, -1 }, /* 42 to 80,000 */ { 0xC4B94BD5, 389, -1 }, /* Caltron - 9 in 1 (USA) (Proto) */ /* ines mappers that uses unif boards */ diff --git a/src/ines.c b/src/ines.c index 2399220..2bc8ab5 100644 --- a/src/ines.c +++ b/src/ines.c @@ -670,6 +670,7 @@ INES_BOARD_BEGIN() INES_BOARD( "GN-45", 366, GN45_Init ) INES_BOARD( "MMC3 PIRATE SFC-12", 372, Mapper372_Init ) INES_BOARD( "95/96 Super HiK 4-in-1", 374, Mapper374_Init ) + INES_BOARD( "42 to 80,000 (970630C)", 380, Mapper380_Init ) INES_BOARD( "KN-42", 381, Mapper381_Init ) INES_BOARD( "830928C", 382, Mapper382_Init ) INES_BOARD( "Caltron 9-in-1", 389, Mapper389_Init ) diff --git a/src/ines.h b/src/ines.h index 4219a7f..24e0abb 100644 --- a/src/ines.h +++ b/src/ines.h @@ -260,8 +260,9 @@ void Mapper360_Init(CartInfo *); void Mapper369_Init(CartInfo *); void Mapper372_Init(CartInfo *); void Mapper374_Init(CartInfo *); -void Mapper382_Init(CartInfo *); +void Mapper380_Init(CartInfo *); void Mapper381_Init(CartInfo *); +void Mapper382_Init(CartInfo *); void Mapper389_Init(CartInfo *); void Mapper390_Init(CartInfo *); void Mapper516_Init(CartInfo *); From e1bf53e80c15f8aa45902a92478226bf85a08e1e Mon Sep 17 00:00:00 2001 From: negativeExponent Date: Tue, 24 Mar 2020 01:46:36 +0800 Subject: [PATCH 3/4] m274: Update --- src/boards/bmc80013b.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/boards/bmc80013b.c b/src/boards/bmc80013b.c index 2966bde..a58c77d 100644 --- a/src/boards/bmc80013b.c +++ b/src/boards/bmc80013b.c @@ -21,7 +21,10 @@ * Its UNIF board name is BMC-80013-B. * https://wiki.nesdev.com/w/index.php/NES_2.0_Mapper_274 */ + /* 2020-03-22 - Update support for Cave Story II, FIXME: Arabian does not work for some reasons... */ + #include "mapinc.h" +#include "../ines.h" static uint8 regs[2], mode; @@ -37,7 +40,7 @@ static void Sync(void) { if (mode & 0x02) setprg16(0x8000, (regs[0] & 0x0F) | (regs[1] & 0x70)); else - setprg16(0x8000, (regs[0] & 0x0F) | 0x80); + setprg16(0x8000, (regs[0] & ((ROM_size - 1) & 0x0F)) | 0x80); setprg16(0xC000, regs[1]); setmirror(((regs[0] >> 4) & 1) ^ 1); } From 915c2be6a8515976688d4fb61535228f93006fde Mon Sep 17 00:00:00 2001 From: negativeExponent Date: Tue, 24 Mar 2020 01:50:10 +0800 Subject: [PATCH 4/4] Fix unable to load some unif carts --- src/unif.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/unif.c b/src/unif.c index cd4099b..ff5a477 100644 --- a/src/unif.c +++ b/src/unif.c @@ -273,10 +273,10 @@ static int TVCI(FCEUFILE *fp) { } static int EnableBattery(FCEUFILE *fp) { - FCEU_printf(" Battery-backed.\n"); - if (FCEU_fgetc(fp) == EOF) - return(0); - UNIFCart.battery = 1; + int ret = FCEU_fgetc(fp); + UNIFCart.battery = (ret > 0) ? 1 : 0; + if (UNIFCart.battery) + FCEU_printf(" Battery-backed.\n"); return(1); }