aboutsummaryrefslogtreecommitdiff
path: root/dumptxt.c
diff options
context:
space:
mode:
authorB. Watson <yalhcru@gmail.com>2017-09-22 16:09:17 -0400
committerB. Watson <yalhcru@gmail.com>2017-09-22 16:09:17 -0400
commitb2cad8050e2077f09535607a829183a842023da7 (patch)
tree1f51d630c7596355b023a8cb4583fe46e3d066a7 /dumptxt.c
downloaddefender-b2cad8050e2077f09535607a829183a842023da7.tar.gz
initial commit
Diffstat (limited to 'dumptxt.c')
-rw-r--r--dumptxt.c88
1 files changed, 88 insertions, 0 deletions
diff --git a/dumptxt.c b/dumptxt.c
new file mode 100644
index 0000000..1c1c3cd
--- /dev/null
+++ b/dumptxt.c
@@ -0,0 +1,88 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+/* extract DSCII text from rom image, print in human-readable form.
+ usage: ./dumptxt startaddr endaddr
+ addresses are hex.
+
+ $C0: copyright symbol (double-wide), we print as 'c)'
+ $C1 - $DA: alphabet (but J Q Z are bogus-looking)
+ $B0 - $BA: numbers
+ $8D - carriage return (and newline), we print as 'nl'
+ $A0 - space
+
+ $F0-$FF set the color mask, but only in text drawn by draw_title_text.
+ We print these as cN where N is the low nybble.
+ */
+
+#define ROM "defender.rom"
+
+int main(int argc, char **argv) {
+ int i, start, end, needaddr = 1;
+ unsigned char buf[16384];
+ FILE *f = fopen(ROM, "rb");
+
+ if(argc != 3) {
+ fprintf(stderr, "Usage: %s startaddr endaddr\n give addresses in hex, e.g. %s b844 b86c\n", argv[0], argv[0]);
+ exit(1);
+ }
+
+ if(!f) {
+ perror(ROM);
+ exit(1);
+ }
+
+ fread(buf, 16384, 1, f);
+
+ start = (int)strtol(argv[1], 0, 16);
+ end = (int)strtol(argv[2], 0, 16);
+
+ if(start < 0x8000 || start >= 0xc000 || end < 0x8000 || end >= 0xc000) {
+ fprintf(stderr, "start/end addr(s) invalid or out of range, must be 8000-bfff\n");
+ exit(1);
+ }
+
+ fprintf(stderr, "dumping text from $%04x to $%04x\n", start, end);
+
+ for(i = start; i <= end; i++) {
+ unsigned char c = buf[i - 0x8000];
+
+ if(needaddr) {
+ printf("%04x: '", start);
+ needaddr = 0;
+ }
+
+ if(!c) {
+ putchar('\'');
+ putchar('\n');
+ needaddr = 1;
+ } else if(c >= 0xb0 && c <= 0xba) {
+ putchar(c - 0xb0 + '0');
+ } else if(c == 0xc0) {
+ putchar('c');
+ putchar(')');
+ } else if(c == 0xa0) {
+ putchar(' ');
+ } else if(c == 0x8d) {
+ putchar('n');
+ putchar('l');
+ } else if(c >= 0xc1 && c <= 0xda) {
+ putchar(c - 0xc1 + 'A');
+ } else if(c >= 0xf0) {
+ putchar('c');
+ if(c > 0xf9)
+ putchar(c - 0xfa + 'A');
+ else
+ putchar(c - 0xf0 + '0');
+ } else {
+ putchar('?');
+ }
+ }
+
+ if(!needaddr) {
+ putchar('\'');
+ putchar('\n');
+ fprintf(stderr, "last string not null-terminated!\n");
+ }
+ return 0;
+}