Break out step()
This commit is contained in:
parent
09bb1854bf
commit
b7ade42661
1 changed files with 287 additions and 282 deletions
39
src/vm.rs
39
src/vm.rs
|
@ -12,6 +12,7 @@ pub enum UxnError {
|
|||
StackError(StackError),
|
||||
MemoryError(MemoryError),
|
||||
ExecutionLimit(u16),
|
||||
Break,
|
||||
ArithmeticOverflow,
|
||||
ArithmeticUnderflow,
|
||||
DivisionByZero,
|
||||
|
@ -111,22 +112,6 @@ impl Uxn {
|
|||
|
||||
// Run one clock cycle (instruction)
|
||||
pub fn step(&mut self) -> Result<(), UxnError> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn run(&mut self, limit: u16) -> Result<(), UxnError> {
|
||||
let mut executed = 0;
|
||||
'run: loop {
|
||||
if executed == limit {
|
||||
return Err(UxnError::ExecutionLimit(executed));
|
||||
}
|
||||
|
||||
if self.is_halted() {
|
||||
break;
|
||||
}
|
||||
|
||||
executed += 1;
|
||||
|
||||
match self.lda1(self.pc) {
|
||||
Err(e) => return Err(UxnError::MemoryError(e)),
|
||||
Ok(opcode) => {
|
||||
|
@ -189,7 +174,7 @@ impl Uxn {
|
|||
match (kflag, rflag, sflag, icode) {
|
||||
(0, 0, 0, 0x00) => {
|
||||
// BRK
|
||||
break 'run;
|
||||
return Err(UxnError::Break);
|
||||
}
|
||||
(_, _, _, 0x00) => {
|
||||
// LIT
|
||||
|
@ -408,6 +393,26 @@ impl Uxn {
|
|||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn run(&mut self, limit: u16) -> Result<(), UxnError> {
|
||||
let mut executed = 0;
|
||||
loop {
|
||||
if executed == limit {
|
||||
return Err(UxnError::ExecutionLimit(executed));
|
||||
}
|
||||
|
||||
if self.is_halted() {
|
||||
break;
|
||||
}
|
||||
|
||||
executed += 1;
|
||||
|
||||
match self.step() {
|
||||
Err(e) => return Err(e),
|
||||
Ok(()) => continue,
|
||||
};
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue