all repos — xyw @ d948e873377306b80936716af38d72d4e3aa99ef

A minimal virtual machine and assembler for terminals.

Renamed stack pointers.
h3rald h3rald@h3rald.com
Tue, 02 Dec 2025 09:44:11 +0100
commit

d948e873377306b80936716af38d72d4e3aa99ef

parent

cb5922cec8ad98d1f22117c14bd10095582a6d2e

1 files changed, 37 insertions(+), 37 deletions(-)

jump to
M xywrun.cxywrun.c

@@ -22,8 +22,8 @@

/* system device */ #define SYSTEM_STATE 0xff00 #define SYSTEM_ERROR 0xff01 -#define SYSTEM_SSP 0xff02 -#define SYSTEM_USP 0xff03 +#define SYSTEM_S 0xff02 +#define SYSTEM_U 0xff03 #define SYSTEM_PAGE 0xff04 #define SYSTEM_ON_ERROR 0xff05

@@ -40,8 +40,8 @@ xyw_byte system_stack[STACK_SIZE];

xyw_byte user_stack[STACK_SIZE]; //// 1-byte pointers and registers -xyw_byte *ssp = &xyw_memory[SYSTEM_SSP]; -xyw_byte *usp = &xyw_memory[SYSTEM_USP]; +xyw_byte *s = &xyw_memory[SYSTEM_S]; +xyw_byte *u = &xyw_memory[SYSTEM_U]; static xyw_byte x_val = 0; // X register storage static xyw_byte y_val = 0; // Y register storage xyw_byte *x = &x_val;

@@ -78,51 +78,51 @@ //// System stack management

static xyw_word ss_popw() { - if (*ssp < 2) + if (*s < 2) { xyw_memory[SYSTEM_ERROR] = XYW_ERROR_STACK_UNDERFLOW; return -1; } - xyw_word val = mget(SYSTEM_STACK_START + (*ssp) - 2); - mset(SYSTEM_STACK_START + (*ssp) - 2, 0); - (*ssp) -= 2; + xyw_word val = mget(SYSTEM_STACK_START + (*s) - 2); + mset(SYSTEM_STACK_START + (*s) - 2, 0); + (*s) -= 2; return val; } static void ss_pushw(xyw_word val) { - if (*ssp > STACK_SIZE - 2) + if (*s > STACK_SIZE - 2) { xyw_memory[SYSTEM_ERROR] = XYW_ERROR_STACK_OVERFLOW; return; } - mset(SYSTEM_STACK_START + *ssp, val); - (*ssp) += 2; + mset(SYSTEM_STACK_START + *s, val); + (*s) += 2; } //// User stack management static void us_push(xyw_byte val) { - if (*usp > STACK_SIZE - 1) + if (*u > STACK_SIZE - 1) { xyw_memory[SYSTEM_ERROR] = XYW_ERROR_STACK_OVERFLOW; return; } xyw_dbg(" => %02X\n", val); - user_stack[(*usp)++] = val; + user_stack[(*u)++] = val; } static void us_pushw(xyw_word val) { - if (*usp > STACK_SIZE - 2) + if (*u > STACK_SIZE - 2) { xyw_memory[SYSTEM_ERROR] = XYW_ERROR_STACK_OVERFLOW; return; } - mset(USER_STACK_START + *usp, val); + mset(USER_STACK_START + *u, val); xyw_dbg(" => %04X\n", val); - (*usp) += 2; + (*u) += 2; } //// Instructions

@@ -149,73 +149,73 @@ static void PSHyw() { us_pushw(*yw); }

static xyw_byte POP() { - if (*usp < 1) + if (*u < 1) { xyw_memory[SYSTEM_ERROR] = XYW_ERROR_STACK_UNDERFLOW; return -1; } - xyw_byte val = user_stack[--(*usp)]; - user_stack[*usp] = 0; + xyw_byte val = user_stack[--(*u)]; + user_stack[*u] = 0; return val; } static xyw_word POPw() { - if (*usp < 2) + if (*u < 2) { xyw_memory[SYSTEM_ERROR] = XYW_ERROR_STACK_UNDERFLOW; return -1; } - xyw_word val = mget(USER_STACK_START + (*usp) - 2); - mset(USER_STACK_START + (*usp) - 2, 0); - (*usp) -= 2; + xyw_word val = mget(USER_STACK_START + (*u) - 2); + mset(USER_STACK_START + (*u) - 2, 0); + (*u) -= 2; return val; } static void POPx() { - if (*usp < 1) + if (*u < 1) { xyw_memory[SYSTEM_ERROR] = XYW_ERROR_STACK_UNDERFLOW; return; } - *x = user_stack[--(*usp)]; - user_stack[*usp] = 0; + *x = user_stack[--(*u)]; + user_stack[*u] = 0; } static void POPy() { - if (*usp < 1) + if (*u < 1) { xyw_memory[SYSTEM_ERROR] = XYW_ERROR_STACK_UNDERFLOW; return; } - *y = user_stack[--(*usp)]; - user_stack[*usp] = 0; + *y = user_stack[--(*u)]; + user_stack[*u] = 0; } static void POPxw() { - if (*usp < 2) + if (*u < 2) { xyw_memory[SYSTEM_ERROR] = XYW_ERROR_STACK_UNDERFLOW; return; } - *xw = mget(USER_STACK_START + (*usp) - 2); - mset(USER_STACK_START + (*usp) - 2, 0); - (*usp) -= 2; + *xw = mget(USER_STACK_START + (*u) - 2); + mset(USER_STACK_START + (*u) - 2, 0); + (*u) -= 2; } static void POPyw() { - if (*usp < 2) + if (*u < 2) { xyw_memory[SYSTEM_ERROR] = XYW_ERROR_STACK_UNDERFLOW; return; } - *yw = mget(USER_STACK_START + (*usp) - 2); - mset(USER_STACK_START + (*usp) - 2, 0); - (*usp) -= 2; + *yw = mget(USER_STACK_START + (*u) - 2); + mset(USER_STACK_START + (*u) - 2, 0); + (*u) -= 2; } static void LDRx() { us_push(xyw_memory[*x]); }