diff --git a/M6502/M6502.cs b/M6502/M6502.cs index edf93cd..64fd372 100644 --- a/M6502/M6502.cs +++ b/M6502/M6502.cs @@ -223,8 +223,28 @@ namespace EightBit private void StoreFixupEffect(byte data) { - var fixedAddress = (byte)(this.Bus.Address.High + 1); - this.MemoryWrite((byte)(data & fixedAddress)); + ////var fixedAddress = (byte)(this.Bus.Address.High + 1); + //var fixedAddress = this.FixedPage + 1; + //var updated = (byte)(data & fixedAddress); + //if (this.Fixed) + //{ + // this.Bus.Address.High = updated; + //} + + //this.MemoryWrite(updated); + + byte updated; + if (this.Fixed) + { + updated = (byte)(data & this.FixedPage); + this.Bus.Address.High = updated; + } + else + { + updated = (byte)(data & this.UnfixedPage); + this.Bus.Address.High = updated; + } + this.MemoryWrite(updated); } private void SHA() => this.StoreFixupEffect((byte)(this.A & this.X)); diff --git a/M6502/M6502Core.cs b/M6502/M6502Core.cs index a4542c7..5acfc5c 100644 --- a/M6502/M6502Core.cs +++ b/M6502/M6502Core.cs @@ -646,12 +646,22 @@ namespace EightBit private byte fixedPage; + private byte unfixedPage; + public byte FixedPage { get => this.fixedPage; protected set => this.fixedPage = value; } + public byte UnfixedPage + { + get => this.unfixedPage; + protected set => this.unfixedPage = value; + } + + public bool Fixed => this.FixedPage != this.UnfixedPage; + protected void MaybeFixup() { if (this.Bus.Address.High != this.FixedPage) @@ -685,6 +695,7 @@ namespace EightBit protected void NoteFixedAddress(ushort address) { + this.UnfixedPage = this.Bus.Address.High; this.Intermediate.Word = address; this.FixedPage = this.Intermediate.High; this.Bus.Address.Low = this.Intermediate.Low;