Skip to content

Commit

Permalink
Autoadjust BASIC start offset based on filesize. Emit warnings, error.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
hackerb9 committed Jul 31, 2024
1 parent df1d114 commit c05b51a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
25 changes: 23 additions & 2 deletions m100-tokenize-main.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,30 @@ int fixup_ptrs() {
/* Offset into RAM for start of the first BASIC program.
0x8001: Used by Model 100, Tandy 102, Kyocera-85, and Olivetti M10.
0xA001: Used by Tandy 200 (which has more ROM and less RAM). */
int offset = 0x8001;
long offset = 0x8001;

ptr[nlines++] = ftell(yyout); /* Pointer to final NULL byte */
long filesize = ftell(yyout); /* Pointer to final NULL byte */
ptr[nlines++] = filesize;

/* Double-check size of .BA file */
fprintf(stderr, "file size is 0x%x\n", filesize);
if ( filesize >= 0x10000 ) {
fprintf(stderr, "Fatal Error. Program too large to fit in 64K RAM.\n");
fprintf(stderr, "Due to 16-bit pointers in BASIC, this cannot work.\n");
exit(1);
}
else if ( filesize >= 0x8000 ) {
fprintf(stderr, "Warning. Program too large to fit in 32K RAM.\n");
fprintf(stderr, "The output cannot run on any standard hardware.\n");
if ( filesize+offset >= 0x10000 )
offset=0;
}
else if ( filesize >= 0x6000 ) {
fprintf(stderr, "Notice. Program too large to fit in 24K RAM.\n");
fprintf(stderr, "The output cannot run on a standard Tandy 200.\n");
if ( filesize+offset >= 0x10000 )
offset=0x8001;
}

if (fseek(yyout, 0L, SEEK_SET) != 0) {
perror("fseek");
Expand Down
4 changes: 0 additions & 4 deletions m100-tokenize.lex
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@
%%

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

0 comments on commit c05b51a

Please sign in to comment.