mirror of
https://github.com/MoleskiCoder/EightBitNet.git
synced 2026-01-22 16:16:17 +00:00
Rationalise use of "intermediate" Register16
This commit is contained in:
@@ -5,13 +5,11 @@ namespace EightBit
|
||||
{
|
||||
public abstract class BigEndianProcessor(Bus memory) : Processor(memory)
|
||||
{
|
||||
private readonly Register16 intermediate = new();
|
||||
|
||||
public override Register16 PeekWord(ushort address)
|
||||
{
|
||||
this.intermediate.High = this.Bus.Peek(address);
|
||||
this.intermediate.Low = this.Bus.Peek(++address);
|
||||
return this.intermediate;
|
||||
this.Intermediate.High = this.Bus.Peek(address);
|
||||
this.Intermediate.Low = this.Bus.Peek(++address);
|
||||
return this.Intermediate;
|
||||
}
|
||||
|
||||
public override void PokeWord(ushort address, Register16 value)
|
||||
@@ -22,32 +20,32 @@ namespace EightBit
|
||||
|
||||
protected override Register16 FetchWord()
|
||||
{
|
||||
this.intermediate.High = this.FetchByte();
|
||||
this.intermediate.Low = this.FetchByte();
|
||||
return this.intermediate;
|
||||
this.Intermediate.High = this.FetchByte();
|
||||
this.Intermediate.Low = this.FetchByte();
|
||||
return this.Intermediate;
|
||||
}
|
||||
|
||||
protected override Register16 GetWord()
|
||||
{
|
||||
this.intermediate.High = this.MemoryRead();
|
||||
this.Intermediate.High = this.MemoryRead();
|
||||
++this.Bus.Address.Word;
|
||||
this.intermediate.Low = this.MemoryRead();
|
||||
return this.intermediate;
|
||||
this.Intermediate.Low = this.MemoryRead();
|
||||
return this.Intermediate;
|
||||
}
|
||||
|
||||
protected override Register16 GetWordPaged()
|
||||
{
|
||||
this.intermediate.High = this.MemoryRead();
|
||||
this.Intermediate.High = this.MemoryRead();
|
||||
++this.Bus.Address.Low;
|
||||
this.intermediate.Low = this.MemoryRead();
|
||||
return this.intermediate;
|
||||
this.Intermediate.Low = this.MemoryRead();
|
||||
return this.Intermediate;
|
||||
}
|
||||
|
||||
protected override Register16 PopWord()
|
||||
{
|
||||
this.intermediate.High = this.Pop();
|
||||
this.intermediate.Low = this.Pop();
|
||||
return this.intermediate;
|
||||
this.Intermediate.High = this.Pop();
|
||||
this.Intermediate.Low = this.Pop();
|
||||
return this.Intermediate;
|
||||
}
|
||||
|
||||
protected override void PushWord(Register16 value)
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace EightBit
|
||||
|
||||
public byte Data { get => this.data; set => this.data = value; }
|
||||
|
||||
public Register16 Address { get; } = new Register16();
|
||||
public Register16 Address { get; } = new();
|
||||
|
||||
public abstract MemoryMapping Mapping(ushort absolute);
|
||||
|
||||
@@ -30,16 +30,12 @@ namespace EightBit
|
||||
|
||||
public byte Peek(Register16 absolute) => this.Peek(absolute.Word);
|
||||
|
||||
public byte Peek(byte low, byte high) => this.Reference(low, high);
|
||||
|
||||
public void Poke(byte value) => this.Reference() = value;
|
||||
|
||||
public void Poke(ushort absolute, byte value) => this.Reference(absolute) = value;
|
||||
|
||||
public void Poke(Register16 absolute, byte value) => this.Poke(absolute.Word, value);
|
||||
|
||||
public void Poke(byte low, byte high, byte value) => this.Reference(low, high) = value;
|
||||
|
||||
public byte Read()
|
||||
{
|
||||
this.OnReadingByte();
|
||||
@@ -127,8 +123,6 @@ namespace EightBit
|
||||
|
||||
protected ref byte Reference() => ref this.Reference(this.Address);
|
||||
|
||||
protected ref byte Reference(byte low, byte high) => ref this.Reference(new Register16(low, high).Word);
|
||||
|
||||
protected void LoadHexFile(string path)
|
||||
{
|
||||
using var file = new IntelHexFile(path);
|
||||
|
||||
@@ -6,13 +6,11 @@ namespace EightBit
|
||||
{
|
||||
public abstract class LittleEndianProcessor(Bus memory) : Processor(memory)
|
||||
{
|
||||
private readonly Register16 intermediate = new();
|
||||
|
||||
public override Register16 PeekWord(ushort address)
|
||||
{
|
||||
this.intermediate.Low = this.Bus.Peek(address);
|
||||
this.intermediate.High = this.Bus.Peek(++address);
|
||||
return this.intermediate;
|
||||
this.Intermediate.Low = this.Bus.Peek(address);
|
||||
this.Intermediate.High = this.Bus.Peek(++address);
|
||||
return this.Intermediate;
|
||||
}
|
||||
|
||||
public override void PokeWord(ushort address, Register16 value)
|
||||
@@ -23,32 +21,32 @@ namespace EightBit
|
||||
|
||||
protected override Register16 FetchWord()
|
||||
{
|
||||
this.intermediate.Low = this.FetchByte();
|
||||
this.intermediate.High = this.FetchByte();
|
||||
return this.intermediate;
|
||||
this.Intermediate.Low = this.FetchByte();
|
||||
this.Intermediate.High = this.FetchByte();
|
||||
return this.Intermediate;
|
||||
}
|
||||
|
||||
protected override Register16 GetWord()
|
||||
{
|
||||
this.intermediate.Low = this.MemoryRead();
|
||||
this.Intermediate.Low = this.MemoryRead();
|
||||
++this.Bus.Address.Word;
|
||||
this.intermediate.High = this.MemoryRead();
|
||||
return this.intermediate;
|
||||
this.Intermediate.High = this.MemoryRead();
|
||||
return this.Intermediate;
|
||||
}
|
||||
|
||||
protected override Register16 GetWordPaged()
|
||||
{
|
||||
this.intermediate.Low = this.MemoryRead();
|
||||
this.Intermediate.Low = this.MemoryRead();
|
||||
++this.Bus.Address.Low;
|
||||
this.intermediate.High = this.MemoryRead();
|
||||
return this.intermediate;
|
||||
this.Intermediate.High = this.MemoryRead();
|
||||
return this.Intermediate;
|
||||
}
|
||||
|
||||
protected override Register16 PopWord()
|
||||
{
|
||||
this.intermediate.Low = this.Pop();
|
||||
this.intermediate.High = this.Pop();
|
||||
return this.intermediate;
|
||||
this.Intermediate.Low = this.Pop();
|
||||
this.Intermediate.High = this.Pop();
|
||||
return this.Intermediate;
|
||||
}
|
||||
|
||||
protected override void PushWord(Register16 value)
|
||||
|
||||
@@ -33,7 +33,9 @@ namespace EightBit
|
||||
|
||||
public Bus Bus { get; } = memory;
|
||||
|
||||
public Register16 PC { get; } = new Register16();
|
||||
public Register16 PC { get; } = new();
|
||||
|
||||
public Register16 Intermediate { get; } = new();
|
||||
|
||||
protected byte OpCode { get; set; }
|
||||
|
||||
@@ -194,7 +196,8 @@ namespace EightBit
|
||||
|
||||
protected Register16 GetWordPaged(byte page, byte offset)
|
||||
{
|
||||
this.Bus.Address.Word = new Register16(offset, page).Word;
|
||||
this.Bus.Address.Low = offset;
|
||||
this.Bus.Address.High = page;
|
||||
return this.GetWordPaged();
|
||||
}
|
||||
|
||||
@@ -208,7 +211,8 @@ namespace EightBit
|
||||
|
||||
protected void SetWordPaged(byte page, byte offset, Register16 value)
|
||||
{
|
||||
this.Bus.Address.Word = new Register16(offset, page).Word;
|
||||
this.Bus.Address.Low = offset;
|
||||
this.Bus.Address.High = page;
|
||||
this.SetWordPaged(value);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user