aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAstatin <[email protected]>2024-10-28 15:19:04 +0900
committerAstatin <[email protected]>2024-10-28 15:19:04 +0900
commitbb9eb75b17ad0cb1d19329b2da025723d74e1155 (patch)
tree9f0075eafcdfb6e1bf79f6a5df2c8eb9608b0e9f
parentfd5098e546ed2144c5f32fbe12b03ad784463cf9 (diff)
Fix unpredictable first row of pixel in window
-rw-r--r--src/display.rs24
1 files 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);
}
}