BLOCKED FILE SAVING AND LOADING BY J.G.HARSTON ============================================== VERSION 1.01, 23 AUGUST 1987 The Spectrum tape routes save the saved data as one single block. The tape routines on some other platforms save tape data in a series of shorter blocks. This gives the ability to rewind after loading errors and retry. This code demonstates how to do this with the Spectrum. Saved data format ----------------- Data is saved in blocks of 256 bytes or longer, each block has a standard header indicating that block's length and where it is to be loaded to. The final block is indicated by having a length of less than 256 bytes. If the final block of actual data is a full block then a zero-length block is saved after it to end the data. Multiple sets of: +----- | Header, length=nn | Data of nn bytes +----- If final block length>255 bytes, additional block: +----- | Header, length=0 | zero-length data block +----- The final zero-length block has to be a header block of zero bytes length as the Spectrum tape routines read the block type byte before checking the length, so it ends up also being the parity byte, so has to be zero to avoid a Tape loading error. Blocks.s -------- Blocks.s is source code to save and load blocked data. The file information is stored in memory and then an entry point is called. On entry to SAVE: START = start address LENGTH = data length BLKLEN = maximum block size to use, must be at least 256 HEADER+0 = file type HEADER+1 to +10 = filename HEADER+15 to 16 = extra address On entry to LOAD: HEADER+0 = file type HEADER+1 to +10 = filename SAVE.s, LOAD.s and *SAVE, *LOAD ------------------------------- LOAD.s and SAVE.s are source for *LOAD and *SAVE commands runnable with the JGH ROM to load and save blocked data. *SAVE filename START+LENGTH *SAVE filename START+LENGTH:BLKLEN Saves a code file, START, LENGTH and BLKLEN are in hexadecimal. If BLKLEN is present, uses that as the maximum block size, otherwise uses a block size of 512. BLKLEN must be 256 or larger. *LOAD filename Loads the file into memory as specified by the headers. Notes ----- The demonstration code loads all the data and stops if any loading error occurs. A further development would be to call lower-level tape routines and catch any loading errors and prompt the user to rewind and retry.