C64 - expose tape data as a memory domain, because why not
This commit is contained in:
parent
807edebe6d
commit
3a852707c4
|
@ -8,8 +8,11 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
|
|||
{
|
||||
private IMemoryDomains _memoryDomains;
|
||||
|
||||
private void SetupMemoryDomains(bool diskDriveEnabled)
|
||||
private void SetupMemoryDomains()
|
||||
{
|
||||
bool diskDriveEnabled = _board.DiskDrive != null;
|
||||
bool tapeDriveEnabled = _board.TapeDrive != null;
|
||||
|
||||
var domains = new List<MemoryDomain>
|
||||
{
|
||||
C64MemoryDomainFactory.Create("System Bus", 0x10000, a => _board.Cpu.Peek(a), (a, v) => _board.Cpu.Poke(a, v)),
|
||||
|
@ -30,6 +33,15 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
|
|||
C64MemoryDomainFactory.Create("1541 VIA1", 0x10, a => _board.DiskDrive.PeekVia1(a), (a, v) => _board.DiskDrive.PokeVia1(a, v))
|
||||
});
|
||||
}
|
||||
|
||||
if (tapeDriveEnabled)
|
||||
{
|
||||
domains.AddRange(new[]
|
||||
{
|
||||
C64MemoryDomainFactory.Create("Tape Data", _board.TapeDrive.TapeDataDomain.Length, a => _board.TapeDrive.TapeDataDomain[a], (a,v) => _board.TapeDrive.TapeDataDomain[a] = (byte)v)
|
||||
});
|
||||
}
|
||||
|
||||
_memoryDomains = new MemoryDomainList(domains);
|
||||
((BasicServiceProvider)ServiceProvider).Register(_memoryDomains);
|
||||
}
|
||||
|
|
|
@ -32,9 +32,9 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
|
|||
RomSanityCheck();
|
||||
|
||||
Init(SyncSettings.VicType, Settings.BorderType, SyncSettings.SidType, SyncSettings.TapeDriveType, SyncSettings.DiskDriveType);
|
||||
_cyclesPerFrame = _board.Vic.CyclesPerFrame;
|
||||
SetupMemoryDomains(_board.DiskDrive != null);
|
||||
_cyclesPerFrame = _board.Vic.CyclesPerFrame;
|
||||
_memoryCallbacks = new MemoryCallbackSystem();
|
||||
|
||||
HardReset();
|
||||
|
||||
switch (SyncSettings.VicType)
|
||||
|
@ -66,6 +66,8 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
|
|||
// There are no multi-cart cart games, so just hardcode .First()
|
||||
CoreComm.RomStatusDetails = $"{game.Name}\r\nSHA1:{roms.First().HashSHA1()}\r\nMD5:{roms.First().HashMD5()}\r\nMapper Impl \"{_board.CartPort.CartridgeType}\"";
|
||||
}
|
||||
|
||||
SetupMemoryDomains();
|
||||
}
|
||||
|
||||
// Currently we will require at least one rom. If multiple they MUST be all the same media type in the same format
|
||||
|
|
|
@ -27,5 +27,8 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cassette
|
|||
}
|
||||
|
||||
public abstract void SyncState(Serializer ser);
|
||||
|
||||
// Exposed for memory domains, should not be used for actual emulation implementation
|
||||
public abstract byte[] TapeDataDomain { get; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,12 +9,18 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cassette
|
|||
|
||||
public override void ExecutePhase2()
|
||||
{
|
||||
if (_tape != null && !ReadMotor()) _tape.ExecuteCycle();
|
||||
if (_tape != null && !ReadMotor())
|
||||
{
|
||||
_tape.ExecuteCycle();
|
||||
}
|
||||
}
|
||||
|
||||
public override void HardReset()
|
||||
{
|
||||
if (_tape != null) _tape.Rewind();
|
||||
if (_tape != null)
|
||||
{
|
||||
_tape.Rewind();
|
||||
}
|
||||
}
|
||||
|
||||
public override bool ReadDataInputBuffer()
|
||||
|
@ -41,5 +47,8 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cassette
|
|||
{
|
||||
_tape = null;
|
||||
}
|
||||
|
||||
// Exposed for memory domains, should not be used for actual emulation implementation
|
||||
public override byte[] TapeDataDomain => _tape.TapeDataDomain;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,16 +6,16 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Media
|
|||
{
|
||||
public class Tape
|
||||
{
|
||||
private readonly byte[] _tapeData;
|
||||
private readonly byte[] _tapeData;
|
||||
private readonly byte _version;
|
||||
private readonly int _start;
|
||||
private readonly int _end;
|
||||
private readonly int _start;
|
||||
private readonly int _end;
|
||||
|
||||
private int _pos;
|
||||
private int _pos;
|
||||
|
||||
private int _cycle;
|
||||
private int _cycle;
|
||||
|
||||
private bool _data;
|
||||
private bool _data;
|
||||
|
||||
public Tape(byte version, byte[] tapeData, int start, int end)
|
||||
{
|
||||
|
@ -26,43 +26,43 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Media
|
|||
Rewind();
|
||||
}
|
||||
|
||||
public void ExecuteCycle()
|
||||
{
|
||||
if (_cycle == 0)
|
||||
{
|
||||
if (_pos >= _end)
|
||||
{
|
||||
_data = true;
|
||||
return;
|
||||
}
|
||||
public void ExecuteCycle()
|
||||
{
|
||||
if (_cycle == 0)
|
||||
{
|
||||
if (_pos >= _end)
|
||||
{
|
||||
_data = true;
|
||||
return;
|
||||
}
|
||||
|
||||
_cycle = _tapeData[_pos++] * 8;
|
||||
if (_cycle == 0)
|
||||
{
|
||||
if (_version == 0)
|
||||
{
|
||||
_cycle = 256 * 8; // unspecified overflow condition
|
||||
}
|
||||
else
|
||||
{
|
||||
_cycle = (int)(BitConverter.ToUInt32(_tapeData, _pos - 1) >> 8);
|
||||
_pos += 3;
|
||||
if (_cycle == 0)
|
||||
{
|
||||
throw new Exception("Bad tape data");
|
||||
}
|
||||
}
|
||||
}
|
||||
_cycle = _tapeData[_pos++] * 8;
|
||||
if (_cycle == 0)
|
||||
{
|
||||
if (_version == 0)
|
||||
{
|
||||
_cycle = 256 * 8; // unspecified overflow condition
|
||||
}
|
||||
else
|
||||
{
|
||||
_cycle = (int)(BitConverter.ToUInt32(_tapeData, _pos - 1) >> 8);
|
||||
_pos += 3;
|
||||
if (_cycle == 0)
|
||||
{
|
||||
throw new Exception("Bad tape data");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_cycle++;
|
||||
}
|
||||
_cycle++;
|
||||
}
|
||||
|
||||
// Send a single negative pulse at the end of a cycle
|
||||
_data = --_cycle != 0;
|
||||
}
|
||||
// Send a single negative pulse at the end of a cycle
|
||||
_data = --_cycle != 0;
|
||||
}
|
||||
|
||||
// Rewinds the tape back to start
|
||||
public void Rewind()
|
||||
// Rewinds the tape back to start
|
||||
public void Rewind()
|
||||
{
|
||||
_pos = _start;
|
||||
_cycle = 0;
|
||||
|
@ -71,7 +71,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Media
|
|||
// Reads from tape, this will tell the caller if the flag pin should be raised
|
||||
public bool Read()
|
||||
{
|
||||
return _data;
|
||||
return _data;
|
||||
}
|
||||
|
||||
// Try to construct a tape file from file data. Returns null if not a tape file, throws exceptions for bad tape files.
|
||||
|
@ -100,5 +100,8 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Media
|
|||
ser.Sync("Cycle", ref _cycle);
|
||||
ser.Sync("Data", ref _data);
|
||||
}
|
||||
|
||||
// Exposed for memory domains, should not be used for actual emulation implementation
|
||||
public byte[] TapeDataDomain => _tapeData;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue