From f093bf1e53b85d75bb2d5da6abb9a69652a94ba9 Mon Sep 17 00:00:00 2001 From: Adrian Conlon Date: Sat, 9 May 2026 14:11:07 +0100 Subject: [PATCH] Work in progress --- MC6809/MC6809.cs | 934 ++++++++++++++++++++++++++++------------------- 1 file changed, 555 insertions(+), 379 deletions(-) diff --git a/MC6809/MC6809.cs b/MC6809/MC6809.cs index 19bb2f8..8d6fff4 100644 --- a/MC6809/MC6809.cs +++ b/MC6809/MC6809.cs @@ -4,6 +4,7 @@ namespace MC6809 { using EightBit; + using System.Diagnostics; // Uses some information from: // http://www.cpu-world.com/Arch/6809.html @@ -188,7 +189,11 @@ namespace MC6809 } } - private void SYNC() => this.Halt(); + private void SYNC() + { + this.SwallowCurrent(); + this.Halt(); + } public void Halt() { @@ -365,6 +370,8 @@ namespace MC6809 public int EntireRegisterSet => this.CC & (byte)StatusBits.EF; + public bool E => this.EntireRegisterSet != 0; + public int FastInterruptMasked => this.CC & (byte)StatusBits.FF; public int HalfCarry => this.CC & (byte)StatusBits.HF; @@ -499,7 +506,6 @@ namespace MC6809 this.CC = SetBit(this.CC, StatusBits.FF); // Disable FIRQ this.GetWordPaged(0xff, RESET_vector); this.Jump(this.Intermediate); - this.Tick(10); } protected override void HandleINT() @@ -511,7 +517,6 @@ namespace MC6809 this.CC = SetBit(this.CC, StatusBits.IF); // Disable IRQ this.GetWordPaged(0xff, IRQ_vector); this.Jump(this.Intermediate); - this.Tick(12); } private void HandleHALT() @@ -530,7 +535,6 @@ namespace MC6809 this.CC = SetBit(this.CC, StatusBits.FF); // Disable FIRQ this.GetWordPaged(0xff, NMI_vector); this.Jump(this.Intermediate); - this.Tick(12); } private void HandleFIRQ() @@ -543,7 +547,6 @@ namespace MC6809 this.CC = SetBit(this.CC, StatusBits.FF); // Disable FIRQ this.GetWordPaged(0xff, FIRQ_vector); this.Jump(this.Intermediate); - this.Tick(12); } #endregion @@ -552,12 +555,14 @@ namespace MC6809 protected override void BusWrite() { + this.Tick(); this.LowerRW(); base.BusWrite(); } protected override byte BusRead() { + this.Tick(); this.RaiseRW(); return base.BusRead(); } @@ -594,10 +599,8 @@ namespace MC6809 private Register16 PopWord(Register16 stack) { - this.Pop(stack); - this.Intermediate.High = this.Bus.Data; - this.Pop(stack); - this.Intermediate.Low = this.Bus.Data; + this.Intermediate.High = this.Pop(stack); + this.Intermediate.Low = this.Pop(stack); return this.Intermediate; } @@ -607,8 +610,7 @@ namespace MC6809 private void RelativeByteAddress() { - this.FetchByte(); - var offset = (sbyte)this.Bus.Data; + var offset = (sbyte)this.FetchByte(); this.Intermediate.Word = (ushort)(this.PC.Word + offset); } @@ -619,11 +621,7 @@ namespace MC6809 this.Intermediate.Word = (ushort)(this.PC.Word + offset); } - private void DirectAddress() - { - this.FetchByte(); - this.Intermediate.Assign(this.Bus.Data, this.DP); - } + private void DirectAddress() => this.Intermediate.Assign(this.FetchByte(), this.DP); private void ExtendedAddress() => this.FetchWord(); @@ -641,8 +639,7 @@ namespace MC6809 private void IndexedAddress() { - this.FetchByte(); - var type = this.Bus.Data; + var type = this.FetchByte(); var r = this.RR((type & (byte)(Bits.Bit6 | Bits.Bit5)) >> 5); if ((type & (byte)Bits.Bit7) != 0) @@ -650,61 +647,71 @@ namespace MC6809 switch (type & (byte)Mask.Four) { case 0b0000: // ,R+ - this.Tick(2); this.Intermediate.Assign(r); r.Word++; + this.SwallowCurrent(); + this.SwallowRead(2); break; case 0b0001: // ,R++ - this.Tick(3); this.Intermediate.Assign(r); r.Word += 2; + this.SwallowCurrent(); + this.SwallowRead(3); break; case 0b0010: // ,-R - this.Tick(2); --r.Word; this.Intermediate.Assign(r); + this.SwallowCurrent(); + this.SwallowRead(2); break; case 0b0011: // ,--R - this.Tick(3); r.Word -= 2; this.Intermediate.Assign(r); + this.SwallowCurrent(); + this.SwallowRead(3); break; case 0b0100: // ,R this.Intermediate.Assign(r); + this.SwallowCurrent(); break; case 0b0101: // B,R - this.Tick(); this.Intermediate.Word = (ushort)(r.Word + (sbyte)this.B); + this.SwallowCurrent(); + this.SwallowRead(); break; case 0b0110: // A,R - this.Tick(); this.Intermediate.Word = (ushort)(r.Word + (sbyte)this.A); + this.SwallowCurrent(); + this.SwallowRead(); break; case 0b1000: // n,R (eight-bit) - this.Tick(); this.FetchByte(); this.Intermediate.Word = (ushort)(r.Word + (sbyte)this.Bus.Data); + this.SwallowRead(); break; case 0b1001: // n,R (sixteen-bit) - this.Tick(4); this.FetchWord(); this.Intermediate.Word += r.Word; + this.SwallowCurrent(); + this.SwallowRead(2); break; case 0b1011: // D,R - this.Tick(4); this.Intermediate.Word = (ushort)(r.Word + this.D.Word); + this.SwallowCurrent(3); + this.SwallowRead(2); break; case 0b1100: // n,PCR (eight-bit) - this.Tick(); this.RelativeByteAddress(); + this.SwallowRead(); break; case 0b1101: // n,PCR (sixteen-bit) - this.Tick(2); this.RelativeWordAddress(); + this.SwallowCurrent(); + this.SwallowRead(3); break; case 0b1111: // [n] - this.Tick(2); - this.ExtendedAddress(); + this.FetchWord(); + this.SwallowCurrent(); break; default: throw new InvalidOperationException("Invalid index type"); @@ -713,16 +720,17 @@ namespace MC6809 var indirect = type & (byte)Bits.Bit4; if (indirect != 0) { - this.Tick(3); var address = this.Intermediate; this.GetWord(address); + this.SwallowRead(); } } else { // EA = ,R + 5-bit offset - this.Tick(); this.Intermediate.Word = (ushort)(r.Word + SignExtend(5, (byte)(type & (byte)Mask.Five))); + this.SwallowCurrent(); + this.SwallowRead(); } } @@ -763,7 +771,9 @@ namespace MC6809 private void ExtendedWord() { this.ExtendedAddress(); + this.SwallowRead(); this.GetWord(this.Intermediate); + this.SwallowRead(); } #endregion @@ -871,7 +881,7 @@ namespace MC6809 this.RelativeWordAddress(); if (this.Branch(this.Intermediate, condition)) { - this.Tick(); + //this.Tick(); } } @@ -901,64 +911,66 @@ namespace MC6809 this.SaveRegisterState(); } - private void SaveRegisterState() => this.PSH(this.S, this.EntireRegisterSet != 0 ? (byte)Mask.Eight : (byte)0b10000001); + private void SaveRegisterState() => this.PSH(this.S, this.E ? (byte)Mask.Eight : (byte)0b10000001); - private void RestoreRegisterState() => this.PUL(this.S, this.EntireRegisterSet != 0 ? (byte)Mask.Eight : (byte)0b10000001); + private void RestoreRegisterState() => this.PUL(this.S, this.E ? (byte)Mask.Eight : (byte)0b10000001); private void PSHS() => this.PSH(this.S); private void PSHU() => this.PSH(this.U); - private void PSH(Register16 stack) => this.PSH(stack, this.Bus.Data); - - private void PSH(Register16 stack, byte data) + private void PSH(Register16 stack) { - if ((data & (byte)Bits.Bit7) != 0) + this.SwallowRead(2); + this.SwallowPop(stack); + this.PSH(stack, this.Bus.Data); + } + + private void PSH(Register16 stack, byte control) + { + // Reverse order of PUL + + // Eight-bit registers + + if ((control & (byte)Bits.Bit7) != 0) { - this.Tick(2); this.Push(stack, this.PC); } - if ((data & (byte)Bits.Bit6) != 0) + if ((control & (byte)Bits.Bit6) != 0) { - this.Tick(2); - // Pushing to the S stack means we must be pushing U this.Push(stack, ReferenceEquals(stack, this.S) ? this.U : this.S); } - if ((data & (byte)Bits.Bit5) != 0) + if ((control & (byte)Bits.Bit5) != 0) { - this.Tick(2); this.Push(stack, this.Y); } - if ((data & (byte)Bits.Bit4) != 0) + if ((control & (byte)Bits.Bit4) != 0) { - this.Tick(2); this.Push(stack, this.X); } - if ((data & (byte)Bits.Bit3) != 0) + // Eight-bit registers + + if ((control & (byte)Bits.Bit3) != 0) { - this.Tick(); this.Push(stack, this.DP); } - if ((data & (byte)Bits.Bit2) != 0) + if ((control & (byte)Bits.Bit2) != 0) { - this.Tick(); this.Push(stack, this.B); } - if ((data & (byte)Bits.Bit1) != 0) + if ((control & (byte)Bits.Bit1) != 0) { - this.Tick(); this.Push(stack, this.A); } - if ((data & (byte)Bits.Bit0) != 0) + if ((control & (byte)Bits.Bit0) != 0) { - this.Tick(); this.Push(stack, this.CC); } } @@ -966,61 +978,59 @@ namespace MC6809 private void PULU() => this.PUL(this.U); private void PULS() => this.PUL(this.S); - private void PUL(Register16 stack) => this.PUL(stack, this.Bus.Data); - - private void PUL(Register16 stack, byte data) + private void PUL(Register16 stack) { - if ((data & (byte)Bits.Bit0) != 0) + this.SwallowRead(2); + this.PUL(stack, this.Bus.Data); + this.SwallowPop(stack); + } + + private void PUL(Register16 stack, byte control) + { + // Reverse order of PSH + + // Eight-bit registers + + if ((control & (byte)Bits.Bit0) != 0) { - this.Tick(); - this.Pop(stack); - this.CC = this.Bus.Data; + this.CC = this.Pop(stack); } - if ((data & (byte)Bits.Bit1) != 0) + if ((control & (byte)Bits.Bit1) != 0) { - this.Tick(); - this.Pop(stack); - this.A = this.Bus.Data; + this.A = this.Pop(stack); } - if ((data & (byte)Bits.Bit2) != 0) + if ((control & (byte)Bits.Bit2) != 0) { - this.Tick(); - this.Pop(stack); - this.B = this.Bus.Data; + this.B = this.Pop(stack); } - if ((data & (byte)Bits.Bit3) != 0) + if ((control & (byte)Bits.Bit3) != 0) { - this.Tick(); - this.Pop(stack); - this.DP = this.Bus.Data; + this.DP = this.Pop(stack); } - if ((data & (byte)Bits.Bit4) != 0) + // Sixteen-bit registers + + if ((control & (byte)Bits.Bit4) != 0) { - this.Tick(2); this.X.Assign(this.PopWord(stack)); } - if ((data & (byte)Bits.Bit5) != 0) + if ((control & (byte)Bits.Bit5) != 0) { - this.Tick(2); this.Y.Assign(this.PopWord(stack)); } - if ((data & (byte)Bits.Bit6) != 0) + if ((control & (byte)Bits.Bit6) != 0) { - this.Tick(2); - // Pulling from the S stack means we must be pulling U (ReferenceEquals(stack, this.S) ? this.U : this.S).Assign(this.PopWord(stack)); } - if ((data & (byte)Bits.Bit7) != 0) + if ((control & (byte)Bits.Bit7) != 0) { - this.Tick(2); this.PC.Assign(this.PopWord(stack)); } } @@ -1100,6 +1110,8 @@ namespace MC6809 (leftRegister, rightRegister) = (rightRegister, leftRegister); } } + + this.SwallowRead(6); } private void TFR() @@ -1136,10 +1148,36 @@ namespace MC6809 this.ReferenceTransfer8(destinationSpecifier) = sourceRegister; } } + + this.SwallowRead(4); } #endregion + #region Cycle wastage + + private void SwallowRead(int ticks = 1) + { + for (int i = 0; i < ticks; i++) + { + _ = this.MemoryRead(0xff, 0xff); + } + } + + private void SwallowFetch() => _ = this.FetchByte(); + + private void SwallowCurrent(int ticks = 1) + { + for (int i = 0; i < ticks; i++) + { + _ = this.MemoryRead(this.PC); + } + } + + private void SwallowPop(Register16 stack) => _ = this.MemoryRead(stack); + + #endregion + #region Instruction execution public override void PoweredStep() @@ -1196,364 +1234,364 @@ namespace MC6809 private void ExecuteUnprefixed() { - switch (this.OpCode) + switch (this.OpCode) { case 0x10: this.Prefix10(); break; case 0x11: this.Prefix11(); break; // ABX - case 0x3a: this.Tick(3); this.ABX(); break; // ABX (inherent) + case 0x3a: this.ABX(); Debug.Assert(this.Cycles == 3); break; // ABX (inherent) // ADC - case 0x89: this.Tick(2); this.ImmediateByte(); this.ADCA(); break; // ADC (ADCA immediate) - case 0x99: this.Tick(4); this.DirectByte(); this.ADCA(); break; // ADC (ADCA direct) - case 0xa9: this.Tick(4); this.IndexedByte(); this.ADCA(); break; // ADC (ADCA indexed) - case 0xb9: this.Tick(4); this.ExtendedByte(); this.ADCA(); break; // ADC (ADCA extended) + case 0x89: this.ImmediateByte(); this.ADCA(); Debug.Assert(this.Cycles == 2); break; // ADC (ADCA immediate) + case 0x99: this.DirectByte(); this.ADCA(); Debug.Assert(this.Cycles == 4); break; // ADC (ADCA direct) + case 0xa9: this.IndexedByte(); this.ADCA(); Debug.Assert(this.Cycles >= 4); break; // ADC (ADCA indexed) + case 0xb9: this.ExtendedByte(); this.ADCA(); Debug.Assert(this.Cycles == 5); break; // ADC (ADCA extended) - case 0xc9: this.Tick(2); this.ImmediateByte(); this.ADCB(); break; // ADC (ADCB immediate) - case 0xd9: this.Tick(4); this.DirectByte(); this.ADCB(); break; // ADC (ADCB direct) - case 0xe9: this.Tick(4); this.IndexedByte(); this.ADCB(); break; // ADC (ADCB indexed) - case 0xf9: this.Tick(4); this.ExtendedByte(); this.ADCB(); break; // ADC (ADCB extended) + case 0xc9: this.ImmediateByte(); this.ADCB(); Debug.Assert(this.Cycles == 2); break; // ADC (ADCB immediate) + case 0xd9: this.DirectByte(); this.ADCB(); Debug.Assert(this.Cycles == 4); break; // ADC (ADCB direct) + case 0xe9: this.IndexedByte(); this.ADCB(); Debug.Assert(this.Cycles >= 4); break; // ADC (ADCB indexed) + case 0xf9: this.ExtendedByte(); this.ADCB(); Debug.Assert(this.Cycles == 5); break; // ADC (ADCB extended) // ADD - case 0x8b: this.Tick(2); this.ImmediateByte(); this.ADDA(); break; // ADD (ADDA immediate) - case 0x9b: this.Tick(4); this.DirectByte(); this.ADDA(); break; // ADD (ADDA direct) - case 0xab: this.Tick(4); this.IndexedByte(); this.ADDA(); break; // ADD (ADDA indexed) - case 0xbb: this.Tick(5); this.ExtendedByte(); this.ADDA(); break; // ADD (ADDA extended) + case 0x8b: this.ImmediateByte(); this.ADDA(); Debug.Assert(this.Cycles == 2); break; // ADD (ADDA immediate) + case 0x9b: this.DirectByte(); this.ADDA(); Debug.Assert(this.Cycles == 4); break; // ADD (ADDA direct) + case 0xab: this.IndexedByte(); this.ADDA(); Debug.Assert(this.Cycles >= 4); break; // ADD (ADDA indexed) + case 0xbb: this.ExtendedByte(); this.ADDA(); Debug.Assert(this.Cycles == 5); break; // ADD (ADDA extended) - case 0xcb: this.Tick(2); this.ImmediateByte(); this.ADDB(); break; // ADD (ADDB immediate) - case 0xdb: this.Tick(4); this.DirectByte(); this.ADDB(); break; // ADD (ADDB direct) - case 0xeb: this.Tick(4); this.IndexedByte(); this.ADDB(); break; // ADD (ADDB indexed) - case 0xfb: this.Tick(5); this.ExtendedByte(); this.ADDB(); break; // ADD (ADDB extended) + case 0xcb: this.ImmediateByte(); this.ADDB(); Debug.Assert(this.Cycles == 2); break; // ADD (ADDB immediate) + case 0xdb: this.DirectByte(); this.ADDB(); Debug.Assert(this.Cycles == 4); break; // ADD (ADDB direct) + case 0xeb: this.IndexedByte(); this.ADDB(); Debug.Assert(this.Cycles >= 4); break; // ADD (ADDB indexed) + case 0xfb: this.ExtendedByte(); this.ADDB(); Debug.Assert(this.Cycles == 5); break; // ADD (ADDB extended) - case 0xc3: this.Tick(4); this.ImmediateWord(); this.ADDD(); break; // ADD (ADDD immediate) - case 0xd3: this.Tick(6); this.DirectWord(); this.ADDD(); break; // ADD (ADDD direct) - case 0xe3: this.Tick(6); this.IndexedWord(); this.ADDD(); break; // ADD (ADDD indexed) - case 0xf3: this.Tick(7); this.ExtendedWord(); this.ADDD(); break; // ADD (ADDD extended) + case 0xc3: this.ImmediateWord(); this.ADDD(); Debug.Assert(this.Cycles == 4); break; // ADD (ADDD immediate) + case 0xd3: this.DirectWord(); this.ADDD(); Debug.Assert(this.Cycles == 6); break; // ADD (ADDD direct) + case 0xe3: this.IndexedWord(); this.ADDD(); Debug.Assert(this.Cycles >= 6); break; // ADD (ADDD indexed) + case 0xf3: this.ExtendedWord(); this.ADDD(); Debug.Assert(this.Cycles == 7); break; // ADD (ADDD extended) // AND - case 0x84: this.Tick(2); this.ImmediateByte(); this.ANDA(); break; // AND (ANDA immediate) - case 0x94: this.Tick(4); this.DirectByte(); this.ANDA(); break; // AND (ANDA direct) - case 0xa4: this.Tick(4); this.IndexedByte(); this.ANDA(); break; // AND (ANDA indexed) - case 0xb4: this.Tick(5); this.ExtendedByte(); this.ANDA(); break; // AND (ANDA extended) + case 0x84: this.ImmediateByte(); this.ANDA(); Debug.Assert(this.Cycles == 2); break; // AND (ANDA immediate) + case 0x94: this.DirectByte(); this.ANDA(); Debug.Assert(this.Cycles == 4); break; // AND (ANDA direct) + case 0xa4: this.IndexedByte(); this.ANDA(); Debug.Assert(this.Cycles >= 4); break; // AND (ANDA indexed) + case 0xb4: this.ExtendedByte(); this.ANDA(); Debug.Assert(this.Cycles == 5); break; // AND (ANDA extended) - case 0xc4: this.Tick(2); this.ImmediateByte(); this.ANDB(); break; // AND (ANDB immediate) - case 0xd4: this.Tick(4); this.DirectByte(); this.ANDB(); break; // AND (ANDB direct) - case 0xe4: this.Tick(4); this.IndexedByte(); this.ANDB(); break; // AND (ANDB indexed) - case 0xf4: this.Tick(5); this.ExtendedByte(); this.ANDB(); break; // AND (ANDB extended) + case 0xc4: this.ImmediateByte(); this.ANDB(); Debug.Assert(this.Cycles == 2); break; // AND (ANDB immediate) + case 0xd4: this.DirectByte(); this.ANDB(); Debug.Assert(this.Cycles == 4); break; // AND (ANDB direct) + case 0xe4: this.IndexedByte(); this.ANDB(); Debug.Assert(this.Cycles >= 4); break; // AND (ANDB indexed) + case 0xf4: this.ExtendedByte(); this.ANDB(); Debug.Assert(this.Cycles == 5); break; // AND (ANDB extended) - case 0x1c: this.Tick(3); this.ImmediateByte(); this.ANDCC(); break; // AND (ANDCC immediate) + case 0x1c: this.ImmediateByte(); this.ANDCC(); Debug.Assert(this.Cycles == 3); break; // AND (ANDCC immediate) // ASL/LSL - case 0x08: this.Tick(6); this.DirectByte(); this.ASL(); break; // ASL (direct) - case 0x48: this.Tick(2); this.ASLA(); break; // ASL (ASLA inherent) - case 0x58: this.Tick(2); this.ASLB(); break; // ASL (ASLB inherent) - case 0x68: this.Tick(6); this.IndexedByte(); this.ASL(); break; // ASL (indexed) - case 0x78: this.Tick(7); this.ExtendedByte(); this.ASL(); break; // ASL (extended) + case 0x08: this.DirectByte(); this.ASL(); Debug.Assert(this.Cycles == 6); break; // ASL (direct) + case 0x48: this.ASLA(); Debug.Assert(this.Cycles == 2); break; // ASL (ASLA inherent) + case 0x58: this.ASLB(); Debug.Assert(this.Cycles == 2); break; // ASL (ASLB inherent) + case 0x68: this.IndexedByte(); this.ASL(); Debug.Assert(this.Cycles >= 6); break; // ASL (indexed) + case 0x78: this.ExtendedByte(); this.ASL(); Debug.Assert(this.Cycles == 7); break; // ASL (extended) // ASR - case 0x07: this.Tick(6); this.DirectByte(); this.ASR(); break; // ASR (direct) - case 0x47: this.Tick(2); this.ASRA(); break; // ASR (ASRA inherent) - case 0x57: this.Tick(2); this.ASRB(); break; // ASR (ASRB inherent) - case 0x67: this.Tick(6); this.IndexedByte(); this.ASR(); break; // ASR (indexed) - case 0x77: this.Tick(7); this.ExtendedByte(); this.ASR(); break; // ASR (extended) + case 0x07: this.DirectByte(); this.ASR(); break; // ASR (direct) + case 0x47: this.ASRA(); break; // ASR (ASRA inherent) + case 0x57: this.ASRB(); break; // ASR (ASRB inherent) + case 0x67: this.IndexedByte(); this.ASR(); break; // ASR (indexed) + case 0x77: this.ExtendedByte(); this.ASR(); break; // ASR (extended) // BIT - case 0x85: this.Tick(2); this.ImmediateByte(); this.BITA(); break; // BIT (BITA immediate) - case 0x95: this.Tick(4); this.DirectByte(); this.BITA(); break; // BIT (BITA direct) - case 0xa5: this.Tick(4); this.IndexedByte(); this.BITA(); break; // BIT (BITA indexed) - case 0xb5: this.Tick(5); this.ExtendedByte(); this.BITA(); break; // BIT (BITA extended) + case 0x85: this.ImmediateByte(); this.BITA(); break; // BIT (BITA immediate) + case 0x95: this.DirectByte(); this.BITA(); break; // BIT (BITA direct) + case 0xa5: this.IndexedByte(); this.BITA(); break; // BIT (BITA indexed) + case 0xb5: this.ExtendedByte(); this.BITA(); break; // BIT (BITA extended) - case 0xc5: this.Tick(2); this.ImmediateByte(); this.BITB(); break; // BIT (BITB immediate) - case 0xd5: this.Tick(4); this.DirectByte(); this.BITB(); break; // BIT (BITB direct) - case 0xe5: this.Tick(4); this.IndexedByte(); this.BITB(); break; // BIT (BITB indexed) - case 0xf5: this.Tick(5); this.ExtendedByte(); this.BITB(); break; // BIT (BITB extended) + case 0xc5: this.ImmediateByte(); this.BITB(); break; // BIT (BITB immediate) + case 0xd5: this.DirectByte(); this.BITB(); break; // BIT (BITB direct) + case 0xe5: this.IndexedByte(); this.BITB(); break; // BIT (BITB indexed) + case 0xf5: this.ExtendedByte(); this.BITB(); break; // BIT (BITB extended) // CLR - case 0x0f: this.Tick(6); this.DirectAddress(); this.CLR(); break; // CLR (direct) - case 0x4f: this.Tick(2); this.CLRA(); break; // CLR (CLRA implied) - case 0x5f: this.Tick(2); this.CLRB(); break; // CLR (CLRB implied) - case 0x6f: this.Tick(6); this.IndexedAddress(); this.CLR(); break; // CLR (indexed) - case 0x7f: this.Tick(7); this.ExtendedAddress(); this.CLR(); break; // CLR (extended) + case 0x0f: this.DirectAddress(); this.CLR(); break; // CLR (direct) + case 0x4f: this.CLRA(); Debug.Assert(this.Cycles == 2); break; // CLR (CLRA implied) + case 0x5f: this.CLRB(); Debug.Assert(this.Cycles == 2); break; // CLR (CLRB implied) + case 0x6f: this.IndexedAddress(); this.CLR(); break; // CLR (indexed) + case 0x7f: this.ExtendedAddress(); this.CLR(); break; // CLR (extended) // CMP // CMPA - case 0x81: this.Tick(2); this.ImmediateByte(); this.CMPA(); break; // CMP (CMPA, immediate) - case 0x91: this.Tick(4); this.DirectByte(); this.CMPA(); break; // CMP (CMPA, direct) - case 0xa1: this.Tick(4); this.IndexedByte(); this.CMPA(); break; // CMP (CMPA, indexed) - case 0xb1: this.Tick(5); this.ExtendedByte(); this.CMPA(); break; // CMP (CMPA, extended) + case 0x81: this.ImmediateByte(); this.CMPA(); break; // CMP (CMPA, immediate) + case 0x91: this.DirectByte(); this.CMPA(); break; // CMP (CMPA, direct) + case 0xa1: this.IndexedByte(); this.CMPA(); break; // CMP (CMPA, indexed) + case 0xb1: this.ExtendedByte(); this.CMPA(); break; // CMP (CMPA, extended) // CMPB - case 0xc1: this.Tick(2); this.ImmediateByte(); this.CMPB(); break; // CMP (CMPB, immediate) - case 0xd1: this.Tick(4); this.DirectByte(); this.CMPB(); break; // CMP (CMPB, direct) - case 0xe1: this.Tick(4); this.IndexedByte(); this.CMPB(); break; // CMP (CMPB, indexed) - case 0xf1: this.Tick(5); this.ExtendedByte(); this.CMPB(); break; // CMP (CMPB, extended) + case 0xc1: this.ImmediateByte(); this.CMPB(); break; // CMP (CMPB, immediate) + case 0xd1: this.DirectByte(); this.CMPB(); break; // CMP (CMPB, direct) + case 0xe1: this.IndexedByte(); this.CMPB(); break; // CMP (CMPB, indexed) + case 0xf1: this.ExtendedByte(); this.CMPB(); break; // CMP (CMPB, extended) // CMPX - case 0x8c: this.Tick(4); this.ImmediateWord(); this.CMPX(); break; // CMP (CMPX, immediate) - case 0x9c: this.Tick(6); this.DirectWord(); this.CMPX(); break; // CMP (CMPX, direct) - case 0xac: this.Tick(6); this.IndexedWord(); this.CMPX(); break; // CMP (CMPX, indexed) - case 0xbc: this.Tick(7); this.ExtendedWord(); this.CMPX(); break; // CMP (CMPX, extended) + case 0x8c: this.ImmediateWord(); this.CMPX(); break; // CMP (CMPX, immediate) + case 0x9c: this.DirectWord(); this.CMPX(); break; // CMP (CMPX, direct) + case 0xac: this.IndexedWord(); this.CMPX(); break; // CMP (CMPX, indexed) + case 0xbc: this.ExtendedWord(); this.CMPX(); break; // CMP (CMPX, extended) // COM - case 0x03: this.Tick(6); this.DirectByte(); this.COM(); break; // COM (direct) - case 0x43: this.Tick(2); this.COMA(); break; // COM (COMA inherent) - case 0x53: this.Tick(2); this.COMB(); break; // COM (COMB inherent) - case 0x63: this.Tick(6); this.IndexedByte(); this.COM(); break; // COM (indexed) - case 0x73: this.Tick(7); this.ExtendedByte(); this.COM(); break; // COM (extended) + case 0x03: this.DirectByte(); this.COM(); break; // COM (direct) + case 0x43: this.COMA(); Debug.Assert(this.Cycles == 2); break; // COM (COMA inherent) + case 0x53: this.COMB(); Debug.Assert(this.Cycles == 2); break; // COM (COMB inherent) + case 0x63: this.IndexedByte(); this.COM(); break; // COM (indexed) + case 0x73: this.ExtendedByte(); this.COM(); break; // COM (extended) // CWAI - case 0x3c: this.Tick(11); this.ImmediateByte(); this.CWAI(); break; // CWAI (direct) + case 0x3c: this.CWAI(); break; // CWAI (direct) // DAA - case 0x19: this.Tick(2); this.DAA(); break; // DAA (inherent) + case 0x19: this.DAA(); Debug.Assert(this.Cycles == 2); break; // DAA (inherent) // DEC - case 0x0a: this.Tick(6); this.DirectByte(); this.DEC(); break; // DEC (direct) - case 0x4a: this.Tick(2); this.DECA(); break; // DEC (DECA inherent) - case 0x5a: this.Tick(2); this.DECB(); break; // DEC (DECB inherent) - case 0x6a: this.Tick(6); this.IndexedByte(); this.DEC(); break; // DEC (indexed) - case 0x7a: this.Tick(7); this.ExtendedByte(); this.DEC(); break; // DEC (extended) + case 0x0a: this.DirectByte(); this.DEC(); break; // DEC (direct) + case 0x4a: this.DECA(); Debug.Assert(this.Cycles == 2); break; // DEC (DECA inherent) + case 0x5a: this.DECB(); Debug.Assert(this.Cycles == 2); break; // DEC (DECB inherent) + case 0x6a: this.IndexedByte(); this.DEC(); break; // DEC (indexed) + case 0x7a: this.ExtendedByte(); this.DEC(); break; // DEC (extended) // EOR // EORA - case 0x88: this.Tick(2); this.ImmediateByte(); this.EORA(); break; // EOR (EORA immediate) - case 0x98: this.Tick(4); this.DirectByte(); this.EORA(); break; // EOR (EORA direct) - case 0xa8: this.Tick(4); this.IndexedByte(); this.EORA(); break; // EOR (EORA indexed) - case 0xb8: this.Tick(5); this.ExtendedByte(); this.EORA(); break; // EOR (EORA extended) + case 0x88: this.ImmediateByte(); this.EORA(); break; // EOR (EORA immediate) + case 0x98: this.DirectByte(); this.EORA(); break; // EOR (EORA direct) + case 0xa8: this.IndexedByte(); this.EORA(); break; // EOR (EORA indexed) + case 0xb8: this.ExtendedByte(); this.EORA(); break; // EOR (EORA extended) // EORB - case 0xc8: this.Tick(2); this.ImmediateByte(); this.EORB(); break; // EOR (EORB immediate) - case 0xd8: this.Tick(4); this.DirectByte(); this.EORB(); break; // EOR (EORB direct) - case 0xe8: this.Tick(4); this.IndexedByte(); this.EORB(); break; // EOR (EORB indexed) - case 0xf8: this.Tick(5); this.ExtendedByte(); this.EORB(); break; // EOR (EORB extended) + case 0xc8: this.ImmediateByte(); this.EORB(); break; // EOR (EORB immediate) + case 0xd8: this.DirectByte(); this.EORB(); break; // EOR (EORB direct) + case 0xe8: this.IndexedByte(); this.EORB(); break; // EOR (EORB indexed) + case 0xf8: this.ExtendedByte(); this.EORB(); break; // EOR (EORB extended) // EXG - case 0x1e: this.Tick(8); this.ImmediateByte(); this.EXG(); break; // EXG (R1,R2 immediate) + case 0x1e: this.ImmediateByte(); this.EXG(); Debug.Assert(this.Cycles == 8); break; // EXG (R1,R2 immediate) // INC - case 0x0c: this.Tick(6); this.DirectByte(); this.INC(); break; // INC (direct) - case 0x4c: this.Tick(2); this.INCA(); break; // INC (INCA inherent) - case 0x5c: this.Tick(2); this.INCB(); break; // INC (INCB inherent) - case 0x6c: this.Tick(6); this.IndexedByte(); this.INC(); break; // INC (indexed) - case 0x7c: this.Tick(7); this.ExtendedByte(); this.INC(); break; // INC (extended) + case 0x0c: this.DirectByte(); this.INC(); break; // INC (direct) + case 0x4c: this.INCA(); Debug.Assert(this.Cycles == 2); break; // INC (INCA inherent) + case 0x5c: this.INCB(); Debug.Assert(this.Cycles == 2); break; // INC (INCB inherent) + case 0x6c: this.IndexedByte(); this.INC(); break; // INC (indexed) + case 0x7c: this.ExtendedByte(); this.INC(); break; // INC (extended) // JMP - case 0x0e: this.Tick(6); this.DirectAddress(); this.JMP(); break; // JMP (direct) - case 0x6e: this.Tick(6); this.IndexedAddress(); this.JMP(); break; // JMP (indexed) - case 0x7e: this.Tick(7); this.ExtendedAddress(); this.JMP(); break; // JMP (extended) + case 0x0e: this.DirectAddress(); this.JMP(); break; // JMP (direct) + case 0x6e: this.IndexedAddress(); this.JMP(); break; // JMP (indexed) + case 0x7e: this.ExtendedAddress(); this.JMP(); break; // JMP (extended) // JSR - case 0x9d: this.Tick(6); this.DirectAddress(); this.JSR(); break; // JSR (direct) - case 0xad: this.Tick(6); this.IndexedAddress(); this.JSR(); break; // JSR (indexed) - case 0xbd: this.Tick(7); this.ExtendedAddress(); this.JSR(); break; // JSR (extended) + case 0x9d: this.DirectAddress(); this.JSR(); break; // JSR (direct) + case 0xad: this.IndexedAddress(); this.JSR(); break; // JSR (indexed) + case 0xbd: this.ExtendedAddress(); this.JSR(); break; // JSR (extended) // LD // LDA - case 0x86: this.Tick(2); this.ImmediateByte(); this.LDA(); break; // LD (LDA immediate) - case 0x96: this.Tick(4); this.DirectByte(); this.LDA(); break; // LD (LDA direct) - case 0xa6: this.Tick(4); this.IndexedByte(); this.LDA(); break; // LD (LDA indexed) - case 0xb6: this.Tick(5); this.ExtendedByte(); this.LDA(); break; // LD (LDA extended) + case 0x86: this.ImmediateByte(); this.LDA(); break; // LD (LDA immediate) + case 0x96: this.DirectByte(); this.LDA(); break; // LD (LDA direct) + case 0xa6: this.IndexedByte(); this.LDA(); break; // LD (LDA indexed) + case 0xb6: this.ExtendedByte(); this.LDA(); break; // LD (LDA extended) // LDB - case 0xc6: this.Tick(2); this.ImmediateByte(); this.LDB(); break; // LD (LDB immediate) - case 0xd6: this.Tick(4); this.DirectByte(); this.LDB(); break; // LD (LDB direct) - case 0xe6: this.Tick(4); this.IndexedByte(); this.LDB(); break; // LD (LDB indexed) - case 0xf6: this.Tick(5); this.ExtendedByte(); this.LDB(); break; // LD (LDB extended) + case 0xc6: this.ImmediateByte(); this.LDB(); break; // LD (LDB immediate) + case 0xd6: this.DirectByte(); this.LDB(); break; // LD (LDB direct) + case 0xe6: this.IndexedByte(); this.LDB(); break; // LD (LDB indexed) + case 0xf6: this.ExtendedByte(); this.LDB(); break; // LD (LDB extended) // LDD - case 0xcc: this.Tick(3); this.ImmediateWord(); this.LDD(); break; // LD (LDD immediate) - case 0xdc: this.Tick(5); this.DirectWord(); this.LDD(); break; // LD (LDD direct) - case 0xec: this.Tick(5); this.IndexedWord(); this.LDD(); break; // LD (LDD indexed) - case 0xfc: this.Tick(6); this.ExtendedWord(); this.LDD(); break; // LD (LDD extended) + case 0xcc: this.ImmediateWord(); this.LDD(); break; // LD (LDD immediate) + case 0xdc: this.DirectWord(); this.LDD(); break; // LD (LDD direct) + case 0xec: this.IndexedWord(); this.LDD(); break; // LD (LDD indexed) + case 0xfc: this.ExtendedWord(); this.LDD(); break; // LD (LDD extended) // LDU - case 0xce: this.Tick(3); this.ImmediateWord(); this.LDU(); break; // LD (LDU immediate) - case 0xde: this.Tick(5); this.DirectWord(); this.LDU(); break; // LD (LDU direct) - case 0xee: this.Tick(5); this.IndexedWord(); this.LDU(); break; // LD (LDU indexed) - case 0xfe: this.Tick(6); this.ExtendedWord(); this.LDU(); break; // LD (LDU extended) + case 0xce: this.ImmediateWord(); this.LDU(); break; // LD (LDU immediate) + case 0xde: this.DirectWord(); this.LDU(); break; // LD (LDU direct) + case 0xee: this.IndexedWord(); this.LDU(); break; // LD (LDU indexed) + case 0xfe: this.ExtendedWord(); this.LDU(); break; // LD (LDU extended) // LDX - case 0x8e: this.Tick(3); this.ImmediateWord(); this.LDX(); break; // LD (LDX immediate) - case 0x9e: this.Tick(5); this.DirectWord(); this.LDX(); break; // LD (LDX direct) - case 0xae: this.Tick(5); this.IndexedWord(); this.LDX(); break; // LD (LDX indexed) - case 0xbe: this.Tick(6); this.ExtendedWord(); this.LDX(); break; // LD (LDX extended) + case 0x8e: this.ImmediateWord(); this.LDX(); break; // LD (LDX immediate) + case 0x9e: this.DirectWord(); this.LDX(); break; // LD (LDX direct) + case 0xae: this.IndexedWord(); this.LDX(); break; // LD (LDX indexed) + case 0xbe: this.ExtendedWord(); this.LDX(); break; // LD (LDX extended) // LEA - case 0x30: this.Tick(4); this.LEAX(); break; // LEA (LEAX indexed) - case 0x31: this.Tick(4); this.LEAY(); break; // LEA (LEAY indexed) - case 0x32: this.Tick(4); this.LEAS(); break; // LEA (LEAS indexed) - case 0x33: this.Tick(4); this.LEAU(); break; // LEA (LEAU indexed) + case 0x30: this.LEAX(); break; // LEA (LEAX indexed) + case 0x31: this.LEAY(); break; // LEA (LEAY indexed) + case 0x32: this.LEAS(); break; // LEA (LEAS indexed) + case 0x33: this.LEAU(); break; // LEA (LEAU indexed) // LSR - case 0x04: this.Tick(6); this.DirectByte(); this.LSR(); break; // LSR (direct) - case 0x44: this.Tick(2); this.LSRA(); break; // LSR (LSRA inherent) - case 0x54: this.Tick(2); this.LSRB(); break; // LSR (LSRB inherent) - case 0x64: this.Tick(6); this.IndexedByte(); this.LSR(); break; // LSR (indexed) - case 0x74: this.Tick(7); this.ExtendedByte(); this.LSR(); break; // LSR (extended) + case 0x04: this.DirectByte(); this.LSR(); break; // LSR (direct) + case 0x44: this.LSRA(); break; // LSR (LSRA inherent) + case 0x54: this.LSRB(); break; // LSR (LSRB inherent) + case 0x64: this.IndexedByte(); this.LSR(); break; // LSR (indexed) + case 0x74: this.ExtendedByte(); this.LSR(); break; // LSR (extended) // MUL - case 0x3d: this.Tick(11); this.MUL(); break; // MUL (inherent) + case 0x3d: this.MUL(); Debug.Assert(this.Cycles == 11); break; // MUL (inherent) // NEG - case 0x00: this.Tick(6); this.DirectByte(); this.NEG(); break; // NEG (direct) - case 0x40: this.Tick(2); this.NEGA(); break; // NEG (NEGA, inherent) - case 0x50: this.Tick(2); this.NEGB(); break; // NEG (NEGB, inherent) - case 0x60: this.Tick(6); this.IndexedByte(); this.NEG(); break; // NEG (indexed) - case 0x70: this.Tick(7); this.ExtendedByte(); this.NEG(); break; // NEG (extended) + case 0x00: this.DirectByte(); this.NEG(); break; // NEG (direct) + case 0x40: this.NEGA(); Debug.Assert(this.Cycles == 2); break; // NEG (NEGA, inherent) + case 0x50: this.NEGB(); Debug.Assert(this.Cycles == 2); break; // NEG (NEGB, inherent) + case 0x60: this.IndexedByte(); this.NEG(); break; // NEG (indexed) + case 0x70: this.ExtendedByte(); this.NEG(); break; // NEG (extended) // NOP - case 0x12: this.Tick(2); break; // NOP (inherent) + case 0x12: this.NOP(); Debug.Assert(this.Cycles == 2); break; // NOP (inherent) // OR // ORA - case 0x8a: this.Tick(2); this.ImmediateByte(); this.ORA(); break; // OR (ORA immediate) - case 0x9a: this.Tick(4); this.DirectByte(); this.ORA(); break; // OR (ORA direct) - case 0xaa: this.Tick(4); this.IndexedByte(); this.ORA(); break; // OR (ORA indexed) - case 0xba: this.Tick(5); this.ExtendedByte(); this.ORA(); break; // OR (ORA extended) + case 0x8a: this.ImmediateByte(); this.ORA(); break; // OR (ORA immediate) + case 0x9a: this.DirectByte(); this.ORA(); break; // OR (ORA direct) + case 0xaa: this.IndexedByte(); this.ORA(); break; // OR (ORA indexed) + case 0xba: this.ExtendedByte(); this.ORA(); break; // OR (ORA extended) // ORB - case 0xca: this.Tick(2); this.ImmediateByte(); this.ORB(); break; // OR (ORB immediate) - case 0xda: this.Tick(4); this.DirectByte(); this.ORB(); break; // OR (ORB direct) - case 0xea: this.Tick(4); this.IndexedByte(); this.ORB(); break; // OR (ORB indexed) - case 0xfa: this.Tick(5); this.ExtendedByte(); this.ORB(); break; // OR (ORB extended) + case 0xca: this.ImmediateByte(); this.ORB(); break; // OR (ORB immediate) + case 0xda: this.DirectByte(); this.ORB(); break; // OR (ORB direct) + case 0xea: this.IndexedByte(); this.ORB(); break; // OR (ORB indexed) + case 0xfa: this.ExtendedByte(); this.ORB(); break; // OR (ORB extended) // ORCC - case 0x1a: this.Tick(3); this.ImmediateByte(); this.ORCC(); break; // OR (ORCC immediate) + case 0x1a: this.ImmediateByte(); this.ORCC(); break; // OR (ORCC immediate) // PSH - case 0x34: this.Tick(5); this.ImmediateByte(); this.PSHS(); break; // PSH (PSHS immediate) - case 0x36: this.Tick(5); this.ImmediateByte(); this.PSHU(); break; // PSH (PSHU immediate) + case 0x34: this.ImmediateByte(); this.PSHS(); break; // PSH (PSHS immediate) + case 0x36: this.ImmediateByte(); this.PSHU(); break; // PSH (PSHU immediate) // PUL - case 0x35: this.Tick(5); this.ImmediateByte(); this.PULS(); break; // PUL (PULS immediate) - case 0x37: this.Tick(5); this.ImmediateByte(); this.PULU(); break; // PUL (PULU immediate) + case 0x35: this.ImmediateByte(); this.PULS(); break; // PUL (PULS immediate) + case 0x37: this.ImmediateByte(); this.PULU(); break; // PUL (PULU immediate) // ROL - case 0x09: this.Tick(6); this.DirectByte(); this.ROL(); break; // ROL (direct) - case 0x49: this.Tick(2); this.ROLA(); break; // ROL (ROLA inherent) - case 0x59: this.Tick(2); this.ROLB(); break; // ROL (ROLB inherent) - case 0x69: this.Tick(6); this.IndexedByte(); this.ROL(); break; // ROL (indexed) - case 0x79: this.Tick(7); this.ExtendedByte(); this.ROL(); break; // ROL (extended) + case 0x09: this.DirectByte(); this.ROL(); break; // ROL (direct) + case 0x49: this.ROLA(); Debug.Assert(this.Cycles == 2); break; // ROL (ROLA inherent) + case 0x59: this.ROLB(); Debug.Assert(this.Cycles == 2); break; // ROL (ROLB inherent) + case 0x69: this.IndexedByte(); this.ROL(); break; // ROL (indexed) + case 0x79: this.ExtendedByte(); this.ROL(); break; // ROL (extended) // ROR - case 0x06: this.Tick(6); this.DirectByte(); this.ROR(); break; // ROR (direct) - case 0x46: this.Tick(2); this.RORA(); break; // ROR (RORA inherent) - case 0x56: this.Tick(2); this.RORB(); break; // ROR (RORB inherent) - case 0x66: this.Tick(6); this.IndexedByte(); this.ROR(); break; // ROR (indexed) - case 0x76: this.Tick(7); this.ExtendedByte();this.ROR(); break; // ROR (extended) + case 0x06: this.DirectByte(); this.ROR(); break; // ROR (direct) + case 0x46: this.RORA(); break; // ROR (RORA inherent) + case 0x56: this.RORB(); break; // ROR (RORB inherent) + case 0x66: this.IndexedByte(); this.ROR(); break; // ROR (indexed) + case 0x76: this.ExtendedByte();this.ROR(); break; // ROR (extended) // RTI - case 0x3B: this.Tick(6); this.RTI(); break; // RTI (inherent) + case 0x3B: this.RTI(); Debug.Assert(this.Cycles == (this.E ? 15 : 6)); break; // RTI (inherent) // RTS - case 0x39: this.Tick(5); this.RTS(); break; // RTS (inherent) + case 0x39: this.RTS(); Debug.Assert(this.Cycles == 5); break; // RTS (inherent) // SBC // SBCA - case 0x82: this.Tick(2); this.ImmediateByte(); this.SBCA(); break; // SBC (SBCA immediate) - case 0x92: this.Tick(4); this.DirectByte(); this.SBCA(); break; // SBC (SBCA direct) - case 0xa2: this.Tick(4); this.IndexedByte(); this.SBCA(); break; // SBC (SBCA indexed) - case 0xb2: this.Tick(5); this.ExtendedByte(); this.SBCA(); break; // SBC (SBCB extended) + case 0x82: this.ImmediateByte(); this.SBCA(); Debug.Assert(this.Cycles == 2); break; // SBC (SBCA immediate) + case 0x92: this.DirectByte(); this.SBCA(); Debug.Assert(this.Cycles == 4); break; // SBC (SBCA direct) + case 0xa2: this.IndexedByte(); this.SBCA(); Debug.Assert(this.Cycles >= 4); break; // SBC (SBCA indexed) + case 0xb2: this.ExtendedByte(); this.SBCA(); Debug.Assert(this.Cycles == 5); break; // SBC (SBCB extended) // SBCB - case 0xc2: this.Tick(2); this.ImmediateByte(); this.SBCB(); break; // SBC (SBCB immediate) - case 0xd2: this.Tick(4); this.DirectByte(); this.SBCB(); break; // SBC (SBCB direct) - case 0xe2: this.Tick(4); this.IndexedByte(); this.SBCB(); break; // SBC (SBCB indexed) - case 0xf2: this.Tick(5); this.ExtendedByte(); this.SBCB(); break; // SBC (SBCB extended) + case 0xc2: this.ImmediateByte(); this.SBCB(); Debug.Assert(this.Cycles == 2); break; // SBC (SBCB immediate) + case 0xd2: this.DirectByte(); this.SBCB(); Debug.Assert(this.Cycles == 4); break; // SBC (SBCB direct) + case 0xe2: this.IndexedByte(); this.SBCB(); Debug.Assert(this.Cycles >= 4); break; // SBC (SBCB indexed) + case 0xf2: this.ExtendedByte(); this.SBCB(); Debug.Assert(this.Cycles == 5); break; // SBC (SBCB extended) // SEX - case 0x1d: this.Tick(2); this.SEX(); break; // SEX (inherent) + case 0x1d: this.SEX(); Debug.Assert(this.Cycles == 2); break; // SEX (inherent) // ST // STA - case 0x97: this.Tick(4); this.DirectAddress(); this.STA(); break; // ST (STA direct) - case 0xa7: this.Tick(4); this.IndexedAddress(); this.STA(); break; // ST (STA indexed) - case 0xb7: this.Tick(5); this.ExtendedAddress(); this.STA(); break; // ST (STA extended) + case 0x97: this.DirectAddress(); this.STA(); break; // ST (STA direct) + case 0xa7: this.IndexedAddress(); this.STA(); break; // ST (STA indexed) + case 0xb7: this.ExtendedAddress(); this.STA(); break; // ST (STA extended) // STB - case 0xd7: this.Tick(4); this.DirectAddress(); this.STB(); break; // ST (STB direct) - case 0xe7: this.Tick(4); this.IndexedAddress(); this.STB(); break; // ST (STB indexed) - case 0xf7: this.Tick(5); this.ExtendedAddress(); this.STB(); break; // ST (STB extended) + case 0xd7: this.DirectAddress(); this.STB(); break; // ST (STB direct) + case 0xe7: this.IndexedAddress(); this.STB(); break; // ST (STB indexed) + case 0xf7: this.ExtendedAddress(); this.STB(); break; // ST (STB extended) // STD - case 0xdd: this.Tick(5); this.DirectAddress(); this.STD(); break; // ST (STD direct) - case 0xed: this.Tick(5); this.IndexedAddress(); this.STD(); break; // ST (STD indexed) - case 0xfd: this.Tick(6); this.ExtendedAddress(); this.STD(); break; // ST (STD extended) + case 0xdd: this.DirectAddress(); this.STD(); break; // ST (STD direct) + case 0xed: this.IndexedAddress(); this.STD(); break; // ST (STD indexed) + case 0xfd: this.ExtendedAddress(); this.STD(); break; // ST (STD extended) // STU - case 0xdf: this.Tick(5); this.DirectAddress(); this.STU(); break; // ST (STU direct) - case 0xef: this.Tick(5); this.IndexedAddress(); this.STU(); break; // ST (STU indexed) - case 0xff: this.Tick(6); this.ExtendedAddress(); this.STU(); break; // ST (STU extended) + case 0xdf: this.DirectAddress(); this.STU(); break; // ST (STU direct) + case 0xef: this.IndexedAddress(); this.STU(); break; // ST (STU indexed) + case 0xff: this.ExtendedAddress(); this.STU(); break; // ST (STU extended) // STX - case 0x9f: this.Tick(5); this.DirectAddress(); this.STX(); break; // ST (STX direct) - case 0xaf: this.Tick(5); this.IndexedAddress(); this.STX(); break; // ST (STX indexed) - case 0xbf: this.Tick(6); this.ExtendedAddress(); this.STX(); break; // ST (STX extended) + case 0x9f: this.DirectAddress(); this.STX(); break; // ST (STX direct) + case 0xaf: this.IndexedAddress(); this.STX(); break; // ST (STX indexed) + case 0xbf: this.ExtendedAddress(); this.STX(); break; // ST (STX extended) // SUB // SUBA - case 0x80: this.Tick(2); this.ImmediateByte(); this.SUBA(); break; // SUB (SUBA immediate) - case 0x90: this.Tick(4); this.DirectByte(); this.SUBA(); break; // SUB (SUBA direct) - case 0xa0: this.Tick(4); this.IndexedByte(); this.SUBA(); break; // SUB (SUBA indexed) - case 0xb0: this.Tick(5); this.ExtendedByte(); this.SUBA(); break; // SUB (SUBA extended) + case 0x80: this.ImmediateByte(); this.SUBA(); break; // SUB (SUBA immediate) + case 0x90: this.DirectByte(); this.SUBA(); break; // SUB (SUBA direct) + case 0xa0: this.IndexedByte(); this.SUBA(); break; // SUB (SUBA indexed) + case 0xb0: this.ExtendedByte(); this.SUBA(); break; // SUB (SUBA extended) // SUBB - case 0xc0: this.Tick(2); this.ImmediateByte(); this.SUBB(); break; // SUB (SUBB immediate) - case 0xd0: this.Tick(4); this.DirectByte(); this.SUBB(); break; // SUB (SUBB direct) - case 0xe0: this.Tick(4); this.IndexedByte(); this.SUBB(); break; // SUB (SUBB indexed) - case 0xf0: this.Tick(5); this.ExtendedByte(); this.SUBB(); break; // SUB (SUBB extended) + case 0xc0: this.ImmediateByte(); this.SUBB(); break; // SUB (SUBB immediate) + case 0xd0: this.DirectByte(); this.SUBB(); break; // SUB (SUBB direct) + case 0xe0: this.IndexedByte(); this.SUBB(); break; // SUB (SUBB indexed) + case 0xf0: this.ExtendedByte(); this.SUBB(); break; // SUB (SUBB extended) // SUBD - case 0x83: this.Tick(4); this.ImmediateWord(); this.SUBD(); break; // SUB (SUBD immediate) - case 0x93: this.Tick(6); this.DirectWord(); this.SUBD(); break; // SUB (SUBD direct) - case 0xa3: this.Tick(6); this.IndexedWord(); this.SUBD(); break; // SUB (SUBD indexed) - case 0xb3: this.Tick(7); this.ExtendedWord(); this.SUBD(); break; // SUB (SUBD extended) + case 0x83: this.ImmediateWord(); this.SUBD(); break; // SUB (SUBD immediate) + case 0x93: this.DirectWord(); this.SUBD(); break; // SUB (SUBD direct) + case 0xa3: this.IndexedWord(); this.SUBD(); break; // SUB (SUBD indexed) + case 0xb3: this.ExtendedWord(); this.SUBD(); break; // SUB (SUBD extended) // SWI - case 0x3f: this.Tick(10); this.SWI(); break; // SWI (inherent) + case 0x3f: this.SWI(); break; // SWI (inherent) // SYNC - case 0x13: this.Tick(4); this.SYNC(); break; // SYNC (inherent) + case 0x13: this.SYNC(); break; // SYNC (inherent) // TFR - case 0x1f: this.Tick(6); this.ImmediateByte(); this.TFR(); break; // TFR (immediate) + case 0x1f: this.ImmediateByte(); this.TFR(); Debug.Assert(this.Cycles == 6); break; // TFR (immediate) // TST - case 0x0d: this.Tick(6); this.DirectByte(); this.TST(); break; // TST (direct) - case 0x4d: this.Tick(2); this.TSTA(); break; // TST (TSTA inherent) - case 0x5d: this.Tick(2); this.TSTB(); break; // TST (TSTB inherent) - case 0x6d: this.Tick(6); this.IndexedByte(); this.TST(); break; // TST (indexed) - case 0x7d: this.Tick(7); this.ExtendedByte(); this.TST(); break; // TST (extended) + case 0x0d: this.DirectByte(); this.TST(); break; // TST (direct) + case 0x4d: this.TSTA(); Debug.Assert(this.Cycles == 2); break; // TST (TSTA inherent) + case 0x5d: this.TSTB(); Debug.Assert(this.Cycles == 2); break; // TST (TSTB inherent) + case 0x6d: this.IndexedByte(); this.TST(); break; // TST (indexed) + case 0x7d: this.ExtendedByte(); this.TST(); break; // TST (extended) // Branching - case 0x16: this.Tick(5); this.LBRA(); break; // BRA (LBRA relative) - case 0x17: this.Tick(9); this.LBSR(); break; // BSR (LBSR relative) - case 0x20: this.Tick(3); this.BRA(); break; // BRA (relative) - case 0x21: this.Tick(3); this.BRN(); break; // BRN (relative) - case 0x22: this.Tick(3); this.BHI(); break; // BHI (relative) - case 0x23: this.Tick(3); this.BLS(); break; // BLS (relative) - case 0x24: this.Tick(3); this.BCC(); break; // BCC (relative) - case 0x25: this.Tick(3); this.BCS(); break; // BCS (relative) - case 0x26: this.Tick(3); this.BNE(); break; // BNE (relative) - case 0x27: this.Tick(3); this.BEQ(); break; // BEQ (relative) - case 0x28: this.Tick(3); this.BVC(); break; // BVC (relative) - case 0x29: this.Tick(3); this.BVS(); break; // BVS (relative) - case 0x2a: this.Tick(3); this.BPL(); break; // BPL (relative) - case 0x2b: this.Tick(3); this.BMI(); break; // BMI (relative) - case 0x2c: this.Tick(3); this.BGE(); break; // BGE (relative) - case 0x2d: this.Tick(3); this.BLT(); break; // BLT (relative) - case 0x2e: this.Tick(3); this.BGT(); break; // BGT (relative) - case 0x2f: this.Tick(3); this.BLE(); break; // BLE (relative) + case 0x16: this.LBRA(); break; // BRA (LBRA relative) + case 0x17: this.LBSR(); break; // BSR (LBSR relative) + case 0x20: this.BRA(); break; // BRA (relative) + case 0x21: this.BRN(); break; // BRN (relative) + case 0x22: this.BHI(); break; // BHI (relative) + case 0x23: this.BLS(); break; // BLS (relative) + case 0x24: this.BCC(); break; // BCC (relative) + case 0x25: this.BCS(); break; // BCS (relative) + case 0x26: this.BNE(); break; // BNE (relative) + case 0x27: this.BEQ(); break; // BEQ (relative) + case 0x28: this.BVC(); break; // BVC (relative) + case 0x29: this.BVS(); break; // BVS (relative) + case 0x2a: this.BPL(); break; // BPL (relative) + case 0x2b: this.BMI(); break; // BMI (relative) + case 0x2c: this.BGE(); break; // BGE (relative) + case 0x2d: this.BLT(); break; // BLT (relative) + case 0x2e: this.BGT(); break; // BGT (relative) + case 0x2f: this.BLE(); break; // BLE (relative) - case 0x8d: this.Tick(7); this.BSR(); break; // BSR (relative) + case 0x8d: this.BSR(); break; // BSR (relative) default: throw new InvalidOperationException("Unknown op-code"); @@ -1567,60 +1605,60 @@ namespace MC6809 // CMP // CMPD - case 0x83: this.Tick(5); this.ImmediateWord(); this.CMPD(); break; // CMP (CMPD, immediate) - case 0x93: this.Tick(7); this.DirectWord(); this.CMPD(); break; // CMP (CMPD, direct) - case 0xa3: this.Tick(7); this.IndexedWord(); this.CMPD(); break; // CMP (CMPD, indexed) - case 0xb3: this.Tick(8); this.ExtendedWord(); this.CMPD(); break; // CMP (CMPD, extended) + case 0x83: this.ImmediateWord(); this.CMPD(); break; // CMP (CMPD, immediate) + case 0x93: this.DirectWord(); this.CMPD(); break; // CMP (CMPD, direct) + case 0xa3: this.IndexedWord(); this.CMPD(); break; // CMP (CMPD, indexed) + case 0xb3: this.ExtendedWord(); this.CMPD(); break; // CMP (CMPD, extended) // CMPY - case 0x8c: this.Tick(5); this.ImmediateWord(); this.CMPY(); break; // CMP (CMPY, immediate) - case 0x9c: this.Tick(7); this.DirectWord(); this.CMPY(); break; // CMP (CMPY, direct) - case 0xac: this.Tick(7); this.IndexedWord(); this.CMPY(); break; // CMP (CMPY, indexed) - case 0xbc: this.Tick(8); this.ExtendedWord(); this.CMPY(); break; // CMP (CMPY, extended) + case 0x8c: this.ImmediateWord(); this.CMPY(); break; // CMP (CMPY, immediate) + case 0x9c: this.DirectWord(); this.CMPY(); break; // CMP (CMPY, direct) + case 0xac: this.IndexedWord(); this.CMPY(); break; // CMP (CMPY, indexed) + case 0xbc: this.ExtendedWord(); this.CMPY(); break; // CMP (CMPY, extended) // LD // LDS - case 0xce: this.Tick(4); this.ImmediateWord(); this.LDS(); break; // LD (LDS immediate) - case 0xde: this.Tick(6); this.DirectWord(); this.LDS(); break; // LD (LDS direct) - case 0xee: this.Tick(6); this.IndexedWord(); this.LDS(); break; // LD (LDS indexed) - case 0xfe: this.Tick(7); this.ExtendedWord(); this.LDS(); break; // LD (LDS extended) + case 0xce: this.ImmediateWord(); this.LDS(); break; // LD (LDS immediate) + case 0xde: this.DirectWord(); this.LDS(); break; // LD (LDS direct) + case 0xee: this.IndexedWord(); this.LDS(); break; // LD (LDS indexed) + case 0xfe: this.ExtendedWord(); this.LDS(); break; // LD (LDS extended) // LDY - case 0x8e: this.Tick(4); this.ImmediateWord(); this.LDY(); break; // LD (LDY immediate) - case 0x9e: this.Tick(6); this.DirectWord(); this.LDY(); break; // LD (LDY direct) - case 0xae: this.Tick(6); this.IndexedWord(); this.LDY(); break; // LD (LDY indexed) - case 0xbe: this.Tick(7); this.ExtendedWord(); this.LDY(); break; // LD (LDY extended) + case 0x8e: this.ImmediateWord(); this.LDY(); break; // LD (LDY immediate) + case 0x9e: this.DirectWord(); this.LDY(); break; // LD (LDY direct) + case 0xae: this.IndexedWord(); this.LDY(); break; // LD (LDY indexed) + case 0xbe: this.ExtendedWord(); this.LDY(); break; // LD (LDY extended) // Branching - case 0x21: this.Tick(5); this.LBRN(); break; // BRN (LBRN relative) - case 0x22: this.Tick(5); this.LBHI(); break; // BHI (LBHI relative) - case 0x23: this.Tick(5); this.LBLS(); break; // BLS (LBLS relative) - case 0x24: this.Tick(5); this.LBCC(); break; // BCC (LBCC relative) - case 0x25: this.Tick(5); this.LBCS(); break; // BCS (LBCS relative) - case 0x26: this.Tick(5); this.LBNE(); break; // BNE (LBNE relative) - case 0x27: this.Tick(5); this.LBEQ(); break; // BEQ (LBEQ relative) - case 0x28: this.Tick(5); this.LBVC(); break; // BVC (LBVC relative) - case 0x29: this.Tick(5); this.LBVS(); break; // BVS (LBVS relative) - case 0x2a: this.Tick(5); this.LBPL(); break; // BPL (LBPL relative) - case 0x2b: this.Tick(5); this.LBMI(); break; // BMI (LBMI relative) - case 0x2c: this.Tick(5); this.LBGE(); break; // BGE (LBGE relative) - case 0x2d: this.Tick(5); this.LBLT(); break; // BLT (LBLT relative) - case 0x2e: this.Tick(5); this.LBGT(); break; // BGT (LBGT relative) - case 0x2f: this.Tick(5); this.LBLE(); break; // BLE (LBLE relative) + case 0x21: this.LBRN(); break; // BRN (LBRN relative) + case 0x22: this.LBHI(); break; // BHI (LBHI relative) + case 0x23: this.LBLS(); break; // BLS (LBLS relative) + case 0x24: this.LBCC(); break; // BCC (LBCC relative) + case 0x25: this.LBCS(); break; // BCS (LBCS relative) + case 0x26: this.LBNE(); break; // BNE (LBNE relative) + case 0x27: this.LBEQ(); break; // BEQ (LBEQ relative) + case 0x28: this.LBVC(); break; // BVC (LBVC relative) + case 0x29: this.LBVS(); break; // BVS (LBVS relative) + case 0x2a: this.LBPL(); break; // BPL (LBPL relative) + case 0x2b: this.LBMI(); break; // BMI (LBMI relative) + case 0x2c: this.LBGE(); break; // BGE (LBGE relative) + case 0x2d: this.LBLT(); break; // BLT (LBLT relative) + case 0x2e: this.LBGT(); break; // BGT (LBGT relative) + case 0x2f: this.LBLE(); break; // BLE (LBLE relative) // STS - case 0xdf: this.Tick(6); this.DirectAddress(); this.STS(); break; // ST (STS direct) - case 0xef: this.Tick(6); this.IndexedAddress(); this.STS(); break; // ST (STS indexed) - case 0xff: this.Tick(7); this.ExtendedAddress(); this.STS(); break; // ST (STS extended) + case 0xdf: this.DirectAddress(); this.STS(); break; // ST (STS direct) + case 0xef: this.IndexedAddress(); this.STS(); break; // ST (STS indexed) + case 0xff: this.ExtendedAddress(); this.STS(); break; // ST (STS extended) // STY - case 0x9f: this.Tick(6); this.DirectAddress(); this.STY(); break; // ST (STY direct) - case 0xaf: this.Tick(6); this.IndexedAddress(); this.STY(); break; // ST (STY indexed) - case 0xbf: this.Tick(7); this.ExtendedAddress(); this.STY(); break; // ST (STY extended) + case 0x9f: this.DirectAddress(); this.STY(); break; // ST (STY direct) + case 0xaf: this.IndexedAddress(); this.STY(); break; // ST (STY indexed) + case 0xbf: this.ExtendedAddress(); this.STY(); break; // ST (STY extended) // SWI - case 0x3f: this.Tick(11); this.SWI2(); break; // SWI (SWI2 inherent) + case 0x3f: this.SWI2(); break; // SWI (SWI2 inherent) default: throw new InvalidOperationException("Unknown 10 prefixed op-code"); @@ -1634,19 +1672,19 @@ namespace MC6809 // CMP // CMPU - case 0x83: this.Tick(5); this.ImmediateWord(); this.CMPU(); break; // CMP (CMPU, immediate) - case 0x93: this.Tick(7); this.DirectWord(); this.CMPU(); break; // CMP (CMPU, direct) - case 0xa3: this.Tick(7); this.IndexedWord(); this.CMPU(); break; // CMP (CMPU, indexed) - case 0xb3: this.Tick(8); this.ExtendedWord(); this.CMPU(); break; // CMP (CMPU, extended) + case 0x83: this.ImmediateWord(); this.CMPU(); break; // CMP (CMPU, immediate) + case 0x93: this.DirectWord(); this.CMPU(); break; // CMP (CMPU, direct) + case 0xa3: this.IndexedWord(); this.CMPU(); break; // CMP (CMPU, indexed) + case 0xb3: this.ExtendedWord(); this.CMPU(); break; // CMP (CMPU, extended) // CMPS - case 0x8c: this.Tick(5); this.ImmediateWord(); this.CMPS(); break; // CMP (CMPS, immediate) - case 0x9c: this.Tick(7); this.DirectWord(); this.CMPS(); break; // CMP (CMPS, direct) - case 0xac: this.Tick(7); this.IndexedWord(); this.CMPS(); break; // CMP (CMPS, indexed) - case 0xbc: this.Tick(8); this.ExtendedWord(); this.CMPS(); break; // CMP (CMPS, extended) + case 0x8c: this.ImmediateWord(); this.CMPS(); break; // CMP (CMPS, immediate) + case 0x9c: this.DirectWord(); this.CMPS(); break; // CMP (CMPS, direct) + case 0xac: this.IndexedWord(); this.CMPS(); break; // CMP (CMPS, indexed) + case 0xbc: this.ExtendedWord(); this.CMPS(); break; // CMP (CMPS, extended) // SWI - case 0x3f: this.Tick(11); this.SWI3(); break; // SWI (SWI3 inherent) + case 0x3f: this.SWI3(); break; // SWI (SWI3 inherent) default: throw new InvalidOperationException("Unknown 11 prefixed op-code"); @@ -1657,6 +1695,8 @@ namespace MC6809 #region Miscellaneous instruction implementations + private void NOP() => this.SwallowCurrent(); + private void ADCA() => this.A = this.AddWithCarry(this.A); private void ADCB() => this.B = this.AddWithCarry(this.B); @@ -1681,6 +1721,7 @@ namespace MC6809 var addition = operand.Word + data.Word; this.CC = this.AdjustAddition(operand, data, (uint)addition); result.Word = (ushort)addition; + this.SwallowRead(); } private void ANDCC() => this.CC &= this.Bus.Data; @@ -1690,8 +1731,17 @@ namespace MC6809 private byte And(byte operand, byte data) => this.Through((byte)(operand & data)); - private void ASLA() => this.A = this.ArithmeticShiftLeft(this.A); - private void ASLB() => this.B = this.ArithmeticShiftLeft(this.B); + private void ASLA() + { + this.SwallowCurrent(); + this.A = this.ArithmeticShiftLeft(this.A); + } + + private void ASLB() + { + this.SwallowCurrent(); + this.B = this.ArithmeticShiftLeft(this.B); + } private void ASL() => this.MemoryWrite(this.ArithmeticShiftLeft(this.Bus.Data)); @@ -1704,8 +1754,17 @@ namespace MC6809 return operand; } - private void ASRA() => this.A = this.ArithmeticShiftRight(this.A); - private void ASRB() => this.B = this.ArithmeticShiftRight(this.B); + private void ASRA() + { + this.SwallowCurrent(); + this.A = this.ArithmeticShiftRight(this.A); + } + + private void ASRB() + { + this.SwallowCurrent(); + this.B = this.ArithmeticShiftRight(this.B); + } private void ASR() => this.MemoryWrite(this.ArithmeticShiftRight(this.Bus.Data)); @@ -1722,8 +1781,17 @@ namespace MC6809 private void Bit(byte operand, byte data) => this.And(operand, data); - private void CLRA() => this.A = this.Clear(); - private void CLRB() => this.B = this.Clear(); + private void CLRA() + { + this.SwallowCurrent(); + this.A = this.Clear(); + } + + private void CLRB() + { + this.SwallowCurrent(); + this.B = this.Clear(); + } private void CLR() => this.MemoryWrite(this.Intermediate, this.Clear()); @@ -1746,8 +1814,17 @@ namespace MC6809 private void Compare(Register16 operand) => this.Subtract(operand, this.Intermediate, this.Intermediate); - private void COMA() => this.A = this.Complement(this.A); - private void COMB() => this.B = this.Complement(this.B); + private void COMA() + { + this.SwallowCurrent(); + this.A = this.Complement(this.A); + } + + private void COMB() + { + this.SwallowCurrent(); + this.B = this.Complement(this.B); + } private void COM() => this.MemoryWrite(this.Complement(this.Bus.Data)); @@ -1759,6 +1836,8 @@ namespace MC6809 private void CWAI() { + this.SwallowCurrent(); + this.SwallowRead(); this.CC &= this.Bus.Data; this.SaveEntireRegisterState(); this.Halt(); @@ -1766,6 +1845,8 @@ namespace MC6809 private void DAA() { + this.SwallowCurrent(); + var original = this.A; var lowNibble = LowNibble(original); @@ -1797,8 +1878,17 @@ namespace MC6809 private byte ExclusiveOr(byte operand, byte data) => this.Through((byte)(operand ^ data)); - private void DECA() => this.A = this.Decrement(this.A); - private void DECB() => this.B = this.Decrement(this.B); + private void DECA() + { + this.SwallowCurrent(); + this.A = this.Decrement(this.A); + } + + private void DECB() + { + this.SwallowCurrent(); + this.B = this.Decrement(this.B); + } private void DEC() => this.MemoryWrite(this.Decrement(this.Bus.Data)); @@ -1811,8 +1901,17 @@ namespace MC6809 return result; } - private void INCA() => this.A = this.Increment(this.A); - private void INCB() => this.B = this.Increment(this.B); + private void INCA() + { + this.SwallowCurrent(); + this.A = this.Increment(this.A); + } + + private void INCB() + { + this.SwallowCurrent(); + this.B = this.Increment(this.B); + } private void INC() => this.MemoryWrite(this.Increment(this.Bus.Data)); @@ -1830,8 +1929,17 @@ namespace MC6809 private void JSR() => this.Call(this.Intermediate); - private void LSRA() => this.A = this.LogicalShiftRight(this.A); - private void LSRB() => this.B = this.LogicalShiftRight(this.B); + private void LSRA() + { + this.SwallowCurrent(); + this.A = this.LogicalShiftRight(this.A); + } + + private void LSRB() + { + this.SwallowCurrent(); + this.B = this.LogicalShiftRight(this.B); + } private void LSR() => this.MemoryWrite(this.LogicalShiftRight(this.Bus.Data)); @@ -1844,13 +1952,24 @@ namespace MC6809 private void MUL() { + this.SwallowCurrent(); + this.SwallowRead(9); this.D.Word = (ushort)(this.A * this.B); this.CC = this.AdjustZero(this.D); this.CC = SetBit(this.CC, StatusBits.CF, this.D.Low & (byte)Bits.Bit7); } - private void NEGA() => this.A = this.Negate(this.A); - private void NEGB() => this.B = this.Negate(this.B); + private void NEGA() + { + this.SwallowCurrent(); + this.A = this.Negate(this.A); + } + + private void NEGB() + { + this.SwallowCurrent(); + this.B = this.Negate(this.B); + } private void NEG() => this.MemoryWrite(this.Negate(this.Bus.Data)); @@ -1871,8 +1990,17 @@ namespace MC6809 private byte Or(byte operand) => this.Through((byte)(operand | this.Bus.Data)); - private void ROLA() => this.A = this.RotateLeft(this.A); - private void ROLB() => this.B = this.RotateLeft(this.B); + private void ROLA() + { + this.SwallowCurrent(); + this.A = this.RotateLeft(this.A); + } + + private void ROLB() + { + this.SwallowCurrent(); + this.B = this.RotateLeft(this.B); + } private void ROL() => this.MemoryWrite(this.RotateLeft(this.Bus.Data)); @@ -1886,8 +2014,17 @@ namespace MC6809 return result; } - private void RORA() => this.A = this.RotateRight(this.A); - private void RORB() => this.B = this.RotateRight(this.B); + private void RORA() + { + this.SwallowCurrent(); + this.A = this.RotateRight(this.A); + } + + private void RORB() + { + this.SwallowCurrent(); + this.B = this.RotateRight(this.B); + } private void ROR() => this.MemoryWrite(this.RotateRight(this.Bus.Data)); @@ -1900,9 +2037,18 @@ namespace MC6809 return result; } - private void RTI() => this.RestoreRegisterState(); + private void RTI() + { + this.RestoreRegisterState(); + this.SwallowRead(); + } - private void RTS() => this.Return(); + private void RTS() + { + this.SwallowCurrent(); + this.Return(); + this.SwallowRead(); + } private void SBCA() => this.A = this.SubtractWithCarry(this.A); private void SBCB() => this.B = this.SubtractWithCarry(this.B); @@ -1930,7 +2076,11 @@ namespace MC6809 result.Word = (ushort)subtraction; } - private void SEX() => this.A = this.SEX(this.B); + private void SEX() + { + this.SwallowCurrent(); + this.A = this.SEX(this.B); + } private byte SEX(byte from) { @@ -1940,29 +2090,50 @@ namespace MC6809 private void SWI() { + SwallowCurrent(); + SwallowRead(); this.SaveEntireRegisterState(); this.CC = SetBit(this.CC, StatusBits.IF); // Disable IRQ this.CC = SetBit(this.CC, StatusBits.FF); // Disable FIRQ + SwallowRead(); this.GetWordPaged(0xff, SWI_vector); this.Jump(this.Intermediate); + SwallowRead(); } private void SWI2() { + this.SwallowCurrent(); + this.SwallowRead(); this.SaveEntireRegisterState(); + this.SwallowRead(); this.GetWordPaged(0xff, SWI2_vector); this.Jump(this.Intermediate); + this.SwallowRead(); } private void SWI3() { + this.SwallowCurrent(); + this.SwallowRead(); this.SaveEntireRegisterState(); + this.SwallowRead(); this.GetWordPaged(0xff, SWI3_vector); this.Jump(this.Intermediate); + this.SwallowRead(); } - private void TSTA() => this.Test(this.A); - private void TSTB() => this.Test(this.B); + private void TSTA() + { + this.SwallowCurrent(); + this.Test(this.A); + } + + private void TSTB() + { + this.SwallowCurrent(); + this.Test(this.B); + } private void TST() => this.Test(this.Bus.Data); @@ -1994,7 +2165,12 @@ namespace MC6809 this.U.Assign(this.Intermediate); } - private void ABX() => this.X.Word += this.B; + private void ABX() + { + this.SwallowCurrent(); + this.X.Word += this.B; + this.SwallowRead(); + } private void Prefix10() {