From 75a9396b574a6a7fc68f1f62c1ca97fbbd68324c Mon Sep 17 00:00:00 2001 From: Alex Janka Date: Wed, 15 Feb 2023 08:25:04 +1100 Subject: [PATCH] comments and a lil fixing --- src/processor/memory.rs | 13 +++++-------- src/processor/memory/mmio/apu.rs | 2 +- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/processor/memory.rs b/src/processor/memory.rs index d16fc42..afed77e 100644 --- a/src/processor/memory.rs +++ b/src/processor/memory.rs @@ -119,6 +119,7 @@ impl Memory { } fn get_io(&self, address: Address) -> u8 { + // range: 0xFF00 - 0xFF4B inclusive match address { 0xFF00 => self.joypad.as_register(), 0xFF10..0xFF40 => self.apu.get_register(address), @@ -127,6 +128,7 @@ impl Memory { } fn set_io(&mut self, address: Address, data: u8) { + // range: 0xFF00 - 0xFF4B inclusive let addr_l = (address - 0xFF00) as usize; if !self.user_mode { self.io[addr_l] = data; @@ -150,11 +152,7 @@ impl Memory { // mixed read/write self.masked_io(addr_l, data, 0b01111000); } - 0xFF4D | 0xFF56 => { - // cgb only - self.io[addr_l] = data; - } - 0xFF03 | 0xFF08..0xFF0F | 0xFF44 | 0xFF76 | 0xFF77 => { + 0xFF03 | 0xFF08..0xFF0F | 0xFF44 => { // read-only addresses println!("BANNED write: {data:#X} to {address:#X}"); } @@ -170,9 +168,8 @@ impl Memory { self.oam[l as usize] = self.get(addr); } } - _ => { - self.io[addr_l] = data; - } + 0x0..0xFF00 | 0xFF4C..=u16::MAX => panic!("passed wrong address to set_io"), + _ => self.io[addr_l] = data, } } } diff --git a/src/processor/memory/mmio/apu.rs b/src/processor/memory/mmio/apu.rs index 1a06cc5..83a9b57 100644 --- a/src/processor/memory/mmio/apu.rs +++ b/src/processor/memory/mmio/apu.rs @@ -117,7 +117,7 @@ impl Apu { 0xFF13 | 0xFF18 | 0xFF1B | 0xFF1D | 0xFF20 => 0xFF, // not registers 0xFF15 | 0xFF1F | 0xFF27..0xFF30 => 0xFF, - 0x0..0xFF10 | 0xFF40..0xFFFF | 0xFFFF => panic!("non-apu addr in apu"), + 0x0..0xFF10 | 0xFF40..=0xFFFF => panic!("non-apu addr in apu"), _ => self.mem[reg(addr)], } }