mapper cleanups (#494)

* m215: Fix support for submapper 1 cart

* Switch UNL43272 to new Mapper242 implementation

* Merge mappers BMC-70in1/B and 236

* Merge 58/213/GK-192

* Assign GS-2004/GS-2014 to mapper 283

* Cleanup

Co-authored-by: negativeExponent <negativeExponent@users.noreply.github.com>
This commit is contained in:
negativeExponent
2022-02-05 10:19:33 -08:00
committed by GitHub
parent ffff495072
commit 17ad461e7d
10 changed files with 86 additions and 333 deletions

View File

@@ -33,13 +33,16 @@ static SFORMAT StateRegs[] =
static void Sync(void)
{
int prg;
int chr;
if (chrramvariant)
{
prg = reg[1] &7 | reg[0] <<3;
chr = 0;
}
else
{
prg = reg[1] &15;
prg = reg[1] & 0x0F;
chr = reg[0] & 0x0F;
}
switch (reg[1] >>4 &3)
{
@@ -56,11 +59,10 @@ static void Sync(void)
setprg16(0xC000, prg);
break;
}
setchr8(reg[0] &15);
setchr8(chr);
setmirror((reg[0] >>5 &1) ^1);
}
static DECLFR(M236Read)
{
if ((reg[1] >>4 &3) ==1)

View File

@@ -19,6 +19,7 @@
*/
#include "mapinc.h"
#include "../ines.h"
static uint8 reg, mirr;
static SFORMAT StateRegs[] =
@@ -29,25 +30,25 @@ static SFORMAT StateRegs[] =
};
static void Sync(void) {
setprg8(0x6000, 31);
setprg8(0x6000, (ROM_size == 17) ? 32 : 31); /* FIXME: Verify these */
setprg32(0x8000, reg);
setchr8(0);
}
static DECLFW(BMCGS2013Write) {
static DECLFW(M283Write) {
reg = V;
Sync();
}
static void BMCGS2013Power(void) {
static void M283Power(void) {
reg = 0;
Sync();
SetReadHandler(0x6000, 0x7FFF, CartBR);
SetReadHandler(0x8000, 0xFFFF, CartBR);
SetWriteHandler(0x8000, 0xFFFF, BMCGS2013Write);
SetWriteHandler(0x8000, 0xFFFF, M283Write);
}
static void BMCGS2013Reset(void) {
static void M283Reset(void) {
reg = 0;
}
@@ -55,9 +56,9 @@ static void StateRestore(int version) {
Sync();
}
void BMCGS2013_Init(CartInfo *info) {
info->Reset = BMCGS2013Reset;
info->Power = BMCGS2013Power;
void Mapper283_Init(CartInfo *info) {
info->Reset = M283Reset;
info->Power = M283Power;
GameStateRestore = StateRestore;
AddExState(&StateRegs, ~0, 0, 0);
}

View File

@@ -17,15 +17,27 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Super Game (Sugar Softec) protected mapper
* Pocahontas 2 (Unl) [U][!], etc.
* TODO: 9in1 LION KING HANGS!
* Submapper 0, UNIF board name UNL-8237:
* Earthworm Jim 2
* Mortal Kombat 3 (SuperGame, not Extra 60, not to be confused by similarly-named games from other developers)
* Mortal Kombat 3 Extra 60 (both existing ROM images are just extracts of the 2-in-1 multicart containing this game)
* Pocahontas Part 2
* 2-in-1: Aladdin, EarthWorm Jim 2 (Super 808)
* 2-in-1: The Lion King, Bomber Boy (GD-103)
* 2-in-1 Super Golden Card: EarthWorm Jim 2, Boogerman (king002)
* 2-in-1: Mortal Kombat 3 Extra 60, The Super Shinobi (king005)
* 3-in-1: Boogerman, Adventure Island 3, Double Dragon 3 (Super 308)
* 5-in-1 Golden Card: Aladdin, EarthWorm Jim 2, Garo Densetsu Special, Silkworm, Contra Force (SPC005)
* 6-in-1 Golden Card: EarthWorm Jim 2, Mortal Kombat 3, Double Dragon 3, Contra 3, The Jungle Book, Turtles Tournament Fighters (SPC009)
*
* Submapper 1, UNIF board name UNL-8237A:
* 9-in-1 High Standard Card: The Lion King, EarthWorm Jim 2, Aladdin, Boogerman, Somari, Turtles Tournament Fighters, Mortal Kombat 3, Captain Tsubasa 2, Taito Basketball (king001)
*/
#include "mapinc.h"
#include "mmc3.h"
static uint8 cmdin;
static uint8 submapper;
static uint8 regperm[8][8] =
{
@@ -52,80 +64,51 @@ static uint8 adrperm[8][8] =
};
static void UNL8237CW(uint32 A, uint8 V) {
if (EXPREGS[0] & 0x40)
setchr1(A, ((EXPREGS[1] & 0xc) << 6) | (V & 0x7F) | ((EXPREGS[1] & 0x20) << 2));
uint16 outer_bank;
if (submapper == 1)
outer_bank = ((EXPREGS[1] & 0xE) << 7);
else
setchr1(A, ((EXPREGS[1] & 0xc) << 6) | V);
outer_bank = ((EXPREGS[1] & 0xC) << 6);
if (EXPREGS[0] & 0x40)
setchr1(A, outer_bank | (V & 0x7F) | ((EXPREGS[1] & 0x20) << 2));
else
setchr1(A, outer_bank | V);
}
static void UNL8237PW(uint32 A, uint8 V) {
uint8 outer_bank = ((EXPREGS[1] & 3) << 5);
if (submapper == 1)
outer_bank |= ((EXPREGS[1] & 8) << 4);
if (EXPREGS[0] & 0x40) {
uint8 sbank = (EXPREGS[1] & 0x10);
if (EXPREGS[0] & 0x80) {
if (EXPREGS[0] & 0x80) { /* NROM */
uint8 bank = ((EXPREGS[1] & 3) << 4) | (EXPREGS[0] & 0x7) | (sbank >> 1);
if (EXPREGS[0] & 0x20)
if (EXPREGS[0] & 0x20) /* NROM-256 */
setprg32(0x8000, bank >> 1);
else {
else { /* NROM-128 */
setprg16(0x8000, bank);
setprg16(0xC000, bank);
}
} else
setprg8(A, ((EXPREGS[1] & 3) << 5) | (V & 0x0F) | sbank);
setprg8(A, outer_bank | (V & 0x0F) | sbank);
} else {
if (EXPREGS[0] & 0x80) {
if (EXPREGS[0] & 0x80) { /* NROM */
uint8 bank = ((EXPREGS[1] & 3) << 4) | (EXPREGS[0] & 0xF);
if (EXPREGS[0] & 0x20)
if (EXPREGS[0] & 0x20) /* NROM-256 */
setprg32(0x8000, bank >> 1);
else {
else { /* NROM-128 */
setprg16(0x8000, bank);
setprg16(0xC000, bank);
}
} else
setprg8(A, ((EXPREGS[1] & 3) << 5) | (V & 0x1F));
setprg8(A, outer_bank | (V & 0x1F));
}
}
static void UNL8237ACW(uint32 A, uint8 V) {
if (EXPREGS[0] & 0x40)
setchr1(A, ((EXPREGS[1] & 0xE) << 7) | (V & 0x7F) | ((EXPREGS[1] & 0x20) << 2));
else
setchr1(A, ((EXPREGS[1] & 0xE) << 7) | V);
}
static void UNL8237APW(uint32 A, uint8 V) {
if (EXPREGS[0] & 0x40) {
uint8 sbank = (EXPREGS[1] & 0x10);
if (EXPREGS[0] & 0x80) {
uint8 bank = ((EXPREGS[1] & 3) << 4) | ((EXPREGS[1] & 8) << 3) | (EXPREGS[0] & 0x7) | (sbank >> 1);
if (EXPREGS[0] & 0x20) {
/* FCEU_printf("8000:%02X\n",bank>>1); */
setprg32(0x8000, bank >> 1);
} else {
/* FCEU_printf("8000-C000:%02X\n",bank); */
setprg16(0x8000, bank);
setprg16(0xC000, bank);
}
} else {
/* FCEU_printf("%04x:%02X\n",A,((EXPREGS[1]&3)<<5)|((EXPREGS[1]&8)<<4)|(V&0x0F)|sbank); */
setprg8(A, ((EXPREGS[1] & 3) << 5) | ((EXPREGS[1] & 8) << 4) | (V & 0x0F) | sbank);
}
} else {
if (EXPREGS[0] & 0x80) {
uint8 bank = ((EXPREGS[1] & 3) << 4) | ((EXPREGS[1] & 8) << 3) | (EXPREGS[0] & 0xF);
if (EXPREGS[0] & 0x20) {
/* FCEU_printf("8000:%02X\n",(bank>>1)&0x07); */
setprg32(0x8000, bank >> 1);
} else {
/* FCEU_printf("8000-C000:%02X\n",bank&0x0F); */
setprg16(0x8000, bank);
setprg16(0xC000, bank);
}
} else {
/* FCEU_printf("%04X:%02X\n",A,(((EXPREGS[1]&3)<<5)|((EXPREGS[1]&8)<<4)|(V&0x1F))&0x1F); */
setprg8(A, ((EXPREGS[1] & 3) << 5) | ((EXPREGS[1] & 8) << 4) | (V & 0x1F));
}
}
}
static DECLFW(UNL8237Write) {
uint8 dat = V;
uint8 adr = adrperm[EXPREGS[2]][((A >> 12) & 6) | (A & 1)];
@@ -139,8 +122,8 @@ static DECLFW(UNL8237Write) {
}
static DECLFW(UNL8237ExWrite) {
switch (A) {
case 0x5000: EXPREGS[0] = V; FixMMC3PRG(MMC3_cmd); break;
switch (A & 0xF007) {
case 0x5000: EXPREGS[0] = V; FixMMC3PRG(MMC3_cmd); FixMMC3CHR(MMC3_cmd); break;
case 0x5001: EXPREGS[1] = V; FixMMC3PRG(MMC3_cmd); FixMMC3CHR(MMC3_cmd); break;
case 0x5007: EXPREGS[2] = V; break;
}
@@ -148,7 +131,7 @@ static DECLFW(UNL8237ExWrite) {
static void UNL8237Power(void) {
EXPREGS[0] = EXPREGS[2] = 0;
EXPREGS[1] = 3;
EXPREGS[1] = 0x0F;
GenMMC3Power();
SetWriteHandler(0x8000, 0xFFFF, UNL8237Write);
SetWriteHandler(0x5000, 0x7FFF, UNL8237ExWrite);
@@ -160,14 +143,12 @@ void UNL8237_Init(CartInfo *info) {
pwrap = UNL8237PW;
info->Power = UNL8237Power;
AddExState(EXPREGS, 3, 0, "EXPR");
AddExState(&cmdin, 1, 0, "CMDI");
AddExState(&submapper, 1, 0, "SUBM");
if (info->iNES2)
submapper = info->submapper;
}
void UNL8237A_Init(CartInfo *info) {
GenMMC3_Init(info, 256, 256, 0, 0);
cwrap = UNL8237ACW;
pwrap = UNL8237APW;
info->Power = UNL8237Power;
AddExState(EXPREGS, 3, 0, "EXPR");
AddExState(&cmdin, 1, 0, "CMDI");
UNL8237_Init(info);
submapper = 1;
}

View File

@@ -19,6 +19,7 @@
*/
#include "mapinc.h"
#include "../ines.h"
static uint16 latche, latcheinit;
static uint16 addrreg0, addrreg1;
@@ -137,38 +138,9 @@ void BMCD1038_Init(CartInfo *info) {
AddExState(&dipswitch, 1, 0, "DIPSW");
}
/*------------------ UNL43272 ---------------------------*/
/* mapper much complex, including 16K bankswitching */
static void UNL43272Sync(void) {
if ((latche & 0x81) == 0x81) {
setprg32(0x8000, (latche & 0x38) >> 3);
} else
FCEU_printf("unrecognized command %04!\n", latche);
setchr8(0);
setmirror(0);
}
static DECLFR(UNL43272Read) {
if (latche & 0x400)
return CartBR(A & 0xFE);
else
return CartBR(A);
}
static void UNL43272Reset(void) {
latche = 0;
UNL43272Sync();
}
void UNL43272_Init(CartInfo *info) {
Latch_Init(info, UNL43272Sync, UNL43272Read, 0x0081, 0x8000, 0xFFFF, 0);
info->Reset = UNL43272Reset;
AddExState(&dipswitch, 1, 0, "DIPSW");
}
/*------------------ Map 058 ---------------------------*/
static void BMCGK192Sync(void) {
static void M58Sync(void) {
if (latche & 0x40) {
setprg16(0x8000, latche & 7);
setprg16(0xC000, latche & 7);
@@ -178,8 +150,8 @@ static void BMCGK192Sync(void) {
setmirror(((latche & 0x80) >> 7) ^ 1);
}
void BMCGK192_Init(CartInfo *info) {
Latch_Init(info, BMCGK192Sync, NULL, 0x0000, 0x8000, 0xFFFF, 0);
void Mapper58_Init(CartInfo *info) {
Latch_Init(info, M58Sync, NULL, 0x0000, 0x8000, 0xFFFF, 0);
}
/*------------------ Map 059 ---------------------------*/
@@ -373,20 +345,7 @@ void Mapper212_Init(CartInfo *info) {
/*------------------ Map 213 ---------------------------*/
static void M213Sync(void) {
if(latche & 0x40) {
setprg16(0x8000, (latche & 7));
setprg16(0xC000, (latche & 7));
} else {
setprg32(0x8000, (latche >> 1) & 3);
}
setchr8((latche >> 3) & 7);
setmirror(((latche & 1)^((latche >> 6) & 1)) ^ 1);
}
void Mapper213_Init(CartInfo *info) {
Latch_Init(info, M213Sync, NULL, 0x0000, 0x8000, 0xFFFF, 0);
}
/* SEE MAPPER 58 */
/*------------------ Map 214 ---------------------------*/
@@ -540,7 +499,7 @@ static void M242Sync(void) {
}
}
if (!hasBattery && (latche & 0x80) == 0x80)
if (!hasBattery && (latche & 0x80) == 0x80 && (ROM_size * 16) > 256)
/* CHR-RAM write protect hack, needed for some multicarts */
SetupCartCHRMapping(0, CHRptr[0], 0x2000, 0);
else

View File

@@ -1,123 +0,0 @@
/* 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 is_large_banks, hw_switch;
static uint8 large_bank;
static uint8 prg_bank;
static uint8 chr_bank;
static uint8 bank_mode;
static uint8 mirroring;
static SFORMAT StateRegs[] =
{
{ &large_bank, 1, "LB" },
{ &hw_switch, 1, "DPSW" },
{ &prg_bank, 1, "PRG" },
{ &chr_bank, 1, "CHR" },
{ &bank_mode, 1, "BM" },
{ &mirroring, 1, "MIRR" },
{ 0 }
};
static void Sync(void) {
switch (bank_mode) {
case 0x00:
case 0x10:
setprg16(0x8000, large_bank | prg_bank);
setprg16(0xC000, large_bank | 7);
break;
case 0x20:
setprg32(0x8000, (large_bank | prg_bank) >> 1);
break;
case 0x30:
setprg16(0x8000, large_bank | prg_bank);
setprg16(0xC000, large_bank | prg_bank);
break;
}
setmirror(mirroring);
if (!is_large_banks)
setchr8(chr_bank);
}
static DECLFR(BMC70in1Read) {
if (bank_mode == 0x10)
/* if(is_large_banks) */
return CartBR((A & 0xFFF0) | hw_switch);
#if 0
else
return CartBR((A&0xFFF0)|hw_switch);
#endif
else
return CartBR(A);
}
static DECLFW(BMC70in1Write) {
if (A & 0x4000) {
bank_mode = A & 0x30;
prg_bank = A & 7;
} else {
mirroring = ((A & 0x20) >> 5) ^ 1;
if (is_large_banks)
large_bank = (A & 3) << 3;
else
chr_bank = A & 7;
}
Sync();
}
static void BMC70in1Reset(void) {
bank_mode = 0;
large_bank = 0;
Sync();
hw_switch++;
hw_switch &= 0xf;
}
static void BMC70in1Power(void) {
setchr8(0);
bank_mode = 0;
large_bank = 0;
Sync();
SetReadHandler(0x8000, 0xFFFF, BMC70in1Read);
SetWriteHandler(0x8000, 0xffff, BMC70in1Write);
}
static void StateRestore(int version) {
Sync();
}
void BMC70in1_Init(CartInfo *info) {
is_large_banks = 0;
hw_switch = 0xd;
info->Power = BMC70in1Power;
info->Reset = BMC70in1Reset;
GameStateRestore = StateRestore;
AddExState(&StateRegs, ~0, 0, 0);
}
void BMC70in1B_Init(CartInfo *info) {
is_large_banks = 1;
hw_switch = 0x6;
info->Power = BMC70in1Power;
info->Reset = BMC70in1Reset;
GameStateRestore = StateRestore;
AddExState(&StateRegs, ~0, 0, 0);
}

View File

@@ -1,63 +0,0 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2007 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, mirr;
static SFORMAT StateRegs[] =
{
{ &reg, 1, "REGS" },
{ &mirr, 1, "MIRR" },
{ 0 }
};
static void Sync(void) {
setprg8(0x6000, 32);
setprg32(0x8000, reg);
setchr8(0);
}
static DECLFW(BMCGS2004Write) {
reg = V;
Sync();
}
static void BMCGS2004Power(void) {
reg = 0x07;
Sync();
SetReadHandler(0x6000, 0x7FFF, CartBR);
SetReadHandler(0x8000, 0xFFFF, CartBR);
SetWriteHandler(0x8000, 0xFFFF, BMCGS2004Write);
}
static void BMCGS2004Reset(void) {
reg = 0x07;
}
static void StateRestore(int version) {
Sync();
}
void BMCGS2004_Init(CartInfo *info) {
info->Reset = BMCGS2004Reset;
info->Power = BMCGS2004Power;
GameStateRestore = StateRestore;
AddExState(&StateRegs, ~0, 0, 0);
}