...
|
...
|
@@ -26,17 +26,20 @@ 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 void (*devw)(Device *d, Uint8 a, Uint16 b);
|
29
|
30
|
static Uint16 (*devr)(Device *d, Uint8 a);
|
30
|
31
|
static void (*warp)(Uxn *u, Uint16 a);
|
|
32
|
+static void (*pull)(Uxn *u);
|
31
|
33
|
|
32
|
34
|
static void push8(Stack *s, Uint16 a) { if(s->ptr == 0xff) { s->error = 2; return; } s->dat[s->ptr++] = a; }
|
33
|
35
|
static Uint16 pop8_keep(Stack *s) { if(s->kptr == 0) { s->error = 1; return 0; } return s->dat[--s->kptr]; }
|
34
|
36
|
static Uint16 pop8_nokeep(Stack *s) { if(s->ptr == 0) { s->error = 1; return 0; } return s->dat[--s->ptr]; }
|
35
|
37
|
static void poke8(Uint8 *m, Uint16 a, Uint16 b) { m[a] = b; }
|
36
|
38
|
static Uint16 peek8(Uint8 *m, Uint16 a) { return m[a]; }
|
37
|
|
-static void devw8(Device *d, Uint8 a, Uint8 b) { d->dat[a & 0xf] = b; d->talk(d, a & 0x0f, 1); }
|
|
39
|
+static void devw8(Device *d, Uint8 a, Uint16 b) { d->dat[a & 0xf] = b; d->talk(d, a & 0x0f, 1); }
|
38
|
40
|
static Uint16 devr8(Device *d, Uint8 a) { d->talk(d, a & 0x0f, 0); return d->dat[a & 0xf]; }
|
39
|
41
|
static void warp8(Uxn *u, Uint16 a){ u->ram.ptr += (Sint8)a; }
|
|
42
|
+static void pull8(Uxn *u){ push8(u->src, peek8(u->ram.dat, u->ram.ptr++)); }
|
40
|
43
|
|
41
|
44
|
void poke16(Uint8 *m, Uint16 a, Uint16 b) { poke8(m, a, b >> 8); poke8(m, a + 1, b); }
|
42
|
45
|
Uint16 peek16(Uint8 *m, Uint16 a) { return (peek8(m, a) << 8) + peek8(m, a + 1); }
|
...
|
...
|
@@ -45,9 +48,10 @@ static Uint16 pop16(Stack *s) { Uint8 a = pop8(s), b = pop8(s); return a + (b <<
|
45
|
48
|
static void devw16(Device *d, Uint8 a, Uint16 b) { devw8(d, a, b >> 8); devw8(d, a + 1, b); }
|
46
|
49
|
static Uint16 devr16(Device *d, Uint8 a) { return (devr8(d, a) << 8) + devr8(d, a + 1); }
|
47
|
50
|
static void warp16(Uxn *u, Uint16 a){ u->ram.ptr = a; }
|
|
51
|
+static void pull16(Uxn *u){ push16(u->src, peek16(u->ram.dat, u->ram.ptr++)); u->ram.ptr++; }
|
48
|
52
|
|
49
|
53
|
/* Stack */
|
50
|
|
-static void op_lit(Uxn *u) { push8(u->src, peek8(u->ram.dat, u->ram.ptr++)); }
|
|
54
|
+static void op_lit(Uxn *u) { pull(u); }
|
51
|
55
|
static void op_inc(Uxn *u) { Uint16 a = pop(u->src); push(u->src, a + 1); }
|
52
|
56
|
static void op_pop(Uxn *u) { pop(u->src); }
|
53
|
57
|
static void op_dup(Uxn *u) { Uint16 a = pop(u->src); push(u->src, a); push(u->src, a); }
|
...
|
...
|
@@ -72,7 +76,7 @@ static void op_str(Uxn *u) { Uint8 a = pop8(u->src); Uint8 b = pop(u->src); poke
|
72
|
76
|
static void op_lda(Uxn *u) { Uint16 a = pop16(u->src); push(u->src, peek(u->ram.dat, a)); }
|
73
|
77
|
static void op_sta(Uxn *u) { Uint16 a = pop16(u->src); Uint16 b = pop(u->src); poke(u->ram.dat, a, b); }
|
74
|
78
|
static void op_dei(Uxn *u) { Uint8 a = pop8(u->src); push(u->src, devr(&u->dev[a >> 4], a)); }
|
75
|
|
-static void op_deo(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); devw8(&u->dev[a >> 4], a, b); }
|
|
79
|
+static void op_deo(Uxn *u) { Uint8 a = pop8(u->src); Uint16 b = pop(u->src); devw(&u->dev[a >> 4], a, b); }
|
76
|
80
|
/* Arithmetic */
|
77
|
81
|
static void op_add(Uxn *u) { Uint16 a = pop(u->src), b = pop(u->src); push(u->src, b + a); }
|
78
|
82
|
static void op_sub(Uxn *u) { Uint16 a = pop(u->src), b = pop(u->src); push(u->src, b - a); }
|
...
|
...
|
@@ -82,21 +86,12 @@ static void op_and(Uxn *u) { Uint16 a = pop(u->src), b = pop(u->src); push(u->sr
|
82
|
86
|
static void op_ora(Uxn *u) { Uint16 a = pop(u->src), b = pop(u->src); push(u->src, b | a); }
|
83
|
87
|
static void op_eor(Uxn *u) { Uint16 a = pop(u->src), b = pop(u->src); push(u->src, b ^ a); }
|
84
|
88
|
static void op_sft(Uxn *u) { Uint16 a = pop8(u->src), b = pop(u->src); push(u->src, b >> (a & 0x07) << ((a & 0x70) >> 4)); }
|
85
|
|
-/* Stack(16-bits) */
|
86
|
|
-static void op_lit16(Uxn *u) { push16(u->src, peek16(u->ram.dat, u->ram.ptr++)); u->ram.ptr++; }
|
87
|
|
-/* Memory(16-bits) */
|
88
|
|
-static void op_deo16(Uxn *u) { Uint8 a = pop8(u->src); Uint16 b = pop16(u->src); devw16(&u->dev[a >> 4], a, b); }
|
89
|
89
|
|
90
|
90
|
static void (*ops[])(Uxn *u) = {
|
91
|
91
|
op_lit, op_inc, op_pop, op_dup, op_nip, op_swp, op_ovr, op_rot,
|
92
|
92
|
op_equ, op_neq, op_gth, op_lth, op_jmp, op_jnz, op_jsr, op_sth,
|
93
|
93
|
op_ldz, op_stz, op_ldr, op_str, op_lda, op_sta, op_dei, op_deo,
|
94
|
94
|
op_add, op_sub, op_mul, op_div, op_and, op_ora, op_eor, op_sft,
|
95
|
|
- /* 16-bit */
|
96
|
|
- op_lit16, op_inc, op_pop, op_dup, op_nip, op_swp, op_ovr, op_rot,
|
97
|
|
- op_equ, op_neq, op_gth, op_lth, op_jmp, op_jnz, op_jsr, op_sth,
|
98
|
|
- op_ldz, op_stz, op_ldr, op_str, op_lda, op_sta, op_dei, op_deo16,
|
99
|
|
- op_add, op_sub, op_mul, op_div, op_and, op_ora, op_eor, op_sft
|
100
|
95
|
};
|
101
|
96
|
|
102
|
97
|
/* clang-format on */
|
...
|
...
|
@@ -134,16 +129,20 @@ uxn_eval(Uxn *u, Uint16 vec)
|
134
|
129
|
peek = peek16;
|
135
|
130
|
poke = poke16;
|
136
|
131
|
devr = devr16;
|
|
132
|
+ devw = devw16;
|
137
|
133
|
warp = warp16;
|
|
134
|
+ pull = pull16;
|
138
|
135
|
} else {
|
139
|
136
|
pop = pop8;
|
140
|
137
|
push = push8;
|
141
|
138
|
peek = peek8;
|
142
|
139
|
poke = poke8;
|
143
|
140
|
devr = devr8;
|
|
141
|
+ devw = devw8;
|
144
|
142
|
warp = warp8;
|
|
143
|
+ pull = pull8;
|
145
|
144
|
}
|
146
|
|
- (*ops[(instr & 0x1f) | ((instr & MODE_SHORT) >> 1)])(u);
|
|
145
|
+ (*ops[instr & 0x1f])(u);
|
147
|
146
|
if(u->wst.error)
|
148
|
147
|
return uxn_halt(u, u->wst.error, "Working-stack", instr);
|
149
|
148
|
if(u->rst.error)
|