From cb47d23233f28594d029abd647847e14e54849ba Mon Sep 17 00:00:00 2001 From: transistor Date: Tue, 23 Nov 2021 11:45:44 -0800 Subject: [PATCH] Fixed issue with colour 0 being the mask colour For systems that legitimately use 0 for black, this causes a problem, so I instead use 0xFFFFFFFF for the mask colour which corresponds to transparent white in ARGB format, which minifb doesn't support anyways --- src/host/gfx.rs | 9 +++++---- src/peripherals/genesis/ym7101.rs | 6 ++---- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/host/gfx.rs b/src/host/gfx.rs index 3bf5d6e..a1c6841 100644 --- a/src/host/gfx.rs +++ b/src/host/gfx.rs @@ -22,7 +22,7 @@ impl BlitableSurface for Frame { for y in pos_y..(pos_y + height) { for x in pos_x..(pos_x + width) { match bitmap.next().unwrap() { - 0 => { }, + 0xFFFFFFFF => { }, value if x < self.width && y < self.height => { self.bitmap[(x + (y * self.width)) as usize] = value; }, _ => { }, } @@ -31,6 +31,7 @@ impl BlitableSurface for Frame { } fn clear(&mut self, value: u32) { + let value = if value == 0xFFFFFFFF { 0 } else { value }; for i in 0..((self.width as usize) * (self.height as usize)) { self.bitmap[i] = value; } @@ -40,14 +41,14 @@ impl BlitableSurface for Frame { pub struct FrameSwapper { pub current: Frame, - pub previous: Frame, + //pub previous: Frame, } impl FrameSwapper { pub fn new(width: u32, height: u32) -> FrameSwapper { FrameSwapper { current: Frame { width, height, bitmap: vec![0; (width * height) as usize] }, - previous: Frame { width, height, bitmap: vec![0; (width * height) as usize] }, + //previous: Frame { width, height, bitmap: vec![0; (width * height) as usize] }, } } @@ -66,7 +67,7 @@ impl WindowUpdater for FrameSwapper { } fn update_frame(&mut self, width: u32, _height: u32, bitmap: &mut [u32]) { - std::mem::swap(&mut self.current, &mut self.previous); + //std::mem::swap(&mut self.current, &mut self.previous); for y in 0..self.current.height { for x in 0..self.current.width { diff --git a/src/peripherals/genesis/ym7101.rs b/src/peripherals/genesis/ym7101.rs index 37707b9..1fe7d76 100644 --- a/src/peripherals/genesis/ym7101.rs +++ b/src/peripherals/genesis/ym7101.rs @@ -209,7 +209,7 @@ impl Ym7101State { pub fn get_palette_colour(&self, palette: u8, colour: u8) -> u32 { if colour == 0 { - return 0; + return 0xFFFFFFFF; } let rgb = read_beu16(&self.cram[(((palette * 16) + colour) * 2) as usize..]); (((rgb & 0xF00) as u32) >> 4) | (((rgb & 0x0F0) as u32) << 8) | (((rgb & 0x00F) as u32) << 20) @@ -259,9 +259,7 @@ impl Ym7101State { pub fn draw_background(&mut self, frame: &mut Frame) { let bg_colour = self.get_palette_colour((self.regs[REG_BACKGROUND] & 0x30) >> 4, self.regs[REG_BACKGROUND] & 0x0f); - for i in 0..(frame.width as usize * frame.height as usize) { - frame.bitmap[i] = bg_colour; - } + frame.clear(bg_colour); } pub fn draw_cell_table(&mut self, frame: &mut Frame, cell_table: u32) {