Skip to content

Commit

Permalink
Use PC instead of ADR for instruction history
Browse files Browse the repository at this point in the history
  • Loading branch information
nabijaczleweli committed Mar 13, 2020
1 parent 573f21c commit 746d258
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/binutils/pir_8_emu/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub struct Vm {
/// Any instruction successfully loaded will be added to the front of this queue
pub instruction_history: ArrayDeque<[(u16, Instruction, u16); 10], ArrayDequeBehaviourWrapping>,

/// Pause execution when ADR is contained herein until the flag is cleared
/// Pause execution when PC is contained herein until the flag is cleared
pub breakpoints: BTreeSet<u16>,
pub active_breakpoint: Option<u16>,
}
Expand Down Expand Up @@ -164,8 +164,8 @@ impl Vm {
self.curr_op += 1;


let (adr_r, adr_w) = (self.adr.was_read(), self.adr.was_written());
let adr = *self.adr;
let (pc_r, pc_w) = (self.pc.was_read(), self.pc.was_written());
let pc = self.pc.wrapping_sub(1);

if self.curr_op >= self.ops.1 {
if self.ins.was_written() {
Expand All @@ -175,9 +175,9 @@ impl Vm {

let mut data = 0u16;
for i in 1..=(self.instruction.data_length() as u16) {
data = (data << 8) | (self.memory[..][adr.wrapping_add(i) as usize] as u16);
data = (data << 8) | (self.memory[..][pc.wrapping_add(i) as usize] as u16);
}
self.instruction_history.push_front((adr, self.instruction, data));
self.instruction_history.push_front((pc, self.instruction, data));
} else {
self.ops = NEXT_INSTRUCTION;
self.instruction_valid = false;
Expand All @@ -187,12 +187,12 @@ impl Vm {
new_ops = true;
}

self.active_breakpoint = self.breakpoints.get(&adr).copied();
self.active_breakpoint = self.breakpoints.get(&pc).copied();

if !adr_r {
self.adr.reset_rw();
if adr_w {
*self.adr = adr;
if !pc_r {
self.pc.reset_rw();
if pc_w {
*self.pc = pc.wrapping_add(1);
}
}

Expand Down

0 comments on commit 746d258

Please sign in to comment.