From fee621d1f20a45239ffcb3536ef28be98be697f1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jo=C3=A3o=20Magalh=C3=A3es?= <joamag@gmail.com>
Date: Mon, 20 Feb 2023 13:45:19 +0000
Subject: [PATCH] feat: initial implementation of palette for SDL We still need
 to add more palettes from the Web frontend.

---
 frontends/sdl/src/main.rs | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/frontends/sdl/src/main.rs b/frontends/sdl/src/main.rs
index f5b180a6..e64d6ec5 100644
--- a/frontends/sdl/src/main.rs
+++ b/frontends/sdl/src/main.rs
@@ -85,6 +85,17 @@ impl Emulator {
         );
     }
 
+    pub fn toggle_palette(&mut self) {
+        //colors: ["b6a571", "8b7e56", "554d35", "201d13"]
+        // @todo add more palettes here
+        self.system.ppu().set_palette_colors(&[
+            [0xb6, 0xa5, 0x71],
+            [139, 126, 86],
+            [85, 77, 83],
+            [32, 29, 19],
+        ])
+    }
+
     pub fn run(&mut self) {
         // updates the icon of the window to reflect the image
         // and style of the emulator
@@ -131,6 +142,12 @@ impl Emulator {
                     } => {
                         self.benchmark();
                     }
+                    Event::KeyDown {
+                        keycode: Some(Keycode::P),
+                        ..
+                    } => {
+                        self.toggle_palette();
+                    }
                     Event::KeyDown {
                         keycode: Some(keycode),
                         ..
-- 
GitLab