diff options
-rw-r--r-- | listamsb.c | 29 |
1 files changed, 24 insertions, 5 deletions
@@ -23,6 +23,13 @@ even with cart-based AMSB2 and no DOS loaded. */ #define MAX_PROGLEN 30000 +/* a program whose header has a length less than this can't be + a real AMSB program. The minimum size is what you get if you + SAVE when there's no program in memory (right after boot or + a NEW). The minimum size for a program that actually contains + code seems to be 5 (for 10 PRINT) */ +#define MIN_PROGLEN 2 + const char *self; char pipe_command[BUFSIZ + 1] = { "a8cat" }; @@ -77,13 +84,23 @@ int read_header(void) { int proglen; b = read_byte(); - if(b) die("first byte not $00, not an AMSB file"); + if(b) die("not an AMSB file: first byte not $00"); proglen = read_word(); + if(verbose) + fprintf(stderr, "proglen == %d (%04x)\n", proglen, proglen); + if(proglen > MAX_PROGLEN) { - fprintf(stderr, "%s: program too big (%d bytes), won't fit in Atari memory\n", + fprintf(stderr, "%s: not an AMSB file: too big (%d bytes), won't fit in Atari memory\n", self, proglen); + exit(1); + } + + if(proglen < MIN_PROGLEN) { + fprintf(stderr, "%s: not an AMSB file: program size in header too small (%d)\n", + self, proglen); + exit(1); } return proglen; @@ -266,8 +283,6 @@ int main(int argc, char **argv) { open_output(); proglen = read_header(); - if(verbose) - fprintf(stderr, "proglen == %d (%04x)\n", proglen, proglen); while( (lineno = next_line()) != -1 ) if(verbose) @@ -280,7 +295,11 @@ int main(int argc, char **argv) { if(verbose) fprintf(stderr, "file size matches proglen\n"); } else { - fprintf(stderr, "%s: trailing garbage at EOF\n", self); + fprintf(stderr, "%s: file size doesn't match length in header\n", self); + } + + if(fgetc(infile) != EOF) { + fprintf(stderr, "%s: trailing garbage at end of file\n", self); } if(unknowns) { |