Skip to content

Commit

Permalink
Reworking PPU layout (WIP). Adding window support
Browse files Browse the repository at this point in the history
  • Loading branch information
TylerBloom committed Sep 7, 2024
1 parent 032c135 commit ec1b2c6
Show file tree
Hide file tree
Showing 6 changed files with 211 additions and 222 deletions.
4 changes: 1 addition & 3 deletions spirit/src/cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -730,9 +730,7 @@ impl Cpu {
LoadOp::Basic {
dest: RegOrPointer::Pointer,
src: RegOrPointer::Pointer,
} => {
self.state = CpuState::Halted
}
} => self.state = CpuState::Halted,
LoadOp::Basic { dest, src } => self.write_byte(dest, mem, self.copy_byte(mem, src)),
LoadOp::Direct16(reg, val) => self.write_wide_reg(reg, val),
LoadOp::Direct(reg, val) => self.write_byte(reg, mem, val),
Expand Down
12 changes: 6 additions & 6 deletions spirit/src/mem/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub struct IoRegisters {
/// ADDR FF48 & FF49
monochrome_obj_palettes: [u8; 2],
/// ADDR FF4A & FF4B
window_position: (u8, u8),
window_position: [u8; 2],
/// ADDR FF4F
// TODO: Only the 0th bit is used. From the docs:
// """
Expand Down Expand Up @@ -197,8 +197,8 @@ impl Index<u16> for IoRegisters {
0xFF47 => &self.monochrome_bg_palette,
0xFF48 => &self.monochrome_obj_palettes[0],
0xFF49 => &self.monochrome_obj_palettes[1],
0xFF4A => &self.window_position.0,
0xFF4B => &self.window_position.1,
0xFF4A => &self.window_position[0],
0xFF4B => &self.window_position[1],
0xFF4F => &self.vram_select,
0xFF50 => &self.boot_status,
n @ 0xFF51..=0xFF55 => &self.vram_dma[(n - 0xFF51) as usize],
Expand Down Expand Up @@ -248,12 +248,12 @@ impl IndexMut<u16> for IoRegisters {
0xFF46 => {
panic!("OAM DMA transfer not implemented yet!!");
// &mut self.oam_dma
},
}
0xFF47 => &mut self.monochrome_bg_palette,
0xFF48 => &mut self.monochrome_obj_palettes[0],
0xFF49 => &mut self.monochrome_obj_palettes[1],
0xFF4A => &mut self.window_position.0,
0xFF4B => &mut self.window_position.1,
0xFF4A => &mut self.window_position[0],
0xFF4B => &mut self.window_position[1],
0xFF4F => &mut self.vram_select,
0xFF50 => &mut self.boot_status,
0xFF4F => &mut self.vram_select,
Expand Down
8 changes: 2 additions & 6 deletions spirit/src/mem/mbc/mbc2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ impl Index<u16> for MBC2 {
match index {
0x0000..=0x3FFF => todo!("read from rom bank 0"),
0x4000..=0x7FFF => todo!("read from rom bank 1-F"),
i @ 0xA000..=0xBFFF => {
&self.ram[(i & 0x01FF) as usize]
},
i @ 0xA000..=0xBFFF => &self.ram[(i & 0x01FF) as usize],
_ => unreachable!(),
}
}
Expand All @@ -38,9 +36,7 @@ impl IndexMut<u16> for MBC2 {
i @ 0xA000..=0xBFFF if self.ram_enabled == 0x0A => {
todo!("Index into RAM")
}
0xA000..=0xBFFF if self.ram_enabled == 0x0A => {
&mut self.dead_byte
}
0xA000..=0xBFFF if self.ram_enabled == 0x0A => &mut self.dead_byte,
_ => unreachable!(),
}
}
Expand Down
4 changes: 2 additions & 2 deletions spirit/src/mem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ impl MemoryMap {
self.io.inc_lcd_y()
}

pub(crate) fn inc_ppu_status(&mut self, state: PpuMode) {
self.vram.inc_status(state)
pub(crate) fn set_ppu_status(&mut self, state: PpuMode) {
self.vram.set_status(state)
}

pub fn request_vblank_int(&mut self) {
Expand Down
4 changes: 2 additions & 2 deletions spirit/src/mem/vram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ impl VRam {
}
}

pub(crate) fn inc_status(&mut self, other: PpuMode) {
self.status = std::cmp::max(self.status, other);
pub(crate) fn set_status(&mut self, other: PpuMode) {
self.status = other;
}

pub(crate) fn reset_status(&mut self) {
Expand Down
Loading

0 comments on commit ec1b2c6

Please sign in to comment.