DOSPLUS 3.5 for the Model I - SYS4/SYS Disassembled
Page Customization
Page Index
SYS4/SYS
Other Navigation
Introduction/Summary
DOSPLUS 3.5 SYS4/SYS Disassembly - The Granule System (Model I)
SYS4/SYS is the low overlay that the manual calls the granule system: it allocates disk space. It is requested only by SYS0/SYS's record locator (4CFDH), with code 33H (its 4D58H), when the granule of a file that a read or a write needs is not among the five segments kept in the file control block. SYS4/SYS finds the segment in the file's directory entries, adds granules to the file when it ends before that granule, and returns the segment so that the record locator can put it into the control block's list.
The file is a load module of 3 blocks, 594 bytes, from 4E00H to 5051H, with the transfer address 4E00H. It uses the 256 bytes at 5100H, after its end, for the granule allocation table and then the hash index table (5100H); the directory sectors go through the system buffer at 4200HH.
The Parts of SYS4/SYS
| Address | Contents |
|---|---|
| 4E00H-4E4BH | The routine table (routines 2 and 3), routine 2, and routine 3, which returns the segment and updates the list (4E00H, 4E04H, 4E06H). |
| 4E4CH-4E99H | The walk through the segments of the file's entries (4E4CH). |
| 4E9AH-4F64H | Adding granules: growing the last segment, starting new segments, Disk space full (4E9AH). |
| 4F65H-4F9AH | Writing the table and the entry; the self-modified bit test and bit set (4F65H, 4F80H). |
| 4F9BH-500DH | Making an extended entry and finding a free hash index byte (4F9BH, 4FF2H). |
| 500EH-5051H | Reading and writing the two tables (500EH). |
Finding the Segment
The walk (4E4CH) starts at the file's first entry (FCB+07H) and adds up the granules of each segment descriptor (bits 4-0 of the second byte plus 1) until the segment that reaches the granule wanted; FEH links to an extended entry, whose segments are read in turn. Routine 3 (4E06H) then works out the granule's place in the segment and looks for the segment in the control block's list by its cylinder and first granule. A segment that is there (one that has just grown) gets its new granule byte and is returned with the NC FLAG; otherwise the second to fourth elements move one place on, the fifth is dropped, and the segment is returned with the C FLAG for the record locator to store as the second element (its 4D96H).
Adding Granules
When the file's segments end before the granule wanted, the file gets as many granules as it is short (4E9AH). Each one is taken right after the last segment when that granule is free and the segment holds fewer than 32 granules, so a file grows in one piece when it can. Otherwise the next descriptor of the entry starts a new segment, at the first free granule from the cylinder after the last segment to the diskette's last cylinder (the GAT's byte CCH plus 35), then from cylinder 0; no free granule gives error 1BH, Disk space full, after the work done so far is written.
A file whose entry has no segment yet starts its search at a cylinder chosen by the entry's directory sector: the cylinders are divided by the number of directory sectors that hold entries, and the quotient is multiplied by the entry's sector (bits 4-0 of its logical file number). Files whose entries are in different directory sectors therefore start in different parts of the diskette (4EACH-4EC4H).
When the entry's four descriptors are used up, the table and the entry are written and an extended entry is made (4F9BH): a free byte of the hash index table is looked for from the file's first entry on, then from the start (none gives error 1EH, Directory full can't extend file); it gets the hash code of the file's first entry, and the new entry is 90H, the logical file number of the entry before it, twenty bytes 00H and ten FFH (it has no name). The entry before it gets FEH and the new logical file number at +1EH-+1FH, and the walk is made again. The granule tests and sets use BIT n,B and SET n,A instructions whose second byte is stored before they run (4F80H).
Differences from the Manual
The manual does not describe how DOSPLUS 3.5 chooses where a file's space goes; the start cylinder by directory sector, the growth of the last segment and the extended entry without a name are from the bytes. The extended entry gets the hash code of the file's first entry, so it is found under the same code as the file.
Variables
Memory Outside SYS4/SYS
| Address Size | Contents |
|---|---|
| 4200HH-42FFHH 256 bytes | System Sector Buffer Directory sectors (4E5AH, 4F65H, 4FBAH). |
Work Areas
| Address Size | Contents |
|---|---|
| 5100H-51FFH 256 bytes | Table Buffer The granule allocation table, then the hash index table (5100H). |
| 51CCH 1 byte | Cylinder Count GAT byte CCH, the cylinders less 35 (4EACH, 4EF4H, 4F1CH). |
| 4E4AH 1 byte | Place in the Segment The operand of LD A,n (4E11H, 4E49H). |
| 4F66H 1 byte | Entry Logical File Number The entry the walk is at: the operand of LD A,n (4E54H, 4F65H, 4FC2H, 4FDDH). |
| 4F8BH 1 byte | BIT Opcode The second byte of BIT n,B (4F87H). |
| 4F99H 1 byte | SET Opcode The second byte of SET n,A (4F94H). |
| 4FEDH 1 byte | New Logical File Number The operand of LD (HL),n, the link to the new extended entry (4FADH, 4FECH). |
Registers at Routine 3
| Register | Contents |
|---|---|
| IX | The file control block (entry and return). |
| IY | The drive control table: DCT+0EH the directory length, DCT+10H the granules per cylinder. |
| BC | Entry: the granule of the file wanted. Return with the C FLAG: Register C the cylinder and Register B the granule byte of the segment. |
| DE | Return with the C FLAG: the file's granules before the segment. |
| HL | Return with the C FLAG: the second element's last byte (FCB+13H); with the NC FLAG: the descriptor, Register H the granule byte, Register L the cylinder. |
| A | Return: the granule's place in the segment; an error code with the NZ FLAG (14H-18H, 1BH, 1EH or a disk error). |
Outside Routines
| Address | Contents |
|---|---|
| 4485H | SYS0/SYS: DISKIO%, functions 6 (SREAD) and 7 (SWRITE) (500EH). |
| 490CH, 4915H | SYS0/SYS: read and write the directory sector of a logical file number. |
| 4934H | SYS0/SYS: 8 bit multiply (4EC0H). |
| 4943H | SYS0/SYS: 8 bit divide (4EB7H, 4EE7H). |
Disassembly
4E00H - The Routine Table
Data: SYS4/SYS's table of routines 2 and 3, one word each, used by SYS0/SYS's overlay request handler (its 49C9H-49DCH) for the request codes 32H and 33H. SYS0/SYS's record locator requests 33H (its 4D58H) when the granule of a file it needs is not in the five segments of the file control block; no file of the diskette requests 32H or any other code 34H-3FH.
4E04H - Routine 2
Nothing to do when SYS0/SYS's record locator brings SYS4/SYS back.
4E06H - Routine 3 - The Segment of a Granule
Requested with code 33H by SYS0/SYS's record locator (4D58H) with Index Register IX the file control block, Register Pair BC the granule of the file wanted (counted from 0) and Index Register IY the drive's control table (LOCDCT% at its 4D00H). The file's directory entries are searched for the segment holding the granule (4E4CH); when the file ends before it, granules are added (4E9AH). Register A returns the granule's place in the segment. A segment already in the list (it has grown) gets its new count, and the routine returns the NC FLAG with Register H = the segment's granule byte and Register L its cylinder; a segment not in the list returns the C FLAG with Register C = its cylinder, Register B its granule byte, Register Pair DE the file's granules before it and Register Pair HL the last byte of the list's second element, which the record locator fills (its 4D96H). On an error Register A holds its code with the NZ FLAG.
4E4CH - Finding the Segment of a Granule
Walks the segment descriptors of the file's directory entries (the first at FCB+07H, then each extended entry an FEH links to), adding up the granules, until the segment that holds granule Register Pair BC. Register Pair HL returns its descriptor (Register L the cylinder, Register H the granule byte) and Register Pair DE the granules before it, with the Z FLAG. When the list ends first (FFH), granules are added at 4E9AH and the walk is made again. The logical file number of each entry read is kept at 4F66H, the operand of the LD A,n at 4F65H.
4E9AH - Adding Granules to a File
Entered with Register Pair HL at the FFH that ends the segments of the file's last entry (in the buffer at 4200H), Register Pair DE the granules the file holds and Register Pair BC the granule wanted: the file gets Register Pair BC less Register Pair DE plus 1 granules. Each granule is taken next to the last segment when that granule is free (the segment grows, up to 32 granules); otherwise a new segment starts in the next descriptor at the first free granule found from that cylinder on, or, for an entry with no segment yet, from a cylinder chosen by the entry's directory sector, so files are spread over the diskette. When the entry has no descriptor left an extended entry is made (4F9BH). The granule allocation table is read into 5100H and written back with the entry at the end (4F65H).
4F65H - Writing the Table and the Entry
Writes the granule allocation table from 5100H and the directory sector of the entry the walk is at (its logical file number is the operand at 4F66H, stored at 4E54H), after checking that the entry in the buffer at 4200H is active.
4F80H - The Granule Bits
4F80H tests bit Register A of Register B by storing the second byte of a BIT n,B instruction (40H + n times 8) at 4F8BH; 4F8DH returns Register A = the bit n alone by storing the second byte of SET n,A (C7H + n times 8) at 4F99H.
4F9BH - Making an Extended Entry
Reads the hash index table into 5100H and looks for a free entry, from the file's first entry on, then from the start (4FF2H); none gives error 1EH. The new entry's hash index byte is the first entry's hash code. The new entry (FXDE) gets 90H (extended, active), the logical file number of the entry before it at +01H, 00H at +02H-+15H and FFH at +16H-+1FH; the entry before it (the one at 4F66H) gets FEH and the new logical file number at +1EH-+1FH.
4FF2H - A Free Hash Index Byte
Looks in the hash index table at 5100H for a byte 00H (a free entry), first from logical file number Register A on, then from 0. The search goes through the entries of one directory sector (+20H each), then the next sector, up to the directory's last sector (DCT+0EH less 3). Register Pair HL returns the free byte with the Z FLAG, or the NZ FLAG when there is none.
500EH - Reading and Writing the Tables
500EH reads and 5020H writes the granule allocation table (directory sector 0), 5032H reads and 5042H writes the hash index table (directory sector 1), all of drive Register C through 5100H. Each returns the Z FLAG when done, or the NZ FLAG with error 14H, 15H, 16H or 17H.
5100H - The Table Buffer
Not in the file: the granule allocation table (500EH, 5020H) and then the hash index table (5032H, 5042H) of the drive are read here and written from here.