diff --git a/src/gb.rs b/src/gb.rs index b3e4949f704ef2c2bfe6451054818f5d20348543..3494c3f315bcebdfb3ae0fca402907b9610ba3df 100644 --- a/src/gb.rs +++ b/src/gb.rs @@ -1,4 +1,4 @@ -use crate::{cpu::Cpu, mmu::Mmu, ppu::Ppu, util::read_file}; +use crate::{cpu::Cpu, mmu::Mmu, ppu::{Ppu, FRAME_BUFFER_SIZE}, util::read_file}; pub struct GameBoy { cpu: Cpu, @@ -38,7 +38,7 @@ impl GameBoy { self.cpu.ppu() } - pub fn frame_buffer(&mut self) -> &Box<[u8; 73920]> { + pub fn frame_buffer(&mut self) -> &Box<[u8; FRAME_BUFFER_SIZE]> { &(self.ppu().frame_buffer) } diff --git a/src/ppu.rs b/src/ppu.rs index 54914287b35e6f4aa9cdf90b4a23f2b7c68807a3..c43f054635470ff9367e3bffbb6aa5651e6bf6a1 100644 --- a/src/ppu.rs +++ b/src/ppu.rs @@ -13,6 +13,9 @@ pub const DISPLAY_WIDTH: usize = 160; /// The height of the Game Boy screen in pixels. pub const DISPLAY_HEIGHT: usize = 154; +// The size of the RGB frame buffer in bytes. +pub const FRAME_BUFFER_SIZE: usize = DISPLAY_WIDTH * DISPLAY_HEIGHT * RGB_SIZE; + /// Represents the Game Boy PPU (Pixel Processing Unit) and controls /// all of the logic behind the graphics processing and presentation. /// Should store both the VRAM and HRAM together with the internal @@ -27,7 +30,7 @@ pub const DISPLAY_HEIGHT: usize = 154; pub struct Ppu { /// The 8 bit based RGB frame buffer with the /// processed set of pixels ready to be displayed on screen. - pub frame_buffer: Box<[u8; DISPLAY_WIDTH * DISPLAY_HEIGHT * RGB_SIZE]>, + pub frame_buffer: Box<[u8; FRAME_BUFFER_SIZE]>, /// Video dedicated memory (VRAM) where both the tiles and /// the sprites are going to be stored. pub vram: [u8; VRAM_SIZE],