#include #include /* 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; }