@@ -1076,7 +1076,7 @@ protected override void Dispose(bool disposing)
10761076 private bool _emulatorPaused ;
10771077 public bool EmulatorPaused
10781078 {
1079- get => _emulatorPaused ;
1079+ get => _emulatorPaused && ! _unpauseByFrameAdvance ;
10801080
10811081 private set
10821082 {
@@ -1088,6 +1088,23 @@ private set
10881088 }
10891089 }
10901090
1091+ private bool _unpauseByFrameAdvance ;
1092+
1093+ /// <summary>
1094+ /// Avoids using EmulatorPaused to handle frame advance, thus allowing Lua to unpause during a frame advance.
1095+ /// </summary>
1096+ private bool UnpauseByFrameAdvance
1097+ {
1098+ get => _unpauseByFrameAdvance ;
1099+ set
1100+ {
1101+ if ( _unpauseByFrameAdvance == value ) return ;
1102+ _unpauseByFrameAdvance = value ;
1103+
1104+ OnPauseToggle ( ! value ) ;
1105+ }
1106+ }
1107+
10911108 private void OnPauseToggle ( bool newPauseState )
10921109 {
10931110 if ( ! newPauseState ) // Unpausing
@@ -2936,21 +2953,22 @@ private void StepRunLoop_Core(bool force = false)
29362953 // handle the initial trigger of a frame advance
29372954 runFrame = true ;
29382955 _frameAdvanceTimestamp = currentTimestamp ;
2956+ // Pausing is inconsistent with the behavior of TAStudio while seeking, but it's always been this way so.
29392957 PauseEmulator ( ) ;
29402958 }
29412959 else if ( frameProgressTimeElapsed )
29422960 {
29432961 runFrame = true ;
29442962 _runloopFrameProgress = true ;
2945- UnpauseEmulator ( ) ;
2963+ UnpauseByFrameAdvance = true ;
29462964 }
29472965 }
29482966 else
29492967 {
29502968 if ( _runloopFrameAdvance )
29512969 {
29522970 // handle release of frame advance
2953- PauseEmulator ( ) ;
2971+ UnpauseByFrameAdvance = false ;
29542972 }
29552973 _runloopFrameProgress = false ;
29562974 }
0 commit comments