From c5c1a0e2cec46f2fe02e5ab762fe5d8bd702e874 Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Thu, 22 Feb 2024 07:04:29 +0100 Subject: [PATCH] WIP: added -a option. Fixed missing break when adding incpath --- src/main.c | 11 +++++++++-- src/ulas.c | 2 +- src/ulas.h | 2 ++ src/uldas.c | 3 +++ 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/main.c b/src/main.c index b346ffb..3386281 100644 --- a/src/main.c +++ b/src/main.c @@ -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; diff --git a/src/ulas.c b/src/ulas.c index ef62a7b..46d10aa 100644 --- a/src/ulas.c +++ b/src/ulas.c @@ -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; diff --git a/src/ulas.h b/src/ulas.h index 29c28c2..616c982 100644 --- a/src/ulas.h +++ b/src/ulas.h @@ -132,6 +132,8 @@ struct ulas_config { int preproc_only; int disas; + unsigned int org; + // all include search paths char **incpaths; unsigned int incpathslen; diff --git a/src/uldas.c b/src/uldas.c index 5202b1b..09be3b8 100644 --- a/src/uldas.c +++ b/src/uldas.c @@ -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; } -- 2.30.2