TRSDOS 6.2 for the Model 4 - SYS10/SYS Disassembled
Page Customization
Page Index
SYS10/SYS
Other Navigation
Introduction/Summary
TRSDOS 6.2 SYS10/SYS Disassembly (Model 4)
SYS10/SYS is the overlay of @REMOVE (SVC 57), the system's only way to delete a file. It is a load module of 257 bytes, 212 of them loaded: 210 at 1E00H-1ED1H and the length word at 23FEH-23FFH, with its transfer address at 1E00H. A program opens the file and calls @REMOVE with Register Pair DE pointing at the FCB; the stub at 19A6H on the SYS0/SYS page sends request 9CH, and RST28 has CKMOD@ load SYS10 into the overlay area, unless OVRLY$ shows it is still there, and calls 1E00H (1E00H). The REMOVE command (member 5 of SYS6/SYS), PURGE (member 5 of SYS7/SYS), SYSGEN (member 2 of SYS8/SYS), BACKUP/CMD, CONV/CMD and BASIC's KILL remove files this way.
For an open file SYS10 first checks the access level the file was opened with: only FULL or REMOVE (levels 0 and 1) may remove it, any other gives error 37 with nothing changed (1E0BH). On a write protected diskette @OPEN gives the FCB READ access, so @REMOVE fails here with error 37, not 15; an FCB built by hand, as PURGE builds it, gets error 15 from the first @DIRWR with nothing changed. It reads the GAT of the drive into DIRBUF$ (2300H) and then works through the file's directory entries, the primary entry (FPDE) at the file's DEC and each extended entry (FXDE) it links to. For each entry it walks the extent fields from DIR+22 and clears every granule of each extent in the GAT copy, stopping at a field that starts with FEH (a link) or FFH (the end); it marks the entry spare by resetting bit 4 of DIR+0 and writes the directory sector, then reads the HIT, puts 00H at the entry's position and writes the HIT. A link sends it on to the FXDE named in the field (1E1BH). After the last entry it writes the GAT and fills the 32 bytes of the FCB with 00H. The return goes through RESTREG, set up by CKOPEN@, so the caller gets back Register Pairs BC, DE and HL and Index Register IX; Register A holds 00H with the Zero flag, or the error with NZ.
The granules of an extent are cleared by RMVEXT (1E89H). The first byte of the extent field is the cylinder and so the GAT byte; the second gives the first granule in bits 7-5 and the count less one in bits 4-0. The granules per cylinder are DCT+8 bits 7-5 plus one, doubled for a two sided drive (DCT+4 bit 5), and the count runs on into the next GAT byte when the cylinder is used up. Each bit is cleared with an instruction RES n,B that RMVGRN writes for the granule (1EC5H).
An FCB that is not open goes another way (1E6BH). If its type byte is 10H, a device that @OPEN or @INIT routed to, @REMOVE closes it as @CLOSE would: the FCB becomes an asterisk, the device's two letters and 03H. The device stays as it is; removing a device is the REMOVE command's work with the DCB, not this SVC's. Any other FCB gets error 38, File not open.
The bytes are those of the TRSDOS 6.2.1 Level AR system diskette. The labels are those of Logical Systems' own source of the system, whose SYS10/ASM is headed LDOS 6.2 and dated 11 February 1983: aligned against this file it accounts for all 212 loaded bytes over 124 source rows with no instruction unexplained.
This file is the same program in LS-DOS 6.3.1H. Laid into memory through their own load records the two releases' SYS10/SYS images are identical to the byte, all 212 of them, and all 123 instructions stand at the same address doing the same thing. The two files differ in twenty bytes and nowhere else: the copyright record at file offset 0008H, which is never loaded, reads *(C) 1982,83,84 by LSI* here and (C) 1982-4,6,90 MISOSYS in the later release. So the LS-DOS 6.3.1 SYS10/SYS page is this same disassembly under the later name, and the two bugs below are those two bugs one generation earlier. The only way this system has of deleting a file was written in February 1983 and never changed again.
Notes
The entries are written as they are freed, the GAT only at the end. A disk error once the first directory write has reached the disk (its verify, the HIT read or write, the read of an FXDE, or the GAT write) returns at once: the entries written so far are spare, an entry whose HIT step failed keeps its HIT position, an FXDE not yet reached stays in use with its FPDE gone, and the GAT on the disk still shows all the granules in use (T28). An error in the GAT read or the FPDE read, or a write protected disk (error 15 at 1E44H), changes nothing. The FCB is then left open, and a second @REMOVE with it finishes the removal, since the walk does not test the in use bit; REMOVE and PURGE stop at the first error, and once the FCB is gone the file cannot be opened again (error 24).
The rest of a spare entry is left as it was, its name, dates and extent fields with it. Nothing tests whether another FCB has the same file open, which is a bug of SYS3/SYS. Nor is the entry at FCB+7 checked to be in use or to hold the file's name, so an FCB whose file was already removed, or whose diskette was changed, removes whatever entry now has that DEC (T29). A freed FXDE keeps bit 7 (80H) and the spare FPDE its FE link, where CLOSE writes 00H and FFH FFH; nothing reads a spare entry. Functions 2 to 7 of the request return NZ with Register A holding the function times 10H; no stub sends them.
There are no hidden instructions. Three operands are written while SYS10 runs: the LD DE at 1E53H keeps the extent field that ended each entry's walk (1E54H), the CP at 1EB9H the granules per cylinder (1EBAH), and the RES at 1ECFH its bit number (1ED0H). The GAT read at 1E21H puts the last two bytes of the GAT over the overlay length at 23FEH-23FFH.
Bugs (listed on the TRSDOS 6.2 reference page): T28, @REMOVE writes each directory entry and the HIT as it frees them and the GAT only at the end, and returns at the first disk error: once the first directory write has reached the disk the file is left half removed, its entries spare (one perhaps still in the HIT), an FXDE not yet reached in use with no FPDE, and all its granules allocated in the GAT on the disk, so the file can no longer be opened and its space is lost (1E27H, 1E52H, 1E5FH); T29, the entry at the FCB's DEC is freed without a test that it is still the file's, so removing through a second FCB of a file already removed, or through an FCB kept open across a diskette change, deletes whatever file now has that DEC (1E1BH).
Variables
Memory Used by SYS10/SYS
| Address Size | Contents |
|---|---|
| 1D00H-1DFFH 256 bytes | SBUFF$ The directory sector of each entry (1E24H), then the HIT (1E47H), changed at 1E42H and 1E4DH. |
| 1E54H-1E55H 2 bytes | EXTINFO+1 The extent field last read (1E2FH), loaded at 1E53H after the walk. |
| 1EBAH 1 byte | GRNSCYL+1 The granules per cylinder (1EA2H), compared at 1EB9H. |
| 1ED0H 1 byte | RMVGRN1+1 The second byte of RES n,B (1ECCH). |
| 2300H-23FFH 256 bytes | DIRBUF$ The GAT of the drive (1E21H), changed by RMVEXT (1EB6H) and written at 1E5CH. |
| 23FEH-23FFH 2 bytes | Overlay length 00D2H, the length of SYS10 read by SYSTEM (SYSRES); written over by the GAT read. |
Routines of Other Files Called
| Address | Routine |
|---|---|
| 1566H, 1568H | LNKFCB@ and CKOPEN@ (SYS0/SYS): Index Register IX to the FCB, the return through RESTREG (1E70H, 1E0BH). |
| 1803H | @DIRWR (SYS0/SYS): writes SBUFF$ to the directory sector of entry Register B (1E44H). |
| 1874H, 1875H | @GATRD and @GATWR (SYS0/SYS): read and write the GAT in DIRBUF$ (1E21H, 1E5CH). |
| 1897H, 1898H | @HITRD and @HITWR (SYS0/SYS): read and write the HIT in SBUFF$ (1E47H, 1E4FH). |
| 18BBH | @DIRRD (SYS0/SYS): reads the directory sector of entry Register B into SBUFF$, Register Pair HL to the entry (1E24H). |
| 1A2BH | @DCTBYT (SYS0/SYS): a byte of the drive's DCT (1E8DH, 1E99H). |
Disassembly
1E00H - SYS10: @REMOVE
@REMOVE (SVC 57) is LD A,57 and RST 28H with Register Pair DE pointing at an FCB; the stub at 19A6H on the SYS0/SYS page sends request 9CH, so RST28 has CKMOD@ load SYS10, unless OVRLY$ shows it is still there, and calls 1E00H. For an open file, with REMOVE or FULL access, SYS10 gives every granule of the file back in the GAT, marks its directory entry and any extended entries spare, puts 00H in their HIT positions and clears the 32 bytes of the FCB. For a device opened as a file it only turns the FCB back into the device specification, as @CLOSE does. The REMOVE command (member 5 of SYS6/SYS), PURGE (member 5 of SYS7/SYS), SYSGEN (SYS8/SYS), BACKUP/CMD, CONV/CMD and BASIC/CMD use it.
1E1BH - REMOV1: Free the Granules, the Entries and the HIT Positions
The GAT of the file's drive is read into DIRBUF$ (2300H) and kept there to the end. For the file's primary directory entry (FPDE) and then each extended entry (FXDE) in turn, the extent fields from DIR+22 are walked: each extent's granules are cleared in the GAT copy (RMVEXT), and the walk ends at a field whose first byte is FEH (the link to an FXDE) or FFH (no more). The entry is then marked spare and written, and its HIT position set to 00H and the HIT written; a link sends the work on to the FXDE. Only after the last entry is the GAT written back. An error returns at once. Before the first directory write has reached the disk nothing has changed; after it, the entries already marked spare stay spare and the GAT on the disk still allocates their granules, because it is written only at 1E5CH (T28). Nothing tests that the entry at the FCB's DEC is in use or holds the file's name (T29).
1E6BH - CLOSDCB: A Device Opened as a File
The FCB is not an open file. If its type byte is 10H, a device that @OPEN or @INIT routed to (DEVOPEN), @REMOVE only closes it: the FCB becomes an asterisk, the two letters of the device name from FCB+6 and FCB+7, and 03H, the way @CLOSE leaves it (CLOSDEV in SYS3/SYS). The device itself is not removed. Any other FCB gets error 38.
1E89H - RMVEXT and RMVGRN: Clear the Granules of an Extent
Register Pair DE holds an extent field: Register E the cylinder relative to the start of the disk, which is the GAT byte (2300H plus the cylinder); Register D bits 7-5 the first granule and bits 4-0 the count less one. The granules per cylinder come from the drive's DCT (DCT+8 bits 7-5, plus 1, doubled for a two sided drive: DCT+4 bit 5). The granules are cleared one by one with a RES n,B that RMVGRN builds, going on to the next GAT byte when a cylinder is used up, as an extent may run over cylinders.