chore: move vram buffer to PPU struct
This commit is contained in:
parent
677a584ba7
commit
26df683cff
16
src/bus.rs
16
src/bus.rs
|
@ -1,10 +1,12 @@
|
|||
use super::cartridge::Cartridge;
|
||||
use crate::ppu;
|
||||
|
||||
use super::cartridge::Cartridge;
|
||||
use super::ppu::PPU;
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Bus {
|
||||
boot: Option<[u8; 256]>, // Boot ROM is 256b long
|
||||
cartridge: Option<Cartridge>,
|
||||
vram: [u8; 8192], // 8KB of VRAM
|
||||
ppu: PPU
|
||||
}
|
||||
|
||||
impl Default for Bus {
|
||||
|
@ -12,7 +14,7 @@ impl Default for Bus {
|
|||
Self {
|
||||
boot: Some(include_bytes!("../bin/DMG_ROM.bin").to_owned()),
|
||||
cartridge: None,
|
||||
vram: [0; 8192],
|
||||
ppu: Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -56,7 +58,7 @@ impl Bus {
|
|||
},
|
||||
0x8000..=0x9FFF => {
|
||||
// 8KB Video RAM
|
||||
self.vram[(addr - 0x8000) as usize]
|
||||
self.ppu.vram[(addr - 0x8000) as usize]
|
||||
}
|
||||
0xA000..=0xBFFF => {
|
||||
// 8KB External RAM
|
||||
|
@ -106,7 +108,7 @@ impl Bus {
|
|||
}
|
||||
0x8000..=0x9FFF => {
|
||||
// 8KB Video RAM
|
||||
self.vram[(addr - 0x8000) as usize] = byte;
|
||||
self.ppu.vram[(addr - 0x8000) as usize] = byte;
|
||||
}
|
||||
0xA000..=0xBFFF => {
|
||||
// 8KB External RAM
|
||||
|
@ -168,8 +170,8 @@ impl Bus {
|
|||
},
|
||||
0x8000..=0x9FFF => {
|
||||
// 8KB Video RAM
|
||||
(self.vram[((addr + 1) - 0x8000) as usize] as u16) << 8
|
||||
| self.vram[(addr - 0x8000) as usize] as u16
|
||||
(self.ppu.vram[((addr + 1) - 0x8000) as usize] as u16) << 8
|
||||
| self.ppu.vram[(addr - 0x8000) as usize] as u16
|
||||
}
|
||||
0xA000..=0xBFFF => {
|
||||
// 8KB External RAM
|
||||
|
|
14
src/ppu.rs
14
src/ppu.rs
|
@ -1,7 +1,19 @@
|
|||
struct PPU {
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct PPU {
|
||||
lcdc: LCDControl,
|
||||
pub vram: [u8; 8192],
|
||||
}
|
||||
|
||||
impl Default for PPU {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
lcdc: Default::default(),
|
||||
vram: [0; 8192],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug,Default, Clone, Copy)]
|
||||
struct LCDControl {
|
||||
lcd_enable: bool, // Bit 7
|
||||
window_tile_map_select: bool,
|
||||
|
|
Loading…
Reference in New Issue