ref: 8e588754bccfbc8446e9d5092cd99fdc071d8188
parent: 52ab0d153472f74effbcbd7fbfb6faa84dd80e61
author: aiju <devnull@localhost>
date: Thu Apr 2 18:09:34 EDT 2015
games/gba: fix -3 crash and prevent >100% speed
--- a/sys/src/games/gba/dat.h
+++ b/sys/src/games/gba/dat.h
@@ -141,6 +141,8 @@
KB = 1024,
BACKTYPELEN = 64,
HZ = 16777216,
+ MILLION = 1000000,
+ BILLION = 1000000000,
};
typedef struct Var Var;
--- a/sys/src/games/gba/gba.c
+++ b/sys/src/games/gba/gba.c
@@ -317,6 +317,8 @@
extern uchar pic[];
Mouse m;
int x;
+ static vlong old, delta;
+ vlong new, diff;
if(nbrecvul(mc->resizec) > 0){
if(getwindow(display, Refnone) < 0)
@@ -347,7 +349,20 @@
flushimage(display, 1);
if(profile)
timing();
- audioout();
+ if(audioout() < 0){
+ new = nsec();
+ diff = 0;
+ if(old != 0){
+ diff = BILLION/60 - (new - old) - delta;
+ if(diff >= MILLION)
+ sleep(diff/MILLION);
+ }
+ old = nsec();
+ if(diff != 0){
+ diff = (old - new) - (diff / MILLION) * MILLION;
+ delta += (diff - delta) / 100;
+ }
+ }
if(framestep){
paused = 1;
qlock(&pauselock);
--- a/sys/src/games/gba/ppu.c
+++ b/sys/src/games/gba/ppu.c
@@ -754,7 +754,8 @@
setif(IRQVCTR);
}else{
syncppu(240);
- linecopy();
+ if(ppuy < 160)
+ linecopy();
addevent(&evhblank, 68*4);
hblank = 1;
if((stat & IRQHBLEN) != 0)