From 8f566e4eb05f25a86435aa3270b96b53be42ef31 Mon Sep 17 00:00:00 2001
From: "B. Watson" <urchlay@slackware.uk>
Date: Mon, 24 Mar 2025 21:05:56 -0400
Subject: listbas: initial (buggy) support for OSS Integer BASIC.

---
 Makefile     |   4 +-
 bas.c        |   7 ++-
 bas.h        |   1 +
 int_tokens.c | 189 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 int_tokens.h |   5 ++
 listbas.c    |  40 ++++++++++++-
 6 files changed, 240 insertions(+), 6 deletions(-)
 create mode 100644 int_tokens.c
 create mode 100644 int_tokens.h

diff --git a/Makefile b/Makefile
index 02c7f01..95d3b77 100644
--- a/Makefile
+++ b/Makefile
@@ -74,8 +74,8 @@ cxrefbas: bas.o bcdfp.o linetab.o
 
 bas2aplus: bas.o
 
-listbas: listbas.c bas.o bcdfp.o tokens.o atables.o turbo_tokens.o aplus_tokens.o bxl_tokens.o bxe_tokens.o
-	$(CC) $(CFLAGS) -o listbas listbas.c bas.o bcdfp.o tokens.o atables.o turbo_tokens.o aplus_tokens.o bxl_tokens.o bxe_tokens.o -lm
+listbas: listbas.c bas.o bcdfp.o tokens.o atables.o turbo_tokens.o aplus_tokens.o bxl_tokens.o bxe_tokens.o int_tokens.o
+	$(CC) $(CFLAGS) -o listbas listbas.c bas.o bcdfp.o tokens.o atables.o turbo_tokens.o aplus_tokens.o bxl_tokens.o bxe_tokens.o int_tokens.o -lm
 
 bas.o: bas.c bas.h
 
diff --git a/bas.c b/bas.c
index e5df296..6973876 100644
--- a/bas.c
+++ b/bas.c
@@ -30,6 +30,8 @@ int aplus_errtok_hack = 0;
 /* BASIC XL token 0x5a is followed by a single "subtoken", this skips it. */
 int bxl_exttok_hack = 0;
 
+int numconst_size = 6; /* 2 for OSS Integer BASIC */
+
 unsigned short lomem;
 unsigned short vntp;
 unsigned short vntd;
@@ -114,6 +116,7 @@ void parse_header(void) {
 	int vntp_offset;
 
 	lomem = getword(0);
+	if(lomem == 0x77) lomem = 0;
 	vntp = getword(2);
 	vntd = getword(4);
 	vvtp = getword(6);
@@ -403,7 +406,7 @@ void walk_code(unsigned int startlineno, unsigned int endlineno) {
 							CALL(on_exp_token);
 							pos++;
 							CALL(on_num_const);
-							pos += 6;
+							pos += numconst_size;
 							break;
 						case OP_HEXCONST:
 							if(allow_hex_const) {
@@ -415,7 +418,7 @@ void walk_code(unsigned int startlineno, unsigned int endlineno) {
 							if(allow_hex_const) {
 								CALL(on_num_const);
 							}
-							pos += 6;
+							pos += numconst_size;
 							break;
 						case OP_STRCONST:
 							CALL(on_exp_token);
diff --git a/bas.h b/bas.h
index 945b51b..c7da381 100644
--- a/bas.h
+++ b/bas.h
@@ -205,6 +205,7 @@ extern int verbose;
 extern int allow_hex_const;
 extern int aplus_errtok_hack;
 extern int bxl_exttok_hack;
+extern int numconst_size;
 
 extern void set_self(const char *argv0);
 extern void die(const char *msg);
diff --git a/int_tokens.c b/int_tokens.c
new file mode 100644
index 0000000..8daccbc
--- /dev/null
+++ b/int_tokens.c
@@ -0,0 +1,189 @@
+const char *int_cmds[] = {
+	"REM",        /* $00 */
+	"DATA",       /* $01 */
+	"INPUT",      /* $02 */
+	"COLOR",      /* $03 */
+	"LIST",       /* $04 */
+	"ENTER",      /* $05 */
+	"LET",        /* $06 */
+	"IF",         /* $07 */
+	"FOR",        /* $08 */
+	"NEXT",       /* $09 */
+	"GOTO",       /* $0A */
+	"GO TO",      /* $0B */
+	"GOSUB",      /* $0C */
+	"TRAP",       /* $0D */
+	"BYE",        /* $0E */
+	"CONT",       /* $0F */
+	"COM",        /* $10 */
+	"CLOSE",      /* $11 */
+	"CLR",        /* $12 */
+	"VBLANKWAIT", /* $13 */
+	"HITCLR",     /* $14 */
+	"       ",    /* $15 */
+	"DIM",        /* $16 */
+	"END",        /* $17 */
+	"NEW",        /* $18 */
+	"OPEN",       /* $19 */
+	"LOAD",       /* $1A */
+	"SAVE",       /* $1B */
+	"STATUS",     /* $1C */
+	"NOTE",       /* $1D */
+	"POINT",      /* $1E */
+	"XIO",        /* $1F */
+	"ON",         /* $20 */
+	"POKE",       /* $21 */
+	"PRINT",      /* $22 */
+	"READ",       /* $23 */
+	"RESTORE",    /* $24 */
+	"RETURN",     /* $25 */
+	"RUN",        /* $26 */
+	"STOP",       /* $27 */
+	"POP",        /* $28 */
+	"?",          /* $29 */
+	"GET",        /* $2A */
+	"PUT",        /* $2B */
+	"GRAPHICS",   /* $2C */
+	"PLOT",       /* $2D */
+	"POSITION",   /* $2E */
+	"DOS",        /* $2F */
+	"DRAWTO",     /* $30 */
+	"SETCOLOR",   /* $31 */
+	"LOCATE",     /* $32 */
+	"SOUND",      /* $33 */
+	"LPRINT",     /* $34 */
+	"CSAVE",      /* $35 */
+	"CLOAD",      /* $36 */
+	"",           /* $37 */
+	"ERROR- ",    /* $38 */
+	"WHILE",      /* $39 */
+	"ENDWHILE",   /* $3A */
+	"TRACEOFF",   /* $3B */
+	"TRACE",      /* $3C */
+	"ELSE",       /* $3D */
+	"ENDIF",      /* $3E */
+	"DPOKE",      /* $3F */
+	"LOMEM",      /* $40 */
+	"DEL",        /* $41 */
+	"VINC",       /* $42 */
+	"VDEC",       /* $43 */
+	"VCONST",     /* $44 */
+	"BPUT",       /* $45 */
+	"BGET",       /* $46 */
+	"TAB",        /* $47 */
+	"CP",         /* $48 */
+	"ERASE",      /* $49 */
+	"PROTECT",    /* $4A */
+	"UNPROTECT",  /* $4B */
+	"DIR",        /* $4C */
+	"RENAME",     /* $4D */
+	"MOVE",       /* $4E */
+	"MISSILE",    /* $4F */
+	"PMCLR",      /* $50 */
+	"PMCOLOR",    /* $51 */
+	"PMGRAPHICS", /* $52 */
+	"PMMOVE",     /* $53 */
+	"PMWIDTH",    /* $54 */
+	"SET",        /* $55 */
+	"LVAR",       /* $56 */
+	"RENUM",      /* $57 */
+	"FAST",       /* $58 */
+	"NUM",        /* $59 */
+	"END",        /* $5A */
+};
+
+const int int_cmd_size = sizeof(int_cmds);
+
+const char *int_ops[] = {
+	0, 0, 0, 0, 0, 0, 0, 0,
+	0, 0, 0, 0, 0, 0, 0, 0,
+	",",          /* $10 */
+	":",          /* $11 */
+	";",          /* $12 */
+	"\x1b",       /* $13 */
+	"GOTO",       /* $14 */
+	"GOSUB",      /* $15 */
+	"TO",         /* $16 */
+	"STEP",       /* $17 */
+	"=",          /* $18 */
+	"=",          /* $19 */
+	"THEN",       /* $1A */
+	"#",          /* $1B */
+	"^&",         /* $1C */
+	"^!",         /* $1D */
+	"^%",         /* $1E */
+	">>",         /* $1F */
+	"<<",         /* $20 */
+	"<=",         /* $21 */
+	"<>",         /* $22 */
+	">=",         /* $23 */
+	"<",          /* $24 */
+	">",          /* $25 */
+	"=",          /* $26 */
+	"\\",         /* $27 */
+	"*",          /* $28 */
+	"+",          /* $29 */
+	"-",          /* $2A */
+	"/",          /* $2B */
+	"%",          /* $2C */
+	"NOT",        /* $2D */
+	"OR",         /* $2E */
+	"AND",        /* $2F */
+	"!",          /* $30 */
+	"&",          /* $31 */
+	"(",          /* $32 */
+	")",          /* $33 */
+	"<=",         /* $34 */
+	"<>",         /* $35 */
+	">=",         /* $36 */
+	"<",          /* $37 */
+	">",          /* $38 */
+	"=",          /* $39 */
+	"+",          /* $3A */
+	"-",          /* $3B */
+	"(",          /* $3C */
+	"",           /* $3D */
+	"",           /* $3E */
+	"(",          /* $3F */
+	"(",          /* $40 */
+	",",          /* $41 */
+	";",          /* $42 */
+	"LEFT$(",     /* $43 */
+	"RIGHT$(",    /* $44 */
+	"MID$(",      /* $45 */
+	"STR$(",      /* $46 */
+	"CHR$(",      /* $47 */
+	"USR(",       /* $48 */
+	"ASC(",       /* $49 */
+	"VAL(",       /* $4A */
+	"LEN(",       /* $4B */
+	"ADR(",       /* $4C */
+	"BUMP(",      /* $4D */
+	"FIND(",      /* $4E */
+	"HEX$(",      /* $4F */
+	"RANDOM(",    /* $50 */
+	"DPEEK(",     /* $51 */
+	"RUN(",       /* $52 */
+	"    ",       /* $53 */
+	"PEEK(",      /* $54 */
+	"    ",       /* $55 */
+	"RND(",       /* $56 */
+	"FRE(",       /* $57 */
+	"SQR(",       /* $58 */
+	"SGN(",       /* $59 */
+	"ABS(",       /* $5A */
+	"INT(",       /* $5B */
+	"SYS(",       /* $5C */
+	"PADDLE(",    /* $5D */
+	"STICK(",     /* $5E */
+	"PTRIG(",     /* $5F */
+	"STRIG(",     /* $60 */
+	"VSTICK(",    /* $61 */
+	"HSTICK(",    /* $62 */
+	"PMADR(",     /* $63 */
+	"ERR(",       /* $64 */
+	"TAB(",       /* $65 */
+	"PEN(",       /* $66 */
+};
+
+const int int_ops_size = sizeof(int_ops);
diff --git a/int_tokens.h b/int_tokens.h
new file mode 100644
index 0000000..135890e
--- /dev/null
+++ b/int_tokens.h
@@ -0,0 +1,5 @@
+extern const char *int_cmds[];
+extern const char *int_ops[];
+
+extern const int int_cmd_size;
+extern const int int_ops_size;
diff --git a/listbas.c b/listbas.c
index 9457745..c6c4992 100644
--- a/listbas.c
+++ b/listbas.c
@@ -17,6 +17,7 @@
 #include "aplus_tokens.h"
 #include "bxl_tokens.h"
 #include "bxe_tokens.h"
+#include "int_tokens.h"
 #include "atables.h"
 #include "whichbas.h"
 
@@ -25,6 +26,7 @@
 #define B_APLUS SRET_APLUS
 #define B_BXL   SRET_BXL
 #define B_BXE   SRET_BXE
+#define B_INT   SRET_OSSINT
 
 #define COLOR_FMT "\x1b[%d;3%dm"  /* 1st %d is 1 for bold, 2nd is color */
 
@@ -135,6 +137,9 @@ int get_bas_type(char *arg) {
 	if(arg[0] == 't')
 		return B_TURBO;
 
+	if(arg[0] == 't')
+		return B_INT;
+
 	if(arg[0] == 'a') {
 		if(arg[1] == '+')
 			return B_APLUS;
@@ -346,7 +351,19 @@ void color_off(void) {
 	fputs(COLOR_OFF, outfh);
 }
 
-void print_number(unsigned int pos, int hex) {
+void print_int_number(unsigned int pos, int hex) {
+	unsigned int num = program[pos] | (program[pos + 1] << 8);
+	if(color) color_on(color_const);
+	if(hex) {
+		fprintf(outfh, (num > 0xff ? "%04x" : "%02x"), num);
+	} else {
+		fprintf(outfh, "%d", num);
+	}
+	if(color) color_off();
+	printf("end of print_int_number()\n");
+}
+
+void print_bcd_number(unsigned int pos, int hex) {
 	double num = bcd2double(program + pos);
 	if(color) color_on(color_const);
 	if(hex) {
@@ -360,6 +377,13 @@ void print_number(unsigned int pos, int hex) {
 	if(color) color_off();
 }
 
+void print_number(unsigned int pos, int hex) {
+	if(bas_type == B_INT)
+		print_int_number(pos, hex);
+	else
+		print_bcd_number(pos, hex);
+}
+
 /* only called in magazine mode. cursor control characters
    like a bell in the middle of a non-inverse string
    should not cause it to print {inv}{bell}{norm}. The {bell}
@@ -1009,6 +1033,11 @@ void init_aplus_tables() {
 	memmove(op_tokens, aplus_ops, aplus_ops_size);
 }
 
+void init_int_tables() {
+	memmove(cmd_tokens, int_cmds, int_cmd_size);
+	memmove(op_tokens, int_ops, int_ops_size);
+}
+
 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);
@@ -1030,6 +1059,9 @@ void init_token_tables() {
 	if(bas_type == B_APLUS) {
 		init_aplus_tables();
 		return;
+	} else if(bas_type == B_INT) {
+		init_int_tables();
+		return;
 	}
 
 	init_bas_tables();
@@ -1067,6 +1099,7 @@ void set_bas_dialect(int d) {
 		case SRET_TURBO:
 		case SRET_BXL:
 		case SRET_BXE:
+		case SRET_OSSINT:
 			bas_type = d;
 			break;
 		case SRET_AMSB:
@@ -1121,7 +1154,10 @@ void init_bas_dialect() {
 	if(autodetect)
 		detect_bas_dialect();
 
-	if(bas_type == B_TURBO || bas_type == B_BXL || bas_type == B_BXE)
+	if(bas_type == B_INT)
+		numconst_size = 2;
+
+	if(bas_type == B_TURBO || bas_type == B_BXL || bas_type == B_BXE || bas_type == B_INT)
 		allow_hex_const = 1;
 
 	if(bas_type == B_APLUS)
-- 
cgit v1.2.3