Various fixes related to argument save/restore and other issues.
h3rald h3rald@h3rald.com
Fri, 24 Jul 2026 13:15:37 +0200
M
Makefile
→
Makefile
@@ -13,7 +13,6 @@ LDFLAGS += -lwinmm
else ifeq ($(UNAME_S),Darwin) LDFLAGS += -framework AudioToolbox -framework CoreFoundation else ifeq ($(UNAME_S),Linux) - LDFLAGS += -lasound # Only link -lasound if the ALSA headers are actually installed # (libasound2-dev). Mirrors the __has_include check in beeper.c, which # falls back to the OSS backend when they're missing.
M
xywrun.c
→
xywrun.c
@@ -365,6 +365,16 @@
//// Internal VM state xyw_byte error_handler_entry_s = 0; +// Argument feeding state (CLI args) +static int arg_index = 1; +static int arg_char_pos = 0; + +// Sub-image argument feeding state +#define MAX_SUBIMAGE_ARGS 256 +static char subimage_args_buf[MAX_SUBIMAGE_ARGS]; +static int subimage_args_active = 0; +static int subimage_args_pos = 0; + static int process_events() { // Error handling@@ -383,7 +393,8 @@ *pc = on_error_handler;
} else { - // No error handler, halt execution + // No error handler: halt execution + xyw_memory[SYSTEM_STATE] &= ~SYSTEM_STATE_RUNNING; return xyw_memory[SYSTEM_ERROR]; } }@@ -400,6 +411,11 @@ xyw_byte s, u, x_val, y_val;
xyw_word pc_val, xw_val, yw_val; xyw_byte error_handler_entry_s; int argv_processed; + int arg_index; + int arg_char_pos; + char subimage_args_buf[MAX_SUBIMAGE_ARGS]; + int subimage_args_active; + int subimage_args_pos; } xyw_image_snapshot; static xyw_image_snapshot exec_stack[MAX_IMAGE_EXEC_DEPTH];@@ -453,12 +469,6 @@ error_handler_entry_s = 0;
xyw_argv_processed = 0; } -// Sub-image argument feeding state -#define MAX_SUBIMAGE_ARGS 256 -static char subimage_args_buf[MAX_SUBIMAGE_ARGS]; -static int subimage_args_active = 0; -static int subimage_args_pos = 0; - static int load_and_launch(const char *path, char *argstart) { FILE *fp = fopen(path, "rb");@@ -515,6 +525,11 @@ snap->xw_val = *xw;
snap->yw_val = *yw; snap->error_handler_entry_s = error_handler_entry_s; snap->argv_processed = xyw_argv_processed; + snap->arg_index = arg_index; + snap->arg_char_pos = arg_char_pos; + memcpy(snap->subimage_args_buf, subimage_args_buf, sizeof(subimage_args_buf)); + snap->subimage_args_active = subimage_args_active; + snap->subimage_args_pos = subimage_args_pos; } static void restore_snapshot(xyw_image_snapshot *snap)@@ -532,6 +547,11 @@ *xw = snap->xw_val;
*yw = snap->yw_val; error_handler_entry_s = snap->error_handler_entry_s; xyw_argv_processed = snap->argv_processed; + arg_index = snap->arg_index; + arg_char_pos = snap->arg_char_pos; + memcpy(subimage_args_buf, snap->subimage_args_buf, sizeof(subimage_args_buf)); + subimage_args_active = snap->subimage_args_active; + subimage_args_pos = snap->subimage_args_pos; // Devices with state outside xyw_memory (file cursor, clock timer target, // beeper device) don't roll back automatically — re-sync to a clean slate@@ -564,10 +584,6 @@ load_and_launch(path, argstart);
} //// Event dispatch (WAITING state) - -// Argument feeding state (CLI args) -static int arg_index = 1; -static int arg_char_pos = 0; // Feed the next external event and dispatch its handler. // Returns 1 if an event was dispatched, 0 if no more events.@@ -780,7 +796,7 @@ *x = saved_x;
*y = saved_y; *xw = saved_xw; *yw = saved_yw; - return 0; + return xyw_memory[SYSTEM_ERROR]; } static void xyw_teardown_devices(void)