more scopes for Gambatte memory callbacks

This commit is contained in:
CasualPokePlayer 2021-11-21 19:58:06 -08:00
parent 80d588a002
commit 307f6f262e
2 changed files with 79 additions and 3 deletions

View File

@ -47,7 +47,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
private const string systemBusScope = "System Bus";
private MemoryCallbackSystem _memorycallbacks = new MemoryCallbackSystem(new[] { systemBusScope });
private MemoryCallbackSystem _memorycallbacks = new MemoryCallbackSystem(new[] { systemBusScope, "ROM", "VRAM", "SRAM", "WRAM", "OAM", "HRAM" });
public IMemoryCallbackSystem MemoryCallbacks => _memorycallbacks;
private LibGambatte.MemoryCallback _readcb;
@ -71,7 +71,83 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
return (address, cycleOffset) =>
{
callbackCycleCount = _cycleCount + cycleOffset;
if (getHasCBOfType()) MemoryCallbacks.CallMemoryCallbacks(address, 0, rawFlags, systemBusScope);
if (getHasCBOfType())
{
MemoryCallbacks.CallMemoryCallbacks(address, 0, rawFlags, systemBusScope);
if (address < 0x4000u) // always rom bank 0 for most mbcs (todo: edge mbcs where this doesn't apply)
{
MemoryCallbacks.CallMemoryCallbacks(address, 0, rawFlags, "ROM");
}
else if (address < 0x8000u) // rom bank x
{
var bank = LibGambatte.gambatte_getrombank(GambatteState); // this will return 1 in case there is no mbc (0 is valid for some mbcs too)
address += (uint)(bank * 0x4000);
address -= 0x4000u;
MemoryCallbacks.CallMemoryCallbacks(address, 0, rawFlags, "ROM");
}
else if (address < 0xA000u) // vram (may be banked on CGB in CGB enhanced mode)
{
if (IsCGBMode() && !IsCGBDMGMode())
{
var bank = LibGambatte.gambatte_cpuread(GambatteState, 0xFF4F) & 1;
address += (uint)(bank * 0x2000);
}
address -= 0x8000u;
MemoryCallbacks.CallMemoryCallbacks(address, 0, rawFlags, "VRAM");
}
else if (address < 0xC000u) // sram (may be banked)
{
var bank = LibGambatte.gambatte_getsrambank(GambatteState); // this will return 0 in case there is only one bank
address += (uint)(bank * 0xA000);
address -= 0xA000u;
MemoryCallbacks.CallMemoryCallbacks(address, 0, rawFlags, "SRAM");
}
else if (address < 0xD000u) // wram bank 0
{
address -= 0xC000u;
MemoryCallbacks.CallMemoryCallbacks(address, 0, rawFlags, "WRAM");
}
else if (address < 0xE000u) // wram bank x (always one for dmg/cgb in dmg mode)
{
if (IsCGBMode() && !IsCGBDMGMode())
{
var bank = Math.Max(LibGambatte.gambatte_cpuread(GambatteState, 0xFF70) & 7, 1);
address += (uint)(bank * 0x1000);
}
address -= 0xD000u;
MemoryCallbacks.CallMemoryCallbacks(address, 0, rawFlags, "WRAM");
}
else if (address < 0xFE00u) // echo ram
{
// do we do something here?
}
else if (address < 0xFEA0u) // oam
{
address -= 0xFEA0u;
MemoryCallbacks.CallMemoryCallbacks(address, 0, rawFlags, "OAM");
}
else if (address < 0xFF00u) // "extra" oam
{
// do we do something here?
}
else if (address < 0xFF80u) // mmio
{
// do we do something here?
}
else if (address < 0xFFFF) // hram
{
address -= 0xFF80u;
MemoryCallbacks.CallMemoryCallbacks(address, 0, rawFlags, "HRAM");
}
else if (address == 0xFFFF) // ie reg
{
// do we do something here?
}
else
{
throw new InvalidOperationException("Core accessed invalid address???");
}
}
};
}

View File

@ -28,7 +28,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
_linkedOverflow = new int[_numCores];
RomDetails = "";
_memoryCallbacks = new MemoryCallbackSystem(new[] { "System Bus" });
_memoryCallbacks = new MemoryCallbackSystem(new[] { "System Bus", "ROM", "VRAM", "SRAM", "WRAM", "OAM", "HRAM" });
for (int i = 0; i < _numCores; i++)
{