chore: clean up code

This commit is contained in:
Rekai Nyangadzayi Musuka 2021-03-15 22:08:47 -05:00
parent 84babc4d69
commit 3d82465b04
1 changed files with 10 additions and 9 deletions

View File

@ -70,17 +70,18 @@ impl Bus {
match addr { match addr {
0x0000..=0x3FFF => { 0x0000..=0x3FFF => {
// 16KB ROM bank 00 // 16KB ROM bank 00
if addr <= 0x00FF && self.boot.is_some() { if addr < 0x00FF {
let boot = self.boot.unwrap(); if let Some(boot) = self.boot {
boot[addr as usize] return boot[addr as usize];
} else {
match &self.cartridge {
Some(cart) => cart.read_byte(addr),
None => panic!("Tried to read from a non-existant cartridge"),
} }
} }
match self.cartridge.as_ref() {
Some(cart) => cart.read_byte(addr),
None => panic!("Tried to read from a non-existant cartridge"),
}
} }
0x4000..=0x7FFF => match &self.cartridge { 0x4000..=0x7FFF => match self.cartridge.as_ref() {
// 16KB ROM Bank 01 -> NN (switchable via MB) // 16KB ROM Bank 01 -> NN (switchable via MB)
Some(cart) => cart.read_byte(addr), Some(cart) => cart.read_byte(addr),
None => panic!("Tried to read from a non-existant cartridge"), None => panic!("Tried to read from a non-existant cartridge"),
@ -89,7 +90,7 @@ impl Bus {
// 8KB Video RAM // 8KB Video RAM
self.ppu.vram[(addr - 0x8000) as usize] self.ppu.vram[(addr - 0x8000) as usize]
} }
0xA000..=0xBFFF => match &self.cartridge { 0xA000..=0xBFFF => match self.cartridge.as_ref() {
// 8KB External RAM // 8KB External RAM
Some(cart) => cart.read_byte(addr), Some(cart) => cart.read_byte(addr),
None => panic!("Tried to read from the external RAM of a non-existant cartridge"), None => panic!("Tried to read from the external RAM of a non-existant cartridge"),