chore: move vram buffer to PPU struct

This commit is contained in:
Rekai Nyangadzayi Musuka 2020-12-24 00:27:06 -06:00
parent 677a584ba7
commit 26df683cff
2 changed files with 22 additions and 8 deletions

View File

@ -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

View File

@ -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,