2013-10-27 22:07:40 +00:00
|
|
|
|
using BizHawk.Common;
|
2014-07-03 15:35:50 +00:00
|
|
|
|
using BizHawk.Common.NumberExtensions;
|
2013-10-27 22:07:40 +00:00
|
|
|
|
|
2013-11-14 13:15:41 +00:00
|
|
|
|
namespace BizHawk.Emulation.Cores.Nintendo.NES
|
2012-07-19 18:30:39 +00:00
|
|
|
|
{
|
2013-08-25 01:08:17 +00:00
|
|
|
|
public sealed class Mapper057 : NES.NESBoardBase
|
2012-07-19 18:30:39 +00:00
|
|
|
|
{
|
2016-10-17 13:01:11 +00:00
|
|
|
|
// http://wiki.nesdev.com/w/index.php/INES_Mapper_057
|
2012-07-19 18:30:39 +00:00
|
|
|
|
|
|
|
|
|
bool prg_mode = false;
|
2012-07-20 03:19:19 +00:00
|
|
|
|
int chr_reg_low_0, chr_reg_low_1, chr_reg;
|
2012-07-19 18:30:39 +00:00
|
|
|
|
int prg_reg;
|
|
|
|
|
|
2016-10-17 13:01:11 +00:00
|
|
|
|
[MapperProp]
|
|
|
|
|
public int Mapper57_DipSwitch = 0;
|
|
|
|
|
|
2012-07-19 18:30:39 +00:00
|
|
|
|
public override bool Configure(NES.EDetectionOrigin origin)
|
|
|
|
|
{
|
|
|
|
|
switch (Cart.board_type)
|
|
|
|
|
{
|
|
|
|
|
case "MAPPER057":
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SetMirrorType(EMirrorType.Horizontal);
|
|
|
|
|
|
2016-10-17 13:01:11 +00:00
|
|
|
|
AutoMapperProps.Apply(this);
|
|
|
|
|
|
2012-07-19 18:30:39 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void SyncState(Serializer ser)
|
|
|
|
|
{
|
|
|
|
|
ser.Sync("prg_reg", ref prg_reg);
|
|
|
|
|
ser.Sync("chr_reg", ref chr_reg);
|
2012-07-20 03:19:19 +00:00
|
|
|
|
ser.Sync("chr_reg_low_0", ref chr_reg);
|
|
|
|
|
ser.Sync("chr_reg_low_1", ref chr_reg);
|
2012-07-19 18:30:39 +00:00
|
|
|
|
ser.Sync("prg_mode", ref prg_mode);
|
|
|
|
|
base.SyncState(ser);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void WritePRG(int addr, byte value)
|
|
|
|
|
{
|
2012-07-20 03:19:19 +00:00
|
|
|
|
addr &= 0x8800;
|
2012-07-19 18:30:39 +00:00
|
|
|
|
if (addr == 0)
|
|
|
|
|
{
|
2012-07-20 03:19:19 +00:00
|
|
|
|
chr_reg_low_0 = value & 0x07;
|
|
|
|
|
chr_reg &= 0x08;
|
|
|
|
|
chr_reg |= (value & 0x40) >> 3;
|
2012-07-19 18:30:39 +00:00
|
|
|
|
}
|
2012-07-20 03:19:19 +00:00
|
|
|
|
else if(addr == 0x800)
|
2012-07-19 18:30:39 +00:00
|
|
|
|
{
|
|
|
|
|
prg_reg = (value >> 5) & 0x07;
|
|
|
|
|
prg_mode = value.Bit(4);
|
2012-07-20 03:19:19 +00:00
|
|
|
|
chr_reg_low_1 = (value & 0x07);
|
2012-07-20 02:57:46 +00:00
|
|
|
|
|
2016-10-17 13:01:11 +00:00
|
|
|
|
if (value.Bit(3))
|
2012-07-19 18:30:39 +00:00
|
|
|
|
{
|
|
|
|
|
SetMirrorType(EMirrorType.Horizontal);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
SetMirrorType(EMirrorType.Vertical);
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-07-20 03:19:19 +00:00
|
|
|
|
|
|
|
|
|
chr_reg &= ~0x07;
|
|
|
|
|
chr_reg |= (chr_reg_low_0 | chr_reg_low_1);
|
2012-07-19 18:30:39 +00:00
|
|
|
|
|
|
|
|
|
//Console.WriteLine("chr page = {0}", chr_reg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override byte ReadPRG(int addr)
|
|
|
|
|
{
|
|
|
|
|
if (prg_mode)
|
|
|
|
|
{
|
|
|
|
|
return ROM[((prg_reg >> 1) * 0x8000) + addr];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return ROM[(prg_reg * 0x4000) + (addr & 0x3FFF)];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override byte ReadPPU(int addr)
|
|
|
|
|
{
|
|
|
|
|
if (addr < 0x2000)
|
|
|
|
|
{
|
|
|
|
|
return VROM[(chr_reg * 0x2000) + addr];
|
|
|
|
|
}
|
|
|
|
|
return base.ReadPPU(addr);
|
|
|
|
|
}
|
2016-10-17 13:01:11 +00:00
|
|
|
|
|
|
|
|
|
public override byte ReadWRAM(int addr)
|
|
|
|
|
{
|
|
|
|
|
return (byte)(Mapper57_DipSwitch & 3);
|
|
|
|
|
}
|
2012-07-19 18:30:39 +00:00
|
|
|
|
}
|
|
|
|
|
}
|