...
|
...
|
@@ -12,95 +12,98 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
12
|
12
|
WITH REGARD TO THIS SOFTWARE.
|
13
|
13
|
*/
|
14
|
14
|
|
|
15
|
+#define MODE_RETURN 0x40
|
|
16
|
+#define MODE_KEEP 0x80
|
|
17
|
+
|
15
|
18
|
#pragma mark - Operations
|
16
|
19
|
|
17
|
20
|
/* clang-format off */
|
18
|
|
-void push8(Stack *s, Uint8 a) { if(s->ptr == 0xff) { s->error = 2; return; } s->dat[s->ptr++] = a; }
|
19
|
|
-Uint8 pop8_keep(Stack *s) { if(s->kptr == 0) { s->error = 1; return 0; } return s->dat[--s->kptr]; }
|
20
|
|
-Uint8 pop8_nokeep(Stack *s) { if(s->ptr == 0) { s->error = 1; return 0; } return s->dat[--s->ptr]; }
|
|
21
|
+static void push8(Stack *s, Uint8 a) { if(s->ptr == 0xff) { s->error = 2; return; } s->dat[s->ptr++] = a; }
|
|
22
|
+static Uint8 pop8_keep(Stack *s) { if(s->kptr == 0) { s->error = 1; return 0; } return s->dat[--s->kptr]; }
|
|
23
|
+static Uint8 pop8_nokeep(Stack *s) { if(s->ptr == 0) { s->error = 1; return 0; } return s->dat[--s->ptr]; }
|
21
|
24
|
static Uint8 (*pop8)(Stack *s);
|
22
|
|
-void mempoke8(Uint8 *m, Uint16 a, Uint8 b) { m[a] = b; }
|
23
|
|
-Uint8 mempeek8(Uint8 *m, Uint16 a) { return m[a]; }
|
24
|
|
-void devpoke8(Device *d, Uint8 a, Uint8 b) { d->dat[a & 0xf] = b; d->talk(d, a & 0x0f, 1); }
|
25
|
|
-Uint8 devpeek8(Device *d, Uint8 a) { d->talk(d, a & 0x0f, 0); return d->dat[a & 0xf]; }
|
26
|
|
-void push16(Stack *s, Uint16 a) { push8(s, a >> 8); push8(s, a); }
|
27
|
|
-Uint16 pop16(Stack *s) { Uint8 a = pop8(s), b = pop8(s); return a + (b << 8); }
|
|
25
|
+static void mempoke8(Uint8 *m, Uint16 a, Uint8 b) { m[a] = b; }
|
|
26
|
+static Uint8 mempeek8(Uint8 *m, Uint16 a) { return m[a]; }
|
|
27
|
+static void devpoke8(Device *d, Uint8 a, Uint8 b) { d->dat[a & 0xf] = b; d->talk(d, a & 0x0f, 1); }
|
|
28
|
+static Uint8 devpeek8(Device *d, Uint8 a) { d->talk(d, a & 0x0f, 0); return d->dat[a & 0xf]; }
|
|
29
|
+static void push16(Stack *s, Uint16 a) { push8(s, a >> 8); push8(s, a); }
|
|
30
|
+static Uint16 pop16(Stack *s) { Uint8 a = pop8(s), b = pop8(s); return a + (b << 8); }
|
28
|
31
|
void mempoke16(Uint8 *m, Uint16 a, Uint16 b) { mempoke8(m, a, b >> 8); mempoke8(m, a + 1, b); }
|
29
|
32
|
Uint16 mempeek16(Uint8 *m, Uint16 a) { return (mempeek8(m, a) << 8) + mempeek8(m, a + 1); }
|
30
|
|
-void devpoke16(Device *d, Uint8 a, Uint16 b) { devpoke8(d, a, b >> 8); devpoke8(d, a + 1, b); }
|
31
|
|
-Uint16 devpeek16(Device *d, Uint16 a) { return (devpeek8(d, a) << 8) + devpeek8(d, a + 1); }
|
|
33
|
+static void devpoke16(Device *d, Uint8 a, Uint16 b) { devpoke8(d, a, b >> 8); devpoke8(d, a + 1, b); }
|
|
34
|
+static Uint16 devpeek16(Device *d, Uint16 a) { return (devpeek8(d, a) << 8) + devpeek8(d, a + 1); }
|
32
|
35
|
/* Stack */
|
33
|
|
-void op_brk(Uxn *u) { u->ram.ptr = 0; }
|
34
|
|
-void op_nop(Uxn *u) { (void)u; }
|
35
|
|
-void op_lit(Uxn *u) { push8(u->src, mempeek8(u->ram.dat, u->ram.ptr++)); }
|
36
|
|
-void op_pop(Uxn *u) { pop8(u->src); }
|
37
|
|
-void op_dup(Uxn *u) { Uint8 a = pop8(u->src); push8(u->src, a); push8(u->src, a); }
|
38
|
|
-void op_swp(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, a); push8(u->src, b); }
|
39
|
|
-void op_ovr(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b); push8(u->src, a); push8(u->src, b); }
|
40
|
|
-void op_rot(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src), c = pop8(u->src); push8(u->src, b); push8(u->src, a); push8(u->src, c); }
|
|
36
|
+static void op_brk(Uxn *u) { u->ram.ptr = 0; }
|
|
37
|
+static void op_nop(Uxn *u) { (void)u; }
|
|
38
|
+static void op_lit(Uxn *u) { push8(u->src, mempeek8(u->ram.dat, u->ram.ptr++)); }
|
|
39
|
+static void op_pop(Uxn *u) { pop8(u->src); }
|
|
40
|
+static void op_dup(Uxn *u) { Uint8 a = pop8(u->src); push8(u->src, a); push8(u->src, a); }
|
|
41
|
+static void op_swp(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, a); push8(u->src, b); }
|
|
42
|
+static void op_ovr(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b); push8(u->src, a); push8(u->src, b); }
|
|
43
|
+static void op_rot(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src), c = pop8(u->src); push8(u->src, b); push8(u->src, a); push8(u->src, c); }
|
41
|
44
|
/* Logic */
|
42
|
|
-void op_equ(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b == a); }
|
43
|
|
-void op_neq(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b != a); }
|
44
|
|
-void op_gth(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b > a); }
|
45
|
|
-void op_lth(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b < a); }
|
46
|
|
-void op_jmp(Uxn *u) { Uint8 a = pop8(u->src); u->ram.ptr += (Sint8)a; }
|
47
|
|
-void op_jnz(Uxn *u) { Uint8 a = pop8(u->src); if(pop8(u->src)) u->ram.ptr += (Sint8)a; }
|
48
|
|
-void op_jsr(Uxn *u) { Uint8 a = pop8(u->src); push16(u->dst, u->ram.ptr); u->ram.ptr += (Sint8)a; }
|
49
|
|
-void op_sth(Uxn *u) { Uint8 a = pop8(u->src); push8(u->dst, a); }
|
|
45
|
+static void op_equ(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b == a); }
|
|
46
|
+static void op_neq(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b != a); }
|
|
47
|
+static void op_gth(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b > a); }
|
|
48
|
+static void op_lth(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b < a); }
|
|
49
|
+static void op_jmp(Uxn *u) { Uint8 a = pop8(u->src); u->ram.ptr += (Sint8)a; }
|
|
50
|
+static void op_jnz(Uxn *u) { Uint8 a = pop8(u->src); if(pop8(u->src)) u->ram.ptr += (Sint8)a; }
|
|
51
|
+static void op_jsr(Uxn *u) { Uint8 a = pop8(u->src); push16(u->dst, u->ram.ptr); u->ram.ptr += (Sint8)a; }
|
|
52
|
+static void op_sth(Uxn *u) { Uint8 a = pop8(u->src); push8(u->dst, a); }
|
50
|
53
|
/* Memory */
|
51
|
|
-void op_pek(Uxn *u) { Uint8 a = pop8(u->src); push8(u->src, mempeek8(u->ram.dat, a)); }
|
52
|
|
-void op_pok(Uxn *u) { Uint8 a = pop8(u->src); Uint8 b = pop8(u->src); mempoke8(u->ram.dat, a, b); }
|
53
|
|
-void op_ldr(Uxn *u) { Uint8 a = pop8(u->src); push8(u->src, mempeek8(u->ram.dat, u->ram.ptr + (Sint8)a)); }
|
54
|
|
-void op_str(Uxn *u) { Uint8 a = pop8(u->src); Uint8 b = pop8(u->src); mempoke8(u->ram.dat, u->ram.ptr + (Sint8)a, b); }
|
55
|
|
-void op_lda(Uxn *u) { Uint16 a = pop16(u->src); push8(u->src, mempeek8(u->ram.dat, a)); }
|
56
|
|
-void op_sta(Uxn *u) { Uint16 a = pop16(u->src); Uint8 b = pop8(u->src); mempoke8(u->ram.dat, a, b); }
|
57
|
|
-void op_dei(Uxn *u) { Uint8 a = pop8(u->src); push8(u->src, devpeek8(&u->dev[a >> 4], a)); }
|
58
|
|
-void op_deo(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); devpoke8(&u->dev[a >> 4], a, b); }
|
|
54
|
+static void op_pek(Uxn *u) { Uint8 a = pop8(u->src); push8(u->src, mempeek8(u->ram.dat, a)); }
|
|
55
|
+static void op_pok(Uxn *u) { Uint8 a = pop8(u->src); Uint8 b = pop8(u->src); mempoke8(u->ram.dat, a, b); }
|
|
56
|
+static void op_ldr(Uxn *u) { Uint8 a = pop8(u->src); push8(u->src, mempeek8(u->ram.dat, u->ram.ptr + (Sint8)a)); }
|
|
57
|
+static void op_str(Uxn *u) { Uint8 a = pop8(u->src); Uint8 b = pop8(u->src); mempoke8(u->ram.dat, u->ram.ptr + (Sint8)a, b); }
|
|
58
|
+static void op_lda(Uxn *u) { Uint16 a = pop16(u->src); push8(u->src, mempeek8(u->ram.dat, a)); }
|
|
59
|
+static void op_sta(Uxn *u) { Uint16 a = pop16(u->src); Uint8 b = pop8(u->src); mempoke8(u->ram.dat, a, b); }
|
|
60
|
+static void op_dei(Uxn *u) { Uint8 a = pop8(u->src); push8(u->src, devpeek8(&u->dev[a >> 4], a)); }
|
|
61
|
+static void op_deo(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); devpoke8(&u->dev[a >> 4], a, b); }
|
59
|
62
|
/* Arithmetic */
|
60
|
|
-void op_add(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b + a); }
|
61
|
|
-void op_sub(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b - a); }
|
62
|
|
-void op_mul(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b * a); }
|
63
|
|
-void op_div(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); if(a == 0) { u->src->error = 3; a = 1; } push8(u->src, b / a); }
|
64
|
|
-void op_and(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b & a); }
|
65
|
|
-void op_ora(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b | a); }
|
66
|
|
-void op_eor(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b ^ a); }
|
67
|
|
-void op_sft(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b >> (a & 0x07) << ((a & 0x70) >> 4)); }
|
|
63
|
+static void op_add(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b + a); }
|
|
64
|
+static void op_sub(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b - a); }
|
|
65
|
+static void op_mul(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b * a); }
|
|
66
|
+static void op_div(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); if(a == 0) { u->src->error = 3; a = 1; } push8(u->src, b / a); }
|
|
67
|
+static void op_and(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b & a); }
|
|
68
|
+static void op_ora(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b | a); }
|
|
69
|
+static void op_eor(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b ^ a); }
|
|
70
|
+static void op_sft(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b >> (a & 0x07) << ((a & 0x70) >> 4)); }
|
68
|
71
|
/* Stack */
|
69
|
|
-void op_lit16(Uxn *u) { push16(u->src, mempeek16(u->ram.dat, u->ram.ptr++)); u->ram.ptr++; }
|
70
|
|
-void op_pop16(Uxn *u) { pop16(u->src); }
|
71
|
|
-void op_dup16(Uxn *u) { Uint16 a = pop16(u->src); push16(u->src, a); push16(u->src, a); }
|
72
|
|
-void op_swp16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push16(u->src, a); push16(u->src, b); }
|
73
|
|
-void op_ovr16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push16(u->src, b); push16(u->src, a); push16(u->src, b); }
|
74
|
|
-void op_rot16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src), c = pop16(u->src); push16(u->src, b); push16(u->src, a); push16(u->src, c); }
|
|
72
|
+static void op_lit16(Uxn *u) { push16(u->src, mempeek16(u->ram.dat, u->ram.ptr++)); u->ram.ptr++; }
|
|
73
|
+static void op_pop16(Uxn *u) { pop16(u->src); }
|
|
74
|
+static void op_dup16(Uxn *u) { Uint16 a = pop16(u->src); push16(u->src, a); push16(u->src, a); }
|
|
75
|
+static void op_swp16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push16(u->src, a); push16(u->src, b); }
|
|
76
|
+static void op_ovr16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push16(u->src, b); push16(u->src, a); push16(u->src, b); }
|
|
77
|
+static void op_rot16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src), c = pop16(u->src); push16(u->src, b); push16(u->src, a); push16(u->src, c); }
|
75
|
78
|
/* Logic(16-bits) */
|
76
|
|
-void op_equ16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push8(u->src, b == a); }
|
77
|
|
-void op_neq16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push8(u->src, b != a); }
|
78
|
|
-void op_gth16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push8(u->src, b > a); }
|
79
|
|
-void op_lth16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push8(u->src, b < a); }
|
80
|
|
-void op_jmp16(Uxn *u) { u->ram.ptr = pop16(u->src); }
|
81
|
|
-void op_jnz16(Uxn *u) { Uint16 a = pop16(u->src); if(pop8(u->src)) u->ram.ptr = a; }
|
82
|
|
-void op_jsr16(Uxn *u) { push16(u->dst, u->ram.ptr); u->ram.ptr = pop16(u->src); }
|
83
|
|
-void op_sth16(Uxn *u) { Uint16 a = pop16(u->src); push16(u->dst, a); }
|
|
79
|
+static void op_equ16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push8(u->src, b == a); }
|
|
80
|
+static void op_neq16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push8(u->src, b != a); }
|
|
81
|
+static void op_gth16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push8(u->src, b > a); }
|
|
82
|
+static void op_lth16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push8(u->src, b < a); }
|
|
83
|
+static void op_jmp16(Uxn *u) { u->ram.ptr = pop16(u->src); }
|
|
84
|
+static void op_jnz16(Uxn *u) { Uint16 a = pop16(u->src); if(pop8(u->src)) u->ram.ptr = a; }
|
|
85
|
+static void op_jsr16(Uxn *u) { push16(u->dst, u->ram.ptr); u->ram.ptr = pop16(u->src); }
|
|
86
|
+static void op_sth16(Uxn *u) { Uint16 a = pop16(u->src); push16(u->dst, a); }
|
84
|
87
|
/* Memory(16-bits) */
|
85
|
|
-void op_pek16(Uxn *u) { Uint8 a = pop8(u->src); push16(u->src, mempeek16(u->ram.dat, a)); }
|
86
|
|
-void op_pok16(Uxn *u) { Uint8 a = pop8(u->src); Uint16 b = pop16(u->src); mempoke16(u->ram.dat, a, b); }
|
87
|
|
-void op_ldr16(Uxn *u) { Uint8 a = pop8(u->src); push16(u->src, mempeek16(u->ram.dat, u->ram.ptr + (Sint8)a)); }
|
88
|
|
-void op_str16(Uxn *u) { Uint8 a = pop8(u->src); Uint16 b = pop16(u->src); mempoke16(u->ram.dat, u->ram.ptr + (Sint8)a, b); }
|
89
|
|
-void op_lda16(Uxn *u) { Uint16 a = pop16(u->src); push16(u->src, mempeek16(u->ram.dat, a)); }
|
90
|
|
-void op_sta16(Uxn *u) { Uint16 a = pop16(u->src); Uint16 b = pop16(u->src); mempoke16(u->ram.dat, a, b); }
|
91
|
|
-void op_dei16(Uxn *u) { Uint8 a = pop8(u->src); push16(u->src, devpeek16(&u->dev[a >> 4], a)); }
|
92
|
|
-void op_deo16(Uxn *u) { Uint8 a = pop8(u->src); Uint16 b = pop16(u->src); devpoke16(&u->dev[a >> 4], a, b); }
|
|
88
|
+static void op_pek16(Uxn *u) { Uint8 a = pop8(u->src); push16(u->src, mempeek16(u->ram.dat, a)); }
|
|
89
|
+static void op_pok16(Uxn *u) { Uint8 a = pop8(u->src); Uint16 b = pop16(u->src); mempoke16(u->ram.dat, a, b); }
|
|
90
|
+static void op_ldr16(Uxn *u) { Uint8 a = pop8(u->src); push16(u->src, mempeek16(u->ram.dat, u->ram.ptr + (Sint8)a)); }
|
|
91
|
+static void op_str16(Uxn *u) { Uint8 a = pop8(u->src); Uint16 b = pop16(u->src); mempoke16(u->ram.dat, u->ram.ptr + (Sint8)a, b); }
|
|
92
|
+static void op_lda16(Uxn *u) { Uint16 a = pop16(u->src); push16(u->src, mempeek16(u->ram.dat, a)); }
|
|
93
|
+static void op_sta16(Uxn *u) { Uint16 a = pop16(u->src); Uint16 b = pop16(u->src); mempoke16(u->ram.dat, a, b); }
|
|
94
|
+static void op_dei16(Uxn *u) { Uint8 a = pop8(u->src); push16(u->src, devpeek16(&u->dev[a >> 4], a)); }
|
|
95
|
+static void op_deo16(Uxn *u) { Uint8 a = pop8(u->src); Uint16 b = pop16(u->src); devpoke16(&u->dev[a >> 4], a, b); }
|
93
|
96
|
/* Arithmetic(16-bits) */
|
94
|
|
-void op_add16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push16(u->src, b + a); }
|
95
|
|
-void op_sub16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push16(u->src, b - a); }
|
96
|
|
-void op_mul16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push16(u->src, b * a); }
|
97
|
|
-void op_div16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); if(a == 0) { u->src->error = 3; a = 1; } push16(u->src, b / a); }
|
98
|
|
-void op_and16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push16(u->src, b & a); }
|
99
|
|
-void op_ora16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push16(u->src, b | a); }
|
100
|
|
-void op_eor16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push16(u->src, b ^ a); }
|
101
|
|
-void op_sft16(Uxn *u) { Uint8 a = pop8(u->src); Uint16 b = pop16(u->src); push16(u->src, b >> (a & 0x0f) << ((a & 0xf0) >> 4)); }
|
|
97
|
+static void op_add16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push16(u->src, b + a); }
|
|
98
|
+static void op_sub16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push16(u->src, b - a); }
|
|
99
|
+static void op_mul16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push16(u->src, b * a); }
|
|
100
|
+static void op_div16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); if(a == 0) { u->src->error = 3; a = 1; } push16(u->src, b / a); }
|
|
101
|
+static void op_and16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push16(u->src, b & a); }
|
|
102
|
+static void op_ora16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push16(u->src, b | a); }
|
|
103
|
+static void op_eor16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push16(u->src, b ^ a); }
|
|
104
|
+static void op_sft16(Uxn *u) { Uint8 a = pop8(u->src); Uint16 b = pop16(u->src); push16(u->src, b >> (a & 0x0f) << ((a & 0xf0) >> 4)); }
|
102
|
105
|
|
103
|
|
-void (*ops[])(Uxn *u) = {
|
|
106
|
+static void (*ops[])(Uxn *u) = {
|
104
|
107
|
op_brk, op_lit, op_nop, op_pop, op_dup, op_swp, op_ovr, op_rot,
|
105
|
108
|
op_equ, op_neq, op_gth, op_lth, op_jmp, op_jnz, op_jsr, op_sth,
|
106
|
109
|
op_pek, op_pok, op_ldr, op_str, op_lda, op_sta, op_dei, op_deo,
|
...
|
...
|
@@ -116,38 +119,35 @@ void (*ops[])(Uxn *u) = {
|
116
|
119
|
|
117
|
120
|
#pragma mark - Core
|
118
|
121
|
|
119
|
|
-int
|
120
|
|
-uxn_step(Uxn *u, Uint8 instr)
|
121
|
|
-{
|
122
|
|
- Uint8 op = instr & 0x3f, freturn = instr & 0x40, fkeep = instr & 0x80;
|
123
|
|
- u->src = freturn ? &u->rst : &u->wst;
|
124
|
|
- u->dst = freturn ? &u->wst : &u->rst;
|
125
|
|
- if(fkeep) {
|
126
|
|
- pop8 = pop8_keep;
|
127
|
|
- u->src->kptr = u->src->ptr;
|
128
|
|
- } else
|
129
|
|
- pop8 = pop8_nokeep;
|
130
|
|
- /* run */
|
131
|
|
- (*ops[op])(u);
|
132
|
|
- if(u->wst.error)
|
133
|
|
- return uxn_halt(u, u->wst.error, "Working-stack", instr);
|
134
|
|
- if(u->rst.error)
|
135
|
|
- return uxn_halt(u, u->rst.error, "Return-stack", instr);
|
136
|
|
- return 1;
|
137
|
|
-}
|
138
|
|
-
|
139
|
122
|
int
|
140
|
123
|
uxn_eval(Uxn *u, Uint16 vec)
|
141
|
124
|
{
|
142
|
125
|
if(u->dev[0].dat[0xf])
|
143
|
126
|
return 0;
|
144
|
127
|
u->ram.ptr = vec;
|
145
|
|
- u->wst.error = 0;
|
146
|
|
- u->rst.error = 0;
|
147
|
|
- if(u->wst.ptr > 0xf8) u->wst.ptr = 0xf8;
|
148
|
|
- while(u->ram.ptr)
|
149
|
|
- if(!uxn_step(u, u->ram.dat[u->ram.ptr++]))
|
150
|
|
- return 0;
|
|
128
|
+ while(u->ram.ptr) {
|
|
129
|
+ Uint8 instr = u->ram.dat[u->ram.ptr++];
|
|
130
|
+ /* Return Mode */
|
|
131
|
+ if(instr & MODE_RETURN) {
|
|
132
|
+ u->src = &u->rst;
|
|
133
|
+ u->dst = &u->wst;
|
|
134
|
+ } else {
|
|
135
|
+ u->src = &u->wst;
|
|
136
|
+ u->dst = &u->rst;
|
|
137
|
+ }
|
|
138
|
+ /* Keep Mode */
|
|
139
|
+ if(instr & MODE_KEEP) {
|
|
140
|
+ pop8 = pop8_keep;
|
|
141
|
+ u->src->kptr = u->src->ptr;
|
|
142
|
+ } else {
|
|
143
|
+ pop8 = pop8_nokeep;
|
|
144
|
+ }
|
|
145
|
+ (*ops[instr & 0x3f])(u);
|
|
146
|
+ if(u->wst.error)
|
|
147
|
+ return uxn_halt(u, u->wst.error, "Working-stack", instr);
|
|
148
|
+ if(u->rst.error)
|
|
149
|
+ return uxn_halt(u, u->rst.error, "Return-stack", instr);
|
|
150
|
+ }
|
151
|
151
|
return 1;
|
152
|
152
|
}
|
153
|
153
|
|