Now writing to output file.
h3rald h3rald@h3rald.com
Thu, 27 Nov 2025 16:23:21 +0100
3 files changed,
15 insertions(+),
7 deletions(-)
M
xyw.c
→
xyw.c
@@ -116,7 +116,7 @@ {
const char *input_file = argv[1]; // Output file is the same as input but with .rom extension char output_file[256]; - snprintf(output_file, sizeof(output_file), "%.*s.rom", (int)(strlen(input_file) - 4), input_file); + snprintf(output_file, sizeof(output_file), "%.*s.xywi", (int)(strlen(input_file) - 4), input_file); if (xyw_assemble(input_file, output_file) != 0) { // TODO: Standardize errors
M
xywasm.c
→
xywasm.c
@@ -508,6 +508,8 @@ token_type = TOKEN_TYPE_SYMBOL;
return 0; } +//// Directive processing + static int process_directive_org(xyw_context *ctx) { xyw_token_terminator r = next_token(ctx);@@ -586,7 +588,6 @@ if (r == TOKEN_END_EOL || r == TOKEN_END_EOF || r == TOKEN_END_COMMENT)
{ break; } - // Store byte in memory data[ptr++] = (xyw_byte)token_value; } return 0;@@ -673,7 +674,7 @@ directive = 0;
return r; } -// Process and validate tokens +// Process and validate a token static int process_token(xyw_context *ctx) { if (token_length == 0)@@ -716,6 +717,7 @@ token_error("Unrecognized token");
return -1; } +// Get the next token from the input file (without processing it) static xyw_token_terminator next_token(xyw_context *ctx) { char c;@@ -828,13 +830,18 @@ xyw_context ctx;
ctx.file = (char *)input; ctx.line = 1; ctx.column = 1; - if (process_file(&ctx) != 0) { return -1; } - - (void)output; // TODO: write to output file - printf("Assembled %s successfully. Bytecode size: %d bytes\n", input, ptr); + FILE *fp = fopen(output, "wb"); + if (!fp) + { + fprintf(stderr, "Could not open output file for writing"); + return -1; + } + fwrite(data, 1, ptr, fp); + fclose(fp); + printf("Assembled %s successfully (%d bytes).\n", input, ptr); return 0; }