aboutsummaryrefslogtreecommitdiff
path: root/bas.h
diff options
context:
space:
mode:
Diffstat (limited to 'bas.h')
-rw-r--r--bas.h80
1 files changed, 80 insertions, 0 deletions
diff --git a/bas.h b/bas.h
new file mode 100644
index 0000000..3a65567
--- /dev/null
+++ b/bas.h
@@ -0,0 +1,80 @@
+/* bas.h - API for writing standalone programs that deal with
+ tokenized Atari 8-bit BASIC program. */
+
+/* maximum size of the program in memory. 64KB is actually way overkill. */
+#define BUFSIZE 65536
+
+/* the difference between the VVTP and VNTP values in the file, and the
+ actual file positions of the variable names and values. */
+#define TBL_OFFSET 0xf2
+
+/* minimum program size, for a program that has no variables and
+ only one line of code (the immediate line 32768, consisting only of
+ one token, which would be CSAVE). anything smaller than this, we
+ can't process. */
+#define MIN_PROG_SIZE 21
+
+/* maximum practical size for a BASIC program. if a file exceeds this
+ size, we warn about it, but otherwise process it normally.
+ this value is derived by subtracting the default LOMEM without DOS
+ ($0700) from the start of the display list in GR.0 ($9c20, on a 48K Atari).
+ */
+#define MAX_PROG_SIZE 38176
+
+/* maximum number of variables in the variable name and value tables. this
+ could be 128, but "ERROR- 4" still expands the tables. Entries >128
+ don't have tokens, can't be referred to in code, but we'll preserve
+ them anyway. */
+#define MAXVARS 256
+
+/* tokenized colon (statement separator) */
+#define TOK_COLON 0x14
+
+/* variable types, bits 6-7 of byte 0 of each vvtable entry. */
+#define TYPE_SCALAR 0
+#define TYPE_ARRAY 1
+#define TYPE_STRING 2
+
+/* BASIC 14-byte header values */
+extern unsigned short lomem;
+extern unsigned short vntp;
+extern unsigned short vntd;
+extern unsigned short vvtp;
+extern unsigned short stmtab;
+extern unsigned short stmcur;
+extern unsigned short starp;
+
+/* positions where various parts of the file start,
+ derived from the header vars above. */
+extern unsigned short codestart;
+extern unsigned short code_end;
+extern unsigned short vnstart;
+extern unsigned short vvstart;
+extern int filelen;
+
+/* name of executable, taken from argv[0] */
+extern const char *self;
+
+/* entire file gets read into memory (for now) */
+extern unsigned char program[BUFSIZE];
+
+/* file handles */
+extern FILE *input_file;
+extern FILE *output_file;
+
+extern int verbose;
+
+extern void set_self(const char *argv0);
+extern void die(const char *msg);
+extern int readfile(void);
+extern unsigned short getword(int addr);
+extern void setword(int addr, int value);
+extern void dump_header_vars(void);
+extern void parse_header(void);
+extern void update_header(void);
+extern void move_code(int offset);
+extern void adjust_vntable_size(int oldsize, int newsize);
+extern void invalid_args(const char *arg);
+extern FILE *open_file(const char *name, const char *mode);
+extern void open_input(const char *name);
+extern void open_output(const char *name);