all repos — xyw @ 96c722bf450bc2395e24f95b7d65eb692a1d8203

A minimal virtual machine and assembler for terminals.

Refactoring (leveraging load_and_lunch function, removing duplications)
h3rald h3rald@h3rald.com
Fri, 24 Jul 2026 13:42:00 +0200
commit

96c722bf450bc2395e24f95b7d65eb692a1d8203

parent

e82e14a573af6f5ebeecdf290be8f1c8ee6f3375

1 files changed, 5 insertions(+), 28 deletions(-)

jump to
M xywrun.cxywrun.c

@@ -829,36 +829,13 @@

//// Main run function int xyw_run(const char *input) { - // Load bytecode into memory - FILE *fp = fopen(input, "rb"); - if (!fp) + atexit(xyw_teardown_devices); + + if (load_and_launch(input, NULL) != 0) { - fprintf(stderr, "Error - Could not open file [%s]\n", input); return -1; } - size_t bytes_read = fread(&xyw_memory[USER_MEMORY_START], 1, MEMORY_SIZE - USER_MEMORY_START, fp); - if (bytes_read == 0) - { - fprintf(stderr, "Error - Could not read file contents [%s]\n", input); - fclose(fp); - return -1; - } - XYW_DBG("Loaded %zu bytes into memory\n", bytes_read); - fclose(fp); - xyw_memory[SYSTEM_STATE] |= SYSTEM_STATE_RUNNING; - // Setup devices - for (int i = 0; i < XYW_TOTAL_DEVICES; i++) - { - if (xyw_devices[i].setup) - { - xyw_devices[i].setup(xyw_devices[i].data); - } - } - atexit(xyw_teardown_devices); - // Set direct page to device page by default - xyw_memory[SYSTEM_PAGE] = 0xff; - int eval_result = xyw_eval(0x0000); - - return eval_result; + XYW_DBG("Loaded image into memory\n"); + return xyw_eval(0x0000); }