diff options
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | listamsb.c | 35 | ||||
-rw-r--r-- | listbas.c | 7 | ||||
-rw-r--r-- | whichbas.c | 18 |
4 files changed, 52 insertions, 12 deletions
@@ -25,7 +25,7 @@ SCRIPTS=dasm2atasm diffbas a8diff MANS=a8eol.1 xfd2atr.1 atr2xfd.1 blob2c.1 cart2xex.1 fenders.1 xexsplit.1 xexcat.1 atrsize.1 rom2cart.1 unmac65.1 axe.1 dasm2atasm.1 blob2xex.1 xexamine.1 xex1to2.1 unprotbas.1 protbas.1 renumbas.1 dumpbas.1 vxrefbas.1 cxrefbas.1 listbas.1 a8cat.1 a8xd.1 whichbas.1 diffbas.1 a8diff.1 bas2aplus.1 listamsb.1 MAN5S=xex.5 MAN7S=atascii.7 fauxtari.7 -DOCS=README.txt equates.inc *.dasm LICENSE ksiders/atr.txt +DOCS=README.txt AMSB.txt equates.inc *.dasm LICENSE ksiders/atr.txt PSFS=fonts/fauxtari-8.psf fonts/fauxtari-16.psf fonts/fauxtari-24.psf BDFS=fonts/fauxtari-8.bdf fonts/fauxtari-16.bdf fonts/fauxtari-24.bdf TTF=fonts/FauxtariScalableMono.ttf @@ -33,7 +33,7 @@ TTF=fonts/FauxtariScalableMono.ttf SUBDIRS=ksiders jindroush # All the programs share this version number... -VERSION=0.2.1 +VERSION=0.2.2 # If your system doesn't support gzipped man pages, comment this out: GZIP_MAN=y @@ -558,8 +558,7 @@ int crunch_line(void) { return codelen; } -/* only called during decrunching. - only handles one-byte tokens (only has to). */ +/* only called during decrunching. */ void expand_token(int ext, unsigned char t, unsigned char *buf) { const char *result; @@ -582,6 +581,33 @@ void expand_token(int ext, unsigned char t, unsigned char *buf) { strcpy((char *)buf, result); } +int read_token(void) { + int tok = read_prog_byte(); + if(tok == 0xff) { + tok <<= 8; + tok |= read_prog_byte(); + } + return tok; +} + +int token_is_extended(int tok) { + return tok > 0xff; +} + +int append_token(int tok, char *buf, int len) { + if(token_is_extended(tok)) { + buf[len++] = 0xff; + buf[len++] = tok; + } else { + buf[len++] = tok; + } + return len; +} + +void token2text(int tok, unsigned char *buf) { + return expand_token(token_is_extended(tok), tok & 0xff, buf); +} + /* only called during decrunching. the tokenizer in AMSB requires spaces to separate keywords and variables/numbers. "IF A THEN 100" really needs the spaces @@ -671,6 +697,8 @@ int decrunch_line(void) { byte = read_prog_byte(); if(byte != 0) { + if(byte == ' ' || is_comment_start(byte)) spacecount++; + if(in_string) { if(byte == '|') in_string = 0; @@ -754,6 +782,9 @@ void crunch_program(void) { newproglen, percent < 0 ? -percent : percent, percent < 0 ? "larger" : "smaller"); + + if(decrunch && spacecount) + warn("%d spaces/comments, are you sure it was crunched?", spacecount); } void print_help(void) { @@ -1069,6 +1069,13 @@ void set_bas_dialect(int d) { case SRET_BXE: bas_type = d; break; + case SRET_AMSB: + die("This is an Atari Microsoft BASIC program. Use listamsb."); + break; + case SRET_COMPILED_TURBO: + case SRET_NOT_BASIC: + die("This is not any kind of BASIC program I know about."); + break; default: fprintf(stderr, "whichbas results ambiguous; guessing Turbo BASIC\n"); bas_type = SRET_TURBO; @@ -969,21 +969,23 @@ CALLBACK(handle_end_stmt) { } /* return true if input_file is Atari MS BASIC. - AMSB files begin with a 3-byte header: 0x00, then 2 byte length + AMSB files begin with a 3-byte header: 0x00 or 0x01, then 2 byte length (LSB/MSB), which is actually 3 bytes less than the full length of the file (or, it's the length of the file minus the 3-byte header). Also, the files always end with 3 0x00 bytes. We check that the header length is 3 bytes less than the file length, - then check for the 3 0x00's at the end. + then check for the 3 0x00's at the end... or, if the first byte was 1, + meaning "locked program", check for 3 "encrypted" 0x00's at the end. */ int detect_amsb(void) { - int len, c; + int trailing_byte_value = 0, len, c; if(verbose) fprintf(stderr, "entering detect_amsb()\n"); rewind(input_file); c = fgetc(input_file); - if(c) return 0; + if(c > 1) return 0; + if(c) trailing_byte_value = 0x54; c = fgetc(input_file); if(c == EOF) return 0; len = (fgetc(input_file) << 8) | c; @@ -1000,9 +1002,9 @@ int detect_amsb(void) { if(verbose) fprintf(stderr, "detect_amsb() file size is correct, checking for 3 nulls\n"); fseek(input_file, -3, SEEK_END); - if(fgetc(input_file)) return 0; - if(fgetc(input_file)) return 0; - if(fgetc(input_file)) return 0; + if(fgetc(input_file) != trailing_byte_value) return 0; + if(fgetc(input_file) != trailing_byte_value) return 0; + if(fgetc(input_file) != trailing_byte_value) return 0; if(verbose) fprintf(stderr, "detect_amsb() found 3 nulls, return 1\n"); @@ -1053,7 +1055,7 @@ void detect_foreign(void) { foreign("ELF executable (not BASIC at all!)", SRET_NOT_BASIC); } - if(c == 0 && detect_amsb()) { + if((c == 0 || c == 1) && detect_amsb()) { foreign("Atari Microsoft BASIC", SRET_AMSB); } |