From db4341c0d471844ca1bea9a648210f46d0d118af Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Mon, 4 Dec 2023 20:45:32 +0100 Subject: [PATCH] Added .fill instruction --- src/ulas.c | 41 ++++++++++++++++++++++++++++++++++++++++- tests/t0.bin | Bin 101 -> 104 bytes tests/t0.s | 1 + 3 files changed, 41 insertions(+), 1 deletion(-) 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 9afc30490e7a3f48857b954fa7cc084c14431fe0..44cd58b8f7d60f8e8a46237e6ed3dd3521264b29 100644 GIT binary patch delta 8 PcmYezn2^fM$jAr)3v&U< delta 4 Lcmc~uosbFu1XuyX 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 -- 2.30.2