The method Amstrad opted for to interface disc commands to Basic has the tremendous advantage of making nearly all software written for cassette directly compatible with disc drives. However, it has the disadvantage of supporting only serial files, that is files can be opened, read in record one, followed by two, followed by three and so on. There is no facility for 'Random Access'files, (although these are supported in the CP/M environment). In a random access file any record can be read at random. For example, record 55 can be read directly, without Basic having to read in and skip over records 1 to 54 as with a serial file.
The machine code program presented here over the next two weeks gives the Basic programmer the facility to use simulated random access Tiles. I say simulated because the program itself uses Amsdos serial files as there is no file mapping available in Amsdos, but to the Basic user the files appear to be randomly accessible. Another advantage of using this filing system is that as files do not have to be opened and closed there is no limit to how many files a Basic program can access 'at once'. Amsdos normally supports only one input and one output file simultaneously.
The user interface is via three new RSX commands, these are DREAD, DWRITE and CREATE. Each will be described in detail, but you will find it easier to understand their use by using and studying the demonstration program included. To use the new commands you will first of all need to type in and run the Basic loader program, this will inform you if you have made any errors in the data statements, in which case you should recheck your listing.
Before you can read or write to a file it must first be created, using the CREATE command. This is followed by a filename string and the maximum size of the file. Note that once created you cannot enlarge a file, so always over estimate the number of bytes required. The usual format of RSX's is required, that is a '|' (shift @) character preceding the command name, and a comma directly after it. This should be familiar to disc users as it is the same as is used by the ERA, REN, DIR, etc. commands. A valid sequence to create a file called "PCW01.DAT", which can hold up to 2000 characters would be:
f$ = "PCW01.DAT" |CREATE, @f$,2000
A random file must have a fixed record length, (the number of characters. m each record). In the demo program this is 40 characters. When writing a string to a file you must pad out the length to the full record length with spaces, using for example the function FNp$ as in the demo program. Details of DWRITE and DREAD next week.