mlb: Added support for sections to mlb
authorLukas Krickl <lukas@krickl.dev>
Sun, 19 Jan 2025 07:00:06 +0000 (08:00 +0100)
committerLukas Krickl <lukas@krickl.dev>
Sun, 19 Jan 2025 07:00:06 +0000 (08:00 +0100)
This still needs testing.
It uses the current address at time of using .section as an offset so
that mlb files can be formatted correctly.

man/ulas.5
src/ulas.c
src/ulas.h

index 7a85c7786e2357855fc1d6cda23f5f38d46650b5..964b8810efa11ba7c72bc5ea0731288320242600 100644 (file)
@@ -141,7 +141,9 @@ The special value $ will evaluate to the current address.
 
 .SH section
   \.section <name>
-  Defines a section name. 
+  Defines a section name.
+  For mlb files .section will use the address (set via .org) present at the time of 
+  invoking .section as an offset address.
 
 .SH SEE ALSO
 
index d0b4a33a4dd050c59cbdc62e0f8e18ce25ef3d26..b38d4aa66a8eb2d6c5783d76fdca99b5c38257dc 100644 (file)
@@ -90,6 +90,7 @@ void ulas_nextpass(void) {
   ulas.chksm = 0;
   ulas.filename = ulas.initial_filename;
   ulas.section[0] = '\0'; // reset section
+  ulas.section_address = 0;
 
   for (int i = 0; i < ULAS_CHARCODEMAPLEN; i++) {
     ulas.charcodemap[i] = (char)i;
@@ -366,6 +367,11 @@ int ulas_symbolset(const char *cname, int scope, struct ulas_tok tok,
 }
 
 int ulas_symbolout_mlbloc(FILE *dst, long addr) {
+  if (ulas.section[0] != '\0') {
+    fprintf(dst, "%s:", ulas.section);
+    return (int)ulas.section_address;
+  }
+
   if (addr == -1) {
     fprintf(dst, "Unknown:");
     return 0;
@@ -2440,6 +2446,7 @@ int ulas_asmdirsection(FILE *dst, FILE *src, const char **line,
     return -1;
   }
   strncpy(ulas.section, ulas.tok.buf, ULAS_SECTIONMAX);
+  ulas.section_address = ulas.address;
   return 0;
 }
 
index fc67478d2db8c51c32a98a15354bea973eb97a82..43deaa73f65f477824b3027fd2697fd60849de77 100644 (file)
@@ -319,7 +319,9 @@ struct ulas {
   // but cna be set with a directive
   char charcodemap[ULAS_CHARCODEMAPLEN];
   char section[ULAS_SECTIONMAX];
-
+  // where was the section defined?
+  unsigned int section_address; 
+    
   struct ulas_arch arch;
 };