diff --git a/BizHawk.Client.Common/PathManager.cs b/BizHawk.Client.Common/PathManager.cs index 9479e05e5c..c908157956 100644 --- a/BizHawk.Client.Common/PathManager.cs +++ b/BizHawk.Client.Common/PathManager.cs @@ -100,17 +100,10 @@ namespace BizHawk.Client.Common return Environment.SpecialFolder.Recent.ToString(); } - if (path.Length >= 5 && path.Substring(0, 5) == "%exe%") - { - if (path.Length == 5) - { - return GetExeDirectoryAbsolute(); - } - - var tmp = path.Remove(0, 5); - tmp = tmp.Insert(0, GetExeDirectoryAbsolute()); - return tmp; - } + if (path.StartsWith("%exe%")) + return GetExeDirectoryAbsolute() + path.Substring(5); + if (path.StartsWith("%rom%")) + return Global.Config.LastRomPath + path.Substring(5); if (path[0] == '.') { diff --git a/BizHawk.Client.Common/config/PathEntry.cs b/BizHawk.Client.Common/config/PathEntry.cs index 9a95354253..9b6b710212 100644 --- a/BizHawk.Client.Common/config/PathEntry.cs +++ b/BizHawk.Client.Common/config/PathEntry.cs @@ -128,14 +128,14 @@ namespace BizHawk.Client.Common private static string ResolveToolsPath(string subPath) { - if (Path.IsPathRooted(subPath)) + if (Path.IsPathRooted(subPath) || subPath.StartsWith("%")) { return subPath; } var toolsPath = Global.Config.PathEntries["Global", "Tools"].Path; - // Hack for backwards compabitilbity, preior to 1.11.5, .wch files were in .\Tools, we don't want that to turn into .Tools\Tools + // Hack for backwards compatibility, prior to 1.11.5, .wch files were in .\Tools, we don't want that to turn into .Tools\Tools if (subPath == "Tools") { return toolsPath; diff --git a/BizHawk.Client.EmuHawk/MainForm.cs b/BizHawk.Client.EmuHawk/MainForm.cs index 852c058ecd..06e394e0e2 100644 --- a/BizHawk.Client.EmuHawk/MainForm.cs +++ b/BizHawk.Client.EmuHawk/MainForm.cs @@ -2133,8 +2133,8 @@ namespace BizHawk.Client.EmuHawk "Apple II", "*.dsk;*.do;*.po;%ARCH%", "Virtual Boy", "*.vb;%ARCH%", "Neo Geo Pocket", "*.ngp;*.ngc;%ARCH%", - "Sinclair ZX Spectrum", "*.tzx;*.tap;*.dsk;*.pzx;*.csw;*.wav;%ARCH%", - "Amstrad CPC", "*.cdt;*.dsk;%ARCH%", + "Sinclair ZX Spectrum", "*.tzx;*.tap;*.dsk;*.pzx;*.csw;*.wav;%ARCH%", + "Amstrad CPC", "*.cdt;*.dsk;%ARCH%", "All Files", "*.*"); } @@ -2164,8 +2164,8 @@ namespace BizHawk.Client.EmuHawk "Virtual Boy", "*.vb;%ARCH%", "Neo Geo Pocket", "*.ngp;*.ngc;%ARCH%", "Commodore 64", "*.prg; *.d64, *.g64; *.crt; *.tap;%ARCH%", - "Sinclair ZX Spectrum", "*.tzx;*.tap;*.dsk;*.pzx;*.csw;*.wav;%ARCH%", - "All Files", "*.*"); + "Sinclair ZX Spectrum", "*.tzx;*.tap;*.dsk;*.pzx;*.csw;*.wav;%ARCH%", + "All Files", "*.*"); } } @@ -2186,7 +2186,6 @@ namespace BizHawk.Client.EmuHawk } var file = new FileInfo(ofd.FileName); - Global.Config.LastRomPath = file.DirectoryName; _lastOpenRomFilter = ofd.FilterIndex; var lra = new LoadRomArgs { OpenAdvanced = new OpenAdvanced_OpenRom { Path = file.FullName } }; @@ -3550,8 +3549,16 @@ namespace BizHawk.Client.EmuHawk private LoadRomArgs _currentLoadRomArgs; - // Still needs a good bit of refactoring public bool LoadRom(string path, LoadRomArgs args) + { + bool ret = _LoadRom(path, args); + if(!ret) return false; + Global.Config.LastRomPath = Path.GetFullPath(Path.GetDirectoryName(path)); + return true; + } + + // Still needs a good bit of refactoring + public bool _LoadRom(string path, LoadRomArgs args) { path = HawkFile.Util_ResolveLink(path); @@ -3696,7 +3703,7 @@ namespace BizHawk.Client.EmuHawk } } - if (Emulator is TI83 && Global.Config.TI83autoloadKeyPad) + if (Emulator is TI83 && Global.Config.TI83autoloadKeyPad) { GlobalWin.Tools.Load(); } @@ -3725,15 +3732,15 @@ namespace BizHawk.Client.EmuHawk } } - if (Emulator.CoreComm.RomStatusDetails == null && loader.Rom != null) - { - Emulator.CoreComm.RomStatusDetails = $"{loader.Game.Name}\r\nSHA1:{loader.Rom.RomData.HashSHA1()}\r\nMD5:{loader.Rom.RomData.HashMD5()}\r\n"; - } - else if (Emulator.CoreComm.RomStatusDetails == null && loader.Rom == null) - { - // single disc game - Emulator.CoreComm.RomStatusDetails = $"{loader.Game.Name}\r\nSHA1:N/A\r\nMD5:N/A\r\n"; - } + if (Emulator.CoreComm.RomStatusDetails == null && loader.Rom != null) + { + Emulator.CoreComm.RomStatusDetails = $"{loader.Game.Name}\r\nSHA1:{loader.Rom.RomData.HashSHA1()}\r\nMD5:{loader.Rom.RomData.HashMD5()}\r\n"; + } + else if (Emulator.CoreComm.RomStatusDetails == null && loader.Rom == null) + { + // single disc game + Emulator.CoreComm.RomStatusDetails = $"{loader.Game.Name}\r\nSHA1:N/A\r\nMD5:N/A\r\n"; + } if (Emulator.HasBoardInfo()) { diff --git a/BizHawk.Client.EmuHawk/config/PathConfig.cs b/BizHawk.Client.EmuHawk/config/PathConfig.cs index c8eb7ed78e..6c7ef17e6b 100644 --- a/BizHawk.Client.EmuHawk/config/PathConfig.cs +++ b/BizHawk.Client.EmuHawk/config/PathConfig.cs @@ -33,6 +33,7 @@ namespace BizHawk.Client.EmuHawk { "%recent%", "%exe%", + "%rom%", ".\\", "..\\", }; diff --git a/BizHawk.Emulation.Cores/BizHawk.Emulation.Cores.csproj b/BizHawk.Emulation.Cores/BizHawk.Emulation.Cores.csproj index 356d3b37ea..9e88151afb 100644 --- a/BizHawk.Emulation.Cores/BizHawk.Emulation.Cores.csproj +++ b/BizHawk.Emulation.Cores/BizHawk.Emulation.Cores.csproj @@ -720,6 +720,7 @@ + diff --git a/BizHawk.Emulation.Cores/CPUs/LR35902/LR35902.cs b/BizHawk.Emulation.Cores/CPUs/LR35902/LR35902.cs index 65f3d98597..ab747aa687 100644 --- a/BizHawk.Emulation.Cores/CPUs/LR35902/LR35902.cs +++ b/BizHawk.Emulation.Cores/CPUs/LR35902/LR35902.cs @@ -29,7 +29,7 @@ namespace BizHawk.Emulation.Common.Components.LR35902 public const ushort RLC = 14; public const ushort RL = 15; public const ushort RRC = 16; - public const ushort RR = 17; + public const ushort RR = 17; public const ushort CPL = 18; public const ushort DA = 19; public const ushort SCF = 20; @@ -44,7 +44,7 @@ namespace BizHawk.Emulation.Common.Components.LR35902 public const ushort SWAP = 29; public const ushort BIT = 30; public const ushort RES = 31; - public const ushort SET = 32; + public const ushort SET = 32; public const ushort EI = 33; public const ushort DI = 34; public const ushort HALT = 35; @@ -108,6 +108,18 @@ namespace BizHawk.Emulation.Common.Components.LR35902 this.WriteMemory = WriteMemory; } + //a little CDL related stuff + public delegate void DoCDLCallbackType(ushort addr, LR35902.eCDLog_Flags flags); + + public DoCDLCallbackType CDLCallback; + + public enum eCDLog_Flags + { + eCDLog_Flags_ExecFirst = 1, + eCDLog_Flags_ExecOperand = 2, + eCDLog_Flags_Data = 4, + }; + // Execute instructions public void ExecuteOne(ref byte interrupt_src, byte interrupt_enable) { @@ -117,7 +129,7 @@ namespace BizHawk.Emulation.Common.Components.LR35902 // do nothing break; case OP: - // Read the opcode of the next instruction + // Read the opcode of the next instruction if (EI_pending > 0 && !CB_prefix) { EI_pending--; @@ -148,6 +160,7 @@ namespace BizHawk.Emulation.Common.Components.LR35902 { if (OnExecFetch != null) OnExecFetch(RegPC); if (TraceCallback != null && !CB_prefix) TraceCallback(State()); + if (CDLCallback != null) CDLCallback(RegPC, eCDLog_Flags.eCDLog_Flags_ExecFirst); FetchInstruction(ReadMemory(RegPC++)); } instr_pntr = 0; @@ -333,6 +346,7 @@ namespace BizHawk.Emulation.Common.Components.LR35902 { if (OnExecFetch != null) OnExecFetch(RegPC); if (TraceCallback != null && !CB_prefix) TraceCallback(State()); + if (CDLCallback != null) CDLCallback(RegPC, eCDLog_Flags.eCDLog_Flags_ExecFirst); RegPC++; FetchInstruction(ReadMemory(RegPC)); @@ -348,10 +362,11 @@ namespace BizHawk.Emulation.Common.Components.LR35902 OP }; } } - else + else { if (OnExecFetch != null) OnExecFetch(RegPC); if (TraceCallback != null && !CB_prefix) TraceCallback(State()); + if (CDLCallback != null) CDLCallback(RegPC, eCDLog_Flags.eCDLog_Flags_ExecFirst); if (Halt_bug_3) { @@ -416,6 +431,7 @@ namespace BizHawk.Emulation.Common.Components.LR35902 stopped = false; if (OnExecFetch != null) OnExecFetch(RegPC); if (TraceCallback != null && !CB_prefix) TraceCallback(State()); + if (CDLCallback != null) CDLCallback(RegPC, eCDLog_Flags.eCDLog_Flags_ExecFirst); FetchInstruction(ReadMemory(RegPC++)); instr_pntr = 0; @@ -445,6 +461,7 @@ namespace BizHawk.Emulation.Common.Components.LR35902 stopped = false; if (OnExecFetch != null) OnExecFetch(RegPC); if (TraceCallback != null && !CB_prefix) TraceCallback(State()); + if (CDLCallback != null) CDLCallback(RegPC, eCDLog_Flags.eCDLog_Flags_ExecFirst); FetchInstruction(ReadMemory(RegPC++)); instr_pntr = 0; @@ -472,6 +489,7 @@ namespace BizHawk.Emulation.Common.Components.LR35902 case OP_G: if (OnExecFetch != null) OnExecFetch(RegPC); if (TraceCallback != null) TraceCallback(State()); + if (CDLCallback != null) CDLCallback(RegPC, eCDLog_Flags.eCDLog_Flags_ExecFirst); FetchInstruction(ReadMemory(RegPC)); // note no increment diff --git a/BizHawk.Emulation.Cores/CPUs/LR35902/Operations.cs b/BizHawk.Emulation.Cores/CPUs/LR35902/Operations.cs index 582c2cd437..1cbded15b3 100644 --- a/BizHawk.Emulation.Cores/CPUs/LR35902/Operations.cs +++ b/BizHawk.Emulation.Cores/CPUs/LR35902/Operations.cs @@ -7,7 +7,13 @@ namespace BizHawk.Emulation.Common.Components.LR35902 { public void Read_Func(ushort dest, ushort src_l, ushort src_h) { - Regs[dest] = ReadMemory((ushort)(Regs[src_l] | (Regs[src_h]) << 8)); + ushort addr = (ushort)(Regs[src_l] | (Regs[src_h]) << 8); + if (CDLCallback != null) + { + if (src_l == PCl) CDLCallback(addr, eCDLog_Flags.eCDLog_Flags_ExecOperand); + else CDLCallback(addr, eCDLog_Flags.eCDLog_Flags_Data); + } + Regs[dest] = ReadMemory(addr); } // speical read for POP AF that always clears the lower 4 bits of F @@ -18,7 +24,9 @@ namespace BizHawk.Emulation.Common.Components.LR35902 public void Write_Func(ushort dest_l, ushort dest_h, ushort src) { - WriteMemory((ushort)(Regs[dest_l] | (Regs[dest_h]) << 8), (byte)Regs[src]); + ushort addr = (ushort)(Regs[dest_l] | (Regs[dest_h]) << 8); + if (CDLCallback != null) CDLCallback(addr, eCDLog_Flags.eCDLog_Flags_Data); + WriteMemory(addr, (byte)Regs[src]); } public void TR_Func(ushort dest, ushort src) diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.ICodeDataLog.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.ICodeDataLog.cs new file mode 100644 index 0000000000..051aa995ee --- /dev/null +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.ICodeDataLog.cs @@ -0,0 +1,181 @@ +using System; +using System.IO; +using System.Collections.Generic; + +using BizHawk.Emulation.Common; +using BizHawk.Emulation.Common.Components.LR35902; + +namespace BizHawk.Emulation.Cores.Nintendo.GBHawk +{ + public partial class GBHawk : ICodeDataLogger + { + private ICodeDataLog _cdl; + + public void SetCDL(ICodeDataLog cdl) + { + _cdl = cdl; + if (cdl == null) + this.cpu.CDLCallback = null; + else this.cpu.CDLCallback = DoCDL; + } + + public void NewCDL(ICodeDataLog cdl) + { + cdl["ROM"] = new byte[MemoryDomains["ROM"].Size]; + cdl["HRAM"] = new byte[MemoryDomains["Zero Page RAM"].Size]; + + cdl["WRAM"] = new byte[MemoryDomains["Main RAM"].Size]; + + if (MemoryDomains.Has("Cart RAM")) + { + cdl["CartRAM"] = new byte[MemoryDomains["Cart RAM"].Size]; + } + + cdl.SubType = "GB"; + cdl.SubVer = 0; + } + + [FeatureNotImplemented] + void ICodeDataLogger.DisassembleCDL(Stream s, ICodeDataLog cdl) + { + } + + public void DoCDL2(LR35902.eCDLog_Flags flags, string type, int cdladdr) + { + if (type == null) return; + _cdl[type][cdladdr] |= (byte)flags; + } + + public void DoCDL(ushort addr, LR35902.eCDLog_Flags flags) + { + MemoryCallbacks.CallReads(addr, "System Bus"); + addr_access = addr; + + if (ppu.DMA_start) + { + // some of gekkio's tests require these to be accessible during DMA + if (addr < 0x8000) + { + if (ppu.DMA_addr < 0x80) + { + return; + } + else + { + mapper.MapCDL(addr, flags); + return; + } + } + else if ((addr >= 0xE000) && (addr < 0xF000)) + { + DoCDL2(flags, "WRAM", addr - 0xE000); + } + else if ((addr >= 0xF000) && (addr < 0xFE00)) + { + DoCDL2(flags, "WRAM", (RAM_Bank * 0x1000) + (addr - 0xF000)); + } + else if ((addr >= 0xFE00) && (addr < 0xFEA0) && ppu.DMA_OAM_access) + { + return; + } + else if ((addr >= 0xFF00) && (addr < 0xFF80)) // The game GOAL! Requires Hardware Regs to be accessible + { + return; + } + else if ((addr >= 0xFF80)) + { + DoCDL2(flags, "HRAM", addr - 0xFF80); + } + + } + + if (addr < 0x900) + { + if (addr < 0x100) + { + // return Either BIOS ROM or Game ROM + if ((GB_bios_register & 0x1) == 0) + { + return; + } + else + { + mapper.MapCDL(addr, flags); + return; + } + } + else if (addr >= 0x200) + { + // return Either BIOS ROM or Game ROM + if (((GB_bios_register & 0x1) == 0) && is_GBC) + { + return; + } + else + { + mapper.MapCDL(addr, flags); + return; + } + } + else + { + mapper.MapCDL(addr, flags); + return; + } + } + else if (addr < 0x8000) + { + mapper.MapCDL(addr, flags); + return; + } + else if (addr < 0xA000) + { + return; + } + else if (addr < 0xC000) + { + mapper.MapCDL(addr, flags); + return; + } + else if (addr < 0xD000) + { + return; + } + else if (addr < 0xE000) + { + DoCDL2(flags, "WRAM", (RAM_Bank * 0x1000) + (addr - 0xD000)); + } + else if (addr < 0xF000) + { + DoCDL2(flags, "WRAM", addr - 0xE000); + } + else if (addr < 0xFE00) + { + DoCDL2(flags, "WRAM", (RAM_Bank * 0x1000) + (addr - 0xF000)); + } + else if (addr < 0xFEA0) + { + return; + } + else if (addr < 0xFF00) + { + return; + } + else if (addr < 0xFF80) + { + return; + } + else if (addr < 0xFFFF) + { + DoCDL2(flags, "HRAM", addr - 0xFF80); + } + else + { + return; + } + + } + + + } +} \ No newline at end of file diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/MapperBase.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/MapperBase.cs index 89b8ce1034..d813ec52fa 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/MapperBase.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/MapperBase.cs @@ -1,6 +1,8 @@ using BizHawk.Common; using System; +using BizHawk.Emulation.Common.Components.LR35902; + namespace BizHawk.Emulation.Cores.Nintendo.GBHawk { public class MapperBase @@ -44,5 +46,19 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk public virtual void RTC_Get(byte value, int index) { } + + public virtual void MapCDL(ushort addr, LR35902.eCDLog_Flags flags) + { + } + + protected void SetCDLROM(LR35902.eCDLog_Flags flags, int cdladdr) + { + Core.DoCDL2(flags, "ROM", cdladdr); + } + + protected void SetCDLRAM(LR35902.eCDLog_Flags flags, int cdladdr) + { + Core.DoCDL2(flags, "CartRAM", cdladdr); + } } } 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 b6ad35bb1b..d5e0be860c 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_Camera.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_Camera.cs @@ -2,6 +2,8 @@ using BizHawk.Common.NumberExtensions; using System; +using BizHawk.Emulation.Common.Components.LR35902; + namespace BizHawk.Emulation.Cores.Nintendo.GBHawk { // Default mapper with no bank switching @@ -31,6 +33,25 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk } } + public override void MapCDL(ushort addr, LR35902.eCDLog_Flags flags) + { + if (addr < 0x8000) + { + SetCDLROM(flags, addr); + } + else + { + if (Core.cart_RAM != null) + { + SetCDLRAM(flags, addr - 0xA000); + } + else + { + return; + } + } + } + public override byte PeekMemory(ushort addr) { return ReadMemory(addr); 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 2df4c92454..77a73c0602 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_Default.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_Default.cs @@ -2,6 +2,8 @@ using BizHawk.Common.NumberExtensions; using System; +using BizHawk.Emulation.Common.Components.LR35902; + namespace BizHawk.Emulation.Cores.Nintendo.GBHawk { // Default mapper with no bank switching @@ -31,6 +33,25 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk } } + public override void MapCDL(ushort addr, LR35902.eCDLog_Flags flags) + { + if (addr < 0x8000) + { + SetCDLROM(flags, addr); + } + else + { + if (Core.cart_RAM != null) + { + SetCDLRAM(flags, addr - 0xA000); + } + else + { + return; + } + } + } + public override byte PeekMemory(ushort addr) { return ReadMemory(addr); 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 6f63e13541..61f015b5a1 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_HuC1.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_HuC1.cs @@ -2,6 +2,8 @@ using BizHawk.Common.NumberExtensions; using System; +using BizHawk.Emulation.Common.Components.LR35902; + namespace BizHawk.Emulation.Cores.Nintendo.GBHawk { // hudson mapper used in ex Daikaijuu monogatari @@ -75,6 +77,47 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk } } + public override void MapCDL(ushort addr, LR35902.eCDLog_Flags flags) + { + if (addr < 0x4000) + { + SetCDLROM(flags, addr); + } + else if (addr < 0x8000) + { + SetCDLROM(flags, (addr - 0x4000) + ROM_bank * 0x4000); + } + else if ((addr >= 0xA000) && (addr < 0xC000)) + { + if (RAM_enable) + { + if (Core.cart_RAM != null) + { + if (((addr - 0xA000) + RAM_bank * 0x2000) < Core.cart_RAM.Length) + { + SetCDLRAM(flags, (addr - 0xA000) + RAM_bank * 0x2000); + } + else + { + return; + } + } + else + { + return; + } + } + else + { + return; + } + } + else + { + return; + } + } + public override byte PeekMemory(ushort addr) { return ReadMemory(addr); 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 0daf88475a..0c16a29779 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_HuC3.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_HuC3.cs @@ -2,6 +2,8 @@ using BizHawk.Common.NumberExtensions; using System; +using BizHawk.Emulation.Common.Components.LR35902; + namespace BizHawk.Emulation.Cores.Nintendo.GBHawk { // Default mapper with no bank switching @@ -31,6 +33,25 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk } } + public override void MapCDL(ushort addr, LR35902.eCDLog_Flags flags) + { + if (addr < 0x8000) + { + SetCDLROM(flags, addr); + } + else + { + if (Core.cart_RAM != null) + { + SetCDLRAM(flags, addr - 0xA000); + } + else + { + return; + } + } + } + public override byte PeekMemory(ushort addr) { return ReadMemory(addr); 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 d8763afa6a..e2b280ddff 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_MBC1.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_MBC1.cs @@ -2,6 +2,8 @@ using BizHawk.Common.NumberExtensions; using System; +using BizHawk.Emulation.Common.Components.LR35902; + namespace BizHawk.Emulation.Cores.Nintendo.GBHawk { // MBC1 with bank switching and RAM @@ -45,7 +47,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk else { return Core._rom[addr]; - } + } } else if (addr < 0x8000) { @@ -72,6 +74,45 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk } } + public override void MapCDL(ushort addr, LR35902.eCDLog_Flags flags) + { + if (addr < 0x4000) + { + // lowest bank is fixed, but is still effected by mode + if (sel_mode) + { + SetCDLROM(flags, (ROM_bank & 0x60) * 0x4000 + addr); + } + else + { + SetCDLROM(flags, addr); + } + } + else if (addr < 0x8000) + { + SetCDLROM(flags, (addr - 0x4000) + ROM_bank * 0x4000); + } + else + { + if (Core.cart_RAM != null) + { + if (RAM_enable && (((addr - 0xA000) + RAM_bank * 0x2000) < Core.cart_RAM.Length)) + { + SetCDLRAM(flags, (addr - 0xA000) + RAM_bank * 0x2000); + } + else + { + return; + } + + } + else + { + return; + } + } + } + public override byte PeekMemory(ushort addr) { return ReadMemory(addr); 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 d72112aa40..8a01891cb3 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 @@ -2,6 +2,8 @@ using BizHawk.Common.NumberExtensions; using System; +using BizHawk.Emulation.Common.Components.LR35902; + namespace BizHawk.Emulation.Cores.Nintendo.GBHawk { // MBC1 with bank switching and RAM @@ -68,6 +70,45 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk } } + public override void MapCDL(ushort addr, LR35902.eCDLog_Flags flags) + { + if (addr < 0x4000) + { + // lowest bank is fixed, but is still effected by mode + if (sel_mode) + { + SetCDLROM(flags, ((ROM_bank & 0x60) >> 1) * 0x4000 + addr); + } + else + { + SetCDLROM(flags, addr); + } + } + else if (addr < 0x8000) + { + SetCDLROM(flags, (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)) + { + SetCDLRAM(flags, (addr - 0xA000) + RAM_bank * 0x2000); + } + else + { + return; + } + + } + else + { + return; + } + } + } + public override byte PeekMemory(ushort addr) { return ReadMemory(addr); 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 7510d00522..51537b6cbc 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_MBC2.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_MBC2.cs @@ -2,6 +2,8 @@ using BizHawk.Common.NumberExtensions; using System; +using BizHawk.Emulation.Common.Components.LR35902; + namespace BizHawk.Emulation.Cores.Nintendo.GBHawk { // MBC2 with bank switching and RAM @@ -44,6 +46,30 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk } } + public override void MapCDL(ushort addr, LR35902.eCDLog_Flags flags) + { + if (addr < 0x4000) + { + SetCDLROM(flags, addr); + } + else if (addr < 0x8000) + { + SetCDLROM(flags, (addr - 0x4000) + ROM_bank * 0x4000); + } + else if ((addr >= 0xA000) && (addr < 0xA200)) + { + if (RAM_enable) + { + SetCDLRAM(flags, addr - 0xA000); + } + return; + } + else + { + return; + } + } + public override byte PeekMemory(ushort addr) { return ReadMemory(addr); 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 e0649675ab..8d77992172 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_MBC3.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_MBC3.cs @@ -2,6 +2,8 @@ using BizHawk.Common.NumberExtensions; using System; +using BizHawk.Emulation.Common.Components.LR35902; + namespace BizHawk.Emulation.Cores.Nintendo.GBHawk { // MBC3 mapper with Real Time Clock @@ -79,7 +81,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk { return 0xFF; } - } + } else { return 0xFF; @@ -87,6 +89,48 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk } } + public override void MapCDL(ushort addr, LR35902.eCDLog_Flags flags) + { + if (addr < 0x4000) + { + SetCDLROM(flags, addr); + } + else if (addr < 0x8000) + { + SetCDLROM(flags, (addr - 0x4000) + ROM_bank * 0x4000); + } + else + { + if (RAM_enable) + { + if ((Core.cart_RAM != null) && (RAM_bank < 3)) + { + if (((addr - 0xA000) + RAM_bank * 0x2000) < Core.cart_RAM.Length) + { + SetCDLRAM(flags, (addr - 0xA000) + RAM_bank * 0x2000); + } + else + { + return; + } + } + + if ((RAM_bank >= 8) && (RAM_bank < 0xC)) + { + return; + } + else + { + return; + } + } + else + { + return; + } + } + } + public override byte PeekMemory(ushort addr) { return ReadMemory(addr); 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 cbaf5bc601..72fb7d2808 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_MBC5.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_MBC5.cs @@ -2,6 +2,8 @@ using BizHawk.Common.NumberExtensions; using System; +using BizHawk.Emulation.Common.Components.LR35902; + namespace BizHawk.Emulation.Cores.Nintendo.GBHawk { // MBC5, common mapper for GBC games @@ -63,6 +65,37 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk } } + public override void MapCDL(ushort addr, LR35902.eCDLog_Flags flags) + { + if (addr < 0x4000) + { + SetCDLROM(flags, addr); + } + else if (addr < 0x8000) + { + SetCDLROM(flags, (addr - 0x4000) + ROM_bank * 0x4000); + } + else + { + if (Core.cart_RAM != null) + { + if (RAM_enable && (((addr - 0xA000) + RAM_bank * 0x2000) < Core.cart_RAM.Length)) + { + SetCDLRAM(flags, (addr - 0xA000) + RAM_bank * 0x2000); + } + else + { + return; + } + + } + else + { + return; + } + } + } + public override byte PeekMemory(ushort addr) { return ReadMemory(addr); 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 5cbdd331ff..84ce6bbba2 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_MBC6.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_MBC6.cs @@ -2,6 +2,8 @@ using BizHawk.Common.NumberExtensions; using System; +using BizHawk.Emulation.Common.Components.LR35902; + namespace BizHawk.Emulation.Cores.Nintendo.GBHawk { // Default mapper with no bank switching @@ -31,6 +33,25 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk } } + public override void MapCDL(ushort addr, LR35902.eCDLog_Flags flags) + { + if (addr < 0x8000) + { + SetCDLROM(flags, addr); + } + else + { + if (Core.cart_RAM != null) + { + SetCDLRAM(flags, addr - 0xA000); + } + else + { + return; + } + } + } + public override byte PeekMemory(ushort addr) { return ReadMemory(addr); 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 41b9dd1506..52d4c62ccc 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_MBC7.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_MBC7.cs @@ -2,6 +2,8 @@ using BizHawk.Common.NumberExtensions; using System; +using BizHawk.Emulation.Common.Components.LR35902; + namespace BizHawk.Emulation.Cores.Nintendo.GBHawk { // Mapper with built in EEPROM, also used with Kirby's tilt 'n tumble @@ -81,6 +83,37 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk } } + public override void MapCDL(ushort addr, LR35902.eCDLog_Flags flags) + { + if (addr < 0x4000) + { + SetCDLROM(flags, addr); + } + else if (addr < 0x8000) + { + SetCDLROM(flags, (addr - 0x4000) + ROM_bank * 0x4000); + } + else if (addr < 0xA000) + { + return; + } + else if (addr < 0xB000) + { + if (RAM_enable_1 && RAM_enable_2) + { + return; + } + else + { + return; + } + } + else + { + return; + } + } + public override byte PeekMemory(ushort addr) { return ReadMemory(addr); 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 0a45601998..5e6364a082 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_MMM01.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_MMM01.cs @@ -2,6 +2,8 @@ using BizHawk.Common.NumberExtensions; using System; +using BizHawk.Emulation.Common.Components.LR35902; + namespace BizHawk.Emulation.Cores.Nintendo.GBHawk { // Default mapper with no bank switching @@ -31,6 +33,25 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk } } + public override void MapCDL(ushort addr, LR35902.eCDLog_Flags flags) + { + if (addr < 0x8000) + { + SetCDLROM(flags, addr); + } + else + { + if (Core.cart_RAM != null) + { + SetCDLRAM(flags, addr - 0xA000); + } + else + { + return; + } + } + } + public override byte PeekMemory(ushort addr) { return ReadMemory(addr); 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 a45175f84e..845074051d 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_RockMan8.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_RockMan8.cs @@ -2,6 +2,8 @@ using BizHawk.Common.NumberExtensions; using System; +using BizHawk.Emulation.Common.Components.LR35902; + namespace BizHawk.Emulation.Cores.Nintendo.GBHawk { // RockMan 8, just some simple bankswitching @@ -37,6 +39,24 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk } } + public override void MapCDL(ushort addr, LR35902.eCDLog_Flags flags) + { + if (addr < 0x4000) + { + // lowest bank is fixed + SetCDLROM(flags, addr); + + } + else if (addr < 0x8000) + { + SetCDLROM(flags, (addr - 0x4000) + ROM_bank * 0x4000); + } + else + { + return; + } + } + public override byte PeekMemory(ushort addr) { return ReadMemory(addr); 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 c96600a6fd..c568a099e6 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 @@ -2,6 +2,8 @@ using BizHawk.Common.NumberExtensions; using System; +using BizHawk.Emulation.Common.Components.LR35902; + namespace BizHawk.Emulation.Cores.Nintendo.GBHawk { // Sachen Bootleg Mapper @@ -69,6 +71,43 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk } } + public override void MapCDL(ushort addr, LR35902.eCDLog_Flags flags) + { + if (addr < 0x4000) + { + if (locked) + { + // header is scrambled + if ((addr >= 0x100) && (addr < 0x200)) + { + int temp0 = (addr & 1); + int temp1 = (addr & 2); + int temp4 = (addr & 0x10); + int temp6 = (addr & 0x40); + + temp0 = temp0 << 6; + temp1 = temp1 << 3; + temp4 = temp4 >> 3; + temp6 = temp6 >> 6; + + addr &= 0x1AC; + addr |= (ushort)(temp0 | temp1 | temp4 | temp6); + } + addr |= 0x80; + } + + SetCDLROM(flags, addr + BASE_ROM_Bank * 0x4000); + } + else if (addr < 0x8000) + { + SetCDLROM(flags, (addr - 0x4000) + ROM_bank * 0x4000); + } + else + { + return; + } + } + public override byte PeekMemory(ushort addr) { return ReadMemory(addr); 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 29f16a8212..3b0512f61e 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 @@ -2,6 +2,8 @@ using BizHawk.Common.NumberExtensions; using System; +using BizHawk.Emulation.Common.Components.LR35902; + namespace BizHawk.Emulation.Cores.Nintendo.GBHawk { // Sachen Bootleg Mapper @@ -72,6 +74,44 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk } } + public override void MapCDL(ushort addr, LR35902.eCDLog_Flags flags) + { + if (addr < 0x4000) + { + // header is scrambled + if ((addr >= 0x100) && (addr < 0x200)) + { + int temp0 = (addr & 1); + int temp1 = (addr & 2); + int temp4 = (addr & 0x10); + int temp6 = (addr & 0x40); + + temp0 = temp0 << 6; + temp1 = temp1 << 3; + temp4 = temp4 >> 3; + temp6 = temp6 >> 6; + + addr &= 0x1AC; + addr |= (ushort)(temp0 | temp1 | temp4 | temp6); + } + + if (locked_GBC) { addr |= 0x80; } + + SetCDLROM(flags, addr + BASE_ROM_Bank * 0x4000); + } + else if (addr < 0x8000) + { + int temp_bank = (ROM_bank & ~ROM_bank_mask) | (ROM_bank_mask & BASE_ROM_Bank); + temp_bank &= ROM_mask; + + SetCDLROM(flags, (addr - 0x4000) + temp_bank * 0x4000); + } + else + { + return; + } + } + public override byte PeekMemory(ushort addr) { return ReadMemory(addr); 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 dc6c6d8d9f..2bbf751e71 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_TAMA5.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_TAMA5.cs @@ -2,6 +2,8 @@ using BizHawk.Common.NumberExtensions; using System; +using BizHawk.Emulation.Common.Components.LR35902; + namespace BizHawk.Emulation.Cores.Nintendo.GBHawk { // Default mapper with no bank switching @@ -31,6 +33,25 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk } } + public override void MapCDL(ushort addr, LR35902.eCDLog_Flags flags) + { + if (addr < 0x8000) + { + SetCDLROM(flags, addr); + } + else + { + if (Core.cart_RAM != null) + { + SetCDLRAM(flags, addr - 0xA000); + } + else + { + return; + } + } + } + public override byte PeekMemory(ushort addr) { return ReadMemory(addr); 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 9d60fc865c..18566457a5 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_WisdomTree.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_WisdomTree.cs @@ -2,6 +2,8 @@ using BizHawk.Common.NumberExtensions; using System; +using BizHawk.Emulation.Common.Components.LR35902; + namespace BizHawk.Emulation.Cores.Nintendo.GBHawk { // Wisdom tree mapper (32K bank switching) @@ -32,6 +34,18 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk } } + public override void MapCDL(ushort addr, LR35902.eCDLog_Flags flags) + { + if (addr < 0x8000) + { + SetCDLROM(flags, ROM_bank * 0x8000 + addr); + } + else + { + return; + } + } + public override byte PeekMemory(ushort addr) { return ReadMemory(addr); diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/MemoryMap.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/MemoryMap.cs index 12037bdc4a..fdeafdc9e3 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/MemoryMap.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/MemoryMap.cs @@ -133,7 +133,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk else if (addr < 0xFEA0) { if (ppu.OAM_access_read) { return OAM[addr - 0xFE00]; } - else { return 0xFF; } + else { return 0xFF; } } else if (addr < 0xFF00) {