all repos — xyw @ 9f4cfdee9a26b6cdb7e15bcacfab3917946f29db

A minimal virtual machine and assembler for terminals.

Implementing support for image loading and executing (some tests failing).
h3rald h3rald@h3rald.com
Thu, 23 Jul 2026 15:46:51 +0200
commit

9f4cfdee9a26b6cdb7e15bcacfab3917946f29db

parent

bf8a8145b86d19e0a944060a34c2d07ed37ef161

3 files changed, 25 insertions(+), 1 deletions(-)

jump to
A examples/launcher.xyw

@@ -0,0 +1,21 @@

+.include "lib/macros.xyw" + +executing puts JSRw fileops.xim puts JSRw NL PUTC +fileops.xim system.image_exec STW + +executing puts JSRw helloworld.xim puts JSRw NL PUTC +helloworld.xim system.image_exec STW + +done puts JSRw NL PUTC +HLT + +.label executing + .string "Executing: " +.label done + .string "Done!" +.label fileops.xim + .string "fileops.xim" +.label helloworld.xim + .string "helloworld.xim" + +.include "lib/puts.xyw"
M test.shtest.sh

@@ -10,6 +10,7 @@ "run_test print-args.xyw test1 test2 -- assert_output_equals \$'print-args.xim, test1, test2\\n'"

"run_test factorial8.xyw assert_output_equals \$'120\\n'" "run_test factorial16.xyw assert_output_equals \$'5040\\n'" "run_test fileops.xyw assert_output_equals \$'This is a test file.\\nIt has multiple lines.\\n'" + "run_test launcher.xyw assert_output_equals \$'Executing: fileops.xim\\n This is a test file.\\nIt has multiple lines.\\nExecuting: helloworld.xim\\n Hello, World!\\nDone!\\n'" ) ### Helper functions
M xywrun.cxywrun.c

@@ -550,6 +550,7 @@ }

static void save_snapshot(xyw_image_snapshot *snap) { + XYW_DBG("== Saving snapshot"); memcpy(snap->memory, xyw_memory, sizeof(xyw_memory)); memcpy(snap->user_stack, user_stack, sizeof(user_stack)); memcpy(snap->system_stack, system_stack, sizeof(system_stack));

@@ -567,6 +568,7 @@ }

static void restore_snapshot(xyw_image_snapshot *snap) { + XYW_DBG("== Restoring snapshot"); memcpy(xyw_memory, snap->memory, sizeof(xyw_memory)); memcpy(user_stack, snap->user_stack, sizeof(user_stack)); memcpy(system_stack, snap->system_stack, sizeof(system_stack));

@@ -653,7 +655,7 @@ 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 - /* HLT */ case 0x00: return 0; + /* HLT */ case 0x00: xyw_memory[SYSTEM_STATE] &= ~SYSTEM_STATE_RUNNING; break; /* NOP */ case 0x01: break; /* 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); )