[NES] add freeze system for sysbus
This commit is contained in:
parent
729d52d18f
commit
c32a9e11f0
|
@ -16,6 +16,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
public PPU ppu;
|
||||
public APU apu;
|
||||
byte[] ram;
|
||||
MemoryDomain.FreezeData[] sysbus_freeze = new MemoryDomain.FreezeData[65536];
|
||||
protected byte[] CIRAM; //AKA nametables
|
||||
string game_name; //friendly name exposed to user and used as filename base
|
||||
CartInfo cart; //the current cart prototype. should be moved into the board, perhaps
|
||||
|
@ -196,15 +197,21 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
|
||||
public byte ReadMemory(ushort addr)
|
||||
{
|
||||
if (addr < 0x0800) return ram[addr];
|
||||
else if (addr < 0x1000) return ram[addr - 0x0800];
|
||||
else if (addr < 0x1800) return ram[addr - 0x1000];
|
||||
else if (addr < 0x2000) return ram[addr - 0x1800];
|
||||
else if (addr < 0x4000) return ReadPPUReg(addr & 7);
|
||||
else if (addr < 0x4020) return ReadReg(addr); //we're not rebasing the register just to keep register names canonical
|
||||
else if (addr < 0x6000) return board.ReadEXP(addr);
|
||||
else if (addr < 0x8000) return board.ReadPRAM(addr);
|
||||
else return board.ReadPRG(addr - 0x8000);
|
||||
byte ret;
|
||||
if (addr < 0x0800) ret = ram[addr];
|
||||
else if (addr < 0x1000) ret = ram[addr - 0x0800];
|
||||
else if (addr < 0x1800) ret = ram[addr - 0x1000];
|
||||
else if (addr < 0x2000) ret = ram[addr - 0x1800];
|
||||
else if (addr < 0x4000) ret = ReadPPUReg(addr & 7);
|
||||
else if (addr < 0x4020) ret = ReadReg(addr); //we're not rebasing the register just to keep register names canonical
|
||||
else if (addr < 0x6000) ret = board.ReadEXP(addr);
|
||||
else if (addr < 0x8000) ret = board.ReadPRAM(addr);
|
||||
else ret = board.ReadPRG(addr - 0x8000);
|
||||
|
||||
//apply freeze
|
||||
if (sysbus_freeze[addr].IsFrozen) ret = sysbus_freeze[addr].value;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public void WriteMemory(ushort addr, byte value)
|
||||
|
|
|
@ -177,13 +177,16 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
addr => ReadMemory((ushort)addr), (addr, value) => WriteMemory((ushort)addr, value));
|
||||
var PPUBus = new MemoryDomain("PPU Bus", 0x4000, Endian.Little,
|
||||
addr => ppu.ppubus_peek(addr), (addr, value) => ppu.ppubus_write(addr, value));
|
||||
var dCIRAM = new MemoryDomain("CIRAM (nametables)", 0x800, Endian.Little,
|
||||
var CIRAMdomain = new MemoryDomain("CIRAM (nametables)", 0x800, Endian.Little,
|
||||
addr => CIRAM[addr & 0x07FF], (addr, value) => CIRAM[addr & 0x07FF] = value);
|
||||
|
||||
|
||||
SystemBus.GetFreeze = addr => sysbus_freeze[addr];
|
||||
SystemBus.SetFreeze = (addr,value) => sysbus_freeze[addr] = value;
|
||||
|
||||
domains.Add(RAM);
|
||||
domains.Add(SystemBus);
|
||||
domains.Add(PPUBus);
|
||||
domains.Add(dCIRAM);
|
||||
domains.Add(CIRAMdomain);
|
||||
|
||||
if (board.SaveRam != null)
|
||||
{
|
||||
|
|
|
@ -48,8 +48,29 @@ namespace BizHawk
|
|||
public readonly int Size;
|
||||
public readonly Endian Endian;
|
||||
|
||||
public struct FreezeData
|
||||
{
|
||||
public FreezeData(Flag flags, byte value)
|
||||
{
|
||||
this.flags = flags;
|
||||
this.value = value;
|
||||
}
|
||||
public byte value;
|
||||
public Flag flags;
|
||||
public enum Flag : byte
|
||||
{
|
||||
None = 0,
|
||||
Frozen = 1
|
||||
}
|
||||
|
||||
public bool IsFrozen { get { return flags != Flag.None; } }
|
||||
public static FreezeData Unfrozen { get { return new FreezeData(); } }
|
||||
}
|
||||
|
||||
public readonly Func<int, byte> PeekByte;
|
||||
public readonly Action<int, byte> PokeByte;
|
||||
public Func<int, FreezeData> GetFreeze;
|
||||
public Action<int, FreezeData> SetFreeze;
|
||||
|
||||
public MemoryDomain(string name, int size, Endian endian, Func<int, byte> peekByte, Action<int, byte> pokeByte)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue