diff --git a/src/BizHawk.Emulation.Cores/Consoles/Fairchild/ChannelF/ChannelF.CpuLink.cs b/src/BizHawk.Emulation.Cores/Consoles/Fairchild/ChannelF/ChannelF.CpuLink.cs index f470f1d46c..7f5916fba5 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Fairchild/ChannelF/ChannelF.CpuLink.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Fairchild/ChannelF/ChannelF.CpuLink.cs @@ -7,7 +7,9 @@ public partial class ChannelF public readonly struct CpuLink(ChannelF channelF) : IF3850Link { public byte ReadMemory(ushort address) - => channelF.ReadBus(address); + => channelF._cdl == null + ? channelF.ReadBus(address) + : channelF.ReadMemory_CDL(address); public void WriteMemory(ushort address, byte value) => channelF.WriteBus(address, value); diff --git a/src/BizHawk.Emulation.Cores/Consoles/Fairchild/ChannelF/ChannelF.ICodeDataLog.cs b/src/BizHawk.Emulation.Cores/Consoles/Fairchild/ChannelF/ChannelF.ICodeDataLog.cs new file mode 100644 index 0000000000..977dcd4081 --- /dev/null +++ b/src/BizHawk.Emulation.Cores/Consoles/Fairchild/ChannelF/ChannelF.ICodeDataLog.cs @@ -0,0 +1,86 @@ +using BizHawk.Emulation.Common; +using System.IO; + +namespace BizHawk.Emulation.Cores.Consoles.ChannelF +{ + public partial class ChannelF : ICodeDataLogger + { + private ICodeDataLog _cdl; + + public void SetCDL(ICodeDataLog cdl) + { + _cdl = cdl; + } + + public void NewCDL(ICodeDataLog cdl) + { + void AddIfExists(string name) + { + var found = _memoryDomains[name]; + if (found is not null) cdl[name] = new byte[found.Size]; + } + + cdl["System Bus"] = new byte[_memoryDomains["System Bus"]!.Size]; + + AddIfExists("BIOS1"); + AddIfExists("BIOS2"); + AddIfExists("ROM"); + + cdl.SubType = "ChannelF"; + cdl.SubVer = 0; + } + + [FeatureNotImplemented] + public void DisassembleCDL(Stream s, ICodeDataLog cdl) + => throw new NotImplementedException(); + + public enum CDLType + { + None, + BIOS1, + BIOS2, + CARTROM + } + + public struct CDLResult + { + public CDLType Type; + public int Address; + } + + private byte ReadMemory_CDL(ushort addr) + { + var mapping = ReadCDL(addr); + var res = mapping.Type; + var address = mapping.Address; + + byte data = ReadBus(addr); + + switch (res) + { + case CDLType.None: + default: + // shouldn't get here + break; + + case CDLType.BIOS1: + _cdl["BIOS1"][address] = data; + break; + + case CDLType.BIOS2: + _cdl["BIOS2"][address] = data; + break; + + case CDLType.CARTROM: + _cdl["ROM"][address] = data; + break; + } + + // update the system bus as well + // because why not + _cdl["System Bus"][addr] = data; + + return data; + } + } +} diff --git a/src/BizHawk.Emulation.Cores/Consoles/Fairchild/ChannelF/Memory.cs b/src/BizHawk.Emulation.Cores/Consoles/Fairchild/ChannelF/Memory.cs index 920df11212..3083e733a2 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Fairchild/ChannelF/Memory.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Fairchild/ChannelF/Memory.cs @@ -30,6 +30,30 @@ public byte ReadBus(ushort addr) } } + public CDLResult ReadCDL(ushort addr) + { + var result = new CDLResult(); + int divisor = addr / 0x400; + result.Address = addr % 0x400; + + switch (divisor) + { + case 0: + result.Type = CDLType.BIOS1; + break; + + case 1: + result.Type = CDLType.BIOS2; + break; + + default: + result.Type = CDLType.CARTROM; + break; + } + + return result; + } + /// /// Simulates writing a byte of data to the address space (in its default configuration, there is no writeable RAM in the /// Channel F addressable through the address space)