diff --git a/BizHawk.Emulation/Consoles/Atari/2600/Atari2600.Core.cs b/BizHawk.Emulation/Consoles/Atari/2600/Atari2600.Core.cs index 4327e4dbcf..7925ca88e8 100644 --- a/BizHawk.Emulation/Consoles/Atari/2600/Atari2600.Core.cs +++ b/BizHawk.Emulation/Consoles/Atari/2600/Atari2600.Core.cs @@ -63,11 +63,28 @@ namespace BizHawk addr = (ushort)(addr & 0x1FFF); if ((addr & 0x1080) == 0) { - return tia.ReadMemory(addr); + return tia.ReadMemory(addr, false); } else if ((addr & 0x1080) == 0x0080) { - return m6532.ReadMemory(addr); + return m6532.ReadMemory(addr, false); + } + else + { + return rom[addr & 0x0FFF]; + } + } + + public byte BasePeekMemory(ushort addr) + { + addr = (ushort)(addr & 0x1FFF); + if ((addr & 0x1080) == 0) + { + return tia.ReadMemory(addr, true); + } + else if ((addr & 0x1080) == 0x0080) + { + return m6532.ReadMemory(addr, true); } else { @@ -106,8 +123,6 @@ namespace BizHawk public byte PeekMemory(ushort addr) { - //TODO - this is dangerous, because at least, the lag flag can get set by a read - byte temp = mapper.ReadMemory((ushort)(addr & 0x1FFF)); return temp; @@ -217,7 +232,7 @@ namespace BizHawk //if (render == false) return; } - public byte ReadControls1() + public byte ReadControls1(bool peek) { if (CoreInputComm.InputCallback != null) CoreInputComm.InputCallback(); byte value = 0xFF; @@ -227,11 +242,11 @@ namespace BizHawk if (Controller["P1 Left"]) value &= 0xBF; if (Controller["P1 Right"]) value &= 0x7F; if (Controller["P1 Button"]) value &= 0xF7; - _islag = false; + if(!peek) _islag = false; return value; } - public byte ReadControls2() + public byte ReadControls2(bool peek) { if (CoreInputComm.InputCallback != null) CoreInputComm.InputCallback(); byte value = 0xFF; @@ -241,7 +256,7 @@ namespace BizHawk if (Controller["P2 Left"]) value &= 0xBF; if (Controller["P2 Right"]) value &= 0x7F; if (Controller["P2 Button"]) value &= 0xF7; - _islag = false; + if (!peek) _islag = false; return value; } @@ -253,8 +268,9 @@ namespace BizHawk public void SetP0Diff(bool setting) { p0difficulty = setting; } public void SetP1Diff(bool setting) { p1difficulty = setting; } - public byte ReadConsoleSwitches() + public byte ReadConsoleSwitches(bool peek) { + //TODO - zeromus isnt sure this should clear the lag flag byte value = 0xFF; bool select = Controller["Select"]; @@ -265,7 +281,7 @@ namespace BizHawk if (bw) value &= 0xF7; if (p0difficulty) value &= 0xBF; if (p1difficulty) value &= 0x7F; - _islag = false; + if(!peek) _islag = false; return value; } } @@ -274,6 +290,7 @@ namespace BizHawk { public Atari2600 core; public virtual byte ReadMemory(ushort addr) { return core.BaseReadMemory(addr); } + public virtual byte PeekMemory(ushort addr) { return core.BasePeekMemory(addr); } public virtual void WriteMemory(ushort addr, byte value) { core.BaseWriteMemory(addr, value); } public virtual void SyncState(Serializer ser) { } public virtual void Dispose() { } diff --git a/BizHawk.Emulation/Consoles/Atari/2600/M6532.cs b/BizHawk.Emulation/Consoles/Atari/2600/M6532.cs index 9ec3ea458f..d58f4814f4 100644 --- a/BizHawk.Emulation/Consoles/Atari/2600/M6532.cs +++ b/BizHawk.Emulation/Consoles/Atari/2600/M6532.cs @@ -65,7 +65,7 @@ namespace BizHawk.Emulation.Consoles.Atari timer.prescalerCount = 1 << timer.prescalerShift; } - public byte ReadMemory(ushort addr) + public byte ReadMemory(ushort addr, bool peek) { // Register Select (?) bool RS = (addr & 0x0200) != 0; @@ -83,7 +83,7 @@ namespace BizHawk.Emulation.Consoles.Atari { // Read Output reg A // Combine readings from player 1 and player 2 - byte temp = (byte)(core.ReadControls1() & 0xF0 | ((core.ReadControls2() >> 4) & 0x0F)); + byte temp = (byte)(core.ReadControls1(peek) & 0xF0 | ((core.ReadControls2(peek) >> 4) & 0x0F)); temp = (byte)(temp & ~ddra); return temp; } @@ -95,7 +95,7 @@ namespace BizHawk.Emulation.Consoles.Atari else if (registerAddr == 0x02) { // Read Output reg B - byte temp = core.ReadConsoleSwitches(); + byte temp = core.ReadConsoleSwitches(peek); temp = (byte)(temp & ~ddrb); return temp; diff --git a/BizHawk.Emulation/Consoles/Atari/2600/TIA.cs b/BizHawk.Emulation/Consoles/Atari/2600/TIA.cs index 38a479ce36..8cf88a2c10 100644 --- a/BizHawk.Emulation/Consoles/Atari/2600/TIA.cs +++ b/BizHawk.Emulation/Consoles/Atari/2600/TIA.cs @@ -999,8 +999,8 @@ namespace BizHawk.Emulation.Consoles.Atari } } } - - public byte ReadMemory(ushort addr) + + public byte ReadMemory(ushort addr, bool peek) { ushort maskedAddr = (ushort)(addr & 0x000F); if (maskedAddr == 0x00) // CXM0P @@ -1050,11 +1050,11 @@ namespace BizHawk.Emulation.Consoles.Atari } else if (maskedAddr == 0x0C) // INPT4 { - return (byte)((core.ReadControls1() & 0x08) != 0 ? 0x80 : 0x00); + return (byte)((core.ReadControls1(peek) & 0x08) != 0 ? 0x80 : 0x00); } else if (maskedAddr == 0x0D) // INPT5 { - return (byte)((core.ReadControls2() & 0x08) != 0 ? 0x80 : 0x00); + return (byte)((core.ReadControls2(peek) & 0x08) != 0 ? 0x80 : 0x00); } return 0x00; diff --git a/BizHawk.Emulation/Consoles/Atari/2600/oldTIA.cs b/BizHawk.Emulation/Consoles/Atari/2600/oldTIA.cs index d3ec3f3823..a30a690d93 100644 --- a/BizHawk.Emulation/Consoles/Atari/2600/oldTIA.cs +++ b/BizHawk.Emulation/Consoles/Atari/2600/oldTIA.cs @@ -352,7 +352,7 @@ namespace BizHawk.Emulation.Consoles.Atari } } - public byte ReadMemory(ushort addr) + public byte ReadMemory(ushort addr, bool peek) { ushort maskedAddr = (ushort)(addr & 0x000F); Console.WriteLine("TIA read: " + maskedAddr.ToString("x")); @@ -370,12 +370,12 @@ namespace BizHawk.Emulation.Consoles.Atari { if (inpt4 == true) { - inpt4 = ((core.ReadControls1() & 0x08) != 0); + inpt4 = ((core.ReadControls1(peek) & 0x08) != 0); } } else { - inpt4 = ((core.ReadControls1() & 0x08) != 0); + inpt4 = ((core.ReadControls1(peek) & 0x08) != 0); } return (byte)(inpt4 ? 0x80 : 0x00);