From 0ca783bcce9fd251d0b028c00f7f9373aa454f39 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 19:41:41 +0100 Subject: [PATCH] refactor: made frame buffer size a const --- src/gb.rs | 4 ++-- src/ppu.rs | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/gb.rs b/src/gb.rs index b3e4949f..3494c3f3 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 54914287..c43f0546 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], -- GitLab