From: Lukas Krickl Date: Tue, 5 Dec 2023 18:56:23 +0000 (+0100) Subject: Added .str directive X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=5a2819874f3a30b7bbd61d4443ec45f6ac93e910;p=ulas%2F.git Added .str directive --- diff --git a/src/ulas.c b/src/ulas.c index 44938ec..ea96dc8 100644 --- a/src/ulas.c +++ b/src/ulas.c @@ -2223,6 +2223,28 @@ int ulas_asmdirfill(FILE *dst, const char **line, unsigned long n, int *rc) { return written; } +int ulas_asmdirstr(FILE *dst, const char **line, unsigned long n, int *rc) { + // .str expr, expr, expr + struct ulas_tok t; + int written = 0; + memset(&t, 0, sizeof(t)); + + do { + char *s = ulas_strexpr(line, n, rc); + long len = strlen(s); + ulas_asmout(dst, s, len); + + written += len; + if (ulas_tok(&ulas.tok, line, n) > 0) { + t = ulas_totok(ulas.tok.buf, strnlen(ulas.tok.buf, ulas.tok.maxlen), rc); + } else { + break; + } + } while (*rc != -1 && t.type == ','); + + return written; +} + int ulas_asmline(FILE *dst, FILE *src, const char *line, unsigned long n) { // this buffer is written both to dst and to verbose output char outbuf[ULAS_OUTBUFMAX]; @@ -2283,8 +2305,10 @@ int ulas_asmline(FILE *dst, FILE *src, const char *line, unsigned long n) { case ULAS_ASMDIR_FILL: other_writes += ulas_asmdirfill(dst, &line, n, &rc); break; - case ULAS_ASMDIR_INCBIN: case ULAS_ASMDIR_STR: + other_writes += ulas_asmdirstr(dst, &line, n, &rc); + break; + case ULAS_ASMDIR_INCBIN: case ULAS_ASMDIR_PAD: // TODO: pad is the same as .fill n, $ - n case ULAS_ASMDIR_NONE: diff --git a/tests/t0.bin b/tests/t0.bin index 79fe45a..5f3faed 100644 Binary files a/tests/t0.bin and b/tests/t0.bin differ diff --git a/tests/t0.s b/tests/t0.s index 0faea94..f3999dc 100644 --- a/tests/t0.s +++ b/tests/t0.s @@ -91,3 +91,5 @@ l2: .fill 1, 0x180-$ ; fill until 0x180 nop .def str s2 = "Hello" + +.str "test1", "test2"