Browse code

Progress merging 8/16 opcodes

neauoire authored on 29/08/2021 22:05:37
Showing 1 changed files
... ...
@@ -19,23 +19,31 @@ WITH REGARD TO THIS SOFTWARE.
19 19
 #pragma mark - Operations
20 20
 
21 21
 /* clang-format off */
22
+
23
+/* Utilities */
24
+static void   (*push)(Stack *s, Uint16 a);
25
+static Uint16 (*pop8)(Stack *s);
26
+static Uint16 (*pop)(Stack *s);
27
+static void   (*poke)(Uint8 *m, Uint16 a, Uint16 b);
28
+static Uint16 (*peek)(Uint8 *m, Uint16 a);
29
+
22 30
 static void   push8(Stack *s, Uint16 a) { if(s->ptr == 0xff) { s->error = 2; return; } s->dat[s->ptr++] = a; }
23 31
 static Uint16  pop8_keep(Stack *s) { if(s->kptr == 0) { s->error = 1; return 0; } return s->dat[--s->kptr]; }
24 32
 static Uint16  pop8_nokeep(Stack *s) { if(s->ptr == 0) { s->error = 1; return 0; } return s->dat[--s->ptr]; }
25
-static Uint16 (*pop8)(Stack *s);
26
-static void   poke8(Uint8 *m, Uint16 a, Uint8 b) { m[a] = b; }
27
-static Uint8  peek8(Uint8 *m, Uint16 a) { return m[a]; }
28
-static void   devw8(Device *d, Uint8 a, Uint8 b) { d->dat[a & 0xf] = b; d->talk(d, a & 0x0f, 1); }
29
-static Uint8  devr8(Device *d, Uint8 a) { d->talk(d, a & 0x0f, 0); return d->dat[a & 0xf];  }
30
-static void   push16(Stack *s, Uint16 a) { push8(s, a >> 8); push8(s, a); }
31
-static Uint16 pop16(Stack *s) { Uint8 a = pop8(s), b = pop8(s); return a + (b << 8); }
33
+
34
+static void   poke8(Uint8 *m, Uint16 a, Uint16 b) { m[a] = b; }
35
+static Uint16 peek8(Uint8 *m, Uint16 a) { return m[a]; }
32 36
 void   poke16(Uint8 *m, Uint16 a, Uint16 b) { poke8(m, a, b >> 8); poke8(m, a + 1, b); }
33 37
 Uint16 peek16(Uint8 *m, Uint16 a) { return (peek8(m, a) << 8) + peek8(m, a + 1); }
38
+
39
+static void   push16(Stack *s, Uint16 a) { push8(s, a >> 8); push8(s, a); }
40
+static Uint16 pop16(Stack *s) { Uint8 a = pop8(s), b = pop8(s); return a + (b << 8); }
41
+
42
+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];  }
34 44
 static void   devw16(Device *d, Uint8 a, Uint16 b) { devw8(d, a, b >> 8); devw8(d, a + 1, b); }
35 45
 static Uint16 devr16(Device *d, Uint16 a) { return (devr8(d, a) << 8) + devr8(d, a + 1); }
36
-/* Utilities */
37
-static Uint16 (*pop)(Stack *s);
38
-static void (*push)(Stack *s, Uint16 a);
46
+
39 47
 /* Stack */
40 48
 static void op_lit(Uxn *u) { push8(u->src, peek8(u->ram.dat, u->ram.ptr++)); }
41 49
 static void op_inc(Uxn *u) { Uint8 a = pop8(u->src); push8(u->src, a + 1); }
... ...
@@ -55,12 +63,12 @@ static void op_jnz(Uxn *u) { Uint8 a = pop8(u->src); if(pop8(u->src)) u->ram.ptr
55 63
 static void op_jsr(Uxn *u) { Uint8 a = pop8(u->src); push16(u->dst, u->ram.ptr); u->ram.ptr += (Sint8)a; }
56 64
 static void op_sth(Uxn *u) { Uint8 a = pop8(u->src); push8(u->dst, a); }
57 65
 /* Memory */
58
-static void op_ldz(Uxn *u) { Uint8 a = pop8(u->src); push8(u->src, peek8(u->ram.dat, a)); }
59
-static void op_stz(Uxn *u) { Uint8 a = pop8(u->src); Uint8 b = pop8(u->src); poke8(u->ram.dat, a, b); }
66
+static void op_ldz(Uxn *u) { Uint8 a = pop8(u->src); push(u->src, peek(u->ram.dat, a)); }
67
+static void op_stz(Uxn *u) { Uint8 a = pop8(u->src); Uint16 b = pop(u->src); poke(u->ram.dat, a, b); }
60 68
 static void op_ldr(Uxn *u) { Uint8 a = pop8(u->src); push8(u->src, peek8(u->ram.dat, u->ram.ptr + (Sint8)a)); }
61 69
 static void op_str(Uxn *u) { Uint8 a = pop8(u->src); Uint8 b = pop8(u->src); poke8(u->ram.dat, u->ram.ptr + (Sint8)a, b); }
62
-static void op_lda(Uxn *u) { Uint16 a = pop16(u->src); push8(u->src, peek8(u->ram.dat, a)); }
63
-static void op_sta(Uxn *u) { Uint16 a = pop16(u->src); Uint8 b = pop8(u->src); poke8(u->ram.dat, a, b); }
70
+static void op_lda(Uxn *u) { Uint16 a = pop16(u->src); push(u->src, peek(u->ram.dat, a)); }
71
+static void op_sta(Uxn *u) { Uint16 a = pop16(u->src); Uint16 b = pop(u->src); poke(u->ram.dat, a, b); }
64 72
 static void op_dei(Uxn *u) { Uint8 a = pop8(u->src); push8(u->src, devr8(&u->dev[a >> 4], a)); }
65 73
 static void op_deo(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); devw8(&u->dev[a >> 4], a, b); }
66 74
 /* Arithmetic */
... ...
@@ -87,12 +95,8 @@ static void op_jnz16(Uxn *u) { Uint16 a = pop16(u->src); if(pop8(u->src)) u->ram
87 95
 static void op_jsr16(Uxn *u) { push16(u->dst, u->ram.ptr); u->ram.ptr = pop16(u->src); }
88 96
 static void op_sth16(Uxn *u) { Uint16 a = pop16(u->src); push16(u->dst, a); }
89 97
 /* Memory(16-bits) */
90
-static void op_ldz16(Uxn *u) { Uint8 a = pop8(u->src); push16(u->src, peek16(u->ram.dat, a)); }
91
-static void op_stz16(Uxn *u) { Uint8 a = pop8(u->src); Uint16 b = pop16(u->src); poke16(u->ram.dat, a, b); }
92 98
 static void op_ldr16(Uxn *u) { Uint8 a = pop8(u->src); push16(u->src, peek16(u->ram.dat, u->ram.ptr + (Sint8)a)); }
93 99
 static void op_str16(Uxn *u) { Uint8 a = pop8(u->src); Uint16 b = pop16(u->src); poke16(u->ram.dat, u->ram.ptr + (Sint8)a, b); }
94
-static void op_lda16(Uxn *u) { Uint16 a = pop16(u->src); push16(u->src, peek16(u->ram.dat, a)); }
95
-static void op_sta16(Uxn *u) { Uint16 a = pop16(u->src); Uint16 b = pop16(u->src); poke16(u->ram.dat, a, b); }
96 100
 static void op_dei16(Uxn *u) { Uint8 a = pop8(u->src); push16(u->src, devr16(&u->dev[a >> 4], a)); }
97 101
 static void op_deo16(Uxn *u) { Uint8 a = pop8(u->src); Uint16 b = pop16(u->src); devw16(&u->dev[a >> 4], a, b); }
98 102
 
... ...
@@ -104,7 +108,7 @@ static void (*ops[])(Uxn *u) = {
104 108
 	/* 16-bit */
105 109
 	op_lit16, op_inc16, op_pop16, op_dup16, op_nip16, op_swp16, op_ovr16, op_rot16,
106 110
 	op_equ, op_neq, op_gth, op_lth, op_jmp16, op_jnz16, op_jsr16, op_sth16, 
107
-	op_ldz16, op_stz16, op_ldr16, op_str16, op_lda16, op_sta16, op_dei16, op_deo16, 
111
+	op_ldz, op_stz, op_ldr16, op_str16, op_lda, op_sta, op_dei16, op_deo16, 
108 112
 	op_add, op_sub, op_mul, op_div, op_and, op_ora, op_eor, op_sft
109 113
 };
110 114
 
... ...
@@ -140,9 +144,13 @@ uxn_eval(Uxn *u, Uint16 vec)
140 144
 		if(instr & MODE_SHORT) {
141 145
 			pop = pop16;
142 146
 			push = push16;
147
+			peek = peek16;
148
+			poke = poke16;
143 149
 		} else {
144 150
 			pop = pop8;
145 151
 			push = push8;
152
+			peek = peek8;
153
+			poke = poke8;
146 154
 		}
147 155
 		(*ops[(instr & 0x1f) | ((instr & MODE_SHORT) >> 1)])(u);
148 156
 		if(u->wst.error)