From c4b81f0916ca9f7826552aa1b51a2d8d27ef8b3e Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Mon, 4 Jun 2018 12:18:37 -0400 Subject: Clean up linkerscript and add it as a Makefile target --- tools/make_shim.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'tools/make_shim.c') diff --git a/tools/make_shim.c b/tools/make_shim.c index 70da31d..fc60821 100644 --- a/tools/make_shim.c +++ b/tools/make_shim.c @@ -95,6 +95,8 @@ int main(int argc, char * argv[]) { } for (int arg_idx = optind; arg_idx < argc; arg_idx++) { + int last = -1; + int curr; eline[0] = 0; lineno = 0; fname = argv[arg_idx]; @@ -102,6 +104,7 @@ int main(int argc, char * argv[]) { if (file == NULL) RIP("Unable to open file"); while ((lineptr = fgets(line, sizeof(line), file)) != NULL) { + // Assume it's already sorted lineno++; unsigned short bank = 0; unsigned short pointer = 0; @@ -135,6 +138,7 @@ int main(int argc, char * argv[]) { bank = strtoul(lineptr, &end, 16); if (bank == 0 && end == lineptr) RIP("Unable to parse bank number"); + curr = (bank << 14) | (pointer & 0x3fff); // Main loop const char * section = NULL; @@ -157,10 +161,16 @@ int main(int argc, char * argv[]) { // Found section, but cannot shim it continue; - printf("SECTION \"Shim for %s\", %s[$%04X]", symbol, section, pointer); - if (bank) - printf(", BANK[$%04X]", bank); - printf("\n%s::\n\n", symbol); + if (curr != last) { + if (last != -1) + fputc('\n', stdout); + printf("SECTION \"Shim for %s\", %s[$%04X]", symbol, section, pointer); + if (bank) + printf(", BANK[$%04X]", bank); + printf("\n%s::\n", symbol); + last = curr; + } else + printf("%s::\n", symbol); fflush(stdout); } fclose(file); -- cgit v1.2.3