summaryrefslogtreecommitdiffhomepage
path: root/mixlib
diff options
context:
space:
mode:
Diffstat (limited to 'mixlib')
-rw-r--r--mixlib/mix_vm.c32
-rw-r--r--mixlib/mix_vm.h6
2 files changed, 26 insertions, 12 deletions
diff --git a/mixlib/mix_vm.c b/mixlib/mix_vm.c
index 2c41097..38ce5a9 100644
--- a/mixlib/mix_vm.c
+++ b/mixlib/mix_vm.c
@@ -308,6 +308,25 @@ mix_vm_get_prog_count (const mix_vm_t *vm)
return get_loc_ (vm);
}
+/* Reposition program counter and reset state so that a loaded
+ program can be restarted.
+*/
+void
+mix_vm_reset_program (mix_vm_t *vm)
+{
+ guint k;
+ g_return_if_fail (vm != NULL);
+ reset_loc_ (vm);
+ halt_ (vm, FALSE);
+ set_rA_ (vm, MIX_WORD_ZERO);
+ set_rX_ (vm, MIX_WORD_ZERO);
+ set_rJ_ (vm, MIX_WORD_ZERO);
+ for ( k = 1; k < IREG_NO_+1; ++k )
+ set_rI_ (vm, k, MIX_WORD_ZERO);
+ set_over_ (vm, FALSE);
+ set_cmp_ (vm, mix_EQ);
+}
+
/* continue execution of instructions in memory */
int
mix_vm_run (mix_vm_t *vm)
@@ -315,12 +334,6 @@ mix_vm_run (mix_vm_t *vm)
mix_ins_t ins;
g_return_val_if_fail (vm != NULL, MIX_VM_ERROR);
- if ( is_halted_ (vm) )
- {
- reset_loc_ (vm); /* set current location to start address */
- halt_ (vm, FALSE);
- }
-
while ( !is_halted_ (vm) )
{
mix_word_to_ins_uncheck (get_cell_ (vm, get_loc_ (vm)), ins);
@@ -340,12 +353,7 @@ mix_vm_exec_next (mix_vm_t *vm)
mix_ins_t ins;
g_return_val_if_fail (vm != NULL, MIX_VM_ERROR);
if (get_loc_ (vm) >= MIX_VM_CELL_NO) halt_ (vm, TRUE);
- if (is_halted_ (vm))
- {
- reset_loc_ (vm); /* set current location to start address */
- halt_ (vm, FALSE);
- return MIX_VM_HALT;
- }
+ if (is_halted_ (vm)) return MIX_VM_HALT;
mix_word_to_ins_uncheck (get_cell_ (vm, get_loc_ (vm)), ins);
if (!(*ins_handlers_[ins.opcode]) (vm, &ins))
return MIX_VM_ERROR;
diff --git a/mixlib/mix_vm.h b/mixlib/mix_vm.h
index cf4965c..62ba34d 100644
--- a/mixlib/mix_vm.h
+++ b/mixlib/mix_vm.h
@@ -127,6 +127,12 @@ mix_vm_get_symbol_table (const mix_vm_t *vm);
extern mix_address_t
mix_vm_get_prog_count (const mix_vm_t *vm);
+/* Reposition program counter and reset state so that a loaded
+ program can be restarted.
+*/
+extern void
+mix_vm_reset_program (mix_vm_t *vm);
+
/* continue execution of instructions in memory */
/* Possible outcomes */
enum {