-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fd909e1
commit 808cc78
Showing
6 changed files
with
233 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
/* FCEUmm - NES/Famicom Emulator | ||
* | ||
* Copyright notice for this file: | ||
* Copyright (C) 2023 | ||
* | ||
* 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 528 | ||
* UNIF BMC-831128C | ||
*/ | ||
|
||
#include "mapinc.h" | ||
#include "vrcirq.h" | ||
|
||
static uint8 preg[4], creg[8], mirr; | ||
static uint8 gamesel; | ||
static uint8 *WRAM; | ||
static uint32 WRAMSIZE; | ||
|
||
static SFORMAT StateRegs[] = | ||
{ | ||
{ preg, 4, "PREG" }, | ||
{ creg, 8, "CREG" }, | ||
{ &mirr, 1, "MIRR" }, | ||
{ &gamesel, 1, "GSEL" }, | ||
{ 0 } | ||
}; | ||
|
||
static void Sync(void) { | ||
uint8 mask = (gamesel << 4) | 0x0F; | ||
if (preg[3] == 1) { | ||
setprg8r(0x10, 0x6000, 0); | ||
} else { | ||
setprg8(0x6000, (preg[3] & mask) + gamesel); | ||
} | ||
setprg8(0x8000, (preg[0] & mask) + (gamesel << 4)); | ||
setprg8(0xA000, (preg[1] & mask) + (gamesel << 4)); | ||
setprg8(0xC000, ( ~1 & mask) + (gamesel << 4)); | ||
setprg8(0xE000, ( ~0 & mask) + (gamesel << 4)); | ||
setchr1(0x0000, creg[0] + (gamesel << 8)); | ||
setchr1(0x0400, creg[1] + (gamesel << 8)); | ||
setchr1(0x0800, creg[2] + (gamesel << 8)); | ||
setchr1(0x0C00, creg[3] + (gamesel << 8)); | ||
setchr1(0x1000, creg[4] + (gamesel << 8)); | ||
setchr1(0x1400, creg[5] + (gamesel << 8)); | ||
setchr1(0x1800, creg[6] + (gamesel << 8)); | ||
setchr1(0x1C00, creg[7] + (gamesel << 8)); | ||
switch (mirr & 3) { | ||
case 0: setmirror(MI_V); break; | ||
case 1: setmirror(MI_H); break; | ||
case 2: setmirror(MI_0); break; | ||
case 3: setmirror(MI_1); break; | ||
} | ||
} | ||
|
||
static DECLFW(M528Write1) { | ||
switch (A & 0x0F) { | ||
case 0x0: creg[0] = V; break; | ||
case 0x1: creg[1] = V; break; | ||
case 0x2: creg[2] = V; break; | ||
case 0x3: creg[3] = V; break; | ||
case 0x4: creg[4] = V; break; | ||
case 0x5: creg[5] = V; break; | ||
case 0x6: creg[6] = V; break; | ||
case 0x7: creg[7] = V; break; | ||
case 0x8: preg[3] = V; break; | ||
case 0x9: preg[0] = V; break; | ||
case 0xA: preg[1] = V; break; | ||
case 0xB: break; | ||
case 0xC: mirr = V & 3; break; | ||
case 0xD: VRCIRQ_Control(V); break; | ||
case 0xE: VRCIRQ_Acknowledge(); break; | ||
case 0xF: VRCIRQ_Latch(V); break; | ||
} | ||
gamesel = (A & 0x4000) >> 14; | ||
Sync(); | ||
} | ||
|
||
static void M528Power(void) { | ||
int i; | ||
gamesel = 0; | ||
preg[0] = 0; | ||
preg[1] = 1; | ||
preg[2] = 0; | ||
preg[3] = 0; | ||
for (i = 0; i < 8; i++) { | ||
creg[i] = i; | ||
} | ||
Sync(); | ||
|
||
SetReadHandler(0x8000, 0xFFFF, CartBR); | ||
SetWriteHandler(0xA000, 0xAFFF, M528Write1); | ||
SetWriteHandler(0xC000, 0xCFFF, M528Write1); | ||
|
||
SetReadHandler(0x6000, 0x7FFF, CartBR); | ||
SetWriteHandler(0x6000, 0x7FFF, CartBW); | ||
FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); | ||
} | ||
|
||
static void StateRestore(int version) { | ||
Sync(); | ||
} | ||
|
||
void Mapper528_Init(CartInfo *info) { | ||
info->Power = M528Power; | ||
GameStateRestore = StateRestore; | ||
VRCIRQ_Init(); | ||
AddExState(&StateRegs, ~0, 0, 0); | ||
|
||
WRAMSIZE = 8192; | ||
WRAM = (uint8*) FCEU_gmalloc(WRAMSIZE); | ||
SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); | ||
AddExState(WRAM, WRAMSIZE, 0, "WRAM"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
#include "mapinc.h" | ||
#include "vrcirq.h" | ||
|
||
static int16 IRQPrescaler; | ||
static uint8 IRQCount; | ||
static uint8 IRQLatch; | ||
static uint8 IRQd; | ||
static uint8 IRQa; | ||
static uint8 IRQm; | ||
|
||
static SFORMAT StateRegs[] = | ||
{ | ||
{ &IRQPrescaler, 2, "PREC" }, | ||
{ &IRQCount, 1, "IRQC" }, | ||
{ &IRQLatch, 1, "IRQL" }, | ||
{ &IRQd, 1, "IRQD" }, | ||
{ &IRQa, 1, "IRQA" }, | ||
{ &IRQm, 1, "IRQM" }, | ||
|
||
{ 0 } | ||
}; | ||
|
||
static void FP_FASTAPASS(1) VRCIRQ_IrqHook(int a) | ||
{ | ||
int count = a; | ||
|
||
if (!IRQa) { | ||
return; | ||
} | ||
|
||
while (count) { | ||
count--; | ||
IRQPrescaler -= 3; | ||
if (IRQm || (IRQPrescaler < 0 && !IRQm)) { | ||
IRQPrescaler += 341; | ||
if (IRQCount == 0xFF) { | ||
X6502_IRQBegin(FCEU_IQEXT); | ||
IRQCount = IRQLatch; | ||
} else { | ||
IRQCount++; | ||
} | ||
} | ||
} | ||
} | ||
|
||
void VRCIRQ_Init(void) | ||
{ | ||
IRQPrescaler = 0; | ||
IRQCount = 0; | ||
IRQLatch = 0; | ||
IRQd = 0; | ||
IRQa = 0; | ||
IRQm = 0; | ||
MapIRQHook = VRCIRQ_IrqHook; | ||
|
||
AddExState(&StateRegs, ~0, 0, 0); | ||
} | ||
|
||
void VRCIRQ_Latch(uint8 V) | ||
{ | ||
IRQLatch = V; | ||
} | ||
|
||
void VRCIRQ_LatchNibble(uint8 V, uint8 highBit) | ||
{ | ||
if (highBit) { | ||
IRQLatch &= 0x0F; | ||
IRQLatch |= V << 4; | ||
} else { | ||
IRQLatch &= 0xF0; | ||
IRQLatch |= V & 0xF; | ||
} | ||
} | ||
|
||
void VRCIRQ_Control(uint8 V) | ||
{ | ||
IRQd = (V & 0x01) == 0x01; | ||
IRQa = (V & 0x02) == 0x02; | ||
IRQm = (V & 0x04) == 0x04; | ||
IRQPrescaler = 341; | ||
|
||
if (IRQa) { | ||
IRQCount = IRQLatch; | ||
} | ||
|
||
X6502_IRQEnd(FCEU_IQEXT); | ||
} | ||
|
||
void VRCIRQ_Acknowledge(void) | ||
{ | ||
IRQa = IRQd; | ||
X6502_IRQEnd(FCEU_IQEXT); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#ifndef _VRCIRQ_H | ||
#define _VRCIRQ_H | ||
|
||
void VRCIRQ_Init(void); | ||
void VRCIRQ_Latch(uint8 V); | ||
void VRCIRQ_LatchNibble(uint8 V, uint8 highBit); | ||
void VRCIRQ_Control(uint8 V); | ||
void VRCIRQ_Acknowledge(void); | ||
|
||
#endif /* _VRCIRQ_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters