Clean up code
This commit is contained in:
parent
38eea41ce5
commit
2447a98e87
@ -148,7 +148,7 @@ impl Backplane {
|
|||||||
.get(card_num as usize)
|
.get(card_num as usize)
|
||||||
.ok_or_else(|| anyhow!("Card {} does not exist", card_num))?
|
.ok_or_else(|| anyhow!("Card {} does not exist", card_num))?
|
||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
.cmd(cmd, &self)
|
.cmd(cmd, self)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read_word(&self, address: u32, supervisor: bool) -> Result<u16, BusError> {
|
pub fn read_word(&self, address: u32, supervisor: bool) -> Result<u16, BusError> {
|
||||||
|
@ -58,6 +58,7 @@ pub trait Card: Debug + Display + mopa::Any {
|
|||||||
fn new(data: Value) -> anyhow::Result<Self>
|
fn new(data: Value) -> anyhow::Result<Self>
|
||||||
where
|
where
|
||||||
Self: Sized;
|
Self: Sized;
|
||||||
|
|
||||||
fn new_dyn(data: Value) -> anyhow::Result<Rc<RefCell<dyn Card>>>
|
fn new_dyn(data: Value) -> anyhow::Result<Rc<RefCell<dyn Card>>>
|
||||||
where
|
where
|
||||||
Self: Sized + 'static,
|
Self: Sized + 'static,
|
||||||
@ -65,9 +66,7 @@ pub trait Card: Debug + Display + mopa::Any {
|
|||||||
let card = Self::new(data)?;
|
let card = Self::new(data)?;
|
||||||
Ok(Rc::new(RefCell::new(card)))
|
Ok(Rc::new(RefCell::new(card)))
|
||||||
}
|
}
|
||||||
fn display(&self) -> String {
|
|
||||||
String::new()
|
|
||||||
}
|
|
||||||
fn read_byte(&mut self, _address: u32) -> NullableResult<u8, BusError> {
|
fn read_byte(&mut self, _address: u32) -> NullableResult<u8, BusError> {
|
||||||
NullableResult::Null
|
NullableResult::Null
|
||||||
}
|
}
|
||||||
|
41
src/m68k.rs
41
src/m68k.rs
@ -24,7 +24,7 @@ impl Display for BusError {
|
|||||||
|
|
||||||
impl Error for BusError {}
|
impl Error for BusError {}
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone)]
|
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||||
pub enum BusErrorCause {
|
pub enum BusErrorCause {
|
||||||
ReadingByte,
|
ReadingByte,
|
||||||
ReadingWord,
|
ReadingWord,
|
||||||
@ -33,6 +33,15 @@ pub enum BusErrorCause {
|
|||||||
ReadingInstruction,
|
ReadingInstruction,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl BusErrorCause {
|
||||||
|
fn is_write(self) -> bool {
|
||||||
|
self == Self::WritingByte || self == Self::WritingWord
|
||||||
|
}
|
||||||
|
fn is_byte(self) -> bool {
|
||||||
|
self == Self::ReadingByte || self == Self::WritingByte
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Display for BusErrorCause {
|
impl Display for BusErrorCause {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
@ -286,20 +295,10 @@ impl M68K {
|
|||||||
}
|
}
|
||||||
self.handling_bus_error = true;
|
self.handling_bus_error = true;
|
||||||
self.store_mem_cycles = false;
|
self.store_mem_cycles = false;
|
||||||
let (write, ins, byte_access) = match bus_error.cause {
|
|
||||||
BusErrorCause::ReadingByte => (false, false, true),
|
|
||||||
BusErrorCause::WritingByte => (true, false, true),
|
|
||||||
BusErrorCause::ReadingWord => (false, false, false),
|
|
||||||
BusErrorCause::WritingWord => (true, false, false),
|
|
||||||
BusErrorCause::ReadingInstruction => (false, true, false),
|
|
||||||
};
|
|
||||||
let stored_mem_cycles_len = self.stored_mem_cycles.len();
|
let stored_mem_cycles_len = self.stored_mem_cycles.len();
|
||||||
let last_cycle = &self.stored_mem_cycles[stored_mem_cycles_len - 1];
|
let last_cycle = &self.stored_mem_cycles[stored_mem_cycles_len - 1];
|
||||||
if let Err(snd_bus_error) = self.berr_trap(
|
if let Err(snd_bus_error) = self.berr_trap(
|
||||||
write,
|
bus_error,
|
||||||
ins,
|
|
||||||
byte_access,
|
|
||||||
bus_error.address,
|
|
||||||
last_cycle.try_get_write_data().unwrap_or(0),
|
last_cycle.try_get_write_data().unwrap_or(0),
|
||||||
) {
|
) {
|
||||||
println!(
|
println!(
|
||||||
@ -747,9 +746,7 @@ impl M68K {
|
|||||||
} else if last_cycle.is_err() {
|
} else if last_cycle.is_err() {
|
||||||
self.stored_mem_cycles.pop();
|
self.stored_mem_cycles.pop();
|
||||||
}
|
}
|
||||||
self.use_stored_mem_cycles = true;
|
} else if format == 0 {
|
||||||
self.handling_bus_error = false;
|
|
||||||
} if format == 0 {
|
|
||||||
// Nothing extra needed
|
// Nothing extra needed
|
||||||
} else {
|
} else {
|
||||||
self.trap(14)?;
|
self.trap(14)?;
|
||||||
@ -1760,10 +1757,7 @@ impl M68K {
|
|||||||
|
|
||||||
fn berr_trap(
|
fn berr_trap(
|
||||||
&mut self,
|
&mut self,
|
||||||
write: bool,
|
bus_error: DetailedBusError,
|
||||||
ins: bool,
|
|
||||||
byte_access: bool,
|
|
||||||
fault_addr: u32,
|
|
||||||
write_data: u16,
|
write_data: u16,
|
||||||
) -> Result<(), InsExecError> {
|
) -> Result<(), InsExecError> {
|
||||||
let orig_sr = self.sr;
|
let orig_sr = self.sr;
|
||||||
@ -1792,11 +1786,12 @@ impl M68K {
|
|||||||
// Unused
|
// Unused
|
||||||
self.push(0, Size::Word)?;
|
self.push(0, Size::Word)?;
|
||||||
// Fault address
|
// Fault address
|
||||||
self.push(fault_addr, Size::Long)?;
|
self.push(bus_error.address, Size::Long)?;
|
||||||
// Special status word
|
// Special status word
|
||||||
let special_status_word = (u16::from(write) << 8)
|
let ins = bus_error.cause == BusErrorCause::ReadingInstruction;
|
||||||
| (u16::from(byte_access) << 9)
|
let special_status_word = (u16::from(bus_error.cause.is_write()) << 8)
|
||||||
| (((fault_addr & 0x1) as u16) << 10)
|
| (u16::from(bus_error.cause.is_byte()) << 9)
|
||||||
|
| (((bus_error.address & 0x1) as u16) << 10)
|
||||||
| u16::from(!ins)
|
| u16::from(!ins)
|
||||||
| u16::from(ins);
|
| u16::from(ins);
|
||||||
self.push(u32::from(special_status_word), Size::Word)?;
|
self.push(u32::from(special_status_word), Size::Word)?;
|
||||||
|
14
src/mmu.rs
14
src/mmu.rs
@ -162,15 +162,13 @@ impl Card for MmuCard {
|
|||||||
if j_frame == frame {
|
if j_frame == frame {
|
||||||
if range_one_page == Some(false) {
|
if range_one_page == Some(false) {
|
||||||
break;
|
break;
|
||||||
} else {
|
}
|
||||||
range_one_page = Some(true);
|
range_one_page = Some(true);
|
||||||
}
|
|
||||||
} else if (j_frame - frame) == ((((j - i) as u32) + 1) * 0x1000) {
|
} else if (j_frame - frame) == ((((j - i) as u32) + 1) * 0x1000) {
|
||||||
if range_one_page == Some(true) {
|
if range_one_page == Some(true) {
|
||||||
break;
|
break;
|
||||||
} else {
|
|
||||||
range_one_page = Some(false);
|
|
||||||
}
|
}
|
||||||
|
range_one_page = Some(false);
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -246,15 +244,13 @@ impl Card for MmuCard {
|
|||||||
if j_frame == frame {
|
if j_frame == frame {
|
||||||
if range_one_page == Some(false) {
|
if range_one_page == Some(false) {
|
||||||
break;
|
break;
|
||||||
} else {
|
|
||||||
range_one_page = Some(true);
|
|
||||||
}
|
}
|
||||||
|
range_one_page = Some(true);
|
||||||
} else if (j_frame - frame) == ((((j - i) as u32) + 1) * 0x1000) {
|
} else if (j_frame - frame) == ((((j - i) as u32) + 1) * 0x1000) {
|
||||||
if range_one_page == Some(true) {
|
if range_one_page == Some(true) {
|
||||||
break;
|
break;
|
||||||
} else {
|
|
||||||
range_one_page = Some(false);
|
|
||||||
}
|
}
|
||||||
|
range_one_page = Some(false);
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -26,10 +26,6 @@ impl Display for SymbolDisplayer<'_> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, Error)]
|
|
||||||
#[error("Invalid symbol table")]
|
|
||||||
struct InvalidSymbolTable;
|
|
||||||
|
|
||||||
pub struct BreakpointDisplayer<'a>(&'a SymbolTable);
|
pub struct BreakpointDisplayer<'a>(&'a SymbolTable);
|
||||||
|
|
||||||
impl Display for BreakpointDisplayer<'_> {
|
impl Display for BreakpointDisplayer<'_> {
|
||||||
|
Loading…
Reference in New Issue
Block a user