From ced37c45c312f6d07bbe1736ed0e002255a9f373 Mon Sep 17 00:00:00 2001 From: alyosha-tas Date: Thu, 2 Apr 2020 15:41:03 -0400 Subject: [PATCH] GBHawk: memory ap optimizations --- .../Nintendo/GBHawk/Mappers/MapperBase.cs | 14 +++++- .../Nintendo/GBHawk/Mappers/Mapper_Camera.cs | 45 +++++++++--------- .../Nintendo/GBHawk/Mappers/Mapper_Default.cs | 29 +++++++----- .../Nintendo/GBHawk/Mappers/Mapper_HuC1.cs | 14 ++++-- .../Nintendo/GBHawk/Mappers/Mapper_HuC3.cs | 16 ++++--- .../Nintendo/GBHawk/Mappers/Mapper_MBC1.cs | 37 ++++++++------- .../GBHawk/Mappers/Mapper_MBC1_Multi.cs | 35 +++++++------- .../Nintendo/GBHawk/Mappers/Mapper_MBC2.cs | 16 ++++--- .../Nintendo/GBHawk/Mappers/Mapper_MBC3.cs | 47 ++++++++++--------- .../Nintendo/GBHawk/Mappers/Mapper_MBC5.cs | 33 ++++++------- .../Nintendo/GBHawk/Mappers/Mapper_MBC6.cs | 18 +++++-- .../Nintendo/GBHawk/Mappers/Mapper_MBC7.cs | 14 ++++-- .../Nintendo/GBHawk/Mappers/Mapper_MMM01.cs | 18 +++++-- .../GBHawk/Mappers/Mapper_RockMan8.cs | 17 +++---- .../GBHawk/Mappers/Mapper_Sachen_MMC1.cs | 17 +++---- .../GBHawk/Mappers/Mapper_Sachen_MMC2.cs | 21 +++++---- .../Nintendo/GBHawk/Mappers/Mapper_TAMA5.cs | 42 ++++++++--------- .../GBHawk/Mappers/Mapper_WisdomTree.cs | 25 +++++----- .../Consoles/Nintendo/GBHawk/MemoryMap.cs | 24 +++++----- 19 files changed, 273 insertions(+), 209 deletions(-) diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/MapperBase.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/MapperBase.cs index 7bfd6073d6..12da082b14 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/MapperBase.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/MapperBase.cs @@ -7,12 +7,22 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk { public GBHawk Core { get; set; } - public virtual byte ReadMemory(ushort addr) + public virtual byte ReadMemoryLow(ushort addr) { return 0; } - public virtual byte PeekMemory(ushort addr) + public virtual byte ReadMemoryHigh(ushort addr) + { + return 0; + } + + public virtual byte PeekMemoryLow(ushort addr) + { + return 0; + } + + public virtual byte PeekMemoryHigh(ushort addr) { return 0; } diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_Camera.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_Camera.cs index 2d169926b6..1fac3677e5 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_Camera.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_Camera.cs @@ -28,39 +28,40 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk regs_enable = false; } - public override byte ReadMemory(ushort addr) + public override byte ReadMemoryLow(ushort addr) { if (addr < 0x4000) { return Core._rom[addr]; } - else if (addr < 0x8000) + else { return Core._rom[(addr - 0x4000) + ROM_bank * 0x4000]; } + } + + public override byte ReadMemoryHigh(ushort addr) + { + if (regs_enable) + { + if ((addr & 0x7F) == 0) + { + return 0;// regs[0]; + } + else + { + return 0; + } + } else { - if (regs_enable) + if (/*RAM_enable && */(((addr - 0xA000) + RAM_bank * 0x2000) < Core.cart_RAM.Length)) { - if ((addr & 0x7F) == 0) - { - return 0;// regs[0]; - } - else - { - return 0; - } + return Core.cart_RAM[(addr - 0xA000) + RAM_bank * 0x2000]; } - else + else { - if (/*RAM_enable && */(((addr - 0xA000) + RAM_bank * 0x2000) < Core.cart_RAM.Length)) - { - return Core.cart_RAM[(addr - 0xA000) + RAM_bank * 0x2000]; - } - else - { - return 0xFF; - } + return 0xFF; } } } @@ -92,9 +93,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk } } - public override byte PeekMemory(ushort addr) + public override byte PeekMemoryLow(ushort addr) { - return ReadMemory(addr); + return ReadMemoryLow(addr); } public override void WriteMemory(ushort addr, byte value) diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_Default.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_Default.cs index 6b22b6ee8b..94bfe54e00 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_Default.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_Default.cs @@ -10,22 +10,20 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk // nothing to initialize } - public override byte ReadMemory(ushort addr) + public override byte ReadMemoryLow(ushort addr) { - if (addr < 0x8000) + return Core._rom[addr]; + } + + public override byte ReadMemoryHigh(ushort addr) + { + if (Core.cart_RAM != null) { - return Core._rom[addr]; + return Core.cart_RAM[addr - 0xA000]; } else { - if (Core.cart_RAM != null) - { - return Core.cart_RAM[addr - 0xA000]; - } - else - { - return 0; - } + return 0; } } @@ -48,9 +46,14 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk } } - public override byte PeekMemory(ushort addr) + public override byte PeekMemoryLow(ushort addr) { - return ReadMemory(addr); + return ReadMemoryLow(addr); + } + + public override byte PeekMemoryHigh(ushort addr) + { + return ReadMemoryHigh(addr); } public override void WriteMemory(ushort addr, byte value) diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_HuC1.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_HuC1.cs index 62bd8c3f65..febbccf996 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_HuC1.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_HuC1.cs @@ -31,17 +31,21 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk } } - public override byte ReadMemory(ushort addr) + public override byte ReadMemoryLow(ushort addr) { if (addr < 0x4000) { return Core._rom[addr]; } - else if (addr < 0x8000) + else { return Core._rom[(addr - 0x4000) + ROM_bank * 0x4000]; } - else if ((addr >= 0xA000) && (addr < 0xC000)) + } + + public override byte ReadMemoryHigh(ushort addr) + { + if ((addr >= 0xA000) && (addr < 0xC000)) { if (RAM_enable) { @@ -115,9 +119,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk } } - public override byte PeekMemory(ushort addr) + public override byte PeekMemoryLow(ushort addr) { - return ReadMemory(addr); + return ReadMemoryLow(addr); } public override void WriteMemory(ushort addr, byte value) diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_HuC3.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_HuC3.cs index cc00676c90..4c88df0396 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_HuC3.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_HuC3.cs @@ -44,17 +44,21 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk } } - public override byte ReadMemory(ushort addr) + public override byte ReadMemoryLow(ushort addr) { if (addr < 0x4000) { return Core._rom[addr]; } - else if (addr < 0x8000) + else { return Core._rom[(addr - 0x4000) + ROM_bank * 0x4000]; } - else if ((addr >= 0xA000) && (addr < 0xC000)) + } + + public override byte ReadMemoryHigh(ushort addr) + { + if ((addr >= 0xA000) && (addr < 0xC000)) { if ((control >= 0xB) && (control < 0xE)) { @@ -64,7 +68,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk } return chip_read; } - + if (RAM_enable) { if (Core.cart_RAM != null) @@ -136,9 +140,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk } } - public override byte PeekMemory(ushort addr) + public override byte PeekMemoryLow(ushort addr) { - return ReadMemory(addr); + return ReadMemoryLow(addr); } public override void WriteMemory(ushort addr, byte value) diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_MBC1.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_MBC1.cs index e305e42f86..53e739d655 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_MBC1.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_MBC1.cs @@ -32,42 +32,43 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk } } - public override byte ReadMemory(ushort addr) + public override byte ReadMemoryLow(ushort addr) { if (addr < 0x4000) { - // lowest bank is fixed, but is still effected by mode + // lowest bank is fixed, but is still effected by mode if (sel_mode) { - return Core._rom[(ROM_bank & 0x60) * 0x4000 + addr]; + return Core._rom[(ROM_bank & 0x60) * 0x4000 + addr]; } else { return Core._rom[addr]; } } - else if (addr < 0x8000) + else { return Core._rom[(addr - 0x4000) + ROM_bank * 0x4000]; } - else - { - if (Core.cart_RAM != null) - { - if (RAM_enable && (((addr - 0xA000) + RAM_bank * 0x2000) < Core.cart_RAM.Length)) - { - return Core.cart_RAM[(addr - 0xA000) + RAM_bank * 0x2000]; - } - else - { - return 0xFF; - } + } + public override byte ReadMemoryHigh(ushort addr) + { + if (Core.cart_RAM != null) + { + if (RAM_enable && (((addr - 0xA000) + RAM_bank * 0x2000) < Core.cart_RAM.Length)) + { + return Core.cart_RAM[(addr - 0xA000) + RAM_bank * 0x2000]; } else { return 0xFF; } + + } + else + { + return 0xFF; } } @@ -110,9 +111,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk } } - public override byte PeekMemory(ushort addr) + public override byte PeekMemoryLow(ushort addr) { - return ReadMemory(addr); + return ReadMemoryLow(addr); } public override void WriteMemory(ushort addr, byte value) diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_MBC1_Multi.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_MBC1_Multi.cs index d438f83228..d6acccd6ac 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_MBC1_Multi.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_MBC1_Multi.cs @@ -28,7 +28,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk } } - public override byte ReadMemory(ushort addr) + public override byte ReadMemoryLow(ushort addr) { if (addr < 0x4000) { @@ -42,28 +42,29 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk return Core._rom[addr]; } } - else if (addr < 0x8000) + else { return Core._rom[(addr - 0x4000) + (((ROM_bank & 0x60) >> 1) | (ROM_bank & 0xF)) * 0x4000]; } - else - { - if (Core.cart_RAM != null) - { - if (RAM_enable && (((addr - 0xA000) + RAM_bank * 0x2000) < Core.cart_RAM.Length)) - { - return Core.cart_RAM[(addr - 0xA000) + RAM_bank * 0x2000]; - } - else - { - return 0xFF; - } + } + public override byte ReadMemoryHigh(ushort addr) + { + if (Core.cart_RAM != null) + { + if (RAM_enable && (((addr - 0xA000) + RAM_bank * 0x2000) < Core.cart_RAM.Length)) + { + return Core.cart_RAM[(addr - 0xA000) + RAM_bank * 0x2000]; } else { - return 0; + return 0xFF; } + + } + else + { + return 0; } } @@ -106,9 +107,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk } } - public override byte PeekMemory(ushort addr) + public override byte PeekMemoryLow(ushort addr) { - return ReadMemory(addr); + return ReadMemoryLow(addr); } public override void WriteMemory(ushort addr, byte value) diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_MBC2.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_MBC2.cs index 6dba2cbeec..7d5649dd8a 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_MBC2.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_MBC2.cs @@ -19,17 +19,21 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk ROM_mask = Core._rom.Length / 0x4000 - 1; } - public override byte ReadMemory(ushort addr) + public override byte ReadMemoryLow(ushort addr) { if (addr < 0x4000) { return Core._rom[addr]; } - else if (addr < 0x8000) + else { return Core._rom[(addr - 0x4000) + ROM_bank * 0x4000]; - } - else if ((addr >= 0xA000) && (addr < 0xA200)) + } + } + + public override byte ReadMemoryHigh(ushort addr) + { + if ((addr >= 0xA000) && (addr < 0xA200)) { if (RAM_enable) { @@ -67,9 +71,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk } } - public override byte PeekMemory(ushort addr) + public override byte PeekMemoryLow(ushort addr) { - return ReadMemory(addr); + return ReadMemoryLow(addr); } public override void WriteMemory(ushort addr, byte value) diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_MBC3.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_MBC3.cs index 355192afc4..a0bd65fb91 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_MBC3.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_MBC3.cs @@ -45,47 +45,48 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk RTC_regs_latch_wr = true; } - public override byte ReadMemory(ushort addr) + public override byte ReadMemoryLow(ushort addr) { if (addr < 0x4000) { return Core._rom[addr]; } - else if (addr < 0x8000) + else { return Core._rom[(addr - 0x4000) + ROM_bank * 0x4000]; } - else - { - if (RAM_enable) - { - if ((Core.cart_RAM != null) && (RAM_bank <= RAM_mask)) - { - if (((addr - 0xA000) + RAM_bank * 0x2000) < Core.cart_RAM.Length) - { - return Core.cart_RAM[(addr - 0xA000) + RAM_bank * 0x2000]; - } - else - { - return 0xFF; - } - } + } - if ((RAM_bank >= 8) && (RAM_bank <= 0xC)) + public override byte ReadMemoryHigh(ushort addr) + { + if (RAM_enable) + { + if ((Core.cart_RAM != null) && (RAM_bank <= RAM_mask)) + { + if (((addr - 0xA000) + RAM_bank * 0x2000) < Core.cart_RAM.Length) { - //Console.WriteLine("reg: " + (RAM_bank - 8) + " value: " + RTC_regs_latch[RAM_bank - 8] + " cpu: " + Core.cpu.TotalExecutedCycles); - return RTC_regs_latch[RAM_bank - 8]; + return Core.cart_RAM[(addr - 0xA000) + RAM_bank * 0x2000]; } else { - return 0x0; + return 0xFF; } } + + if ((RAM_bank >= 8) && (RAM_bank <= 0xC)) + { + //Console.WriteLine("reg: " + (RAM_bank - 8) + " value: " + RTC_regs_latch[RAM_bank - 8] + " cpu: " + Core.cpu.TotalExecutedCycles); + return RTC_regs_latch[RAM_bank - 8]; + } else { return 0x0; } } + else + { + return 0x0; + } } public override void MapCDL(ushort addr, LR35902.eCDLogMemFlags flags) @@ -130,9 +131,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk } } - public override byte PeekMemory(ushort addr) + public override byte PeekMemoryLow(ushort addr) { - return ReadMemory(addr); + return ReadMemoryLow(addr); } public override void WriteMemory(ushort addr, byte value) diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_MBC5.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_MBC5.cs index 4dc482ae55..6b67f6c02d 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_MBC5.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_MBC5.cs @@ -31,34 +31,35 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk } } - public override byte ReadMemory(ushort addr) + public override byte ReadMemoryLow(ushort addr) { if (addr < 0x4000) { return Core._rom[addr]; } - else if (addr < 0x8000) + else { return Core._rom[(addr - 0x4000) + ROM_bank * 0x4000]; } - else - { - if (Core.cart_RAM != null) - { - if (RAM_enable && (((addr - 0xA000) + RAM_bank * 0x2000) < Core.cart_RAM.Length)) - { - return Core.cart_RAM[(addr - 0xA000) + RAM_bank * 0x2000]; - } - else - { - return 0xFF; - } + } + public override byte ReadMemoryHigh(ushort addr) + { + if (Core.cart_RAM != null) + { + if (RAM_enable && (((addr - 0xA000) + RAM_bank * 0x2000) < Core.cart_RAM.Length)) + { + return Core.cart_RAM[(addr - 0xA000) + RAM_bank * 0x2000]; } else { return 0xFF; } + + } + else + { + return 0xFF; } } @@ -93,9 +94,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk } } - public override byte PeekMemory(ushort addr) + public override byte PeekMemoryLow(ushort addr) { - return ReadMemory(addr); + return ReadMemoryLow(addr); } public override void WriteMemory(ushort addr, byte value) diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_MBC6.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_MBC6.cs index c2b496fde8..3611dd1413 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_MBC6.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_MBC6.cs @@ -10,7 +10,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk // nothing to initialize } - public override byte ReadMemory(ushort addr) + public override byte ReadMemoryLow(ushort addr) { if (addr < 0x8000) { @@ -29,6 +29,18 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk } } + public override byte ReadMemoryHigh(ushort addr) + { + if (Core.cart_RAM != null) + { + return Core.cart_RAM[addr - 0xA000]; + } + else + { + return 0; + } + } + public override void MapCDL(ushort addr, LR35902.eCDLogMemFlags flags) { if (addr < 0x8000) @@ -48,9 +60,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk } } - public override byte PeekMemory(ushort addr) + public override byte PeekMemoryLow(ushort addr) { - return ReadMemory(addr); + return ReadMemoryLow(addr); } public override void WriteMemory(ushort addr, byte value) diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_MBC7.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_MBC7.cs index 84a9f2c648..69204039f8 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_MBC7.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_MBC7.cs @@ -57,17 +57,21 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk instr_bit_counter = instr = EE_addr = instr_case = instr_clocks = EE_value = countdown = 0; } - public override byte ReadMemory(ushort addr) + public override byte ReadMemoryLow(ushort addr) { if (addr < 0x4000) { return Core._rom[addr]; } - else if (addr < 0x8000) + else { return Core._rom[(addr - 0x4000) + ROM_bank * 0x4000]; } - else if (addr < 0xA000) + } + + public override byte ReadMemoryHigh(ushort addr) + { + if (addr < 0xA000) { return 0xFF; } @@ -119,9 +123,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk } } - public override byte PeekMemory(ushort addr) + public override byte PeekMemoryLow(ushort addr) { - return ReadMemory(addr); + return ReadMemoryLow(addr); } public override void WriteMemory(ushort addr, byte value) diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_MMM01.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_MMM01.cs index 8be96a5562..d804752560 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_MMM01.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_MMM01.cs @@ -10,7 +10,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk // nothing to initialize } - public override byte ReadMemory(ushort addr) + public override byte ReadMemoryLow(ushort addr) { if (addr < 0x8000) { @@ -29,6 +29,18 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk } } + public override byte ReadMemoryHigh(ushort addr) + { + if (Core.cart_RAM != null) + { + return Core.cart_RAM[addr - 0xA000]; + } + else + { + return 0; + } + } + public override void MapCDL(ushort addr, LR35902.eCDLogMemFlags flags) { if (addr < 0x8000) @@ -48,9 +60,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk } } - public override byte PeekMemory(ushort addr) + public override byte PeekMemoryLow(ushort addr) { - return ReadMemory(addr); + return ReadMemoryLow(addr); } public override void WriteMemory(ushort addr, byte value) diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_RockMan8.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_RockMan8.cs index db618691f5..2cd2a9c92d 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_RockMan8.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_RockMan8.cs @@ -18,7 +18,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk if (ROM_mask > 4) { ROM_mask |= 3; } } - public override byte ReadMemory(ushort addr) + public override byte ReadMemoryLow(ushort addr) { if (addr < 0x4000) { @@ -26,14 +26,15 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk return Core._rom[addr]; } - else if (addr < 0x8000) + else { return Core._rom[(addr - 0x4000) + ROM_bank * 0x4000]; } - else - { - return 0xFF; - } + } + + public override byte ReadMemoryHigh(ushort addr) + { + return 0xFF; } public override void MapCDL(ushort addr, LR35902.eCDLogMemFlags flags) @@ -54,9 +55,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk } } - public override byte PeekMemory(ushort addr) + public override byte PeekMemoryLow(ushort addr) { - return ReadMemory(addr); + return ReadMemoryLow(addr); } public override void WriteMemory(ushort addr, byte value) diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_Sachen_MMC1.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_Sachen_MMC1.cs index 2b827f9019..53e1bdc5a3 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_Sachen_MMC1.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_Sachen_MMC1.cs @@ -33,7 +33,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk counter = 0; } - public override byte ReadMemory(ushort addr) + public override byte ReadMemoryLow(ushort addr) { if (addr < 0x4000) { @@ -60,14 +60,15 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk return Core._rom[addr + BASE_ROM_Bank * 0x4000]; } - else if (addr < 0x8000) + else { return Core._rom[(addr - 0x4000) + ROM_bank * 0x4000]; } - else - { - return 0xFF; - } + } + + public override byte ReadMemoryHigh(ushort addr) + { + return 0xFF; } public override void MapCDL(ushort addr, LR35902.eCDLogMemFlags flags) @@ -107,9 +108,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk } } - public override byte PeekMemory(ushort addr) + public override byte PeekMemoryLow(ushort addr) { - return ReadMemory(addr); + return ReadMemoryLow(addr); } public override void WriteMemory(ushort addr, byte value) diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_Sachen_MMC2.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_Sachen_MMC2.cs index 49ae5bbe7e..814d2c8533 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_Sachen_MMC2.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_Sachen_MMC2.cs @@ -35,7 +35,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk counter = 0; } - public override byte ReadMemory(ushort addr) + public override byte ReadMemoryLow(ushort addr) { if (addr < 0x4000) { @@ -60,21 +60,22 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk return Core._rom[addr + BASE_ROM_Bank * 0x4000]; } - else if (addr < 0x8000) + else { int temp_bank = (ROM_bank & ~ROM_bank_mask) | (ROM_bank_mask & BASE_ROM_Bank); temp_bank &= ROM_mask; return Core._rom[(addr - 0x4000) + temp_bank * 0x4000]; } - else - { - return 0xFF; - } } - public override void MapCDL(ushort addr, LR35902.eCDLogMemFlags flags) - { + public override byte ReadMemoryHigh(ushort addr) + { + return 0xFF; + } + + public override void MapCDL(ushort addr, LR35902.eCDLogMemFlags flags) + { if (addr < 0x4000) { // header is scrambled @@ -111,9 +112,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk } } - public override byte PeekMemory(ushort addr) + public override byte PeekMemoryLow(ushort addr) { - return ReadMemory(addr); + return ReadMemoryLow(addr); } public override void WriteMemory(ushort addr, byte value) diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_TAMA5.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_TAMA5.cs index d22e545c9e..5566a5370c 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_TAMA5.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_TAMA5.cs @@ -46,35 +46,35 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk ctrl = 0; } - public override byte ReadMemory(ushort addr) + public override byte ReadMemoryLow(ushort addr) { if (addr < 0x4000) { return Core._rom[addr]; } - else if (addr < 0x8000) + else { return Core._rom[(addr - 0x4000) + ROM_bank * 0x4000]; } - else + } + + public override byte ReadMemoryHigh(ushort addr) + { + switch (ctrl) { - - switch (ctrl) - { - case 0xA: - // The game won't proceed unless this value (anded with 3) is 1 - // see bank 0: 0x1A7D to 0x1A89 - return 1; - case 0xC: - //Console.WriteLine("read low: " + Chip_return_low); - return Chip_return_low; - case 0xD: - //Console.WriteLine("read high: " + Chip_return_high); - return Chip_return_high; - } - - return 0x0; + case 0xA: + // The game won't proceed unless this value (anded with 3) is 1 + // see bank 0: 0x1A7D to 0x1A89 + return 1; + case 0xC: + //Console.WriteLine("read low: " + Chip_return_low); + return Chip_return_low; + case 0xD: + //Console.WriteLine("read high: " + Chip_return_high); + return Chip_return_high; } + + return 0x0; } public override void MapCDL(ushort addr, LR35902.eCDLogMemFlags flags) @@ -93,9 +93,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk } } - public override byte PeekMemory(ushort addr) + public override byte PeekMemoryLow(ushort addr) { - return ReadMemory(addr); + return ReadMemoryLow(addr); } public override void WriteMemory(ushort addr, byte value) diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_WisdomTree.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_WisdomTree.cs index 657d71aee5..59a9c669cf 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_WisdomTree.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_WisdomTree.cs @@ -19,16 +19,14 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk if (ROM_mask > 0x100) { ROM_mask |= 0xFF; } } - public override byte ReadMemory(ushort addr) + public override byte ReadMemoryLow(ushort addr) { - if (addr < 0x8000) - { - return Core._rom[ROM_bank * 0x8000 + addr]; - } - else - { - return 0xFF; - } + return Core._rom[ROM_bank * 0x8000 + addr]; + } + + public override byte ReadMemoryHigh(ushort addr) + { + return 0xFF; } public override void MapCDL(ushort addr, LR35902.eCDLogMemFlags flags) @@ -43,9 +41,14 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk } } - public override byte PeekMemory(ushort addr) + public override byte PeekMemoryLow(ushort addr) { - return ReadMemory(addr); + return ReadMemoryLow(addr); + } + + public override byte PeekMemoryHigh(ushort addr) + { + return ReadMemoryHigh(addr); } public override void WriteMemory(ushort addr, byte value) diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/MemoryMap.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/MemoryMap.cs index e375ce9156..eacf4b6ffe 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/MemoryMap.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/MemoryMap.cs @@ -42,7 +42,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk } else { - return mapper.ReadMemory(addr); + return mapper.ReadMemoryLow(addr); } } else if ((addr >= 0xE000) && (addr < 0xF000)) @@ -74,7 +74,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk { if (addr >= 0x900) { - return mapper.ReadMemory(addr); + return mapper.ReadMemoryLow(addr); } else { @@ -87,7 +87,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk } else { - return mapper.ReadMemory(addr); + return mapper.ReadMemoryLow(addr); } } else if (addr >= 0x200) @@ -99,12 +99,12 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk } else { - return mapper.ReadMemory(addr); + return mapper.ReadMemoryLow(addr); } } else { - return mapper.ReadMemory(addr); + return mapper.ReadMemoryLow(addr); } } } @@ -115,7 +115,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk } else if (addr < 0xC000) { - return mapper.ReadMemory(addr); + return mapper.ReadMemoryHigh(addr); } else if (addr < 0xFE00) { @@ -266,7 +266,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk } else { - return mapper.ReadMemory(addr); + return mapper.PeekMemoryLow(addr); } } else if ((addr >= 0xE000) && (addr < 0xF000)) @@ -297,7 +297,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk { if (addr >= 0x900) { - return mapper.ReadMemory(addr); + return mapper.PeekMemoryLow(addr); } else { @@ -310,7 +310,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk } else { - return mapper.ReadMemory(addr); + return mapper.PeekMemoryLow(addr); } } else if (addr >= 0x200) @@ -322,12 +322,12 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk } else { - return mapper.ReadMemory(addr); + return mapper.PeekMemoryLow(addr); } } else { - return mapper.ReadMemory(addr); + return mapper.PeekMemoryLow(addr); } } } @@ -338,7 +338,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk } else if (addr < 0xC000) { - return mapper.PeekMemory(addr); + return mapper.PeekMemoryHigh(addr); } else if (addr < 0xFE00) {