WIP: added -a option. Fixed missing break when adding incpath
authorLukas Krickl <lukas@krickl.dev>
Thu, 22 Feb 2024 06:04:29 +0000 (07:04 +0100)
committerLukas Krickl <lukas@krickl.dev>
Thu, 22 Feb 2024 06:04:29 +0000 (07:04 +0100)
src/main.c
src/ulas.c
src/ulas.h
src/uldas.c

index b346ffb3951b7cde735f0feb1773b3847393c68f..3386281c476c9682b60dc590b5a7c3ea3b9ff56b 100644 (file)
@@ -23,7 +23,7 @@
 #define ULAS_OPTS "hvVpd"
 
 // args with value
-#define ULAS_OPTS_ARG "o:l:s:i:w:"
+#define ULAS_OPTS_ARG "o:l:s:i:w:a:"
 
 #define ULAS_HELP(a, desc) printf("\t-%s\t%s\n", (a), desc);
 
@@ -34,7 +34,9 @@ unsigned long incpathslen = 0;
 
 void ulas_help(void) {
   printf("%s\n", ULAS_NAME);
-  printf("Usage %s [-%s] [-o=path] [input]\n\n", ULAS_NAME, ULAS_OPTS);
+  printf("Usage %s [-%s] [-o=path] [-i=path] [-l=path] [-a=initial-address] "
+         "[input]\n\n",
+         ULAS_NAME, ULAS_OPTS);
   ULAS_HELP("h", "display this help and exit");
   ULAS_HELP("V", "display version info and exit");
   ULAS_HELP("v", "verbose output");
@@ -43,6 +45,7 @@ void ulas_help(void) {
   ULAS_HELP("l=path", "Listing file");
   ULAS_HELP("s=path", "Symbols file");
   ULAS_HELP("i=path", "Add include search path");
+  ULAS_HELP("a=initial-address", "Initial starting address");
   ULAS_HELP("d", "Disassemble a file");
   ULAS_HELP("w=warning", "Toggle warnings: a=all, o=overflow");
 }
@@ -84,6 +87,10 @@ void ulas_getopt(int argc, char **argv, struct ulas_config *cfg) {
     case 'i':
       assert(incpathslen < ULAS_INCPATHSMAX);
       incpaths[incpathslen++] = strndup(optarg, ULAS_PATHMAX);
+      break;
+    case 'a':
+      cfg->org = strtol(optarg, NULL, 0);
+      break;
     case 'w':
       cfg->warn_level ^= warnings[(int)optarg[0]];
       break;
index ef62a7bf8f990a018c6e3f3385e8cbf514de3587..46d10aa9c8efdda1e1b4a3b36e2f5d5740511a67 100644 (file)
@@ -56,7 +56,7 @@ void ulas_nextpass(void) {
   ulas.scope = 1;
   ulas.line = 0;
   ulas.icntr = 0;
-  ulas.address = 0;
+  ulas.address = ulascfg.org;
   ulas.chksm = 0;
   ulas.filename = ulas.initial_filename;
 
index 29c28c295ecc769fd83b1f7893688f76a68196d1..616c9826c1fdd5276ba6e4146feb0c71fcca9eed 100644 (file)
@@ -132,6 +132,8 @@ struct ulas_config {
   int preproc_only;
   int disas;
 
+  unsigned int org;
+
   // all include search paths
   char **incpaths;
   unsigned int incpathslen;
index 5202b1b119fbac89c0d79d06313b7f7592a7d23a..09be3b82725e68542136978b808fe6916949deb1 100644 (file)
@@ -3,6 +3,9 @@
 int ulas_dasm(FILE *src, FILE *dst) {
   // pass 1: run and collect labels 
   // pass 2: run and output to file
+  
+  // TODO: the instruction list should be sorted so we can search it faster
+  // but for now we just do it as a linear search
 
   return 0;
 }