code: plan9front

Download patch

ref: 415c110b284bdd519e6dedcfea97e45edcb8977a
parent: e502abe001306ad8c95ea5b32a437c53d90eccfa
author: Michael Forney <mforney@mforney.org>
date: Sun Feb 7 23:58:49 EST 2021

games/gb: fix reversed audio channels
The high bits correspond to the left channel, and the low bits to the
right channel.

Reference: https://gbdev.io/pandocs/#sound-control-registers

Tested with pokemon crystal.

--- a/sys/src/games/gb/apu.c
+++ b/sys/src/games/gb/apu.c
@@ -115,13 +115,13 @@
 		if(i == 2 ? ((reg[NR30] & 0x80) == 0) : ((*sndch[i].env & 0xf8) == 0))
 			continue;
 		v = sndch[i].samp * 2 - 15;
-		if((cnth & 1<<i) != 0)
-			ov0 += v;
 		if((cnth & 1<<4<<i) != 0)
+			ov0 += v;
+		if((cnth & 1<<i) != 0)
 			ov1 += v;
 	}
-	ov0 *= 1 + (cntl & 7);
-	ov1 *= 1 + (cntl >> 4 & 7);
+	ov0 *= 1 + (cntl >> 4 & 7);
+	ov1 *= 1 + (cntl & 7);
 }
 
 static void