|★ APPLICATIONS ★ PROGRAMMATION ★ DIRECT ACCESS ROUTINES ★|
|Direct Access Routines|The Amstrad User)||Applications Programmation|
It is possible to go one better than the standard AMSDOS file access system, says Petr Lukes
This program demonstrates how to access any part of a disc, without using the sequential file system implemented in AMSDOS. It uses the routines from CUSTOM FORMATS, TAU, February 1988, and could be used as a building block for implementing a Direct Access file system.
Direct Access is often referred to as Random Access, but this term is not very appropriate. A randomly selected record would not be of much use for anything; a particular record is needed, and for that we need some means of locating it. The term Relative Access is also used, meaning that records are referenced in relation to the first record of the file.
Direct Access filing systems incorporate algorithms for computing the location of a record based on its key. An address file would consist of records with fields allocated to surname, initials, etc. with the surname field most likely designated as the key. The filing system would then store and retrieve the individual records using the given algorithm (it could be hashing, binary tree or one of many others), as required. Designing an efficient Direct Access file is not a trivial matter, and I have not attempted it here.
The program merely demonstrates how to read, edit and write any record if its location is known. It considers the whole disc is available to it, without any regard for any reserved tracks or directories. Do not experiment on a disc which holds wanted data.
AMSDOS uses sectors of 512 bytes, each identified by the track number (0 to 39d) and sector number on that track (c1H to c9H in case of a DATA disc); the program uses blocks of the same size as a sector but numbered consecutively from 0 to 359d. For the chosen record size of 128 bytes, there will be 1440 (40*9*512/128) records numbered consecutively from 0 to 1439. A filing system could allocate some records to two or more files or to a directory, the same ways as CP/M does.
One application which would not be too difficult to implement is a year's diary (I know it has been done before, with the AMSDOS filing structure). There would be enough space for close to two years with two days per block on a normal disc; an alternative would be a disc formatted to 41 tracks by FORMATS (one extra track on the disc should be quite safe; I have tried it but the risk is yours), so giving 369 blocks: enough for one day per block and some overlap of the previous and next years.