From 4de9fa64f1402bfd861e3f1a5c901aea92e9fa80 Mon Sep 17 00:00:00 2001 From: ketmar Date: Fri, 7 Sep 2012 10:59:00 +0000 Subject: [PATCH] urasm: fixup table writer FossilOrigin-Name: fb5bdf16fec276a906a6994a74a245ff8f1fd55fc7892526d61d7cf860199d60 --- src/urasm.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/urasm.c b/src/urasm.c index b08b320..cc5a3a6 100644 --- a/src/urasm.c +++ b/src/urasm.c @@ -767,8 +767,8 @@ static int isLabelDefinedOrKnown (const char *name, uint16_t addr, int qtype) { static void fixupOperandCB (const URAOperand *op, uint16_t opdestaddr, uint16_t opaddr, int fixuptype, int size) { if (pass == 1) { - static const char *n[4] = {"none", "word", "low", "high"}; - fprintf(stderr, "%d: fixupOperandCB: destaddr=#%04x; addr=#%04x; pc=#%04X; fixuptype=%s\n", size, opdestaddr, opaddr, pc, n[fixuptype]); + //static const char *n[4] = {"none", "word", "low", "high"}; + //fprintf(stderr, "%d: fixupOperandCB: destaddr=#%04x; addr=#%04x; pc=#%04X; fixuptype=%s\n", size, opdestaddr, opaddr, pc, n[fixuptype]); addFixup(opdestaddr, opaddr, fixuptype, size); } } @@ -1097,12 +1097,28 @@ static MAYBE_UNUSED SourceLine *findNextInstruction (const char *name) { /////////////////////////////////////////////////////////////////////////////// // writers // +static int optWriteFixups = 0; static int optRunTape = 1; static int optRunDMB = 1; static int optTapExt = 0; /* set '.tap' extension (but don't write tape; this for inline tape blocks) */ static int optSNA48 = 1; +/////////////////////////////////////////////////////////////////////////////// +static void writeFixups (void) { + FILE *fo = fopen("zfixuptable.txt", "w"); + // + if (fo == NULL) fatal("can't write fixup file"); + fprintf(fo, "; addr dadr sz\n"); + for (const FixupItem *fx = fixlisthead; fx != NULL; fx = fx->next) { + static const char type[4] = "NWLH"; + fprintf(fo, "%c #%04x #%04x %d\n", type[fx->fixuptype], fx->opaddr, fx->opdestaddr, fx->size); + } + fclose(fo); +} + + +/////////////////////////////////////////////////////////////////////////////// /* return 'found' flag */ static int findChunkFrom (int addr, int *start, int *len) { if (addr < 0) addr = 0; @@ -2730,6 +2746,7 @@ static struct option longOpts[] = { {"none", 0, NULL, 'n'}, {"help", 0, NULL, 'h'}, {"hob", 0, NULL, 'H'}, + {"fixups", 0, NULL, 'H'}, {NULL, 0, NULL, 0} }; @@ -2753,6 +2770,7 @@ static void usage (const char *pname) { " -B --autodmb write DMB file with autostart\n" " -H --hob write HoBeta code file(s)\n" " -n --none write nothing\n" + " -F --fixups write fixup file 'zfixuptable.txt'\n" " -h --help this help\n"); } @@ -2778,7 +2796,7 @@ int main (int argc, char *argv[]) { tapeLoaderName[0] = 0; // printf("urasm v%d.%d.%d, compile date: %s %s\n", VERSION_HI, VERSION_MID, VERSION_LO, __DATE__, __TIME__); - while ((c = getopt_long(argc, argv, "sStTbBrnhH", longOpts, NULL)) >= 0) { + while ((c = getopt_long(argc, argv, "sStTbBrnhHF", longOpts, NULL)) >= 0) { switch (c) { case 'S': /*optRunSNA = 1;*/ optSNA48 = 0; optWriteType = 's'; optWTChanged = 1; break; case 's': /*optRunSNA = 0;*/ optSNA48 = 1; optWriteType = 's'; optWTChanged = 1; break; @@ -2789,6 +2807,7 @@ int main (int argc, char *argv[]) { case 'H': optWriteType = 'H'; optWTChanged = 1; break; case 'r': case 'n': optWriteType = c; optWTChanged = 1; break; case 'h': usage(pname); res = 0; goto earlyerrquit; + case 'F': optWriteFixups = 1; break; case '?': return 1; } } @@ -2845,6 +2864,7 @@ int main (int argc, char *argv[]) { case 'H': saveHob(oc); break; } free(oc); + if (optWriteFixups) writeFixups(); } } else { fprintf(stderr, "ERROR: loading error!\n"); -- 2.11.4.GIT