From bb9eb75b17ad0cb1d19329b2da025723d74e1155 Mon Sep 17 00:00:00 2001 From: Astatin Date: Mon, 28 Oct 2024 15:19:04 +0900 Subject: Fix unpredictable first row of pixel in window --- src/display.rs | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/display.rs b/src/display.rs index 7abf5b3..3e3bd17 100644 --- a/src/display.rs +++ b/src/display.rs @@ -228,22 +228,20 @@ impl Display { 0 }; - let y_tile = (self.ly - self.window_y) as usize; + let tilemap_y_px = (self.ly - self.window_y) as usize; + let y_tile = tilemap_y_px / 8; + let tile_y_px = tilemap_y_px % 8; - for x in 0..32 { - if tilemap_pointer + (y_tile / 8) * 32 + x >= 2048 { + for lx in 0..32 { + let tile_index = y_tile * 32 + lx; + if tilemap_pointer + tile_index >= 2048 { return; } - let tile = self.tilemaps[tilemap_pointer + (y_tile / 8) * 32 + x]; - if x * 8 + self.window_x as usize - 7 < 160 && self.ly >= self.window_y { - self.print_tile( - tile, - x as u8 * 8 + self.window_x - 7, - self.ly, - (y_tile % 8) as usize, - 0, - ); - } + + let tile = self.tilemaps[tilemap_pointer + tile_index]; + let tilemap_x_px = lx as u8 * 8 + self.window_x - 7; + + self.print_tile(tile, tilemap_x_px, self.ly, tile_y_px as usize, 0); } } -- cgit v1.2.3-70-g09d2