Direct interpretation from disk in MineOS


The DISKIN word, defined below, can be used to feed a disk image directly into the interpreter loop. So you can edit the disk image as text file in your
favorite text editor and then just do DISKIN. Since the compilation can take long time for larger programs, it will print out the input as we go by. The following limitations apply:
  • Do not use too long lines - I recommend up to 128 bytes maximum (there is no check and anything over 64 bytes will spill into return stack area)
  • The text file should have 128-byte worth of blanks or comments at the end, to make sure we read the 128-sector boundary correctly. I usually use 2 lines of some commented text fluff (as you can see in the code below).

Note: I originally wrote the following code for MineOS 1.0. You can use it with MineOS 1.1 I think but be aware that it uses a different DISKRS and already has \ comments.

: \ FALSE TIBPTR @ C! ;
1 VOCAB @ 3 - C!
\ The above defines comments like this one
 
: DISKRS \ addr sect -- bool
\ Read disk 128-byte sector sect from address addr, return if success
 DISKADDR @ RBP! 896 ! 4 898 C!
 BEGIN 898 C@ DUP 4 = WHILE DROP TICK REPEAT
 0= IF 768 SWAP 128 MOVE TRUE ELSE DROP FALSE THEN ;
 
: TOKEOL \ addr -- addr
\ Find either CR, LF or NUL in the string, replace with NUL, return next address
 BEGIN DUP C@ DUP 10 <> OVER 13 <> AND SWAP 0<> AND
 WHILE 1+ REPEAT FALSE OVER C! 1+ ;
 
: DISKIN2 \ --
\ Execute the interpreter
 >R >R TIB DUP TYPE CR INTERPRET R> R> ; 
: DISKIN1 \ --
\ Interpret disk sector
 1024 BEGIN DUP TOKEOL 2DUP SWAP - ROT OVER
 TIBPTR @ SWAP MOVE OVER 1152 <=
 WHILE DROP DISKIN2 TIB TIBPTR ! REPEAT
 1- TIB + TIBPTR ! DROP ; 
: DISKIN \ --
\ Interpret from disk
 CR TIB TIBPTR ! FALSE DUP 1152 !
 BEGIN 1024 OVER DISKRS WHILE
 DISKIN1 1+ REPEAT DROP
 TIB FALSE OVER ! TIBPTR ! ;
 
 
\ These two lines are here to prolong the file by one 128-byte sector
\ so that we ensure all code is processed correctly. DO NOT REMOVE !!!