Mercurial > repos > blastem
comparison dis.c @ 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 | 3eced113081c |
children | c4bfbf55d418 |
comparison
equal
deleted
inserted
replaced
946:6b90ec50daf3 | 947:d29722e3359c |
---|---|
6 #include "68kinst.h" | 6 #include "68kinst.h" |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 #include <stdlib.h> | 8 #include <stdlib.h> |
9 #include <string.h> | 9 #include <string.h> |
10 #include <stdarg.h> | 10 #include <stdarg.h> |
11 #include <ctype.h> | |
11 #include "vos_program_module.h" | 12 #include "vos_program_module.h" |
12 #include "tern.h" | 13 #include "tern.h" |
14 #include "util.h" | |
13 | 15 |
14 uint8_t visited[(16*1024*1024)/16]; | 16 uint8_t visited[(16*1024*1024)/16]; |
15 uint16_t label[(16*1024*1024)/8]; | 17 uint16_t label[(16*1024*1024)/8]; |
16 | 18 |
17 void fatal_error(char *format, ...) | 19 void fatal_error(char *format, ...) |
121 } else { | 123 } else { |
122 return m68k_default_label_fun(dst, address, NULL); | 124 return m68k_default_label_fun(dst, address, NULL); |
123 } | 125 } |
124 } | 126 } |
125 | 127 |
128 char * strip_ws(char * text) | |
129 { | |
130 while (*text && (!isprint(*text) || isblank(*text))) | |
131 { | |
132 text++; | |
133 } | |
134 char * ret = text; | |
135 text = ret + strlen(ret) - 1; | |
136 while (text > ret && (!isprint(*text) || isblank(*text))) | |
137 { | |
138 *text = 0; | |
139 text--; | |
140 } | |
141 return ret; | |
142 } | |
143 | |
126 int main(int argc, char ** argv) | 144 int main(int argc, char ** argv) |
127 { | 145 { |
128 long filesize; | 146 long filesize; |
129 unsigned short *filebuf; | 147 unsigned short *filebuf; |
130 char disbuf[1024]; | 148 char disbuf[1024]; |
131 m68kinst instbuf; | 149 m68kinst instbuf; |
132 unsigned short * cur; | 150 unsigned short * cur; |
133 deferred *def = NULL, *tmpd; | 151 deferred *def = NULL, *tmpd; |
134 | 152 |
135 uint8_t labels = 0, addr = 0, only = 0, vos = 0, reset = 0; | 153 uint8_t labels = 0, addr = 0, only = 0, vos = 0, reset = 0; |
154 tern_node * named_labels = NULL; | |
136 | 155 |
137 for(uint8_t opt = 2; opt < argc; ++opt) { | 156 for(uint8_t opt = 2; opt < argc; ++opt) { |
138 if (argv[opt][0] == '-') { | 157 if (argv[opt][0] == '-') { |
139 FILE * address_log; | 158 FILE * address_log; |
140 switch (argv[opt][1]) | 159 switch (argv[opt][1]) |
165 fprintf(stderr, "Failed to open %s for reading\n", argv[opt]); | 184 fprintf(stderr, "Failed to open %s for reading\n", argv[opt]); |
166 exit(1); | 185 exit(1); |
167 } | 186 } |
168 while (fgets(disbuf, sizeof(disbuf), address_log)) { | 187 while (fgets(disbuf, sizeof(disbuf), address_log)) { |
169 if (disbuf[0]) { | 188 if (disbuf[0]) { |
170 uint32_t address = strtol(disbuf, NULL, 16); | 189 char *end; |
190 uint32_t address = strtol(disbuf, &end, 16); | |
171 if (address) { | 191 if (address) { |
172 def = defer(address, def); | 192 def = defer(address, def); |
173 reference(address); | 193 reference(address); |
194 if (*end == '=') { | |
195 named_labels = add_label(named_labels, strip_ws(end+1), address); | |
196 } | |
174 } | 197 } |
175 } | 198 } |
176 } | 199 } |
177 } | 200 } |
178 } else { | 201 } else { |
179 uint32_t address = strtol(argv[opt], NULL, 16); | 202 char *end; |
203 uint32_t address = strtol(argv[opt], &end, 16); | |
180 def = defer(address, def); | 204 def = defer(address, def); |
181 reference(address); | 205 reference(address); |
206 if (*end == '=') { | |
207 named_labels = add_label(named_labels, end+1, address); | |
208 } | |
182 } | 209 } |
183 } | 210 } |
184 | 211 |
185 FILE * f = fopen(argv[1], "rb"); | 212 FILE * f = fopen(argv[1], "rb"); |
186 fseek(f, 0, SEEK_END); | 213 fseek(f, 0, SEEK_END); |
187 filesize = ftell(f); | 214 filesize = ftell(f); |
188 fseek(f, 0, SEEK_SET); | 215 fseek(f, 0, SEEK_SET); |
189 | 216 |
190 tern_node * named_labels = NULL; | |
191 char int_key[MAX_INT_KEY_SIZE]; | 217 char int_key[MAX_INT_KEY_SIZE]; |
192 uint32_t address_off, address_end; | 218 uint32_t address_off, address_end; |
193 if (vos) | 219 if (vos) |
194 { | 220 { |
195 vos_program_module header; | 221 vos_program_module header; |