From bfd3c8ece9299146b94efca129b1f382c79da346 Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Fri, 4 Mar 2022 15:09:58 +0100 Subject: Prepare uxn ppu initialization --- Makefile | 7 +- src/main.c | 60 +- src/ppu.c | 144 ++ src/ppu.h | 20 + src/rom.c | 52 + src/shorthand.h | 46 + src/uxn-fast.c | 4286 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/uxn.h | 49 + 8 files changed, 4625 insertions(+), 39 deletions(-) create mode 100644 src/ppu.c create mode 100644 src/ppu.h create mode 100644 src/rom.c create mode 100644 src/shorthand.h create mode 100644 src/uxn-fast.c create mode 100644 src/uxn.h diff --git a/Makefile b/Makefile index 2896bfc..cfdf43f 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,10 @@ +BASE_UXN := src/uxn/src SRC_DIR ?= src BUILD_DIR ?= build SRC_MAIN ?= $(SRC_DIR)/main.c EXE_NAME ?= fbtest BIN := $(BUILD_DIR)/$(EXE_NAME) -BASE_UXN := src/uxn/src/uxn.h +UXN_HEAD := $(BASE_UXN)/uxn.h CC ?= cc CFLAGS := -Wall -Wextra -pedantic @@ -24,13 +25,13 @@ endif main: $(BIN) -$(BIN): $(SRC_MAIN) $(BUILD_DIR) $(BASE_UXN) +$(BIN): $(SRC_MAIN) $(BUILD_DIR) $(UXN_HEAD) $(CC) $(CFLAGS) -o $(BIN) $(SRC_MAIN) $(BUILD_DIR): mkdir -p $(BUILD_DIR) -$(BASE_UXN): +$(UXN_HEAD): git submodule init git submodule update diff --git a/src/main.c b/src/main.c index b5247af..aabf79f 100644 --- a/src/main.c +++ b/src/main.c @@ -1,45 +1,36 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "shorthand.h" +#include "ppu.c" +#include "uxn-fast.c" +#include "rom.c" + +// static Uxn u; +// static Device *devscreen; +// static Device *devctrl; +// static Device *devmouse; +// static Device *devaudio; int main(void) { - // Open frambuffer and get the size. - int fb = open("/dev/fb0", O_RDWR); - if (fb <= 0) { - fprintf(stderr, "couldn't open the framebuffer\n"); - exit(EXIT_FAILURE); - } - struct fb_var_screeninfo info; - if (ioctl(fb, FBIOGET_VSCREENINFO, &info) != 0) { - fprintf(stderr, "couldn't get the framebuffer size\n"); - exit(EXIT_FAILURE); - } - - // Mmap the framebuffer to a buffer object. - size_t width = info.xres; - size_t height = info.yres; - size_t len = 4 * width * height; - uint32_t *buf = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, fb, 0); - if (buf == MAP_FAILED) { - fprintf(stderr, "couldn't mmap the framebuffer\n"); - exit(EXIT_FAILURE); - } + ppu_init(); // Main loop. uint8_t shade = 0; size_t counter = 0; size_t direction = 1; while (true) { - for (size_t j = 0; j < height; j++) { - for (size_t i = 0; i < width; i++) { - buf[j * width + i] = shade; + for (size_t j = 0; j < screen_height; j++) { + for (size_t i = 0; i < screen_width; i++) { + framebuffer[j * screen_width + i] = shade; } } counter++; @@ -54,8 +45,5 @@ main(void) { } } - // Cleanup. - munmap(buf, len); - close(fb); return 0; } diff --git a/src/ppu.c b/src/ppu.c new file mode 100644 index 0000000..6c38ab6 --- /dev/null +++ b/src/ppu.c @@ -0,0 +1,144 @@ +#include + +#include "ppu.h" + +/* +Copyright (c) 2021 Devine Lu Linvega +Copyright (c) 2021 Andrew Alderwick +Copyright (c) 2021 Bad Diode + +Permission to use, copy, modify, and distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE. +*/ + +static size_t screen_width = 0; +static size_t screen_height = 0; + +static u32 *framebuffer = 0; + +static u32 palette[16]; +static u8 *pixels_buf; +static u8 *dirty_lines; +static u8 reqdraw = 0; +// TODO: Probably should consider this +// static u32 rgb_order; + +static u8 blending[5][16] = { + {0, 0, 0, 0, 1, 0, 1, 1, 2, 2, 0, 2, 3, 3, 3, 0}, + {0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3}, + {1, 2, 3, 1, 1, 2, 3, 1, 1, 2, 3, 1, 1, 2, 3, 1}, + {2, 3, 1, 2, 2, 3, 1, 2, 2, 3, 1, 2, 2, 3, 1, 2}, + {1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0}}; + +void +ppu_pixel(u8 layer, u16 x, u16 y, u8 color) { + size_t idx = y * screen_width + x; + u8 *pixel = &pixels_buf[idx], shift = layer * 2; + if(x < screen_width && y < screen_height) { + *pixel = (*pixel & ~(0x3 << shift)) | (color << shift); + } + dirty_lines[y] |= 1; +} + +void +ppu_1bpp(u8 layer, u16 x, u16 y, u8 *sprite, u8 color, u8 flipx, u8 flipy) { + u16 v, h; + for(v = 0; v < 8; v++) + for(h = 0; h < 8; h++) { + u8 ch1 = (sprite[v] >> (7 - h)) & 0x1; + if(ch1 || blending[4][color]) + ppu_pixel(layer, + x + (flipx ? 7 - h : h), + y + (flipy ? 7 - v : v), + blending[ch1][color]); + } +} + +void +ppu_2bpp(u8 layer, u16 x, u16 y, u8 *sprite, u8 color, u8 flipx, u8 flipy) { + u16 v, h; + for(v = 0; v < 8; v++) + for(h = 0; h < 8; h++) { + u8 ch1 = ((sprite[v] >> (7 - h)) & 0x1); + u8 ch2 = ((sprite[v + 8] >> (7 - h)) & 0x1); + u8 ch = ch1 + ch2 * 2; + if(ch || blending[4][color]) + ppu_pixel(layer, + x + (flipx ? 7 - h : h), + y + (flipy ? 7 - v : v), + blending[ch][color]); + } +} + +void +redraw_screen(void) { + for (size_t j = 0; j < screen_height; j++) { + dirty_lines[j] = 1; + } +} + +int +ppu_init(void) { + // Open frambuffer and get the size. + int fb = open("/dev/fb0", O_RDWR); + if (fb <= 0) { + fprintf(stderr, "couldn't open the framebuffer\n"); + exit(EXIT_FAILURE); + } + struct fb_var_screeninfo info; + if (ioctl(fb, FBIOGET_VSCREENINFO, &info) != 0) { + fprintf(stderr, "couldn't get the framebuffer size\n"); + exit(EXIT_FAILURE); + } + + // Mmap the framebuffer to a buffer object. + screen_width = info.xres; + screen_height = info.yres; + size_t len = 4 * screen_width * screen_height; + framebuffer = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, fb, 0); + if (framebuffer == MAP_FAILED) { + fprintf(stderr, "couldn't mmap the framebuffer\n"); + exit(EXIT_FAILURE); + } + + // Allocate intermediate buffers. + pixels_buf = malloc(screen_width * screen_height); + dirty_lines = malloc(screen_height); + + // Initialize default palette. + palette[0] = 0x444444; + palette[1] = 0xffffff; + palette[2] = 0x7777ff; + palette[3] = 0xff7777; + + // Clear pixel buffer memory. + memset(pixels_buf, 0, screen_width * screen_height); + memset(dirty_lines, 1, screen_height); + + // Make sure we perform an initial screen drawing. + reqdraw = 1; + redraw_screen(); + + return 1; +} + +void +blit_framebuffer(void) { + if (reqdraw == 0) { + return; + } + for (size_t j = 0; j < screen_height; j++) { + if (dirty_lines[j] != 0) { + for (size_t i = 0; i < screen_width; i++) { + size_t idx = i + j * screen_width; + framebuffer[idx] = palette[pixels_buf[idx] % 16]; + } + } + dirty_lines[j] = 0; + } + reqdraw = 0; +} diff --git a/src/ppu.h b/src/ppu.h new file mode 100644 index 0000000..852c207 --- /dev/null +++ b/src/ppu.h @@ -0,0 +1,20 @@ +/* +Copyright (c) 2021 Devine Lu Linvega +Copyright (c) 2021 Andrew Alderwick + +Permission to use, copy, modify, and distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE. +*/ + +typedef unsigned char Uint8; +typedef unsigned short Uint16; +typedef unsigned int Uint32; + +int ppu_init(void); +void ppu_pixel(Uint8 layer, Uint16 x, Uint16 y, Uint8 color); +void ppu_1bpp(Uint8 layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy); +void ppu_2bpp(Uint8 layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy); diff --git a/src/rom.c b/src/rom.c new file mode 100644 index 0000000..419cad8 --- /dev/null +++ b/src/rom.c @@ -0,0 +1,52 @@ +const u16 uxn_rom[] = { + 0x0120, 0x8043, 0x3720, 0xf020, 0x807f, 0x3708, 0xf020, 0x80e0, + 0x370a, 0xf020, 0x80c0, 0x370c, 0x2280, 0x8036, 0x3f01, 0x0020, + 0x3920, 0x0280, 0x8031, 0x3624, 0x0180, 0x803f, 0x3104, 0x0120, + 0x2ed4, 0x0220, 0x2e2f, 0x0220, 0x2e71, 0x0220, 0x2eae, 0x0320, + 0x2e3a, 0x8000, 0x3000, 0x2321, 0x0080, 0x8031, 0x3002, 0x0020, + 0x3848, 0x2880, 0x8037, 0x3004, 0x0020, 0x3950, 0x2a80, 0x8037, + 0x0f01, 0x0305, 0x0480, 0x801f, 0x0500, 0x3080, 0x203f, 0x9103, + 0x8038, 0x372c, 0x80cf, 0x172f, 0x0f80, 0x801c, 0x0500, 0x3080, + 0x203f, 0x9103, 0x8038, 0x372c, 0x2880, 0x2036, 0x0800, 0x8038, + 0x3728, 0x80cf, 0x172f, 0x8003, 0x1f04, 0x0080, 0x8005, 0x3f30, + 0x0320, 0x3891, 0x2c80, 0x8037, 0x3628, 0x0020, 0x3808, 0x2880, + 0xcf37, 0x2f80, 0x8017, 0x1c0f, 0x0080, 0x8005, 0x3f30, 0x0320, + 0x3891, 0x2c80, 0x8037, 0x3628, 0x0020, 0x3808, 0x2880, 0x4f37, + 0x2f80, 0x0017, 0x1080, 0x0080, 0x8003, 0x1f30, 0x0080, 0x2005, + 0x9103, 0x8038, 0x372c, 0x8003, 0x1f30, 0x0080, 0x8005, 0x3002, + 0x0020, 0x3940, 0x8038, 0x3728, 0x0480, 0x2030, 0x5000, 0x8039, + 0x372a, 0x0180, 0x2f80, 0x0317, 0x3080, 0x801f, 0x0500, 0x0480, + 0x2030, 0x4000, 0x3839, 0x2a80, 0x8037, 0x3002, 0x0020, 0x3950, + 0x2880, 0x8037, 0x8001, 0x172f, 0x8a01, 0xab80, 0x220d, 0x206c, + 0x8103, 0x2c80, 0x8037, 0x8000, 0x0300, 0x0f80, 0x801c, 0x1f40, + 0x0180, 0x801f, 0x0500, 0x0280, 0x2030, 0x4000, 0x3839, 0x2880, + 0x0337, 0xf080, 0x801c, 0x1f01, 0x0080, 0x8005, 0x3004, 0x0020, + 0x3940, 0x8038, 0x372a, 0x8003, 0x172f, 0x8901, 0xca80, 0x220d, + 0x806c, 0x8010, 0x8f00, 0x8003, 0x1f02, 0x0080, 0x8005, 0x3f40, + 0x0480, 0x2030, 0x4000, 0x3839, 0x032f, 0x0380, 0x801c, 0x0500, + 0x4080, 0x203f, 0x4000, 0x8038, 0x3002, 0x0020, 0x3808, 0x6f38, + 0x804f, 0x2000, 0xe702, 0x012e, 0x808a, 0x0dc9, 0x6c22, 0x1080, + 0x0080, 0x038f, 0x0280, 0x801f, 0x0500, 0x4080, 0x803f, 0x3004, + 0x2f38, 0x8003, 0x1c03, 0x0080, 0x8005, 0x3f40, 0x0020, 0x3840, + 0x0280, 0x2030, 0x0800, 0x3838, 0x4f6f, 0x8080, 0x0220, 0x2ee7, + 0x8a01, 0xcd80, 0x220d, 0x186c, 0x200f, 0x8103, 0x2c80, 0x8037, + 0x372a, 0x2880, 0x8037, 0xcf00, 0x8018, 0x172f, 0x2880, 0x2036, + 0x0800, 0x8038, 0x3728, 0x1080, 0x18cf, 0x2f80, 0x8017, 0x3628, + 0x0020, 0x3908, 0x2880, 0x8037, 0x362a, 0x0020, 0x3808, 0x2a80, + 0x8037, 0xcf20, 0x8018, 0x172f, 0x2880, 0x2036, 0x0800, 0x8038, + 0x3728, 0x3080, 0x184f, 0x2f80, 0x6c17, 0x0480, 0x2030, 0x4000, + 0x8039, 0x372a, 0x0280, 0x2030, 0x4800, 0x8038, 0x3728, 0x0080, + 0x2e80, 0x8017, 0x3002, 0x0020, 0x3849, 0x2880, 0x8037, 0x8001, + 0x172e, 0x0280, 0x2030, 0x4a00, 0x8038, 0x3728, 0x0280, 0x2e80, + 0x8017, 0x3002, 0x0020, 0x384b, 0x2880, 0x8037, 0x8003, 0x172e, + 0x0f6c, 0x6738, 0xdf5f, 0xbfbf, 0x00bf, 0x1807, 0x2320, 0x4844, + 0x0048, 0x827c, 0x8282, 0x8282, 0x007c, 0x1030, 0x1010, 0x1010, + 0x0010, 0x827c, 0x7c02, 0x8080, 0x00fe, 0x827c, 0x1c02, 0x8202, + 0x007c, 0x140c, 0x4424, 0xfe84, 0x0004, 0x80fe, 0x7c80, 0x8202, + 0x007c, 0x827c, 0xfc80, 0x8282, 0x007c, 0x827c, 0x1e02, 0x0202, + 0x0002, 0x827c, 0x7c82, 0x8282, 0x007c, 0x827c, 0x7e82, 0x8202, + 0x007c, 0x827c, 0x7e02, 0x8282, 0x007e, 0x82fc, 0xfc82, 0x8282, + 0x00fc, 0x827c, 0x8080, 0x8280, 0x007c, 0x82fc, 0x8282, 0x8282, + 0x00fc, 0x827c, 0xf080, 0x8280, 0x007c, 0x827c, 0xf080, 0x8080, + 0x8080, +}; diff --git a/src/shorthand.h b/src/shorthand.h new file mode 100644 index 0000000..0897824 --- /dev/null +++ b/src/shorthand.h @@ -0,0 +1,46 @@ +/* +Copyright (c) 2021 Bad Diode + +Permission to use, copy, modify, and distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE. +*/ + +#ifndef UTILS_SHORTHAND_H +#define UTILS_SHORTHAND_H + +#include +#include +#include + +// +// This simple header just typedefs the basic C define types to a shorter name, +// loads the quality of life bool macro for _Bool and defines shorthand macros +// for byte sizes. + +typedef uint8_t u8; +typedef uint16_t u16; +typedef uint32_t u32; +typedef uint64_t u64; +typedef int8_t s8; +typedef int16_t s16; +typedef int32_t s32; +typedef int64_t s64; +typedef volatile u8 vu8; +typedef volatile u16 vu16; +typedef volatile u32 vu32; +typedef volatile u64 vu64; +typedef volatile s8 vs8; +typedef volatile s16 vs16; +typedef volatile s32 vs32; +typedef volatile s64 vs64; + +#define KB(N) ((u64)(N) * 1024) +#define MB(N) ((u64)KB(N) * 1024) +#define GB(N) ((u64)MB(N) * 1024) +#define TB(N) ((u64)GB(N) * 1024) + +#endif // UTILS_SHORTHAND_H diff --git a/src/uxn-fast.c b/src/uxn-fast.c new file mode 100644 index 0000000..7ee1d04 --- /dev/null +++ b/src/uxn-fast.c @@ -0,0 +1,4286 @@ +#include "uxn.h" + +/* +Copyright (u) 2021 Devine Lu Linvega +Copyright (u) 2021 Andrew Alderwick + +Permission to use, copy, modify, and distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE. +*/ + +/* + ^ +/!\ THIS FILE IS AUTOMATICALLY GENERATED +--- + +Its contents can get overwritten with the processed contents of src/uxn.c. +See etc/mkuxn-fast.moon for instructions. + +*/ + +#define MODE_RETURN 0x40 +#define MODE_KEEP 0x80 + +/* clang-format off */ +static void mempoke8(Uint8 *m, Uint16 a, Uint8 b) { m[a] = b; } +static Uint8 mempeek8(Uint8 *m, Uint16 a) { return m[a]; } +static void devpoke8(Device *d, Uint8 a, Uint8 b) { d->dat[a & 0xf] = b; d->talk(d, a & 0x0f, 1); } +static Uint8 devpeek8(Device *d, Uint8 a) { d->talk(d, a & 0x0f, 0); return d->dat[a & 0xf]; } +void __attribute__ ((noinline)) mempoke16(Uint8 *m, Uint16 a, Uint16 b) { mempoke8(m, a, b >> 8); mempoke8(m, a + 1, b); } +Uint16 __attribute__ ((noinline)) mempeek16(Uint8 *m, Uint16 a) { return (mempeek8(m, a) << 8) + mempeek8(m, a + 1); } +static void __attribute__ ((noinline)) devpoke16(Device *d, Uint8 a, Uint16 b) { devpoke8(d, a, b >> 8); devpoke8(d, a + 1, b); } + +/* clang-format on */ + +int +uxn_eval(Uxn *u, Uint16 vec) +{ + Uint8 instr; + if(!vec || u->dev[0].dat[0xf]) + return 0; + u->ram.ptr = vec; + if(u->wst.ptr > 0xf8) u->wst.ptr = 0xf8; + while((instr = u->ram.dat[u->ram.ptr++])) { + switch(instr) { +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-value" +#pragma GCC diagnostic ignored "-Wunused-variable" + case 0x00: /* LIT */ + case 0x80: /* LITk */ + __asm__("evaluxn_00_LIT:"); + { + u->wst.dat[u->wst.ptr] = mempeek8(u->ram.dat, u->ram.ptr++); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr > 254, 0)) { + u->wst.error = 2; + goto error; + } +#endif + u->wst.ptr += 1; + } + break; + case 0x01: /* INC */ + __asm__("evaluxn_01_INC:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1]; + u->wst.dat[u->wst.ptr - 1] = a + 1; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 1, 0)) { + u->wst.error = 1; + goto error; + } +#endif + } + break; + case 0x02: /* POP */ + __asm__("evaluxn_02_POP:"); + { + u->wst.dat[u->wst.ptr - 1]; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 1, 0)) { + u->wst.error = 1; + goto error; + } +#endif + u->wst.ptr -= 1; + } + break; + case 0x03: /* DUP */ + __asm__("evaluxn_03_DUP:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1]; + u->wst.dat[u->wst.ptr] = a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 1, 0)) { + u->wst.error = 1; + goto error; + } + if(__builtin_expect(u->wst.ptr > 254, 0)) { + u->wst.error = 2; + goto error; + } +#endif + u->wst.ptr += 1; + } + break; + case 0x04: /* NIP */ + __asm__("evaluxn_04_NIP:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1]; + u->wst.dat[u->wst.ptr - 2]; + u->wst.dat[u->wst.ptr - 2] = a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 2, 0)) { + u->wst.error = 1; + goto error; + } +#endif + u->wst.ptr -= 1; + } + break; + case 0x05: /* SWP */ + __asm__("evaluxn_05_SWP:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; + u->wst.dat[u->wst.ptr - 2] = a; + u->wst.dat[u->wst.ptr - 1] = b; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 2, 0)) { + u->wst.error = 1; + goto error; + } +#endif + } + break; + case 0x06: /* OVR */ + __asm__("evaluxn_06_OVR:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; + u->wst.dat[u->wst.ptr] = b; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 2, 0)) { + u->wst.error = 1; + goto error; + } + if(__builtin_expect(u->wst.ptr > 254, 0)) { + u->wst.error = 2; + goto error; + } +#endif + u->wst.ptr += 1; + } + break; + case 0x07: /* ROT */ + __asm__("evaluxn_07_ROT:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2], c = u->wst.dat[u->wst.ptr - 3]; + u->wst.dat[u->wst.ptr - 3] = b; + u->wst.dat[u->wst.ptr - 2] = a; + u->wst.dat[u->wst.ptr - 1] = c; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 3, 0)) { + u->wst.error = 1; + goto error; + } +#endif + } + break; + case 0x08: /* EQU */ + __asm__("evaluxn_08_EQU:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; + u->wst.dat[u->wst.ptr - 2] = b == a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 2, 0)) { + u->wst.error = 1; + goto error; + } +#endif + u->wst.ptr -= 1; + } + break; + case 0x09: /* NEQ */ + __asm__("evaluxn_09_NEQ:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; + u->wst.dat[u->wst.ptr - 2] = b != a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 2, 0)) { + u->wst.error = 1; + goto error; + } +#endif + u->wst.ptr -= 1; + } + break; + case 0x0a: /* GTH */ + __asm__("evaluxn_0a_GTH:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; + u->wst.dat[u->wst.ptr - 2] = b > a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 2, 0)) { + u->wst.error = 1; + goto error; + } +#endif + u->wst.ptr -= 1; + } + break; + case 0x0b: /* LTH */ + __asm__("evaluxn_0b_LTH:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; + u->wst.dat[u->wst.ptr - 2] = b < a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 2, 0)) { + u->wst.error = 1; + goto error; + } +#endif + u->wst.ptr -= 1; + } + break; + case 0x0c: /* JMP */ + __asm__("evaluxn_0c_JMP:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1]; + u->ram.ptr += (Sint8)a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 1, 0)) { + u->wst.error = 1; + goto error; + } +#endif + u->wst.ptr -= 1; + } + break; + case 0x0d: /* JCN */ + __asm__("evaluxn_0d_JCN:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1]; + if(u->wst.dat[u->wst.ptr - 2]) u->ram.ptr += (Sint8)a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 2, 0)) { + u->wst.error = 1; + goto error; + } +#endif + u->wst.ptr -= 2; + } + break; + case 0x0e: /* JSR */ + __asm__("evaluxn_0e_JSR:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1]; + u->rst.dat[u->rst.ptr] = u->ram.ptr >> 8; + u->rst.dat[u->rst.ptr + 1] = u->ram.ptr & 0xff; + u->ram.ptr += (Sint8)a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 1, 0)) { + u->wst.error = 1; + goto error; + } +#endif + u->wst.ptr -= 1; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr > 253, 0)) { + u->rst.error = 2; + goto error; + } +#endif + u->rst.ptr += 2; + } + break; + case 0x0f: /* STH */ + __asm__("evaluxn_0f_STH:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1]; + u->rst.dat[u->rst.ptr] = a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 1, 0)) { + u->wst.error = 1; + goto error; + } +#endif + u->wst.ptr -= 1; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr > 254, 0)) { + u->rst.error = 2; + goto error; + } +#endif + u->rst.ptr += 1; + } + break; + case 0x10: /* LDZ */ + __asm__("evaluxn_10_LDZ:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1]; + u->wst.dat[u->wst.ptr - 1] = mempeek8(u->ram.dat, a); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 1, 0)) { + u->wst.error = 1; + goto error; + } +#endif + } + break; + case 0x11: /* STZ */ + __asm__("evaluxn_11_STZ:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1]; + Uint8 b = u->wst.dat[u->wst.ptr - 2]; + mempoke8(u->ram.dat, a, b); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 2, 0)) { + u->wst.error = 1; + goto error; + } +#endif + u->wst.ptr -= 2; + } + break; + case 0x12: /* LDR */ + __asm__("evaluxn_12_LDR:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1]; + u->wst.dat[u->wst.ptr - 1] = mempeek8(u->ram.dat, u->ram.ptr + (Sint8)a); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 1, 0)) { + u->wst.error = 1; + goto error; + } +#endif + } + break; + case 0x13: /* STR */ + __asm__("evaluxn_13_STR:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1]; + Uint8 b = u->wst.dat[u->wst.ptr - 2]; + mempoke8(u->ram.dat, u->ram.ptr + (Sint8)a, b); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 2, 0)) { + u->wst.error = 1; + goto error; + } +#endif + u->wst.ptr -= 2; + } + break; + case 0x14: /* LDA */ + __asm__("evaluxn_14_LDA:"); + { + Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)); + u->wst.dat[u->wst.ptr - 2] = mempeek8(u->ram.dat, a); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 2, 0)) { + u->wst.error = 1; + goto error; + } +#endif + u->wst.ptr -= 1; + } + break; + case 0x15: /* STA */ + __asm__("evaluxn_15_STA:"); + { + Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)); + Uint8 b = u->wst.dat[u->wst.ptr - 3]; + mempoke8(u->ram.dat, a, b); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 3, 0)) { + u->wst.error = 1; + goto error; + } +#endif + u->wst.ptr -= 3; + } + break; + case 0x16: /* DEI */ + __asm__("evaluxn_16_DEI:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1]; + u->wst.dat[u->wst.ptr - 1] = devpeek8(&u->dev[a >> 4], a); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 1, 0)) { + u->wst.error = 1; + goto error; + } +#endif + } + break; + case 0x17: /* DEO */ + __asm__("evaluxn_17_DEO:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; + devpoke8(&u->dev[a >> 4], a, b); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 2, 0)) { + u->wst.error = 1; + goto error; + } +#endif + u->wst.ptr -= 2; + } + break; + case 0x18: /* ADD */ + __asm__("evaluxn_18_ADD:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; + u->wst.dat[u->wst.ptr - 2] = b + a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 2, 0)) { + u->wst.error = 1; + goto error; + } +#endif + u->wst.ptr -= 1; + } + break; + case 0x19: /* SUB */ + __asm__("evaluxn_19_SUB:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; + u->wst.dat[u->wst.ptr - 2] = b - a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 2, 0)) { + u->wst.error = 1; + goto error; + } +#endif + u->wst.ptr -= 1; + } + break; + case 0x1a: /* MUL */ + __asm__("evaluxn_1a_MUL:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; + u->wst.dat[u->wst.ptr - 2] = b * a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 2, 0)) { + u->wst.error = 1; + goto error; + } +#endif + u->wst.ptr -= 1; + } + break; + case 0x1b: /* DIV */ + __asm__("evaluxn_1b_DIV:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; + if(a == 0) { + u->wst.error = 3; +#ifndef NO_STACK_CHECKS + goto error; +#endif + a = 1; + } + u->wst.dat[u->wst.ptr - 2] = b / a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 2, 0)) { + u->wst.error = 1; + goto error; + } +#endif + u->wst.ptr -= 1; + } + break; + case 0x1c: /* AND */ + __asm__("evaluxn_1c_AND:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; + u->wst.dat[u->wst.ptr - 2] = b & a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 2, 0)) { + u->wst.error = 1; + goto error; + } +#endif + u->wst.ptr -= 1; + } + break; + case 0x1d: /* ORA */ + __asm__("evaluxn_1d_ORA:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; + u->wst.dat[u->wst.ptr - 2] = b | a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 2, 0)) { + u->wst.error = 1; + goto error; + } +#endif + u->wst.ptr -= 1; + } + break; + case 0x1e: /* EOR */ + __asm__("evaluxn_1e_EOR:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; + u->wst.dat[u->wst.ptr - 2] = b ^ a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 2, 0)) { + u->wst.error = 1; + goto error; + } +#endif + u->wst.ptr -= 1; + } + break; + case 0x1f: /* SFT */ + __asm__("evaluxn_1f_SFT:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; + u->wst.dat[u->wst.ptr - 2] = b >> (a & 0x07) << ((a & 0x70) >> 4); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 2, 0)) { + u->wst.error = 1; + goto error; + } +#endif + u->wst.ptr -= 1; + } + break; + case 0x20: /* LIT2 */ + case 0xa0: /* LIT2k */ + __asm__("evaluxn_20_LIT2:"); + { + u->wst.dat[u->wst.ptr] = mempeek8(u->ram.dat, u->ram.ptr++); + u->wst.dat[u->wst.ptr + 1] = mempeek8(u->ram.dat, u->ram.ptr++); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr > 253, 0)) { + u->wst.error = 2; + goto error; + } +#endif + u->wst.ptr += 2; + } + break; + case 0x21: /* INC2 */ + __asm__("evaluxn_21_INC2:"); + { + Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)); + u->wst.dat[u->wst.ptr - 2] = (a + 1) >> 8; + u->wst.dat[u->wst.ptr - 1] = (a + 1) & 0xff; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 2, 0)) { + u->wst.error = 1; + goto error; + } +#endif + } + break; + case 0x22: /* POP2 */ + __asm__("evaluxn_22_POP2:"); + { + (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 2, 0)) { + u->wst.error = 1; + goto error; + } +#endif + u->wst.ptr -= 2; + } + break; + case 0x23: /* DUP2 */ + __asm__("evaluxn_23_DUP2:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; + u->wst.dat[u->wst.ptr] = b; + u->wst.dat[u->wst.ptr + 1] = a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 2, 0)) { + u->wst.error = 1; + goto error; + } + if(__builtin_expect(u->wst.ptr > 253, 0)) { + u->wst.error = 2; + goto error; + } +#endif + u->wst.ptr += 2; + } + break; + case 0x24: /* NIP2 */ + __asm__("evaluxn_24_NIP2:"); + { + Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)); + (u->wst.dat[u->wst.ptr - 3] | (u->wst.dat[u->wst.ptr - 4] << 8)); + u->wst.dat[u->wst.ptr - 4] = a >> 8; + u->wst.dat[u->wst.ptr - 3] = a & 0xff; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 4, 0)) { + u->wst.error = 1; + goto error; + } +#endif + u->wst.ptr -= 2; + } + break; + case 0x25: /* SWP2 */ + __asm__("evaluxn_25_SWP2:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2], c = u->wst.dat[u->wst.ptr - 3], d = u->wst.dat[u->wst.ptr - 4]; + u->wst.dat[u->wst.ptr - 4] = b; + u->wst.dat[u->wst.ptr - 3] = a; + u->wst.dat[u->wst.ptr - 2] = d; + u->wst.dat[u->wst.ptr - 1] = c; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 4, 0)) { + u->wst.error = 1; + goto error; + } +#endif + } + break; + case 0x26: /* OVR2 */ + __asm__("evaluxn_26_OVR2:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2], c = u->wst.dat[u->wst.ptr - 3], d = u->wst.dat[u->wst.ptr - 4]; + u->wst.dat[u->wst.ptr] = d; + u->wst.dat[u->wst.ptr + 1] = c; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 4, 0)) { + u->wst.error = 1; + goto error; + } + if(__builtin_expect(u->wst.ptr > 253, 0)) { + u->wst.error = 2; + goto error; + } +#endif + u->wst.ptr += 2; + } + break; + case 0x27: /* ROT2 */ + __asm__("evaluxn_27_ROT2:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2], c = u->wst.dat[u->wst.ptr - 3], d = u->wst.dat[u->wst.ptr - 4], e = u->wst.dat[u->wst.ptr - 5], f = u->wst.dat[u->wst.ptr - 6]; + u->wst.dat[u->wst.ptr - 6] = d; + u->wst.dat[u->wst.ptr - 5] = c; + u->wst.dat[u->wst.ptr - 4] = b; + u->wst.dat[u->wst.ptr - 3] = a; + u->wst.dat[u->wst.ptr - 2] = f; + u->wst.dat[u->wst.ptr - 1] = e; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 6, 0)) { + u->wst.error = 1; + goto error; + } +#endif + } + break; + case 0x28: /* EQU2 */ + __asm__("evaluxn_28_EQU2:"); + { + Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)), b = (u->wst.dat[u->wst.ptr - 3] | (u->wst.dat[u->wst.ptr - 4] << 8)); + u->wst.dat[u->wst.ptr - 4] = b == a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 4, 0)) { + u->wst.error = 1; + goto error; + } +#endif + u->wst.ptr -= 3; + } + break; + case 0x29: /* NEQ2 */ + __asm__("evaluxn_29_NEQ2:"); + { + Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)), b = (u->wst.dat[u->wst.ptr - 3] | (u->wst.dat[u->wst.ptr - 4] << 8)); + u->wst.dat[u->wst.ptr - 4] = b != a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 4, 0)) { + u->wst.error = 1; + goto error; + } +#endif + u->wst.ptr -= 3; + } + break; + case 0x2a: /* GTH2 */ + __asm__("evaluxn_2a_GTH2:"); + { + Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)), b = (u->wst.dat[u->wst.ptr - 3] | (u->wst.dat[u->wst.ptr - 4] << 8)); + u->wst.dat[u->wst.ptr - 4] = b > a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 4, 0)) { + u->wst.error = 1; + goto error; + } +#endif + u->wst.ptr -= 3; + } + break; + case 0x2b: /* LTH2 */ + __asm__("evaluxn_2b_LTH2:"); + { + Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)), b = (u->wst.dat[u->wst.ptr - 3] | (u->wst.dat[u->wst.ptr - 4] << 8)); + u->wst.dat[u->wst.ptr - 4] = b < a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 4, 0)) { + u->wst.error = 1; + goto error; + } +#endif + u->wst.ptr -= 3; + } + break; + case 0x2c: /* JMP2 */ + __asm__("evaluxn_2c_JMP2:"); + { + u->ram.ptr = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 2, 0)) { + u->wst.error = 1; + goto error; + } +#endif + u->wst.ptr -= 2; + } + break; + case 0x2d: /* JCN2 */ + __asm__("evaluxn_2d_JCN2:"); + { + Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)); + if(u->wst.dat[u->wst.ptr - 3]) u->ram.ptr = a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 3, 0)) { + u->wst.error = 1; + goto error; + } +#endif + u->wst.ptr -= 3; + } + break; + case 0x2e: /* JSR2 */ + __asm__("evaluxn_2e_JSR2:"); + { + u->rst.dat[u->rst.ptr] = u->ram.ptr >> 8; + u->rst.dat[u->rst.ptr + 1] = u->ram.ptr & 0xff; + u->ram.ptr = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 2, 0)) { + u->wst.error = 1; + goto error; + } +#endif + u->wst.ptr -= 2; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr > 253, 0)) { + u->rst.error = 2; + goto error; + } +#endif + u->rst.ptr += 2; + } + break; + case 0x2f: /* STH2 */ + __asm__("evaluxn_2f_STH2:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; + u->rst.dat[u->rst.ptr] = b; + u->rst.dat[u->rst.ptr + 1] = a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 2, 0)) { + u->wst.error = 1; + goto error; + } +#endif + u->wst.ptr -= 2; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr > 253, 0)) { + u->rst.error = 2; + goto error; + } +#endif + u->rst.ptr += 2; + } + break; + case 0x30: /* LDZ2 */ + __asm__("evaluxn_30_LDZ2:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1]; + u->wst.dat[u->wst.ptr - 1] = mempeek8(u->ram.dat, a); + u->wst.dat[u->wst.ptr] = mempeek8(u->ram.dat, a + 1); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 1, 0)) { + u->wst.error = 1; + goto error; + } + if(__builtin_expect(u->wst.ptr > 254, 0)) { + u->wst.error = 2; + goto error; + } +#endif + u->wst.ptr += 1; + } + break; + case 0x31: /* STZ2 */ + __asm__("evaluxn_31_STZ2:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1]; + Uint16 b = (u->wst.dat[u->wst.ptr - 2] | (u->wst.dat[u->wst.ptr - 3] << 8)); + mempoke16(u->ram.dat, a, b); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 3, 0)) { + u->wst.error = 1; + goto error; + } +#endif + u->wst.ptr -= 3; + } + break; + case 0x32: /* LDR2 */ + __asm__("evaluxn_32_LDR2:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1]; + u->wst.dat[u->wst.ptr - 1] = mempeek8(u->ram.dat, u->ram.ptr + (Sint8)a); + u->wst.dat[u->wst.ptr] = mempeek8(u->ram.dat, u->ram.ptr + (Sint8)a + 1); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 1, 0)) { + u->wst.error = 1; + goto error; + } + if(__builtin_expect(u->wst.ptr > 254, 0)) { + u->wst.error = 2; + goto error; + } +#endif + u->wst.ptr += 1; + } + break; + case 0x33: /* STR2 */ + __asm__("evaluxn_33_STR2:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1]; + Uint16 b = (u->wst.dat[u->wst.ptr - 2] | (u->wst.dat[u->wst.ptr - 3] << 8)); + mempoke16(u->ram.dat, u->ram.ptr + (Sint8)a, b); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 3, 0)) { + u->wst.error = 1; + goto error; + } +#endif + u->wst.ptr -= 3; + } + break; + case 0x34: /* LDA2 */ + __asm__("evaluxn_34_LDA2:"); + { + Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)); + u->wst.dat[u->wst.ptr - 2] = mempeek8(u->ram.dat, a); + u->wst.dat[u->wst.ptr - 1] = mempeek8(u->ram.dat, a + 1); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 2, 0)) { + u->wst.error = 1; + goto error; + } +#endif + } + break; + case 0x35: /* STA2 */ + __asm__("evaluxn_35_STA2:"); + { + Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)); + Uint16 b = (u->wst.dat[u->wst.ptr - 3] | (u->wst.dat[u->wst.ptr - 4] << 8)); + mempoke16(u->ram.dat, a, b); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 4, 0)) { + u->wst.error = 1; + goto error; + } +#endif + u->wst.ptr -= 4; + } + break; + case 0x36: /* DEI2 */ + __asm__("evaluxn_36_DEI2:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1]; + u->wst.dat[u->wst.ptr - 1] = devpeek8(&u->dev[a >> 4], a); + u->wst.dat[u->wst.ptr] = devpeek8(&u->dev[a >> 4], a + 1); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 1, 0)) { + u->wst.error = 1; + goto error; + } + if(__builtin_expect(u->wst.ptr > 254, 0)) { + u->wst.error = 2; + goto error; + } +#endif + u->wst.ptr += 1; + } + break; + case 0x37: /* DEO2 */ + __asm__("evaluxn_37_DEO2:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1]; + Uint16 b = (u->wst.dat[u->wst.ptr - 2] | (u->wst.dat[u->wst.ptr - 3] << 8)); + devpoke16(&u->dev[a >> 4], a, b); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 3, 0)) { + u->wst.error = 1; + goto error; + } +#endif + u->wst.ptr -= 3; + } + break; + case 0x38: /* ADD2 */ + __asm__("evaluxn_38_ADD2:"); + { + Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)), b = (u->wst.dat[u->wst.ptr - 3] | (u->wst.dat[u->wst.ptr - 4] << 8)); + u->wst.dat[u->wst.ptr - 4] = (b + a) >> 8; + u->wst.dat[u->wst.ptr - 3] = (b + a) & 0xff; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 4, 0)) { + u->wst.error = 1; + goto error; + } +#endif + u->wst.ptr -= 2; + } + break; + case 0x39: /* SUB2 */ + __asm__("evaluxn_39_SUB2:"); + { + Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)), b = (u->wst.dat[u->wst.ptr - 3] | (u->wst.dat[u->wst.ptr - 4] << 8)); + u->wst.dat[u->wst.ptr - 4] = (b - a) >> 8; + u->wst.dat[u->wst.ptr - 3] = (b - a) & 0xff; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 4, 0)) { + u->wst.error = 1; + goto error; + } +#endif + u->wst.ptr -= 2; + } + break; + case 0x3a: /* MUL2 */ + __asm__("evaluxn_3a_MUL2:"); + { + Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)), b = (u->wst.dat[u->wst.ptr - 3] | (u->wst.dat[u->wst.ptr - 4] << 8)); + u->wst.dat[u->wst.ptr - 4] = (b * a) >> 8; + u->wst.dat[u->wst.ptr - 3] = (b * a) & 0xff; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 4, 0)) { + u->wst.error = 1; + goto error; + } +#endif + u->wst.ptr -= 2; + } + break; + case 0x3b: /* DIV2 */ + __asm__("evaluxn_3b_DIV2:"); + { + Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)), b = (u->wst.dat[u->wst.ptr - 3] | (u->wst.dat[u->wst.ptr - 4] << 8)); + if(a == 0) { + u->wst.error = 3; +#ifndef NO_STACK_CHECKS + goto error; +#endif + a = 1; + } + u->wst.dat[u->wst.ptr - 4] = (b / a) >> 8; + u->wst.dat[u->wst.ptr - 3] = (b / a) & 0xff; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 4, 0)) { + u->wst.error = 1; + goto error; + } +#endif + u->wst.ptr -= 2; + } + break; + case 0x3c: /* AND2 */ + __asm__("evaluxn_3c_AND2:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2], c = u->wst.dat[u->wst.ptr - 3], d = u->wst.dat[u->wst.ptr - 4]; + u->wst.dat[u->wst.ptr - 4] = d & b; + u->wst.dat[u->wst.ptr - 3] = c & a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 4, 0)) { + u->wst.error = 1; + goto error; + } +#endif + u->wst.ptr -= 2; + } + break; + case 0x3d: /* ORA2 */ + __asm__("evaluxn_3d_ORA2:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2], c = u->wst.dat[u->wst.ptr - 3], d = u->wst.dat[u->wst.ptr - 4]; + u->wst.dat[u->wst.ptr - 4] = d | b; + u->wst.dat[u->wst.ptr - 3] = c | a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 4, 0)) { + u->wst.error = 1; + goto error; + } +#endif + u->wst.ptr -= 2; + } + break; + case 0x3e: /* EOR2 */ + __asm__("evaluxn_3e_EOR2:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2], c = u->wst.dat[u->wst.ptr - 3], d = u->wst.dat[u->wst.ptr - 4]; + u->wst.dat[u->wst.ptr - 4] = d ^ b; + u->wst.dat[u->wst.ptr - 3] = c ^ a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 4, 0)) { + u->wst.error = 1; + goto error; + } +#endif + u->wst.ptr -= 2; + } + break; + case 0x3f: /* SFT2 */ + __asm__("evaluxn_3f_SFT2:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1]; + Uint16 b = (u->wst.dat[u->wst.ptr - 2] | (u->wst.dat[u->wst.ptr - 3] << 8)); + u->wst.dat[u->wst.ptr - 3] = (b >> (a & 0x0f) << ((a & 0xf0) >> 4)) >> 8; + u->wst.dat[u->wst.ptr - 2] = (b >> (a & 0x0f) << ((a & 0xf0) >> 4)) & 0xff; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 3, 0)) { + u->wst.error = 1; + goto error; + } +#endif + u->wst.ptr -= 1; + } + break; + case 0x40: /* LITr */ + case 0xc0: /* LITkr */ + __asm__("evaluxn_40_LITr:"); + { + u->rst.dat[u->rst.ptr] = mempeek8(u->ram.dat, u->ram.ptr++); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr > 254, 0)) { + u->rst.error = 2; + goto error; + } +#endif + u->rst.ptr += 1; + } + break; + case 0x41: /* INCr */ + __asm__("evaluxn_41_INCr:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1]; + u->rst.dat[u->rst.ptr - 1] = a + 1; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 1, 0)) { + u->rst.error = 1; + goto error; + } +#endif + } + break; + case 0x42: /* POPr */ + __asm__("evaluxn_42_POPr:"); + { + u->rst.dat[u->rst.ptr - 1]; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 1, 0)) { + u->rst.error = 1; + goto error; + } +#endif + u->rst.ptr -= 1; + } + break; + case 0x43: /* DUPr */ + __asm__("evaluxn_43_DUPr:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1]; + u->rst.dat[u->rst.ptr] = a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 1, 0)) { + u->rst.error = 1; + goto error; + } + if(__builtin_expect(u->rst.ptr > 254, 0)) { + u->rst.error = 2; + goto error; + } +#endif + u->rst.ptr += 1; + } + break; + case 0x44: /* NIPr */ + __asm__("evaluxn_44_NIPr:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1]; + u->rst.dat[u->rst.ptr - 2]; + u->rst.dat[u->rst.ptr - 2] = a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 2, 0)) { + u->rst.error = 1; + goto error; + } +#endif + u->rst.ptr -= 1; + } + break; + case 0x45: /* SWPr */ + __asm__("evaluxn_45_SWPr:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; + u->rst.dat[u->rst.ptr - 2] = a; + u->rst.dat[u->rst.ptr - 1] = b; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 2, 0)) { + u->rst.error = 1; + goto error; + } +#endif + } + break; + case 0x46: /* OVRr */ + __asm__("evaluxn_46_OVRr:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; + u->rst.dat[u->rst.ptr] = b; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 2, 0)) { + u->rst.error = 1; + goto error; + } + if(__builtin_expect(u->rst.ptr > 254, 0)) { + u->rst.error = 2; + goto error; + } +#endif + u->rst.ptr += 1; + } + break; + case 0x47: /* ROTr */ + __asm__("evaluxn_47_ROTr:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2], c = u->rst.dat[u->rst.ptr - 3]; + u->rst.dat[u->rst.ptr - 3] = b; + u->rst.dat[u->rst.ptr - 2] = a; + u->rst.dat[u->rst.ptr - 1] = c; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 3, 0)) { + u->rst.error = 1; + goto error; + } +#endif + } + break; + case 0x48: /* EQUr */ + __asm__("evaluxn_48_EQUr:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; + u->rst.dat[u->rst.ptr - 2] = b == a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 2, 0)) { + u->rst.error = 1; + goto error; + } +#endif + u->rst.ptr -= 1; + } + break; + case 0x49: /* NEQr */ + __asm__("evaluxn_49_NEQr:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; + u->rst.dat[u->rst.ptr - 2] = b != a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 2, 0)) { + u->rst.error = 1; + goto error; + } +#endif + u->rst.ptr -= 1; + } + break; + case 0x4a: /* GTHr */ + __asm__("evaluxn_4a_GTHr:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; + u->rst.dat[u->rst.ptr - 2] = b > a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 2, 0)) { + u->rst.error = 1; + goto error; + } +#endif + u->rst.ptr -= 1; + } + break; + case 0x4b: /* LTHr */ + __asm__("evaluxn_4b_LTHr:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; + u->rst.dat[u->rst.ptr - 2] = b < a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 2, 0)) { + u->rst.error = 1; + goto error; + } +#endif + u->rst.ptr -= 1; + } + break; + case 0x4c: /* JMPr */ + __asm__("evaluxn_4c_JMPr:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1]; + u->ram.ptr += (Sint8)a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 1, 0)) { + u->rst.error = 1; + goto error; + } +#endif + u->rst.ptr -= 1; + } + break; + case 0x4d: /* JCNr */ + __asm__("evaluxn_4d_JCNr:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1]; + if(u->rst.dat[u->rst.ptr - 2]) u->ram.ptr += (Sint8)a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 2, 0)) { + u->rst.error = 1; + goto error; + } +#endif + u->rst.ptr -= 2; + } + break; + case 0x4e: /* JSRr */ + __asm__("evaluxn_4e_JSRr:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1]; + u->wst.dat[u->wst.ptr] = u->ram.ptr >> 8; + u->wst.dat[u->wst.ptr + 1] = u->ram.ptr & 0xff; + u->ram.ptr += (Sint8)a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 1, 0)) { + u->rst.error = 1; + goto error; + } +#endif + u->rst.ptr -= 1; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr > 253, 0)) { + u->wst.error = 2; + goto error; + } +#endif + u->wst.ptr += 2; + } + break; + case 0x4f: /* STHr */ + __asm__("evaluxn_4f_STHr:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1]; + u->wst.dat[u->wst.ptr] = a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 1, 0)) { + u->rst.error = 1; + goto error; + } +#endif + u->rst.ptr -= 1; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr > 254, 0)) { + u->wst.error = 2; + goto error; + } +#endif + u->wst.ptr += 1; + } + break; + case 0x50: /* LDZr */ + __asm__("evaluxn_50_LDZr:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1]; + u->rst.dat[u->rst.ptr - 1] = mempeek8(u->ram.dat, a); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 1, 0)) { + u->rst.error = 1; + goto error; + } +#endif + } + break; + case 0x51: /* STZr */ + __asm__("evaluxn_51_STZr:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1]; + Uint8 b = u->rst.dat[u->rst.ptr - 2]; + mempoke8(u->ram.dat, a, b); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 2, 0)) { + u->rst.error = 1; + goto error; + } +#endif + u->rst.ptr -= 2; + } + break; + case 0x52: /* LDRr */ + __asm__("evaluxn_52_LDRr:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1]; + u->rst.dat[u->rst.ptr - 1] = mempeek8(u->ram.dat, u->ram.ptr + (Sint8)a); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 1, 0)) { + u->rst.error = 1; + goto error; + } +#endif + } + break; + case 0x53: /* STRr */ + __asm__("evaluxn_53_STRr:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1]; + Uint8 b = u->rst.dat[u->rst.ptr - 2]; + mempoke8(u->ram.dat, u->ram.ptr + (Sint8)a, b); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 2, 0)) { + u->rst.error = 1; + goto error; + } +#endif + u->rst.ptr -= 2; + } + break; + case 0x54: /* LDAr */ + __asm__("evaluxn_54_LDAr:"); + { + Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)); + u->rst.dat[u->rst.ptr - 2] = mempeek8(u->ram.dat, a); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 2, 0)) { + u->rst.error = 1; + goto error; + } +#endif + u->rst.ptr -= 1; + } + break; + case 0x55: /* STAr */ + __asm__("evaluxn_55_STAr:"); + { + Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)); + Uint8 b = u->rst.dat[u->rst.ptr - 3]; + mempoke8(u->ram.dat, a, b); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 3, 0)) { + u->rst.error = 1; + goto error; + } +#endif + u->rst.ptr -= 3; + } + break; + case 0x56: /* DEIr */ + __asm__("evaluxn_56_DEIr:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1]; + u->rst.dat[u->rst.ptr - 1] = devpeek8(&u->dev[a >> 4], a); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 1, 0)) { + u->rst.error = 1; + goto error; + } +#endif + } + break; + case 0x57: /* DEOr */ + __asm__("evaluxn_57_DEOr:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; + devpoke8(&u->dev[a >> 4], a, b); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 2, 0)) { + u->rst.error = 1; + goto error; + } +#endif + u->rst.ptr -= 2; + } + break; + case 0x58: /* ADDr */ + __asm__("evaluxn_58_ADDr:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; + u->rst.dat[u->rst.ptr - 2] = b + a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 2, 0)) { + u->rst.error = 1; + goto error; + } +#endif + u->rst.ptr -= 1; + } + break; + case 0x59: /* SUBr */ + __asm__("evaluxn_59_SUBr:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; + u->rst.dat[u->rst.ptr - 2] = b - a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 2, 0)) { + u->rst.error = 1; + goto error; + } +#endif + u->rst.ptr -= 1; + } + break; + case 0x5a: /* MULr */ + __asm__("evaluxn_5a_MULr:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; + u->rst.dat[u->rst.ptr - 2] = b * a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 2, 0)) { + u->rst.error = 1; + goto error; + } +#endif + u->rst.ptr -= 1; + } + break; + case 0x5b: /* DIVr */ + __asm__("evaluxn_5b_DIVr:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; + if(a == 0) { + u->rst.error = 3; +#ifndef NO_STACK_CHECKS + goto error; +#endif + a = 1; + } + u->rst.dat[u->rst.ptr - 2] = b / a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 2, 0)) { + u->rst.error = 1; + goto error; + } +#endif + u->rst.ptr -= 1; + } + break; + case 0x5c: /* ANDr */ + __asm__("evaluxn_5c_ANDr:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; + u->rst.dat[u->rst.ptr - 2] = b & a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 2, 0)) { + u->rst.error = 1; + goto error; + } +#endif + u->rst.ptr -= 1; + } + break; + case 0x5d: /* ORAr */ + __asm__("evaluxn_5d_ORAr:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; + u->rst.dat[u->rst.ptr - 2] = b | a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 2, 0)) { + u->rst.error = 1; + goto error; + } +#endif + u->rst.ptr -= 1; + } + break; + case 0x5e: /* EORr */ + __asm__("evaluxn_5e_EORr:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; + u->rst.dat[u->rst.ptr - 2] = b ^ a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 2, 0)) { + u->rst.error = 1; + goto error; + } +#endif + u->rst.ptr -= 1; + } + break; + case 0x5f: /* SFTr */ + __asm__("evaluxn_5f_SFTr:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; + u->rst.dat[u->rst.ptr - 2] = b >> (a & 0x07) << ((a & 0x70) >> 4); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 2, 0)) { + u->rst.error = 1; + goto error; + } +#endif + u->rst.ptr -= 1; + } + break; + case 0x60: /* LIT2r */ + case 0xe0: /* LIT2kr */ + __asm__("evaluxn_60_LIT2r:"); + { + u->rst.dat[u->rst.ptr] = mempeek8(u->ram.dat, u->ram.ptr++); + u->rst.dat[u->rst.ptr + 1] = mempeek8(u->ram.dat, u->ram.ptr++); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr > 253, 0)) { + u->rst.error = 2; + goto error; + } +#endif + u->rst.ptr += 2; + } + break; + case 0x61: /* INC2r */ + __asm__("evaluxn_61_INC2r:"); + { + Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)); + u->rst.dat[u->rst.ptr - 2] = (a + 1) >> 8; + u->rst.dat[u->rst.ptr - 1] = (a + 1) & 0xff; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 2, 0)) { + u->rst.error = 1; + goto error; + } +#endif + } + break; + case 0x62: /* POP2r */ + __asm__("evaluxn_62_POP2r:"); + { + (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 2, 0)) { + u->rst.error = 1; + goto error; + } +#endif + u->rst.ptr -= 2; + } + break; + case 0x63: /* DUP2r */ + __asm__("evaluxn_63_DUP2r:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; + u->rst.dat[u->rst.ptr] = b; + u->rst.dat[u->rst.ptr + 1] = a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 2, 0)) { + u->rst.error = 1; + goto error; + } + if(__builtin_expect(u->rst.ptr > 253, 0)) { + u->rst.error = 2; + goto error; + } +#endif + u->rst.ptr += 2; + } + break; + case 0x64: /* NIP2r */ + __asm__("evaluxn_64_NIP2r:"); + { + Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)); + (u->rst.dat[u->rst.ptr - 3] | (u->rst.dat[u->rst.ptr - 4] << 8)); + u->rst.dat[u->rst.ptr - 4] = a >> 8; + u->rst.dat[u->rst.ptr - 3] = a & 0xff; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 4, 0)) { + u->rst.error = 1; + goto error; + } +#endif + u->rst.ptr -= 2; + } + break; + case 0x65: /* SWP2r */ + __asm__("evaluxn_65_SWP2r:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2], c = u->rst.dat[u->rst.ptr - 3], d = u->rst.dat[u->rst.ptr - 4]; + u->rst.dat[u->rst.ptr - 4] = b; + u->rst.dat[u->rst.ptr - 3] = a; + u->rst.dat[u->rst.ptr - 2] = d; + u->rst.dat[u->rst.ptr - 1] = c; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 4, 0)) { + u->rst.error = 1; + goto error; + } +#endif + } + break; + case 0x66: /* OVR2r */ + __asm__("evaluxn_66_OVR2r:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2], c = u->rst.dat[u->rst.ptr - 3], d = u->rst.dat[u->rst.ptr - 4]; + u->rst.dat[u->rst.ptr] = d; + u->rst.dat[u->rst.ptr + 1] = c; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 4, 0)) { + u->rst.error = 1; + goto error; + } + if(__builtin_expect(u->rst.ptr > 253, 0)) { + u->rst.error = 2; + goto error; + } +#endif + u->rst.ptr += 2; + } + break; + case 0x67: /* ROT2r */ + __asm__("evaluxn_67_ROT2r:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2], c = u->rst.dat[u->rst.ptr - 3], d = u->rst.dat[u->rst.ptr - 4], e = u->rst.dat[u->rst.ptr - 5], f = u->rst.dat[u->rst.ptr - 6]; + u->rst.dat[u->rst.ptr - 6] = d; + u->rst.dat[u->rst.ptr - 5] = c; + u->rst.dat[u->rst.ptr - 4] = b; + u->rst.dat[u->rst.ptr - 3] = a; + u->rst.dat[u->rst.ptr - 2] = f; + u->rst.dat[u->rst.ptr - 1] = e; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 6, 0)) { + u->rst.error = 1; + goto error; + } +#endif + } + break; + case 0x68: /* EQU2r */ + __asm__("evaluxn_68_EQU2r:"); + { + Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)), b = (u->rst.dat[u->rst.ptr - 3] | (u->rst.dat[u->rst.ptr - 4] << 8)); + u->rst.dat[u->rst.ptr - 4] = b == a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 4, 0)) { + u->rst.error = 1; + goto error; + } +#endif + u->rst.ptr -= 3; + } + break; + case 0x69: /* NEQ2r */ + __asm__("evaluxn_69_NEQ2r:"); + { + Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)), b = (u->rst.dat[u->rst.ptr - 3] | (u->rst.dat[u->rst.ptr - 4] << 8)); + u->rst.dat[u->rst.ptr - 4] = b != a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 4, 0)) { + u->rst.error = 1; + goto error; + } +#endif + u->rst.ptr -= 3; + } + break; + case 0x6a: /* GTH2r */ + __asm__("evaluxn_6a_GTH2r:"); + { + Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)), b = (u->rst.dat[u->rst.ptr - 3] | (u->rst.dat[u->rst.ptr - 4] << 8)); + u->rst.dat[u->rst.ptr - 4] = b > a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 4, 0)) { + u->rst.error = 1; + goto error; + } +#endif + u->rst.ptr -= 3; + } + break; + case 0x6b: /* LTH2r */ + __asm__("evaluxn_6b_LTH2r:"); + { + Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)), b = (u->rst.dat[u->rst.ptr - 3] | (u->rst.dat[u->rst.ptr - 4] << 8)); + u->rst.dat[u->rst.ptr - 4] = b < a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 4, 0)) { + u->rst.error = 1; + goto error; + } +#endif + u->rst.ptr -= 3; + } + break; + case 0x6c: /* JMP2r */ + __asm__("evaluxn_6c_JMP2r:"); + { + u->ram.ptr = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 2, 0)) { + u->rst.error = 1; + goto error; + } +#endif + u->rst.ptr -= 2; + } + break; + case 0x6d: /* JCN2r */ + __asm__("evaluxn_6d_JCN2r:"); + { + Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)); + if(u->rst.dat[u->rst.ptr - 3]) u->ram.ptr = a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 3, 0)) { + u->rst.error = 1; + goto error; + } +#endif + u->rst.ptr -= 3; + } + break; + case 0x6e: /* JSR2r */ + __asm__("evaluxn_6e_JSR2r:"); + { + u->wst.dat[u->wst.ptr] = u->ram.ptr >> 8; + u->wst.dat[u->wst.ptr + 1] = u->ram.ptr & 0xff; + u->ram.ptr = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 2, 0)) { + u->rst.error = 1; + goto error; + } +#endif + u->rst.ptr -= 2; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr > 253, 0)) { + u->wst.error = 2; + goto error; + } +#endif + u->wst.ptr += 2; + } + break; + case 0x6f: /* STH2r */ + __asm__("evaluxn_6f_STH2r:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; + u->wst.dat[u->wst.ptr] = b; + u->wst.dat[u->wst.ptr + 1] = a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 2, 0)) { + u->rst.error = 1; + goto error; + } +#endif + u->rst.ptr -= 2; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr > 253, 0)) { + u->wst.error = 2; + goto error; + } +#endif + u->wst.ptr += 2; + } + break; + case 0x70: /* LDZ2r */ + __asm__("evaluxn_70_LDZ2r:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1]; + u->rst.dat[u->rst.ptr - 1] = mempeek8(u->ram.dat, a); + u->rst.dat[u->rst.ptr] = mempeek8(u->ram.dat, a + 1); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 1, 0)) { + u->rst.error = 1; + goto error; + } + if(__builtin_expect(u->rst.ptr > 254, 0)) { + u->rst.error = 2; + goto error; + } +#endif + u->rst.ptr += 1; + } + break; + case 0x71: /* STZ2r */ + __asm__("evaluxn_71_STZ2r:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1]; + Uint16 b = (u->rst.dat[u->rst.ptr - 2] | (u->rst.dat[u->rst.ptr - 3] << 8)); + mempoke16(u->ram.dat, a, b); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 3, 0)) { + u->rst.error = 1; + goto error; + } +#endif + u->rst.ptr -= 3; + } + break; + case 0x72: /* LDR2r */ + __asm__("evaluxn_72_LDR2r:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1]; + u->rst.dat[u->rst.ptr - 1] = mempeek8(u->ram.dat, u->ram.ptr + (Sint8)a); + u->rst.dat[u->rst.ptr] = mempeek8(u->ram.dat, u->ram.ptr + (Sint8)a + 1); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 1, 0)) { + u->rst.error = 1; + goto error; + } + if(__builtin_expect(u->rst.ptr > 254, 0)) { + u->rst.error = 2; + goto error; + } +#endif + u->rst.ptr += 1; + } + break; + case 0x73: /* STR2r */ + __asm__("evaluxn_73_STR2r:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1]; + Uint16 b = (u->rst.dat[u->rst.ptr - 2] | (u->rst.dat[u->rst.ptr - 3] << 8)); + mempoke16(u->ram.dat, u->ram.ptr + (Sint8)a, b); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 3, 0)) { + u->rst.error = 1; + goto error; + } +#endif + u->rst.ptr -= 3; + } + break; + case 0x74: /* LDA2r */ + __asm__("evaluxn_74_LDA2r:"); + { + Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)); + u->rst.dat[u->rst.ptr - 2] = mempeek8(u->ram.dat, a); + u->rst.dat[u->rst.ptr - 1] = mempeek8(u->ram.dat, a + 1); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 2, 0)) { + u->rst.error = 1; + goto error; + } +#endif + } + break; + case 0x75: /* STA2r */ + __asm__("evaluxn_75_STA2r:"); + { + Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)); + Uint16 b = (u->rst.dat[u->rst.ptr - 3] | (u->rst.dat[u->rst.ptr - 4] << 8)); + mempoke16(u->ram.dat, a, b); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 4, 0)) { + u->rst.error = 1; + goto error; + } +#endif + u->rst.ptr -= 4; + } + break; + case 0x76: /* DEI2r */ + __asm__("evaluxn_76_DEI2r:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1]; + u->rst.dat[u->rst.ptr - 1] = devpeek8(&u->dev[a >> 4], a); + u->rst.dat[u->rst.ptr] = devpeek8(&u->dev[a >> 4], a + 1); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 1, 0)) { + u->rst.error = 1; + goto error; + } + if(__builtin_expect(u->rst.ptr > 254, 0)) { + u->rst.error = 2; + goto error; + } +#endif + u->rst.ptr += 1; + } + break; + case 0x77: /* DEO2r */ + __asm__("evaluxn_77_DEO2r:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1]; + Uint16 b = (u->rst.dat[u->rst.ptr - 2] | (u->rst.dat[u->rst.ptr - 3] << 8)); + devpoke16(&u->dev[a >> 4], a, b); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 3, 0)) { + u->rst.error = 1; + goto error; + } +#endif + u->rst.ptr -= 3; + } + break; + case 0x78: /* ADD2r */ + __asm__("evaluxn_78_ADD2r:"); + { + Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)), b = (u->rst.dat[u->rst.ptr - 3] | (u->rst.dat[u->rst.ptr - 4] << 8)); + u->rst.dat[u->rst.ptr - 4] = (b + a) >> 8; + u->rst.dat[u->rst.ptr - 3] = (b + a) & 0xff; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 4, 0)) { + u->rst.error = 1; + goto error; + } +#endif + u->rst.ptr -= 2; + } + break; + case 0x79: /* SUB2r */ + __asm__("evaluxn_79_SUB2r:"); + { + Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)), b = (u->rst.dat[u->rst.ptr - 3] | (u->rst.dat[u->rst.ptr - 4] << 8)); + u->rst.dat[u->rst.ptr - 4] = (b - a) >> 8; + u->rst.dat[u->rst.ptr - 3] = (b - a) & 0xff; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 4, 0)) { + u->rst.error = 1; + goto error; + } +#endif + u->rst.ptr -= 2; + } + break; + case 0x7a: /* MUL2r */ + __asm__("evaluxn_7a_MUL2r:"); + { + Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)), b = (u->rst.dat[u->rst.ptr - 3] | (u->rst.dat[u->rst.ptr - 4] << 8)); + u->rst.dat[u->rst.ptr - 4] = (b * a) >> 8; + u->rst.dat[u->rst.ptr - 3] = (b * a) & 0xff; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 4, 0)) { + u->rst.error = 1; + goto error; + } +#endif + u->rst.ptr -= 2; + } + break; + case 0x7b: /* DIV2r */ + __asm__("evaluxn_7b_DIV2r:"); + { + Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)), b = (u->rst.dat[u->rst.ptr - 3] | (u->rst.dat[u->rst.ptr - 4] << 8)); + if(a == 0) { + u->rst.error = 3; +#ifndef NO_STACK_CHECKS + goto error; +#endif + a = 1; + } + u->rst.dat[u->rst.ptr - 4] = (b / a) >> 8; + u->rst.dat[u->rst.ptr - 3] = (b / a) & 0xff; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 4, 0)) { + u->rst.error = 1; + goto error; + } +#endif + u->rst.ptr -= 2; + } + break; + case 0x7c: /* AND2r */ + __asm__("evaluxn_7c_AND2r:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2], c = u->rst.dat[u->rst.ptr - 3], d = u->rst.dat[u->rst.ptr - 4]; + u->rst.dat[u->rst.ptr - 4] = d & b; + u->rst.dat[u->rst.ptr - 3] = c & a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 4, 0)) { + u->rst.error = 1; + goto error; + } +#endif + u->rst.ptr -= 2; + } + break; + case 0x7d: /* ORA2r */ + __asm__("evaluxn_7d_ORA2r:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2], c = u->rst.dat[u->rst.ptr - 3], d = u->rst.dat[u->rst.ptr - 4]; + u->rst.dat[u->rst.ptr - 4] = d | b; + u->rst.dat[u->rst.ptr - 3] = c | a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 4, 0)) { + u->rst.error = 1; + goto error; + } +#endif + u->rst.ptr -= 2; + } + break; + case 0x7e: /* EOR2r */ + __asm__("evaluxn_7e_EOR2r:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2], c = u->rst.dat[u->rst.ptr - 3], d = u->rst.dat[u->rst.ptr - 4]; + u->rst.dat[u->rst.ptr - 4] = d ^ b; + u->rst.dat[u->rst.ptr - 3] = c ^ a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 4, 0)) { + u->rst.error = 1; + goto error; + } +#endif + u->rst.ptr -= 2; + } + break; + case 0x7f: /* SFT2r */ + __asm__("evaluxn_7f_SFT2r:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1]; + Uint16 b = (u->rst.dat[u->rst.ptr - 2] | (u->rst.dat[u->rst.ptr - 3] << 8)); + u->rst.dat[u->rst.ptr - 3] = (b >> (a & 0x0f) << ((a & 0xf0) >> 4)) >> 8; + u->rst.dat[u->rst.ptr - 2] = (b >> (a & 0x0f) << ((a & 0xf0) >> 4)) & 0xff; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 3, 0)) { + u->rst.error = 1; + goto error; + } +#endif + u->rst.ptr -= 1; + } + break; + case 0x81: /* INCk */ + __asm__("evaluxn_81_INCk:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1]; + u->wst.dat[u->wst.ptr] = a + 1; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 1, 0)) { + u->wst.error = 1; + goto error; + } + if(__builtin_expect(u->wst.ptr > 254, 0)) { + u->wst.error = 2; + goto error; + } +#endif + u->wst.ptr += 1; + } + break; + case 0x82: /* POPk */ + __asm__("evaluxn_82_POPk:"); + { + u->wst.dat[u->wst.ptr - 1]; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 1, 0)) { + u->wst.error = 1; + goto error; + } +#endif + } + break; + case 0x83: /* DUPk */ + __asm__("evaluxn_83_DUPk:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1]; + u->wst.dat[u->wst.ptr] = a; + u->wst.dat[u->wst.ptr + 1] = a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 1, 0)) { + u->wst.error = 1; + goto error; + } + if(__builtin_expect(u->wst.ptr > 253, 0)) { + u->wst.error = 2; + goto error; + } +#endif + u->wst.ptr += 2; + } + break; + case 0x84: /* NIPk */ + __asm__("evaluxn_84_NIPk:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1]; + u->wst.dat[u->wst.ptr - 2]; + u->wst.dat[u->wst.ptr] = a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 2, 0)) { + u->wst.error = 1; + goto error; + } + if(__builtin_expect(u->wst.ptr > 254, 0)) { + u->wst.error = 2; + goto error; + } +#endif + u->wst.ptr += 1; + } + break; + case 0x85: /* SWPk */ + __asm__("evaluxn_85_SWPk:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; + u->wst.dat[u->wst.ptr] = a; + u->wst.dat[u->wst.ptr + 1] = b; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 2, 0)) { + u->wst.error = 1; + goto error; + } + if(__builtin_expect(u->wst.ptr > 253, 0)) { + u->wst.error = 2; + goto error; + } +#endif + u->wst.ptr += 2; + } + break; + case 0x86: /* OVRk */ + __asm__("evaluxn_86_OVRk:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; + u->wst.dat[u->wst.ptr] = b; + u->wst.dat[u->wst.ptr + 1] = a; + u->wst.dat[u->wst.ptr + 2] = b; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 2, 0)) { + u->wst.error = 1; + goto error; + } + if(__builtin_expect(u->wst.ptr > 252, 0)) { + u->wst.error = 2; + goto error; + } +#endif + u->wst.ptr += 3; + } + break; + case 0x87: /* ROTk */ + __asm__("evaluxn_87_ROTk:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2], c = u->wst.dat[u->wst.ptr - 3]; + u->wst.dat[u->wst.ptr] = b; + u->wst.dat[u->wst.ptr + 1] = a; + u->wst.dat[u->wst.ptr + 2] = c; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 3, 0)) { + u->wst.error = 1; + goto error; + } + if(__builtin_expect(u->wst.ptr > 252, 0)) { + u->wst.error = 2; + goto error; + } +#endif + u->wst.ptr += 3; + } + break; + case 0x88: /* EQUk */ + __asm__("evaluxn_88_EQUk:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; + u->wst.dat[u->wst.ptr] = b == a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 2, 0)) { + u->wst.error = 1; + goto error; + } + if(__builtin_expect(u->wst.ptr > 254, 0)) { + u->wst.error = 2; + goto error; + } +#endif + u->wst.ptr += 1; + } + break; + case 0x89: /* NEQk */ + __asm__("evaluxn_89_NEQk:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; + u->wst.dat[u->wst.ptr] = b != a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 2, 0)) { + u->wst.error = 1; + goto error; + } + if(__builtin_expect(u->wst.ptr > 254, 0)) { + u->wst.error = 2; + goto error; + } +#endif + u->wst.ptr += 1; + } + break; + case 0x8a: /* GTHk */ + __asm__("evaluxn_8a_GTHk:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; + u->wst.dat[u->wst.ptr] = b > a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 2, 0)) { + u->wst.error = 1; + goto error; + } + if(__builtin_expect(u->wst.ptr > 254, 0)) { + u->wst.error = 2; + goto error; + } +#endif + u->wst.ptr += 1; + } + break; + case 0x8b: /* LTHk */ + __asm__("evaluxn_8b_LTHk:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; + u->wst.dat[u->wst.ptr] = b < a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 2, 0)) { + u->wst.error = 1; + goto error; + } + if(__builtin_expect(u->wst.ptr > 254, 0)) { + u->wst.error = 2; + goto error; + } +#endif + u->wst.ptr += 1; + } + break; + case 0x8c: /* JMPk */ + __asm__("evaluxn_8c_JMPk:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1]; + u->ram.ptr += (Sint8)a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 1, 0)) { + u->wst.error = 1; + goto error; + } +#endif + } + break; + case 0x8d: /* JCNk */ + __asm__("evaluxn_8d_JCNk:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1]; + if(u->wst.dat[u->wst.ptr - 2]) u->ram.ptr += (Sint8)a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 2, 0)) { + u->wst.error = 1; + goto error; + } +#endif + } + break; + case 0x8e: /* JSRk */ + __asm__("evaluxn_8e_JSRk:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1]; + u->rst.dat[u->rst.ptr] = u->ram.ptr >> 8; + u->rst.dat[u->rst.ptr + 1] = u->ram.ptr & 0xff; + u->ram.ptr += (Sint8)a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 1, 0)) { + u->wst.error = 1; + goto error; + } + if(__builtin_expect(u->rst.ptr > 253, 0)) { + u->rst.error = 2; + goto error; + } +#endif + u->rst.ptr += 2; + } + break; + case 0x8f: /* STHk */ + __asm__("evaluxn_8f_STHk:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1]; + u->rst.dat[u->rst.ptr] = a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 1, 0)) { + u->wst.error = 1; + goto error; + } + if(__builtin_expect(u->rst.ptr > 254, 0)) { + u->rst.error = 2; + goto error; + } +#endif + u->rst.ptr += 1; + } + break; + case 0x90: /* LDZk */ + __asm__("evaluxn_90_LDZk:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1]; + u->wst.dat[u->wst.ptr] = mempeek8(u->ram.dat, a); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 1, 0)) { + u->wst.error = 1; + goto error; + } + if(__builtin_expect(u->wst.ptr > 254, 0)) { + u->wst.error = 2; + goto error; + } +#endif + u->wst.ptr += 1; + } + break; + case 0x91: /* STZk */ + __asm__("evaluxn_91_STZk:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1]; + Uint8 b = u->wst.dat[u->wst.ptr - 2]; + mempoke8(u->ram.dat, a, b); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 2, 0)) { + u->wst.error = 1; + goto error; + } +#endif + } + break; + case 0x92: /* LDRk */ + __asm__("evaluxn_92_LDRk:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1]; + u->wst.dat[u->wst.ptr] = mempeek8(u->ram.dat, u->ram.ptr + (Sint8)a); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 1, 0)) { + u->wst.error = 1; + goto error; + } + if(__builtin_expect(u->wst.ptr > 254, 0)) { + u->wst.error = 2; + goto error; + } +#endif + u->wst.ptr += 1; + } + break; + case 0x93: /* STRk */ + __asm__("evaluxn_93_STRk:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1]; + Uint8 b = u->wst.dat[u->wst.ptr - 2]; + mempoke8(u->ram.dat, u->ram.ptr + (Sint8)a, b); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 2, 0)) { + u->wst.error = 1; + goto error; + } +#endif + } + break; + case 0x94: /* LDAk */ + __asm__("evaluxn_94_LDAk:"); + { + Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)); + u->wst.dat[u->wst.ptr] = mempeek8(u->ram.dat, a); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 2, 0)) { + u->wst.error = 1; + goto error; + } + if(__builtin_expect(u->wst.ptr > 254, 0)) { + u->wst.error = 2; + goto error; + } +#endif + u->wst.ptr += 1; + } + break; + case 0x95: /* STAk */ + __asm__("evaluxn_95_STAk:"); + { + Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)); + Uint8 b = u->wst.dat[u->wst.ptr - 3]; + mempoke8(u->ram.dat, a, b); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 3, 0)) { + u->wst.error = 1; + goto error; + } +#endif + } + break; + case 0x96: /* DEIk */ + __asm__("evaluxn_96_DEIk:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1]; + u->wst.dat[u->wst.ptr] = devpeek8(&u->dev[a >> 4], a); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 1, 0)) { + u->wst.error = 1; + goto error; + } + if(__builtin_expect(u->wst.ptr > 254, 0)) { + u->wst.error = 2; + goto error; + } +#endif + u->wst.ptr += 1; + } + break; + case 0x97: /* DEOk */ + __asm__("evaluxn_97_DEOk:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; + devpoke8(&u->dev[a >> 4], a, b); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 2, 0)) { + u->wst.error = 1; + goto error; + } +#endif + } + break; + case 0x98: /* ADDk */ + __asm__("evaluxn_98_ADDk:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; + u->wst.dat[u->wst.ptr] = b + a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 2, 0)) { + u->wst.error = 1; + goto error; + } + if(__builtin_expect(u->wst.ptr > 254, 0)) { + u->wst.error = 2; + goto error; + } +#endif + u->wst.ptr += 1; + } + break; + case 0x99: /* SUBk */ + __asm__("evaluxn_99_SUBk:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; + u->wst.dat[u->wst.ptr] = b - a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 2, 0)) { + u->wst.error = 1; + goto error; + } + if(__builtin_expect(u->wst.ptr > 254, 0)) { + u->wst.error = 2; + goto error; + } +#endif + u->wst.ptr += 1; + } + break; + case 0x9a: /* MULk */ + __asm__("evaluxn_9a_MULk:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; + u->wst.dat[u->wst.ptr] = b * a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 2, 0)) { + u->wst.error = 1; + goto error; + } + if(__builtin_expect(u->wst.ptr > 254, 0)) { + u->wst.error = 2; + goto error; + } +#endif + u->wst.ptr += 1; + } + break; + case 0x9b: /* DIVk */ + __asm__("evaluxn_9b_DIVk:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; + if(a == 0) { + u->wst.error = 3; +#ifndef NO_STACK_CHECKS + goto error; +#endif + a = 1; + } + u->wst.dat[u->wst.ptr] = b / a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 2, 0)) { + u->wst.error = 1; + goto error; + } + if(__builtin_expect(u->wst.ptr > 254, 0)) { + u->wst.error = 2; + goto error; + } +#endif + u->wst.ptr += 1; + } + break; + case 0x9c: /* ANDk */ + __asm__("evaluxn_9c_ANDk:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; + u->wst.dat[u->wst.ptr] = b & a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 2, 0)) { + u->wst.error = 1; + goto error; + } + if(__builtin_expect(u->wst.ptr > 254, 0)) { + u->wst.error = 2; + goto error; + } +#endif + u->wst.ptr += 1; + } + break; + case 0x9d: /* ORAk */ + __asm__("evaluxn_9d_ORAk:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; + u->wst.dat[u->wst.ptr] = b | a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 2, 0)) { + u->wst.error = 1; + goto error; + } + if(__builtin_expect(u->wst.ptr > 254, 0)) { + u->wst.error = 2; + goto error; + } +#endif + u->wst.ptr += 1; + } + break; + case 0x9e: /* EORk */ + __asm__("evaluxn_9e_EORk:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; + u->wst.dat[u->wst.ptr] = b ^ a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 2, 0)) { + u->wst.error = 1; + goto error; + } + if(__builtin_expect(u->wst.ptr > 254, 0)) { + u->wst.error = 2; + goto error; + } +#endif + u->wst.ptr += 1; + } + break; + case 0x9f: /* SFTk */ + __asm__("evaluxn_9f_SFTk:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; + u->wst.dat[u->wst.ptr] = b >> (a & 0x07) << ((a & 0x70) >> 4); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 2, 0)) { + u->wst.error = 1; + goto error; + } + if(__builtin_expect(u->wst.ptr > 254, 0)) { + u->wst.error = 2; + goto error; + } +#endif + u->wst.ptr += 1; + } + break; + case 0xa1: /* INC2k */ + __asm__("evaluxn_a1_INC2k:"); + { + Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)); + u->wst.dat[u->wst.ptr] = (a + 1) >> 8; + u->wst.dat[u->wst.ptr + 1] = (a + 1) & 0xff; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 2, 0)) { + u->wst.error = 1; + goto error; + } + if(__builtin_expect(u->wst.ptr > 253, 0)) { + u->wst.error = 2; + goto error; + } +#endif + u->wst.ptr += 2; + } + break; + case 0xa2: /* POP2k */ + __asm__("evaluxn_a2_POP2k:"); + { + (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 2, 0)) { + u->wst.error = 1; + goto error; + } +#endif + } + break; + case 0xa3: /* DUP2k */ + __asm__("evaluxn_a3_DUP2k:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; + u->wst.dat[u->wst.ptr] = b; + u->wst.dat[u->wst.ptr + 1] = a; + u->wst.dat[u->wst.ptr + 2] = b; + u->wst.dat[u->wst.ptr + 3] = a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 2, 0)) { + u->wst.error = 1; + goto error; + } + if(__builtin_expect(u->wst.ptr > 251, 0)) { + u->wst.error = 2; + goto error; + } +#endif + u->wst.ptr += 4; + } + break; + case 0xa4: /* NIP2k */ + __asm__("evaluxn_a4_NIP2k:"); + { + Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)); + (u->wst.dat[u->wst.ptr - 3] | (u->wst.dat[u->wst.ptr - 4] << 8)); + u->wst.dat[u->wst.ptr] = a >> 8; + u->wst.dat[u->wst.ptr + 1] = a & 0xff; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 4, 0)) { + u->wst.error = 1; + goto error; + } + if(__builtin_expect(u->wst.ptr > 253, 0)) { + u->wst.error = 2; + goto error; + } +#endif + u->wst.ptr += 2; + } + break; + case 0xa5: /* SWP2k */ + __asm__("evaluxn_a5_SWP2k:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2], c = u->wst.dat[u->wst.ptr - 3], d = u->wst.dat[u->wst.ptr - 4]; + u->wst.dat[u->wst.ptr] = b; + u->wst.dat[u->wst.ptr + 1] = a; + u->wst.dat[u->wst.ptr + 2] = d; + u->wst.dat[u->wst.ptr + 3] = c; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 4, 0)) { + u->wst.error = 1; + goto error; + } + if(__builtin_expect(u->wst.ptr > 251, 0)) { + u->wst.error = 2; + goto error; + } +#endif + u->wst.ptr += 4; + } + break; + case 0xa6: /* OVR2k */ + __asm__("evaluxn_a6_OVR2k:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2], c = u->wst.dat[u->wst.ptr - 3], d = u->wst.dat[u->wst.ptr - 4]; + u->wst.dat[u->wst.ptr] = d; + u->wst.dat[u->wst.ptr + 1] = c; + u->wst.dat[u->wst.ptr + 2] = b; + u->wst.dat[u->wst.ptr + 3] = a; + u->wst.dat[u->wst.ptr + 4] = d; + u->wst.dat[u->wst.ptr + 5] = c; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 4, 0)) { + u->wst.error = 1; + goto error; + } + if(__builtin_expect(u->wst.ptr > 249, 0)) { + u->wst.error = 2; + goto error; + } +#endif + u->wst.ptr += 6; + } + break; + case 0xa7: /* ROT2k */ + __asm__("evaluxn_a7_ROT2k:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2], c = u->wst.dat[u->wst.ptr - 3], d = u->wst.dat[u->wst.ptr - 4], e = u->wst.dat[u->wst.ptr - 5], f = u->wst.dat[u->wst.ptr - 6]; + u->wst.dat[u->wst.ptr] = d; + u->wst.dat[u->wst.ptr + 1] = c; + u->wst.dat[u->wst.ptr + 2] = b; + u->wst.dat[u->wst.ptr + 3] = a; + u->wst.dat[u->wst.ptr + 4] = f; + u->wst.dat[u->wst.ptr + 5] = e; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 6, 0)) { + u->wst.error = 1; + goto error; + } + if(__builtin_expect(u->wst.ptr > 249, 0)) { + u->wst.error = 2; + goto error; + } +#endif + u->wst.ptr += 6; + } + break; + case 0xa8: /* EQU2k */ + __asm__("evaluxn_a8_EQU2k:"); + { + Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)), b = (u->wst.dat[u->wst.ptr - 3] | (u->wst.dat[u->wst.ptr - 4] << 8)); + u->wst.dat[u->wst.ptr] = b == a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 4, 0)) { + u->wst.error = 1; + goto error; + } + if(__builtin_expect(u->wst.ptr > 254, 0)) { + u->wst.error = 2; + goto error; + } +#endif + u->wst.ptr += 1; + } + break; + case 0xa9: /* NEQ2k */ + __asm__("evaluxn_a9_NEQ2k:"); + { + Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)), b = (u->wst.dat[u->wst.ptr - 3] | (u->wst.dat[u->wst.ptr - 4] << 8)); + u->wst.dat[u->wst.ptr] = b != a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 4, 0)) { + u->wst.error = 1; + goto error; + } + if(__builtin_expect(u->wst.ptr > 254, 0)) { + u->wst.error = 2; + goto error; + } +#endif + u->wst.ptr += 1; + } + break; + case 0xaa: /* GTH2k */ + __asm__("evaluxn_aa_GTH2k:"); + { + Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)), b = (u->wst.dat[u->wst.ptr - 3] | (u->wst.dat[u->wst.ptr - 4] << 8)); + u->wst.dat[u->wst.ptr] = b > a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 4, 0)) { + u->wst.error = 1; + goto error; + } + if(__builtin_expect(u->wst.ptr > 254, 0)) { + u->wst.error = 2; + goto error; + } +#endif + u->wst.ptr += 1; + } + break; + case 0xab: /* LTH2k */ + __asm__("evaluxn_ab_LTH2k:"); + { + Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)), b = (u->wst.dat[u->wst.ptr - 3] | (u->wst.dat[u->wst.ptr - 4] << 8)); + u->wst.dat[u->wst.ptr] = b < a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 4, 0)) { + u->wst.error = 1; + goto error; + } + if(__builtin_expect(u->wst.ptr > 254, 0)) { + u->wst.error = 2; + goto error; + } +#endif + u->wst.ptr += 1; + } + break; + case 0xac: /* JMP2k */ + __asm__("evaluxn_ac_JMP2k:"); + { + u->ram.ptr = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 2, 0)) { + u->wst.error = 1; + goto error; + } +#endif + } + break; + case 0xad: /* JCN2k */ + __asm__("evaluxn_ad_JCN2k:"); + { + Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)); + if(u->wst.dat[u->wst.ptr - 3]) u->ram.ptr = a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 3, 0)) { + u->wst.error = 1; + goto error; + } +#endif + } + break; + case 0xae: /* JSR2k */ + __asm__("evaluxn_ae_JSR2k:"); + { + u->rst.dat[u->rst.ptr] = u->ram.ptr >> 8; + u->rst.dat[u->rst.ptr + 1] = u->ram.ptr & 0xff; + u->ram.ptr = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 2, 0)) { + u->wst.error = 1; + goto error; + } + if(__builtin_expect(u->rst.ptr > 253, 0)) { + u->rst.error = 2; + goto error; + } +#endif + u->rst.ptr += 2; + } + break; + case 0xaf: /* STH2k */ + __asm__("evaluxn_af_STH2k:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; + u->rst.dat[u->rst.ptr] = b; + u->rst.dat[u->rst.ptr + 1] = a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 2, 0)) { + u->wst.error = 1; + goto error; + } + if(__builtin_expect(u->rst.ptr > 253, 0)) { + u->rst.error = 2; + goto error; + } +#endif + u->rst.ptr += 2; + } + break; + case 0xb0: /* LDZ2k */ + __asm__("evaluxn_b0_LDZ2k:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1]; + u->wst.dat[u->wst.ptr] = mempeek8(u->ram.dat, a); + u->wst.dat[u->wst.ptr + 1] = mempeek8(u->ram.dat, a + 1); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 1, 0)) { + u->wst.error = 1; + goto error; + } + if(__builtin_expect(u->wst.ptr > 253, 0)) { + u->wst.error = 2; + goto error; + } +#endif + u->wst.ptr += 2; + } + break; + case 0xb1: /* STZ2k */ + __asm__("evaluxn_b1_STZ2k:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1]; + Uint16 b = (u->wst.dat[u->wst.ptr - 2] | (u->wst.dat[u->wst.ptr - 3] << 8)); + mempoke16(u->ram.dat, a, b); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 3, 0)) { + u->wst.error = 1; + goto error; + } +#endif + } + break; + case 0xb2: /* LDR2k */ + __asm__("evaluxn_b2_LDR2k:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1]; + u->wst.dat[u->wst.ptr] = mempeek8(u->ram.dat, u->ram.ptr + (Sint8)a); + u->wst.dat[u->wst.ptr + 1] = mempeek8(u->ram.dat, u->ram.ptr + (Sint8)a + 1); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 1, 0)) { + u->wst.error = 1; + goto error; + } + if(__builtin_expect(u->wst.ptr > 253, 0)) { + u->wst.error = 2; + goto error; + } +#endif + u->wst.ptr += 2; + } + break; + case 0xb3: /* STR2k */ + __asm__("evaluxn_b3_STR2k:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1]; + Uint16 b = (u->wst.dat[u->wst.ptr - 2] | (u->wst.dat[u->wst.ptr - 3] << 8)); + mempoke16(u->ram.dat, u->ram.ptr + (Sint8)a, b); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 3, 0)) { + u->wst.error = 1; + goto error; + } +#endif + } + break; + case 0xb4: /* LDA2k */ + __asm__("evaluxn_b4_LDA2k:"); + { + Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)); + u->wst.dat[u->wst.ptr] = mempeek8(u->ram.dat, a); + u->wst.dat[u->wst.ptr + 1] = mempeek8(u->ram.dat, a + 1); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 2, 0)) { + u->wst.error = 1; + goto error; + } + if(__builtin_expect(u->wst.ptr > 253, 0)) { + u->wst.error = 2; + goto error; + } +#endif + u->wst.ptr += 2; + } + break; + case 0xb5: /* STA2k */ + __asm__("evaluxn_b5_STA2k:"); + { + Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)); + Uint16 b = (u->wst.dat[u->wst.ptr - 3] | (u->wst.dat[u->wst.ptr - 4] << 8)); + mempoke16(u->ram.dat, a, b); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 4, 0)) { + u->wst.error = 1; + goto error; + } +#endif + } + break; + case 0xb6: /* DEI2k */ + __asm__("evaluxn_b6_DEI2k:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1]; + u->wst.dat[u->wst.ptr] = devpeek8(&u->dev[a >> 4], a); + u->wst.dat[u->wst.ptr + 1] = devpeek8(&u->dev[a >> 4], a + 1); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 1, 0)) { + u->wst.error = 1; + goto error; + } + if(__builtin_expect(u->wst.ptr > 253, 0)) { + u->wst.error = 2; + goto error; + } +#endif + u->wst.ptr += 2; + } + break; + case 0xb7: /* DEO2k */ + __asm__("evaluxn_b7_DEO2k:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1]; + Uint16 b = (u->wst.dat[u->wst.ptr - 2] | (u->wst.dat[u->wst.ptr - 3] << 8)); + devpoke16(&u->dev[a >> 4], a, b); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 3, 0)) { + u->wst.error = 1; + goto error; + } +#endif + } + break; + case 0xb8: /* ADD2k */ + __asm__("evaluxn_b8_ADD2k:"); + { + Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)), b = (u->wst.dat[u->wst.ptr - 3] | (u->wst.dat[u->wst.ptr - 4] << 8)); + u->wst.dat[u->wst.ptr] = (b + a) >> 8; + u->wst.dat[u->wst.ptr + 1] = (b + a) & 0xff; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 4, 0)) { + u->wst.error = 1; + goto error; + } + if(__builtin_expect(u->wst.ptr > 253, 0)) { + u->wst.error = 2; + goto error; + } +#endif + u->wst.ptr += 2; + } + break; + case 0xb9: /* SUB2k */ + __asm__("evaluxn_b9_SUB2k:"); + { + Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)), b = (u->wst.dat[u->wst.ptr - 3] | (u->wst.dat[u->wst.ptr - 4] << 8)); + u->wst.dat[u->wst.ptr] = (b - a) >> 8; + u->wst.dat[u->wst.ptr + 1] = (b - a) & 0xff; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 4, 0)) { + u->wst.error = 1; + goto error; + } + if(__builtin_expect(u->wst.ptr > 253, 0)) { + u->wst.error = 2; + goto error; + } +#endif + u->wst.ptr += 2; + } + break; + case 0xba: /* MUL2k */ + __asm__("evaluxn_ba_MUL2k:"); + { + Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)), b = (u->wst.dat[u->wst.ptr - 3] | (u->wst.dat[u->wst.ptr - 4] << 8)); + u->wst.dat[u->wst.ptr] = (b * a) >> 8; + u->wst.dat[u->wst.ptr + 1] = (b * a) & 0xff; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 4, 0)) { + u->wst.error = 1; + goto error; + } + if(__builtin_expect(u->wst.ptr > 253, 0)) { + u->wst.error = 2; + goto error; + } +#endif + u->wst.ptr += 2; + } + break; + case 0xbb: /* DIV2k */ + __asm__("evaluxn_bb_DIV2k:"); + { + Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)), b = (u->wst.dat[u->wst.ptr - 3] | (u->wst.dat[u->wst.ptr - 4] << 8)); + if(a == 0) { + u->wst.error = 3; +#ifndef NO_STACK_CHECKS + goto error; +#endif + a = 1; + } + u->wst.dat[u->wst.ptr] = (b / a) >> 8; + u->wst.dat[u->wst.ptr + 1] = (b / a) & 0xff; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 4, 0)) { + u->wst.error = 1; + goto error; + } + if(__builtin_expect(u->wst.ptr > 253, 0)) { + u->wst.error = 2; + goto error; + } +#endif + u->wst.ptr += 2; + } + break; + case 0xbc: /* AND2k */ + __asm__("evaluxn_bc_AND2k:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2], c = u->wst.dat[u->wst.ptr - 3], d = u->wst.dat[u->wst.ptr - 4]; + u->wst.dat[u->wst.ptr] = d & b; + u->wst.dat[u->wst.ptr + 1] = c & a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 4, 0)) { + u->wst.error = 1; + goto error; + } + if(__builtin_expect(u->wst.ptr > 253, 0)) { + u->wst.error = 2; + goto error; + } +#endif + u->wst.ptr += 2; + } + break; + case 0xbd: /* ORA2k */ + __asm__("evaluxn_bd_ORA2k:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2], c = u->wst.dat[u->wst.ptr - 3], d = u->wst.dat[u->wst.ptr - 4]; + u->wst.dat[u->wst.ptr] = d | b; + u->wst.dat[u->wst.ptr + 1] = c | a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 4, 0)) { + u->wst.error = 1; + goto error; + } + if(__builtin_expect(u->wst.ptr > 253, 0)) { + u->wst.error = 2; + goto error; + } +#endif + u->wst.ptr += 2; + } + break; + case 0xbe: /* EOR2k */ + __asm__("evaluxn_be_EOR2k:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2], c = u->wst.dat[u->wst.ptr - 3], d = u->wst.dat[u->wst.ptr - 4]; + u->wst.dat[u->wst.ptr] = d ^ b; + u->wst.dat[u->wst.ptr + 1] = c ^ a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 4, 0)) { + u->wst.error = 1; + goto error; + } + if(__builtin_expect(u->wst.ptr > 253, 0)) { + u->wst.error = 2; + goto error; + } +#endif + u->wst.ptr += 2; + } + break; + case 0xbf: /* SFT2k */ + __asm__("evaluxn_bf_SFT2k:"); + { + Uint8 a = u->wst.dat[u->wst.ptr - 1]; + Uint16 b = (u->wst.dat[u->wst.ptr - 2] | (u->wst.dat[u->wst.ptr - 3] << 8)); + u->wst.dat[u->wst.ptr] = (b >> (a & 0x0f) << ((a & 0xf0) >> 4)) >> 8; + u->wst.dat[u->wst.ptr + 1] = (b >> (a & 0x0f) << ((a & 0xf0) >> 4)) & 0xff; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 3, 0)) { + u->wst.error = 1; + goto error; + } + if(__builtin_expect(u->wst.ptr > 253, 0)) { + u->wst.error = 2; + goto error; + } +#endif + u->wst.ptr += 2; + } + break; + case 0xc1: /* INCkr */ + __asm__("evaluxn_c1_INCkr:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1]; + u->rst.dat[u->rst.ptr] = a + 1; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 1, 0)) { + u->rst.error = 1; + goto error; + } + if(__builtin_expect(u->rst.ptr > 254, 0)) { + u->rst.error = 2; + goto error; + } +#endif + u->rst.ptr += 1; + } + break; + case 0xc2: /* POPkr */ + __asm__("evaluxn_c2_POPkr:"); + { + u->rst.dat[u->rst.ptr - 1]; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 1, 0)) { + u->rst.error = 1; + goto error; + } +#endif + } + break; + case 0xc3: /* DUPkr */ + __asm__("evaluxn_c3_DUPkr:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1]; + u->rst.dat[u->rst.ptr] = a; + u->rst.dat[u->rst.ptr + 1] = a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 1, 0)) { + u->rst.error = 1; + goto error; + } + if(__builtin_expect(u->rst.ptr > 253, 0)) { + u->rst.error = 2; + goto error; + } +#endif + u->rst.ptr += 2; + } + break; + case 0xc4: /* NIPkr */ + __asm__("evaluxn_c4_NIPkr:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1]; + u->rst.dat[u->rst.ptr - 2]; + u->rst.dat[u->rst.ptr] = a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 2, 0)) { + u->rst.error = 1; + goto error; + } + if(__builtin_expect(u->rst.ptr > 254, 0)) { + u->rst.error = 2; + goto error; + } +#endif + u->rst.ptr += 1; + } + break; + case 0xc5: /* SWPkr */ + __asm__("evaluxn_c5_SWPkr:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; + u->rst.dat[u->rst.ptr] = a; + u->rst.dat[u->rst.ptr + 1] = b; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 2, 0)) { + u->rst.error = 1; + goto error; + } + if(__builtin_expect(u->rst.ptr > 253, 0)) { + u->rst.error = 2; + goto error; + } +#endif + u->rst.ptr += 2; + } + break; + case 0xc6: /* OVRkr */ + __asm__("evaluxn_c6_OVRkr:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; + u->rst.dat[u->rst.ptr] = b; + u->rst.dat[u->rst.ptr + 1] = a; + u->rst.dat[u->rst.ptr + 2] = b; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 2, 0)) { + u->rst.error = 1; + goto error; + } + if(__builtin_expect(u->rst.ptr > 252, 0)) { + u->rst.error = 2; + goto error; + } +#endif + u->rst.ptr += 3; + } + break; + case 0xc7: /* ROTkr */ + __asm__("evaluxn_c7_ROTkr:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2], c = u->rst.dat[u->rst.ptr - 3]; + u->rst.dat[u->rst.ptr] = b; + u->rst.dat[u->rst.ptr + 1] = a; + u->rst.dat[u->rst.ptr + 2] = c; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 3, 0)) { + u->rst.error = 1; + goto error; + } + if(__builtin_expect(u->rst.ptr > 252, 0)) { + u->rst.error = 2; + goto error; + } +#endif + u->rst.ptr += 3; + } + break; + case 0xc8: /* EQUkr */ + __asm__("evaluxn_c8_EQUkr:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; + u->rst.dat[u->rst.ptr] = b == a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 2, 0)) { + u->rst.error = 1; + goto error; + } + if(__builtin_expect(u->rst.ptr > 254, 0)) { + u->rst.error = 2; + goto error; + } +#endif + u->rst.ptr += 1; + } + break; + case 0xc9: /* NEQkr */ + __asm__("evaluxn_c9_NEQkr:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; + u->rst.dat[u->rst.ptr] = b != a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 2, 0)) { + u->rst.error = 1; + goto error; + } + if(__builtin_expect(u->rst.ptr > 254, 0)) { + u->rst.error = 2; + goto error; + } +#endif + u->rst.ptr += 1; + } + break; + case 0xca: /* GTHkr */ + __asm__("evaluxn_ca_GTHkr:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; + u->rst.dat[u->rst.ptr] = b > a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 2, 0)) { + u->rst.error = 1; + goto error; + } + if(__builtin_expect(u->rst.ptr > 254, 0)) { + u->rst.error = 2; + goto error; + } +#endif + u->rst.ptr += 1; + } + break; + case 0xcb: /* LTHkr */ + __asm__("evaluxn_cb_LTHkr:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; + u->rst.dat[u->rst.ptr] = b < a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 2, 0)) { + u->rst.error = 1; + goto error; + } + if(__builtin_expect(u->rst.ptr > 254, 0)) { + u->rst.error = 2; + goto error; + } +#endif + u->rst.ptr += 1; + } + break; + case 0xcc: /* JMPkr */ + __asm__("evaluxn_cc_JMPkr:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1]; + u->ram.ptr += (Sint8)a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 1, 0)) { + u->rst.error = 1; + goto error; + } +#endif + } + break; + case 0xcd: /* JCNkr */ + __asm__("evaluxn_cd_JCNkr:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1]; + if(u->rst.dat[u->rst.ptr - 2]) u->ram.ptr += (Sint8)a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 2, 0)) { + u->rst.error = 1; + goto error; + } +#endif + } + break; + case 0xce: /* JSRkr */ + __asm__("evaluxn_ce_JSRkr:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1]; + u->wst.dat[u->wst.ptr] = u->ram.ptr >> 8; + u->wst.dat[u->wst.ptr + 1] = u->ram.ptr & 0xff; + u->ram.ptr += (Sint8)a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 1, 0)) { + u->rst.error = 1; + goto error; + } + if(__builtin_expect(u->wst.ptr > 253, 0)) { + u->wst.error = 2; + goto error; + } +#endif + u->wst.ptr += 2; + } + break; + case 0xcf: /* STHkr */ + __asm__("evaluxn_cf_STHkr:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1]; + u->wst.dat[u->wst.ptr] = a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 1, 0)) { + u->rst.error = 1; + goto error; + } + if(__builtin_expect(u->wst.ptr > 254, 0)) { + u->wst.error = 2; + goto error; + } +#endif + u->wst.ptr += 1; + } + break; + case 0xd0: /* LDZkr */ + __asm__("evaluxn_d0_LDZkr:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1]; + u->rst.dat[u->rst.ptr] = mempeek8(u->ram.dat, a); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 1, 0)) { + u->rst.error = 1; + goto error; + } + if(__builtin_expect(u->rst.ptr > 254, 0)) { + u->rst.error = 2; + goto error; + } +#endif + u->rst.ptr += 1; + } + break; + case 0xd1: /* STZkr */ + __asm__("evaluxn_d1_STZkr:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1]; + Uint8 b = u->rst.dat[u->rst.ptr - 2]; + mempoke8(u->ram.dat, a, b); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 2, 0)) { + u->rst.error = 1; + goto error; + } +#endif + } + break; + case 0xd2: /* LDRkr */ + __asm__("evaluxn_d2_LDRkr:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1]; + u->rst.dat[u->rst.ptr] = mempeek8(u->ram.dat, u->ram.ptr + (Sint8)a); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 1, 0)) { + u->rst.error = 1; + goto error; + } + if(__builtin_expect(u->rst.ptr > 254, 0)) { + u->rst.error = 2; + goto error; + } +#endif + u->rst.ptr += 1; + } + break; + case 0xd3: /* STRkr */ + __asm__("evaluxn_d3_STRkr:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1]; + Uint8 b = u->rst.dat[u->rst.ptr - 2]; + mempoke8(u->ram.dat, u->ram.ptr + (Sint8)a, b); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 2, 0)) { + u->rst.error = 1; + goto error; + } +#endif + } + break; + case 0xd4: /* LDAkr */ + __asm__("evaluxn_d4_LDAkr:"); + { + Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)); + u->rst.dat[u->rst.ptr] = mempeek8(u->ram.dat, a); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 2, 0)) { + u->rst.error = 1; + goto error; + } + if(__builtin_expect(u->rst.ptr > 254, 0)) { + u->rst.error = 2; + goto error; + } +#endif + u->rst.ptr += 1; + } + break; + case 0xd5: /* STAkr */ + __asm__("evaluxn_d5_STAkr:"); + { + Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)); + Uint8 b = u->rst.dat[u->rst.ptr - 3]; + mempoke8(u->ram.dat, a, b); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 3, 0)) { + u->rst.error = 1; + goto error; + } +#endif + } + break; + case 0xd6: /* DEIkr */ + __asm__("evaluxn_d6_DEIkr:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1]; + u->rst.dat[u->rst.ptr] = devpeek8(&u->dev[a >> 4], a); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 1, 0)) { + u->rst.error = 1; + goto error; + } + if(__builtin_expect(u->rst.ptr > 254, 0)) { + u->rst.error = 2; + goto error; + } +#endif + u->rst.ptr += 1; + } + break; + case 0xd7: /* DEOkr */ + __asm__("evaluxn_d7_DEOkr:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; + devpoke8(&u->dev[a >> 4], a, b); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 2, 0)) { + u->rst.error = 1; + goto error; + } +#endif + } + break; + case 0xd8: /* ADDkr */ + __asm__("evaluxn_d8_ADDkr:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; + u->rst.dat[u->rst.ptr] = b + a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 2, 0)) { + u->rst.error = 1; + goto error; + } + if(__builtin_expect(u->rst.ptr > 254, 0)) { + u->rst.error = 2; + goto error; + } +#endif + u->rst.ptr += 1; + } + break; + case 0xd9: /* SUBkr */ + __asm__("evaluxn_d9_SUBkr:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; + u->rst.dat[u->rst.ptr] = b - a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 2, 0)) { + u->rst.error = 1; + goto error; + } + if(__builtin_expect(u->rst.ptr > 254, 0)) { + u->rst.error = 2; + goto error; + } +#endif + u->rst.ptr += 1; + } + break; + case 0xda: /* MULkr */ + __asm__("evaluxn_da_MULkr:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; + u->rst.dat[u->rst.ptr] = b * a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 2, 0)) { + u->rst.error = 1; + goto error; + } + if(__builtin_expect(u->rst.ptr > 254, 0)) { + u->rst.error = 2; + goto error; + } +#endif + u->rst.ptr += 1; + } + break; + case 0xdb: /* DIVkr */ + __asm__("evaluxn_db_DIVkr:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; + if(a == 0) { + u->rst.error = 3; +#ifndef NO_STACK_CHECKS + goto error; +#endif + a = 1; + } + u->rst.dat[u->rst.ptr] = b / a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 2, 0)) { + u->rst.error = 1; + goto error; + } + if(__builtin_expect(u->rst.ptr > 254, 0)) { + u->rst.error = 2; + goto error; + } +#endif + u->rst.ptr += 1; + } + break; + case 0xdc: /* ANDkr */ + __asm__("evaluxn_dc_ANDkr:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; + u->rst.dat[u->rst.ptr] = b & a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 2, 0)) { + u->rst.error = 1; + goto error; + } + if(__builtin_expect(u->rst.ptr > 254, 0)) { + u->rst.error = 2; + goto error; + } +#endif + u->rst.ptr += 1; + } + break; + case 0xdd: /* ORAkr */ + __asm__("evaluxn_dd_ORAkr:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; + u->rst.dat[u->rst.ptr] = b | a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 2, 0)) { + u->rst.error = 1; + goto error; + } + if(__builtin_expect(u->rst.ptr > 254, 0)) { + u->rst.error = 2; + goto error; + } +#endif + u->rst.ptr += 1; + } + break; + case 0xde: /* EORkr */ + __asm__("evaluxn_de_EORkr:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; + u->rst.dat[u->rst.ptr] = b ^ a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 2, 0)) { + u->rst.error = 1; + goto error; + } + if(__builtin_expect(u->rst.ptr > 254, 0)) { + u->rst.error = 2; + goto error; + } +#endif + u->rst.ptr += 1; + } + break; + case 0xdf: /* SFTkr */ + __asm__("evaluxn_df_SFTkr:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; + u->rst.dat[u->rst.ptr] = b >> (a & 0x07) << ((a & 0x70) >> 4); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 2, 0)) { + u->rst.error = 1; + goto error; + } + if(__builtin_expect(u->rst.ptr > 254, 0)) { + u->rst.error = 2; + goto error; + } +#endif + u->rst.ptr += 1; + } + break; + case 0xe1: /* INC2kr */ + __asm__("evaluxn_e1_INC2kr:"); + { + Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)); + u->rst.dat[u->rst.ptr] = (a + 1) >> 8; + u->rst.dat[u->rst.ptr + 1] = (a + 1) & 0xff; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 2, 0)) { + u->rst.error = 1; + goto error; + } + if(__builtin_expect(u->rst.ptr > 253, 0)) { + u->rst.error = 2; + goto error; + } +#endif + u->rst.ptr += 2; + } + break; + case 0xe2: /* POP2kr */ + __asm__("evaluxn_e2_POP2kr:"); + { + (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 2, 0)) { + u->rst.error = 1; + goto error; + } +#endif + } + break; + case 0xe3: /* DUP2kr */ + __asm__("evaluxn_e3_DUP2kr:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; + u->rst.dat[u->rst.ptr] = b; + u->rst.dat[u->rst.ptr + 1] = a; + u->rst.dat[u->rst.ptr + 2] = b; + u->rst.dat[u->rst.ptr + 3] = a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 2, 0)) { + u->rst.error = 1; + goto error; + } + if(__builtin_expect(u->rst.ptr > 251, 0)) { + u->rst.error = 2; + goto error; + } +#endif + u->rst.ptr += 4; + } + break; + case 0xe4: /* NIP2kr */ + __asm__("evaluxn_e4_NIP2kr:"); + { + Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)); + (u->rst.dat[u->rst.ptr - 3] | (u->rst.dat[u->rst.ptr - 4] << 8)); + u->rst.dat[u->rst.ptr] = a >> 8; + u->rst.dat[u->rst.ptr + 1] = a & 0xff; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 4, 0)) { + u->rst.error = 1; + goto error; + } + if(__builtin_expect(u->rst.ptr > 253, 0)) { + u->rst.error = 2; + goto error; + } +#endif + u->rst.ptr += 2; + } + break; + case 0xe5: /* SWP2kr */ + __asm__("evaluxn_e5_SWP2kr:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2], c = u->rst.dat[u->rst.ptr - 3], d = u->rst.dat[u->rst.ptr - 4]; + u->rst.dat[u->rst.ptr] = b; + u->rst.dat[u->rst.ptr + 1] = a; + u->rst.dat[u->rst.ptr + 2] = d; + u->rst.dat[u->rst.ptr + 3] = c; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 4, 0)) { + u->rst.error = 1; + goto error; + } + if(__builtin_expect(u->rst.ptr > 251, 0)) { + u->rst.error = 2; + goto error; + } +#endif + u->rst.ptr += 4; + } + break; + case 0xe6: /* OVR2kr */ + __asm__("evaluxn_e6_OVR2kr:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2], c = u->rst.dat[u->rst.ptr - 3], d = u->rst.dat[u->rst.ptr - 4]; + u->rst.dat[u->rst.ptr] = d; + u->rst.dat[u->rst.ptr + 1] = c; + u->rst.dat[u->rst.ptr + 2] = b; + u->rst.dat[u->rst.ptr + 3] = a; + u->rst.dat[u->rst.ptr + 4] = d; + u->rst.dat[u->rst.ptr + 5] = c; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 4, 0)) { + u->rst.error = 1; + goto error; + } + if(__builtin_expect(u->rst.ptr > 249, 0)) { + u->rst.error = 2; + goto error; + } +#endif + u->rst.ptr += 6; + } + break; + case 0xe7: /* ROT2kr */ + __asm__("evaluxn_e7_ROT2kr:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2], c = u->rst.dat[u->rst.ptr - 3], d = u->rst.dat[u->rst.ptr - 4], e = u->rst.dat[u->rst.ptr - 5], f = u->rst.dat[u->rst.ptr - 6]; + u->rst.dat[u->rst.ptr] = d; + u->rst.dat[u->rst.ptr + 1] = c; + u->rst.dat[u->rst.ptr + 2] = b; + u->rst.dat[u->rst.ptr + 3] = a; + u->rst.dat[u->rst.ptr + 4] = f; + u->rst.dat[u->rst.ptr + 5] = e; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 6, 0)) { + u->rst.error = 1; + goto error; + } + if(__builtin_expect(u->rst.ptr > 249, 0)) { + u->rst.error = 2; + goto error; + } +#endif + u->rst.ptr += 6; + } + break; + case 0xe8: /* EQU2kr */ + __asm__("evaluxn_e8_EQU2kr:"); + { + Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)), b = (u->rst.dat[u->rst.ptr - 3] | (u->rst.dat[u->rst.ptr - 4] << 8)); + u->rst.dat[u->rst.ptr] = b == a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 4, 0)) { + u->rst.error = 1; + goto error; + } + if(__builtin_expect(u->rst.ptr > 254, 0)) { + u->rst.error = 2; + goto error; + } +#endif + u->rst.ptr += 1; + } + break; + case 0xe9: /* NEQ2kr */ + __asm__("evaluxn_e9_NEQ2kr:"); + { + Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)), b = (u->rst.dat[u->rst.ptr - 3] | (u->rst.dat[u->rst.ptr - 4] << 8)); + u->rst.dat[u->rst.ptr] = b != a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 4, 0)) { + u->rst.error = 1; + goto error; + } + if(__builtin_expect(u->rst.ptr > 254, 0)) { + u->rst.error = 2; + goto error; + } +#endif + u->rst.ptr += 1; + } + break; + case 0xea: /* GTH2kr */ + __asm__("evaluxn_ea_GTH2kr:"); + { + Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)), b = (u->rst.dat[u->rst.ptr - 3] | (u->rst.dat[u->rst.ptr - 4] << 8)); + u->rst.dat[u->rst.ptr] = b > a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 4, 0)) { + u->rst.error = 1; + goto error; + } + if(__builtin_expect(u->rst.ptr > 254, 0)) { + u->rst.error = 2; + goto error; + } +#endif + u->rst.ptr += 1; + } + break; + case 0xeb: /* LTH2kr */ + __asm__("evaluxn_eb_LTH2kr:"); + { + Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)), b = (u->rst.dat[u->rst.ptr - 3] | (u->rst.dat[u->rst.ptr - 4] << 8)); + u->rst.dat[u->rst.ptr] = b < a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 4, 0)) { + u->rst.error = 1; + goto error; + } + if(__builtin_expect(u->rst.ptr > 254, 0)) { + u->rst.error = 2; + goto error; + } +#endif + u->rst.ptr += 1; + } + break; + case 0xec: /* JMP2kr */ + __asm__("evaluxn_ec_JMP2kr:"); + { + u->ram.ptr = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 2, 0)) { + u->rst.error = 1; + goto error; + } +#endif + } + break; + case 0xed: /* JCN2kr */ + __asm__("evaluxn_ed_JCN2kr:"); + { + Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)); + if(u->rst.dat[u->rst.ptr - 3]) u->ram.ptr = a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 3, 0)) { + u->rst.error = 1; + goto error; + } +#endif + } + break; + case 0xee: /* JSR2kr */ + __asm__("evaluxn_ee_JSR2kr:"); + { + u->wst.dat[u->wst.ptr] = u->ram.ptr >> 8; + u->wst.dat[u->wst.ptr + 1] = u->ram.ptr & 0xff; + u->ram.ptr = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 2, 0)) { + u->rst.error = 1; + goto error; + } + if(__builtin_expect(u->wst.ptr > 253, 0)) { + u->wst.error = 2; + goto error; + } +#endif + u->wst.ptr += 2; + } + break; + case 0xef: /* STH2kr */ + __asm__("evaluxn_ef_STH2kr:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; + u->wst.dat[u->wst.ptr] = b; + u->wst.dat[u->wst.ptr + 1] = a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 2, 0)) { + u->rst.error = 1; + goto error; + } + if(__builtin_expect(u->wst.ptr > 253, 0)) { + u->wst.error = 2; + goto error; + } +#endif + u->wst.ptr += 2; + } + break; + case 0xf0: /* LDZ2kr */ + __asm__("evaluxn_f0_LDZ2kr:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1]; + u->rst.dat[u->rst.ptr] = mempeek8(u->ram.dat, a); + u->rst.dat[u->rst.ptr + 1] = mempeek8(u->ram.dat, a + 1); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 1, 0)) { + u->rst.error = 1; + goto error; + } + if(__builtin_expect(u->rst.ptr > 253, 0)) { + u->rst.error = 2; + goto error; + } +#endif + u->rst.ptr += 2; + } + break; + case 0xf1: /* STZ2kr */ + __asm__("evaluxn_f1_STZ2kr:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1]; + Uint16 b = (u->rst.dat[u->rst.ptr - 2] | (u->rst.dat[u->rst.ptr - 3] << 8)); + mempoke16(u->ram.dat, a, b); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 3, 0)) { + u->rst.error = 1; + goto error; + } +#endif + } + break; + case 0xf2: /* LDR2kr */ + __asm__("evaluxn_f2_LDR2kr:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1]; + u->rst.dat[u->rst.ptr] = mempeek8(u->ram.dat, u->ram.ptr + (Sint8)a); + u->rst.dat[u->rst.ptr + 1] = mempeek8(u->ram.dat, u->ram.ptr + (Sint8)a + 1); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 1, 0)) { + u->rst.error = 1; + goto error; + } + if(__builtin_expect(u->rst.ptr > 253, 0)) { + u->rst.error = 2; + goto error; + } +#endif + u->rst.ptr += 2; + } + break; + case 0xf3: /* STR2kr */ + __asm__("evaluxn_f3_STR2kr:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1]; + Uint16 b = (u->rst.dat[u->rst.ptr - 2] | (u->rst.dat[u->rst.ptr - 3] << 8)); + mempoke16(u->ram.dat, u->ram.ptr + (Sint8)a, b); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 3, 0)) { + u->rst.error = 1; + goto error; + } +#endif + } + break; + case 0xf4: /* LDA2kr */ + __asm__("evaluxn_f4_LDA2kr:"); + { + Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)); + u->rst.dat[u->rst.ptr] = mempeek8(u->ram.dat, a); + u->rst.dat[u->rst.ptr + 1] = mempeek8(u->ram.dat, a + 1); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 2, 0)) { + u->rst.error = 1; + goto error; + } + if(__builtin_expect(u->rst.ptr > 253, 0)) { + u->rst.error = 2; + goto error; + } +#endif + u->rst.ptr += 2; + } + break; + case 0xf5: /* STA2kr */ + __asm__("evaluxn_f5_STA2kr:"); + { + Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)); + Uint16 b = (u->rst.dat[u->rst.ptr - 3] | (u->rst.dat[u->rst.ptr - 4] << 8)); + mempoke16(u->ram.dat, a, b); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 4, 0)) { + u->rst.error = 1; + goto error; + } +#endif + } + break; + case 0xf6: /* DEI2kr */ + __asm__("evaluxn_f6_DEI2kr:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1]; + u->rst.dat[u->rst.ptr] = devpeek8(&u->dev[a >> 4], a); + u->rst.dat[u->rst.ptr + 1] = devpeek8(&u->dev[a >> 4], a + 1); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 1, 0)) { + u->rst.error = 1; + goto error; + } + if(__builtin_expect(u->rst.ptr > 253, 0)) { + u->rst.error = 2; + goto error; + } +#endif + u->rst.ptr += 2; + } + break; + case 0xf7: /* DEO2kr */ + __asm__("evaluxn_f7_DEO2kr:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1]; + Uint16 b = (u->rst.dat[u->rst.ptr - 2] | (u->rst.dat[u->rst.ptr - 3] << 8)); + devpoke16(&u->dev[a >> 4], a, b); +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 3, 0)) { + u->rst.error = 1; + goto error; + } +#endif + } + break; + case 0xf8: /* ADD2kr */ + __asm__("evaluxn_f8_ADD2kr:"); + { + Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)), b = (u->rst.dat[u->rst.ptr - 3] | (u->rst.dat[u->rst.ptr - 4] << 8)); + u->rst.dat[u->rst.ptr] = (b + a) >> 8; + u->rst.dat[u->rst.ptr + 1] = (b + a) & 0xff; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 4, 0)) { + u->rst.error = 1; + goto error; + } + if(__builtin_expect(u->rst.ptr > 253, 0)) { + u->rst.error = 2; + goto error; + } +#endif + u->rst.ptr += 2; + } + break; + case 0xf9: /* SUB2kr */ + __asm__("evaluxn_f9_SUB2kr:"); + { + Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)), b = (u->rst.dat[u->rst.ptr - 3] | (u->rst.dat[u->rst.ptr - 4] << 8)); + u->rst.dat[u->rst.ptr] = (b - a) >> 8; + u->rst.dat[u->rst.ptr + 1] = (b - a) & 0xff; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 4, 0)) { + u->rst.error = 1; + goto error; + } + if(__builtin_expect(u->rst.ptr > 253, 0)) { + u->rst.error = 2; + goto error; + } +#endif + u->rst.ptr += 2; + } + break; + case 0xfa: /* MUL2kr */ + __asm__("evaluxn_fa_MUL2kr:"); + { + Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)), b = (u->rst.dat[u->rst.ptr - 3] | (u->rst.dat[u->rst.ptr - 4] << 8)); + u->rst.dat[u->rst.ptr] = (b * a) >> 8; + u->rst.dat[u->rst.ptr + 1] = (b * a) & 0xff; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 4, 0)) { + u->rst.error = 1; + goto error; + } + if(__builtin_expect(u->rst.ptr > 253, 0)) { + u->rst.error = 2; + goto error; + } +#endif + u->rst.ptr += 2; + } + break; + case 0xfb: /* DIV2kr */ + __asm__("evaluxn_fb_DIV2kr:"); + { + Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)), b = (u->rst.dat[u->rst.ptr - 3] | (u->rst.dat[u->rst.ptr - 4] << 8)); + if(a == 0) { + u->rst.error = 3; +#ifndef NO_STACK_CHECKS + goto error; +#endif + a = 1; + } + u->rst.dat[u->rst.ptr] = (b / a) >> 8; + u->rst.dat[u->rst.ptr + 1] = (b / a) & 0xff; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 4, 0)) { + u->rst.error = 1; + goto error; + } + if(__builtin_expect(u->rst.ptr > 253, 0)) { + u->rst.error = 2; + goto error; + } +#endif + u->rst.ptr += 2; + } + break; + case 0xfc: /* AND2kr */ + __asm__("evaluxn_fc_AND2kr:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2], c = u->rst.dat[u->rst.ptr - 3], d = u->rst.dat[u->rst.ptr - 4]; + u->rst.dat[u->rst.ptr] = d & b; + u->rst.dat[u->rst.ptr + 1] = c & a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 4, 0)) { + u->rst.error = 1; + goto error; + } + if(__builtin_expect(u->rst.ptr > 253, 0)) { + u->rst.error = 2; + goto error; + } +#endif + u->rst.ptr += 2; + } + break; + case 0xfd: /* ORA2kr */ + __asm__("evaluxn_fd_ORA2kr:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2], c = u->rst.dat[u->rst.ptr - 3], d = u->rst.dat[u->rst.ptr - 4]; + u->rst.dat[u->rst.ptr] = d | b; + u->rst.dat[u->rst.ptr + 1] = c | a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 4, 0)) { + u->rst.error = 1; + goto error; + } + if(__builtin_expect(u->rst.ptr > 253, 0)) { + u->rst.error = 2; + goto error; + } +#endif + u->rst.ptr += 2; + } + break; + case 0xfe: /* EOR2kr */ + __asm__("evaluxn_fe_EOR2kr:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2], c = u->rst.dat[u->rst.ptr - 3], d = u->rst.dat[u->rst.ptr - 4]; + u->rst.dat[u->rst.ptr] = d ^ b; + u->rst.dat[u->rst.ptr + 1] = c ^ a; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 4, 0)) { + u->rst.error = 1; + goto error; + } + if(__builtin_expect(u->rst.ptr > 253, 0)) { + u->rst.error = 2; + goto error; + } +#endif + u->rst.ptr += 2; + } + break; + case 0xff: /* SFT2kr */ + __asm__("evaluxn_ff_SFT2kr:"); + { + Uint8 a = u->rst.dat[u->rst.ptr - 1]; + Uint16 b = (u->rst.dat[u->rst.ptr - 2] | (u->rst.dat[u->rst.ptr - 3] << 8)); + u->rst.dat[u->rst.ptr] = (b >> (a & 0x0f) << ((a & 0xf0) >> 4)) >> 8; + u->rst.dat[u->rst.ptr + 1] = (b >> (a & 0x0f) << ((a & 0xf0) >> 4)) & 0xff; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 3, 0)) { + u->rst.error = 1; + goto error; + } + if(__builtin_expect(u->rst.ptr > 253, 0)) { + u->rst.error = 2; + goto error; + } +#endif + u->rst.ptr += 2; + } + break; +#pragma GCC diagnostic pop + } + } + return 1; +#ifndef NO_STACK_CHECKS +error: + return 0; +#endif +} + +int +uxn_boot(Uxn *u) +{ + unsigned int i; + char *cptr = (char *)u; + for(i = 0; i < sizeof(*u); i++) + cptr[i] = 0; + return 1; +} + +Device * +uxn_port(Uxn *u, Uint8 id, char *name, void (*talkfn)(Device *d, Uint8 b0, Uint8 w)) +{ + Device *d = &u->dev[id]; + d->addr = id * 0x10; + d->u = u; + d->mem = u->ram.dat; + d->talk = talkfn; + (void)name; + return d; +} diff --git a/src/uxn.h b/src/uxn.h new file mode 100644 index 0000000..e904e24 --- /dev/null +++ b/src/uxn.h @@ -0,0 +1,49 @@ +/* +Copyright (c) 2021 Devine Lu Linvega + +Permission to use, copy, modify, and distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE. +*/ + +typedef unsigned char Uint8; +typedef signed char Sint8; +typedef unsigned short Uint16; +typedef signed short Sint16; + +#define PAGE_PROGRAM 0x0100 + +typedef struct { + Uint8 ptr, kptr, error; + Uint8 dat[256]; +} Stack; + +typedef struct { + Uint16 ptr; + Uint8 dat[65536]; +} Memory; + +typedef struct Device { + struct Uxn *u; + Uint8 addr, dat[16], *mem; + void (*talk)(struct Device *d, Uint8, Uint8); +} Device; + +typedef struct Uxn { + Stack wst, rst, *src, *dst; + Memory ram; + Device dev[16]; +} Uxn; + +struct Uxn; + +void mempoke16(Uint8 *m, Uint16 a, Uint16 b); +Uint16 mempeek16(Uint8 *m, Uint16 a); + +int uxn_boot(Uxn *c); +int uxn_eval(Uxn *u, Uint16 vec); +int uxn_halt(Uxn *u, Uint8 error, char *name, int id); +Device *uxn_port(Uxn *u, Uint8 id, char *name, void (*talkfn)(Device *, Uint8, Uint8)); -- cgit v1.2.1