From 0e7a1a391d8c4a99e9b68df827da8615c7669b8f Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Sat, 24 Feb 2024 07:50:29 +0100 Subject: [PATCH] WIP: disas functionality --- src/uldas.c | 48 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/src/uldas.c b/src/uldas.c index 15cddab..d0e978a 100644 --- a/src/uldas.c +++ b/src/uldas.c @@ -7,12 +7,54 @@ 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); + char buf[ULAS_OUTBUFMAX]; + memset(buf, 0, ULAS_OUTBUFMAX); + unsigned long read = 0; - return 0; + // find the correct instructions + // needs to match every byte! + // first read max outbuf + read = fread(buf, 1, ULAS_OUTBUFMAX, src); + if (read == 0) { + return 0; + } + + // now find the instruction that matches all + // read bytes + // -> then reset src's read buffer to the srctell + actual instruction's + // length if nothing matches simply output a .db for the first byte and return + for (int i = 0; ulas.arch.instrs[i].name; i++) { + const struct ulas_instr *instr = &ulas.arch.instrs[i]; + + // test all instruction's contents + for (int j = 0; instr->data[j]; j++) { + unsigned short dat = instr->data[j]; + if (dat == ULAS_DATZERO) { + dat = 0; + } + + // do we even have enough data? + if (j >= read) { + break; + } + + switch (dat) { + case ULAS_E8: + case ULAS_A8: + break; + case ULAS_E16: + case ULAS_A16: + break; + default: + break; + } + } + } + + return 1; } +// TODO: implement label generation int ulas_dasm(FILE *src, FILE *dst) { // pass 1: run and collect labels // pass 2: run and output to file -- 2.30.2