TRSDOS 6.2 for the Model 4 - SYS0/SYS Disassembled
Page Customization
Page Index
SYS0/SYS
Parts of the File
Other Navigation
Introduction/Summary
TRSDOS 6.2 SYS0/SYS Disassembly (Model 4)
SYS0/SYS is everything resident in TRSDOS 6.2 that is not in BOOT/SYS. LBOOT on the BOOT/SYS page reads it record by record through the floppy disk driver and jumps to its transfer address, 1E00H. It is a load module of 43 load blocks, 4708 bytes of file and 4499 bytes loaded, every one of which is on exactly one row of this page, and the blocks go to five places: low memory (0000H-01FFH, the restart vectors, the time, the interrupt vectors and the task table, the 26 system flags, the system control blocks and the supervisor call table), 0380H-03FFH (the stack guard, @PAUSE, @SOUND, @DECHEX and the reboot stub), the resident system SYSRES at 1300H-1CFFH, the start-up code at 1E00H-2166H, which runs once and is then overwritten by the first overlay to load, and the sign-on screen, which is loaded straight into video memory at F80DH-FE27H in sixteen blocks.
SYSRES holds the file positioning routines from 1300H: the byte I/O that @GET and @PUT reach for an open file, the record services @READ, @WRITE, @POSN, @LOC, @LOF and the rest, the end of file test, the translation of a record number into a cylinder and a sector through the extents of the file control block, the allocation of space as a file grows, and the directory, GAT and HIT routines. Then comes the loader: @HIGH$, the stubs of the calls a system overlay serves, the disk calls, the RST 28H dispatcher, the routine that reads an overlay into 1E00H or a library member into 2400H, @LOAD, @RUN and the load module reader. Last is the task processor: the interrupt handler, the real time clock interrupt that runs the twelve task slots, and the task calls.
The start-up points the non maskable interrupt at the floppy disk driver, sets the ports from their images in low memory, works out how much memory the machine has, asks for the date and the time unless SYSTEM has turned the prompts off or a date survived a reset, shows the date, looks at the D, ENTER and CLEAR keys and at the AUTO command, loads the SYSGEN configuration, restores the drives and ends in the AUTO command or at TRSDOS Ready.
The bytes are those of the TRSDOS 6.2.1 system diskette, patch level AR. The labels and the names of the system's cells are those of Logical Systems' own source of TRSDOS 6.2, which is one patch level behind this release at level AD: aligned instruction by instruction against the whole of this file it leaves one instruction and five bytes unaccounted for, which are listed under Notes, so every label on this page sits on the instruction the source gives it.
Notes
Bugs (listed on the TRSDOS 6.2 reference page): T6, the search for a cylinder with a free granule (1756H) has no limit where the GAT's cylinder map ends, which a drive of more than 203 cylinders would need (latent); T7, EXITBRK (1C8EH) goes to the debugger or the BREAK vector without putting the memory map, the logical bank or NFLAG$ bit 6 back; T8, the start-up accepts only the years 1980 to 1987 (1ECAH), which is the limit that made an upgrade unavoidable and that LS-DOS 6.3 was sold to lift; T9, bit 7 and bit 0 of DATE$+4 are set and never cleared (1ED4H), and this file does not load the byte, so both survive a reset; T10, the boot key test reads keyboard rows 0 and 6 as one byte (1FDAH), so the down arrow starts the debugger as D does and the at sign skips the AUTO command as ENTER does; T11, the CLEAR key test reads rows 5 and 6 as one byte (204CH), so the space bar, the 9 and the oblique stroke all skip the SYSGEN configuration; T12, a reply of fewer than three fields does not end the parse (20F6H), so a short time reply is completed from whatever is left in the buffer at 1E00H. T6 and T7 stand in the same instructions in LS-DOS 6.3.1 and so are its bugs too, and so, in a wider form, are T9 to T12; T8 is the one the later release fixed outright.
Three places hide an instruction in the operand of another: 1567H (0D2H, so LNKFCB@ skips the open test of CKOPEN@), and 1874H and 1897H (0F6H, an OR 0AFH that sets NZ for @GATRD and @HITRD one byte before the XOR A of @GATWR and @HITWR).
Several instructions are written over while the system runs: FDDINT$ at 000EH by SYSTEM (SMOOTH); the debugger hook @DBGHK at 199FH (1A68H, 1A7AH, 1C75H); the operand bytes at 13EAH (the verify), 1650H and 1660H (IOREC), 16A7H (ALLOC), 1760H (CG17), 17ACH (STUFDEC), 1802H (NHIT3), 1839H (NHIT7), 1862H and 186DH (TSTBIT and SETBIT), 1A70H, 1A75H and 1A79H (the dispatcher), 1AD2H, 1BB3H, 1C88H (the BREAK vector) and 1CECH (@RPTSK); and in the start-up 1FD2H and 2002H, both of which patch the stub at 2056H before it is moved to 4350H.
The stub at 2056H-20ADH is shown at the addresses it is loaded at and runs 22FAH higher, at 4350H-43A7H: 2019H moves it there because 1E00H-23FFH is where the SYSGEN configuration and then the overlays load. Its run addresses are the same as LS-DOS 6.3.1's, 4360H for the call to @ICNFG and 4398H for the store at 0038H, although its file addresses are 28H lower.
A supervisor call number below 128 is looked up in SVCTAB$ (0100H), and the dispatcher copies the caller's Register C into Register A before it jumps to the routine it finds. A number with bit 7 set is an overlay request: its bits 3-0 name the overlay and its bits 6-4 the function wanted in it.
The whole of this file against Logical Systems' source of level AD. Over 2153 source rows and all 4499 loaded bytes there is one instruction and there are five bytes that the two do not share, and every one of the six is a patch of the levels between AD and AR rather than a mistake in the source: at 1A16H this release calls @BANK as a supervisor call, LD A,66H and RST 28H, where the source has a plain CALL into the routine, the same three bytes either way; FDDINT$ at 000EH ships as DI where the source leaves NOP, which goes with bit 3 of DFLAG$ being set; OSRLS$ at 003BH is 01H against 00H, which with OSVER$ at 0085H is what makes this release 6.02.01 and the source's 6.02.00; DFLAG$ at 006DH is 0AH against 02H, so type-ahead and SMOOTH are both on where the source has type-ahead alone; and the sign-on text in video memory carries this version and this year of copyright where the source carries the earlier ones.
Against LS-DOS 6.3.1, which Part 13 of this project disassembles in full. This release answers 99 supervisor calls where LS-DOS answers 107: 95 (@HEXD) and 107 (@VDPRT) are later additions and hold the invalid word here. @DATE is call 18 at 07A8H here, in the clock module of BOOT/SYS beside @TIME, where LS-DOS moves it into this file at 1420H. Every one of the fifteen file services, calls 61 to 75, is at a different address in the two releases, because LS-DOS re-laid the whole of 1300H-15FFH. And @SEEKSC, call 71, is a routine of its own here at 1421H that seeks the drive to a record, where LS-DOS points it at a RET and its own update sheet says the call does nothing.
Index Register IX points at the file control block through the whole of the file positioning code. Its bytes as that code reads them: byte 0 the access and type, with bit 6 set when the file may be written; byte 1 bit 7 byte or record working, bit 6 the end of file moves only when the file grows, bit 5 the buffer does not hold the record wanted, bit 4 the buffer has been changed, bits 2-0 the access level; bytes 3 and 4 the buffer address; byte 5 the offset of the next byte in the buffer; byte 8 the end of file offset; byte 9 the logical record length; bytes 10 and 11 the next record number; bytes 12 and 13 the ending record number.
Variables
Memory the Parts Written So Far Use and Do Not Show
| Address Size | Contents |
|---|---|
| 0300H-037FH 128 bytes | STACK$ The system stack, which BOOT/SYS loads and this file does not. It rests at 0380H and grows downward; the two zero bytes at 0380H are the guard under it. |
| 0470H-04BFH 80 bytes | DCT$ The eight drive code tables, ten bytes each, which BOOT/SYS loads. The stub moves a configured set over them at 2064H, and Index Register IY points at the table of the drive in hand through the disk code. |
| 04C4H 1 byte | RSTOR$ Whether the drives are to be restored at boot, read by the stub at 2078H. BOOT/SYS loads it. |
| 1D00H-1DFFH 256 bytes | SBUFF$ The system's own sector buffer, the last page of SYSRES. The system control block at 008FH and the job control block at 00C3H both point at it, so an overlay read and a job control file read share it. |
| 1E00H-23FFH 1536 bytes | OVERLAY and DIRBUF$ The overlay area. The start-up code of this file runs at 1E00H and is the first thing in it; after that each of SYS1/SYS to SYS13/SYS loads there in turn, and 2300H-23FFH is the directory sector buffer. 1E00H is also the buffer the start-up reads its replies into. |
| 2400H - | MAXCOR$ The first address above the overlay area, where a library member, a driver, a filter or a drive table loads. |
| 3000H - | MINCOR$ The lowest address a program may use, which is what LOW$ at 001EH holds in the file. |
| 4300H-43FFH 256 bytes | MOD3BUF A scratch page above the overlay area, which the boot sector ran in. @IPL copies the five byte reboot stub at 03FBH to 4300H and returns to it, the start-up moves eight drive code tables through it, and the stub at 2056H is moved to 4350H and run there. |
| F400H-F7FFH 1024 bytes | The keyboard Eight rows read at F401H, F402H, F404H, F408H, F410H, F420H, F440H and F480H when the keyboard is switched in. The start-up reads row 6 at F460H for the CLEAR key at 204CH and rows 0 and 6 together for the boot keys. |
| F800H-FFFFH 2048 bytes | CRTBGN$ The video memory, 80 by 24 characters from F800H. Sixteen of this file's load blocks write the sign-on screen straight into it at F80DH-FE27H, so the screen is painted by the loader and not by any code. |
| 90H port | SNDPORT The sound port. @SOUND at 0392H drives bit 0 high and bit 1 low in turn, holding each for a count that sets the pitch. |
| 9CH port | The Model 4P boot ROM control Bit 0 set maps the boot ROM in at 0000H. Only a Model 4P answers it; the three bytes at 0001H write to it and a Model 4 ignores them. |
Disassembly
0000H - Page 0: Restart Vectors and System Storage
SYS0/SYS loads the first page of memory, 0000H-00F0H, in six pieces: the restart vectors, the time, the interrupt vectors and the task table, the 26 system flags, two chain vectors and the control blocks of the system files. In the memory map this DOS runs the Model 4 in there is no ROM, so every one of these addresses is RAM. The six areas the file does not load (user storage, the whole of DATE$, the non maskable interrupt vector, the debugger's save area and the ends of two file control blocks) are shown as DEFS rows and keep whatever was in memory; the boot code and the start-up code at 1E00H set some of them.
0100H - SVCTAB$: The Supervisor Call Table
SVCTAB$, 0100H-01FFH, holds one address for each of the 128 supervisor call numbers. RST28 at 1A5BH doubles a number below 128 into the low byte of an address in page 01H, with the 01H of the high byte as an immediate operand at 1A51H, and jumps to the word it finds there with Register A loaded from Register C. Many of the words point at short stubs at 197BH-19B4H that pass the request on to a system overlay. Twenty-nine of the 128 numbers are unassigned and point at SVCERR at 1AF4H, which shows and logs Error 2BH (43, an SVC parameter error) and aborts the program: 23, 36 to 39, 84, 92, 95, 107 and 108 to 127. TRSDOS 6.2 answers 99 calls and LS-DOS 6.3.1 answers 107: the two the later release adds are 95 (@HEXD) and 107 (@VDPRT), and both of them hold the invalid word here. The names are those of SVCMAC/ASM, which gives a macro for each that assembles the LD A and the RST 28H.
0380H - The Stack Guard, @PAUSE, @SOUND, @DECHEX and the Reboot Stub
SYS0/SYS loads 0380H-03FFH, the last 128 bytes of the system stack page, over what BOOT/SYS put there. The page holds four things that have nowhere else to live: the two word stack guard at the very bottom of the stack, the delay loop of @PAUSE (SVC 16), the tone generator of @SOUND (SVC 104) with its table of eight notes, the decimal to binary conversion of @DECHEX (SVC 96), and the five byte stub @IPL (SVC 0) copies to 4300H to restart the machine. The resting top of the stack is 0380H and STACK$ is 0300H, so a stack that grew more than 128 bytes would reach these routines: the two zero bytes at 0380H are what a program that overran the stack would overwrite first.
1300H - FILPOSN: @BYTEIO, Byte I/O to a File
SYS0/SYS loads 1300H-1CFFH, the resident file system, the system loader and the task processor (SYSRES), which stay in memory for the life of the system. It begins with the file positioning routines, FILPOSN. @BYTEIO is entered from @CHNIO (JP M,1300H at 0693H on the BOOT/SYS page) when a @GET, @PUT or @CTL is sent to a DCB that is an open file's FCB. Register B holds the request (1 get, 2 put, above 2 control), Register C the byte to put and Index Register IX the FCB. Throughout FILPOSN, FCB+1 bit 7 means byte or record I/O, bit 6 the end of file moves only when the file grows, bit 5 the buffer does not hold the current sector, bit 4 the buffer was changed, bit 3 the directory is updated on every write and bits 2-0 the access level; FCB+3/+4 is the buffer, +5 the offset of the next byte, +8 the end of file offset, +9 the LRL, +10/+11 the next record number (NRN) and +12/+13 the ending record number (ERN).
1421H - The Record Services: @SEEKSC to @VER
The fifteen record services, calls 61 to 75, are all in 1421H-1565H, and every one of them is at a different address in LS-DOS 6.3.1, which re-laid the whole of 1300H-15FFH: 255 of these 346 bytes differ between the two releases, where the band above and the band below are all but identical. The services share three routines of the band above: CKOPEN@ at 1568H, which finds the file control block and checks that it is open, RWRIT@ at 13A2H, which writes the buffer back if it has been changed, and CKEOF1 at 1592H, which compares the next record number with the end of file. Index Register IX points at the control block throughout.
1566H - LNKFCB@ and CKOPEN@: Check an FCB and Save the Registers
Every file SVC calls CKOPEN@ first. It saves the FCB address in JDCB$ (0024H) and its own return address in JRET$ (0026H). For an FCB that is not open it drops the routine's return address and returns error 38 to the SVC's caller. For an open one it points Index Register IX to the FCB, saves Register Pairs HL, DE, BC and the caller's Index Register IX, and plants RESTREG (1589H) as the return address of the file routine, so that a plain RET restores them all. LNKFCB@ enters with the Carry flag set, which skips the open test.
158FH - @CKEOF and CKEOF1: Test for the End of File
CKEOF1 compares the current position with the end of file: the sector of the position (the NRN, adjusted by ADJUST for byte I/O) against the ERN, and in the same sector the offset against the end of file offset. It returns Z and Register A = 00H before the end of file, NZ and Register A = 1CH (error 28, End of file encountered) at it, and NZ and 1DH (error 29, Record number out of range) past it, with Register Pair HL = the NRN as it was and Register C = the offset. @CKEOF (SVC 62) is the same for a program.
15B7H - ADJUST: The Sector of a Byte Position
Entered at 15B7H with Register C loaded from the offset, or at 15BAH with the caller's Register C. For a file used by bytes or records (FCB+1 bit 7) it moves Register Pair HL (a sector number) forward by one when Register C is not zero and back by one when the buffer is current (FCB+1 bit 5 clear), so that Register Pair HL names the sector the position is in.
15CBH - IOREC: Find the Cylinder and Sector of a Record
IOREC turns the NRN into a cylinder (Register D) and sector (Register E) on the file's drive (Register C). It divides the NRN by the sectors per granule to get the file's granule number and the sector inside the granule, then looks for the extent that holds that granule among the first extent at FCB+14 and the four extent records at FCB+16 to FCB+31 (two bytes of granules counted before the extent, then the extent's cylinder and its allocation byte: starting granule in bits 7-5, granules less one in bits 4-0). A matching extent record is moved to the first position. When no extent in the FCB holds the granule, ALLOC at 1664H reads the directory and allocates space if the file must grow.
1664H - ALLOC: Find a Granule's Extent in the Directory
ALLOC is called by IOREC when none of the extents in the FCB holds the granule Register Pair BC. CYL_GRN at 16AEH finds the extent in the file's directory entries (allocating space first if the file must grow); ALLOC then works out the granule's position inside that extent and looks for the extent among the FCB's five extent fields. It returns Z with Register A = the granule inside the extent and Register Pair DE = the granules before it, and either No Carry with Register H = the allocation byte and Register L = the starting cylinder (the extent was in the FCB; its allocation byte is refreshed), or Carry with Register C = the cylinder, Register B = the allocation byte and Register Pair HL = FCB+19, after the extent records were moved up to make room for it.
16AEH - CYL_GRN: Find the Directory Extent of a Granule
CYL_GRN reads the file's directory entries, starting with the primary entry (FCB+7) and following the links to its extended entries, and counts the granules extent by extent until it reaches the extent that holds granule Register Pair BC. Each directory entry has five extent fields at +16H to +1FH: a cylinder and an allocation byte (starting granule in bits 7-5, granules less one in bits 4-0); FFH marks an unused field and FEH a link, whose second byte is the directory entry code of the next entry. If the granule lies past the last extent, CG07 allocates space and the search starts again. It returns Z with Register L = the cylinder, Register H = the allocation byte and Register Pair DE = the granules before the extent.
16F2H - CG07: Allocate Granules to a File
Reached when the file must grow to hold granule Register Pair BC. Register Pair HL points to the first unused extent field and Register Pair DE holds the granules already allocated. CG07 reads the GAT into DIRBUF$ (2300H) and allocates one granule at a time: it extends the last extent when the granule after it is free on the disk, otherwise it starts a new extent at the first cylinder with free space, searching up from the cylinder in Register L (AFLAG$ (006AH) for a file's first extent, otherwise the cylinder where the previous extent ended or the last granule was allocated) and then from cylinder 0. When the fifth extent field is needed it writes the GAT and the entry and gets an extended directory entry (NEWHIT). At the end it writes the GAT and the directory entry back.
17AFH - NEWHIT: Get an Extended Directory Entry
When all four extent fields of a directory entry are used, the fifth becomes a link to an extended entry (FXDE). NEWHIT reads the Hash Index Table (HIT) into SBUFF$, finds a free slot with @SCNHIT, gives it the file's hash code, writes the HIT back, and makes the new entry: attributes 90H (extended, in use), a link back to the entry before it, twenty zero bytes and five unused extent fields. It then writes FEH and the new entry's code into the fifth field of the entry before it.
1803H - @DIRWR, @SCNHIT, TSTBIT and SETBIT
@DIRWR (SVC 88) writes SBUFF$ to the directory sector of entry Register B (its DEC) on drive Register C, with the system data mark, and reads it back; it tries twice. A verify returns error 6 for a sector with the system data mark, so error 6 is success. It returns error 18 (Directory write error), or 15 for a write protected disk. @SCNHIT finds a free slot in the HIT in SBUFF$. TSTBIT and SETBIT build a BIT n,B or SET n,A instruction for granule n of a GAT byte.
1874H - @GATRD, @GATWR, @HITRD and @HITWR
@GATRD (SVC 86) reads the Granule Allocation Table, sector 0 of the directory cylinder, into DIRBUF$ (2300H); @GATWR (SVC 89) writes it back with the system data mark and verifies it. @HITRD and @HITWR do the same for the Hash Index Table, sector 1, in SBUFF$ (1D00H). Each read entry is one byte before the write entry: the byte F6H makes an OR AFH that sets NZ, while the write entry's XOR A sets Z. They return Z on success, or NZ with error 20, 21, 22 or 23.
18BBH - @DIRRD, CALCDIR, @RDSSC and @DIRCYL: Directory Reads
@DIRRD (SVC 87) reads the directory sector that holds entry Register B (a DEC: bits 7-5 the entry in the sector, bits 4-0 the sector less 2) of drive Register C into SBUFF$ and returns Register Pair HL pointing to the entry. @RDSSC (SVC 85) reads a sector that must carry the system data mark; when it does not, the diskette may have been changed, so it reads the boot sector (cylinder 0, sector 1), takes the directory cylinder from its byte 2, stores it in the drive code table (DCT+9) and tries again.
190AH - @MUL8, RELCYL, @DIV8 and CKDBLBIT
@MUL8 (SVC 90) multiplies Register A by Register E and returns the low byte of the product in Register A. @DIV8 (SVC 93) divides Register E by Register A and returns the quotient in Register A and the remainder in Register E. RELCYL turns a granule number (Register A) into cylinders (Register A) and the granule in that cylinder (Register E), using the granules per cylinder of the FCB's drive; CKDBLBIT doubles Register A for a two sided diskette.
1948H - @HIGH$, @FLAGS, @BREAK and @WHERE
The start of LOADER, the system loader and its small SVCs. @HIGH$ (SVC 100) reads (Register Pair HL = 0) or sets (Register Pair HL = the new value) HIGH$ (040EH) when Register B is 0, or LOW$ (001EH) when it is not; neither HIGH$ nor LOW$ can be set while CFLAG$ bit 0 is set. @FLAGS (SVC 101) points Index Register IY to the system flags. @BREAK (SVC 103) swaps the BREAK vector. @WHERE (SVC 7) returns the address after the caller's RST 28H.
197BH - The Overlay Stubs: SVCs Served by System Overlays
Each of these SVCs loads Register A with an overlay request and issues RST 28H again. A request has bit 7 set; bits 3-0 name the overlay (2 to 7 for SYS0 to SYS5, 8 to 15 for SYS6 to SYS13) and bits 6-4 the function inside it. RST28 drops the stub's return address, so the overlay returns straight to the program.
19B5H - The Disk SVCs: IOFUNC
SVCs 40 to 55 load Register A with the driver function (0 to 15) and go to IOFUNC, which switches memory bank 0 in, stores the drive (Register C) in LDRV$, points Index Register IY to the drive's code table entry and calls its first three bytes: a JP to the driver, or a RET (with Register A = 20H, error 32, Illegal drive number, and NZ) when the drive is disabled. Afterwards it restores the bank that was in use. The driver gets Register B = the function, Register C = the drive and Index Register IY = the drive code table.
1A1EH - @GTDCT and the Drive Code Table Field Routines
The drive code table DCT$ at 0470H has ten bytes for each of drives 0 to 7. @GTDCT (SVC 81) points Index Register IY to the entry of drive Register C. DCTFLD@ works out the entry's address (0470H plus ten times the drive) and, with field number Register H, the low byte of the field's address. @DCTBYT returns field Register A of drive Register C; D@FBYT8 and DCTBYT8@ return field 8 (the granule layout) of the FCB's drive or of drive Register C.
1A43H - RST28: The SVC Dispatcher
RST 28H jumps here (0028H). An SVC number below 128 (bit 7 clear) is a supervisor call: SVCUSER saves its number in LSVC$ and the return address in SVCRET$ (except for @ERROR), takes the routine's address from SVCTAB$ at 0100H plus twice the number, copies Register C into Register A and jumps there, so every SVC routine receives the caller's Register C in Register A. A number with bit 7 set is a request for a system overlay: RST28 drops the return address of the RST, turns the debugger hook off while the overlay runs, loads the overlay through CKMOD@ if it is not resident and calls it with the request in Register A.
1A7FH - CKMOD@: Load a System Overlay
CKMOD@ makes sure the overlay named by the request in Register A is in memory. SYS1 to SYS5 and SYS9 to SYS13 run at 1E00H; if OVRLY$ shows the overlay is already there nothing is read. A request 88H, 89H or 8AH (SYS6, SYS7 or SYS8 with function 0, the libraries, loaded at 2400H) is always read, with Register B naming the library member. The overlay's directory entry code is the overlay number (2 to 7 for SYS0 to SYS5) or the number plus 18H (20H to 27H for SYS6 to SYS13). The entry is read on drive 0 and must be a system file in use; its first two extents go into SFCB$ (008CH) and LOADER reads the file. An error goes to SYSERR.
1AF4H - SVCERR, SYSERR, @ABORT, @EXIT and @ERROR
SVCERR serves the unassigned SVC numbers with error 43. SYSERR shows and logs Error xxH for an error the system cannot recover from, resets the stack and aborts. @ABORT (SVC 21) and @EXIT (SVC 22) return to the system through SYS1, @ABORT with the return code FFFFH. @ERROR (SVC 26) shows the message of the error code in Register C (in Register A after the dispatcher) through SYS4.
1B1DH - @RUN and @LOAD: Load a Program
@LOAD (SVC 76) opens the program file whose FCB is at Register Pair DE with the system buffer SBUFF$ (1D00H) and reads its load records into memory; it returns Register Pair HL = the transfer address. Its errors return with bits 7 and 6 set (return to the caller and short message), and File not in directory becomes Program not found. @RUN (SVC 77) loads the program and jumps to it with Register Pair BC pointing to the command line, through the debugger when SFLAG$ bit 7 asks for it.
1B56H - LOADER: Read the Load Records of a File
LOADER reads the file of the FCB at Register Pair DE through the buffer at 1D00H, one byte at a time with LDR15, and acts on each record: 01H a load block (length, address, bytes), 02H the transfer address (which ends the load), 04H the end of a library member, 08H a library member header, 0AH the end of the member headers (the member was not found, error 34), any other type below 20H skipped with its length, and 20H or above error 34, Load file format error. For a library, Register B names the member: its header gives the transfer address, the record number and the offset where the member starts, and LOADER positions the file there and reads on.
1BF2H - @IPL: Restart the Machine
@IPL (SVC 0) copies the five byte stub BOOTCOD (03FBH-03FFH) to 4300H and jumps there; the stub selects the Model III memory map with the ROM at 0000H and restarts through RST 00H.
1BFFH - RST38@: The Interrupt Handler and Task Processor
RST 38H (interrupt mode 1) comes here through the JP 1BFFH that SYS0/SYS loads at 0038H. The handler saves the interrupted program counter in PCSAVE$ (07AFH) for SYSTEM (TRACE), marks the task processor active in NFLAG$, switches to logical bank 0 and to the all RAM memory map with bank 0 (Operation Register bits 6-4 cleared, bits 1-0 = 11), reads the interrupt latch from port E0H (active low on the Model 4, so it is inverted) and calls the vector in INTVC$ (003EH) of each latched bit that INTMSK$ allows, with Register Pairs AF, BC, DE and HL and Index Register IX saved (not Index Register IY or the alternate set). It then checks the keyboard for BREAK, restores the memory map and the bank and returns.
1C94H - RTCPROC and RTCTASK: The Clock Interrupt and the Tasks
RTCPROC is the vector of interrupt bit 2, the real time clock. On every clock interrupt it runs task 11. When the bit rotated out of TIMSL$ is 1 (every second interrupt with 55H) it also runs tasks 8, 9 and 10, counts TIMER$, runs one of tasks 0 to 7 picked by the low three bits of TIMER$, and then the clock and cursor task TIMTSK$ (0713H), whose address it puts on the stack as the return address of the last task. RTCTASK runs the task of slot Register A: the slot in TCB$ (004EH) holds the address of the task's control block, the first word of the control block is the task's entry, and the task gets Index Register IX = its control block. RTCTASK stores the slot's address at 1CECH, for @RPTSK and @KLTSK.
1CD0H - The Task SVCs: @KLTSK, @RMTSK, @ADTSK, @RPTSK and @CKTSK
@ADTSK (SVC 29) puts the control block at Register Pair DE into slot Register C (passed in Register A); @RMTSK (SVC 30) puts NOTASK there; @KLTSK (SVC 32), called by a running task, removes that task and ends it; @RPTSK (SVC 31), called by a running task, makes the address after its call the task's new entry and ends this run; @CKTSK (SVC 28) returns Z when slot Register A is free. Slots above 11 are refused. NOTASK (1CE9H) is the control block of an empty slot: its entry word points to the RET at 1CE8H.
1E00H - SYSINIT4: The Start-Up
1E00H is the transfer address of SYS0/SYS, so these 871 bytes are the first code of the system to run after the loader in BOOT/SYS hands over. They run once: the overlay area 1E00H-23FFH is where SYS1/SYS to SYS13/SYS load, so the first overlay called writes over all of it. The start-up points the non maskable interrupt at the floppy disk driver, clears the stack and the spare device control blocks, sets the four ports from their images in low memory, finds out whether the machine has the two extra banks of a 128K Model 4, asks for the date and the time, works out the day of the year and the day of the week, shows the date, reads the keyboard for the D, ENTER and CLEAR keys, loads the SYSGEN configuration, restores the drives and leaves through the AUTO command or TRSDOS Ready. Of the whole file this is the part LS-DOS 6.3.1 changed most: 837 of these 871 bytes differ, where the resident system above is all but identical, and five of the twelve bugs of this release are in these rows.
F80DH - The Sign-On Screen, Loaded Straight into Video Memory
SYS0/SYS ends with eighteen load blocks that go into video memory, which the boot code left mapped at F800H-FFFFH and cleared to spaces. Two of them write the version and copyright lines across the top two rows, and the other sixteen draw the logo, one block for each screen row from row 4 to row 19. Nothing in the file paints the screen: the loader writes the bytes where they are to be seen, so the sign-on is on the screen before the start-up code at 1E00H is reached. The logo is drawn in the Model 4 block graphics characters 80H-0BFH, each of which is a cell two pixels wide and three deep with one bit for each pixel, and it is symmetrical about the middle, 33 characters wide at its top and bottom row and 15 at its waist. The bytes the file does not load are left as the spaces the boot wrote.