From ddfee9a71ca2ae634fce3e784e185c39dc9b88da Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jo=C3=A3o=20Magalh=C3=A3es?= <joamag@gmail.com>
Date: Mon, 1 May 2023 01:40:04 +0100
Subject: [PATCH] feat: immediate re-compute of palettes

---
 src/mmu.rs | 2 +-
 src/ppu.rs | 8 ++++++++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/mmu.rs b/src/mmu.rs
index 974b97ae..a7a1f141 100644
--- a/src/mmu.rs
+++ b/src/mmu.rs
@@ -349,7 +349,7 @@ impl Mmu {
                     // 0xFF4C - KEY0 (CGB only)
                     0x4c => {
                         self.key0 = value;
-                        if self.key0 == 0x04 {
+                        if value == 0x04 {
                             self.ppu().set_dmg_compat(true);
                         }
                     }
diff --git a/src/ppu.rs b/src/ppu.rs
index f2e7ab5c..c7783022 100644
--- a/src/ppu.rs
+++ b/src/ppu.rs
@@ -930,6 +930,14 @@ impl Ppu {
 
     pub fn set_dmg_compat(&mut self, value: bool) {
         self.dmg_compat = value;
+
+        // if we're switching to the DMG compat mode
+        // then we need to recompute the palettes so
+        // that the colors are correct according to 
+        // the compat palettes set by the Boot ROM
+        if value {
+            self.compute_palettes();
+        }
     }
 
     pub fn gb_mode(&self) -> GameBoyMode {
-- 
GitLab