From 2bba9622d3c79e63d457a88c74202a6ddf2346d9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jo=C3=A3o=20Magalh=C3=A3es?= <joamag@gmail.com>
Date: Fri, 7 Apr 2023 23:44:37 +0100
Subject: [PATCH] feat: added glob panning audio store

---
 src/apu.rs | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/src/apu.rs b/src/apu.rs
index 712d88ee..ed70ca82 100644
--- a/src/apu.rs
+++ b/src/apu.rs
@@ -76,6 +76,8 @@ pub struct Apu {
     ch4_length_stop: bool,
     ch4_enabled: bool,
 
+    glob_panning: u8,
+
     right_enabled: bool,
     left_enabled: bool,
 
@@ -149,6 +151,8 @@ impl Apu {
             ch4_length_stop: false,
             ch4_enabled: false,
 
+            glob_panning: 0x0,
+
             left_enabled: true,
             right_enabled: true,
 
@@ -232,6 +236,8 @@ impl Apu {
         self.ch4_length_stop = false;
         self.ch4_enabled = false;
 
+        self.glob_panning = 0x0;
+
         self.left_enabled = true;
         self.right_enabled = true;
 
@@ -302,9 +308,13 @@ impl Apu {
     }
 
     pub fn read(&mut self, addr: u16) -> u8 {
-        {
-            warnln!("Reading from unknown APU location 0x{:04x}", addr);
-            0xff
+        match addr {
+            // 0xFF25 — NR51: Sound panning
+            0xff25 => self.glob_panning,
+            _ => {
+                warnln!("Reading from unknown APU location 0x{:04x}", addr);
+                0xff
+            }
         }
     }
 
@@ -424,7 +434,7 @@ impl Apu {
             }
             // 0xFF25 — NR51: Sound panning
             0xff25 => {
-                //@TODO: Implement sound panning
+                self.glob_panning = value;
             }
             // 0xFF26 — NR52: Sound on/off
             0xff26 => {
-- 
GitLab