diff --git a/sys/src/games/gb/audio.c b/sys/src/games/gb/audio.c index 09806cbed..898437446 100644 --- a/sys/src/games/gb/audio.c +++ b/sys/src/games/gb/audio.c @@ -7,6 +7,7 @@ static int fd; static int sc, ch1c, ch2c, ch3c, ch4c, ch4sr = 1, ch1vec, ch2vec, ch4vec, ch1v, ch2v, ch4v; +extern int paused; enum { SAMPLE = 44100 }; @@ -201,8 +202,11 @@ audioproc(void *) int i; for(;;){ - for(i = 0; i < sizeof samples/4; i++) - dosample(samples + 2 * i); + if(paused) + memset(samples, 0, sizeof samples); + else + for(i = 0; i < sizeof samples/4; i++) + dosample(samples + 2 * i); write(fd, samples, sizeof samples); } } diff --git a/sys/src/games/gb/gb.c b/sys/src/games/gb/gb.c index edc8e238a..bdeb9bbd8 100644 --- a/sys/src/games/gb/gb.c +++ b/sys/src/games/gb/gb.c @@ -9,10 +9,11 @@ #include "fns.h" uchar *cart, *ram; -int mbc, rombanks, rambanks, clock, ppuclock, divclock, timerclock, syncclock, syncfreq, sleeps, checkclock, msgclock, timerfreq, timer, keys, savefd, savereq, loadreq, scale; +int mbc, rombanks, rambanks, clock, ppuclock, divclock, timerclock, syncclock, syncfreq, sleeps, checkclock, msgclock, timerfreq, timer, keys, savefd, savereq, loadreq, scale, paused; Rectangle picr; Image *bg, *tmp; Mousectl *mc; +QLock pauselock; void message(char *fmt, ...) @@ -177,7 +178,7 @@ keyproc(void *) if(read(fd, buf, 256) <= 0) sysfatal("read /dev/kbd: %r"); if(buf[0] == 'c'){ - if(strchr(buf, Kesc)) + if(utfrune(buf, KF|12) || utfrune(buf, 'o')) threadexitsall(nil); if(utfrune(buf, KF|5)) savereq = 1; @@ -192,6 +193,13 @@ keyproc(void *) s += chartorune(&r, s); switch(r){ case Kesc: + if(paused) + qunlock(&pauselock); + else + qlock(&pauselock); + paused = !paused; + break; + case KF|12: threadexitsall(nil); case Kdown: keys |= 1<<3; @@ -270,6 +278,10 @@ threadmain(int argc, char** argv) loadstate("gb.save"); loadreq = 0; } + if(paused){ + qlock(&pauselock); + qunlock(&pauselock); + } t = step(); clock += t; ppuclock += t;