From: Lukas Krickl Date: Wed, 12 Mar 2025 05:17:11 +0000 (+0100) Subject: ulas: Added .bank directive X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=8a4c6a91684eccfb424bd8ebd28c9ecaff37f2e4;p=ulas%2F.git ulas: Added .bank directive --- diff --git a/man/ulas.5 b/man/ulas.5 index 18e772a..f2cc927 100644 --- a/man/ulas.5 +++ b/man/ulas.5 @@ -148,6 +148,11 @@ The special value $ will evaluate to the current address. For mlb files ulas offers a few pre-defined section names that get translated to their respective mlb names (wram == GbWorkRam; prgrom == GbPrgRom). +.SH bank + \.bank + Sets the current bank. + This is only used for symbol files. + .SH SEE ALSO ulas(1) for a rference on how to use ulas. diff --git a/src/ulas.c b/src/ulas.c index 673ee02..79d89ef 100644 --- a/src/ulas.c +++ b/src/ulas.c @@ -2487,6 +2487,12 @@ int ulas_asmdirsection(FILE *dst, FILE *src, const char **line, return 0; } +int ulas_asmdirbank(FILE *dst, FILE *src, const char **line, + unsigned long n, int *rc) { + ULAS_EVALEXPRS(ulas.bank = ulas_intexpr(line, strnlen(*line, n), rc)); + return *rc; +} + 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]; @@ -2539,6 +2545,7 @@ int ulas_asmline(FILE *dst, FILE *src, const char *line, unsigned long n) { ULAS_ASMSTR_CHR, ULAS_ASMSTR_REP, ULAS_ASMSTR_SECTION, + ULAS_ASMSTR_BANK, NULL}; enum ulas_asmdir dirs[] = { ULAS_ASMDIR_ORG, ULAS_ASMDIR_SET, @@ -2548,7 +2555,7 @@ int ulas_asmline(FILE *dst, FILE *src, const char *line, unsigned long n) { ULAS_ASMDIR_CHKSM, ULAS_ASMDIR_ADV, ULAS_ASMDIR_SET_ENUM_DEF, ULAS_ASMDIR_DEFINE_ENUM, ULAS_ASMDIR_SETCHRCODE, ULAS_ASMDIR_CHR, - ULAS_ASMDIR_REP, ULAS_ASMDIR_SECTION}; + ULAS_ASMDIR_REP, ULAS_ASMDIR_SECTION, ULAS_ASMDIR_BANK}; enum ulas_asmdir dir = ULAS_ASMDIR_NONE; @@ -2615,6 +2622,9 @@ int ulas_asmline(FILE *dst, FILE *src, const char *line, unsigned long n) { case ULAS_ASMDIR_SECTION: rc = ulas_asmdirsection(dst, src, &line, n); break; + case ULAS_ASMDIR_BANK: + rc = ulas_asmdirbank(dst, src, &line, n, &rc); + break; case ULAS_ASMDIR_PAD: // TODO: pad is the same as .fill n, $ - n case ULAS_ASMDIR_NONE: diff --git a/src/ulas.h b/src/ulas.h index 129b068..1260b11 100644 --- a/src/ulas.h +++ b/src/ulas.h @@ -78,6 +78,7 @@ extern unsigned long defslen; #define ULAS_ASMSTR_CHR ".chr" #define ULAS_ASMSTR_REP ".rep" #define ULAS_ASMSTR_SECTION ".section" +#define ULAS_ASMSTR_BANK ".bank" // configurable tokens #define ULAS_TOK_COMMENT ';' @@ -469,6 +470,10 @@ enum ulas_asmdir { // .section // set the current section ULAS_ASMDIR_SECTION, + + // .bank + // sets the current bank number + ULAS_ASMDIR_BANK }; #define ULAS_INSTRTOKMAX 16 diff --git a/tests/t0.s b/tests/t0.s index 1a020d2..77e90b1 100644 --- a/tests/t0.s +++ b/tests/t0.s @@ -1,4 +1,5 @@ .section test ; with comment +.bank 1 + 2 ; this is a sample assembly file ; that can be read by tests.