CDL - preliminary SMS support (only one mapper)
This commit is contained in:
parent
70e0954f28
commit
642f965685
|
@ -790,6 +790,7 @@
|
|||
<Compile Include="Consoles\Sega\Saturn\Yabause.IStatable.cs">
|
||||
<DependentUpon>Yabause.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Consoles\Sega\SMS\CDL_SMS.cs" />
|
||||
<Compile Include="Consoles\Sega\SMS\SMS.Input.cs" />
|
||||
<Compile Include="Consoles\Sega\SMS\TerebiOekaki.cs" />
|
||||
<Compile Include="Consoles\Sega\SMS\MemoryMap.Korea.cs" />
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -35,6 +35,7 @@ namespace BizHawk.Emulation.Cores.Components.Z80
|
|||
|
||||
// Memory Access
|
||||
|
||||
public Func<ushort, bool, byte> FetchMemory;
|
||||
public Func<ushort, byte> ReadMemory;
|
||||
public Action<ushort, byte> WriteMemory;
|
||||
|
||||
|
@ -48,6 +49,26 @@ namespace BizHawk.Emulation.Cores.Components.Z80
|
|||
return ReadMemory(addr);
|
||||
}
|
||||
|
||||
public byte FetchFirstMemoryWrapper(ushort addr)
|
||||
{
|
||||
if (MemoryCallbacks != null)
|
||||
{
|
||||
MemoryCallbacks.CallReads(addr);
|
||||
}
|
||||
|
||||
return FetchMemory(addr, true);
|
||||
}
|
||||
|
||||
public byte FetchMemoryWrapper(ushort addr)
|
||||
{
|
||||
if (MemoryCallbacks != null)
|
||||
{
|
||||
MemoryCallbacks.CallReads(addr);
|
||||
}
|
||||
|
||||
return FetchMemory(addr, false);
|
||||
}
|
||||
|
||||
public void WriteMemoryWrapper(ushort addr, byte value)
|
||||
{
|
||||
if (MemoryCallbacks != null)
|
||||
|
|
|
@ -0,0 +1,104 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using BizHawk.Emulation.Common;
|
||||
|
||||
namespace BizHawk.Emulation.Cores.Sega.MasterSystem
|
||||
{
|
||||
partial class SMS
|
||||
{
|
||||
enum CDLog_AddrType
|
||||
{
|
||||
None,
|
||||
ROM, MainRAM, SaveRAM, CartRAM,
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum CDLog_Flags
|
||||
{
|
||||
ExecFirst = 0x01,
|
||||
ExecOperand = 0x02,
|
||||
Data = 0x04
|
||||
};
|
||||
|
||||
struct CDLog_MapResults
|
||||
{
|
||||
public CDLog_AddrType Type;
|
||||
public int Address;
|
||||
}
|
||||
|
||||
delegate CDLog_MapResults MapMemoryDelegate(ushort addr, bool write);
|
||||
|
||||
MapMemoryDelegate MapMemory;
|
||||
|
||||
void RunCDL(ushort address, CDLog_Flags flags)
|
||||
{
|
||||
if (MapMemory != null)
|
||||
{
|
||||
CDLog_MapResults results = MapMemory(address, false);
|
||||
switch (results.Type)
|
||||
{
|
||||
case CDLog_AddrType.None: break;
|
||||
case CDLog_AddrType.ROM: CDL["ROM"][results.Address] |= (byte)flags; break;
|
||||
case CDLog_AddrType.MainRAM: CDL["Main RAM"][results.Address] |= (byte)flags; break;
|
||||
case CDLog_AddrType.SaveRAM: CDL["Save RAM"][results.Address] |= (byte)flags; break;
|
||||
case CDLog_AddrType.CartRAM: CDL["Cart (Volatile) RAM"][results.Address] |= (byte)flags; break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A wrapper for FetchMemory which inserts CDL logic
|
||||
/// </summary>
|
||||
public byte FetchMemory_CDL(ushort address, bool first)
|
||||
{
|
||||
RunCDL(address, first ? CDLog_Flags.ExecFirst : CDLog_Flags.ExecOperand);
|
||||
return ReadMemory(address);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A wrapper for ReadMemory which inserts CDL logic
|
||||
/// </summary>
|
||||
public byte ReadMemory_CDL(ushort address)
|
||||
{
|
||||
RunCDL(address, CDLog_Flags.Data);
|
||||
return ReadMemory(address);
|
||||
}
|
||||
|
||||
void ICodeDataLogger.SetCDL(CodeDataLog cdl)
|
||||
{
|
||||
CDL = cdl;
|
||||
if (cdl == null)
|
||||
{
|
||||
Cpu.ReadMemory = ReadMemory;
|
||||
Cpu.WriteMemory = WriteMemory;
|
||||
Cpu.FetchMemory = FetchMemory_StubThunk;
|
||||
}
|
||||
else
|
||||
{
|
||||
Cpu.ReadMemory = ReadMemory_CDL;
|
||||
Cpu.WriteMemory = WriteMemory;
|
||||
Cpu.FetchMemory = FetchMemory_CDL;
|
||||
}
|
||||
}
|
||||
|
||||
void ICodeDataLogger.NewCDL(CodeDataLog cdl)
|
||||
{
|
||||
cdl["ROM"] = new byte[memoryDomains["ROM"].Size];
|
||||
cdl["Main RAM"] = new byte[memoryDomains["Main RAM"].Size];
|
||||
|
||||
if (memoryDomains.Has("Save RAM"))
|
||||
cdl["Save RAM"] = new byte[memoryDomains["Save RAM"].Size];
|
||||
|
||||
if (memoryDomains.Has("Cart (Volatile) RAM"))
|
||||
cdl["Cart (Volatile) RAM"] = new byte[memoryDomains["Cart (Volatile) RAM"].Size];
|
||||
|
||||
cdl.SubType = "SMS";
|
||||
cdl.SubVer = 0;
|
||||
}
|
||||
|
||||
//not supported
|
||||
void ICodeDataLogger.DisassembleCDL(Stream s, CodeDataLog cdl) { }
|
||||
|
||||
CodeDataLog CDL;
|
||||
}
|
||||
}
|
|
@ -32,8 +32,8 @@
|
|||
|
||||
void InitCodeMastersMapper()
|
||||
{
|
||||
Cpu.ReadMemory = ReadMemoryCM;
|
||||
Cpu.WriteMemory = WriteMemoryCM;
|
||||
ReadMemory = ReadMemoryCM;
|
||||
WriteMemory = WriteMemoryCM;
|
||||
WriteMemoryCM(0x0000, 0);
|
||||
WriteMemoryCM(0x4000, 1);
|
||||
WriteMemoryCM(0x8000, 0);
|
||||
|
@ -85,8 +85,8 @@
|
|||
|
||||
void InitCodeMastersMapperRam()
|
||||
{
|
||||
Cpu.ReadMemory = ReadMemoryCMRam;
|
||||
Cpu.WriteMemory = WriteMemoryCMRam;
|
||||
ReadMemory = ReadMemoryCMRam;
|
||||
WriteMemory = WriteMemoryCMRam;
|
||||
WriteMemoryCM(0x0000, 0);
|
||||
WriteMemoryCM(0x4000, 1);
|
||||
WriteMemoryCM(0x8000, 0);
|
||||
|
|
|
@ -31,8 +31,8 @@
|
|||
{
|
||||
ExtRam = new byte[size];
|
||||
ExtRamMask = size - 1;
|
||||
Cpu.ReadMemory = ReadMemoryExt;
|
||||
Cpu.WriteMemory = WriteMemoryExt;
|
||||
ReadMemory = ReadMemoryExt;
|
||||
WriteMemory = WriteMemoryExt;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -23,8 +23,8 @@
|
|||
|
||||
void InitKoreaMapper()
|
||||
{
|
||||
Cpu.ReadMemory = ReadMemoryKR;
|
||||
Cpu.WriteMemory = WriteMemoryKR;
|
||||
ReadMemory = ReadMemoryKR;
|
||||
WriteMemory = WriteMemoryKR;
|
||||
RomBank0 = 0;
|
||||
RomBank1 = 1;
|
||||
RomBank2 = 0;
|
||||
|
@ -72,8 +72,8 @@
|
|||
|
||||
void InitMSXMapper()
|
||||
{
|
||||
Cpu.ReadMemory = ReadMemoryMSX;
|
||||
Cpu.WriteMemory = WriteMemoryMSX;
|
||||
ReadMemory = ReadMemoryMSX;
|
||||
WriteMemory = WriteMemoryMSX;
|
||||
RomBank0 = 0;
|
||||
RomBank1 = 0;
|
||||
RomBank2 = 0;
|
||||
|
@ -83,7 +83,7 @@
|
|||
void InitNemesisMapper()
|
||||
{
|
||||
InitMSXMapper();
|
||||
Cpu.ReadMemory = ReadMemoryNemesis;
|
||||
ReadMemory = ReadMemoryNemesis;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
bool BiosMapped { get { return (Port3E & 0x40) == 0x40; } }
|
||||
|
||||
byte ReadMemory(ushort address)
|
||||
byte ReadMemorySega(ushort address)
|
||||
{
|
||||
byte ret = 0xFF;
|
||||
|
||||
|
@ -56,7 +56,7 @@
|
|||
return ret;
|
||||
}
|
||||
|
||||
void WriteMemory(ushort address, byte value)
|
||||
void WriteMemorySega(ushort address, byte value)
|
||||
{
|
||||
if (address >= 0xC000)
|
||||
SystemRam[address & RamSizeMask] = value;
|
||||
|
@ -91,14 +91,51 @@
|
|||
}
|
||||
}
|
||||
|
||||
CDLog_MapResults MapMemorySega(ushort address, bool write)
|
||||
{
|
||||
if (address < 0xC000)
|
||||
{
|
||||
if ((Port3E & 0x48) == 0x48) // cart and bios disabled, return empty bus
|
||||
return new CDLog_MapResults();
|
||||
else if (BiosMapped && BiosRom != null)
|
||||
return new CDLog_MapResults(); //bios tracking of CDL is not supported
|
||||
else if (address < 1024)
|
||||
return new CDLog_MapResults() { Type = CDLog_AddrType.ROM, Address = address };
|
||||
else if (address < 0x4000)
|
||||
return new CDLog_MapResults() { Type = CDLog_AddrType.ROM, Address = (RomBank0 * BankSize) + address };
|
||||
else if (address < 0x8000)
|
||||
return new CDLog_MapResults() { Type = CDLog_AddrType.ROM, Address = (RomBank1 * BankSize) + address };
|
||||
else
|
||||
{
|
||||
switch (SaveRamBank)
|
||||
{
|
||||
case 0: return new CDLog_MapResults() { Type = CDLog_AddrType.ROM, Address = (RomBank2 * BankSize) + (address & BankSizeMask) };
|
||||
case 1:
|
||||
if (SaveRAM != null) return new CDLog_MapResults() { Type = CDLog_AddrType.SaveRAM, Address = (address & BankSizeMask) % SaveRAM.Length };
|
||||
else return new CDLog_MapResults();
|
||||
case 2:
|
||||
if (SaveRAM != null) return new CDLog_MapResults() { Type = CDLog_AddrType.SaveRAM, Address = (BankSize + (address & BankSizeMask)) & BankSizeMask };
|
||||
else return new CDLog_MapResults();
|
||||
default:
|
||||
return new CDLog_MapResults() { Type = CDLog_AddrType.MainRAM, Address = address & RamSizeMask };
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return new CDLog_MapResults() { Type = CDLog_AddrType.MainRAM, Address = address & RamSizeMask };
|
||||
}
|
||||
}
|
||||
|
||||
void InitSegaMapper()
|
||||
{
|
||||
Cpu.ReadMemory = ReadMemory;
|
||||
Cpu.WriteMemory = WriteMemory;
|
||||
WriteMemory(0xFFFC, 0);
|
||||
WriteMemory(0xFFFD, 0);
|
||||
WriteMemory(0xFFFE, 1);
|
||||
WriteMemory(0xFFFF, 2);
|
||||
ReadMemory = ReadMemorySega;
|
||||
WriteMemory = WriteMemorySega;
|
||||
MapMemory = MapMemorySega;
|
||||
WriteMemorySega(0xFFFC, 0);
|
||||
WriteMemorySega(0xFFFD, 0);
|
||||
WriteMemorySega(0xFFFE, 1);
|
||||
WriteMemorySega(0xFFFF, 2);
|
||||
}
|
||||
|
||||
// Mapper when loading a BIOS as a ROM (simulating no cart loaded)
|
||||
|
@ -136,12 +173,12 @@
|
|||
|
||||
void InitBiosMapper()
|
||||
{
|
||||
Cpu.ReadMemory = ReadMemoryBIOS;
|
||||
Cpu.WriteMemory = WriteMemoryBIOS;
|
||||
WriteMemory(0xFFFC, 0);
|
||||
WriteMemory(0xFFFD, 0);
|
||||
WriteMemory(0xFFFE, 1);
|
||||
WriteMemory(0xFFFF, 2);
|
||||
ReadMemory = ReadMemoryBIOS;
|
||||
WriteMemory = WriteMemoryBIOS;
|
||||
WriteMemorySega(0xFFFC, 0);
|
||||
WriteMemorySega(0xFFFD, 0);
|
||||
WriteMemorySega(0xFFFE, 1);
|
||||
WriteMemorySega(0xFFFF, 2);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -29,7 +29,7 @@ namespace BizHawk.Emulation.Cores.Sega.MasterSystem
|
|||
)]
|
||||
[ServiceNotApplicable(typeof(IDriveLight))]
|
||||
public sealed partial class SMS : IEmulator, ISaveRam, IStatable, IInputPollable, IRegionable,
|
||||
IDebuggable, ISettable<SMS.SMSSettings, SMS.SMSSyncSettings>
|
||||
IDebuggable, ISettable<SMS.SMSSettings, SMS.SMSSyncSettings>, ICodeDataLogger
|
||||
{
|
||||
// Constants
|
||||
public const int BankSize = 16384;
|
||||
|
@ -214,6 +214,10 @@ namespace BizHawk.Emulation.Cores.Sega.MasterSystem
|
|||
SaveRAM = new byte[0x8000];
|
||||
|
||||
SetupMemoryDomains();
|
||||
|
||||
//this manages the linkage between the cpu and mapper callbacks so it needs running before bootup is complete
|
||||
((ICodeDataLogger)this).SetCDL(null);
|
||||
|
||||
(ServiceProvider as BasicServiceProvider).Register<IDisassemblable>(new Disassembler());
|
||||
}
|
||||
|
||||
|
@ -253,6 +257,24 @@ namespace BizHawk.Emulation.Cores.Sega.MasterSystem
|
|||
isLag = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The ReadMemory callback for the mapper
|
||||
/// </summary>
|
||||
Func<ushort, byte> ReadMemory;
|
||||
|
||||
/// <summary>
|
||||
/// The WriteMemory callback for the wrapper
|
||||
/// </summary>
|
||||
Action<ushort, byte> WriteMemory;
|
||||
|
||||
/// <summary>
|
||||
/// A dummy FetchMemory that simply reads the memory
|
||||
/// </summary>
|
||||
public byte FetchMemory_StubThunk(ushort address, bool first)
|
||||
{
|
||||
return ReadMemory(address);
|
||||
}
|
||||
|
||||
public byte ReadPort(ushort port)
|
||||
{
|
||||
port &= 0xFF;
|
||||
|
@ -452,6 +474,10 @@ namespace BizHawk.Emulation.Cores.Sega.MasterSystem
|
|||
var VRamDomain = new MemoryDomain("Video RAM", Vdp.VRAM.Length, MemoryDomain.Endian.Little,
|
||||
addr => Vdp.VRAM[addr],
|
||||
(addr, value) => Vdp.VRAM[addr] = value);
|
||||
|
||||
var ROMDomain = new MemoryDomain("ROM", RomData.Length, MemoryDomain.Endian.Little,
|
||||
addr => RomData[addr],
|
||||
(addr, value) => RomData[addr] = value);
|
||||
|
||||
var SystemBusDomain = new MemoryDomain("System Bus", 0x10000, MemoryDomain.Endian.Little,
|
||||
(addr) =>
|
||||
|
@ -469,6 +495,7 @@ namespace BizHawk.Emulation.Cores.Sega.MasterSystem
|
|||
|
||||
domains.Add(MainMemoryDomain);
|
||||
domains.Add(VRamDomain);
|
||||
domains.Add(ROMDomain);
|
||||
domains.Add(SystemBusDomain);
|
||||
|
||||
if (SaveRAM != null)
|
||||
|
|
Loading…
Reference in New Issue