...
|
...
|
@@ -27,23 +27,24 @@ 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
|
29
|
static Uint16 (*devr)(Device *d, Uint8 a);
|
|
30
|
+static void (*warp)(Uxn *u, Uint16 a);
|
30
|
31
|
|
31
|
32
|
static void push8(Stack *s, Uint16 a) { if(s->ptr == 0xff) { s->error = 2; return; } s->dat[s->ptr++] = a; }
|
32
|
33
|
static Uint16 pop8_keep(Stack *s) { if(s->kptr == 0) { s->error = 1; return 0; } return s->dat[--s->kptr]; }
|
33
|
34
|
static Uint16 pop8_nokeep(Stack *s) { if(s->ptr == 0) { s->error = 1; return 0; } return s->dat[--s->ptr]; }
|
34
|
|
-
|
35
|
35
|
static void poke8(Uint8 *m, Uint16 a, Uint16 b) { m[a] = b; }
|
36
|
36
|
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); }
|
|
38
|
+static Uint16 devr8(Device *d, Uint8 a) { d->talk(d, a & 0x0f, 0); return d->dat[a & 0xf]; }
|
|
39
|
+static void warp8(Uxn *u, Uint16 a){ u->ram.ptr += (Sint8)a; }
|
|
40
|
+
|
37
|
41
|
void poke16(Uint8 *m, Uint16 a, Uint16 b) { poke8(m, a, b >> 8); poke8(m, a + 1, b); }
|
38
|
42
|
Uint16 peek16(Uint8 *m, Uint16 a) { return (peek8(m, a) << 8) + peek8(m, a + 1); }
|
39
|
|
-
|
40
|
43
|
static void push16(Stack *s, Uint16 a) { push8(s, a >> 8); push8(s, a); }
|
41
|
44
|
static Uint16 pop16(Stack *s) { Uint8 a = pop8(s), b = pop8(s); return a + (b << 8); }
|
42
|
|
-
|
43
|
|
-static void devw8(Device *d, Uint8 a, Uint8 b) { d->dat[a & 0xf] = b; d->talk(d, a & 0x0f, 1); }
|
44
|
|
-static Uint16 devr8(Device *d, Uint8 a) { d->talk(d, a & 0x0f, 0); return d->dat[a & 0xf]; }
|
45
|
45
|
static void devw16(Device *d, Uint8 a, Uint16 b) { devw8(d, a, b >> 8); devw8(d, a + 1, b); }
|
46
|
46
|
static Uint16 devr16(Device *d, Uint8 a) { return (devr8(d, a) << 8) + devr8(d, a + 1); }
|
|
47
|
+static void warp16(Uxn *u, Uint16 a){ u->ram.ptr = a; }
|
47
|
48
|
|
48
|
49
|
/* Stack */
|
49
|
50
|
static void op_lit(Uxn *u) { push8(u->src, peek8(u->ram.dat, u->ram.ptr++)); }
|
...
|
...
|
@@ -59,9 +60,9 @@ static void op_equ(Uxn *u) { Uint16 a = pop(u->src), b = pop(u->src); push8(u->s
|
59
|
60
|
static void op_neq(Uxn *u) { Uint16 a = pop(u->src), b = pop(u->src); push8(u->src, b != a); }
|
60
|
61
|
static void op_gth(Uxn *u) { Uint16 a = pop(u->src), b = pop(u->src); push8(u->src, b > a); }
|
61
|
62
|
static void op_lth(Uxn *u) { Uint16 a = pop(u->src), b = pop(u->src); push8(u->src, b < a); }
|
62
|
|
-static void op_jmp(Uxn *u) { Uint8 a = pop8(u->src); u->ram.ptr += (Sint8)a; }
|
63
|
|
-static void op_jnz(Uxn *u) { Uint8 a = pop8(u->src); if(pop8(u->src)) u->ram.ptr += (Sint8)a; }
|
64
|
|
-static void op_jsr(Uxn *u) { Uint8 a = pop8(u->src); push16(u->dst, u->ram.ptr); u->ram.ptr += (Sint8)a; }
|
|
63
|
+static void op_jmp(Uxn *u) { Uint16 a = pop(u->src); warp(u, a); }
|
|
64
|
+static void op_jnz(Uxn *u) { Uint16 a = pop(u->src); if(pop8(u->src)) warp(u, a); }
|
|
65
|
+static void op_jsr(Uxn *u) { Uint16 a = pop(u->src); push16(u->dst, u->ram.ptr); warp(u, a); }
|
65
|
66
|
static void op_sth(Uxn *u) { Uint16 a = pop(u->src); push(u->dst, a); }
|
66
|
67
|
/* Memory */
|
67
|
68
|
static void op_ldz(Uxn *u) { Uint8 a = pop8(u->src); push(u->src, peek(u->ram.dat, a)); }
|
...
|
...
|
@@ -83,10 +84,6 @@ static void op_eor(Uxn *u) { Uint16 a = pop(u->src), b = pop(u->src); push(u->sr
|
83
|
84
|
static void op_sft(Uxn *u) { Uint16 a = pop8(u->src), b = pop(u->src); push(u->src, b >> (a & 0x07) << ((a & 0x70) >> 4)); }
|
84
|
85
|
/* Stack(16-bits) */
|
85
|
86
|
static void op_lit16(Uxn *u) { push16(u->src, peek16(u->ram.dat, u->ram.ptr++)); u->ram.ptr++; }
|
86
|
|
-/* Logic(16-bits) */
|
87
|
|
-static void op_jmp16(Uxn *u) { u->ram.ptr = pop16(u->src); }
|
88
|
|
-static void op_jnz16(Uxn *u) { Uint16 a = pop16(u->src); if(pop8(u->src)) u->ram.ptr = a; }
|
89
|
|
-static void op_jsr16(Uxn *u) { push16(u->dst, u->ram.ptr); u->ram.ptr = pop16(u->src); }
|
90
|
87
|
/* Memory(16-bits) */
|
91
|
88
|
static void op_deo16(Uxn *u) { Uint8 a = pop8(u->src); Uint16 b = pop16(u->src); devw16(&u->dev[a >> 4], a, b); }
|
92
|
89
|
|
...
|
...
|
@@ -97,7 +94,7 @@ static void (*ops[])(Uxn *u) = {
|
97
|
94
|
op_add, op_sub, op_mul, op_div, op_and, op_ora, op_eor, op_sft,
|
98
|
95
|
/* 16-bit */
|
99
|
96
|
op_lit16, op_inc, op_pop, op_dup, op_nip, op_swp, op_ovr, op_rot,
|
100
|
|
- op_equ, op_neq, op_gth, op_lth, op_jmp16, op_jnz16, op_jsr16, op_sth,
|
|
97
|
+ op_equ, op_neq, op_gth, op_lth, op_jmp, op_jnz, op_jsr, op_sth,
|
101
|
98
|
op_ldz, op_stz, op_ldr, op_str, op_lda, op_sta, op_dei, op_deo16,
|
102
|
99
|
op_add, op_sub, op_mul, op_div, op_and, op_ora, op_eor, op_sft
|
103
|
100
|
};
|
...
|
...
|
@@ -137,12 +134,14 @@ uxn_eval(Uxn *u, Uint16 vec)
|
137
|
134
|
peek = peek16;
|
138
|
135
|
poke = poke16;
|
139
|
136
|
devr = devr16;
|
|
137
|
+ warp = warp16;
|
140
|
138
|
} else {
|
141
|
139
|
pop = pop8;
|
142
|
140
|
push = push8;
|
143
|
141
|
peek = peek8;
|
144
|
142
|
poke = poke8;
|
145
|
143
|
devr = devr8;
|
|
144
|
+ warp = warp8;
|
146
|
145
|
}
|
147
|
146
|
(*ops[(instr & 0x1f) | ((instr & MODE_SHORT) >> 1)])(u);
|
148
|
147
|
if(u->wst.error)
|