NESHawk: Implement mapper 43 and UNIF_UNL-SMB2J

This commit is contained in:
alyosha-tas 2017-12-02 12:22:48 -05:00
parent 5e481a6083
commit 5ba647a632
3 changed files with 232 additions and 0 deletions

View File

@ -664,6 +664,7 @@
<Compile Include="Consoles\Nintendo\NES\Boards\BxROM.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Camerica.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\CamericaGoldenFive.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Mapper043.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Cony.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\CoolBoy.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\DatachBarcode.cs" />
@ -859,6 +860,7 @@
<Compile Include="Consoles\Nintendo\NES\Boards\Taito_X1_017.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\TENGEN-800032.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\TENGEN_800008.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\UNIF\UNIF_UNL_SMB2J.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\UNIF\UNIF-DREAMTECH01.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\UNIF\UNIF_BMC-12-IN-1.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\UNIF\UNIF_BMC-190in1.cs" />

View File

@ -0,0 +1,138 @@
using System;
using BizHawk.Common;
namespace BizHawk.Emulation.Cores.Nintendo.NES
{
public sealed class Mapper043 : NES.NESBoardBase
{
int prg = 0;
int irqcnt = 0;
bool irqenable = false;
bool swap;
private static int[] lut = { 4, 3, 5, 3, 6, 3, 7, 3 };
public override bool Configure(NES.EDetectionOrigin origin)
{
switch (Cart.board_type)
{
case "MAPPER043":
break;
default:
return false;
}
Cart.wram_size = 0;
// not sure on initial mirroring
SetMirrorType(EMirrorType.Vertical);
return true;
}
public override void WriteEXP(int addr, byte value)
{
addr += 0x4000;
switch (addr & 0xF1FF)
{
case 0x4022:
prg = lut[value & 0x7];
break;
case 0x4120:
swap = (value & 1) == 1;
break;
case 0x4122:
irqenable = (value & 1) == 1;
IRQSignal = false;
irqcnt = 0;
break;
}
}
public override void WritePRG(int addr, byte value)
{
addr += 0x8000;
switch (addr & 0xF1FF)
{
case 0x8122:
irqenable = (value & 1) == 1;
IRQSignal = false;
irqcnt = 0;
break;
}
}
public override byte ReadEXP(int addr)
{
if (addr > 0x1000)
{
return ROM[(addr - 0x1000) + 8 * 0x2000];
}
else return base.ReadEXP(addr);
}
public override byte ReadWRAM(int addr)
{
if (swap)
{
return ROM[addr];
}
else
{
return ROM[addr + 0x4000];
}
}
public override byte ReadPRG(int addr)
{
if (addr < 0x2000)
{
return ROM[addr + 0x2000];
}
else if (addr < 0x4000)
{
return ROM[addr - 0x2000];
}
else if (addr < 0x6000)
{
return ROM[(addr - 0x4000) + prg * 0x2000];
}
else
{
if (swap)
{
return ROM[(addr - 0x6000) + 8 * 0x2000];
}
else
{
return ROM[(addr - 0x6000) + 9 * 0x2000];
}
}
}
public override void ClockCPU()
{
if (irqenable)
{
irqcnt++;
if (irqcnt >= 4096)
{
irqenable = false;
IRQSignal = true;
}
}
}
public override void SyncState(Serializer ser)
{
base.SyncState(ser);
ser.Sync("prg", ref prg);
ser.Sync("irqenable", ref irqenable);
ser.Sync("irqcnt", ref irqcnt);
ser.Sync("swap", ref swap);
}
}
}

View File

@ -0,0 +1,92 @@
using System;
using BizHawk.Common;
namespace BizHawk.Emulation.Cores.Nintendo.NES
{
public sealed class UNIF_UNL_SMB2J : NES.NESBoardBase
{
int prg = 0;
int prg_count;
int irqcnt = 0;
bool irqenable = false;
bool swap;
public override bool Configure(NES.EDetectionOrigin origin)
{
switch (Cart.board_type)
{
case "UNIF_UNL-SMB2J":
break;
default:
return false;
}
prg_count = Cart.prg_size/4;
Cart.wram_size = 0;
// not sure on initial mirroring
SetMirrorType(EMirrorType.Vertical);
return true;
}
public override void WriteEXP(int addr, byte value)
{
addr += 0x4000;
switch (addr)
{
case 0x4022:
if (ROM.Length > 0x10000) { prg = (value & 0x01) << 2; }
break;
case 0x4122:
irqenable = (value & 3) > 0;
IRQSignal = false;
irqcnt = 0;
break;
}
}
public override byte ReadEXP(int addr)
{
if (addr > 0x1000)
{
return ROM[(addr - 0x1000) + (prg_count - 3) * 0x1000];
}
else return base.ReadEXP(addr);
}
public override byte ReadWRAM(int addr)
{
return ROM[addr + (prg_count - 2) * 0x1000];
}
public override byte ReadPRG(int addr)
{
return ROM[(addr + prg * 01000)];
}
public override void ClockCPU()
{
if (irqenable)
{
irqcnt++;
if (irqcnt >= 4096)
{
irqenable = false;
IRQSignal = true;
}
}
}
public override void SyncState(Serializer ser)
{
base.SyncState(ser);
ser.Sync("prg", ref prg);
ser.Sync("irqenable", ref irqenable);
ser.Sync("irqcnt", ref irqcnt);
ser.Sync("swap", ref swap);
}
}
}