Browse code

Progress merging 8/16 opcodes

neauoire authored on 30/08/2021 00:36:17
Showing 1 changed files
... ...
@@ -26,6 +26,7 @@ static Uint16 (*pop8)(Stack *s);
26 26
 static Uint16 (*pop)(Stack *s);
27 27
 static void   (*poke)(Uint8 *m, Uint16 a, Uint16 b);
28 28
 static Uint16 (*peek)(Uint8 *m, Uint16 a);
29
+static Uint16 (*devr)(Device *d, Uint8 a);
29 30
 
30 31
 static void   push8(Stack *s, Uint16 a) { if(s->ptr == 0xff) { s->error = 2; return; } s->dat[s->ptr++] = a; }
31 32
 static Uint16  pop8_keep(Stack *s) { if(s->kptr == 0) { s->error = 1; return 0; } return s->dat[--s->kptr]; }
... ...
@@ -40,9 +41,9 @@ static void   push16(Stack *s, Uint16 a) { push8(s, a >> 8); push8(s, a); }
40 41
 static Uint16 pop16(Stack *s) { Uint8 a = pop8(s), b = pop8(s); return a + (b << 8); }
41 42
 
42 43
 static void   devw8(Device *d, Uint8 a, Uint8 b) { d->dat[a & 0xf] = b; d->talk(d, a & 0x0f, 1); }
43
-static Uint8  devr8(Device *d, Uint8 a) { d->talk(d, a & 0x0f, 0); return d->dat[a & 0xf];  }
44
+static Uint16 devr8(Device *d, Uint8 a) { d->talk(d, a & 0x0f, 0); return d->dat[a & 0xf];  }
44 45
 static void   devw16(Device *d, Uint8 a, Uint16 b) { devw8(d, a, b >> 8); devw8(d, a + 1, b); }
45
-static Uint16 devr16(Device *d, Uint16 a) { return (devr8(d, a) << 8) + devr8(d, a + 1); }
46
+static Uint16 devr16(Device *d, Uint8 a) { return (devr8(d, a) << 8) + devr8(d, a + 1); }
46 47
 
47 48
 /* Stack */
48 49
 static void op_lit(Uxn *u) { push8(u->src, peek8(u->ram.dat, u->ram.ptr++)); }
... ...
@@ -69,7 +70,7 @@ static void op_ldr(Uxn *u) { Uint8 a = pop8(u->src); push(u->src, peek(u->ram.da
69 70
 static void op_str(Uxn *u) { Uint8 a = pop8(u->src); Uint8 b = pop(u->src); poke(u->ram.dat, u->ram.ptr + (Sint8)a, b); }
70 71
 static void op_lda(Uxn *u) { Uint16 a = pop16(u->src); push(u->src, peek(u->ram.dat, a)); }
71 72
 static void op_sta(Uxn *u) { Uint16 a = pop16(u->src); Uint16 b = pop(u->src); poke(u->ram.dat, a, b); }
72
-static void op_dei(Uxn *u) { Uint8 a = pop8(u->src); push8(u->src, devr8(&u->dev[a >> 4], a)); }
73
+static void op_dei(Uxn *u) { Uint8 a = pop8(u->src); push(u->src, devr(&u->dev[a >> 4], a)); }
73 74
 static void op_deo(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); devw8(&u->dev[a >> 4], a, b); }
74 75
 /* Arithmetic */
75 76
 static void op_add(Uxn *u) { Uint16 a = pop(u->src), b = pop(u->src); push(u->src, b + a); }
... ...
@@ -87,7 +88,6 @@ static void op_jmp16(Uxn *u) { u->ram.ptr = pop16(u->src); }
87 88
 static void op_jnz16(Uxn *u) { Uint16 a = pop16(u->src); if(pop8(u->src)) u->ram.ptr = a; }
88 89
 static void op_jsr16(Uxn *u) { push16(u->dst, u->ram.ptr); u->ram.ptr = pop16(u->src); }
89 90
 /* Memory(16-bits) */
90
-static void op_dei16(Uxn *u) { Uint8 a = pop8(u->src); push16(u->src, devr16(&u->dev[a >> 4], a)); }
91 91
 static void op_deo16(Uxn *u) { Uint8 a = pop8(u->src); Uint16 b = pop16(u->src); devw16(&u->dev[a >> 4], a, b); }
92 92
 
93 93
 static void (*ops[])(Uxn *u) = {
... ...
@@ -98,7 +98,7 @@ static void (*ops[])(Uxn *u) = {
98 98
 	/* 16-bit */
99 99
 	op_lit16, op_inc, op_pop, op_dup, op_nip, op_swp, op_ovr, op_rot,
100 100
 	op_equ, op_neq, op_gth, op_lth, op_jmp16, op_jnz16, op_jsr16, op_sth, 
101
-	op_ldz, op_stz, op_ldr, op_str, op_lda, op_sta, op_dei16, op_deo16, 
101
+	op_ldz, op_stz, op_ldr, op_str, op_lda, op_sta, op_dei, op_deo16, 
102 102
 	op_add, op_sub, op_mul, op_div, op_and, op_ora, op_eor, op_sft
103 103
 };
104 104
 
... ...
@@ -136,11 +136,13 @@ uxn_eval(Uxn *u, Uint16 vec)
136 136
 			push = push16;
137 137
 			peek = peek16;
138 138
 			poke = poke16;
139
+			devr = devr16;
139 140
 		} else {
140 141
 			pop = pop8;
141 142
 			push = push8;
142 143
 			peek = peek8;
143 144
 			poke = poke8;
145
+			devr = devr8;
144 146
 		}
145 147
 		(*ops[(instr & 0x1f) | ((instr & MODE_SHORT) >> 1)])(u);
146 148
 		if(u->wst.error)