diff options
author | Bad Diode <bd@badd10de.dev> | 2021-05-22 22:14:51 +0200 |
---|---|---|
committer | Bad Diode <bd@badd10de.dev> | 2021-05-22 22:14:51 +0200 |
commit | 2e5e4955337dccc370ed72d0f4fc561abadf84f4 (patch) | |
tree | ade3fa5709bd5551092ba63ad95f5ed6f175087c /src | |
parent | 3924524adf85914bbdb77f002d5443597ef154d8 (diff) | |
download | uxngba-2e5e4955337dccc370ed72d0f4fc561abadf84f4.tar.gz uxngba-2e5e4955337dccc370ed72d0f4fc561abadf84f4.zip |
Update uxn opcodes with alderwick's performance improvements
Diffstat (limited to 'src')
-rw-r--r-- | src/uxn/opcodes.c | 315 | ||||
-rw-r--r-- | src/uxn/uxn.c | 3858 | ||||
-rw-r--r-- | src/uxn/uxn.h | 4 |
3 files changed, 3734 insertions, 443 deletions
diff --git a/src/uxn/opcodes.c b/src/uxn/opcodes.c deleted file mode 100644 index f80cd79..0000000 --- a/src/uxn/opcodes.c +++ /dev/null | |||
@@ -1,315 +0,0 @@ | |||
1 | /* | ||
2 | Copyright (u) 2021 Devine Lu Linvega | ||
3 | Copyright (c) 2021 Adrian "asie" Siekierka | ||
4 | |||
5 | Permission to use, copy, modify, and distribute this software for any | ||
6 | purpose with or without fee is hereby granted, provided that the above | ||
7 | copyright notice and this permission notice appear in all copies. | ||
8 | |||
9 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
10 | WITH REGARD TO THIS SOFTWARE. | ||
11 | */ | ||
12 | |||
13 | /* 8-BIT OPCODES */ | ||
14 | |||
15 | case UXN_OPC(0x00): | ||
16 | case UXN_OPC(0x20): { // brk | ||
17 | u->ram.ptr = 0; | ||
18 | } break; | ||
19 | case UXN_OPC(0x01): { // lit | ||
20 | push8(u->src, mempeek8(u->ram.dat, u->ram.ptr++)); | ||
21 | } break; | ||
22 | case UXN_OPC(0x02): | ||
23 | case UXN_OPC(0x22): { // nop | ||
24 | } break; | ||
25 | case UXN_OPC(0x03): { // pop | ||
26 | pop8(u->src); | ||
27 | } break; | ||
28 | case UXN_OPC(0x04): { // dup | ||
29 | Uint8 a = pop8(u->src); | ||
30 | push8(u->src, a); | ||
31 | push8(u->src, a); | ||
32 | } break; | ||
33 | case UXN_OPC(0x05): { // swp | ||
34 | Uint8 a = pop8(u->src); | ||
35 | Uint8 b = pop8(u->src); | ||
36 | push8(u->src, a); | ||
37 | push8(u->src, b); | ||
38 | } break; | ||
39 | case UXN_OPC(0x06): { // ovr | ||
40 | Uint8 a = pop8(u->src); | ||
41 | Uint8 b = pop8(u->src); | ||
42 | push8(u->src, b); | ||
43 | push8(u->src, a); | ||
44 | push8(u->src, b); | ||
45 | } break; | ||
46 | case UXN_OPC(0x07): { // rot | ||
47 | Uint8 a = pop8(u->src); | ||
48 | Uint8 b = pop8(u->src); | ||
49 | Uint8 c = pop8(u->src); | ||
50 | push8(u->src, b); | ||
51 | push8(u->src, a); | ||
52 | push8(u->src, c); | ||
53 | } break; | ||
54 | case UXN_OPC(0x08): { // equ | ||
55 | Uint8 a = pop8(u->src); | ||
56 | Uint8 b = pop8(u->src); | ||
57 | push8(u->src, b == a); | ||
58 | } break; | ||
59 | case UXN_OPC(0x09): { // neg | ||
60 | Uint8 a = pop8(u->src); | ||
61 | Uint8 b = pop8(u->src); | ||
62 | push8(u->src, b != a); | ||
63 | } break; | ||
64 | case UXN_OPC(0x0A): { // gth | ||
65 | Uint8 a = pop8(u->src); | ||
66 | Uint8 b = pop8(u->src); | ||
67 | push8(u->src, b > a); | ||
68 | } break; | ||
69 | case UXN_OPC(0x0B): { // lth | ||
70 | Uint8 a = pop8(u->src); | ||
71 | Uint8 b = pop8(u->src); | ||
72 | push8(u->src, b < a); | ||
73 | } break; | ||
74 | case UXN_OPC(0x0C): { // jmp | ||
75 | Uint8 a = pop8(u->src); | ||
76 | u->ram.ptr += (Sint8)a; | ||
77 | } break; | ||
78 | case UXN_OPC(0x0D): { // jnz | ||
79 | Uint8 a = pop8(u->src); | ||
80 | if (pop8(u->src)) | ||
81 | u->ram.ptr += (Sint8)a; | ||
82 | } break; | ||
83 | case UXN_OPC(0x0E): { // jsr | ||
84 | Uint8 a = pop8(u->src); | ||
85 | push16(u->dst, u->ram.ptr); | ||
86 | u->ram.ptr += (Sint8)a; | ||
87 | } break; | ||
88 | case UXN_OPC(0x0F): { // sth | ||
89 | Uint8 a = pop8(u->src); | ||
90 | push8(u->dst, a); | ||
91 | } break; | ||
92 | case UXN_OPC(0x10): { // pek | ||
93 | Uint8 a = pop8(u->src); | ||
94 | push8(u->src, mempeek8(u->ram.dat, a)); | ||
95 | } break; | ||
96 | case UXN_OPC(0x11): { // pok | ||
97 | Uint8 a = pop8(u->src); | ||
98 | Uint8 b = pop8(u->src); | ||
99 | mempoke8(u->ram.dat, a, b); | ||
100 | } break; | ||
101 | case UXN_OPC(0x12): { // ldr | ||
102 | Uint8 a = pop8(u->src); | ||
103 | push8(u->src, mempeek8(u->ram.dat, u->ram.ptr + (Sint8)a)); | ||
104 | } break; | ||
105 | case UXN_OPC(0x13): { // str | ||
106 | Uint8 a = pop8(u->src); | ||
107 | Uint8 b = pop8(u->src); | ||
108 | mempoke8(u->ram.dat, u->ram.ptr + (Sint8)a, b); | ||
109 | } break; | ||
110 | case UXN_OPC(0x14): { // lda | ||
111 | Uint16 a = pop16(u->src); | ||
112 | push8(u->src, mempeek8(u->ram.dat, a)); | ||
113 | } break; | ||
114 | case UXN_OPC(0x15): { // sta | ||
115 | Uint16 a = pop16(u->src); | ||
116 | Uint8 b = pop8(u->src); | ||
117 | mempoke8(u->ram.dat, a, b); | ||
118 | } break; | ||
119 | case UXN_OPC(0x16): { // dei | ||
120 | Uint8 a = pop8(u->src); | ||
121 | push8(u->src, devpeek8(&u->dev[a >> 4], a)); | ||
122 | } break; | ||
123 | case UXN_OPC(0x17): { // deo | ||
124 | Uint8 a = pop8(u->src); | ||
125 | Uint8 b = pop8(u->src); | ||
126 | devpoke8(&u->dev[a >> 4], a, b); | ||
127 | } break; | ||
128 | case UXN_OPC(0x18): { // add | ||
129 | Uint8 a = pop8(u->src); | ||
130 | Uint8 b = pop8(u->src); | ||
131 | push8(u->src, b + a); | ||
132 | } break; | ||
133 | case UXN_OPC(0x19): { // sub | ||
134 | Uint8 a = pop8(u->src); | ||
135 | Uint8 b = pop8(u->src); | ||
136 | push8(u->src, b - a); | ||
137 | } break; | ||
138 | case UXN_OPC(0x1A): { // mul | ||
139 | Uint8 a = pop8(u->src); | ||
140 | Uint8 b = pop8(u->src); | ||
141 | push8(u->src, b * a); | ||
142 | } break; | ||
143 | case UXN_OPC(0x1B): { // div | ||
144 | Uint8 a = pop8(u->src); | ||
145 | Uint8 b = pop8(u->src); | ||
146 | push8(u->src, b / a); | ||
147 | } break; | ||
148 | case UXN_OPC(0x1C): { // and | ||
149 | Uint8 a = pop8(u->src); | ||
150 | Uint8 b = pop8(u->src); | ||
151 | push8(u->src, b & a); | ||
152 | } break; | ||
153 | case UXN_OPC(0x1D): { // ora | ||
154 | Uint8 a = pop8(u->src); | ||
155 | Uint8 b = pop8(u->src); | ||
156 | push8(u->src, b | a); | ||
157 | } break; | ||
158 | case UXN_OPC(0x1E): { // eor | ||
159 | Uint8 a = pop8(u->src); | ||
160 | Uint8 b = pop8(u->src); | ||
161 | push8(u->src, b ^ a); | ||
162 | } break; | ||
163 | case UXN_OPC(0x1F): { // sft | ||
164 | Uint8 a = pop8(u->src); | ||
165 | Uint8 b = pop8(u->src); | ||
166 | push8(u->src, b >> (a & 0x07) << ((a & 0x70) >> 4)); | ||
167 | } break; | ||
168 | |||
169 | /* 16-BIT OPCODES */ | ||
170 | |||
171 | case UXN_OPC(0x21): { // lit | ||
172 | push16(u->src, mempeek16_i(u->ram.dat, u->ram.ptr)); | ||
173 | u->ram.ptr += 2; | ||
174 | } break; | ||
175 | case UXN_OPC(0x23): { // pop | ||
176 | pop16(u->src); | ||
177 | } break; | ||
178 | case UXN_OPC(0x24): { // dup | ||
179 | Uint16 a = pop16(u->src); | ||
180 | push16(u->src, a); | ||
181 | push16(u->src, a); | ||
182 | } break; | ||
183 | case UXN_OPC(0x25): { // swp | ||
184 | Uint16 a = pop16(u->src); | ||
185 | Uint16 b = pop16(u->src); | ||
186 | push16(u->src, a); | ||
187 | push16(u->src, b); | ||
188 | } break; | ||
189 | case UXN_OPC(0x26): { // ovr | ||
190 | Uint16 a = pop16(u->src); | ||
191 | Uint16 b = pop16(u->src); | ||
192 | push16(u->src, b); | ||
193 | push16(u->src, a); | ||
194 | push16(u->src, b); | ||
195 | } break; | ||
196 | case UXN_OPC(0x27): { // rot | ||
197 | Uint16 a = pop16(u->src); | ||
198 | Uint16 b = pop16(u->src); | ||
199 | Uint16 c = pop16(u->src); | ||
200 | push16(u->src, b); | ||
201 | push16(u->src, a); | ||
202 | push16(u->src, c); | ||
203 | } break; | ||
204 | case UXN_OPC(0x28): { // equ | ||
205 | Uint16 a = pop16(u->src); | ||
206 | Uint16 b = pop16(u->src); | ||
207 | push8(u->src, b == a); | ||
208 | } break; | ||
209 | case UXN_OPC(0x29): { // neg | ||
210 | Uint16 a = pop16(u->src); | ||
211 | Uint16 b = pop16(u->src); | ||
212 | push8(u->src, b != a); | ||
213 | } break; | ||
214 | case UXN_OPC(0x2A): { // gth | ||
215 | Uint16 a = pop16(u->src); | ||
216 | Uint16 b = pop16(u->src); | ||
217 | push8(u->src, b > a); | ||
218 | } break; | ||
219 | case UXN_OPC(0x2B): { // lth | ||
220 | Uint16 a = pop16(u->src); | ||
221 | Uint16 b = pop16(u->src); | ||
222 | push8(u->src, b < a); | ||
223 | } break; | ||
224 | case UXN_OPC(0x2C): { // jmp | ||
225 | u->ram.ptr = pop16(u->src); | ||
226 | } break; | ||
227 | case UXN_OPC(0x2D): { // jnz | ||
228 | Uint16 a = pop16(u->src); | ||
229 | if (pop8(u->src)) | ||
230 | u->ram.ptr = a; | ||
231 | } break; | ||
232 | case UXN_OPC(0x2E): { // jsr | ||
233 | push16(u->dst, u->ram.ptr); | ||
234 | u->ram.ptr = pop16(u->src); | ||
235 | } break; | ||
236 | case UXN_OPC(0x2F): { // sth | ||
237 | Uint16 a = pop16(u->src); | ||
238 | push16(u->dst, a); | ||
239 | } break; | ||
240 | case UXN_OPC(0x30): { // pek | ||
241 | Uint8 a = pop8(u->src); | ||
242 | push16(u->src, mempeek16_i(u->ram.dat, a)); | ||
243 | } break; | ||
244 | case UXN_OPC(0x31): { // pok | ||
245 | Uint8 a = pop8(u->src); | ||
246 | Uint16 b = pop16(u->src); | ||
247 | mempoke16_i(u->ram.dat, a, b); | ||
248 | } break; | ||
249 | case UXN_OPC(0x32): { // ldr | ||
250 | Uint8 a = pop8(u->src); | ||
251 | push16(u->src, mempeek16_i(u->ram.dat, u->ram.ptr + (Sint8)a)); | ||
252 | } break; | ||
253 | case UXN_OPC(0x33): { // str | ||
254 | Uint8 a = pop8(u->src); | ||
255 | Uint16 b = pop16(u->src); | ||
256 | mempoke16_i(u->ram.dat, u->ram.ptr + (Sint8)a, b); | ||
257 | } break; | ||
258 | case UXN_OPC(0x34): { // lda | ||
259 | Uint16 a = pop16(u->src); | ||
260 | push16(u->src, mempeek16_i(u->ram.dat, a)); | ||
261 | } break; | ||
262 | case UXN_OPC(0x35): { // sta | ||
263 | Uint16 a = pop16(u->src); | ||
264 | Uint16 b = pop16(u->src); | ||
265 | mempoke16_i(u->ram.dat, a, b); | ||
266 | } break; | ||
267 | case UXN_OPC(0x36): { // dei | ||
268 | Uint8 a = pop8(u->src); | ||
269 | push16(u->src, devpeek16(&u->dev[a >> 4], a)); | ||
270 | } break; | ||
271 | case UXN_OPC(0x37): { // deo | ||
272 | Uint8 a = pop8(u->src); | ||
273 | Uint16 b = pop16(u->src); | ||
274 | devpoke16(&u->dev[a >> 4], a, b); | ||
275 | } break; | ||
276 | case UXN_OPC(0x38): { // add | ||
277 | Uint16 a = pop16(u->src); | ||
278 | Uint16 b = pop16(u->src); | ||
279 | push16(u->src, b + a); | ||
280 | } break; | ||
281 | case UXN_OPC(0x39): { // sub | ||
282 | Uint16 a = pop16(u->src); | ||
283 | Uint16 b = pop16(u->src); | ||
284 | push16(u->src, b - a); | ||
285 | } break; | ||
286 | case UXN_OPC(0x3A): { // mul | ||
287 | Uint16 a = pop16(u->src); | ||
288 | Uint16 b = pop16(u->src); | ||
289 | push16(u->src, b * a); | ||
290 | } break; | ||
291 | case UXN_OPC(0x3B): { // div | ||
292 | Uint16 a = pop16(u->src); | ||
293 | Uint16 b = pop16(u->src); | ||
294 | push16(u->src, b / a); | ||
295 | } break; | ||
296 | case UXN_OPC(0x3C): { // and | ||
297 | Uint16 a = pop16(u->src); | ||
298 | Uint16 b = pop16(u->src); | ||
299 | push16(u->src, b & a); | ||
300 | } break; | ||
301 | case UXN_OPC(0x3D): { // ora | ||
302 | Uint16 a = pop16(u->src); | ||
303 | Uint16 b = pop16(u->src); | ||
304 | push16(u->src, b | a); | ||
305 | } break; | ||
306 | case UXN_OPC(0x3E): { // eor | ||
307 | Uint16 a = pop16(u->src); | ||
308 | Uint16 b = pop16(u->src); | ||
309 | push16(u->src, b ^ a); | ||
310 | } break; | ||
311 | case UXN_OPC(0x3F): { // sft | ||
312 | Uint16 a = pop16(u->src); | ||
313 | Uint16 b = pop16(u->src); | ||
314 | push16(u->src, b >> (a & 0x000f) << ((a & 0x00f0) >> 4)); | ||
315 | } break; | ||
diff --git a/src/uxn/uxn.c b/src/uxn/uxn.c index 53f7983..8ae5586 100644 --- a/src/uxn/uxn.c +++ b/src/uxn/uxn.c | |||
@@ -1,9 +1,11 @@ | |||
1 | #include <stdio.h> | 1 | #include <stdio.h> |
2 | #include "uxn.h" | 2 | #include "uxn.h" |
3 | 3 | ||
4 | #define NO_STACK_CHECKS | ||
5 | |||
4 | /* | 6 | /* |
5 | Copyright (u) 2021 Devine Lu Linvega | 7 | Copyright (u) 2021 Devine Lu Linvega |
6 | Copyright (u) 2021 Adrian Siekierka | 8 | Copyright (u) 2021 Andrew Alderwick |
7 | 9 | ||
8 | Permission to use, copy, modify, and distribute this software for any | 10 | Permission to use, copy, modify, and distribute this software for any |
9 | purpose with or without fee is hereby granted, provided that the above | 11 | purpose with or without fee is hereby granted, provided that the above |
@@ -13,142 +15,3743 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |||
13 | WITH REGARD TO THIS SOFTWARE. | 15 | WITH REGARD TO THIS SOFTWARE. |
14 | */ | 16 | */ |
15 | 17 | ||
16 | /* clang-format off */ | 18 | IWRAM_CODE |
17 | |||
18 | static inline void push8(Stack *s, Uint8 a) { | ||
19 | s->dat[s->ptr++] = a; | ||
20 | } | ||
21 | static inline Uint8 pop8_keep(Stack *s) { | ||
22 | return s->dat[--s->kptr]; | ||
23 | } | ||
24 | static inline Uint8 pop8_nokeep(Stack *s) { | ||
25 | return s->dat[--s->ptr]; | ||
26 | } | ||
27 | static inline void devpoke8(Device *d, Uint8 a, Uint8 b) { d->dat[a & 0xf] = b; d->talk(d, a & 0x0f, 1); } | ||
28 | static inline Uint8 devpeek8(Device *d, Uint8 a) { d->talk(d, a & 0x0f, 0); return d->dat[a & 0xf]; } | ||
29 | static inline void push16(Stack *s, Uint16 a) { push8(s, a >> 8); push8(s, a); } | ||
30 | static inline void devpoke16(Device *d, Uint8 a, Uint16 b) { devpoke8(d, a, b >> 8); devpoke8(d, a + 1, b); } | ||
31 | static inline Uint16 devpeek16(Device *d, Uint16 a) { return (devpeek8(d, a) << 8) + devpeek8(d, a + 1); } | ||
32 | |||
33 | /* clang-format on */ | ||
34 | |||
35 | #pragma mark - Core | ||
36 | |||
37 | int | 19 | int |
38 | haltuxn(Uxn *u, char *name, int id) | 20 | evaluxn(Uxn *u, Uint16 vec) |
39 | { | 21 | { |
40 | // txt_printf("Halted: %s#%04x, at 0x%04x\n", name, id, u->ram.ptr); | 22 | Uint8 instr; |
41 | u->ram.ptr = 0; | 23 | u->ram.ptr = vec; |
24 | while(u->ram.ptr) { | ||
25 | instr = u->ram.dat[u->ram.ptr++]; | ||
26 | switch(instr) { | ||
27 | #pragma GCC diagnostic push | ||
28 | #pragma GCC diagnostic ignored "-Wunused-value" | ||
29 | case 0x00: /* BRK */ | ||
30 | case 0x20: /* BRK2 */ | ||
31 | case 0x40: /* BRKr */ | ||
32 | case 0x60: /* BRK2r */ | ||
33 | case 0x80: /* BRKk */ | ||
34 | case 0xa0: /* BRK2k */ | ||
35 | case 0xc0: /* BRKkr */ | ||
36 | case 0xe0: /* BRK2kr */ | ||
37 | { | ||
38 | u->ram.ptr = 0; | ||
39 | break; | ||
40 | } | ||
41 | case 0x01: /* LIT */ | ||
42 | case 0x81: /* LITk */ | ||
43 | { | ||
44 | u->wst.dat[u->wst.ptr] = mempeek8(u->ram.dat, u->ram.ptr++); | ||
45 | #ifndef NO_STACK_CHECKS | ||
46 | if(u->wst.ptr > 254) { | ||
47 | u->wst.error = 2; | ||
48 | goto error; | ||
49 | } | ||
50 | #endif | ||
51 | u->wst.ptr += 1; | ||
52 | break; | ||
53 | } | ||
54 | case 0x02: /* NOP */ | ||
55 | case 0x22: /* NOP2 */ | ||
56 | case 0x42: /* NOPr */ | ||
57 | case 0x62: /* NOP2r */ | ||
58 | case 0x82: /* NOPk */ | ||
59 | case 0xa2: /* NOP2k */ | ||
60 | case 0xc2: /* NOPkr */ | ||
61 | case 0xe2: /* NOP2kr */ | ||
62 | { | ||
63 | (void)u; | ||
64 | break; | ||
65 | } | ||
66 | case 0x03: /* POP */ | ||
67 | { | ||
68 | u->wst.dat[u->wst.ptr - 1]; | ||
69 | #ifndef NO_STACK_CHECKS | ||
70 | if(u->wst.ptr < 1) { | ||
71 | u->wst.error = 1; | ||
72 | goto error; | ||
73 | } | ||
74 | #endif | ||
75 | u->wst.ptr -= 1; | ||
76 | break; | ||
77 | } | ||
78 | case 0x04: /* DUP */ | ||
79 | { | ||
80 | Uint8 a = u->wst.dat[u->wst.ptr - 1]; | ||
81 | u->wst.dat[u->wst.ptr - 1] = a; | ||
82 | u->wst.dat[u->wst.ptr] = a; | ||
83 | #ifndef NO_STACK_CHECKS | ||
84 | if(u->wst.ptr < 1) { | ||
85 | u->wst.error = 1; | ||
86 | goto error; | ||
87 | } | ||
88 | if(u->wst.ptr > 254) { | ||
89 | u->wst.error = 2; | ||
90 | goto error; | ||
91 | } | ||
92 | #endif | ||
93 | u->wst.ptr += 1; | ||
94 | break; | ||
95 | } | ||
96 | case 0x05: /* SWP */ | ||
97 | { | ||
98 | Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; | ||
99 | u->wst.dat[u->wst.ptr - 2] = a; | ||
100 | u->wst.dat[u->wst.ptr - 1] = b; | ||
101 | #ifndef NO_STACK_CHECKS | ||
102 | if(u->wst.ptr < 2) { | ||
103 | u->wst.error = 1; | ||
104 | goto error; | ||
105 | } | ||
106 | #endif | ||
107 | break; | ||
108 | } | ||
109 | case 0x06: /* OVR */ | ||
110 | { | ||
111 | Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; | ||
112 | u->wst.dat[u->wst.ptr - 2] = b; | ||
113 | u->wst.dat[u->wst.ptr - 1] = a; | ||
114 | u->wst.dat[u->wst.ptr] = b; | ||
115 | #ifndef NO_STACK_CHECKS | ||
116 | if(u->wst.ptr < 2) { | ||
117 | u->wst.error = 1; | ||
118 | goto error; | ||
119 | } | ||
120 | if(u->wst.ptr > 254) { | ||
121 | u->wst.error = 2; | ||
122 | goto error; | ||
123 | } | ||
124 | #endif | ||
125 | u->wst.ptr += 1; | ||
126 | break; | ||
127 | } | ||
128 | case 0x07: /* ROT */ | ||
129 | { | ||
130 | Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2], c = u->wst.dat[u->wst.ptr - 3]; | ||
131 | u->wst.dat[u->wst.ptr - 3] = b; | ||
132 | u->wst.dat[u->wst.ptr - 2] = a; | ||
133 | u->wst.dat[u->wst.ptr - 1] = c; | ||
134 | #ifndef NO_STACK_CHECKS | ||
135 | if(u->wst.ptr < 3) { | ||
136 | u->wst.error = 1; | ||
137 | goto error; | ||
138 | } | ||
139 | #endif | ||
140 | break; | ||
141 | } | ||
142 | case 0x08: /* EQU */ | ||
143 | { | ||
144 | Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; | ||
145 | u->wst.dat[u->wst.ptr - 2] = b == a; | ||
146 | #ifndef NO_STACK_CHECKS | ||
147 | if(u->wst.ptr < 2) { | ||
148 | u->wst.error = 1; | ||
149 | goto error; | ||
150 | } | ||
151 | #endif | ||
152 | u->wst.ptr -= 1; | ||
153 | break; | ||
154 | } | ||
155 | case 0x09: /* NEQ */ | ||
156 | { | ||
157 | Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; | ||
158 | u->wst.dat[u->wst.ptr - 2] = b != a; | ||
159 | #ifndef NO_STACK_CHECKS | ||
160 | if(u->wst.ptr < 2) { | ||
161 | u->wst.error = 1; | ||
162 | goto error; | ||
163 | } | ||
164 | #endif | ||
165 | u->wst.ptr -= 1; | ||
166 | break; | ||
167 | } | ||
168 | case 0x0a: /* GTH */ | ||
169 | { | ||
170 | Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; | ||
171 | u->wst.dat[u->wst.ptr - 2] = b > a; | ||
172 | #ifndef NO_STACK_CHECKS | ||
173 | if(u->wst.ptr < 2) { | ||
174 | u->wst.error = 1; | ||
175 | goto error; | ||
176 | } | ||
177 | #endif | ||
178 | u->wst.ptr -= 1; | ||
179 | break; | ||
180 | } | ||
181 | case 0x0b: /* LTH */ | ||
182 | { | ||
183 | Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; | ||
184 | u->wst.dat[u->wst.ptr - 2] = b < a; | ||
185 | #ifndef NO_STACK_CHECKS | ||
186 | if(u->wst.ptr < 2) { | ||
187 | u->wst.error = 1; | ||
188 | goto error; | ||
189 | } | ||
190 | #endif | ||
191 | u->wst.ptr -= 1; | ||
192 | break; | ||
193 | } | ||
194 | case 0x0c: /* JMP */ | ||
195 | { | ||
196 | Uint8 a = u->wst.dat[u->wst.ptr - 1]; | ||
197 | u->ram.ptr += (Sint8)a; | ||
198 | #ifndef NO_STACK_CHECKS | ||
199 | if(u->wst.ptr < 1) { | ||
200 | u->wst.error = 1; | ||
201 | goto error; | ||
202 | } | ||
203 | #endif | ||
204 | u->wst.ptr -= 1; | ||
205 | break; | ||
206 | } | ||
207 | case 0x0d: /* JCN */ | ||
208 | { | ||
209 | Uint8 a = u->wst.dat[u->wst.ptr - 1]; | ||
210 | if(u->wst.dat[u->wst.ptr - 2]) u->ram.ptr += (Sint8)a; | ||
211 | #ifndef NO_STACK_CHECKS | ||
212 | if(u->wst.ptr < 2) { | ||
213 | u->wst.error = 1; | ||
214 | goto error; | ||
215 | } | ||
216 | #endif | ||
217 | u->wst.ptr -= 2; | ||
218 | break; | ||
219 | } | ||
220 | case 0x0e: /* JSR */ | ||
221 | { | ||
222 | Uint8 a = u->wst.dat[u->wst.ptr - 1]; | ||
223 | u->rst.dat[u->rst.ptr] = u->ram.ptr >> 8; | ||
224 | u->rst.dat[u->rst.ptr + 1] = u->ram.ptr & 0xff; | ||
225 | u->ram.ptr += (Sint8)a; | ||
226 | #ifndef NO_STACK_CHECKS | ||
227 | if(u->wst.ptr < 1) { | ||
228 | u->wst.error = 1; | ||
229 | goto error; | ||
230 | } | ||
231 | #endif | ||
232 | u->wst.ptr -= 1; | ||
233 | #ifndef NO_STACK_CHECKS | ||
234 | if(u->rst.ptr > 253) { | ||
235 | u->rst.error = 2; | ||
236 | goto error; | ||
237 | } | ||
238 | #endif | ||
239 | u->rst.ptr += 2; | ||
240 | break; | ||
241 | } | ||
242 | case 0x0f: /* STH */ | ||
243 | { | ||
244 | Uint8 a = u->wst.dat[u->wst.ptr - 1]; | ||
245 | u->rst.dat[u->rst.ptr] = a; | ||
246 | #ifndef NO_STACK_CHECKS | ||
247 | if(u->wst.ptr < 1) { | ||
248 | u->wst.error = 1; | ||
249 | goto error; | ||
250 | } | ||
251 | #endif | ||
252 | u->wst.ptr -= 1; | ||
253 | #ifndef NO_STACK_CHECKS | ||
254 | if(u->rst.ptr > 254) { | ||
255 | u->rst.error = 2; | ||
256 | goto error; | ||
257 | } | ||
258 | #endif | ||
259 | u->rst.ptr += 1; | ||
260 | break; | ||
261 | } | ||
262 | case 0x10: /* LDZ */ | ||
263 | { | ||
264 | Uint8 a = u->wst.dat[u->wst.ptr - 1]; | ||
265 | u->wst.dat[u->wst.ptr - 1] = mempeek8(u->ram.dat, a); | ||
266 | #ifndef NO_STACK_CHECKS | ||
267 | if(u->wst.ptr < 1) { | ||
268 | u->wst.error = 1; | ||
269 | goto error; | ||
270 | } | ||
271 | #endif | ||
272 | break; | ||
273 | } | ||
274 | case 0x11: /* STZ */ | ||
275 | { | ||
276 | Uint8 a = u->wst.dat[u->wst.ptr - 1]; | ||
277 | Uint8 b = u->wst.dat[u->wst.ptr - 2]; | ||
278 | mempoke8(u->ram.dat, a, b); | ||
279 | #ifndef NO_STACK_CHECKS | ||
280 | if(u->wst.ptr < 2) { | ||
281 | u->wst.error = 1; | ||
282 | goto error; | ||
283 | } | ||
284 | #endif | ||
285 | u->wst.ptr -= 2; | ||
286 | break; | ||
287 | } | ||
288 | case 0x12: /* LDR */ | ||
289 | { | ||
290 | Uint8 a = u->wst.dat[u->wst.ptr - 1]; | ||
291 | u->wst.dat[u->wst.ptr - 1] = mempeek8(u->ram.dat, u->ram.ptr + (Sint8)a); | ||
292 | #ifndef NO_STACK_CHECKS | ||
293 | if(u->wst.ptr < 1) { | ||
294 | u->wst.error = 1; | ||
295 | goto error; | ||
296 | } | ||
297 | #endif | ||
298 | break; | ||
299 | } | ||
300 | case 0x13: /* STR */ | ||
301 | { | ||
302 | Uint8 a = u->wst.dat[u->wst.ptr - 1]; | ||
303 | Uint8 b = u->wst.dat[u->wst.ptr - 2]; | ||
304 | mempoke8(u->ram.dat, u->ram.ptr + (Sint8)a, b); | ||
305 | #ifndef NO_STACK_CHECKS | ||
306 | if(u->wst.ptr < 2) { | ||
307 | u->wst.error = 1; | ||
308 | goto error; | ||
309 | } | ||
310 | #endif | ||
311 | u->wst.ptr -= 2; | ||
312 | break; | ||
313 | } | ||
314 | case 0x14: /* LDA */ | ||
315 | { | ||
316 | Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)); | ||
317 | u->wst.dat[u->wst.ptr - 2] = mempeek8(u->ram.dat, a); | ||
318 | #ifndef NO_STACK_CHECKS | ||
319 | if(u->wst.ptr < 2) { | ||
320 | u->wst.error = 1; | ||
321 | goto error; | ||
322 | } | ||
323 | #endif | ||
324 | u->wst.ptr -= 1; | ||
325 | break; | ||
326 | } | ||
327 | case 0x15: /* STA */ | ||
328 | { | ||
329 | Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)); | ||
330 | Uint8 b = u->wst.dat[u->wst.ptr - 3]; | ||
331 | mempoke8(u->ram.dat, a, b); | ||
332 | #ifndef NO_STACK_CHECKS | ||
333 | if(u->wst.ptr < 3) { | ||
334 | u->wst.error = 1; | ||
335 | goto error; | ||
336 | } | ||
337 | #endif | ||
338 | u->wst.ptr -= 3; | ||
339 | break; | ||
340 | } | ||
341 | case 0x16: /* DEI */ | ||
342 | { | ||
343 | Uint8 a = u->wst.dat[u->wst.ptr - 1]; | ||
344 | u->wst.dat[u->wst.ptr - 1] = devpeek8(&u->dev[a >> 4], a); | ||
345 | #ifndef NO_STACK_CHECKS | ||
346 | if(u->wst.ptr < 1) { | ||
347 | u->wst.error = 1; | ||
348 | goto error; | ||
349 | } | ||
350 | #endif | ||
351 | break; | ||
352 | } | ||
353 | case 0x17: /* DEO */ | ||
354 | { | ||
355 | Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; | ||
356 | devpoke8(&u->dev[a >> 4], a, b); | ||
357 | #ifndef NO_STACK_CHECKS | ||
358 | if(u->wst.ptr < 2) { | ||
359 | u->wst.error = 1; | ||
360 | goto error; | ||
361 | } | ||
362 | #endif | ||
363 | u->wst.ptr -= 2; | ||
364 | break; | ||
365 | } | ||
366 | case 0x18: /* ADD */ | ||
367 | { | ||
368 | Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; | ||
369 | u->wst.dat[u->wst.ptr - 2] = b + a; | ||
370 | #ifndef NO_STACK_CHECKS | ||
371 | if(u->wst.ptr < 2) { | ||
372 | u->wst.error = 1; | ||
373 | goto error; | ||
374 | } | ||
375 | #endif | ||
376 | u->wst.ptr -= 1; | ||
377 | break; | ||
378 | } | ||
379 | case 0x19: /* SUB */ | ||
380 | { | ||
381 | Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; | ||
382 | u->wst.dat[u->wst.ptr - 2] = b - a; | ||
383 | #ifndef NO_STACK_CHECKS | ||
384 | if(u->wst.ptr < 2) { | ||
385 | u->wst.error = 1; | ||
386 | goto error; | ||
387 | } | ||
388 | #endif | ||
389 | u->wst.ptr -= 1; | ||
390 | break; | ||
391 | } | ||
392 | case 0x1a: /* MUL */ | ||
393 | { | ||
394 | Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; | ||
395 | u->wst.dat[u->wst.ptr - 2] = b * a; | ||
396 | #ifndef NO_STACK_CHECKS | ||
397 | if(u->wst.ptr < 2) { | ||
398 | u->wst.error = 1; | ||
399 | goto error; | ||
400 | } | ||
401 | #endif | ||
402 | u->wst.ptr -= 1; | ||
403 | break; | ||
404 | } | ||
405 | case 0x1b: /* DIV */ | ||
406 | { | ||
407 | Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; | ||
408 | u->wst.dat[u->wst.ptr - 2] = b / a; | ||
409 | #ifndef NO_STACK_CHECKS | ||
410 | if(u->wst.ptr < 2) { | ||
411 | u->wst.error = 1; | ||
412 | goto error; | ||
413 | } | ||
414 | #endif | ||
415 | u->wst.ptr -= 1; | ||
416 | break; | ||
417 | } | ||
418 | case 0x1c: /* AND */ | ||
419 | { | ||
420 | Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; | ||
421 | u->wst.dat[u->wst.ptr - 2] = b & a; | ||
422 | #ifndef NO_STACK_CHECKS | ||
423 | if(u->wst.ptr < 2) { | ||
424 | u->wst.error = 1; | ||
425 | goto error; | ||
426 | } | ||
427 | #endif | ||
428 | u->wst.ptr -= 1; | ||
429 | break; | ||
430 | } | ||
431 | case 0x1d: /* ORA */ | ||
432 | { | ||
433 | Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; | ||
434 | u->wst.dat[u->wst.ptr - 2] = b | a; | ||
435 | #ifndef NO_STACK_CHECKS | ||
436 | if(u->wst.ptr < 2) { | ||
437 | u->wst.error = 1; | ||
438 | goto error; | ||
439 | } | ||
440 | #endif | ||
441 | u->wst.ptr -= 1; | ||
442 | break; | ||
443 | } | ||
444 | case 0x1e: /* EOR */ | ||
445 | { | ||
446 | Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; | ||
447 | u->wst.dat[u->wst.ptr - 2] = b ^ a; | ||
448 | #ifndef NO_STACK_CHECKS | ||
449 | if(u->wst.ptr < 2) { | ||
450 | u->wst.error = 1; | ||
451 | goto error; | ||
452 | } | ||
453 | #endif | ||
454 | u->wst.ptr -= 1; | ||
455 | break; | ||
456 | } | ||
457 | case 0x1f: /* SFT */ | ||
458 | { | ||
459 | Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; | ||
460 | u->wst.dat[u->wst.ptr - 2] = b >> (a & 0x07) << ((a & 0x70) >> 4); | ||
461 | #ifndef NO_STACK_CHECKS | ||
462 | if(u->wst.ptr < 2) { | ||
463 | u->wst.error = 1; | ||
464 | goto error; | ||
465 | } | ||
466 | #endif | ||
467 | u->wst.ptr -= 1; | ||
468 | break; | ||
469 | } | ||
470 | case 0x21: /* LIT2 */ | ||
471 | case 0xa1: /* LIT2k */ | ||
472 | { | ||
473 | u->wst.dat[u->wst.ptr] = mempeek8(u->ram.dat, u->ram.ptr++); | ||
474 | u->wst.dat[u->wst.ptr + 1] = mempeek8(u->ram.dat, u->ram.ptr++); | ||
475 | #ifndef NO_STACK_CHECKS | ||
476 | if(u->wst.ptr > 253) { | ||
477 | u->wst.error = 2; | ||
478 | goto error; | ||
479 | } | ||
480 | #endif | ||
481 | u->wst.ptr += 2; | ||
482 | break; | ||
483 | } | ||
484 | case 0x23: /* POP2 */ | ||
485 | { | ||
486 | (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)); | ||
487 | #ifndef NO_STACK_CHECKS | ||
488 | if(u->wst.ptr < 2) { | ||
489 | u->wst.error = 1; | ||
490 | goto error; | ||
491 | } | ||
492 | #endif | ||
493 | u->wst.ptr -= 2; | ||
494 | break; | ||
495 | } | ||
496 | case 0x24: /* DUP2 */ | ||
497 | { | ||
498 | Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)); | ||
499 | u->wst.dat[u->wst.ptr - 2] = a >> 8; | ||
500 | u->wst.dat[u->wst.ptr - 1] = a & 0xff; | ||
501 | u->wst.dat[u->wst.ptr] = a >> 8; | ||
502 | u->wst.dat[u->wst.ptr + 1] = a & 0xff; | ||
503 | #ifndef NO_STACK_CHECKS | ||
504 | if(u->wst.ptr < 2) { | ||
505 | u->wst.error = 1; | ||
506 | goto error; | ||
507 | } | ||
508 | if(u->wst.ptr > 253) { | ||
509 | u->wst.error = 2; | ||
510 | goto error; | ||
511 | } | ||
512 | #endif | ||
513 | u->wst.ptr += 2; | ||
514 | break; | ||
515 | } | ||
516 | case 0x25: /* SWP2 */ | ||
517 | { | ||
518 | Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)), b = (u->wst.dat[u->wst.ptr - 3] | (u->wst.dat[u->wst.ptr - 4] << 8)); | ||
519 | u->wst.dat[u->wst.ptr - 4] = a >> 8; | ||
520 | u->wst.dat[u->wst.ptr - 3] = a & 0xff; | ||
521 | u->wst.dat[u->wst.ptr - 2] = b >> 8; | ||
522 | u->wst.dat[u->wst.ptr - 1] = b & 0xff; | ||
523 | #ifndef NO_STACK_CHECKS | ||
524 | if(u->wst.ptr < 4) { | ||
525 | u->wst.error = 1; | ||
526 | goto error; | ||
527 | } | ||
528 | #endif | ||
529 | break; | ||
530 | } | ||
531 | case 0x26: /* OVR2 */ | ||
532 | { | ||
533 | Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)), b = (u->wst.dat[u->wst.ptr - 3] | (u->wst.dat[u->wst.ptr - 4] << 8)); | ||
534 | u->wst.dat[u->wst.ptr - 4] = b >> 8; | ||
535 | u->wst.dat[u->wst.ptr - 3] = b & 0xff; | ||
536 | u->wst.dat[u->wst.ptr - 2] = a >> 8; | ||
537 | u->wst.dat[u->wst.ptr - 1] = a & 0xff; | ||
538 | u->wst.dat[u->wst.ptr] = b >> 8; | ||
539 | u->wst.dat[u->wst.ptr + 1] = b & 0xff; | ||
540 | #ifndef NO_STACK_CHECKS | ||
541 | if(u->wst.ptr < 4) { | ||
542 | u->wst.error = 1; | ||
543 | goto error; | ||
544 | } | ||
545 | if(u->wst.ptr > 253) { | ||
546 | u->wst.error = 2; | ||
547 | goto error; | ||
548 | } | ||
549 | #endif | ||
550 | u->wst.ptr += 2; | ||
551 | break; | ||
552 | } | ||
553 | case 0x27: /* ROT2 */ | ||
554 | { | ||
555 | Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)), b = (u->wst.dat[u->wst.ptr - 3] | (u->wst.dat[u->wst.ptr - 4] << 8)), c = (u->wst.dat[u->wst.ptr - 5] | (u->wst.dat[u->wst.ptr - 6] << 8)); | ||
556 | u->wst.dat[u->wst.ptr - 6] = b >> 8; | ||
557 | u->wst.dat[u->wst.ptr - 5] = b & 0xff; | ||
558 | u->wst.dat[u->wst.ptr - 4] = a >> 8; | ||
559 | u->wst.dat[u->wst.ptr - 3] = a & 0xff; | ||
560 | u->wst.dat[u->wst.ptr - 2] = c >> 8; | ||
561 | u->wst.dat[u->wst.ptr - 1] = c & 0xff; | ||
562 | #ifndef NO_STACK_CHECKS | ||
563 | if(u->wst.ptr < 6) { | ||
564 | u->wst.error = 1; | ||
565 | goto error; | ||
566 | } | ||
567 | #endif | ||
568 | break; | ||
569 | } | ||
570 | case 0x28: /* EQU2 */ | ||
571 | { | ||
572 | Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)), b = (u->wst.dat[u->wst.ptr - 3] | (u->wst.dat[u->wst.ptr - 4] << 8)); | ||
573 | u->wst.dat[u->wst.ptr - 4] = b == a; | ||
574 | #ifndef NO_STACK_CHECKS | ||
575 | if(u->wst.ptr < 4) { | ||
576 | u->wst.error = 1; | ||
577 | goto error; | ||
578 | } | ||
579 | #endif | ||
580 | u->wst.ptr -= 3; | ||
581 | break; | ||
582 | } | ||
583 | case 0x29: /* NEQ2 */ | ||
584 | { | ||
585 | Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)), b = (u->wst.dat[u->wst.ptr - 3] | (u->wst.dat[u->wst.ptr - 4] << 8)); | ||
586 | u->wst.dat[u->wst.ptr - 4] = b != a; | ||
587 | #ifndef NO_STACK_CHECKS | ||
588 | if(u->wst.ptr < 4) { | ||
589 | u->wst.error = 1; | ||
590 | goto error; | ||
591 | } | ||
592 | #endif | ||
593 | u->wst.ptr -= 3; | ||
594 | break; | ||
595 | } | ||
596 | case 0x2a: /* GTH2 */ | ||
597 | { | ||
598 | Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)), b = (u->wst.dat[u->wst.ptr - 3] | (u->wst.dat[u->wst.ptr - 4] << 8)); | ||
599 | u->wst.dat[u->wst.ptr - 4] = b > a; | ||
600 | #ifndef NO_STACK_CHECKS | ||
601 | if(u->wst.ptr < 4) { | ||
602 | u->wst.error = 1; | ||
603 | goto error; | ||
604 | } | ||
605 | #endif | ||
606 | u->wst.ptr -= 3; | ||
607 | break; | ||
608 | } | ||
609 | case 0x2b: /* LTH2 */ | ||
610 | { | ||
611 | Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)), b = (u->wst.dat[u->wst.ptr - 3] | (u->wst.dat[u->wst.ptr - 4] << 8)); | ||
612 | u->wst.dat[u->wst.ptr - 4] = b < a; | ||
613 | #ifndef NO_STACK_CHECKS | ||
614 | if(u->wst.ptr < 4) { | ||
615 | u->wst.error = 1; | ||
616 | goto error; | ||
617 | } | ||
618 | #endif | ||
619 | u->wst.ptr -= 3; | ||
620 | break; | ||
621 | } | ||
622 | case 0x2c: /* JMP2 */ | ||
623 | { | ||
624 | u->ram.ptr = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)); | ||
625 | #ifndef NO_STACK_CHECKS | ||
626 | if(u->wst.ptr < 2) { | ||
627 | u->wst.error = 1; | ||
628 | goto error; | ||
629 | } | ||
630 | #endif | ||
631 | u->wst.ptr -= 2; | ||
632 | break; | ||
633 | } | ||
634 | case 0x2d: /* JCN2 */ | ||
635 | { | ||
636 | Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)); | ||
637 | if(u->wst.dat[u->wst.ptr - 3]) u->ram.ptr = a; | ||
638 | #ifndef NO_STACK_CHECKS | ||
639 | if(u->wst.ptr < 3) { | ||
640 | u->wst.error = 1; | ||
641 | goto error; | ||
642 | } | ||
643 | #endif | ||
644 | u->wst.ptr -= 3; | ||
645 | break; | ||
646 | } | ||
647 | case 0x2e: /* JSR2 */ | ||
648 | { | ||
649 | u->rst.dat[u->rst.ptr] = u->ram.ptr >> 8; | ||
650 | u->rst.dat[u->rst.ptr + 1] = u->ram.ptr & 0xff; | ||
651 | u->ram.ptr = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)); | ||
652 | #ifndef NO_STACK_CHECKS | ||
653 | if(u->wst.ptr < 2) { | ||
654 | u->wst.error = 1; | ||
655 | goto error; | ||
656 | } | ||
657 | #endif | ||
658 | u->wst.ptr -= 2; | ||
659 | #ifndef NO_STACK_CHECKS | ||
660 | if(u->rst.ptr > 253) { | ||
661 | u->rst.error = 2; | ||
662 | goto error; | ||
663 | } | ||
664 | #endif | ||
665 | u->rst.ptr += 2; | ||
666 | break; | ||
667 | } | ||
668 | case 0x2f: /* STH2 */ | ||
669 | { | ||
670 | Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)); | ||
671 | u->rst.dat[u->rst.ptr] = a >> 8; | ||
672 | u->rst.dat[u->rst.ptr + 1] = a & 0xff; | ||
673 | #ifndef NO_STACK_CHECKS | ||
674 | if(u->wst.ptr < 2) { | ||
675 | u->wst.error = 1; | ||
676 | goto error; | ||
677 | } | ||
678 | #endif | ||
679 | u->wst.ptr -= 2; | ||
680 | #ifndef NO_STACK_CHECKS | ||
681 | if(u->rst.ptr > 253) { | ||
682 | u->rst.error = 2; | ||
683 | goto error; | ||
684 | } | ||
685 | #endif | ||
686 | u->rst.ptr += 2; | ||
687 | break; | ||
688 | } | ||
689 | case 0x30: /* LDZ2 */ | ||
690 | { | ||
691 | Uint8 a = u->wst.dat[u->wst.ptr - 1]; | ||
692 | u->wst.dat[u->wst.ptr - 1] = mempeek8(u->ram.dat, a); | ||
693 | u->wst.dat[u->wst.ptr] = mempeek8(u->ram.dat, a + 1); | ||
694 | #ifndef NO_STACK_CHECKS | ||
695 | if(u->wst.ptr < 1) { | ||
696 | u->wst.error = 1; | ||
697 | goto error; | ||
698 | } | ||
699 | if(u->wst.ptr > 254) { | ||
700 | u->wst.error = 2; | ||
701 | goto error; | ||
702 | } | ||
703 | #endif | ||
704 | u->wst.ptr += 1; | ||
705 | break; | ||
706 | } | ||
707 | case 0x31: /* STZ2 */ | ||
708 | { | ||
709 | Uint8 a = u->wst.dat[u->wst.ptr - 1]; | ||
710 | Uint16 b = (u->wst.dat[u->wst.ptr - 2] | (u->wst.dat[u->wst.ptr - 3] << 8)); | ||
711 | mempoke16(u->ram.dat, a, b); | ||
712 | #ifndef NO_STACK_CHECKS | ||
713 | if(u->wst.ptr < 3) { | ||
714 | u->wst.error = 1; | ||
715 | goto error; | ||
716 | } | ||
717 | #endif | ||
718 | u->wst.ptr -= 3; | ||
719 | break; | ||
720 | } | ||
721 | case 0x32: /* LDR2 */ | ||
722 | { | ||
723 | Uint8 a = u->wst.dat[u->wst.ptr - 1]; | ||
724 | u->wst.dat[u->wst.ptr - 1] = mempeek8(u->ram.dat, u->ram.ptr + (Sint8)a); | ||
725 | u->wst.dat[u->wst.ptr] = mempeek8(u->ram.dat, u->ram.ptr + (Sint8)a + 1); | ||
726 | #ifndef NO_STACK_CHECKS | ||
727 | if(u->wst.ptr < 1) { | ||
728 | u->wst.error = 1; | ||
729 | goto error; | ||
730 | } | ||
731 | if(u->wst.ptr > 254) { | ||
732 | u->wst.error = 2; | ||
733 | goto error; | ||
734 | } | ||
735 | #endif | ||
736 | u->wst.ptr += 1; | ||
737 | break; | ||
738 | } | ||
739 | case 0x33: /* STR2 */ | ||
740 | { | ||
741 | Uint8 a = u->wst.dat[u->wst.ptr - 1]; | ||
742 | Uint16 b = (u->wst.dat[u->wst.ptr - 2] | (u->wst.dat[u->wst.ptr - 3] << 8)); | ||
743 | mempoke16(u->ram.dat, u->ram.ptr + (Sint8)a, b); | ||
744 | #ifndef NO_STACK_CHECKS | ||
745 | if(u->wst.ptr < 3) { | ||
746 | u->wst.error = 1; | ||
747 | goto error; | ||
748 | } | ||
749 | #endif | ||
750 | u->wst.ptr -= 3; | ||
751 | break; | ||
752 | } | ||
753 | case 0x34: /* LDA2 */ | ||
754 | { | ||
755 | Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)); | ||
756 | u->wst.dat[u->wst.ptr - 2] = mempeek8(u->ram.dat, a); | ||
757 | u->wst.dat[u->wst.ptr - 1] = mempeek8(u->ram.dat, a + 1); | ||
758 | #ifndef NO_STACK_CHECKS | ||
759 | if(u->wst.ptr < 2) { | ||
760 | u->wst.error = 1; | ||
761 | goto error; | ||
762 | } | ||
763 | #endif | ||
764 | break; | ||
765 | } | ||
766 | case 0x35: /* STA2 */ | ||
767 | { | ||
768 | Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)); | ||
769 | Uint16 b = (u->wst.dat[u->wst.ptr - 3] | (u->wst.dat[u->wst.ptr - 4] << 8)); | ||
770 | mempoke16(u->ram.dat, a, b); | ||
771 | #ifndef NO_STACK_CHECKS | ||
772 | if(u->wst.ptr < 4) { | ||
773 | u->wst.error = 1; | ||
774 | goto error; | ||
775 | } | ||
776 | #endif | ||
777 | u->wst.ptr -= 4; | ||
778 | break; | ||
779 | } | ||
780 | case 0x36: /* DEI2 */ | ||
781 | { | ||
782 | Uint8 a = u->wst.dat[u->wst.ptr - 1]; | ||
783 | u->wst.dat[u->wst.ptr - 1] = devpeek8(&u->dev[a >> 4], a); | ||
784 | u->wst.dat[u->wst.ptr] = devpeek8(&u->dev[a >> 4], a + 1); | ||
785 | #ifndef NO_STACK_CHECKS | ||
786 | if(u->wst.ptr < 1) { | ||
787 | u->wst.error = 1; | ||
788 | goto error; | ||
789 | } | ||
790 | if(u->wst.ptr > 254) { | ||
791 | u->wst.error = 2; | ||
792 | goto error; | ||
793 | } | ||
794 | #endif | ||
795 | u->wst.ptr += 1; | ||
796 | break; | ||
797 | } | ||
798 | case 0x37: /* DEO2 */ | ||
799 | { | ||
800 | Uint8 a = u->wst.dat[u->wst.ptr - 1]; | ||
801 | Uint16 b = (u->wst.dat[u->wst.ptr - 2] | (u->wst.dat[u->wst.ptr - 3] << 8)); | ||
802 | devpoke16(&u->dev[a >> 4], a, b); | ||
803 | #ifndef NO_STACK_CHECKS | ||
804 | if(u->wst.ptr < 3) { | ||
805 | u->wst.error = 1; | ||
806 | goto error; | ||
807 | } | ||
808 | #endif | ||
809 | u->wst.ptr -= 3; | ||
810 | break; | ||
811 | } | ||
812 | case 0x38: /* ADD2 */ | ||
813 | { | ||
814 | Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)), b = (u->wst.dat[u->wst.ptr - 3] | (u->wst.dat[u->wst.ptr - 4] << 8)); | ||
815 | u->wst.dat[u->wst.ptr - 4] = (b + a) >> 8; | ||
816 | u->wst.dat[u->wst.ptr - 3] = (b + a) & 0xff; | ||
817 | #ifndef NO_STACK_CHECKS | ||
818 | if(u->wst.ptr < 4) { | ||
819 | u->wst.error = 1; | ||
820 | goto error; | ||
821 | } | ||
822 | #endif | ||
823 | u->wst.ptr -= 2; | ||
824 | break; | ||
825 | } | ||
826 | case 0x39: /* SUB2 */ | ||
827 | { | ||
828 | Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)), b = (u->wst.dat[u->wst.ptr - 3] | (u->wst.dat[u->wst.ptr - 4] << 8)); | ||
829 | u->wst.dat[u->wst.ptr - 4] = (b - a) >> 8; | ||
830 | u->wst.dat[u->wst.ptr - 3] = (b - a) & 0xff; | ||
831 | #ifndef NO_STACK_CHECKS | ||
832 | if(u->wst.ptr < 4) { | ||
833 | u->wst.error = 1; | ||
834 | goto error; | ||
835 | } | ||
836 | #endif | ||
837 | u->wst.ptr -= 2; | ||
838 | break; | ||
839 | } | ||
840 | case 0x3a: /* MUL2 */ | ||
841 | { | ||
842 | Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)), b = (u->wst.dat[u->wst.ptr - 3] | (u->wst.dat[u->wst.ptr - 4] << 8)); | ||
843 | u->wst.dat[u->wst.ptr - 4] = (b * a) >> 8; | ||
844 | u->wst.dat[u->wst.ptr - 3] = (b * a) & 0xff; | ||
845 | #ifndef NO_STACK_CHECKS | ||
846 | if(u->wst.ptr < 4) { | ||
847 | u->wst.error = 1; | ||
848 | goto error; | ||
849 | } | ||
850 | #endif | ||
851 | u->wst.ptr -= 2; | ||
852 | break; | ||
853 | } | ||
854 | case 0x3b: /* DIV2 */ | ||
855 | { | ||
856 | Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)), b = (u->wst.dat[u->wst.ptr - 3] | (u->wst.dat[u->wst.ptr - 4] << 8)); | ||
857 | u->wst.dat[u->wst.ptr - 4] = (b / a) >> 8; | ||
858 | u->wst.dat[u->wst.ptr - 3] = (b / a) & 0xff; | ||
859 | #ifndef NO_STACK_CHECKS | ||
860 | if(u->wst.ptr < 4) { | ||
861 | u->wst.error = 1; | ||
862 | goto error; | ||
863 | } | ||
864 | #endif | ||
865 | u->wst.ptr -= 2; | ||
866 | break; | ||
867 | } | ||
868 | case 0x3c: /* AND2 */ | ||
869 | { | ||
870 | Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2], c = u->wst.dat[u->wst.ptr - 3], d = u->wst.dat[u->wst.ptr - 4]; | ||
871 | u->wst.dat[u->wst.ptr - 4] = d & b; | ||
872 | u->wst.dat[u->wst.ptr - 3] = c & a; | ||
873 | #ifndef NO_STACK_CHECKS | ||
874 | if(u->wst.ptr < 4) { | ||
875 | u->wst.error = 1; | ||
876 | goto error; | ||
877 | } | ||
878 | #endif | ||
879 | u->wst.ptr -= 2; | ||
880 | break; | ||
881 | } | ||
882 | case 0x3d: /* ORA2 */ | ||
883 | { | ||
884 | Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2], c = u->wst.dat[u->wst.ptr - 3], d = u->wst.dat[u->wst.ptr - 4]; | ||
885 | u->wst.dat[u->wst.ptr - 4] = d | b; | ||
886 | u->wst.dat[u->wst.ptr - 3] = c | a; | ||
887 | #ifndef NO_STACK_CHECKS | ||
888 | if(u->wst.ptr < 4) { | ||
889 | u->wst.error = 1; | ||
890 | goto error; | ||
891 | } | ||
892 | #endif | ||
893 | u->wst.ptr -= 2; | ||
894 | break; | ||
895 | } | ||
896 | case 0x3e: /* EOR2 */ | ||
897 | { | ||
898 | Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2], c = u->wst.dat[u->wst.ptr - 3], d = u->wst.dat[u->wst.ptr - 4]; | ||
899 | u->wst.dat[u->wst.ptr - 4] = d ^ b; | ||
900 | u->wst.dat[u->wst.ptr - 3] = c ^ a; | ||
901 | #ifndef NO_STACK_CHECKS | ||
902 | if(u->wst.ptr < 4) { | ||
903 | u->wst.error = 1; | ||
904 | goto error; | ||
905 | } | ||
906 | #endif | ||
907 | u->wst.ptr -= 2; | ||
908 | break; | ||
909 | } | ||
910 | case 0x3f: /* SFT2 */ | ||
911 | { | ||
912 | Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)), b = (u->wst.dat[u->wst.ptr - 3] | (u->wst.dat[u->wst.ptr - 4] << 8)); | ||
913 | u->wst.dat[u->wst.ptr - 4] = (b >> (a & 0x000f) << ((a & 0x00f0) >> 4)) >> 8; | ||
914 | u->wst.dat[u->wst.ptr - 3] = (b >> (a & 0x000f) << ((a & 0x00f0) >> 4)) & 0xff; | ||
915 | #ifndef NO_STACK_CHECKS | ||
916 | if(u->wst.ptr < 4) { | ||
917 | u->wst.error = 1; | ||
918 | goto error; | ||
919 | } | ||
920 | #endif | ||
921 | u->wst.ptr -= 2; | ||
922 | break; | ||
923 | } | ||
924 | case 0x41: /* LITr */ | ||
925 | case 0xc1: /* LITkr */ | ||
926 | { | ||
927 | u->rst.dat[u->rst.ptr] = mempeek8(u->ram.dat, u->ram.ptr++); | ||
928 | #ifndef NO_STACK_CHECKS | ||
929 | if(u->rst.ptr > 254) { | ||
930 | u->rst.error = 2; | ||
931 | goto error; | ||
932 | } | ||
933 | #endif | ||
934 | u->rst.ptr += 1; | ||
935 | break; | ||
936 | } | ||
937 | case 0x43: /* POPr */ | ||
938 | { | ||
939 | u->rst.dat[u->rst.ptr - 1]; | ||
940 | #ifndef NO_STACK_CHECKS | ||
941 | if(u->rst.ptr < 1) { | ||
942 | u->rst.error = 1; | ||
943 | goto error; | ||
944 | } | ||
945 | #endif | ||
946 | u->rst.ptr -= 1; | ||
947 | break; | ||
948 | } | ||
949 | case 0x44: /* DUPr */ | ||
950 | { | ||
951 | Uint8 a = u->rst.dat[u->rst.ptr - 1]; | ||
952 | u->rst.dat[u->rst.ptr - 1] = a; | ||
953 | u->rst.dat[u->rst.ptr] = a; | ||
954 | #ifndef NO_STACK_CHECKS | ||
955 | if(u->rst.ptr < 1) { | ||
956 | u->rst.error = 1; | ||
957 | goto error; | ||
958 | } | ||
959 | if(u->rst.ptr > 254) { | ||
960 | u->rst.error = 2; | ||
961 | goto error; | ||
962 | } | ||
963 | #endif | ||
964 | u->rst.ptr += 1; | ||
965 | break; | ||
966 | } | ||
967 | case 0x45: /* SWPr */ | ||
968 | { | ||
969 | Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; | ||
970 | u->rst.dat[u->rst.ptr - 2] = a; | ||
971 | u->rst.dat[u->rst.ptr - 1] = b; | ||
972 | #ifndef NO_STACK_CHECKS | ||
973 | if(u->rst.ptr < 2) { | ||
974 | u->rst.error = 1; | ||
975 | goto error; | ||
976 | } | ||
977 | #endif | ||
978 | break; | ||
979 | } | ||
980 | case 0x46: /* OVRr */ | ||
981 | { | ||
982 | Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; | ||
983 | u->rst.dat[u->rst.ptr - 2] = b; | ||
984 | u->rst.dat[u->rst.ptr - 1] = a; | ||
985 | u->rst.dat[u->rst.ptr] = b; | ||
986 | #ifndef NO_STACK_CHECKS | ||
987 | if(u->rst.ptr < 2) { | ||
988 | u->rst.error = 1; | ||
989 | goto error; | ||
990 | } | ||
991 | if(u->rst.ptr > 254) { | ||
992 | u->rst.error = 2; | ||
993 | goto error; | ||
994 | } | ||
995 | #endif | ||
996 | u->rst.ptr += 1; | ||
997 | break; | ||
998 | } | ||
999 | case 0x47: /* ROTr */ | ||
1000 | { | ||
1001 | Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2], c = u->rst.dat[u->rst.ptr - 3]; | ||
1002 | u->rst.dat[u->rst.ptr - 3] = b; | ||
1003 | u->rst.dat[u->rst.ptr - 2] = a; | ||
1004 | u->rst.dat[u->rst.ptr - 1] = c; | ||
1005 | #ifndef NO_STACK_CHECKS | ||
1006 | if(u->rst.ptr < 3) { | ||
1007 | u->rst.error = 1; | ||
1008 | goto error; | ||
1009 | } | ||
1010 | #endif | ||
1011 | break; | ||
1012 | } | ||
1013 | case 0x48: /* EQUr */ | ||
1014 | { | ||
1015 | Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; | ||
1016 | u->rst.dat[u->rst.ptr - 2] = b == a; | ||
1017 | #ifndef NO_STACK_CHECKS | ||
1018 | if(u->rst.ptr < 2) { | ||
1019 | u->rst.error = 1; | ||
1020 | goto error; | ||
1021 | } | ||
1022 | #endif | ||
1023 | u->rst.ptr -= 1; | ||
1024 | break; | ||
1025 | } | ||
1026 | case 0x49: /* NEQr */ | ||
1027 | { | ||
1028 | Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; | ||
1029 | u->rst.dat[u->rst.ptr - 2] = b != a; | ||
1030 | #ifndef NO_STACK_CHECKS | ||
1031 | if(u->rst.ptr < 2) { | ||
1032 | u->rst.error = 1; | ||
1033 | goto error; | ||
1034 | } | ||
1035 | #endif | ||
1036 | u->rst.ptr -= 1; | ||
1037 | break; | ||
1038 | } | ||
1039 | case 0x4a: /* GTHr */ | ||
1040 | { | ||
1041 | Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; | ||
1042 | u->rst.dat[u->rst.ptr - 2] = b > a; | ||
1043 | #ifndef NO_STACK_CHECKS | ||
1044 | if(u->rst.ptr < 2) { | ||
1045 | u->rst.error = 1; | ||
1046 | goto error; | ||
1047 | } | ||
1048 | #endif | ||
1049 | u->rst.ptr -= 1; | ||
1050 | break; | ||
1051 | } | ||
1052 | case 0x4b: /* LTHr */ | ||
1053 | { | ||
1054 | Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; | ||
1055 | u->rst.dat[u->rst.ptr - 2] = b < a; | ||
1056 | #ifndef NO_STACK_CHECKS | ||
1057 | if(u->rst.ptr < 2) { | ||
1058 | u->rst.error = 1; | ||
1059 | goto error; | ||
1060 | } | ||
1061 | #endif | ||
1062 | u->rst.ptr -= 1; | ||
1063 | break; | ||
1064 | } | ||
1065 | case 0x4c: /* JMPr */ | ||
1066 | { | ||
1067 | Uint8 a = u->rst.dat[u->rst.ptr - 1]; | ||
1068 | u->ram.ptr += (Sint8)a; | ||
1069 | #ifndef NO_STACK_CHECKS | ||
1070 | if(u->rst.ptr < 1) { | ||
1071 | u->rst.error = 1; | ||
1072 | goto error; | ||
1073 | } | ||
1074 | #endif | ||
1075 | u->rst.ptr -= 1; | ||
1076 | break; | ||
1077 | } | ||
1078 | case 0x4d: /* JCNr */ | ||
1079 | { | ||
1080 | Uint8 a = u->rst.dat[u->rst.ptr - 1]; | ||
1081 | if(u->rst.dat[u->rst.ptr - 2]) u->ram.ptr += (Sint8)a; | ||
1082 | #ifndef NO_STACK_CHECKS | ||
1083 | if(u->rst.ptr < 2) { | ||
1084 | u->rst.error = 1; | ||
1085 | goto error; | ||
1086 | } | ||
1087 | #endif | ||
1088 | u->rst.ptr -= 2; | ||
1089 | break; | ||
1090 | } | ||
1091 | case 0x4e: /* JSRr */ | ||
1092 | { | ||
1093 | Uint8 a = u->rst.dat[u->rst.ptr - 1]; | ||
1094 | u->wst.dat[u->wst.ptr] = u->ram.ptr >> 8; | ||
1095 | u->wst.dat[u->wst.ptr + 1] = u->ram.ptr & 0xff; | ||
1096 | u->ram.ptr += (Sint8)a; | ||
1097 | #ifndef NO_STACK_CHECKS | ||
1098 | if(u->rst.ptr < 1) { | ||
1099 | u->rst.error = 1; | ||
1100 | goto error; | ||
1101 | } | ||
1102 | #endif | ||
1103 | u->rst.ptr -= 1; | ||
1104 | #ifndef NO_STACK_CHECKS | ||
1105 | if(u->wst.ptr > 253) { | ||
1106 | u->wst.error = 2; | ||
1107 | goto error; | ||
1108 | } | ||
1109 | #endif | ||
1110 | u->wst.ptr += 2; | ||
1111 | break; | ||
1112 | } | ||
1113 | case 0x4f: /* STHr */ | ||
1114 | { | ||
1115 | Uint8 a = u->rst.dat[u->rst.ptr - 1]; | ||
1116 | u->wst.dat[u->wst.ptr] = a; | ||
1117 | #ifndef NO_STACK_CHECKS | ||
1118 | if(u->rst.ptr < 1) { | ||
1119 | u->rst.error = 1; | ||
1120 | goto error; | ||
1121 | } | ||
1122 | #endif | ||
1123 | u->rst.ptr -= 1; | ||
1124 | #ifndef NO_STACK_CHECKS | ||
1125 | if(u->wst.ptr > 254) { | ||
1126 | u->wst.error = 2; | ||
1127 | goto error; | ||
1128 | } | ||
1129 | #endif | ||
1130 | u->wst.ptr += 1; | ||
1131 | break; | ||
1132 | } | ||
1133 | case 0x50: /* LDZr */ | ||
1134 | { | ||
1135 | Uint8 a = u->rst.dat[u->rst.ptr - 1]; | ||
1136 | u->rst.dat[u->rst.ptr - 1] = mempeek8(u->ram.dat, a); | ||
1137 | #ifndef NO_STACK_CHECKS | ||
1138 | if(u->rst.ptr < 1) { | ||
1139 | u->rst.error = 1; | ||
1140 | goto error; | ||
1141 | } | ||
1142 | #endif | ||
1143 | break; | ||
1144 | } | ||
1145 | case 0x51: /* STZr */ | ||
1146 | { | ||
1147 | Uint8 a = u->rst.dat[u->rst.ptr - 1]; | ||
1148 | Uint8 b = u->rst.dat[u->rst.ptr - 2]; | ||
1149 | mempoke8(u->ram.dat, a, b); | ||
1150 | #ifndef NO_STACK_CHECKS | ||
1151 | if(u->rst.ptr < 2) { | ||
1152 | u->rst.error = 1; | ||
1153 | goto error; | ||
1154 | } | ||
1155 | #endif | ||
1156 | u->rst.ptr -= 2; | ||
1157 | break; | ||
1158 | } | ||
1159 | case 0x52: /* LDRr */ | ||
1160 | { | ||
1161 | Uint8 a = u->rst.dat[u->rst.ptr - 1]; | ||
1162 | u->rst.dat[u->rst.ptr - 1] = mempeek8(u->ram.dat, u->ram.ptr + (Sint8)a); | ||
1163 | #ifndef NO_STACK_CHECKS | ||
1164 | if(u->rst.ptr < 1) { | ||
1165 | u->rst.error = 1; | ||
1166 | goto error; | ||
1167 | } | ||
1168 | #endif | ||
1169 | break; | ||
1170 | } | ||
1171 | case 0x53: /* STRr */ | ||
1172 | { | ||
1173 | Uint8 a = u->rst.dat[u->rst.ptr - 1]; | ||
1174 | Uint8 b = u->rst.dat[u->rst.ptr - 2]; | ||
1175 | mempoke8(u->ram.dat, u->ram.ptr + (Sint8)a, b); | ||
1176 | #ifndef NO_STACK_CHECKS | ||
1177 | if(u->rst.ptr < 2) { | ||
1178 | u->rst.error = 1; | ||
1179 | goto error; | ||
1180 | } | ||
1181 | #endif | ||
1182 | u->rst.ptr -= 2; | ||
1183 | break; | ||
1184 | } | ||
1185 | case 0x54: /* LDAr */ | ||
1186 | { | ||
1187 | Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)); | ||
1188 | u->rst.dat[u->rst.ptr - 2] = mempeek8(u->ram.dat, a); | ||
1189 | #ifndef NO_STACK_CHECKS | ||
1190 | if(u->rst.ptr < 2) { | ||
1191 | u->rst.error = 1; | ||
1192 | goto error; | ||
1193 | } | ||
1194 | #endif | ||
1195 | u->rst.ptr -= 1; | ||
1196 | break; | ||
1197 | } | ||
1198 | case 0x55: /* STAr */ | ||
1199 | { | ||
1200 | Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)); | ||
1201 | Uint8 b = u->rst.dat[u->rst.ptr - 3]; | ||
1202 | mempoke8(u->ram.dat, a, b); | ||
1203 | #ifndef NO_STACK_CHECKS | ||
1204 | if(u->rst.ptr < 3) { | ||
1205 | u->rst.error = 1; | ||
1206 | goto error; | ||
1207 | } | ||
1208 | #endif | ||
1209 | u->rst.ptr -= 3; | ||
1210 | break; | ||
1211 | } | ||
1212 | case 0x56: /* DEIr */ | ||
1213 | { | ||
1214 | Uint8 a = u->rst.dat[u->rst.ptr - 1]; | ||
1215 | u->rst.dat[u->rst.ptr - 1] = devpeek8(&u->dev[a >> 4], a); | ||
1216 | #ifndef NO_STACK_CHECKS | ||
1217 | if(u->rst.ptr < 1) { | ||
1218 | u->rst.error = 1; | ||
1219 | goto error; | ||
1220 | } | ||
1221 | #endif | ||
1222 | break; | ||
1223 | } | ||
1224 | case 0x57: /* DEOr */ | ||
1225 | { | ||
1226 | Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; | ||
1227 | devpoke8(&u->dev[a >> 4], a, b); | ||
1228 | #ifndef NO_STACK_CHECKS | ||
1229 | if(u->rst.ptr < 2) { | ||
1230 | u->rst.error = 1; | ||
1231 | goto error; | ||
1232 | } | ||
1233 | #endif | ||
1234 | u->rst.ptr -= 2; | ||
1235 | break; | ||
1236 | } | ||
1237 | case 0x58: /* ADDr */ | ||
1238 | { | ||
1239 | Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; | ||
1240 | u->rst.dat[u->rst.ptr - 2] = b + a; | ||
1241 | #ifndef NO_STACK_CHECKS | ||
1242 | if(u->rst.ptr < 2) { | ||
1243 | u->rst.error = 1; | ||
1244 | goto error; | ||
1245 | } | ||
1246 | #endif | ||
1247 | u->rst.ptr -= 1; | ||
1248 | break; | ||
1249 | } | ||
1250 | case 0x59: /* SUBr */ | ||
1251 | { | ||
1252 | Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; | ||
1253 | u->rst.dat[u->rst.ptr - 2] = b - a; | ||
1254 | #ifndef NO_STACK_CHECKS | ||
1255 | if(u->rst.ptr < 2) { | ||
1256 | u->rst.error = 1; | ||
1257 | goto error; | ||
1258 | } | ||
1259 | #endif | ||
1260 | u->rst.ptr -= 1; | ||
1261 | break; | ||
1262 | } | ||
1263 | case 0x5a: /* MULr */ | ||
1264 | { | ||
1265 | Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; | ||
1266 | u->rst.dat[u->rst.ptr - 2] = b * a; | ||
1267 | #ifndef NO_STACK_CHECKS | ||
1268 | if(u->rst.ptr < 2) { | ||
1269 | u->rst.error = 1; | ||
1270 | goto error; | ||
1271 | } | ||
1272 | #endif | ||
1273 | u->rst.ptr -= 1; | ||
1274 | break; | ||
1275 | } | ||
1276 | case 0x5b: /* DIVr */ | ||
1277 | { | ||
1278 | Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; | ||
1279 | u->rst.dat[u->rst.ptr - 2] = b / a; | ||
1280 | #ifndef NO_STACK_CHECKS | ||
1281 | if(u->rst.ptr < 2) { | ||
1282 | u->rst.error = 1; | ||
1283 | goto error; | ||
1284 | } | ||
1285 | #endif | ||
1286 | u->rst.ptr -= 1; | ||
1287 | break; | ||
1288 | } | ||
1289 | case 0x5c: /* ANDr */ | ||
1290 | { | ||
1291 | Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; | ||
1292 | u->rst.dat[u->rst.ptr - 2] = b & a; | ||
1293 | #ifndef NO_STACK_CHECKS | ||
1294 | if(u->rst.ptr < 2) { | ||
1295 | u->rst.error = 1; | ||
1296 | goto error; | ||
1297 | } | ||
1298 | #endif | ||
1299 | u->rst.ptr -= 1; | ||
1300 | break; | ||
1301 | } | ||
1302 | case 0x5d: /* ORAr */ | ||
1303 | { | ||
1304 | Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; | ||
1305 | u->rst.dat[u->rst.ptr - 2] = b | a; | ||
1306 | #ifndef NO_STACK_CHECKS | ||
1307 | if(u->rst.ptr < 2) { | ||
1308 | u->rst.error = 1; | ||
1309 | goto error; | ||
1310 | } | ||
1311 | #endif | ||
1312 | u->rst.ptr -= 1; | ||
1313 | break; | ||
1314 | } | ||
1315 | case 0x5e: /* EORr */ | ||
1316 | { | ||
1317 | Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; | ||
1318 | u->rst.dat[u->rst.ptr - 2] = b ^ a; | ||
1319 | #ifndef NO_STACK_CHECKS | ||
1320 | if(u->rst.ptr < 2) { | ||
1321 | u->rst.error = 1; | ||
1322 | goto error; | ||
1323 | } | ||
1324 | #endif | ||
1325 | u->rst.ptr -= 1; | ||
1326 | break; | ||
1327 | } | ||
1328 | case 0x5f: /* SFTr */ | ||
1329 | { | ||
1330 | Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; | ||
1331 | u->rst.dat[u->rst.ptr - 2] = b >> (a & 0x07) << ((a & 0x70) >> 4); | ||
1332 | #ifndef NO_STACK_CHECKS | ||
1333 | if(u->rst.ptr < 2) { | ||
1334 | u->rst.error = 1; | ||
1335 | goto error; | ||
1336 | } | ||
1337 | #endif | ||
1338 | u->rst.ptr -= 1; | ||
1339 | break; | ||
1340 | } | ||
1341 | case 0x61: /* LIT2r */ | ||
1342 | case 0xe1: /* LIT2kr */ | ||
1343 | { | ||
1344 | u->rst.dat[u->rst.ptr] = mempeek8(u->ram.dat, u->ram.ptr++); | ||
1345 | u->rst.dat[u->rst.ptr + 1] = mempeek8(u->ram.dat, u->ram.ptr++); | ||
1346 | #ifndef NO_STACK_CHECKS | ||
1347 | if(u->rst.ptr > 253) { | ||
1348 | u->rst.error = 2; | ||
1349 | goto error; | ||
1350 | } | ||
1351 | #endif | ||
1352 | u->rst.ptr += 2; | ||
1353 | break; | ||
1354 | } | ||
1355 | case 0x63: /* POP2r */ | ||
1356 | { | ||
1357 | (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)); | ||
1358 | #ifndef NO_STACK_CHECKS | ||
1359 | if(u->rst.ptr < 2) { | ||
1360 | u->rst.error = 1; | ||
1361 | goto error; | ||
1362 | } | ||
1363 | #endif | ||
1364 | u->rst.ptr -= 2; | ||
1365 | break; | ||
1366 | } | ||
1367 | case 0x64: /* DUP2r */ | ||
1368 | { | ||
1369 | Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)); | ||
1370 | u->rst.dat[u->rst.ptr - 2] = a >> 8; | ||
1371 | u->rst.dat[u->rst.ptr - 1] = a & 0xff; | ||
1372 | u->rst.dat[u->rst.ptr] = a >> 8; | ||
1373 | u->rst.dat[u->rst.ptr + 1] = a & 0xff; | ||
1374 | #ifndef NO_STACK_CHECKS | ||
1375 | if(u->rst.ptr < 2) { | ||
1376 | u->rst.error = 1; | ||
1377 | goto error; | ||
1378 | } | ||
1379 | if(u->rst.ptr > 253) { | ||
1380 | u->rst.error = 2; | ||
1381 | goto error; | ||
1382 | } | ||
1383 | #endif | ||
1384 | u->rst.ptr += 2; | ||
1385 | break; | ||
1386 | } | ||
1387 | case 0x65: /* SWP2r */ | ||
1388 | { | ||
1389 | Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)), b = (u->rst.dat[u->rst.ptr - 3] | (u->rst.dat[u->rst.ptr - 4] << 8)); | ||
1390 | u->rst.dat[u->rst.ptr - 4] = a >> 8; | ||
1391 | u->rst.dat[u->rst.ptr - 3] = a & 0xff; | ||
1392 | u->rst.dat[u->rst.ptr - 2] = b >> 8; | ||
1393 | u->rst.dat[u->rst.ptr - 1] = b & 0xff; | ||
1394 | #ifndef NO_STACK_CHECKS | ||
1395 | if(u->rst.ptr < 4) { | ||
1396 | u->rst.error = 1; | ||
1397 | goto error; | ||
1398 | } | ||
1399 | #endif | ||
1400 | break; | ||
1401 | } | ||
1402 | case 0x66: /* OVR2r */ | ||
1403 | { | ||
1404 | Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)), b = (u->rst.dat[u->rst.ptr - 3] | (u->rst.dat[u->rst.ptr - 4] << 8)); | ||
1405 | u->rst.dat[u->rst.ptr - 4] = b >> 8; | ||
1406 | u->rst.dat[u->rst.ptr - 3] = b & 0xff; | ||
1407 | u->rst.dat[u->rst.ptr - 2] = a >> 8; | ||
1408 | u->rst.dat[u->rst.ptr - 1] = a & 0xff; | ||
1409 | u->rst.dat[u->rst.ptr] = b >> 8; | ||
1410 | u->rst.dat[u->rst.ptr + 1] = b & 0xff; | ||
1411 | #ifndef NO_STACK_CHECKS | ||
1412 | if(u->rst.ptr < 4) { | ||
1413 | u->rst.error = 1; | ||
1414 | goto error; | ||
1415 | } | ||
1416 | if(u->rst.ptr > 253) { | ||
1417 | u->rst.error = 2; | ||
1418 | goto error; | ||
1419 | } | ||
1420 | #endif | ||
1421 | u->rst.ptr += 2; | ||
1422 | break; | ||
1423 | } | ||
1424 | case 0x67: /* ROT2r */ | ||
1425 | { | ||
1426 | Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)), b = (u->rst.dat[u->rst.ptr - 3] | (u->rst.dat[u->rst.ptr - 4] << 8)), c = (u->rst.dat[u->rst.ptr - 5] | (u->rst.dat[u->rst.ptr - 6] << 8)); | ||
1427 | u->rst.dat[u->rst.ptr - 6] = b >> 8; | ||
1428 | u->rst.dat[u->rst.ptr - 5] = b & 0xff; | ||
1429 | u->rst.dat[u->rst.ptr - 4] = a >> 8; | ||
1430 | u->rst.dat[u->rst.ptr - 3] = a & 0xff; | ||
1431 | u->rst.dat[u->rst.ptr - 2] = c >> 8; | ||
1432 | u->rst.dat[u->rst.ptr - 1] = c & 0xff; | ||
1433 | #ifndef NO_STACK_CHECKS | ||
1434 | if(u->rst.ptr < 6) { | ||
1435 | u->rst.error = 1; | ||
1436 | goto error; | ||
1437 | } | ||
1438 | #endif | ||
1439 | break; | ||
1440 | } | ||
1441 | case 0x68: /* EQU2r */ | ||
1442 | { | ||
1443 | Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)), b = (u->rst.dat[u->rst.ptr - 3] | (u->rst.dat[u->rst.ptr - 4] << 8)); | ||
1444 | u->rst.dat[u->rst.ptr - 4] = b == a; | ||
1445 | #ifndef NO_STACK_CHECKS | ||
1446 | if(u->rst.ptr < 4) { | ||
1447 | u->rst.error = 1; | ||
1448 | goto error; | ||
1449 | } | ||
1450 | #endif | ||
1451 | u->rst.ptr -= 3; | ||
1452 | break; | ||
1453 | } | ||
1454 | case 0x69: /* NEQ2r */ | ||
1455 | { | ||
1456 | Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)), b = (u->rst.dat[u->rst.ptr - 3] | (u->rst.dat[u->rst.ptr - 4] << 8)); | ||
1457 | u->rst.dat[u->rst.ptr - 4] = b != a; | ||
1458 | #ifndef NO_STACK_CHECKS | ||
1459 | if(u->rst.ptr < 4) { | ||
1460 | u->rst.error = 1; | ||
1461 | goto error; | ||
1462 | } | ||
1463 | #endif | ||
1464 | u->rst.ptr -= 3; | ||
1465 | break; | ||
1466 | } | ||
1467 | case 0x6a: /* GTH2r */ | ||
1468 | { | ||
1469 | Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)), b = (u->rst.dat[u->rst.ptr - 3] | (u->rst.dat[u->rst.ptr - 4] << 8)); | ||
1470 | u->rst.dat[u->rst.ptr - 4] = b > a; | ||
1471 | #ifndef NO_STACK_CHECKS | ||
1472 | if(u->rst.ptr < 4) { | ||
1473 | u->rst.error = 1; | ||
1474 | goto error; | ||
1475 | } | ||
1476 | #endif | ||
1477 | u->rst.ptr -= 3; | ||
1478 | break; | ||
1479 | } | ||
1480 | case 0x6b: /* LTH2r */ | ||
1481 | { | ||
1482 | Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)), b = (u->rst.dat[u->rst.ptr - 3] | (u->rst.dat[u->rst.ptr - 4] << 8)); | ||
1483 | u->rst.dat[u->rst.ptr - 4] = b < a; | ||
1484 | #ifndef NO_STACK_CHECKS | ||
1485 | if(u->rst.ptr < 4) { | ||
1486 | u->rst.error = 1; | ||
1487 | goto error; | ||
1488 | } | ||
1489 | #endif | ||
1490 | u->rst.ptr -= 3; | ||
1491 | break; | ||
1492 | } | ||
1493 | case 0x6c: /* JMP2r */ | ||
1494 | { | ||
1495 | u->ram.ptr = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)); | ||
1496 | #ifndef NO_STACK_CHECKS | ||
1497 | if(u->rst.ptr < 2) { | ||
1498 | u->rst.error = 1; | ||
1499 | goto error; | ||
1500 | } | ||
1501 | #endif | ||
1502 | u->rst.ptr -= 2; | ||
1503 | break; | ||
1504 | } | ||
1505 | case 0x6d: /* JCN2r */ | ||
1506 | { | ||
1507 | Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)); | ||
1508 | if(u->rst.dat[u->rst.ptr - 3]) u->ram.ptr = a; | ||
1509 | #ifndef NO_STACK_CHECKS | ||
1510 | if(u->rst.ptr < 3) { | ||
1511 | u->rst.error = 1; | ||
1512 | goto error; | ||
1513 | } | ||
1514 | #endif | ||
1515 | u->rst.ptr -= 3; | ||
1516 | break; | ||
1517 | } | ||
1518 | case 0x6e: /* JSR2r */ | ||
1519 | { | ||
1520 | u->wst.dat[u->wst.ptr] = u->ram.ptr >> 8; | ||
1521 | u->wst.dat[u->wst.ptr + 1] = u->ram.ptr & 0xff; | ||
1522 | u->ram.ptr = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)); | ||
1523 | #ifndef NO_STACK_CHECKS | ||
1524 | if(u->rst.ptr < 2) { | ||
1525 | u->rst.error = 1; | ||
1526 | goto error; | ||
1527 | } | ||
1528 | #endif | ||
1529 | u->rst.ptr -= 2; | ||
1530 | #ifndef NO_STACK_CHECKS | ||
1531 | if(u->wst.ptr > 253) { | ||
1532 | u->wst.error = 2; | ||
1533 | goto error; | ||
1534 | } | ||
1535 | #endif | ||
1536 | u->wst.ptr += 2; | ||
1537 | break; | ||
1538 | } | ||
1539 | case 0x6f: /* STH2r */ | ||
1540 | { | ||
1541 | Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)); | ||
1542 | u->wst.dat[u->wst.ptr] = a >> 8; | ||
1543 | u->wst.dat[u->wst.ptr + 1] = a & 0xff; | ||
1544 | #ifndef NO_STACK_CHECKS | ||
1545 | if(u->rst.ptr < 2) { | ||
1546 | u->rst.error = 1; | ||
1547 | goto error; | ||
1548 | } | ||
1549 | #endif | ||
1550 | u->rst.ptr -= 2; | ||
1551 | #ifndef NO_STACK_CHECKS | ||
1552 | if(u->wst.ptr > 253) { | ||
1553 | u->wst.error = 2; | ||
1554 | goto error; | ||
1555 | } | ||
1556 | #endif | ||
1557 | u->wst.ptr += 2; | ||
1558 | break; | ||
1559 | } | ||
1560 | case 0x70: /* LDZ2r */ | ||
1561 | { | ||
1562 | Uint8 a = u->rst.dat[u->rst.ptr - 1]; | ||
1563 | u->rst.dat[u->rst.ptr - 1] = mempeek8(u->ram.dat, a); | ||
1564 | u->rst.dat[u->rst.ptr] = mempeek8(u->ram.dat, a + 1); | ||
1565 | #ifndef NO_STACK_CHECKS | ||
1566 | if(u->rst.ptr < 1) { | ||
1567 | u->rst.error = 1; | ||
1568 | goto error; | ||
1569 | } | ||
1570 | if(u->rst.ptr > 254) { | ||
1571 | u->rst.error = 2; | ||
1572 | goto error; | ||
1573 | } | ||
1574 | #endif | ||
1575 | u->rst.ptr += 1; | ||
1576 | break; | ||
1577 | } | ||
1578 | case 0x71: /* STZ2r */ | ||
1579 | { | ||
1580 | Uint8 a = u->rst.dat[u->rst.ptr - 1]; | ||
1581 | Uint16 b = (u->rst.dat[u->rst.ptr - 2] | (u->rst.dat[u->rst.ptr - 3] << 8)); | ||
1582 | mempoke16(u->ram.dat, a, b); | ||
1583 | #ifndef NO_STACK_CHECKS | ||
1584 | if(u->rst.ptr < 3) { | ||
1585 | u->rst.error = 1; | ||
1586 | goto error; | ||
1587 | } | ||
1588 | #endif | ||
1589 | u->rst.ptr -= 3; | ||
1590 | break; | ||
1591 | } | ||
1592 | case 0x72: /* LDR2r */ | ||
1593 | { | ||
1594 | Uint8 a = u->rst.dat[u->rst.ptr - 1]; | ||
1595 | u->rst.dat[u->rst.ptr - 1] = mempeek8(u->ram.dat, u->ram.ptr + (Sint8)a); | ||
1596 | u->rst.dat[u->rst.ptr] = mempeek8(u->ram.dat, u->ram.ptr + (Sint8)a + 1); | ||
1597 | #ifndef NO_STACK_CHECKS | ||
1598 | if(u->rst.ptr < 1) { | ||
1599 | u->rst.error = 1; | ||
1600 | goto error; | ||
1601 | } | ||
1602 | if(u->rst.ptr > 254) { | ||
1603 | u->rst.error = 2; | ||
1604 | goto error; | ||
1605 | } | ||
1606 | #endif | ||
1607 | u->rst.ptr += 1; | ||
1608 | break; | ||
1609 | } | ||
1610 | case 0x73: /* STR2r */ | ||
1611 | { | ||
1612 | Uint8 a = u->rst.dat[u->rst.ptr - 1]; | ||
1613 | Uint16 b = (u->rst.dat[u->rst.ptr - 2] | (u->rst.dat[u->rst.ptr - 3] << 8)); | ||
1614 | mempoke16(u->ram.dat, u->ram.ptr + (Sint8)a, b); | ||
1615 | #ifndef NO_STACK_CHECKS | ||
1616 | if(u->rst.ptr < 3) { | ||
1617 | u->rst.error = 1; | ||
1618 | goto error; | ||
1619 | } | ||
1620 | #endif | ||
1621 | u->rst.ptr -= 3; | ||
1622 | break; | ||
1623 | } | ||
1624 | case 0x74: /* LDA2r */ | ||
1625 | { | ||
1626 | Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)); | ||
1627 | u->rst.dat[u->rst.ptr - 2] = mempeek8(u->ram.dat, a); | ||
1628 | u->rst.dat[u->rst.ptr - 1] = mempeek8(u->ram.dat, a + 1); | ||
1629 | #ifndef NO_STACK_CHECKS | ||
1630 | if(u->rst.ptr < 2) { | ||
1631 | u->rst.error = 1; | ||
1632 | goto error; | ||
1633 | } | ||
1634 | #endif | ||
1635 | break; | ||
1636 | } | ||
1637 | case 0x75: /* STA2r */ | ||
1638 | { | ||
1639 | Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)); | ||
1640 | Uint16 b = (u->rst.dat[u->rst.ptr - 3] | (u->rst.dat[u->rst.ptr - 4] << 8)); | ||
1641 | mempoke16(u->ram.dat, a, b); | ||
1642 | #ifndef NO_STACK_CHECKS | ||
1643 | if(u->rst.ptr < 4) { | ||
1644 | u->rst.error = 1; | ||
1645 | goto error; | ||
1646 | } | ||
1647 | #endif | ||
1648 | u->rst.ptr -= 4; | ||
1649 | break; | ||
1650 | } | ||
1651 | case 0x76: /* DEI2r */ | ||
1652 | { | ||
1653 | Uint8 a = u->rst.dat[u->rst.ptr - 1]; | ||
1654 | u->rst.dat[u->rst.ptr - 1] = devpeek8(&u->dev[a >> 4], a); | ||
1655 | u->rst.dat[u->rst.ptr] = devpeek8(&u->dev[a >> 4], a + 1); | ||
1656 | #ifndef NO_STACK_CHECKS | ||
1657 | if(u->rst.ptr < 1) { | ||
1658 | u->rst.error = 1; | ||
1659 | goto error; | ||
1660 | } | ||
1661 | if(u->rst.ptr > 254) { | ||
1662 | u->rst.error = 2; | ||
1663 | goto error; | ||
1664 | } | ||
1665 | #endif | ||
1666 | u->rst.ptr += 1; | ||
1667 | break; | ||
1668 | } | ||
1669 | case 0x77: /* DEO2r */ | ||
1670 | { | ||
1671 | Uint8 a = u->rst.dat[u->rst.ptr - 1]; | ||
1672 | Uint16 b = (u->rst.dat[u->rst.ptr - 2] | (u->rst.dat[u->rst.ptr - 3] << 8)); | ||
1673 | devpoke16(&u->dev[a >> 4], a, b); | ||
1674 | #ifndef NO_STACK_CHECKS | ||
1675 | if(u->rst.ptr < 3) { | ||
1676 | u->rst.error = 1; | ||
1677 | goto error; | ||
1678 | } | ||
1679 | #endif | ||
1680 | u->rst.ptr -= 3; | ||
1681 | break; | ||
1682 | } | ||
1683 | case 0x78: /* ADD2r */ | ||
1684 | { | ||
1685 | Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)), b = (u->rst.dat[u->rst.ptr - 3] | (u->rst.dat[u->rst.ptr - 4] << 8)); | ||
1686 | u->rst.dat[u->rst.ptr - 4] = (b + a) >> 8; | ||
1687 | u->rst.dat[u->rst.ptr - 3] = (b + a) & 0xff; | ||
1688 | #ifndef NO_STACK_CHECKS | ||
1689 | if(u->rst.ptr < 4) { | ||
1690 | u->rst.error = 1; | ||
1691 | goto error; | ||
1692 | } | ||
1693 | #endif | ||
1694 | u->rst.ptr -= 2; | ||
1695 | break; | ||
1696 | } | ||
1697 | case 0x79: /* SUB2r */ | ||
1698 | { | ||
1699 | Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)), b = (u->rst.dat[u->rst.ptr - 3] | (u->rst.dat[u->rst.ptr - 4] << 8)); | ||
1700 | u->rst.dat[u->rst.ptr - 4] = (b - a) >> 8; | ||
1701 | u->rst.dat[u->rst.ptr - 3] = (b - a) & 0xff; | ||
1702 | #ifndef NO_STACK_CHECKS | ||
1703 | if(u->rst.ptr < 4) { | ||
1704 | u->rst.error = 1; | ||
1705 | goto error; | ||
1706 | } | ||
1707 | #endif | ||
1708 | u->rst.ptr -= 2; | ||
1709 | break; | ||
1710 | } | ||
1711 | case 0x7a: /* MUL2r */ | ||
1712 | { | ||
1713 | Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)), b = (u->rst.dat[u->rst.ptr - 3] | (u->rst.dat[u->rst.ptr - 4] << 8)); | ||
1714 | u->rst.dat[u->rst.ptr - 4] = (b * a) >> 8; | ||
1715 | u->rst.dat[u->rst.ptr - 3] = (b * a) & 0xff; | ||
1716 | #ifndef NO_STACK_CHECKS | ||
1717 | if(u->rst.ptr < 4) { | ||
1718 | u->rst.error = 1; | ||
1719 | goto error; | ||
1720 | } | ||
1721 | #endif | ||
1722 | u->rst.ptr -= 2; | ||
1723 | break; | ||
1724 | } | ||
1725 | case 0x7b: /* DIV2r */ | ||
1726 | { | ||
1727 | Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)), b = (u->rst.dat[u->rst.ptr - 3] | (u->rst.dat[u->rst.ptr - 4] << 8)); | ||
1728 | u->rst.dat[u->rst.ptr - 4] = (b / a) >> 8; | ||
1729 | u->rst.dat[u->rst.ptr - 3] = (b / a) & 0xff; | ||
1730 | #ifndef NO_STACK_CHECKS | ||
1731 | if(u->rst.ptr < 4) { | ||
1732 | u->rst.error = 1; | ||
1733 | goto error; | ||
1734 | } | ||
1735 | #endif | ||
1736 | u->rst.ptr -= 2; | ||
1737 | break; | ||
1738 | } | ||
1739 | case 0x7c: /* AND2r */ | ||
1740 | { | ||
1741 | Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2], c = u->rst.dat[u->rst.ptr - 3], d = u->rst.dat[u->rst.ptr - 4]; | ||
1742 | u->rst.dat[u->rst.ptr - 4] = d & b; | ||
1743 | u->rst.dat[u->rst.ptr - 3] = c & a; | ||
1744 | #ifndef NO_STACK_CHECKS | ||
1745 | if(u->rst.ptr < 4) { | ||
1746 | u->rst.error = 1; | ||
1747 | goto error; | ||
1748 | } | ||
1749 | #endif | ||
1750 | u->rst.ptr -= 2; | ||
1751 | break; | ||
1752 | } | ||
1753 | case 0x7d: /* ORA2r */ | ||
1754 | { | ||
1755 | Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2], c = u->rst.dat[u->rst.ptr - 3], d = u->rst.dat[u->rst.ptr - 4]; | ||
1756 | u->rst.dat[u->rst.ptr - 4] = d | b; | ||
1757 | u->rst.dat[u->rst.ptr - 3] = c | a; | ||
1758 | #ifndef NO_STACK_CHECKS | ||
1759 | if(u->rst.ptr < 4) { | ||
1760 | u->rst.error = 1; | ||
1761 | goto error; | ||
1762 | } | ||
1763 | #endif | ||
1764 | u->rst.ptr -= 2; | ||
1765 | break; | ||
1766 | } | ||
1767 | case 0x7e: /* EOR2r */ | ||
1768 | { | ||
1769 | Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2], c = u->rst.dat[u->rst.ptr - 3], d = u->rst.dat[u->rst.ptr - 4]; | ||
1770 | u->rst.dat[u->rst.ptr - 4] = d ^ b; | ||
1771 | u->rst.dat[u->rst.ptr - 3] = c ^ a; | ||
1772 | #ifndef NO_STACK_CHECKS | ||
1773 | if(u->rst.ptr < 4) { | ||
1774 | u->rst.error = 1; | ||
1775 | goto error; | ||
1776 | } | ||
1777 | #endif | ||
1778 | u->rst.ptr -= 2; | ||
1779 | break; | ||
1780 | } | ||
1781 | case 0x7f: /* SFT2r */ | ||
1782 | { | ||
1783 | Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)), b = (u->rst.dat[u->rst.ptr - 3] | (u->rst.dat[u->rst.ptr - 4] << 8)); | ||
1784 | u->rst.dat[u->rst.ptr - 4] = (b >> (a & 0x000f) << ((a & 0x00f0) >> 4)) >> 8; | ||
1785 | u->rst.dat[u->rst.ptr - 3] = (b >> (a & 0x000f) << ((a & 0x00f0) >> 4)) & 0xff; | ||
1786 | #ifndef NO_STACK_CHECKS | ||
1787 | if(u->rst.ptr < 4) { | ||
1788 | u->rst.error = 1; | ||
1789 | goto error; | ||
1790 | } | ||
1791 | #endif | ||
1792 | u->rst.ptr -= 2; | ||
1793 | break; | ||
1794 | } | ||
1795 | case 0x83: /* POPk */ | ||
1796 | { | ||
1797 | u->wst.dat[u->wst.ptr - 1]; | ||
1798 | #ifndef NO_STACK_CHECKS | ||
1799 | if(u->wst.ptr < 1) { | ||
1800 | u->wst.error = 1; | ||
1801 | goto error; | ||
1802 | } | ||
1803 | #endif | ||
1804 | break; | ||
1805 | } | ||
1806 | case 0x84: /* DUPk */ | ||
1807 | { | ||
1808 | Uint8 a = u->wst.dat[u->wst.ptr - 1]; | ||
1809 | u->wst.dat[u->wst.ptr] = a; | ||
1810 | u->wst.dat[u->wst.ptr + 1] = a; | ||
1811 | #ifndef NO_STACK_CHECKS | ||
1812 | if(u->wst.ptr < 1) { | ||
1813 | u->wst.error = 1; | ||
1814 | goto error; | ||
1815 | } | ||
1816 | if(u->wst.ptr > 253) { | ||
1817 | u->wst.error = 2; | ||
1818 | goto error; | ||
1819 | } | ||
1820 | #endif | ||
1821 | u->wst.ptr += 2; | ||
1822 | break; | ||
1823 | } | ||
1824 | case 0x85: /* SWPk */ | ||
1825 | { | ||
1826 | Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; | ||
1827 | u->wst.dat[u->wst.ptr] = a; | ||
1828 | u->wst.dat[u->wst.ptr + 1] = b; | ||
1829 | #ifndef NO_STACK_CHECKS | ||
1830 | if(u->wst.ptr < 2) { | ||
1831 | u->wst.error = 1; | ||
1832 | goto error; | ||
1833 | } | ||
1834 | if(u->wst.ptr > 253) { | ||
1835 | u->wst.error = 2; | ||
1836 | goto error; | ||
1837 | } | ||
1838 | #endif | ||
1839 | u->wst.ptr += 2; | ||
1840 | break; | ||
1841 | } | ||
1842 | case 0x86: /* OVRk */ | ||
1843 | { | ||
1844 | Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; | ||
1845 | u->wst.dat[u->wst.ptr] = b; | ||
1846 | u->wst.dat[u->wst.ptr + 1] = a; | ||
1847 | u->wst.dat[u->wst.ptr + 2] = b; | ||
1848 | #ifndef NO_STACK_CHECKS | ||
1849 | if(u->wst.ptr < 2) { | ||
1850 | u->wst.error = 1; | ||
1851 | goto error; | ||
1852 | } | ||
1853 | if(u->wst.ptr > 252) { | ||
1854 | u->wst.error = 2; | ||
1855 | goto error; | ||
1856 | } | ||
1857 | #endif | ||
1858 | u->wst.ptr += 3; | ||
1859 | break; | ||
1860 | } | ||
1861 | case 0x87: /* ROTk */ | ||
1862 | { | ||
1863 | Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2], c = u->wst.dat[u->wst.ptr - 3]; | ||
1864 | u->wst.dat[u->wst.ptr] = b; | ||
1865 | u->wst.dat[u->wst.ptr + 1] = a; | ||
1866 | u->wst.dat[u->wst.ptr + 2] = c; | ||
1867 | #ifndef NO_STACK_CHECKS | ||
1868 | if(u->wst.ptr < 3) { | ||
1869 | u->wst.error = 1; | ||
1870 | goto error; | ||
1871 | } | ||
1872 | if(u->wst.ptr > 252) { | ||
1873 | u->wst.error = 2; | ||
1874 | goto error; | ||
1875 | } | ||
1876 | #endif | ||
1877 | u->wst.ptr += 3; | ||
1878 | break; | ||
1879 | } | ||
1880 | case 0x88: /* EQUk */ | ||
1881 | { | ||
1882 | Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; | ||
1883 | u->wst.dat[u->wst.ptr] = b == a; | ||
1884 | #ifndef NO_STACK_CHECKS | ||
1885 | if(u->wst.ptr < 2) { | ||
1886 | u->wst.error = 1; | ||
1887 | goto error; | ||
1888 | } | ||
1889 | if(u->wst.ptr > 254) { | ||
1890 | u->wst.error = 2; | ||
1891 | goto error; | ||
1892 | } | ||
1893 | #endif | ||
1894 | u->wst.ptr += 1; | ||
1895 | break; | ||
1896 | } | ||
1897 | case 0x89: /* NEQk */ | ||
1898 | { | ||
1899 | Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; | ||
1900 | u->wst.dat[u->wst.ptr] = b != a; | ||
1901 | #ifndef NO_STACK_CHECKS | ||
1902 | if(u->wst.ptr < 2) { | ||
1903 | u->wst.error = 1; | ||
1904 | goto error; | ||
1905 | } | ||
1906 | if(u->wst.ptr > 254) { | ||
1907 | u->wst.error = 2; | ||
1908 | goto error; | ||
1909 | } | ||
1910 | #endif | ||
1911 | u->wst.ptr += 1; | ||
1912 | break; | ||
1913 | } | ||
1914 | case 0x8a: /* GTHk */ | ||
1915 | { | ||
1916 | Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; | ||
1917 | u->wst.dat[u->wst.ptr] = b > a; | ||
1918 | #ifndef NO_STACK_CHECKS | ||
1919 | if(u->wst.ptr < 2) { | ||
1920 | u->wst.error = 1; | ||
1921 | goto error; | ||
1922 | } | ||
1923 | if(u->wst.ptr > 254) { | ||
1924 | u->wst.error = 2; | ||
1925 | goto error; | ||
1926 | } | ||
1927 | #endif | ||
1928 | u->wst.ptr += 1; | ||
1929 | break; | ||
1930 | } | ||
1931 | case 0x8b: /* LTHk */ | ||
1932 | { | ||
1933 | Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; | ||
1934 | u->wst.dat[u->wst.ptr] = b < a; | ||
1935 | #ifndef NO_STACK_CHECKS | ||
1936 | if(u->wst.ptr < 2) { | ||
1937 | u->wst.error = 1; | ||
1938 | goto error; | ||
1939 | } | ||
1940 | if(u->wst.ptr > 254) { | ||
1941 | u->wst.error = 2; | ||
1942 | goto error; | ||
1943 | } | ||
1944 | #endif | ||
1945 | u->wst.ptr += 1; | ||
1946 | break; | ||
1947 | } | ||
1948 | case 0x8c: /* JMPk */ | ||
1949 | { | ||
1950 | Uint8 a = u->wst.dat[u->wst.ptr - 1]; | ||
1951 | u->ram.ptr += (Sint8)a; | ||
1952 | #ifndef NO_STACK_CHECKS | ||
1953 | if(u->wst.ptr < 1) { | ||
1954 | u->wst.error = 1; | ||
1955 | goto error; | ||
1956 | } | ||
1957 | #endif | ||
1958 | break; | ||
1959 | } | ||
1960 | case 0x8d: /* JCNk */ | ||
1961 | { | ||
1962 | Uint8 a = u->wst.dat[u->wst.ptr - 1]; | ||
1963 | if(u->wst.dat[u->wst.ptr - 2]) u->ram.ptr += (Sint8)a; | ||
1964 | #ifndef NO_STACK_CHECKS | ||
1965 | if(u->wst.ptr < 2) { | ||
1966 | u->wst.error = 1; | ||
1967 | goto error; | ||
1968 | } | ||
1969 | #endif | ||
1970 | break; | ||
1971 | } | ||
1972 | case 0x8e: /* JSRk */ | ||
1973 | { | ||
1974 | Uint8 a = u->wst.dat[u->wst.ptr - 1]; | ||
1975 | u->rst.dat[u->rst.ptr] = u->ram.ptr >> 8; | ||
1976 | u->rst.dat[u->rst.ptr + 1] = u->ram.ptr & 0xff; | ||
1977 | u->ram.ptr += (Sint8)a; | ||
1978 | #ifndef NO_STACK_CHECKS | ||
1979 | if(u->wst.ptr < 1) { | ||
1980 | u->wst.error = 1; | ||
1981 | goto error; | ||
1982 | } | ||
1983 | #endif | ||
1984 | #ifndef NO_STACK_CHECKS | ||
1985 | if(u->rst.ptr > 253) { | ||
1986 | u->rst.error = 2; | ||
1987 | goto error; | ||
1988 | } | ||
1989 | #endif | ||
1990 | u->rst.ptr += 2; | ||
1991 | break; | ||
1992 | } | ||
1993 | case 0x8f: /* STHk */ | ||
1994 | { | ||
1995 | Uint8 a = u->wst.dat[u->wst.ptr - 1]; | ||
1996 | u->rst.dat[u->rst.ptr] = a; | ||
1997 | #ifndef NO_STACK_CHECKS | ||
1998 | if(u->wst.ptr < 1) { | ||
1999 | u->wst.error = 1; | ||
2000 | goto error; | ||
2001 | } | ||
2002 | #endif | ||
2003 | #ifndef NO_STACK_CHECKS | ||
2004 | if(u->rst.ptr > 254) { | ||
2005 | u->rst.error = 2; | ||
2006 | goto error; | ||
2007 | } | ||
2008 | #endif | ||
2009 | u->rst.ptr += 1; | ||
2010 | break; | ||
2011 | } | ||
2012 | case 0x90: /* LDZk */ | ||
2013 | { | ||
2014 | Uint8 a = u->wst.dat[u->wst.ptr - 1]; | ||
2015 | u->wst.dat[u->wst.ptr] = mempeek8(u->ram.dat, a); | ||
2016 | #ifndef NO_STACK_CHECKS | ||
2017 | if(u->wst.ptr < 1) { | ||
2018 | u->wst.error = 1; | ||
2019 | goto error; | ||
2020 | } | ||
2021 | if(u->wst.ptr > 254) { | ||
2022 | u->wst.error = 2; | ||
2023 | goto error; | ||
2024 | } | ||
2025 | #endif | ||
2026 | u->wst.ptr += 1; | ||
2027 | break; | ||
2028 | } | ||
2029 | case 0x91: /* STZk */ | ||
2030 | { | ||
2031 | Uint8 a = u->wst.dat[u->wst.ptr - 1]; | ||
2032 | Uint8 b = u->wst.dat[u->wst.ptr - 2]; | ||
2033 | mempoke8(u->ram.dat, a, b); | ||
2034 | #ifndef NO_STACK_CHECKS | ||
2035 | if(u->wst.ptr < 2) { | ||
2036 | u->wst.error = 1; | ||
2037 | goto error; | ||
2038 | } | ||
2039 | #endif | ||
2040 | break; | ||
2041 | } | ||
2042 | case 0x92: /* LDRk */ | ||
2043 | { | ||
2044 | Uint8 a = u->wst.dat[u->wst.ptr - 1]; | ||
2045 | u->wst.dat[u->wst.ptr] = mempeek8(u->ram.dat, u->ram.ptr + (Sint8)a); | ||
2046 | #ifndef NO_STACK_CHECKS | ||
2047 | if(u->wst.ptr < 1) { | ||
2048 | u->wst.error = 1; | ||
2049 | goto error; | ||
2050 | } | ||
2051 | if(u->wst.ptr > 254) { | ||
2052 | u->wst.error = 2; | ||
2053 | goto error; | ||
2054 | } | ||
2055 | #endif | ||
2056 | u->wst.ptr += 1; | ||
2057 | break; | ||
2058 | } | ||
2059 | case 0x93: /* STRk */ | ||
2060 | { | ||
2061 | Uint8 a = u->wst.dat[u->wst.ptr - 1]; | ||
2062 | Uint8 b = u->wst.dat[u->wst.ptr - 2]; | ||
2063 | mempoke8(u->ram.dat, u->ram.ptr + (Sint8)a, b); | ||
2064 | #ifndef NO_STACK_CHECKS | ||
2065 | if(u->wst.ptr < 2) { | ||
2066 | u->wst.error = 1; | ||
2067 | goto error; | ||
2068 | } | ||
2069 | #endif | ||
2070 | break; | ||
2071 | } | ||
2072 | case 0x94: /* LDAk */ | ||
2073 | { | ||
2074 | Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)); | ||
2075 | u->wst.dat[u->wst.ptr] = mempeek8(u->ram.dat, a); | ||
2076 | #ifndef NO_STACK_CHECKS | ||
2077 | if(u->wst.ptr < 2) { | ||
2078 | u->wst.error = 1; | ||
2079 | goto error; | ||
2080 | } | ||
2081 | if(u->wst.ptr > 254) { | ||
2082 | u->wst.error = 2; | ||
2083 | goto error; | ||
2084 | } | ||
2085 | #endif | ||
2086 | u->wst.ptr += 1; | ||
2087 | break; | ||
2088 | } | ||
2089 | case 0x95: /* STAk */ | ||
2090 | { | ||
2091 | Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)); | ||
2092 | Uint8 b = u->wst.dat[u->wst.ptr - 3]; | ||
2093 | mempoke8(u->ram.dat, a, b); | ||
2094 | #ifndef NO_STACK_CHECKS | ||
2095 | if(u->wst.ptr < 3) { | ||
2096 | u->wst.error = 1; | ||
2097 | goto error; | ||
2098 | } | ||
2099 | #endif | ||
2100 | break; | ||
2101 | } | ||
2102 | case 0x96: /* DEIk */ | ||
2103 | { | ||
2104 | Uint8 a = u->wst.dat[u->wst.ptr - 1]; | ||
2105 | u->wst.dat[u->wst.ptr] = devpeek8(&u->dev[a >> 4], a); | ||
2106 | #ifndef NO_STACK_CHECKS | ||
2107 | if(u->wst.ptr < 1) { | ||
2108 | u->wst.error = 1; | ||
2109 | goto error; | ||
2110 | } | ||
2111 | if(u->wst.ptr > 254) { | ||
2112 | u->wst.error = 2; | ||
2113 | goto error; | ||
2114 | } | ||
2115 | #endif | ||
2116 | u->wst.ptr += 1; | ||
2117 | break; | ||
2118 | } | ||
2119 | case 0x97: /* DEOk */ | ||
2120 | { | ||
2121 | Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; | ||
2122 | devpoke8(&u->dev[a >> 4], a, b); | ||
2123 | #ifndef NO_STACK_CHECKS | ||
2124 | if(u->wst.ptr < 2) { | ||
2125 | u->wst.error = 1; | ||
2126 | goto error; | ||
2127 | } | ||
2128 | #endif | ||
2129 | break; | ||
2130 | } | ||
2131 | case 0x98: /* ADDk */ | ||
2132 | { | ||
2133 | Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; | ||
2134 | u->wst.dat[u->wst.ptr] = b + a; | ||
2135 | #ifndef NO_STACK_CHECKS | ||
2136 | if(u->wst.ptr < 2) { | ||
2137 | u->wst.error = 1; | ||
2138 | goto error; | ||
2139 | } | ||
2140 | if(u->wst.ptr > 254) { | ||
2141 | u->wst.error = 2; | ||
2142 | goto error; | ||
2143 | } | ||
2144 | #endif | ||
2145 | u->wst.ptr += 1; | ||
2146 | break; | ||
2147 | } | ||
2148 | case 0x99: /* SUBk */ | ||
2149 | { | ||
2150 | Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; | ||
2151 | u->wst.dat[u->wst.ptr] = b - a; | ||
2152 | #ifndef NO_STACK_CHECKS | ||
2153 | if(u->wst.ptr < 2) { | ||
2154 | u->wst.error = 1; | ||
2155 | goto error; | ||
2156 | } | ||
2157 | if(u->wst.ptr > 254) { | ||
2158 | u->wst.error = 2; | ||
2159 | goto error; | ||
2160 | } | ||
2161 | #endif | ||
2162 | u->wst.ptr += 1; | ||
2163 | break; | ||
2164 | } | ||
2165 | case 0x9a: /* MULk */ | ||
2166 | { | ||
2167 | Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; | ||
2168 | u->wst.dat[u->wst.ptr] = b * a; | ||
2169 | #ifndef NO_STACK_CHECKS | ||
2170 | if(u->wst.ptr < 2) { | ||
2171 | u->wst.error = 1; | ||
2172 | goto error; | ||
2173 | } | ||
2174 | if(u->wst.ptr > 254) { | ||
2175 | u->wst.error = 2; | ||
2176 | goto error; | ||
2177 | } | ||
2178 | #endif | ||
2179 | u->wst.ptr += 1; | ||
2180 | break; | ||
2181 | } | ||
2182 | case 0x9b: /* DIVk */ | ||
2183 | { | ||
2184 | Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; | ||
2185 | u->wst.dat[u->wst.ptr] = b / a; | ||
2186 | #ifndef NO_STACK_CHECKS | ||
2187 | if(u->wst.ptr < 2) { | ||
2188 | u->wst.error = 1; | ||
2189 | goto error; | ||
2190 | } | ||
2191 | if(u->wst.ptr > 254) { | ||
2192 | u->wst.error = 2; | ||
2193 | goto error; | ||
2194 | } | ||
2195 | #endif | ||
2196 | u->wst.ptr += 1; | ||
2197 | break; | ||
2198 | } | ||
2199 | case 0x9c: /* ANDk */ | ||
2200 | { | ||
2201 | Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; | ||
2202 | u->wst.dat[u->wst.ptr] = b & a; | ||
2203 | #ifndef NO_STACK_CHECKS | ||
2204 | if(u->wst.ptr < 2) { | ||
2205 | u->wst.error = 1; | ||
2206 | goto error; | ||
2207 | } | ||
2208 | if(u->wst.ptr > 254) { | ||
2209 | u->wst.error = 2; | ||
2210 | goto error; | ||
2211 | } | ||
2212 | #endif | ||
2213 | u->wst.ptr += 1; | ||
2214 | break; | ||
2215 | } | ||
2216 | case 0x9d: /* ORAk */ | ||
2217 | { | ||
2218 | Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; | ||
2219 | u->wst.dat[u->wst.ptr] = b | a; | ||
2220 | #ifndef NO_STACK_CHECKS | ||
2221 | if(u->wst.ptr < 2) { | ||
2222 | u->wst.error = 1; | ||
2223 | goto error; | ||
2224 | } | ||
2225 | if(u->wst.ptr > 254) { | ||
2226 | u->wst.error = 2; | ||
2227 | goto error; | ||
2228 | } | ||
2229 | #endif | ||
2230 | u->wst.ptr += 1; | ||
2231 | break; | ||
2232 | } | ||
2233 | case 0x9e: /* EORk */ | ||
2234 | { | ||
2235 | Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; | ||
2236 | u->wst.dat[u->wst.ptr] = b ^ a; | ||
2237 | #ifndef NO_STACK_CHECKS | ||
2238 | if(u->wst.ptr < 2) { | ||
2239 | u->wst.error = 1; | ||
2240 | goto error; | ||
2241 | } | ||
2242 | if(u->wst.ptr > 254) { | ||
2243 | u->wst.error = 2; | ||
2244 | goto error; | ||
2245 | } | ||
2246 | #endif | ||
2247 | u->wst.ptr += 1; | ||
2248 | break; | ||
2249 | } | ||
2250 | case 0x9f: /* SFTk */ | ||
2251 | { | ||
2252 | Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; | ||
2253 | u->wst.dat[u->wst.ptr] = b >> (a & 0x07) << ((a & 0x70) >> 4); | ||
2254 | #ifndef NO_STACK_CHECKS | ||
2255 | if(u->wst.ptr < 2) { | ||
2256 | u->wst.error = 1; | ||
2257 | goto error; | ||
2258 | } | ||
2259 | if(u->wst.ptr > 254) { | ||
2260 | u->wst.error = 2; | ||
2261 | goto error; | ||
2262 | } | ||
2263 | #endif | ||
2264 | u->wst.ptr += 1; | ||
2265 | break; | ||
2266 | } | ||
2267 | case 0xa3: /* POP2k */ | ||
2268 | { | ||
2269 | (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)); | ||
2270 | #ifndef NO_STACK_CHECKS | ||
2271 | if(u->wst.ptr < 2) { | ||
2272 | u->wst.error = 1; | ||
2273 | goto error; | ||
2274 | } | ||
2275 | #endif | ||
2276 | break; | ||
2277 | } | ||
2278 | case 0xa4: /* DUP2k */ | ||
2279 | { | ||
2280 | Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)); | ||
2281 | u->wst.dat[u->wst.ptr] = a >> 8; | ||
2282 | u->wst.dat[u->wst.ptr + 1] = a & 0xff; | ||
2283 | u->wst.dat[u->wst.ptr + 2] = a >> 8; | ||
2284 | u->wst.dat[u->wst.ptr + 3] = a & 0xff; | ||
2285 | #ifndef NO_STACK_CHECKS | ||
2286 | if(u->wst.ptr < 2) { | ||
2287 | u->wst.error = 1; | ||
2288 | goto error; | ||
2289 | } | ||
2290 | if(u->wst.ptr > 251) { | ||
2291 | u->wst.error = 2; | ||
2292 | goto error; | ||
2293 | } | ||
2294 | #endif | ||
2295 | u->wst.ptr += 4; | ||
2296 | break; | ||
2297 | } | ||
2298 | case 0xa5: /* SWP2k */ | ||
2299 | { | ||
2300 | Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)), b = (u->wst.dat[u->wst.ptr - 3] | (u->wst.dat[u->wst.ptr - 4] << 8)); | ||
2301 | u->wst.dat[u->wst.ptr] = a >> 8; | ||
2302 | u->wst.dat[u->wst.ptr + 1] = a & 0xff; | ||
2303 | u->wst.dat[u->wst.ptr + 2] = b >> 8; | ||
2304 | u->wst.dat[u->wst.ptr + 3] = b & 0xff; | ||
2305 | #ifndef NO_STACK_CHECKS | ||
2306 | if(u->wst.ptr < 4) { | ||
2307 | u->wst.error = 1; | ||
2308 | goto error; | ||
2309 | } | ||
2310 | if(u->wst.ptr > 251) { | ||
2311 | u->wst.error = 2; | ||
2312 | goto error; | ||
2313 | } | ||
2314 | #endif | ||
2315 | u->wst.ptr += 4; | ||
2316 | break; | ||
2317 | } | ||
2318 | case 0xa6: /* OVR2k */ | ||
2319 | { | ||
2320 | Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)), b = (u->wst.dat[u->wst.ptr - 3] | (u->wst.dat[u->wst.ptr - 4] << 8)); | ||
2321 | u->wst.dat[u->wst.ptr] = b >> 8; | ||
2322 | u->wst.dat[u->wst.ptr + 1] = b & 0xff; | ||
2323 | u->wst.dat[u->wst.ptr + 2] = a >> 8; | ||
2324 | u->wst.dat[u->wst.ptr + 3] = a & 0xff; | ||
2325 | u->wst.dat[u->wst.ptr + 4] = b >> 8; | ||
2326 | u->wst.dat[u->wst.ptr + 5] = b & 0xff; | ||
2327 | #ifndef NO_STACK_CHECKS | ||
2328 | if(u->wst.ptr < 4) { | ||
2329 | u->wst.error = 1; | ||
2330 | goto error; | ||
2331 | } | ||
2332 | if(u->wst.ptr > 249) { | ||
2333 | u->wst.error = 2; | ||
2334 | goto error; | ||
2335 | } | ||
2336 | #endif | ||
2337 | u->wst.ptr += 6; | ||
2338 | break; | ||
2339 | } | ||
2340 | case 0xa7: /* ROT2k */ | ||
2341 | { | ||
2342 | Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)), b = (u->wst.dat[u->wst.ptr - 3] | (u->wst.dat[u->wst.ptr - 4] << 8)), c = (u->wst.dat[u->wst.ptr - 5] | (u->wst.dat[u->wst.ptr - 6] << 8)); | ||
2343 | u->wst.dat[u->wst.ptr] = b >> 8; | ||
2344 | u->wst.dat[u->wst.ptr + 1] = b & 0xff; | ||
2345 | u->wst.dat[u->wst.ptr + 2] = a >> 8; | ||
2346 | u->wst.dat[u->wst.ptr + 3] = a & 0xff; | ||
2347 | u->wst.dat[u->wst.ptr + 4] = c >> 8; | ||
2348 | u->wst.dat[u->wst.ptr + 5] = c & 0xff; | ||
2349 | #ifndef NO_STACK_CHECKS | ||
2350 | if(u->wst.ptr < 6) { | ||
2351 | u->wst.error = 1; | ||
2352 | goto error; | ||
2353 | } | ||
2354 | if(u->wst.ptr > 249) { | ||
2355 | u->wst.error = 2; | ||
2356 | goto error; | ||
2357 | } | ||
2358 | #endif | ||
2359 | u->wst.ptr += 6; | ||
2360 | break; | ||
2361 | } | ||
2362 | case 0xa8: /* EQU2k */ | ||
2363 | { | ||
2364 | Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)), b = (u->wst.dat[u->wst.ptr - 3] | (u->wst.dat[u->wst.ptr - 4] << 8)); | ||
2365 | u->wst.dat[u->wst.ptr] = b == a; | ||
2366 | #ifndef NO_STACK_CHECKS | ||
2367 | if(u->wst.ptr < 4) { | ||
2368 | u->wst.error = 1; | ||
2369 | goto error; | ||
2370 | } | ||
2371 | if(u->wst.ptr > 254) { | ||
2372 | u->wst.error = 2; | ||
2373 | goto error; | ||
2374 | } | ||
2375 | #endif | ||
2376 | u->wst.ptr += 1; | ||
2377 | break; | ||
2378 | } | ||
2379 | case 0xa9: /* NEQ2k */ | ||
2380 | { | ||
2381 | Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)), b = (u->wst.dat[u->wst.ptr - 3] | (u->wst.dat[u->wst.ptr - 4] << 8)); | ||
2382 | u->wst.dat[u->wst.ptr] = b != a; | ||
2383 | #ifndef NO_STACK_CHECKS | ||
2384 | if(u->wst.ptr < 4) { | ||
2385 | u->wst.error = 1; | ||
2386 | goto error; | ||
2387 | } | ||
2388 | if(u->wst.ptr > 254) { | ||
2389 | u->wst.error = 2; | ||
2390 | goto error; | ||
2391 | } | ||
2392 | #endif | ||
2393 | u->wst.ptr += 1; | ||
2394 | break; | ||
2395 | } | ||
2396 | case 0xaa: /* GTH2k */ | ||
2397 | { | ||
2398 | Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)), b = (u->wst.dat[u->wst.ptr - 3] | (u->wst.dat[u->wst.ptr - 4] << 8)); | ||
2399 | u->wst.dat[u->wst.ptr] = b > a; | ||
2400 | #ifndef NO_STACK_CHECKS | ||
2401 | if(u->wst.ptr < 4) { | ||
2402 | u->wst.error = 1; | ||
2403 | goto error; | ||
2404 | } | ||
2405 | if(u->wst.ptr > 254) { | ||
2406 | u->wst.error = 2; | ||
2407 | goto error; | ||
2408 | } | ||
2409 | #endif | ||
2410 | u->wst.ptr += 1; | ||
2411 | break; | ||
2412 | } | ||
2413 | case 0xab: /* LTH2k */ | ||
2414 | { | ||
2415 | Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)), b = (u->wst.dat[u->wst.ptr - 3] | (u->wst.dat[u->wst.ptr - 4] << 8)); | ||
2416 | u->wst.dat[u->wst.ptr] = b < a; | ||
2417 | #ifndef NO_STACK_CHECKS | ||
2418 | if(u->wst.ptr < 4) { | ||
2419 | u->wst.error = 1; | ||
2420 | goto error; | ||
2421 | } | ||
2422 | if(u->wst.ptr > 254) { | ||
2423 | u->wst.error = 2; | ||
2424 | goto error; | ||
2425 | } | ||
2426 | #endif | ||
2427 | u->wst.ptr += 1; | ||
2428 | break; | ||
2429 | } | ||
2430 | case 0xac: /* JMP2k */ | ||
2431 | { | ||
2432 | u->ram.ptr = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)); | ||
2433 | #ifndef NO_STACK_CHECKS | ||
2434 | if(u->wst.ptr < 2) { | ||
2435 | u->wst.error = 1; | ||
2436 | goto error; | ||
2437 | } | ||
2438 | #endif | ||
2439 | break; | ||
2440 | } | ||
2441 | case 0xad: /* JCN2k */ | ||
2442 | { | ||
2443 | Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)); | ||
2444 | if(u->wst.dat[u->wst.ptr - 3]) u->ram.ptr = a; | ||
2445 | #ifndef NO_STACK_CHECKS | ||
2446 | if(u->wst.ptr < 3) { | ||
2447 | u->wst.error = 1; | ||
2448 | goto error; | ||
2449 | } | ||
2450 | #endif | ||
2451 | break; | ||
2452 | } | ||
2453 | case 0xae: /* JSR2k */ | ||
2454 | { | ||
2455 | u->rst.dat[u->rst.ptr] = u->ram.ptr >> 8; | ||
2456 | u->rst.dat[u->rst.ptr + 1] = u->ram.ptr & 0xff; | ||
2457 | u->ram.ptr = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)); | ||
2458 | #ifndef NO_STACK_CHECKS | ||
2459 | if(u->wst.ptr < 2) { | ||
2460 | u->wst.error = 1; | ||
2461 | goto error; | ||
2462 | } | ||
2463 | #endif | ||
2464 | #ifndef NO_STACK_CHECKS | ||
2465 | if(u->rst.ptr > 253) { | ||
2466 | u->rst.error = 2; | ||
2467 | goto error; | ||
2468 | } | ||
2469 | #endif | ||
2470 | u->rst.ptr += 2; | ||
2471 | break; | ||
2472 | } | ||
2473 | case 0xaf: /* STH2k */ | ||
2474 | { | ||
2475 | Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)); | ||
2476 | u->rst.dat[u->rst.ptr] = a >> 8; | ||
2477 | u->rst.dat[u->rst.ptr + 1] = a & 0xff; | ||
2478 | #ifndef NO_STACK_CHECKS | ||
2479 | if(u->wst.ptr < 2) { | ||
2480 | u->wst.error = 1; | ||
2481 | goto error; | ||
2482 | } | ||
2483 | #endif | ||
2484 | #ifndef NO_STACK_CHECKS | ||
2485 | if(u->rst.ptr > 253) { | ||
2486 | u->rst.error = 2; | ||
2487 | goto error; | ||
2488 | } | ||
2489 | #endif | ||
2490 | u->rst.ptr += 2; | ||
2491 | break; | ||
2492 | } | ||
2493 | case 0xb0: /* LDZ2k */ | ||
2494 | { | ||
2495 | Uint8 a = u->wst.dat[u->wst.ptr - 1]; | ||
2496 | u->wst.dat[u->wst.ptr] = mempeek8(u->ram.dat, a); | ||
2497 | u->wst.dat[u->wst.ptr + 1] = mempeek8(u->ram.dat, a + 1); | ||
2498 | #ifndef NO_STACK_CHECKS | ||
2499 | if(u->wst.ptr < 1) { | ||
2500 | u->wst.error = 1; | ||
2501 | goto error; | ||
2502 | } | ||
2503 | if(u->wst.ptr > 253) { | ||
2504 | u->wst.error = 2; | ||
2505 | goto error; | ||
2506 | } | ||
2507 | #endif | ||
2508 | u->wst.ptr += 2; | ||
2509 | break; | ||
2510 | } | ||
2511 | case 0xb1: /* STZ2k */ | ||
2512 | { | ||
2513 | Uint8 a = u->wst.dat[u->wst.ptr - 1]; | ||
2514 | Uint16 b = (u->wst.dat[u->wst.ptr - 2] | (u->wst.dat[u->wst.ptr - 3] << 8)); | ||
2515 | mempoke16(u->ram.dat, a, b); | ||
2516 | #ifndef NO_STACK_CHECKS | ||
2517 | if(u->wst.ptr < 3) { | ||
2518 | u->wst.error = 1; | ||
2519 | goto error; | ||
2520 | } | ||
2521 | #endif | ||
2522 | break; | ||
2523 | } | ||
2524 | case 0xb2: /* LDR2k */ | ||
2525 | { | ||
2526 | Uint8 a = u->wst.dat[u->wst.ptr - 1]; | ||
2527 | u->wst.dat[u->wst.ptr] = mempeek8(u->ram.dat, u->ram.ptr + (Sint8)a); | ||
2528 | u->wst.dat[u->wst.ptr + 1] = mempeek8(u->ram.dat, u->ram.ptr + (Sint8)a + 1); | ||
2529 | #ifndef NO_STACK_CHECKS | ||
2530 | if(u->wst.ptr < 1) { | ||
2531 | u->wst.error = 1; | ||
2532 | goto error; | ||
2533 | } | ||
2534 | if(u->wst.ptr > 253) { | ||
2535 | u->wst.error = 2; | ||
2536 | goto error; | ||
2537 | } | ||
2538 | #endif | ||
2539 | u->wst.ptr += 2; | ||
2540 | break; | ||
2541 | } | ||
2542 | case 0xb3: /* STR2k */ | ||
2543 | { | ||
2544 | Uint8 a = u->wst.dat[u->wst.ptr - 1]; | ||
2545 | Uint16 b = (u->wst.dat[u->wst.ptr - 2] | (u->wst.dat[u->wst.ptr - 3] << 8)); | ||
2546 | mempoke16(u->ram.dat, u->ram.ptr + (Sint8)a, b); | ||
2547 | #ifndef NO_STACK_CHECKS | ||
2548 | if(u->wst.ptr < 3) { | ||
2549 | u->wst.error = 1; | ||
2550 | goto error; | ||
2551 | } | ||
2552 | #endif | ||
2553 | break; | ||
2554 | } | ||
2555 | case 0xb4: /* LDA2k */ | ||
2556 | { | ||
2557 | Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)); | ||
2558 | u->wst.dat[u->wst.ptr] = mempeek8(u->ram.dat, a); | ||
2559 | u->wst.dat[u->wst.ptr + 1] = mempeek8(u->ram.dat, a + 1); | ||
2560 | #ifndef NO_STACK_CHECKS | ||
2561 | if(u->wst.ptr < 2) { | ||
2562 | u->wst.error = 1; | ||
2563 | goto error; | ||
2564 | } | ||
2565 | if(u->wst.ptr > 253) { | ||
2566 | u->wst.error = 2; | ||
2567 | goto error; | ||
2568 | } | ||
2569 | #endif | ||
2570 | u->wst.ptr += 2; | ||
2571 | break; | ||
2572 | } | ||
2573 | case 0xb5: /* STA2k */ | ||
2574 | { | ||
2575 | Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)); | ||
2576 | Uint16 b = (u->wst.dat[u->wst.ptr - 3] | (u->wst.dat[u->wst.ptr - 4] << 8)); | ||
2577 | mempoke16(u->ram.dat, a, b); | ||
2578 | #ifndef NO_STACK_CHECKS | ||
2579 | if(u->wst.ptr < 4) { | ||
2580 | u->wst.error = 1; | ||
2581 | goto error; | ||
2582 | } | ||
2583 | #endif | ||
2584 | break; | ||
2585 | } | ||
2586 | case 0xb6: /* DEI2k */ | ||
2587 | { | ||
2588 | Uint8 a = u->wst.dat[u->wst.ptr - 1]; | ||
2589 | u->wst.dat[u->wst.ptr] = devpeek8(&u->dev[a >> 4], a); | ||
2590 | u->wst.dat[u->wst.ptr + 1] = devpeek8(&u->dev[a >> 4], a + 1); | ||
2591 | #ifndef NO_STACK_CHECKS | ||
2592 | if(u->wst.ptr < 1) { | ||
2593 | u->wst.error = 1; | ||
2594 | goto error; | ||
2595 | } | ||
2596 | if(u->wst.ptr > 253) { | ||
2597 | u->wst.error = 2; | ||
2598 | goto error; | ||
2599 | } | ||
2600 | #endif | ||
2601 | u->wst.ptr += 2; | ||
2602 | break; | ||
2603 | } | ||
2604 | case 0xb7: /* DEO2k */ | ||
2605 | { | ||
2606 | Uint8 a = u->wst.dat[u->wst.ptr - 1]; | ||
2607 | Uint16 b = (u->wst.dat[u->wst.ptr - 2] | (u->wst.dat[u->wst.ptr - 3] << 8)); | ||
2608 | devpoke16(&u->dev[a >> 4], a, b); | ||
2609 | #ifndef NO_STACK_CHECKS | ||
2610 | if(u->wst.ptr < 3) { | ||
2611 | u->wst.error = 1; | ||
2612 | goto error; | ||
2613 | } | ||
2614 | #endif | ||
2615 | break; | ||
2616 | } | ||
2617 | case 0xb8: /* ADD2k */ | ||
2618 | { | ||
2619 | Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)), b = (u->wst.dat[u->wst.ptr - 3] | (u->wst.dat[u->wst.ptr - 4] << 8)); | ||
2620 | u->wst.dat[u->wst.ptr] = (b + a) >> 8; | ||
2621 | u->wst.dat[u->wst.ptr + 1] = (b + a) & 0xff; | ||
2622 | #ifndef NO_STACK_CHECKS | ||
2623 | if(u->wst.ptr < 4) { | ||
2624 | u->wst.error = 1; | ||
2625 | goto error; | ||
2626 | } | ||
2627 | if(u->wst.ptr > 253) { | ||
2628 | u->wst.error = 2; | ||
2629 | goto error; | ||
2630 | } | ||
2631 | #endif | ||
2632 | u->wst.ptr += 2; | ||
2633 | break; | ||
2634 | } | ||
2635 | case 0xb9: /* SUB2k */ | ||
2636 | { | ||
2637 | Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)), b = (u->wst.dat[u->wst.ptr - 3] | (u->wst.dat[u->wst.ptr - 4] << 8)); | ||
2638 | u->wst.dat[u->wst.ptr] = (b - a) >> 8; | ||
2639 | u->wst.dat[u->wst.ptr + 1] = (b - a) & 0xff; | ||
2640 | #ifndef NO_STACK_CHECKS | ||
2641 | if(u->wst.ptr < 4) { | ||
2642 | u->wst.error = 1; | ||
2643 | goto error; | ||
2644 | } | ||
2645 | if(u->wst.ptr > 253) { | ||
2646 | u->wst.error = 2; | ||
2647 | goto error; | ||
2648 | } | ||
2649 | #endif | ||
2650 | u->wst.ptr += 2; | ||
2651 | break; | ||
2652 | } | ||
2653 | case 0xba: /* MUL2k */ | ||
2654 | { | ||
2655 | Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)), b = (u->wst.dat[u->wst.ptr - 3] | (u->wst.dat[u->wst.ptr - 4] << 8)); | ||
2656 | u->wst.dat[u->wst.ptr] = (b * a) >> 8; | ||
2657 | u->wst.dat[u->wst.ptr + 1] = (b * a) & 0xff; | ||
2658 | #ifndef NO_STACK_CHECKS | ||
2659 | if(u->wst.ptr < 4) { | ||
2660 | u->wst.error = 1; | ||
2661 | goto error; | ||
2662 | } | ||
2663 | if(u->wst.ptr > 253) { | ||
2664 | u->wst.error = 2; | ||
2665 | goto error; | ||
2666 | } | ||
2667 | #endif | ||
2668 | u->wst.ptr += 2; | ||
2669 | break; | ||
2670 | } | ||
2671 | case 0xbb: /* DIV2k */ | ||
2672 | { | ||
2673 | Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)), b = (u->wst.dat[u->wst.ptr - 3] | (u->wst.dat[u->wst.ptr - 4] << 8)); | ||
2674 | u->wst.dat[u->wst.ptr] = (b / a) >> 8; | ||
2675 | u->wst.dat[u->wst.ptr + 1] = (b / a) & 0xff; | ||
2676 | #ifndef NO_STACK_CHECKS | ||
2677 | if(u->wst.ptr < 4) { | ||
2678 | u->wst.error = 1; | ||
2679 | goto error; | ||
2680 | } | ||
2681 | if(u->wst.ptr > 253) { | ||
2682 | u->wst.error = 2; | ||
2683 | goto error; | ||
2684 | } | ||
2685 | #endif | ||
2686 | u->wst.ptr += 2; | ||
2687 | break; | ||
2688 | } | ||
2689 | case 0xbc: /* AND2k */ | ||
2690 | { | ||
2691 | Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2], c = u->wst.dat[u->wst.ptr - 3], d = u->wst.dat[u->wst.ptr - 4]; | ||
2692 | u->wst.dat[u->wst.ptr] = d & b; | ||
2693 | u->wst.dat[u->wst.ptr + 1] = c & a; | ||
2694 | #ifndef NO_STACK_CHECKS | ||
2695 | if(u->wst.ptr < 4) { | ||
2696 | u->wst.error = 1; | ||
2697 | goto error; | ||
2698 | } | ||
2699 | if(u->wst.ptr > 253) { | ||
2700 | u->wst.error = 2; | ||
2701 | goto error; | ||
2702 | } | ||
2703 | #endif | ||
2704 | u->wst.ptr += 2; | ||
2705 | break; | ||
2706 | } | ||
2707 | case 0xbd: /* ORA2k */ | ||
2708 | { | ||
2709 | Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2], c = u->wst.dat[u->wst.ptr - 3], d = u->wst.dat[u->wst.ptr - 4]; | ||
2710 | u->wst.dat[u->wst.ptr] = d | b; | ||
2711 | u->wst.dat[u->wst.ptr + 1] = c | a; | ||
2712 | #ifndef NO_STACK_CHECKS | ||
2713 | if(u->wst.ptr < 4) { | ||
2714 | u->wst.error = 1; | ||
2715 | goto error; | ||
2716 | } | ||
2717 | if(u->wst.ptr > 253) { | ||
2718 | u->wst.error = 2; | ||
2719 | goto error; | ||
2720 | } | ||
2721 | #endif | ||
2722 | u->wst.ptr += 2; | ||
2723 | break; | ||
2724 | } | ||
2725 | case 0xbe: /* EOR2k */ | ||
2726 | { | ||
2727 | Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2], c = u->wst.dat[u->wst.ptr - 3], d = u->wst.dat[u->wst.ptr - 4]; | ||
2728 | u->wst.dat[u->wst.ptr] = d ^ b; | ||
2729 | u->wst.dat[u->wst.ptr + 1] = c ^ a; | ||
2730 | #ifndef NO_STACK_CHECKS | ||
2731 | if(u->wst.ptr < 4) { | ||
2732 | u->wst.error = 1; | ||
2733 | goto error; | ||
2734 | } | ||
2735 | if(u->wst.ptr > 253) { | ||
2736 | u->wst.error = 2; | ||
2737 | goto error; | ||
2738 | } | ||
2739 | #endif | ||
2740 | u->wst.ptr += 2; | ||
2741 | break; | ||
2742 | } | ||
2743 | case 0xbf: /* SFT2k */ | ||
2744 | { | ||
2745 | Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)), b = (u->wst.dat[u->wst.ptr - 3] | (u->wst.dat[u->wst.ptr - 4] << 8)); | ||
2746 | u->wst.dat[u->wst.ptr] = (b >> (a & 0x000f) << ((a & 0x00f0) >> 4)) >> 8; | ||
2747 | u->wst.dat[u->wst.ptr + 1] = (b >> (a & 0x000f) << ((a & 0x00f0) >> 4)) & 0xff; | ||
2748 | #ifndef NO_STACK_CHECKS | ||
2749 | if(u->wst.ptr < 4) { | ||
2750 | u->wst.error = 1; | ||
2751 | goto error; | ||
2752 | } | ||
2753 | if(u->wst.ptr > 253) { | ||
2754 | u->wst.error = 2; | ||
2755 | goto error; | ||
2756 | } | ||
2757 | #endif | ||
2758 | u->wst.ptr += 2; | ||
2759 | break; | ||
2760 | } | ||
2761 | case 0xc3: /* POPkr */ | ||
2762 | { | ||
2763 | u->rst.dat[u->rst.ptr - 1]; | ||
2764 | #ifndef NO_STACK_CHECKS | ||
2765 | if(u->rst.ptr < 1) { | ||
2766 | u->rst.error = 1; | ||
2767 | goto error; | ||
2768 | } | ||
2769 | #endif | ||
2770 | break; | ||
2771 | } | ||
2772 | case 0xc4: /* DUPkr */ | ||
2773 | { | ||
2774 | Uint8 a = u->rst.dat[u->rst.ptr - 1]; | ||
2775 | u->rst.dat[u->rst.ptr] = a; | ||
2776 | u->rst.dat[u->rst.ptr + 1] = a; | ||
2777 | #ifndef NO_STACK_CHECKS | ||
2778 | if(u->rst.ptr < 1) { | ||
2779 | u->rst.error = 1; | ||
2780 | goto error; | ||
2781 | } | ||
2782 | if(u->rst.ptr > 253) { | ||
2783 | u->rst.error = 2; | ||
2784 | goto error; | ||
2785 | } | ||
2786 | #endif | ||
2787 | u->rst.ptr += 2; | ||
2788 | break; | ||
2789 | } | ||
2790 | case 0xc5: /* SWPkr */ | ||
2791 | { | ||
2792 | Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; | ||
2793 | u->rst.dat[u->rst.ptr] = a; | ||
2794 | u->rst.dat[u->rst.ptr + 1] = b; | ||
2795 | #ifndef NO_STACK_CHECKS | ||
2796 | if(u->rst.ptr < 2) { | ||
2797 | u->rst.error = 1; | ||
2798 | goto error; | ||
2799 | } | ||
2800 | if(u->rst.ptr > 253) { | ||
2801 | u->rst.error = 2; | ||
2802 | goto error; | ||
2803 | } | ||
2804 | #endif | ||
2805 | u->rst.ptr += 2; | ||
2806 | break; | ||
2807 | } | ||
2808 | case 0xc6: /* OVRkr */ | ||
2809 | { | ||
2810 | Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; | ||
2811 | u->rst.dat[u->rst.ptr] = b; | ||
2812 | u->rst.dat[u->rst.ptr + 1] = a; | ||
2813 | u->rst.dat[u->rst.ptr + 2] = b; | ||
2814 | #ifndef NO_STACK_CHECKS | ||
2815 | if(u->rst.ptr < 2) { | ||
2816 | u->rst.error = 1; | ||
2817 | goto error; | ||
2818 | } | ||
2819 | if(u->rst.ptr > 252) { | ||
2820 | u->rst.error = 2; | ||
2821 | goto error; | ||
2822 | } | ||
2823 | #endif | ||
2824 | u->rst.ptr += 3; | ||
2825 | break; | ||
2826 | } | ||
2827 | case 0xc7: /* ROTkr */ | ||
2828 | { | ||
2829 | Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2], c = u->rst.dat[u->rst.ptr - 3]; | ||
2830 | u->rst.dat[u->rst.ptr] = b; | ||
2831 | u->rst.dat[u->rst.ptr + 1] = a; | ||
2832 | u->rst.dat[u->rst.ptr + 2] = c; | ||
2833 | #ifndef NO_STACK_CHECKS | ||
2834 | if(u->rst.ptr < 3) { | ||
2835 | u->rst.error = 1; | ||
2836 | goto error; | ||
2837 | } | ||
2838 | if(u->rst.ptr > 252) { | ||
2839 | u->rst.error = 2; | ||
2840 | goto error; | ||
2841 | } | ||
2842 | #endif | ||
2843 | u->rst.ptr += 3; | ||
2844 | break; | ||
2845 | } | ||
2846 | case 0xc8: /* EQUkr */ | ||
2847 | { | ||
2848 | Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; | ||
2849 | u->rst.dat[u->rst.ptr] = b == a; | ||
2850 | #ifndef NO_STACK_CHECKS | ||
2851 | if(u->rst.ptr < 2) { | ||
2852 | u->rst.error = 1; | ||
2853 | goto error; | ||
2854 | } | ||
2855 | if(u->rst.ptr > 254) { | ||
2856 | u->rst.error = 2; | ||
2857 | goto error; | ||
2858 | } | ||
2859 | #endif | ||
2860 | u->rst.ptr += 1; | ||
2861 | break; | ||
2862 | } | ||
2863 | case 0xc9: /* NEQkr */ | ||
2864 | { | ||
2865 | Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; | ||
2866 | u->rst.dat[u->rst.ptr] = b != a; | ||
2867 | #ifndef NO_STACK_CHECKS | ||
2868 | if(u->rst.ptr < 2) { | ||
2869 | u->rst.error = 1; | ||
2870 | goto error; | ||
2871 | } | ||
2872 | if(u->rst.ptr > 254) { | ||
2873 | u->rst.error = 2; | ||
2874 | goto error; | ||
2875 | } | ||
2876 | #endif | ||
2877 | u->rst.ptr += 1; | ||
2878 | break; | ||
2879 | } | ||
2880 | case 0xca: /* GTHkr */ | ||
2881 | { | ||
2882 | Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; | ||
2883 | u->rst.dat[u->rst.ptr] = b > a; | ||
2884 | #ifndef NO_STACK_CHECKS | ||
2885 | if(u->rst.ptr < 2) { | ||
2886 | u->rst.error = 1; | ||
2887 | goto error; | ||
2888 | } | ||
2889 | if(u->rst.ptr > 254) { | ||
2890 | u->rst.error = 2; | ||
2891 | goto error; | ||
2892 | } | ||
2893 | #endif | ||
2894 | u->rst.ptr += 1; | ||
2895 | break; | ||
2896 | } | ||
2897 | case 0xcb: /* LTHkr */ | ||
2898 | { | ||
2899 | Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; | ||
2900 | u->rst.dat[u->rst.ptr] = b < a; | ||
2901 | #ifndef NO_STACK_CHECKS | ||
2902 | if(u->rst.ptr < 2) { | ||
2903 | u->rst.error = 1; | ||
2904 | goto error; | ||
2905 | } | ||
2906 | if(u->rst.ptr > 254) { | ||
2907 | u->rst.error = 2; | ||
2908 | goto error; | ||
2909 | } | ||
2910 | #endif | ||
2911 | u->rst.ptr += 1; | ||
2912 | break; | ||
2913 | } | ||
2914 | case 0xcc: /* JMPkr */ | ||
2915 | { | ||
2916 | Uint8 a = u->rst.dat[u->rst.ptr - 1]; | ||
2917 | u->ram.ptr += (Sint8)a; | ||
2918 | #ifndef NO_STACK_CHECKS | ||
2919 | if(u->rst.ptr < 1) { | ||
2920 | u->rst.error = 1; | ||
2921 | goto error; | ||
2922 | } | ||
2923 | #endif | ||
2924 | break; | ||
2925 | } | ||
2926 | case 0xcd: /* JCNkr */ | ||
2927 | { | ||
2928 | Uint8 a = u->rst.dat[u->rst.ptr - 1]; | ||
2929 | if(u->rst.dat[u->rst.ptr - 2]) u->ram.ptr += (Sint8)a; | ||
2930 | #ifndef NO_STACK_CHECKS | ||
2931 | if(u->rst.ptr < 2) { | ||
2932 | u->rst.error = 1; | ||
2933 | goto error; | ||
2934 | } | ||
2935 | #endif | ||
2936 | break; | ||
2937 | } | ||
2938 | case 0xce: /* JSRkr */ | ||
2939 | { | ||
2940 | Uint8 a = u->rst.dat[u->rst.ptr - 1]; | ||
2941 | u->wst.dat[u->wst.ptr] = u->ram.ptr >> 8; | ||
2942 | u->wst.dat[u->wst.ptr + 1] = u->ram.ptr & 0xff; | ||
2943 | u->ram.ptr += (Sint8)a; | ||
2944 | #ifndef NO_STACK_CHECKS | ||
2945 | if(u->rst.ptr < 1) { | ||
2946 | u->rst.error = 1; | ||
2947 | goto error; | ||
2948 | } | ||
2949 | #endif | ||
2950 | #ifndef NO_STACK_CHECKS | ||
2951 | if(u->wst.ptr > 253) { | ||
2952 | u->wst.error = 2; | ||
2953 | goto error; | ||
2954 | } | ||
2955 | #endif | ||
2956 | u->wst.ptr += 2; | ||
2957 | break; | ||
2958 | } | ||
2959 | case 0xcf: /* STHkr */ | ||
2960 | { | ||
2961 | Uint8 a = u->rst.dat[u->rst.ptr - 1]; | ||
2962 | u->wst.dat[u->wst.ptr] = a; | ||
2963 | #ifndef NO_STACK_CHECKS | ||
2964 | if(u->rst.ptr < 1) { | ||
2965 | u->rst.error = 1; | ||
2966 | goto error; | ||
2967 | } | ||
2968 | #endif | ||
2969 | #ifndef NO_STACK_CHECKS | ||
2970 | if(u->wst.ptr > 254) { | ||
2971 | u->wst.error = 2; | ||
2972 | goto error; | ||
2973 | } | ||
2974 | #endif | ||
2975 | u->wst.ptr += 1; | ||
2976 | break; | ||
2977 | } | ||
2978 | case 0xd0: /* LDZkr */ | ||
2979 | { | ||
2980 | Uint8 a = u->rst.dat[u->rst.ptr - 1]; | ||
2981 | u->rst.dat[u->rst.ptr] = mempeek8(u->ram.dat, a); | ||
2982 | #ifndef NO_STACK_CHECKS | ||
2983 | if(u->rst.ptr < 1) { | ||
2984 | u->rst.error = 1; | ||
2985 | goto error; | ||
2986 | } | ||
2987 | if(u->rst.ptr > 254) { | ||
2988 | u->rst.error = 2; | ||
2989 | goto error; | ||
2990 | } | ||
2991 | #endif | ||
2992 | u->rst.ptr += 1; | ||
2993 | break; | ||
2994 | } | ||
2995 | case 0xd1: /* STZkr */ | ||
2996 | { | ||
2997 | Uint8 a = u->rst.dat[u->rst.ptr - 1]; | ||
2998 | Uint8 b = u->rst.dat[u->rst.ptr - 2]; | ||
2999 | mempoke8(u->ram.dat, a, b); | ||
3000 | #ifndef NO_STACK_CHECKS | ||
3001 | if(u->rst.ptr < 2) { | ||
3002 | u->rst.error = 1; | ||
3003 | goto error; | ||
3004 | } | ||
3005 | #endif | ||
3006 | break; | ||
3007 | } | ||
3008 | case 0xd2: /* LDRkr */ | ||
3009 | { | ||
3010 | Uint8 a = u->rst.dat[u->rst.ptr - 1]; | ||
3011 | u->rst.dat[u->rst.ptr] = mempeek8(u->ram.dat, u->ram.ptr + (Sint8)a); | ||
3012 | #ifndef NO_STACK_CHECKS | ||
3013 | if(u->rst.ptr < 1) { | ||
3014 | u->rst.error = 1; | ||
3015 | goto error; | ||
3016 | } | ||
3017 | if(u->rst.ptr > 254) { | ||
3018 | u->rst.error = 2; | ||
3019 | goto error; | ||
3020 | } | ||
3021 | #endif | ||
3022 | u->rst.ptr += 1; | ||
3023 | break; | ||
3024 | } | ||
3025 | case 0xd3: /* STRkr */ | ||
3026 | { | ||
3027 | Uint8 a = u->rst.dat[u->rst.ptr - 1]; | ||
3028 | Uint8 b = u->rst.dat[u->rst.ptr - 2]; | ||
3029 | mempoke8(u->ram.dat, u->ram.ptr + (Sint8)a, b); | ||
3030 | #ifndef NO_STACK_CHECKS | ||
3031 | if(u->rst.ptr < 2) { | ||
3032 | u->rst.error = 1; | ||
3033 | goto error; | ||
3034 | } | ||
3035 | #endif | ||
3036 | break; | ||
3037 | } | ||
3038 | case 0xd4: /* LDAkr */ | ||
3039 | { | ||
3040 | Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)); | ||
3041 | u->rst.dat[u->rst.ptr] = mempeek8(u->ram.dat, a); | ||
3042 | #ifndef NO_STACK_CHECKS | ||
3043 | if(u->rst.ptr < 2) { | ||
3044 | u->rst.error = 1; | ||
3045 | goto error; | ||
3046 | } | ||
3047 | if(u->rst.ptr > 254) { | ||
3048 | u->rst.error = 2; | ||
3049 | goto error; | ||
3050 | } | ||
3051 | #endif | ||
3052 | u->rst.ptr += 1; | ||
3053 | break; | ||
3054 | } | ||
3055 | case 0xd5: /* STAkr */ | ||
3056 | { | ||
3057 | Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)); | ||
3058 | Uint8 b = u->rst.dat[u->rst.ptr - 3]; | ||
3059 | mempoke8(u->ram.dat, a, b); | ||
3060 | #ifndef NO_STACK_CHECKS | ||
3061 | if(u->rst.ptr < 3) { | ||
3062 | u->rst.error = 1; | ||
3063 | goto error; | ||
3064 | } | ||
3065 | #endif | ||
3066 | break; | ||
3067 | } | ||
3068 | case 0xd6: /* DEIkr */ | ||
3069 | { | ||
3070 | Uint8 a = u->rst.dat[u->rst.ptr - 1]; | ||
3071 | u->rst.dat[u->rst.ptr] = devpeek8(&u->dev[a >> 4], a); | ||
3072 | #ifndef NO_STACK_CHECKS | ||
3073 | if(u->rst.ptr < 1) { | ||
3074 | u->rst.error = 1; | ||
3075 | goto error; | ||
3076 | } | ||
3077 | if(u->rst.ptr > 254) { | ||
3078 | u->rst.error = 2; | ||
3079 | goto error; | ||
3080 | } | ||
3081 | #endif | ||
3082 | u->rst.ptr += 1; | ||
3083 | break; | ||
3084 | } | ||
3085 | case 0xd7: /* DEOkr */ | ||
3086 | { | ||
3087 | Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; | ||
3088 | devpoke8(&u->dev[a >> 4], a, b); | ||
3089 | #ifndef NO_STACK_CHECKS | ||
3090 | if(u->rst.ptr < 2) { | ||
3091 | u->rst.error = 1; | ||
3092 | goto error; | ||
3093 | } | ||
3094 | #endif | ||
3095 | break; | ||
3096 | } | ||
3097 | case 0xd8: /* ADDkr */ | ||
3098 | { | ||
3099 | Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; | ||
3100 | u->rst.dat[u->rst.ptr] = b + a; | ||
3101 | #ifndef NO_STACK_CHECKS | ||
3102 | if(u->rst.ptr < 2) { | ||
3103 | u->rst.error = 1; | ||
3104 | goto error; | ||
3105 | } | ||
3106 | if(u->rst.ptr > 254) { | ||
3107 | u->rst.error = 2; | ||
3108 | goto error; | ||
3109 | } | ||
3110 | #endif | ||
3111 | u->rst.ptr += 1; | ||
3112 | break; | ||
3113 | } | ||
3114 | case 0xd9: /* SUBkr */ | ||
3115 | { | ||
3116 | Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; | ||
3117 | u->rst.dat[u->rst.ptr] = b - a; | ||
3118 | #ifndef NO_STACK_CHECKS | ||
3119 | if(u->rst.ptr < 2) { | ||
3120 | u->rst.error = 1; | ||
3121 | goto error; | ||
3122 | } | ||
3123 | if(u->rst.ptr > 254) { | ||
3124 | u->rst.error = 2; | ||
3125 | goto error; | ||
3126 | } | ||
3127 | #endif | ||
3128 | u->rst.ptr += 1; | ||
3129 | break; | ||
3130 | } | ||
3131 | case 0xda: /* MULkr */ | ||
3132 | { | ||
3133 | Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; | ||
3134 | u->rst.dat[u->rst.ptr] = b * a; | ||
3135 | #ifndef NO_STACK_CHECKS | ||
3136 | if(u->rst.ptr < 2) { | ||
3137 | u->rst.error = 1; | ||
3138 | goto error; | ||
3139 | } | ||
3140 | if(u->rst.ptr > 254) { | ||
3141 | u->rst.error = 2; | ||
3142 | goto error; | ||
3143 | } | ||
3144 | #endif | ||
3145 | u->rst.ptr += 1; | ||
3146 | break; | ||
3147 | } | ||
3148 | case 0xdb: /* DIVkr */ | ||
3149 | { | ||
3150 | Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; | ||
3151 | u->rst.dat[u->rst.ptr] = b / a; | ||
3152 | #ifndef NO_STACK_CHECKS | ||
3153 | if(u->rst.ptr < 2) { | ||
3154 | u->rst.error = 1; | ||
3155 | goto error; | ||
3156 | } | ||
3157 | if(u->rst.ptr > 254) { | ||
3158 | u->rst.error = 2; | ||
3159 | goto error; | ||
3160 | } | ||
3161 | #endif | ||
3162 | u->rst.ptr += 1; | ||
3163 | break; | ||
3164 | } | ||
3165 | case 0xdc: /* ANDkr */ | ||
3166 | { | ||
3167 | Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; | ||
3168 | u->rst.dat[u->rst.ptr] = b & a; | ||
3169 | #ifndef NO_STACK_CHECKS | ||
3170 | if(u->rst.ptr < 2) { | ||
3171 | u->rst.error = 1; | ||
3172 | goto error; | ||
3173 | } | ||
3174 | if(u->rst.ptr > 254) { | ||
3175 | u->rst.error = 2; | ||
3176 | goto error; | ||
3177 | } | ||
3178 | #endif | ||
3179 | u->rst.ptr += 1; | ||
3180 | break; | ||
3181 | } | ||
3182 | case 0xdd: /* ORAkr */ | ||
3183 | { | ||
3184 | Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; | ||
3185 | u->rst.dat[u->rst.ptr] = b | a; | ||
3186 | #ifndef NO_STACK_CHECKS | ||
3187 | if(u->rst.ptr < 2) { | ||
3188 | u->rst.error = 1; | ||
3189 | goto error; | ||
3190 | } | ||
3191 | if(u->rst.ptr > 254) { | ||
3192 | u->rst.error = 2; | ||
3193 | goto error; | ||
3194 | } | ||
3195 | #endif | ||
3196 | u->rst.ptr += 1; | ||
3197 | break; | ||
3198 | } | ||
3199 | case 0xde: /* EORkr */ | ||
3200 | { | ||
3201 | Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; | ||
3202 | u->rst.dat[u->rst.ptr] = b ^ a; | ||
3203 | #ifndef NO_STACK_CHECKS | ||
3204 | if(u->rst.ptr < 2) { | ||
3205 | u->rst.error = 1; | ||
3206 | goto error; | ||
3207 | } | ||
3208 | if(u->rst.ptr > 254) { | ||
3209 | u->rst.error = 2; | ||
3210 | goto error; | ||
3211 | } | ||
3212 | #endif | ||
3213 | u->rst.ptr += 1; | ||
3214 | break; | ||
3215 | } | ||
3216 | case 0xdf: /* SFTkr */ | ||
3217 | { | ||
3218 | Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; | ||
3219 | u->rst.dat[u->rst.ptr] = b >> (a & 0x07) << ((a & 0x70) >> 4); | ||
3220 | #ifndef NO_STACK_CHECKS | ||
3221 | if(u->rst.ptr < 2) { | ||
3222 | u->rst.error = 1; | ||
3223 | goto error; | ||
3224 | } | ||
3225 | if(u->rst.ptr > 254) { | ||
3226 | u->rst.error = 2; | ||
3227 | goto error; | ||
3228 | } | ||
3229 | #endif | ||
3230 | u->rst.ptr += 1; | ||
3231 | break; | ||
3232 | } | ||
3233 | case 0xe3: /* POP2kr */ | ||
3234 | { | ||
3235 | (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)); | ||
3236 | #ifndef NO_STACK_CHECKS | ||
3237 | if(u->rst.ptr < 2) { | ||
3238 | u->rst.error = 1; | ||
3239 | goto error; | ||
3240 | } | ||
3241 | #endif | ||
3242 | break; | ||
3243 | } | ||
3244 | case 0xe4: /* DUP2kr */ | ||
3245 | { | ||
3246 | Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)); | ||
3247 | u->rst.dat[u->rst.ptr] = a >> 8; | ||
3248 | u->rst.dat[u->rst.ptr + 1] = a & 0xff; | ||
3249 | u->rst.dat[u->rst.ptr + 2] = a >> 8; | ||
3250 | u->rst.dat[u->rst.ptr + 3] = a & 0xff; | ||
3251 | #ifndef NO_STACK_CHECKS | ||
3252 | if(u->rst.ptr < 2) { | ||
3253 | u->rst.error = 1; | ||
3254 | goto error; | ||
3255 | } | ||
3256 | if(u->rst.ptr > 251) { | ||
3257 | u->rst.error = 2; | ||
3258 | goto error; | ||
3259 | } | ||
3260 | #endif | ||
3261 | u->rst.ptr += 4; | ||
3262 | break; | ||
3263 | } | ||
3264 | case 0xe5: /* SWP2kr */ | ||
3265 | { | ||
3266 | Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)), b = (u->rst.dat[u->rst.ptr - 3] | (u->rst.dat[u->rst.ptr - 4] << 8)); | ||
3267 | u->rst.dat[u->rst.ptr] = a >> 8; | ||
3268 | u->rst.dat[u->rst.ptr + 1] = a & 0xff; | ||
3269 | u->rst.dat[u->rst.ptr + 2] = b >> 8; | ||
3270 | u->rst.dat[u->rst.ptr + 3] = b & 0xff; | ||
3271 | #ifndef NO_STACK_CHECKS | ||
3272 | if(u->rst.ptr < 4) { | ||
3273 | u->rst.error = 1; | ||
3274 | goto error; | ||
3275 | } | ||
3276 | if(u->rst.ptr > 251) { | ||
3277 | u->rst.error = 2; | ||
3278 | goto error; | ||
3279 | } | ||
3280 | #endif | ||
3281 | u->rst.ptr += 4; | ||
3282 | break; | ||
3283 | } | ||
3284 | case 0xe6: /* OVR2kr */ | ||
3285 | { | ||
3286 | Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)), b = (u->rst.dat[u->rst.ptr - 3] | (u->rst.dat[u->rst.ptr - 4] << 8)); | ||
3287 | u->rst.dat[u->rst.ptr] = b >> 8; | ||
3288 | u->rst.dat[u->rst.ptr + 1] = b & 0xff; | ||
3289 | u->rst.dat[u->rst.ptr + 2] = a >> 8; | ||
3290 | u->rst.dat[u->rst.ptr + 3] = a & 0xff; | ||
3291 | u->rst.dat[u->rst.ptr + 4] = b >> 8; | ||
3292 | u->rst.dat[u->rst.ptr + 5] = b & 0xff; | ||
3293 | #ifndef NO_STACK_CHECKS | ||
3294 | if(u->rst.ptr < 4) { | ||
3295 | u->rst.error = 1; | ||
3296 | goto error; | ||
3297 | } | ||
3298 | if(u->rst.ptr > 249) { | ||
3299 | u->rst.error = 2; | ||
3300 | goto error; | ||
3301 | } | ||
3302 | #endif | ||
3303 | u->rst.ptr += 6; | ||
3304 | break; | ||
3305 | } | ||
3306 | case 0xe7: /* ROT2kr */ | ||
3307 | { | ||
3308 | Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)), b = (u->rst.dat[u->rst.ptr - 3] | (u->rst.dat[u->rst.ptr - 4] << 8)), c = (u->rst.dat[u->rst.ptr - 5] | (u->rst.dat[u->rst.ptr - 6] << 8)); | ||
3309 | u->rst.dat[u->rst.ptr] = b >> 8; | ||
3310 | u->rst.dat[u->rst.ptr + 1] = b & 0xff; | ||
3311 | u->rst.dat[u->rst.ptr + 2] = a >> 8; | ||
3312 | u->rst.dat[u->rst.ptr + 3] = a & 0xff; | ||
3313 | u->rst.dat[u->rst.ptr + 4] = c >> 8; | ||
3314 | u->rst.dat[u->rst.ptr + 5] = c & 0xff; | ||
3315 | #ifndef NO_STACK_CHECKS | ||
3316 | if(u->rst.ptr < 6) { | ||
3317 | u->rst.error = 1; | ||
3318 | goto error; | ||
3319 | } | ||
3320 | if(u->rst.ptr > 249) { | ||
3321 | u->rst.error = 2; | ||
3322 | goto error; | ||
3323 | } | ||
3324 | #endif | ||
3325 | u->rst.ptr += 6; | ||
3326 | break; | ||
3327 | } | ||
3328 | case 0xe8: /* EQU2kr */ | ||
3329 | { | ||
3330 | Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)), b = (u->rst.dat[u->rst.ptr - 3] | (u->rst.dat[u->rst.ptr - 4] << 8)); | ||
3331 | u->rst.dat[u->rst.ptr] = b == a; | ||
3332 | #ifndef NO_STACK_CHECKS | ||
3333 | if(u->rst.ptr < 4) { | ||
3334 | u->rst.error = 1; | ||
3335 | goto error; | ||
3336 | } | ||
3337 | if(u->rst.ptr > 254) { | ||
3338 | u->rst.error = 2; | ||
3339 | goto error; | ||
3340 | } | ||
3341 | #endif | ||
3342 | u->rst.ptr += 1; | ||
3343 | break; | ||
3344 | } | ||
3345 | case 0xe9: /* NEQ2kr */ | ||
3346 | { | ||
3347 | Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)), b = (u->rst.dat[u->rst.ptr - 3] | (u->rst.dat[u->rst.ptr - 4] << 8)); | ||
3348 | u->rst.dat[u->rst.ptr] = b != a; | ||
3349 | #ifndef NO_STACK_CHECKS | ||
3350 | if(u->rst.ptr < 4) { | ||
3351 | u->rst.error = 1; | ||
3352 | goto error; | ||
3353 | } | ||
3354 | if(u->rst.ptr > 254) { | ||
3355 | u->rst.error = 2; | ||
3356 | goto error; | ||
3357 | } | ||
3358 | #endif | ||
3359 | u->rst.ptr += 1; | ||
3360 | break; | ||
3361 | } | ||
3362 | case 0xea: /* GTH2kr */ | ||
3363 | { | ||
3364 | Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)), b = (u->rst.dat[u->rst.ptr - 3] | (u->rst.dat[u->rst.ptr - 4] << 8)); | ||
3365 | u->rst.dat[u->rst.ptr] = b > a; | ||
3366 | #ifndef NO_STACK_CHECKS | ||
3367 | if(u->rst.ptr < 4) { | ||
3368 | u->rst.error = 1; | ||
3369 | goto error; | ||
3370 | } | ||
3371 | if(u->rst.ptr > 254) { | ||
3372 | u->rst.error = 2; | ||
3373 | goto error; | ||
3374 | } | ||
3375 | #endif | ||
3376 | u->rst.ptr += 1; | ||
3377 | break; | ||
3378 | } | ||
3379 | case 0xeb: /* LTH2kr */ | ||
3380 | { | ||
3381 | Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)), b = (u->rst.dat[u->rst.ptr - 3] | (u->rst.dat[u->rst.ptr - 4] << 8)); | ||
3382 | u->rst.dat[u->rst.ptr] = b < a; | ||
3383 | #ifndef NO_STACK_CHECKS | ||
3384 | if(u->rst.ptr < 4) { | ||
3385 | u->rst.error = 1; | ||
3386 | goto error; | ||
3387 | } | ||
3388 | if(u->rst.ptr > 254) { | ||
3389 | u->rst.error = 2; | ||
3390 | goto error; | ||
3391 | } | ||
3392 | #endif | ||
3393 | u->rst.ptr += 1; | ||
3394 | break; | ||
3395 | } | ||
3396 | case 0xec: /* JMP2kr */ | ||
3397 | { | ||
3398 | u->ram.ptr = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)); | ||
3399 | #ifndef NO_STACK_CHECKS | ||
3400 | if(u->rst.ptr < 2) { | ||
3401 | u->rst.error = 1; | ||
3402 | goto error; | ||
3403 | } | ||
3404 | #endif | ||
3405 | break; | ||
3406 | } | ||
3407 | case 0xed: /* JCN2kr */ | ||
3408 | { | ||
3409 | Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)); | ||
3410 | if(u->rst.dat[u->rst.ptr - 3]) u->ram.ptr = a; | ||
3411 | #ifndef NO_STACK_CHECKS | ||
3412 | if(u->rst.ptr < 3) { | ||
3413 | u->rst.error = 1; | ||
3414 | goto error; | ||
3415 | } | ||
3416 | #endif | ||
3417 | break; | ||
3418 | } | ||
3419 | case 0xee: /* JSR2kr */ | ||
3420 | { | ||
3421 | u->wst.dat[u->wst.ptr] = u->ram.ptr >> 8; | ||
3422 | u->wst.dat[u->wst.ptr + 1] = u->ram.ptr & 0xff; | ||
3423 | u->ram.ptr = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)); | ||
3424 | #ifndef NO_STACK_CHECKS | ||
3425 | if(u->rst.ptr < 2) { | ||
3426 | u->rst.error = 1; | ||
3427 | goto error; | ||
3428 | } | ||
3429 | #endif | ||
3430 | #ifndef NO_STACK_CHECKS | ||
3431 | if(u->wst.ptr > 253) { | ||
3432 | u->wst.error = 2; | ||
3433 | goto error; | ||
3434 | } | ||
3435 | #endif | ||
3436 | u->wst.ptr += 2; | ||
3437 | break; | ||
3438 | } | ||
3439 | case 0xef: /* STH2kr */ | ||
3440 | { | ||
3441 | Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)); | ||
3442 | u->wst.dat[u->wst.ptr] = a >> 8; | ||
3443 | u->wst.dat[u->wst.ptr + 1] = a & 0xff; | ||
3444 | #ifndef NO_STACK_CHECKS | ||
3445 | if(u->rst.ptr < 2) { | ||
3446 | u->rst.error = 1; | ||
3447 | goto error; | ||
3448 | } | ||
3449 | #endif | ||
3450 | #ifndef NO_STACK_CHECKS | ||
3451 | if(u->wst.ptr > 253) { | ||
3452 | u->wst.error = 2; | ||
3453 | goto error; | ||
3454 | } | ||
3455 | #endif | ||
3456 | u->wst.ptr += 2; | ||
3457 | break; | ||
3458 | } | ||
3459 | case 0xf0: /* LDZ2kr */ | ||
3460 | { | ||
3461 | Uint8 a = u->rst.dat[u->rst.ptr - 1]; | ||
3462 | u->rst.dat[u->rst.ptr] = mempeek8(u->ram.dat, a); | ||
3463 | u->rst.dat[u->rst.ptr + 1] = mempeek8(u->ram.dat, a + 1); | ||
3464 | #ifndef NO_STACK_CHECKS | ||
3465 | if(u->rst.ptr < 1) { | ||
3466 | u->rst.error = 1; | ||
3467 | goto error; | ||
3468 | } | ||
3469 | if(u->rst.ptr > 253) { | ||
3470 | u->rst.error = 2; | ||
3471 | goto error; | ||
3472 | } | ||
3473 | #endif | ||
3474 | u->rst.ptr += 2; | ||
3475 | break; | ||
3476 | } | ||
3477 | case 0xf1: /* STZ2kr */ | ||
3478 | { | ||
3479 | Uint8 a = u->rst.dat[u->rst.ptr - 1]; | ||
3480 | Uint16 b = (u->rst.dat[u->rst.ptr - 2] | (u->rst.dat[u->rst.ptr - 3] << 8)); | ||
3481 | mempoke16(u->ram.dat, a, b); | ||
3482 | #ifndef NO_STACK_CHECKS | ||
3483 | if(u->rst.ptr < 3) { | ||
3484 | u->rst.error = 1; | ||
3485 | goto error; | ||
3486 | } | ||
3487 | #endif | ||
3488 | break; | ||
3489 | } | ||
3490 | case 0xf2: /* LDR2kr */ | ||
3491 | { | ||
3492 | Uint8 a = u->rst.dat[u->rst.ptr - 1]; | ||
3493 | u->rst.dat[u->rst.ptr] = mempeek8(u->ram.dat, u->ram.ptr + (Sint8)a); | ||
3494 | u->rst.dat[u->rst.ptr + 1] = mempeek8(u->ram.dat, u->ram.ptr + (Sint8)a + 1); | ||
3495 | #ifndef NO_STACK_CHECKS | ||
3496 | if(u->rst.ptr < 1) { | ||
3497 | u->rst.error = 1; | ||
3498 | goto error; | ||
3499 | } | ||
3500 | if(u->rst.ptr > 253) { | ||
3501 | u->rst.error = 2; | ||
3502 | goto error; | ||
3503 | } | ||
3504 | #endif | ||
3505 | u->rst.ptr += 2; | ||
3506 | break; | ||
3507 | } | ||
3508 | case 0xf3: /* STR2kr */ | ||
3509 | { | ||
3510 | Uint8 a = u->rst.dat[u->rst.ptr - 1]; | ||
3511 | Uint16 b = (u->rst.dat[u->rst.ptr - 2] | (u->rst.dat[u->rst.ptr - 3] << 8)); | ||
3512 | mempoke16(u->ram.dat, u->ram.ptr + (Sint8)a, b); | ||
3513 | #ifndef NO_STACK_CHECKS | ||
3514 | if(u->rst.ptr < 3) { | ||
3515 | u->rst.error = 1; | ||
3516 | goto error; | ||
3517 | } | ||
3518 | #endif | ||
3519 | break; | ||
3520 | } | ||
3521 | case 0xf4: /* LDA2kr */ | ||
3522 | { | ||
3523 | Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)); | ||
3524 | u->rst.dat[u->rst.ptr] = mempeek8(u->ram.dat, a); | ||
3525 | u->rst.dat[u->rst.ptr + 1] = mempeek8(u->ram.dat, a + 1); | ||
3526 | #ifndef NO_STACK_CHECKS | ||
3527 | if(u->rst.ptr < 2) { | ||
3528 | u->rst.error = 1; | ||
3529 | goto error; | ||
3530 | } | ||
3531 | if(u->rst.ptr > 253) { | ||
3532 | u->rst.error = 2; | ||
3533 | goto error; | ||
3534 | } | ||
3535 | #endif | ||
3536 | u->rst.ptr += 2; | ||
3537 | break; | ||
3538 | } | ||
3539 | case 0xf5: /* STA2kr */ | ||
3540 | { | ||
3541 | Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)); | ||
3542 | Uint16 b = (u->rst.dat[u->rst.ptr - 3] | (u->rst.dat[u->rst.ptr - 4] << 8)); | ||
3543 | mempoke16(u->ram.dat, a, b); | ||
3544 | #ifndef NO_STACK_CHECKS | ||
3545 | if(u->rst.ptr < 4) { | ||
3546 | u->rst.error = 1; | ||
3547 | goto error; | ||
3548 | } | ||
3549 | #endif | ||
3550 | break; | ||
3551 | } | ||
3552 | case 0xf6: /* DEI2kr */ | ||
3553 | { | ||
3554 | Uint8 a = u->rst.dat[u->rst.ptr - 1]; | ||
3555 | u->rst.dat[u->rst.ptr] = devpeek8(&u->dev[a >> 4], a); | ||
3556 | u->rst.dat[u->rst.ptr + 1] = devpeek8(&u->dev[a >> 4], a + 1); | ||
3557 | #ifndef NO_STACK_CHECKS | ||
3558 | if(u->rst.ptr < 1) { | ||
3559 | u->rst.error = 1; | ||
3560 | goto error; | ||
3561 | } | ||
3562 | if(u->rst.ptr > 253) { | ||
3563 | u->rst.error = 2; | ||
3564 | goto error; | ||
3565 | } | ||
3566 | #endif | ||
3567 | u->rst.ptr += 2; | ||
3568 | break; | ||
3569 | } | ||
3570 | case 0xf7: /* DEO2kr */ | ||
3571 | { | ||
3572 | Uint8 a = u->rst.dat[u->rst.ptr - 1]; | ||
3573 | Uint16 b = (u->rst.dat[u->rst.ptr - 2] | (u->rst.dat[u->rst.ptr - 3] << 8)); | ||
3574 | devpoke16(&u->dev[a >> 4], a, b); | ||
3575 | #ifndef NO_STACK_CHECKS | ||
3576 | if(u->rst.ptr < 3) { | ||
3577 | u->rst.error = 1; | ||
3578 | goto error; | ||
3579 | } | ||
3580 | #endif | ||
3581 | break; | ||
3582 | } | ||
3583 | case 0xf8: /* ADD2kr */ | ||
3584 | { | ||
3585 | Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)), b = (u->rst.dat[u->rst.ptr - 3] | (u->rst.dat[u->rst.ptr - 4] << 8)); | ||
3586 | u->rst.dat[u->rst.ptr] = (b + a) >> 8; | ||
3587 | u->rst.dat[u->rst.ptr + 1] = (b + a) & 0xff; | ||
3588 | #ifndef NO_STACK_CHECKS | ||
3589 | if(u->rst.ptr < 4) { | ||
3590 | u->rst.error = 1; | ||
3591 | goto error; | ||
3592 | } | ||
3593 | if(u->rst.ptr > 253) { | ||
3594 | u->rst.error = 2; | ||
3595 | goto error; | ||
3596 | } | ||
3597 | #endif | ||
3598 | u->rst.ptr += 2; | ||
3599 | break; | ||
3600 | } | ||
3601 | case 0xf9: /* SUB2kr */ | ||
3602 | { | ||
3603 | Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)), b = (u->rst.dat[u->rst.ptr - 3] | (u->rst.dat[u->rst.ptr - 4] << 8)); | ||
3604 | u->rst.dat[u->rst.ptr] = (b - a) >> 8; | ||
3605 | u->rst.dat[u->rst.ptr + 1] = (b - a) & 0xff; | ||
3606 | #ifndef NO_STACK_CHECKS | ||
3607 | if(u->rst.ptr < 4) { | ||
3608 | u->rst.error = 1; | ||
3609 | goto error; | ||
3610 | } | ||
3611 | if(u->rst.ptr > 253) { | ||
3612 | u->rst.error = 2; | ||
3613 | goto error; | ||
3614 | } | ||
3615 | #endif | ||
3616 | u->rst.ptr += 2; | ||
3617 | break; | ||
3618 | } | ||
3619 | case 0xfa: /* MUL2kr */ | ||
3620 | { | ||
3621 | Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)), b = (u->rst.dat[u->rst.ptr - 3] | (u->rst.dat[u->rst.ptr - 4] << 8)); | ||
3622 | u->rst.dat[u->rst.ptr] = (b * a) >> 8; | ||
3623 | u->rst.dat[u->rst.ptr + 1] = (b * a) & 0xff; | ||
3624 | #ifndef NO_STACK_CHECKS | ||
3625 | if(u->rst.ptr < 4) { | ||
3626 | u->rst.error = 1; | ||
3627 | goto error; | ||
3628 | } | ||
3629 | if(u->rst.ptr > 253) { | ||
3630 | u->rst.error = 2; | ||
3631 | goto error; | ||
3632 | } | ||
3633 | #endif | ||
3634 | u->rst.ptr += 2; | ||
3635 | break; | ||
3636 | } | ||
3637 | case 0xfb: /* DIV2kr */ | ||
3638 | { | ||
3639 | Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)), b = (u->rst.dat[u->rst.ptr - 3] | (u->rst.dat[u->rst.ptr - 4] << 8)); | ||
3640 | u->rst.dat[u->rst.ptr] = (b / a) >> 8; | ||
3641 | u->rst.dat[u->rst.ptr + 1] = (b / a) & 0xff; | ||
3642 | #ifndef NO_STACK_CHECKS | ||
3643 | if(u->rst.ptr < 4) { | ||
3644 | u->rst.error = 1; | ||
3645 | goto error; | ||
3646 | } | ||
3647 | if(u->rst.ptr > 253) { | ||
3648 | u->rst.error = 2; | ||
3649 | goto error; | ||
3650 | } | ||
3651 | #endif | ||
3652 | u->rst.ptr += 2; | ||
3653 | break; | ||
3654 | } | ||
3655 | case 0xfc: /* AND2kr */ | ||
3656 | { | ||
3657 | Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2], c = u->rst.dat[u->rst.ptr - 3], d = u->rst.dat[u->rst.ptr - 4]; | ||
3658 | u->rst.dat[u->rst.ptr] = d & b; | ||
3659 | u->rst.dat[u->rst.ptr + 1] = c & a; | ||
3660 | #ifndef NO_STACK_CHECKS | ||
3661 | if(u->rst.ptr < 4) { | ||
3662 | u->rst.error = 1; | ||
3663 | goto error; | ||
3664 | } | ||
3665 | if(u->rst.ptr > 253) { | ||
3666 | u->rst.error = 2; | ||
3667 | goto error; | ||
3668 | } | ||
3669 | #endif | ||
3670 | u->rst.ptr += 2; | ||
3671 | break; | ||
3672 | } | ||
3673 | case 0xfd: /* ORA2kr */ | ||
3674 | { | ||
3675 | Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2], c = u->rst.dat[u->rst.ptr - 3], d = u->rst.dat[u->rst.ptr - 4]; | ||
3676 | u->rst.dat[u->rst.ptr] = d | b; | ||
3677 | u->rst.dat[u->rst.ptr + 1] = c | a; | ||
3678 | #ifndef NO_STACK_CHECKS | ||
3679 | if(u->rst.ptr < 4) { | ||
3680 | u->rst.error = 1; | ||
3681 | goto error; | ||
3682 | } | ||
3683 | if(u->rst.ptr > 253) { | ||
3684 | u->rst.error = 2; | ||
3685 | goto error; | ||
3686 | } | ||
3687 | #endif | ||
3688 | u->rst.ptr += 2; | ||
3689 | break; | ||
3690 | } | ||
3691 | case 0xfe: /* EOR2kr */ | ||
3692 | { | ||
3693 | Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2], c = u->rst.dat[u->rst.ptr - 3], d = u->rst.dat[u->rst.ptr - 4]; | ||
3694 | u->rst.dat[u->rst.ptr] = d ^ b; | ||
3695 | u->rst.dat[u->rst.ptr + 1] = c ^ a; | ||
3696 | #ifndef NO_STACK_CHECKS | ||
3697 | if(u->rst.ptr < 4) { | ||
3698 | u->rst.error = 1; | ||
3699 | goto error; | ||
3700 | } | ||
3701 | if(u->rst.ptr > 253) { | ||
3702 | u->rst.error = 2; | ||
3703 | goto error; | ||
3704 | } | ||
3705 | #endif | ||
3706 | u->rst.ptr += 2; | ||
3707 | break; | ||
3708 | } | ||
3709 | case 0xff: /* SFT2kr */ | ||
3710 | { | ||
3711 | Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)), b = (u->rst.dat[u->rst.ptr - 3] | (u->rst.dat[u->rst.ptr - 4] << 8)); | ||
3712 | u->rst.dat[u->rst.ptr] = (b >> (a & 0x000f) << ((a & 0x00f0) >> 4)) >> 8; | ||
3713 | u->rst.dat[u->rst.ptr + 1] = (b >> (a & 0x000f) << ((a & 0x00f0) >> 4)) & 0xff; | ||
3714 | #ifndef NO_STACK_CHECKS | ||
3715 | if(u->rst.ptr < 4) { | ||
3716 | u->rst.error = 1; | ||
3717 | goto error; | ||
3718 | } | ||
3719 | if(u->rst.ptr > 253) { | ||
3720 | u->rst.error = 2; | ||
3721 | goto error; | ||
3722 | } | ||
3723 | #endif | ||
3724 | u->rst.ptr += 2; | ||
3725 | break; | ||
3726 | } | ||
3727 | #pragma GCC diagnostic pop | ||
3728 | } | ||
3729 | } | ||
3730 | return 1; | ||
3731 | #ifndef NO_STACK_CHECKS | ||
3732 | error: | ||
42 | return 0; | 3733 | return 0; |
3734 | #endif | ||
43 | } | 3735 | } |
44 | 3736 | ||
45 | IWRAM_CODE | 3737 | int |
46 | static inline void | 3738 | bootuxn(Uxn *u) |
47 | opcuxn(Uxn *u, Uint8 instr) | ||
48 | { | 3739 | { |
49 | #if 1 | 3740 | size_t i; |
50 | // With CPU error checking enabled, the codebase becomes too large to fit in ITCM. | 3741 | char *cptr = (char *)u; |
51 | // Therefore, we take some concessions. | 3742 | for(i = 0; i < sizeof(*u); i++) |
52 | if (instr & 0x40) { | 3743 | cptr[i] = 0; |
53 | u->src = &u->rst; | 3744 | return 1; |
54 | u->dst = &u->wst; | ||
55 | } else { | ||
56 | u->src = &u->wst; | ||
57 | u->dst = &u->rst; | ||
58 | } | ||
59 | |||
60 | switch (instr & 0xBF) { | ||
61 | #define UXN_SRC (u->src) | ||
62 | #define UXN_DST (u->dst) | ||
63 | |||
64 | #define UXN_KEEP_SYNC {} | ||
65 | #define pop8 pop8_nokeep | ||
66 | #define pop16(s) (pop8((s)) + (pop8((s)) << 8)) | ||
67 | |||
68 | #define UXN_OPC(a) (a) | ||
69 | #include "uxn/opcodes.c" | ||
70 | #undef UXN_OPC | ||
71 | |||
72 | #undef pop16 | ||
73 | #undef pop8 | ||
74 | #undef UXN_KEEP_SYNC | ||
75 | |||
76 | #define UXN_KEEP_SYNC {(*(UXN_SRC)).kptr = (*(UXN_SRC)).ptr;} | ||
77 | #define pop8 pop8_keep | ||
78 | #define pop16(s) (pop8((s)) + (pop8((s)) << 8)) | ||
79 | |||
80 | #define UXN_OPC(a) (a | 0x80) | ||
81 | #include "uxn/opcodes.c" | ||
82 | #undef UXN_OPC | ||
83 | |||
84 | #undef pop16 | ||
85 | #undef pop8 | ||
86 | #undef UXN_KEEP_SYNC | ||
87 | |||
88 | #undef UXN_DST | ||
89 | #undef UXN_SRC | ||
90 | } | ||
91 | #else | ||
92 | switch (instr) { | ||
93 | #define UXN_KEEP_SYNC {} | ||
94 | #define pop8 pop8_nokeep | ||
95 | #define pop16(s) (pop8((s)) + (pop8((s)) << 8)) | ||
96 | |||
97 | #define UXN_OPC(a) (a) | ||
98 | #define UXN_SRC (&u->wst) | ||
99 | #define UXN_DST (&u->rst) | ||
100 | #include "uxn/opcodes.c" | ||
101 | #undef UXN_DST | ||
102 | #undef UXN_SRC | ||
103 | #undef UXN_OPC | ||
104 | |||
105 | #define UXN_OPC(a) (a | 0x40) | ||
106 | #define UXN_SRC (&u->rst) | ||
107 | #define UXN_DST (&u->wst) | ||
108 | #include "uxn/opcodes.c" | ||
109 | #undef UXN_DST | ||
110 | #undef UXN_SRC | ||
111 | #undef UXN_OPC | ||
112 | |||
113 | #undef pop16 | ||
114 | #undef pop8 | ||
115 | #undef UXN_KEEP_SYNC | ||
116 | |||
117 | #define UXN_KEEP_SYNC {(*(UXN_SRC)).kptr = (*(UXN_SRC)).ptr;} | ||
118 | #define pop8 pop8_keep | ||
119 | #define pop16(s) (pop8((s)) + (pop8((s)) << 8)) | ||
120 | |||
121 | #define UXN_OPC(a) (a | 0x80) | ||
122 | #define UXN_SRC (&u->wst) | ||
123 | #define UXN_DST (&u->rst) | ||
124 | #include "uxn/opcodes.c" | ||
125 | #undef UXN_DST | ||
126 | #undef UXN_SRC | ||
127 | #undef UXN_OPC | ||
128 | |||
129 | #define UXN_OPC(a) (a | 0xC0) | ||
130 | #define UXN_SRC (&u->rst) | ||
131 | #define UXN_DST (&u->wst) | ||
132 | #include "uxn/opcodes.c" | ||
133 | #undef UXN_DST | ||
134 | #undef UXN_SRC | ||
135 | #undef UXN_OPC | ||
136 | |||
137 | #undef pop16 | ||
138 | #undef pop8 | ||
139 | #undef UXN_KEEP_SYNC | ||
140 | } | ||
141 | #endif | ||
142 | } | 3745 | } |
143 | 3746 | ||
144 | IWRAM_CODE | ||
145 | int | 3747 | int |
146 | evaluxn(Uxn *u, Uint16 vec) | 3748 | loaduxn(Uxn *u, char *filepath) |
147 | { | 3749 | { |
148 | u->ram.ptr = vec; | 3750 | FILE *f; |
149 | while(u->ram.ptr) { | 3751 | if(!(f = fopen(filepath, "rb"))) { |
150 | opcuxn(u, u->ram.dat[u->ram.ptr++]); | 3752 | return 0; |
151 | } | 3753 | } |
3754 | fread(u->ram.dat + PAGE_PROGRAM, sizeof(u->ram.dat) - PAGE_PROGRAM, 1, f); | ||
152 | return 1; | 3755 | return 1; |
153 | } | 3756 | } |
154 | 3757 | ||
@@ -160,6 +3763,5 @@ portuxn(Uxn *u, Uint8 id, char *name, void (*talkfn)(Device *d, Uint8 b0, Uint8 | |||
160 | d->u = u; | 3763 | d->u = u; |
161 | d->mem = u->ram.dat; | 3764 | d->mem = u->ram.dat; |
162 | d->talk = talkfn; | 3765 | d->talk = talkfn; |
163 | // txt_printf("Dev:#%02x:0x%04x:%s \n", id, d->addr, name); | ||
164 | return d; | 3766 | return d; |
165 | } | 3767 | } |
diff --git a/src/uxn/uxn.h b/src/uxn/uxn.h index b24d058..6c6d53e 100644 --- a/src/uxn/uxn.h +++ b/src/uxn/uxn.h | |||
@@ -49,6 +49,10 @@ static inline void mempoke8(Uint8 *m, Uint16 a, Uint8 b) { m[a] = b; } | |||
49 | static inline Uint8 mempeek8(Uint8 *m, Uint16 a) { return m[a]; } | 49 | static inline Uint8 mempeek8(Uint8 *m, Uint16 a) { return m[a]; } |
50 | static inline void mempoke16(Uint8 *m, Uint16 a, Uint16 b) { mempoke8(m, a, b >> 8); mempoke8(m, a + 1, b); } | 50 | static inline void mempoke16(Uint8 *m, Uint16 a, Uint16 b) { mempoke8(m, a, b >> 8); mempoke8(m, a + 1, b); } |
51 | static inline Uint16 mempeek16(Uint8 *m, Uint16 a) { return (mempeek8(m, a) << 8) + mempeek8(m, a + 1); } | 51 | static inline Uint16 mempeek16(Uint8 *m, Uint16 a) { return (mempeek8(m, a) << 8) + mempeek8(m, a + 1); } |
52 | static inline void devpoke8(Device *d, Uint8 a, Uint8 b) { d->dat[a & 0xf] = b; d->talk(d, a & 0x0f, 1); } | ||
53 | static inline Uint8 devpeek8(Device *d, Uint8 a) { d->talk(d, a & 0x0f, 0); return d->dat[a & 0xf]; } | ||
54 | static inline void devpoke16(Device *d, Uint8 a, Uint16 b) { devpoke8(d, a, b >> 8); devpoke8(d, a + 1, b); } | ||
55 | static inline Uint16 devpeek16(Device *d, Uint16 a) { return (devpeek8(d, a) << 8) + devpeek8(d, a + 1); } | ||
52 | 56 | ||
53 | int loaduxn(Uxn *c, char *filepath); | 57 | int loaduxn(Uxn *c, char *filepath); |
54 | int bootuxn(Uxn *c); | 58 | int bootuxn(Uxn *c); |