Minor changes

This commit is contained in:
transistor 2021-10-14 21:16:31 -07:00
parent e558fc01bf
commit 43b1abfa19
7 changed files with 41 additions and 13 deletions

View File

@ -53,6 +53,12 @@ impl M68k {
self.debugger.use_tracing = true;
}
#[allow(dead_code)]
pub fn enable_debugging(&mut self) {
self.debugger.use_tracing = true;
self.debugger.use_debugger = true;
}
#[allow(dead_code)]
pub fn add_breakpoint(&mut self, addr: Address) {
self.debugger.breakpoints.push(addr as u32);
@ -62,8 +68,7 @@ impl M68k {
for breakpoint in &self.debugger.breakpoints {
if *breakpoint == self.state.pc {
println!("Breakpoint reached: {:08x}", *breakpoint);
self.debugger.use_tracing = true;
self.debugger.use_debugger = true;
self.enable_debugging();
break;
}
}
@ -124,7 +129,7 @@ impl M68k {
},
"dis" | "disassemble" => {
let mut decoder = M68kDecoder::new(self.cputype, 0, 0);
//decoder.dump_disassembly(system, self.state.pc, 0x1000);
decoder.dump_disassembly(system, self.state.pc, 0x1000);
},
"so" | "stepout" => {
self.debugger.step_until_return = Some(self.debugger.stack_tracer.calls.len() - 1);

View File

@ -701,14 +701,12 @@ impl M68kDecoder {
fn read_instruction_word(&mut self, device: &mut AddressableDeviceRefMut<'_>) -> Result<u16, Error> {
let word = device.read_beu16((self.end - self.base) as Address)?;
//debug!("{:#010x} {:#06x?}", self.end, word);
self.end += 2;
Ok(word)
}
fn read_instruction_long(&mut self, device: &mut AddressableDeviceRefMut<'_>) -> Result<u32, Error> {
let word = device.read_beu32((self.end - self.base) as Address)?;
//debug!("{:#010x} {:#010x}", self.end, word);
self.end += 4;
Ok(word)
}
@ -823,7 +821,7 @@ impl M68kDecoder {
(0..((self.end - self.start) / 2)).map(|offset|
Ok(format!("{:04x} ", system.get_bus().read_beu16((self.start + (offset * 2)) as Address).unwrap()))
).collect();
debug!("{:#010x}: {}\n\t{:?}\n", self.start, ins_data.unwrap(), self.instruction);
println!("{:#010x}: {}\n\t{:?}\n", self.start, ins_data.unwrap(), self.instruction);
}
}

View File

@ -16,6 +16,7 @@ pub type Clock = u64;
pub trait Steppable {
fn step(&mut self, system: &System) -> Result<Clock, Error>;
fn on_error(&mut self, _system: &System) { }
fn on_debug(&mut self) { }
}
/// A device that can receive an interrupt. The `interrupt_state_change()` method

View File

@ -30,9 +30,17 @@ impl Error {
}
}
static mut DEBUG_ENABLE: bool = true;
pub fn debug_enabled() -> bool {
unsafe { DEBUG_ENABLE }
}
macro_rules! debug {
($($arg:tt)*) => ({
println!($($arg)*);
if crate::error::debug_enabled() {
println!($($arg)*);
}
})
}

View File

@ -98,14 +98,14 @@ impl Addressable for AtaDevice {
ATA_REG_ERROR => {
data[0] = self.last_error;
},
_ => { println!("{}: reading from {:0x}", DEV_NAME, addr); },
_ => { debug!("{}: reading from {:0x}", DEV_NAME, addr); },
}
Ok(data)
}
fn write(&mut self, addr: Address, data: &[u8]) -> Result<(), Error> {
println!("{}: write to register {:x} with {:x}", DEV_NAME, addr, data[0]);
debug!("{}: write to register {:x} with {:x}", DEV_NAME, addr, data[0]);
match addr {
ATA_REG_DRIVE_HEAD => { self.selected_sector |= ((data[0] & 0x1F) as u32) << 24; },
ATA_REG_CYL_HIGH => { self.selected_sector |= (data[0] as u32) << 16; },
@ -114,11 +114,11 @@ impl Addressable for AtaDevice {
ATA_REG_SECTOR_COUNT => { self.selected_count = (data[0] as u32) * ATA_SECTOR_SIZE; },
ATA_REG_COMMAND => {
match data[0] {
ATA_CMD_READ_SECTORS => { println!("{}: reading sector {:x}", DEV_NAME, self.selected_sector); },
ATA_CMD_WRITE_SECTORS => { println!("{}: writing sector {:x}", DEV_NAME, self.selected_sector); },
ATA_CMD_READ_SECTORS => { debug!("{}: reading sector {:x}", DEV_NAME, self.selected_sector); },
ATA_CMD_WRITE_SECTORS => { debug!("{}: writing sector {:x}", DEV_NAME, self.selected_sector); },
ATA_CMD_IDENTIFY => { },
ATA_CMD_SET_FEATURE => { },
_ => { println!("{}: unrecognized command {:x}", DEV_NAME, data[0]); },
_ => { debug!("{}: unrecognized command {:x}", DEV_NAME, data[0]); },
}
},
ATA_REG_FEATURE => {
@ -127,7 +127,7 @@ impl Addressable for AtaDevice {
ATA_REG_DATA_BYTE => {
// TODO implement writing
},
_ => { println!("{}: writing {:0x} to {:0x}", DEV_NAME, data[0], addr); },
_ => { debug!("{}: writing {:0x} to {:0x}", DEV_NAME, data[0], addr); },
}
Ok(())
}

View File

@ -65,5 +65,15 @@ impl System {
}
}
}
pub fn debug(&mut self) -> Result<(), Error> {
for dev in &self.devices {
match dev {
Device::Addressable(dev) => dev.borrow_mut().on_debug(),
Device::Interruptable(dev) => dev.borrow_mut().on_debug(),
}
}
Ok(())
}
}

View File

@ -1,4 +1,10 @@
* there is a problem with the ANDtoSR instruction, such that interrupts don't occur and the system locks up before the shell starts, but I'm not sure
why it worked before and doesn't work now
* add exception for privileged instructions. Should you separate them in the `match` or just put a guard into the instructions, and if the latter, can
you use the emulator's errors to surface the execption up to the `step_internal` function but not to `System`?
* make functions to print assembly out
* how can you add 68030 support? Should it be all one module that checks maybe during decode if the instruction is supported? Should it 'inherit' from the MC68010 object
* make tests for each instruction