Skip to content

Commit

Permalink
[ChannelFHawk] ICodeDataLogger
Browse files Browse the repository at this point in the history
  • Loading branch information
Asnivor committed Oct 24, 2024
1 parent 4c69ce4 commit e0264ed
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
24 changes: 24 additions & 0 deletions src/BizHawk.Emulation.Cores/Consoles/Fairchild/ChannelF/Memory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/// <summary>
/// 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)
Expand Down

0 comments on commit e0264ed

Please sign in to comment.