From 268193f4891708c6bd53ba8f6246f1654ad41961 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Magalh=C3=A3es?= <joamag@gmail.com> Date: Fri, 1 Jul 2022 11:22:03 +0100 Subject: [PATCH] feat: better drawing of line --- src/mmu.rs | 1 - src/ppu.rs | 12 +++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/mmu.rs b/src/mmu.rs index 56a7999b..8c79e05e 100644 --- a/src/mmu.rs +++ b/src/mmu.rs @@ -111,7 +111,6 @@ impl Mmu { } // Graphics: VRAM (8k) 0x8000 | 0x9000 => { - println!("WRITING TO VRAM"); self.ppu.vram[(addr & 0x1fff) as usize] = value; if addr < 0x9800 { self.ppu.update_tile(addr, value); diff --git a/src/ppu.rs b/src/ppu.rs index 9c0e8ee0..4283078c 100644 --- a/src/ppu.rs +++ b/src/ppu.rs @@ -214,16 +214,18 @@ impl Ppu { let y = ((self.scy + self.line) & 0x07) as usize; let mut x = (self.scx & 0x07) as usize; - let mut frame_offset = self.line as usize * SCREEN_WIDTH * RGBA_SIZE; - + // calculates the index of the initial tile in drawing, + // if the tile data set in use is #1, the indices are + // signed, then calculates a real tile offset let mut tile_index = self.vram[map_offset + line_offset] as usize; - - // if the tile data set in use is #1, the - // indices are signed, calculates a real tile offset if self.bg_tile && tile_index < 128 { tile_index += 256; } + // calculates the frame buffer offset position assuming the proper + // Game Boy screen width and RGBA pixel (4 bytes) size + let mut frame_offset = self.line as usize * SCREEN_WIDTH * RGBA_SIZE; + for _index in 0..SCREEN_WIDTH { // in case the end of tile width has been reached then // a new tile must be retrieved for plotting -- GitLab