Add BMC-SB-5013 (m359) and UNL-82112C (m540)

This commit is contained in:
negativeExponent
2020-02-14 10:44:51 +08:00
parent 310b75964f
commit 0b4b5421dc
4 changed files with 199 additions and 0 deletions

193
src/boards/359.c Normal file
View File

@@ -0,0 +1,193 @@
/* 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 359 - BMC-SB-5013
* NES 2.0 Mapper 540 - UNL-82112C
*/
#include "mapinc.h"
static uint8 mapperNum;
static uint8 preg[4];
static uint8 creg[8];
static uint8 exRegs[4];
static uint8 IRQReload;
static uint8 IRQa;
static uint8 irqPA12;
static uint8 IRQAutoEnable;
static uint8 IRQLatch;
static uint8 IRQCount;
static int16 IRQCount16;
static SFORMAT StateRegs[] = {
{ preg, 4, "PREG" },
{ creg, 8, "CREG" },
{ exRegs, 4, "EXPR" },
{ &IRQReload, 1, "IRQL" },
{ &IRQa, 1, "IRQa" },
{ &irqPA12, 1, "IRQp" },
{ &IRQAutoEnable, 1, "IRQe" },
{ &IRQLatch, 1, "IRQl" },
{ &IRQCount, 1, "IRQ8" },
{ &IRQCount16, 2 | FCEUSTATE_RLSB, "IRQC" },
{ 0 }
};
static void Sync(void) {
uint32 prgMask = 0x3F;
uint32 prgOuterBank = (exRegs[0] & 0x38) << 1;
switch (exRegs[1] & 3) {
case 0: prgMask = 0x3F; break;
case 1: prgMask = 0x1F; break;
case 2: prgMask = 0x2F; break;
case 3: prgMask = 0x0F; break;
}
setprg8(0x6000, (preg[3] & prgMask) | prgOuterBank);
setprg8(0x8000, (preg[0] & prgMask) | prgOuterBank);
setprg8(0xA000, (preg[1] & prgMask) | prgOuterBank);
setprg8(0xC000, (preg[2] & prgMask) | prgOuterBank);
setprg8(0xE000, ( ~0 & prgMask) | prgOuterBank);
if (!UNIFchrrama) {
switch (mapperNum) {
case 359: {
uint32 chrMask = (exRegs[1] & 0x40) ? 0xFF : 0x7F;
uint32 chrOuterBank = (exRegs[3] << 7);
uint32 i;
for (i = 0; i < 8; i++)
setchr1(i << 10, (creg[i] & chrMask) | chrOuterBank);
} break;
case 540:
setchr2(0x0000, creg[0]);
setchr2(0x0800, creg[1]);
setchr2(0x1000, creg[6]);
setchr2(0x1800, creg[7]);
break;
}
} else
setchr8(0);
if (exRegs[2] & 2)
setmirror(MI_0 + (exRegs[2] & 1));
else
setmirror((exRegs[2] & 1) ^ 1);
}
static DECLFW(M359WriteIRQ) {
switch (A & 0xF003) {
case 0xC000:
if (IRQAutoEnable) IRQa = 0;
IRQCount16 &= 0xFF00;
IRQCount16 |= V;
IRQReload = 1;
X6502_IRQEnd(FCEU_IQEXT);
break;
case 0xC001:
if (IRQAutoEnable) IRQa = 1;
IRQCount16 &= 0x00FF;
IRQCount16 |= (V << 8);
IRQLatch = V;
X6502_IRQEnd(FCEU_IQEXT);
break;
case 0xC002:
IRQa = (V & 1);
irqPA12 = (V & 2) >> 1;
IRQAutoEnable = (V & 4) >> 2;
X6502_IRQEnd(FCEU_IQEXT);
break;
case 0xC003:
IRQa = (V & 1);
X6502_IRQEnd(FCEU_IQEXT);
break;
}
}
static DECLFW(M359WritePRG) {
uint32 i = A & 3;
preg[i] = V;
Sync();
}
static DECLFW(M359WriteCHR) {
uint32 i = ((A >> 10) & 4) | (A & 3);
creg[i] = V;
Sync();
}
static DECLFW(M359WriteEx) {
uint32 i = A & 3;
exRegs[i] = V;
Sync();
}
static void M359Power(void) {
Sync();
SetReadHandler(0x6000, 0xFFFF, CartBR);
SetWriteHandler(0x8000, 0x8FFF, M359WritePRG);
SetWriteHandler(0x9000, 0x9FFF, M359WriteEx);
SetWriteHandler(0xA000, 0xBFFF, M359WriteCHR);
SetWriteHandler(0xC000, 0xCFFF, M359WriteIRQ);
}
static void FP_FASTAPASS(1) M359CPUHook(int a) {
if (!irqPA12) {
if (IRQa && IRQCount16) {
IRQCount16 -= a;
if (IRQCount16 <= 0)
X6502_IRQBegin(FCEU_IQEXT);
}
}
}
static void M359IRQHook(void) {
if (irqPA12) {
if (!IRQCount || IRQReload) {
IRQCount = IRQLatch;
IRQReload = 0;
} else
IRQCount--;
if (!IRQCount && IRQa)
X6502_IRQBegin(FCEU_IQEXT);
}
}
static void StateRestore(int version) {
Sync();
}
void Mapper359_Init(CartInfo* info) {
mapperNum = 359;
info->Power = M359Power;
MapIRQHook = M359CPUHook;
GameHBIRQHook = M359IRQHook;
GameStateRestore = StateRestore;
AddExState(&StateRegs, ~0, 0, 0);
}
void Mapper540_Init(CartInfo* info) {
mapperNum = 540;
info->Power = M359Power;
MapIRQHook = M359CPUHook;
GameHBIRQHook = M359IRQHook;
GameStateRestore = StateRestore;
AddExState(&StateRegs, ~0, 0, 0);
}

View File

@@ -679,6 +679,8 @@ static BMAPPINGLocal bmap[] = {
{(uint8_t*)"5-in-1 (CH-501)", 543, Mapper543_Init},
{(uint8_t*)"", 550, Mapper550_Init},
{(uint8_t*)"Brilliant Com Cocoma Pack", 516, Mapper516_Init},
{(uint8_t*)"SB-5013/GCL8050/841242C", 359, Mapper359_Init},
{(uint8_t*)"82112C", 540, Mapper540_Init},
/* UNIF to NES 2.0 BOARDS */

View File

@@ -247,6 +247,7 @@ void Mapper267_Init(CartInfo *);
void Mapper288_Init(CartInfo *);
void Mapper297_Init(CartInfo *);
void Mapper357_Init(CartInfo *);
void Mapper359_Init(CartInfo *);
void Mapper360_Init(CartInfo *);
void Mapper372_Init(CartInfo *);
void Mapper374_Init(CartInfo *);
@@ -258,6 +259,7 @@ void Mapper533_Init(CartInfo *);
void Mapper534_Init(CartInfo *);
void Mapper538_Init(CartInfo *);
void Mapper539_Init(CartInfo *);
void Mapper540_Init(CartInfo *);
void Mapper541_Init(CartInfo *);
void Mapper543_Init(CartInfo *);
void Mapper550_Init(CartInfo *);

View File

@@ -605,6 +605,8 @@ static BMAPPING bmap[] = {
{ "GN-26", 344, BMCGN26_Init, 0 },
{ "KG256", NO_INES,KG256_Init, 0 },
{ "T4A54A", 134, Bs5652_Init, 0 },
{ "SB-5013", 359, Mapper359_Init, 0 },
{ "82112C", 540, Mapper540_Init, 0 },
#ifdef COPYFAMI
{ "COPYFAMI_MMC3", NO_INES, MapperCopyFamiMMC3_Init, 0 },