From e60cc5a36c148ef5ea0e38bcc848cf32f2b54a18 Mon Sep 17 00:00:00 2001 From: Ian C Date: Wed, 11 May 2016 09:18:52 +0100 Subject: Added option to import only labels from library. --- doc/casm.html | 5 +++-- src/casm.c | 18 +++++++++++++++++- src/libout.c | 19 ++++++++++++++----- src/state.c | 6 ++++++ src/state.h | 5 +++++ src/test/link | 2 +- 6 files changed, 46 insertions(+), 9 deletions(-) diff --git a/doc/casm.html b/doc/casm.html index 5628b8d..e0f0299 100644 --- a/doc/casm.html +++ b/doc/casm.html @@ -346,10 +346,11 @@ the skipped bytes unless the optional fill is supplied. -import filename +import filename[, labels] -Includes a simple library file as generated by casm. See the section on simple library files for more details. +Includes a simple library file as generated by casm. See the section on simple library files for more details. If the optional second +argument is set to labels then only the label values are imported. diff --git a/src/casm.c b/src/casm.c index 866b32d..9e5c68e 100644 --- a/src/casm.c +++ b/src/casm.c @@ -511,7 +511,23 @@ static CommandStatus IMPORT(const char *label, int argc, char *argv[], { CMD_ARGC_CHECK(2); - return LibLoad(argv[1], LibLoadAll, err, errsize) ? CMD_OK : CMD_FAILED; + if (argc == 3) + { + if (CompareString(argv[2], "labels")) + { + return LibLoad(argv[1], LibLoadLabels, err, errsize) ? + CMD_OK : CMD_FAILED; + } + else + { + snprintf(err, errsize, "%s: unknown argument %s", argv[0], argv[2]); + return CMD_FAILED; + } + } + else + { + return LibLoad(argv[1], LibLoadAll, err, errsize) ? CMD_OK : CMD_FAILED; + } } diff --git a/src/libout.c b/src/libout.c index 5aed18c..f9ca74f 100644 --- a/src/libout.c +++ b/src/libout.c @@ -149,8 +149,12 @@ int LibLoad(const char *filename, LibLoadOption opt, int min; int len; int old_pc; + unsigned old_bank; Byte *p; + old_bank = Bank(); + old_pc = PC(); + bank = ReadNumber(fp); min = ReadNumber(fp); len = ReadNumber(fp); @@ -159,20 +163,25 @@ int LibLoad(const char *filename, LibLoadOption opt, fread(buff, 1, len, fp); - old_pc = PC(); - SetPC(min); p = buff; - while(len-- > 0) + if (opt != LibLoadLabels) { - PCWrite(*p++); + while(len-- > 0) + { + PCWrite(*p++); + } } SetPC(old_pc); + SetAddressBank(old_bank); } - LabelReadBlob(fp); + if (opt != LibLoadMemory) + { + LabelReadBlob(fp); + } fclose(fp); diff --git a/src/state.c b/src/state.c index 0e47a05..8a8d227 100644 --- a/src/state.c +++ b/src/state.c @@ -188,6 +188,12 @@ void SetAddressBank(unsigned b) } +unsigned Bank(void) +{ + return currbank; +} + + void SetWordMode(WordMode mode) { wmode = mode; diff --git a/src/state.h b/src/state.h index 100aaeb..137670e 100644 --- a/src/state.h +++ b/src/state.h @@ -62,6 +62,11 @@ void ClearState(void); void SetAddressBank(unsigned bank); +/* Get the current bank +*/ +unsigned Bank(void); + + /* Move onto the next pass */ void NextPass(void); diff --git a/src/test/link b/src/test/link index ec09bd6..b30036e 100644 --- a/src/test/link +++ b/src/test/link @@ -3,4 +3,4 @@ option list-labels,all import "lib2.lib" - import "lib1.lib" + import "lib1.lib",labels -- cgit v1.2.3