From f4f97982ce690f604f94e6212a7f79e03ec00365 Mon Sep 17 00:00:00 2001 From: Alex Janka Date: Tue, 18 Jul 2023 13:44:35 +1000 Subject: [PATCH] cleaning --- lib/src/processor/memory/mmio/gpu.rs | 32 ++++++++++++++++------------ 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/lib/src/processor/memory/mmio/gpu.rs b/lib/src/processor/memory/mmio/gpu.rs index 30619c4..b9eb38b 100644 --- a/lib/src/processor/memory/mmio/gpu.rs +++ b/lib/src/processor/memory/mmio/gpu.rs @@ -68,17 +68,14 @@ where let tile_window = tile_window_renderer .map(|tile_window_renderer| TileWindow::new(tile_window_renderer, cgb)); - let blank_colour: ColourFormat = if cgb { - rgb_from_bytes(0xFFFF).into() - } else { - ColourInner::Error.rgb_bytes(None).into() - }; - - let buffer = [blank_colour; WIDTH * HEIGHT]; + let buffer = [get_blank_colour(cgb); WIDTH * HEIGHT]; let layer_window = layer_window_renderer.map(|mut layer_window_renderer| { layer_window_renderer.prepare(WIDTH, HEIGHT * 3); - (layer_window_renderer, [blank_colour; WIDTH * HEIGHT * 3]) + ( + layer_window_renderer, + [get_blank_colour(cgb); WIDTH * HEIGHT * 3], + ) }); Self { @@ -486,14 +483,21 @@ where self.window.display(&self.buffer); if let Some((ref mut window, ref mut buffer)) = self.layer_window { window.display(buffer); - let blank_colour: ColourFormat = if self.cgb_data.is_some() { - rgb_from_bytes(0xFFFF).into() - } else { - ColourInner::Error.rgb_bytes(None).into() - }; + for val in buffer { - *val = blank_colour; + *val = get_blank_colour(self.cgb_data.is_some()); } } } } + +fn get_blank_colour(cgb: bool) -> ColourFormat +where + ColourFormat: From + Copy, +{ + if cgb { + rgb_from_bytes(0xFFFF).into() + } else { + ColourInner::Error.rgb_bytes(None).into() + } +}