TRS-80 DOS - LDOS 5.3.1 for the Model I - BOOT/SYS Disassembled
Page Customization
Page Index
BOOT/SYS
Other Navigation
Introduction/Summary
LDOS 5.3.1 BOOT/SYS Disassembly - The Boot Sectors and the System Information Sector (Model I)
BOOT/SYS is the first file of every LDOS diskette: granule 0 of cylinder 0, sectors 0-4 (the manual's file list gives it 5 records). It is not a load module. Sector 0 is the boot sector the ROM runs, sector 1 is the boot sector for a boot through a disk driver, sector 2 is the system information sector, sector 3 is a copy of the granule allocation table and sector 4 is not used. FORMAT/CMD writes all of it; the manual says BOOT/SYS and DIR/SYS are never to be copied from one diskette to another.
The file on this page holds seven sectors: the five of BOOT/SYS and sectors 5 and 6 of cylinder 0, which lie outside it. Sector 6 holds the second part of the double density boot module SOLE/CMD writes; on this diskette nothing reads it.
When the computer is reset with a diskette in drive 0, the ROM reads cylinder 0, sector 0 into 4200H-42FFH and jumps to 4200H. The boot sector reads sector 4 of the directory cylinder (the cylinder number is byte 2 of the sector, 4202H), checks that the directory record of SYS0/SYS there is in use, works out where the file's first extent starts, reads it sector by sector into a buffer at 5100H-51FFH, copies each load block to its address and jumps to the transfer address, 4E00H. A free directory record displays No System, a sector that cannot be read in two tries displays Disk Error; both wait for a line from the keyboard and stop the computer until RESET is pressed.
Sectors 0 and 1 are shown at 4200H-42FFH, where they run; sectors 2-5 at 4200H-42FFH too, the buffer SYS0/SYS reads the system information sector into; sector 6 at 52F8H-53F7H, where its code would run. Rows of sectors 1-6 carry ids that name the sector (s1-4224H, for example).
How Sector 0 Reads a Sector
Sector 0 works the floppy disk controller through its memory mapped registers, polling the status:
| Step | What the code does |
|---|---|
| Select | 01H to the drive select latch 37E1H before the directory read and before every sector of SYS0/SYS (4211H, 427EH) |
| Seek | Sector to 37EEH, cylinder to the data register 37EFH, command 1BH to 37ECH; bits 1-0 of the command are the bootstrap step rate FORMAT/CMD puts there (42B4H) |
| Read | Command 88H, then each byte is taken from 37EFH when the status shows DATA REQUEST, until BUSY goes off (42C5H) |
| Check | Status AND 1CH (record not found, CRC error, lost data); on an error Force Interrupt D0H and one more try (42DCH, 42ACH) |
The main register set does the loading (Register Pair HL = the load address, Register B = the bytes left in the record); the alternate set does the reading (Register Pair DE' = cylinder and sector, Register Pair BC' = the buffer pointer). A granule is 5 sectors and a cylinder 10.
The Seven Sectors
| Sector | Contents |
|---|---|
| 0 | The boot sector the ROM runs, 4200H. Byte 2 is the directory cylinder (11H), the operand at 42BCH carries the bootstrap step rate. |
| 1 | The boot sector for a boot through a disk driver, 4200H: entered with Index Register IY pointing at drive 0's drive code table, it reads through the driver (function 09H) and works out the geometry from the drive code table and the allocation table. Byte 2 is the directory cylinder, the operand at 4210H the bootstrap step rate. |
| 2 | The system information sector, 4200H: the configuration file flag, the days in each month, two blocks of eight drive code tables (one for a boot through a driver, one for a boot by sector 0), the date and time prompt switches and the names of the days and months. SYS0/SYS reads it into 4200H at every boot. |
| 3 | A copy of the granule allocation table, 4200H, as FORMAT/CMD wrote it: 35 cylinders of 2 granules, the diskette name LDOS531 and the date 07/14/91. |
| 4 | Not used, 4200H: 00H. |
| 5 | Outside BOOT/SYS, 4200H: bytes left from SYS7/SYS and 6CH. |
| 6 | Outside BOOT/SYS, 52F8H: the second part of SOLE/CMD's double density boot module (a load block for 52FCH-53D0H and the transfer address 5312H). |
SYS0/SYS's reset tells the two boots apart by Index Register IY (0000H after sector 0) and sets bit 0 of 442FH after a boot through a driver; that bit picks the block of drive code tables in sector 2 and the operand it takes the bootstrap step rate from (42BCH for sector 0, 4210H for sector 1).
Variables
Memory Outside BOOT/SYS
| Address Size | Contents |
|---|---|
| 37E1H 1 byte | Drive Select Latch Written with 01H (drive 0) by sector 0 at 4213H and 4280H; each write restarts the drive motor time-out. |
| 37ECH 1 byte | Controller Command and Status Commands 1BH (Seek), 88H (Read Sector) and D0H (Force Interrupt) are written here; reading gives the status (bit 0 BUSY, bit 1 DATA REQUEST, bit 2 LOST DATA, bit 3 CRC ERROR, bit 4 RECORD NOT FOUND). |
| 37EEH 1 byte | Controller Sector Register The sector to read, stored with the cylinder by LD (37EEH),DE at 42B4H. |
| 37EFH 1 byte | Controller Data Register The cylinder for the seek (42B4H), then each byte of the sector as it is read (42D7H). |
| 41D4H-41DFH 12 bytes | Stack (Sector 0) Below 41E0H, set at 4204H: return addresses and the pushes of Register Pairs BC, DE and HL during a read. At the jump to SYS0/SYS, 41DEH-41DFH hold 77H 42H. |
| 4152H-415FH 14 bytes | Stack (Sector 1) Below 4160H, set at 4203H: return addresses, the buffer address, the sectors per cylinder and the pushes of the disk driver. |
| 4200H-42FFH 256 bytes | Boot Sector The sector the boot runs from. SYS0/SYS reads the system information sector (sector 2) into the same place. |
| 5100H-51FFH 256 bytes | Sector Buffer The directory sector of SYS0/SYS (5100H attribute byte, 5116H-5117H first extent), the allocation table (51CDH, sectors 1 and 6) and then each sector of SYS0/SYS. |
| 4700H-4709H 10 bytes | Drive 0 Drive Code Table In SYS0/SYS. Sector 6 copies the driver's drive code table here (53A2H-53A8H); SYS0/SYS's reset copies it from Index Register IY after a boot by sector 1. |
| 442FH 1 byte | Boot Flag In SYS0/SYS. Bit 0 is set by its reset after a boot through a disk driver (Index Register IY not 0000H). |
BOOT/SYS Data and Changed Operands
| Address Size | Contents |
|---|---|
| 4202H 1 byte | Directory Cylinder (Sectors 0 and 1) Byte 2 of the boot sector, the operand of CP 11H: 11H. Read at 4216H (sector 0) and 4229H (sector 1); SYS0/SYS copies it to 4709H. |
| 42BCH 1 byte | Seek Command (Sector 0) 1BH; bits 1-0 are the bootstrap step rate (3). FORMAT/CMD writes it; SYS0/SYS's reset copies the two bits to 4703H. |
| 4210H 1 byte | Bootstrap Step Rate (Sector 1) The operand of OR 00H at 420FH: 00H on this diskette. FORMAT/CMD writes it; SYS0/SYS's reset copies it to 4703H after a driver boot. |
| 42ABH 1 byte | Sectors per Cylinder (Sector 1) The operand of SUB 00H at 42AAH, stored at 423AH. |
| 53BFH 1 byte | Sectors per Cylinder (Sector 6) The operand of SUB 00H at 53BEH, stored at 5339H. |
| 42E4H-42FFH 28 bytes | Sector 0 Texts Clear screen (42E4H), No System (42E7H), Disk Error (42F3H), each ended by 03H. |
| 42E6H-42FEH 25 bytes | Sector 1 Texts No System (42E6H), Disk Error (42F2H), each ended by 03H. |
System Information Sector (Sector 2, at 4200H)
| Address Size | Contents |
|---|---|
| 4200H 1 byte | Mark 53H. |
| 4201H 1 byte | Configuration File Flag C9H no CONFIG/SYS; 00H load it. SYS0/SYS replaces it with 00H after reading it. |
| 4202H-420DH 12 bytes | Days in Each Month January to December; 4203H is set to 28 or 29 by the date prompt. |
| 4220H-426FH 80 bytes | Drive Code Tables, Driver Boot Drives 0-7, 10 bytes each: JP 308AH, two 5 inch and two 8 inch drives present. |
| 4270H-42BFH 80 bytes | Drive Code Tables, Sector 0 Boot Drives 0-7: JP 45FBH (SYS0/SYS's floppy driver), drives 0-3 present, 35 cylinders of 10 sectors. |
| 42C0H 1 byte | Set by BACKUP/CMD FFH. |
| 42C2H 1 byte | Date Prompt Switch 00H ask Date?; other values do not. |
| 42C3H 1 byte | Time Prompt Switch 00H ask Time?; other values do not. |
| 42C7H-42DBH 21 bytes | Day Names Sun to Sat. |
| 42DCH-42FFH 36 bytes | Month Names Jan to Dec. |
Outside Routines
| Address | Contents |
|---|---|
| 0033H | ROM: display the character in Register A (42A4H, 42C2H in sector 1). |
| 0040H | ROM: wait for a line from the keyboard into the buffer at Register Pair HL (429AH, 42B9H in sector 1). |
| 01C9H | ROM: clear the screen (4207H in sector 1). |
| 4E00H | SYS0/SYS: its reset code, the transfer address of SYS0/SYS on this diskette. |
Disassembly
4200H - Sector 0: Boot Sector Entry
When the computer is reset with a diskette in drive 0, the ROM reads cylinder 0, sector 0 (single density) into 4200H-42FFH and jumps to 4200H. This sector finds SYS0/SYS through its directory record (sector 4 of the directory cylinder), reads its first extent sector by sector into the buffer at 5100H-51FFH, copies each load block to its address and jumps to the transfer address (4E00H on this diskette). It works the floppy disk controller directly through its memory mapped registers at 37ECH-37EFH. On entry the ROM has selected drive 0, the stack is the ROM's and interrupts may be on.
422EH - Locate SYS0/SYS on the Diskette
Byte 16H of the directory record is the cylinder of the file's first extent and byte 17H holds its first granule (bits 7-5) and the number of granules less one (bits 4-0). This code works the first granule into a sector number, 5 sectors to a granule, and sets up the alternate register set, which does all the reading from here on: Register Pair DE' holds the cylinder and sector of the next sector to read and Register Pair BC' the pointer into the buffer. Only the first extent is used, read as consecutive sectors.
4242H - Load SYS0/SYS Record by Record
SYS0/SYS is a load module: records of a type byte, a length byte and the data. Type 01H is a load block (two address bytes, then the length less 2 data bytes; a length of 02H gives 256), type 02H is the transfer address, and every other type is passed over by its length. The bytes come one at a time from the buffer through 4279H, which reads the next sector when the buffer is used up.
4279H - Fetch the Next Byte of SYS0/SYS
Returns the next byte of the file in Register A. Works in the alternate register set: Register Pair BC' points into the buffer at 5100H and Register Pair DE' holds the cylinder and sector of the next sector to read. When Register C' wraps to 00H the buffer is used up and the next sector is read into it first. The main registers of the caller are not changed.
4294H - Display an Error and Stop
Disk Error is shown when a sector cannot be read, No System (entered at 4297H with Register Pair HL = 42E7H) when the directory record of SYS0/SYS is free. Both wait for a line from the keyboard and then stop the computer; only RESET restarts it.
429EH - Display a Text
Displays the bytes at Register Pair HL through the ROM until the end byte 03H. Register Pair HL is kept.
42ACH - Read a Sector, Two Tries
Reads cylinder Register D, sector Register E of drive 0 into the buffer at Register Pair BC. The first try is the CALL 42B4H; when it fails, the code falls into 42B4H for a second try, which returns straight to the caller. On return the Z FLAG is set if the sector was read, and Register Pair HL holds the buffer address.
| 1771 FDC Command: 1BH (00011011) | Function Description | ||||||||
| Bit 7 | Bit 6 | Bit 5 | Bit 4 | Bit 3 | Bit 2 | Bit 1 | Bit 0 | Summary of Bits | |
| 0 | 0 | 0 | 1 | 1 | 0 | 1 | 1 | Command=Seek (bits 7-4 = 0001) h = 1: head load and settle delay V = 0: no verify r1 r0 = 11: 40 ms stepping rate | |
| 1771 FDC Command: 88H (10001000) | Function Description | ||||||||
| Bit 7 | Bit 6 | Bit 5 | Bit 4 | Bit 3 | Bit 2 | Bit 1 | Bit 0 | Summary of Bits | |
| 1 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | Command=Read Sector (bits 7-5 = 100) m = 0: one sector b = 1: IBM sector length E = 0: no head load delay | |
| 1771 FDC Command: D0H (11010000) | Function Description | ||||||||
| Bit 7 | Bit 6 | Bit 5 | Bit 4 | Bit 3 | Bit 2 | Bit 1 | Bit 0 | Summary of Bits | |
| 1 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | Command=Force Interrupt (bits 7-4 = 1101) I3-I0 = 0000: end the command, no interrupt | |
42E4H - Sector 0: Texts
The three texts this sector displays through 429EH, each ended by 03H.
Sector 1: The Boot Sector for a Driver Boot
Sector 1 also runs at 4200H-42FFH. It is the boot sector for a computer whose own boot code reads the diskette through a disk driver and enters this sector with Index Register IY pointing at drive 0's 10 byte drive code table, whose first three bytes are a JP to the driver. Every read goes through that driver (JP (IY) at 42D5H): function 09H (read a sector) with Register C = drive, Register D = cylinder, Register E = sector and Register Pair HL = the buffer, the same registers SYS0/SYS's own read primitive at 4777H passes. SYS0/SYS's reset (4E4FH-4E61H) sees that Index Register IY is not 0000H, copies the 10 bytes at IY to drive 0's drive code table at 4700H and sets bit 0 of 442FH, which makes it take the drive tables of drives 1-7 from the block at 4220H-426FH of the system information sector (sector 2) instead of the block at 4270H-42BFH. The entries of that block jump to 308AH, outside the LDOS files, and describe two 5 inch and two 8 inch drives, the default configuration the manual gives for the Lobo LX-80 interface; MISOSYS documents bit 0 of 442FH as the flag of a boot from that interface. FORMAT/CMD writes this sector from its image at 6C00H, with the directory cylinder at 4202H and the bootstrap step rate at 4210H.
424CH - Locate SYS0/SYS (Sector 1)
The first extent of SYS0/SYS (bytes 16H-17H of its directory record) gives the cylinder and the first granule. Here the sectors per granule come from the drive code table (bits 4-0 of byte +08H, plus 1), and the granule number is multiplied by them through 42D7H. The read position is set up in the alternate register set, as in sector 0.
4266H - Load SYS0/SYS Record by Record (Sector 1)
The same loader as sector 0 (4242H): type 01H records are copied to their load address, type 02H gives the transfer address, any other type is passed over by its length. The bytes come from 429DH.
429DH - Fetch the Next Byte (Sector 1)
Returns the next byte of SYS0/SYS in Register A, working in the alternate register set (Register Pair BC' = buffer pointer, Register Pair DE' = next cylinder and sector). When Register C' wraps to 00H the next sector is read through the driver; the sector number wraps at the sectors per cylinder stored at 42ABH.
42B3H - Display an Error and Stop (Sector 1)
Disk Error when the driver cannot read a sector of SYS0/SYS; No System (entered at 42B6H with Register Pair HL = 42E6H) when its directory record is free. Then the computer waits for a line from the keyboard and stops.
42BDH - Display a Text (Sector 1)
Displays the bytes at Register Pair HL through the ROM until the end byte 03H; Register Pair HL is left pointing at the 03H.
42C9H - Read a Sector Through the Driver
Reads cylinder Register D, sector Register E of drive 0 into the buffer at Register Pair BC by calling the disk driver through the drive code table at Index Register IY with function 09H. The driver's Z FLAG (set = read) and Register A (the error) come back to the caller; Register Pair HL is kept.
42D7H - Multiply Two Bytes
Returns in Register A the low 8 bits of Register A times Register E, by shift and add. Register D is left holding the first factor and Register E is shifted to 00H; Register Pair BC is kept.
42E6H - Sector 1: Texts
The two messages of this sector, each ended by 03H, and the last byte of the sector.
Sector 2: The System Information Sector (Data)
Sector 2 of cylinder 0 holds the system information of the diskette. SYS0/SYS's reset reads it into 4200H-42FFH (its 4E85H-4E8CH: cylinder 0, sector 2, through the read primitive at 4777H) and uses it there, so the rows show each byte at that address. SYS7/SYS (SYSTEM, its 5A61H and 5A6EH) reads and rewrites it to keep the DATE, TIME, BSTEP, DRIVE and SYSGEN settings; BACKUP/CMD copies it to the destination diskette with byte 01H set to C9H (its 6689H-66A2H). FORMAT/CMD writes a new diskette's sector 2 as 53H followed by 255 bytes of 00H (its 634BH-6361H); this diskette carries the settings of its master.
Sector 3: The Copy of the Granule Allocation Table (Data)
FORMAT/CMD writes its finished image of the granule allocation table (its 6A00H-6AFFH) to sector 3 of cylinder 0 as well as to sector 0 of the directory cylinder (its 6338H-6348H); BACKUP/CMD copies it to the destination (its 6698H-66A2H, 66C7H-66D1H). The rows show each byte at 4200H plus its offset, the place the allocation table takes in the buffer at 4200H. This copy shows the diskette as FORMAT/CMD left it: 35 cylinders of 2 granules, with only BOOT/SYS and the directory cylinder in use.
Sector 4: Not Used (Data)
Sector 4 of cylinder 0 is the last sector of BOOT/SYS (the manual's file list gives BOOT/SYS 5 records). No code reads it at boot; BACKUP/CMD copies it to the destination together with sectors 2 and 3 (its 66A5H-66B5H, 66D4H). On this diskette it is all 00H.
Sector 5: Outside BOOT/SYS (Data)
The file holds two more sectors than BOOT/SYS's five: sectors 5 and 6 of cylinder 0, granule 1, which the allocation table copy in sector 3 shows as free. No code on this diskette reads them. Sector 5 holds the last 23 bytes of SYS7/SYS (its file offsets 3200H-3216H), 12 more bytes and 221 bytes of 6CH.
Sector 6: Second Part of a SOLE/CMD Boot Module (Outside BOOT/SYS, Dead Code on This Diskette)
SOLE/CMD makes a diskette boot in double density by writing a load module to sectors 5 and 6 of cylinder 0 (its 527FH-52BBH) and patching sector 0 to load it (52BEH-52D8H: Index Register IY = 421CH and the code at 4216H). Sector 6 on this diskette holds the second part of that module, byte for byte as SOLE/CMD writes it: a load block of 213 bytes for 52FCH-53D0H and the transfer address 5312H. Sector 0 is not patched and sector 5 does not hold the first part, so nothing reads this sector. The rows show the code at the addresses it would run at, 52F8H plus the offset in the sector. The module's first part (in SOLE/CMD's image at 5500H-55FBH, which it would load to 5200H-52FBH) is the double density read driver the code below calls through Index Register IY, and the routines at 52BFH and 52D1H.
5312H - The Module's Loader (Transfer Address, Dead Code on This Diskette)
The transfer address of the module: the loader that finds SYS0/SYS through the directory and loads it record by record, reading every sector through the double density driver at Index Register IY. It reuses the messages of sector 0 (4229H, 4294H), which stays at 4200H.
53B0H - The Module's Byte Fetch (Dead Code on This Diskette)
Returns the next byte of SYS0/SYS in Register A, working in the alternate register set (Register Pair BC' = buffer pointer, Register Pair DE' = next cylinder and sector), as sector 1 does at 429DH.
53C7H - The Module's Sector Read Through the Driver (Dead Code on This Diskette)
Calls the driver at Index Register IY with the buffer address in Register Pair HL, cylinder Register D and sector Register E. No function code or drive number is loaded: the double density driver of this module only reads (SOLE/CMD's image at 5500H sets its own Register Pair BC: 5 tries, command 88H).