Skip to content

Commit c05b51a

Browse files
committed
Autoadjust BASIC start offset based on filesize. Emit warnings, error.
If the final tokenized program is >= 65536 bytes long, then die with an error. >= 32768 bytes, then warn that it will work on no actual hardware and set offset to 0. (It probably won't work on any virtual hardware, either.) >= 24576 bytes, then warn about Tandy 200 incompatibility and set offset to 0x8001.
1 parent df1d114 commit c05b51a

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

m100-tokenize-main.c

+23-2
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,30 @@ int fixup_ptrs() {
7474
/* Offset into RAM for start of the first BASIC program.
7575
0x8001: Used by Model 100, Tandy 102, Kyocera-85, and Olivetti M10.
7676
0xA001: Used by Tandy 200 (which has more ROM and less RAM). */
77-
int offset = 0x8001;
77+
long offset = 0x8001;
7878

79-
ptr[nlines++] = ftell(yyout); /* Pointer to final NULL byte */
79+
long filesize = ftell(yyout); /* Pointer to final NULL byte */
80+
ptr[nlines++] = filesize;
81+
82+
/* Double-check size of .BA file */
83+
fprintf(stderr, "file size is 0x%x\n", filesize);
84+
if ( filesize >= 0x10000 ) {
85+
fprintf(stderr, "Fatal Error. Program too large to fit in 64K RAM.\n");
86+
fprintf(stderr, "Due to 16-bit pointers in BASIC, this cannot work.\n");
87+
exit(1);
88+
}
89+
else if ( filesize >= 0x8000 ) {
90+
fprintf(stderr, "Warning. Program too large to fit in 32K RAM.\n");
91+
fprintf(stderr, "The output cannot run on any standard hardware.\n");
92+
if ( filesize+offset >= 0x10000 )
93+
offset=0;
94+
}
95+
else if ( filesize >= 0x6000 ) {
96+
fprintf(stderr, "Notice. Program too large to fit in 24K RAM.\n");
97+
fprintf(stderr, "The output cannot run on a standard Tandy 200.\n");
98+
if ( filesize+offset >= 0x10000 )
99+
offset=0x8001;
100+
}
80101

81102
if (fseek(yyout, 0L, SEEK_SET) != 0) {
82103
perror("fseek");

m100-tokenize.lex

-4
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@
2929
%%
3030

3131
^[[:space:]]*[0-9]+[ ]? {
32-
if (ftell(yyout) >= 0x8000) {
33-
fprintf(stderr, "Program too large to fit in 32K RAM\n");
34-
exit(1);
35-
}
3632
ptr[nlines++] = ftell(yyout); /* Cache the location of the current line */
3733
yyput('*'); yyput('*'); /* Dummy placeholder pointer to next line.*/
3834
uint16_t linenum=atoi(yytext); /* BASIC line number. */

0 commit comments

Comments
 (0)