Skip to content

Commit

Permalink
Performance optimizations by moving bank register pulls to separate f…
Browse files Browse the repository at this point in the history
…unctions.
  • Loading branch information
roydmerkel committed Apr 26, 2024
1 parent ac61c26 commit 8d721de
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public virtual void BulkPeekByte(Range<long> addresses, byte[] values)
if (addresses is null) throw new ArgumentNullException(paramName: nameof(addresses));
if (values is null) throw new ArgumentNullException(paramName: nameof(values));

if ((long) addresses.Count() != values.Length)
if ((long) addresses.Count() > values.Length)
{
throw new InvalidOperationException("Invalid length of values array");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,24 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
{
public partial class Gameboy : IDebuggable
{
public ushort GetMapper(string bank)
{
switch(bank)
{
case "ROM0 BANK":
return (ushort)LibGambatte.gambatte_getbank(GambatteState, LibGambatte.BankType.ROM0);
case "ROMX BANK":
return (ushort)LibGambatte.gambatte_getbank(GambatteState, LibGambatte.BankType.ROMX);
case "VRAM BANK":
return (byte)LibGambatte.gambatte_getbank(GambatteState, LibGambatte.BankType.VRAM);
case "SRAM BANK":
return (byte)LibGambatte.gambatte_getbank(GambatteState, LibGambatte.BankType.SRAM);
case "WRAM BANK":
return (byte)LibGambatte.gambatte_getbank(GambatteState, LibGambatte.BankType.WRAM);
default:
throw new NotImplementedException();
}
}
public IDictionary<string, RegisterValue> GetCpuFlagsAndRegisters()
{
var data = new int[10];
Expand All @@ -24,12 +42,6 @@ public IDictionary<string, RegisterValue> GetCpuFlagsAndRegisters()
["F"] = (byte)(data[(int)LibGambatte.RegIndices.F] & 0xff),
["H"] = (byte)(data[(int)LibGambatte.RegIndices.H] & 0xff),
["L"] = (byte)(data[(int)LibGambatte.RegIndices.L] & 0xff),
// banks
["ROM0 BANK"] = (ushort)LibGambatte.gambatte_getbank(GambatteState, LibGambatte.BankType.ROM0),
["ROMX BANK"] = (ushort)LibGambatte.gambatte_getbank(GambatteState, LibGambatte.BankType.ROMX),
["VRAM BANK"] = (byte)LibGambatte.gambatte_getbank(GambatteState, LibGambatte.BankType.VRAM),
["SRAM BANK"] = (byte)LibGambatte.gambatte_getbank(GambatteState, LibGambatte.BankType.SRAM),
["WRAM BANK"] = (byte)LibGambatte.gambatte_getbank(GambatteState, LibGambatte.BankType.WRAM),
// todo: maybe do [bc]/[de]/[hl]?
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ public IDictionary<string, RegisterValue> GetCpuFlagsAndRegisters()
bool fz = (regs.p & 0x02) != 0;
bool fc = (regs.p & 0x01) != 0;

Api.QUERY_peek_gb_banks(out var banks);

return new Dictionary<string, RegisterValue>
{
["PC"] = regs.pc,
Expand All @@ -41,7 +39,16 @@ public IDictionary<string, RegisterValue> GetCpuFlagsAndRegisters()
["Flag Z"] = fz,
["Flag C"] = fc,
["V"] = regs.v,
["H"] = regs.h,
["H"] = regs.h
};
}

public IDictionary<string, uint> GetBanks()
{
Api.QUERY_peek_gb_banks(out var banks);

return new Dictionary<string, uint>
{
["ROM0 BANK"] = banks.rom0,
["ROMX BANK"] = banks.romx,
["VRAM BANK"] = banks.vram,
Expand Down

0 comments on commit 8d721de

Please sign in to comment.