ulas: Added .bank directive
authorLukas Krickl <lukas@krickl.dev>
Wed, 12 Mar 2025 05:17:11 +0000 (06:17 +0100)
committerLukas Krickl <lukas@krickl.dev>
Wed, 12 Mar 2025 05:17:11 +0000 (06:17 +0100)
man/ulas.5
src/ulas.c
src/ulas.h
tests/t0.s

index 18e772a201df5eb5c1ec749d8572955617c3473f..f2cc9270726860e559724ea1a151bd40c5424cdb 100644 (file)
@@ -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 <int>
+  Sets the current bank.
+  This is only used for symbol files.
+
 .SH SEE ALSO
 
   ulas(1) for a rference on how to use ulas.
index 673ee02e2d5e1e4bc506ccb8d9152dca8717c511..79d89ef5ea16806dc76bc503e70bbfed08a21716 100644 (file)
@@ -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:
index 129b068575af7d9de061f05df146cca416fb7630..1260b11086efec809a66cff38555ecbe7bfcb1e8 100644 (file)
@@ -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 <name>
   // set the current section
   ULAS_ASMDIR_SECTION,
+
+  // .bank <banknum>
+  // sets the current bank number
+  ULAS_ASMDIR_BANK
 };
 
 #define ULAS_INSTRTOKMAX 16
index 1a020d214f2b4a491072173d045f1ca1142be6bb..77e90b1c3a2c8c9c0af845b281e24e102bdd8529 100644 (file)
@@ -1,4 +1,5 @@
 .section test ; with comment
+.bank 1 + 2
 
 ; this is a sample assembly file 
 ; that can be read by tests.