From 8e588754bccfbc8446e9d5092cd99fdc071d8188 Mon Sep 17 00:00:00 2001 From: aiju Date: Thu, 2 Apr 2015 22:09:34 +0200 Subject: games/gba: fix -3 crash and prevent >100% speed --- sys/src/games/gba/dat.h | 2 ++ sys/src/games/gba/gba.c | 17 ++++++++++++++++- sys/src/games/gba/ppu.c | 3 ++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/sys/src/games/gba/dat.h b/sys/src/games/gba/dat.h index 4f4651c0a..a609b850b 100644 --- a/sys/src/games/gba/dat.h +++ b/sys/src/games/gba/dat.h @@ -141,6 +141,8 @@ enum { KB = 1024, BACKTYPELEN = 64, HZ = 16777216, + MILLION = 1000000, + BILLION = 1000000000, }; typedef struct Var Var; diff --git a/sys/src/games/gba/gba.c b/sys/src/games/gba/gba.c index bfb65c738..cebd1a830 100644 --- a/sys/src/games/gba/gba.c +++ b/sys/src/games/gba/gba.c @@ -317,6 +317,8 @@ flush(void) 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 @@ flush(void) 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); diff --git a/sys/src/games/gba/ppu.c b/sys/src/games/gba/ppu.c index 85d1d0652..a87caba17 100644 --- a/sys/src/games/gba/ppu.c +++ b/sys/src/games/gba/ppu.c @@ -754,7 +754,8 @@ hblanktick(void *) setif(IRQVCTR); }else{ syncppu(240); - linecopy(); + if(ppuy < 160) + linecopy(); addevent(&evhblank, 68*4); hblank = 1; if((stat & IRQHBLEN) != 0) -- cgit v1.2.3