Skip to content

Commit

Permalink
misc mapper cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
LibretroAdmin committed Nov 12, 2023
1 parent f5518a7 commit 9156856
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 90 deletions.
30 changes: 15 additions & 15 deletions src/boards/162.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ static SFORMAT StateRegs[] =
{ 0 }
};

static void sync()
static void M162Sync(void)
{
setprg32(0x8000, reg[2] <<4 | reg[0] &0x0C /* PRG A17-A20 always normal from $5000 and $5200 */
| ( reg[3] &0x04 ? 0x00 : 0x02) /* PRG A16 is 1 if $5300.2=0 */
Expand All @@ -47,7 +47,7 @@ static void sync()
setchr8(0);
}

static void hblank(void) {
static void M162HBIRQHook(void) {
if (reg[0] &0x80 && scanline <239)
{ /* Actual hardware cannot look at the current scanline number, but instead latches PA09 on PA13 rises. This does not seem possible with the current PPU emulation however. */
setchr4(0x0000, scanline >=127? 1: 0);
Expand All @@ -62,45 +62,45 @@ static uint8 readReg(uint32 A) { return 0x00; }
static void writeReg(uint32 A, uint8 V)
{
reg[A >>8 &3] = V;
sync();
M162Sync();
}

static void power(void)
static void M162Power(void)
{
memset(reg, 0, sizeof(reg));
sync();
M162Sync();
SetReadHandler (0x5000, 0x57FF, readReg);
SetWriteHandler(0x5000, 0x57FF, writeReg);
SetReadHandler (0x6000, 0xFFFF, CartBR);
SetWriteHandler(0x6000, 0x7FFF, CartBW);
}

static void reset(void)
static void M162Reset(void)
{
memset(reg, 0, sizeof(reg));
sync();
M162Sync();
}

static void close(void)
static void M162Close(void)
{
if (WRAM)
FCEU_gfree(WRAM);
WRAM = NULL;
}

static void StateRestore(int version)
static void M162StateRestore(int version)
{
sync();
M162Sync();
}

void Mapper162_Init (CartInfo *info)
{
info->Power = power;
info->Reset = reset;
info->Close = close;
GameHBIRQHook = hblank;
info->Power = M162Power;
info->Reset = M162Reset;
info->Close = M162Close;
GameHBIRQHook = M162HBIRQHook;

GameStateRestore = StateRestore;
GameStateRestore = M162StateRestore;
AddExState(StateRegs, ~0, 0, 0);

WRAMSIZE = info->iNES2? (info->PRGRamSize + info->PRGRamSaveSize): 8192;
Expand Down
26 changes: 13 additions & 13 deletions src/boards/164.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ static SFORMAT StateRegs[] =
{ 0 }
};

static void sync()
static void M164Sync(void)
{
uint8 prgLow = reg[0] &0x0F | reg[0] >>1 &0x10;
uint8 prgHigh = reg[1] <<5;
Expand Down Expand Up @@ -83,45 +83,45 @@ static uint8 readReg(uint32 A)
static void writeReg(uint32 A, uint8 V)
{
reg[A >>8 &7] = V;
sync();
M164Sync();
}

static void power(void)
static void M164Power(void)
{
memset(reg, 0, sizeof(reg));
eeprom_93C66_init();
sync();
M164Sync();
SetReadHandler (0x5400, 0x57FF, readReg);
SetWriteHandler(0x5000, 0x57FF, writeReg);
SetReadHandler (0x6000, 0xFFFF, CartBR);
SetWriteHandler(0x6000, 0x7FFF, CartBW);
}

static void reset(void)
static void M164Reset(void)
{
memset(reg, 0, sizeof(reg));
sync();
M164Sync();
}

static void close(void)
static void M164Close(void)
{
if (WRAM)
FCEU_gfree(WRAM);
WRAM = NULL;
}

static void StateRestore(int version)
static void M164StateRestore(int version)
{
sync();
M164Sync();
}

void Mapper164_Init (CartInfo *info)
{
info->Power = power;
info->Reset = reset;
info->Close = close;
info->Power = M164Power;
info->Reset = M164Reset;
info->Close = M164Close;

GameStateRestore = StateRestore;
GameStateRestore = M164StateRestore;
AddExState(StateRegs, ~0, 0, 0);

WRAMSIZE = info->iNES2? (info->PRGRamSize + (info->PRGRamSaveSize &~0x7FF)): 8192;
Expand Down
26 changes: 13 additions & 13 deletions src/boards/428.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ static SFORMAT StateRegs[] =
{ 0 }
};

static void Sync(void) {
static void M428Sync(void) {
int mask = regs[2] >> 6; /* There is an CNROM mode that takes either two or four inner CHR banks from a CNROM-like latch register at $8000-$FFFF. */

if (regs[1] & 0x10)
Expand All @@ -51,53 +51,53 @@ static void Sync(void) {

static void WriteHi(uint32 A, uint8 V) {
regs[0] = V;
Sync();
M428Sync();
}

static void WriteLo(uint32 A, uint8 V) {
regs[A & 0x03] = V;
Sync();
M428Sync();
}

static uint8 ReadLo(uint32 A) { return hrd_flag; }

static void Power(void) {
static void M428Power(void) {
hrd_flag = 0; /* Solder pad, selecting different menus */

regs[0] = 0;
regs[1] = 0;
regs[2] = 0;

Sync();
M428Sync();
SetWriteHandler(0x8000, 0xFFFF, WriteHi);
SetWriteHandler(0x6001, 0x6002, WriteLo);
SetReadHandler(0x6000, 0x7FFF, ReadLo);
SetReadHandler(0x8000, 0xFFFF, CartBR);
}

static void StateRestore(int version) {
Sync();
static void M428StateRestore(int version) {
M428Sync();
}

static void Reset(void) {
static void M428Reset(void) {
hrd_flag++;
hrd_flag &= 3;

regs[0] = 0;
regs[1] = 0;
regs[2] = 0;

Sync();
M428Sync();
}

void Mapper428_Init(CartInfo *info) {
hrd_flag = 0;

Sync();
M428Sync();

info->Power = Power;
info->Reset = Reset;
info->Power = M428Power;
info->Reset = M428Reset;
AddExState(&StateRegs, ~0, 0, 0);
GameStateRestore = StateRestore;
GameStateRestore = M428StateRestore;
}

30 changes: 15 additions & 15 deletions src/boards/558.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ static SFORMAT StateRegs[] =
{ 0 }
};

static void sync()
static void M558Sync(void)
{
setprg32(0x8000, reg[1] <<4 | reg[0] &0xF | (reg[3] &0x04? 0x00: 0x03));
setprg8r(0x10, 0x6000, 0);
Expand All @@ -47,7 +47,7 @@ static void sync()
eeprom_93C66_write(reg[2] &0x04, reg[2] &0x02, reg[2] &0x01);
}

static void hblank(void) {
static void M558HBIRQHook(void) {
if (reg[0] &0x80 && scanline <239)
{ /* Actual hardware cannot look at the current scanline number, but instead latches PA09 on PA13 rises. This does not seem possible with the current PPU emulation however. */
setchr4(0x0000, scanline >=127? 1: 0);
Expand Down Expand Up @@ -76,47 +76,47 @@ static void writeReg(uint32 A, uint8 V)
V = V &~3 | V >>1 &1 | V <<1 &2;

reg[index] = V;
sync();
M558Sync();
}

static void power(void)
static void M558Power(void)
{
memset(reg, 0, sizeof(reg));
if (haveEEPROM)
eeprom_93C66_init();
sync();
M558Sync();
SetReadHandler (0x5000, 0x57FF, readReg);
SetWriteHandler(0x5000, 0x57FF, writeReg);
SetReadHandler (0x6000, 0xFFFF, CartBR);
SetWriteHandler(0x6000, 0x7FFF, CartBW);
}

static void reset(void)
static void M558Reset(void)
{
memset(reg, 0, sizeof(reg));
sync();
M558Sync();
}

static void close(void)
static void M558Close(void)
{
if (WRAM)
FCEU_gfree(WRAM);
WRAM = NULL;
}

static void StateRestore(int version)
static void M558StateRestore(int version)
{
sync();
M558Sync();
}

void Mapper558_Init (CartInfo *info)
{
info->Power = power;
info->Reset = reset;
info->Close = close;
GameHBIRQHook = hblank;
info->Power = M558Power;
info->Reset = M558Reset;
info->Close = M558Close;
GameHBIRQHook = M558HBIRQHook;

GameStateRestore = StateRestore;
GameStateRestore = M558StateRestore;
AddExState(StateRegs, ~0, 0, 0);

WRAMSIZE = info->PRGRamSize + (info->PRGRamSaveSize &~0x7FF);
Expand Down
14 changes: 7 additions & 7 deletions src/boards/bonza.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,27 @@ static SFORMAT StateRegs[] =
{ 0 }
};

static void Sync(void) {
static void M216Sync(void) {
setprg32(0x8000, prg_reg);
setchr8(chr_reg);
}

static void StateRestore(int version) { Sync(); }
static void M216StateRestore(int version) { M216Sync(); }

static void M216WriteHi(uint32 A, uint8 V) {
prg_reg = A & 1;
chr_reg = (A & 0x0E) >> 1;
Sync();
M216Sync();
}

static void M216Write5000(uint32 A, uint8 V) { }

static uint8 M216Read5000(uint32 A) { return 0; }

static void Power(void) {
static void M216Power(void) {
prg_reg = 0;
chr_reg = 0;
Sync();
M216Sync();
SetReadHandler(0x8000, 0xFFFF, CartBR);
SetWriteHandler(0x8000, 0xFFFF, M216WriteHi);
SetWriteHandler(0x5000, 0x5000, M216Write5000);
Expand All @@ -60,7 +60,7 @@ static void Power(void) {


void Mapper216_Init(CartInfo *info) {
info->Power = Power;
GameStateRestore = StateRestore;
info->Power = M216Power;
GameStateRestore = M216StateRestore;
AddExState(&StateRegs, ~0, 0, 0);
}
Loading

0 comments on commit 9156856

Please sign in to comment.