all repos — xyw @ dff71d1935009002ad772f0a3246c823507f2976

A minimal virtual machine and assembler for terminals.

Fixed SET implementation
h3rald h3rald@h3rald.com
Wed, 18 Feb 2026 09:52:35 +0100
commit

dff71d1935009002ad772f0a3246c823507f2976

parent

3b8128eb5d140e39a2ccd90e2f5f70fe8991b3e7

2 files changed, 6 insertions(+), 6 deletions(-)

jump to
M xywasm.cxywasm.c

@@ -11,7 +11,7 @@ #define error(msg) fprintf(stderr, "Error - %s [%s]\n", msg, ctx->file)

#define token_error(msg) fprintf(stderr, "Error - %s: %s [%s - Ln %d, Col %d]\n", token, msg, ctx->file, token_line, token_column) #define symbol_error(symbol, msg) fprintf(stderr, "Error - %s: %s [%s - Ln %d, Col %d]\n", symbol, msg, ctx->file, token_line, token_column) -#define PSH 0x01 +#define PSH 0x02 typedef struct {
M xywrun.cxywrun.c

@@ -255,7 +255,7 @@

// Create address based on direct page or full address #define ADDR(ad) (w ? (ad) : (DIRECT_PAGE | (ad))) // Push a value to stack -#define PUSH(n) do { if (w) { us_pushw(n); } else { us_push(n); } } while(0) +#define PUSH(n) do { if (w) { us_pushw((xyw_word)(n)); } else { us_push((xyw_byte)(n)); } } while(0) // Pop value from stack #define POP() (w ? us_popw() : us_pop()) // Get argument from x register or stack

@@ -265,9 +265,9 @@ #define ARGY (ry ? (w ? *yw : *y) : (w ? us_popw() : us_pop()))

// Get argument from x or y register or stack #define ARG (rx ? ARGX : (ry ? ARGY : POP())) // Set value to x register or push to stack -#define SETX(v) rx ? (w ? (*xw = v) : (*x = v)) : (w ? us_pushw(v) : us_push(v)) +#define SETX(v) rx ? (w ? (*xw = (xyw_word)(v)) : (*x = (xyw_byte)(v))) : (w ? us_pushw((xyw_word)(v)) : us_push((xyw_byte)(v))) // Set value to y register or push to stack -#define SETY(v) ry ? (w ? (*yw = v) : (*y = v)) : (w ? us_pushw(v) : us_push(v)) +#define SETY(v) ry ? (w ? (*yw = (xyw_word)(v)) : (*y = (xyw_byte)(v))) : (w ? us_pushw((xyw_word)(v)) : us_push((xyw_byte)(v))) // Set value to x or y register or push to stack #define SET(v) do { if (rx) { SETX(v); } else if (ry) { SETY(v); } else { PUSH(v); } } while(0)

@@ -385,9 +385,9 @@ XYW_DBG(" -- PC: %04X -> %02X (%s) [U:%02X|S:%02X|X:%02X|Y:%02X|XW:%04X|YW:%04X]\n", *pc, xyw_memory[*pc], xyw_instructions[xyw_memory[*pc] & 0x1F], *u, *s, *x, *y, *xw, *yw);

switch (xyw_memory[*pc]) { // clang-format off - /* CLR */ OPC_SR1(0x00, , SET(0)); + /* CLR */ OPC_SR1(0x00, , if (rx||ry) { SET(0); } else { return 0; }); /* CLR */ OPC_SR1r(0x00, if (w) { *xw = 0; *yw = 0; } else { *x = 0; *y = 0; } ); - /* SET */ OPC_SR1(0x01, , if (w) { SET(0xFFFF) } else { SET(0xFF) }); + /* SET */ OPC_SR1(0x01, , if (w) { SET(0xFFFF); } else { SET(0xFF); }); /* SET */ OPC_SR1r(0x01, if (w) { *xw = 0xFFFF; *yw = 0xFFFF; } else { *x = 0xFF; *y = 0xFF; } ); /* PSH */ OPC_SR1(0x02, , if (rx||ry) { PUSH(ARG); } else { (*pc)++; PUSH(READ(*pc)); if (w) { (*pc)++; } }) /* PSH */ OPC_SR1r(0x02, PUSH(a); PUSH(b); )