From: Lukas Krickl Date: Thu, 22 Feb 2024 18:38:19 +0000 (+0100) Subject: WIP: disasm X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=40b3b16ba3da8087f02dfbe6681127acefa343ec;p=ulas%2F.git WIP: disasm --- diff --git a/src/uldas.c b/src/uldas.c index cac2532..15cddab 100644 --- a/src/uldas.c +++ b/src/uldas.c @@ -1,17 +1,28 @@ #include "uldas.h" +// dasm the next instruction +// if there are no more bytes to be read, return 0 +// on error return -1 +// otherwise return 1 +int ulas_dasm_next(FILE *src, FILE *dst) { + unsigned long srctell = ftell(src); + // read n bytes (as many as in instruction) + char outbuf[ULAS_OUTBUFMAX]; + memset(outbuf, 0, ULAS_OUTBUFMAX); + + return 0; +} + int ulas_dasm(FILE *src, FILE *dst) { - // pass 1: run and collect labels + // pass 1: run and collect labels // pass 2: run and output to file - - // TODO: the instruction list should be sorted so we can search it faster - // but for now we just do it as a linear search - - unsigned long srctell = ftell(src); - - int c = '\0'; - while (fgetc(src) != EOF) { + + int rc = 0; + while ((rc = ulas_dasm_next(src, dst)) > 0) { + if (rc == -1) { + return -1; + } } - return 0; + return rc; }