Re: [hatari-devel] Time overflow patch

[ Thread Index | Date Index | More lists.tuxfamily.org/hatari-devel Archives ]


----- Thomas Huth wrote:
> 
>  Hi,
> 
> Am Fri, 1 Nov 2013 15:09:42 -0600 (MDT)
> schrieb David Savinkoff <dsavnkff@xxxxxxxxx>:
> > 
> > Hatari will run for 292266 years (including leap seconds),
> > then stall for 292266 years; repeatedly.
> > 
> > This patch allows Hatari to run continuously.
> 
> Did you test this? ... ;-) Anyway, patch applied, thanks!
> 
>  Thomas
> 

Hi Thomas,

I'm withdrawing the previous patch 'time.overflow.diff'
because of a new problem that it doesn't address.

Please apply time.overflow3.diff.

I found that I can freeze Hatari by setting my system
clock backwards after Hatari is started.

1) Start Hatari and move mouse around.
2) date --set='-15 minutes'
3) Note Hatari is frozen
4) date --set='+15 minutes'
5) Note Hatari is Ok

Hatari did not appear to have delays due to the variables wrapping,
however, it does when the time is set backwards. When Sint32
variables are used, the delay is aliased on 71.58 minutes.

time.overflow2.diff is the 'test patch' using Sint32 variables
that wrap in 71.58 minutes. Both time.overflow2.diff and
time.overflow3.diff fix the freezing problem.

Sincerely,
David Savinkoff

--- hatari/src/main.c	2013-11-02 06:12:16.000000000 -0700
+++ hatari/src/main.c	2013-11-02 20:17:25.000000000 -0700
@@ -275,10 +275,11 @@
  */
 void Main_WaitOnVbl(void)
 {
-	Sint64 CurrentTicks;
-	static Sint64 DestTicks = -1;
-	Sint64 FrameDuration_micro;
-	Sint64 nDelay;
+	Sint32 CurrentTicks;
+	static Sint32 OldTicks = -1;
+	static Sint32 DestTicks = 0;
+	Sint32 FrameDuration_micro;
+	Sint32 nDelay;
 
 	nVBLCount++;
 	if (nRunVBLs &&	nVBLCount >= nRunVBLs)
@@ -292,7 +293,7 @@
 	FrameDuration_micro = ClocksTimings_GetVBLDuration_micro ( ConfigureParams.System.nMachineType , nScreenRefreshRate );
 	CurrentTicks = Time_GetTicks();
 
-	if ( DestTicks < 0 )			/* on first call or overflow, init DestTicks */
+	if (CurrentTicks - OldTicks < 0)	/* on first call or overflow, init DestTicks */
 		DestTicks = CurrentTicks + FrameDuration_micro;
 
 	DestTicks += pulse_swallowing_count;	/* audio.c - Audio_CallBack() */
@@ -344,13 +345,20 @@
 	/* Now busy-wait for the right tick: */
 	while (nDelay > 0)
 	{
+		OldTicks = CurrentTicks;
 		CurrentTicks = Time_GetTicks();
+
+		/*Re-initialize DestTicks if CurrentTicks wraps, or time is set backwards */
+		if (CurrentTicks - OldTicks < 0)
+			DestTicks = CurrentTicks;
+
 		nDelay = DestTicks - CurrentTicks;
 	}
 
 //printf ( "tick %lld\n" , CurrentTicks );
 	/* Update DestTicks for next VBL */
 	DestTicks += FrameDuration_micro;
+	OldTicks = CurrentTicks;
 }
 
 
--- hatari/src/main.c	2013-11-02 06:12:16.000000000 -0700
+++ hatari/src/main.c	2013-11-02 20:31:33.000000000 -0700
@@ -276,7 +276,8 @@
 void Main_WaitOnVbl(void)
 {
 	Sint64 CurrentTicks;
-	static Sint64 DestTicks = -1;
+	static Sint64 OldTicks = -1;
+	static Sint64 DestTicks = 0;
 	Sint64 FrameDuration_micro;
 	Sint64 nDelay;
 
@@ -292,7 +293,7 @@
 	FrameDuration_micro = ClocksTimings_GetVBLDuration_micro ( ConfigureParams.System.nMachineType , nScreenRefreshRate );
 	CurrentTicks = Time_GetTicks();
 
-	if ( DestTicks < 0 )			/* on first call or overflow, init DestTicks */
+	if (CurrentTicks - OldTicks < 0)	/* on first call or overflow, init DestTicks */
 		DestTicks = CurrentTicks + FrameDuration_micro;
 
 	DestTicks += pulse_swallowing_count;	/* audio.c - Audio_CallBack() */
@@ -344,13 +345,20 @@
 	/* Now busy-wait for the right tick: */
 	while (nDelay > 0)
 	{
+		OldTicks = CurrentTicks;
 		CurrentTicks = Time_GetTicks();
+
+		/*Re-initialize DestTicks if CurrentTicks wraps, or time is set backwards */
+		if (CurrentTicks - OldTicks < 0)
+			DestTicks = CurrentTicks;
+
 		nDelay = DestTicks - CurrentTicks;
 	}
 
 //printf ( "tick %lld\n" , CurrentTicks );
 	/* Update DestTicks for next VBL */
 	DestTicks += FrameDuration_micro;
+	OldTicks = CurrentTicks;
 }
 
 


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/