From ba9a601874687eb5739f62e36c819ebaff7557dc Mon Sep 17 00:00:00 2001 From: Alex Janka Date: Sun, 23 Apr 2023 10:12:48 +1000 Subject: [PATCH] error is white (colour corrected for cgb) in release builds --- lib/src/processor/memory/mmio/gpu.rs | 18 +++++++++++------- .../processor/memory/mmio/gpu/tile_window.rs | 4 ++-- lib/src/processor/memory/mmio/gpu/types.rs | 16 ++++++++++++++-- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/lib/src/processor/memory/mmio/gpu.rs b/lib/src/processor/memory/mmio/gpu.rs index 9c5fc25..189e03f 100644 --- a/lib/src/processor/memory/mmio/gpu.rs +++ b/lib/src/processor/memory/mmio/gpu.rs @@ -132,7 +132,7 @@ where } else { None }; - let buffer = vec![ColourInner::Error.rgb_bytes(None).into(); WIDTH * HEIGHT]; + let buffer = vec![ColourInner::Error.rgb_bytes(None, false).into(); WIDTH * HEIGHT]; Self { buffer, @@ -321,8 +321,9 @@ where *e = true; } for x in 0..WIDTH { - self.buffer[(scanline as usize * WIDTH) + x] = - ColourInner::Error.rgb_bytes(None).into(); + self.buffer[(scanline as usize * WIDTH) + x] = ColourInner::Error + .rgb_bytes(None, self.is_cgb_mode()) + .into(); } if self.lcdc.bg_window_enable { self.render_scanline_bg(scanline); @@ -335,8 +336,9 @@ where } } else { for x in 0..WIDTH { - self.buffer[(scanline as usize * WIDTH) + x] = - ColourInner::Error.rgb_bytes(None).into(); + self.buffer[(scanline as usize * WIDTH) + x] = ColourInner::Error + .rgb_bytes(None, self.is_cgb_mode()) + .into(); } } if self.lcdc.obj_enable { @@ -487,7 +489,8 @@ where ) }); - self.buffer[buffer_index] = colour.rgb_bytes(cgb_data).into(); + self.buffer[buffer_index] = + colour.rgb_bytes(cgb_data, self.is_cgb_mode()).into(); } } } @@ -564,7 +567,8 @@ where .as_ref() .map(|v| (v.palettes.bg, attributes.palette)); - self.buffer[(scanline as usize * WIDTH) + x] = colour.rgb_bytes(cgb_data).into(); + self.buffer[(scanline as usize * WIDTH) + x] = + colour.rgb_bytes(cgb_data, self.is_cgb_mode()).into(); } } diff --git a/lib/src/processor/memory/mmio/gpu/tile_window.rs b/lib/src/processor/memory/mmio/gpu/tile_window.rs index 82c69f7..30d242a 100644 --- a/lib/src/processor/memory/mmio/gpu/tile_window.rs +++ b/lib/src/processor/memory/mmio/gpu/tile_window.rs @@ -27,7 +27,7 @@ where pub(super) fn new(window: R) -> Self { Self { sprite_buffer: vec![ - ColourInner::Error.rgb_bytes(None).into(); + ColourInner::Error.rgb_bytes(None, false).into(); TILE_WINDOW_WIDTH * TILE_WINDOW_HEIGHT ], sprite_renderer: window, @@ -110,7 +110,7 @@ where }; self.sprite_buffer[real_px_x + (real_px_y * TILE_WINDOW_WIDTH)] = colour - .rgb_bytes(cgb_data.map(|v| (v, attributes.palette))) + .rgb_bytes(cgb_data.map(|v| (v, attributes.palette)), is_cgb_mode) .into(); } } diff --git a/lib/src/processor/memory/mmio/gpu/types.rs b/lib/src/processor/memory/mmio/gpu/types.rs index 559826c..39ad746 100644 --- a/lib/src/processor/memory/mmio/gpu/types.rs +++ b/lib/src/processor/memory/mmio/gpu/types.rs @@ -138,7 +138,11 @@ fn rgb_from_bytes(bytes: u16) -> Colour { } impl ColourInner { - pub(super) fn rgb_bytes(&self, cgb_data: Option<(CgbPalette, u8)>) -> Colour { + pub(super) fn rgb_bytes( + &self, + cgb_data: Option<(CgbPalette, u8)>, + is_cgb_mode: bool, + ) -> Colour { if let Some((cgb_palette, pallete_num)) = cgb_data { if *self == ColourInner::Error { return Colour(0xFF, 0, 0); @@ -152,7 +156,15 @@ impl ColourInner { ColourInner::One => Colour(0xAA, 0xAA, 0xAA), ColourInner::Two => Colour(0x55, 0x55, 0x55), ColourInner::Three => Colour(0x00, 0x00, 0x00), - ColourInner::Error => Colour(0xFF, 0x00, 0x00), + ColourInner::Error => { + if cfg!(debug_assertions) { + Colour(0xFF, 0x00, 0x00) + } else if is_cgb_mode { + rgb_from_bytes(0xFFFF) + } else { + Colour(0xFF, 0xFF, 0xFF) + } + } } } }