summaryrefslogtreecommitdiffhomepage
path: root/mixlib
diff options
context:
space:
mode:
authorjaortega <jaortega>2000-12-20 01:01:29 +0000
committerjaortega <jaortega>2000-12-20 01:01:29 +0000
commitf18a9fd4d5d1c80950c126dad266c69a7646aaf4 (patch)
treee13b6ef15263944218320586c652a3fbd32563d3 /mixlib
parentcf68b09511481dbafcd625b8dec4603d4126599f (diff)
downloadmdk-f18a9fd4d5d1c80950c126dad266c69a7646aaf4.tar.gz
mdk-f18a9fd4d5d1c80950c126dad266c69a7646aaf4.tar.bz2
(mix_vm_reset_program) new function
(mix_vm_run, mix_vm_next) removed automatic reset of location pointer when program halted
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 {