changeset 947:d29722e3359c

Allow specification of named labels as command line arguments to the 68K disassembler
author Michael Pavone <pavone@retrodev.com>
date Sun, 10 Apr 2016 22:22:01 -0700
parents 6b90ec50daf3
children f87522554d7b
files dis.c
diffstat 1 files changed, 29 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/dis.c	Sat Mar 19 17:40:17 2016 -0700
+++ b/dis.c	Sun Apr 10 22:22:01 2016 -0700
@@ -8,8 +8,10 @@
 #include <stdlib.h>
 #include <string.h>
 #include <stdarg.h>
+#include <ctype.h>
 #include "vos_program_module.h"
 #include "tern.h"
+#include "util.h"
 
 uint8_t visited[(16*1024*1024)/16];
 uint16_t label[(16*1024*1024)/8];
@@ -123,6 +125,22 @@
 	}
 }
 
+char * strip_ws(char * text)
+{
+	while (*text && (!isprint(*text) || isblank(*text)))
+	{
+		text++;
+	}
+	char * ret = text;
+	text = ret + strlen(ret) - 1;
+	while (text > ret && (!isprint(*text) || isblank(*text)))
+	{
+		*text = 0;
+		text--;
+	}
+	return ret;
+}
+
 int main(int argc, char ** argv)
 {
 	long filesize;
@@ -133,6 +151,7 @@
 	deferred *def = NULL, *tmpd;
 
 	uint8_t labels = 0, addr = 0, only = 0, vos = 0, reset = 0;
+	tern_node * named_labels = NULL;
 
 	for(uint8_t opt = 2; opt < argc; ++opt) {
 		if (argv[opt][0] == '-') {
@@ -167,18 +186,26 @@
 				}
 				while (fgets(disbuf, sizeof(disbuf), address_log)) {
 				 	if (disbuf[0]) {
-						uint32_t address = strtol(disbuf, NULL, 16);
+						char *end;
+						uint32_t address = strtol(disbuf, &end, 16);
 						if (address) {
 							def = defer(address, def);
 							reference(address);
+							if (*end == '=') {
+								named_labels = add_label(named_labels, strip_ws(end+1), address);
+							}
 						}
 					}
 				}
 			}
 		} else {
-			uint32_t address = strtol(argv[opt], NULL, 16);
+			char *end;
+			uint32_t address = strtol(argv[opt], &end, 16);
 			def = defer(address, def);
 			reference(address);
+			if (*end == '=') {
+				named_labels = add_label(named_labels, end+1, address);
+			}
 		}
 	}
 
@@ -187,7 +214,6 @@
 	filesize = ftell(f);
 	fseek(f, 0, SEEK_SET);
 
-	tern_node * named_labels = NULL;
 	char int_key[MAX_INT_KEY_SIZE];
 	uint32_t address_off, address_end;
 	if (vos)