Is there an elegant way to load "zxbasic" files from disk into SAM's memory?
On the SAMDOS system disk, among various utilities, MGT provided a Spectrum BASIC translator. Unfortunately it can only load from tape.
I took a look at the disassembly of the program and it seems straightforward enough: the BASIC data block is loaded into SAM memory at the correct memory page and offset as indicated by SAM's PROGP and PROG system variables (i.e. where the SAM ROM would expect a SAM BASIC program to be).
Once that's loaded, a translation subroutine (at 0x410E) is called that modifies the tokenised BASIC in-place so that the Spectrum keywords are swapped out for their SAM equivalents. Another subroutine (at 0x40BA) deals with the other system values (pointers to the BASIC variables area etc). It's not foolproof but it works really well for simple BASIC programs.
What I would like to do is load from disk rather than tape, then manually CALL the translation routine directly. SAMDOS won't allow us to simply LOAD "zxbasic" CODE, however, and it complains with "wrong file type".
What you *can* do is load raw disk sectors into memory, but of course you need to know which sectors are used by the file you want to open (and deal with any file-headers in the data):
Code: Select all
REM SAMDOS
READ AT disk, sector, track, address
Code: Select all
REM MasterDOS
READ AT disk, sector, track, address, count
It seems like something that would certainly have been covered in the pages of Format given the crossover of SAM and PlusD owners in the readership…but if it was I haven't come across it yet!