From c80e250ae7a871b5a13edc1900d7c12873dd5fb8 Mon Sep 17 00:00:00 2001 From: alyosha-tas Date: Mon, 23 May 2016 20:29:57 -0400 Subject: [PATCH 1/9] Add data bus state and track it fixes AVGN KO boxing --- .../Consoles/Atari/2600/Tia/TIA.cs | 54 ++++++++++++++----- 1 file changed, 40 insertions(+), 14 deletions(-) diff --git a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Tia/TIA.cs b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Tia/TIA.cs index b15f6751e2..e48ec3d29f 100644 --- a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Tia/TIA.cs +++ b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Tia/TIA.cs @@ -269,6 +269,8 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 private int[] _palette; + public int bus_state; + private byte pf0_update; private byte pf1_update; private byte pf2_update; @@ -419,6 +421,8 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 _CurrentScanLine = 0; _audioClocks = 0; + bus_state = 0; + pf0_update = 0; pf1_update = 0; pf2_update = 0; @@ -716,7 +720,7 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 } } - if (_playField.Score && !_playField.Priority && (collisions & CXPF) != 0 && _core.Settings.ShowPlayfield) + if (_playField.Score && !_playField.Priority && ((collisions & CXPF) != 0) && _core.Settings.ShowPlayfield) { pixelColor = !rightSide ? _palette[_player0.Color] : _palette[_player1.Color]; } @@ -1047,44 +1051,55 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 public byte ReadMemory(ushort addr, bool peek) { var maskedAddr = (ushort)(addr & 0x000F); + byte coll = 0; + int mask = 0; + if (maskedAddr == 0x00) // CXM0P { - return (byte)((((_player0.Missile.Collisions & CXP1) != 0) ? 0x80 : 0x00) | (((_player0.Missile.Collisions & CXP0) != 0) ? 0x40 : 0x00)); + coll=(byte)((((_player0.Missile.Collisions & CXP1) != 0) ? 0x80 : 0x00) | (((_player0.Missile.Collisions & CXP0) != 0) ? 0x40 : 0x00)); + mask = 0x3f; } if (maskedAddr == 0x01) // CXM1P { - return (byte)((((_player1.Missile.Collisions & CXP0) != 0) ? 0x80 : 0x00) | (((_player1.Missile.Collisions & CXP1) != 0) ? 0x40 : 0x00)); + coll = (byte)((((_player1.Missile.Collisions & CXP0) != 0) ? 0x80 : 0x00) | (((_player1.Missile.Collisions & CXP1) != 0) ? 0x40 : 0x00)); + mask = 0x3f; } if (maskedAddr == 0x02) // CXP0FB { - return (byte)((((_player0.Collisions & CXPF) != 0) ? 0x80 : 0x00) | (((_player0.Collisions & CXBL) != 0) ? 0x40 : 0x00)); + coll = (byte)((((_player0.Collisions & CXPF) != 0) ? 0x80 : 0x00) | (((_player0.Collisions & CXBL) != 0) ? 0x40 : 0x00)); + mask = 0x3f; } if (maskedAddr == 0x03) // CXP1FB { - return (byte)((((_player1.Collisions & CXPF) != 0) ? 0x80 : 0x00) | (((_player1.Collisions & CXBL) != 0) ? 0x40 : 0x00)); + coll = (byte)((((_player1.Collisions & CXPF) != 0) ? 0x80 : 0x00) | (((_player1.Collisions & CXBL) != 0) ? 0x40 : 0x00)); + mask = 0x3f; } if (maskedAddr == 0x04) // CXM0FB { - return (byte)((((_player0.Missile.Collisions & CXPF) != 0) ? 0x80 : 0x00) | (((_player0.Missile.Collisions & CXBL) != 0) ? 0x40 : 0x00)); + coll = (byte)((((_player0.Missile.Collisions & CXPF) != 0) ? 0x80 : 0x00) | (((_player0.Missile.Collisions & CXBL) != 0) ? 0x40 : 0x00)); + mask = 0x3f; } if (maskedAddr == 0x05) // CXM1FB { - return (byte)((((_player1.Missile.Collisions & CXPF) != 0) ? 0x80 : 0x00) | (((_player1.Missile.Collisions & CXBL) != 0) ? 0x40 : 0x00)); + coll = (byte)((((_player1.Missile.Collisions & CXPF) != 0) ? 0x80 : 0x00) | (((_player1.Missile.Collisions & CXBL) != 0) ? 0x40 : 0x00)); + mask = 0x3f; } if (maskedAddr == 0x06) // CXBLPF { - return (byte)(((_ball.Collisions & CXPF) != 0) ? 0x80 : 0x00); + coll = (byte)(((_ball.Collisions & CXPF) != 0) ? 0x80 : 0x00); + mask = 0x7f; } if (maskedAddr == 0x07) // CXPPMM { - return (byte)((((_player0.Collisions & CXP1) != 0) ? 0x80 : 0x00) | (((_player0.Missile.Collisions & CXM1) != 0) ? 0x40 : 0x00)); + coll = (byte)((((_player0.Collisions & CXP1) != 0) ? 0x80 : 0x00) | (((_player0.Missile.Collisions & CXM1) != 0) ? 0x40 : 0x00)); + mask = 0x3f; } if (maskedAddr == 0x08) // INPT0 @@ -1093,28 +1108,37 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 // 6105 roughly centers the paddle in Breakout if (_capCharging && _core.Cpu.TotalExecutedCycles - _capChargeStart >= 6105) { - return 0x80; + coll=0x80; } - return 0x00; + coll=0x00; + mask = 0x7f; } if (maskedAddr == 0x0C) // INPT4 { - return (byte)((_core.ReadControls1(peek) & 0x08) != 0 ? 0x80 : 0x00); + coll = (byte)((_core.ReadControls1(peek) & 0x08) != 0 ? 0x80 : 0x00); + mask = 0x7f; } if (maskedAddr == 0x0D) // INPT5 { - return (byte)((_core.ReadControls2(peek) & 0x08) != 0 ? 0x80 : 0x00); + coll = (byte)((_core.ReadControls2(peek) & 0x08) != 0 ? 0x80 : 0x00); + mask = 0x7f; } - return 0x00; + //some bits of the databus will be undriven when a read call is made. Our goal here is to sort out what + // happens to the undriven pins. Most of the time, they will be in whatever state they were when previously + //assigned in some other bus access, so let's go with that. + coll+=(byte)(mask & bus_state); + bus_state = (int)coll; + return coll; } public void WriteMemory(ushort addr, byte value) { var maskedAddr = (ushort)(addr & 0x3f); + bus_state = value; if (maskedAddr == 0x00) // VSYNC { @@ -1575,6 +1599,8 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 ser.Sync("hsyncCnt", ref _hsyncCnt); // add everything to the state + ser.Sync("Bus_State", ref bus_state); + ser.Sync("PF0_up",ref pf0_update); ser.Sync("PF1_up", ref pf1_update); ser.Sync("PF2_up", ref pf2_update); From 7a16d7c49a4440fecbc984df7ddeffe00411242d Mon Sep 17 00:00:00 2001 From: alyosha-tas Date: Mon, 23 May 2016 20:31:55 -0400 Subject: [PATCH 2/9] Add data bus state and track it fixes AVGN KO boxing --- .../Consoles/Atari/2600/Atari2600.Core.cs | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.Core.cs b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.Core.cs index a72c3ebdf9..af3928a556 100644 --- a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.Core.cs +++ b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.Core.cs @@ -36,10 +36,12 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 if ((addr & 0x1080) == 0x0080) { - return M6532.ReadMemory(addr, false); + _tia.bus_state = M6532.ReadMemory(addr, false); + return M6532.ReadMemory(addr, false); } - return Rom[addr & 0x0FFF]; + _tia.bus_state = Rom[addr & 0x0FFF]; + return Rom[addr & 0x0FFF]; } internal byte BasePeekMemory(ushort addr) @@ -52,15 +54,17 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 if ((addr & 0x1080) == 0x0080) { - return M6532.ReadMemory(addr, true); + _tia.bus_state = M6532.ReadMemory(addr, false); + return M6532.ReadMemory(addr, true); } - - return Rom[addr & 0x0FFF]; + _tia.bus_state = Rom[addr & 0x0FFF]; + return Rom[addr & 0x0FFF]; } internal void BaseWriteMemory(ushort addr, byte value) { - if (addr != LastAddress) + _tia.bus_state = value; + if (addr != LastAddress) { DistinctAccessCount++; LastAddress = addr; @@ -83,7 +87,8 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 internal void BasePokeMemory(ushort addr, byte value) { - addr = (ushort)(addr & 0x1FFF); + _tia.bus_state = value; + addr = (ushort)(addr & 0x1FFF); if ((addr & 0x1080) == 0) { _tia.WriteMemory(addr, value); @@ -108,6 +113,7 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 _mapper.Bit13 = addr.Bit(13); var temp = _mapper.ReadMemory((ushort)(addr & 0x1FFF)); + _tia.bus_state = temp; MemoryCallbacks.CallReads(addr); return temp; @@ -116,7 +122,7 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 internal byte PeekMemory(ushort addr) { var temp = _mapper.ReadMemory((ushort)(addr & 0x1FFF)); - + _tia.bus_state = temp; return temp; } From 5520627b7eb708d0bb672bf4d436e489ec498f87 Mon Sep 17 00:00:00 2001 From: alyosha-tas Date: Wed, 25 May 2016 12:37:23 -0400 Subject: [PATCH 3/9] Fix Peek_memory so it points to mapper Peek_memory --- .../Consoles/Atari/2600/Atari2600.Core.cs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.Core.cs b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.Core.cs index af3928a556..19fcd5a887 100644 --- a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.Core.cs +++ b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.Core.cs @@ -54,10 +54,8 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 if ((addr & 0x1080) == 0x0080) { - _tia.bus_state = M6532.ReadMemory(addr, false); return M6532.ReadMemory(addr, true); } - _tia.bus_state = Rom[addr & 0x0FFF]; return Rom[addr & 0x0FFF]; } @@ -87,7 +85,6 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 internal void BasePokeMemory(ushort addr, byte value) { - _tia.bus_state = value; addr = (ushort)(addr & 0x1FFF); if ((addr & 0x1080) == 0) { @@ -121,8 +118,7 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 internal byte PeekMemory(ushort addr) { - var temp = _mapper.ReadMemory((ushort)(addr & 0x1FFF)); - _tia.bus_state = temp; + var temp = _mapper.PeekMemory((ushort)(addr & 0x1FFF)); return temp; } From de48c1cf2c543f814ec40ecf9a7201b195ea7fa6 Mon Sep 17 00:00:00 2001 From: alyosha-tas Date: Wed, 25 May 2016 12:38:28 -0400 Subject: [PATCH 4/9] check for protection from memory peeks WIP --- BizHawk.Emulation.Cores/Consoles/Atari/2600/Tia/TIA.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Tia/TIA.cs b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Tia/TIA.cs index e48ec3d29f..f134ca4a24 100644 --- a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Tia/TIA.cs +++ b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Tia/TIA.cs @@ -1131,6 +1131,8 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 // happens to the undriven pins. Most of the time, they will be in whatever state they were when previously //assigned in some other bus access, so let's go with that. coll+=(byte)(mask & bus_state); + + // this might need to be peek protected, let's just make a note of it for now bus_state = (int)coll; return coll; } @@ -1138,6 +1140,7 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 public void WriteMemory(ushort addr, byte value) { var maskedAddr = (ushort)(addr & 0x3f); + // this might need to be poke protected, let's just make a note of it for now bus_state = value; if (maskedAddr == 0x00) // VSYNC From cbad691741e4db76cb147226c2a66f5c10fdd562 Mon Sep 17 00:00:00 2001 From: alyosha-tas Date: Wed, 25 May 2016 12:39:41 -0400 Subject: [PATCH 5/9] Protect bank state from peeks Also properly check bank swapping --- .../Consoles/Atari/2600/Mappers/m4A50.cs | 167 +++++++++--------- 1 file changed, 84 insertions(+), 83 deletions(-) diff --git a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Mappers/m4A50.cs b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Mappers/m4A50.cs index 23e278fc1a..e786465806 100644 --- a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Mappers/m4A50.cs +++ b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Mappers/m4A50.cs @@ -170,15 +170,17 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 { val = RomImage[(addr & 0xff) + (RomImage.Length - 256)]; if (((_lastData & 0xe0) == 0x60) && ((_lastAddress >= 0x1000) || - (_lastAddress < 0x200))) + (_lastAddress < 0x200)) && !peek) { _sliceHigh = (_sliceHigh & 0xf0ff) | ((addr & 0x8) << 8) | ((addr & 0x70) << 4); } } - - _lastData = val; - _lastAddress = (ushort)(addr & 0x1fff); + if (!peek) + { + _lastData = val; + _lastAddress = (ushort)(addr & 0x1fff); + } return val; } @@ -226,7 +228,7 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 else if (addr < 0x2000 && !poke) // 256B region at 0x1f00 - 0x1fff { if (((_lastData & 0xe0) == 0x60) && - ((_lastAddress >= 0x1000) || (_lastAddress < 0x200))) + ((_lastAddress >= 0x1000) || (_lastAddress < 0x200)) && !poke) { _sliceHigh = (_sliceHigh & 0xf0ff) | ((addr & 0x8) << 8) | ((addr & 0x70) << 4); @@ -252,96 +254,95 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 private void CheckBankSwitch(ushort address, byte value) { - if (((_lastData & 0xe0) == 0x60) && // Switch lower/middle/upper bank - ((_lastAddress >= 0x1000) || (_lastAddress < 0x200))) + if (((_lastData & 0xe0) == 0x60) && // Switch lower/middle/upper bank + ((_lastAddress >= 0x1000) || (_lastAddress < 0x200))) + { + if ((address & 0x0f00) == 0x0c00) // Enable 256B of ROM at 0x1e00 - 0x1eff + { + _isRomHigh = true; + _sliceHigh = (address & 0xff) << 8; + } + else if ((address & 0x0f00) == 0x0d00) // Enable 256B of RAM at 0x1e00 - 0x1eff + { + _isRomHigh = false; + _sliceHigh = (address & 0x7f) << 8; + } + else if ((address & 0x0f40) == 0x0e00) // Enable 2K of ROM at 0x1000 - 0x17ff + { + _isRomLow = true; + _sliceLow = (address & 0x1f) << 11; + } + else if ((address & 0x0f40) == 0x0e40) // Enable 2K of RAM at 0x1000 - 0x17ff + { + _isRomLow = false; + _sliceLow = (address & 0xf) << 11; + } + else if ((address & 0x0f40) == 0x0f00) // Enable 1.5K of ROM at 0x1800 - 0x1dff + { + _isRomMiddle = true; + _sliceMiddle = (address & 0x1f) << 11; + } + else if ((address & 0x0f50) == 0x0f40) // Enable 1.5K of RAM at 0x1800 - 0x1dff + { + _isRomMiddle = false; + _sliceMiddle = (address & 0xf) << 11; + } + else if ((address & 0x0f00) == 0x0400) // Toggle bit A11 of lower block address + { + _sliceLow = _sliceLow ^ 0x800; + } + else if ((address & 0x0f00) == 0x0500) // Toggle bit A12 of lower block address + { + _sliceLow = _sliceLow ^ 0x1000; + } + else if ((address & 0x0f00) == 0x0800) // Toggle bit A11 of middle block address + { + _sliceMiddle = _sliceMiddle ^ 0x800; + } + else if ((address & 0x0f00) == 0x0900) // Toggle bit A12 of middle block address + { + _sliceMiddle = _sliceMiddle ^ 0x1000; + } + } + // Zero-page hotspots for upper page + // 0xf4, 0xf6, 0xfc, 0xfe for ROM + // 0xf5, 0xf7, 0xfd, 0xff for RAM + // 0x74 - 0x7f (0x80 bytes lower) + if ((address & 0xf75) == 0x74) // Enable 256B of ROM at 0x1e00 - 0x1eff { - if ((address & 0x0f00) == 0x0c00) // Enable 256B of ROM at 0x1e00 - 0x1eff - { - _isRomHigh = true; - _sliceHigh = (address & 0xff) << 8; - } - else if ((address & 0x0f00) == 0x0d00) // Enable 256B of RAM at 0x1e00 - 0x1eff - { - _isRomHigh = false; - _sliceHigh = (address & 0x7f) << 8; - } - else if ((address & 0x0f40) == 0x0e00) // Enable 2K of ROM at 0x1000 - 0x17ff + _isRomHigh = true; + _sliceHigh = value << 8; + } + else if ((address & 0xf75) == 0x75) // Enable 256B of RAM at 0x1e00 - 0x1eff + { + _isRomHigh = false; + _sliceHigh = (value & 0x7f) << 8; + } + + // Zero-page hotspots for lower and middle blocks + // 0xf8, 0xf9, 0xfa, 0xfb + // 0x78, 0x79, 0x7a, 0x7b (0x80 bytes lower) + else if ((address & 0xf7c) == 0x78) + { + if ((value & 0xf0) == 0) // Enable 2K of ROM at 0x1000 - 0x17ff { _isRomLow = true; - _sliceLow = (address & 0x1f) << 11; + _sliceLow = (value & 0xf) << 11; } - else if ((address & 0x0f40) == 0x0e40) // Enable 2K of RAM at 0x1000 - 0x17ff + else if ((value & 0xf0) == 0x40) // Enable 2K of RAM at 0x1000 - 0x17ff { _isRomLow = false; - _sliceLow = (address & 0xf) << 11; + _sliceLow = (value & 0xf) << 11; } - else if ((address & 0x0f40) == 0x0f00) // Enable 1.5K of ROM at 0x1800 - 0x1dff + else if ((value & 0xf0) == 0x90) // Enable 1.5K of ROM at 0x1800 - 0x1dff { _isRomMiddle = true; - _sliceMiddle = (address & 0x1f) << 11; + _sliceMiddle = ((value & 0xf) | 0x10) << 11; } - else if ((address & 0x0f50) == 0x0f40) // Enable 1.5K of RAM at 0x1800 - 0x1dff + else if ((value & 0xf0) == 0xc0) // Enable 1.5K of RAM at 0x1800 - 0x1dff { _isRomMiddle = false; - _sliceMiddle = (address & 0xf) << 11; - } - else if ((address & 0x0f00) == 0x0400) // Toggle bit A11 of lower block address - { - _sliceLow = _sliceLow ^ 0x800; - } - else if ((address & 0x0f00) == 0x0500) // Toggle bit A12 of lower block address - { - _sliceLow = _sliceLow ^ 0x1000; - } - else if ((address & 0x0f00) == 0x0800) // Toggle bit A11 of middle block address - { - _sliceMiddle = _sliceMiddle ^ 0x800; - } - else if ((address & 0x0f00) == 0x0900) // Toggle bit A12 of middle block address - { - _sliceMiddle = _sliceMiddle ^ 0x1000; - } - - // Zero-page hotspots for upper page - // 0xf4, 0xf6, 0xfc, 0xfe for ROM - // 0xf5, 0xf7, 0xfd, 0xff for RAM - // 0x74 - 0x7f (0x80 bytes lower) - if ((address & 0xf75) == 0x74) // Enable 256B of ROM at 0x1e00 - 0x1eff - { - _isRomHigh = true; - _sliceHigh = value << 8; - } - else if ((address & 0xf75) == 0x75) // Enable 256B of RAM at 0x1e00 - 0x1eff - { - _isRomHigh = false; - _sliceHigh = (value & 0x7f) << 8; - } - - // Zero-page hotspots for lower and middle blocks - // 0xf8, 0xf9, 0xfa, 0xfb - // 0x78, 0x79, 0x7a, 0x7b (0x80 bytes lower) - else if ((address & 0xf7c) == 0x78) - { - if ((value & 0xf0) == 0) // Enable 2K of ROM at 0x1000 - 0x17ff - { - _isRomLow = true; - _sliceLow = (value & 0xf) << 11; - } - else if ((value & 0xf0) == 0x40) // Enable 2K of RAM at 0x1000 - 0x17ff - { - _isRomLow = false; - _sliceLow = (value & 0xf) << 11; - } - else if ((value & 0xf0) == 0x90) // Enable 1.5K of ROM at 0x1800 - 0x1dff - { - _isRomMiddle = true; - _sliceMiddle = ((value & 0xf) | 0x10) << 11; - } - else if ((value & 0xf0) == 0xc0) // Enable 1.5K of RAM at 0x1800 - 0x1dff - { - _isRomMiddle = false; - _sliceMiddle = (value & 0xf) << 11; - } + _sliceMiddle = (value & 0xf) << 11; } } } From d192d760527457c4337d6c603fd73e876a55c8c5 Mon Sep 17 00:00:00 2001 From: alyosha-tas Date: Wed, 25 May 2016 18:10:05 -0400 Subject: [PATCH 6/9] Add vblank delay to fix 4A50 demo game --- .../Consoles/Atari/2600/Tia/TIA.cs | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Tia/TIA.cs b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Tia/TIA.cs index f134ca4a24..8abe34a3b8 100644 --- a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Tia/TIA.cs +++ b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Tia/TIA.cs @@ -291,6 +291,9 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 private bool enam1_val; private bool enamb_val; + private int vblank_delay; + private byte vblank_value; + private bool p0_stuff; private bool p1_stuff; private bool m0_stuff; @@ -417,6 +420,8 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 _capChargeStart = 0; _capCharging = false; _vblankEnabled = false; + vblank_delay = 0; + vblank_value = 0; _vsyncEnabled = false; _CurrentScanLine = 0; _audioClocks = 0; @@ -476,6 +481,20 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 { // Still ignoring cycles... + // delay vblank latch + if (vblank_delay > 0) + { + vblank_delay++; + if (vblank_delay==3) + { + _vblankEnabled = (vblank_value & 0x02) != 0; + vblank_delay = 0; + } + + } + + + //delay latch to new playfield register if (pf0_updater == true) { @@ -1172,7 +1191,8 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 } else if (maskedAddr == 0x01) // VBLANK { - _vblankEnabled = (value & 0x02) != 0; + vblank_delay = 1; + vblank_value = value; _capCharging = (value & 0x80) == 0; if ((value & 0x80) == 0) { @@ -1642,7 +1662,8 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 ser.Sync("Ticks", ref do_ticks); - + ser.Sync("VBlankDelay", ref vblank_delay); + ser.Sync("VBlankValue", ref vblank_value); // some of these things weren't in the state because they weren't needed if // states were always taken at frame boundaries From fe77d8718f2460edfd1d2efbded568ae5352be92 Mon Sep 17 00:00:00 2001 From: alyosha-tas Date: Fri, 27 May 2016 08:51:49 -0400 Subject: [PATCH 7/9] Add poke flag --- .../Consoles/Atari/2600/Atari2600.IMemoryDomains.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.IMemoryDomains.cs b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.IMemoryDomains.cs index fdaa55729f..9dca7df95a 100644 --- a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.IMemoryDomains.cs +++ b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.IMemoryDomains.cs @@ -20,7 +20,7 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 16, MemoryDomain.Endian.Little, addr => _tia.ReadMemory((ushort)addr, true), - (addr, value) => this._tia.WriteMemory((ushort)addr, value), 1), + (addr, value) => this._tia.WriteMemory((ushort)addr, value, true), 1), new MemoryDomainDelegate( "PIA", 1024, From bd5616050a87eba3ff1b0e6e9225881d4f0549bf Mon Sep 17 00:00:00 2001 From: alyosha-tas Date: Fri, 27 May 2016 08:52:24 -0400 Subject: [PATCH 8/9] Add poke flag --- BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.Core.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.Core.cs b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.Core.cs index 19fcd5a887..adf307eaa1 100644 --- a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.Core.cs +++ b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.Core.cs @@ -71,7 +71,7 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 addr = (ushort)(addr & 0x1FFF); if ((addr & 0x1080) == 0) { - _tia.WriteMemory(addr, value); + _tia.WriteMemory(addr, value, false); } else if ((addr & 0x1080) == 0x0080) { @@ -88,7 +88,7 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 addr = (ushort)(addr & 0x1FFF); if ((addr & 0x1080) == 0) { - _tia.WriteMemory(addr, value); + _tia.WriteMemory(addr, value, true); } else if ((addr & 0x1080) == 0x0080) { From d5c4d2f0375482ca4aa28640769cafd965c64fcd Mon Sep 17 00:00:00 2001 From: alyosha-tas Date: Fri, 27 May 2016 08:53:37 -0400 Subject: [PATCH 9/9] Add poke flag the point of this is to protect the data bus state --- BizHawk.Emulation.Cores/Consoles/Atari/2600/Tia/TIA.cs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Tia/TIA.cs b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Tia/TIA.cs index 8abe34a3b8..d381e798f8 100644 --- a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Tia/TIA.cs +++ b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Tia/TIA.cs @@ -1151,16 +1151,14 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 //assigned in some other bus access, so let's go with that. coll+=(byte)(mask & bus_state); - // this might need to be peek protected, let's just make a note of it for now - bus_state = (int)coll; + if (!peek) bus_state = (int)coll; return coll; } - public void WriteMemory(ushort addr, byte value) + public void WriteMemory(ushort addr, byte value, bool poke) { var maskedAddr = (ushort)(addr & 0x3f); - // this might need to be poke protected, let's just make a note of it for now - bus_state = value; + if (!poke) bus_state = value; if (maskedAddr == 0x00) // VSYNC {