From 726c3fe4cc7860ce9e480f873251989fce4ee7b2 Mon Sep 17 00:00:00 2001 From: Adrian Conlon Date: Thu, 21 Feb 2019 22:52:46 +0000 Subject: [PATCH] More work on minimising the effect of creating garbage collected objects. Signed-off-by: Adrian Conlon --- EightBit/BigEndianProcessor.cs | 32 ++++++++++++++++--------------- EightBit/LittleEndianProcessor.cs | 32 ++++++++++++++++--------------- 2 files changed, 34 insertions(+), 30 deletions(-) diff --git a/EightBit/BigEndianProcessor.cs b/EightBit/BigEndianProcessor.cs index de3be89..0fd5766 100644 --- a/EightBit/BigEndianProcessor.cs +++ b/EightBit/BigEndianProcessor.cs @@ -5,6 +5,8 @@ namespace EightBit { public abstract class BigEndianProcessor : Processor { + private readonly Register16 intermediate = new Register16(); + protected BigEndianProcessor(Bus memory) : base(memory) { @@ -12,9 +14,9 @@ namespace EightBit public override Register16 PeekWord(ushort address) { - var high = this.Bus.Peek(address); - var low = this.Bus.Peek(++address); - return new Register16(low, high); + 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) @@ -25,31 +27,31 @@ namespace EightBit protected override Register16 FetchWord() { - var high = this.FetchByte(); - var low = this.FetchByte(); - return new Register16(low, high); + this.intermediate.High = this.FetchByte(); + this.intermediate.Low = this.FetchByte(); + return this.intermediate; } protected override Register16 GetWord() { - var high = this.BusRead(); + this.intermediate.High = this.BusRead(); ++this.Bus.Address.Word; - var low = this.BusRead(); - return new Register16(low, high); + this.intermediate.Low = this.BusRead(); + return this.intermediate; } protected override Register16 GetWordPaged(byte page, byte offset) { - var high = this.BusRead(offset, page); - var low = this.BusRead(++offset, page); - return new Register16(low, high); + this.intermediate.High = this.BusRead(offset, page); + this.intermediate.Low = this.BusRead(++offset, page); + return this.intermediate; } protected override Register16 PopWord() { - var high = this.Pop(); - var low = this.Pop(); - return new Register16(low, high); + this.intermediate.High = this.Pop(); + this.intermediate.Low = this.Pop(); + return this.intermediate; } protected override void PushWord(Register16 value) diff --git a/EightBit/LittleEndianProcessor.cs b/EightBit/LittleEndianProcessor.cs index f8e9f38..c8a68ce 100644 --- a/EightBit/LittleEndianProcessor.cs +++ b/EightBit/LittleEndianProcessor.cs @@ -6,6 +6,8 @@ namespace EightBit { public abstract class LittleEndianProcessor : Processor { + private readonly Register16 intermediate = new Register16(); + protected LittleEndianProcessor(Bus memory) : base(memory) { @@ -13,9 +15,9 @@ namespace EightBit public override Register16 PeekWord(ushort address) { - var low = this.Bus.Peek(address); - var high = this.Bus.Peek(++address); - return new Register16(low, high); + 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) @@ -26,31 +28,31 @@ namespace EightBit protected override Register16 FetchWord() { - var low = this.FetchByte(); - var high = this.FetchByte(); - return new Register16(low, high); + this.intermediate.Low = this.FetchByte(); + this.intermediate.High = this.FetchByte(); + return this.intermediate; } protected override Register16 GetWord() { - var low = this.BusRead(); + this.intermediate.Low = this.BusRead(); ++this.Bus.Address.Word; - var high = this.BusRead(); - return new Register16(low, high); + this.intermediate.High = this.BusRead(); + return this.intermediate; } protected override Register16 GetWordPaged(byte page, byte offset) { - var low = this.BusRead(offset, page); - var high = this.BusRead(++offset, page); - return new Register16(low, high); + this.intermediate.Low = this.BusRead(offset, page); + this.intermediate.High = this.BusRead(++offset, page); + return this.intermediate; } protected override Register16 PopWord() { - var low = this.Pop(); - var high = this.Pop(); - return new Register16(low, high); + this.intermediate.Low = this.Pop(); + this.intermediate.High = this.Pop(); + return this.intermediate; } protected override void PushWord(Register16 value)