aboutsummaryrefslogtreecommitdiff
path: root/listbas.c
diff options
context:
space:
mode:
authorB. Watson <urchlay@slackware.uk>2024-07-16 01:29:29 -0400
committerB. Watson <urchlay@slackware.uk>2024-07-16 01:29:29 -0400
commit7b2728284fda571410b15ab175e48d5ef4d40115 (patch)
treeb07b4952bf1219cd648ac0041838b9d84f6049ed /listbas.c
parent8b03ef61bb86c51c69ae929aaa4a4c55077ce5a2 (diff)
downloadbw-atari8-tools-7b2728284fda571410b15ab175e48d5ef4d40115.tar.gz
listbas: add support for Turbo BASIC XL.
Diffstat (limited to 'listbas.c')
-rw-r--r--listbas.c172
1 files changed, 156 insertions, 16 deletions
diff --git a/listbas.c b/listbas.c
index dcd303b..bfe7615 100644
--- a/listbas.c
+++ b/listbas.c
@@ -11,7 +11,20 @@
#include "bas.h"
#include "bcdfp.h"
#include "tokens.h"
+#include "turbo_tokens.h"
+/*
+#include "aplus_tokens.h"
+#include "bxl_tokens.h"
+#include "bxe_tokens.h"
+*/
#include "atables.h"
+#include "whichbas.h"
+
+#define B_ATARI SRET_ATARI
+#define B_TURBO SRET_TURBO
+#define B_APLUS SRET_APLUS
+#define B_BXL SRET_BXL
+#define B_BXE SRET_BXE
#define COLOR_FMT "\x1b[%d;3%dm" /* 1st %d is 1 for bold, 2nd is color */
@@ -50,6 +63,11 @@
#define M_MAG 3 /* -m */
#define M_DOTS 4 /* -d */
+const char *cmd_tokens[256];
+const char *op_tokens[256];
+
+int bas_type = B_ATARI;
+
int output_mode = M_UTF8;
int bold = 0; /* 1 with -b */
@@ -99,14 +117,37 @@ void parse_color_scheme(const char *arg) {
color_varnames = parse_color(arg[7]);
}
+int get_bas_type(char *arg) {
+ if(arg[0] == 't')
+ return B_TURBO;
+
+ if(arg[0] == 'a') {
+ if(arg[1] == '+')
+ return B_APLUS;
+ else
+ return B_ATARI;
+ }
+
+ if(arg[0] == 'x') {
+ if(arg[1] == 'l')
+ return B_BXL;
+ else if(arg[1] == 'e')
+ return B_BXE;
+ }
+
+ fprintf(stderr, "%s: Invalid BASIC type for -b option: %s\n", self, arg);
+ exit(1);
+}
+
void print_help(void) {
- printf("Usage: %s [-a|-d|-m|-x|-U] [-b] [-i] [-l] [-u] [-n|-C] [-v] [-c *colors*] <inputfile>\n", self);
+ printf("Usage: %s [-a|-d|-m|-x|-U] [-B] [-i] [-l] [-u] [-n|-C] [-v] [-c *colors*] <inputfile>\n", self);
+ printf(" -b <XX>: set BASIC type. XX is: a = atari, t = turbo, xl, xe, a+.\n");
printf(" -U: output ATASCII as Unicode/UTF-8 (this is the default).\n");
printf(" -a: output raw ATASCII.\n");
printf(" -d: use dots instead of Unicode/UTF-8.\n");
printf(" -m: magazine style listing (see a8cat(1)).\n");
printf(" -x: XL international character set (UTF-8).\n");
- printf(" -b: use bold for color output.\n");
+ printf(" -B: use bold for color output.\n");
printf(" -i: show immediate mode command (line 32768).\n");
printf(" -l: don't print line numbers.\n");
printf(" -C: enable color syntax highlighting (this is the default).\n");
@@ -121,7 +162,7 @@ void parse_args(int argc, char **argv, int from_env) {
optind = 1;
- while( (opt = getopt(argc, argv, "UCviamnbdhxulc:")) != -1) {
+ while( (opt = getopt(argc, argv, "b:UCviamnBdhxulc:")) != -1) {
switch(opt) {
case 'U': output_mode = M_UTF8; break;
case 'a': output_mode = M_ATASCII; break;
@@ -130,11 +171,12 @@ void parse_args(int argc, char **argv, int from_env) {
case 'x': output_mode = M_UTF8_I; break;
case 'v': verbose = 1; break;
case 'i': immediate = 1; break;
- case 'b': bold = 1; break;
+ case 'B': bold = 1; break;
case 'u': underline = 1; break;
case 'C': color = 1; break;
case 'n': color = 0; break;
case 'l': skip_lineno = 1; break;
+ case 'b': bas_type = get_bas_type(optarg); break;
case 'c': parse_color_scheme(optarg); break;
case 'h': print_help(); exit(0);
default:
@@ -389,7 +431,7 @@ CALLBACK(print_cmd) {
if(tok == CMD_ILET) return;
if(color) color_on(color_cmd);
- if(tok > last_command || (!(name = commands[tok]))) {
+ if((!(name = cmd_tokens[tok]))) {
fprintf(outfh, "(bad cmd token $%02x) ", tok);
badtok = 1;
} else {
@@ -398,10 +440,70 @@ CALLBACK(print_cmd) {
if(color) color_off();
}
+void aplus_op_color_on(unsigned char tok) {
+}
+
+void op_color_on(unsigned char tok) {
+ if(!color) return;
+
+ if(bas_type == B_APLUS) {
+ aplus_op_color_on(tok);
+ return;
+ }
+
+ /* common ops for Atari, Turbo, BXL, BXE */
+ if(tok <= last_operator) {
+ if(tok > 0x3c)
+ color_on(color_func);
+ else if(tok == OP_UMINUS || tok == OP_UPLUS)
+ color_on(color_const); /* show leading sign in same color as the number */
+ else if((tok >= 0x17 && tok <= 0x1b) || (tok >= 0x28 && tok <= 0x2a))
+ color_on(color_cmd);
+ else
+ color_on(color_op);
+ return;
+ }
+
+ if(bas_type == B_TURBO) {
+ switch(tok) {
+ case 0x55:
+ case 0x58:
+ case 0x59: /* pseudo-func */
+ case 0x5b:
+ case 0x5c:
+ case 0x5e:
+ case 0x5f: /* pseudo-func */
+ case 0x60: /* pseudo-func */
+ case 0x63: /* pseudo-func */
+ case 0x64:
+ case 0x65:
+ case 0x6b:
+ case 0x6c: /* pseudo-func */
+ case 0x6d: /* pseudo-func */
+ color_on(color_func);
+ return;
+ case 0x5a:
+ case 0x5d:
+ case 0x61:
+ case 0x62:
+ case 0x6a:
+ color_on(color_cmd);
+ return;
+ default:
+ color_on(color_op);
+ }
+ }
+}
+
CALLBACK(print_op) {
const char *name;
switch(tok) {
+ case OP_HEXCONST:
+ if(color) color_on(color_op);
+ outchr('$');
+ if(color) color_off();
+ /* fall thru */
case OP_NUMCONST:
print_number(pos + 1);
return;
@@ -413,17 +515,9 @@ CALLBACK(print_op) {
default: break;
}
- if(color) {
- if(tok > 0x3c)
- color_on(color_func);
- else if(tok == OP_UMINUS || tok == OP_UPLUS)
- color_on(color_const); /* show leading sign in same color as the number */
- else if((tok >= 0x17 && tok <= 0x1b) || (tok >= 0x28 && tok <= 0x2a))
- color_on(color_cmd);
- else
- color_on(color_op);
- }
- if(tok > last_operator || (!(name = operators[tok]))) {
+ if(color) op_color_on(tok);
+
+ if((!(name = op_tokens[tok]))) {
fprintf(outfh, "(bad op token $%02x)", tok);
badtok = 1;
} else {
@@ -496,12 +590,58 @@ void list(void) {
walk_code(0, 32767 + immediate);
}
+void init_bas_tables() {
+ memmove(cmd_tokens, commands, (last_command + 1) * sizeof(char *));
+ memmove(op_tokens, operators, (last_operator + 1) * sizeof(char *));
+}
+
+void init_aplus_tables() {
+ die("BASIC A+ not supported yet!");
+ /*
+ memmove(cmd_tokens, aplus_commands, (last_aplus_command + 1) * sizeof(char *));
+ memmove(op_tokens, aplus_operators, (last_aplus_operator + 1) * sizeof(char *));
+ */
+}
+
+void init_turbo_tables() {
+ memmove(cmd_tokens + last_command + 1, turbo_cmds, turbo_cmd_size);
+ memmove(op_tokens + last_operator + 1, turbo_ops, turbo_ops_size);
+}
+
+void init_bxl_tables() {
+ die("BASIC XL not supported yet!");
+}
+
+void init_bxe_tables() {
+ die("BASIC XE not supported yet!");
+}
+
+void init_token_tables() {
+ if(bas_type == B_APLUS) {
+ init_aplus_tables();
+ return;
+ }
+
+ init_bas_tables();
+
+ if(bas_type == B_TURBO)
+ init_turbo_tables();
+ else if(bas_type == B_BXL)
+ init_bxl_tables();
+ else if(bas_type == B_BXE)
+ init_bxe_tables();
+}
+
int main(int argc, char **argv) {
set_self(*argv);
parse_general_args(argc, argv, print_help);
parse_env_args();
parse_args(argc, argv, 0);
+ if(bas_type != B_ATARI) allow_hex_const = 1;
+
+ init_token_tables();
+
readfile();
parse_header();