shithub: riscv

Download patch

ref: 5a34ad16cd040d163b50dcf7c070968dbd55ac43
parent: 177cbace733eeceaef54e2c1a4032c55d4e100dd
author: aiju <devnull@localhost>
date: Sat Mar 28 06:20:52 EDT 2015

games/gba: very subtle timer bug fixed

--- a/sys/src/games/gba/apu.c
+++ b/sys/src/games/gba/apu.c
@@ -209,7 +209,7 @@
 	s16int s[2];
 	int i;
 	
-	addevent(&evsamp, sratediv + evsamp.time);
+	addevent(&evsamp, sratediv);
 	
 	if(--envctr == 0){
 		envctr = envrel;
--- a/sys/src/games/gba/ev.c
+++ b/sys/src/games/gba/ev.c
@@ -185,9 +185,11 @@
 	Timer *t;
 	u32int v;
 	int to;
+	ulong clock0;
 	
 	t = aux;
-	t->clock = clock + t->time & -(1 << t->sh);
+	clock0 = clock + t->time;
+	t->clock = clock0 & -(1 << t->sh);
 	t->val = -t->time >> t->sh;
 	do{
 		to = 0;
@@ -196,7 +198,7 @@
 			to++;
 		}while(v >= 0x10000);
 		if(t == aux)
-			addevent(t, (0x10000 - t->val << t->sh) + (-clock & (1 << t->sh) - 1));
+			addevent(t, (0x10000 - t->val << t->sh) + (-clock0 & (1 << t->sh) - 1));
 		if((*t->cnt & TIMERIRQ) != 0)
 			setif(IRQTIM0 << t->i);
 		if(t->snd)
--- a/sys/src/games/gba/ppu.c
+++ b/sys/src/games/gba/ppu.c
@@ -733,7 +733,7 @@
 	stat = reg[DISPSTAT];
 	if(hblank){
 		hblclock = clock + evhblank.time;
-		addevent(&evhblank, 240*4 + evhblank.time);
+		addevent(&evhblank, 240*4);
 		hblank = 0;
 		ppux0 = 0;
 		memset(pixpri, VACANT, sizeof(pixpri));
@@ -755,7 +755,7 @@
 	}else{
 		syncppu(240);
 		linecopy();
-		addevent(&evhblank, 68*4 + evhblank.time);
+		addevent(&evhblank, 68*4);
 		hblank = 1;
 		if((stat & IRQHBLEN) != 0)
 			setif(IRQHBL);