aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorB. Watson <urchlay@slackware.uk>2024-07-08 12:50:26 -0400
committerB. Watson <urchlay@slackware.uk>2024-07-08 12:50:26 -0400
commit8b31cda23ae3a6b06dde59fa2d1bf6988a778451 (patch)
tree2f4c69dd05edc5e3ebbc894ffd3adf05f61f5ce8
parentb557e87b4b4a543f71579327ea64c9f62ee2c642 (diff)
downloadbw-atari8-tools-8b31cda23ae3a6b06dde59fa2d1bf6988a778451.tar.gz
whichbas: improve detection for DUMP/LOCAL and TIME$/PMCLR.
-rw-r--r--whichbas.c41
1 files changed, 32 insertions, 9 deletions
diff --git a/whichbas.c b/whichbas.c
index 2e7745d..a61013e 100644
--- a/whichbas.c
+++ b/whichbas.c
@@ -91,7 +91,7 @@ void remove_type(int type) {
}
CALLBACK(handle_cmd) {
- int has_args = 0;
+ int has_args = 0, has_var_arg = 0, vartype = -1;
unsigned char nexttok;
last_cmd = tok;
@@ -102,6 +102,10 @@ CALLBACK(handle_cmd) {
nexttok = program[pos + 1];
has_args = !(nexttok == OP_EOS || nexttok == OP_EOL);
+ if(nexttok >= 0x80) {
+ has_var_arg = 1;
+ vartype = get_vartype(nexttok);
+ }
/* this switch is for tokens that are the same in Atari/Turbo/BXL/BXE, but with
different semantics. non-Atari-BASIC tokens go in the switch below, not
@@ -236,30 +240,43 @@ CALLBACK(handle_cmd) {
}
break;
case 0x4e: /* TIME$= (1 string arg) or PMCLR (1 num arg) */
- /* partial: this doesn't do anything if the arg is a variable; we
- could examine the type, but we don't yet */
if(nexttok == OP_STRCONST) {
remove_type(BT_BXL_BXE);
+ } else if(has_var_arg && vartype == TYPE_STRING) {
+ remove_type(BT_BXL_BXE);
} else if(nexttok == OP_NUMCONST) {
remove_type(BT_TURBO);
+ } else if(has_var_arg && vartype == TYPE_SCALAR) {
+ remove_type(BT_TURBO);
}
break;
case 0x50: /* EXEC (1 arg, *must* be variable) or PMGRAPHICS (1 num arg, may be const) */
- if(nexttok < 0x80) {
+ /* partial: PMGRAPHICS VAR won't be detected. but this usage is rare. */
+ if(!has_var_arg) {
remove_type(BT_TURBO);
}
break;
- case 0x57: /* DUMP (1 optional string arg) or LOCAL (1 variable arg) */
- if(!has_args || (nexttok == OP_STRCONST)) {
- /* if there's no arg, or one string constant arg... */
- /* partial: DUMP A$ not detected */
+ case 0x57: /* DUMP (1 optional string arg) or LOCAL (1 *numeric* variable arg) */
+ /* BXL/BXE's LOCAL only works on scalars, not arrays or strings. so if there's
+ no arg, or one string arg... */
+ if(!has_args) {
+ /* only Turbo allows no arg... */
+ remove_type(BT_BXL_BXE);
+ } else if(nexttok == OP_STRCONST) {
+ /* only Turbo allows a string constant arg... */
remove_type(BT_BXL_BXE);
+ } else if(has_var_arg && vartype == TYPE_STRING) {
+ /* only Turbo allows a string variable arg... */
+ remove_type(BT_BXL_BXE);
+ } else if(has_var_arg && vartype == TYPE_SCALAR) {
+ /* only BXL/BXL allows a scalar variable arg */
+ remove_type(BT_TURBO);
}
case 0x5c: /* GO# (1 arg only) or SORTUP (optional 2nd arg of USING, but no comma) */
case 0x5d: /* # (1 arg only) or SORTDOWN (optional 2nd arg of USING, but no comma) */
/* Turbo BASIC labels have the high 2 bits set to 11, which is illegal
in Atari/BXL/BXE. */
- if(get_vartype(nexttok) == 3) {
+ if(vartype == 3) {
remove_type(BT_BXL_BXE);
} else {
remove_type(BT_TURBO);
@@ -522,6 +539,10 @@ void detect_foreign(void) {
foreign("Unknown file type (not BASIC at all!)");
}
+void check_variables(void) {
+ /* Turbo variables can have _ in the name, and have 3 for the type. */
+}
+
int main(int argc, char **argv) {
set_self(*argv);
parse_general_args(argc, argv, print_help);
@@ -532,6 +553,8 @@ int main(int argc, char **argv) {
readfile();
parse_header();
+ check_variables();
+
allow_hex_const = 1;
on_cmd_token = handle_cmd;
on_exp_token = handle_op;