From bec5a0c3d60ba14579b8dd276a7484cc4b18f8b5 Mon Sep 17 00:00:00 2001 From: Alex Janka Date: Mon, 6 Feb 2023 12:14:02 +1100 Subject: [PATCH] window renders + it all works kind of almost ish --- src/processor/gpu.rs | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/processor/gpu.rs b/src/processor/gpu.rs index cb6a3e2..875a6ca 100644 --- a/src/processor/gpu.rs +++ b/src/processor/gpu.rs @@ -225,9 +225,10 @@ impl CPU { fn render_scanline(&mut self, scanline: u8, lcdc: &LCDC) { if lcdc.bg_window_enable { - self.render_scanline_bg(scanline, lcdc); + let palette = byte_to_palette(self.memory.get(0xFF47)); + self.render_scanline_bg(scanline, lcdc, palette); if lcdc.window_enable { - self.render_scanline_window(scanline, lcdc); + self.render_scanline_window(scanline, lcdc, palette); } } if lcdc.obj_enable { @@ -235,10 +236,9 @@ impl CPU { } } - fn render_scanline_bg(&mut self, scanline: u8, lcdc: &LCDC) { + fn render_scanline_bg(&mut self, scanline: u8, lcdc: &LCDC, palette: Palette) { let scroll_y = self.memory.get(0xFF42); let scroll_x = self.memory.get(0xFF43); - let palette = byte_to_palette(self.memory.get(0xFF47)); self.render_tiles( scanline, &lcdc.bg_tilemap, @@ -249,12 +249,19 @@ impl CPU { ); } - fn render_scanline_window(&mut self, _scanline: u8, _lcdc: &LCDC) { + fn render_scanline_window(&mut self, scanline: u8, lcdc: &LCDC, palette: Palette) { let pos_y = self.memory.get(0xFF4A); // subtracting 7 to get the Real Number... let pos_x = self.memory.get(0xFF4B).wrapping_sub(7); if pos_y < 143 && pos_x < 166 { - // within range!! render here + self.render_tiles( + scanline, + &lcdc.window_tilemap, + &lcdc.tile_area, + palette, + pos_x, + pos_y, + ) } } @@ -266,7 +273,7 @@ impl CPU { tilemap: &TilemapArea, tiledata: &TiledataArea, palette: Palette, - offset_x: u8, + _offset_x: u8, offset_y: u8, ) { let tile_line = (scanline as usize) + (offset_y as usize); @@ -280,8 +287,8 @@ impl CPU { let lsbs = self.memory.get(tile_addr); let msbs = self.memory.get(tile_addr + 1); for px_x in 0..8 { - let lsb = get_bit(lsbs, px_x); - let msb = get_bit(msbs, px_x); + let lsb = get_bit(lsbs, 7 - px_x); + let msb = get_bit(msbs, 7 - px_x); let colour = bits_to_mapped_colour(lsb, msb, palette); let x_coord = ((x * 8) + (px_x as u16)) as usize; if x_coord < WIDTH {