diff --git a/src/main.rs b/src/main.rs index 4e97d48..a93c888 100644 --- a/src/main.rs +++ b/src/main.rs @@ -94,15 +94,13 @@ impl Memory { if self.bootrom_enabled && (address as usize) < self.bootrom.len() { return self.bootrom[address as usize]; } else { - return self.rom[address as usize]; - } + return self.rom[address as usize]; + } } 0x8000..0xA000 => { return self.vram[(address - 0x8000) as usize]; } - 0xA000..0xC000 => { - 0xFF - } + 0xA000..0xC000 => 0xFF, 0xC000..0xE000 => { return self.ram[(address - 0xC000) as usize]; } @@ -213,6 +211,40 @@ impl Default for State { } } +fn cpu_ram_init(cpu: &mut CPU) { + cpu.memory.set(0xFF10, 0x80); + cpu.memory.set(0xFF11, 0xBF); + cpu.memory.set(0xFF12, 0xF3); + cpu.memory.set(0xFF14, 0xBF); + cpu.memory.set(0xFF16, 0x3F); + cpu.memory.set(0xFF19, 0xBF); + cpu.memory.set(0xFF1A, 0x7F); + cpu.memory.set(0xFF1B, 0xFF); + cpu.memory.set(0xFF1C, 0x9F); + cpu.memory.set(0xFF1E, 0xBF); + cpu.memory.set(0xFF20, 0xFF); + cpu.memory.set(0xFF23, 0xBF); + cpu.memory.set(0xFF24, 0x77); + cpu.memory.set(0xFF25, 0xF3); + cpu.memory.set(0xFF26, 0xF1); + cpu.memory.set(0xFF40, 0x91); + cpu.memory.set(0xFF47, 0xFC); + cpu.memory.set(0xFF48, 0xFF); + cpu.memory.set(0xFF49, 0xFF); +} + +#[allow(dead_code)] +fn swap_rom_endian(rom: &ROM) -> ROM { + rom.chunks(2) + .map(|l| { + let mut m = l.to_owned(); + m.reverse(); + m + }) + .flatten() + .collect() +} + static mut PAUSE_ENABLED: bool = false; static mut PAUSE_QUEUED: bool = false; @@ -310,37 +342,3 @@ fn print_cycles(cycles: &i32) { ); stdout().flush().unwrap(); } - -fn cpu_ram_init(cpu: &mut CPU) { - cpu.memory.set(0xFF10, 0x80); - cpu.memory.set(0xFF11, 0xBF); - cpu.memory.set(0xFF12, 0xF3); - cpu.memory.set(0xFF14, 0xBF); - cpu.memory.set(0xFF16, 0x3F); - cpu.memory.set(0xFF19, 0xBF); - cpu.memory.set(0xFF1A, 0x7F); - cpu.memory.set(0xFF1B, 0xFF); - cpu.memory.set(0xFF1C, 0x9F); - cpu.memory.set(0xFF1E, 0xBF); - cpu.memory.set(0xFF20, 0xFF); - cpu.memory.set(0xFF23, 0xBF); - cpu.memory.set(0xFF24, 0x77); - cpu.memory.set(0xFF25, 0xF3); - cpu.memory.set(0xFF26, 0xF1); - cpu.memory.set(0xFF40, 0x91); - cpu.memory.set(0xFF47, 0xFC); - cpu.memory.set(0xFF48, 0xFF); - cpu.memory.set(0xFF49, 0xFF); -} - -#[allow(dead_code)] -fn swap_rom_endian(rom: &ROM) -> ROM { - rom.chunks(2) - .map(|l| { - let mut m = l.to_owned(); - m.reverse(); - m - }) - .flatten() - .collect() -}