diff --git a/EightBit/IntelProcessor.cs b/EightBit/IntelProcessor.cs index 5d5cb29..a91ce17 100644 --- a/EightBit/IntelProcessor.cs +++ b/EightBit/IntelProcessor.cs @@ -194,6 +194,21 @@ namespace EightBit //// + protected abstract void MemoryUpdate(int ticks); + + protected abstract ref byte R(int r, AccessLevel access); + + protected void R(int r, byte value, int ticks = 1) + { + this.R(r, AccessLevel.WriteOnly) = value; + if (r == 6) + { + this.MemoryUpdate(ticks); + } + } + + //// + protected void Restart(byte address) { this.MEMPTR.Assign(address); diff --git a/Intel8080/Intel8080.cs b/Intel8080/Intel8080.cs index 27d6144..b8639ff 100644 --- a/Intel8080/Intel8080.cs +++ b/Intel8080/Intel8080.cs @@ -9,7 +9,7 @@ namespace Intel8080 using System; using System.Diagnostics; - public class Intel8080 : IntelProcessor + public sealed class Intel8080 : IntelProcessor { public Intel8080(Bus bus, InputOutput ports) : base(bus) @@ -97,27 +97,24 @@ namespace Intel8080 this._resetPending = true; } - private void MemoryUpdate(int ticks = 1) + protected override void MemoryUpdate(int ticks = 1) { Debug.Assert(ticks > 0, "Ticks must be greater than zero"); this.OnWritingMemory(); - this.Tick(ticks + 1); - base.MemoryWrite(); - this.Tick(); + this.Tick(ticks + 1); + base.MemoryWrite(); + this.Tick(); this.OnWrittenMemory(); } - protected override void MemoryWrite() - { - this.MemoryUpdate(); - } + protected override void MemoryWrite() => this.MemoryUpdate(); protected override void MemoryRead() { this.OnReadingMemory(); - this.Tick(2); - base.MemoryRead(); - this.Tick(); + this.Tick(2); + base.MemoryRead(); + this.Tick(); this.OnReadMemory(); this.Tick(); } @@ -245,7 +242,7 @@ namespace Intel8080 _ => throw new ArgumentOutOfRangeException(nameof(rp)), }; - private ref byte R(int r, AccessLevel access = AccessLevel.ReadOnly) + protected override ref byte R(int r, AccessLevel access = AccessLevel.ReadOnly) { switch (r) { @@ -283,15 +280,6 @@ namespace Intel8080 } } - private void R(int r, byte value, int ticks = 1) - { - this.R(r, AccessLevel.WriteOnly) = value; - if (r == 6) - { - this.MemoryUpdate(ticks); - } - } - private void Execute(int x, int y, int z, int p, int q) { var memoryY = y == 6; diff --git a/LR35902/LR35902.cs b/LR35902/LR35902.cs index 9a9a5ab..bb38254 100644 --- a/LR35902/LR35902.cs +++ b/LR35902/LR35902.cs @@ -337,7 +337,7 @@ namespace LR35902 private void Start() => this.Stopped = false; - private void MemoryUpdate(int ticks = 1) + protected override void MemoryUpdate(int ticks = 1) { Debug.Assert(ticks > 0, "Ticks must be greater than zero"); this.OnWritingMemory(); @@ -350,10 +350,7 @@ namespace LR35902 this.OnWrittenMemory(); } - protected override void MemoryWrite() - { - this.MemoryUpdate(); - } + protected override void MemoryWrite() => this.MemoryUpdate(); protected override void MemoryRead() { @@ -406,7 +403,7 @@ namespace LR35902 this.TickMachine(); } - private ref byte R(int r, AccessLevel access = AccessLevel.ReadOnly) + protected override ref byte R(int r, AccessLevel access = AccessLevel.ReadOnly) { switch (r) { @@ -444,15 +441,6 @@ namespace LR35902 } } - private void R(int r, byte value, int ticks = 1) - { - this.R(r, AccessLevel.WriteOnly) = value; - if (r == 6) - { - this.MemoryUpdate(ticks); - } - } - private Register16 RP(int rp) => rp switch { 0 => this.BC, diff --git a/M6502/Ricoh2A03.cs b/M6502/Ricoh2A03.cs index ef82bdb..48c0f6a 100644 --- a/M6502/Ricoh2A03.cs +++ b/M6502/Ricoh2A03.cs @@ -10,14 +10,8 @@ namespace M6502 { protected override void ARR() => this.ARR_b(this.Bus.Data); - protected override byte DecimalSUB(byte operand, int borrow) - { - return base.BinarySUB(operand, borrow); - } + protected override byte DecimalSUB(byte operand, int borrow) => base.BinarySUB(operand, borrow); - protected override byte DecimalADC(byte data) - { - return base.BinaryADC(data); - } + protected override byte DecimalADC(byte data) => base.BinaryADC(data); } } diff --git a/MC6809/MC6809.cs b/MC6809/MC6809.cs index 3ebff59..b5af411 100644 --- a/MC6809/MC6809.cs +++ b/MC6809/MC6809.cs @@ -27,13 +27,13 @@ namespace MC6809 public class MC6809 : BigEndianProcessor { - private const byte RESET_vector = 0xfe; // RESET vector - private const byte NMI_vector = 0xfc; // NMI vector - private const byte SWI_vector = 0xfa; // SWI vector - private const byte IRQ_vector = 0xf8; // IRQ vector - private const byte FIRQ_vector = 0xf6; // FIRQ vector - private const byte SWI2_vector = 0xf4; // SWI2 vector - private const byte SWI3_vector = 0xf2; // SWI3 vector + private const byte _vectorRESET = 0xfe; // RESET vector + private const byte _vectorNMI = 0xfc; // NMI vector + private const byte _vectorSWI = 0xfa; // SWI vector + private const byte _vectorIRQ = 0xf8; // IRQ vector + private const byte _vectorFIRQ = 0xf6; // FIRQ vector + private const byte _vectorSWI2 = 0xf4; // SWI2 vector + private const byte _vectorSWI3 = 0xf2; // SWI3 vector private byte _cc; private byte _dp; @@ -514,7 +514,7 @@ namespace MC6809 this.DP = 0; this.CC = SetBit(this.CC, StatusBits.IF); // Disable IRQ this.CC = SetBit(this.CC, StatusBits.FF); // Disable FIRQ - this.Bus.Address.Assign(RESET_vector, 0xff); + this.Bus.Address.Assign(_vectorRESET, 0xff); this.SwallowSpin(3); this.GetPagedInto(this.PC); this.SwallowRead(); @@ -529,7 +529,7 @@ namespace MC6809 this.SaveEntireRegisterState(); this.CC = SetBit(this.CC, StatusBits.IF); // Disable IRQ this.SwallowRead(); - this.GetPagedInto(0xff, IRQ_vector, this.PC); + this.GetPagedInto(0xff, _vectorIRQ, this.PC); this.SwallowRead(); } @@ -549,7 +549,7 @@ namespace MC6809 this.CC = SetBit(this.CC, StatusBits.IF); // Disable IRQ this.CC = SetBit(this.CC, StatusBits.FF); // Disable FIRQ this.SwallowRead(); - this.GetPagedInto(0xff, NMI_vector, this.PC); + this.GetPagedInto(0xff, _vectorNMI, this.PC); this.SwallowRead(); } @@ -563,7 +563,7 @@ namespace MC6809 this.CC = SetBit(this.CC, StatusBits.IF); // Disable IRQ this.CC = SetBit(this.CC, StatusBits.FF); // Disable FIRQ this.SwallowRead(); - this.GetPagedInto(0xff, FIRQ_vector, this.PC); + this.GetPagedInto(0xff, _vectorFIRQ, this.PC); this.SwallowRead(); } @@ -2174,7 +2174,7 @@ namespace MC6809 this.CC = SetBit(this.CC, StatusBits.IF | StatusBits.FF); // Disable IRQ / FIRQ Debug.Assert(this.FastInterruptMasked && this.InterruptMasked); this.SwallowRead(); - this.GetPagedInto(0xff, SWI_vector, this.EA); + this.GetPagedInto(0xff, _vectorSWI, this.EA); this.Jump(this.EA); this.SwallowRead(); } @@ -2184,7 +2184,7 @@ namespace MC6809 this.SaveEntireRegisterState(); this.SwallowRead(); - this.GetPagedInto(0xff, SWI2_vector, this.EA); + this.GetPagedInto(0xff, _vectorSWI2, this.EA); this.Jump(this.EA); this.SwallowRead(); } @@ -2193,7 +2193,7 @@ namespace MC6809 { this.SaveEntireRegisterState(); this.SwallowRead(); - this.GetPagedInto(0xff, SWI3_vector, this.EA); + this.GetPagedInto(0xff, _vectorSWI3, this.EA); this.Jump(this.EA); this.SwallowRead(); } diff --git a/Z80/Z80.cs b/Z80/Z80.cs index 54e8866..d5a46ba 100644 --- a/Z80/Z80.cs +++ b/Z80/Z80.cs @@ -468,18 +468,18 @@ namespace Z80 #endregion - private void MemoryUpdate(int ticks = 1) + protected override void MemoryUpdate(int ticks = 1) { Debug.Assert(ticks > 0, "Ticks must be greater than zero"); this.OnWritingMemory(); - this.Tick(ticks); - this.LowerMREQ(); - this.LowerWR(); - this.Tick(); - base.MemoryWrite(); - this.RaiseWR(); - this.RaiseMREQ(); - this.Tick(); + this.Tick(ticks); + this.LowerMREQ(); + this.LowerWR(); + this.Tick(); + base.MemoryWrite(); + this.RaiseWR(); + this.RaiseMREQ(); + this.Tick(); this.OnWrittenMemory(); } @@ -499,18 +499,18 @@ namespace Z80 protected override void MemoryRead() { this.OnReadingMemory(); - this.Tick(); - this.LowerMREQ(); - this.LowerRD(); - this.Tick(); - base.MemoryRead(); - this.RaiseRD(); - this.RaiseMREQ(); - if (this.M1.Lowered()) - { - this.RefreshMemory(); - } - this.Tick(); + this.Tick(); + this.LowerMREQ(); + this.LowerRD(); + this.Tick(); + base.MemoryRead(); + this.RaiseRD(); + this.RaiseMREQ(); + if (this.M1.Lowered()) + { + this.RefreshMemory(); + } + this.Tick(); this.OnReadMemory(); } @@ -749,7 +749,7 @@ namespace Z80 _ => throw new ArgumentOutOfRangeException(nameof(rp)), }; - private ref byte R(int r, AccessLevel access = AccessLevel.ReadOnly) + protected override ref byte R(int r, AccessLevel access = AccessLevel.ReadOnly) { switch (r) { @@ -795,15 +795,6 @@ namespace Z80 } } - private void R(int r, byte value, int ticks = 1) - { - this.R(r, AccessLevel.WriteOnly) = value; - if (r == 6) - { - this.MemoryUpdate(ticks); - } - } - private ref byte R2(int r) { switch (r)