From 6a773ac272bfd84038e74a3eaea973bb4a77ff67 Mon Sep 17 00:00:00 2001 From: alyosha-tas Date: Sat, 20 Jul 2019 14:47:36 -0400 Subject: [PATCH] Atari 2600: more bug fixes --- .../Consoles/Atari/2600/Tia/TIA.cs | 46 ++++++++++++++++--- .../Consoles/Atari/2600/Tia/Tia.MissleData.cs | 6 ++- .../Consoles/Atari/2600/Tia/Tia.PlayerData.cs | 17 ++++++- .../Consoles/Atari/2600/Tia/Tia.SyncState.cs | 5 ++ 4 files changed, 65 insertions(+), 9 deletions(-) diff --git a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Tia/TIA.cs b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Tia/TIA.cs index 5140726551..4b9353f085 100644 --- a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Tia/TIA.cs +++ b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Tia/TIA.cs @@ -104,6 +104,11 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 private int _hmbDelay; private byte _hmbVal; + private int _nusiz0Delay; + private byte _nusiz0Val; + private int _nusiz1Delay; + private byte _nusiz1Val; + private int _hmClrDelay; private int _prg0Delay; @@ -223,6 +228,11 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 _hmbDelay = 0; _hmbVal = 0; + _nusiz0Delay = 0; + _nusiz0Val = 0; + _nusiz1Delay = 0; + _nusiz1Val = 0; + _prg0Delay = 0; _prg1Delay = 0; _prg0Val = 0; @@ -404,6 +414,32 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 } } + if (_nusiz0Delay > 0) + { + _nusiz0Delay++; + if (_nusiz0Delay == 4) + { + _nusiz0Delay = 0; + + _player0.Nusiz = (byte)(_nusiz0Val & 0x37); + _player0.Missile.Size = (byte)((_nusiz0Val & 0x30) >> 4); + _player0.Missile.Number = (byte)(_nusiz0Val & 0x07); + } + } + + if (_nusiz1Delay > 0) + { + _nusiz1Delay++; + if (_nusiz1Delay == 4) + { + _nusiz1Delay = 0; + + _player1.Nusiz = (byte)(_nusiz1Val & 0x37); + _player1.Missile.Size = (byte)((_nusiz1Val & 0x30) >> 4); + _player1.Missile.Number = (byte)(_nusiz1Val & 0x07); + } + } + // Reset the RDY flag when we reach hblank if (_hsyncCnt <= 0) { @@ -1054,15 +1090,13 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 } else if (maskedAddr == 0x04) // NUSIZ0 { - _player0.Nusiz = (byte)(value & 0x37); - _player0.Missile.Size = (byte)((value & 0x30) >> 4); - _player0.Missile.Number = (byte)(value & 0x07); + _nusiz0Delay = 1; + _nusiz0Val = value; } else if (maskedAddr == 0x05) // NUSIZ1 { - _player1.Nusiz = (byte)(value & 0x37); - _player1.Missile.Size = (byte)((value & 0x30) >> 4); - _player1.Missile.Number = (byte)(value & 0x07); + _nusiz1Delay = 1; + _nusiz1Val = value; } else if (maskedAddr == 0x06) // COLUP0 { diff --git a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Tia/Tia.MissleData.cs b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Tia/Tia.MissleData.cs index f6bab5dc25..38c579712b 100644 --- a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Tia/Tia.MissleData.cs +++ b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Tia/Tia.MissleData.cs @@ -82,7 +82,7 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 { _startSignal = HPosCnt; _signalReached = HPosCnt + 5; - if (HPosCnt != 156) { _draw_signaled = true; } + _draw_signaled = true; } if (_startSignal < _signalReached) @@ -111,6 +111,10 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 { _startSignal -= _startSignal - 60; } + else if (_startSignal < 161) + { + _startSignal -= _startSignal - 156; + } } } diff --git a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Tia/Tia.PlayerData.cs b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Tia/Tia.PlayerData.cs index 56773a173b..3d33f1426e 100644 --- a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Tia/Tia.PlayerData.cs +++ b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Tia/Tia.PlayerData.cs @@ -1,5 +1,9 @@ using BizHawk.Common; +// TODO: Some of the values that are being latched (like Nusiz) are being latched based on the internal player ticks, not the external hsync ticks. +// This can be seen for example in the player32_hblank test ROM. +// Which values these are exactly needs to be more carefully studied. + namespace BizHawk.Emulation.Cores.Atari.Atari2600 { public partial class TIA @@ -104,9 +108,13 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 } } } - else + else if (ScanCntInit) { ScanCntInit = false; + //ScanCnt++; + } + else + { ScanCnt++; } } @@ -164,7 +172,7 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 { _startSignal = HPosCnt - 1; _signalReached = HPosCnt + 5; - if (HPosCnt != 156) { _draw_signaled = true; } + _draw_signaled = true; } if (_startSignal < _signalReached) @@ -193,6 +201,11 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 { _startSignal -= _startSignal - 60; } + + else if (_startSignal < 161) + { + _startSignal -= _startSignal - 156; + } } } diff --git a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Tia/Tia.SyncState.cs b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Tia/Tia.SyncState.cs index 8881944917..deb62d3a7b 100644 --- a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Tia/Tia.SyncState.cs +++ b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Tia/Tia.SyncState.cs @@ -51,6 +51,11 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 ser.Sync("hmb_delay", ref _hmbDelay); ser.Sync("hmb_val", ref _hmbVal); + ser.Sync("_nusiz0Delay", ref _nusiz0Delay); + ser.Sync("_nusiz0Val", ref _nusiz0Val); + ser.Sync("_nusiz1Delay", ref _nusiz1Delay); + ser.Sync("_nusiz1Val", ref _nusiz1Val); + ser.Sync("_hmClrDelay", ref _hmClrDelay); ser.Sync("PRG0_delay", ref _prg0Delay);