diff options
author | B. Watson <urchlay@slackware.uk> | 2024-07-21 16:27:38 -0400 |
---|---|---|
committer | B. Watson <urchlay@slackware.uk> | 2024-07-21 16:27:38 -0400 |
commit | 57fe23c251492b61558483cbde470700cc4083e7 (patch) | |
tree | 26b7e6af1a6410e6a6f8d99087a22af89be6355c | |
parent | 3a4f45ee3127973157da66f4ebfa624bc91749a8 (diff) | |
download | bw-atari8-tools-57fe23c251492b61558483cbde470700cc4083e7.tar.gz |
bas2aplus: show token names in errors and verbose messages.
-rw-r--r-- | bas2aplus.1 | 15 | ||||
-rw-r--r-- | bas2aplus.c | 91 | ||||
-rw-r--r-- | bas2aplus.rst | 15 |
3 files changed, 92 insertions, 29 deletions
diff --git a/bas2aplus.1 b/bas2aplus.1 index 48d8f2a..46eb8cf 100644 --- a/bas2aplus.1 +++ b/bas2aplus.1 @@ -42,6 +42,12 @@ All Atari BASIC programs can be successfully converted. Some BASIC XL/XE tokens have no equivalent in BASIC/A+, so programs using these can\(aqt be converted (you will see messages on standard error, in that case). +.sp +Turbo BASIC is not supported. +.sp +Trying to convert a program that is already BASIC/A+ will appear to +succeed, but the resulting program will be gibberish and will likely +crash BASIC/A+ when \fBRUN\fP\&. .SH OPTIONS .SS General Options .INDENT 0.0 @@ -116,6 +122,10 @@ Also, BASIC XL supports hex constants, with a leading \fB$\fP\&. A+ doesn\(aqt support these, so they get converted to the equivalent decimal constant. This is basically a cosmetic change; \fBA=$0600\fP assigns the same value as \fBA=1536\fP\&. +.sp +BASIC XL also allows some syntax that\(aqs not valid in BASIC +A+. For instance, \fBDIR\fP is allowed with no argument in XL. +\fBbas2aplus\fP doesn\(aqt detect these constructs. .SH BASIC XE .sp BASIC XE is the last in the series of OSS BASIC interpreters. It adds @@ -129,6 +139,11 @@ program anyway. .B \fBHITCLR\fP, \fBINVERSE\fP, \fBNORMAL\fP, \fBBLOAD\fP, \fBBSAVE\fP Not supported in either A+ or XL. .UNINDENT +.sp +BASIC XE also allows some syntax that\(aqs not valid in either BASIC +XL or A+. For instance, \fBIF <condition>\fP can appear as the last +statement on a line, and \fBLVAR\fP no longer requires an argument. +\fBbas2aplus\fP doesn\(aqt detect these constructs. .SH TURBO BASIC .sp Not supported. It\(aqs also an extended version of Atari BASIC (by diff --git a/bas2aplus.c b/bas2aplus.c index d7768cd..ee71130 100644 --- a/bas2aplus.c +++ b/bas2aplus.c @@ -9,11 +9,10 @@ #undef DUMP_TABLES -#ifdef DUMP_TABLES #include "tokens.c" #include "aplus_tokens.c" #include "bxl_tokens.c" -#endif +#include "bxe_tokens.c" /* there are a few more BXL commands past 0x55, but they have no A+ equivalents. */ @@ -66,10 +65,11 @@ unsigned char cmd_table[] = { ...though BUMP( and FIND( do have A+ equivalents (they just need a left paren inserted after) */ unsigned char op_table[] = { - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, - 0x0e, /* convert BXL hex const to decimal */ - 0, 0, 0, 0, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* not used: 0x00-0x07 */ + 0xff, 0xff, 0xff, 0xff, 0xff, /* not used: 0x08-0x0c */ + 0x0e, /* convert BXL hex const to decimal */ + 0x0e, 0x0f, /* numeric and string consts are the same */ + 0xff, 0xff, /* these 2 not used: 0x10-0x11 */ /* these are the same, 0x12-0x1b */ 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, @@ -171,39 +171,72 @@ void parse_args(int argc, char **argv) { die("Only one input and one output file allowed."); } -CALLBACK(conv_cmd) { - if(tok > LAST_BXL_CMD) { - fprintf(stderr, "%s: Invalid cmd token %02x at line %d, pos %04x, skipping.\n", - self, tok, lineno, pos); - return; +const char *get_tok_name(unsigned char tok, int is_cmd) { + if(is_cmd) { + if(tok <= last_command) { + return commands[tok]; + } else if(tok == 0x5a) { + return "BASIC XL LOCAL/EXIT/PROCEDURE/CALL/SORTUP/SORTDOWN"; + } else if(tok == 0x59 || (tok > 0x5a && tok < 0x65)) { + return bxe_cmds[tok - 0x57]; + } else if(tok > last_command && tok <= 0x58) { + return bxl_cmds[tok - 0x38]; + } else { + return "(maybe Turbo BASIC?)"; + } + } else { + if(tok < 0x12) return ""; + if(tok <= last_operator) { + return operators[tok]; + } else if(tok <= 0x68) { + return bxl_ops[tok - 0x55]; + } else { + return "(maybe Turbo BASIC?)"; + } } +} - program[pos] = cmd_table[tok]; - if(verbose) - fprintf(stderr, "cmd tok %02x converted to %02x at line %d, pos %04x\n", tok, program[pos], lineno, pos); +void unsupported_msg(unsigned char tok, int lineno, int is_cmd) { + fprintf(stderr, "%s: Invalid %s \"%s\" (%02x) at line %d, not converted.\n", + self, is_cmd ? "command" : "operator", get_tok_name(tok, is_cmd), tok, lineno); } -CALLBACK(conv_op) { - unsigned char newtok; +int is_supported_cmd(unsigned char tok, int lineno) { + if(tok > LAST_BXL_CMD) { + unsupported_msg(tok, lineno, 1); + return 0; + } + return 1; +} - if(tok < 0x12 && tok != OP_HEXCONST) return; +int is_supported_op(unsigned char tok, int lineno) { + if(tok > LAST_BXL_OP || op_table[tok] == 0xff) { + unsupported_msg(tok, lineno, 0); + return 0; + } + return 1; +} - if(tok > LAST_BXL_OP) { - fprintf(stderr, "%s: Invalid op token %02x at line %d, pos %04x, skipping.\n", - self, tok, lineno, pos); +CALLBACK(conv_cmd) { + if(!is_supported_cmd(tok, lineno)) return; - } - newtok = op_table[tok]; - if(newtok == 0xff) { - fprintf(stderr, "%s: BXL op token %02x at line %d, pos %04x, has no A+ equivalent, skipping.\n", - self, tok, lineno, pos); + program[pos] = cmd_table[tok]; + + if(verbose && tok != program[pos]) + fprintf(stderr, "cmd tok \"%s\" ($%02x) converted to $%02x at line %d, pos $%04x\n", + get_tok_name(tok, 1), tok, program[pos], lineno, pos); +} + +CALLBACK(conv_op) { + if(!is_supported_op(tok, lineno)) return; - } - program[pos] = newtok; - if(verbose) - fprintf(stderr, "op tok %02x converted to %02x at line %d, pos %04x\n", tok, program[pos], lineno, pos); + program[pos] = op_table[tok]; + + if(verbose && tok != program[pos]) + fprintf(stderr, "op tok \"%s\" ($%02x) converted to $%02x at line %d, pos $%04x\n", + get_tok_name(tok, 0), tok, program[pos], lineno, pos); } int main(int argc, char **argv) { diff --git a/bas2aplus.rst b/bas2aplus.rst index 2ea77d4..0358091 100644 --- a/bas2aplus.rst +++ b/bas2aplus.rst @@ -24,6 +24,12 @@ XL/XE tokens have no equivalent in BASIC/A+, so programs using these can't be converted (you will see messages on standard error, in that case). +Turbo BASIC is not supported. + +Trying to convert a program that is already BASIC/A+ will appear to +succeed, but the resulting program will be gibberish and will likely +crash BASIC/A+ when **RUN**. + OPTIONS ======= @@ -91,6 +97,10 @@ doesn't support these, so they get converted to the equivalent decimal constant. This is basically a cosmetic change; **A=$0600** assigns the same value as **A=1536**. +BASIC XL also allows some syntax that's not valid in BASIC +A+. For instance, **DIR** is allowed with no argument in XL. +**bas2aplus** doesn't detect these constructs. + BASIC XE ======== @@ -104,6 +114,11 @@ a few keywords to BASIC XL, which also don't exist in A+. These are: **HITCLR**, **INVERSE**, **NORMAL**, **BLOAD**, **BSAVE** Not supported in either A+ or XL. +BASIC XE also allows some syntax that's not valid in either BASIC +XL or A+. For instance, **IF <condition>** can appear as the last +statement on a line, and **LVAR** no longer requires an argument. +**bas2aplus** doesn't detect these constructs. + TURBO BASIC =========== |