Skip to content
Snippets Groups Projects
Verified Commit 0ca783bc authored by João Magalhães's avatar João Magalhães :rocket:
Browse files

refactor: made frame buffer size a const

parent 49932ec9
No related branches found
No related tags found
No related merge requests found
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 { pub struct GameBoy {
cpu: Cpu, cpu: Cpu,
...@@ -38,7 +38,7 @@ impl GameBoy { ...@@ -38,7 +38,7 @@ impl GameBoy {
self.cpu.ppu() 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) &(self.ppu().frame_buffer)
} }
......
...@@ -13,6 +13,9 @@ pub const DISPLAY_WIDTH: usize = 160; ...@@ -13,6 +13,9 @@ pub const DISPLAY_WIDTH: usize = 160;
/// The height of the Game Boy screen in pixels. /// The height of the Game Boy screen in pixels.
pub const DISPLAY_HEIGHT: usize = 154; 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 /// Represents the Game Boy PPU (Pixel Processing Unit) and controls
/// all of the logic behind the graphics processing and presentation. /// all of the logic behind the graphics processing and presentation.
/// Should store both the VRAM and HRAM together with the internal /// Should store both the VRAM and HRAM together with the internal
...@@ -27,7 +30,7 @@ pub const DISPLAY_HEIGHT: usize = 154; ...@@ -27,7 +30,7 @@ pub const DISPLAY_HEIGHT: usize = 154;
pub struct Ppu { pub struct Ppu {
/// The 8 bit based RGB frame buffer with the /// The 8 bit based RGB frame buffer with the
/// processed set of pixels ready to be displayed on screen. /// 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 /// Video dedicated memory (VRAM) where both the tiles and
/// the sprites are going to be stored. /// the sprites are going to be stored.
pub vram: [u8; VRAM_SIZE], pub vram: [u8; VRAM_SIZE],
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment