all repos — xyw @ ee6b5ab02beb5d628b9111fd8aba5365d54841fc

A minimal virtual machine and assembler for terminals.

Renamed xyw_short to xyw_word.
h3rald h3rald@h3rald.com
Fri, 28 Nov 2025 14:48:43 +0100
commit

ee6b5ab02beb5d628b9111fd8aba5365d54841fc

parent

571fe84dd66abeae19c28552d52b65da046f377b

3 files changed, 27 insertions(+), 27 deletions(-)

jump to
M xyw.cxyw.c

@@ -76,33 +76,33 @@ xyw_byte *y = &xyw_memory[SYSTEM_Y];

//// Helpers to manage 2-byte values to memory (big-endian) -static inline xyw_short mget(xyw_short addr) +static inline xyw_word mget(xyw_word addr) { - return ((xyw_short)xyw_memory[addr] << 8) | xyw_memory[addr + 1]; + return ((xyw_word)xyw_memory[addr] << 8) | xyw_memory[addr + 1]; } -static inline void mset(xyw_short addr, xyw_short val) +static inline void mset(xyw_word addr, xyw_word val) { xyw_memory[addr] = (val >> 8) & 0xFF; xyw_memory[addr + 1] = val & 0xFF; } -static inline void madd(xyw_short addr, int delta) +static inline void madd(xyw_word addr, int delta) { - xyw_short val = mget(addr); - mset(addr, (xyw_short)(val + delta)); + xyw_word val = mget(addr); + mset(addr, (xyw_word)(val + delta)); } //// Helpers for common registers -static inline xyw_short pc(void) { return mget(SYSTEM_PC); } -static inline void pc_set(xyw_short val) { mset(SYSTEM_PC, val); } +static inline xyw_word pc(void) { return mget(SYSTEM_PC); } +static inline void pc_set(xyw_word val) { mset(SYSTEM_PC, val); } static inline void pc_add(int delta) { madd(SYSTEM_PC, delta); } -static inline xyw_short xw(void) { return mget(SYSTEM_XW); } -static inline void xw_set(xyw_short val) { mset(SYSTEM_XW, val); } +static inline xyw_word xw(void) { return mget(SYSTEM_XW); } +static inline void xw_set(xyw_word val) { mset(SYSTEM_XW, val); } static inline void xw_add(int delta) { madd(SYSTEM_XW, delta); } -static inline xyw_short yw(void) { return mget(SYSTEM_YW); } -static inline void yw_set(xyw_short val) { mset(SYSTEM_YW, val); } +static inline xyw_word yw(void) { return mget(SYSTEM_YW); } +static inline void yw_set(xyw_word val) { mset(SYSTEM_YW, val); } static inline void yw_add(int delta) { madd(SYSTEM_YW, delta); } //// Main Function
M xyw.hxyw.h

@@ -2,7 +2,7 @@ #ifndef XYW_H

#define XYW_H typedef unsigned char xyw_byte; -typedef unsigned short xyw_short; +typedef unsigned short xyw_word; int xyw_assemble(const char *input, const char *output);
M xywasm.cxywasm.c

@@ -42,7 +42,7 @@ typedef struct

{ char *name; xyw_symbol_type type; - xyw_short address; + xyw_word address; char *contents; } xyw_symbol;

@@ -80,7 +80,7 @@ // The token being processed

static char token[TOKEN_MAX_LENGTH]; static unsigned int token_length = 0; static xyw_token_type token_type = TOKEN_TYPE_UNKNOWN; -static xyw_short token_value = 0; +static xyw_word token_value = 0; // Tracks whether we are inside a directive or not static unsigned int directive = 0;

@@ -89,7 +89,7 @@ // Bytecode to be written

xyw_byte data[0xffff]; // Current write pointer -xyw_short ptr = 0x0000; +xyw_word ptr = 0x0000; // Dictionary for symbols (macros and labels) // Actually following Uxn design here ;)

@@ -98,11 +98,11 @@ char *dictnext = dict;

// List of symbols (macros and labels) xyw_symbol symbols[MAX_SYMBOLS]; -xyw_short symcount = 0; +xyw_word symcount = 0; // List of references to symbols xyw_symbol refs[MAX_REFS]; -xyw_short refcount = 0; +xyw_word refcount = 0; //// Dictionary management

@@ -164,7 +164,7 @@ //// Utilities

static int find_symbol(char *name) { - for (xyw_short i = 0; i < symcount; i++) + for (xyw_word i = 0; i < symcount; i++) { for (unsigned int j = 0; j < TOKEN_MAX_LENGTH; j++) {

@@ -243,7 +243,7 @@ }

return 0; } -static inline void write(xyw_short addr, xyw_short val) +static inline void write(xyw_word addr, xyw_word val) { if (val > 0xff) {

@@ -255,13 +255,13 @@ data[addr] = (xyw_byte)val;

} // Append raw bytecode data -static inline void append(xyw_short val) +static inline void append(xyw_word val) { write(ptr++, val); } // Encode a push instruction -static inline void push(xyw_short val) +static inline void push(xyw_word val) { (val > 0xff) ? append(PSH | MODE_W) : append(PSH); append(val);

@@ -332,7 +332,7 @@

static int process_hex_number(xyw_context *ctx) { // Token is a hex number starting with $ - xyw_short value = 0; + xyw_word value = 0; for (unsigned int i = 1; i < token_length; i++) { char c = token[i];

@@ -369,7 +369,7 @@

static int process_binary_number(xyw_context *ctx) { // Token is a binary number starting with % - xyw_short value = 0; + xyw_word value = 0; for (unsigned int i = 1; i < token_length; i++) { char c = token[i];

@@ -402,7 +402,7 @@

static int process_decimal_number(xyw_context *ctx) { // Token is a decimal number (may or may not start with -) - xyw_short value = 0; + xyw_word value = 0; unsigned int start_index = 0; int is_negative = 0; if (token[0] == '-')

@@ -582,7 +582,7 @@ return -1;

} printf("Directive:\t.org %s\n", token); // Move the pointer to the specified address - ptr = (xyw_short)token_value; + ptr = (xyw_word)token_value; return validate_single_directive_argument(ctx, r); }

@@ -1000,7 +1000,7 @@ fprintf(stderr, "Could not open output file for writing");

return -1; } // Patch labels - for (xyw_short i = 0; i < refcount; i++) + for (xyw_word i = 0; i < refcount; i++) { xyw_symbol *refsym = &refs[i]; int symindex = find_symbol(refsym->name);