git: 9front

Download patch

ref: b68b2cd425a4ab62b6fb62d5906d2f1de5a8f1a6
parent: b56415003ebff96da9228e9df82e66bc15492ad4
author: aiju <aiju@phicode.de>
date: Sat Aug 25 18:13:29 EDT 2012

gb: pause function

--- 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 @@
 	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);
 	}
 }
--- 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 @@
 		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 @@
 			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;
@@ -269,6 +277,10 @@
 		if(loadreq){
 			loadstate("gb.save");
 			loadreq = 0;
+		}
+		if(paused){
+			qlock(&pauselock);
+			qunlock(&pauselock);
 		}
 		t = step();
 		clock += t;
--