Minimal test working!
h3rald h3rald@h3rald.com
Mon, 01 Dec 2025 15:37:19 +0100
1 files changed,
10 insertions(+),
9 deletions(-)
jump to
M
xywrun.c
→
xywrun.c
@@ -109,6 +109,7 @@ {
xyw_memory[SYSTEM_ERROR] = XYW_ERROR_STACK_OVERFLOW; return; } + printf(" => %02X\n", val); user_stack[(*usp)++] = val; }@@ -120,6 +121,7 @@ xyw_memory[SYSTEM_ERROR] = XYW_ERROR_STACK_OVERFLOW;
return; } mset(USER_STACK_START + *usp, val); + printf(" => %04X\n", val); (*usp) += 2; }@@ -127,13 +129,15 @@ //// Instructions
static void PSH() { - xyw_byte val = xyw_memory[(*pc)++]; + (*pc)++; + xyw_byte val = xyw_memory[*pc]; us_push(val); } static void PSHw() { - xyw_word val = mget((*pc)++); + (*pc)++; + xyw_word val = mget(*pc); us_pushw(val); (*pc)++; }@@ -457,7 +461,7 @@ return -1;
} // Check header xyw_byte header[6]; - printf("Reading header from file [%s]\n", input); + dbg("Reading header from file [%s]\n", input); fread(header, 1, 6, fp); if (header[0] != 0x0F || header[1] != 'x' || header[2] != 'y' || header[3] != 'w' || header[4] != 0x00 || header[5] != 0xF0) {@@ -465,24 +469,21 @@ fprintf(stderr, "Error - Invalid file header [%s]\n", input);
fclose(fp); return -1; } - printf("File header OK\n"); + dbg("File header OK\n"); // Load the rest of the file into memory size_t bytes_read = fread(&xyw_memory[USER_MEMORY_START], 1, MEMORY_SIZE - USER_MEMORY_START, fp); - printf("Read %zu bytes into memory\n", bytes_read); if (bytes_read == 0) { fprintf(stderr, "Error - Could not read file contents [%s]\n", input); fclose(fp); return -1; } + dbg("Loaded %zu bytes into memory\n", bytes_read); fclose(fp); - printf("Starting execution...\n"); xyw_memory[SYSTEM_STATE] = 1; - printf("PC: %04X: opcode: %02X\n", *pc, xyw_memory[*pc]); while (xyw_memory[SYSTEM_STATE] && *pc < 20) { - printf("PC: %04X\n", *pc); - dbg("Executing opcode: %02X (%s)\n", xyw_memory[*pc], xyw_instructions[xyw_memory[*pc] & 0x1F]); + dbg("PC: %04X -> %02X (%s)\n", *pc, xyw_memory[*pc], xyw_instructions[xyw_memory[*pc] & 0x1F]); switch (xyw_memory[*pc]) { // clang-format off