code: plan9front

Download patch

ref: cb5b36f7c62545b92bbe577175de82c6c6cc9be9
parent: 53d55013598d7cd214d01cbf0b026844fe7ca8d2
author: qwx <qwx@sciops.net>
date: Tue Feb 28 18:37:21 EST 2023

games/dmid: fix running status for streams

regression from previous commits; better handling

--- a/sys/src/games/dmid.c
+++ b/sys/src/games/dmid.c
@@ -149,13 +149,12 @@
 {
 	u8int v;
 
-	if(x == nil){
+	if(x == nil || x->p == nil)
 		Bread(ib, &v, 1);
-		return v;
-	}
-	if(x->p >= x->e || x->ended)
+	else if(x->p >= x->e || x->ended)
 		sysfatal("track overflow");
-	v = *x->p++;
+	else
+		v = *x->p++;
 	dprint("%02ux", v);
 	return v;
 }
@@ -397,17 +396,17 @@
 
 	dprint(" [%zd] ", x - tr);
 	e = get8(x);
-	if(x != nil){
-		if((e & 0x80) == 0){
+	if((e & 0x80) == 0){
+		if(x->p != nil)
 			x->p--;
-			e = x->ev;
-			if((e & 0x80) == 0)
-				sysfatal("invalid event");
-		}else
-			x->ev = e;
-	}
+		e = x->ev;
+		dprint(" *%02ux ", e);
+		if((e & 0x80) == 0)
+			sysfatal("invalid event %#ux", e);
+	}else
+		x->ev = e;
 	c = chan + (e & 15);
-	dprint("(%02ux) ", e);
+	dprint("| %02ux ", e);
 	n = get8(x);
 	switch(e >> 4){
 	case 0x8: noteoff(c, n, get8(x)); break;
@@ -562,13 +561,16 @@
 	putcmd(Rop3, 1, 0);
 	trace = debug;
 	if(stream){
+		Trk ☺;
+		memset(&☺, 0, sizeof ☺);
+		tr = &☺;
 		for(;;){
-			getvar(nil);
-			if(ev(nil, 0) < 0)
+			getvar(&☺);
+			if(ev(&☺, 0) < 0)
 				exits(nil);
 		}
 	}
-	for(end=0; !end;){
+	for(;;){
 		end = 1;
 		for(x=tr; x<tr+ntrk; x++){
 			if(x->ended)
@@ -584,6 +586,8 @@
 				x->Δ = getvar(x);
 			}
 		}
+		if(end)
+			break;
 		samp(1);
 	}
 	exits(nil);