From 9cb338f83e5e1ccd4cf597538d1592ea21881e96 Mon Sep 17 00:00:00 2001 From: Maurizio Porrato Date: Fri, 24 Apr 2020 07:41:14 +0100 Subject: [PATCH] Fix execution of instructions with two literals --- dsim.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/dsim.c b/dsim.c index 335b9f0..c8333f1 100644 --- a/dsim.c +++ b/dsim.c @@ -15,7 +15,7 @@ uint16_t ram[0x10000]; uint16_t ra, rb, rc, rx, ry, rz, ri, rj; uint16_t rpc, rsp, rex, ria; -uint16_t lit; /* temporary storage for literal operands */ +uint16_t lit_a, lit_b; /* temporary storage for literal operands */ bool skip_next; uint64_t ticks; @@ -78,6 +78,10 @@ void shutdown() uint16_t *val(int operand, bool is_a) { + uint16_t *lit; + + lit = (is_a ? &lit_a : &lit_b); + switch (operand) { case 0x00: return &ra; @@ -153,11 +157,11 @@ uint16_t *val(int operand, bool is_a) return &ram[ram[rpc++]]; case 0x1f: ticks++; - lit = ram[rpc++]; - return &lit; + *lit = ram[rpc++]; + return lit; default: - lit = operand - 0x21; - return &lit; + *lit = operand - 0x21; + return lit; } }