BizHawk/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Boards/Mapper60.cs

136 lines
2.6 KiB
C#
Raw Normal View History

2016-10-17 22:34:54 +00:00
using System;
using BizHawk.Common;
using BizHawk.Common.NumberExtensions;
2013-11-14 13:15:41 +00:00
namespace BizHawk.Emulation.Cores.Nintendo.NES
2012-07-17 23:52:55 +00:00
{
public sealed class Mapper60 : NES.NESBoardBase
2012-07-17 23:52:55 +00:00
{
// http://wiki.nesdev.com/w/index.php/INES_Mapper_060
2012-07-17 23:52:55 +00:00
private int _reg;
private bool IsPrg16Mode { get { return _reg.Bit(7); } }
[MapperProp]
public int Mapper60_DipSwitch;
private const int DipSwitchMask = 3;
2012-07-17 23:52:55 +00:00
public override bool Configure(NES.EDetectionOrigin origin)
{
switch (Cart.board_type)
{
case "MAPPER060":
2016-10-17 22:34:54 +00:00
// Hack, Reset 4-in-1 is a different board but still assign to mapper 60
if (Cart.prg_size != 64 || Cart.chr_size != 32)
{
break;
}
return false;
2012-07-17 23:52:55 +00:00
default:
return false;
}
AutoMapperProps.Apply(this);
2012-07-17 23:52:55 +00:00
return true;
}
public override void SyncState(Serializer ser)
{
base.SyncState(ser);
ser.Sync("_reg", ref _reg);
}
public override void WritePRG(int addr, byte value)
{
_reg = addr;
int mirr = ((_reg & 8) >> 3) ^ 1;
SetMirrorType(mirr > 0 ? EMirrorType.Vertical : EMirrorType.Horizontal);
2012-07-17 23:52:55 +00:00
}
public override byte ReadPRG(int addr)
2012-07-17 23:52:55 +00:00
{
if ((_reg & 0x100) > 0)
2012-07-17 23:52:55 +00:00
{
return (byte)(Mapper60_DipSwitch & DipSwitchMask);
}
if (IsPrg16Mode)
{
int bank = (_reg >> 4) & 7;
return ROM[(bank * 0x4000) + (addr & 0x3FFF)];
2012-07-17 23:52:55 +00:00
}
else
{
int bank = (_reg >> 5) & 3;
return ROM[(bank * 0x8000) + (addr & 0x7FFF)];
2012-07-17 23:52:55 +00:00
}
}
public override byte ReadPPU(int addr)
{
if (addr < 0x2000)
{
return VROM[((_reg & 7) * 0x2000) + (addr & 0x1FFF)];
2012-07-17 23:52:55 +00:00
}
2012-07-17 23:52:55 +00:00
return base.ReadPPU(addr);
}
}
2016-10-17 22:34:54 +00:00
public class Reset4in1 : NES.NESBoardBase
{
private int resetSwitch = 0;
public override bool Configure(NES.EDetectionOrigin origin)
{
switch (Cart.board_type)
{
case "MAPPER060":
// Hack, Reset 4-in-1 is a different board but still assign to mapper 60
if (Cart.prg_size == 64 && Cart.chr_size == 32)
{
break;
}
return false;
default:
return false;
}
return true;
}
public override void SyncState(Serializer ser)
{
ser.Sync("resetSwitch", ref resetSwitch);
base.SyncState(ser);
}
public override void NESSoftReset()
{
resetSwitch = (resetSwitch + 1) & 3;
base.NESSoftReset();
}
public override byte ReadPRG(int addr)
{
return ROM[(resetSwitch << 14) + (addr & 0x3FFF)];
}
public override byte ReadPPU(int addr)
{
if (addr < 0x2000)
{
return VROM[(resetSwitch << 13) + addr];
}
return base.ReadPPU(addr);
}
}
2012-07-17 23:52:55 +00:00
}