aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2021-08-16 09:31:54 +0200
committerBad Diode <bd@badd10de.dev>2021-08-16 09:31:54 +0200
commit3652f2a9f8190e688d0e358d3a8ae6ea5c31b45d (patch)
tree6f9ccbbf9ee8e927610f710b09aea322a044a776
parent54c0c3b42c20dc6e0637e9c0f20a036f2e168db5 (diff)
downloaduxngba-3652f2a9f8190e688d0e358d3a8ae6ea5c31b45d.tar.gz
uxngba-3652f2a9f8190e688d0e358d3a8ae6ea5c31b45d.zip
Update UXN with OPCODE changes (-NOP, +NIP)
-rw-r--r--roms/audio.rombin435 -> 435 bytes
-rw-r--r--roms/automata.rombin255 -> 255 bytes
-rw-r--r--roms/bifurcan.rombin584 -> 584 bytes
-rw-r--r--roms/controller.rombin985 -> 985 bytes
-rw-r--r--roms/dvd.rombin315 -> 315 bytes
-rw-r--r--roms/file.load.rombin1233 -> 1233 bytes
-rw-r--r--roms/hover.rombin508 -> 508 bytes
-rw-r--r--roms/label.rombin1458 -> 1457 bytes
-rw-r--r--roms/multichannel.audio.rombin1235 -> 1235 bytes
-rw-r--r--roms/polycat.rombin801 -> 801 bytes
-rw-r--r--roms/proportional_fonts.rombin1333 -> 1333 bytes
-rw-r--r--roms/screen.rombin646 -> 800 bytes
-rw-r--r--roms/shapes.rombin1077 -> 1077 bytes
-rw-r--r--roms/theme.rombin3231 -> 3227 bytes
-rw-r--r--roms/wallpaper.rombin190 -> 190 bytes
-rw-r--r--src/uxn.c731
16 files changed, 465 insertions, 266 deletions
diff --git a/roms/audio.rom b/roms/audio.rom
index d01771a..ad4924d 100644
--- a/roms/audio.rom
+++ b/roms/audio.rom
Binary files differ
diff --git a/roms/automata.rom b/roms/automata.rom
index 57c505c..285d439 100644
--- a/roms/automata.rom
+++ b/roms/automata.rom
Binary files differ
diff --git a/roms/bifurcan.rom b/roms/bifurcan.rom
index 3cbb81c..796491f 100644
--- a/roms/bifurcan.rom
+++ b/roms/bifurcan.rom
Binary files differ
diff --git a/roms/controller.rom b/roms/controller.rom
index 30019ad..47a56a2 100644
--- a/roms/controller.rom
+++ b/roms/controller.rom
Binary files differ
diff --git a/roms/dvd.rom b/roms/dvd.rom
index b6a8cf2..4d3fc61 100644
--- a/roms/dvd.rom
+++ b/roms/dvd.rom
Binary files differ
diff --git a/roms/file.load.rom b/roms/file.load.rom
index 3889807..292933e 100644
--- a/roms/file.load.rom
+++ b/roms/file.load.rom
Binary files differ
diff --git a/roms/hover.rom b/roms/hover.rom
index 3cebc60..fa2c544 100644
--- a/roms/hover.rom
+++ b/roms/hover.rom
Binary files differ
diff --git a/roms/label.rom b/roms/label.rom
index 76510b2..535c7ee 100644
--- a/roms/label.rom
+++ b/roms/label.rom
Binary files differ
diff --git a/roms/multichannel.audio.rom b/roms/multichannel.audio.rom
index 0b71e07..d7f652b 100644
--- a/roms/multichannel.audio.rom
+++ b/roms/multichannel.audio.rom
Binary files differ
diff --git a/roms/polycat.rom b/roms/polycat.rom
index 93ec926..42fe18c 100644
--- a/roms/polycat.rom
+++ b/roms/polycat.rom
Binary files differ
diff --git a/roms/proportional_fonts.rom b/roms/proportional_fonts.rom
index e40d6fc..96a8ee1 100644
--- a/roms/proportional_fonts.rom
+++ b/roms/proportional_fonts.rom
Binary files differ
diff --git a/roms/screen.rom b/roms/screen.rom
index 210d5c4..6fd8f99 100644
--- a/roms/screen.rom
+++ b/roms/screen.rom
Binary files differ
diff --git a/roms/shapes.rom b/roms/shapes.rom
index 6b38de9..b633b77 100644
--- a/roms/shapes.rom
+++ b/roms/shapes.rom
Binary files differ
diff --git a/roms/theme.rom b/roms/theme.rom
index 315a2c9..4fe36e6 100644
--- a/roms/theme.rom
+++ b/roms/theme.rom
Binary files differ
diff --git a/roms/wallpaper.rom b/roms/wallpaper.rom
index ba653b8..3bd6406 100644
--- a/roms/wallpaper.rom
+++ b/roms/wallpaper.rom
Binary files differ
diff --git a/src/uxn.c b/src/uxn.c
index d6da3b9..3a8cdb3 100644
--- a/src/uxn.c
+++ b/src/uxn.c
@@ -15,12 +15,28 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
15WITH REGARD TO THIS SOFTWARE. 15WITH REGARD TO THIS SOFTWARE.
16*/ 16*/
17 17
18/*
19 ^
20/!\ THIS FILE IS AUTOMATICALLY GENERATED
21---
22
23Its contents can get overwritten with the processed contents of src/uxn.c.
24See etc/mkuxn-fast.moon for instructions.
25
26*/
27
28#define MODE_RETURN 0x40
29#define MODE_KEEP 0x80
30
18IWRAM_CODE 31IWRAM_CODE
19int 32int
20evaluxn(Uxn *u, u16 vec) 33evaluxn(Uxn *u, u16 vec)
21{ 34{
22 u8 instr; 35 u8 instr;
36 if(u->dev[0].dat[0xf])
37 return 0;
23 u->ram.ptr = vec; 38 u->ram.ptr = vec;
39 if(u->wst.ptr > 0xf8) u->wst.ptr = 0xf8;
24 while(u->ram.ptr) { 40 while(u->ram.ptr) {
25 instr = u->ram.dat[u->ram.ptr++]; 41 instr = u->ram.dat[u->ram.ptr++];
26 switch(instr) { 42 switch(instr) {
@@ -35,14 +51,14 @@ evaluxn(Uxn *u, u16 vec)
35 case 0xa0: /* BRK2k */ 51 case 0xa0: /* BRK2k */
36 case 0xc0: /* BRKkr */ 52 case 0xc0: /* BRKkr */
37 case 0xe0: /* BRK2kr */ 53 case 0xe0: /* BRK2kr */
38 __asm__( "evaluxn_00_BRK:" ); 54 __asm__("evaluxn_00_BRK:");
39 { 55 {
40 u->ram.ptr = 0; 56 u->ram.ptr = 0;
41 } 57 }
42 break; 58 break;
43 case 0x01: /* LIT */ 59 case 0x01: /* LIT */
44 case 0x81: /* LITk */ 60 case 0x81: /* LITk */
45 __asm__( "evaluxn_01_LIT:" ); 61 __asm__("evaluxn_01_LIT:");
46 { 62 {
47 u->wst.dat[u->wst.ptr] = mempeek8(u->ram.dat, u->ram.ptr++); 63 u->wst.dat[u->wst.ptr] = mempeek8(u->ram.dat, u->ram.ptr++);
48#ifndef NO_STACK_CHECKS 64#ifndef NO_STACK_CHECKS
@@ -54,21 +70,8 @@ evaluxn(Uxn *u, u16 vec)
54 u->wst.ptr += 1; 70 u->wst.ptr += 1;
55 } 71 }
56 break; 72 break;
57 case 0x02: /* NOP */ 73 case 0x02: /* POP */
58 case 0x22: /* NOP2 */ 74 __asm__("evaluxn_02_POP:");
59 case 0x42: /* NOPr */
60 case 0x62: /* NOP2r */
61 case 0x82: /* NOPk */
62 case 0xa2: /* NOP2k */
63 case 0xc2: /* NOPkr */
64 case 0xe2: /* NOP2kr */
65 __asm__( "evaluxn_02_NOP:" );
66 {
67 (void)u;
68 }
69 break;
70 case 0x03: /* POP */
71 __asm__( "evaluxn_03_POP:" );
72 { 75 {
73 u->wst.dat[u->wst.ptr - 1]; 76 u->wst.dat[u->wst.ptr - 1];
74#ifndef NO_STACK_CHECKS 77#ifndef NO_STACK_CHECKS
@@ -80,8 +83,8 @@ evaluxn(Uxn *u, u16 vec)
80 u->wst.ptr -= 1; 83 u->wst.ptr -= 1;
81 } 84 }
82 break; 85 break;
83 case 0x04: /* DUP */ 86 case 0x03: /* DUP */
84 __asm__( "evaluxn_04_DUP:" ); 87 __asm__("evaluxn_03_DUP:");
85 { 88 {
86 u8 a = u->wst.dat[u->wst.ptr - 1]; 89 u8 a = u->wst.dat[u->wst.ptr - 1];
87 u->wst.dat[u->wst.ptr] = a; 90 u->wst.dat[u->wst.ptr] = a;
@@ -98,8 +101,23 @@ evaluxn(Uxn *u, u16 vec)
98 u->wst.ptr += 1; 101 u->wst.ptr += 1;
99 } 102 }
100 break; 103 break;
104 case 0x04: /* NIP */
105 __asm__("evaluxn_04_NIP:");
106 {
107 u8 a = u->wst.dat[u->wst.ptr - 1];
108 u->wst.dat[u->wst.ptr - 2];
109 u->wst.dat[u->wst.ptr - 2] = a;
110#ifndef NO_STACK_CHECKS
111 if(__builtin_expect(u->wst.ptr < 2, 0)) {
112 u->wst.error = 1;
113 goto error;
114 }
115#endif
116 u->wst.ptr -= 1;
117 }
118 break;
101 case 0x05: /* SWP */ 119 case 0x05: /* SWP */
102 __asm__( "evaluxn_05_SWP:" ); 120 __asm__("evaluxn_05_SWP:");
103 { 121 {
104 u8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; 122 u8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2];
105 u->wst.dat[u->wst.ptr - 2] = a; 123 u->wst.dat[u->wst.ptr - 2] = a;
@@ -113,7 +131,7 @@ evaluxn(Uxn *u, u16 vec)
113 } 131 }
114 break; 132 break;
115 case 0x06: /* OVR */ 133 case 0x06: /* OVR */
116 __asm__( "evaluxn_06_OVR:" ); 134 __asm__("evaluxn_06_OVR:");
117 { 135 {
118 u8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; 136 u8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2];
119 u->wst.dat[u->wst.ptr] = b; 137 u->wst.dat[u->wst.ptr] = b;
@@ -131,7 +149,7 @@ evaluxn(Uxn *u, u16 vec)
131 } 149 }
132 break; 150 break;
133 case 0x07: /* ROT */ 151 case 0x07: /* ROT */
134 __asm__( "evaluxn_07_ROT:" ); 152 __asm__("evaluxn_07_ROT:");
135 { 153 {
136 u8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2], c = u->wst.dat[u->wst.ptr - 3]; 154 u8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2], c = u->wst.dat[u->wst.ptr - 3];
137 u->wst.dat[u->wst.ptr - 3] = b; 155 u->wst.dat[u->wst.ptr - 3] = b;
@@ -146,7 +164,7 @@ evaluxn(Uxn *u, u16 vec)
146 } 164 }
147 break; 165 break;
148 case 0x08: /* EQU */ 166 case 0x08: /* EQU */
149 __asm__( "evaluxn_08_EQU:" ); 167 __asm__("evaluxn_08_EQU:");
150 { 168 {
151 u8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; 169 u8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2];
152 u->wst.dat[u->wst.ptr - 2] = b == a; 170 u->wst.dat[u->wst.ptr - 2] = b == a;
@@ -160,7 +178,7 @@ evaluxn(Uxn *u, u16 vec)
160 } 178 }
161 break; 179 break;
162 case 0x09: /* NEQ */ 180 case 0x09: /* NEQ */
163 __asm__( "evaluxn_09_NEQ:" ); 181 __asm__("evaluxn_09_NEQ:");
164 { 182 {
165 u8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; 183 u8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2];
166 u->wst.dat[u->wst.ptr - 2] = b != a; 184 u->wst.dat[u->wst.ptr - 2] = b != a;
@@ -174,7 +192,7 @@ evaluxn(Uxn *u, u16 vec)
174 } 192 }
175 break; 193 break;
176 case 0x0a: /* GTH */ 194 case 0x0a: /* GTH */
177 __asm__( "evaluxn_0a_GTH:" ); 195 __asm__("evaluxn_0a_GTH:");
178 { 196 {
179 u8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; 197 u8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2];
180 u->wst.dat[u->wst.ptr - 2] = b > a; 198 u->wst.dat[u->wst.ptr - 2] = b > a;
@@ -188,7 +206,7 @@ evaluxn(Uxn *u, u16 vec)
188 } 206 }
189 break; 207 break;
190 case 0x0b: /* LTH */ 208 case 0x0b: /* LTH */
191 __asm__( "evaluxn_0b_LTH:" ); 209 __asm__("evaluxn_0b_LTH:");
192 { 210 {
193 u8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; 211 u8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2];
194 u->wst.dat[u->wst.ptr - 2] = b < a; 212 u->wst.dat[u->wst.ptr - 2] = b < a;
@@ -202,7 +220,7 @@ evaluxn(Uxn *u, u16 vec)
202 } 220 }
203 break; 221 break;
204 case 0x0c: /* JMP */ 222 case 0x0c: /* JMP */
205 __asm__( "evaluxn_0c_JMP:" ); 223 __asm__("evaluxn_0c_JMP:");
206 { 224 {
207 u8 a = u->wst.dat[u->wst.ptr - 1]; 225 u8 a = u->wst.dat[u->wst.ptr - 1];
208 u->ram.ptr += (s8)a; 226 u->ram.ptr += (s8)a;
@@ -216,7 +234,7 @@ evaluxn(Uxn *u, u16 vec)
216 } 234 }
217 break; 235 break;
218 case 0x0d: /* JCN */ 236 case 0x0d: /* JCN */
219 __asm__( "evaluxn_0d_JCN:" ); 237 __asm__("evaluxn_0d_JCN:");
220 { 238 {
221 u8 a = u->wst.dat[u->wst.ptr - 1]; 239 u8 a = u->wst.dat[u->wst.ptr - 1];
222 if(u->wst.dat[u->wst.ptr - 2]) u->ram.ptr += (s8)a; 240 if(u->wst.dat[u->wst.ptr - 2]) u->ram.ptr += (s8)a;
@@ -230,7 +248,7 @@ evaluxn(Uxn *u, u16 vec)
230 } 248 }
231 break; 249 break;
232 case 0x0e: /* JSR */ 250 case 0x0e: /* JSR */
233 __asm__( "evaluxn_0e_JSR:" ); 251 __asm__("evaluxn_0e_JSR:");
234 { 252 {
235 u8 a = u->wst.dat[u->wst.ptr - 1]; 253 u8 a = u->wst.dat[u->wst.ptr - 1];
236 u->rst.dat[u->rst.ptr] = u->ram.ptr >> 8; 254 u->rst.dat[u->rst.ptr] = u->ram.ptr >> 8;
@@ -253,7 +271,7 @@ evaluxn(Uxn *u, u16 vec)
253 } 271 }
254 break; 272 break;
255 case 0x0f: /* STH */ 273 case 0x0f: /* STH */
256 __asm__( "evaluxn_0f_STH:" ); 274 __asm__("evaluxn_0f_STH:");
257 { 275 {
258 u8 a = u->wst.dat[u->wst.ptr - 1]; 276 u8 a = u->wst.dat[u->wst.ptr - 1];
259 u->rst.dat[u->rst.ptr] = a; 277 u->rst.dat[u->rst.ptr] = a;
@@ -274,7 +292,7 @@ evaluxn(Uxn *u, u16 vec)
274 } 292 }
275 break; 293 break;
276 case 0x10: /* LDZ */ 294 case 0x10: /* LDZ */
277 __asm__( "evaluxn_10_LDZ:" ); 295 __asm__("evaluxn_10_LDZ:");
278 { 296 {
279 u8 a = u->wst.dat[u->wst.ptr - 1]; 297 u8 a = u->wst.dat[u->wst.ptr - 1];
280 u->wst.dat[u->wst.ptr - 1] = mempeek8(u->ram.dat, a); 298 u->wst.dat[u->wst.ptr - 1] = mempeek8(u->ram.dat, a);
@@ -287,7 +305,7 @@ evaluxn(Uxn *u, u16 vec)
287 } 305 }
288 break; 306 break;
289 case 0x11: /* STZ */ 307 case 0x11: /* STZ */
290 __asm__( "evaluxn_11_STZ:" ); 308 __asm__("evaluxn_11_STZ:");
291 { 309 {
292 u8 a = u->wst.dat[u->wst.ptr - 1]; 310 u8 a = u->wst.dat[u->wst.ptr - 1];
293 u8 b = u->wst.dat[u->wst.ptr - 2]; 311 u8 b = u->wst.dat[u->wst.ptr - 2];
@@ -302,7 +320,7 @@ evaluxn(Uxn *u, u16 vec)
302 } 320 }
303 break; 321 break;
304 case 0x12: /* LDR */ 322 case 0x12: /* LDR */
305 __asm__( "evaluxn_12_LDR:" ); 323 __asm__("evaluxn_12_LDR:");
306 { 324 {
307 u8 a = u->wst.dat[u->wst.ptr - 1]; 325 u8 a = u->wst.dat[u->wst.ptr - 1];
308 u->wst.dat[u->wst.ptr - 1] = mempeek8(u->ram.dat, u->ram.ptr + (s8)a); 326 u->wst.dat[u->wst.ptr - 1] = mempeek8(u->ram.dat, u->ram.ptr + (s8)a);
@@ -315,7 +333,7 @@ evaluxn(Uxn *u, u16 vec)
315 } 333 }
316 break; 334 break;
317 case 0x13: /* STR */ 335 case 0x13: /* STR */
318 __asm__( "evaluxn_13_STR:" ); 336 __asm__("evaluxn_13_STR:");
319 { 337 {
320 u8 a = u->wst.dat[u->wst.ptr - 1]; 338 u8 a = u->wst.dat[u->wst.ptr - 1];
321 u8 b = u->wst.dat[u->wst.ptr - 2]; 339 u8 b = u->wst.dat[u->wst.ptr - 2];
@@ -330,7 +348,7 @@ evaluxn(Uxn *u, u16 vec)
330 } 348 }
331 break; 349 break;
332 case 0x14: /* LDA */ 350 case 0x14: /* LDA */
333 __asm__( "evaluxn_14_LDA:" ); 351 __asm__("evaluxn_14_LDA:");
334 { 352 {
335 u16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)); 353 u16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8));
336 u->wst.dat[u->wst.ptr - 2] = mempeek8(u->ram.dat, a); 354 u->wst.dat[u->wst.ptr - 2] = mempeek8(u->ram.dat, a);
@@ -344,7 +362,7 @@ evaluxn(Uxn *u, u16 vec)
344 } 362 }
345 break; 363 break;
346 case 0x15: /* STA */ 364 case 0x15: /* STA */
347 __asm__( "evaluxn_15_STA:" ); 365 __asm__("evaluxn_15_STA:");
348 { 366 {
349 u16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)); 367 u16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8));
350 u8 b = u->wst.dat[u->wst.ptr - 3]; 368 u8 b = u->wst.dat[u->wst.ptr - 3];
@@ -359,7 +377,7 @@ evaluxn(Uxn *u, u16 vec)
359 } 377 }
360 break; 378 break;
361 case 0x16: /* DEI */ 379 case 0x16: /* DEI */
362 __asm__( "evaluxn_16_DEI:" ); 380 __asm__("evaluxn_16_DEI:");
363 { 381 {
364 u8 a = u->wst.dat[u->wst.ptr - 1]; 382 u8 a = u->wst.dat[u->wst.ptr - 1];
365 u->wst.dat[u->wst.ptr - 1] = devpeek8(&u->dev[a >> 4], a); 383 u->wst.dat[u->wst.ptr - 1] = devpeek8(&u->dev[a >> 4], a);
@@ -372,7 +390,7 @@ evaluxn(Uxn *u, u16 vec)
372 } 390 }
373 break; 391 break;
374 case 0x17: /* DEO */ 392 case 0x17: /* DEO */
375 __asm__( "evaluxn_17_DEO:" ); 393 __asm__("evaluxn_17_DEO:");
376 { 394 {
377 u8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; 395 u8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2];
378 devpoke8(&u->dev[a >> 4], a, b); 396 devpoke8(&u->dev[a >> 4], a, b);
@@ -386,7 +404,7 @@ evaluxn(Uxn *u, u16 vec)
386 } 404 }
387 break; 405 break;
388 case 0x18: /* ADD */ 406 case 0x18: /* ADD */
389 __asm__( "evaluxn_18_ADD:" ); 407 __asm__("evaluxn_18_ADD:");
390 { 408 {
391 u8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; 409 u8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2];
392 u->wst.dat[u->wst.ptr - 2] = b + a; 410 u->wst.dat[u->wst.ptr - 2] = b + a;
@@ -400,7 +418,7 @@ evaluxn(Uxn *u, u16 vec)
400 } 418 }
401 break; 419 break;
402 case 0x19: /* SUB */ 420 case 0x19: /* SUB */
403 __asm__( "evaluxn_19_SUB:" ); 421 __asm__("evaluxn_19_SUB:");
404 { 422 {
405 u8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; 423 u8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2];
406 u->wst.dat[u->wst.ptr - 2] = b - a; 424 u->wst.dat[u->wst.ptr - 2] = b - a;
@@ -414,7 +432,7 @@ evaluxn(Uxn *u, u16 vec)
414 } 432 }
415 break; 433 break;
416 case 0x1a: /* MUL */ 434 case 0x1a: /* MUL */
417 __asm__( "evaluxn_1a_MUL:" ); 435 __asm__("evaluxn_1a_MUL:");
418 { 436 {
419 u8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; 437 u8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2];
420 u->wst.dat[u->wst.ptr - 2] = b * a; 438 u->wst.dat[u->wst.ptr - 2] = b * a;
@@ -428,9 +446,16 @@ evaluxn(Uxn *u, u16 vec)
428 } 446 }
429 break; 447 break;
430 case 0x1b: /* DIV */ 448 case 0x1b: /* DIV */
431 __asm__( "evaluxn_1b_DIV:" ); 449 __asm__("evaluxn_1b_DIV:");
432 { 450 {
433 u8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; 451 u8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2];
452 if(a == 0) {
453 u->wst.error = 3;
454#ifndef NO_STACK_CHECKS
455 goto error;
456#endif
457 a = 1;
458 }
434 u->wst.dat[u->wst.ptr - 2] = b / a; 459 u->wst.dat[u->wst.ptr - 2] = b / a;
435#ifndef NO_STACK_CHECKS 460#ifndef NO_STACK_CHECKS
436 if(__builtin_expect(u->wst.ptr < 2, 0)) { 461 if(__builtin_expect(u->wst.ptr < 2, 0)) {
@@ -442,7 +467,7 @@ evaluxn(Uxn *u, u16 vec)
442 } 467 }
443 break; 468 break;
444 case 0x1c: /* AND */ 469 case 0x1c: /* AND */
445 __asm__( "evaluxn_1c_AND:" ); 470 __asm__("evaluxn_1c_AND:");
446 { 471 {
447 u8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; 472 u8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2];
448 u->wst.dat[u->wst.ptr - 2] = b & a; 473 u->wst.dat[u->wst.ptr - 2] = b & a;
@@ -456,7 +481,7 @@ evaluxn(Uxn *u, u16 vec)
456 } 481 }
457 break; 482 break;
458 case 0x1d: /* ORA */ 483 case 0x1d: /* ORA */
459 __asm__( "evaluxn_1d_ORA:" ); 484 __asm__("evaluxn_1d_ORA:");
460 { 485 {
461 u8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; 486 u8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2];
462 u->wst.dat[u->wst.ptr - 2] = b | a; 487 u->wst.dat[u->wst.ptr - 2] = b | a;
@@ -470,7 +495,7 @@ evaluxn(Uxn *u, u16 vec)
470 } 495 }
471 break; 496 break;
472 case 0x1e: /* EOR */ 497 case 0x1e: /* EOR */
473 __asm__( "evaluxn_1e_EOR:" ); 498 __asm__("evaluxn_1e_EOR:");
474 { 499 {
475 u8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; 500 u8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2];
476 u->wst.dat[u->wst.ptr - 2] = b ^ a; 501 u->wst.dat[u->wst.ptr - 2] = b ^ a;
@@ -484,7 +509,7 @@ evaluxn(Uxn *u, u16 vec)
484 } 509 }
485 break; 510 break;
486 case 0x1f: /* SFT */ 511 case 0x1f: /* SFT */
487 __asm__( "evaluxn_1f_SFT:" ); 512 __asm__("evaluxn_1f_SFT:");
488 { 513 {
489 u8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; 514 u8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2];
490 u->wst.dat[u->wst.ptr - 2] = b >> (a & 0x07) << ((a & 0x70) >> 4); 515 u->wst.dat[u->wst.ptr - 2] = b >> (a & 0x07) << ((a & 0x70) >> 4);
@@ -499,7 +524,7 @@ evaluxn(Uxn *u, u16 vec)
499 break; 524 break;
500 case 0x21: /* LIT2 */ 525 case 0x21: /* LIT2 */
501 case 0xa1: /* LIT2k */ 526 case 0xa1: /* LIT2k */
502 __asm__( "evaluxn_21_LIT2:" ); 527 __asm__("evaluxn_21_LIT2:");
503 { 528 {
504 u->wst.dat[u->wst.ptr] = mempeek8(u->ram.dat, u->ram.ptr++); 529 u->wst.dat[u->wst.ptr] = mempeek8(u->ram.dat, u->ram.ptr++);
505 u->wst.dat[u->wst.ptr + 1] = mempeek8(u->ram.dat, u->ram.ptr++); 530 u->wst.dat[u->wst.ptr + 1] = mempeek8(u->ram.dat, u->ram.ptr++);
@@ -512,8 +537,8 @@ evaluxn(Uxn *u, u16 vec)
512 u->wst.ptr += 2; 537 u->wst.ptr += 2;
513 } 538 }
514 break; 539 break;
515 case 0x23: /* POP2 */ 540 case 0x22: /* POP2 */
516 __asm__( "evaluxn_23_POP2:" ); 541 __asm__("evaluxn_22_POP2:");
517 { 542 {
518 (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)); 543 (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8));
519#ifndef NO_STACK_CHECKS 544#ifndef NO_STACK_CHECKS
@@ -525,8 +550,8 @@ evaluxn(Uxn *u, u16 vec)
525 u->wst.ptr -= 2; 550 u->wst.ptr -= 2;
526 } 551 }
527 break; 552 break;
528 case 0x24: /* DUP2 */ 553 case 0x23: /* DUP2 */
529 __asm__( "evaluxn_24_DUP2:" ); 554 __asm__("evaluxn_23_DUP2:");
530 { 555 {
531 u8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; 556 u8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2];
532 u->wst.dat[u->wst.ptr] = b; 557 u->wst.dat[u->wst.ptr] = b;
@@ -544,8 +569,24 @@ evaluxn(Uxn *u, u16 vec)
544 u->wst.ptr += 2; 569 u->wst.ptr += 2;
545 } 570 }
546 break; 571 break;
572 case 0x24: /* NIP2 */
573 __asm__("evaluxn_24_NIP2:");
574 {
575 u16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8));
576 (u->wst.dat[u->wst.ptr - 3] | (u->wst.dat[u->wst.ptr - 4] << 8));
577 u->wst.dat[u->wst.ptr - 4] = a >> 8;
578 u->wst.dat[u->wst.ptr - 3] = a & 0xff;
579#ifndef NO_STACK_CHECKS
580 if(__builtin_expect(u->wst.ptr < 4, 0)) {
581 u->wst.error = 1;
582 goto error;
583 }
584#endif
585 u->wst.ptr -= 2;
586 }
587 break;
547 case 0x25: /* SWP2 */ 588 case 0x25: /* SWP2 */
548 __asm__( "evaluxn_25_SWP2:" ); 589 __asm__("evaluxn_25_SWP2:");
549 { 590 {
550 u8 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]; 591 u8 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];
551 u->wst.dat[u->wst.ptr - 4] = b; 592 u->wst.dat[u->wst.ptr - 4] = b;
@@ -561,7 +602,7 @@ evaluxn(Uxn *u, u16 vec)
561 } 602 }
562 break; 603 break;
563 case 0x26: /* OVR2 */ 604 case 0x26: /* OVR2 */
564 __asm__( "evaluxn_26_OVR2:" ); 605 __asm__("evaluxn_26_OVR2:");
565 { 606 {
566 u8 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]; 607 u8 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];
567 u->wst.dat[u->wst.ptr] = d; 608 u->wst.dat[u->wst.ptr] = d;
@@ -580,7 +621,7 @@ evaluxn(Uxn *u, u16 vec)
580 } 621 }
581 break; 622 break;
582 case 0x27: /* ROT2 */ 623 case 0x27: /* ROT2 */
583 __asm__( "evaluxn_27_ROT2:" ); 624 __asm__("evaluxn_27_ROT2:");
584 { 625 {
585 u8 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], e = u->wst.dat[u->wst.ptr - 5], f = u->wst.dat[u->wst.ptr - 6]; 626 u8 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], e = u->wst.dat[u->wst.ptr - 5], f = u->wst.dat[u->wst.ptr - 6];
586 u->wst.dat[u->wst.ptr - 6] = d; 627 u->wst.dat[u->wst.ptr - 6] = d;
@@ -598,7 +639,7 @@ evaluxn(Uxn *u, u16 vec)
598 } 639 }
599 break; 640 break;
600 case 0x28: /* EQU2 */ 641 case 0x28: /* EQU2 */
601 __asm__( "evaluxn_28_EQU2:" ); 642 __asm__("evaluxn_28_EQU2:");
602 { 643 {
603 u16 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)); 644 u16 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));
604 u->wst.dat[u->wst.ptr - 4] = b == a; 645 u->wst.dat[u->wst.ptr - 4] = b == a;
@@ -612,7 +653,7 @@ evaluxn(Uxn *u, u16 vec)
612 } 653 }
613 break; 654 break;
614 case 0x29: /* NEQ2 */ 655 case 0x29: /* NEQ2 */
615 __asm__( "evaluxn_29_NEQ2:" ); 656 __asm__("evaluxn_29_NEQ2:");
616 { 657 {
617 u16 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)); 658 u16 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));
618 u->wst.dat[u->wst.ptr - 4] = b != a; 659 u->wst.dat[u->wst.ptr - 4] = b != a;
@@ -626,7 +667,7 @@ evaluxn(Uxn *u, u16 vec)
626 } 667 }
627 break; 668 break;
628 case 0x2a: /* GTH2 */ 669 case 0x2a: /* GTH2 */
629 __asm__( "evaluxn_2a_GTH2:" ); 670 __asm__("evaluxn_2a_GTH2:");
630 { 671 {
631 u16 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)); 672 u16 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));
632 u->wst.dat[u->wst.ptr - 4] = b > a; 673 u->wst.dat[u->wst.ptr - 4] = b > a;
@@ -640,7 +681,7 @@ evaluxn(Uxn *u, u16 vec)
640 } 681 }
641 break; 682 break;
642 case 0x2b: /* LTH2 */ 683 case 0x2b: /* LTH2 */
643 __asm__( "evaluxn_2b_LTH2:" ); 684 __asm__("evaluxn_2b_LTH2:");
644 { 685 {
645 u16 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)); 686 u16 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));
646 u->wst.dat[u->wst.ptr - 4] = b < a; 687 u->wst.dat[u->wst.ptr - 4] = b < a;
@@ -654,7 +695,7 @@ evaluxn(Uxn *u, u16 vec)
654 } 695 }
655 break; 696 break;
656 case 0x2c: /* JMP2 */ 697 case 0x2c: /* JMP2 */
657 __asm__( "evaluxn_2c_JMP2:" ); 698 __asm__("evaluxn_2c_JMP2:");
658 { 699 {
659 u->ram.ptr = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)); 700 u->ram.ptr = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8));
660#ifndef NO_STACK_CHECKS 701#ifndef NO_STACK_CHECKS
@@ -667,7 +708,7 @@ evaluxn(Uxn *u, u16 vec)
667 } 708 }
668 break; 709 break;
669 case 0x2d: /* JCN2 */ 710 case 0x2d: /* JCN2 */
670 __asm__( "evaluxn_2d_JCN2:" ); 711 __asm__("evaluxn_2d_JCN2:");
671 { 712 {
672 u16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)); 713 u16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8));
673 if(u->wst.dat[u->wst.ptr - 3]) u->ram.ptr = a; 714 if(u->wst.dat[u->wst.ptr - 3]) u->ram.ptr = a;
@@ -681,7 +722,7 @@ evaluxn(Uxn *u, u16 vec)
681 } 722 }
682 break; 723 break;
683 case 0x2e: /* JSR2 */ 724 case 0x2e: /* JSR2 */
684 __asm__( "evaluxn_2e_JSR2:" ); 725 __asm__("evaluxn_2e_JSR2:");
685 { 726 {
686 u->rst.dat[u->rst.ptr] = u->ram.ptr >> 8; 727 u->rst.dat[u->rst.ptr] = u->ram.ptr >> 8;
687 u->rst.dat[u->rst.ptr + 1] = u->ram.ptr & 0xff; 728 u->rst.dat[u->rst.ptr + 1] = u->ram.ptr & 0xff;
@@ -703,7 +744,7 @@ evaluxn(Uxn *u, u16 vec)
703 } 744 }
704 break; 745 break;
705 case 0x2f: /* STH2 */ 746 case 0x2f: /* STH2 */
706 __asm__( "evaluxn_2f_STH2:" ); 747 __asm__("evaluxn_2f_STH2:");
707 { 748 {
708 u8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; 749 u8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2];
709 u->rst.dat[u->rst.ptr] = b; 750 u->rst.dat[u->rst.ptr] = b;
@@ -725,7 +766,7 @@ evaluxn(Uxn *u, u16 vec)
725 } 766 }
726 break; 767 break;
727 case 0x30: /* LDZ2 */ 768 case 0x30: /* LDZ2 */
728 __asm__( "evaluxn_30_LDZ2:" ); 769 __asm__("evaluxn_30_LDZ2:");
729 { 770 {
730 u8 a = u->wst.dat[u->wst.ptr - 1]; 771 u8 a = u->wst.dat[u->wst.ptr - 1];
731 u->wst.dat[u->wst.ptr - 1] = mempeek8(u->ram.dat, a); 772 u->wst.dat[u->wst.ptr - 1] = mempeek8(u->ram.dat, a);
@@ -744,7 +785,7 @@ evaluxn(Uxn *u, u16 vec)
744 } 785 }
745 break; 786 break;
746 case 0x31: /* STZ2 */ 787 case 0x31: /* STZ2 */
747 __asm__( "evaluxn_31_STZ2:" ); 788 __asm__("evaluxn_31_STZ2:");
748 { 789 {
749 u8 a = u->wst.dat[u->wst.ptr - 1]; 790 u8 a = u->wst.dat[u->wst.ptr - 1];
750 u16 b = (u->wst.dat[u->wst.ptr - 2] | (u->wst.dat[u->wst.ptr - 3] << 8)); 791 u16 b = (u->wst.dat[u->wst.ptr - 2] | (u->wst.dat[u->wst.ptr - 3] << 8));
@@ -759,7 +800,7 @@ evaluxn(Uxn *u, u16 vec)
759 } 800 }
760 break; 801 break;
761 case 0x32: /* LDR2 */ 802 case 0x32: /* LDR2 */
762 __asm__( "evaluxn_32_LDR2:" ); 803 __asm__("evaluxn_32_LDR2:");
763 { 804 {
764 u8 a = u->wst.dat[u->wst.ptr - 1]; 805 u8 a = u->wst.dat[u->wst.ptr - 1];
765 u->wst.dat[u->wst.ptr - 1] = mempeek8(u->ram.dat, u->ram.ptr + (s8)a); 806 u->wst.dat[u->wst.ptr - 1] = mempeek8(u->ram.dat, u->ram.ptr + (s8)a);
@@ -778,7 +819,7 @@ evaluxn(Uxn *u, u16 vec)
778 } 819 }
779 break; 820 break;
780 case 0x33: /* STR2 */ 821 case 0x33: /* STR2 */
781 __asm__( "evaluxn_33_STR2:" ); 822 __asm__("evaluxn_33_STR2:");
782 { 823 {
783 u8 a = u->wst.dat[u->wst.ptr - 1]; 824 u8 a = u->wst.dat[u->wst.ptr - 1];
784 u16 b = (u->wst.dat[u->wst.ptr - 2] | (u->wst.dat[u->wst.ptr - 3] << 8)); 825 u16 b = (u->wst.dat[u->wst.ptr - 2] | (u->wst.dat[u->wst.ptr - 3] << 8));
@@ -793,7 +834,7 @@ evaluxn(Uxn *u, u16 vec)
793 } 834 }
794 break; 835 break;
795 case 0x34: /* LDA2 */ 836 case 0x34: /* LDA2 */
796 __asm__( "evaluxn_34_LDA2:" ); 837 __asm__("evaluxn_34_LDA2:");
797 { 838 {
798 u16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)); 839 u16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8));
799 u->wst.dat[u->wst.ptr - 2] = mempeek8(u->ram.dat, a); 840 u->wst.dat[u->wst.ptr - 2] = mempeek8(u->ram.dat, a);
@@ -807,7 +848,7 @@ evaluxn(Uxn *u, u16 vec)
807 } 848 }
808 break; 849 break;
809 case 0x35: /* STA2 */ 850 case 0x35: /* STA2 */
810 __asm__( "evaluxn_35_STA2:" ); 851 __asm__("evaluxn_35_STA2:");
811 { 852 {
812 u16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)); 853 u16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8));
813 u16 b = (u->wst.dat[u->wst.ptr - 3] | (u->wst.dat[u->wst.ptr - 4] << 8)); 854 u16 b = (u->wst.dat[u->wst.ptr - 3] | (u->wst.dat[u->wst.ptr - 4] << 8));
@@ -822,7 +863,7 @@ evaluxn(Uxn *u, u16 vec)
822 } 863 }
823 break; 864 break;
824 case 0x36: /* DEI2 */ 865 case 0x36: /* DEI2 */
825 __asm__( "evaluxn_36_DEI2:" ); 866 __asm__("evaluxn_36_DEI2:");
826 { 867 {
827 u8 a = u->wst.dat[u->wst.ptr - 1]; 868 u8 a = u->wst.dat[u->wst.ptr - 1];
828 u->wst.dat[u->wst.ptr - 1] = devpeek8(&u->dev[a >> 4], a); 869 u->wst.dat[u->wst.ptr - 1] = devpeek8(&u->dev[a >> 4], a);
@@ -841,7 +882,7 @@ evaluxn(Uxn *u, u16 vec)
841 } 882 }
842 break; 883 break;
843 case 0x37: /* DEO2 */ 884 case 0x37: /* DEO2 */
844 __asm__( "evaluxn_37_DEO2:" ); 885 __asm__("evaluxn_37_DEO2:");
845 { 886 {
846 u8 a = u->wst.dat[u->wst.ptr - 1]; 887 u8 a = u->wst.dat[u->wst.ptr - 1];
847 u16 b = (u->wst.dat[u->wst.ptr - 2] | (u->wst.dat[u->wst.ptr - 3] << 8)); 888 u16 b = (u->wst.dat[u->wst.ptr - 2] | (u->wst.dat[u->wst.ptr - 3] << 8));
@@ -856,7 +897,7 @@ evaluxn(Uxn *u, u16 vec)
856 } 897 }
857 break; 898 break;
858 case 0x38: /* ADD2 */ 899 case 0x38: /* ADD2 */
859 __asm__( "evaluxn_38_ADD2:" ); 900 __asm__("evaluxn_38_ADD2:");
860 { 901 {
861 u16 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)); 902 u16 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));
862 u->wst.dat[u->wst.ptr - 4] = (b + a) >> 8; 903 u->wst.dat[u->wst.ptr - 4] = (b + a) >> 8;
@@ -871,7 +912,7 @@ evaluxn(Uxn *u, u16 vec)
871 } 912 }
872 break; 913 break;
873 case 0x39: /* SUB2 */ 914 case 0x39: /* SUB2 */
874 __asm__( "evaluxn_39_SUB2:" ); 915 __asm__("evaluxn_39_SUB2:");
875 { 916 {
876 u16 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)); 917 u16 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));
877 u->wst.dat[u->wst.ptr - 4] = (b - a) >> 8; 918 u->wst.dat[u->wst.ptr - 4] = (b - a) >> 8;
@@ -886,7 +927,7 @@ evaluxn(Uxn *u, u16 vec)
886 } 927 }
887 break; 928 break;
888 case 0x3a: /* MUL2 */ 929 case 0x3a: /* MUL2 */
889 __asm__( "evaluxn_3a_MUL2:" ); 930 __asm__("evaluxn_3a_MUL2:");
890 { 931 {
891 u16 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)); 932 u16 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));
892 u->wst.dat[u->wst.ptr - 4] = (b * a) >> 8; 933 u->wst.dat[u->wst.ptr - 4] = (b * a) >> 8;
@@ -901,9 +942,16 @@ evaluxn(Uxn *u, u16 vec)
901 } 942 }
902 break; 943 break;
903 case 0x3b: /* DIV2 */ 944 case 0x3b: /* DIV2 */
904 __asm__( "evaluxn_3b_DIV2:" ); 945 __asm__("evaluxn_3b_DIV2:");
905 { 946 {
906 u16 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)); 947 u16 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));
948 if(a == 0) {
949 u->wst.error = 3;
950#ifndef NO_STACK_CHECKS
951 goto error;
952#endif
953 a = 1;
954 }
907 u->wst.dat[u->wst.ptr - 4] = (b / a) >> 8; 955 u->wst.dat[u->wst.ptr - 4] = (b / a) >> 8;
908 u->wst.dat[u->wst.ptr - 3] = (b / a) & 0xff; 956 u->wst.dat[u->wst.ptr - 3] = (b / a) & 0xff;
909#ifndef NO_STACK_CHECKS 957#ifndef NO_STACK_CHECKS
@@ -916,7 +964,7 @@ evaluxn(Uxn *u, u16 vec)
916 } 964 }
917 break; 965 break;
918 case 0x3c: /* AND2 */ 966 case 0x3c: /* AND2 */
919 __asm__( "evaluxn_3c_AND2:" ); 967 __asm__("evaluxn_3c_AND2:");
920 { 968 {
921 u8 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]; 969 u8 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];
922 u->wst.dat[u->wst.ptr - 4] = d & b; 970 u->wst.dat[u->wst.ptr - 4] = d & b;
@@ -931,7 +979,7 @@ evaluxn(Uxn *u, u16 vec)
931 } 979 }
932 break; 980 break;
933 case 0x3d: /* ORA2 */ 981 case 0x3d: /* ORA2 */
934 __asm__( "evaluxn_3d_ORA2:" ); 982 __asm__("evaluxn_3d_ORA2:");
935 { 983 {
936 u8 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]; 984 u8 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];
937 u->wst.dat[u->wst.ptr - 4] = d | b; 985 u->wst.dat[u->wst.ptr - 4] = d | b;
@@ -946,7 +994,7 @@ evaluxn(Uxn *u, u16 vec)
946 } 994 }
947 break; 995 break;
948 case 0x3e: /* EOR2 */ 996 case 0x3e: /* EOR2 */
949 __asm__( "evaluxn_3e_EOR2:" ); 997 __asm__("evaluxn_3e_EOR2:");
950 { 998 {
951 u8 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]; 999 u8 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];
952 u->wst.dat[u->wst.ptr - 4] = d ^ b; 1000 u->wst.dat[u->wst.ptr - 4] = d ^ b;
@@ -961,7 +1009,7 @@ evaluxn(Uxn *u, u16 vec)
961 } 1009 }
962 break; 1010 break;
963 case 0x3f: /* SFT2 */ 1011 case 0x3f: /* SFT2 */
964 __asm__( "evaluxn_3f_SFT2:" ); 1012 __asm__("evaluxn_3f_SFT2:");
965 { 1013 {
966 u8 a = u->wst.dat[u->wst.ptr - 1]; 1014 u8 a = u->wst.dat[u->wst.ptr - 1];
967 u16 b = (u->wst.dat[u->wst.ptr - 2] | (u->wst.dat[u->wst.ptr - 3] << 8)); 1015 u16 b = (u->wst.dat[u->wst.ptr - 2] | (u->wst.dat[u->wst.ptr - 3] << 8));
@@ -978,7 +1026,7 @@ evaluxn(Uxn *u, u16 vec)
978 break; 1026 break;
979 case 0x41: /* LITr */ 1027 case 0x41: /* LITr */
980 case 0xc1: /* LITkr */ 1028 case 0xc1: /* LITkr */
981 __asm__( "evaluxn_41_LITr:" ); 1029 __asm__("evaluxn_41_LITr:");
982 { 1030 {
983 u->rst.dat[u->rst.ptr] = mempeek8(u->ram.dat, u->ram.ptr++); 1031 u->rst.dat[u->rst.ptr] = mempeek8(u->ram.dat, u->ram.ptr++);
984#ifndef NO_STACK_CHECKS 1032#ifndef NO_STACK_CHECKS
@@ -990,8 +1038,8 @@ evaluxn(Uxn *u, u16 vec)
990 u->rst.ptr += 1; 1038 u->rst.ptr += 1;
991 } 1039 }
992 break; 1040 break;
993 case 0x43: /* POPr */ 1041 case 0x42: /* POPr */
994 __asm__( "evaluxn_43_POPr:" ); 1042 __asm__("evaluxn_42_POPr:");
995 { 1043 {
996 u->rst.dat[u->rst.ptr - 1]; 1044 u->rst.dat[u->rst.ptr - 1];
997#ifndef NO_STACK_CHECKS 1045#ifndef NO_STACK_CHECKS
@@ -1003,8 +1051,8 @@ evaluxn(Uxn *u, u16 vec)
1003 u->rst.ptr -= 1; 1051 u->rst.ptr -= 1;
1004 } 1052 }
1005 break; 1053 break;
1006 case 0x44: /* DUPr */ 1054 case 0x43: /* DUPr */
1007 __asm__( "evaluxn_44_DUPr:" ); 1055 __asm__("evaluxn_43_DUPr:");
1008 { 1056 {
1009 u8 a = u->rst.dat[u->rst.ptr - 1]; 1057 u8 a = u->rst.dat[u->rst.ptr - 1];
1010 u->rst.dat[u->rst.ptr] = a; 1058 u->rst.dat[u->rst.ptr] = a;
@@ -1021,8 +1069,23 @@ evaluxn(Uxn *u, u16 vec)
1021 u->rst.ptr += 1; 1069 u->rst.ptr += 1;
1022 } 1070 }
1023 break; 1071 break;
1072 case 0x44: /* NIPr */
1073 __asm__("evaluxn_44_NIPr:");
1074 {
1075 u8 a = u->rst.dat[u->rst.ptr - 1];
1076 u->rst.dat[u->rst.ptr - 2];
1077 u->rst.dat[u->rst.ptr - 2] = a;
1078#ifndef NO_STACK_CHECKS
1079 if(__builtin_expect(u->rst.ptr < 2, 0)) {
1080 u->rst.error = 1;
1081 goto error;
1082 }
1083#endif
1084 u->rst.ptr -= 1;
1085 }
1086 break;
1024 case 0x45: /* SWPr */ 1087 case 0x45: /* SWPr */
1025 __asm__( "evaluxn_45_SWPr:" ); 1088 __asm__("evaluxn_45_SWPr:");
1026 { 1089 {
1027 u8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; 1090 u8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2];
1028 u->rst.dat[u->rst.ptr - 2] = a; 1091 u->rst.dat[u->rst.ptr - 2] = a;
@@ -1036,7 +1099,7 @@ evaluxn(Uxn *u, u16 vec)
1036 } 1099 }
1037 break; 1100 break;
1038 case 0x46: /* OVRr */ 1101 case 0x46: /* OVRr */
1039 __asm__( "evaluxn_46_OVRr:" ); 1102 __asm__("evaluxn_46_OVRr:");
1040 { 1103 {
1041 u8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; 1104 u8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2];
1042 u->rst.dat[u->rst.ptr] = b; 1105 u->rst.dat[u->rst.ptr] = b;
@@ -1054,7 +1117,7 @@ evaluxn(Uxn *u, u16 vec)
1054 } 1117 }
1055 break; 1118 break;
1056 case 0x47: /* ROTr */ 1119 case 0x47: /* ROTr */
1057 __asm__( "evaluxn_47_ROTr:" ); 1120 __asm__("evaluxn_47_ROTr:");
1058 { 1121 {
1059 u8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2], c = u->rst.dat[u->rst.ptr - 3]; 1122 u8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2], c = u->rst.dat[u->rst.ptr - 3];
1060 u->rst.dat[u->rst.ptr - 3] = b; 1123 u->rst.dat[u->rst.ptr - 3] = b;
@@ -1069,7 +1132,7 @@ evaluxn(Uxn *u, u16 vec)
1069 } 1132 }
1070 break; 1133 break;
1071 case 0x48: /* EQUr */ 1134 case 0x48: /* EQUr */
1072 __asm__( "evaluxn_48_EQUr:" ); 1135 __asm__("evaluxn_48_EQUr:");
1073 { 1136 {
1074 u8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; 1137 u8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2];
1075 u->rst.dat[u->rst.ptr - 2] = b == a; 1138 u->rst.dat[u->rst.ptr - 2] = b == a;
@@ -1083,7 +1146,7 @@ evaluxn(Uxn *u, u16 vec)
1083 } 1146 }
1084 break; 1147 break;
1085 case 0x49: /* NEQr */ 1148 case 0x49: /* NEQr */
1086 __asm__( "evaluxn_49_NEQr:" ); 1149 __asm__("evaluxn_49_NEQr:");
1087 { 1150 {
1088 u8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; 1151 u8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2];
1089 u->rst.dat[u->rst.ptr - 2] = b != a; 1152 u->rst.dat[u->rst.ptr - 2] = b != a;
@@ -1097,7 +1160,7 @@ evaluxn(Uxn *u, u16 vec)
1097 } 1160 }
1098 break; 1161 break;
1099 case 0x4a: /* GTHr */ 1162 case 0x4a: /* GTHr */
1100 __asm__( "evaluxn_4a_GTHr:" ); 1163 __asm__("evaluxn_4a_GTHr:");
1101 { 1164 {
1102 u8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; 1165 u8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2];
1103 u->rst.dat[u->rst.ptr - 2] = b > a; 1166 u->rst.dat[u->rst.ptr - 2] = b > a;
@@ -1111,7 +1174,7 @@ evaluxn(Uxn *u, u16 vec)
1111 } 1174 }
1112 break; 1175 break;
1113 case 0x4b: /* LTHr */ 1176 case 0x4b: /* LTHr */
1114 __asm__( "evaluxn_4b_LTHr:" ); 1177 __asm__("evaluxn_4b_LTHr:");
1115 { 1178 {
1116 u8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; 1179 u8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2];
1117 u->rst.dat[u->rst.ptr - 2] = b < a; 1180 u->rst.dat[u->rst.ptr - 2] = b < a;
@@ -1125,7 +1188,7 @@ evaluxn(Uxn *u, u16 vec)
1125 } 1188 }
1126 break; 1189 break;
1127 case 0x4c: /* JMPr */ 1190 case 0x4c: /* JMPr */
1128 __asm__( "evaluxn_4c_JMPr:" ); 1191 __asm__("evaluxn_4c_JMPr:");
1129 { 1192 {
1130 u8 a = u->rst.dat[u->rst.ptr - 1]; 1193 u8 a = u->rst.dat[u->rst.ptr - 1];
1131 u->ram.ptr += (s8)a; 1194 u->ram.ptr += (s8)a;
@@ -1139,7 +1202,7 @@ evaluxn(Uxn *u, u16 vec)
1139 } 1202 }
1140 break; 1203 break;
1141 case 0x4d: /* JCNr */ 1204 case 0x4d: /* JCNr */
1142 __asm__( "evaluxn_4d_JCNr:" ); 1205 __asm__("evaluxn_4d_JCNr:");
1143 { 1206 {
1144 u8 a = u->rst.dat[u->rst.ptr - 1]; 1207 u8 a = u->rst.dat[u->rst.ptr - 1];
1145 if(u->rst.dat[u->rst.ptr - 2]) u->ram.ptr += (s8)a; 1208 if(u->rst.dat[u->rst.ptr - 2]) u->ram.ptr += (s8)a;
@@ -1153,7 +1216,7 @@ evaluxn(Uxn *u, u16 vec)
1153 } 1216 }
1154 break; 1217 break;
1155 case 0x4e: /* JSRr */ 1218 case 0x4e: /* JSRr */
1156 __asm__( "evaluxn_4e_JSRr:" ); 1219 __asm__("evaluxn_4e_JSRr:");
1157 { 1220 {
1158 u8 a = u->rst.dat[u->rst.ptr - 1]; 1221 u8 a = u->rst.dat[u->rst.ptr - 1];
1159 u->wst.dat[u->wst.ptr] = u->ram.ptr >> 8; 1222 u->wst.dat[u->wst.ptr] = u->ram.ptr >> 8;
@@ -1176,7 +1239,7 @@ evaluxn(Uxn *u, u16 vec)
1176 } 1239 }
1177 break; 1240 break;
1178 case 0x4f: /* STHr */ 1241 case 0x4f: /* STHr */
1179 __asm__( "evaluxn_4f_STHr:" ); 1242 __asm__("evaluxn_4f_STHr:");
1180 { 1243 {
1181 u8 a = u->rst.dat[u->rst.ptr - 1]; 1244 u8 a = u->rst.dat[u->rst.ptr - 1];
1182 u->wst.dat[u->wst.ptr] = a; 1245 u->wst.dat[u->wst.ptr] = a;
@@ -1197,7 +1260,7 @@ evaluxn(Uxn *u, u16 vec)
1197 } 1260 }
1198 break; 1261 break;
1199 case 0x50: /* LDZr */ 1262 case 0x50: /* LDZr */
1200 __asm__( "evaluxn_50_LDZr:" ); 1263 __asm__("evaluxn_50_LDZr:");
1201 { 1264 {
1202 u8 a = u->rst.dat[u->rst.ptr - 1]; 1265 u8 a = u->rst.dat[u->rst.ptr - 1];
1203 u->rst.dat[u->rst.ptr - 1] = mempeek8(u->ram.dat, a); 1266 u->rst.dat[u->rst.ptr - 1] = mempeek8(u->ram.dat, a);
@@ -1210,7 +1273,7 @@ evaluxn(Uxn *u, u16 vec)
1210 } 1273 }
1211 break; 1274 break;
1212 case 0x51: /* STZr */ 1275 case 0x51: /* STZr */
1213 __asm__( "evaluxn_51_STZr:" ); 1276 __asm__("evaluxn_51_STZr:");
1214 { 1277 {
1215 u8 a = u->rst.dat[u->rst.ptr - 1]; 1278 u8 a = u->rst.dat[u->rst.ptr - 1];
1216 u8 b = u->rst.dat[u->rst.ptr - 2]; 1279 u8 b = u->rst.dat[u->rst.ptr - 2];
@@ -1225,7 +1288,7 @@ evaluxn(Uxn *u, u16 vec)
1225 } 1288 }
1226 break; 1289 break;
1227 case 0x52: /* LDRr */ 1290 case 0x52: /* LDRr */
1228 __asm__( "evaluxn_52_LDRr:" ); 1291 __asm__("evaluxn_52_LDRr:");
1229 { 1292 {
1230 u8 a = u->rst.dat[u->rst.ptr - 1]; 1293 u8 a = u->rst.dat[u->rst.ptr - 1];
1231 u->rst.dat[u->rst.ptr - 1] = mempeek8(u->ram.dat, u->ram.ptr + (s8)a); 1294 u->rst.dat[u->rst.ptr - 1] = mempeek8(u->ram.dat, u->ram.ptr + (s8)a);
@@ -1238,7 +1301,7 @@ evaluxn(Uxn *u, u16 vec)
1238 } 1301 }
1239 break; 1302 break;
1240 case 0x53: /* STRr */ 1303 case 0x53: /* STRr */
1241 __asm__( "evaluxn_53_STRr:" ); 1304 __asm__("evaluxn_53_STRr:");
1242 { 1305 {
1243 u8 a = u->rst.dat[u->rst.ptr - 1]; 1306 u8 a = u->rst.dat[u->rst.ptr - 1];
1244 u8 b = u->rst.dat[u->rst.ptr - 2]; 1307 u8 b = u->rst.dat[u->rst.ptr - 2];
@@ -1253,7 +1316,7 @@ evaluxn(Uxn *u, u16 vec)
1253 } 1316 }
1254 break; 1317 break;
1255 case 0x54: /* LDAr */ 1318 case 0x54: /* LDAr */
1256 __asm__( "evaluxn_54_LDAr:" ); 1319 __asm__("evaluxn_54_LDAr:");
1257 { 1320 {
1258 u16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)); 1321 u16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8));
1259 u->rst.dat[u->rst.ptr - 2] = mempeek8(u->ram.dat, a); 1322 u->rst.dat[u->rst.ptr - 2] = mempeek8(u->ram.dat, a);
@@ -1267,7 +1330,7 @@ evaluxn(Uxn *u, u16 vec)
1267 } 1330 }
1268 break; 1331 break;
1269 case 0x55: /* STAr */ 1332 case 0x55: /* STAr */
1270 __asm__( "evaluxn_55_STAr:" ); 1333 __asm__("evaluxn_55_STAr:");
1271 { 1334 {
1272 u16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)); 1335 u16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8));
1273 u8 b = u->rst.dat[u->rst.ptr - 3]; 1336 u8 b = u->rst.dat[u->rst.ptr - 3];
@@ -1282,7 +1345,7 @@ evaluxn(Uxn *u, u16 vec)
1282 } 1345 }
1283 break; 1346 break;
1284 case 0x56: /* DEIr */ 1347 case 0x56: /* DEIr */
1285 __asm__( "evaluxn_56_DEIr:" ); 1348 __asm__("evaluxn_56_DEIr:");
1286 { 1349 {
1287 u8 a = u->rst.dat[u->rst.ptr - 1]; 1350 u8 a = u->rst.dat[u->rst.ptr - 1];
1288 u->rst.dat[u->rst.ptr - 1] = devpeek8(&u->dev[a >> 4], a); 1351 u->rst.dat[u->rst.ptr - 1] = devpeek8(&u->dev[a >> 4], a);
@@ -1295,7 +1358,7 @@ evaluxn(Uxn *u, u16 vec)
1295 } 1358 }
1296 break; 1359 break;
1297 case 0x57: /* DEOr */ 1360 case 0x57: /* DEOr */
1298 __asm__( "evaluxn_57_DEOr:" ); 1361 __asm__("evaluxn_57_DEOr:");
1299 { 1362 {
1300 u8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; 1363 u8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2];
1301 devpoke8(&u->dev[a >> 4], a, b); 1364 devpoke8(&u->dev[a >> 4], a, b);
@@ -1309,7 +1372,7 @@ evaluxn(Uxn *u, u16 vec)
1309 } 1372 }
1310 break; 1373 break;
1311 case 0x58: /* ADDr */ 1374 case 0x58: /* ADDr */
1312 __asm__( "evaluxn_58_ADDr:" ); 1375 __asm__("evaluxn_58_ADDr:");
1313 { 1376 {
1314 u8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; 1377 u8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2];
1315 u->rst.dat[u->rst.ptr - 2] = b + a; 1378 u->rst.dat[u->rst.ptr - 2] = b + a;
@@ -1323,7 +1386,7 @@ evaluxn(Uxn *u, u16 vec)
1323 } 1386 }
1324 break; 1387 break;
1325 case 0x59: /* SUBr */ 1388 case 0x59: /* SUBr */
1326 __asm__( "evaluxn_59_SUBr:" ); 1389 __asm__("evaluxn_59_SUBr:");
1327 { 1390 {
1328 u8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; 1391 u8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2];
1329 u->rst.dat[u->rst.ptr - 2] = b - a; 1392 u->rst.dat[u->rst.ptr - 2] = b - a;
@@ -1337,7 +1400,7 @@ evaluxn(Uxn *u, u16 vec)
1337 } 1400 }
1338 break; 1401 break;
1339 case 0x5a: /* MULr */ 1402 case 0x5a: /* MULr */
1340 __asm__( "evaluxn_5a_MULr:" ); 1403 __asm__("evaluxn_5a_MULr:");
1341 { 1404 {
1342 u8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; 1405 u8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2];
1343 u->rst.dat[u->rst.ptr - 2] = b * a; 1406 u->rst.dat[u->rst.ptr - 2] = b * a;
@@ -1351,9 +1414,16 @@ evaluxn(Uxn *u, u16 vec)
1351 } 1414 }
1352 break; 1415 break;
1353 case 0x5b: /* DIVr */ 1416 case 0x5b: /* DIVr */
1354 __asm__( "evaluxn_5b_DIVr:" ); 1417 __asm__("evaluxn_5b_DIVr:");
1355 { 1418 {
1356 u8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; 1419 u8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2];
1420 if(a == 0) {
1421 u->rst.error = 3;
1422#ifndef NO_STACK_CHECKS
1423 goto error;
1424#endif
1425 a = 1;
1426 }
1357 u->rst.dat[u->rst.ptr - 2] = b / a; 1427 u->rst.dat[u->rst.ptr - 2] = b / a;
1358#ifndef NO_STACK_CHECKS 1428#ifndef NO_STACK_CHECKS
1359 if(__builtin_expect(u->rst.ptr < 2, 0)) { 1429 if(__builtin_expect(u->rst.ptr < 2, 0)) {
@@ -1365,7 +1435,7 @@ evaluxn(Uxn *u, u16 vec)
1365 } 1435 }
1366 break; 1436 break;
1367 case 0x5c: /* ANDr */ 1437 case 0x5c: /* ANDr */
1368 __asm__( "evaluxn_5c_ANDr:" ); 1438 __asm__("evaluxn_5c_ANDr:");
1369 { 1439 {
1370 u8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; 1440 u8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2];
1371 u->rst.dat[u->rst.ptr - 2] = b & a; 1441 u->rst.dat[u->rst.ptr - 2] = b & a;
@@ -1379,7 +1449,7 @@ evaluxn(Uxn *u, u16 vec)
1379 } 1449 }
1380 break; 1450 break;
1381 case 0x5d: /* ORAr */ 1451 case 0x5d: /* ORAr */
1382 __asm__( "evaluxn_5d_ORAr:" ); 1452 __asm__("evaluxn_5d_ORAr:");
1383 { 1453 {
1384 u8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; 1454 u8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2];
1385 u->rst.dat[u->rst.ptr - 2] = b | a; 1455 u->rst.dat[u->rst.ptr - 2] = b | a;
@@ -1393,7 +1463,7 @@ evaluxn(Uxn *u, u16 vec)
1393 } 1463 }
1394 break; 1464 break;
1395 case 0x5e: /* EORr */ 1465 case 0x5e: /* EORr */
1396 __asm__( "evaluxn_5e_EORr:" ); 1466 __asm__("evaluxn_5e_EORr:");
1397 { 1467 {
1398 u8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; 1468 u8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2];
1399 u->rst.dat[u->rst.ptr - 2] = b ^ a; 1469 u->rst.dat[u->rst.ptr - 2] = b ^ a;
@@ -1407,7 +1477,7 @@ evaluxn(Uxn *u, u16 vec)
1407 } 1477 }
1408 break; 1478 break;
1409 case 0x5f: /* SFTr */ 1479 case 0x5f: /* SFTr */
1410 __asm__( "evaluxn_5f_SFTr:" ); 1480 __asm__("evaluxn_5f_SFTr:");
1411 { 1481 {
1412 u8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; 1482 u8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2];
1413 u->rst.dat[u->rst.ptr - 2] = b >> (a & 0x07) << ((a & 0x70) >> 4); 1483 u->rst.dat[u->rst.ptr - 2] = b >> (a & 0x07) << ((a & 0x70) >> 4);
@@ -1422,7 +1492,7 @@ evaluxn(Uxn *u, u16 vec)
1422 break; 1492 break;
1423 case 0x61: /* LIT2r */ 1493 case 0x61: /* LIT2r */
1424 case 0xe1: /* LIT2kr */ 1494 case 0xe1: /* LIT2kr */
1425 __asm__( "evaluxn_61_LIT2r:" ); 1495 __asm__("evaluxn_61_LIT2r:");
1426 { 1496 {
1427 u->rst.dat[u->rst.ptr] = mempeek8(u->ram.dat, u->ram.ptr++); 1497 u->rst.dat[u->rst.ptr] = mempeek8(u->ram.dat, u->ram.ptr++);
1428 u->rst.dat[u->rst.ptr + 1] = mempeek8(u->ram.dat, u->ram.ptr++); 1498 u->rst.dat[u->rst.ptr + 1] = mempeek8(u->ram.dat, u->ram.ptr++);
@@ -1435,8 +1505,8 @@ evaluxn(Uxn *u, u16 vec)
1435 u->rst.ptr += 2; 1505 u->rst.ptr += 2;
1436 } 1506 }
1437 break; 1507 break;
1438 case 0x63: /* POP2r */ 1508 case 0x62: /* POP2r */
1439 __asm__( "evaluxn_63_POP2r:" ); 1509 __asm__("evaluxn_62_POP2r:");
1440 { 1510 {
1441 (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)); 1511 (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8));
1442#ifndef NO_STACK_CHECKS 1512#ifndef NO_STACK_CHECKS
@@ -1448,8 +1518,8 @@ evaluxn(Uxn *u, u16 vec)
1448 u->rst.ptr -= 2; 1518 u->rst.ptr -= 2;
1449 } 1519 }
1450 break; 1520 break;
1451 case 0x64: /* DUP2r */ 1521 case 0x63: /* DUP2r */
1452 __asm__( "evaluxn_64_DUP2r:" ); 1522 __asm__("evaluxn_63_DUP2r:");
1453 { 1523 {
1454 u8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; 1524 u8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2];
1455 u->rst.dat[u->rst.ptr] = b; 1525 u->rst.dat[u->rst.ptr] = b;
@@ -1467,8 +1537,24 @@ evaluxn(Uxn *u, u16 vec)
1467 u->rst.ptr += 2; 1537 u->rst.ptr += 2;
1468 } 1538 }
1469 break; 1539 break;
1540 case 0x64: /* NIP2r */
1541 __asm__("evaluxn_64_NIP2r:");
1542 {
1543 u16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8));
1544 (u->rst.dat[u->rst.ptr - 3] | (u->rst.dat[u->rst.ptr - 4] << 8));
1545 u->rst.dat[u->rst.ptr - 4] = a >> 8;
1546 u->rst.dat[u->rst.ptr - 3] = a & 0xff;
1547#ifndef NO_STACK_CHECKS
1548 if(__builtin_expect(u->rst.ptr < 4, 0)) {
1549 u->rst.error = 1;
1550 goto error;
1551 }
1552#endif
1553 u->rst.ptr -= 2;
1554 }
1555 break;
1470 case 0x65: /* SWP2r */ 1556 case 0x65: /* SWP2r */
1471 __asm__( "evaluxn_65_SWP2r:" ); 1557 __asm__("evaluxn_65_SWP2r:");
1472 { 1558 {
1473 u8 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]; 1559 u8 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];
1474 u->rst.dat[u->rst.ptr - 4] = b; 1560 u->rst.dat[u->rst.ptr - 4] = b;
@@ -1484,7 +1570,7 @@ evaluxn(Uxn *u, u16 vec)
1484 } 1570 }
1485 break; 1571 break;
1486 case 0x66: /* OVR2r */ 1572 case 0x66: /* OVR2r */
1487 __asm__( "evaluxn_66_OVR2r:" ); 1573 __asm__("evaluxn_66_OVR2r:");
1488 { 1574 {
1489 u8 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]; 1575 u8 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];
1490 u->rst.dat[u->rst.ptr] = d; 1576 u->rst.dat[u->rst.ptr] = d;
@@ -1503,7 +1589,7 @@ evaluxn(Uxn *u, u16 vec)
1503 } 1589 }
1504 break; 1590 break;
1505 case 0x67: /* ROT2r */ 1591 case 0x67: /* ROT2r */
1506 __asm__( "evaluxn_67_ROT2r:" ); 1592 __asm__("evaluxn_67_ROT2r:");
1507 { 1593 {
1508 u8 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], e = u->rst.dat[u->rst.ptr - 5], f = u->rst.dat[u->rst.ptr - 6]; 1594 u8 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], e = u->rst.dat[u->rst.ptr - 5], f = u->rst.dat[u->rst.ptr - 6];
1509 u->rst.dat[u->rst.ptr - 6] = d; 1595 u->rst.dat[u->rst.ptr - 6] = d;
@@ -1521,7 +1607,7 @@ evaluxn(Uxn *u, u16 vec)
1521 } 1607 }
1522 break; 1608 break;
1523 case 0x68: /* EQU2r */ 1609 case 0x68: /* EQU2r */
1524 __asm__( "evaluxn_68_EQU2r:" ); 1610 __asm__("evaluxn_68_EQU2r:");
1525 { 1611 {
1526 u16 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)); 1612 u16 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));
1527 u->rst.dat[u->rst.ptr - 4] = b == a; 1613 u->rst.dat[u->rst.ptr - 4] = b == a;
@@ -1535,7 +1621,7 @@ evaluxn(Uxn *u, u16 vec)
1535 } 1621 }
1536 break; 1622 break;
1537 case 0x69: /* NEQ2r */ 1623 case 0x69: /* NEQ2r */
1538 __asm__( "evaluxn_69_NEQ2r:" ); 1624 __asm__("evaluxn_69_NEQ2r:");
1539 { 1625 {
1540 u16 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)); 1626 u16 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));
1541 u->rst.dat[u->rst.ptr - 4] = b != a; 1627 u->rst.dat[u->rst.ptr - 4] = b != a;
@@ -1549,7 +1635,7 @@ evaluxn(Uxn *u, u16 vec)
1549 } 1635 }
1550 break; 1636 break;
1551 case 0x6a: /* GTH2r */ 1637 case 0x6a: /* GTH2r */
1552 __asm__( "evaluxn_6a_GTH2r:" ); 1638 __asm__("evaluxn_6a_GTH2r:");
1553 { 1639 {
1554 u16 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)); 1640 u16 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));
1555 u->rst.dat[u->rst.ptr - 4] = b > a; 1641 u->rst.dat[u->rst.ptr - 4] = b > a;
@@ -1563,7 +1649,7 @@ evaluxn(Uxn *u, u16 vec)
1563 } 1649 }
1564 break; 1650 break;
1565 case 0x6b: /* LTH2r */ 1651 case 0x6b: /* LTH2r */
1566 __asm__( "evaluxn_6b_LTH2r:" ); 1652 __asm__("evaluxn_6b_LTH2r:");
1567 { 1653 {
1568 u16 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)); 1654 u16 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));
1569 u->rst.dat[u->rst.ptr - 4] = b < a; 1655 u->rst.dat[u->rst.ptr - 4] = b < a;
@@ -1577,7 +1663,7 @@ evaluxn(Uxn *u, u16 vec)
1577 } 1663 }
1578 break; 1664 break;
1579 case 0x6c: /* JMP2r */ 1665 case 0x6c: /* JMP2r */
1580 __asm__( "evaluxn_6c_JMP2r:" ); 1666 __asm__("evaluxn_6c_JMP2r:");
1581 { 1667 {
1582 u->ram.ptr = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)); 1668 u->ram.ptr = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8));
1583#ifndef NO_STACK_CHECKS 1669#ifndef NO_STACK_CHECKS
@@ -1590,7 +1676,7 @@ evaluxn(Uxn *u, u16 vec)
1590 } 1676 }
1591 break; 1677 break;
1592 case 0x6d: /* JCN2r */ 1678 case 0x6d: /* JCN2r */
1593 __asm__( "evaluxn_6d_JCN2r:" ); 1679 __asm__("evaluxn_6d_JCN2r:");
1594 { 1680 {
1595 u16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)); 1681 u16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8));
1596 if(u->rst.dat[u->rst.ptr - 3]) u->ram.ptr = a; 1682 if(u->rst.dat[u->rst.ptr - 3]) u->ram.ptr = a;
@@ -1604,7 +1690,7 @@ evaluxn(Uxn *u, u16 vec)
1604 } 1690 }
1605 break; 1691 break;
1606 case 0x6e: /* JSR2r */ 1692 case 0x6e: /* JSR2r */
1607 __asm__( "evaluxn_6e_JSR2r:" ); 1693 __asm__("evaluxn_6e_JSR2r:");
1608 { 1694 {
1609 u->wst.dat[u->wst.ptr] = u->ram.ptr >> 8; 1695 u->wst.dat[u->wst.ptr] = u->ram.ptr >> 8;
1610 u->wst.dat[u->wst.ptr + 1] = u->ram.ptr & 0xff; 1696 u->wst.dat[u->wst.ptr + 1] = u->ram.ptr & 0xff;
@@ -1626,7 +1712,7 @@ evaluxn(Uxn *u, u16 vec)
1626 } 1712 }
1627 break; 1713 break;
1628 case 0x6f: /* STH2r */ 1714 case 0x6f: /* STH2r */
1629 __asm__( "evaluxn_6f_STH2r:" ); 1715 __asm__("evaluxn_6f_STH2r:");
1630 { 1716 {
1631 u8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; 1717 u8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2];
1632 u->wst.dat[u->wst.ptr] = b; 1718 u->wst.dat[u->wst.ptr] = b;
@@ -1648,7 +1734,7 @@ evaluxn(Uxn *u, u16 vec)
1648 } 1734 }
1649 break; 1735 break;
1650 case 0x70: /* LDZ2r */ 1736 case 0x70: /* LDZ2r */
1651 __asm__( "evaluxn_70_LDZ2r:" ); 1737 __asm__("evaluxn_70_LDZ2r:");
1652 { 1738 {
1653 u8 a = u->rst.dat[u->rst.ptr - 1]; 1739 u8 a = u->rst.dat[u->rst.ptr - 1];
1654 u->rst.dat[u->rst.ptr - 1] = mempeek8(u->ram.dat, a); 1740 u->rst.dat[u->rst.ptr - 1] = mempeek8(u->ram.dat, a);
@@ -1667,7 +1753,7 @@ evaluxn(Uxn *u, u16 vec)
1667 } 1753 }
1668 break; 1754 break;
1669 case 0x71: /* STZ2r */ 1755 case 0x71: /* STZ2r */
1670 __asm__( "evaluxn_71_STZ2r:" ); 1756 __asm__("evaluxn_71_STZ2r:");
1671 { 1757 {
1672 u8 a = u->rst.dat[u->rst.ptr - 1]; 1758 u8 a = u->rst.dat[u->rst.ptr - 1];
1673 u16 b = (u->rst.dat[u->rst.ptr - 2] | (u->rst.dat[u->rst.ptr - 3] << 8)); 1759 u16 b = (u->rst.dat[u->rst.ptr - 2] | (u->rst.dat[u->rst.ptr - 3] << 8));
@@ -1682,7 +1768,7 @@ evaluxn(Uxn *u, u16 vec)
1682 } 1768 }
1683 break; 1769 break;
1684 case 0x72: /* LDR2r */ 1770 case 0x72: /* LDR2r */
1685 __asm__( "evaluxn_72_LDR2r:" ); 1771 __asm__("evaluxn_72_LDR2r:");
1686 { 1772 {
1687 u8 a = u->rst.dat[u->rst.ptr - 1]; 1773 u8 a = u->rst.dat[u->rst.ptr - 1];
1688 u->rst.dat[u->rst.ptr - 1] = mempeek8(u->ram.dat, u->ram.ptr + (s8)a); 1774 u->rst.dat[u->rst.ptr - 1] = mempeek8(u->ram.dat, u->ram.ptr + (s8)a);
@@ -1701,7 +1787,7 @@ evaluxn(Uxn *u, u16 vec)
1701 } 1787 }
1702 break; 1788 break;
1703 case 0x73: /* STR2r */ 1789 case 0x73: /* STR2r */
1704 __asm__( "evaluxn_73_STR2r:" ); 1790 __asm__("evaluxn_73_STR2r:");
1705 { 1791 {
1706 u8 a = u->rst.dat[u->rst.ptr - 1]; 1792 u8 a = u->rst.dat[u->rst.ptr - 1];
1707 u16 b = (u->rst.dat[u->rst.ptr - 2] | (u->rst.dat[u->rst.ptr - 3] << 8)); 1793 u16 b = (u->rst.dat[u->rst.ptr - 2] | (u->rst.dat[u->rst.ptr - 3] << 8));
@@ -1716,7 +1802,7 @@ evaluxn(Uxn *u, u16 vec)
1716 } 1802 }
1717 break; 1803 break;
1718 case 0x74: /* LDA2r */ 1804 case 0x74: /* LDA2r */
1719 __asm__( "evaluxn_74_LDA2r:" ); 1805 __asm__("evaluxn_74_LDA2r:");
1720 { 1806 {
1721 u16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)); 1807 u16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8));
1722 u->rst.dat[u->rst.ptr - 2] = mempeek8(u->ram.dat, a); 1808 u->rst.dat[u->rst.ptr - 2] = mempeek8(u->ram.dat, a);
@@ -1730,7 +1816,7 @@ evaluxn(Uxn *u, u16 vec)
1730 } 1816 }
1731 break; 1817 break;
1732 case 0x75: /* STA2r */ 1818 case 0x75: /* STA2r */
1733 __asm__( "evaluxn_75_STA2r:" ); 1819 __asm__("evaluxn_75_STA2r:");
1734 { 1820 {
1735 u16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)); 1821 u16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8));
1736 u16 b = (u->rst.dat[u->rst.ptr - 3] | (u->rst.dat[u->rst.ptr - 4] << 8)); 1822 u16 b = (u->rst.dat[u->rst.ptr - 3] | (u->rst.dat[u->rst.ptr - 4] << 8));
@@ -1745,7 +1831,7 @@ evaluxn(Uxn *u, u16 vec)
1745 } 1831 }
1746 break; 1832 break;
1747 case 0x76: /* DEI2r */ 1833 case 0x76: /* DEI2r */
1748 __asm__( "evaluxn_76_DEI2r:" ); 1834 __asm__("evaluxn_76_DEI2r:");
1749 { 1835 {
1750 u8 a = u->rst.dat[u->rst.ptr - 1]; 1836 u8 a = u->rst.dat[u->rst.ptr - 1];
1751 u->rst.dat[u->rst.ptr - 1] = devpeek8(&u->dev[a >> 4], a); 1837 u->rst.dat[u->rst.ptr - 1] = devpeek8(&u->dev[a >> 4], a);
@@ -1764,7 +1850,7 @@ evaluxn(Uxn *u, u16 vec)
1764 } 1850 }
1765 break; 1851 break;
1766 case 0x77: /* DEO2r */ 1852 case 0x77: /* DEO2r */
1767 __asm__( "evaluxn_77_DEO2r:" ); 1853 __asm__("evaluxn_77_DEO2r:");
1768 { 1854 {
1769 u8 a = u->rst.dat[u->rst.ptr - 1]; 1855 u8 a = u->rst.dat[u->rst.ptr - 1];
1770 u16 b = (u->rst.dat[u->rst.ptr - 2] | (u->rst.dat[u->rst.ptr - 3] << 8)); 1856 u16 b = (u->rst.dat[u->rst.ptr - 2] | (u->rst.dat[u->rst.ptr - 3] << 8));
@@ -1779,7 +1865,7 @@ evaluxn(Uxn *u, u16 vec)
1779 } 1865 }
1780 break; 1866 break;
1781 case 0x78: /* ADD2r */ 1867 case 0x78: /* ADD2r */
1782 __asm__( "evaluxn_78_ADD2r:" ); 1868 __asm__("evaluxn_78_ADD2r:");
1783 { 1869 {
1784 u16 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)); 1870 u16 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));
1785 u->rst.dat[u->rst.ptr - 4] = (b + a) >> 8; 1871 u->rst.dat[u->rst.ptr - 4] = (b + a) >> 8;
@@ -1794,7 +1880,7 @@ evaluxn(Uxn *u, u16 vec)
1794 } 1880 }
1795 break; 1881 break;
1796 case 0x79: /* SUB2r */ 1882 case 0x79: /* SUB2r */
1797 __asm__( "evaluxn_79_SUB2r:" ); 1883 __asm__("evaluxn_79_SUB2r:");
1798 { 1884 {
1799 u16 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)); 1885 u16 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));
1800 u->rst.dat[u->rst.ptr - 4] = (b - a) >> 8; 1886 u->rst.dat[u->rst.ptr - 4] = (b - a) >> 8;
@@ -1809,7 +1895,7 @@ evaluxn(Uxn *u, u16 vec)
1809 } 1895 }
1810 break; 1896 break;
1811 case 0x7a: /* MUL2r */ 1897 case 0x7a: /* MUL2r */
1812 __asm__( "evaluxn_7a_MUL2r:" ); 1898 __asm__("evaluxn_7a_MUL2r:");
1813 { 1899 {
1814 u16 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)); 1900 u16 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));
1815 u->rst.dat[u->rst.ptr - 4] = (b * a) >> 8; 1901 u->rst.dat[u->rst.ptr - 4] = (b * a) >> 8;
@@ -1824,9 +1910,16 @@ evaluxn(Uxn *u, u16 vec)
1824 } 1910 }
1825 break; 1911 break;
1826 case 0x7b: /* DIV2r */ 1912 case 0x7b: /* DIV2r */
1827 __asm__( "evaluxn_7b_DIV2r:" ); 1913 __asm__("evaluxn_7b_DIV2r:");
1828 { 1914 {
1829 u16 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)); 1915 u16 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));
1916 if(a == 0) {
1917 u->rst.error = 3;
1918#ifndef NO_STACK_CHECKS
1919 goto error;
1920#endif
1921 a = 1;
1922 }
1830 u->rst.dat[u->rst.ptr - 4] = (b / a) >> 8; 1923 u->rst.dat[u->rst.ptr - 4] = (b / a) >> 8;
1831 u->rst.dat[u->rst.ptr - 3] = (b / a) & 0xff; 1924 u->rst.dat[u->rst.ptr - 3] = (b / a) & 0xff;
1832#ifndef NO_STACK_CHECKS 1925#ifndef NO_STACK_CHECKS
@@ -1839,7 +1932,7 @@ evaluxn(Uxn *u, u16 vec)
1839 } 1932 }
1840 break; 1933 break;
1841 case 0x7c: /* AND2r */ 1934 case 0x7c: /* AND2r */
1842 __asm__( "evaluxn_7c_AND2r:" ); 1935 __asm__("evaluxn_7c_AND2r:");
1843 { 1936 {
1844 u8 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]; 1937 u8 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];
1845 u->rst.dat[u->rst.ptr - 4] = d & b; 1938 u->rst.dat[u->rst.ptr - 4] = d & b;
@@ -1854,7 +1947,7 @@ evaluxn(Uxn *u, u16 vec)
1854 } 1947 }
1855 break; 1948 break;
1856 case 0x7d: /* ORA2r */ 1949 case 0x7d: /* ORA2r */
1857 __asm__( "evaluxn_7d_ORA2r:" ); 1950 __asm__("evaluxn_7d_ORA2r:");
1858 { 1951 {
1859 u8 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]; 1952 u8 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];
1860 u->rst.dat[u->rst.ptr - 4] = d | b; 1953 u->rst.dat[u->rst.ptr - 4] = d | b;
@@ -1869,7 +1962,7 @@ evaluxn(Uxn *u, u16 vec)
1869 } 1962 }
1870 break; 1963 break;
1871 case 0x7e: /* EOR2r */ 1964 case 0x7e: /* EOR2r */
1872 __asm__( "evaluxn_7e_EOR2r:" ); 1965 __asm__("evaluxn_7e_EOR2r:");
1873 { 1966 {
1874 u8 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]; 1967 u8 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];
1875 u->rst.dat[u->rst.ptr - 4] = d ^ b; 1968 u->rst.dat[u->rst.ptr - 4] = d ^ b;
@@ -1884,7 +1977,7 @@ evaluxn(Uxn *u, u16 vec)
1884 } 1977 }
1885 break; 1978 break;
1886 case 0x7f: /* SFT2r */ 1979 case 0x7f: /* SFT2r */
1887 __asm__( "evaluxn_7f_SFT2r:" ); 1980 __asm__("evaluxn_7f_SFT2r:");
1888 { 1981 {
1889 u8 a = u->rst.dat[u->rst.ptr - 1]; 1982 u8 a = u->rst.dat[u->rst.ptr - 1];
1890 u16 b = (u->rst.dat[u->rst.ptr - 2] | (u->rst.dat[u->rst.ptr - 3] << 8)); 1983 u16 b = (u->rst.dat[u->rst.ptr - 2] | (u->rst.dat[u->rst.ptr - 3] << 8));
@@ -1899,8 +1992,8 @@ evaluxn(Uxn *u, u16 vec)
1899 u->rst.ptr -= 1; 1992 u->rst.ptr -= 1;
1900 } 1993 }
1901 break; 1994 break;
1902 case 0x83: /* POPk */ 1995 case 0x82: /* POPk */
1903 __asm__( "evaluxn_83_POPk:" ); 1996 __asm__("evaluxn_82_POPk:");
1904 { 1997 {
1905 u->wst.dat[u->wst.ptr - 1]; 1998 u->wst.dat[u->wst.ptr - 1];
1906#ifndef NO_STACK_CHECKS 1999#ifndef NO_STACK_CHECKS
@@ -1911,8 +2004,8 @@ evaluxn(Uxn *u, u16 vec)
1911#endif 2004#endif
1912 } 2005 }
1913 break; 2006 break;
1914 case 0x84: /* DUPk */ 2007 case 0x83: /* DUPk */
1915 __asm__( "evaluxn_84_DUPk:" ); 2008 __asm__("evaluxn_83_DUPk:");
1916 { 2009 {
1917 u8 a = u->wst.dat[u->wst.ptr - 1]; 2010 u8 a = u->wst.dat[u->wst.ptr - 1];
1918 u->wst.dat[u->wst.ptr] = a; 2011 u->wst.dat[u->wst.ptr] = a;
@@ -1930,8 +2023,27 @@ evaluxn(Uxn *u, u16 vec)
1930 u->wst.ptr += 2; 2023 u->wst.ptr += 2;
1931 } 2024 }
1932 break; 2025 break;
2026 case 0x84: /* NIPk */
2027 __asm__("evaluxn_84_NIPk:");
2028 {
2029 u8 a = u->wst.dat[u->wst.ptr - 1];
2030 u->wst.dat[u->wst.ptr - 2];
2031 u->wst.dat[u->wst.ptr] = a;
2032#ifndef NO_STACK_CHECKS
2033 if(__builtin_expect(u->wst.ptr < 2, 0)) {
2034 u->wst.error = 1;
2035 goto error;
2036 }
2037 if(__builtin_expect(u->wst.ptr > 254, 0)) {
2038 u->wst.error = 2;
2039 goto error;
2040 }
2041#endif
2042 u->wst.ptr += 1;
2043 }
2044 break;
1933 case 0x85: /* SWPk */ 2045 case 0x85: /* SWPk */
1934 __asm__( "evaluxn_85_SWPk:" ); 2046 __asm__("evaluxn_85_SWPk:");
1935 { 2047 {
1936 u8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; 2048 u8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2];
1937 u->wst.dat[u->wst.ptr] = a; 2049 u->wst.dat[u->wst.ptr] = a;
@@ -1950,7 +2062,7 @@ evaluxn(Uxn *u, u16 vec)
1950 } 2062 }
1951 break; 2063 break;
1952 case 0x86: /* OVRk */ 2064 case 0x86: /* OVRk */
1953 __asm__( "evaluxn_86_OVRk:" ); 2065 __asm__("evaluxn_86_OVRk:");
1954 { 2066 {
1955 u8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; 2067 u8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2];
1956 u->wst.dat[u->wst.ptr] = b; 2068 u->wst.dat[u->wst.ptr] = b;
@@ -1970,7 +2082,7 @@ evaluxn(Uxn *u, u16 vec)
1970 } 2082 }
1971 break; 2083 break;
1972 case 0x87: /* ROTk */ 2084 case 0x87: /* ROTk */
1973 __asm__( "evaluxn_87_ROTk:" ); 2085 __asm__("evaluxn_87_ROTk:");
1974 { 2086 {
1975 u8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2], c = u->wst.dat[u->wst.ptr - 3]; 2087 u8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2], c = u->wst.dat[u->wst.ptr - 3];
1976 u->wst.dat[u->wst.ptr] = b; 2088 u->wst.dat[u->wst.ptr] = b;
@@ -1990,7 +2102,7 @@ evaluxn(Uxn *u, u16 vec)
1990 } 2102 }
1991 break; 2103 break;
1992 case 0x88: /* EQUk */ 2104 case 0x88: /* EQUk */
1993 __asm__( "evaluxn_88_EQUk:" ); 2105 __asm__("evaluxn_88_EQUk:");
1994 { 2106 {
1995 u8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; 2107 u8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2];
1996 u->wst.dat[u->wst.ptr] = b == a; 2108 u->wst.dat[u->wst.ptr] = b == a;
@@ -2008,7 +2120,7 @@ evaluxn(Uxn *u, u16 vec)
2008 } 2120 }
2009 break; 2121 break;
2010 case 0x89: /* NEQk */ 2122 case 0x89: /* NEQk */
2011 __asm__( "evaluxn_89_NEQk:" ); 2123 __asm__("evaluxn_89_NEQk:");
2012 { 2124 {
2013 u8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; 2125 u8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2];
2014 u->wst.dat[u->wst.ptr] = b != a; 2126 u->wst.dat[u->wst.ptr] = b != a;
@@ -2026,7 +2138,7 @@ evaluxn(Uxn *u, u16 vec)
2026 } 2138 }
2027 break; 2139 break;
2028 case 0x8a: /* GTHk */ 2140 case 0x8a: /* GTHk */
2029 __asm__( "evaluxn_8a_GTHk:" ); 2141 __asm__("evaluxn_8a_GTHk:");
2030 { 2142 {
2031 u8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; 2143 u8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2];
2032 u->wst.dat[u->wst.ptr] = b > a; 2144 u->wst.dat[u->wst.ptr] = b > a;
@@ -2044,7 +2156,7 @@ evaluxn(Uxn *u, u16 vec)
2044 } 2156 }
2045 break; 2157 break;
2046 case 0x8b: /* LTHk */ 2158 case 0x8b: /* LTHk */
2047 __asm__( "evaluxn_8b_LTHk:" ); 2159 __asm__("evaluxn_8b_LTHk:");
2048 { 2160 {
2049 u8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; 2161 u8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2];
2050 u->wst.dat[u->wst.ptr] = b < a; 2162 u->wst.dat[u->wst.ptr] = b < a;
@@ -2062,7 +2174,7 @@ evaluxn(Uxn *u, u16 vec)
2062 } 2174 }
2063 break; 2175 break;
2064 case 0x8c: /* JMPk */ 2176 case 0x8c: /* JMPk */
2065 __asm__( "evaluxn_8c_JMPk:" ); 2177 __asm__("evaluxn_8c_JMPk:");
2066 { 2178 {
2067 u8 a = u->wst.dat[u->wst.ptr - 1]; 2179 u8 a = u->wst.dat[u->wst.ptr - 1];
2068 u->ram.ptr += (s8)a; 2180 u->ram.ptr += (s8)a;
@@ -2075,7 +2187,7 @@ evaluxn(Uxn *u, u16 vec)
2075 } 2187 }
2076 break; 2188 break;
2077 case 0x8d: /* JCNk */ 2189 case 0x8d: /* JCNk */
2078 __asm__( "evaluxn_8d_JCNk:" ); 2190 __asm__("evaluxn_8d_JCNk:");
2079 { 2191 {
2080 u8 a = u->wst.dat[u->wst.ptr - 1]; 2192 u8 a = u->wst.dat[u->wst.ptr - 1];
2081 if(u->wst.dat[u->wst.ptr - 2]) u->ram.ptr += (s8)a; 2193 if(u->wst.dat[u->wst.ptr - 2]) u->ram.ptr += (s8)a;
@@ -2088,7 +2200,7 @@ evaluxn(Uxn *u, u16 vec)
2088 } 2200 }
2089 break; 2201 break;
2090 case 0x8e: /* JSRk */ 2202 case 0x8e: /* JSRk */
2091 __asm__( "evaluxn_8e_JSRk:" ); 2203 __asm__("evaluxn_8e_JSRk:");
2092 { 2204 {
2093 u8 a = u->wst.dat[u->wst.ptr - 1]; 2205 u8 a = u->wst.dat[u->wst.ptr - 1];
2094 u->rst.dat[u->rst.ptr] = u->ram.ptr >> 8; 2206 u->rst.dat[u->rst.ptr] = u->ram.ptr >> 8;
@@ -2108,7 +2220,7 @@ evaluxn(Uxn *u, u16 vec)
2108 } 2220 }
2109 break; 2221 break;
2110 case 0x8f: /* STHk */ 2222 case 0x8f: /* STHk */
2111 __asm__( "evaluxn_8f_STHk:" ); 2223 __asm__("evaluxn_8f_STHk:");
2112 { 2224 {
2113 u8 a = u->wst.dat[u->wst.ptr - 1]; 2225 u8 a = u->wst.dat[u->wst.ptr - 1];
2114 u->rst.dat[u->rst.ptr] = a; 2226 u->rst.dat[u->rst.ptr] = a;
@@ -2126,7 +2238,7 @@ evaluxn(Uxn *u, u16 vec)
2126 } 2238 }
2127 break; 2239 break;
2128 case 0x90: /* LDZk */ 2240 case 0x90: /* LDZk */
2129 __asm__( "evaluxn_90_LDZk:" ); 2241 __asm__("evaluxn_90_LDZk:");
2130 { 2242 {
2131 u8 a = u->wst.dat[u->wst.ptr - 1]; 2243 u8 a = u->wst.dat[u->wst.ptr - 1];
2132 u->wst.dat[u->wst.ptr] = mempeek8(u->ram.dat, a); 2244 u->wst.dat[u->wst.ptr] = mempeek8(u->ram.dat, a);
@@ -2144,7 +2256,7 @@ evaluxn(Uxn *u, u16 vec)
2144 } 2256 }
2145 break; 2257 break;
2146 case 0x91: /* STZk */ 2258 case 0x91: /* STZk */
2147 __asm__( "evaluxn_91_STZk:" ); 2259 __asm__("evaluxn_91_STZk:");
2148 { 2260 {
2149 u8 a = u->wst.dat[u->wst.ptr - 1]; 2261 u8 a = u->wst.dat[u->wst.ptr - 1];
2150 u8 b = u->wst.dat[u->wst.ptr - 2]; 2262 u8 b = u->wst.dat[u->wst.ptr - 2];
@@ -2158,7 +2270,7 @@ evaluxn(Uxn *u, u16 vec)
2158 } 2270 }
2159 break; 2271 break;
2160 case 0x92: /* LDRk */ 2272 case 0x92: /* LDRk */
2161 __asm__( "evaluxn_92_LDRk:" ); 2273 __asm__("evaluxn_92_LDRk:");
2162 { 2274 {
2163 u8 a = u->wst.dat[u->wst.ptr - 1]; 2275 u8 a = u->wst.dat[u->wst.ptr - 1];
2164 u->wst.dat[u->wst.ptr] = mempeek8(u->ram.dat, u->ram.ptr + (s8)a); 2276 u->wst.dat[u->wst.ptr] = mempeek8(u->ram.dat, u->ram.ptr + (s8)a);
@@ -2176,7 +2288,7 @@ evaluxn(Uxn *u, u16 vec)
2176 } 2288 }
2177 break; 2289 break;
2178 case 0x93: /* STRk */ 2290 case 0x93: /* STRk */
2179 __asm__( "evaluxn_93_STRk:" ); 2291 __asm__("evaluxn_93_STRk:");
2180 { 2292 {
2181 u8 a = u->wst.dat[u->wst.ptr - 1]; 2293 u8 a = u->wst.dat[u->wst.ptr - 1];
2182 u8 b = u->wst.dat[u->wst.ptr - 2]; 2294 u8 b = u->wst.dat[u->wst.ptr - 2];
@@ -2190,7 +2302,7 @@ evaluxn(Uxn *u, u16 vec)
2190 } 2302 }
2191 break; 2303 break;
2192 case 0x94: /* LDAk */ 2304 case 0x94: /* LDAk */
2193 __asm__( "evaluxn_94_LDAk:" ); 2305 __asm__("evaluxn_94_LDAk:");
2194 { 2306 {
2195 u16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)); 2307 u16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8));
2196 u->wst.dat[u->wst.ptr] = mempeek8(u->ram.dat, a); 2308 u->wst.dat[u->wst.ptr] = mempeek8(u->ram.dat, a);
@@ -2208,7 +2320,7 @@ evaluxn(Uxn *u, u16 vec)
2208 } 2320 }
2209 break; 2321 break;
2210 case 0x95: /* STAk */ 2322 case 0x95: /* STAk */
2211 __asm__( "evaluxn_95_STAk:" ); 2323 __asm__("evaluxn_95_STAk:");
2212 { 2324 {
2213 u16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)); 2325 u16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8));
2214 u8 b = u->wst.dat[u->wst.ptr - 3]; 2326 u8 b = u->wst.dat[u->wst.ptr - 3];
@@ -2222,7 +2334,7 @@ evaluxn(Uxn *u, u16 vec)
2222 } 2334 }
2223 break; 2335 break;
2224 case 0x96: /* DEIk */ 2336 case 0x96: /* DEIk */
2225 __asm__( "evaluxn_96_DEIk:" ); 2337 __asm__("evaluxn_96_DEIk:");
2226 { 2338 {
2227 u8 a = u->wst.dat[u->wst.ptr - 1]; 2339 u8 a = u->wst.dat[u->wst.ptr - 1];
2228 u->wst.dat[u->wst.ptr] = devpeek8(&u->dev[a >> 4], a); 2340 u->wst.dat[u->wst.ptr] = devpeek8(&u->dev[a >> 4], a);
@@ -2240,7 +2352,7 @@ evaluxn(Uxn *u, u16 vec)
2240 } 2352 }
2241 break; 2353 break;
2242 case 0x97: /* DEOk */ 2354 case 0x97: /* DEOk */
2243 __asm__( "evaluxn_97_DEOk:" ); 2355 __asm__("evaluxn_97_DEOk:");
2244 { 2356 {
2245 u8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; 2357 u8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2];
2246 devpoke8(&u->dev[a >> 4], a, b); 2358 devpoke8(&u->dev[a >> 4], a, b);
@@ -2253,7 +2365,7 @@ evaluxn(Uxn *u, u16 vec)
2253 } 2365 }
2254 break; 2366 break;
2255 case 0x98: /* ADDk */ 2367 case 0x98: /* ADDk */
2256 __asm__( "evaluxn_98_ADDk:" ); 2368 __asm__("evaluxn_98_ADDk:");
2257 { 2369 {
2258 u8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; 2370 u8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2];
2259 u->wst.dat[u->wst.ptr] = b + a; 2371 u->wst.dat[u->wst.ptr] = b + a;
@@ -2271,7 +2383,7 @@ evaluxn(Uxn *u, u16 vec)
2271 } 2383 }
2272 break; 2384 break;
2273 case 0x99: /* SUBk */ 2385 case 0x99: /* SUBk */
2274 __asm__( "evaluxn_99_SUBk:" ); 2386 __asm__("evaluxn_99_SUBk:");
2275 { 2387 {
2276 u8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; 2388 u8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2];
2277 u->wst.dat[u->wst.ptr] = b - a; 2389 u->wst.dat[u->wst.ptr] = b - a;
@@ -2289,7 +2401,7 @@ evaluxn(Uxn *u, u16 vec)
2289 } 2401 }
2290 break; 2402 break;
2291 case 0x9a: /* MULk */ 2403 case 0x9a: /* MULk */
2292 __asm__( "evaluxn_9a_MULk:" ); 2404 __asm__("evaluxn_9a_MULk:");
2293 { 2405 {
2294 u8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; 2406 u8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2];
2295 u->wst.dat[u->wst.ptr] = b * a; 2407 u->wst.dat[u->wst.ptr] = b * a;
@@ -2307,9 +2419,16 @@ evaluxn(Uxn *u, u16 vec)
2307 } 2419 }
2308 break; 2420 break;
2309 case 0x9b: /* DIVk */ 2421 case 0x9b: /* DIVk */
2310 __asm__( "evaluxn_9b_DIVk:" ); 2422 __asm__("evaluxn_9b_DIVk:");
2311 { 2423 {
2312 u8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; 2424 u8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2];
2425 if(a == 0) {
2426 u->wst.error = 3;
2427#ifndef NO_STACK_CHECKS
2428 goto error;
2429#endif
2430 a = 1;
2431 }
2313 u->wst.dat[u->wst.ptr] = b / a; 2432 u->wst.dat[u->wst.ptr] = b / a;
2314#ifndef NO_STACK_CHECKS 2433#ifndef NO_STACK_CHECKS
2315 if(__builtin_expect(u->wst.ptr < 2, 0)) { 2434 if(__builtin_expect(u->wst.ptr < 2, 0)) {
@@ -2325,7 +2444,7 @@ evaluxn(Uxn *u, u16 vec)
2325 } 2444 }
2326 break; 2445 break;
2327 case 0x9c: /* ANDk */ 2446 case 0x9c: /* ANDk */
2328 __asm__( "evaluxn_9c_ANDk:" ); 2447 __asm__("evaluxn_9c_ANDk:");
2329 { 2448 {
2330 u8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; 2449 u8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2];
2331 u->wst.dat[u->wst.ptr] = b & a; 2450 u->wst.dat[u->wst.ptr] = b & a;
@@ -2343,7 +2462,7 @@ evaluxn(Uxn *u, u16 vec)
2343 } 2462 }
2344 break; 2463 break;
2345 case 0x9d: /* ORAk */ 2464 case 0x9d: /* ORAk */
2346 __asm__( "evaluxn_9d_ORAk:" ); 2465 __asm__("evaluxn_9d_ORAk:");
2347 { 2466 {
2348 u8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; 2467 u8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2];
2349 u->wst.dat[u->wst.ptr] = b | a; 2468 u->wst.dat[u->wst.ptr] = b | a;
@@ -2361,7 +2480,7 @@ evaluxn(Uxn *u, u16 vec)
2361 } 2480 }
2362 break; 2481 break;
2363 case 0x9e: /* EORk */ 2482 case 0x9e: /* EORk */
2364 __asm__( "evaluxn_9e_EORk:" ); 2483 __asm__("evaluxn_9e_EORk:");
2365 { 2484 {
2366 u8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; 2485 u8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2];
2367 u->wst.dat[u->wst.ptr] = b ^ a; 2486 u->wst.dat[u->wst.ptr] = b ^ a;
@@ -2379,7 +2498,7 @@ evaluxn(Uxn *u, u16 vec)
2379 } 2498 }
2380 break; 2499 break;
2381 case 0x9f: /* SFTk */ 2500 case 0x9f: /* SFTk */
2382 __asm__( "evaluxn_9f_SFTk:" ); 2501 __asm__("evaluxn_9f_SFTk:");
2383 { 2502 {
2384 u8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; 2503 u8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2];
2385 u->wst.dat[u->wst.ptr] = b >> (a & 0x07) << ((a & 0x70) >> 4); 2504 u->wst.dat[u->wst.ptr] = b >> (a & 0x07) << ((a & 0x70) >> 4);
@@ -2396,8 +2515,8 @@ evaluxn(Uxn *u, u16 vec)
2396 u->wst.ptr += 1; 2515 u->wst.ptr += 1;
2397 } 2516 }
2398 break; 2517 break;
2399 case 0xa3: /* POP2k */ 2518 case 0xa2: /* POP2k */
2400 __asm__( "evaluxn_a3_POP2k:" ); 2519 __asm__("evaluxn_a2_POP2k:");
2401 { 2520 {
2402 (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)); 2521 (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8));
2403#ifndef NO_STACK_CHECKS 2522#ifndef NO_STACK_CHECKS
@@ -2408,8 +2527,8 @@ evaluxn(Uxn *u, u16 vec)
2408#endif 2527#endif
2409 } 2528 }
2410 break; 2529 break;
2411 case 0xa4: /* DUP2k */ 2530 case 0xa3: /* DUP2k */
2412 __asm__( "evaluxn_a4_DUP2k:" ); 2531 __asm__("evaluxn_a3_DUP2k:");
2413 { 2532 {
2414 u8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; 2533 u8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2];
2415 u->wst.dat[u->wst.ptr] = b; 2534 u->wst.dat[u->wst.ptr] = b;
@@ -2429,8 +2548,28 @@ evaluxn(Uxn *u, u16 vec)
2429 u->wst.ptr += 4; 2548 u->wst.ptr += 4;
2430 } 2549 }
2431 break; 2550 break;
2551 case 0xa4: /* NIP2k */
2552 __asm__("evaluxn_a4_NIP2k:");
2553 {
2554 u16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8));
2555 (u->wst.dat[u->wst.ptr - 3] | (u->wst.dat[u->wst.ptr - 4] << 8));
2556 u->wst.dat[u->wst.ptr] = a >> 8;
2557 u->wst.dat[u->wst.ptr + 1] = a & 0xff;
2558#ifndef NO_STACK_CHECKS
2559 if(__builtin_expect(u->wst.ptr < 4, 0)) {
2560 u->wst.error = 1;
2561 goto error;
2562 }
2563 if(__builtin_expect(u->wst.ptr > 253, 0)) {
2564 u->wst.error = 2;
2565 goto error;
2566 }
2567#endif
2568 u->wst.ptr += 2;
2569 }
2570 break;
2432 case 0xa5: /* SWP2k */ 2571 case 0xa5: /* SWP2k */
2433 __asm__( "evaluxn_a5_SWP2k:" ); 2572 __asm__("evaluxn_a5_SWP2k:");
2434 { 2573 {
2435 u8 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]; 2574 u8 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];
2436 u->wst.dat[u->wst.ptr] = b; 2575 u->wst.dat[u->wst.ptr] = b;
@@ -2451,7 +2590,7 @@ evaluxn(Uxn *u, u16 vec)
2451 } 2590 }
2452 break; 2591 break;
2453 case 0xa6: /* OVR2k */ 2592 case 0xa6: /* OVR2k */
2454 __asm__( "evaluxn_a6_OVR2k:" ); 2593 __asm__("evaluxn_a6_OVR2k:");
2455 { 2594 {
2456 u8 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]; 2595 u8 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];
2457 u->wst.dat[u->wst.ptr] = d; 2596 u->wst.dat[u->wst.ptr] = d;
@@ -2474,7 +2613,7 @@ evaluxn(Uxn *u, u16 vec)
2474 } 2613 }
2475 break; 2614 break;
2476 case 0xa7: /* ROT2k */ 2615 case 0xa7: /* ROT2k */
2477 __asm__( "evaluxn_a7_ROT2k:" ); 2616 __asm__("evaluxn_a7_ROT2k:");
2478 { 2617 {
2479 u8 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], e = u->wst.dat[u->wst.ptr - 5], f = u->wst.dat[u->wst.ptr - 6]; 2618 u8 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], e = u->wst.dat[u->wst.ptr - 5], f = u->wst.dat[u->wst.ptr - 6];
2480 u->wst.dat[u->wst.ptr] = d; 2619 u->wst.dat[u->wst.ptr] = d;
@@ -2497,7 +2636,7 @@ evaluxn(Uxn *u, u16 vec)
2497 } 2636 }
2498 break; 2637 break;
2499 case 0xa8: /* EQU2k */ 2638 case 0xa8: /* EQU2k */
2500 __asm__( "evaluxn_a8_EQU2k:" ); 2639 __asm__("evaluxn_a8_EQU2k:");
2501 { 2640 {
2502 u16 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)); 2641 u16 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));
2503 u->wst.dat[u->wst.ptr] = b == a; 2642 u->wst.dat[u->wst.ptr] = b == a;
@@ -2515,7 +2654,7 @@ evaluxn(Uxn *u, u16 vec)
2515 } 2654 }
2516 break; 2655 break;
2517 case 0xa9: /* NEQ2k */ 2656 case 0xa9: /* NEQ2k */
2518 __asm__( "evaluxn_a9_NEQ2k:" ); 2657 __asm__("evaluxn_a9_NEQ2k:");
2519 { 2658 {
2520 u16 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)); 2659 u16 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));
2521 u->wst.dat[u->wst.ptr] = b != a; 2660 u->wst.dat[u->wst.ptr] = b != a;
@@ -2533,7 +2672,7 @@ evaluxn(Uxn *u, u16 vec)
2533 } 2672 }
2534 break; 2673 break;
2535 case 0xaa: /* GTH2k */ 2674 case 0xaa: /* GTH2k */
2536 __asm__( "evaluxn_aa_GTH2k:" ); 2675 __asm__("evaluxn_aa_GTH2k:");
2537 { 2676 {
2538 u16 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)); 2677 u16 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));
2539 u->wst.dat[u->wst.ptr] = b > a; 2678 u->wst.dat[u->wst.ptr] = b > a;
@@ -2551,7 +2690,7 @@ evaluxn(Uxn *u, u16 vec)
2551 } 2690 }
2552 break; 2691 break;
2553 case 0xab: /* LTH2k */ 2692 case 0xab: /* LTH2k */
2554 __asm__( "evaluxn_ab_LTH2k:" ); 2693 __asm__("evaluxn_ab_LTH2k:");
2555 { 2694 {
2556 u16 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)); 2695 u16 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));
2557 u->wst.dat[u->wst.ptr] = b < a; 2696 u->wst.dat[u->wst.ptr] = b < a;
@@ -2569,7 +2708,7 @@ evaluxn(Uxn *u, u16 vec)
2569 } 2708 }
2570 break; 2709 break;
2571 case 0xac: /* JMP2k */ 2710 case 0xac: /* JMP2k */
2572 __asm__( "evaluxn_ac_JMP2k:" ); 2711 __asm__("evaluxn_ac_JMP2k:");
2573 { 2712 {
2574 u->ram.ptr = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)); 2713 u->ram.ptr = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8));
2575#ifndef NO_STACK_CHECKS 2714#ifndef NO_STACK_CHECKS
@@ -2581,7 +2720,7 @@ evaluxn(Uxn *u, u16 vec)
2581 } 2720 }
2582 break; 2721 break;
2583 case 0xad: /* JCN2k */ 2722 case 0xad: /* JCN2k */
2584 __asm__( "evaluxn_ad_JCN2k:" ); 2723 __asm__("evaluxn_ad_JCN2k:");
2585 { 2724 {
2586 u16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)); 2725 u16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8));
2587 if(u->wst.dat[u->wst.ptr - 3]) u->ram.ptr = a; 2726 if(u->wst.dat[u->wst.ptr - 3]) u->ram.ptr = a;
@@ -2594,7 +2733,7 @@ evaluxn(Uxn *u, u16 vec)
2594 } 2733 }
2595 break; 2734 break;
2596 case 0xae: /* JSR2k */ 2735 case 0xae: /* JSR2k */
2597 __asm__( "evaluxn_ae_JSR2k:" ); 2736 __asm__("evaluxn_ae_JSR2k:");
2598 { 2737 {
2599 u->rst.dat[u->rst.ptr] = u->ram.ptr >> 8; 2738 u->rst.dat[u->rst.ptr] = u->ram.ptr >> 8;
2600 u->rst.dat[u->rst.ptr + 1] = u->ram.ptr & 0xff; 2739 u->rst.dat[u->rst.ptr + 1] = u->ram.ptr & 0xff;
@@ -2613,7 +2752,7 @@ evaluxn(Uxn *u, u16 vec)
2613 } 2752 }
2614 break; 2753 break;
2615 case 0xaf: /* STH2k */ 2754 case 0xaf: /* STH2k */
2616 __asm__( "evaluxn_af_STH2k:" ); 2755 __asm__("evaluxn_af_STH2k:");
2617 { 2756 {
2618 u8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; 2757 u8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2];
2619 u->rst.dat[u->rst.ptr] = b; 2758 u->rst.dat[u->rst.ptr] = b;
@@ -2632,7 +2771,7 @@ evaluxn(Uxn *u, u16 vec)
2632 } 2771 }
2633 break; 2772 break;
2634 case 0xb0: /* LDZ2k */ 2773 case 0xb0: /* LDZ2k */
2635 __asm__( "evaluxn_b0_LDZ2k:" ); 2774 __asm__("evaluxn_b0_LDZ2k:");
2636 { 2775 {
2637 u8 a = u->wst.dat[u->wst.ptr - 1]; 2776 u8 a = u->wst.dat[u->wst.ptr - 1];
2638 u->wst.dat[u->wst.ptr] = mempeek8(u->ram.dat, a); 2777 u->wst.dat[u->wst.ptr] = mempeek8(u->ram.dat, a);
@@ -2651,7 +2790,7 @@ evaluxn(Uxn *u, u16 vec)
2651 } 2790 }
2652 break; 2791 break;
2653 case 0xb1: /* STZ2k */ 2792 case 0xb1: /* STZ2k */
2654 __asm__( "evaluxn_b1_STZ2k:" ); 2793 __asm__("evaluxn_b1_STZ2k:");
2655 { 2794 {
2656 u8 a = u->wst.dat[u->wst.ptr - 1]; 2795 u8 a = u->wst.dat[u->wst.ptr - 1];
2657 u16 b = (u->wst.dat[u->wst.ptr - 2] | (u->wst.dat[u->wst.ptr - 3] << 8)); 2796 u16 b = (u->wst.dat[u->wst.ptr - 2] | (u->wst.dat[u->wst.ptr - 3] << 8));
@@ -2665,7 +2804,7 @@ evaluxn(Uxn *u, u16 vec)
2665 } 2804 }
2666 break; 2805 break;
2667 case 0xb2: /* LDR2k */ 2806 case 0xb2: /* LDR2k */
2668 __asm__( "evaluxn_b2_LDR2k:" ); 2807 __asm__("evaluxn_b2_LDR2k:");
2669 { 2808 {
2670 u8 a = u->wst.dat[u->wst.ptr - 1]; 2809 u8 a = u->wst.dat[u->wst.ptr - 1];
2671 u->wst.dat[u->wst.ptr] = mempeek8(u->ram.dat, u->ram.ptr + (s8)a); 2810 u->wst.dat[u->wst.ptr] = mempeek8(u->ram.dat, u->ram.ptr + (s8)a);
@@ -2684,7 +2823,7 @@ evaluxn(Uxn *u, u16 vec)
2684 } 2823 }
2685 break; 2824 break;
2686 case 0xb3: /* STR2k */ 2825 case 0xb3: /* STR2k */
2687 __asm__( "evaluxn_b3_STR2k:" ); 2826 __asm__("evaluxn_b3_STR2k:");
2688 { 2827 {
2689 u8 a = u->wst.dat[u->wst.ptr - 1]; 2828 u8 a = u->wst.dat[u->wst.ptr - 1];
2690 u16 b = (u->wst.dat[u->wst.ptr - 2] | (u->wst.dat[u->wst.ptr - 3] << 8)); 2829 u16 b = (u->wst.dat[u->wst.ptr - 2] | (u->wst.dat[u->wst.ptr - 3] << 8));
@@ -2698,7 +2837,7 @@ evaluxn(Uxn *u, u16 vec)
2698 } 2837 }
2699 break; 2838 break;
2700 case 0xb4: /* LDA2k */ 2839 case 0xb4: /* LDA2k */
2701 __asm__( "evaluxn_b4_LDA2k:" ); 2840 __asm__("evaluxn_b4_LDA2k:");
2702 { 2841 {
2703 u16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)); 2842 u16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8));
2704 u->wst.dat[u->wst.ptr] = mempeek8(u->ram.dat, a); 2843 u->wst.dat[u->wst.ptr] = mempeek8(u->ram.dat, a);
@@ -2717,7 +2856,7 @@ evaluxn(Uxn *u, u16 vec)
2717 } 2856 }
2718 break; 2857 break;
2719 case 0xb5: /* STA2k */ 2858 case 0xb5: /* STA2k */
2720 __asm__( "evaluxn_b5_STA2k:" ); 2859 __asm__("evaluxn_b5_STA2k:");
2721 { 2860 {
2722 u16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)); 2861 u16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8));
2723 u16 b = (u->wst.dat[u->wst.ptr - 3] | (u->wst.dat[u->wst.ptr - 4] << 8)); 2862 u16 b = (u->wst.dat[u->wst.ptr - 3] | (u->wst.dat[u->wst.ptr - 4] << 8));
@@ -2731,7 +2870,7 @@ evaluxn(Uxn *u, u16 vec)
2731 } 2870 }
2732 break; 2871 break;
2733 case 0xb6: /* DEI2k */ 2872 case 0xb6: /* DEI2k */
2734 __asm__( "evaluxn_b6_DEI2k:" ); 2873 __asm__("evaluxn_b6_DEI2k:");
2735 { 2874 {
2736 u8 a = u->wst.dat[u->wst.ptr - 1]; 2875 u8 a = u->wst.dat[u->wst.ptr - 1];
2737 u->wst.dat[u->wst.ptr] = devpeek8(&u->dev[a >> 4], a); 2876 u->wst.dat[u->wst.ptr] = devpeek8(&u->dev[a >> 4], a);
@@ -2750,7 +2889,7 @@ evaluxn(Uxn *u, u16 vec)
2750 } 2889 }
2751 break; 2890 break;
2752 case 0xb7: /* DEO2k */ 2891 case 0xb7: /* DEO2k */
2753 __asm__( "evaluxn_b7_DEO2k:" ); 2892 __asm__("evaluxn_b7_DEO2k:");
2754 { 2893 {
2755 u8 a = u->wst.dat[u->wst.ptr - 1]; 2894 u8 a = u->wst.dat[u->wst.ptr - 1];
2756 u16 b = (u->wst.dat[u->wst.ptr - 2] | (u->wst.dat[u->wst.ptr - 3] << 8)); 2895 u16 b = (u->wst.dat[u->wst.ptr - 2] | (u->wst.dat[u->wst.ptr - 3] << 8));
@@ -2764,7 +2903,7 @@ evaluxn(Uxn *u, u16 vec)
2764 } 2903 }
2765 break; 2904 break;
2766 case 0xb8: /* ADD2k */ 2905 case 0xb8: /* ADD2k */
2767 __asm__( "evaluxn_b8_ADD2k:" ); 2906 __asm__("evaluxn_b8_ADD2k:");
2768 { 2907 {
2769 u16 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)); 2908 u16 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));
2770 u->wst.dat[u->wst.ptr] = (b + a) >> 8; 2909 u->wst.dat[u->wst.ptr] = (b + a) >> 8;
@@ -2783,7 +2922,7 @@ evaluxn(Uxn *u, u16 vec)
2783 } 2922 }
2784 break; 2923 break;
2785 case 0xb9: /* SUB2k */ 2924 case 0xb9: /* SUB2k */
2786 __asm__( "evaluxn_b9_SUB2k:" ); 2925 __asm__("evaluxn_b9_SUB2k:");
2787 { 2926 {
2788 u16 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)); 2927 u16 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));
2789 u->wst.dat[u->wst.ptr] = (b - a) >> 8; 2928 u->wst.dat[u->wst.ptr] = (b - a) >> 8;
@@ -2802,7 +2941,7 @@ evaluxn(Uxn *u, u16 vec)
2802 } 2941 }
2803 break; 2942 break;
2804 case 0xba: /* MUL2k */ 2943 case 0xba: /* MUL2k */
2805 __asm__( "evaluxn_ba_MUL2k:" ); 2944 __asm__("evaluxn_ba_MUL2k:");
2806 { 2945 {
2807 u16 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)); 2946 u16 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));
2808 u->wst.dat[u->wst.ptr] = (b * a) >> 8; 2947 u->wst.dat[u->wst.ptr] = (b * a) >> 8;
@@ -2821,9 +2960,16 @@ evaluxn(Uxn *u, u16 vec)
2821 } 2960 }
2822 break; 2961 break;
2823 case 0xbb: /* DIV2k */ 2962 case 0xbb: /* DIV2k */
2824 __asm__( "evaluxn_bb_DIV2k:" ); 2963 __asm__("evaluxn_bb_DIV2k:");
2825 { 2964 {
2826 u16 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)); 2965 u16 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));
2966 if(a == 0) {
2967 u->wst.error = 3;
2968#ifndef NO_STACK_CHECKS
2969 goto error;
2970#endif
2971 a = 1;
2972 }
2827 u->wst.dat[u->wst.ptr] = (b / a) >> 8; 2973 u->wst.dat[u->wst.ptr] = (b / a) >> 8;
2828 u->wst.dat[u->wst.ptr + 1] = (b / a) & 0xff; 2974 u->wst.dat[u->wst.ptr + 1] = (b / a) & 0xff;
2829#ifndef NO_STACK_CHECKS 2975#ifndef NO_STACK_CHECKS
@@ -2840,7 +2986,7 @@ evaluxn(Uxn *u, u16 vec)
2840 } 2986 }
2841 break; 2987 break;
2842 case 0xbc: /* AND2k */ 2988 case 0xbc: /* AND2k */
2843 __asm__( "evaluxn_bc_AND2k:" ); 2989 __asm__("evaluxn_bc_AND2k:");
2844 { 2990 {
2845 u8 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]; 2991 u8 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];
2846 u->wst.dat[u->wst.ptr] = d & b; 2992 u->wst.dat[u->wst.ptr] = d & b;
@@ -2859,7 +3005,7 @@ evaluxn(Uxn *u, u16 vec)
2859 } 3005 }
2860 break; 3006 break;
2861 case 0xbd: /* ORA2k */ 3007 case 0xbd: /* ORA2k */
2862 __asm__( "evaluxn_bd_ORA2k:" ); 3008 __asm__("evaluxn_bd_ORA2k:");
2863 { 3009 {
2864 u8 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]; 3010 u8 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];
2865 u->wst.dat[u->wst.ptr] = d | b; 3011 u->wst.dat[u->wst.ptr] = d | b;
@@ -2878,7 +3024,7 @@ evaluxn(Uxn *u, u16 vec)
2878 } 3024 }
2879 break; 3025 break;
2880 case 0xbe: /* EOR2k */ 3026 case 0xbe: /* EOR2k */
2881 __asm__( "evaluxn_be_EOR2k:" ); 3027 __asm__("evaluxn_be_EOR2k:");
2882 { 3028 {
2883 u8 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]; 3029 u8 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];
2884 u->wst.dat[u->wst.ptr] = d ^ b; 3030 u->wst.dat[u->wst.ptr] = d ^ b;
@@ -2897,7 +3043,7 @@ evaluxn(Uxn *u, u16 vec)
2897 } 3043 }
2898 break; 3044 break;
2899 case 0xbf: /* SFT2k */ 3045 case 0xbf: /* SFT2k */
2900 __asm__( "evaluxn_bf_SFT2k:" ); 3046 __asm__("evaluxn_bf_SFT2k:");
2901 { 3047 {
2902 u8 a = u->wst.dat[u->wst.ptr - 1]; 3048 u8 a = u->wst.dat[u->wst.ptr - 1];
2903 u16 b = (u->wst.dat[u->wst.ptr - 2] | (u->wst.dat[u->wst.ptr - 3] << 8)); 3049 u16 b = (u->wst.dat[u->wst.ptr - 2] | (u->wst.dat[u->wst.ptr - 3] << 8));
@@ -2916,8 +3062,8 @@ evaluxn(Uxn *u, u16 vec)
2916 u->wst.ptr += 2; 3062 u->wst.ptr += 2;
2917 } 3063 }
2918 break; 3064 break;
2919 case 0xc3: /* POPkr */ 3065 case 0xc2: /* POPkr */
2920 __asm__( "evaluxn_c3_POPkr:" ); 3066 __asm__("evaluxn_c2_POPkr:");
2921 { 3067 {
2922 u->rst.dat[u->rst.ptr - 1]; 3068 u->rst.dat[u->rst.ptr - 1];
2923#ifndef NO_STACK_CHECKS 3069#ifndef NO_STACK_CHECKS
@@ -2928,8 +3074,8 @@ evaluxn(Uxn *u, u16 vec)
2928#endif 3074#endif
2929 } 3075 }
2930 break; 3076 break;
2931 case 0xc4: /* DUPkr */ 3077 case 0xc3: /* DUPkr */
2932 __asm__( "evaluxn_c4_DUPkr:" ); 3078 __asm__("evaluxn_c3_DUPkr:");
2933 { 3079 {
2934 u8 a = u->rst.dat[u->rst.ptr - 1]; 3080 u8 a = u->rst.dat[u->rst.ptr - 1];
2935 u->rst.dat[u->rst.ptr] = a; 3081 u->rst.dat[u->rst.ptr] = a;
@@ -2947,8 +3093,27 @@ evaluxn(Uxn *u, u16 vec)
2947 u->rst.ptr += 2; 3093 u->rst.ptr += 2;
2948 } 3094 }
2949 break; 3095 break;
3096 case 0xc4: /* NIPkr */
3097 __asm__("evaluxn_c4_NIPkr:");
3098 {
3099 u8 a = u->rst.dat[u->rst.ptr - 1];
3100 u->rst.dat[u->rst.ptr - 2];
3101 u->rst.dat[u->rst.ptr] = a;
3102#ifndef NO_STACK_CHECKS
3103 if(__builtin_expect(u->rst.ptr < 2, 0)) {
3104 u->rst.error = 1;
3105 goto error;
3106 }
3107 if(__builtin_expect(u->rst.ptr > 254, 0)) {
3108 u->rst.error = 2;
3109 goto error;
3110 }
3111#endif
3112 u->rst.ptr += 1;
3113 }
3114 break;
2950 case 0xc5: /* SWPkr */ 3115 case 0xc5: /* SWPkr */
2951 __asm__( "evaluxn_c5_SWPkr:" ); 3116 __asm__("evaluxn_c5_SWPkr:");
2952 { 3117 {
2953 u8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; 3118 u8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2];
2954 u->rst.dat[u->rst.ptr] = a; 3119 u->rst.dat[u->rst.ptr] = a;
@@ -2967,7 +3132,7 @@ evaluxn(Uxn *u, u16 vec)
2967 } 3132 }
2968 break; 3133 break;
2969 case 0xc6: /* OVRkr */ 3134 case 0xc6: /* OVRkr */
2970 __asm__( "evaluxn_c6_OVRkr:" ); 3135 __asm__("evaluxn_c6_OVRkr:");
2971 { 3136 {
2972 u8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; 3137 u8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2];
2973 u->rst.dat[u->rst.ptr] = b; 3138 u->rst.dat[u->rst.ptr] = b;
@@ -2987,7 +3152,7 @@ evaluxn(Uxn *u, u16 vec)
2987 } 3152 }
2988 break; 3153 break;
2989 case 0xc7: /* ROTkr */ 3154 case 0xc7: /* ROTkr */
2990 __asm__( "evaluxn_c7_ROTkr:" ); 3155 __asm__("evaluxn_c7_ROTkr:");
2991 { 3156 {
2992 u8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2], c = u->rst.dat[u->rst.ptr - 3]; 3157 u8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2], c = u->rst.dat[u->rst.ptr - 3];
2993 u->rst.dat[u->rst.ptr] = b; 3158 u->rst.dat[u->rst.ptr] = b;
@@ -3007,7 +3172,7 @@ evaluxn(Uxn *u, u16 vec)
3007 } 3172 }
3008 break; 3173 break;
3009 case 0xc8: /* EQUkr */ 3174 case 0xc8: /* EQUkr */
3010 __asm__( "evaluxn_c8_EQUkr:" ); 3175 __asm__("evaluxn_c8_EQUkr:");
3011 { 3176 {
3012 u8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; 3177 u8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2];
3013 u->rst.dat[u->rst.ptr] = b == a; 3178 u->rst.dat[u->rst.ptr] = b == a;
@@ -3025,7 +3190,7 @@ evaluxn(Uxn *u, u16 vec)
3025 } 3190 }
3026 break; 3191 break;
3027 case 0xc9: /* NEQkr */ 3192 case 0xc9: /* NEQkr */
3028 __asm__( "evaluxn_c9_NEQkr:" ); 3193 __asm__("evaluxn_c9_NEQkr:");
3029 { 3194 {
3030 u8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; 3195 u8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2];
3031 u->rst.dat[u->rst.ptr] = b != a; 3196 u->rst.dat[u->rst.ptr] = b != a;
@@ -3043,7 +3208,7 @@ evaluxn(Uxn *u, u16 vec)
3043 } 3208 }
3044 break; 3209 break;
3045 case 0xca: /* GTHkr */ 3210 case 0xca: /* GTHkr */
3046 __asm__( "evaluxn_ca_GTHkr:" ); 3211 __asm__("evaluxn_ca_GTHkr:");
3047 { 3212 {
3048 u8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; 3213 u8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2];
3049 u->rst.dat[u->rst.ptr] = b > a; 3214 u->rst.dat[u->rst.ptr] = b > a;
@@ -3061,7 +3226,7 @@ evaluxn(Uxn *u, u16 vec)
3061 } 3226 }
3062 break; 3227 break;
3063 case 0xcb: /* LTHkr */ 3228 case 0xcb: /* LTHkr */
3064 __asm__( "evaluxn_cb_LTHkr:" ); 3229 __asm__("evaluxn_cb_LTHkr:");
3065 { 3230 {
3066 u8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; 3231 u8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2];
3067 u->rst.dat[u->rst.ptr] = b < a; 3232 u->rst.dat[u->rst.ptr] = b < a;
@@ -3079,7 +3244,7 @@ evaluxn(Uxn *u, u16 vec)
3079 } 3244 }
3080 break; 3245 break;
3081 case 0xcc: /* JMPkr */ 3246 case 0xcc: /* JMPkr */
3082 __asm__( "evaluxn_cc_JMPkr:" ); 3247 __asm__("evaluxn_cc_JMPkr:");
3083 { 3248 {
3084 u8 a = u->rst.dat[u->rst.ptr - 1]; 3249 u8 a = u->rst.dat[u->rst.ptr - 1];
3085 u->ram.ptr += (s8)a; 3250 u->ram.ptr += (s8)a;
@@ -3092,7 +3257,7 @@ evaluxn(Uxn *u, u16 vec)
3092 } 3257 }
3093 break; 3258 break;
3094 case 0xcd: /* JCNkr */ 3259 case 0xcd: /* JCNkr */
3095 __asm__( "evaluxn_cd_JCNkr:" ); 3260 __asm__("evaluxn_cd_JCNkr:");
3096 { 3261 {
3097 u8 a = u->rst.dat[u->rst.ptr - 1]; 3262 u8 a = u->rst.dat[u->rst.ptr - 1];
3098 if(u->rst.dat[u->rst.ptr - 2]) u->ram.ptr += (s8)a; 3263 if(u->rst.dat[u->rst.ptr - 2]) u->ram.ptr += (s8)a;
@@ -3105,7 +3270,7 @@ evaluxn(Uxn *u, u16 vec)
3105 } 3270 }
3106 break; 3271 break;
3107 case 0xce: /* JSRkr */ 3272 case 0xce: /* JSRkr */
3108 __asm__( "evaluxn_ce_JSRkr:" ); 3273 __asm__("evaluxn_ce_JSRkr:");
3109 { 3274 {
3110 u8 a = u->rst.dat[u->rst.ptr - 1]; 3275 u8 a = u->rst.dat[u->rst.ptr - 1];
3111 u->wst.dat[u->wst.ptr] = u->ram.ptr >> 8; 3276 u->wst.dat[u->wst.ptr] = u->ram.ptr >> 8;
@@ -3125,7 +3290,7 @@ evaluxn(Uxn *u, u16 vec)
3125 } 3290 }
3126 break; 3291 break;
3127 case 0xcf: /* STHkr */ 3292 case 0xcf: /* STHkr */
3128 __asm__( "evaluxn_cf_STHkr:" ); 3293 __asm__("evaluxn_cf_STHkr:");
3129 { 3294 {
3130 u8 a = u->rst.dat[u->rst.ptr - 1]; 3295 u8 a = u->rst.dat[u->rst.ptr - 1];
3131 u->wst.dat[u->wst.ptr] = a; 3296 u->wst.dat[u->wst.ptr] = a;
@@ -3143,7 +3308,7 @@ evaluxn(Uxn *u, u16 vec)
3143 } 3308 }
3144 break; 3309 break;
3145 case 0xd0: /* LDZkr */ 3310 case 0xd0: /* LDZkr */
3146 __asm__( "evaluxn_d0_LDZkr:" ); 3311 __asm__("evaluxn_d0_LDZkr:");
3147 { 3312 {
3148 u8 a = u->rst.dat[u->rst.ptr - 1]; 3313 u8 a = u->rst.dat[u->rst.ptr - 1];
3149 u->rst.dat[u->rst.ptr] = mempeek8(u->ram.dat, a); 3314 u->rst.dat[u->rst.ptr] = mempeek8(u->ram.dat, a);
@@ -3161,7 +3326,7 @@ evaluxn(Uxn *u, u16 vec)
3161 } 3326 }
3162 break; 3327 break;
3163 case 0xd1: /* STZkr */ 3328 case 0xd1: /* STZkr */
3164 __asm__( "evaluxn_d1_STZkr:" ); 3329 __asm__("evaluxn_d1_STZkr:");
3165 { 3330 {
3166 u8 a = u->rst.dat[u->rst.ptr - 1]; 3331 u8 a = u->rst.dat[u->rst.ptr - 1];
3167 u8 b = u->rst.dat[u->rst.ptr - 2]; 3332 u8 b = u->rst.dat[u->rst.ptr - 2];
@@ -3175,7 +3340,7 @@ evaluxn(Uxn *u, u16 vec)
3175 } 3340 }
3176 break; 3341 break;
3177 case 0xd2: /* LDRkr */ 3342 case 0xd2: /* LDRkr */
3178 __asm__( "evaluxn_d2_LDRkr:" ); 3343 __asm__("evaluxn_d2_LDRkr:");
3179 { 3344 {
3180 u8 a = u->rst.dat[u->rst.ptr - 1]; 3345 u8 a = u->rst.dat[u->rst.ptr - 1];
3181 u->rst.dat[u->rst.ptr] = mempeek8(u->ram.dat, u->ram.ptr + (s8)a); 3346 u->rst.dat[u->rst.ptr] = mempeek8(u->ram.dat, u->ram.ptr + (s8)a);
@@ -3193,7 +3358,7 @@ evaluxn(Uxn *u, u16 vec)
3193 } 3358 }
3194 break; 3359 break;
3195 case 0xd3: /* STRkr */ 3360 case 0xd3: /* STRkr */
3196 __asm__( "evaluxn_d3_STRkr:" ); 3361 __asm__("evaluxn_d3_STRkr:");
3197 { 3362 {
3198 u8 a = u->rst.dat[u->rst.ptr - 1]; 3363 u8 a = u->rst.dat[u->rst.ptr - 1];
3199 u8 b = u->rst.dat[u->rst.ptr - 2]; 3364 u8 b = u->rst.dat[u->rst.ptr - 2];
@@ -3207,7 +3372,7 @@ evaluxn(Uxn *u, u16 vec)
3207 } 3372 }
3208 break; 3373 break;
3209 case 0xd4: /* LDAkr */ 3374 case 0xd4: /* LDAkr */
3210 __asm__( "evaluxn_d4_LDAkr:" ); 3375 __asm__("evaluxn_d4_LDAkr:");
3211 { 3376 {
3212 u16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)); 3377 u16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8));
3213 u->rst.dat[u->rst.ptr] = mempeek8(u->ram.dat, a); 3378 u->rst.dat[u->rst.ptr] = mempeek8(u->ram.dat, a);
@@ -3225,7 +3390,7 @@ evaluxn(Uxn *u, u16 vec)
3225 } 3390 }
3226 break; 3391 break;
3227 case 0xd5: /* STAkr */ 3392 case 0xd5: /* STAkr */
3228 __asm__( "evaluxn_d5_STAkr:" ); 3393 __asm__("evaluxn_d5_STAkr:");
3229 { 3394 {
3230 u16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)); 3395 u16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8));
3231 u8 b = u->rst.dat[u->rst.ptr - 3]; 3396 u8 b = u->rst.dat[u->rst.ptr - 3];
@@ -3239,7 +3404,7 @@ evaluxn(Uxn *u, u16 vec)
3239 } 3404 }
3240 break; 3405 break;
3241 case 0xd6: /* DEIkr */ 3406 case 0xd6: /* DEIkr */
3242 __asm__( "evaluxn_d6_DEIkr:" ); 3407 __asm__("evaluxn_d6_DEIkr:");
3243 { 3408 {
3244 u8 a = u->rst.dat[u->rst.ptr - 1]; 3409 u8 a = u->rst.dat[u->rst.ptr - 1];
3245 u->rst.dat[u->rst.ptr] = devpeek8(&u->dev[a >> 4], a); 3410 u->rst.dat[u->rst.ptr] = devpeek8(&u->dev[a >> 4], a);
@@ -3257,7 +3422,7 @@ evaluxn(Uxn *u, u16 vec)
3257 } 3422 }
3258 break; 3423 break;
3259 case 0xd7: /* DEOkr */ 3424 case 0xd7: /* DEOkr */
3260 __asm__( "evaluxn_d7_DEOkr:" ); 3425 __asm__("evaluxn_d7_DEOkr:");
3261 { 3426 {
3262 u8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; 3427 u8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2];
3263 devpoke8(&u->dev[a >> 4], a, b); 3428 devpoke8(&u->dev[a >> 4], a, b);
@@ -3270,7 +3435,7 @@ evaluxn(Uxn *u, u16 vec)
3270 } 3435 }
3271 break; 3436 break;
3272 case 0xd8: /* ADDkr */ 3437 case 0xd8: /* ADDkr */
3273 __asm__( "evaluxn_d8_ADDkr:" ); 3438 __asm__("evaluxn_d8_ADDkr:");
3274 { 3439 {
3275 u8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; 3440 u8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2];
3276 u->rst.dat[u->rst.ptr] = b + a; 3441 u->rst.dat[u->rst.ptr] = b + a;
@@ -3288,7 +3453,7 @@ evaluxn(Uxn *u, u16 vec)
3288 } 3453 }
3289 break; 3454 break;
3290 case 0xd9: /* SUBkr */ 3455 case 0xd9: /* SUBkr */
3291 __asm__( "evaluxn_d9_SUBkr:" ); 3456 __asm__("evaluxn_d9_SUBkr:");
3292 { 3457 {
3293 u8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; 3458 u8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2];
3294 u->rst.dat[u->rst.ptr] = b - a; 3459 u->rst.dat[u->rst.ptr] = b - a;
@@ -3306,7 +3471,7 @@ evaluxn(Uxn *u, u16 vec)
3306 } 3471 }
3307 break; 3472 break;
3308 case 0xda: /* MULkr */ 3473 case 0xda: /* MULkr */
3309 __asm__( "evaluxn_da_MULkr:" ); 3474 __asm__("evaluxn_da_MULkr:");
3310 { 3475 {
3311 u8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; 3476 u8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2];
3312 u->rst.dat[u->rst.ptr] = b * a; 3477 u->rst.dat[u->rst.ptr] = b * a;
@@ -3324,9 +3489,16 @@ evaluxn(Uxn *u, u16 vec)
3324 } 3489 }
3325 break; 3490 break;
3326 case 0xdb: /* DIVkr */ 3491 case 0xdb: /* DIVkr */
3327 __asm__( "evaluxn_db_DIVkr:" ); 3492 __asm__("evaluxn_db_DIVkr:");
3328 { 3493 {
3329 u8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; 3494 u8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2];
3495 if(a == 0) {
3496 u->rst.error = 3;
3497#ifndef NO_STACK_CHECKS
3498 goto error;
3499#endif
3500 a = 1;
3501 }
3330 u->rst.dat[u->rst.ptr] = b / a; 3502 u->rst.dat[u->rst.ptr] = b / a;
3331#ifndef NO_STACK_CHECKS 3503#ifndef NO_STACK_CHECKS
3332 if(__builtin_expect(u->rst.ptr < 2, 0)) { 3504 if(__builtin_expect(u->rst.ptr < 2, 0)) {
@@ -3342,7 +3514,7 @@ evaluxn(Uxn *u, u16 vec)
3342 } 3514 }
3343 break; 3515 break;
3344 case 0xdc: /* ANDkr */ 3516 case 0xdc: /* ANDkr */
3345 __asm__( "evaluxn_dc_ANDkr:" ); 3517 __asm__("evaluxn_dc_ANDkr:");
3346 { 3518 {
3347 u8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; 3519 u8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2];
3348 u->rst.dat[u->rst.ptr] = b & a; 3520 u->rst.dat[u->rst.ptr] = b & a;
@@ -3360,7 +3532,7 @@ evaluxn(Uxn *u, u16 vec)
3360 } 3532 }
3361 break; 3533 break;
3362 case 0xdd: /* ORAkr */ 3534 case 0xdd: /* ORAkr */
3363 __asm__( "evaluxn_dd_ORAkr:" ); 3535 __asm__("evaluxn_dd_ORAkr:");
3364 { 3536 {
3365 u8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; 3537 u8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2];
3366 u->rst.dat[u->rst.ptr] = b | a; 3538 u->rst.dat[u->rst.ptr] = b | a;
@@ -3378,7 +3550,7 @@ evaluxn(Uxn *u, u16 vec)
3378 } 3550 }
3379 break; 3551 break;
3380 case 0xde: /* EORkr */ 3552 case 0xde: /* EORkr */
3381 __asm__( "evaluxn_de_EORkr:" ); 3553 __asm__("evaluxn_de_EORkr:");
3382 { 3554 {
3383 u8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; 3555 u8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2];
3384 u->rst.dat[u->rst.ptr] = b ^ a; 3556 u->rst.dat[u->rst.ptr] = b ^ a;
@@ -3396,7 +3568,7 @@ evaluxn(Uxn *u, u16 vec)
3396 } 3568 }
3397 break; 3569 break;
3398 case 0xdf: /* SFTkr */ 3570 case 0xdf: /* SFTkr */
3399 __asm__( "evaluxn_df_SFTkr:" ); 3571 __asm__("evaluxn_df_SFTkr:");
3400 { 3572 {
3401 u8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; 3573 u8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2];
3402 u->rst.dat[u->rst.ptr] = b >> (a & 0x07) << ((a & 0x70) >> 4); 3574 u->rst.dat[u->rst.ptr] = b >> (a & 0x07) << ((a & 0x70) >> 4);
@@ -3413,8 +3585,8 @@ evaluxn(Uxn *u, u16 vec)
3413 u->rst.ptr += 1; 3585 u->rst.ptr += 1;
3414 } 3586 }
3415 break; 3587 break;
3416 case 0xe3: /* POP2kr */ 3588 case 0xe2: /* POP2kr */
3417 __asm__( "evaluxn_e3_POP2kr:" ); 3589 __asm__("evaluxn_e2_POP2kr:");
3418 { 3590 {
3419 (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)); 3591 (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8));
3420#ifndef NO_STACK_CHECKS 3592#ifndef NO_STACK_CHECKS
@@ -3425,8 +3597,8 @@ evaluxn(Uxn *u, u16 vec)
3425#endif 3597#endif
3426 } 3598 }
3427 break; 3599 break;
3428 case 0xe4: /* DUP2kr */ 3600 case 0xe3: /* DUP2kr */
3429 __asm__( "evaluxn_e4_DUP2kr:" ); 3601 __asm__("evaluxn_e3_DUP2kr:");
3430 { 3602 {
3431 u8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; 3603 u8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2];
3432 u->rst.dat[u->rst.ptr] = b; 3604 u->rst.dat[u->rst.ptr] = b;
@@ -3446,8 +3618,28 @@ evaluxn(Uxn *u, u16 vec)
3446 u->rst.ptr += 4; 3618 u->rst.ptr += 4;
3447 } 3619 }
3448 break; 3620 break;
3621 case 0xe4: /* NIP2kr */
3622 __asm__("evaluxn_e4_NIP2kr:");
3623 {
3624 u16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8));
3625 (u->rst.dat[u->rst.ptr - 3] | (u->rst.dat[u->rst.ptr - 4] << 8));
3626 u->rst.dat[u->rst.ptr] = a >> 8;
3627 u->rst.dat[u->rst.ptr + 1] = a & 0xff;
3628#ifndef NO_STACK_CHECKS
3629 if(__builtin_expect(u->rst.ptr < 4, 0)) {
3630 u->rst.error = 1;
3631 goto error;
3632 }
3633 if(__builtin_expect(u->rst.ptr > 253, 0)) {
3634 u->rst.error = 2;
3635 goto error;
3636 }
3637#endif
3638 u->rst.ptr += 2;
3639 }
3640 break;
3449 case 0xe5: /* SWP2kr */ 3641 case 0xe5: /* SWP2kr */
3450 __asm__( "evaluxn_e5_SWP2kr:" ); 3642 __asm__("evaluxn_e5_SWP2kr:");
3451 { 3643 {
3452 u8 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]; 3644 u8 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];
3453 u->rst.dat[u->rst.ptr] = b; 3645 u->rst.dat[u->rst.ptr] = b;
@@ -3468,7 +3660,7 @@ evaluxn(Uxn *u, u16 vec)
3468 } 3660 }
3469 break; 3661 break;
3470 case 0xe6: /* OVR2kr */ 3662 case 0xe6: /* OVR2kr */
3471 __asm__( "evaluxn_e6_OVR2kr:" ); 3663 __asm__("evaluxn_e6_OVR2kr:");
3472 { 3664 {
3473 u8 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]; 3665 u8 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];
3474 u->rst.dat[u->rst.ptr] = d; 3666 u->rst.dat[u->rst.ptr] = d;
@@ -3491,7 +3683,7 @@ evaluxn(Uxn *u, u16 vec)
3491 } 3683 }
3492 break; 3684 break;
3493 case 0xe7: /* ROT2kr */ 3685 case 0xe7: /* ROT2kr */
3494 __asm__( "evaluxn_e7_ROT2kr:" ); 3686 __asm__("evaluxn_e7_ROT2kr:");
3495 { 3687 {
3496 u8 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], e = u->rst.dat[u->rst.ptr - 5], f = u->rst.dat[u->rst.ptr - 6]; 3688 u8 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], e = u->rst.dat[u->rst.ptr - 5], f = u->rst.dat[u->rst.ptr - 6];
3497 u->rst.dat[u->rst.ptr] = d; 3689 u->rst.dat[u->rst.ptr] = d;
@@ -3514,7 +3706,7 @@ evaluxn(Uxn *u, u16 vec)
3514 } 3706 }
3515 break; 3707 break;
3516 case 0xe8: /* EQU2kr */ 3708 case 0xe8: /* EQU2kr */
3517 __asm__( "evaluxn_e8_EQU2kr:" ); 3709 __asm__("evaluxn_e8_EQU2kr:");
3518 { 3710 {
3519 u16 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)); 3711 u16 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));
3520 u->rst.dat[u->rst.ptr] = b == a; 3712 u->rst.dat[u->rst.ptr] = b == a;
@@ -3532,7 +3724,7 @@ evaluxn(Uxn *u, u16 vec)
3532 } 3724 }
3533 break; 3725 break;
3534 case 0xe9: /* NEQ2kr */ 3726 case 0xe9: /* NEQ2kr */
3535 __asm__( "evaluxn_e9_NEQ2kr:" ); 3727 __asm__("evaluxn_e9_NEQ2kr:");
3536 { 3728 {
3537 u16 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)); 3729 u16 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));
3538 u->rst.dat[u->rst.ptr] = b != a; 3730 u->rst.dat[u->rst.ptr] = b != a;
@@ -3550,7 +3742,7 @@ evaluxn(Uxn *u, u16 vec)
3550 } 3742 }
3551 break; 3743 break;
3552 case 0xea: /* GTH2kr */ 3744 case 0xea: /* GTH2kr */
3553 __asm__( "evaluxn_ea_GTH2kr:" ); 3745 __asm__("evaluxn_ea_GTH2kr:");
3554 { 3746 {
3555 u16 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)); 3747 u16 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));
3556 u->rst.dat[u->rst.ptr] = b > a; 3748 u->rst.dat[u->rst.ptr] = b > a;
@@ -3568,7 +3760,7 @@ evaluxn(Uxn *u, u16 vec)
3568 } 3760 }
3569 break; 3761 break;
3570 case 0xeb: /* LTH2kr */ 3762 case 0xeb: /* LTH2kr */
3571 __asm__( "evaluxn_eb_LTH2kr:" ); 3763 __asm__("evaluxn_eb_LTH2kr:");
3572 { 3764 {
3573 u16 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)); 3765 u16 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));
3574 u->rst.dat[u->rst.ptr] = b < a; 3766 u->rst.dat[u->rst.ptr] = b < a;
@@ -3586,7 +3778,7 @@ evaluxn(Uxn *u, u16 vec)
3586 } 3778 }
3587 break; 3779 break;
3588 case 0xec: /* JMP2kr */ 3780 case 0xec: /* JMP2kr */
3589 __asm__( "evaluxn_ec_JMP2kr:" ); 3781 __asm__("evaluxn_ec_JMP2kr:");
3590 { 3782 {
3591 u->ram.ptr = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)); 3783 u->ram.ptr = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8));
3592#ifndef NO_STACK_CHECKS 3784#ifndef NO_STACK_CHECKS
@@ -3598,7 +3790,7 @@ evaluxn(Uxn *u, u16 vec)
3598 } 3790 }
3599 break; 3791 break;
3600 case 0xed: /* JCN2kr */ 3792 case 0xed: /* JCN2kr */
3601 __asm__( "evaluxn_ed_JCN2kr:" ); 3793 __asm__("evaluxn_ed_JCN2kr:");
3602 { 3794 {
3603 u16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)); 3795 u16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8));
3604 if(u->rst.dat[u->rst.ptr - 3]) u->ram.ptr = a; 3796 if(u->rst.dat[u->rst.ptr - 3]) u->ram.ptr = a;
@@ -3611,7 +3803,7 @@ evaluxn(Uxn *u, u16 vec)
3611 } 3803 }
3612 break; 3804 break;
3613 case 0xee: /* JSR2kr */ 3805 case 0xee: /* JSR2kr */
3614 __asm__( "evaluxn_ee_JSR2kr:" ); 3806 __asm__("evaluxn_ee_JSR2kr:");
3615 { 3807 {
3616 u->wst.dat[u->wst.ptr] = u->ram.ptr >> 8; 3808 u->wst.dat[u->wst.ptr] = u->ram.ptr >> 8;
3617 u->wst.dat[u->wst.ptr + 1] = u->ram.ptr & 0xff; 3809 u->wst.dat[u->wst.ptr + 1] = u->ram.ptr & 0xff;
@@ -3630,7 +3822,7 @@ evaluxn(Uxn *u, u16 vec)
3630 } 3822 }
3631 break; 3823 break;
3632 case 0xef: /* STH2kr */ 3824 case 0xef: /* STH2kr */
3633 __asm__( "evaluxn_ef_STH2kr:" ); 3825 __asm__("evaluxn_ef_STH2kr:");
3634 { 3826 {
3635 u8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; 3827 u8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2];
3636 u->wst.dat[u->wst.ptr] = b; 3828 u->wst.dat[u->wst.ptr] = b;
@@ -3649,7 +3841,7 @@ evaluxn(Uxn *u, u16 vec)
3649 } 3841 }
3650 break; 3842 break;
3651 case 0xf0: /* LDZ2kr */ 3843 case 0xf0: /* LDZ2kr */
3652 __asm__( "evaluxn_f0_LDZ2kr:" ); 3844 __asm__("evaluxn_f0_LDZ2kr:");
3653 { 3845 {
3654 u8 a = u->rst.dat[u->rst.ptr - 1]; 3846 u8 a = u->rst.dat[u->rst.ptr - 1];
3655 u->rst.dat[u->rst.ptr] = mempeek8(u->ram.dat, a); 3847 u->rst.dat[u->rst.ptr] = mempeek8(u->ram.dat, a);
@@ -3668,7 +3860,7 @@ evaluxn(Uxn *u, u16 vec)
3668 } 3860 }
3669 break; 3861 break;
3670 case 0xf1: /* STZ2kr */ 3862 case 0xf1: /* STZ2kr */
3671 __asm__( "evaluxn_f1_STZ2kr:" ); 3863 __asm__("evaluxn_f1_STZ2kr:");
3672 { 3864 {
3673 u8 a = u->rst.dat[u->rst.ptr - 1]; 3865 u8 a = u->rst.dat[u->rst.ptr - 1];
3674 u16 b = (u->rst.dat[u->rst.ptr - 2] | (u->rst.dat[u->rst.ptr - 3] << 8)); 3866 u16 b = (u->rst.dat[u->rst.ptr - 2] | (u->rst.dat[u->rst.ptr - 3] << 8));
@@ -3682,7 +3874,7 @@ evaluxn(Uxn *u, u16 vec)
3682 } 3874 }
3683 break; 3875 break;
3684 case 0xf2: /* LDR2kr */ 3876 case 0xf2: /* LDR2kr */
3685 __asm__( "evaluxn_f2_LDR2kr:" ); 3877 __asm__("evaluxn_f2_LDR2kr:");
3686 { 3878 {
3687 u8 a = u->rst.dat[u->rst.ptr - 1]; 3879 u8 a = u->rst.dat[u->rst.ptr - 1];
3688 u->rst.dat[u->rst.ptr] = mempeek8(u->ram.dat, u->ram.ptr + (s8)a); 3880 u->rst.dat[u->rst.ptr] = mempeek8(u->ram.dat, u->ram.ptr + (s8)a);
@@ -3701,7 +3893,7 @@ evaluxn(Uxn *u, u16 vec)
3701 } 3893 }
3702 break; 3894 break;
3703 case 0xf3: /* STR2kr */ 3895 case 0xf3: /* STR2kr */
3704 __asm__( "evaluxn_f3_STR2kr:" ); 3896 __asm__("evaluxn_f3_STR2kr:");
3705 { 3897 {
3706 u8 a = u->rst.dat[u->rst.ptr - 1]; 3898 u8 a = u->rst.dat[u->rst.ptr - 1];
3707 u16 b = (u->rst.dat[u->rst.ptr - 2] | (u->rst.dat[u->rst.ptr - 3] << 8)); 3899 u16 b = (u->rst.dat[u->rst.ptr - 2] | (u->rst.dat[u->rst.ptr - 3] << 8));
@@ -3715,7 +3907,7 @@ evaluxn(Uxn *u, u16 vec)
3715 } 3907 }
3716 break; 3908 break;
3717 case 0xf4: /* LDA2kr */ 3909 case 0xf4: /* LDA2kr */
3718 __asm__( "evaluxn_f4_LDA2kr:" ); 3910 __asm__("evaluxn_f4_LDA2kr:");
3719 { 3911 {
3720 u16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)); 3912 u16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8));
3721 u->rst.dat[u->rst.ptr] = mempeek8(u->ram.dat, a); 3913 u->rst.dat[u->rst.ptr] = mempeek8(u->ram.dat, a);
@@ -3734,7 +3926,7 @@ evaluxn(Uxn *u, u16 vec)
3734 } 3926 }
3735 break; 3927 break;
3736 case 0xf5: /* STA2kr */ 3928 case 0xf5: /* STA2kr */
3737 __asm__( "evaluxn_f5_STA2kr:" ); 3929 __asm__("evaluxn_f5_STA2kr:");
3738 { 3930 {
3739 u16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)); 3931 u16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8));
3740 u16 b = (u->rst.dat[u->rst.ptr - 3] | (u->rst.dat[u->rst.ptr - 4] << 8)); 3932 u16 b = (u->rst.dat[u->rst.ptr - 3] | (u->rst.dat[u->rst.ptr - 4] << 8));
@@ -3748,7 +3940,7 @@ evaluxn(Uxn *u, u16 vec)
3748 } 3940 }
3749 break; 3941 break;
3750 case 0xf6: /* DEI2kr */ 3942 case 0xf6: /* DEI2kr */
3751 __asm__( "evaluxn_f6_DEI2kr:" ); 3943 __asm__("evaluxn_f6_DEI2kr:");
3752 { 3944 {
3753 u8 a = u->rst.dat[u->rst.ptr - 1]; 3945 u8 a = u->rst.dat[u->rst.ptr - 1];
3754 u->rst.dat[u->rst.ptr] = devpeek8(&u->dev[a >> 4], a); 3946 u->rst.dat[u->rst.ptr] = devpeek8(&u->dev[a >> 4], a);
@@ -3767,7 +3959,7 @@ evaluxn(Uxn *u, u16 vec)
3767 } 3959 }
3768 break; 3960 break;
3769 case 0xf7: /* DEO2kr */ 3961 case 0xf7: /* DEO2kr */
3770 __asm__( "evaluxn_f7_DEO2kr:" ); 3962 __asm__("evaluxn_f7_DEO2kr:");
3771 { 3963 {
3772 u8 a = u->rst.dat[u->rst.ptr - 1]; 3964 u8 a = u->rst.dat[u->rst.ptr - 1];
3773 u16 b = (u->rst.dat[u->rst.ptr - 2] | (u->rst.dat[u->rst.ptr - 3] << 8)); 3965 u16 b = (u->rst.dat[u->rst.ptr - 2] | (u->rst.dat[u->rst.ptr - 3] << 8));
@@ -3781,7 +3973,7 @@ evaluxn(Uxn *u, u16 vec)
3781 } 3973 }
3782 break; 3974 break;
3783 case 0xf8: /* ADD2kr */ 3975 case 0xf8: /* ADD2kr */
3784 __asm__( "evaluxn_f8_ADD2kr:" ); 3976 __asm__("evaluxn_f8_ADD2kr:");
3785 { 3977 {
3786 u16 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)); 3978 u16 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));
3787 u->rst.dat[u->rst.ptr] = (b + a) >> 8; 3979 u->rst.dat[u->rst.ptr] = (b + a) >> 8;
@@ -3800,7 +3992,7 @@ evaluxn(Uxn *u, u16 vec)
3800 } 3992 }
3801 break; 3993 break;
3802 case 0xf9: /* SUB2kr */ 3994 case 0xf9: /* SUB2kr */
3803 __asm__( "evaluxn_f9_SUB2kr:" ); 3995 __asm__("evaluxn_f9_SUB2kr:");
3804 { 3996 {
3805 u16 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)); 3997 u16 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));
3806 u->rst.dat[u->rst.ptr] = (b - a) >> 8; 3998 u->rst.dat[u->rst.ptr] = (b - a) >> 8;
@@ -3819,7 +4011,7 @@ evaluxn(Uxn *u, u16 vec)
3819 } 4011 }
3820 break; 4012 break;
3821 case 0xfa: /* MUL2kr */ 4013 case 0xfa: /* MUL2kr */
3822 __asm__( "evaluxn_fa_MUL2kr:" ); 4014 __asm__("evaluxn_fa_MUL2kr:");
3823 { 4015 {
3824 u16 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)); 4016 u16 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));
3825 u->rst.dat[u->rst.ptr] = (b * a) >> 8; 4017 u->rst.dat[u->rst.ptr] = (b * a) >> 8;
@@ -3838,9 +4030,16 @@ evaluxn(Uxn *u, u16 vec)
3838 } 4030 }
3839 break; 4031 break;
3840 case 0xfb: /* DIV2kr */ 4032 case 0xfb: /* DIV2kr */
3841 __asm__( "evaluxn_fb_DIV2kr:" ); 4033 __asm__("evaluxn_fb_DIV2kr:");
3842 { 4034 {
3843 u16 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)); 4035 u16 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));
4036 if(a == 0) {
4037 u->rst.error = 3;
4038#ifndef NO_STACK_CHECKS
4039 goto error;
4040#endif
4041 a = 1;
4042 }
3844 u->rst.dat[u->rst.ptr] = (b / a) >> 8; 4043 u->rst.dat[u->rst.ptr] = (b / a) >> 8;
3845 u->rst.dat[u->rst.ptr + 1] = (b / a) & 0xff; 4044 u->rst.dat[u->rst.ptr + 1] = (b / a) & 0xff;
3846#ifndef NO_STACK_CHECKS 4045#ifndef NO_STACK_CHECKS
@@ -3857,7 +4056,7 @@ evaluxn(Uxn *u, u16 vec)
3857 } 4056 }
3858 break; 4057 break;
3859 case 0xfc: /* AND2kr */ 4058 case 0xfc: /* AND2kr */
3860 __asm__( "evaluxn_fc_AND2kr:" ); 4059 __asm__("evaluxn_fc_AND2kr:");
3861 { 4060 {
3862 u8 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]; 4061 u8 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];
3863 u->rst.dat[u->rst.ptr] = d & b; 4062 u->rst.dat[u->rst.ptr] = d & b;
@@ -3876,7 +4075,7 @@ evaluxn(Uxn *u, u16 vec)
3876 } 4075 }
3877 break; 4076 break;
3878 case 0xfd: /* ORA2kr */ 4077 case 0xfd: /* ORA2kr */
3879 __asm__( "evaluxn_fd_ORA2kr:" ); 4078 __asm__("evaluxn_fd_ORA2kr:");
3880 { 4079 {
3881 u8 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]; 4080 u8 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];
3882 u->rst.dat[u->rst.ptr] = d | b; 4081 u->rst.dat[u->rst.ptr] = d | b;
@@ -3895,7 +4094,7 @@ evaluxn(Uxn *u, u16 vec)
3895 } 4094 }
3896 break; 4095 break;
3897 case 0xfe: /* EOR2kr */ 4096 case 0xfe: /* EOR2kr */
3898 __asm__( "evaluxn_fe_EOR2kr:" ); 4097 __asm__("evaluxn_fe_EOR2kr:");
3899 { 4098 {
3900 u8 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]; 4099 u8 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];
3901 u->rst.dat[u->rst.ptr] = d ^ b; 4100 u->rst.dat[u->rst.ptr] = d ^ b;
@@ -3914,7 +4113,7 @@ evaluxn(Uxn *u, u16 vec)
3914 } 4113 }
3915 break; 4114 break;
3916 case 0xff: /* SFT2kr */ 4115 case 0xff: /* SFT2kr */
3917 __asm__( "evaluxn_ff_SFT2kr:" ); 4116 __asm__("evaluxn_ff_SFT2kr:");
3918 { 4117 {
3919 u8 a = u->rst.dat[u->rst.ptr - 1]; 4118 u8 a = u->rst.dat[u->rst.ptr - 1];
3920 u16 b = (u->rst.dat[u->rst.ptr - 2] | (u->rst.dat[u->rst.ptr - 3] << 8)); 4119 u16 b = (u->rst.dat[u->rst.ptr - 2] | (u->rst.dat[u->rst.ptr - 3] << 8));