BizHawk/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/AxROM.cs

109 lines
2.3 KiB
C#
Raw Normal View History

2011-02-28 09:39:24 +00:00
using System;
2011-03-01 09:32:12 +00:00
using System.IO;
2011-02-28 09:39:24 +00:00
using System.Diagnostics;
namespace BizHawk.Emulation.Consoles.Nintendo.Boards
{
2011-03-01 09:32:12 +00:00
//TODO - hardcode CRAM size and assert
2011-02-28 09:39:24 +00:00
//generally mapper7
2011-03-01 09:32:12 +00:00
//Battletoads
//Time Lord
//Marble Madness
2011-02-28 09:39:24 +00:00
public class AxROM : NES.NESBoardBase
{
2011-03-01 09:32:12 +00:00
//configuration
2011-02-28 09:39:24 +00:00
string type;
bool bus_conflict;
int cram_mask;
int prg_mask;
2011-03-01 09:32:12 +00:00
//state
byte[] cram;
2011-02-28 09:39:24 +00:00
int prg;
public AxROM(string type)
{
this.type = type;
switch (type)
{
case "ANROM": bus_conflict = false; break;
case "AOROM": bus_conflict = true; break;
}
}
public override void Initialize(NES.RomInfo romInfo, NES nes)
{
base.Initialize(romInfo, nes);
//guess CRAM size (this is a very confident guess!)
if (RomInfo.CRAM_Size == -1) RomInfo.CRAM_Size = 8;
cram = new byte[RomInfo.CRAM_Size * 1024];
cram_mask = cram.Length - 1;
if (type == "ANROM")
{
Debug.Assert(RomInfo.PRG_Size == 8, "not sure how to handle this; please report");
prg_mask = 3;
}
if (type == "AOROM")
{
Debug.Assert(RomInfo.PRG_Size == 16 || RomInfo.PRG_Size == 8, "not sure how to handle this; please report");
prg_mask = RomInfo.PRG_Size-1;
}
2011-02-28 10:16:07 +00:00
//it is necessary to write during initialization to set the mirroring
2011-02-28 09:39:24 +00:00
WritePRG(0, 0);
}
public override byte ReadPRG(int addr)
{
return RomInfo.ROM[addr + (prg << 15)];
}
public override void WritePRG(int addr, byte value)
{
2011-02-28 10:48:18 +00:00
if (bus_conflict) value = HandleNormalPRGConflict(addr,value);
2011-02-28 09:39:24 +00:00
prg = value & prg_mask;
if ((value & 0x10) == 0)
SetMirrorType(NES.EMirrorType.OneScreenA);
else
SetMirrorType(NES.EMirrorType.OneScreenB);
}
public override byte ReadPPU(int addr)
{
if (addr < 0x2000)
{
return cram[addr & cram_mask];
}
else return base.ReadPPU(addr);
}
public override void WritePPU(int addr, byte value)
{
if (addr < 0x2000)
{
cram[addr & cram_mask] = value;
}
else base.WritePPU(addr,value);
}
2011-03-01 09:32:12 +00:00
public override void SaveStateBinary(BinaryWriter bw)
{
base.SaveStateBinary(bw);
bw.Write(prg);
Util.WriteByteBuffer(bw, cram);
}
public override void LoadStateBinary(BinaryReader br)
{
base.LoadStateBinary(br);
prg = br.ReadInt32();
cram = Util.ReadByteBuffer(br, false);
}
2011-02-28 09:39:24 +00:00
}
}