Fix execution of instructions with two literals

This commit is contained in:
Maurizio Porrato 2020-04-24 07:41:14 +01:00
parent 4127d9bde8
commit 9cb338f83e
1 changed files with 9 additions and 5 deletions

14
dsim.c
View File

@ -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;
}
}