mirror of
https://github.com/MoleskiCoder/EightBitNet.git
synced 2025-01-04 20:31:08 +00:00
Correct style issues
This commit is contained in:
parent
dc677e5358
commit
d5c0dcc175
@ -7,66 +7,65 @@ namespace EightBit
|
||||
{
|
||||
public override Register16 PeekWord(ushort address)
|
||||
{
|
||||
this.Intermediate.High = this.Bus.Peek(address);
|
||||
this.Intermediate.Low = this.Bus.Peek(++address);
|
||||
return this.Intermediate;
|
||||
Intermediate.High = Bus.Peek(address);
|
||||
Intermediate.Low = Bus.Peek(++address);
|
||||
return Intermediate;
|
||||
}
|
||||
|
||||
public override void PokeWord(ushort address, Register16 value)
|
||||
{
|
||||
this.Bus.Poke(address, value.High);
|
||||
this.Bus.Poke(++address, value.Low);
|
||||
Bus.Poke(address, value.High);
|
||||
Bus.Poke(++address, value.Low);
|
||||
}
|
||||
|
||||
protected override Register16 FetchWord()
|
||||
{
|
||||
this.Intermediate.High = this.FetchByte();
|
||||
this.Intermediate.Low = this.FetchByte();
|
||||
return this.Intermediate;
|
||||
Intermediate.High = FetchByte();
|
||||
Intermediate.Low = FetchByte();
|
||||
return Intermediate;
|
||||
}
|
||||
|
||||
protected override Register16 GetWord()
|
||||
{
|
||||
this.Intermediate.High = this.MemoryRead();
|
||||
++this.Bus.Address.Word;
|
||||
this.Intermediate.Low = this.MemoryRead();
|
||||
return this.Intermediate;
|
||||
Intermediate.High = MemoryRead();
|
||||
++Bus.Address.Word;
|
||||
Intermediate.Low = MemoryRead();
|
||||
return Intermediate;
|
||||
}
|
||||
|
||||
protected override Register16 GetWordPaged()
|
||||
{
|
||||
this.Intermediate.High = this.MemoryRead();
|
||||
++this.Bus.Address.Low;
|
||||
this.Intermediate.Low = this.MemoryRead();
|
||||
return this.Intermediate;
|
||||
Intermediate.High = MemoryRead();
|
||||
++Bus.Address.Low;
|
||||
Intermediate.Low = MemoryRead();
|
||||
return Intermediate;
|
||||
}
|
||||
|
||||
protected override Register16 PopWord()
|
||||
{
|
||||
this.Intermediate.High = this.Pop();
|
||||
this.Intermediate.Low = this.Pop();
|
||||
return this.Intermediate;
|
||||
Intermediate.High = Pop();
|
||||
Intermediate.Low = Pop();
|
||||
return Intermediate;
|
||||
}
|
||||
|
||||
protected override void PushWord(Register16 value)
|
||||
{
|
||||
this.Push(value.Low);
|
||||
this.Push(value.High);
|
||||
Push(value.Low);
|
||||
Push(value.High);
|
||||
}
|
||||
|
||||
protected override void SetWord(Register16 value)
|
||||
{
|
||||
this.MemoryWrite(value.High);
|
||||
++this.Bus.Address.Word;
|
||||
this.MemoryWrite(value.Low);
|
||||
MemoryWrite(value.High);
|
||||
++Bus.Address.Word;
|
||||
MemoryWrite(value.Low);
|
||||
}
|
||||
|
||||
protected override void SetWordPaged(Register16 value)
|
||||
{
|
||||
this.MemoryWrite(value.High);
|
||||
++this.Bus.Address.Low;
|
||||
this.MemoryWrite(value.Low);
|
||||
MemoryWrite(value.High);
|
||||
++Bus.Address.Low;
|
||||
MemoryWrite(value.Low);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ namespace EightBit
|
||||
|
||||
public abstract class Bus : IMapper
|
||||
{
|
||||
private byte data;
|
||||
private byte _data;
|
||||
|
||||
public event EventHandler<EventArgs>? WritingByte;
|
||||
|
||||
@ -18,71 +18,71 @@ namespace EightBit
|
||||
|
||||
public event EventHandler<EventArgs>? ReadByte;
|
||||
|
||||
public ref byte Data => ref this.data;
|
||||
public ref byte Data => ref _data;
|
||||
|
||||
public Register16 Address { get; } = new();
|
||||
|
||||
public abstract MemoryMapping Mapping(ushort absolute);
|
||||
|
||||
public byte Peek() => this.Reference();
|
||||
public byte Peek() => Reference();
|
||||
|
||||
public byte Peek(ushort absolute) => this.Reference(absolute);
|
||||
public byte Peek(ushort absolute) => Reference(absolute);
|
||||
|
||||
public byte Peek(Register16 absolute) => this.Peek(absolute.Word);
|
||||
public byte Peek(Register16 absolute) => Peek(absolute.Word);
|
||||
|
||||
public void Poke(byte value) => this.Reference() = value;
|
||||
public void Poke(byte value) => Reference() = value;
|
||||
|
||||
public void Poke(ushort absolute, byte value) => this.Reference(absolute) = value;
|
||||
public void Poke(ushort absolute, byte value) => Reference(absolute) = value;
|
||||
|
||||
public void Poke(Register16 absolute, byte value) => this.Poke(absolute.Word, value);
|
||||
public void Poke(Register16 absolute, byte value) => Poke(absolute.Word, value);
|
||||
|
||||
public byte Read()
|
||||
{
|
||||
this.OnReadingByte();
|
||||
var returned = this.Data = this.Reference();
|
||||
this.OnReadByte();
|
||||
OnReadingByte();
|
||||
var returned = Data = Reference();
|
||||
OnReadByte();
|
||||
return returned;
|
||||
}
|
||||
|
||||
public byte Read(ushort absolute)
|
||||
{
|
||||
this.Address.Word = absolute;
|
||||
return this.Read();
|
||||
Address.Word = absolute;
|
||||
return Read();
|
||||
}
|
||||
|
||||
public byte Read(Register16 absolute) => this.Read(absolute.Low, absolute.High);
|
||||
public byte Read(Register16 absolute) => Read(absolute.Low, absolute.High);
|
||||
|
||||
public byte Read(byte low, byte high)
|
||||
{
|
||||
this.Address.Assign(low, high);
|
||||
return this.Read();
|
||||
Address.Assign(low, high);
|
||||
return Read();
|
||||
}
|
||||
|
||||
public void Write()
|
||||
{
|
||||
this.OnWritingByte();
|
||||
this.Reference() = this.Data;
|
||||
this.OnWrittenByte();
|
||||
OnWritingByte();
|
||||
Reference() = Data;
|
||||
OnWrittenByte();
|
||||
}
|
||||
|
||||
public void Write(byte value)
|
||||
{
|
||||
this.Data = value;
|
||||
this.Write();
|
||||
Data = value;
|
||||
Write();
|
||||
}
|
||||
|
||||
public void Write(ushort absolute, byte value)
|
||||
{
|
||||
this.Address.Word = absolute;
|
||||
this.Write(value);
|
||||
Address.Word = absolute;
|
||||
Write(value);
|
||||
}
|
||||
|
||||
public void Write(Register16 absolute, byte value) => this.Write(absolute.Low, absolute.High, value);
|
||||
public void Write(Register16 absolute, byte value) => Write(absolute.Low, absolute.High, value);
|
||||
|
||||
public void Write(byte low, byte high, byte value)
|
||||
{
|
||||
this.Address.Assign(low, high);
|
||||
this.Write(value);
|
||||
Address.Assign(low, high);
|
||||
Write(value);
|
||||
}
|
||||
|
||||
public virtual void RaisePOWER()
|
||||
@ -95,37 +95,37 @@ namespace EightBit
|
||||
|
||||
public abstract void Initialize();
|
||||
|
||||
protected virtual void OnWritingByte() => this.WritingByte?.Invoke(this, EventArgs.Empty);
|
||||
protected virtual void OnWritingByte() => WritingByte?.Invoke(this, EventArgs.Empty);
|
||||
|
||||
protected virtual void OnWrittenByte() => this.WrittenByte?.Invoke(this, EventArgs.Empty);
|
||||
protected virtual void OnWrittenByte() => WrittenByte?.Invoke(this, EventArgs.Empty);
|
||||
|
||||
protected virtual void OnReadingByte() => this.ReadingByte?.Invoke(this, EventArgs.Empty);
|
||||
protected virtual void OnReadingByte() => ReadingByte?.Invoke(this, EventArgs.Empty);
|
||||
|
||||
protected virtual void OnReadByte() => this.ReadByte?.Invoke(this, EventArgs.Empty);
|
||||
protected virtual void OnReadByte() => ReadByte?.Invoke(this, EventArgs.Empty);
|
||||
|
||||
protected ref byte Reference(ushort absolute)
|
||||
{
|
||||
var mapped = this.Mapping(absolute);
|
||||
var mapped = Mapping(absolute);
|
||||
var offset = (ushort)mapped.Offset(absolute);
|
||||
if (mapped.Access == AccessLevel.ReadOnly)
|
||||
{
|
||||
this.Data = mapped.Memory.Peek(offset);
|
||||
return ref this.data;
|
||||
Data = mapped.Memory.Peek(offset);
|
||||
return ref _data;
|
||||
}
|
||||
|
||||
return ref mapped.Memory.Reference(offset);
|
||||
}
|
||||
|
||||
protected ref byte Reference(Register16 absolute) => ref this.Reference(absolute.Word);
|
||||
protected ref byte Reference(Register16 absolute) => ref Reference(absolute.Word);
|
||||
|
||||
protected ref byte Reference() => ref this.Reference(this.Address);
|
||||
protected ref byte Reference() => ref Reference(Address);
|
||||
|
||||
protected void LoadHexFile(string path)
|
||||
{
|
||||
var file = new IntelHexFile(path);
|
||||
foreach (var (address, content) in file.Parse())
|
||||
{
|
||||
var mapped = this.Mapping(address);
|
||||
var mapped = Mapping(address);
|
||||
var offset = address - mapped.Begin;
|
||||
mapped.Memory.Load(content, offset);
|
||||
}
|
||||
|
@ -20,18 +20,18 @@ namespace EightBit
|
||||
{
|
||||
for (var i = 0; i < extra; ++i)
|
||||
{
|
||||
this.Tick();
|
||||
Tick();
|
||||
}
|
||||
}
|
||||
|
||||
public void Tick()
|
||||
{
|
||||
++this.Cycles;
|
||||
this.OnTicked();
|
||||
++Cycles;
|
||||
OnTicked();
|
||||
}
|
||||
|
||||
protected virtual void OnTicked() => this.Ticked?.Invoke(this, EventArgs.Empty);
|
||||
protected virtual void OnTicked() => Ticked?.Invoke(this, EventArgs.Empty);
|
||||
|
||||
protected void ResetCycles() => this.Cycles = 0;
|
||||
protected void ResetCycles() => Cycles = 0;
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ namespace EightBit
|
||||
|
||||
public class Device
|
||||
{
|
||||
private PinLevel powerLine;
|
||||
private PinLevel _powerLine;
|
||||
|
||||
public event EventHandler<EventArgs>? RaisingPOWER;
|
||||
|
||||
@ -18,36 +18,36 @@ namespace EightBit
|
||||
|
||||
public event EventHandler<EventArgs>? LoweredPOWER;
|
||||
|
||||
public bool Powered => this.POWER.Raised();
|
||||
public bool Powered => POWER.Raised();
|
||||
|
||||
public ref PinLevel POWER => ref this.powerLine;
|
||||
public ref PinLevel POWER => ref _powerLine;
|
||||
|
||||
public virtual void RaisePOWER()
|
||||
{
|
||||
if (this.POWER.Lowered())
|
||||
if (POWER.Lowered())
|
||||
{
|
||||
this.OnRaisingPOWER();
|
||||
this.POWER.Raise();
|
||||
this.OnRaisedPOWER();
|
||||
OnRaisingPOWER();
|
||||
POWER.Raise();
|
||||
OnRaisedPOWER();
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void LowerPOWER()
|
||||
{
|
||||
if (this.POWER.Raised())
|
||||
if (POWER.Raised())
|
||||
{
|
||||
this.OnLoweringPOWER();
|
||||
this.POWER.Lower();
|
||||
this.OnLoweredPOWER();
|
||||
OnLoweringPOWER();
|
||||
POWER.Lower();
|
||||
OnLoweredPOWER();
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void OnRaisingPOWER() => this.RaisingPOWER?.Invoke(this, EventArgs.Empty);
|
||||
protected virtual void OnRaisingPOWER() => RaisingPOWER?.Invoke(this, EventArgs.Empty);
|
||||
|
||||
protected virtual void OnRaisedPOWER() => this.RaisedPOWER?.Invoke(this, EventArgs.Empty);
|
||||
protected virtual void OnRaisedPOWER() => RaisedPOWER?.Invoke(this, EventArgs.Empty);
|
||||
|
||||
protected virtual void OnLoweringPOWER() => this.LoweringPOWER?.Invoke(this, EventArgs.Empty);
|
||||
protected virtual void OnLoweringPOWER() => LoweringPOWER?.Invoke(this, EventArgs.Empty);
|
||||
|
||||
protected virtual void OnLoweredPOWER() => this.LoweredPOWER?.Invoke(this, EventArgs.Empty);
|
||||
protected virtual void OnLoweredPOWER() => LoweredPOWER?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
@ -8,8 +8,8 @@ namespace EightBit
|
||||
|
||||
public sealed class InputOutput
|
||||
{
|
||||
private readonly byte[] input = new byte[0x100];
|
||||
private readonly byte[] output = new byte[0x100];
|
||||
private readonly byte[] _input = new byte[0x100];
|
||||
private readonly byte[] _output = new byte[0x100];
|
||||
|
||||
public event EventHandler<PortEventArgs>? ReadingPort;
|
||||
|
||||
@ -19,35 +19,35 @@ namespace EightBit
|
||||
|
||||
public event EventHandler<PortEventArgs>? WrittenPort;
|
||||
|
||||
public byte Read(byte port) => this.ReadInputPort(port);
|
||||
public byte Read(byte port) => ReadInputPort(port);
|
||||
|
||||
public void Write(byte port, byte value) => this.WriteOutputPort(port, value);
|
||||
public void Write(byte port, byte value) => WriteOutputPort(port, value);
|
||||
|
||||
public byte ReadInputPort(byte port)
|
||||
{
|
||||
this.OnReadingPort(port);
|
||||
var value = this.input[port];
|
||||
this.OnReadPort(port);
|
||||
OnReadingPort(port);
|
||||
var value = _input[port];
|
||||
OnReadPort(port);
|
||||
return value;
|
||||
}
|
||||
|
||||
public void WriteInputPort(byte port, byte value) => this.input[port] = value;
|
||||
public void WriteInputPort(byte port, byte value) => _input[port] = value;
|
||||
|
||||
public byte ReadOutputPort(byte port) => this.output[port];
|
||||
public byte ReadOutputPort(byte port) => _output[port];
|
||||
|
||||
public void WriteOutputPort(byte port, byte value)
|
||||
{
|
||||
this.OnWritingPort(port);
|
||||
this.output[port] = value;
|
||||
this.OnWrittenPort(port);
|
||||
OnWritingPort(port);
|
||||
_output[port] = value;
|
||||
OnWrittenPort(port);
|
||||
}
|
||||
|
||||
private void OnReadingPort(byte port) => this.ReadingPort?.Invoke(this, new PortEventArgs(port));
|
||||
private void OnReadingPort(byte port) => ReadingPort?.Invoke(this, new PortEventArgs(port));
|
||||
|
||||
private void OnReadPort(byte port) => this.ReadPort?.Invoke(this, new PortEventArgs(port));
|
||||
private void OnReadPort(byte port) => ReadPort?.Invoke(this, new PortEventArgs(port));
|
||||
|
||||
private void OnWritingPort(byte port) => this.WritingPort?.Invoke(this, new PortEventArgs(port));
|
||||
private void OnWritingPort(byte port) => WritingPort?.Invoke(this, new PortEventArgs(port));
|
||||
|
||||
private void OnWrittenPort(byte port) => this.WrittenPort?.Invoke(this, new PortEventArgs(port));
|
||||
private void OnWrittenPort(byte port) => WrittenPort?.Invoke(this, new PortEventArgs(port));
|
||||
}
|
||||
}
|
||||
|
@ -11,23 +11,23 @@ namespace EightBit
|
||||
public class IntelHexFile(string path)
|
||||
{
|
||||
private readonly string _path = path;
|
||||
private bool eof;
|
||||
private bool _eof;
|
||||
|
||||
public IEnumerable<Tuple<ushort, byte[]>> Parse()
|
||||
{
|
||||
this.eof = false;
|
||||
using var reader = File.OpenText(this._path);
|
||||
while (!reader.EndOfStream && !this.eof)
|
||||
_eof = false;
|
||||
using var reader = File.OpenText(_path);
|
||||
while (!reader.EndOfStream && !_eof)
|
||||
{
|
||||
var line = reader.ReadLine() ?? throw new InvalidOperationException("Early EOF detected");
|
||||
var parsed = this.Parse(line);
|
||||
var parsed = Parse(line);
|
||||
if (parsed != null)
|
||||
{
|
||||
yield return parsed;
|
||||
}
|
||||
}
|
||||
|
||||
if (!this.eof)
|
||||
if (!_eof)
|
||||
{
|
||||
throw new InvalidOperationException("File is missing an EOF record");
|
||||
}
|
||||
@ -77,7 +77,7 @@ namespace EightBit
|
||||
return new Tuple<ushort, byte[]>(address, ParseDataRecord(line, count));
|
||||
|
||||
case 0x01:
|
||||
this.eof = true;
|
||||
_eof = true;
|
||||
return null;
|
||||
|
||||
default:
|
||||
|
@ -8,11 +8,11 @@ namespace EightBit
|
||||
{
|
||||
public IntelOpCodeDecoded(byte opCode)
|
||||
{
|
||||
this.X = (opCode & 0b11000000) >> 6; // 0 - 3
|
||||
this.Y = (opCode & 0b00111000) >> 3; // 0 - 7
|
||||
this.Z = opCode & 0b00000111; // 0 - 7
|
||||
this.P = (this.Y & 0b110) >> 1; // 0 - 3
|
||||
this.Q = this.Y & 1; // 0 - 1
|
||||
X = (opCode & 0b11000000) >> 6; // 0 - 3
|
||||
Y = (opCode & 0b00111000) >> 3; // 0 - 7
|
||||
Z = opCode & 0b00000111; // 0 - 7
|
||||
P = (Y & 0b110) >> 1; // 0 - 3
|
||||
Q = Y & 1; // 0 - 1
|
||||
}
|
||||
|
||||
public int X { get; }
|
||||
|
@ -11,16 +11,16 @@ namespace EightBit
|
||||
private static readonly int[] HalfCarryTableAdd = [0, 0, 1, 0, 1, 0, 1, 1];
|
||||
private static readonly int[] HalfCarryTableSub = [0, 1, 1, 1, 0, 0, 0, 1];
|
||||
|
||||
private readonly IntelOpCodeDecoded[] decodedOpCodes = new IntelOpCodeDecoded[0x100];
|
||||
private readonly IntelOpCodeDecoded[] _decodedOpCodes = new IntelOpCodeDecoded[0x100];
|
||||
|
||||
private PinLevel haltLine;
|
||||
private PinLevel _haltLine;
|
||||
|
||||
protected IntelProcessor(Bus bus)
|
||||
: base(bus)
|
||||
{
|
||||
for (var i = 0; i < 0x100; ++i)
|
||||
{
|
||||
this.decodedOpCodes[i] = new((byte)i);
|
||||
_decodedOpCodes[i] = new((byte)i);
|
||||
}
|
||||
}
|
||||
|
||||
@ -38,49 +38,49 @@ namespace EightBit
|
||||
|
||||
public abstract Register16 AF { get; }
|
||||
|
||||
public ref byte A => ref this.AF.High;
|
||||
public ref byte A => ref AF.High;
|
||||
|
||||
public ref byte F => ref this.AF.Low;
|
||||
public ref byte F => ref AF.Low;
|
||||
|
||||
public abstract Register16 BC { get; }
|
||||
|
||||
public ref byte B => ref this.BC.High;
|
||||
public ref byte B => ref BC.High;
|
||||
|
||||
public ref byte C => ref this.BC.Low;
|
||||
public ref byte C => ref BC.Low;
|
||||
|
||||
public abstract Register16 DE { get; }
|
||||
|
||||
public ref byte D => ref this.DE.High;
|
||||
public ref byte D => ref DE.High;
|
||||
|
||||
public ref byte E => ref this.DE.Low;
|
||||
public ref byte E => ref DE.Low;
|
||||
|
||||
public abstract Register16 HL { get; }
|
||||
|
||||
public ref byte H => ref this.HL.High;
|
||||
public ref byte H => ref HL.High;
|
||||
|
||||
public ref byte L => ref this.HL.Low;
|
||||
public ref byte L => ref HL.Low;
|
||||
|
||||
public ref PinLevel HALT => ref this.haltLine;
|
||||
public ref PinLevel HALT => ref _haltLine;
|
||||
|
||||
public IntelOpCodeDecoded GetDecodedOpCode(byte opCode) => this.decodedOpCodes[opCode];
|
||||
public IntelOpCodeDecoded GetDecodedOpCode(byte opCode) => _decodedOpCodes[opCode];
|
||||
|
||||
public virtual void RaiseHALT()
|
||||
{
|
||||
if (this.HALT.Lowered())
|
||||
if (HALT.Lowered())
|
||||
{
|
||||
this.OnRaisingHALT();
|
||||
this.HALT.Raise();
|
||||
this.OnRaisedHALT();
|
||||
OnRaisingHALT();
|
||||
HALT.Raise();
|
||||
OnRaisedHALT();
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void LowerHALT()
|
||||
{
|
||||
if (this.HALT.Raised())
|
||||
if (HALT.Raised())
|
||||
{
|
||||
this.OnLoweringHALT();
|
||||
this.HALT.Lower();
|
||||
this.OnLoweredHALT();
|
||||
OnLoweringHALT();
|
||||
HALT.Lower();
|
||||
OnLoweredHALT();
|
||||
}
|
||||
}
|
||||
|
||||
@ -100,73 +100,73 @@ namespace EightBit
|
||||
|
||||
protected override void OnRaisedPOWER()
|
||||
{
|
||||
this.PC.Word = this.SP.Word = this.AF.Word = this.BC.Word = this.DE.Word = this.HL.Word = (ushort)Mask.Sixteen;
|
||||
this.RaiseHALT();
|
||||
PC.Word = SP.Word = AF.Word = BC.Word = DE.Word = HL.Word = (ushort)Mask.Sixteen;
|
||||
RaiseHALT();
|
||||
base.OnRaisedPOWER();
|
||||
}
|
||||
|
||||
protected virtual void OnRaisingHALT() => this.RaisingHALT?.Invoke(this, EventArgs.Empty);
|
||||
protected virtual void OnRaisingHALT() => RaisingHALT?.Invoke(this, EventArgs.Empty);
|
||||
|
||||
protected virtual void OnRaisedHALT()
|
||||
{
|
||||
++this.PC.Word; // Release the PC from HALT instruction
|
||||
this.RaisedHALT?.Invoke(this, EventArgs.Empty);
|
||||
++PC.Word; // Release the PC from HALT instruction
|
||||
RaisedHALT?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
protected virtual void OnLoweringHALT() => this.LoweringHALT?.Invoke(this, EventArgs.Empty);
|
||||
protected virtual void OnLoweringHALT() => LoweringHALT?.Invoke(this, EventArgs.Empty);
|
||||
|
||||
protected virtual void OnLoweredHALT()
|
||||
{
|
||||
--this.PC.Word; // Keep the PC on the HALT instruction (i.e. executing NOP)
|
||||
this.LoweredHALT?.Invoke(this, EventArgs.Empty);
|
||||
--PC.Word; // Keep the PC on the HALT instruction (i.e. executing NOP)
|
||||
LoweredHALT?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
protected override void HandleRESET()
|
||||
{
|
||||
base.HandleRESET();
|
||||
this.Jump(0);
|
||||
Jump(0);
|
||||
}
|
||||
|
||||
protected sealed override void Push(byte value)
|
||||
{
|
||||
--this.SP.Word;
|
||||
this.MemoryWrite(this.SP, value);
|
||||
--SP.Word;
|
||||
MemoryWrite(SP, value);
|
||||
}
|
||||
|
||||
protected sealed override byte Pop()
|
||||
{
|
||||
var returned = this.MemoryRead(this.SP);
|
||||
this.SP.Word++;
|
||||
var returned = MemoryRead(SP);
|
||||
SP.Word++;
|
||||
return returned;
|
||||
}
|
||||
|
||||
protected sealed override Register16 GetWord()
|
||||
{
|
||||
var returned = base.GetWord();
|
||||
this.MEMPTR.Assign(this.Bus.Address);
|
||||
MEMPTR.Assign(Bus.Address);
|
||||
return returned;
|
||||
}
|
||||
|
||||
protected sealed override void SetWord(Register16 value)
|
||||
{
|
||||
base.SetWord(value);
|
||||
this.MEMPTR.Assign(this.Bus.Address);
|
||||
MEMPTR.Assign(Bus.Address);
|
||||
}
|
||||
|
||||
////
|
||||
|
||||
protected void Restart(byte address)
|
||||
{
|
||||
this.MEMPTR.Assign(address, 0);
|
||||
this.Call(this.MEMPTR);
|
||||
MEMPTR.Assign(address, 0);
|
||||
Call(MEMPTR);
|
||||
}
|
||||
|
||||
protected bool CallConditional(bool condition)
|
||||
{
|
||||
this.FetchWordMEMPTR();
|
||||
FetchWordMEMPTR();
|
||||
if (condition)
|
||||
{
|
||||
this.Call(this.MEMPTR);
|
||||
Call(MEMPTR);
|
||||
}
|
||||
|
||||
return condition;
|
||||
@ -174,10 +174,10 @@ namespace EightBit
|
||||
|
||||
protected bool JumpConditional(bool condition)
|
||||
{
|
||||
this.FetchWordMEMPTR();
|
||||
FetchWordMEMPTR();
|
||||
if (condition)
|
||||
{
|
||||
this.Jump(this.MEMPTR);
|
||||
Jump(MEMPTR);
|
||||
}
|
||||
|
||||
return condition;
|
||||
@ -187,7 +187,7 @@ namespace EightBit
|
||||
{
|
||||
if (condition)
|
||||
{
|
||||
this.Return();
|
||||
Return();
|
||||
}
|
||||
|
||||
return condition;
|
||||
@ -195,36 +195,36 @@ namespace EightBit
|
||||
|
||||
protected void FetchWordMEMPTR()
|
||||
{
|
||||
this.FetchWord();
|
||||
this.MEMPTR.Assign(this.Intermediate);
|
||||
FetchWord();
|
||||
MEMPTR.Assign(Intermediate);
|
||||
}
|
||||
|
||||
protected void JumpIndirect()
|
||||
{
|
||||
this.FetchWordMEMPTR();
|
||||
this.Jump(this.MEMPTR);
|
||||
FetchWordMEMPTR();
|
||||
Jump(MEMPTR);
|
||||
}
|
||||
|
||||
protected void CallIndirect()
|
||||
{
|
||||
this.FetchWordMEMPTR();
|
||||
this.Call(this.MEMPTR);
|
||||
FetchWordMEMPTR();
|
||||
Call(MEMPTR);
|
||||
}
|
||||
|
||||
protected void JumpRelative(sbyte offset)
|
||||
{
|
||||
this.MEMPTR.Word = (ushort)(this.PC.Word + offset);
|
||||
this.Jump(this.MEMPTR);
|
||||
MEMPTR.Word = (ushort)(PC.Word + offset);
|
||||
Jump(MEMPTR);
|
||||
}
|
||||
|
||||
protected bool JumpRelativeConditional(bool condition)
|
||||
{
|
||||
this.Intermediate.Assign(this.PC);
|
||||
++this.PC.Word;
|
||||
Intermediate.Assign(PC);
|
||||
++PC.Word;
|
||||
if (condition)
|
||||
{
|
||||
var offset = (sbyte)this.MemoryRead(this.Intermediate);
|
||||
this.JumpRelative(offset);
|
||||
var offset = (sbyte)MemoryRead(Intermediate);
|
||||
JumpRelative(offset);
|
||||
}
|
||||
|
||||
return condition;
|
||||
@ -233,7 +233,7 @@ namespace EightBit
|
||||
protected override sealed void Return()
|
||||
{
|
||||
base.Return();
|
||||
this.MEMPTR.Assign(this.PC);
|
||||
MEMPTR.Assign(PC);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,65 +8,65 @@ namespace EightBit
|
||||
{
|
||||
public override Register16 PeekWord(ushort address)
|
||||
{
|
||||
this.Intermediate.Low = this.Bus.Peek(address);
|
||||
this.Intermediate.High = this.Bus.Peek(++address);
|
||||
return this.Intermediate;
|
||||
Intermediate.Low = Bus.Peek(address);
|
||||
Intermediate.High = Bus.Peek(++address);
|
||||
return Intermediate;
|
||||
}
|
||||
|
||||
public override void PokeWord(ushort address, Register16 value)
|
||||
{
|
||||
this.Bus.Poke(address, value.Low);
|
||||
this.Bus.Poke(++address, value.High);
|
||||
Bus.Poke(address, value.Low);
|
||||
Bus.Poke(++address, value.High);
|
||||
}
|
||||
|
||||
protected override Register16 FetchWord()
|
||||
{
|
||||
this.Intermediate.Low = this.FetchByte();
|
||||
this.Intermediate.High = this.FetchByte();
|
||||
return this.Intermediate;
|
||||
Intermediate.Low = FetchByte();
|
||||
Intermediate.High = FetchByte();
|
||||
return Intermediate;
|
||||
}
|
||||
|
||||
protected override Register16 GetWord()
|
||||
{
|
||||
this.Intermediate.Low = this.MemoryRead();
|
||||
++this.Bus.Address.Word;
|
||||
this.Intermediate.High = this.MemoryRead();
|
||||
return this.Intermediate;
|
||||
Intermediate.Low = MemoryRead();
|
||||
++Bus.Address.Word;
|
||||
Intermediate.High = MemoryRead();
|
||||
return Intermediate;
|
||||
}
|
||||
|
||||
protected override Register16 GetWordPaged()
|
||||
{
|
||||
this.Intermediate.Low = this.MemoryRead();
|
||||
++this.Bus.Address.Low;
|
||||
this.Intermediate.High = this.MemoryRead();
|
||||
return this.Intermediate;
|
||||
Intermediate.Low = MemoryRead();
|
||||
++Bus.Address.Low;
|
||||
Intermediate.High = MemoryRead();
|
||||
return Intermediate;
|
||||
}
|
||||
|
||||
protected override Register16 PopWord()
|
||||
{
|
||||
this.Intermediate.Low = this.Pop();
|
||||
this.Intermediate.High = this.Pop();
|
||||
return this.Intermediate;
|
||||
Intermediate.Low = Pop();
|
||||
Intermediate.High = Pop();
|
||||
return Intermediate;
|
||||
}
|
||||
|
||||
protected override void PushWord(Register16 value)
|
||||
{
|
||||
this.Push(value.High);
|
||||
this.Push(value.Low);
|
||||
Push(value.High);
|
||||
Push(value.Low);
|
||||
}
|
||||
|
||||
protected override void SetWord(Register16 value)
|
||||
{
|
||||
this.MemoryWrite(value.Low);
|
||||
++this.Bus.Address.Word;
|
||||
this.MemoryWrite(value.High);
|
||||
MemoryWrite(value.Low);
|
||||
++Bus.Address.Word;
|
||||
MemoryWrite(value.High);
|
||||
}
|
||||
|
||||
protected override void SetWordPaged(Register16 value)
|
||||
{
|
||||
this.MemoryWrite(value.Low);
|
||||
++this.Bus.Address.Low;
|
||||
this.MemoryWrite(value.High);
|
||||
MemoryWrite(value.Low);
|
||||
++Bus.Address.Low;
|
||||
MemoryWrite(value.High);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ namespace EightBit
|
||||
|
||||
public int Offset(ushort absolute)
|
||||
{
|
||||
return (absolute - this.Begin) & this.Mask;
|
||||
return (absolute - Begin) & Mask;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,13 +12,13 @@ namespace EightBit
|
||||
|
||||
public event EventHandler<EventArgs>? ExecutingInstruction;
|
||||
public event EventHandler<EventArgs>? ExecutedInstruction;
|
||||
protected virtual void OnExecutedInstruction() => this.ExecutedInstruction?.Invoke(this, EventArgs.Empty);
|
||||
protected virtual void OnExecutingInstruction() => this.ExecutingInstruction?.Invoke(this, EventArgs.Empty);
|
||||
protected virtual void OnExecutedInstruction() => ExecutedInstruction?.Invoke(this, EventArgs.Empty);
|
||||
protected virtual void OnExecutingInstruction() => ExecutingInstruction?.Invoke(this, EventArgs.Empty);
|
||||
|
||||
#endregion
|
||||
|
||||
private PinLevel resetLine;
|
||||
private PinLevel intLine;
|
||||
private PinLevel _resetLine;
|
||||
private PinLevel _intLine;
|
||||
|
||||
public event EventHandler<EventArgs>? RaisingRESET;
|
||||
|
||||
@ -36,9 +36,9 @@ namespace EightBit
|
||||
|
||||
public event EventHandler<EventArgs>? LoweredINT;
|
||||
|
||||
public ref PinLevel RESET => ref this.resetLine;
|
||||
public ref PinLevel RESET => ref _resetLine;
|
||||
|
||||
public ref PinLevel INT => ref this.intLine;
|
||||
public ref PinLevel INT => ref _intLine;
|
||||
|
||||
public Bus Bus { get; } = memory;
|
||||
|
||||
@ -60,15 +60,15 @@ namespace EightBit
|
||||
|
||||
public virtual int Step()
|
||||
{
|
||||
this.ResetCycles();
|
||||
this.OnExecutingInstruction();
|
||||
if (this.Powered)
|
||||
ResetCycles();
|
||||
OnExecutingInstruction();
|
||||
if (Powered)
|
||||
{
|
||||
this.PoweredStep();
|
||||
PoweredStep();
|
||||
}
|
||||
|
||||
this.OnExecutedInstruction();
|
||||
return this.Cycles;
|
||||
OnExecutedInstruction();
|
||||
return Cycles;
|
||||
}
|
||||
|
||||
public abstract void PoweredStep();
|
||||
@ -78,9 +78,9 @@ namespace EightBit
|
||||
public int Run(int limit)
|
||||
{
|
||||
var current = 0;
|
||||
while (this.Powered && (current < limit))
|
||||
while (Powered && (current < limit))
|
||||
{
|
||||
current += this.Step();
|
||||
current += Step();
|
||||
}
|
||||
|
||||
return current;
|
||||
@ -88,131 +88,131 @@ namespace EightBit
|
||||
|
||||
public void Execute(byte value)
|
||||
{
|
||||
this.OpCode = value;
|
||||
this.Execute();
|
||||
OpCode = value;
|
||||
Execute();
|
||||
}
|
||||
|
||||
public abstract Register16 PeekWord(ushort address);
|
||||
|
||||
public abstract void PokeWord(ushort address, Register16 value);
|
||||
|
||||
public void PokeWord(ushort address, ushort value) => this.PokeWord(address, new Register16(value));
|
||||
public void PokeWord(ushort address, ushort value) => PokeWord(address, new Register16(value));
|
||||
|
||||
public virtual void RaiseRESET()
|
||||
{
|
||||
if (this.RESET.Lowered())
|
||||
if (RESET.Lowered())
|
||||
{
|
||||
this.OnRaisingRESET();
|
||||
this.RESET.Raise();
|
||||
this.OnRaisedRESET();
|
||||
OnRaisingRESET();
|
||||
RESET.Raise();
|
||||
OnRaisedRESET();
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void LowerRESET()
|
||||
{
|
||||
if (this.RESET.Raised())
|
||||
if (RESET.Raised())
|
||||
{
|
||||
this.OnLoweringRESET();
|
||||
this.RESET.Lower();
|
||||
this.OnLoweredRESET();
|
||||
OnLoweringRESET();
|
||||
RESET.Lower();
|
||||
OnLoweredRESET();
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void RaiseINT()
|
||||
{
|
||||
if (this.INT.Lowered())
|
||||
if (INT.Lowered())
|
||||
{
|
||||
this.OnRaisingINT();
|
||||
this.INT.Raise();
|
||||
this.OnRaisedINT();
|
||||
OnRaisingINT();
|
||||
INT.Raise();
|
||||
OnRaisedINT();
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void LowerINT()
|
||||
{
|
||||
if (this.INT.Raised())
|
||||
if (INT.Raised())
|
||||
{
|
||||
this.OnLoweringINT();
|
||||
this.INT.Lower();
|
||||
this.OnLoweredINT();
|
||||
OnLoweringINT();
|
||||
INT.Lower();
|
||||
OnLoweredINT();
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void OnRaisingRESET() => this.RaisingRESET?.Invoke(this, EventArgs.Empty);
|
||||
protected virtual void OnRaisingRESET() => RaisingRESET?.Invoke(this, EventArgs.Empty);
|
||||
|
||||
protected virtual void OnRaisedRESET() => this.RaisedRESET?.Invoke(this, EventArgs.Empty);
|
||||
protected virtual void OnRaisedRESET() => RaisedRESET?.Invoke(this, EventArgs.Empty);
|
||||
|
||||
protected virtual void OnLoweringRESET() => this.LoweringRESET?.Invoke(this, EventArgs.Empty);
|
||||
protected virtual void OnLoweringRESET() => LoweringRESET?.Invoke(this, EventArgs.Empty);
|
||||
|
||||
protected virtual void OnLoweredRESET() => this.LoweredRESET?.Invoke(this, EventArgs.Empty);
|
||||
protected virtual void OnLoweredRESET() => LoweredRESET?.Invoke(this, EventArgs.Empty);
|
||||
|
||||
protected virtual void OnRaisingINT() => this.RaisingINT?.Invoke(this, EventArgs.Empty);
|
||||
protected virtual void OnRaisingINT() => RaisingINT?.Invoke(this, EventArgs.Empty);
|
||||
|
||||
protected virtual void OnRaisedINT() => this.RaisedINT?.Invoke(this, EventArgs.Empty);
|
||||
protected virtual void OnRaisedINT() => RaisedINT?.Invoke(this, EventArgs.Empty);
|
||||
|
||||
protected virtual void OnLoweringINT() => this.LoweringINT?.Invoke(this, EventArgs.Empty);
|
||||
protected virtual void OnLoweringINT() => LoweringINT?.Invoke(this, EventArgs.Empty);
|
||||
|
||||
protected virtual void OnLoweredINT() => this.LoweredINT?.Invoke(this, EventArgs.Empty);
|
||||
protected virtual void OnLoweredINT() => LoweredINT?.Invoke(this, EventArgs.Empty);
|
||||
|
||||
protected virtual void HandleRESET() => this.RaiseRESET();
|
||||
protected virtual void HandleRESET() => RaiseRESET();
|
||||
|
||||
protected virtual void HandleINT() => this.RaiseINT();
|
||||
protected virtual void HandleINT() => RaiseINT();
|
||||
|
||||
protected void MemoryWrite(byte low, byte high)
|
||||
{
|
||||
this.Bus.Address.Assign(low, high);
|
||||
this.MemoryWrite();
|
||||
Bus.Address.Assign(low, high);
|
||||
MemoryWrite();
|
||||
}
|
||||
|
||||
protected void MemoryWrite(byte low, byte high, byte data)
|
||||
{
|
||||
this.Bus.Address.Assign(low, high);
|
||||
this.MemoryWrite(data);
|
||||
Bus.Address.Assign(low, high);
|
||||
MemoryWrite(data);
|
||||
}
|
||||
|
||||
protected void MemoryWrite(ushort address, byte data)
|
||||
{
|
||||
this.Bus.Address.Word = address;
|
||||
this.MemoryWrite(data);
|
||||
Bus.Address.Word = address;
|
||||
MemoryWrite(data);
|
||||
}
|
||||
|
||||
protected void MemoryWrite(Register16 address, byte data) => this.MemoryWrite(address.Low, address.High, data);
|
||||
protected void MemoryWrite(Register16 address, byte data) => MemoryWrite(address.Low, address.High, data);
|
||||
|
||||
protected void MemoryWrite(Register16 address) => this.MemoryWrite(address.Low, address.High);
|
||||
protected void MemoryWrite(Register16 address) => MemoryWrite(address.Low, address.High);
|
||||
|
||||
protected void MemoryWrite(byte data)
|
||||
{
|
||||
this.Bus.Data = data;
|
||||
this.MemoryWrite();
|
||||
Bus.Data = data;
|
||||
MemoryWrite();
|
||||
}
|
||||
|
||||
protected virtual void MemoryWrite() => this.BusWrite();
|
||||
protected virtual void MemoryWrite() => BusWrite();
|
||||
|
||||
protected virtual void BusWrite() => this.Bus.Write(); // N.B. Should be the only real call into the "Bus.Write" code.
|
||||
protected virtual void BusWrite() => Bus.Write(); // N.B. Should be the only real call into the "Bus.Write" code.
|
||||
|
||||
protected byte MemoryRead(byte low, byte high)
|
||||
{
|
||||
this.Bus.Address.Assign(low, high);
|
||||
return this.MemoryRead();
|
||||
Bus.Address.Assign(low, high);
|
||||
return MemoryRead();
|
||||
}
|
||||
|
||||
protected byte MemoryRead(ushort address)
|
||||
{
|
||||
this.Bus.Address.Word = address;
|
||||
return this.MemoryRead();
|
||||
Bus.Address.Word = address;
|
||||
return MemoryRead();
|
||||
}
|
||||
|
||||
protected byte MemoryRead(Register16 address) => this.MemoryRead(address.Low, address.High);
|
||||
protected byte MemoryRead(Register16 address) => MemoryRead(address.Low, address.High);
|
||||
|
||||
protected virtual byte MemoryRead() => this.BusRead();
|
||||
protected virtual byte MemoryRead() => BusRead();
|
||||
|
||||
protected virtual byte BusRead() => this.Bus.Read(); // N.B. Should be the only real call into the "Bus.Read" code.
|
||||
protected virtual byte BusRead() => Bus.Read(); // N.B. Should be the only real call into the "Bus.Read" code.
|
||||
|
||||
protected virtual byte FetchByte()
|
||||
{
|
||||
this.Bus.Address.Assign(this.PC);
|
||||
this.PC.Word++;
|
||||
return this.MemoryRead();
|
||||
Bus.Address.Assign(PC);
|
||||
PC.Word++;
|
||||
return MemoryRead();
|
||||
}
|
||||
|
||||
protected abstract Register16 GetWord();
|
||||
@ -223,34 +223,34 @@ namespace EightBit
|
||||
|
||||
protected Register16 GetWordPaged(Register16 address)
|
||||
{
|
||||
return this.GetWordPaged(address.High, address.Low);
|
||||
return GetWordPaged(address.High, address.Low);
|
||||
}
|
||||
|
||||
protected Register16 GetWordPaged(byte page, byte offset)
|
||||
{
|
||||
this.Bus.Address.Assign(offset, page);
|
||||
return this.GetWordPaged();
|
||||
Bus.Address.Assign(offset, page);
|
||||
return GetWordPaged();
|
||||
}
|
||||
|
||||
protected abstract void SetWordPaged(Register16 value);
|
||||
|
||||
protected void SetWordPaged(Register16 address, Register16 value)
|
||||
{
|
||||
this.SetWordPaged(address.High, address.Low, value);
|
||||
SetWordPaged(address.High, address.Low, value);
|
||||
}
|
||||
|
||||
protected void SetWordPaged(byte page, byte offset, Register16 value)
|
||||
{
|
||||
this.Bus.Address.Assign(offset, page);
|
||||
this.SetWordPaged(value);
|
||||
Bus.Address.Assign(offset, page);
|
||||
SetWordPaged(value);
|
||||
}
|
||||
|
||||
protected abstract Register16 FetchWord();
|
||||
|
||||
protected void FetchWordAddress()
|
||||
{
|
||||
this.FetchWord();
|
||||
this.Bus.Address.Assign(this.Intermediate);
|
||||
FetchWord();
|
||||
Bus.Address.Assign(Intermediate);
|
||||
}
|
||||
|
||||
protected abstract void Push(byte value);
|
||||
@ -263,47 +263,47 @@ namespace EightBit
|
||||
|
||||
protected Register16 GetWord(ushort address)
|
||||
{
|
||||
this.Bus.Address.Word = address;
|
||||
return this.GetWord();
|
||||
Bus.Address.Word = address;
|
||||
return GetWord();
|
||||
}
|
||||
|
||||
protected Register16 GetWord(Register16 address)
|
||||
{
|
||||
this.Bus.Address.Assign(address);
|
||||
return this.GetWord();
|
||||
Bus.Address.Assign(address);
|
||||
return GetWord();
|
||||
}
|
||||
|
||||
protected void SetWord(ushort address, Register16 value)
|
||||
{
|
||||
this.Bus.Address.Word = address;
|
||||
this.SetWord(value);
|
||||
Bus.Address.Word = address;
|
||||
SetWord(value);
|
||||
}
|
||||
|
||||
protected void SetWord(Register16 address, Register16 value)
|
||||
{
|
||||
this.Bus.Address.Assign(address);
|
||||
this.SetWord(value);
|
||||
Bus.Address.Assign(address);
|
||||
SetWord(value);
|
||||
}
|
||||
|
||||
protected void Jump(ushort destination) => this.PC.Word = destination;
|
||||
protected void Jump(ushort destination) => PC.Word = destination;
|
||||
|
||||
protected void Jump(Register16 destination)
|
||||
{
|
||||
this.PC.Assign(destination);
|
||||
PC.Assign(destination);
|
||||
}
|
||||
|
||||
protected void Call(ushort destination)
|
||||
{
|
||||
this.Intermediate.Word = destination;
|
||||
this.Call(this.Intermediate);
|
||||
Intermediate.Word = destination;
|
||||
Call(Intermediate);
|
||||
}
|
||||
|
||||
protected virtual void Call(Register16 destination)
|
||||
{
|
||||
this.PushWord(this.PC);
|
||||
this.Jump(destination);
|
||||
PushWord(PC);
|
||||
Jump(destination);
|
||||
}
|
||||
|
||||
protected virtual void Return() => this.Jump(this.PopWord());
|
||||
protected virtual void Return() => Jump(PopWord());
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ namespace EightBit
|
||||
{
|
||||
}
|
||||
|
||||
public override sealed ref byte Reference(ushort address) => ref this.Bytes()[address];
|
||||
public override sealed ref byte Reference(ushort address) => ref Bytes()[address];
|
||||
|
||||
public new void Poke(ushort address, byte value) => base.Poke(address, value);
|
||||
}
|
||||
|
@ -9,19 +9,19 @@ namespace EightBit
|
||||
[DebuggerDisplay("Word = {Word}")]
|
||||
public sealed class Register16
|
||||
{
|
||||
private byte low;
|
||||
private byte high;
|
||||
private byte _low;
|
||||
private byte _high;
|
||||
|
||||
public Register16(byte low, byte high)
|
||||
{
|
||||
this.Low = low;
|
||||
this.High = high;
|
||||
Low = low;
|
||||
High = high;
|
||||
}
|
||||
|
||||
public Register16(ushort value)
|
||||
{
|
||||
this.Low = Chip.LowByte(value);
|
||||
this.High = Chip.HighByte(value);
|
||||
Low = Chip.LowByte(value);
|
||||
High = Chip.HighByte(value);
|
||||
}
|
||||
|
||||
public Register16()
|
||||
@ -46,30 +46,30 @@ namespace EightBit
|
||||
|
||||
public Register16(Register16 rhs)
|
||||
{
|
||||
this.Low = rhs.Low;
|
||||
this.High = rhs.High;
|
||||
Low = rhs.Low;
|
||||
High = rhs.High;
|
||||
}
|
||||
|
||||
public ushort Word
|
||||
{
|
||||
get => Chip.MakeWord(this.Low, this.High);
|
||||
get => Chip.MakeWord(Low, High);
|
||||
|
||||
set
|
||||
{
|
||||
this.Low = Chip.LowByte(value);
|
||||
this.High = Chip.HighByte(value);
|
||||
Low = Chip.LowByte(value);
|
||||
High = Chip.HighByte(value);
|
||||
}
|
||||
}
|
||||
|
||||
public ref byte Low => ref this.low;
|
||||
public ref byte Low => ref _low;
|
||||
|
||||
public ref byte High => ref this.high;
|
||||
public ref byte High => ref _high;
|
||||
|
||||
public static bool operator ==(Register16 left, Register16 right) => left.Equals(right);
|
||||
|
||||
public static bool operator !=(Register16 left, Register16 right) => !(left == right);
|
||||
|
||||
public override int GetHashCode() => this.Word;
|
||||
public override int GetHashCode() => Word;
|
||||
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
@ -88,18 +88,18 @@ namespace EightBit
|
||||
return false;
|
||||
}
|
||||
|
||||
return rhs.Low == this.Low && rhs.High == this.High;
|
||||
return rhs.Low == Low && rhs.High == High;
|
||||
}
|
||||
|
||||
public void Assign(byte low, byte high)
|
||||
{
|
||||
this.low = low;
|
||||
this.high = high;
|
||||
_low = low;
|
||||
_high = high;
|
||||
}
|
||||
|
||||
public void Assign(Register16 from)
|
||||
{
|
||||
this.Assign(from.low, from.high);
|
||||
Assign(from._low, from._high);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,9 +9,9 @@ namespace EightBit
|
||||
|
||||
public class Rom(int size = 0) : Memory
|
||||
{
|
||||
private byte[] bytes = new byte[size];
|
||||
private byte[] _bytes = new byte[size];
|
||||
|
||||
public override int Size => this.bytes.Length;
|
||||
public override int Size => _bytes.Length;
|
||||
|
||||
public static int Load(Stream file, ref byte[] output, int writeOffset = 0, int readOffset = 0, int limit = -1, int maximumSize = -1)
|
||||
{
|
||||
@ -52,40 +52,40 @@ namespace EightBit
|
||||
|
||||
public override int Load(FileStream file, int writeOffset = 0, int readOffset = 0, int limit = -1)
|
||||
{
|
||||
var maximumSize = this.Size - writeOffset;
|
||||
return Load(file, ref this.Bytes(), writeOffset, readOffset, limit, maximumSize);
|
||||
var maximumSize = Size - writeOffset;
|
||||
return Load(file, ref Bytes(), writeOffset, readOffset, limit, maximumSize);
|
||||
}
|
||||
|
||||
public override int Load(string path, int writeOffset = 0, int readOffset = 0, int limit = -1)
|
||||
{
|
||||
var maximumSize = this.Size - writeOffset;
|
||||
return Load(path, ref this.Bytes(), writeOffset, readOffset, limit, maximumSize);
|
||||
var maximumSize = Size - writeOffset;
|
||||
return Load(path, ref Bytes(), writeOffset, readOffset, limit, maximumSize);
|
||||
}
|
||||
|
||||
public override int Load(byte[] from, int writeOffset = 0, int readOffset = 0, int limit = -1)
|
||||
{
|
||||
if (limit < 0)
|
||||
{
|
||||
limit = Math.Min(from.Length, this.Size - readOffset);
|
||||
limit = Math.Min(from.Length, Size - readOffset);
|
||||
}
|
||||
|
||||
var extent = limit + writeOffset;
|
||||
if (this.Size < extent)
|
||||
if (Size < extent)
|
||||
{
|
||||
var updated = new byte[extent];
|
||||
Array.Copy(this.Bytes(), updated, this.Size);
|
||||
this.Bytes() = updated;
|
||||
Array.Copy(Bytes(), updated, Size);
|
||||
Bytes() = updated;
|
||||
}
|
||||
|
||||
Array.Copy(from, readOffset, this.Bytes(), writeOffset, limit);
|
||||
Array.Copy(from, readOffset, Bytes(), writeOffset, limit);
|
||||
|
||||
return limit;
|
||||
}
|
||||
|
||||
public override byte Peek(ushort address) => this.Bytes()[address];
|
||||
public override byte Peek(ushort address) => Bytes()[address];
|
||||
|
||||
protected ref byte[] Bytes() => ref this.bytes;
|
||||
protected ref byte[] Bytes() => ref _bytes;
|
||||
|
||||
protected override void Poke(ushort address, byte value) => this.Bytes()[address] = value;
|
||||
protected override void Poke(ushort address, byte value) => Bytes()[address] = value;
|
||||
}
|
||||
}
|
||||
|
@ -8,10 +8,10 @@ namespace EightBit
|
||||
|
||||
public class UnusedMemory(int size, byte unchanging) : Memory
|
||||
{
|
||||
private readonly int size = size;
|
||||
private readonly byte unchanging = unchanging;
|
||||
private readonly int _size = size;
|
||||
private readonly byte _unchanging = unchanging;
|
||||
|
||||
public override int Size => this.size;
|
||||
public override int Size => _size;
|
||||
|
||||
public override int Load(FileStream file, int writeOffset = 0, int readOffset = 0, int limit = -1) => throw new System.NotImplementedException();
|
||||
|
||||
@ -19,7 +19,7 @@ namespace EightBit
|
||||
|
||||
public override int Load(byte[] from, int writeOffset = 0, int readOffset = 0, int limit = -1) => throw new System.NotImplementedException();
|
||||
|
||||
public override byte Peek(ushort address) => this.unchanging;
|
||||
public override byte Peek(ushort address) => _unchanging;
|
||||
|
||||
protected override void Poke(ushort address, byte value) => throw new System.NotImplementedException();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user