Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
fix unsigned subtraction
Browse files Browse the repository at this point in the history
  • Loading branch information
filiparag committed Dec 7, 2023
1 parent 3e5c305 commit 775aa0e
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions src/processor/implementation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,11 @@ impl Processor {
}

#[allow(dead_code)]
pub fn run(&mut self, breakpoints: bool, count: Option<isize>) -> Result<usize, EmulationError> {
pub fn run(
&mut self,
breakpoints: bool,
count: Option<isize>,
) -> Result<usize, EmulationError> {
let instruction_count = self.runtime_counter;
let end = if let Instruction::NoOperation = self.rom[self.last_instruction_address()] {
if self.last_instruction_address() == 0 {
Expand All @@ -160,18 +164,20 @@ impl Processor {
self.last_instruction_address()
};
let runtime_end = match count {
Some(v) => if v >= 0 {
self.runtime_counter + v as usize
} else {
let count= if self.runtime_counter > 0 {
self.runtime_counter as isize + v
Some(v) => {
if v >= 0 {
self.runtime_counter + v as usize
} else {
0
};
self.reset();
count as usize
},
None => usize::MAX
let count = if self.runtime_counter > 0 {
self.runtime_counter as isize + v
} else {
0
};
self.reset();
count as usize
}
}
None => usize::MAX,
};
while self.program_counter <= end && self.runtime_counter < runtime_end {
if !self.tick()? {
Expand All @@ -181,7 +187,7 @@ impl Processor {
break;
}
}
Ok(self.runtime_counter - instruction_count)
Ok((self.runtime_counter as isize - instruction_count as isize) as usize)
}

#[allow(dead_code)]
Expand Down

0 comments on commit 775aa0e

Please sign in to comment.