From 06821bf8806570c733fa1799a6f940bf6a984efc Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Tue, 16 Mar 2021 22:51:41 -0500 Subject: [PATCH] fix: improve types of heap allocated arrays --- src/cartridge.rs | 4 ++-- src/high_ram.rs | 4 ++-- src/ppu.rs | 8 ++++---- src/work_ram.rs | 8 ++++---- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/cartridge.rs b/src/cartridge.rs index bf937fb..1e4c8e2 100644 --- a/src/cartridge.rs +++ b/src/cartridge.rs @@ -30,7 +30,7 @@ impl Cartridge { MBCKind::None => todo!("Handle no MBC Situation"), MBCKind::MBC1 => MBC1 { ram_size, - ram: vec![0; ram_byte_count as usize].into_boxed_slice(), + ram: vec![0; ram_byte_count as usize], bank_count, ..Default::default() }, @@ -90,7 +90,7 @@ struct MBC1 { current_ram_bank: u8, // 2-bit number mode: bool, ram_size: RamSize, - ram: Box<[u8]>, + ram: Vec, bank_count: BankCount, ram_enabled: bool, } diff --git a/src/high_ram.rs b/src/high_ram.rs index b7a871b..195e5b6 100644 --- a/src/high_ram.rs +++ b/src/high_ram.rs @@ -1,12 +1,12 @@ #[derive(Debug, Clone)] pub struct HighRam { - buf: Box<[u8]>, + buf: Box<[u8; 127]>, } impl Default for HighRam { fn default() -> Self { Self { - buf: vec![0u8; 128].into_boxed_slice(), + buf: Box::new([0u8; 127]), } } } diff --git a/src/ppu.rs b/src/ppu.rs index 172cdb6..223c47e 100644 --- a/src/ppu.rs +++ b/src/ppu.rs @@ -8,8 +8,8 @@ pub struct Ppu { pub lcd_control: LCDControl, pub monochrome: Monochrome, pub pos: ScreenPosition, - pub vram: Box<[u8]>, - pub oam: Box<[u8]>, + pub vram: Box<[u8; 8192]>, + pub oam: Box<[u8; 160]>, frame_buf: [u8; GB_WIDTH * GB_HEIGHT * 4], pub stat: LCDStatus, cycles: Cycles, @@ -81,8 +81,8 @@ impl Default for Ppu { monochrome: Default::default(), pos: Default::default(), stat: Default::default(), - vram: vec![0; 8192].into_boxed_slice(), - oam: vec![0; 160].into_boxed_slice(), + vram: Box::new([0u8; 8192]), + oam: Box::new([0u8; 160]), cycles: 0.into(), frame_buf: [0; GB_WIDTH * GB_HEIGHT * 4], } diff --git a/src/work_ram.rs b/src/work_ram.rs index 0f2fcca..0e987de 100644 --- a/src/work_ram.rs +++ b/src/work_ram.rs @@ -1,6 +1,6 @@ #[derive(Debug, Clone)] pub struct WorkRam { - bank: Box<[u8]>, + bank: Box<[u8; 4096]>, } impl WorkRam { @@ -16,7 +16,7 @@ impl WorkRam { impl Default for WorkRam { fn default() -> Self { Self { - bank: vec![0u8; 4096].into_boxed_slice(), + bank: Box::new([0u8; 4096]), } } } @@ -35,14 +35,14 @@ pub enum BankNumber { #[derive(Debug, Clone)] pub struct VariableWorkRam { current: BankNumber, - bank_n: Box<[[u8; 4096]]>, // 4K for Variable amount of Banks (Banks 1 -> 7) in Game Boy Colour + bank_n: Box<[[u8; 4096]; 7]>, // 4K for Variable amount of Banks (Banks 1 -> 7) in Game Boy Colour } impl Default for VariableWorkRam { fn default() -> Self { Self { current: BankNumber::One, - bank_n: vec![[0u8; 4096]; 7].into_boxed_slice(), + bank_n: Box::new([[0u8; 4096]; 7]), } } }