From 7f796dd9893cad90d8b606eca044a3ca94d3bac6 Mon Sep 17 00:00:00 2001 From: Ry Date: Sun, 17 Apr 2022 13:29:17 -0700 Subject: [PATCH] fox32: Dump RAM if bad opcode --- src/cpu.rs | 4 +++- src/memory.rs | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/cpu.rs b/src/cpu.rs index 9a1f57c..942deec 100644 --- a/src/cpu.rs +++ b/src/cpu.rs @@ -268,6 +268,8 @@ impl Cpu { println!("{:#010X}: bad opcode {:#06X}", self.instruction_pointer, opcode); println!("size instr . cond dest src"); println!("{:02b} {:06b} {:01b} {:03b} {:02b} {:02b}", size, instruction, empty, condition, destination, source); + println!("dumping RAM"); + self.bus.memory.dump(); panic!("bad opcode"); } } @@ -2852,4 +2854,4 @@ impl Instruction { _ => None, } } -} \ No newline at end of file +} diff --git a/src/memory.rs b/src/memory.rs index 80f624c..23ccd3d 100644 --- a/src/memory.rs +++ b/src/memory.rs @@ -5,6 +5,7 @@ use crate::error; use std::cell::UnsafeCell; use std::sync::Arc; use std::io::Write; +use std::fs::File; pub const MEMORY_RAM_SIZE: usize = 0x04000000; // 64 MiB pub const MEMORY_ROM_SIZE: usize = 0x00080000; // 512 KiB @@ -54,6 +55,11 @@ impl Memory { pub fn ram(&self) -> &mut MemoryRam { &mut self.inner().ram } pub fn rom(&self) -> &mut MemoryRom { &mut self.inner().rom } + pub fn dump(&self) { + let mut file = File::create("memory.dump").expect("failed to open memory dump file"); + file.write_all(self.ram()).expect("failed to write memory dump file"); + } + pub fn read_8(&self, address: u32) -> u8 { let address = address as usize;