diff --git a/EightBit/Processor.cs b/EightBit/Processor.cs index c8fe80d..d3bb3b9 100644 --- a/EightBit/Processor.cs +++ b/EightBit/Processor.cs @@ -92,10 +92,7 @@ namespace EightBit return current; } - protected virtual byte FetchInstruction() - { - return this.FetchByte(); - } + protected virtual byte FetchInstruction() => this.FetchByte(); public void Execute(byte value) { @@ -219,19 +216,13 @@ namespace EightBit protected abstract void GetInto(Register16 into); - protected virtual void GetWord() - { - this.GetInto(this.Intermediate); - } + protected virtual void GetWord() => this.GetInto(this.Intermediate); protected abstract void SetWord(Register16 value); protected abstract void GetPagedInto(Register16 into); - protected virtual void GetWordPaged() - { - this.GetPagedInto(this.Intermediate); - } + protected virtual void GetWordPaged() => this.GetPagedInto(this.Intermediate); protected void GetWordPaged(byte page, byte offset) { @@ -262,10 +253,7 @@ namespace EightBit protected abstract void FetchInto(Register16 into); - protected void FetchWord() - { - this.FetchInto(this.Intermediate); - } + protected void FetchWord() => this.FetchInto(this.Intermediate); protected void FetchWordAddress() { diff --git a/M6502/Core.cs b/M6502/Core.cs index fc20c97..6bdde2c 100644 --- a/M6502/Core.cs +++ b/M6502/Core.cs @@ -554,14 +554,19 @@ namespace M6502 protected sealed override void BusWrite() { - this.Tick(); - this.WriteToBus(); + this.OnWritingMemory(); + this.Tick(); + this.WriteToBus(); + this.OnWrittenMemory(); } protected sealed override byte BusRead() { - this.Tick(); - return this.ReadFromBus(); + this.OnReadingMemory(); + this.Tick(); + this.ReadFromBus(); + this.OnReadMemory(); + return this.Bus.Data; } private byte ReadFromBus() @@ -1060,7 +1065,7 @@ namespace M6502 #region Increment/decrement - private void DEX() =>this.X = this.DEC(this.X); + private void DEX() => this.X = this.DEC(this.X); private void DEY() => this.Y = this.DEC(this.Y); diff --git a/MC6809/MC6809.cs b/MC6809/MC6809.cs index f38b16a..0c0ee52 100644 --- a/MC6809/MC6809.cs +++ b/MC6809/MC6809.cs @@ -573,16 +573,21 @@ namespace MC6809 protected override void BusWrite() { - this.Tick(); - this.LowerRW(); - base.BusWrite(); + this.OnWritingMemory(); + this.Tick(); + this.LowerRW(); + base.BusWrite(); + this.OnWrittenMemory(); } protected override byte BusRead() { - this.Tick(); - this.RaiseRW(); - return base.BusRead(); + this.OnReadingMemory(); + this.Tick(); + this.RaiseRW(); + base.BusRead(); + this.OnReadMemory(); + return this.Bus.Data; } #endregion @@ -1262,7 +1267,7 @@ namespace MC6809 } else { - this.Execute(this.FetchByte()); + this.Execute(this.FetchInstruction()); } } @@ -2017,7 +2022,7 @@ namespace MC6809 private byte Negate(byte operand) { this.CC = SetBit(this.CC, StatusBits.VF, operand == (byte)Bits.Bit7); - this.Intermediate.Word = (ushort)(0 - operand); + this.Intermediate.Word = (ushort)(~operand + 1); operand = this.Intermediate.Low; this.CC = this.AdjustNZ(operand); this.CC = this.AdjustCarry(this.Intermediate); @@ -2126,8 +2131,8 @@ namespace MC6809 private void SWI() { this.SaveEntireRegisterState(); - this.CC = SetBit(this.CC, StatusBits.IF); // Disable IRQ - this.CC = SetBit(this.CC, StatusBits.FF); // Disable FIRQ + 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.Jump(this.EA); @@ -2202,13 +2207,13 @@ namespace MC6809 private void Prefix10() { this._prefix10 = true; - this.Execute(this.FetchByte()); + this.Execute(this.FetchInstruction()); } private void Prefix11() { this._prefix11 = true; - this.Execute(this.FetchByte()); + this.Execute(this.FetchInstruction()); } #endregion