When saving Forth or assembly code, the address of the LINK field of the first word you want to save is required as the start address.
Given the following code:
: TEST ( -- ) 200 0 DO I . LOOP ;
To save the above using BSAVE, first obtain the Link Field Address (LFA) of the word, by first obtaining the Code Field Address (CFA) via the word ' (pronounced tick) and passing that to >LINK (pronounced 'to link') to get the LFA:
' TEST >LINK
At this point, the LFA (Link Field Address) of the word TEST is at the top of the stack. It is now only necessary to supply a starting block number to the stack:
10
Now, the word BSAVE can be executed:
BSAVE
Note, all of the above can be entered on a single line:
' TEST >LINK 10 BSAVE
At this point, the word TEST shall be saved to block 10 in binary format. Because the amount of data saved to disk is small, only one block is required, therefore the value left on the stack upon completion shall be 11, as 11 is the next block after block 10.
A more useful example is to take an application such as the Assembler, which starts on block 9 of the utilities disk, and save it to a different block file in binary format. When the assembler is loaded from disk using LOAD, it takes approximately 15 seconds to load and compile (on an emulated system, or a TI with a ramdisk). When loading using BLOAD it takes less than one second, because it is simply loading a pre-compiled program in the exact address it was saved from.
Assuming a freshly booted system, load the assembler from block 9 of the UTILS disk:
9 LOAD
This will load and compile the assembler. Now create a new blocks file on DSK3 called ASSM, with a capacity of 20 blocks:
20 MKBLK DSK3.ASSM
Note that MKBLK automatically sets the new file as the currently USEd blocks file.
Now, it is possible to save the already compiled assembler to the disk. First, we must ensure that we save from the very first word of the assembler program. The first word in the assembler is called R0, so we tick R0 and obtain its LFA, and use this in the BSAVE command:
' R0 >LINK 1 BSAVE
The assembler is now saved to the new blocks file in binary format.
It is essential to realise that BSAVE simply saves from the address that you give it, to the address pointed to by the word HERE. This means the memory saved to disk is the memory starting at the start address that you specify, up to and including the last definition or data compiled to memory.
Also note, when loading a BSAVEd block of memory with BLOAD, it loads the binary saved data starting at the exact same address it was saved from and will overwrite anything that was occupying the memory space prior to loading.
|