diff options
author | B. Watson <urchlay@slackware.uk> | 2024-07-09 03:14:02 -0400 |
---|---|---|
committer | B. Watson <urchlay@slackware.uk> | 2024-07-09 03:14:02 -0400 |
commit | a2a2a8437246ea12bbce0c133538617e49c43a90 (patch) | |
tree | c94e677d5f73a1a22eb1d7aa83c33b80228e9b2c | |
parent | 188c35607585e0bd2cf861d1db761754a32cf260 (diff) | |
download | bw-atari8-tools-a2a2a8437246ea12bbce0c133538617e49c43a90.tar.gz |
whichbas: detect compiled Turbo.
-rw-r--r-- | whichbas.1 | 235 | ||||
-rw-r--r-- | whichbas.c | 4 | ||||
-rw-r--r-- | whichbas.rst | 3 |
3 files changed, 242 insertions, 0 deletions
diff --git a/whichbas.1 b/whichbas.1 new file mode 100644 index 0000000..4c32834 --- /dev/null +++ b/whichbas.1 @@ -0,0 +1,235 @@ +.\" Man page generated from reStructuredText. +. +. +.nr rst2man-indent-level 0 +. +.de1 rstReportMargin +\\$1 \\n[an-margin] +level \\n[rst2man-indent-level] +level margin: \\n[rst2man-indent\\n[rst2man-indent-level]] +- +\\n[rst2man-indent0] +\\n[rst2man-indent1] +\\n[rst2man-indent2] +.. +.de1 INDENT +.\" .rstReportMargin pre: +. RS \\$1 +. nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin] +. nr rst2man-indent-level +1 +.\" .rstReportMargin post: +.. +.de UNINDENT +. RE +.\" indent \\n[an-margin] +.\" old: \\n[rst2man-indent\\n[rst2man-indent-level]] +.nr rst2man-indent-level -1 +.\" new: \\n[rst2man-indent\\n[rst2man-indent-level]] +.in \\n[rst2man-indent\\n[rst2man-indent-level]]u +.. +.TH "WHICHBAS" 1 "2024-07-09" "0.2.1" "Urchlay's Atari 8-bit Tools" +.SH NAME +whichbas \- Determine BASIC variant of a tokenized Atari 8-bit program +.SH SYNOPSIS +.sp +whichbas [\-v] \fIinput\-file\fP +.SH DESCRIPTION +.sp +\fBwhichbas\fP reads a tokenized Atari 8\-bit BASIC, Turbo BASIC, +BASIC XL, BASIC XE, or Atari Microsoft BASIC program and attempts to +discover which BASIC is required to run it. +.sp +\fIinput\-file\fP must be an actual file. \fBwhichbas\fP can\(aqt read from +standard input, because it seeks in the input file. +.SH OPTIONS +.SS Detection Options +.INDENT 0.0 +.TP +.B \fB\-s\fP +Script (or silent) mode. Instead of printing a human\-readable +name like "Turbo BASIC XL" or "OSS BASIC XE" to stdout, \fBwhichbas\fP +will print nothing on standard output, but will exit with a status +indicating what it detected. The caller can check the return status +(e.g. the \fB$?\fP variable in Bourne/POSIX shells, or \fBERRORLEVEL\fP +in MS\-DOS or Windows). See \fBEXIT STATUS\fP, below. +.TP +.B \fB\-k\fP +Keep going. The default is to stop looking at the program if the +BASIC type gets narrowed down to either Turbo BASIC or BASIC XE. +This option also enables \fB\-v\fP (verbose). It\(aqs really only useful +for testing, if you\(aqre hacking on \fBwhichbas\fP itself. +.UNINDENT +.SS General Options +.INDENT 0.0 +.TP +.B \fB\-\-help\fP +Print usage message and exit. +.TP +.B \fB\-\-version\fP +Print version number and exit. +.TP +.B \fB\-v\fP +Verbose operation. When displaying a number in verbose mode, it will +be prefixed with \fI$\fP if it\(aqs in hex, or no prefix for decimal. +.UNINDENT +.SH NOTES +.sp +Atari BASIC programs are detected \fIalmost\fP 100% reliably. See \fBBUGS\fP, below, +for the gory details. +.sp +Turbo BASIC, BASIC XL, and BASIC XE are all supersets of Atari BASIC. +If you wrote a program using one of them, but didn\(aqt use any of the +extra commands or functions, the result is still an Atari BASIC program. +Likewise, if you wrote a program using BASIC XE, but only used the +commands/functions it has in common with BASIC XL, it would be +detected as BASIC XL. +.sp +There are two types of BASIC XE programs: regular and \fIEXTEND\fPed. The +extended type is detected 100% reliably, because the first byte of the +file changes from \fB$00\fP to \fB$DD\fP\&. Non\-extended programs are only +identified as BASIC XE if they use any of the extra commands BASIC XE +adds to those found in BASIC XL. +.sp +Detection of Turbo vs. BXL/BXE isn\(aqt 100% reliable, and probably +never will be. There\(aqs too much overlap between the sets of extra +tokens added by each. Programs that don\(aqt use very many of the extra +functions provided by Turbo/BXL/BXE may show up as "Either Turbo BASIC XL +or OSS BASIC XE". +.sp +Atari Microsoft BASIC is detected by checking that the first two +bytes of the file are not zero, and that the last 3 are zero. This +may result in false positives (files that aren\(aqt BASIC programs at +all might show up as Microsoft). Also, no distinction is made between +Atari MS BASIC 1.0 and 2.0. +.sp +Various non\-BASIC files are detected (including Mac/65 source, +ELF binaries, etc) as a convenience, but I wouldn\(aqt rely on +\fBwhichbas\fP\(aqs non\-BASIC file type detection if I were you. +.SH LIMITATIONS +.sp +\fBwhichbas\fP knows nothing about other BASICs such as Frost BASIC, +BASIC/A+, Altirra BASIC... +.SH BUGS +.sp +It\(aqs possible to get a BASIC XL/XE program to misdetect as Atari BASIC +by writing a program that does these things: +.INDENT 0.0 +.INDENT 3.5 +.INDENT 0.0 +.IP \(bu 2 +Dimensions a string array with a number of elements that isn\(aqt just a +numeric constant or numeric variable (e.g. \fIDIM A$(2+2,10)\fP or +\fIDIM A$(I*2,10)\fP). The code that detects a 2D string \fIDIM\fP command +can only handle simple cases like \fIDIM A$(10,10)\fP or \fIDIM A$(I,10)\fP\&. +It doesn\(aqt actually matter if the 2nd argument is a fancy expression, +though. +.IP \(bu 2 +Does \fInot\fP actually \fIuse\fP the string array variable by assigning to +it or reading a value from it. String array accesses in BASIC XL/XE +are reliably detected because they require a semicolon after the +first number, even if there isn\(aqt a 2nd number. Example: \fI? A$(2;)\fP +prints the 2nd element of the \fIA$\fP string array. If it were written +as \fI? A$(2)\fP, but \fIA$\fP is a string array (not a regular string), +BASIC XL/XE would give an \fIError 40\fP (string type mismatch) at +runtime. +.UNINDENT +.UNINDENT +.UNINDENT +.sp +The good news is, such a program will still work fine in Atari BASIC. +Believe it or not, it\(aqs true. +.SH EXIT STATUS +.sp +Without the \fB\-s\fP option, exit status is 0 for success, non\-zero for +failure. +.sp +With the \fB\-s\fP option, the exit status is: +.INDENT 0.0 +.TP +.B \fB0\fP +Not used with \fB\-s\fP\&. +.TP +.B \fB1\fP or \fB2\fP +Error reading file. Error message will be printed on standard error. +.TP +.B \fB3\fP +Atari BASIC detected. +.TP +.B \fB4\fP +Turbo BASIC detected. +.TP +.B \fB5\fP +OSS BASIC XL detected. +.TP +.B \fB6\fP +Non\-EXTENDed OSS BASIC XE detected. +.TP +.B \fB7\fP +Turbo BASIC or BASIC XL (undecided which). +.TP +.B \fB8\fP +Turbo BASIC or non\-EXTENDed BASIC XE (undecided which). +.TP +.B \fB9\fP +Turbo BASIC, BASIC XL, or non\-EXTENDed BASIC XE (undecided which). +.TP +.B \fB10\fP +Unknown Atari BASIC derivative (not Atari BASIC, but not +Turbo/BXL/BXE either). +.TP +.B \fB11\fP +Atari Microsoft BASIC detected. +.TP +.B \fB12\fP +EXTENDed OSS BASIC XE detected. +.TP +.B \fB13\fP +Compiled Turbo BASIC detected. +.TP +.B \fB32\fP +None of the above; not BASIC. +.UNINDENT +.SH COPYRIGHT +.sp +WTFPL. See \fI\%http://www.wtfpl.net/txt/copying/\fP for details. +.SH AUTHOR +.INDENT 0.0 +.IP B. 3 +Watson <\fI\%urchlay@slackware.uk\fP>; Urchlay on irc.libera.chat \fI##atari\fP\&. +.UNINDENT +.SH SEE ALSO +.sp +\fBa8cat\fP(1), +\fBa8eol\fP(1), +\fBa8xd\fP(1), +\fBatr2xfd\fP(1), +\fBatrsize\fP(1), +\fBaxe\fP(1), +\fBblob2c\fP(1), +\fBblob2xex\fP(1), +\fBcart2xex\fP(1), +\fBcxrefbas\fP(1), +\fBdasm2atasm\fP(1), +\fBdumpbas\fP(1), +\fBf2toxex\fP(1), +\fBfenders\fP(1), +\fBlistbas\fP(1), +\fBprotbas\fP(1), +\fBrenumbas\fP(1), +\fBrom2cart\fP(1), +\fBunmac65\fP(1), +\fBunprotbas\fP(1), +\fBvxrefbas\fP(1), +\fBwhichbas\fP(1), +\fBxex1to2\fP(1), +\fBxexamine\fP(1), +\fBxexcat\fP(1), +\fBxexsplit\fP(1), +\fBxfd2atr\fP(1), +\fBxex\fP(5), +\fBatascii\fP(7). +.sp +Any good Atari 8\-bit book: \fIDe Re Atari\fP, \fIThe Atari BASIC Reference +Manual\fP, the \fIOS Users\(aq Guide\fP, \fIMapping the Atari\fP, etc. +.\" Generated by docutils manpage writer. +. @@ -27,6 +27,7 @@ int bas_type = 0x0f; /* start out with all enabled */ #define SRET_UKNOWN_DERIV 10 #define SRET_AMSB 11 #define SRET_EXTENDED_BXE 12 +#define SRET_COMPILED_TURBO 13 #define SRET_NOT_BASIC 32 int script_mode = 0; /* -s flag */ @@ -712,6 +713,9 @@ void detect_foreign(void) { return; } + if(c == 0xfb && d == 0xc2) + foreign("Compiled Turbo BASIC XL", SRET_COMPILED_TURBO); + if(c == 0xff && d == 0xff) foreign("XEX executable (not BASIC at all!)", SRET_NOT_BASIC); diff --git a/whichbas.rst b/whichbas.rst index 350be21..bd7e354 100644 --- a/whichbas.rst +++ b/whichbas.rst @@ -151,6 +151,9 @@ With the **-s** option, the exit status is: **12** EXTENDed OSS BASIC XE detected. +**13** + Compiled Turbo BASIC detected. + **32** None of the above; not BASIC. |