| ★ APPLICATIONS ★ DISQUE ★ RSX - RANDOM DISC ACCESS (POPULAR COMPUTING WEEKLY) ★ |
RANDOM DISC ACCESS![]() | RANDOM DISC ACCESS: Part 2![]() |
Part Two of simulated random access files on the 464 starts right off with syntax details of the new commands available to Basic. The :ID WRITE command takes three parameters; these are, the filename, the offset at which to start writing in the file, and the string of characters to be written. The offset is usually the record number less one, times the record length. For simplicity, I suggest you always use a function similar to FNr in the demonstration program. The number of characters written is taken from the length of the buffer string, this is why it must be padded out to the record length. A typical :ID WRITE command might look like this; f$ = "PCW01.DAT" buf$ "The text to go to the file, padded to the rec len"
This would write out record two. Obviously records can be written out in any order. The |IDREAD command has the same syntax as the |ID WRITE command, that is, filename, followed by offset at which to start reading, followed by buffer string. In this case the buffer string must be equal to the record length and is the number of characters read from the file. So to read back the record we saved about into the string buf$, the sequence would be;
If this all seems rather complicated it will become much clearer by studying the demonstration program (printed last week). A final point to the Basic user, a number of errors can occur, if, for instance, you try to read a record number outside the range of the file, or you give the wrong number of parameters to a command. In each case a clear error message is printed and the program halts with an error number 31. Basic calls this an Unknown Error, and as it never normally occurs, you can check for it in your error trapping routines. The files created by the Create command can be erased as normal using the ERA command. It is not advisable to try and read them using the normal INPUT#9, as there are no 'CR' characters at the end of a record, and unpredictable effects may occur. The assembly language listing is included to illustrate how the program actually works. It should be of interest to anyone who wants to use the DOS from machine code, as it demonstrates reading and writing files, as well as using the Amsdos RSX's from machine code (eg, ERA, REN and DISC). The source code is commented and should be fairly straight forward to understand. The method of simulating random access is to use Amsdos serial files, which are opened, read or written to , and closed within each command. A DWRITE command actually creates a temporary file called "TEMP.RAN" which is never seen by the Basic user as it is deleted before returning to Basic. This simulated random access is not quite as fast as true random access files, but the latter would be very difficult, if not impossible, to implement using Amsdos. However, the method used is much quicker and compact than trying to simulate random access from Basic. The technique used to return an error to the Basic is to load the E register with the error number required, and then to call the error routine in the Basic ROM directly by its physical address ($CA94), having first selected and enabled the Basic ROM. PopularComputingWeekly860123 |
| ![]() |
|