From: Lukas Krickl Date: Mon, 4 Dec 2023 19:45:32 +0000 (+0100) Subject: Added .fill instruction X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=db4341c0d471844ca1bea9a648210f46d0d118af;p=ulas%2F.git Added .fill instruction --- diff --git a/src/ulas.c b/src/ulas.c index 738ec60..f5cc43d 100644 --- a/src/ulas.c +++ b/src/ulas.c @@ -2138,6 +2138,43 @@ int ulas_asmdirdef(const char **line, unsigned long n) { return ulas_asmdirset(line, n, t); } +int ulas_asmdirfill(FILE *dst, const char **line, unsigned long n, int *rc) { + // fill , + int written = 0; + + int ival = ulas_intexpr(line, n, rc); + char val = (char)ival; + if (*rc == -1) { + return 0; + } + + ulas_tok(&ulas.tok, line, n); + struct ulas_tok t = + ulas_totok(ulas.tok.buf, strnlen(ulas.tok.buf, ulas.tok.maxlen), rc); + + if (*rc == -1 || t.type != ',') { + ULASERR("Expected ,\n"); + return 0; + } + + int count = ulas_intexpr(line, n, rc); + if (count < 0) { + ULASERR("Count must be positive\n"); + return 0; + } + + if (*rc == -1) { + return 0; + } + + for (int i = 0; i < count; i++) { + ulas_asmout(dst, &val, 1); + written++; + } + + 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]; @@ -2195,10 +2232,12 @@ int ulas_asmline(FILE *dst, FILE *src, const char *line, unsigned long n) { case ULAS_ASMDIR_BYTE: other_writes += ulas_asmdirbyte(dst, &line, n, &rc); break; - case ULAS_ASMDIR_STR: case ULAS_ASMDIR_FILL: + other_writes += ulas_asmdirfill(dst, &line, n, &rc); + break; case ULAS_ASMDIR_PAD: case ULAS_ASMDIR_INCBIN: + case ULAS_ASMDIR_STR: case ULAS_ASMDIR_NONE: ULASPANIC("asmdir not implemented\n"); break; diff --git a/tests/t0.bin b/tests/t0.bin index 9afc304..44cd58b 100644 Binary files a/tests/t0.bin and b/tests/t0.bin differ diff --git a/tests/t0.s b/tests/t0.s index 00713f3..3d195af 100644 --- a/tests/t0.s +++ b/tests/t0.s @@ -87,3 +87,4 @@ l2: ld a, s1 .db 1, 2, 3 +.fill 1, 3