From 393556d2fc70dc0def5a6bb0463daf234ef23e36 Mon Sep 17 00:00:00 2001 From: Ian C Date: Tue, 17 May 2016 08:38:47 +0100 Subject: Added support for 24 bit address labels. * Also fixes bug where bank wasn't reset between passes. --- doc/casm.html | 35 +++++++++++++++++++++++++++++++++++ src/casm.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- src/label.c | 2 +- src/test/lib2 | 3 ++- src/test/link | 4 ++-- 5 files changed, 95 insertions(+), 5 deletions(-) diff --git a/doc/casm.html b/doc/casm.html index 2e95ccc..7696136 100644 --- a/doc/casm.html +++ b/doc/casm.html @@ -454,6 +454,41 @@ word
+

Options

+ +

The core of CASM supports the following options that can be set via the +option command. +

+ + + + + + + + + +
OptionDescription
+option address24, <on|off> + +Controls whether addresses have the current bank set in the high word, e.g. + +
+        org     $8000
+        bank    7
+
+        option  +address24
+label1: ; Label1 == $078000
+        
+        option  -address24
+label2: ; Label2 == $8000
+
+ +Note that the name is rather misleading; bank numbers are allowed to be greater +than 256. + +
+

Expressions

In any of the directives above, where a value is defined, an expression can diff --git a/src/casm.c b/src/casm.c index 1fa6d03..f1de63b 100644 --- a/src/casm.c +++ b/src/casm.c @@ -144,6 +144,48 @@ static ValTableHandler *valtable_handler; static int valtable_count; +/* ---------------------------------------- OPTIONS +*/ + +enum option_t +{ + OPT_ADDRESS24 +}; + +static const ValueTable option_set[] = +{ + {"address24", OPT_ADDRESS24}, + {NULL} +}; + + +typedef struct +{ + int address24; +} Options; + +static Options options = {FALSE}; + + +CommandStatus SetOption(int opt, int argc, char *argv[], + int quoted[], char *err, size_t errsize) +{ + CMD_ARGC_CHECK(1); + + switch(opt) + { + case OPT_ADDRESS24: + options.address24 = ParseTrueFalse(argv[0], FALSE); + break; + default: + break; + } + + return CMD_OK; +} + + + /* ---------------------------------------- PROTOS */ static void CheckLimits(void); @@ -154,6 +196,7 @@ static void RunPass(const char *name, FILE *, int depth); static void ProduceOutput(void); + /* ---------------------------------------- STATIC VALUE TABLE HANDLING */ static void PushValTableHandler(const ValueTable *t, @@ -637,6 +680,7 @@ int main(int argc, char *argv[]) return EXIT_FAILURE; } + PushValTableHandler(option_set, SetOption); PushValTableHandler(ListOptions(), ListSetOption); PushValTableHandler(MacroOptions(), MacroSetOption); PushValTableHandler(CodepageOptions(), CodepageSetOption); @@ -658,6 +702,7 @@ int main(int argc, char *argv[]) RunPass(argv[1], fp, 0); rewind(fp); + SetAddressBank(0); SetPC(0); MacroSetDefaults(); AliasClear(); @@ -717,6 +762,8 @@ static void InitProcessors(void) SetWordMode(cpu->word_mode); SetAddressSpace(cpu->address_space); + + options.address24 = FALSE; } @@ -843,7 +890,14 @@ static void RunPass(const char *name, FILE *fp, int depth) /* This may well be updated by a command, but easier to set anyway */ - LabelSet(label, PC(), type); + if (options.address24) + { + LabelSet(label, (Bank() << 16) | PC(), type); + } + else + { + LabelSet(label, PC(), type); + } } /* Check for no command/label only. Still record for macro though. diff --git a/src/label.c b/src/label.c index 449f4d0..440ea8d 100644 --- a/src/label.c +++ b/src/label.c @@ -503,7 +503,7 @@ void LabelDump(FILE *fp, int dump_private) for(f = 0; f < g->no_locals; f++) { - fprintf(fp, "; .%-*s = $%4.4x (%d)\n", MAX_LABEL_SIZE, + fprintf(fp, "; .%-*s = $%8.8x (%d)\n", MAX_LABEL_SIZE, g->locals[f].name, (unsigned)g->locals[f].value, g->locals[f].value); diff --git a/src/test/lib2 b/src/test/lib2 index a1c6224..a16febf 100644 --- a/src/test/lib2 +++ b/src/test/lib2 @@ -1,7 +1,8 @@ option output-file,lib2.lib option output-format,lib - org $8800 + option +address24 + org $078800 start_lib2: ld hl,$4321 diff --git a/src/test/link b/src/test/link index 41d11f1..ec09bd6 100644 --- a/src/test/link +++ b/src/test/link @@ -2,5 +2,5 @@ option +list option list-labels,all - import "lib2.lib",all,-$1000 - import "lib1.lib",all,$1000 + import "lib2.lib" + import "lib1.lib" -- cgit v1.2.3