Mapper 556: use the modularized ASIC cores.
This commit is contained in:
336
src/boards/556.c
336
src/boards/556.c
@@ -19,312 +19,84 @@
|
||||
*/
|
||||
|
||||
/* NES 2.0 Mapper 556
|
||||
* Used for the for the è¶…å¼ºå°æ–°2+ç‘ªèŽ‰å®¶æ— 7-in-1 (JY-215) multicart.
|
||||
* Used for the for the 餓狼傳說 激鬥篇 HiK 7-in-1 (JY-215) multicart.
|
||||
*/
|
||||
|
||||
#include "mapinc.h"
|
||||
#include "asic_mmc3.h"
|
||||
#include "asic_vrc2and4.h"
|
||||
#include "wram.h"
|
||||
|
||||
static uint8 reg[5];
|
||||
static uint8 mmc3Reg[8];
|
||||
static uint8 mmc3Cmd;
|
||||
static uint8 mmc3Mirr;
|
||||
static uint8 mmc3Wram;
|
||||
static uint8 mmc3IRQLatch;
|
||||
static uint8 mmc3IRQCount;
|
||||
static uint8 mmc3IRQa;
|
||||
static uint8 mmc3IRQReload;
|
||||
static uint8 vrc4Prg[2];
|
||||
static uint8 vrc4Mirr;
|
||||
static uint8 vrc4Misc;
|
||||
static uint16 vrc4Chr[8];
|
||||
static uint8 vrc4IRQLatch;
|
||||
static uint8 vrc4IRQa;
|
||||
static uint8 vrc4IRQCount;
|
||||
static int16 vrc4IRQCycles;
|
||||
static uint8 *WRAM = NULL;
|
||||
static uint32 WRAMSIZE = 0;
|
||||
static uint8 reg[4];
|
||||
static uint8 index;
|
||||
|
||||
static SFORMAT StateRegs[] = {
|
||||
{ reg, 5, "REGS" },
|
||||
{ mmc3Reg, 8, "MMC3" },
|
||||
{ &mmc3Cmd, 1, "M3IX" },
|
||||
{ &mmc3Mirr, 1, "M3MI" },
|
||||
{ &mmc3Wram, 1, "M3WR" },
|
||||
{ &mmc3IRQLatch, 1, "M3RL" },
|
||||
{ &mmc3IRQCount, 1, "M3CN" },
|
||||
{ &mmc3IRQa, 1, "M3IQ" },
|
||||
{ &mmc3IRQReload, 1, "M3IR" },
|
||||
{ vrc4Prg, 2, "V4PR" },
|
||||
{ &vrc4Mirr, 1, "V4MI" },
|
||||
{ &vrc4Misc, 1, "V4MS" },
|
||||
{ vrc4Chr, 16, "V4CH" },
|
||||
{ &vrc4IRQLatch, 1, "VILA" },
|
||||
{ &vrc4IRQa, 1, "VIMO" },
|
||||
{ &vrc4IRQCount, 1, "VICO" },
|
||||
{ &vrc4IRQCycles, 2, "VICY" },
|
||||
{ &index, 1, "INDX" },
|
||||
{ 0 },
|
||||
};
|
||||
|
||||
static void Sync(void) {
|
||||
uint32 prgmask = ~reg[3] & 0x3F;
|
||||
uint32 prgbase = ((reg[3] & 0x40) << 2) | reg[1];
|
||||
uint32 chrmask = 0xFF >> (~reg[2] & 0x0F);
|
||||
uint32 chrbase = ((reg[3] & 0x40) << 6) | ((reg[2] & 0xF0) << 4) | reg[0];
|
||||
uint32 cbase = 0; /* prg/chr bank flip flag */
|
||||
|
||||
if (~reg[2] & 0x80) {
|
||||
/* MMC3 */
|
||||
cbase = (mmc3Cmd << 8) & 0x4000;
|
||||
setprg8(0x8000 ^ cbase, (prgbase & ~prgmask) | (mmc3Reg[6] & prgmask));
|
||||
setprg8(0xA000, (prgbase & ~prgmask) | (mmc3Reg[7] & prgmask));
|
||||
setprg8(0xC000 ^ cbase, (prgbase & ~prgmask) | (0xFE & prgmask));
|
||||
setprg8(0xE000, (prgbase & ~prgmask) | (0xFF & prgmask));
|
||||
|
||||
cbase = (mmc3Cmd << 5) & 0x1000;
|
||||
setchr1(0x0000 ^ cbase, (chrbase & ~chrmask) | ((mmc3Reg[0] & 0xFE) & chrmask));
|
||||
setchr1(0x0400 ^ cbase, (chrbase & ~chrmask) | ((mmc3Reg[0] | 0x01) & chrmask));
|
||||
setchr1(0x0800 ^ cbase, (chrbase & ~chrmask) | ((mmc3Reg[1] & 0xFE) & chrmask));
|
||||
setchr1(0x0C00 ^ cbase, (chrbase & ~chrmask) | ((mmc3Reg[1] | 0x01) & chrmask));
|
||||
setchr1(0x1000 ^ cbase, (chrbase & ~chrmask) | (mmc3Reg[2] & chrmask));
|
||||
setchr1(0x1400 ^ cbase, (chrbase & ~chrmask) | (mmc3Reg[3] & chrmask));
|
||||
setchr1(0x1800 ^ cbase, (chrbase & ~chrmask) | (mmc3Reg[4] & chrmask));
|
||||
setchr1(0x1C00 ^ cbase, (chrbase & ~chrmask) | (mmc3Reg[5] & chrmask));
|
||||
|
||||
setmirror((mmc3Mirr & 0x01) ^ 1);
|
||||
static void sync (void) {
|
||||
int prgAND = ~reg[3] &0x3F;
|
||||
int chrAND = 0xFF >>(~reg[2] &0xF);
|
||||
int prgOR = (reg[1] | reg[3] <<2 &0x100) &~prgAND;
|
||||
int chrOR = (reg[0] | reg[2] <<4 &0x0F00 | reg[3] <<6 &0x1000) &~chrAND;
|
||||
if (reg[2] &0x80) {
|
||||
VRC24_syncWRAM(0);
|
||||
VRC24_syncPRG(prgAND, prgOR);
|
||||
VRC24_syncCHR(chrAND, chrOR);
|
||||
VRC24_syncMirror();
|
||||
} else {
|
||||
/* VRC4 mode */
|
||||
cbase = (vrc4Misc << 13) & 0x4000;
|
||||
setprg8(0x8000 ^ cbase, (prgbase & ~prgmask) | (vrc4Prg[0] & prgmask));
|
||||
setprg8(0xA000, (prgbase & ~prgmask) | (vrc4Prg[1] & prgmask));
|
||||
setprg8(0xC000 ^ cbase, (prgbase & ~prgmask) | (0xFE & prgmask));
|
||||
setprg8(0xE000, (prgbase & ~prgmask) | (0xFF & prgmask));
|
||||
|
||||
setchr1(0x0000, (chrbase & ~chrmask) | (vrc4Chr[0] & chrmask));
|
||||
setchr1(0x0400, (chrbase & ~chrmask) | (vrc4Chr[1] & chrmask));
|
||||
setchr1(0x0800, (chrbase & ~chrmask) | (vrc4Chr[2] & chrmask));
|
||||
setchr1(0x0C00, (chrbase & ~chrmask) | (vrc4Chr[3] & chrmask));
|
||||
setchr1(0x1000, (chrbase & ~chrmask) | (vrc4Chr[4] & chrmask));
|
||||
setchr1(0x1400, (chrbase & ~chrmask) | (vrc4Chr[5] & chrmask));
|
||||
setchr1(0x1800, (chrbase & ~chrmask) | (vrc4Chr[6] & chrmask));
|
||||
setchr1(0x1C00, (chrbase & ~chrmask) | (vrc4Chr[7] & chrmask));
|
||||
|
||||
switch (vrc4Mirr & 0x03) {
|
||||
case 0: setmirror(MI_V); break;
|
||||
case 1: setmirror(MI_H); break;
|
||||
case 2: setmirror(MI_0); break;
|
||||
case 3: setmirror(MI_1); break;
|
||||
}
|
||||
MMC3_syncWRAM(0);
|
||||
MMC3_syncPRG(prgAND, prgOR);
|
||||
MMC3_syncCHR(chrAND, chrOR);
|
||||
MMC3_syncMirror();
|
||||
}
|
||||
}
|
||||
|
||||
static DECLFW(writeMMC3) {
|
||||
switch (A & 0xE001) {
|
||||
case 0x8000:
|
||||
mmc3Cmd = V;
|
||||
Sync();
|
||||
break;
|
||||
case 0x8001:
|
||||
mmc3Reg[mmc3Cmd & 7] = V;
|
||||
Sync();
|
||||
break;
|
||||
case 0xA000:
|
||||
mmc3Mirr = V;
|
||||
Sync();
|
||||
break;
|
||||
case 0xA001:
|
||||
mmc3Wram = V;
|
||||
Sync();
|
||||
break;
|
||||
case 0xC000:
|
||||
mmc3IRQLatch = V;
|
||||
break;
|
||||
case 0xC001:
|
||||
mmc3IRQReload = 1;
|
||||
break;
|
||||
case 0xE000:
|
||||
mmc3IRQa = 0;
|
||||
X6502_IRQEnd(FCEU_IQEXT);
|
||||
break;
|
||||
case 0xE001:
|
||||
mmc3IRQa = 1;
|
||||
break;
|
||||
static void applyMode (uint8 clear) {
|
||||
if (reg[2] &0x80)
|
||||
VRC4_activate(clear, sync, 0x05, 0x0A, 1, NULL, NULL, NULL, NULL, NULL);
|
||||
else
|
||||
MMC3_activate(clear, sync, MMC3_TYPE_AX5202P, NULL, NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
static DECLFW(writeReg) {
|
||||
if (~reg[3] &0x80) {
|
||||
reg[index++ &3] = V;
|
||||
if (index == 3)
|
||||
applyMode(1);
|
||||
else
|
||||
sync();
|
||||
}
|
||||
}
|
||||
|
||||
static DECLFW(writeVRC4) {
|
||||
uint8 index;
|
||||
A = (A & 0xF000) | ((A >> 2) & 3) | (A & 3);
|
||||
switch (A & 0xF000) {
|
||||
case 0x8000:
|
||||
case 0xA000:
|
||||
vrc4Prg[(A >> 13) & 1] = V;
|
||||
Sync();
|
||||
break;
|
||||
case 0x9000:
|
||||
if (~A & 2) {
|
||||
vrc4Mirr = V;
|
||||
} else if (~A & 1) {
|
||||
vrc4Misc = V;
|
||||
}
|
||||
Sync();
|
||||
break;
|
||||
case 0xF000:
|
||||
switch (A & 3) {
|
||||
case 0:
|
||||
vrc4IRQLatch = (vrc4IRQLatch & 0xF0) | (V & 0x0F);
|
||||
break;
|
||||
case 1:
|
||||
vrc4IRQLatch = (vrc4IRQLatch & 0x0F) | (V << 4);
|
||||
break;
|
||||
case 2:
|
||||
vrc4IRQa = V;
|
||||
if (vrc4IRQa & 0x02) {
|
||||
vrc4IRQCount = vrc4IRQLatch;
|
||||
vrc4IRQCycles = 341;
|
||||
}
|
||||
X6502_IRQEnd(FCEU_IQEXT);
|
||||
break;
|
||||
case 3:
|
||||
vrc4IRQa = (vrc4IRQa & ~0x02) | ((vrc4IRQa << 1) & 0x02);
|
||||
X6502_IRQEnd(FCEU_IQEXT);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
index = ((A - 0xB000) >> 11) | ((A >> 1) & 1);
|
||||
if (A & 1) {
|
||||
vrc4Chr[index] = (vrc4Chr[index] & 0x0F) | (V << 4);
|
||||
} else {
|
||||
vrc4Chr[index] = (vrc4Chr[index] & ~0x0F) | (V & 0x0F);
|
||||
}
|
||||
Sync();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static DECLFW(M556WriteReg) {
|
||||
if (~reg[3] & 0x80) {
|
||||
reg[reg[4] & 3] = V;
|
||||
reg[4]++;
|
||||
Sync();
|
||||
}
|
||||
}
|
||||
|
||||
static DECLFW(M556Write) {
|
||||
if (~reg[2] & 0x80) {
|
||||
writeMMC3(A, V);
|
||||
} else {
|
||||
writeVRC4(A, V);
|
||||
}
|
||||
}
|
||||
|
||||
static void FP_FASTAPASS(1) M556CPUHook(int a) {
|
||||
int count = a;
|
||||
|
||||
if (~reg[2] & 0x80) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* VRC4 IRQ mode */
|
||||
while (count--) {
|
||||
if ((vrc4IRQa & 0x02) && ((vrc4IRQa & 0x04) || ((vrc4IRQCycles -= 3) <= 0))) {
|
||||
if (~vrc4IRQa & 0x04) {
|
||||
vrc4IRQCycles += 341;
|
||||
}
|
||||
if (!++vrc4IRQCount) {
|
||||
vrc4IRQCount = vrc4IRQLatch;
|
||||
X6502_IRQBegin(FCEU_IQEXT);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void M556HBHook(void) {
|
||||
int count = mmc3IRQCount;
|
||||
|
||||
if (reg[2] & 0x80) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* MMC3 IRQ mode */
|
||||
if (!count || mmc3IRQReload) {
|
||||
mmc3IRQCount = mmc3IRQLatch;
|
||||
} else {
|
||||
mmc3IRQCount--;
|
||||
}
|
||||
if (count && !mmc3IRQCount && mmc3IRQa) {
|
||||
X6502_IRQBegin(FCEU_IQEXT);
|
||||
}
|
||||
mmc3IRQReload = 0;
|
||||
}
|
||||
|
||||
static void M556Reset(void) {
|
||||
int i;
|
||||
for (i = 0; i < 5; i++) {
|
||||
reg[i] = 0;
|
||||
}
|
||||
static void reset (void) {
|
||||
reg[0] = reg[1] = reg[3] = 0;
|
||||
reg[2] = 0x0F;
|
||||
Sync();
|
||||
index = 0;
|
||||
applyMode(1);
|
||||
}
|
||||
|
||||
static void M556Power(void) {
|
||||
int i;
|
||||
for (i = 0; i < 5; i++) {
|
||||
reg[i] = 0;
|
||||
}
|
||||
for (i = 0; i < 8; i++) {
|
||||
mmc3Reg[i] = 0;
|
||||
}
|
||||
for (i = 0; i < 2; i++) {
|
||||
vrc4Prg[i] = 0;
|
||||
}
|
||||
for (i = 0; i < 8; i++) {
|
||||
vrc4Chr[i] = 0;
|
||||
}
|
||||
mmc3Cmd = mmc3Mirr = mmc3Wram = mmc3IRQLatch = mmc3IRQCount = mmc3IRQa = mmc3IRQReload = 0;
|
||||
vrc4Mirr = vrc4Misc = vrc4IRQLatch = vrc4IRQa = vrc4IRQCount = vrc4IRQCycles = 0;
|
||||
static void power (void) {
|
||||
reg[0] = reg[1] = reg[3] = 0;
|
||||
reg[2] = 0x0F;
|
||||
Sync();
|
||||
|
||||
SetReadHandler(0x8000, 0xFFFF, CartBR);
|
||||
SetWriteHandler(0x5000, 0x5FFF, M556WriteReg);
|
||||
SetWriteHandler(0x8000, 0xFFFF, M556Write);
|
||||
|
||||
if (WRAM) {
|
||||
setprg8r(0x10, 0x6000, 0);
|
||||
SetReadHandler(0x6000, 0x7FFF, CartBR);
|
||||
SetWriteHandler(0x6000, 0x7FFF, CartBW);
|
||||
}
|
||||
index = 0;
|
||||
SetReadHandler(0x6000, 0xFFFF, CartBR);
|
||||
SetWriteHandler(0x5000, 0x5FFF, writeReg);
|
||||
applyMode(1);
|
||||
}
|
||||
|
||||
static void M556Close(void) {
|
||||
if (WRAM) {
|
||||
FCEU_gfree(WRAM);
|
||||
}
|
||||
WRAM = NULL;
|
||||
static void restore (int version) {
|
||||
applyMode(0);
|
||||
}
|
||||
|
||||
static void StateRestore(int version) {
|
||||
Sync();
|
||||
}
|
||||
|
||||
void Mapper556_Init(CartInfo *info) {
|
||||
info->Reset = M556Reset;
|
||||
info->Power = M556Power;
|
||||
info->Close = M556Close;
|
||||
MapIRQHook = M556CPUHook;
|
||||
GameHBIRQHook = M556HBHook;
|
||||
GameStateRestore = StateRestore;
|
||||
void Mapper556_Init (CartInfo *info) {
|
||||
MMC3_addExState();
|
||||
VRC24_addExState();
|
||||
WRAM_init(info, 8);
|
||||
info->Reset = reset;
|
||||
info->Power = power;
|
||||
GameStateRestore = restore;
|
||||
AddExState(StateRegs, ~0, 0, 0);
|
||||
|
||||
WRAMSIZE = info->PRGRamSize + info->PRGRamSaveSize;
|
||||
if (WRAMSIZE) {
|
||||
WRAM = (uint8 *)FCEU_gmalloc(WRAMSIZE);
|
||||
SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1);
|
||||
AddExState(WRAM, WRAMSIZE, 0, "WRAM");
|
||||
if (info->battery) {
|
||||
info->SaveGame[0] = WRAM;
|
||||
info->SaveGameLen[0] = WRAMSIZE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,14 +37,14 @@ void TC3294_syncWRAM (int OR) {
|
||||
}
|
||||
|
||||
void TC3294_syncPRG (int AND, int OR) {
|
||||
int prgAND =~TC3294_reg[3] &0x3F;
|
||||
int prgAND = ~TC3294_reg[3] &0x3F;
|
||||
int prgOR = TC3294_reg[1] | TC3294_reg[2] <<2 &0x300;
|
||||
MMC3_syncPRG(prgAND &AND, prgOR &~prgAND &AND | OR &~AND);
|
||||
}
|
||||
|
||||
void TC3294_syncCHR (int AND, int OR) {
|
||||
int chrAND =0xFF >>(~TC3294_reg[2] &0xF);
|
||||
int chrOR =TC3294_reg[0] | TC3294_reg[2] <<4 &0xF00;
|
||||
int chrAND = 0xFF >>(~TC3294_reg[2] &0xF);
|
||||
int chrOR = TC3294_reg[0] | TC3294_reg[2] <<4 &0xF00;
|
||||
MMC3_syncCHR(chrAND &AND, chrOR &~chrAND &AND | OR &~AND);
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ void TC3294_syncMirror () {
|
||||
|
||||
DECLFW(TC3294_write) {
|
||||
if (~TC3294_reg[3] &0x40) {
|
||||
TC3294_reg[TC3294_index++ &3] =V;
|
||||
TC3294_reg[TC3294_index++ &3] = V;
|
||||
TC3294_cbSync();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user