Skip to content

Commit

Permalink
Use an array for framebuffer
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaacMarovitz committed Apr 30, 2024
1 parent 0c8afc7 commit 4e3a8f5
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/components/mmu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub struct MMU {
intf: Interrupts,
inte: Interrupts,
wram_bank: usize,
boot_rom: [u8; 0x900],
boot_rom: [u8; 0x900],
boot_rom_enabled: bool,
mode: GBMode
}
Expand Down
4 changes: 3 additions & 1 deletion src/components/ppu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use crate::config::{Color, Config, Palette};
use crate::Framebuffer;
use bitflags::bitflags;

/// RGBA (4 bytes) per pixel
pub const FRAMEBUFFER_SIZE: usize = 4 * SCREEN_W * SCREEN_H;
pub const SCREEN_W: usize = 160;
pub const SCREEN_H: usize = 144;

Expand Down Expand Up @@ -611,7 +613,7 @@ impl Memory for PPU {
self.ppu_mode = PPUMode::HBlank;

let mut framebuffer = self.framebuffer.write().unwrap();
*framebuffer = vec![0x00; 4 * SCREEN_W * SCREEN_H];
*framebuffer = [0; FRAMEBUFFER_SIZE];
}
}
0xFF41 => {
Expand Down
2 changes: 1 addition & 1 deletion src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ impl Context {
]
}

pub fn update(&mut self, rgba: &Vec<u8>) {
pub fn update(&mut self, rgba: &[u8]) {
self.queue.write_texture(
wgpu::ImageCopyTexture {
aspect: wgpu::TextureAspect::All,
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use winit::event_loop::EventLoop;
use winit::application::ApplicationHandler;
use winit::window::{Window, WindowId};

type Framebuffer = Arc<RwLock<Vec<u8>>>;
type Framebuffer = Arc<RwLock<[u8; FRAMEBUFFER_SIZE]>>;

mod config;
mod context;
Expand Down Expand Up @@ -162,7 +162,7 @@ fn main() {
event_loop.set_control_flow(ControlFlow::Poll);

let (input_tx, input_rx) = mpsc::channel::<(JoypadButton, bool)>();
let framebuffer: Framebuffer = Arc::new(RwLock::new(vec![0; 4 * SCREEN_W * SCREEN_H]));
let framebuffer: Framebuffer = Arc::new(RwLock::new([0; FRAMEBUFFER_SIZE]));

let mut app = App {
game_name: String::from(game_name),
Expand Down

0 comments on commit 4e3a8f5

Please sign in to comment.