diff --git a/src/mmu.rs b/src/mmu.rs index 56a7999bd954a8a331887b1658c608face03851a..8c79e05ecb56f282575b8181efcddbde2f4bc858 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 9c0e8ee0ce38fbf385e13ce2a887e6c310f50493..4283078cac1d9dcb7e1ea5e42a119d0893dd6ba7 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