From 27e1c5c9f827ab31224fbc3c293ec0d548e5a787 Mon Sep 17 00:00:00 2001 From: Adrian Conlon Date: Thu, 21 Feb 2019 19:58:49 +0000 Subject: [PATCH] Make Register16 a class, rather than struct. Tricky, but a bit faster than before. Signed-off-by: Adrian Conlon --- EightBit/BigEndianProcessor.cs | 4 +- EightBit/Bus.cs | 17 +- EightBit/IntelProcessor.cs | 94 ++-- EightBit/LittleEndianProcessor.cs | 4 +- EightBit/Processor.cs | 27 +- EightBit/Ram.cs | 7 +- EightBit/Register16.cs | 18 +- M6502/Disassembler.cs | 4 +- M6502/M6502.Test/Board.cs | 4 +- M6502/M6502.cs | 36 +- Z80/Disassembler.cs | 28 +- Z80/RefreshRegister.cs | 6 +- Z80/Z80.Test/Board.cs | 8 +- Z80/Z80.Test/Program.cs | 1 + Z80/Z80.cs | 716 +++++++++++++++--------------- 15 files changed, 502 insertions(+), 472 deletions(-) diff --git a/EightBit/BigEndianProcessor.cs b/EightBit/BigEndianProcessor.cs index 99390f3..de3be89 100644 --- a/EightBit/BigEndianProcessor.cs +++ b/EightBit/BigEndianProcessor.cs @@ -33,7 +33,7 @@ namespace EightBit protected override Register16 GetWord() { var high = this.BusRead(); - ++this.Bus.Address(); + ++this.Bus.Address.Word; var low = this.BusRead(); return new Register16(low, high); } @@ -61,7 +61,7 @@ namespace EightBit protected override void SetWord(Register16 value) { this.BusWrite(value.High); - ++this.Bus.Address(); + ++this.Bus.Address.Word; this.BusWrite(value.Low); } diff --git a/EightBit/Bus.cs b/EightBit/Bus.cs index 4a91db7..3fecdb8 100644 --- a/EightBit/Bus.cs +++ b/EightBit/Bus.cs @@ -8,7 +8,6 @@ namespace EightBit public abstract class Bus : IMapper { - private Register16 address; private byte data; public event EventHandler WritingByte; @@ -21,7 +20,7 @@ namespace EightBit public byte Data { get => this.data; set => this.data = value; } - public ref Register16 Address() => ref this.address; + public Register16 Address { get; } = new Register16(); public abstract MemoryMapping Mapping(ushort absolute); @@ -51,7 +50,7 @@ namespace EightBit public byte Read(ushort absolute) { - this.Address().Word = absolute; + this.Address.Word = absolute; return this.Read(); } @@ -59,8 +58,8 @@ namespace EightBit public byte Read(byte low, byte high) { - this.Address().Low = low; - this.Address().High = high; + this.Address.Low = low; + this.Address.High = high; return this.Read(); } @@ -79,7 +78,7 @@ namespace EightBit public void Write(ushort absolute, byte value) { - this.Address().Word = absolute; + this.Address.Word = absolute; this.Write(value); } @@ -87,8 +86,8 @@ namespace EightBit public void Write(byte low, byte high, byte value) { - this.Address().Low = low; - this.Address().High = high; + this.Address.Low = low; + this.Address.High = high; this.Write(value); } @@ -125,7 +124,7 @@ namespace EightBit protected ref byte Reference(Register16 absolute) => ref this.Reference(absolute.Word); - protected ref byte Reference() => ref this.Reference(this.Address()); + 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); diff --git a/EightBit/IntelProcessor.cs b/EightBit/IntelProcessor.cs index a969ee1..a223d34 100644 --- a/EightBit/IntelProcessor.cs +++ b/EightBit/IntelProcessor.cs @@ -13,10 +13,6 @@ namespace EightBit private readonly IntelOpCodeDecoded[] decodedOpCodes = new IntelOpCodeDecoded[0x100]; - private Register16 sp = new Register16((ushort)Mask.Mask16); - - private Register16 memptr = new Register16((ushort)Mask.Mask16); - private PinLevel haltLine; protected IntelProcessor(Bus bus) @@ -36,36 +32,36 @@ namespace EightBit public event EventHandler LoweredHALT; + public Register16 SP { get; } = new Register16((ushort)Mask.Mask16); + + public Register16 MEMPTR { get; } = new Register16((ushort)Mask.Mask16); + + public abstract Register16 AF { get; } + + public byte A { get => this.AF.High; set => this.AF.High = value; } + + public byte F { get => this.AF.Low; set => this.AF.Low = value; } + + public abstract Register16 BC { get; } + + public byte B { get => this.BC.High; set => this.BC.High = value; } + + public byte C { get => this.BC.Low; set => this.BC.Low = value; } + + public abstract Register16 DE { get; } + + public byte D { get => this.DE.High; set => this.DE.High = value; } + + public byte E { get => this.DE.Low; set => this.DE.Low = value; } + + public abstract Register16 HL { get; } + + public byte H { get => this.HL.High; set => this.HL.High = value; } + + public byte L { get => this.HL.Low; set => this.HL.Low = value; } + protected bool Halted => this.HALT().Lowered(); - public ref Register16 SP() => ref this.sp; - - public ref Register16 MEMPTR() => ref this.memptr; - - public abstract ref Register16 AF(); - - public ref byte A() => ref this.AF().High; - - public ref byte F() => ref this.AF().Low; - - public abstract ref Register16 BC(); - - public ref byte B() => ref this.BC().High; - - public ref byte C() => ref this.BC().Low; - - public abstract ref Register16 DE(); - - public ref byte D() => ref this.DE().High; - - public ref byte E() => ref this.DE().Low; - - public abstract ref Register16 HL(); - - public ref byte H() => ref this.HL().High; - - public ref byte L() => ref this.HL().Low; - public ref PinLevel HALT() => ref this.haltLine; public IntelOpCodeDecoded GetDecodedOpCode(byte opCode) => this.decodedOpCodes[opCode]; @@ -74,7 +70,7 @@ namespace EightBit { base.RaisePOWER(); this.RaiseHALT(); - this.SP().Word = this.AF().Word = this.BC().Word = this.DE().Word = this.HL().Word = (ushort)Mask.Mask16; + this.SP.Word = this.AF.Word = this.BC.Word = this.DE.Word = this.HL.Word = (ushort)Mask.Mask16; } public virtual void RaiseHALT() @@ -122,38 +118,38 @@ namespace EightBit this.Jump(0); } - protected sealed override void Push(byte value) => this.Bus.Write(--this.SP(), value); + protected sealed override void Push(byte value) => this.Bus.Write(--this.SP.Word, value); - protected sealed override byte Pop() => this.Bus.Read(this.SP()++); + protected sealed override byte Pop() => this.Bus.Read(this.SP.Word++); protected sealed override Register16 GetWord() { var returned = base.GetWord(); - this.MEMPTR().Word = this.Bus.Address().Word; + this.MEMPTR.Word = this.Bus.Address.Word; return returned; } protected sealed override void SetWord(Register16 value) { base.SetWord(value); - this.MEMPTR().Word = this.Bus.Address().Word; + this.MEMPTR.Word = this.Bus.Address.Word; } //// protected void Restart(byte address) { - this.MEMPTR().Low = address; - this.MEMPTR().High = 0; - this.Call(this.MEMPTR()); + this.MEMPTR.Low = address; + this.MEMPTR.High = 0; + this.Call(this.MEMPTR); } protected bool CallConditional(bool condition) { - this.MEMPTR().Word = this.FetchWord().Word; + this.MEMPTR.Word = this.FetchWord().Word; if (condition) { - this.Call(this.MEMPTR()); + this.Call(this.MEMPTR); } return condition; @@ -161,10 +157,10 @@ namespace EightBit protected bool JumpConditional(bool condition) { - this.MEMPTR().Word = this.FetchWord().Word; + this.MEMPTR.Word = this.FetchWord().Word; if (condition) { - this.Jump(this.MEMPTR()); + this.Jump(this.MEMPTR); } return condition; @@ -182,8 +178,8 @@ namespace EightBit protected void JumpRelative(sbyte offset) { - this.MEMPTR().Word = (ushort)(this.PC().Word + offset); - this.Jump(this.MEMPTR()); + this.MEMPTR.Word = (ushort)(this.PC.Word + offset); + this.Jump(this.MEMPTR); } protected bool JumpRelativeConditional(bool condition) @@ -200,18 +196,18 @@ namespace EightBit protected override sealed void Return() { base.Return(); - this.MEMPTR().Word = this.PC().Word; + this.MEMPTR.Word = this.PC.Word; } protected void Halt() { - --this.PC(); + --this.PC.Word; this.LowerHALT(); } protected void Proceed() { - ++this.PC(); + ++this.PC.Word; this.RaiseHALT(); } } diff --git a/EightBit/LittleEndianProcessor.cs b/EightBit/LittleEndianProcessor.cs index 073d154..f8e9f38 100644 --- a/EightBit/LittleEndianProcessor.cs +++ b/EightBit/LittleEndianProcessor.cs @@ -34,7 +34,7 @@ namespace EightBit protected override Register16 GetWord() { var low = this.BusRead(); - ++this.Bus.Address(); + ++this.Bus.Address.Word; var high = this.BusRead(); return new Register16(low, high); } @@ -62,7 +62,7 @@ namespace EightBit protected override void SetWord(Register16 value) { this.BusWrite(value.Low); - ++this.Bus.Address(); + ++this.Bus.Address.Word; this.BusWrite(value.High); } diff --git a/EightBit/Processor.cs b/EightBit/Processor.cs index 4cd929d..0eb9ddb 100644 --- a/EightBit/Processor.cs +++ b/EightBit/Processor.cs @@ -10,7 +10,6 @@ namespace EightBit { private PinLevel resetLine; private PinLevel intLine; - private Register16 pc; protected Processor(Bus memory) { @@ -35,9 +34,9 @@ namespace EightBit public Bus Bus { get; } - protected byte OpCode { get; set; } + public Register16 PC { get; } = new Register16(); - public ref Register16 PC() => ref this.pc; + protected byte OpCode { get; set; } public ref PinLevel RESET() => ref this.resetLine; @@ -118,14 +117,14 @@ namespace EightBit protected void BusWrite(byte low, byte high, byte data) { - this.Bus.Address().Low = low; - this.Bus.Address().High = high; + this.Bus.Address.Low = low; + this.Bus.Address.High = high; this.BusWrite(data); } protected void BusWrite(ushort address, byte data) { - this.Bus.Address().Word = address; + this.Bus.Address.Word = address; this.BusWrite(data); } @@ -141,14 +140,14 @@ namespace EightBit protected byte BusRead(byte low, byte high) { - this.Bus.Address().Low = low; - this.Bus.Address().High = high; + this.Bus.Address.Low = low; + this.Bus.Address.High = high; return this.BusRead(); } protected byte BusRead(ushort address) { - this.Bus.Address().Word = address; + this.Bus.Address.Word = address; return this.BusRead(); } @@ -156,7 +155,7 @@ namespace EightBit protected virtual byte BusRead() => this.Bus.Read(); // N.B. Should be the only real call into the "Bus.Read" code. - protected byte FetchByte() => this.BusRead(this.PC()++); + protected byte FetchByte() => this.BusRead(this.PC.Word++); protected abstract Register16 GetWord(); @@ -178,23 +177,23 @@ namespace EightBit protected Register16 GetWord(ushort address) { - this.Bus.Address().Word = address; + this.Bus.Address.Word = address; return this.GetWord(); } protected void SetWord(ushort address, Register16 value) { - this.Bus.Address().Word = address; + this.Bus.Address.Word = address; this.SetWord(value); } - protected void Jump(ushort destination) => this.PC().Word = destination; + protected void Jump(ushort destination) => this.PC.Word = destination; protected void Jump(Register16 destination) => this.Jump(destination.Word); protected void Call(ushort destination) { - this.PushWord(this.PC()); + this.PushWord(this.PC); this.Jump(destination); } diff --git a/EightBit/Ram.cs b/EightBit/Ram.cs index a83e884..2dc36ce 100644 --- a/EightBit/Ram.cs +++ b/EightBit/Ram.cs @@ -6,11 +6,16 @@ namespace EightBit { public class Ram : Rom { - public Ram(int size = 0) + public Ram(int size) : base(size) { } + public Ram() + : this(0) + { + } + public override sealed ref byte Reference(ushort address) => ref this.Bytes()[address]; public new void Poke(ushort address, byte value) => base.Poke(address, value); diff --git a/EightBit/Register16.cs b/EightBit/Register16.cs index ead398d..7391781 100644 --- a/EightBit/Register16.cs +++ b/EightBit/Register16.cs @@ -8,11 +8,8 @@ namespace EightBit using System.Runtime.InteropServices; [DebuggerDisplay("Word = {Word}")] - public struct Register16 + public class Register16 { - public byte Low; - public byte High; - public Register16(byte low, byte high) { this.Low = low; @@ -25,6 +22,11 @@ namespace EightBit this.High = Chip.HighByte(value); } + public Register16() + : this((ushort)0) + { + } + public Register16(int value) : this((ushort)value) { @@ -55,6 +57,10 @@ namespace EightBit } } + public byte Low { get; set; } + + public byte High { get; set; } + public static Register16 operator ++(Register16 value) => Increment(value); public static Register16 operator --(Register16 value) => Decrement(value); @@ -77,12 +83,12 @@ namespace EightBit public override bool Equals(object obj) { - if (!(obj is Register16)) + var rhs = obj as Register16; + if (rhs == null) { return false; } - var rhs = (Register16)obj; return rhs.Low == this.Low && rhs.High == this.High; } diff --git a/M6502/Disassembler.cs b/M6502/Disassembler.cs index d5ce4cb..6e1a4cc 100644 --- a/M6502/Disassembler.cs +++ b/M6502/Disassembler.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) Adrian Conlon. All rights reserved. // @@ -56,7 +56,7 @@ namespace EightBit output.Append(" "); var next = this.bus.Peek((ushort)(current + 1)); - var relative = (ushort)(this.processor.PC().Word + 2 + (sbyte)next); + var relative = (ushort)(this.processor.PC.Word + 2 + (sbyte)next); var aaa = (cell & 0b11100000) >> 5; var bbb = (cell & 0b00011100) >> 2; diff --git a/M6502/M6502.Test/Board.cs b/M6502/M6502.Test/Board.cs index 03ad6fb..2028214 100644 --- a/M6502/M6502.Test/Board.cs +++ b/M6502/M6502.Test/Board.cs @@ -70,7 +70,7 @@ namespace M6502.Test private void CPU_ExecutedInstruction(object sender, System.EventArgs e) { - var pc = this.CPU.PC().Word; + var pc = this.CPU.PC.Word; if (this.oldPC != pc) { this.oldPC = pc; @@ -87,7 +87,7 @@ namespace M6502.Test private void CPU_ExecutingInstruction(object sender, System.EventArgs e) { - var address = this.CPU.PC().Word; + var address = this.CPU.PC.Word; var cell = this.Peek(address); var output = new StringBuilder(); diff --git a/M6502/M6502.cs b/M6502/M6502.cs index fd3e5c0..0c39492 100644 --- a/M6502/M6502.cs +++ b/M6502/M6502.cs @@ -12,7 +12,7 @@ namespace EightBit private const byte RSTvector = 0xfc; // RST vector private const byte NMIvector = 0xfa; // NMI vector - private Register16 intermediate; + private readonly Register16 intermediate = new Register16(); private bool handlingRESET = false; private bool handlingNMI = false; @@ -204,7 +204,7 @@ namespace EightBit case 0x2e: this.BusReadModifyWrite(this.ROL(this.AM_Absolute())); break; // ROL (absolute) case 0x2f: this.RLA(this.AM_Absolute()); break; // *RLA (absolute) - case 0x30: this.Branch(this.Negative); break; // BMI (relative) + case 0x30: this.Branch(this.Negative); break; // BMI (relative) case 0x31: this.A = this.AndR(this.A, this.AM_IndirectIndexedY()); break; // AND (indirect indexed Y) case 0x32: break; case 0x33: this.RLA(this.AM_IndirectIndexedY()); break; // *RLA (indirect indexed Y) @@ -272,7 +272,7 @@ namespace EightBit case 0x6e: this.BusReadModifyWrite(this.ROR(this.AM_Absolute())); break; // ROR (absolute) case 0x6f: this.RRA(this.AM_Absolute()); break; // *RRA (absolute) - case 0x70: this.Branch(this.Overflow); break; // BVS (relative) + case 0x70: this.Branch(this.Overflow); break; // BVS (relative) case 0x71: this.A = this.ADC(this.A, this.AM_IndirectIndexedY()); break; // ADC (indirect indexed Y) case 0x72: break; case 0x73: this.RRA(this.AM_IndirectIndexedY()); break; // *RRA (indirect indexed Y) @@ -340,7 +340,7 @@ namespace EightBit case 0xae: this.X = this.Through(this.AM_Absolute()); break; // LDX (absolute) case 0xaf: this.A = this.X = this.Through(this.AM_Absolute()); break; // *LAX (absolute) - case 0xb0: this.Branch(this.Carry); break; // BCS (relative) + case 0xb0: this.Branch(this.Carry); break; // BCS (relative) case 0xb1: this.A = this.Through(this.AM_IndirectIndexedY()); break; // LDA (indirect indexed Y) case 0xb2: break; case 0xb3: this.A = this.X = this.Through(this.AM_IndirectIndexedY()); break; // *LAX (indirect indexed Y) @@ -407,7 +407,7 @@ namespace EightBit case 0xed: this.A = this.SBC(this.A, this.AM_Absolute()); break; // SBC (absolute) case 0xee: this.BusReadModifyWrite(this.INC(this.AM_Absolute())); break; // *ISB (absolute) - case 0xf0: this.Branch(this.Zero); break; // BEQ (relative) + case 0xf0: this.Branch(this.Zero); break; // BEQ (relative) case 0xf1: this.A = this.SBC(this.A, this.AM_IndirectIndexedY()); break; // SBC (indirect indexed Y) case 0xf2: break; case 0xf3: this.ISB(this.AM_IndirectIndexedY()); break; // *ISB (indirect indexed Y) @@ -443,7 +443,7 @@ namespace EightBit if (this.RDY().Raised()) { this.LowerSYNC(); // Instruction fetch beginning - this.OpCode = this.Bus.Read(this.PC()++); // can't use fetchByte + this.OpCode = this.Bus.Read(this.PC.Word++); // can't use fetchByte if (this.RESET().Lowered()) { this.HandleRESET(); @@ -579,13 +579,13 @@ namespace EightBit var software = !hardware; if (reset) { - this.DummyPush(this.PC().High); - this.DummyPush(this.PC().Low); + this.DummyPush(this.PC.High); + this.DummyPush(this.PC.Low); this.DummyPush(this.P); } else { - this.PushWord(this.PC()); + this.PushWord(this.PC); this.Push((byte)(this.P | (int)(software ? StatusBits.BF : 0))); } @@ -599,8 +599,8 @@ namespace EightBit { this.Tick(); this.Bus.Data = value; - this.Bus.Address().Low = this.S--; - this.Bus.Address().High = 1; + this.Bus.Address.Low = this.S--; + this.Bus.Address.High = 1; } private Register16 Address_Absolute() => this.FetchWord(); @@ -658,7 +658,7 @@ namespace EightBit private ushort Address_relative_byte() { var offset = (sbyte)this.FetchByte(); - this.intermediate.Word = (ushort)(this.PC().Word + offset); + this.intermediate.Word = (ushort)(this.PC.Word + offset); return this.intermediate.Word; } @@ -734,11 +734,11 @@ namespace EightBit if (condition) { this.BusRead(); - var page = this.PC().High; + var page = this.PC.High; this.Jump(destination); - if (this.PC().High != page) + if (this.PC.High != page) { - this.BusRead(this.PC().Low, page); + this.BusRead(this.PC.Low, page); } } } @@ -878,10 +878,10 @@ namespace EightBit { var low = this.FetchByte(); this.BusRead(this.S, 1); // dummy read - this.PushWord(this.PC()); + this.PushWord(this.PC); var high = this.FetchByte(); - this.PC().Low = low; - this.PC().High = high; + this.PC.Low = low; + this.PC.High = high; } private byte LSR(byte value) diff --git a/Z80/Disassembler.cs b/Z80/Disassembler.cs index 3a635d1..5fc27be 100644 --- a/Z80/Disassembler.cs +++ b/Z80/Disassembler.cs @@ -1,4 +1,8 @@ -namespace EightBit +// +// Copyright (c) Adrian Conlon. All rights reserved. +// + +namespace EightBit { using System.Text; @@ -34,20 +38,20 @@ public static string State(Z80 cpu) { - var pc = cpu.PC(); - var sp = cpu.SP(); + var pc = cpu.PC; + var sp = cpu.SP; - var a = cpu.A(); - var f = cpu.F(); + var a = cpu.A; + var f = cpu.F; - var b = cpu.B(); - var c = cpu.C(); + var b = cpu.B; + var c = cpu.C; - var d = cpu.D(); - var e = cpu.E(); + var d = cpu.D; + var e = cpu.E; - var h = cpu.H(); - var l = cpu.L(); + var h = cpu.H; + var l = cpu.L; var i = cpu.IV; var r = cpu.REFRESH(); @@ -67,7 +71,7 @@ public string Disassemble(Z80 cpu) { this.prefixCB = this.prefixDD = this.prefixED = this.prefixFD = false; - return this.Disassemble(cpu, cpu.PC().Word); + return this.Disassemble(cpu, cpu.PC.Word); } private static string CC(int flag) diff --git a/Z80/RefreshRegister.cs b/Z80/RefreshRegister.cs index c8a735c..028ff47 100644 --- a/Z80/RefreshRegister.cs +++ b/Z80/RefreshRegister.cs @@ -1,4 +1,8 @@ -namespace EightBit +// +// Copyright (c) Adrian Conlon. All rights reserved. +// + +namespace EightBit { public struct RefreshRegister { diff --git a/Z80/Z80.Test/Board.cs b/Z80/Z80.Test/Board.cs index 34c183e..d1d14a3 100644 --- a/Z80/Z80.Test/Board.cs +++ b/Z80/Z80.Test/Board.cs @@ -68,13 +68,13 @@ namespace Z80.Test private void BDOS() { - switch (CPU.C()) + switch (CPU.C) { case 0x2: - System.Console.Out.Write(CPU.E().ToString()); + System.Console.Out.Write(CPU.E.ToString()); break; case 0x9: - for (ushort i = CPU.DE().Word; Peek(i) != '$'; ++i) + for (ushort i = CPU.DE.Word; Peek(i) != '$'; ++i) { System.Console.Out.Write((char)Peek(i)); } @@ -85,7 +85,7 @@ namespace Z80.Test private void CPU_ExecutingInstruction_CPM(object sender, System.EventArgs e) { - switch (this.CPU.PC().Word) + switch (this.CPU.PC.Word) { case 0x0: // CP/M warm start if (++this.warmstartCount == 2) diff --git a/Z80/Z80.Test/Program.cs b/Z80/Z80.Test/Program.cs index 9670a44..fd6a877 100644 --- a/Z80/Z80.Test/Program.cs +++ b/Z80/Z80.Test/Program.cs @@ -13,6 +13,7 @@ namespace Z80.Test #if DEBUG configuration.DebugMode = true; #endif + // configuration.DebugMode = true; using (var harness = new TestHarness(configuration)) { diff --git a/Z80/Z80.cs b/Z80/Z80.cs index e44443f..d81492c 100644 --- a/Z80/Z80.cs +++ b/Z80/Z80.cs @@ -10,8 +10,18 @@ namespace EightBit { private readonly InputOutput ports; - private readonly Register16[] accumulatorFlags = new Register16[2]; - private readonly Register16[,] registers = new Register16[2, 3]; + private readonly Register16[] accumulatorFlags = { new Register16(), new Register16() }; + private readonly Register16[,] registers = + { + { + new Register16(), new Register16(), new Register16(), + }, + { + new Register16(0), new Register16(0), new Register16(0), + }, + }; + + private readonly Register16 intermediate = new Register16(); private RefreshRegister refresh = new RefreshRegister(0x7f); @@ -26,10 +36,6 @@ namespace EightBit private int accumulatorFlagsSet = 0; private int registerSet = 0; - - private Register16 ix = new Register16(0xffff); - private Register16 iy = new Register16(0xffff); - private sbyte displacement = 0; private bool displaced = false; @@ -67,35 +73,35 @@ namespace EightBit public bool IFF2 { get; set; } = false; + public override Register16 AF => this.accumulatorFlags[this.accumulatorFlagsSet]; + + public override Register16 BC => this.registers[this.registerSet, (int)RegisterIndex.IndexBC]; + + public override Register16 DE => this.registers[this.registerSet, (int)RegisterIndex.IndexDE]; + + public override Register16 HL => this.registers[this.registerSet, (int)RegisterIndex.IndexHL]; + + public Register16 IX { get; } = new Register16(0xffff); + + public byte IXH { get => this.IX.High; set => this.IX.High = value; } + + public byte IXL { get => this.IX.Low; set => this.IX.Low = value; } + + public Register16 IY { get; } = new Register16(0xffff); + + public byte IYH { get => this.IY.High; set => this.IY.High = value; } + + public byte IYL { get => this.IY.Low; set => this.IY.Low = value; } + private ushort DisplacedAddress { get { - var returned = (this.prefixDD ? this.IX() : this.IY()).Word + this.displacement; - return this.MEMPTR().Word = (ushort)returned; + var returned = (this.prefixDD ? this.IX : this.IY).Word + this.displacement; + return this.MEMPTR.Word = (ushort)returned; } } - public override ref Register16 AF() => ref this.accumulatorFlags[this.accumulatorFlagsSet]; - - public override ref Register16 BC() => ref this.registers[this.registerSet, (int)RegisterIndex.IndexBC]; - - public override ref Register16 DE() => ref this.registers[this.registerSet, (int)RegisterIndex.IndexDE]; - - public override ref Register16 HL() => ref this.registers[this.registerSet, (int)RegisterIndex.IndexHL]; - - public ref Register16 IX() => ref this.ix; - - public ref byte IXH() => ref this.IX().High; - - public ref byte IXL() => ref this.IX().Low; - - public ref Register16 IY() => ref this.iy; - - public ref byte IYH() => ref this.IY().High; - - public ref byte IYL() => ref this.IY().Low; - public ref RefreshRegister REFRESH() => ref this.refresh; public ref PinLevel NMI() => ref this.nmiLine; @@ -119,10 +125,10 @@ namespace EightBit this.IV = (byte)Mask.Mask8; this.ExxAF(); - this.AF().Word = (ushort)Mask.Mask16; + this.AF.Word = (ushort)Mask.Mask16; this.Exx(); - this.IX().Word = this.IY().Word = this.BC().Word = this.DE().Word = this.HL().Word = (ushort)Mask.Mask16; + this.IX.Word = this.IY.Word = this.BC.Word = this.DE.Word = this.HL.Word = (ushort)Mask.Mask16; this.prefixCB = this.prefixDD = this.prefixED = this.prefixFD = false; } @@ -270,7 +276,7 @@ namespace EightBit this.Tick(13); break; case 2: - this.Call(this.MEMPTR() = new Register16(this.Bus.Data, this.IV)); + this.Call(this.MEMPTR.Word = new Register16(this.Bus.Data, this.IV).Word); this.Tick(19); break; default: @@ -382,51 +388,51 @@ namespace EightBit private void EnableInterrupts() => this.IFF1 = this.IFF2 = true; - private ref Register16 HL2() + private Register16 HL2() { if (!this.displaced) { - return ref this.HL(); + return this.HL; } if (this.prefixDD) { - return ref this.IX(); + return this.IX; } // Must be FD prefix - return ref this.IY(); + return this.IY; } - private ref Register16 RP(int rp) + private Register16 RP(int rp) { switch (rp) { case 0: - return ref this.BC(); + return this.BC; case 1: - return ref this.DE(); + return this.DE; case 2: - return ref this.HL2(); + return this.HL2(); case 3: - return ref this.SP(); + return this.SP; default: throw new ArgumentOutOfRangeException(nameof(rp)); } } - private ref Register16 RP2(int rp) + private Register16 RP2(int rp) { switch (rp) { case 0: - return ref this.BC(); + return this.BC; case 1: - return ref this.DE(); + return this.DE; case 2: - return ref this.HL2(); + return this.HL2(); case 3: - return ref this.AF(); + return this.AF; default: throw new ArgumentOutOfRangeException(nameof(rp)); } @@ -437,21 +443,21 @@ namespace EightBit switch (r) { case 0: - return this.B(); + return this.B; case 1: - return this.C(); + return this.C; case 2: - return this.D(); + return this.D; case 3: - return this.E(); + return this.E; case 4: return this.HL2().High; case 5: return this.HL2().Low; case 6: - return this.Bus.Read(this.displaced ? this.DisplacedAddress : this.HL().Word); + return this.Bus.Read(this.displaced ? this.DisplacedAddress : this.HL.Word); case 7: - return this.A(); + return this.A; default: throw new ArgumentOutOfRangeException(nameof(r)); } @@ -462,16 +468,16 @@ namespace EightBit switch (r) { case 0: - this.B() = value; + this.B = value; break; case 1: - this.C() = value; + this.C = value; break; case 2: - this.D() = value; + this.D = value; break; case 3: - this.E() = value; + this.E = value; break; case 4: this.HL2().High = value; @@ -480,10 +486,10 @@ namespace EightBit this.HL2().Low = value; break; case 6: - this.Bus.Write(this.displaced ? this.DisplacedAddress : this.HL().Word, value); + this.Bus.Write(this.displaced ? this.DisplacedAddress : this.HL.Word, value); break; case 7: - this.A() = value; + this.A = value; break; default: throw new ArgumentOutOfRangeException(nameof(r)); @@ -495,28 +501,28 @@ namespace EightBit switch (r) { case 0: - this.B() = value; + this.B = value; break; case 1: - this.C() = value; + this.C = value; break; case 2: - this.D() = value; + this.D = value; break; case 3: - this.E() = value; + this.E = value; break; case 4: - this.H() = value; + this.H = value; break; case 5: - this.L() = value; + this.L = value; break; case 6: - this.Bus.Write(this.HL(), value); + this.Bus.Write(this.HL, value); break; case 7: - this.A() = value; + this.A = value; break; default: throw new ArgumentOutOfRangeException(nameof(r)); @@ -564,7 +570,7 @@ namespace EightBit throw new NotSupportedException("Invalid operation mode"); } - this.F() = AdjustSZP(this.F(), operand); + this.F = AdjustSZP(this.F, operand); this.Tick(8); break; case 1: // BIT y, r[z] @@ -572,11 +578,11 @@ namespace EightBit this.BIT(y, operand); if (direct) { - this.F() = AdjustXY(this.F(), operand); + this.F = AdjustXY(this.F, operand); } else { - this.F() = AdjustXY(this.F(), this.MEMPTR().High); + this.F = AdjustXY(this.F, this.MEMPTR.High); this.Tick(4); } @@ -626,21 +632,21 @@ namespace EightBit switch (z) { case 0: // Input from port with 16-bit address - this.MEMPTR() = this.Bus.Address() = this.BC(); - this.MEMPTR()++; + this.MEMPTR.Word = this.Bus.Address.Word = this.BC.Word; + this.MEMPTR.Word++; this.ReadPort(); if (y != 6) { this.R(y, this.Bus.Data); // IN r[y],(C) } - this.F() = AdjustSZPXY(this.F(), this.Bus.Data); - this.F() = ClearFlag(this.F(), StatusBits.NF | StatusBits.HC); + this.F = AdjustSZPXY(this.F, this.Bus.Data); + this.F = ClearFlag(this.F, StatusBits.NF | StatusBits.HC); this.Tick(12); break; case 1: // Output to port with 16-bit address - this.MEMPTR() = this.Bus.Address() = this.BC(); - this.MEMPTR()++; + this.MEMPTR.Word = this.Bus.Address.Word = this.BC.Word; + this.MEMPTR.Word++; if (y != 6) { this.Bus.Data = this.R(y); // OUT (C),r[y] @@ -669,14 +675,14 @@ namespace EightBit this.Tick(15); break; case 3: // Retrieve/store register pair from/to immediate address - this.Bus.Address() = this.FetchWord(); + this.Bus.Address.Word = this.FetchWord().Word; switch (q) { case 0: // LD (nn), rp[p] this.SetWord(this.RP(p)); break; case 1: // LD rp[p], (nn) - this.RP(p) = this.GetWord(); + this.RP(p).Word = this.GetWord().Word; break; default: throw new NotSupportedException("Invalid operation mode"); @@ -728,23 +734,23 @@ namespace EightBit switch (y) { case 0: // LD I,A - this.IV = this.A(); + this.IV = this.A; this.Tick(9); break; case 1: // LD R,A - this.REFRESH() = this.A(); + this.REFRESH() = this.A; this.Tick(9); break; case 2: // LD A,I - this.F() = AdjustSZXY(this.F(), this.A() = this.IV); - this.F() = ClearFlag(this.F(), StatusBits.NF | StatusBits.HC); - this.F() = SetFlag(this.F(), StatusBits.PF, this.IFF2); + this.F = AdjustSZXY(this.F, this.A = this.IV); + this.F = ClearFlag(this.F, StatusBits.NF | StatusBits.HC); + this.F = SetFlag(this.F, StatusBits.PF, this.IFF2); this.Tick(9); break; case 3: // LD A,R - this.F() = AdjustSZXY(this.F(), this.A() = this.REFRESH()); - this.F() = ClearFlag(this.F(), StatusBits.NF | StatusBits.HC); - this.F() = SetFlag(this.F(), StatusBits.PF, this.IFF2); + this.F = AdjustSZXY(this.F, this.A = this.REFRESH()); + this.F = ClearFlag(this.F, StatusBits.NF | StatusBits.HC); + this.F = SetFlag(this.F, StatusBits.PF, this.IFF2); this.Tick(9); break; case 4: // RRD @@ -784,8 +790,8 @@ namespace EightBit case 6: // LDIR if (this.LDIR()) { - this.MEMPTR() = --this.PC(); - --this.PC(); + this.MEMPTR.Word = --this.PC.Word; + --this.PC.Word; this.Tick(5); } @@ -793,8 +799,8 @@ namespace EightBit case 7: // LDDR if (this.LDDR()) { - this.MEMPTR() = --this.PC(); - --this.PC(); + this.MEMPTR.Word = --this.PC.Word; + --this.PC.Word; this.Tick(5); } @@ -814,8 +820,8 @@ namespace EightBit case 6: // CPIR if (this.CPIR()) { - this.MEMPTR() = --this.PC(); - --this.PC(); + this.MEMPTR.Word = --this.PC.Word; + --this.PC.Word; this.Tick(5); } @@ -823,13 +829,13 @@ namespace EightBit case 7: // CPDR if (this.CPDR()) { - this.MEMPTR() = --this.PC(); - --this.PC(); + this.MEMPTR.Word = --this.PC.Word; + --this.PC.Word; this.Tick(5); } else { - this.MEMPTR().Word = (ushort)(this.PC().Word - 2); + this.MEMPTR.Word = (ushort)(this.PC.Word - 2); } break; @@ -848,7 +854,7 @@ namespace EightBit case 6: // INIR if (this.INIR()) { - this.PC().Word -= 2; + this.PC.Word -= 2; this.Tick(5); } @@ -856,7 +862,7 @@ namespace EightBit case 7: // INDR if (this.INDR()) { - this.PC().Word -= 2; + this.PC.Word -= 2; this.Tick(5); } @@ -876,7 +882,7 @@ namespace EightBit case 6: // OTIR if (this.OTIR()) { - this.PC().Word -= 2; + this.PC.Word -= 2; this.Tick(5); } @@ -884,7 +890,7 @@ namespace EightBit case 7: // OTDR if (this.OTDR()) { - this.PC().Word -= 2; + this.PC.Word -= 2; this.Tick(5); } @@ -919,7 +925,7 @@ namespace EightBit this.Tick(4); break; case 2: // DJNZ d - if (this.JumpRelativeConditional(--this.B() != 0)) + if (this.JumpRelativeConditional(--this.B != 0)) { this.Tick(5); } @@ -950,7 +956,7 @@ namespace EightBit switch (q) { case 0: // LD rp,nn - this.RP(p) = this.FetchWord(); + this.RP(p).Word = this.FetchWord().Word; this.Tick(10); break; case 1: // ADD HL,rp @@ -969,28 +975,28 @@ namespace EightBit switch (p) { case 0: // LD (BC),A - this.MEMPTR() = this.Bus.Address() = this.BC(); - this.MEMPTR()++; - this.MEMPTR().High = this.Bus.Data = this.A(); + this.MEMPTR.Word = this.Bus.Address.Word = this.BC.Word; + ++this.MEMPTR.Word; + this.MEMPTR.High = this.Bus.Data = this.A; this.Bus.Write(); this.Tick(7); break; case 1: // LD (DE),A - this.MEMPTR() = this.Bus.Address() = this.DE(); - this.MEMPTR()++; - this.MEMPTR().High = this.Bus.Data = this.A(); + this.MEMPTR.Word = this.Bus.Address.Word = this.DE.Word; + ++this.MEMPTR.Word; + this.MEMPTR.High = this.Bus.Data = this.A; this.Bus.Write(); this.Tick(7); break; case 2: // LD (nn),HL - this.Bus.Address() = this.FetchWord(); + this.Bus.Address.Word = this.FetchWord().Word; this.SetWord(this.HL2()); this.Tick(16); break; case 3: // LD (nn),A - this.MEMPTR() = this.Bus.Address() = this.FetchWord(); - this.MEMPTR()++; - this.MEMPTR().High = this.Bus.Data = this.A(); + this.MEMPTR.Word = this.Bus.Address.Word = this.FetchWord().Word; + ++this.MEMPTR.Word; + this.MEMPTR.High = this.Bus.Data = this.A; this.Bus.Write(); this.Tick(13); break; @@ -1003,26 +1009,26 @@ namespace EightBit switch (p) { case 0: // LD A,(BC) - this.MEMPTR() = this.Bus.Address() = this.BC(); - this.MEMPTR()++; - this.A() = this.Bus.Read(); + this.MEMPTR.Word = this.Bus.Address.Word = this.BC.Word; + ++this.MEMPTR.Word; + this.A = this.Bus.Read(); this.Tick(7); break; case 1: // LD A,(DE) - this.MEMPTR() = this.Bus.Address() = this.DE(); - this.MEMPTR()++; - this.A() = this.Bus.Read(); + this.MEMPTR.Word = this.Bus.Address.Word = this.DE.Word; + ++this.MEMPTR.Word; + this.A = this.Bus.Read(); this.Tick(7); break; case 2: // LD HL,(nn) - this.Bus.Address() = this.FetchWord(); - this.HL2() = this.GetWord(); + this.Bus.Address.Word = this.FetchWord().Word; + this.HL2().Word = this.GetWord().Word; this.Tick(16); break; case 3: // LD A,(nn) - this.MEMPTR() = this.Bus.Address() = this.FetchWord(); - this.MEMPTR()++; - this.A() = this.Bus.Read(); + this.MEMPTR.Word = this.Bus.Address.Word = this.FetchWord().Word; + ++this.MEMPTR.Word; + this.A = this.Bus.Read(); this.Tick(13); break; default: @@ -1039,10 +1045,10 @@ namespace EightBit switch (q) { case 0: // INC rp - ++this.RP(p); + ++this.RP(p).Word; break; case 1: // DEC rp - --this.RP(p); + --this.RP(p).Word; break; default: throw new NotSupportedException("Invalid operation mode"); @@ -1089,16 +1095,16 @@ namespace EightBit switch (y) { case 0: - this.A() = this.RLC(this.A()); + this.A = this.RLC(this.A); break; case 1: - this.A() = this.RRC(this.A()); + this.A = this.RRC(this.A); break; case 2: - this.A() = this.RL(this.A()); + this.A = this.RL(this.A); break; case 3: - this.A() = this.RR(this.A()); + this.A = this.RR(this.A); break; case 4: this.DAA(); @@ -1139,11 +1145,11 @@ namespace EightBit switch (y) { case 4: - this.H() = this.R(z); + this.H = this.R(z); normal = false; break; case 5: - this.L() = this.R(z); + this.L = this.R(z); normal = false; break; } @@ -1154,11 +1160,11 @@ namespace EightBit switch (z) { case 4: - this.R(y, this.H()); + this.R(y, this.H); normal = false; break; case 5: - this.R(y, this.L()); + this.R(y, this.L); normal = false; break; } @@ -1244,7 +1250,7 @@ namespace EightBit switch (q) { case 0: // POP rp2[p] - this.RP2(p) = this.PopWord(); + this.RP2(p).Word = this.PopWord().Word; this.Tick(10); break; case 1: @@ -1263,7 +1269,7 @@ namespace EightBit this.Tick(4); break; case 3: // LD SP,HL - this.SP() = this.HL2(); + this.SP.Word = this.HL2().Word; this.Tick(4); break; default: @@ -1284,7 +1290,7 @@ namespace EightBit switch (y) { case 0: // JP nn - this.Jump(this.MEMPTR() = this.FetchWord()); + this.Jump(this.MEMPTR.Word = this.FetchWord().Word); this.Tick(10); break; case 1: // CB prefix @@ -1302,7 +1308,7 @@ namespace EightBit this.Tick(11); break; case 3: // IN A,(n) - this.A() = this.ReadPort(this.FetchByte()); + this.A = this.ReadPort(this.FetchByte()); this.Tick(11); break; case 4: // EX (SP),HL @@ -1310,7 +1316,7 @@ namespace EightBit this.Tick(19); break; case 5: // EX DE,HL - (this.DE(), this.HL()) = (this.HL(), this.DE()); + (this.DE.Word, this.HL.Word) = (this.HL.Word, this.DE.Word); this.Tick(4); break; case 6: // DI @@ -1345,7 +1351,7 @@ namespace EightBit switch (p) { case 0: // CALL nn - this.Call(this.MEMPTR() = this.FetchWord()); + this.Call(this.MEMPTR.Word = this.FetchWord().Word); this.Tick(17); break; case 1: // DD prefix @@ -1435,36 +1441,36 @@ namespace EightBit private byte Subtract(byte operand, byte value, int carry = 0) { - var subtraction = new Register16(operand - value - carry); - var result = subtraction.Low; + this.intermediate.Word = (ushort)(operand - value - carry); + var result = this.intermediate.Low; - this.F() = AdjustHalfCarrySub(this.F(), operand, value, result); - this.F() = AdjustOverflowSub(this.F(), operand, value, result); + this.F = AdjustHalfCarrySub(this.F, operand, value, result); + this.F = AdjustOverflowSub(this.F, operand, value, result); - this.F() = SetFlag(this.F(), StatusBits.NF); - this.F() = SetFlag(this.F(), StatusBits.CF, subtraction.High & (byte)StatusBits.CF); - this.F() = AdjustSZ(this.F(), result); + this.F = SetFlag(this.F, StatusBits.NF); + this.F = SetFlag(this.F, StatusBits.CF, this.intermediate.High & (byte)StatusBits.CF); + this.F = AdjustSZ(this.F, result); return result; } private byte Increment(byte operand) { - this.F() = ClearFlag(this.F(), StatusBits.NF); + this.F = ClearFlag(this.F, StatusBits.NF); var result = ++operand; - this.F() = AdjustSZXY(this.F(), result); - this.F() = SetFlag(this.F(), StatusBits.VF, result == (byte)Bits.Bit7); - this.F() = ClearFlag(this.F(), StatusBits.HC, LowNibble(result)); + this.F = AdjustSZXY(this.F, result); + this.F = SetFlag(this.F, StatusBits.VF, result == (byte)Bits.Bit7); + this.F = ClearFlag(this.F, StatusBits.HC, LowNibble(result)); return result; } private byte Decrement(byte operand) { - this.F() = SetFlag(this.F(), StatusBits.NF); - this.F() = ClearFlag(this.F(), StatusBits.HC, LowNibble(operand)); + this.F = SetFlag(this.F, StatusBits.NF); + this.F = ClearFlag(this.F, StatusBits.HC, LowNibble(operand)); var result = --operand; - this.F() = AdjustSZXY(this.F(), result); - this.F() = SetFlag(this.F(), StatusBits.VF, result == (byte)Mask.Mask7); + this.F = AdjustSZXY(this.F, result); + this.F = SetFlag(this.F, StatusBits.VF, result == (byte)Mask.Mask7); return result; } @@ -1481,13 +1487,13 @@ namespace EightBit switch (flag) { case 0: // NZ - return this.JumpRelativeConditional((this.F() & (byte)StatusBits.ZF) == 0); + return this.JumpRelativeConditional((this.F & (byte)StatusBits.ZF) == 0); case 1: // Z - return this.JumpRelativeConditional((this.F() & (byte)StatusBits.ZF) != 0); + return this.JumpRelativeConditional((this.F & (byte)StatusBits.ZF) != 0); case 2: // NC - return this.JumpRelativeConditional((this.F() & (byte)StatusBits.CF) == 0); + return this.JumpRelativeConditional((this.F & (byte)StatusBits.CF) == 0); case 3: // C - return this.JumpRelativeConditional((this.F() & (byte)StatusBits.CF) != 0); + return this.JumpRelativeConditional((this.F & (byte)StatusBits.CF) != 0); default: throw new ArgumentOutOfRangeException(nameof(flag)); } @@ -1498,21 +1504,21 @@ namespace EightBit switch (flag) { case 0: // NZ - return this.ReturnConditional((this.F() & (byte)StatusBits.ZF) == 0); + return this.ReturnConditional((this.F & (byte)StatusBits.ZF) == 0); case 1: // Z - return this.ReturnConditional((this.F() & (byte)StatusBits.ZF) != 0); + return this.ReturnConditional((this.F & (byte)StatusBits.ZF) != 0); case 2: // NC - return this.ReturnConditional((this.F() & (byte)StatusBits.CF) == 0); + return this.ReturnConditional((this.F & (byte)StatusBits.CF) == 0); case 3: // C - return this.ReturnConditional((this.F() & (byte)StatusBits.CF) != 0); + return this.ReturnConditional((this.F & (byte)StatusBits.CF) != 0); case 4: // PO - return this.ReturnConditional((this.F() & (byte)StatusBits.PF) == 0); + return this.ReturnConditional((this.F & (byte)StatusBits.PF) == 0); case 5: // PE - return this.ReturnConditional((this.F() & (byte)StatusBits.PF) != 0); + return this.ReturnConditional((this.F & (byte)StatusBits.PF) != 0); case 6: // P - return this.ReturnConditional((this.F() & (byte)StatusBits.SF) == 0); + return this.ReturnConditional((this.F & (byte)StatusBits.SF) == 0); case 7: // M - return this.ReturnConditional((this.F() & (byte)StatusBits.SF) != 0); + return this.ReturnConditional((this.F & (byte)StatusBits.SF) != 0); default: throw new ArgumentOutOfRangeException(nameof(flag)); } @@ -1523,21 +1529,21 @@ namespace EightBit switch (flag) { case 0: // NZ - return this.JumpConditional((this.F() & (byte)StatusBits.ZF) == 0); + return this.JumpConditional((this.F & (byte)StatusBits.ZF) == 0); case 1: // Z - return this.JumpConditional((this.F() & (byte)StatusBits.ZF) != 0); + return this.JumpConditional((this.F & (byte)StatusBits.ZF) != 0); case 2: // NC - return this.JumpConditional((this.F() & (byte)StatusBits.CF) == 0); + return this.JumpConditional((this.F & (byte)StatusBits.CF) == 0); case 3: // C - return this.JumpConditional((this.F() & (byte)StatusBits.CF) != 0); + return this.JumpConditional((this.F & (byte)StatusBits.CF) != 0); case 4: // PO - return this.JumpConditional((this.F() & (byte)StatusBits.PF) == 0); + return this.JumpConditional((this.F & (byte)StatusBits.PF) == 0); case 5: // PE - return this.JumpConditional((this.F() & (byte)StatusBits.PF) != 0); + return this.JumpConditional((this.F & (byte)StatusBits.PF) != 0); case 6: // P - return this.JumpConditional((this.F() & (byte)StatusBits.SF) == 0); + return this.JumpConditional((this.F & (byte)StatusBits.SF) == 0); case 7: // M - return this.JumpConditional((this.F() & (byte)StatusBits.SF) != 0); + return this.JumpConditional((this.F & (byte)StatusBits.SF) != 0); default: throw new ArgumentOutOfRangeException(nameof(flag)); } @@ -1548,21 +1554,21 @@ namespace EightBit switch (flag) { case 0: // NZ - return this.CallConditional((this.F() & (byte)StatusBits.ZF) == 0); + return this.CallConditional((this.F & (byte)StatusBits.ZF) == 0); case 1: // Z - return this.CallConditional((this.F() & (byte)StatusBits.ZF) != 0); + return this.CallConditional((this.F & (byte)StatusBits.ZF) != 0); case 2: // NC - return this.CallConditional((this.F() & (byte)StatusBits.CF) == 0); + return this.CallConditional((this.F & (byte)StatusBits.CF) == 0); case 3: // C - return this.CallConditional((this.F() & (byte)StatusBits.CF) != 0); + return this.CallConditional((this.F & (byte)StatusBits.CF) != 0); case 4: // PO - return this.CallConditional((this.F() & (byte)StatusBits.PF) == 0); + return this.CallConditional((this.F & (byte)StatusBits.PF) == 0); case 5: // PE - return this.CallConditional((this.F() & (byte)StatusBits.PF) != 0); + return this.CallConditional((this.F & (byte)StatusBits.PF) != 0); case 6: // P - return this.CallConditional((this.F() & (byte)StatusBits.SF) == 0); + return this.CallConditional((this.F & (byte)StatusBits.SF) == 0); case 7: // M - return this.CallConditional((this.F() & (byte)StatusBits.SF) != 0); + return this.CallConditional((this.F & (byte)StatusBits.SF) != 0); default: throw new ArgumentOutOfRangeException(nameof(flag)); } @@ -1570,207 +1576,207 @@ namespace EightBit private void SBC(Register16 value) { - this.MEMPTR().Word = this.HL2().Word; + this.MEMPTR.Word = this.HL2().Word; - var beforeNegative = this.MEMPTR().High & (byte)StatusBits.SF; + var beforeNegative = this.MEMPTR.High & (byte)StatusBits.SF; var valueNegative = value.High & (byte)StatusBits.SF; - var result = this.MEMPTR().Word - value.Word - (this.F() & (byte)StatusBits.CF); + var result = this.MEMPTR.Word - value.Word - (this.F & (byte)StatusBits.CF); this.HL2().Word = (ushort)result; var afterNegative = this.HL2().High & (byte)StatusBits.SF; - this.F() = SetFlag(this.F(), StatusBits.SF, afterNegative); - this.F() = ClearFlag(this.F(), StatusBits.ZF, this.HL2().Word); - this.F() = AdjustHalfCarrySub(this.F(), this.MEMPTR().High, value.High, this.HL2().High); - this.F() = AdjustOverflowSub(this.F(), beforeNegative, valueNegative, afterNegative); - this.F() = SetFlag(this.F(), StatusBits.NF); - this.F() = SetFlag(this.F(), StatusBits.CF, result & (int)Bits.Bit16); - this.F() = AdjustXY(this.F(), this.HL2().High); + this.F = SetFlag(this.F, StatusBits.SF, afterNegative); + this.F = ClearFlag(this.F, StatusBits.ZF, this.HL2().Word); + this.F = AdjustHalfCarrySub(this.F, this.MEMPTR.High, value.High, this.HL2().High); + this.F = AdjustOverflowSub(this.F, beforeNegative, valueNegative, afterNegative); + this.F = SetFlag(this.F, StatusBits.NF); + this.F = SetFlag(this.F, StatusBits.CF, result & (int)Bits.Bit16); + this.F = AdjustXY(this.F, this.HL2().High); - ++this.MEMPTR(); + ++this.MEMPTR.Word; } private void ADC(Register16 value) { - this.MEMPTR().Word = this.HL2().Word; + this.MEMPTR.Word = this.HL2().Word; - var beforeNegative = this.MEMPTR().High & (byte)StatusBits.SF; + var beforeNegative = this.MEMPTR.High & (byte)StatusBits.SF; var valueNegative = value.High & (byte)StatusBits.SF; - var result = this.MEMPTR().Word + value.Word + (this.F() & (byte)StatusBits.CF); + var result = this.MEMPTR.Word + value.Word + (this.F & (byte)StatusBits.CF); this.HL2().Word = (ushort)result; var afterNegative = this.HL2().High & (byte)StatusBits.SF; - this.F() = SetFlag(this.F(), StatusBits.SF, afterNegative); - this.F() = ClearFlag(this.F(), StatusBits.ZF, this.HL2().Word); - this.F() = AdjustHalfCarryAdd(this.F(), this.MEMPTR().High, value.High, this.HL2().High); - this.F() = AdjustOverflowAdd(this.F(), beforeNegative, valueNegative, afterNegative); - this.F() = ClearFlag(this.F(), StatusBits.NF); - this.F() = SetFlag(this.F(), StatusBits.CF, result & (int)Bits.Bit16); - this.F() = AdjustXY(this.F(), this.HL2().High); + this.F = SetFlag(this.F, StatusBits.SF, afterNegative); + this.F = ClearFlag(this.F, StatusBits.ZF, this.HL2().Word); + this.F = AdjustHalfCarryAdd(this.F, this.MEMPTR.High, value.High, this.HL2().High); + this.F = AdjustOverflowAdd(this.F, beforeNegative, valueNegative, afterNegative); + this.F = ClearFlag(this.F, StatusBits.NF); + this.F = SetFlag(this.F, StatusBits.CF, result & (int)Bits.Bit16); + this.F = AdjustXY(this.F, this.HL2().High); - ++this.MEMPTR(); + ++this.MEMPTR.Word; } private void Add(Register16 value) { - this.MEMPTR().Word = this.HL2().Word; + this.MEMPTR.Word = this.HL2().Word; - var result = this.MEMPTR().Word + value.Word; + var result = this.MEMPTR.Word + value.Word; this.HL2().Word = (ushort)result; - this.F() = ClearFlag(this.F(), StatusBits.NF); - this.F() = SetFlag(this.F(), StatusBits.CF, result & (int)Bits.Bit16); - this.F() = AdjustHalfCarryAdd(this.F(), this.MEMPTR().High, value.High, this.HL2().High); - this.F() = AdjustXY(this.F(), this.HL2().High); + this.F = ClearFlag(this.F, StatusBits.NF); + this.F = SetFlag(this.F, StatusBits.CF, result & (int)Bits.Bit16); + this.F = AdjustHalfCarryAdd(this.F, this.MEMPTR.High, value.High, this.HL2().High); + this.F = AdjustXY(this.F, this.HL2().High); - ++this.MEMPTR(); + ++this.MEMPTR.Word; } private void Add(byte value, int carry = 0) { - var result = new Register16(this.A() + value + carry); + this.intermediate.Word = (ushort)(this.A + value + carry); - this.F() = AdjustHalfCarryAdd(this.F(), this.A(), value, result.Low); - this.F() = AdjustOverflowAdd(this.F(), this.A(), value, result.Low); + this.F = AdjustHalfCarryAdd(this.F, this.A, value, this.intermediate.Low); + this.F = AdjustOverflowAdd(this.F, this.A, value, this.intermediate.Low); - this.F() = ClearFlag(this.F(), StatusBits.NF); - this.F() = SetFlag(this.F(), StatusBits.CF, result.High & (byte)StatusBits.CF); - this.F() = AdjustSZXY(this.F(), this.A() = result.Low); + this.F = ClearFlag(this.F, StatusBits.NF); + this.F = SetFlag(this.F, StatusBits.CF, this.intermediate.High & (byte)StatusBits.CF); + this.F = AdjustSZXY(this.F, this.A = this.intermediate.Low); } - private void ADC(byte value) => this.Add(value, this.F() & (byte)StatusBits.CF); + private void ADC(byte value) => this.Add(value, this.F & (byte)StatusBits.CF); private void SUB(byte value, int carry = 0) { - this.A() = this.Subtract(this.A(), value, carry); - this.F() = AdjustXY(this.F(), this.A()); + this.A = this.Subtract(this.A, value, carry); + this.F = AdjustXY(this.F, this.A); } - private void SBC(byte value) => this.SUB(value, this.F() & (byte)StatusBits.CF); + private void SBC(byte value) => this.SUB(value, this.F & (byte)StatusBits.CF); private void AndR(byte value) { - this.F() = SetFlag(this.F(), StatusBits.HC); - this.F() = ClearFlag(this.F(), StatusBits.CF | StatusBits.NF); - this.F() = AdjustSZPXY(this.F(), this.A() &= value); + this.F = SetFlag(this.F, StatusBits.HC); + this.F = ClearFlag(this.F, StatusBits.CF | StatusBits.NF); + this.F = AdjustSZPXY(this.F, this.A &= value); } private void XorR(byte value) { - this.F() = ClearFlag(this.F(), StatusBits.HC | StatusBits.CF | StatusBits.NF); - this.F() = AdjustSZPXY(this.F(), this.A() ^= value); + this.F = ClearFlag(this.F, StatusBits.HC | StatusBits.CF | StatusBits.NF); + this.F = AdjustSZPXY(this.F, this.A ^= value); } private void OrR(byte value) { - this.F() = ClearFlag(this.F(), StatusBits.HC | StatusBits.CF | StatusBits.NF); - this.F() = AdjustSZPXY(this.F(), this.A() |= value); + this.F = ClearFlag(this.F, StatusBits.HC | StatusBits.CF | StatusBits.NF); + this.F = AdjustSZPXY(this.F, this.A |= value); } private void Compare(byte value) { - this.Subtract(this.A(), value); - this.F() = AdjustXY(this.F(), value); + this.Subtract(this.A, value); + this.F = AdjustXY(this.F, value); } private byte RLC(byte operand) { - this.F() = ClearFlag(this.F(), StatusBits.NF | StatusBits.HC); + this.F = ClearFlag(this.F, StatusBits.NF | StatusBits.HC); var carry = operand & (byte)Bits.Bit7; - this.F() = SetFlag(this.F(), StatusBits.CF, carry); + this.F = SetFlag(this.F, StatusBits.CF, carry); var result = (byte)((operand << 1) | (carry >> 7)); - this.F() = AdjustXY(this.F(), result); + this.F = AdjustXY(this.F, result); return result; } private byte RRC(byte operand) { - this.F() = ClearFlag(this.F(), StatusBits.NF | StatusBits.HC); + this.F = ClearFlag(this.F, StatusBits.NF | StatusBits.HC); var carry = operand & (byte)Bits.Bit0; - this.F() = SetFlag(this.F(), StatusBits.CF, carry); + this.F = SetFlag(this.F, StatusBits.CF, carry); var result = (byte)((operand >> 1) | (carry << 7)); - this.F() = AdjustXY(this.F(), result); + this.F = AdjustXY(this.F, result); return result; } private byte RL(byte operand) { - this.F() = ClearFlag(this.F(), StatusBits.NF | StatusBits.HC); - var carry = this.F() & (byte)StatusBits.CF; - this.F() = SetFlag(this.F(), StatusBits.CF, operand & (byte)Bits.Bit7); + this.F = ClearFlag(this.F, StatusBits.NF | StatusBits.HC); + var carry = this.F & (byte)StatusBits.CF; + this.F = SetFlag(this.F, StatusBits.CF, operand & (byte)Bits.Bit7); var result = (byte)((operand << 1) | carry); - this.F() = AdjustXY(this.F(), result); + this.F = AdjustXY(this.F, result); return result; } private byte RR(byte operand) { - this.F() = ClearFlag(this.F(), StatusBits.NF | StatusBits.HC); - var carry = this.F() & (byte)StatusBits.CF; - this.F() = SetFlag(this.F(), StatusBits.CF, operand & (byte)Bits.Bit0); + this.F = ClearFlag(this.F, StatusBits.NF | StatusBits.HC); + var carry = this.F & (byte)StatusBits.CF; + this.F = SetFlag(this.F, StatusBits.CF, operand & (byte)Bits.Bit0); var result = (byte)((operand >> 1) | (carry << 7)); - this.F() = AdjustXY(this.F(), result); + this.F = AdjustXY(this.F, result); return result; } private byte SLA(byte operand) { - this.F() = ClearFlag(this.F(), StatusBits.NF | StatusBits.HC); - this.F() = SetFlag(this.F(), StatusBits.CF, operand & (byte)Bits.Bit7); + this.F = ClearFlag(this.F, StatusBits.NF | StatusBits.HC); + this.F = SetFlag(this.F, StatusBits.CF, operand & (byte)Bits.Bit7); var result = (byte)(operand << 1); - this.F() = AdjustXY(this.F(), result); + this.F = AdjustXY(this.F, result); return result; } private byte SRA(byte operand) { - this.F() = ClearFlag(this.F(), StatusBits.NF | StatusBits.HC); - this.F() = SetFlag(this.F(), StatusBits.CF, operand & (byte)Bits.Bit0); + this.F = ClearFlag(this.F, StatusBits.NF | StatusBits.HC); + this.F = SetFlag(this.F, StatusBits.CF, operand & (byte)Bits.Bit0); var result = (byte)((operand >> 1) | (operand & (byte)Bits.Bit7)); - this.F() = AdjustXY(this.F(), result); + this.F = AdjustXY(this.F, result); return result; } private byte SLL(byte operand) { - this.F() = ClearFlag(this.F(), StatusBits.NF | StatusBits.HC); - this.F() = SetFlag(this.F(), StatusBits.CF, operand & (byte)Bits.Bit7); + this.F = ClearFlag(this.F, StatusBits.NF | StatusBits.HC); + this.F = SetFlag(this.F, StatusBits.CF, operand & (byte)Bits.Bit7); var result = (byte)((operand << 1) | (byte)Bits.Bit0); - this.F() = AdjustXY(this.F(), result); + this.F = AdjustXY(this.F, result); return result; } private byte SRL(byte operand) { - this.F() = ClearFlag(this.F(), StatusBits.NF | StatusBits.HC); - this.F() = SetFlag(this.F(), StatusBits.CF, operand & (byte)Bits.Bit0); + this.F = ClearFlag(this.F, StatusBits.NF | StatusBits.HC); + this.F = SetFlag(this.F, StatusBits.CF, operand & (byte)Bits.Bit0); var result = (byte)((operand >> 1) & ~(byte)Bits.Bit7); - this.F() = AdjustXY(this.F(), result); - this.F() = SetFlag(this.F(), StatusBits.ZF, result); + this.F = AdjustXY(this.F, result); + this.F = SetFlag(this.F, StatusBits.ZF, result); return result; } private void BIT(int n, byte operand) { - this.F() = SetFlag(this.F(), StatusBits.HC); - this.F() = ClearFlag(this.F(), StatusBits.NF); + this.F = SetFlag(this.F, StatusBits.HC); + this.F = ClearFlag(this.F, StatusBits.NF); var discarded = (byte)(operand & (1 << n)); - this.F() = AdjustSZ(this.F(), discarded); - this.F() = ClearFlag(this.F(), StatusBits.PF, discarded); + this.F = AdjustSZ(this.F, discarded); + this.F = ClearFlag(this.F, StatusBits.PF, discarded); } private void DAA() { - var updated = this.A(); + var updated = this.A; - var lowAdjust = ((this.F() & (byte)StatusBits.HC) != 0) || (LowNibble(this.A()) > 9); - var highAdjust = ((this.F() & (byte)StatusBits.CF) != 0) || (this.A() > 0x99); + var lowAdjust = ((this.F & (byte)StatusBits.HC) != 0) || (LowNibble(this.A) > 9); + var highAdjust = ((this.F & (byte)StatusBits.CF) != 0) || (this.A > 0x99); - if ((this.F() & (byte)StatusBits.NF) != 0) + if ((this.F & (byte)StatusBits.NF) != 0) { if (lowAdjust) { @@ -1795,248 +1801,258 @@ namespace EightBit } } - this.F() = (byte)((this.F() & (byte)(StatusBits.CF | StatusBits.NF)) | (this.A() > 0x99 ? (byte)StatusBits.CF : 0) | ((this.A() ^ updated) & (byte)StatusBits.HC)); + this.F = (byte)((this.F & (byte)(StatusBits.CF | StatusBits.NF)) | (this.A > 0x99 ? (byte)StatusBits.CF : 0) | ((this.A ^ updated) & (byte)StatusBits.HC)); - this.F() = AdjustSZPXY(this.F(), this.A() = updated); + this.F = AdjustSZPXY(this.F, this.A = updated); } private void SCF() { - this.F() = SetFlag(this.F(), StatusBits.CF); - this.F() = ClearFlag(this.F(), StatusBits.HC | StatusBits.NF); - this.F() = AdjustXY(this.F(), this.A()); + this.F = SetFlag(this.F, StatusBits.CF); + this.F = ClearFlag(this.F, StatusBits.HC | StatusBits.NF); + this.F = AdjustXY(this.F, this.A); } private void CCF() { - this.F() = ClearFlag(this.F(), StatusBits.NF); - var carry = this.F() & (byte)StatusBits.CF; - this.F() = SetFlag(this.F(), StatusBits.HC, carry); - this.F() = ClearFlag(this.F(), StatusBits.CF, carry); - this.F() = AdjustXY(this.F(), this.A()); + this.F = ClearFlag(this.F, StatusBits.NF); + var carry = this.F & (byte)StatusBits.CF; + this.F = SetFlag(this.F, StatusBits.HC, carry); + this.F = ClearFlag(this.F, StatusBits.CF, carry); + this.F = AdjustXY(this.F, this.A); } private void CPL() { - this.F() = SetFlag(this.F(), StatusBits.HC | StatusBits.NF); - this.F() = AdjustXY(this.F(), this.A() = (byte)~this.A()); + this.F = SetFlag(this.F, StatusBits.HC | StatusBits.NF); + this.F = AdjustXY(this.F, this.A = (byte)~this.A); } private void XHTL() { - this.MEMPTR().Low = this.Bus.Read(this.SP()); + this.MEMPTR.Low = this.Bus.Read(this.SP); this.Bus.Write(this.HL2().Low); - this.HL2().Low = this.MEMPTR().Low; - ++this.Bus.Address(); - this.MEMPTR().High = this.Bus.Read(); + this.HL2().Low = this.MEMPTR.Low; + ++this.Bus.Address.Word; + this.MEMPTR.High = this.Bus.Read(); this.Bus.Write(this.HL2().High); - this.HL2().High = this.MEMPTR().High; + this.HL2().High = this.MEMPTR.High; } - private void BlockCompare(Register16 source, ref Register16 counter) + private void BlockCompare(Register16 source, Register16 counter) { var value = this.Bus.Read(source); - var result = (byte)(this.A() - value); + var result = (byte)(this.A - value); - this.F() = SetFlag(this.F(), StatusBits.PF, --counter.Word); + this.F = SetFlag(this.F, StatusBits.PF, --counter.Word); - this.F() = AdjustSZ(this.F(), result); - this.F() = AdjustHalfCarrySub(this.F(), this.A(), value, result); - this.F() = SetFlag(this.F(), StatusBits.NF); + this.F = AdjustSZ(this.F, result); + this.F = AdjustHalfCarrySub(this.F, this.A, value, result); + this.F = SetFlag(this.F, StatusBits.NF); - result -= (byte)((this.F() & (byte)StatusBits.HC) >> 4); + result -= (byte)((this.F & (byte)StatusBits.HC) >> 4); - this.F() = SetFlag(this.F(), StatusBits.YF, result & (byte)Bits.Bit1); - this.F() = SetFlag(this.F(), StatusBits.XF, result & (byte)Bits.Bit3); + this.F = SetFlag(this.F, StatusBits.YF, result & (byte)Bits.Bit1); + this.F = SetFlag(this.F, StatusBits.XF, result & (byte)Bits.Bit3); } private void CPI() { - this.BlockCompare(this.HL()++, ref this.BC()); - ++this.MEMPTR(); + this.BlockCompare(this.HL, this.BC); + ++this.HL.Word; + ++this.MEMPTR.Word; } private bool CPIR() { this.CPI(); - return ((this.F() & (byte)StatusBits.PF) != 0) && ((this.F() & (byte)StatusBits.ZF) == 0); // See CPI + return ((this.F & (byte)StatusBits.PF) != 0) && ((this.F & (byte)StatusBits.ZF) == 0); // See CPI } private void CPD() { - this.BlockCompare(this.HL()--, ref this.BC()); - --this.MEMPTR(); + this.BlockCompare(this.HL, this.BC); + --this.HL.Word; + --this.MEMPTR.Word; } private bool CPDR() { this.CPD(); - return ((this.F() & (byte)StatusBits.PF) != 0) && ((this.F() & (byte)StatusBits.ZF) == 0); // See CPD + return ((this.F & (byte)StatusBits.PF) != 0) && ((this.F & (byte)StatusBits.ZF) == 0); // See CPD } - private void BlockLoad(Register16 source, Register16 destination, ref Register16 counter) + private void BlockLoad(Register16 source, Register16 destination, Register16 counter) { var value = this.Bus.Read(source); this.Bus.Write(destination, value); - var xy = this.A() + value; - this.F() = SetFlag(this.F(), StatusBits.XF, xy & (int)Bits.Bit3); - this.F() = SetFlag(this.F(), StatusBits.YF, xy & (int)Bits.Bit1); - this.F() = ClearFlag(this.F(), StatusBits.NF | StatusBits.HC); - this.F() = SetFlag(this.F(), StatusBits.PF, --counter.Word); + var xy = this.A + value; + this.F = SetFlag(this.F, StatusBits.XF, xy & (int)Bits.Bit3); + this.F = SetFlag(this.F, StatusBits.YF, xy & (int)Bits.Bit1); + this.F = ClearFlag(this.F, StatusBits.NF | StatusBits.HC); + this.F = SetFlag(this.F, StatusBits.PF, --counter.Word); } private void LDI() { - this.BlockLoad(this.HL()++, this.DE()++, ref this.BC()); + this.BlockLoad(this.HL, this.DE, this.BC); + ++this.HL.Word; + ++this.DE.Word; } private bool LDIR() { this.LDI(); - return (this.F() & (byte)StatusBits.PF) != 0; // See LDI + return (this.F & (byte)StatusBits.PF) != 0; // See LDI } private void LDD() { - this.BlockLoad(this.HL()--, this.DE()--, ref this.BC()); + this.BlockLoad(this.HL, this.DE, this.BC); + --this.HL.Word; + --this.DE.Word; } private bool LDDR() { this.LDD(); - return (this.F() & (byte)StatusBits.PF) != 0; // See LDD + return (this.F & (byte)StatusBits.PF) != 0; // See LDD } private void BlockIn(Register16 source, Register16 destination) { - this.MEMPTR() = this.Bus.Address() = source; + this.MEMPTR.Word = this.Bus.Address.Word = source.Word; var value = this.ReadPort(); this.Bus.Write(destination, value); source.High = this.Decrement(source.High); - this.F() = SetFlag(this.F(), StatusBits.NF); + this.F = SetFlag(this.F, StatusBits.NF); } private void INI() { - this.BlockIn(this.BC(), this.HL()++); - ++this.MEMPTR(); + this.BlockIn(this.BC, this.HL); + ++this.HL.Word; + ++this.MEMPTR.Word; } private bool INIR() { this.INI(); - return (this.F() & (byte)StatusBits.ZF) == 0; // See INI + return (this.F & (byte)StatusBits.ZF) == 0; // See INI } private void IND() { - this.BlockIn(this.BC(), this.HL()--); - --this.MEMPTR(); + this.BlockIn(this.BC, this.HL); + --this.HL.Word; + --this.MEMPTR.Word; } private bool INDR() { this.IND(); - return (this.F() & (byte)StatusBits.ZF) == 0; // See IND + return (this.F & (byte)StatusBits.ZF) == 0; // See IND } private void BlockOut(Register16 source, Register16 destination) { var value = this.Bus.Read(source); - this.Bus.Address() = destination; + this.Bus.Address.Word = destination.Word; this.WritePort(); destination.High = this.Decrement(destination.High); - this.MEMPTR() = destination; - this.F() = SetFlag(this.F(), StatusBits.NF, value & (byte)Bits.Bit7); - this.F() = SetFlag(this.F(), StatusBits.HC | StatusBits.CF, (this.L() + value) > 0xff); - this.F() = AdjustParity(this.F(), (byte)(((value + this.L()) & (int)Mask.Mask3) ^ this.B())); + this.MEMPTR.Word = destination.Word; + this.F = SetFlag(this.F, StatusBits.NF, value & (byte)Bits.Bit7); + this.F = SetFlag(this.F, StatusBits.HC | StatusBits.CF, (this.L + value) > 0xff); + this.F = AdjustParity(this.F, (byte)(((value + this.L) & (int)Mask.Mask3) ^ this.B)); } private void OUTI() { - this.BlockOut(this.HL()++, this.BC()); - ++this.MEMPTR(); + this.BlockOut(this.HL, this.BC); + ++this.HL.Word; + ++this.MEMPTR.Word; } private bool OTIR() { this.OUTI(); - return (this.F() & (byte)StatusBits.ZF) == 0; // See OUTI + return (this.F & (byte)StatusBits.ZF) == 0; // See OUTI } private void OUTD() { - this.BlockOut(this.HL()--, this.BC()); - --this.MEMPTR(); + this.BlockOut(this.HL, this.BC); + --this.HL.Word; + --this.MEMPTR.Word; } private bool OTDR() { this.OUTD(); - return (this.F() & (byte)StatusBits.ZF) == 0; // See OUTD + return (this.F & (byte)StatusBits.ZF) == 0; // See OUTD } private void NEG() { - this.F() = SetFlag(this.F(), StatusBits.PF, this.A() == (byte)Bits.Bit7); - this.F() = SetFlag(this.F(), StatusBits.CF, this.A()); - this.F() = SetFlag(this.F(), StatusBits.NF); + this.F = SetFlag(this.F, StatusBits.PF, this.A == (byte)Bits.Bit7); + this.F = SetFlag(this.F, StatusBits.CF, this.A); + this.F = SetFlag(this.F, StatusBits.NF); - var original = this.A(); + var original = this.A; - this.A() = (byte)(~this.A() + 1); // two's complement + this.A = (byte)(~this.A + 1); // two's complement - this.F() = AdjustHalfCarrySub(this.F(), (byte)0, original, this.A()); - this.F() = AdjustOverflowSub(this.F(), (byte)0, original, this.A()); + this.F = AdjustHalfCarrySub(this.F, (byte)0, original, this.A); + this.F = AdjustOverflowSub(this.F, (byte)0, original, this.A); - this.F() = AdjustSZXY(this.F(), this.A()); + this.F = AdjustSZXY(this.F, this.A); } private void RRD() { - this.MEMPTR().Word = this.Bus.Address().Word = this.HL().Word; - ++this.MEMPTR(); + this.MEMPTR.Word = this.Bus.Address.Word = this.HL.Word; + ++this.MEMPTR.Word; var memory = this.Bus.Read(); - this.Bus.Write((byte)(PromoteNibble(this.A()) | HighNibble(memory))); - this.A() = (byte)(HigherNibble(this.A()) | LowerNibble(memory)); - this.F() = AdjustSZPXY(this.F(), this.A()); - this.F() = ClearFlag(this.F(), StatusBits.NF | StatusBits.HC); + this.Bus.Write((byte)(PromoteNibble(this.A) | HighNibble(memory))); + this.A = (byte)(HigherNibble(this.A) | LowerNibble(memory)); + this.F = AdjustSZPXY(this.F, this.A); + this.F = ClearFlag(this.F, StatusBits.NF | StatusBits.HC); } private void RLD() { - this.MEMPTR().Word = this.Bus.Address().Word = this.HL().Word; - ++this.MEMPTR(); + this.MEMPTR.Word = this.Bus.Address.Word = this.HL.Word; + ++this.MEMPTR.Word; var memory = this.Bus.Read(); - this.Bus.Write((byte)(PromoteNibble(memory) | LowNibble(this.A()))); - this.A() = (byte)(HigherNibble(this.A()) | HighNibble(memory)); - F() = AdjustSZPXY(this.F(), this.A()); - this.F() = ClearFlag(this.F(), StatusBits.NF | StatusBits.HC); + this.Bus.Write((byte)(PromoteNibble(memory) | LowNibble(this.A))); + this.A = (byte)(HigherNibble(this.A) | HighNibble(memory)); + this.F = AdjustSZPXY(this.F, this.A); + this.F = ClearFlag(this.F, StatusBits.NF | StatusBits.HC); } private void WritePort(byte port) { - this.MEMPTR().Word = this.Bus.Address().Word = new Register16(port, this.A()).Word; - this.Bus.Data = this.A(); + this.MEMPTR.Word = this.Bus.Address.Word = new Register16(port, this.A).Word; + this.Bus.Data = this.A; this.WritePort(); - ++this.MEMPTR().Low; + ++this.MEMPTR.Low; } private void WritePort() { - this.ports.Write(this.Bus.Address().Low, this.Bus.Data); + this.ports.Write(this.Bus.Address.Low, this.Bus.Data); } private byte ReadPort(byte port) { - this.MEMPTR().Word = this.Bus.Address().Word = new Register16(port, this.A()).Word; - ++this.MEMPTR().Low; + this.MEMPTR.Word = this.Bus.Address.Word = new Register16(port, this.A).Word; + ++this.MEMPTR.Low; return this.ReadPort(); } private byte ReadPort() { - return this.Bus.Data = this.ports.Read(this.Bus.Address().Low); + return this.Bus.Data = this.ports.Read(this.Bus.Address.Low); } } }