More work on minimising the effect of creating garbage collected objects.

Signed-off-by: Adrian Conlon <Adrian.conlon@gmail.com>
This commit is contained in:
Adrian Conlon 2019-02-21 22:52:46 +00:00
parent 968b1c6545
commit 726c3fe4cc
2 changed files with 34 additions and 30 deletions

View File

@ -5,6 +5,8 @@ namespace EightBit
{ {
public abstract class BigEndianProcessor : Processor public abstract class BigEndianProcessor : Processor
{ {
private readonly Register16 intermediate = new Register16();
protected BigEndianProcessor(Bus memory) protected BigEndianProcessor(Bus memory)
: base(memory) : base(memory)
{ {
@ -12,9 +14,9 @@ namespace EightBit
public override Register16 PeekWord(ushort address) public override Register16 PeekWord(ushort address)
{ {
var high = this.Bus.Peek(address); this.intermediate.High = this.Bus.Peek(address);
var low = this.Bus.Peek(++address); this.intermediate.Low = this.Bus.Peek(++address);
return new Register16(low, high); return this.intermediate;
} }
public override void PokeWord(ushort address, Register16 value) public override void PokeWord(ushort address, Register16 value)
@ -25,31 +27,31 @@ namespace EightBit
protected override Register16 FetchWord() protected override Register16 FetchWord()
{ {
var high = this.FetchByte(); this.intermediate.High = this.FetchByte();
var low = this.FetchByte(); this.intermediate.Low = this.FetchByte();
return new Register16(low, high); return this.intermediate;
} }
protected override Register16 GetWord() protected override Register16 GetWord()
{ {
var high = this.BusRead(); this.intermediate.High = this.BusRead();
++this.Bus.Address.Word; ++this.Bus.Address.Word;
var low = this.BusRead(); this.intermediate.Low = this.BusRead();
return new Register16(low, high); return this.intermediate;
} }
protected override Register16 GetWordPaged(byte page, byte offset) protected override Register16 GetWordPaged(byte page, byte offset)
{ {
var high = this.BusRead(offset, page); this.intermediate.High = this.BusRead(offset, page);
var low = this.BusRead(++offset, page); this.intermediate.Low = this.BusRead(++offset, page);
return new Register16(low, high); return this.intermediate;
} }
protected override Register16 PopWord() protected override Register16 PopWord()
{ {
var high = this.Pop(); this.intermediate.High = this.Pop();
var low = this.Pop(); this.intermediate.Low = this.Pop();
return new Register16(low, high); return this.intermediate;
} }
protected override void PushWord(Register16 value) protected override void PushWord(Register16 value)

View File

@ -6,6 +6,8 @@ namespace EightBit
{ {
public abstract class LittleEndianProcessor : Processor public abstract class LittleEndianProcessor : Processor
{ {
private readonly Register16 intermediate = new Register16();
protected LittleEndianProcessor(Bus memory) protected LittleEndianProcessor(Bus memory)
: base(memory) : base(memory)
{ {
@ -13,9 +15,9 @@ namespace EightBit
public override Register16 PeekWord(ushort address) public override Register16 PeekWord(ushort address)
{ {
var low = this.Bus.Peek(address); this.intermediate.Low = this.Bus.Peek(address);
var high = this.Bus.Peek(++address); this.intermediate.High = this.Bus.Peek(++address);
return new Register16(low, high); return this.intermediate;
} }
public override void PokeWord(ushort address, Register16 value) public override void PokeWord(ushort address, Register16 value)
@ -26,31 +28,31 @@ namespace EightBit
protected override Register16 FetchWord() protected override Register16 FetchWord()
{ {
var low = this.FetchByte(); this.intermediate.Low = this.FetchByte();
var high = this.FetchByte(); this.intermediate.High = this.FetchByte();
return new Register16(low, high); return this.intermediate;
} }
protected override Register16 GetWord() protected override Register16 GetWord()
{ {
var low = this.BusRead(); this.intermediate.Low = this.BusRead();
++this.Bus.Address.Word; ++this.Bus.Address.Word;
var high = this.BusRead(); this.intermediate.High = this.BusRead();
return new Register16(low, high); return this.intermediate;
} }
protected override Register16 GetWordPaged(byte page, byte offset) protected override Register16 GetWordPaged(byte page, byte offset)
{ {
var low = this.BusRead(offset, page); this.intermediate.Low = this.BusRead(offset, page);
var high = this.BusRead(++offset, page); this.intermediate.High = this.BusRead(++offset, page);
return new Register16(low, high); return this.intermediate;
} }
protected override Register16 PopWord() protected override Register16 PopWord()
{ {
var low = this.Pop(); this.intermediate.Low = this.Pop();
var high = this.Pop(); this.intermediate.High = this.Pop();
return new Register16(low, high); return this.intermediate;
} }
protected override void PushWord(Register16 value) protected override void PushWord(Register16 value)