From 7656cf8b05f581ba440040ee4e211d911c0c7cac Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Thu, 14 Dec 2023 00:34:37 -0500 Subject: [PATCH] Boot! --- src/main.rs | 9 +++++---- src/mmu.rs | 4 +++- src/ppu.rs | 1 + src/registers.rs | 2 +- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index a61d7c2..a12ef32 100644 --- a/src/main.rs +++ b/src/main.rs @@ -29,21 +29,22 @@ pub const STEP_CYCLES: u32 = (STEP_TIME as f64 / (1000_f64 / CLOCK_FREQUENCY as #[derive(Parser)] struct Args { rom_path: String, + boot_rom: String } #[tokio::main] async fn main() -> Result<(), impl std::error::Error> { let args = Args::parse(); let mut file = File::open(args.rom_path).expect("No ROM found!"); + let mut boot = File::open(args.boot_rom).expect("No Boot ROM found!"); let mut buffer = Vec::new(); + let mut boot_rom = Vec::new(); file.read_to_end(&mut buffer).expect("Failed to read ROM!"); - - let nintendo_logo = &buffer[0x0104..=0x0133]; + boot.read_to_end(&mut boot_rom).expect("Failed to read Boot ROM!"); // Display Nintendo Logo - - // Run checksum + buffer[0..=0x00FF].copy_from_slice(boot_rom.as_slice()); // Get game name let name_data = &buffer[0x0134..=0x0143]; diff --git a/src/mmu.rs b/src/mmu.rs index 03f94a4..930a9dc 100644 --- a/src/mmu.rs +++ b/src/mmu.rs @@ -74,7 +74,8 @@ impl MMU { pub fn write(&mut self, a: u16, v: u8) { match a { - 0x0000..=0x7FFF => self.rom[a as usize] = v, + // TODO: MBC + 0x0000..=0x7FFF => {} 0x8000..=0x9FFF => self.ppu.write(a, v), // TODO: MBC 0xA000..=0xBFFF => {} @@ -94,6 +95,7 @@ impl MMU { // TODO: APU 0xFF10..=0xFF3F => {}, 0xFF0F => self.intf = Interrupts::from_bits(v).unwrap(), + 0xFF50 => {}, 0xFF70 => self.wram_bank = match v & 0x07 { 0 => 1, n => n as usize }, 0xFFFF => self.inte = Interrupts::from_bits_truncate(v), _ => panic!("Write to unsupported address ({:#06x})!", a), diff --git a/src/ppu.rs b/src/ppu.rs index d2942c8..065338d 100644 --- a/src/ppu.rs +++ b/src/ppu.rs @@ -434,6 +434,7 @@ impl PPU { 0xFF49 => self.op1, 0xFF4A => self.wy, 0xFF4B => self.wx, + 0xFF4D => 0x00, 0xFF4F => 0xFE | self.ram_bank as u8, _ => panic!("Read to unsupported PPU address ({:#06x})!", a), } diff --git a/src/registers.rs b/src/registers.rs index d2a0405..1f128ab 100644 --- a/src/registers.rs +++ b/src/registers.rs @@ -93,7 +93,7 @@ impl Registers { e: 0xD8, h: 0x01, l: 0x4D, - pc: 0x0100, + pc: 0x0000, sp: 0xFFFE } },