TRS-80 DOS - LDOS 5.3.1 for the Model I - SYS0/SYS Disassembled

Page Customization

Introduction/Summary

LDOS 5.3.1 SYS0/SYS Disassembly - The Resident System (Model I)

SYS0/SYS is the part of LDOS that stays in memory from the boot on. The boot sector of BOOT/SYS loads it and jumps to its transfer address, 4E00H. Everything below 4E00H stays resident: the restart vectors and device control blocks at 400CH, the system variables at 4300H, the supervisor call vectors at 4400H, the task table and the interrupt service routine at 4500H, the floppy disk driver, the drive code tables at 4700H, the disk primitives, the file routines (@READ, @WRITE, @POSN and the others), the directory sector routines, the supervisor dispatcher of RST 28H, the overlay loader and the module loader. The code from 4E00H to 50FFH is the reset. It runs once at every boot and is then overwritten, because 4E00H-51FFH is the overlay area every other system file (SYS1/SYS to SYS13/SYS) loads into.

The file is a load module of 4165 bytes. It starts with a header record of type 05H, the module name SYS0 and two spaces, and a record of type 1FH, the text Copyright 1991 MISOSYS, Inc., All rights reserved. Then come 35 load blocks (type 01H) and the transfer address record (type 02H) for 4E00H. The first three blocks go straight to the screen (3C00H-3E7FH): the sign-on lines and the LDOS logo appear while the file loads.

The reset finds the top of memory (HIGH$, 4049H), sets the clock speed and the cassette latch, saves the ROM's keyboard, video and printer driver addresses, installs its own video driver when the computer has lower case, sets up drive 0 from the boot (bit 0 of MFLAG$, 442FH, tells a boot through a disk driver from a boot by sector 0), turns on the clock and disk interrupts and reads the system information sector into 4200H. It asks for the date and the time when that sector says to, starts the clock task, copies the drive code tables of drives 1-7, reads the allocation table of the diskette in drive 0, shows the diskette's name and date, and then loads CONFIG/SYS and carries out the AUTO command, unless the keys held at the boot say otherwise.

Request Codes

A program reaches the system by a CALL to one of the vectors at 4400H-44C6H. A vector either jumps to a routine of SYS0/SYS or loads Register A with a request code and does RST 28H. ROM 0028H jumps to 400CH and from there to the supervisor dispatcher at 4BCDH.

BitsMeaning
7Set: the request is carried out by a system file loaded into 4E00H. Clear: a resident request (4BEFH).
6-4The function within the system file, passed to it in Register A.
3-0The system file: its number plus 2 (3 for SYS1/SYS up to 0EH for SYS12/SYS); 07H is SYS5/SYS (DEBUG), 08H SYS6/SYS and 09H SYS7/SYS, the two libraries, whose member is picked by Register B. The overlay loader reads directory records 3-7 for SYS1/SYS-SYS5/SYS and 20H-26H for SYS6/SYS and on (4BF5H).

OVRLY$ (430EH) holds the request code of the system file now at 4E00H, so a file already there is not read again.

Keys Held at the Boot

KeyEffect (tested at the end of the reset)
ENTER or @The AUTO command is not carried out, unless it starts with 2AH (5012H).
D or DOWN ARROWThe DEBUG monitor is entered before the system starts (5015H).
CLEAR or 9, SPACE or /CONFIG/SYS is not loaded (5044H).

An AUTO command that starts with 2AH runs with BREAK disabled: the reset changes the RES 4,(HL) of its relocated end into SET 4,(HL) (5000H).

About This Page

Every byte of the file is shown, in address order, with the bytes that are not in the file (marked Not in the file) where the system keeps variables. The last 42 bytes of the reset (505AH-5083H) are copied to 405DH and run there; their rows say the address each instruction runs at. Two load blocks meet at 4700H: the block 461CH-4700H ends with E9H there and the next block puts C3H over it, so 4700H holds C3H.

Memory Map

Load Blocks in File Order

The 35 load blocks of the file, adjacent blocks taken together, in the order the boot sector loads them. The transfer address is 4E00H.

AddressContents
3D40H-3E7FH320 bytes in 2 blocks
400CH-403CH49 bytes in 1 block
403EH-4040H3 bytes in 1 block
4044H-4048H5 bytes in 1 block
404BH-405CH18 bytes in 1 block
4300H-4305H6 bytes in 1 block
4308H-4317H16 bytes in 1 block
4338H-4348H17 bytes in 1 block
4378H-4398H33 bytes in 1 block
43C0H-43D7H24 bytes in 1 block
4400H-4402H3 bytes in 1 block
4405H-4465H97 bytes in 1 block
4467H-447FH25 bytes in 1 block
44A0H-461BH380 bytes in 2 blocks
4399H-43AFH23 bytes in 1 block
461CH-4700H229 bytes in 1 block
4700H-47CAH203 bytes in 1 block
3C00H-3C39H58 bytes in 1 block
3C46H-3C76H49 bytes in 1 block
47CBH-4DD7H1549 bytes in 7 blocks
4DF0H-5083H660 bytes in 3 blocks
431BH-4335H27 bytes in 1 block
4349H-4372H42 bytes in 1 block
5084H-50FFH124 bytes in 1 block
41DEH-41DFH2 bytes in 1 block

Sections of the Disassembly

AddressContents
3C00HSign-On Screen (Video Memory, Data)
400CHRestart Vectors
4015HDevice Control Blocks of the Keyboard, Video and Printer
402DH@EXIT and @ABORT
403EHOSVER$, the Clock and the Date
41DEHThe Reset's Return Word
4300H@KITSK and @ICNFG Hooks
431BHBoot Prompt: Display, Input, Parse
4338HThe CONFIG/SYS Filespec
4349HParse Three Two Digit Fields
4378HThe Video Driver for Lower Case
4399HWait for the Drive Motor
43C0HDevice Control Blocks of JL, SI and SO
4400HThe Supervisor Call Vectors
44A0HSFCB$, the Control Block for System Files
44B4HThe DEBUG Launcher and Four More Vectors
44C7H@DVRHK: Find the Driver of a Device
44E3H@DSPLY, @PRINT and @MSG: Send a Text to a Device
4500HTCB$, the Task Table
4518HThe Interrupt Service Routine
456FHThe Clock Interrupt: Run the Tasks
458AHRun the Task in Slot A
459DH@KLTSK, @RMTSK and @ADTSK
45BEHThe Clock Task
45E0HThe Floppy Disk Driver: Select the Drive
45FBHThe Driver's Entry: Function Dispatch
461CHWait Until the Controller Is Not Busy
462AHSeek: Cylinder D, Sector E
466BHThe Read and Write Engine
4700HDCT$, the Drive Code Tables
4750HThe Disk Primitives
478FHGETDCT and DCTBYT: Find a Drive's Code Table
47B4HCopy a System File's Extents into SFCB$
47CBH@SKIP and @POSN: Position a File
480FH@RREAD and @BKSP
4835H@REW and @PEOF
484DH@LOC and @LOF
4886H@WEOF: Write the End of File to the Directory
48ADH@READ, @WRITE and @VER
48ECHA File Used as a Device
4919HPut a Byte into a File
494FHRead the Sector of the Next Record Number
4993HWrite the Buffer When It Was Changed
49F1HThe File Prologue
4A1AH@CKEOF: Test the End of File
4A41HFind the Sector of the Next Record Number
4B10HDIRRD and DIRWR: Read and Write a Directory Sector
4B45HRDSSEC: Read a Directory Sector
4B6CHMULTEA, DIVEA, @MULT and @DIV
4BCBHCall a Drive's Driver
4BCDHThe Supervisor Dispatcher (RST 28H)
4BF5HLoad the System File of a Request
4C5EH@RUN and @LOAD
4C77H@LOAD: Load a Program File
4C8DHThe Module Loader
4D3AHThe Clock Display Task and @TIME, @DATE
4D6AHThe Program Counter Display Task
4D8FHThe Current Sector of a File
4DA6HThe Keyboard Scan of Every Interrupt
4DF0HBase Cells for Resident Modules
4E00HThe Reset: Memory, Video and Drive 0
4E90HThe Reset: The Date
4EF4HThe Reset: Store and Display the Date
4F89HThe Reset: The Time
4FBDHThe Reset: Clock, Drives and the Diskette
5000HThe Reset: AUTO, CONFIG/SYS and the Return to LDOS
5084HThe Reset's Display Helpers

Memory SYS0/SYS Uses

AddressContents
0000H-2FFFHThe Level II ROM. SYS0/SYS uses its restarts (0028H, 0038H), its device routine (001BH, 03C2H), its display of a character (0033H), its line input (0040H), its delay (0060H), its keyboard driver (03E3H), its video driver (0458H, 047DH, 049AH, 04A6H, 0506H) and its printer driver (058DH).
37E0HThe interrupt latch of the expansion interface: bit 7 the clock, bit 6 the disk controller (4518H).
37E1HThe drive select latch (45F3H, 4625H).
37E4HThe cassette select latch, 00H at the reset (4E22H).
37ECH-37EFHThe floppy disk controller: command and status, track, sector and data registers.
3801H-3880HThe keyboard matrix: 3801H row 0, 3840H row 6 (ENTER, BREAK), 3841H rows 0 and 6, 3860H rows 5 and 6, 3880H row 7 (SHIFT).
3C00H-3FFFHVideo memory. The sign-on screen loads here; the reset writes the diskette name (3CD6H), its date (3CE0H) and the prompts Date? (3F17H) and Time? (3F57H).
Port FEHThe speed control: bit 0 set for the fast clock (4E1FH, 506EH); 4427H keeps a copy.
400CH-41DFHLow memory of SYS0/SYS: restart vectors, device control blocks, the clock, the date and the interrupt vectors.
405DH-4086HDBGSV$, DEBUG's register save area; during the reset the end of the reset runs here (505AH-5083H).
4152H-41A1HWhere CONFIG/SYS loads its copy of the eight drive code tables, which the reset copies to 4700H.
4200H-42FFHA sector buffer: the boot sector, then the system information sector, then the allocation table of drive 0; afterwards the buffer of system file loads (SFCB$ +03H).
4300H-4DFFHThe resident system.
4E00H-51FFHThe reset, then the overlay area of the system files.

Variables

The named entry points and variables of SYS0/SYS, then every data byte of the file and every cell it keeps outside the file, by address. The names are those of the LDOS technical documentation.

Equate Table

AddressNameContents
4015HKIDCB$4015H, KIDCB$, the keyboard's device control block, +00H: 01H, the device type (an input device). KI/DVR, SYS2/SYS, SYS6/SYS and SYS11/SYS address the block from here.
401DHDODCB$401DH, DODCB$, the video display's device control block, +00H: 07H, the device type (input, output and control). @DSPLY (44E3H) sends its text to the block at 401DH.
4025HPRDCB$4025H, PRDCB$, the printer's device control block, +00H: 06H, the device type (output and control). @PRINT (44F8H) sends its text to the block at 4025H.
403EHOSVER$403EH, OSVER$: 53H, the system version 5.3 (BASIC/CMD reads it, its 5344H).
4040HTIMER$4040H, TIMER$: the tick counter, incremented on every clock interrupt by 4583H (40 a second on the Model I). Its bits 2-0 pick the task slot 458AH runs on each tick. FORMAT/CMD, BACKUP/CMD, KI/DVR, SYS2/SYS and SYS12/SYS read it to time delays and key repeats.
4041HTIME$Not in the file: 4041H-4043H, TIME$: seconds, minutes and hours, kept by the clock task at 45BEH and set by the boot time prompt (4FB5H-4FBBH). Not loading them keeps the time running across a reset.
4044HDATE$4044H, DATE$: the year, two digits as a binary number (80-99 for 1980-1999, 0-11 for 2000-2011), stored by the reset at 4F2FH from the year offset in 4466H.
4049HHIGH$Not in the file: 4049H-404AH, HIGH$, the highest address free for programs. The reset stores the top of memory it finds here and at 4403H (4E17H-4E1AH); modules that install themselves in high memory (KI/DVR, PR/FLT, FDUBL/CMD, SYS9/SYS ...) lower it.
404BHINTIM$404BH, INTIM$: a copy of the interrupt latch (37E0H) the interrupt service routine read last (4518H-4522H): bit 7 the clock, bit 6 the disk controller.
404CHINTMSK$404CH, INTMSK$: the mask of the interrupt bits that are served (4524H). The reset stores C0H (bits 7 and 6) at 4E7FH-4E82H.
404DHINTVC$404DH-404EH, INTVC$, the first of eight vectors, one for each bit of the interrupt latch: bit 0. 4537H is the RET at the end of the interrupt service routine, so an unused bit does nothing.
405DHDBGSV$DEBUG's register save area (outside the file). The reset copies its last 42 bytes here and runs them (505AH-5083H).
4300H@KITSKRETurn at once. While this byte is C9H nothing is hooked to the keyboard; SYS6/SYS stores C3H here and an address at 4301H-4302H (its 5555H, 54FCH) to have its keyboard task run, and puts C9H back.
4303H@ICNFGRETurn at once. SYS0/SYS's reset calls it after it has loaded CONFIG/SYS (5073H); a configuration that needs to run code at boot leaves a jump here (SYS6/SYS stores into 4303H, its 530AH).
4306HSVDAT1$Not in the file, so a reset keeps them: 4306H, SVDAT1$, the month of the system date OR 50H once a date is set (4EEBH-4EEFH; SYS7/SYS DATE 52ABH, 535FH), and 4307H, SVDAT2$, the day (4EE4H). The reset skips the date prompt when 4306H holds 51H-5CH (a month OR 50H), and the date and the time prompts when it holds 50H (4E9DH-4EA7H).
4307HSVDAT2$The day of the system date, kept over a reset (not in the file).
4308HLDRV$4308H, LDRV$: the drive number of the last disk primitive call (4779H-477CH store Register C here); 4750H selects it again. FFH: no drive yet. BACKUP/CMD stores into it (its 547AH).
4309HPDRV$4309H, PDRV$: the last value written to the drive select latch 37E1H (45F0H), which 461CH writes again while it waits so the drive stays selected. FFH in the file.
430AHJDCB$430AH-430BH, JDCB$: the address of the file or device control block of the current call, stored by the common file prologue (49F9H). SYS4/SYS reads it to name the file in an error message (its 4F6BH).
430CHJRET$430CH-430DH, JRET$: the return address of the program's call into the file system (49F6H), the address SYS4/SYS reports in REFERENCED AT (its 4FFAH). FORMAT/CMD, SYS6/SYS and SYS7/SYS point Register Pair HL at 430DH.
430EHOVRLY$430EH, OVRLY$: the request code of the system file now in the overlay area at 4E00H (00H: none). The overlay loader compares and stores it (4C03H-4C0AH); 4A92H and 4BE1H read it; BASIC/CMD and BASIC/OV3 store into it.
430FHSFLAG$430FH, SFLAG$, the system flags. Bit 1 run the program without DEBUG (4C6EH), bit 2 a program load by @RUN is in progress (4C62H), bit 3 FAST (the reset doubles the drive motor wait and sets bit 0 of port FEH, 4399H, 5061H), bit 4 BREAK disabled (455BH; the reset clears it, or sets it for an AUTO command that starts with 2AH), bit 5 a JCL job runs, bit 7 DEBUG is on (4C71H); the others are used by the overlays and programs (SYS5/SYS, SYS6/SYS, SYS7/SYS, BASIC/CMD).
4318HINBUF$The 64 byte command line buffer (4318H-4357H). The reset parses the date and time fields into its first three bytes and copies the AUTO command into it.
4358HJFCB$The 32 byte file control block of the job log (4358H-4377H). In the file these bytes hold the end of the reset's field parser (4349H-4372H), which is used only at the boot.
43B8HKISV$Not in the file: 43B8H-43B9H, KISV$, the keyboard driver address saved by the reset from 4016H (4E25H-4E28H). SYS6/SYS reads it (its 5205H).
43BAHDOSV$Not in the file: 43BAH-43BBH, DOSV$, the video driver address saved by the reset (4E3EH): 0458H, or 4378H on a computer with lower case. SYS6/SYS reads it (its 520BH).
43BCHPRSV$Not in the file: 43BCH-43BDH, PRSV$, the printer driver address saved by the reset from 4026H (4E41H-4E44H). PR/FLT and SYS6/SYS read it.
43BEHKIJCL$Not in the file: 43BEH-43BFH, KIJCL$, where SYS11/SYS (JCL) and KI/DVR keep the keyboard driver address they replaced.
43C0HJLDCB$43C0H, JLDCB$, the job log's device control block, +00H: 08H, the type of a device with nothing assigned (bit 3).
43C8HSIDCB$43C8H, SIDCB$, the standard input's device control block, +00H: 08H, nothing assigned.
43D0HSODCB$43D0H, SODCB$, the standard output's device control block, +00H: 08H, nothing assigned.
43D8HS1DCB$-S5DCB$Five spare device control blocks of eight bytes (43D8H-43FFH), cleared by the reset.
4400H@CMD (@CMNDR)Load Register A with 93H, the request code of SYS1/SYS's function 10H, the LDOS READY command loop: display LDOS READY and take the next command.
4405H@CMNDILoad Register A with 0B3H, the request code of SYS1/SYS's function 30H: execute the command line at Register Pair HL (ended by 0DH); when the command ends, @EXIT (402DH) runs and LDOS Ready follows (SYS1/SYS pushes 402DH as the command's return address, its 4E58H). SYS0/SYS's reset returns into 4405H to run the AUTO command (5029H-502BH); BASIC/CMD, SYS7/SYS and SYS11/SYS jump here.
4409H@ERRORSave the interrupted program's Register Pair AF to the stack. Register A holds the error number in bits 5-0, bit 6 set for the short message and bit 7 set to return to the caller instead of ending the program. SYS4/SYS takes it back from the stack.
440DH@DEBUGJump to 44B4H, which saves Register Pair AF and loads SYS5/SYS, the DEBUG monitor. SYS0/SYS's reset calls 440DH when D (or the DOWN ARROW key) is held at boot (5017H).
4410H@ADTSKJump to 45A5H to add a task: Register A = the task slot (0-11) and Register Pair DE = the task's block (its first word is the address of its routine). SYS0/SYS's reset adds the clock at slot 7 (4FBDH-4FC2H).
4413H@RMTSKJump to 45A2H to remove the task in slot Register A: its entry in the task table at 4500H gets the empty block 45B2H.
4416H@RPTSKJump to 45B4H. A task routine calls it to have its next run start at the instruction after the CALL; the task ends for this tick.
4419H@KLTSKJump to 459DH. A task routine calls it to remove itself from the task table; it returns to the routine that ran the task.
441CH@FSPECLoad Register A with 0C3H, the request code of SYS1/SYS's function 40H: take a file specification from the text at Register Pair HL into the control block at Register Pair DE.
441FHDFLAG$441FH, DFLAG$, the device flags: bit 0 the spooler is installed, bit 1 type ahead, bit 2 the screen print and keyboard macro (JKL) module, bit 3 PR/FLT installed, bit 4 KI/DVR installed (KI/DVR 526FH, PR/FLT 521AH, SYS6/SYS and SYS7/SYS set and test them). 00H at boot.
4420H@INITLoad Register A with 0A4H, the request code of SYS2/SYS's function 20H: open the file whose control block is at Register Pair DE, creating it when it does not exist (Register Pair HL = its 256 byte buffer, Register B = the record length, 0 for 256).
4423HKFLAG$4423H, KFLAG$, the keyboard flags. The interrupt routine's keyboard scan (4DA6H) sets bit 0 when BREAK is pressed (unless BREAK is disabled), bit 1 when SHIFT and @ are held (pause) and bit 2 when ENTER is held; the keyboard drivers and the programs clear them. Bit 5 is the CAPS lock, set (20H) at boot. Read and changed by BACKUP/CMD, BASIC/CMD, KI/DVR, TED/CMD, SYS6/SYS, SYS7/SYS and SYS11/SYS.
4424H@OPENLoad Register A with 94H, the request code of SYS2/SYS's function 10H: open the existing file whose control block is at Register Pair DE (Register Pair HL = its buffer, Register B = the record length). @LOAD uses it (4C7CH).
4428H@CLOSELoad Register A with 95H, the request code of SYS3/SYS's function 10H: close the file or device whose control block is at Register Pair DE.
442CH@KILLLoad Register A with 9CH, the request code of SYS10/SYS's function 10H: delete the file whose control block is at Register Pair DE.
442FHMFLAG$442FH, MFLAG$, the machine flags: bit 0 set by the reset when it was entered with Index Register IY not 0000H, a boot through a disk driver (the Lobo LX-80 interface), which selects the first block of drive tables in the system information sector (4E5EH-4E61H, 4FCEH; SYS6/SYS, SYS7/SYS and FORMAT/CMD read it).
4430H@LOADJump to 4C77H to load the program file named in the control block at Register Pair DE and return its transfer address in Register Pair HL.
4433H@RUNJump to 4C5EH to load the program file named at Register Pair DE and run it.
4436H@READJump to 48ADH to read the next record of the file at Register Pair DE (into the record area at Register Pair HL when the record length is not 256).
4439H@WRITEJump to 48CBH to write the next record of the file at Register Pair DE.
443CH@VERJump to 48E6H to write the next record of the file at Register Pair DE and read it back to check it.
443FH@REWJump to 4835H to put the file at Register Pair DE back at its first record.
4442H@POSNJump to 47CFH to put the file at Register Pair DE at the record number in Register Pair BC.
4445H@BKSPJump to 4816H to move the file at Register Pair DE back one record.
4448H@PEOFJump to 483CH to put the file at Register Pair DE at its end, ready to add records.
444BH@CKEOFJump to 4A1AH to test whether the file at Register Pair DE is at its end (Register A = 1CH and the NZ FLAG at the end, 1DH beyond it, 00H with the Z FLAG before it).
444EH@WEOFJump to 4886H to write the end of file of the file at Register Pair DE into its directory record.
4454H@RREADJump to 480FH to read the current sector of the file at Register Pair DE again.
4457H@RWRITJump to 499EH to write the file's buffer back to the current sector of the file at Register Pair DE.
445AH@LOCJump to 484DH to return in Register Pair BC the current record number of the file at Register Pair DE.
445DH@LOFJump to 4878H to return in Register Pair BC the number of records of the file at Register Pair DE.
4460H@SKIPJump to 47CBH to pass over the next record of the file at Register Pair DE.
4463H@DODIRLoad Register A with 0AEH, the request code of SYS12/SYS's function 20H: directory display or directory information of the drive in Register C.
4467H@DSPLYJump to 44E3H to display the text at Register Pair HL (ended by 03H, or by 0DH, which is displayed).
446AH@PRINTJump to 44F8H to print the text at Register Pair HL (ended by 03H or 0DH).
446DH@TIMEJump to 4D48H to store the time as HH:MM:SS (8 characters) at Register Pair HL.
4470H@DATEJump to 4D63H to store the date as MM/DD/YY (8 characters) at Register Pair HL.
4473H@FEXTLoad Register A with 0D3H, the request code of SYS1/SYS's function 50H: give the file specification at Register Pair DE the extension at Register Pair HL when it has none.
4476H@PARAMLoad Register A with 0E3H, the request code of SYS1/SYS's function 60H: read the parameters at Register Pair HL against the parameter table at Register Pair DE.
4479H@MSGJUMP to 44E6H to send the text at Register Pair HL to the device whose control block is at Register Pair DE, until 03H or 0DH. SYS6/SYS calls it (its 5329H, 53C8H).
447BH@LOGOTGOSUB to 44E3H to display the text at Register Pair HL on the video, then go on into @LOGER below to send it to the job log.
447EH@LOGERJUMP to 44FDH, a RET: the job log takes nothing until a module points this jump elsewhere. SYS1/SYS, SYS6/SYS and SYS11/SYS call 447EH.
4480HCFCB$Not in the file: 4480H-449FH, CFCB$, the 32 byte control block that SYS1/SYS fills for the command being run (its 4E6CH); BASIC/CMD, its overlays, SYS6/SYS and SYS12/SYS use it too.
44A0HSFCB$44A0H, SFCB$ +00H: 80H, bit 7 set: the block describes an open file, which the file prologue (49F3H) requires.
44B8H@CKDRVLoad Register A with 0C4H, the request code of SYS2/SYS's function 40H: check that the drive in Register C is ready and has a diskette.
44BBH@FNAMELoad Register A with 0A5H, the request code of SYS3/SYS's function 20H: build the file specification of directory record Register B on drive Register C into the buffer at Register Pair DE.
44BEH@DOKEYLoad Register A with 0CDH, the request code of SYS11/SYS's function 40H: take a key for a JCL job. SYS11/SYS changes the operand at 44BFH to 0DDH while it answers an input request of the job and back to 0CDH (its 50C3H, 50D7H).
44C1H@MULTJump to 4B8FH to multiply Register Pair HL by Register A (the 24 bit product: Register Pair HL the high 16 bits, Register A the low 8 bits).
44C4H@DIVJump to 4BA9H to divide Register Pair HL by Register A (quotient in Register Pair HL, remainder in Register A).
44F8H@PRINTPoint Register Pair DE to 4025H, PRDCB$, the printer's device control block.
4500HTCB$The task table, twelve words for the task slots 0-11 (4500H-4517H).
459DH@KLTSKDiscard the return address into the task routine (POP into Register Pair DE): the RET below goes back to the routine that ran the task.
45A2H@RMTSKPoint Register Pair DE to 45B2H, the empty task block.
45A5H@ADTSKCompare Register A (the slot) against 0CH. The NO CARRY FLAG is set for a slot of 12 or more.
45B4H@RPTSKLoad Register Pair HL with the address of the running slot's entry in TCB$. The operand at 45B5H-45B6H is 0000H in the file; 458EH stores the entry's address there before every task runs.
4700HDCT$The drive code tables, eight entries of 10 bytes for drives 0-7 (4700H-474FH).
4754HSELECTLoad Register A with 01H, the driver's function select the drive.
4759HRSELCTLoad Register A with 07H, the driver's function wait until the controller is not busy.
475EHSEEKLoad Register A with 06H, the driver's function seek cylinder Register D for sector Register E.
4763HWRSECTLoad Register A with 0DH, the driver's function write the sector at Register Pair HL to cylinder Register D, sector Register E.
4768HWRPROTLoad Register A with 0EH, the driver's function write a sector with the deleted data mark, used for every directory sector (4B25H).
476DHWRTRKLoad Register A with 0FH, the driver's function write a track (FORMAT/CMD) from the buffer at Register Pair HL.
4772HVERSECLoad Register A with 0AH, the driver's function verify (read without storing) cylinder Register D, sector Register E.
4777HRDSECTLoad Register A with 09H, the driver's function read cylinder Register D, sector Register E into the buffer at Register Pair HL. The code goes on into 4779H.
478FHGETDCTPoint Index Register IY at the drive code table of drive Register C (4700H + 10 x the drive); DCTBYT at 4793H fetches one of its bytes.
479CHDCTBYTSave the caller's Register Pair HL to the stack.
47CBH@SKIPGOSUB to 484DH (@LOC) to work out the current record number into Register Pair BC.
47CFH@POSNGOSUB to 49F3H, the file prologue: it checks that the control block at Register Pair DE is open, points Index Register IX at it, saves Register Pairs BC, DE and HL and Index Register IX for the return, and comes back with Register A = 00H.
480FH@RREADGOSUB to 49F3H, the file prologue (Index Register IX = the file control block, Register A = 00H).
4816H@BKSPGOSUB to 49F3H, the file prologue (Index Register IX = the file control block, Register A = 00H).
4835H@REWGOSUB to 49F3H, the file prologue (Index Register IX = the file control block, Register A = 00H).
483CH@PEOFGOSUB to 49F3H, the file prologue (Index Register IX = the file control block, Register A = 00H).
484DH@LOCGOSUB to 49F3H, the file prologue (Index Register IX = the file control block, Register A = 00H).
4878H@LOFGOSUB to 49F3H, the file prologue (Index Register IX = the file control block, Register A = 00H).
4886H@WEOFGOSUB to 49F3H, the file prologue (Index Register IX = the file control block, Register A = 00H).
48ADH@READGOSUB to 49F3H, the file prologue (Index Register IX = the file control block, Register A = 00H).
48CBH@WRITEGOSUB to 49F3H, the file prologue (Index Register IX = the file control block, Register A = 00H). @VER joins at 48CEH with Register A = 01H.
48E6H@VERGOSUB to 49F3H, the file prologue (Index Register IX = the file control block, Register A = 00H).
499EH@RWRITGOSUB to 49F3H, the file prologue (Index Register IX = the file control block, Register A = 00H).
4A1AH@CKEOFGOSUB to 49F3H, the file prologue (Index Register IX = the file control block, Register A = 00H).
4B10HDIRRDSave the caller's Register Pair DE to the stack.
4B1FHDIRWRSave the caller's Register Pair DE to the stack.
4B45HRDSSECRead a directory sector: cylinder Register D, sector Register E of drive Register C into the buffer at Register Pair HL, with the directory cylinder corrected when the boot sector gave a wrong one.
4B65HDIRCYLLoad Register A with 09H, the offset of the directory cylinder in a drive code table.
4B6CHMULTEASave Register Pair BC to the stack: Register B is the bit counter.
4B7BHDIVEASave the caller's Register Pair BC to the stack.
4B8FH@MULTSave the caller's Register Pair BC to the stack.
4BA9H@DIVSave the caller's Register Pair DE to the stack.
4C5EH@RUNSave Register Pair HL (the command line pointer) to the stack.
4C77H@LOADLoad Register B with 00H, the record length for @OPEN: 256 bytes.
4D48H@TIMEPoint Register Pair DE to 4043H, the hours of TIME$ (the fields are taken downwards: hours, minutes, seconds).
4D63H@DATEPoint Register Pair DE to 4046H, the month of DATE$ (taken downwards: month, day, year).

Low Memory (400CH-41DFH)

Address
Size
Contents
4015H
1 byte
DEFB 01H
4015H, KIDCB$, the keyboard's device control block, +00H: 01H, the device type (an input device). KI/DVR, SYS2/SYS, SYS6/SYS and SYS11/SYS address the block from here.
4016H-4017H
2 bytes
DEFW 03E3H
4016H-4017H, KIDCB$ +01H-+02H: 03E3H, the ROM's keyboard driver. SYS0/SYS's reset copies this address to 43B8H (4E25H-4E28H); KI/DVR (its 5436H, 5559H), SYS7/SYS and SYS11/SYS replace it with their own drivers and put it back.
4018H-401AH
3 bytes
DEFB 00H x 3
4018H-401AH, KIDCB$ +03H-+05H: three bytes of 00H for the driver's use. SYS7/SYS stores into 4018H (its 5281H).
401BH-401CH
2 bytes
DEFM "KI"
401BH-401CH, KIDCB$ +06H-+07H: the device name KI.
401DH
1 byte
DEFB 07H
401DH, DODCB$, the video display's device control block, +00H: 07H, the device type (input, output and control). @DSPLY (44E3H) sends its text to the block at 401DH.
401EH-401FH
2 bytes
DEFW 0458H
401EH-401FH, DODCB$ +01H-+02H: 0458H, the ROM's video driver. SYS0/SYS's reset replaces it with 4378H, its own driver that shows lower case, when video memory keeps bit 6 of a byte written to it (4E2BH-4E3BH), and saves the address in force at 43BAH.
4020H-4021H
2 bytes
DEFW 3C00H
4020H-4021H, DODCB$ +03H-+04H: 3C00H, the cursor position in video memory (the top left corner). SYS0/SYS sets it for each prompt (431BH, 4F53H) and leaves it at 3F40H after the reset (5076H-5079H); BASIC/CMD, SYS5/SYS, SYS6/SYS and SYS7/SYS read and set it.
4022H
1 byte
DEFB 00H
4022H, DODCB$ +05H: the character under the cursor, 00H when the cursor is off (the ROM's driver puts it back before it moves the cursor). SYS7/SYS reads it (its 5479H).
4023H-4024H
2 bytes
DEFM "DO"
4023H-4024H, DODCB$ +06H-+07H: the device name DO.
4025H
1 byte
DEFB 06H
4025H, PRDCB$, the printer's device control block, +00H: 06H, the device type (output and control). @PRINT (44F8H) sends its text to the block at 4025H.
4026H-4027H
2 bytes
DEFW 058DH
4026H-4027H, PRDCB$ +01H-+02H: 058DH, the ROM's printer driver. SYS0/SYS's reset copies the address to 43BCH (4E41H-4E44H).
4028H
1 byte
DEFB 42H
4028H, PRDCB$ +03H: 42H (66), the lines on a printer page, the ROM's default.
4029H
1 byte
DEFB 00H
4029H, PRDCB$ +04H: 00H, the count of lines printed on the page.
402AH
1 byte
DEFB 00H
402AH, PRDCB$ +05H: 00H, the driver's spare byte.
402BH-402CH
2 bytes
DEFM "PR"
402BH-402CH, PRDCB$ +06H-+07H: the device name PR.
4036H-403CH
7 bytes
DEFB FFH x 7
4036H-403CH: the ROM keyboard driver's work area, one byte for each keyboard row 0-6, the keys it last saw held (the ROM's 03EBH-03EFH takes as new only keys not set here). FFH in every byte makes every key held at boot count as already seen, so a key held during the reset is not taken as typed. KI/DVR uses these bytes too (its 52C8H, 535FH, 5394H).
403DH
1 byte
DEFS 1
Not in the file: 403DH, the ROM's video mode byte (bit 3 set for 32 characters a line), left as the ROM set it. BASIC/CMD reads it (its 5A0CH).
403EH
1 byte
DEFB 53H
403EH, OSVER$: 53H, the system version 5.3 (BASIC/CMD reads it, its 5344H).
403FH
1 byte
DEFB 00H
403FH: 00H. No code of SYS0/SYS addresses it.
4040H
1 byte
DEFB 00H
4040H, TIMER$: the tick counter, incremented on every clock interrupt by 4583H (40 a second on the Model I). Its bits 2-0 pick the task slot 458AH runs on each tick. FORMAT/CMD, BACKUP/CMD, KI/DVR, SYS2/SYS and SYS12/SYS read it to time delays and key repeats.
4041H-4043H
3 bytes
DEFS 3
Not in the file: 4041H-4043H, TIME$: seconds, minutes and hours, kept by the clock task at 45BEH and set by the boot time prompt (4FB5H-4FBBH). Not loading them keeps the time running across a reset.
4044H
1 byte
DEFB 00H
4044H, DATE$: the year, two digits as a binary number (80-99 for 1980-1999, 0-11 for 2000-2011), stored by the reset at 4F2FH from the year offset in 4466H.
4045H
1 byte
DEFB 00H
4045H: the day of the month (1-31), stored by the reset at 4F09H from 4307H.
4046H
1 byte
DEFB 00H
4046H: the month (1-12), stored by the reset at 4EF4H. 4D63H (@DATE) displays 4044H-4046H.
4047H
1 byte
DEFB 00H
4047H: the day of the year, low 8 bits (1-366), stored by the reset at 4F1FH.
4048H
1 byte
DEFB 00H
4048H: bit 0 = bit 8 of the day of the year (4F20H-4F23H), bits 3-1 = the day of the week, 1 for Sunday to 7 for Saturday (4F44H-4F4FH), bit 7 = a leap year (4ECDH-4ED0H). SYS7/SYS (DATE) sets the same bits.
4049H-404AH
2 bytes
DEFS 2
Not in the file: 4049H-404AH, HIGH$, the highest address free for programs. The reset stores the top of memory it finds here and at 4403H (4E17H-4E1AH); modules that install themselves in high memory (KI/DVR, PR/FLT, FDUBL/CMD, SYS9/SYS ...) lower it.
404BH
1 byte
DEFB 00H
404BH, INTIM$: a copy of the interrupt latch (37E0H) the interrupt service routine read last (4518H-4522H): bit 7 the clock, bit 6 the disk controller.
404CH
1 byte
DEFB 00H
404CH, INTMSK$: the mask of the interrupt bits that are served (4524H). The reset stores C0H (bits 7 and 6) at 4E7FH-4E82H.
404DH-404EH
2 bytes
DEFW 4537H
404DH-404EH, INTVC$, the first of eight vectors, one for each bit of the interrupt latch: bit 0. 4537H is the RET at the end of the interrupt service routine, so an unused bit does nothing.
404FH-4050H
2 bytes
DEFW 4537H
404FH-4050H: the vector of interrupt bit 1, 4537H (a RET, not used).
4051H-4052H
2 bytes
DEFW 4537H
4051H-4052H: the vector of interrupt bit 2, 4537H (a RET, not used).
4053H-4054H
2 bytes
DEFW 4537H
4053H-4054H: the vector of interrupt bit 3, 4537H (a RET, not used).
4055H-4056H
2 bytes
DEFW 4537H
4055H-4056H: the vector of interrupt bit 4, 4537H (a RET, not used).
4057H-4058H
2 bytes
DEFW 4537H
4057H-4058H: the vector of interrupt bit 5, 4537H (a RET, not used).
4059H-405AH
2 bytes
DEFW 461CH
4059H-405AH: the vector of interrupt bit 6, the disk controller's interrupt request: 461CH, which waits until the controller is not busy, selecting the drive again from 4309H while it waits.
405BH-405CH
2 bytes
DEFW 456FH
405BH-405CH: the vector of interrupt bit 7, the clock: 456FH, which runs the four task slots 08H-0BH, then counts the tick at 4040H and runs one of the slots 00H-07H.
41DEH-41DFH
2 bytes
DEFW 0000H
41DEH-41DFH: 0000H. The reset starts with the Stack Pointer at 41DEH, so a RET with nothing pushed takes this word: the RET NZ at 4E8FH (the system information sector could not be read) goes to 0000H, the ROM's restart. After a boot by sector 0 of BOOT/SYS the boot sector's last CALLs have stored 4277H here (77H 42H) after this block was loaded.

System Variables (4300H-43FFH)

Address
Size
Contents
4301H-4302H
2 bytes
DEFB 00H x 2
4301H-4302H: the address of the @KITSK jump, 0000H while 4300H holds the RET. SYS6/SYS reads and writes it (its 5456H, 54FCH, 555DH).
4304H-4305H
2 bytes
DEFB 00H x 2
4304H-4305H: the address of the @ICNFG jump, 0000H while 4303H holds the RET.
4306H-4307H
2 bytes
DEFS 2
Not in the file, so a reset keeps them: 4306H, SVDAT1$, the month of the system date OR 50H once a date is set (4EEBH-4EEFH; SYS7/SYS DATE 52ABH, 535FH), and 4307H, SVDAT2$, the day (4EE4H). The reset skips the date prompt when 4306H holds 51H-5CH (a month OR 50H), and the date and the time prompts when it holds 50H (4E9DH-4EA7H).
4308H
1 byte
DEFB FFH
4308H, LDRV$: the drive number of the last disk primitive call (4779H-477CH store Register C here); 4750H selects it again. FFH: no drive yet. BACKUP/CMD stores into it (its 547AH).
4309H
1 byte
DEFB FFH
4309H, PDRV$: the last value written to the drive select latch 37E1H (45F0H), which 461CH writes again while it waits so the drive stays selected. FFH in the file.
430AH-430BH
2 bytes
DEFB 00H x 2
430AH-430BH, JDCB$: the address of the file or device control block of the current call, stored by the common file prologue (49F9H). SYS4/SYS reads it to name the file in an error message (its 4F6BH).
430CH-430DH
2 bytes
DEFB 00H x 2
430CH-430DH, JRET$: the return address of the program's call into the file system (49F6H), the address SYS4/SYS reports in REFERENCED AT (its 4FFAH). FORMAT/CMD, SYS6/SYS and SYS7/SYS point Register Pair HL at 430DH.
430EH
1 byte
DEFB 00H
430EH, OVRLY$: the request code of the system file now in the overlay area at 4E00H (00H: none). The overlay loader compares and stores it (4C03H-4C0AH); 4A92H and 4BE1H read it; BASIC/CMD and BASIC/OV3 store into it.
430FH
1 byte
DEFB 00H
430FH, SFLAG$, the system flags. Bit 1 run the program without DEBUG (4C6EH), bit 2 a program load by @RUN is in progress (4C62H), bit 3 FAST (the reset doubles the drive motor wait and sets bit 0 of port FEH, 4399H, 5061H), bit 4 BREAK disabled (455BH; the reset clears it, or sets it for an AUTO command that starts with 2AH), bit 5 a JCL job runs, bit 7 DEBUG is on (4C71H); the others are used by the overlays and programs (SYS5/SYS, SYS6/SYS, SYS7/SYS, BASIC/CMD).
4310H-4311H
2 bytes
DEFW 4876H
4310H-4311H: the address SYS5/SYS (DEBUG) calls for a command it does not know (its 4E95H): 4876H (OR A / RET), which returns at once with the flags set from Register A. SYS9/SYS stores the address of its extended DEBUG commands here and checks that 4876H is still there before it installs them (its 4E00H-4E22H); SYS6/SYS and SYS7/SYS put 4876H back.
4312H-4314H
3 bytes
DEFB 00H x 3
4312H-4314H: three bytes of 00H. No code of SYS0/SYS addresses them.
4315H
1 byte
DEFB C9H
4315H: the BREAK trap switch. C9H (RET) means off, as does any value but C3H (SYS1/SYS stores 00H, its 4E3BH and 4EA9H); a program that wants BREAK to stop it stores C3H (JP) here and the address at 4316H (BASIC/CMD, SYS1/SYS, SYS5/SYS, SYS6/SYS, SYS7/SYS). When the interrupt service routine sees BREAK while 4315H holds C3H and bit 4 of 430FH is clear, it stores 00H here and goes to the address at 4316H instead of returning (455FH-456EH). The supervisor dispatcher keeps it off while an overlay runs (4BD3H, 4BEAH).
4316H-4317H
2 bytes
DEFW 44B4H
4316H-4317H: the address the BREAK trap goes to, 44B4H (enter DEBUG) in the file. SYS5/SYS and SYS7/SYS store other addresses (their 4F9BH, 5221H).
4318H-431AH
3 bytes
DEFS 3
Not in the file: 4318H-431AH, the first bytes of INBUF$, the 64 byte command line buffer (4318H-4357H: SYS1/SYS reads up to 63 characters into it and stores 03H at 4357H, its 4E16H-4E20H and 4E4FH). During the reset the date and time parser stores its three fields here, the last field typed at 4318H (4349H-4371H); then the reset copies the AUTO command into 4318H-4337H (5030H-5037H), and SYS1/SYS takes command lines from here. Until the first command, 4338H-4357H hold the CONFIG/SYS file specification and the end of the date parser.
4336H-4337H
2 bytes
DEFS 2
Not in the file: 4336H-4337H, bytes 30 and 31 of INBUF$ (4318H-4357H), the last two bytes of the AUTO command the reset copies there.
4338H-4347H
16 bytes
DEFM "CONFIG/SYS.CCC:0"
4338H-4347H: the file specification CONFIG/SYS.CCC:0: the file CONFIG/SYS with the password CCC on drive 0. SYS7/SYS's SYSGEN creates the file under this name.
4348H
1 byte
DEFB 03H
4348H: 03H, the end of the file specification.
4373H-4377H
5 bytes
DEFS 5
Not in the file: 4373H-4377H, the last bytes of JFCB$ (4358H-4377H).
43B0H-43B7H
8 bytes
DEFS 8
Not in the file: 43B0H-43B7H. No code of the LDOS files on this diskette addresses these bytes.
43B8H-43B9H
2 bytes
DEFS 2
Not in the file: 43B8H-43B9H, KISV$, the keyboard driver address saved by the reset from 4016H (4E25H-4E28H). SYS6/SYS reads it (its 5205H).
43BAH-43BBH
2 bytes
DEFS 2
Not in the file: 43BAH-43BBH, DOSV$, the video driver address saved by the reset (4E3EH): 0458H, or 4378H on a computer with lower case. SYS6/SYS reads it (its 520BH).
43BCH-43BDH
2 bytes
DEFS 2
Not in the file: 43BCH-43BDH, PRSV$, the printer driver address saved by the reset from 4026H (4E41H-4E44H). PR/FLT and SYS6/SYS read it.
43BEH-43BFH
2 bytes
DEFS 2
Not in the file: 43BEH-43BFH, KIJCL$, where SYS11/SYS (JCL) and KI/DVR keep the keyboard driver address they replaced.
43C0H
1 byte
DEFB 08H
43C0H, JLDCB$, the job log's device control block, +00H: 08H, the type of a device with nothing assigned (bit 3).
43C1H-43C5H
5 bytes
DEFB 00H x 5
43C1H-43C5H, JLDCB$ +01H-+05H: no driver address and no driver bytes yet.
43C6H-43C7H
2 bytes
DEFM "JL"
43C6H-43C7H, JLDCB$ +06H-+07H: the device name JL.
43C8H
1 byte
DEFB 08H
43C8H, SIDCB$, the standard input's device control block, +00H: 08H, nothing assigned.
43C9H-43CDH
5 bytes
DEFB 00H x 5
43C9H-43CDH, SIDCB$ +01H-+05H: no driver address and no driver bytes yet.
43CEH-43CFH
2 bytes
DEFM "SI"
43CEH-43CFH, SIDCB$ +06H-+07H: the device name SI.
43D0H
1 byte
DEFB 08H
43D0H, SODCB$, the standard output's device control block, +00H: 08H, nothing assigned.
43D1H-43D5H
5 bytes
DEFB 00H x 5
43D1H-43D5H, SODCB$ +01H-+05H: no driver address and no driver bytes yet.
43D6H-43D7H
2 bytes
DEFM "SO"
43D6H-43D7H, SODCB$ +06H-+07H: the device name SO.
43D8H-43FFH
40 bytes
DEFS 40
Not in the file: 43D8H-43FFH, five spare device control blocks (S1DCB$-S5DCB$, eight bytes each). The reset fills them with 00H (4E47H-4E4DH); SET and ROUTE (SYS6/SYS) create user devices in them.

Among the Supervisor Call Vectors (4400H-449FH)

Address
Size
Contents
4403H-4404H
2 bytes
DEFS 2
Not in the file: 4403H-4404H, the top of memory found by the reset (4E1AH), kept apart from HIGH$ (4049H) so that a module chain in high memory can be found: SYS10/SYS walks the chain only when HIGH$ differs from it (its 4F2CH); SYS6/SYS reads it too.
441FH
1 byte
DEFB 00H
441FH, DFLAG$, the device flags: bit 0 the spooler is installed, bit 1 type ahead, bit 2 the screen print and keyboard macro (JKL) module, bit 3 PR/FLT installed, bit 4 KI/DVR installed (KI/DVR 526FH, PR/FLT 521AH, SYS6/SYS and SYS7/SYS set and test them). 00H at boot.
4423H
1 byte
DEFB 20H
4423H, KFLAG$, the keyboard flags. The interrupt routine's keyboard scan (4DA6H) sets bit 0 when BREAK is pressed (unless BREAK is disabled), bit 1 when SHIFT and @ are held (pause) and bit 2 when ENTER is held; the keyboard drivers and the programs clear them. Bit 5 is the CAPS lock, set (20H) at boot. Read and changed by BACKUP/CMD, BASIC/CMD, KI/DVR, TED/CMD, SYS6/SYS, SYS7/SYS and SYS11/SYS.
4427H
1 byte
DEFB 00H
4427H: the last value written to port FEH, the speed control. The reset ORs 01H into it and writes it to the port when bit 3 of 430FH (FAST) is set after the configuration file is loaded (5065H-506EH); SYSTEM (FAST and SLOW, SYS7/SYS 5220H-5231H) changes it.
442BH
1 byte
DEFB 00H
442BH: 00H, the spare byte after @CLOSE. No code of the LDOS files on this diskette addresses it.
442FH
1 byte
DEFB 00H
442FH, MFLAG$, the machine flags: bit 0 set by the reset when it was entered with Index Register IY not 0000H, a boot through a disk driver (the Lobo LX-80 interface), which selects the first block of drive tables in the system information sector (4E5EH-4E61H, 4FCEH; SYS6/SYS, SYS7/SYS and FORMAT/CMD read it).
4466H
1 byte
DEFS 1
Not in the file: 4466H, the year of the system date as an offset from 1980 (0-31, 1980-2011), stored by the reset's date prompt (4EC4H) and by SYS7/SYS's DATE (its 5296H, 5353H); the reset works the leap year and the day of the week from it (4EF8H).
4480H-449FH
32 bytes
DEFS 32
Not in the file: 4480H-449FH, CFCB$, the 32 byte control block that SYS1/SYS fills for the command being run (its 4E6CH); BASIC/CMD, its overlays, SYS6/SYS and SYS12/SYS use it too.

SFCB$ and Its Neighbours (44A0H-44FFH)

Address
Size
Contents
44A0H
1 byte
DEFB 80H
44A0H, SFCB$ +00H: 80H, bit 7 set: the block describes an open file, which the file prologue (49F3H) requires.
44A1H
1 byte
DEFB 00H
44A1H, SFCB$ +01H: the file flags (bits 2-0 the access granted, bit 5 the buffer must be read first). The overlay loader stores 20H here before every load (4C20H-4C22H): full access and an empty buffer.
44A2H
1 byte
DEFB 00H
44A2H, SFCB$ +02H: 00H, not used by SYS0/SYS's file routines.
44A3H-44A4H
2 bytes
DEFW 4200H
44A3H-44A4H, SFCB$ +03H-+04H: 4200H, the address of the 256 byte buffer the system file's sectors are read into (the module loader at 4C8DH takes its bytes from 4200H-42FFH).
44A5H
1 byte
DEFB 00H
44A5H, SFCB$ +05H: 00H, the position of the next byte in the buffer.
44A6H
1 byte
DEFB 00H
44A6H, SFCB$ +06H: 00H, the drive: system files are read from drive 0.
44A7H
1 byte
DEFB 00H
44A7H, SFCB$ +07H: the directory record number of the system file, stored by the overlay loader (4C1CH): 3-7 for SYS1/SYS-SYS5/SYS, 20H-26H for SYS6/SYS-SYS12/SYS.
44A8H
1 byte
DEFB 00H
44A8H, SFCB$ +08H: 00H, the end of file byte (not used for a system file).
44A9H
1 byte
DEFB 00H
44A9H, SFCB$ +09H: 00H, the record length: 256 bytes.
44AAH-44ABH
2 bytes
DEFB 00H x 2
44AAH-44ABH, SFCB$ +0AH-+0BH: the next record number, set to 0000H before every load (4C25H-4C27H) so the file is read from its start.
44ACH-44ADH
2 bytes
DEFB FFH x 2
44ACH-44ADH, SFCB$ +0CH-+0DH: FFFFH, the ending record number, as high as it goes, so a system file never reaches its end of file before its last load record.
44AEH-44AFH
2 bytes
DEFB 00H x 2
44AEH-44AFH, SFCB$ +0EH-+0FH: the first extent of the system file (cylinder, then the first granule in bits 7-5 and the granules less one in bits 4-0), copied from bytes 16H-17H of its directory record by 47B4H.
44B0H-44B3H
4 bytes
DEFB FFH x 4
44B0H-44B3H, SFCB$ +10H-+13H: the number of granules of the first extent (a word, 47BBH-47C2H) and the second extent (bytes 18H-19H of the directory record, 47C3H). FFH in the file.
44FEH-44FFH
2 bytes
DEFB 00H x 2
44FEH-44FFH: two bytes of 00H. No code of SYS0/SYS addresses them.

Task Table, Clock and Driver (4500H-46FFH)

Address
Size
Contents
4500H-4501H
2 bytes
DEFW 45B2H
4500H-4501H: the entry of task slot 0 (run on every eighth tick, when bits 2-0 of TIMER$ (4040H) equal 0): 45B2H, the empty block, whose routine is the RET at 45B1H.
4502H-4503H
2 bytes
DEFW 45B2H
4502H-4503H: the entry of task slot 1 (run on every eighth tick, when bits 2-0 of TIMER$ (4040H) equal 1): 45B2H, the empty block, whose routine is the RET at 45B1H.
4504H-4505H
2 bytes
DEFW 45B2H
4504H-4505H: the entry of task slot 2 (run on every eighth tick, when bits 2-0 of TIMER$ (4040H) equal 2): 45B2H, the empty block, whose routine is the RET at 45B1H.
4506H-4507H
2 bytes
DEFW 45B2H
4506H-4507H: the entry of task slot 3 (run on every eighth tick, when bits 2-0 of TIMER$ (4040H) equal 3): 45B2H, the empty block, whose routine is the RET at 45B1H.
4508H-4509H
2 bytes
DEFW 45B2H
4508H-4509H: the entry of task slot 4 (run on every eighth tick, when bits 2-0 of TIMER$ (4040H) equal 4): 45B2H, the empty block, whose routine is the RET at 45B1H.
450AH-450BH
2 bytes
DEFW 45B2H
450AH-450BH: the entry of task slot 5 (run on every eighth tick, when bits 2-0 of TIMER$ (4040H) equal 5): 45B2H, the empty block, whose routine is the RET at 45B1H.
450CH-450DH
2 bytes
DEFW 45B2H
450CH-450DH: the entry of task slot 6 (run on every eighth tick, when bits 2-0 of TIMER$ (4040H) equal 6): 45B2H, the empty block, whose routine is the RET at 45B1H. SYS7/SYS puts the clock display 4D3AH here and takes it out again (its 532AH-5334H).
450EH-450FH
2 bytes
DEFW 45B2H
450EH-450FH: the entry of task slot 7 (run on every eighth tick, when bits 2-0 of TIMER$ (4040H) equal 7): 45B2H, the empty block, whose routine is the RET at 45B1H. SYS0/SYS's reset puts the clock's block 45BEH here (4FBDH-4FC2H).
4510H-4511H
2 bytes
DEFW 45B2H
4510H-4511H: the entry of task slot 8 (run on every tick): 45B2H, the empty block, whose routine is the RET at 45B1H.
4512H-4513H
2 bytes
DEFW 45B2H
4512H-4513H: the entry of task slot 9 (run on every tick): 45B2H, the empty block, whose routine is the RET at 45B1H.
4514H-4515H
2 bytes
DEFW 45B2H
4514H-4515H: the entry of task slot 10 (run on every tick): 45B2H, the empty block, whose routine is the RET at 45B1H.
4516H-4517H
2 bytes
DEFW 45B2H
4516H-4517H: the entry of task slot 11 (run on every tick): 45B2H, the empty block, whose routine is the RET at 45B1H. SYS7/SYS puts the program counter display 4D6AH here and takes it out again (its 53A7H-53B1H).
45B2H-45B3H
2 bytes
DEFW 45B1H
45B2H-45B3H: the empty task block. Its first word is 45B1H, the RET above, so a free slot does nothing.
45BEH-45BFH
2 bytes
DEFW 45C1H
45BEH-45BFH: the block's first word: 45C1H, its routine.
45C0H
1 byte
DEFB 05H
45C0H, the block's byte +02H: the count of calls left before the next second, 05H. The routine counts it down through Index Register IX.
45DBH-45DCH
2 bytes
DEFB 00H x 2
45DBH-45DCH: two bytes of 00H. No code of SYS0/SYS addresses them.
45DDH-45DFH
3 bytes
DEFB 3CH, 3CH, 18H
45DDH-45DFH: the limits of the clock fields: 3CH (60) seconds, 3CH (60) minutes, 18H (24) hours, read by 45D2H.
4679H-467BH
3 bytes
DEFB 01H, 1AH, 02H
The parameters of a read: 01H, the first error number of a read (469DH stores it at 46F6H, so the errors of the status bits are 03H lost data, 04H parity error, 05H not found, 06H a system data record (the deleted data mark of a directory sector), 07H a locked or deleted record), and 1AH 02H, the body of the transfer loop: LD A,(DE) / LD (BC),A, a byte from the data register into the buffer.
467FH-4681H
3 bytes
DEFB 01H, 1AH, 0EH
The parameters of a verify: 01H, the first error number of a read, and 1AH 0EH, the loop body LD A,(DE) / LD C,03H: the byte is read from the data register and not stored (the 0EH takes the INC BC at 46D3H as its operand). Entered at 4681H from 4672H, the bytes 0EH A8H are LD C,0A8H: the command Write Sector for the writes.
4697H-4699H
3 bytes
DEFB 09H, 0AH, 12H
The parameters of a write: 09H, the first error number of a write (0BH lost data, 0CH parity error, 0DH not found, 0EH write fault, 0FH write protected), and 0AH 12H, the loop body LD A,(BC) / LD (DE),A, a byte from the buffer into the data register.
46FFH
1 byte
DEFB FDH
46FFH: FDH, the last byte but one of the load record 461CH-4700H; the record ends with E9H at 4700H (FDH E9H, JP (IY)), but the next record (4700H-47CAH) loads C3H over 4700H, so in memory 46FFH-4700H are FDH C3H. No code of the LDOS files on this diskette jumps to 46FFH.

Drive Code Tables and Primitives (4700H-47FFH)

Address
Size
Contents
4700H-4702H
3 bytes
DEFB C3H, FBH, 45H
4700H-4702H, drive 0, +00H-+02H: JP 45FBH, SYS0/SYS's floppy disk driver; the drive is present.
4703H
1 byte
DEFB 83H
4703H, drive 0, +03H: 83H, step rate 3 and bit 7 (write protect) set. The reset keeps only bits 6-2 and puts in the bootstrap step rate of the boot sector (4E6EH-4E75H: AND 7CH, OR the rate), so the write protect bit is off after a boot.
4704H
1 byte
DEFB 01H
4704H, drive 0, +04H: 01H, select line 1 (drive 0). The reset ORs in bit 5 when the allocation table of the diskette in drive 0 says two sides (4FE3H-4FEDH).
4705H
1 byte
DEFB 01H
4705H, drive 0, +05H: 01H, the cylinder the head is on as the file was built; the first Seek tells the controller this value through its track register.
4706H
1 byte
DEFB 22H
4706H, drive 0, +06H: 22H, highest cylinder 34 (35 cylinders).
4707H
1 byte
DEFB 09H
4707H, drive 0, +07H: 09H, highest sector 9 (10 sectors a track, single density), one head.
4708H
1 byte
DEFB 24H
4708H, drive 0, +08H: 24H, 5 sectors to a granule (bits 4-0 plus 1) and 2 granules on a track (bits 7-5 plus 1).
4709H
1 byte
DEFB 11H
4709H, drive 0, +09H: 11H, directory cylinder 17. The reset stores the directory cylinder from byte 2 of the boot sector here (4E76H-4E79H).
470AH-4713H
10 bytes
DEFB C3H, FBH, 45H, 03H, 02H, 11H, 22H, 09H, 24H, 11H
470AH-4713H, drive 1: JP 45FBH (present), +03H 03H step rate 3, +04H 02H select line 2, +05H 11H head on cylinder 17, +06H 22H 35 cylinders, +07H 09H 10 sectors, +08H 24H 2 granules of 5 sectors, +09H 11H directory cylinder 17. Replaced by the reset from the system information sector.
4714H-471DH
10 bytes
DEFB C3H, FBH, 45H, 03H, 04H, 11H, 22H, 09H, 24H, 11H
4714H-471DH, drive 2: JP 45FBH (present), step rate 3, select line 4, head on cylinder 17, 35 cylinders of 10 sectors, 2 granules of 5 sectors, directory cylinder 17. Replaced by the reset.
471EH-4727H
10 bytes
DEFB C3H, FBH, 45H, 03H, 08H, 11H, 22H, 09H, 24H, 11H
471EH-4727H, drive 3: JP 45FBH (present), step rate 3, select line 8, head on cylinder 17, 35 cylinders of 10 sectors, 2 granules of 5 sectors, directory cylinder 17. Replaced by the reset.
4728H
1 byte
DEFB C9H
4728H, drive 4, +00H: C9H (RET), not present. Replaced by the reset.
4729H-4731H
9 bytes
DEFB 00H x 9
4729H-4731H, drive 4, +01H-+09H: 00H, no driver and no geometry.
4732H
1 byte
DEFB C9H
4732H, drive 5, +00H: C9H (RET), not present. Replaced by the reset.
4733H-473BH
9 bytes
DEFB 00H x 9
4733H-473BH, drive 5, +01H-+09H: 00H, no driver and no geometry.
473CH
1 byte
DEFB C9H
473CH, drive 6, +00H: C9H (RET), not present. Replaced by the reset.
473DH-4745H
9 bytes
DEFB 00H x 9
473DH-4745H, drive 6, +01H-+09H: 00H, no driver and no geometry.
4746H
1 byte
DEFB C9H
4746H, drive 7, +00H: C9H (RET), not present. Replaced by the reset.
4747H-474FH
9 bytes
DEFB 00H x 9
4747H-474FH, drive 7, +01H-+09H: 00H, no driver and no geometry.
4758H
1 byte
DEFB 00H
4758H: the fifth byte of SELECT, the status byte of the command interpreter. SYS1/SYS clears it for every command line typed or given to @CMNDI, sets bit 1 for a line from a program (function 20H) and bit 2 while a line is typed, and tests bit 4 (no program run) and bit 1 (its 4E22H-4E53H, 4E8EH, 4E97H). Members of SYS6/SYS and SYS7/SYS test bit 1 and set bit 3, which KI/DVR tests (its 520BH); SYS4/SYS skips the error message when bit 6 is set and gives the short message when bit 7 is set (its 4EC7H-4EDDH) and clears bit 7, which TED/CMD sets (its 56AFH).
475DH
1 byte
DEFB 00H
475DH: the fifth byte of RSELCT, the date stamping flags that SYS2/SYS (its 4EA7H) and SYS3/SYS (its 4E99H) use when they open and close files; BACKUP/CMD, SYS6/SYS and SYS7/SYS read it too.
4762H
1 byte
DEFB FFH
4762H: the fifth byte of SEEK, FFH. No code of the LDOS files on this diskette addresses it.
4767H
1 byte
DEFB 01H
4767H: the fifth byte of WRSECT, 01H: the cylinder where SYS8/SYS starts its search for free space (its 4EBFH). Nothing writes it, so every search starts at cylinder 1.
476CH
1 byte
DEFB 00H
476CH: the fifth byte of WRPROT, 00H. No code of the LDOS files on this diskette addresses it.
4771H
1 byte
DEFB 00H
4771H: the fifth byte of WRTRK, 00H. No code of the LDOS files on this diskette addresses it.
4776H
1 byte
DEFB 00H
4776H: the fifth byte of VERSEC, 00H. No code of the LDOS files on this diskette addresses it.
478EH
1 byte
DEFB 00H
478EH: 00H, the spare byte after the primitives.

File Routines to the Base Cells (4800H-4DFFH)

Address
Size
Contents
4B64H
1 byte
DEFB 00H
4B64H: 00H, a spare byte. No code addresses it.
4BBCH-4BC8H
13 bytes
DEFB 00H x 13
4BBCH-4BC8H: 13 bytes of 00H. SYS1/SYS stores a word at 4BC0H (its 4F43H).
4BC9H-4BCAH
2 bytes
DEFB 00H x 2
4BC9H-4BCAH: every system file 1-12 starts with a load block for these two bytes: the length of the file's part at 4E00H (for example 03AFH for SYS4/SYS), so they always hold the length of the system file in the overlay area. SYS7/SYS reads and writes them (its 5764H, 5812H).
4C54H-4C5CH
9 bytes
DEFM "SYS Error"
4C54H-4C5CH: the message displayed when a request cannot be served: an unknown request code below 80H, or a system file that is missing or cannot be loaded.
4C5DH
1 byte
DEFB 0DH
4C5DH: 0DH, the end of the SYS Error text (displayed: the line ends).
4D3AH-4D3BH
2 bytes
DEFW 4D3DH
4D3AH-4D3BH: the task block's first word: 4D3DH, its routine.
4D3CH
1 byte
DEFB 05H
4D3CH, the block's byte +02H: the calls left before the next display, 05H.
4D6AH-4D6BH
2 bytes
DEFW 4D6CH
4D6AH-4D6BH: the task block's first word: 4D6CH, its routine.
4DD8H-4DEFH
24 bytes
DEFS 24
Not in the file: 4DD8H-4DEFH. No code of the LDOS files on this diskette addresses these bytes.
4DF0H-4DFDH
14 bytes
DEFB 00H x 14
4DF0H-4DFDH: 14 bytes of 00H, the cells listed above, empty at boot.
4DFEH-4DFFH
2 bytes
DEFW 43B0H
4DFEH-4DFFH: 43B0H, the address of the eight bytes 43B0H-43B7H. No code of the LDOS files on this diskette reads this word.

The Reset (4E00H-50FFH)

Address
Size
Contents
50B6H
1 byte
DEFB 1EH
50B6H: 1EH, clear to the end of the line, the first byte of the date prompt (4EACH).
50B7H-50BDH
7 bytes
DEFM "Date ? "
50B7H-50BDH: the prompt Date ? followed by a space.
50BEH
1 byte
DEFB 03H
50BEH: 03H, the end of text mark of the date prompt.
50BFH
1 byte
DEFB 1EH
50BFH: 1EH, clear to the end of the line, the first byte of the time prompt (4F9CH).
50C0H-50C6H
7 bytes
DEFM "Time ? "
50C0H-50C6H: the prompt Time ? followed by a space.
50C7H
1 byte
DEFB 03H
50C7H: 03H, the end of text mark of the time prompt.
50C8H-50FFH
56 bytes
DEFB 00H x 56
50C8H-50FFH: 56 bytes of 00H, the end of the file's last block before 5100H.

Changed Code and Data Outside the Rows Above

AddressContents
4E66HEntered from 4E54H, the operand bytes of LD BC,0BC2EH run as LD L,0BCH.
505EHThe second byte of RES 4,(HL) (A6H) in the file; the reset stores E6H for an AUTO command that starts with 2AH, so it runs (at 4061H) as SET 4,(HL).
4BF0HThe reset stores C8H (RET Z) here for an AUTO command that starts with 2AH (500BH-500DH).
4201HThe configuration file flag of the system information sector; the reset saves it and stores 00H (4E90H-4E95H).
4203HThe days of February in the system information sector, set to 28 or 29 (4ED6H, 4F01H).
4704HByte +04H of drive 0's drive code table: the reset ORs in bit 5 for a double sided diskette.

Disassembly

3C00H - Sign-On Screen (Video Memory, Data)

The first three load blocks of SYS0/SYS go straight into video memory (3C00H-3FFFH, 64 characters by 16 rows): while the boot sector loads the file, the sign-on lines and the LDOS logo appear on the screen the boot sector has just cleared. They are data, not code. SYS0/SYS's reset later adds the diskette name and date (3CD6H-3CDDH, 3CE0H-3CE7H), the date and time prompts (3F17H, 3F57H) and the day, date and time line it builds from them.

3C00-3C39
DEFM " L D O S - THE LOGICAL DISK OPERATING SYSTEM - VER 5.3.1" 20 20 20 4C 20 44 20 4F 20 53 20 2D 20 54 48 45 20 4C 4F 47 49 43 41 4C 20 44 49 53 4B 20 4F 50 45 52 41 54 49 4E 47 20 53 59 53 54 45 4D 20 2D 20 56 45 52 20 35 2E 33 2E 31
Screen row 0, columns 0-57: the title line, three spaces then L D O S - THE LOGICAL DISK OPERATING SYSTEM - VER 5.3.1. SYS0/SYS's reset stores 20H over 3C00H again after its video memory test (4E2BH-4E31H).
3C3A-3C45
DEFS 12
Not in the file: screen row 0, columns 58-63, and row 1, columns 0-5, keep the spaces the boot sector's clear screen left.
3C46-3C76
DEFM "Copyright 1991 MISOSYS, INC., ALL RIGHTS RESERVED" 43 6F 70 79 72 69 67 68 74 20 31 39 39 31 20 4D 49 53 4F 53 59 53 2C 20 49 4E 43 2E 2C 20 41 4C 4C 20 52 49 47 48 54 53 20 52 45 53 45 52 56 45 44
Screen row 1, columns 6-54: the copyright line. On a computer whose video memory has no lower case the small letters show as other characters; SYS0/SYS does not change them.
3C77-3D3F
DEFS 201
Not in the file: the rest of row 1 and rows 2-4 (3C77H-3D3FH). SYS0/SYS's reset writes the name of the diskette in drive 0 at 3CD6H-3CDDH and its date at 3CE0H-3CE7H (row 3, 4FF0H-4FFEH); the rest stays blank.
3D40-3D4F
DEFB 20H, BFH, BFH, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 20H 20 BF BF 20 20 20 20 20 20 20 20 20 20 20 20 20
Screen row 5, columns 0-15, the top row of the logo: a space, then the upright of the L (BFH BFH at columns 1-2) and 13 spaces. Codes 80H-BFH are graphics characters (two by three blocks, bit 0 the top left block up to bit 5 the bottom right), 20H is a space.
3D50-3D5F
DEFB 20H, BFH, BFH, 8FH, 8FH, 8FH, 8FH, 8FH, 8FH, AFH, BDH, B4H, 20H, 20H, 20H, 20H 20 BF BF 8F 8F 8F 8F 8F 8F AF BD B4 20 20 20 20
Screen row 5, columns 16-31, the top row of the logo: the top of the D: upright BFH BFH, bar 8FH x 6, the corner AFH BDH B4H, then spaces. Codes 80H-BFH are graphics characters (two by three blocks, bit 0 the top left block up to bit 5 the bottom right), 20H is a space.
3D60-3D6F
DEFB 20H, BFH, BFH, 8FH, 8FH, 8FH, 8FH, 8FH, 8FH, 8FH, 8FH, BFH, BFH, 20H, 20H, 20H 20 BF BF 8F 8F 8F 8F 8F 8F 8F 8F BF BF 20 20 20
Screen row 5, columns 32-47, the top row of the logo: the top of the O: upright BFH BFH, bar 8FH x 8, upright BFH BFH, then spaces. Codes 80H-BFH are graphics characters (two by three blocks, bit 0 the top left block up to bit 5 the bottom right), 20H is a space.
3D70-3D7F
DEFB 20H, BFH, BFH, 8FH, 8FH, 8FH, 8FH, 8FH, 8FH, 8FH, 8FH, BFH, BFH, 20H, 54H, 4DH 20 BF BF 8F 8F 8F 8F 8F 8F 8F 8F BF BF 20 54 4D
Screen row 5, columns 48-63, the top row of the logo: the top of the S: BFH BFH, bar 8FH x 8, BFH BFH, a space and TM (54H 4DH) at columns 62-63. Codes 80H-BFH are graphics characters (two by three blocks, bit 0 the top left block up to bit 5 the bottom right), 20H is a space.
3D80-3D8F
DEFB 20H, BFH, BFH, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 20H 20 BF BF 20 20 20 20 20 20 20 20 20 20 20 20 20
Screen row 6, columns 0-15, the second row of the logo: a space, the upright of the L (BFH BFH) and spaces. Codes 80H-BFH are graphics characters (two by three blocks, bit 0 the top left block up to bit 5 the bottom right), 20H is a space.
3D90-3D9F
DEFB 20H, BFH, BFH, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 82H, BFH, BDH, 20H, 20H, 20H 20 BF BF 20 20 20 20 20 20 20 82 BF BD 20 20 20
Screen row 6, columns 16-31, the second row of the logo: the D: its left upright BFH BFH, spaces, then the curve 82H BFH BDH at columns 25-27. Codes 80H-BFH are graphics characters (two by three blocks, bit 0 the top left block up to bit 5 the bottom right), 20H is a space.
3DA0-3DAF
DEFB 20H, BFH, BFH, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 20H, BFH, BFH, 20H, 20H, 20H 20 BF BF 20 20 20 20 20 20 20 20 BF BF 20 20 20
Screen row 6, columns 32-47, the second row of the logo: the O: left upright BFH BFH, spaces, right upright BFH BFH. Codes 80H-BFH are graphics characters (two by three blocks, bit 0 the top left block up to bit 5 the bottom right), 20H is a space.
3DB0-3DBF
DEFB 20H, BFH, BFH, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 20H 20 BF BF 20 20 20 20 20 20 20 20 20 20 20 20 20
Screen row 6, columns 48-63, the second row of the logo: the S: its left upright BFH BFH at columns 48-49 and spaces. Codes 80H-BFH are graphics characters (two by three blocks, bit 0 the top left block up to bit 5 the bottom right), 20H is a space.
3DC0-3DCF
DEFB 20H, BFH, BFH, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 20H 20 BF BF 20 20 20 20 20 20 20 20 20 20 20 20 20
Screen row 7, columns 0-15, the third row of the logo: a space, the upright of the L (BFH BFH) and spaces. Codes 80H-BFH are graphics characters (two by three blocks, bit 0 the top left block up to bit 5 the bottom right), 20H is a space.
3DD0-3DDF
DEFB 20H, BFH, BFH, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 20H, BFH, BFH, 20H, 20H, 20H 20 BF BF 20 20 20 20 20 20 20 20 BF BF 20 20 20
Screen row 7, columns 16-31, the third row of the logo: the D: left upright BFH BFH, spaces, right side BFH BFH at columns 26-27. Codes 80H-BFH are graphics characters (two by three blocks, bit 0 the top left block up to bit 5 the bottom right), 20H is a space.
3DE0-3DEF
DEFB 20H, BFH, BFH, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 20H, BFH, BFH, 20H, 20H, 20H 20 BF BF 20 20 20 20 20 20 20 20 BF BF 20 20 20
Screen row 7, columns 32-47, the third row of the logo: the O: left upright BFH BFH, spaces, right upright BFH BFH. Codes 80H-BFH are graphics characters (two by three blocks, bit 0 the top left block up to bit 5 the bottom right), 20H is a space.
3DF0-3DFF
DEFB 20H, 8FH, 8FH, 8FH, 8FH, 8FH, 8FH, 8FH, 8FH, 8FH, 8FH, BFH, BFH, 20H, 20H, 20H 20 8F 8F 8F 8F 8F 8F 8F 8F 8F 8F BF BF 20 20 20
Screen row 7, columns 48-63, the third row of the logo: the middle bar of the S: 8FH x 10 at columns 48-57 and BFH BFH at columns 58-59. Codes 80H-BFH are graphics characters (two by three blocks, bit 0 the top left block up to bit 5 the bottom right), 20H is a space.
3E00-3E0F
DEFB 20H, BFH, BFH, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 20H 20 BF BF 20 20 20 20 20 20 20 20 20 20 20 20 20
Screen row 8, columns 0-15, the fourth row of the logo: a space, the upright of the L (BFH BFH) and spaces. Codes 80H-BFH are graphics characters (two by three blocks, bit 0 the top left block up to bit 5 the bottom right), 20H is a space.
3E10-3E1F
DEFB 20H, BFH, BFH, 20H, 20H, 20H, 20H, 20H, 20H, 20H, A0H, BFH, 9FH, 20H, 20H, 20H 20 BF BF 20 20 20 20 20 20 20 A0 BF 9F 20 20 20
Screen row 8, columns 16-31, the fourth row of the logo: the D: left upright BFH BFH, spaces, the curve A0H BFH 9FH at columns 25-27. Codes 80H-BFH are graphics characters (two by three blocks, bit 0 the top left block up to bit 5 the bottom right), 20H is a space.
3E20-3E2F
DEFB 20H, BFH, BFH, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 20H, BFH, BFH, 20H, 20H, 20H 20 BF BF 20 20 20 20 20 20 20 20 BF BF 20 20 20
Screen row 8, columns 32-47, the fourth row of the logo: the O: left upright BFH BFH, spaces, right upright BFH BFH. Codes 80H-BFH are graphics characters (two by three blocks, bit 0 the top left block up to bit 5 the bottom right), 20H is a space.
3E30-3E3F
DEFB 20H, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 20H, BFH, BFH, 20H, 20H, 20H 20 20 20 20 20 20 20 20 20 20 20 BF BF 20 20 20
Screen row 8, columns 48-63, the fourth row of the logo: the S: its right upright BFH BFH at columns 58-59 and spaces. Codes 80H-BFH are graphics characters (two by three blocks, bit 0 the top left block up to bit 5 the bottom right), 20H is a space.
3E40-3E4F
DEFB 20H, BFH, BFH, BCH, BCH, BCH, BCH, BCH, BCH, BCH, BCH, BFH, BFH, 20H, 20H, 20H 20 BF BF BC BC BC BC BC BC BC BC BF BF 20 20 20
Screen row 9, columns 0-15, the bottom row of the logo: a space, the foot of the L: BFH BFH and the bar BCH x 8, BFH BFH at columns 11-12. Codes 80H-BFH are graphics characters (two by three blocks, bit 0 the top left block up to bit 5 the bottom right), 20H is a space.
3E50-3E5F
DEFB 20H, BFH, BFH, BCH, BCH, BCH, BCH, BCH, BCH, BEH, 9FH, 87H, 20H, 20H, 20H, 20H 20 BF BF BC BC BC BC BC BC BE 9F 87 20 20 20 20
Screen row 9, columns 16-31, the bottom row of the logo: the bottom of the D: upright BFH BFH, bar BCH x 6, the corner BEH 9FH 87H. Codes 80H-BFH are graphics characters (two by three blocks, bit 0 the top left block up to bit 5 the bottom right), 20H is a space.
3E60-3E6F
DEFB 20H, BFH, BFH, BCH, BCH, BCH, BCH, BCH, BCH, BCH, BCH, BFH, BFH, 20H, 20H, 20H 20 BF BF BC BC BC BC BC BC BC BC BF BF 20 20 20
Screen row 9, columns 32-47, the bottom row of the logo: the bottom of the O: BFH BFH, bar BCH x 8, BFH BFH. Codes 80H-BFH are graphics characters (two by three blocks, bit 0 the top left block up to bit 5 the bottom right), 20H is a space.
3E70-3E7F
DEFB 20H, BFH, BFH, BCH, BCH, BCH, BCH, BCH, BCH, BCH, BCH, BFH, BFH, 20H, 20H, 20H 20 BF BF BC BC BC BC BC BC BC BC BF BF 20 20 20
Screen row 9, columns 48-63, the bottom row of the logo: the bottom of the S: BFH BFH, bar BCH x 8, BFH BFH. Codes 80H-BFH are graphics characters (two by three blocks, bit 0 the top left block up to bit 5 the bottom right), 20H is a space.
3E80-3FFF
DEFS 384
Not in the file: screen rows 10-15. SYS0/SYS's reset puts the Date? prompt at 3F17H (row 12) and the Time? prompt at 3F57H (row 13), and moves the cursor to 3F40H (row 13) before it returns (5076H-5079H).

400CH - Restart Vectors

The Level II ROM sends its RST 28H, RST 30H and RST 38H restarts through these three bytes each (ROM 0028H, 0030H and 0038H jump to 400CH, 400FH and 4012H). SYS0/SYS loads a JP into each: the supervisor call dispatcher, the DEBUG entry and the interrupt service routine. RST 28H with a request code in Register A is how every overlay of the system is called.

400C
Jump to 4BCDH, the supervisor call dispatcher. ROM 0028H (RST 28H) comes here with the request code in Register A (for example 93H, return to LDOS READY, from 402DH). 4BCDH loads the system file the code names into 4E00H when it is not already there and calls it.
400F
Jump to 44B4H, which saves Register Pair AF and issues request 87H (load and run SYS5/SYS, the DEBUG monitor). ROM 0030H (RST 30H, the breakpoint instruction DEBUG plants) comes here; SYS0/SYS's own 4C73H jumps here to enter DEBUG before a loaded program runs, and SYS5/SYS and SYS7/SYS read this vector's address (their 4F98H and 521CH).
4012
Jump to 4518H, the interrupt service routine. ROM 0038H (RST 38H, the maskable interrupt in mode 1) comes here on every interrupt of the expansion interface. SYS0/SYS's reset stores C3H (the JP) here again as its last step before it enables interrupts (507CH-507FH); FORMAT/CMD and BACKUP/CMD store other values here and put the byte back (FORMAT/CMD 6008H-6010H, 6446H; BACKUP/CMD 52C6H, 5ED3H-5EDBH).

4015H - Device Control Blocks of the Keyboard, Video and Printer

The ROM's device control blocks, eight bytes each, loaded with the ROM's own values: +00H the type of device, +01H-+02H the address of its driver, +03H-+05H the driver's own bytes, +06H-+07H the two letter device name. SYS0/SYS's reset saves the three driver addresses at 43B8H, 43BAH and 43BCH, and on a computer with lower case video memory points the video block at its own driver at 4378H.

4015
DEFB 01H 01
4015H, KIDCB$, the keyboard's device control block, +00H: 01H, the device type (an input device). KI/DVR, SYS2/SYS, SYS6/SYS and SYS11/SYS address the block from here.
4016-4017
DEFW 03E3H E3 03
4016H-4017H, KIDCB$ +01H-+02H: 03E3H, the ROM's keyboard driver. SYS0/SYS's reset copies this address to 43B8H (4E25H-4E28H); KI/DVR (its 5436H, 5559H), SYS7/SYS and SYS11/SYS replace it with their own drivers and put it back.
4018-401A
DEFB 00H x 3 00 x 3
4018H-401AH, KIDCB$ +03H-+05H: three bytes of 00H for the driver's use. SYS7/SYS stores into 4018H (its 5281H).
401B-401C
DEFM "KI" 4B 49
401BH-401CH, KIDCB$ +06H-+07H: the device name KI.
401D
DEFB 07H 07
401DH, DODCB$, the video display's device control block, +00H: 07H, the device type (input, output and control). @DSPLY (44E3H) sends its text to the block at 401DH.
401E-401F
DEFW 0458H 58 04
401EH-401FH, DODCB$ +01H-+02H: 0458H, the ROM's video driver. SYS0/SYS's reset replaces it with 4378H, its own driver that shows lower case, when video memory keeps bit 6 of a byte written to it (4E2BH-4E3BH), and saves the address in force at 43BAH.
4020-4021
DEFW 3C00H 00 3C
4020H-4021H, DODCB$ +03H-+04H: 3C00H, the cursor position in video memory (the top left corner). SYS0/SYS sets it for each prompt (431BH, 4F53H) and leaves it at 3F40H after the reset (5076H-5079H); BASIC/CMD, SYS5/SYS, SYS6/SYS and SYS7/SYS read and set it.
4022
DEFB 00H 00
4022H, DODCB$ +05H: the character under the cursor, 00H when the cursor is off (the ROM's driver puts it back before it moves the cursor). SYS7/SYS reads it (its 5479H).
4023-4024
DEFM "DO" 44 4F
4023H-4024H, DODCB$ +06H-+07H: the device name DO.
4025
DEFB 06H 06
4025H, PRDCB$, the printer's device control block, +00H: 06H, the device type (output and control). @PRINT (44F8H) sends its text to the block at 4025H.
4026-4027
DEFW 058DH 8D 05
4026H-4027H, PRDCB$ +01H-+02H: 058DH, the ROM's printer driver. SYS0/SYS's reset copies the address to 43BCH (4E41H-4E44H).
4028
DEFB 42H 42
4028H, PRDCB$ +03H: 42H (66), the lines on a printer page, the ROM's default.
4029
DEFB 00H 00
4029H, PRDCB$ +04H: 00H, the count of lines printed on the page.
402A
DEFB 00H 00
402AH, PRDCB$ +05H: 00H, the driver's spare byte.
402B-402C
DEFM "PR" 50 52
402BH-402CH, PRDCB$ +06H-+07H: the device name PR.

402DH - @EXIT and @ABORT

The two ways a program ends. Both issue request 93H, which runs the LDOS READY command loop of SYS1/SYS. Programs JP to 402DH (@EXIT) when they finish and to 4030H (@ABORT) when they stop on an error; SYS11/SYS (JCL) and BASIC/CMD (its 5545H-5559H) write other request codes or jumps into them while they run.

402D
LD A,93H 3E 93
Load Register A with 93H, the request code of SYS1/SYS's command loop (system file 1, function 10H): @EXIT, the normal end of a program.
402F
RST 28H EF
RST 28H: call the supervisor dispatcher (400CH, 4BCDH) with the request code 93H in Register A. SYS1/SYS displays LDOS READY and waits for the next command; it does not return here.
4030
LD A,93H 3E 93
Load Register A with 93H, the same request code as @EXIT: @ABORT, the end of a program after an error. The two entries are separate so that SYS11/SYS (JCL) can give them different request codes while a job runs.
4032
RST 28H EF
RST 28H: call the supervisor dispatcher with the request code in Register A (93H): LDOS READY.
4033
Jump to 44CAH: @DVRHK, the device driver hook. The caller gives the address of a device control block in Register Pair IX (or in Register Pair HL at 44C7H) and the request in Register B and Register C; 44CAH follows the block's links to its driver and enters it.
4036-403C
DEFB FFH x 7 FF x 7
4036H-403CH: the ROM keyboard driver's work area, one byte for each keyboard row 0-6, the keys it last saw held (the ROM's 03EBH-03EFH takes as new only keys not set here). FFH in every byte makes every key held at boot count as already seen, so a key held during the reset is not taken as typed. KI/DVR uses these bytes too (its 52C8H, 535FH, 5394H).
403D
DEFS 1
Not in the file: 403DH, the ROM's video mode byte (bit 3 set for 32 characters a line), left as the ROM set it. BASIC/CMD reads it (its 5A0CH).

403EH - OSVER$, the Clock and the Date

The version byte, the 25 millisecond tick counter, the time of day and the date. The time (4041H-4043H) is not in the file, so a reset keeps the clock running across a reboot; the date bytes are loaded as 00H and set by the boot date prompt or kept from the last date (4306H, 4307H).

403E
DEFB 53H 53
403EH, OSVER$: 53H, the system version 5.3 (BASIC/CMD reads it, its 5344H).
403F
DEFB 00H 00
403FH: 00H. No code of SYS0/SYS addresses it.
4040
DEFB 00H 00
4040H, TIMER$: the tick counter, incremented on every clock interrupt by 4583H (40 a second on the Model I). Its bits 2-0 pick the task slot 458AH runs on each tick. FORMAT/CMD, BACKUP/CMD, KI/DVR, SYS2/SYS and SYS12/SYS read it to time delays and key repeats.
4041-4043
DEFS 3
Not in the file: 4041H-4043H, TIME$: seconds, minutes and hours, kept by the clock task at 45BEH and set by the boot time prompt (4FB5H-4FBBH). Not loading them keeps the time running across a reset.
4044
DEFB 00H 00
4044H, DATE$: the year, two digits as a binary number (80-99 for 1980-1999, 0-11 for 2000-2011), stored by the reset at 4F2FH from the year offset in 4466H.
4045
DEFB 00H 00
4045H: the day of the month (1-31), stored by the reset at 4F09H from 4307H.
4046
DEFB 00H 00
4046H: the month (1-12), stored by the reset at 4EF4H. 4D63H (@DATE) displays 4044H-4046H.
4047
DEFB 00H 00
4047H: the day of the year, low 8 bits (1-366), stored by the reset at 4F1FH.
4048
DEFB 00H 00
4048H: bit 0 = bit 8 of the day of the year (4F20H-4F23H), bits 3-1 = the day of the week, 1 for Sunday to 7 for Saturday (4F44H-4F4FH), bit 7 = a leap year (4ECDH-4ED0H). SYS7/SYS (DATE) sets the same bits.
4049-404A
DEFS 2
Not in the file: 4049H-404AH, HIGH$, the highest address free for programs. The reset stores the top of memory it finds here and at 4403H (4E17H-4E1AH); modules that install themselves in high memory (KI/DVR, PR/FLT, FDUBL/CMD, SYS9/SYS ...) lower it.
404B
DEFB 00H 00
404BH, INTIM$: a copy of the interrupt latch (37E0H) the interrupt service routine read last (4518H-4522H): bit 7 the clock, bit 6 the disk controller.
404C
DEFB 00H 00
404CH, INTMSK$: the mask of the interrupt bits that are served (4524H). The reset stores C0H (bits 7 and 6) at 4E7FH-4E82H.
404D-404E
DEFW 4537H 37 45
404DH-404EH, INTVC$, the first of eight vectors, one for each bit of the interrupt latch: bit 0. 4537H is the RET at the end of the interrupt service routine, so an unused bit does nothing.
404F-4050
DEFW 4537H 37 45
404FH-4050H: the vector of interrupt bit 1, 4537H (a RET, not used).
4051-4052
DEFW 4537H 37 45
4051H-4052H: the vector of interrupt bit 2, 4537H (a RET, not used).
4053-4054
DEFW 4537H 37 45
4053H-4054H: the vector of interrupt bit 3, 4537H (a RET, not used).
4055-4056
DEFW 4537H 37 45
4055H-4056H: the vector of interrupt bit 4, 4537H (a RET, not used).
4057-4058
DEFW 4537H 37 45
4057H-4058H: the vector of interrupt bit 5, 4537H (a RET, not used).
4059-405A
DEFW 461CH 1C 46
4059H-405AH: the vector of interrupt bit 6, the disk controller's interrupt request: 461CH, which waits until the controller is not busy, selecting the drive again from 4309H while it waits.
405B-405C
DEFW 456FH 6F 45
405BH-405CH: the vector of interrupt bit 7, the clock: 456FH, which runs the four task slots 08H-0BH, then counts the tick at 4040H and runs one of the slots 00H-07H.

41DEH - The Reset's Return Word

Two bytes at the top of the stack SYS0/SYS's reset sets (Stack Pointer 41DEH at 4E03H). They are the file's last load block.

41DE-41DF
DEFW 0000H 00 00
41DEH-41DFH: 0000H. The reset starts with the Stack Pointer at 41DEH, so a RET with nothing pushed takes this word: the RET NZ at 4E8FH (the system information sector could not be read) goes to 0000H, the ROM's restart. After a boot by sector 0 of BOOT/SYS the boot sector's last CALLs have stored 4277H here (77H 42H) after this block was loaded.

4300H - @KITSK and @ICNFG Hooks

Two three byte hooks, each a RET and two spare bytes in the file. A module that wants to be called puts a JP there (C3H and an address). The keyboard drivers call @KITSK (4300H) on every key request (KI/DVR 52C5H, 549FH; BASIC/CMD 5C60H; BASIC/OV2 5621H) and SYS6/SYS installs and removes its own jump there; SYS0/SYS's reset calls @ICNFG (4303H) after a configuration file has been loaded (5073H), and SYS6/SYS writes it.

4300
RET C9
@KITSK: RETurn at once. While this byte is C9H nothing is hooked to the keyboard; SYS6/SYS stores C3H here and an address at 4301H-4302H (its 5555H, 54FCH) to have its keyboard task run, and puts C9H back.
4301-4302
DEFB 00H x 2 00 x 2
4301H-4302H: the address of the @KITSK jump, 0000H while 4300H holds the RET. SYS6/SYS reads and writes it (its 5456H, 54FCH, 555DH).
4303
RET C9
@ICNFG: RETurn at once. SYS0/SYS's reset calls it after it has loaded CONFIG/SYS (5073H); a configuration that needs to run code at boot leaves a jump here (SYS6/SYS stores into 4303H, its 530AH).
4304-4305
DEFB 00H x 2 00 x 2
4304H-4305H: the address of the @ICNFG jump, 0000H while 4303H holds the RET.
4306-4307
DEFS 2
Not in the file, so a reset keeps them: 4306H, SVDAT1$, the month of the system date OR 50H once a date is set (4EEBH-4EEFH; SYS7/SYS DATE 52ABH, 535FH), and 4307H, SVDAT2$, the day (4EE4H). The reset skips the date prompt when 4306H holds 51H-5CH (a month OR 50H), and the date and the time prompts when it holds 50H (4E9DH-4EA7H).
4308
DEFB FFH FF
4308H, LDRV$: the drive number of the last disk primitive call (4779H-477CH store Register C here); 4750H selects it again. FFH: no drive yet. BACKUP/CMD stores into it (its 547AH).
4309
DEFB FFH FF
4309H, PDRV$: the last value written to the drive select latch 37E1H (45F0H), which 461CH writes again while it waits so the drive stays selected. FFH in the file.
430A-430B
DEFB 00H x 2 00 x 2
430AH-430BH, JDCB$: the address of the file or device control block of the current call, stored by the common file prologue (49F9H). SYS4/SYS reads it to name the file in an error message (its 4F6BH).
430C-430D
DEFB 00H x 2 00 x 2
430CH-430DH, JRET$: the return address of the program's call into the file system (49F6H), the address SYS4/SYS reports in REFERENCED AT (its 4FFAH). FORMAT/CMD, SYS6/SYS and SYS7/SYS point Register Pair HL at 430DH.
430E
DEFB 00H 00
430EH, OVRLY$: the request code of the system file now in the overlay area at 4E00H (00H: none). The overlay loader compares and stores it (4C03H-4C0AH); 4A92H and 4BE1H read it; BASIC/CMD and BASIC/OV3 store into it.
430F
DEFB 00H 00
430FH, SFLAG$, the system flags. Bit 1 run the program without DEBUG (4C6EH), bit 2 a program load by @RUN is in progress (4C62H), bit 3 FAST (the reset doubles the drive motor wait and sets bit 0 of port FEH, 4399H, 5061H), bit 4 BREAK disabled (455BH; the reset clears it, or sets it for an AUTO command that starts with 2AH), bit 5 a JCL job runs, bit 7 DEBUG is on (4C71H); the others are used by the overlays and programs (SYS5/SYS, SYS6/SYS, SYS7/SYS, BASIC/CMD).
4310-4311
DEFW 4876H 76 48
4310H-4311H: the address SYS5/SYS (DEBUG) calls for a command it does not know (its 4E95H): 4876H (OR A / RET), which returns at once with the flags set from Register A. SYS9/SYS stores the address of its extended DEBUG commands here and checks that 4876H is still there before it installs them (its 4E00H-4E22H); SYS6/SYS and SYS7/SYS put 4876H back.
4312-4314
DEFB 00H x 3 00 x 3
4312H-4314H: three bytes of 00H. No code of SYS0/SYS addresses them.
4315
DEFB C9H C9
4315H: the BREAK trap switch. C9H (RET) means off, as does any value but C3H (SYS1/SYS stores 00H, its 4E3BH and 4EA9H); a program that wants BREAK to stop it stores C3H (JP) here and the address at 4316H (BASIC/CMD, SYS1/SYS, SYS5/SYS, SYS6/SYS, SYS7/SYS). When the interrupt service routine sees BREAK while 4315H holds C3H and bit 4 of 430FH is clear, it stores 00H here and goes to the address at 4316H instead of returning (455FH-456EH). The supervisor dispatcher keeps it off while an overlay runs (4BD3H, 4BEAH).
4316-4317
DEFW 44B4H B4 44
4316H-4317H: the address the BREAK trap goes to, 44B4H (enter DEBUG) in the file. SYS5/SYS and SYS7/SYS store other addresses (their 4F9BH, 5221H).
4318-431A
DEFS 3
Not in the file: 4318H-431AH, the first bytes of INBUF$, the 64 byte command line buffer (4318H-4357H: SYS1/SYS reads up to 63 characters into it and stores 03H at 4357H, its 4E16H-4E20H and 4E4FH). During the reset the date and time parser stores its three fields here, the last field typed at 4318H (4349H-4371H); then the reset copies the AUTO command into 4318H-4337H (5030H-5037H), and SYS1/SYS takes command lines from here. Until the first command, 4338H-4357H hold the CONFIG/SYS file specification and the end of the date parser.

431BH - Boot Prompt: Display, Input, Parse

Used only by the reset (4EB2H for the date, 4FA2H for the time); once the reset has finished, 431BH-4337H is part of INBUF$ and the AUTO command is copied over it. Register Pair HL gives the screen address of the prompt, Register Pair DE the prompt text, Register B the most characters to accept and Register C the limit for a separator (any character below it ends a field). Returns with the CARRY FLAG set when three fields of two digits were read, the fields stored at 431AH, 4319H and 4318H.

431B
LD (4020H),HL 22 20 40
Store Register Pair HL (the screen address of the prompt, 3F17H or 3F57H) at 4020H-4021H, the cursor position of the video's device control block: the prompt is displayed there.
431E
EX DE,HL EB
Exchange Register Pairs DE and HL: Register Pair HL now points at the prompt text (50B6H or 50BFH), Register Pair DE holds the screen address.
431F
GOSUB to 4467H (@DSPLY) to display the prompt text at Register Pair HL: 1EH (clear to the end of the line), then Date ? or Time ? and a space, ended by 03H.
4322
LD HL,4E00H 21 00 4E
Point Register Pair HL to 4E00H, the input buffer: the start of the reset code, which has already run.
4325
PUSH BC C5
Save Register Pair BC (Register B = the most characters, Register C = the separator limit) to the stack; the ROM's line input changes Register B.
4326
GOSUB to the ROM's line input at 0040H: it shows the cursor, takes up to Register B characters into the buffer at Register Pair HL (4E00H) until ENTER, and returns with Register B = the number of characters typed.
4329
XOR A AF
Set Register A to 00H (XOR A), which also clears the CARRY FLAG.
432A
OR B B0
OR Register B (the number of characters typed) into Register A: the Z FLAG is set when nothing was typed. The CARRY FLAG stays clear.
432B
POP BC C1
Restore Register Pair BC (Register B = the most characters, Register C = the separator limit) from the stack. POP does not change the flags.
432C
RET Z C8
If the Z FLAG is set (nothing was typed), RETurn with the CARRY FLAG clear: no fields.
432D
JUMP to 4349H to parse the line at Register Pair HL (4E00H).
432F
LD A,(HL) 7E
Fetch the next character of the line from Register Pair HL into Register A. 434FH and 435AH call this routine.
4330
INC HL 23
INCrement Register Pair HL past the character just fetched.
4331
SUB 30H D6 30
SUBtract 30H (the character 0) from Register A: a digit becomes its value 0-9.
4333
CP 0AH FE 0A
Compare Register A against 0AH. The CARRY FLAG is set when the character was a digit (0-9); a character below 0 wraps to 0D0H-0FFH and does not set it.
4335
RET C9
RETurn with the CARRY FLAG set and Register A = the digit's value, or the CARRY FLAG clear (not a digit).
4336-4337
DEFS 2
Not in the file: 4336H-4337H, bytes 30 and 31 of INBUF$ (4318H-4357H), the last two bytes of the AUTO command the reset copies there.

4338H - The CONFIG/SYS Filespec

The name the reset passes to @LOAD (4430H) to load the configuration that SYSTEM (SYSGEN) saved (5051H-5056H). After the reset, 4358H-4377H is JFCB$, the JCL file's control block of SYS11/SYS and SYS6/SYS, which overwrites the end of the date parser below.

4338-4347
DEFM "CONFIG/SYS.CCC:0" 43 4F 4E 46 49 47 2F 53 59 53 2E 43 43 43 3A 30
4338H-4347H: the file specification CONFIG/SYS.CCC:0: the file CONFIG/SYS with the password CCC on drive 0. SYS7/SYS's SYSGEN creates the file under this name.
4348
DEFB 03H 03
4348H: 03H, the end of the file specification.

4349H - Parse Three Two Digit Fields

Reads the line at Register Pair HL as three fields of two digits each, separated by any one character below the limit in Register C, and stores them at 431AH, 4319H and 4318H (the first field typed at 431AH). Returns with the CARRY FLAG set when all three were read. A field that is not two digits, a separator not below Register C, or ENTER before the third field returns with the CARRY FLAG clear (the fields read so far are stored). 4358H-4377H is reused as JFCB$ after the reset.

4349
LD DE,431AH 11 1A 43
Point Register Pair DE to 431AH, where the first field goes.
434C
LD B,03H 06 03
Load Register B with 03H, the number of fields.
434E
PUSH DE D5
Save Register Pair DE (the address for this field) to the stack: Register E is used for the value below. 4371H loops back here.
434F
GOSUB to 432FH to fetch the next character from Register Pair HL: the CARRY FLAG is set and Register A holds its value if it is a digit.
4352
If the NO CARRY FLAG is set (not a digit), JUMP to 4363H to return with the CARRY FLAG clear.
4354
LD E,A 5F
Copy Register A (the first digit) into Register E.
4355
RLCA 07
Rotate Register A left one bit: Register A = the first digit x 2 (a digit is at most 9, so no bit is lost).
4356
RLCA 07
Rotate Register A left one bit again: Register A = the first digit x 4.
4357
ADD A,E 83
ADD Register E (the first digit) to Register A: Register A = the first digit x 5.
4358
RLCA 07
Rotate Register A left one bit: Register A = the first digit x 10.
4359
LD E,A 5F
Copy Register A (the first digit times 10, the tens) into Register E for the addition below.
435A
GOSUB to 432FH to fetch the next character from Register Pair HL: the second digit.
435D
If the NO CARRY FLAG is set (the second character is not a digit), JUMP to 4363H to return with the CARRY FLAG clear.
435F
ADD A,E 83
ADD Register E (the tens) to Register A (the second digit): Register A = the value of the field, 0-99.
4360
LD E,A 5F
Copy Register A (the field's value) into Register E.
4361
SCF 37
Set the CARRY FLAG: the field is two good digits, the value is in Register E.
4362
LD A,E 7B
Copy Register E (the field's value) into Register A.
4363
POP DE D1
Restore Register Pair DE (the address for this field) from the stack. POP does not change the flags.
4364
RET NC D0
If the NO CARRY FLAG is set (the field was not two digits), RETurn with the CARRY FLAG clear.
4365
LD (DE),A 12
Store Register A (the field's value) at Register Pair DE (431AH, 4319H or 4318H).
4366
DEC B 05
DECrement Register B, the fields still to read.
4367
SCF 37
Set the CARRY FLAG (DEC does not change it, so it is set again for the return below).
4368
RET Z C8
If the Z FLAG is set (Register B reached 0: all three fields are stored), RETurn with the CARRY FLAG set.
4369
DEC DE 1B
DECrement Register Pair DE: the next field goes one byte lower.
436A
LD A,(HL) 7E
Fetch the character after the field from Register Pair HL into Register A: the separator.
436B
INC HL 23
INCrement Register Pair HL past the separator.
436C
CP C B9
Compare Register A (the separator) against Register C (the limit: 30H for the date, so any character below 0, or 3BH for the time). The NO CARRY FLAG is set when the separator is not below the limit.
436D
RET NC D0
If the NO CARRY FLAG is set (the separator in Register A is not below Register C), RETurn with the CARRY FLAG clear.
436E
CP 0DH FE 0D
Compare Register A (the separator) against 0DH, ENTER. The Z FLAG is set (and the CARRY FLAG cleared) when the line ends here.
4370
RET Z C8
If the Z FLAG is set (the line ended before the third field), RETurn with the CARRY FLAG clear.
4371
JUMP back to 434EH to read the next field at Register Pair HL into the next byte down.
4373-4377
DEFS 5
Not in the file: 4373H-4377H, the last bytes of JFCB$ (4358H-4377H).

4378H - The Video Driver for Lower Case

SYS0/SYS's reset puts 4378H into the video's device control block (401EH) when video memory keeps bit 6 (lower case is fitted). It is the start of the ROM's video driver (0458H-046FH) with one change: for a character 20H-7FH it jumps straight to the ROM's 047DH, passing over the ROM's 0471H-047CH, which folds the codes 60H-7FH into upper case. Entered as a driver: Register Pair IX = the device control block (401DH), Register C = the character, the CARRY FLAG set for a request to read the character at the cursor.

4378
LD L,(IX+03H) DD 6E 03
Load Register L with byte +03H of the device control block at Index Register IX (4020H): the low byte of the cursor position.
437B
LD H,(IX+04H) DD 66 04
Load Register H with byte +04H of the device control block at Index Register IX (4021H): the high byte. Register Pair HL = the cursor's address in video memory.
437E
If the CARRY FLAG is set (the caller asks for the character at the cursor), JUMP to the ROM at 049AH, which returns it in Register A.
4381
LD A,(IX+05H) DD 7E 05
Fetch byte +05H of the device control block at Index Register IX (4022H) into Register A: the character under the cursor, 00H when the cursor is off.
4384
OR A B7
Set the flags from Register A (OR A): the Z FLAG is set when the cursor is off.
4385
If the Z FLAG is set (no cursor on the screen), JUMP to 4388H.
4387
LD (HL),A 77
Store Register A (the character the cursor hides) back at the cursor's address in Register Pair HL, taking the cursor off the screen.
4388
LD A,C 79
Copy Register C (the character to display) into Register A.
4389
CP 20H FE 20
Compare Register A (the character) against 20H. The CARRY FLAG is set for a control code (00H-1FH).
438B
If the CARRY FLAG is set (a control code), JUMP to the ROM's control code handler at 0506H.
438E
CP 80H FE 80
Compare Register A (the character) against 80H. The NO CARRY FLAG is set for a graphics character or a space compression code (80H-FFH).
4390
If the NO CARRY FLAG is set (Register A is 80H or more), JUMP to the ROM at 04A6H, which handles graphics and space compression codes.
4393
JUMP to the ROM at 047DH to put the character (20H-7FH, lower case kept) on the screen and move the cursor.
4396
LD A,9EH 3E 9E
Load Register A with 9EH, the request code of SYS12/SYS's function 10H (@RAMDIR, a directory into memory). No code in the LDOS files on this diskette calls 4396H.
4398
RST 28H EF
RST 28H: call the supervisor dispatcher with the request code in Register A (9EH). If it returns, execution goes on into 4399H.

4399H - Wait for the Drive Motor

Reached by the JP 4399H at 45F8H when the controller reported the drive NOT READY (bit 7 of its status, which 461CH leaves in Register A) just before the drive was selected, so the motor was off. It calls the ROM's delay at 0060H with Register B = 7FH (about half a second at the normal clock speed) once, twice when bit 2 of byte +03H of the drive's code table is clear, and twice as often again when bit 3 of SFLAG$ (430FH, FAST) is set. Register Pair BC is kept.

4399
LD A,(430FH) 3A 0F 43
Fetch SFLAG$, the system flags, from 430FH into Register A to test the FAST bit.
439C
BIT 3,A CB 5F
Test bit 3 of Register A (FAST, the faster clock). The NZ FLAG is set when it is on.
439E
If the NZ FLAG is set (FAST), GOSUB to 43A1H for an extra round of the waits below; then the code falls into 43A1H for the normal round.
43A1
BIT 2,(IY+03H) FD CB 03 56
Test bit 2 of byte +03H of the drive code table at Index Register IY. The Z FLAG is set when the bit is clear.
43A5
If the Z FLAG is set (bit 2 of byte +03H at Index Register IY clear), GOSUB to 43A8H for one more wait; then the code falls into 43A8H for the last wait.
43A8
PUSH BC C5
Save Register Pair BC to the stack: the ROM's delay counts Register Pair BC down.
43A9
LD B,7FH 06 7F
Load Register B with 7FH: the ROM's delay at 0060H counts Register Pair BC (7FxxH) down to 0.
43AB
GOSUB to the ROM's delay at 0060H, which decrements Register Pair BC until it is 0.
43AE
POP BC C1
Restore the caller's Register Pair BC (saved at 43A8H) from the stack.
43AF
RET C9
RETurn to the caller (43A1H, 43A5H, or the caller of 45E0H).
43B0-43B7
DEFS 8
Not in the file: 43B0H-43B7H. No code of the LDOS files on this diskette addresses these bytes.
43B8-43B9
DEFS 2
Not in the file: 43B8H-43B9H, KISV$, the keyboard driver address saved by the reset from 4016H (4E25H-4E28H). SYS6/SYS reads it (its 5205H).
43BA-43BB
DEFS 2
Not in the file: 43BAH-43BBH, DOSV$, the video driver address saved by the reset (4E3EH): 0458H, or 4378H on a computer with lower case. SYS6/SYS reads it (its 520BH).
43BC-43BD
DEFS 2
Not in the file: 43BCH-43BDH, PRSV$, the printer driver address saved by the reset from 4026H (4E41H-4E44H). PR/FLT and SYS6/SYS read it.
43BE-43BF
DEFS 2
Not in the file: 43BEH-43BFH, KIJCL$, where SYS11/SYS (JCL) and KI/DVR keep the keyboard driver address they replaced.

43C0H - Device Control Blocks of JL, SI and SO

Three more device control blocks in the same layout as 4015H: the job log (JL), the standard input (SI) and the standard output (SO). Type 08H with no driver: a request to them returns at once (44D7H-44DEH) until SET, ROUTE or LINK (SYS6/SYS) assigns them.

43C0
DEFB 08H 08
43C0H, JLDCB$, the job log's device control block, +00H: 08H, the type of a device with nothing assigned (bit 3).
43C1-43C5
DEFB 00H x 5 00 x 5
43C1H-43C5H, JLDCB$ +01H-+05H: no driver address and no driver bytes yet.
43C6-43C7
DEFM "JL" 4A 4C
43C6H-43C7H, JLDCB$ +06H-+07H: the device name JL.
43C8
DEFB 08H 08
43C8H, SIDCB$, the standard input's device control block, +00H: 08H, nothing assigned.
43C9-43CD
DEFB 00H x 5 00 x 5
43C9H-43CDH, SIDCB$ +01H-+05H: no driver address and no driver bytes yet.
43CE-43CF
DEFM "SI" 53 49
43CEH-43CFH, SIDCB$ +06H-+07H: the device name SI.
43D0
DEFB 08H 08
43D0H, SODCB$, the standard output's device control block, +00H: 08H, nothing assigned.
43D1-43D5
DEFB 00H x 5 00 x 5
43D1H-43D5H, SODCB$ +01H-+05H: no driver address and no driver bytes yet.
43D6-43D7
DEFM "SO" 53 4F
43D6H-43D7H, SODCB$ +06H-+07H: the device name SO.
43D8-43FF
DEFS 40
Not in the file: 43D8H-43FFH, five spare device control blocks (S1DCB$-S5DCB$, eight bytes each). The reset fills them with 00H (4E47H-4E4DH); SET and ROUTE (SYS6/SYS) create user devices in them.

4400H - The Supervisor Call Vectors

The fixed entry points of the system, the same address for every program: each is either a JP to a routine of SYS0/SYS or a request stub, LD A with a request code and RST 28H. A request code names a system file in its low four bits (the file number plus 2: 3 for SYS1/SYS up to 0EH for SYS12/SYS) and a function of that file in bits 6-4. Programs CALL these addresses; the supervisor dispatcher (4BCDH) drops the return address the RST pushes, so the overlay's RET goes straight back to the program. That is why a stub needs no RET, and why the byte after some stubs is free: SYS0/SYS keeps variables there (4403H, 4423H, 4427H, 442BH, 442FH, 441FH, 4466H).

4400
LD A,93H 3E 93
@CMD (also called @CMNDR): Load Register A with 93H, the request code of SYS1/SYS's function 10H, the LDOS READY command loop: display LDOS READY and take the next command.
4402
RST 28H EF
RST 28H: call the supervisor dispatcher (400CH, 4BCDH) with the request code in Register A (93H). SYS1/SYS does not return.
4403-4404
DEFS 2
Not in the file: 4403H-4404H, the top of memory found by the reset (4E1AH), kept apart from HIGH$ (4049H) so that a module chain in high memory can be found: SYS10/SYS walks the chain only when HIGH$ differs from it (its 4F2CH); SYS6/SYS reads it too.
4405
LD A,B3H 3E B3
@CMNDI: Load Register A with 0B3H, the request code of SYS1/SYS's function 30H: execute the command line at Register Pair HL (ended by 0DH); when the command ends, @EXIT (402DH) runs and LDOS Ready follows (SYS1/SYS pushes 402DH as the command's return address, its 4E58H). SYS0/SYS's reset returns into 4405H to run the AUTO command (5029H-502BH); BASIC/CMD, SYS7/SYS and SYS11/SYS jump here.
4407
RST 28H EF
RST 28H: call the supervisor dispatcher with the request code in Register A (0B3H).
4408
RET Z C8
RETurn if the Z FLAG is set. The RST above does not return here (the dispatcher returns to the program that called 4405H), so this byte is reached only by a jump to 4408H; with the NZ FLAG set it falls into @ERROR.
4409
PUSH AF F5
@ERROR: Save the interrupted program's Register Pair AF to the stack. Register A holds the error number in bits 5-0, bit 6 set for the short message and bit 7 set to return to the caller instead of ending the program. SYS4/SYS takes it back from the stack.
440A
LD A,96H 3E 96
Load Register A with 96H, the request code of SYS4/SYS's function 10H: display the message of the error number pushed above.
440C
RST 28H EF
RST 28H: call the supervisor dispatcher with the request code in Register A (96H). SYS4/SYS either returns to the program that called 4409H (bit 7 of the error byte set) or ends it through @ABORT (4030H); it does not come back to 440DH.
440D
@DEBUG: Jump to 44B4H, which saves Register Pair AF and loads SYS5/SYS, the DEBUG monitor. SYS0/SYS's reset calls 440DH when D (or the DOWN ARROW key) is held at boot (5017H).
4410
@ADTSK: Jump to 45A5H to add a task: Register A = the task slot (0-11) and Register Pair DE = the task's block (its first word is the address of its routine). SYS0/SYS's reset adds the clock at slot 7 (4FBDH-4FC2H).
4413
@RMTSK: Jump to 45A2H to remove the task in slot Register A: its entry in the task table at 4500H gets the empty block 45B2H.
4416
@RPTSK: Jump to 45B4H. A task routine calls it to have its next run start at the instruction after the CALL; the task ends for this tick.
4419
@KLTSK: Jump to 459DH. A task routine calls it to remove itself from the task table; it returns to the routine that ran the task.
441C
LD A,C3H 3E C3
@FSPEC: Load Register A with 0C3H, the request code of SYS1/SYS's function 40H: take a file specification from the text at Register Pair HL into the control block at Register Pair DE.
441E
RST 28H EF
RST 28H: call the supervisor dispatcher with the request code in Register A (0C3H).
441F
DEFB 00H 00
441FH, DFLAG$, the device flags: bit 0 the spooler is installed, bit 1 type ahead, bit 2 the screen print and keyboard macro (JKL) module, bit 3 PR/FLT installed, bit 4 KI/DVR installed (KI/DVR 526FH, PR/FLT 521AH, SYS6/SYS and SYS7/SYS set and test them). 00H at boot.
4420
LD A,A4H 3E A4
@INIT: Load Register A with 0A4H, the request code of SYS2/SYS's function 20H: open the file whose control block is at Register Pair DE, creating it when it does not exist (Register Pair HL = its 256 byte buffer, Register B = the record length, 0 for 256).
4422
RST 28H EF
RST 28H: call the supervisor dispatcher with the request code in Register A (0A4H).
4423
DEFB 20H 20
4423H, KFLAG$, the keyboard flags. The interrupt routine's keyboard scan (4DA6H) sets bit 0 when BREAK is pressed (unless BREAK is disabled), bit 1 when SHIFT and @ are held (pause) and bit 2 when ENTER is held; the keyboard drivers and the programs clear them. Bit 5 is the CAPS lock, set (20H) at boot. Read and changed by BACKUP/CMD, BASIC/CMD, KI/DVR, TED/CMD, SYS6/SYS, SYS7/SYS and SYS11/SYS.
4424
LD A,94H 3E 94
@OPEN: Load Register A with 94H, the request code of SYS2/SYS's function 10H: open the existing file whose control block is at Register Pair DE (Register Pair HL = its buffer, Register B = the record length). @LOAD uses it (4C7CH).
4426
RST 28H EF
RST 28H: call the supervisor dispatcher with the request code in Register A (94H).
4427
DEFB 00H 00
4427H: the last value written to port FEH, the speed control. The reset ORs 01H into it and writes it to the port when bit 3 of 430FH (FAST) is set after the configuration file is loaded (5065H-506EH); SYSTEM (FAST and SLOW, SYS7/SYS 5220H-5231H) changes it.
4428
LD A,95H 3E 95
@CLOSE: Load Register A with 95H, the request code of SYS3/SYS's function 10H: close the file or device whose control block is at Register Pair DE.
442A
RST 28H EF
RST 28H: call the supervisor dispatcher with the request code in Register A (95H).
442B
DEFB 00H 00
442BH: 00H, the spare byte after @CLOSE. No code of the LDOS files on this diskette addresses it.
442C
LD A,9CH 3E 9C
@KILL: Load Register A with 9CH, the request code of SYS10/SYS's function 10H: delete the file whose control block is at Register Pair DE.
442E
RST 28H EF
RST 28H: call the supervisor dispatcher with the request code in Register A (9CH).
442F
DEFB 00H 00
442FH, MFLAG$, the machine flags: bit 0 set by the reset when it was entered with Index Register IY not 0000H, a boot through a disk driver (the Lobo LX-80 interface), which selects the first block of drive tables in the system information sector (4E5EH-4E61H, 4FCEH; SYS6/SYS, SYS7/SYS and FORMAT/CMD read it).
4430
@LOAD: Jump to 4C77H to load the program file named in the control block at Register Pair DE and return its transfer address in Register Pair HL.
4433
@RUN: Jump to 4C5EH to load the program file named at Register Pair DE and run it.
4436
@READ: Jump to 48ADH to read the next record of the file at Register Pair DE (into the record area at Register Pair HL when the record length is not 256).
4439
@WRITE: Jump to 48CBH to write the next record of the file at Register Pair DE.
443C
@VER: Jump to 48E6H to write the next record of the file at Register Pair DE and read it back to check it.
443F
@REW: Jump to 4835H to put the file at Register Pair DE back at its first record.
4442
@POSN: Jump to 47CFH to put the file at Register Pair DE at the record number in Register Pair BC.
4445
@BKSP: Jump to 4816H to move the file at Register Pair DE back one record.
4448
@PEOF: Jump to 483CH to put the file at Register Pair DE at its end, ready to add records.
444B
@CKEOF: Jump to 4A1AH to test whether the file at Register Pair DE is at its end (Register A = 1CH and the NZ FLAG at the end, 1DH beyond it, 00H with the Z FLAG before it).
444E
@WEOF: Jump to 4886H to write the end of file of the file at Register Pair DE into its directory record.
4451
LD A,A3H 3E A3
Load Register A with 0A3H, the request code of SYS1/SYS's function 20H: carry out the command line at Register Pair HL and return to the caller; a line that cannot be carried out returns Register A = 02H with the NZ FLAG (SYS1/SYS 4E29H, 4E97H). SYS6/SYS (its 55A4H) and SYS7/SYS (its 525EH) jump here.
4453
RST 28H EF
RST 28H: call the supervisor dispatcher with the request code in Register A (0A3H).
4454
@RREAD: Jump to 480FH to read the current sector of the file at Register Pair DE again.
4457
@RWRIT: Jump to 499EH to write the file's buffer back to the current sector of the file at Register Pair DE.
445A
@LOC: Jump to 484DH to return in Register Pair BC the current record number of the file at Register Pair DE.
445D
@LOF: Jump to 4878H to return in Register Pair BC the number of records of the file at Register Pair DE.
4460
@SKIP: Jump to 47CBH to pass over the next record of the file at Register Pair DE.
4463
LD A,AEH 3E AE
@DODIR: Load Register A with 0AEH, the request code of SYS12/SYS's function 20H: directory display or directory information of the drive in Register C.
4465
RST 28H EF
RST 28H: call the supervisor dispatcher with the request code in Register A (0AEH).
4466
DEFS 1
Not in the file: 4466H, the year of the system date as an offset from 1980 (0-31, 1980-2011), stored by the reset's date prompt (4EC4H) and by SYS7/SYS's DATE (its 5296H, 5353H); the reset works the leap year and the day of the week from it (4EF8H).
4467
@DSPLY: Jump to 44E3H to display the text at Register Pair HL (ended by 03H, or by 0DH, which is displayed).
446A
@PRINT: Jump to 44F8H to print the text at Register Pair HL (ended by 03H or 0DH).
446D
@TIME: Jump to 4D48H to store the time as HH:MM:SS (8 characters) at Register Pair HL.
4470
@DATE: Jump to 4D63H to store the date as MM/DD/YY (8 characters) at Register Pair HL.
4473
LD A,D3H 3E D3
@FEXT: Load Register A with 0D3H, the request code of SYS1/SYS's function 50H: give the file specification at Register Pair DE the extension at Register Pair HL when it has none.
4475
RST 28H EF
RST 28H: call the supervisor dispatcher with the request code in Register A (0D3H).
4476
LD A,E3H 3E E3
@PARAM: Load Register A with 0E3H, the request code of SYS1/SYS's function 60H: read the parameters at Register Pair HL against the parameter table at Register Pair DE.
4478
RST 28H EF
RST 28H: call the supervisor dispatcher with the request code in Register A (0E3H).
4479
@MSG: JUMP to 44E6H to send the text at Register Pair HL to the device whose control block is at Register Pair DE, until 03H or 0DH. SYS6/SYS calls it (its 5329H, 53C8H).
447B
@LOGOT: GOSUB to 44E3H to display the text at Register Pair HL on the video, then go on into @LOGER below to send it to the job log.
447E
@LOGER: JUMP to 44FDH, a RET: the job log takes nothing until a module points this jump elsewhere. SYS1/SYS, SYS6/SYS and SYS11/SYS call 447EH.
4480-449F
DEFS 32
Not in the file: 4480H-449FH, CFCB$, the 32 byte control block that SYS1/SYS fills for the command being run (its 4E6CH); BASIC/CMD, its overlays, SYS6/SYS and SYS12/SYS use it too.

44A0H - SFCB$, the Control Block for System Files

A 20 byte file control block the overlay loader (4BF5H) uses to read a system file: it stores the directory record number at 44A7H, the flags at 44A1H, a record number of 0 at 44AAH-44ABH and the first two extents of the file at 44AEH-44B3H (47B4H), then loads the file through it (4C3CH). Its buffer is 4200H. The bytes after it (44B4H on) are code, so only the fields up to the second extent exist.

44A0
DEFB 80H 80
44A0H, SFCB$ +00H: 80H, bit 7 set: the block describes an open file, which the file prologue (49F3H) requires.
44A1
DEFB 00H 00
44A1H, SFCB$ +01H: the file flags (bits 2-0 the access granted, bit 5 the buffer must be read first). The overlay loader stores 20H here before every load (4C20H-4C22H): full access and an empty buffer.
44A2
DEFB 00H 00
44A2H, SFCB$ +02H: 00H, not used by SYS0/SYS's file routines.
44A3-44A4
DEFW 4200H 00 42
44A3H-44A4H, SFCB$ +03H-+04H: 4200H, the address of the 256 byte buffer the system file's sectors are read into (the module loader at 4C8DH takes its bytes from 4200H-42FFH).
44A5
DEFB 00H 00
44A5H, SFCB$ +05H: 00H, the position of the next byte in the buffer.
44A6
DEFB 00H 00
44A6H, SFCB$ +06H: 00H, the drive: system files are read from drive 0.
44A7
DEFB 00H 00
44A7H, SFCB$ +07H: the directory record number of the system file, stored by the overlay loader (4C1CH): 3-7 for SYS1/SYS-SYS5/SYS, 20H-26H for SYS6/SYS-SYS12/SYS.
44A8
DEFB 00H 00
44A8H, SFCB$ +08H: 00H, the end of file byte (not used for a system file).
44A9
DEFB 00H 00
44A9H, SFCB$ +09H: 00H, the record length: 256 bytes.
44AA-44AB
DEFB 00H x 2 00 x 2
44AAH-44ABH, SFCB$ +0AH-+0BH: the next record number, set to 0000H before every load (4C25H-4C27H) so the file is read from its start.
44AC-44AD
DEFB FFH x 2 FF x 2
44ACH-44ADH, SFCB$ +0CH-+0DH: FFFFH, the ending record number, as high as it goes, so a system file never reaches its end of file before its last load record.
44AE-44AF
DEFB 00H x 2 00 x 2
44AEH-44AFH, SFCB$ +0EH-+0FH: the first extent of the system file (cylinder, then the first granule in bits 7-5 and the granules less one in bits 4-0), copied from bytes 16H-17H of its directory record by 47B4H.
44B0-44B3
DEFB FFH x 4 FF x 4
44B0H-44B3H, SFCB$ +10H-+13H: the number of granules of the first extent (a word, 47BBH-47C2H) and the second extent (bytes 18H-19H of the directory record, 47C3H). FFH in the file.

44B4H - The DEBUG Launcher and Four More Vectors

44B4H is where RST 30H (400FH), @DEBUG (440DH) and the BREAK trap (4316H) lead. Then four request stubs and the jumps to the arithmetic routines.

44B4
PUSH AF F5
Save Register Pair AF to the stack: SYS5/SYS (DEBUG) shows and restores the program's registers, Register Pair AF first.
44B5
LD A,87H 3E 87
Load Register A with 87H, the request code of SYS5/SYS, the DEBUG monitor.
44B7
RST 28H EF
RST 28H: call the supervisor dispatcher with the request code in Register A (87H).
44B8
LD A,C4H 3E C4
@CKDRV: Load Register A with 0C4H, the request code of SYS2/SYS's function 40H: check that the drive in Register C is ready and has a diskette.
44BA
RST 28H EF
RST 28H: call the supervisor dispatcher with the request code in Register A (0C4H).
44BB
LD A,A5H 3E A5
@FNAME: Load Register A with 0A5H, the request code of SYS3/SYS's function 20H: build the file specification of directory record Register B on drive Register C into the buffer at Register Pair DE.
44BD
RST 28H EF
RST 28H: call the supervisor dispatcher with the request code in Register A (0A5H).
44BE
LD A,CDH 3E CD
@DOKEY: Load Register A with 0CDH, the request code of SYS11/SYS's function 40H: take a key for a JCL job. SYS11/SYS changes the operand at 44BFH to 0DDH while it answers an input request of the job and back to 0CDH (its 50C3H, 50D7H).
44C0
RST 28H EF
RST 28H: call the supervisor dispatcher with the request code in Register A (0CDH or 0DDH).
44C1
@MULT: Jump to 4B8FH to multiply Register Pair HL by Register A (the 24 bit product: Register Pair HL the high 16 bits, Register A the low 8 bits).
44C4
@DIV: Jump to 4BA9H to divide Register Pair HL by Register A (quotient in Register Pair HL, remainder in Register A).

44C7H - @DVRHK: Find the Driver of a Device

The ROM's device routine (03C2H) jumps to 4033H, and so here at 44CAH, when the type of a device control block does not match the request: Index Register IX = the block, Register B = the request (01H input, 02H output, 04H control), Register C = the character, and the ROM's return address 03DDH on the stack. A block of type 10H is linked to another block (its +01H-+02H): the code follows the links. A type above 10H is an open file control block: its byte is read or written by 48ECH. A type with bit 3 set has nothing assigned and returns at once. Any other block's driver is called at its +01H-+02H.

44C7
PUSH HL E5
Save Register Pair HL (the address of the next device control block in the chain) to the stack.
44C8
POP IX DD E1
Restore it into Index Register IX: Index Register IX now points at the next block.
44CA
LD L,(IX+01H) DD 6E 01
Load Register L with byte +01H of the device control block at Index Register IX: the low byte of its driver address, or of the next block's address for a linked block.
44CD
LD H,(IX+02H) DD 66 02
Load Register H with byte +02H of the device control block at Index Register IX: the high byte. Register Pair HL = the driver (or the next block).
44D0
LD A,(IX+00H) DD 7E 00
Fetch byte +00H of the device control block at Index Register IX into Register A: its type.
44D3
CP 10H FE 10
Compare Register A (the type) against 10H, the type of a block linked to another block.
44D5
If the Z FLAG is set (Register A = 10H: a linked block), JUMP to 44C7H to go on to the block at Register Pair HL.
44D7
If the NO CARRY FLAG is set (the type in Register A is above 10H: an open file's control block), JUMP to 48ECH to read or write a byte of the file.
44DA
AND 08H E6 08
Mask Register A (the type) to bit 3, the bit of a device with nothing assigned.
44DC
XOR 08H EE 08
Flip bit 3 of Register A (XOR 08H): the Z FLAG is now set when bit 3 of the type was set.
44DE
RET Z C8
If the Z FLAG is set (nothing is assigned to the device), RETurn at once (to 03DDH in the ROM) with Register A = 00H: an input request gets no character.
44DF
LD A,B 78
Copy Register B (the request: 01H input, 02H output, 04H control) into Register A.
44E0
CP 02H FE 02
Compare Register A (the request) against 02H: the CARRY FLAG is set for input, the Z FLAG for output, neither for control, the flags a driver tests on entry.
44E2
JP (HL) E9
JUMP to the driver at Register Pair HL with Register C = the character and Index Register IX = its device control block.

44E3H - @DSPLY, @PRINT and @MSG: Send a Text to a Device

44E3H sends to the video (401DH), 44F8H to the printer (4025H), 44E6H (@MSG at 4479H) to the device control block in Register Pair DE. The text at Register Pair HL ends with 03H (not sent) or 0DH (sent). Register Pair HL comes back unchanged.

44E3
LD DE,401DH 11 1D 40
Point Register Pair DE to 401DH, DODCB$, the video's device control block.
44E6
PUSH HL E5
Save Register Pair HL (the start of the text) to the stack, to return it unchanged.
44E7
LD A,(HL) 7E
Fetch the next character of the text at Register Pair HL into Register A. 44F4H loops back here.
44E8
CP 03H FE 03
Compare Register A (the character) against 03H, the end of text that is not sent.
44EA
If the Z FLAG is set (Register A = 03H), JUMP to 44F6H to return.
44EC
PUSH AF F5
Save Register Pair AF (the character) to the stack: the ROM's output routine changes Register A.
44ED
GOSUB to the ROM's output routine at 001BH, which sends the character in Register A to the device whose control block is at Register Pair DE.
44F0
POP AF F1
Restore Register Pair AF (the character just sent) from the stack.
44F1
INC HL 23
INCrement Register Pair HL to the next character of the text.
44F2
CP 0DH FE 0D
Compare Register A (the character just sent) against 0DH, ENTER, which ends a line and the text.
44F4
If the NZ FLAG is set (Register A was not 0DH), LOOP BACK to 44E7H for the next character.
44F6
POP HL E1
Restore Register Pair HL (the start of the text) from the stack.
44F7
RET C9
RETurn to the caller with Register Pair HL at the start of the text.
44F8
LD DE,4025H 11 25 40
@PRINT: Point Register Pair DE to 4025H, PRDCB$, the printer's device control block.
44FB
JUMP to 44E6H to send the text at Register Pair HL to the printer.
44FD
RET C9
RETurn. @LOGER (447EH) jumps here, so the job log does nothing until it is pointed elsewhere.
44FE-44FF
DEFB 00H x 2 00 x 2
44FEH-44FFH: two bytes of 00H. No code of SYS0/SYS addresses them.

4500H - TCB$, the Task Table

Twelve words, one for each task slot 0-11: the address of the task's block, whose first word is the address of the task's routine (the routine finds its block in Index Register IX and may keep its own bytes after that word). The clock interrupt runs slots 8-11 on every tick (40 a second) and one of slots 0-7 in turn, so each of those runs 5 times a second (456FH-458AH). @ADTSK, @RMTSK, @RPTSK and @KLTSK (4410H-4419H) change the entries. In the file every slot holds 45B2H, the empty block.

4500-4501
DEFW 45B2H B2 45
4500H-4501H: the entry of task slot 0 (run on every eighth tick, when bits 2-0 of TIMER$ (4040H) equal 0): 45B2H, the empty block, whose routine is the RET at 45B1H.
4502-4503
DEFW 45B2H B2 45
4502H-4503H: the entry of task slot 1 (run on every eighth tick, when bits 2-0 of TIMER$ (4040H) equal 1): 45B2H, the empty block, whose routine is the RET at 45B1H.
4504-4505
DEFW 45B2H B2 45
4504H-4505H: the entry of task slot 2 (run on every eighth tick, when bits 2-0 of TIMER$ (4040H) equal 2): 45B2H, the empty block, whose routine is the RET at 45B1H.
4506-4507
DEFW 45B2H B2 45
4506H-4507H: the entry of task slot 3 (run on every eighth tick, when bits 2-0 of TIMER$ (4040H) equal 3): 45B2H, the empty block, whose routine is the RET at 45B1H.
4508-4509
DEFW 45B2H B2 45
4508H-4509H: the entry of task slot 4 (run on every eighth tick, when bits 2-0 of TIMER$ (4040H) equal 4): 45B2H, the empty block, whose routine is the RET at 45B1H.
450A-450B
DEFW 45B2H B2 45
450AH-450BH: the entry of task slot 5 (run on every eighth tick, when bits 2-0 of TIMER$ (4040H) equal 5): 45B2H, the empty block, whose routine is the RET at 45B1H.
450C-450D
DEFW 45B2H B2 45
450CH-450DH: the entry of task slot 6 (run on every eighth tick, when bits 2-0 of TIMER$ (4040H) equal 6): 45B2H, the empty block, whose routine is the RET at 45B1H. SYS7/SYS puts the clock display 4D3AH here and takes it out again (its 532AH-5334H).
450E-450F
DEFW 45B2H B2 45
450EH-450FH: the entry of task slot 7 (run on every eighth tick, when bits 2-0 of TIMER$ (4040H) equal 7): 45B2H, the empty block, whose routine is the RET at 45B1H. SYS0/SYS's reset puts the clock's block 45BEH here (4FBDH-4FC2H).
4510-4511
DEFW 45B2H B2 45
4510H-4511H: the entry of task slot 8 (run on every tick): 45B2H, the empty block, whose routine is the RET at 45B1H.
4512-4513
DEFW 45B2H B2 45
4512H-4513H: the entry of task slot 9 (run on every tick): 45B2H, the empty block, whose routine is the RET at 45B1H.
4514-4515
DEFW 45B2H B2 45
4514H-4515H: the entry of task slot 10 (run on every tick): 45B2H, the empty block, whose routine is the RET at 45B1H.
4516-4517
DEFW 45B2H B2 45
4516H-4517H: the entry of task slot 11 (run on every tick): 45B2H, the empty block, whose routine is the RET at 45B1H. SYS7/SYS puts the program counter display 4D6AH here and takes it out again (its 53A7H-53B1H).

4518H - The Interrupt Service Routine

ROM 0038H (RST 38H in interrupt mode 1) jumps to 4012H and so here. It reads the expansion interface's interrupt latch at 37E0H (bit 7 the 25 millisecond clock, bit 6 the disk controller), keeps a copy at 404BH, and for every bit that is also set in the mask at 404CH calls the routine whose address is in that bit's vector at 404DH-405CH. Then it scans the keyboard for BREAK, SHIFT @ and ENTER (4DA6H): SHIFT BREAK selects the drive of the last disk call again, BREAK alone springs the BREAK trap at 4315H. Registers are kept.

4518
PUSH HL E5
Save the interrupted program's Register Pair HL to the stack.
4519
PUSH AF F5
Save the interrupted program's Register Pair AF to the stack.
451A
LD HL,37E0H 21 E0 37
Point Register Pair HL to 37E0H, the interrupt latch of the expansion interface.
451D
LD A,(HL) 7E
Fetch the interrupt latch at Register Pair HL (37E0H) into Register A.
451E
OR (HL) B6
OR the latch at Register Pair HL (37E0H), read a second time, into Register A, so a request that arrives between the two reads is not lost. Register A now holds the interrupt bits: bit 7 the clock, bit 6 the disk controller.
451F
LD HL,404BH 21 4B 40
Point Register Pair HL to 404BH, INTIM$, the copy of the interrupt bits.
4522
LD (HL),A 77
Store Register A (the interrupt bits) at Register Pair HL (404BH, INTIM$) for any routine that wants to know what caused the interrupt.
4523
INC L 2C
INCrement Register L: Register Pair HL now points at 404CH, INTMSK$.
4524
AND (HL) A6
Mask Register A (the interrupt bits) with INTMSK$ at Register Pair HL (404CH, C0H after the reset). The Z FLAG is set when no served interrupt is pending.
4525
If the Z FLAG is set (no bit of Register A to serve), JUMP to 452FH for the keyboard scan.
4527
INC L 2C
INCrement Register L: Register Pair HL points at the low byte of the next vector (404DH for bit 0 the first time). 452BH-452DH loop back here.
4528
RRA 1F
Rotate Register A (the interrupt bits still to look at) right through the CARRY FLAG: the lowest bit goes into the CARRY FLAG.
4529
If the CARRY FLAG is set (this bit's interrupt is pending), JUMP to 4538H to call its vector at Register Pair HL.
452B
INC L 2C
INCrement Register L past the high byte of the vector. 454DH comes back here after a vector's routine.
452C
OR A B7
Set the flags from Register A (OR A): the Z FLAG is set when no higher interrupt bit is left.
452D
If the NZ FLAG is set (bits remain in Register A), LOOP BACK to 4527H for the next vector.
452F
GOSUB to 4DA6H to scan the keyboard for BREAK, SHIFT @ and ENTER. On return the NZ FLAG is set when BREAK is held and the CARRY FLAG when a SHIFT key is held.
4532
If the NZ FLAG is set (BREAK is held), JUMP to 454FH.
4534
POP AF F1
Restore Register Pair AF from the stack. 4556H and the BREAK tests come back here.
4535
POP HL E1
Restore the interrupted program's Register Pair HL from the stack.
4536
EI FB
Enable interrupts again (the ROM's RST 38H entry left them off).
4537
RET C9
RETurn to the interrupted program. The vectors of the unused interrupt bits (404DH-4058H) point at this RET.
4538
PUSH AF F5
Save Register Pair AF (Register A = the interrupt bits still to look at) to the stack.
4539
PUSH BC C5
Save the interrupted program's Register Pair BC to the stack.
453A
PUSH DE D5
Save the interrupted program's Register Pair DE to the stack.
453B
PUSH HL E5
Save Register Pair HL (the address of the vector's low byte) to the stack.
453C
PUSH IX DD E5
Save Index Register IX to the stack: the task routines use it.
453E
LD DE,4547H 11 47 45
Load Register Pair DE with 4547H, the address the vector's routine returns to.
4541
PUSH DE D5
Save Register Pair DE (4547H) to the stack as the routine's return address.
4542
LD E,(HL) 5E
Fetch the low byte of the vector at Register Pair HL into Register E.
4543
INC L 2C
INCrement Register L to the vector's high byte.
4544
LD D,(HL) 56
Fetch the high byte of the vector at Register Pair HL into Register D. Register Pair DE = the routine (461CH for the disk controller, 456FH for the clock).
4545
EX DE,HL EB
Exchange Register Pairs DE and HL: Register Pair HL = the routine's address.
4546
JP (HL) E9
JUMP to the routine at Register Pair HL; its RET comes back to 4547H.
4547
POP IX DD E1
Restore the interrupted program's Index Register IX from the stack.
4549
POP HL E1
Restore Register Pair HL (the vector's low byte address) from the stack.
454A
POP DE D1
Restore the interrupted program's Register Pair DE from the stack.
454B
POP BC C1
Restore the interrupted program's Register Pair BC from the stack.
454C
POP AF F1
Restore Register Pair AF (Register A = the interrupt bits still to look at) from the stack.
454D
JUMP to 452BH to go on with the next vector and the interrupt bits left in Register A.
454F
BREAK is held. If the NO CARRY FLAG is set (no SHIFT key with it), JUMP to 4558H for the BREAK trap.
4551
PUSH BC C5
SHIFT BREAK: Save Register Pair BC to the stack.
4552
GOSUB to 4750H, which takes the drive of the last disk call from 4308H (LDRV$) and calls its driver with function 01H, selecting the drive again.
4555
POP BC C1
Restore the interrupted program's Register Pair BC from the stack.
4556
JUMP to 4534H to restore Register Pairs AF and HL and return from the interrupt.
4558
LD A,(430FH) 3A 0F 43
Fetch SFLAG$, the system flags, from 430FH into Register A to test BREAK disabled.
455B
BIT 4,A CB 67
Test bit 4 of Register A (SFLAG$): BREAK disabled when it is set.
455D
If the NZ FLAG is set (BREAK is disabled), JUMP to 4534H to return from the interrupt.
455F
LD HL,4315H 21 15 43
Point Register Pair HL to 4315H, the BREAK trap switch.
4562
LD A,C3H 3E C3
Load Register A with C3H, the value of the switch when the trap is on.
4564
SUB (HL) 96
SUBtract the switch at Register Pair HL (4315H) from Register A: Register A = 00H and the Z FLAG set when the switch holds C3H.
4565
If the NZ FLAG is set (the trap is off), JUMP to 4534H to return from the interrupt.
4567
LD (HL),A 77
Store Register A (00H) at Register Pair HL (4315H): the trap is used once and is now off.
4568
LD HL,(4316H) 2A 16 43
Fetch the trap address from 4316H-4317H into Register Pair HL (44B4H, DEBUG, unless a program set its own).
456B
POP AF F1
Restore Register Pair AF from the stack: the interrupted program's Register Pair AF.
456C
EX (SP),HL E3
Exchange Register Pair HL with the top of the stack (the Stack Pointer is not changed): the interrupted program's Register Pair HL comes back and the trap address takes its place on the stack, above the interrupted program's return address.
456D
EI FB
Enable interrupts again before going to the trap address.
456E
RET C9
RETurn to the trap address: the program is left at its interrupted address, which stays on the stack.

456FH - The Clock Interrupt: Run the Tasks

The vector of interrupt bit 7 (405BH), 40 times a second. It runs the tasks of slots 8, 9, 10 and 11, counts the tick in TIMER$ (4040H) and runs the task of slot 0-7 that bits 2-0 of the count select.

456F
LD A,08H 3E 08
Load Register A with 08H, the number of task slot 8, run on every tick.
4571
GOSUB to 458AH to run the task in the slot in Register A (8).
4574
LD A,09H 3E 09
Load Register A with 09H, the number of task slot 9, run on every tick.
4576
GOSUB to 458AH to run the task in the slot in Register A (9).
4579
LD A,0AH 3E 0A
Load Register A with 0AH, the number of task slot 10, run on every tick.
457B
GOSUB to 458AH to run the task in the slot in Register A (10).
457E
LD A,0BH 3E 0B
Load Register A with 0BH, the number of task slot 11, run on every tick.
4580
GOSUB to 458AH to run the task in the slot in Register A (11).
4583
LD HL,4040H 21 40 40
Point Register Pair HL to 4040H, TIMER$, the tick counter.
4586
INC (HL) 34
INCrement the tick counter at Register Pair HL (4040H).
4587
LD A,(HL) 7E
Fetch the new count from Register Pair HL (4040H) into Register A.
4588
AND 07H E6 07
Mask Register A to bits 2-0: the slot (0-7) whose task runs on this tick. The code falls into 458AH, whose RET returns to the interrupt routine.

458AH - Run the Task in Slot A

Register A = the slot (0-11). Points Index Register IX at the slot's task block and jumps to the routine whose address is the block's first word. The address of the slot's table entry is kept in the operand at 45B5H for @RPTSK and @KLTSK.

458A
RLCA 07
Rotate Register A (the slot number, at most 0BH) left one bit: Register A = the slot x 2, the offset of its word in the task table.
458B
LD L,A 6F
Copy Register A (the offset) into Register L.
458C
LD H,45H 26 45
Load Register H with 45H. Register Pair HL = 4500H + the slot x 2, the slot's entry in TCB$.
458E
LD (45B5H),HL 22 B5 45
Store Register Pair HL (the entry's address) into 45B5H-45B6H, the operand of the LD HL at 45B4H, so that @RPTSK and @KLTSK know which slot is running.
4591
LD E,(HL) 5E
Fetch the low byte of the task's block address from the entry at Register Pair HL into Register E.
4592
INC L 2C
INCrement Register L to the high byte of the entry.
4593
LD D,(HL) 56
Fetch the high byte from Register Pair HL into Register D. Register Pair DE = the task's block.
4594
PUSH DE D5
Save Register Pair DE (the task's block) to the stack.
4595
POP IX DD E1
Restore it into Index Register IX: the task routine finds its block in Index Register IX.
4597
EX DE,HL EB
Exchange Register Pairs DE and HL: Register Pair HL = the task's block.
4598
LD E,(HL) 5E
Fetch the low byte of the routine's address (the block's first word) at Register Pair HL into Register E.
4599
INC HL 23
INCrement Register Pair HL to the high byte of the routine's address.
459A
LD D,(HL) 56
Fetch the high byte from Register Pair HL into Register D. Register Pair DE = the task's routine.
459B
EX DE,HL EB
Exchange Register Pairs DE and HL: Register Pair HL = the routine.
459C
JP (HL) E9
JUMP to the task routine at Register Pair HL, with Index Register IX = its block. Its RET returns to the caller of 458AH.

459DH - @KLTSK, @RMTSK and @ADTSK

459DH (@KLTSK) is called by a running task to remove itself; 45A2H (@RMTSK) removes the task in slot Register A; 45A5H (@ADTSK) puts the block at Register Pair DE into slot Register A. Interrupts are off while the two bytes of an entry change. A slot number of 12 or more is ignored.

459D
POP DE D1
@KLTSK: Discard the return address into the task routine (POP into Register Pair DE): the RET below goes back to the routine that ran the task.
459E
LD A,(45B5H) 3A B5 45
Fetch the low byte of the running slot's entry address from 45B5H into Register A: 00H-16H, the slot x 2.
45A1
RRCA 0F
Rotate Register A right one bit: Register A = the running task's slot number. The code goes on into @RMTSK.
45A2
LD DE,45B2H 11 B2 45
@RMTSK: Point Register Pair DE to 45B2H, the empty task block.
45A5
CP 0CH FE 0C
@ADTSK: Compare Register A (the slot) against 0CH. The NO CARRY FLAG is set for a slot of 12 or more.
45A7
RET NC D0
If the NO CARRY FLAG is set (no such slot), RETurn without a change.
45A8
RLCA 07
Rotate Register A (the slot) left one bit: Register A = the slot x 2.
45A9
LD L,A 6F
Copy Register A (the slot x 2) into Register L, the low byte of the entry's address.
45AA
LD H,45H 26 45
Load Register H with 45H. Register Pair HL = 4500H + the slot x 2, the slot's entry in TCB$.
45AC
DI F3
Disable interrupts, so the clock does not run the slot while its entry is half written. 45BCH joins here.
45AD
LD (HL),E 73
Store Register E (the low byte of the block's address) into the entry at Register Pair HL.
45AE
INC L 2C
INCrement Register L to the entry's high byte.
45AF
LD (HL),D 72
Store Register D (the high byte of the block's address) into the entry at Register Pair HL.
45B0
EI FB
Enable interrupts again: the entry is complete.
45B1
RET C9
RETurn to the caller with Register A = 00H: the command was issued. The empty task block 45B2H names this RET as its routine.
45B2-45B3
DEFW 45B1H B1 45
45B2H-45B3H: the empty task block. Its first word is 45B1H, the RET above, so a free slot does nothing.
45B4
LD HL,0000H 21 00 00
@RPTSK: Load Register Pair HL with the address of the running slot's entry in TCB$. The operand at 45B5H-45B6H is 0000H in the file; 458EH stores the entry's address there before every task runs.
45B7
LD E,(HL) 5E
Fetch the low byte of the running task's block address from the entry at Register Pair HL into Register E.
45B8
INC HL 23
INCrement Register Pair HL to the entry's high byte.
45B9
LD D,(HL) 56
Fetch the high byte from Register Pair HL into Register D. Register Pair DE = the running task's block.
45BA
EX DE,HL EB
Exchange Register Pairs DE and HL: Register Pair HL = the task's block, whose first word is the address of its routine.
45BB
POP DE D1
Restore the return address into the task routine (the address after its CALL 4416H) from the stack into Register Pair DE.
45BC
JUMP to 45ACH to store Register Pair DE as the block's first word: the next time the slot runs, the routine continues after its CALL. The RET at 45B1H returns to the routine that ran the task.

45BEH - The Clock Task

The task block SYS0/SYS's reset puts into slot 7 (4FBDH-4FC2H): run 5 times a second, it counts 5 calls and then adds one second to TIME$ (4041H-4043H), carrying into the minutes and hours.

45BE-45BF
DEFW 45C1H C1 45
45BEH-45BFH: the block's first word: 45C1H, its routine.
45C0
DEFB 05H 05
45C0H, the block's byte +02H: the count of calls left before the next second, 05H. The routine counts it down through Index Register IX.
45C1
DEC (IX+02H) DD 35 02
DECrement byte +02H of the task block at Index Register IX (45C0H), the calls left before the next second.
45C4
RET NZ C0
If the NZ FLAG is set (the count has not reached 0), RETurn: not a full second yet.
45C5
LD (IX+02H),05H DD 36 02 05
Store 05H into byte +02H of the task block at Index Register IX (45C0H): the next second is 5 calls away.
45C9
LD B,03H 06 03
Load Register B with 03H: seconds, minutes and hours.
45CB
LD HL,4041H 21 41 40
Point Register Pair HL to 4041H, the seconds of TIME$.
45CE
LD DE,45DDH 11 DD 45
Point Register Pair DE to 45DDH, the table of the limits: 60 seconds, 60 minutes, 24 hours.
45D1
INC (HL) 34
INCrement the clock field at Register Pair HL (the seconds the first time). 45D8H loops back here.
45D2
LD A,(DE) 1A
Fetch the field's limit from the table at Register Pair DE into Register A.
45D3
SUB (HL) 96
SUBtract the field at Register Pair HL from Register A (the limit). The Z FLAG is set when the field has reached its limit.
45D4
RET NZ C0
If the NZ FLAG is set (no carry into the next field), RETurn.
45D5
LD (HL),A 77
Store Register A (00H) into the field at Register Pair HL: it starts again from 0.
45D6
INC L 2C
INCrement Register L to the next field (4042H minutes, then 4043H hours).
45D7
INC E 1C
INCrement Register E to the next limit in the table.
45D8
DECrement Register B (the fields left) and LOOP BACK to 45D1H to carry into the next field. After the hours wrap at 24 the date is not changed.
45DA
RET C9
RETurn to the task loop: all three fields carried (midnight).
45DB-45DC
DEFB 00H x 2 00 x 2
45DBH-45DCH: two bytes of 00H. No code of SYS0/SYS addresses them.
45DD-45DF
DEFB 3CH, 3CH, 18H 3C 3C 18
45DDH-45DFH: the limits of the clock fields: 3CH (60) seconds, 3CH (60) minutes, 18H (24) hours, read by 45D2H.

45E0H - The Floppy Disk Driver: Select the Drive

SYS0/SYS's driver for the expansion interface's floppy disk controller (registers 37ECH-37EFH, drive select latch 37E1H). Every drive code table entry of a floppy drive jumps to 45FBH. 45E0H waits until the controller is not busy, then writes the drive's select line(s) and side bit to the latch; if the controller had reported NOT READY (the motor was off) it waits for the motor through 4399H. Index Register IY points at the drive's code table.

45E0
GOSUB to 461CH to wait until the controller is not busy. Register A comes back holding the controller's status.
45E3
RLCA 07
Rotate Register A (the status) left one bit: bit 7, NOT READY, goes into the CARRY FLAG.
45E4
PUSH AF F5
Save Register Pair AF (the CARRY FLAG = NOT READY) to the stack.
45E5
LD A,(IY+03H) FD 7E 03
Fetch byte +03H of the drive code table at Index Register IY into Register A: the drive's flags, bit 4 the side to use.
45E8
AND 10H E6 10
Mask Register A to bit 4, the side the last seek chose.
45EA
RRCA 0F
Rotate Register A right one bit: the side bit moves to bit 3, the side select line of the latch.
45EB
OR (IY+04H) FD B6 04
OR byte +04H of the drive code table at Index Register IY into Register A: its bits 3-0 are the drive's select line(s).
45EE
AND 0FH E6 0F
Mask Register A to bits 3-0: the value for the drive select latch.
45F0
LD (4309H),A 32 09 43
Store Register A (the select value) at 4309H, PDRV$, so that 461CH can write it again while it waits.
45F3
LD (37E1H),A 32 E1 37
Store Register A (the select value) to the drive select latch at 37E1H: the drive is selected and its motor starts or keeps running.
45F6
POP AF F1
Restore Register Pair AF (the CARRY FLAG = NOT READY before the select) from the stack.
45F7
RET NC D0
If the NO CARRY FLAG is set (the drive was ready), RETurn.
45F8
JUMP to 4399H to wait for the motor to come up to speed; it returns to the caller.

45FBH - The Driver's Entry: Function Dispatch

The address every floppy drive code table jumps to (4700H +00H: JP 45FBH). Register B = the function: 00H nothing, 01H select, 02H-04H restore to cylinder 0, 05H step in one cylinder, 06H seek, 07H wait until not busy, 09H read a sector, 0AH verify a sector, 0BH-0DH write a sector, 0EH write a sector with the deleted data mark (directory), 0FH write a track. Register C = the drive, Register D = the cylinder, Register E = the sector, Register Pair HL = the buffer, Index Register IY = the drive code table. Returns with the Z FLAG set and Register A = 00H when the function succeeded, otherwise Register A = the error number.

45FB
LD A,B 78
Copy Register B (the function) into Register A.
45FC
OR A B7
Set the flags from Register A (OR A): the Z FLAG is set for function 00H.
45FD
RET Z C8
If the Z FLAG is set (function 00H), RETurn with nothing done.
45FE
CP 07H FE 07
Compare Register A (the function) against 07H.
4600
If the Z FLAG is set (function 07H), JUMP to 461CH to wait until the controller is not busy.
4602
If the NO CARRY FLAG is set (functions 08H and up: reading and writing), JUMP to 466BH.
4604
CP 06H FE 06
Compare Register A (the function) against 06H.
4606
If the Z FLAG is set (function 06H), JUMP to 462AH to seek cylinder Register D for sector Register E.
4608
DEC A 3D
DECrement Register A (the function): the Z FLAG is set for function 01H.
4609
If the Z FLAG is set (function 01H), JUMP to 45E0H to select the drive.
460B
INC (IY+05H) FD 34 05
INCrement byte +05H of the drive code table at Index Register IY, the cylinder the head is on: the step in of function 05H moves one cylinder in. Functions 02H-04H set it to 0 below.
460E
CP 04H FE 04
Compare Register A (the function less 1) against 04H: the Z FLAG is set for function 05H.
4610
LD B,58H 06 58
Load Register B with 58H, the controller command Step In with the track register updated. LD does not change the flags.
1771 FDC Command: 58H (01011000)Function Description
Bit 7Bit 6Bit 5Bit 4Bit 3Bit 2Bit 1Bit 0Summary of Bits
01011000Command=Step In (bits 7-5 = 010)
u = 1: update the track register
h = 1: head load and settle delay
V = 0: no verify
r1 r0 = 00: 6 ms (12 ms on the Radio Shack interface) stepping rate
4612
If the Z FLAG is set (function 05H), JUMP to 4659H to OR in the drive's step rate and issue the command in Register B (58H).
4614
LD (IY+05H),00H FD 36 05 00
Store 00H into byte +05H of the drive code table at Index Register IY: after a restore the head is on cylinder 0. 46EBH calls this entry after a sector was not found.
4618
LD B,08H 06 08
Load Register B with 08H, the controller command Restore.
1771 FDC Command: 08H (00001000)Function Description
Bit 7Bit 6Bit 5Bit 4Bit 3Bit 2Bit 1Bit 0Summary of Bits
00001000Command=Restore (bits 7-4 = 0000)
h = 1: head load and settle delay
V = 0: no verify
r1 r0 = 00: 6 ms (12 ms on the Radio Shack interface) stepping rate
461A
JUMP to 4659H to OR in the drive's step rate and issue the command in Register B.

461CH - Wait Until the Controller Is Not Busy

Returns when bit 0 (BUSY) of the controller's status is clear, with the status in Register A. While it waits it writes the last drive select value (4309H) to the latch again, which keeps the drive selected and its motor running. It is also the vector of the controller's interrupt (4059H) and function 07H of the driver.

461C
LD A,(37ECH) 3A EC 37
Fetch the controller's status from 37ECH into Register A.
461F
BIT 0,A CB 47
Test bit 0 of Register A (the status): BUSY, set while a command runs.
4621
RET Z C8
If the Z FLAG is set (the controller is not busy), RETurn with the status in Register A.
4622
LD A,(4309H) 3A 09 43
Fetch the last drive select value from 4309H (PDRV$) into Register A.
4625
LD (37E1H),A 32 E1 37
Store Register A (the drive select value) to the latch at 37E1H again, so the drive stays selected.
4628
LOOP BACK to 461CH to read the controller's status again.

462AH - Seek: Cylinder D, Sector E

462AH waits for the controller first; 462DH does not. The sector number in Register E counts through both sides of a cylinder: a number at or above the sectors on a track (byte +07H, bits 4-0, plus 1) is reduced by that count and, on a drive with two sides (byte +04H bit 5), bit 4 of byte +03H is set for side 1. The sector and the cylinder go to the controller's sector and data registers, the cylinder also to byte +05H, and the Seek command is issued with the drive's step rate. Register Pair DE comes back unchanged.

462A
GOSUB to 461CH to wait until the controller is not busy.
462D
LD A,(IY+05H) FD 7E 05
Fetch byte +05H of the drive code table at Index Register IY into Register A: the cylinder the head is on.
4630
LD (37EDH),A 32 ED 37
Store Register A (the head's cylinder) to the controller's track register at 37EDH, so the Seek steps from the right place.
4633
LD A,(IY+07H) FD 7E 07
Fetch byte +07H of the drive code table at Index Register IY into Register A: bits 4-0 hold the highest sector number on a track.
4636
AND 1FH E6 1F
Mask Register A to bits 4-0: the highest sector number.
4638
INC A 3C
INCrement Register A: Register A = the sectors on a track.
4639
RES 4,(IY+03H) FD CB 03 A6
Clear bit 4 of byte +03H of the drive code table at Index Register IY: side 0 unless the sector is on side 1.
463D
SUB E 93
SUBtract Register E (the sector wanted) from Register A (the sectors on a track).
463E
NEG ED 44
Negate Register A: Register A = the sector wanted less the sectors on a track; the SIGN FLAG is set when the sector is on side 0.
4640
PUSH DE D5
Save Register Pair DE (the cylinder and the sector as given) to the stack.
4641
If the SIGN FLAG is set (Register E is below the sectors on a track: side 0), JUMP to 464FH with Register E unchanged.
4644
LD E,A 5F
Copy Register A (the sector less the sectors on a track) into Register E: the sector's number on side 1.
4645
BIT 5,(IY+04H) FD CB 04 6E
Test bit 5 of byte +04H of the drive code table at Index Register IY: set for a drive with two sides.
4649
If the Z FLAG is set (one side), JUMP to 464FH without choosing side 1.
464B
SET 4,(IY+03H) FD CB 03 E6
Set bit 4 of byte +03H of the drive code table at Index Register IY: side 1 (45E5H-45EAH turn it into bit 3 of the drive select latch).
464F
LD (37EEH),DE ED 53 EE 37
Store Register Pair DE to 37EEH-37EFH: Register E (the sector on its side) to the controller's sector register at 37EEH and Register D (the cylinder) to its data register at 37EFH, where the Seek takes the cylinder to go to.
4653
POP DE D1
Restore Register Pair DE (the cylinder and the sector as given) from the stack.
4654
LD (IY+05H),D FD 72 05
Store Register D (the cylinder) into byte +05H of the drive code table at Index Register IY: after the Seek the head is on it.
4657
LD B,18H 06 18
Load Register B with 18H, the controller command Seek.
1771 FDC Command: 18H (00011000)Function Description
Bit 7Bit 6Bit 5Bit 4Bit 3Bit 2Bit 1Bit 0Summary of Bits
00011000Command=Seek (bits 7-4 = 0001)
h = 1: head load and settle delay
V = 0: no verify
r1 r0 = 00: 6 ms (12 ms on the Radio Shack interface) stepping rate
4659
GOSUB to 45E0H to select the drive (with the side bit) and wait for the motor if it was off.
465C
LD A,(IY+03H) FD 7E 03
Fetch byte +03H of the drive code table at Index Register IY into Register A.
465F
AND 03H E6 03
Mask Register A to bits 1-0: the drive's step rate.
4661
OR B B0
OR Register B (the command: 18H Seek, 08H Restore or 58H Step In) into Register A, so the command steps at the drive's rate.
4662
LD (37ECH),A 32 EC 37
Store Register A (the command) to the controller's command register at 37ECH. The read and write engine enters here with its own command in Register A (46C1H).
4665
LD B,08H 06 08
Load Register B with 08H for a short delay: the controller needs a moment to set BUSY before its status is read.
4667
DECrement Register B and LOOP BACK to 4667H until it reaches 0.
4669
XOR A AF
Set Register A to 00H (XOR A) with the Z FLAG set: no error.
466A
RET C9
RETurn to the caller with the entry's address in Register Pair HL.

466BH - The Read and Write Engine

Functions 08H and up. Register B gets the number of tries and Register C the controller command: 88H Read Sector (10 tries), 88H for a verify (5 tries), A8H Write Sector, ABH Write Sector with the deleted data mark (function 0EH) and F4H Write Track (function 0FH), 5 tries for the writes. The three bytes after each CALL 469AH are its parameters: the first error number of the operation and the two bytes of the transfer loop's body. A write is refused with error 0FH when bit 7 of byte +03H of the drive code table (the software write protect) is set.

466B
LD BC,0588H 01 88 05
Load Register Pair BC with 0588H: Register B = 05H tries, Register C = 88H, the command Read Sector.
466E
CP 0AH FE 0A
Compare Register A (the function) against 0AH.
4670
If the Z FLAG is set (function 0AH, verify), JUMP to 467CH with 5 tries and the read command in Register Pair BC.
4672
If the NO CARRY FLAG is set (functions 0BH-0FH, the writes), JUMP to 4681H, inside the bytes of the LD BC at 467FH, where they read as LD C,0A8H.
4674
LD B,0AH 06 0A
Function 09H, read: Load Register B with 0AH, 10 tries.
4676
GOSUB to 469AH, which takes the three parameter bytes that follow (01H, 1AH, 02H) and goes on to read the sector; it returns to this routine's caller.
4679-467B
DEFB 01H, 1AH, 02H 01 1A 02
The parameters of a read: 01H, the first error number of a read (469DH stores it at 46F6H, so the errors of the status bits are 03H lost data, 04H parity error, 05H not found, 06H a system data record (the deleted data mark of a directory sector), 07H a locked or deleted record), and 1AH 02H, the body of the transfer loop: LD A,(DE) / LD (BC),A, a byte from the data register into the buffer.
467C
GOSUB to 469AH with the verify's three parameter bytes, which follow (01H, 1AH, 0EH); it returns to this routine's caller.
467F-4681
DEFB 01H, 1AH, 0EH 01 1A 0E
The parameters of a verify: 01H, the first error number of a read, and 1AH 0EH, the loop body LD A,(DE) / LD C,03H: the byte is read from the data register and not stored (the 0EH takes the INC BC at 46D3H as its operand). Entered at 4681H from 4672H, the bytes 0EH A8H are LD C,0A8H: the command Write Sector for the writes.
4682
XOR B A8
Exclusive OR Register B into Register A. Never executed as written: this byte (A8H) is the operand of LD C,0A8H when 4681H is entered from 4672H, and execution goes on at 4683H.
4683
CP 0EH FE 0E
Compare Register A (the function, 0BH-0FH) against 0EH.
4685
If the CARRY FLAG is set (functions 0BH-0DH: a plain write), JUMP to 468DH with the command A8H in Register C.
4687
LD C,F4H 0E F4
Load Register C with F4H, the command Write Track, for function 0FH. LD does not change the flags of the CP above.
1771 FDC Command: F4H (11110100)Function Description
Bit 7Bit 6Bit 5Bit 4Bit 3Bit 2Bit 1Bit 0Summary of Bits
11110100Command=Write Track (bits 7-4 = 1111)
E = 1: head load delay
In the data, F7H writes the two CRC bytes and F8H-FEH are written as address marks
4689
If the NZ FLAG is set (function 0FH), JUMP to 468DH with Write Track in Register C.
468B
LD C,ABH 0E AB
Load Register C with ABH, Write Sector with the data mark F8H, the deleted data mark used for directory sectors (function 0EH).
1771 FDC Command: ABH (10101011)Function Description
Bit 7Bit 6Bit 5Bit 4Bit 3Bit 2Bit 1Bit 0Summary of Bits
10101011Command=Write Sector (bits 7-5 = 101)
m = 0: one sector
b = 1: IBM sector length
E = 0: no head load delay
a1 a0 = 11: data mark F8H
468D
BIT 7,(IY+03H) FD CB 03 7E
Test bit 7 of byte +03H of the drive code table at Index Register IY: the drive's software write protect.
4691
LD A,0FH 3E 0F
Load Register A with 0FH, the error number of a write protected disk. LD does not change the flags.
4693
RET NZ C0
If the NZ FLAG is set (the drive is write protected), RETurn with Register A = 0FH and the NZ FLAG.
4694
GOSUB to 469AH with the write's three parameter bytes, which follow (09H, 0AH, 12H); it returns to this routine's caller.
4697-4699
DEFB 09H, 0AH, 12H 09 0A 12
The parameters of a write: 09H, the first error number of a write (0BH lost data, 0CH parity error, 0DH not found, 0EH write fault, 0FH write protected), and 0AH 12H, the loop body LD A,(BC) / LD (DE),A, a byte from the buffer into the data register.
469A
EX (SP),HL E3
Exchange Register Pair HL with the top of the stack (the Stack Pointer is not changed): Register Pair HL = the address of the three parameter bytes after the CALL, and the caller's Register Pair HL (the buffer) is on the stack.
469B
LD A,(HL) 7E
Fetch the first parameter byte at Register Pair HL into Register A: the first error number of the operation (01H or 09H).
469C
INC HL 23
INCrement Register Pair HL to the second parameter byte.
469D
LD (46F6H),A 32 F6 46
Store Register A (the first error number) at 46F6H, the operand of the LD A at 46F5H that the error decoder starts from.
46A0
LD A,(HL) 7E
Fetch the second parameter byte at Register Pair HL into Register A: the first byte of the loop body.
46A1
INC HL 23
INCrement Register Pair HL to the third parameter byte.
46A2
LD H,(HL) 66
Fetch the third parameter byte at Register Pair HL into Register H: the second byte of the loop body.
46A3
LD L,A 6F
Copy Register A (the first byte of the loop body) into Register L. Register Pair HL = the loop body.
46A4
LD (46D1H),HL 22 D1 46
Store Register Pair HL (the two bytes of the loop body) at 46D1H-46D2H, inside the transfer loop.
46A7
POP HL E1
Restore the caller's Register Pair HL (the buffer) from the stack. The address of the parameter bytes is dropped: the engine never returns to them.
46A8
PUSH BC C5
Save Register Pair BC (Register B = the tries left, Register C = the command) to the stack. 46E1H and 46F0H loop back here for another try.
46A9
BIT 4,C CB 61
Test bit 4 of Register C (the command): clear for Read Sector and Write Sector, set for Write Track (F4H).
46AB
If the Z FLAG is set (a sector command), GOSUB to 462AH to seek cylinder Register D for sector Register E (which also picks the side). A Write Track works on the cylinder the head is on.
46AE
PUSH DE D5
Save Register Pair DE (the cylinder and sector) to the stack.
46AF
PUSH HL E5
Save Register Pair HL (the buffer) to the stack.
46B0
LD HL,37ECH 21 EC 37
Point Register Pair HL to 37ECH, the controller's command and status register.
46B3
GOSUB to 461CH to wait until the controller is not busy (the Seek is finished).
46B6
GOSUB to 46FDH, a NOP and a RET in the file. SYSTEM (SMOOTH) changes the NOP to F3H (DI), so interrupts stay off from here to the end of the transfer.
46B9
LD A,D 7A
Copy Register D (the cylinder) into Register A.
46BA
LD (37EDH),A 32 ED 37
Store Register A (the cylinder) to the controller's track register at 37EDH, the cylinder the head is now on, which the controller compares with the sector's ID field.
46BD
LD DE,37EFH 11 EF 37
Point Register Pair DE to 37EFH, the controller's data register.
46C0
LD A,C 79
Copy Register C (the command) into Register A.
46C1
GOSUB to 4662H to write the command in Register A to 37ECH and wait a moment; Register A comes back as 00H.
46C4
POP BC C1
Restore Register Pair BC from the stack: the buffer address saved at 46AFH.
46C5
PUSH BC C5
Save Register Pair BC (the buffer address) to the stack again, for the restore at 46DBH.
46C6
JUMP to 46CBH to wait for the first byte of the sector or the end of the command.
46C8
RRCA 0F
Rotate Register A (the status, DATA REQUEST clear) right one bit: bit 0, BUSY, goes into the CARRY FLAG.
46C9
If the NO CARRY FLAG is set (the controller is no longer busy: the command has finished), JUMP to 46D7H to check the result.
46CB
LD A,(HL) 7E
Fetch the controller's status from 37ECH (Register Pair HL) into Register A. 46C9H, 46CEH and 46D4H come back here.
46CC
BIT 1,A CB 4F
Test bit 1 of Register A (the status): DATA REQUEST, a byte to be moved.
46CE
If the Z FLAG is set (no byte waiting), JUMP to 46C8H to check whether the command has finished.
46D0
DI F3
Disable interrupts: from the first byte on, nothing may delay the transfer (the controller loses data if a byte waits too long).
46D1
NOP 00
The two bytes 46D1H-46D2H are the body of the transfer loop, 00H 00H (two NOPs) in the file; 46A4H stores the body of the operation here before the command starts: 1AH 02H (LD A,(DE) / LD (BC),A) to read, 1AH 0EH (LD A,(DE) and the operand of LD C) to verify, 0AH 12H (LD A,(BC) / LD (DE),A) to write. Register Pair DE = the data register 37EFH, Register Pair BC = the buffer.
46D2
NOP 00
The second byte of the loop body: 00H (NOP) in the file, replaced by 46A4H.
46D3
INC BC 03
INCrement Register Pair BC to the next byte of the buffer (for a verify this byte is the operand of LD C,03H instead).
46D4
JUMP to 46CBH for the next byte or the end of the command.
46D7
EI FB
Enable interrupts again: the command has finished.
46D8
LD A,(HL) 7E
Fetch the controller's final status from 37ECH (Register Pair HL) into Register A.
46D9
AND 7CH E6 7C
Mask Register A to bits 6-2 of the status: 6 write protected (a read: a deleted data mark), 5 write fault (a read: the record type), 4 not found, 3 CRC error, 2 lost data. The Z FLAG is set when none is on.
46DB
POP HL E1
Restore Register Pair HL (the buffer) from the stack.
46DC
POP DE D1
Restore Register Pair DE (the cylinder and sector) from the stack.
46DD
POP BC C1
Restore Register Pair BC (Register B = the tries left, Register C = the command) from the stack.
46DE
RET Z C8
If the Z FLAG is set (no error bit in Register A), RETurn with Register A = 00H: the operation succeeded.
46DF
BIT 2,A CB 57
Test bit 2 of Register A: LOST DATA, a byte not moved in time.
46E1
If the NZ FLAG is set (lost data), JUMP to 46A8H to try again without counting the try.
46E3
PUSH AF F5
Save Register Pair AF (the error bits) to the stack.
46E4
AND 18H E6 18
Mask Register A to bits 4 and 3: NOT FOUND and CRC ERROR, the errors worth another try.
46E6
If the Z FLAG is set (another error: write protect, write fault or the record type), JUMP to 46F3H to turn the status into an error number without trying again.
46E8
BIT 4,A CB 67
Test bit 4 of Register A: NOT FOUND, the sector's ID field was not found.
46EA
PUSH BC C5
Save Register Pair BC (the tries and the command) to the stack: 4614H changes Register B.
46EB
If the NZ FLAG is set (the sector was not found), GOSUB to 4614H to restore the head to cylinder 0, so the next try seeks from a known place.
46EE
POP BC C1
Restore Register Pair BC (Register B = the tries left, Register C = the command) from the stack.
46EF
POP AF F1
Restore Register Pair AF (the error bits) from the stack.
46F0
DECrement Register B (the tries left) and, if it is not 0, LOOP BACK to 46A8H for another try.
46F2
LD B,F1H 06 F1
Load Register B with F1H. The instruction is passed over by its effect: Register B is set again at 46F4H. Entered at 46F3H (from 46E6H), the byte F1H is POP AF, which takes back the error bits saved at 46E3H.
46F4
LD B,A 47
Copy Register A (the error bits of the status) into Register B.
46F5
LD A,00H 3E 00
Load Register A with the first error number of the operation: the operand at 46F6H is 00H in the file; 469DH stores 01H (read, verify) or 09H (write) there, and FDUBL/CMD stores its own (its 54B4H).
46F7
RRC B CB 08
Rotate Register B (the error bits) right one bit: the lowest bit goes into the CARRY FLAG. 46FBH loops back here.
46F9
RET C D8
If the CARRY FLAG is set (the lowest error bit is found), RETurn with Register A = the error number and the NZ FLAG set.
46FA
INC A 3C
INCrement Register A, the error number, for the next bit.
46FB
LOOP BACK to 46F7H to test the next bit of Register B. Bits 1-0 are always clear, so the error number is the first number plus 2 for bit 2, plus 3 for bit 3 and so on.
46FD
NOP 00
No operation, then the RET below. 46B6H (and FDUBL/CMD, its 54D5H) calls this byte; SYSTEM (SMOOTH) stores F3H (DI) here (SYS7/SYS 5500H), and SYS6/SYS reads it (its 546BH).
46FE
RET C9
RETurn to the caller (46B6H). The end of the floppy disk driver.
46FF
DEFB FDH FD
46FFH: FDH, the last byte but one of the load record 461CH-4700H; the record ends with E9H at 4700H (FDH E9H, JP (IY)), but the next record (4700H-47CAH) loads C3H over 4700H, so in memory 46FFH-4700H are FDH C3H. No code of the LDOS files on this diskette jumps to 46FFH.

4700H - DCT$, the Drive Code Tables

Eight entries of 10 bytes, drives 0-7 (GETDCT, 478FH, points Index Register IY at entry 4700H + drive x 10). +00H C3H for a drive that is present (a JP) or C9H for one that is not (a RET, so a call returns at once with nothing done); +01H-+02H the driver address; +03H flags (bits 1-0 step rate, bit 2 one motor wait less, bit 4 side 1, bit 5 an 8 inch drive, bit 6 double density, bit 7 software write protect); +04H bits 3-0 the select line(s), bit 5 two sides, bit 6 the controller can do double density; +05H the cylinder the head is on; +06H the highest cylinder; +07H bits 4-0 the highest sector on a track, bits 7-5 the heads less one; +08H bits 4-0 the sectors in a granule less one, bits 7-5 the granules on a track less one; +09H the directory cylinder. SYS0/SYS's reset replaces drive 0's entry after a boot through a driver and drives 1-7 from the system information sector (4E56H, 4FC5H-4FD6H).

4700-4702
DEFB C3H, FBH, 45H C3 FB 45
4700H-4702H, drive 0, +00H-+02H: JP 45FBH, SYS0/SYS's floppy disk driver; the drive is present.
4703
DEFB 83H 83
4703H, drive 0, +03H: 83H, step rate 3 and bit 7 (write protect) set. The reset keeps only bits 6-2 and puts in the bootstrap step rate of the boot sector (4E6EH-4E75H: AND 7CH, OR the rate), so the write protect bit is off after a boot.
4704
DEFB 01H 01
4704H, drive 0, +04H: 01H, select line 1 (drive 0). The reset ORs in bit 5 when the allocation table of the diskette in drive 0 says two sides (4FE3H-4FEDH).
4705
DEFB 01H 01
4705H, drive 0, +05H: 01H, the cylinder the head is on as the file was built; the first Seek tells the controller this value through its track register.
4706
DEFB 22H 22
4706H, drive 0, +06H: 22H, highest cylinder 34 (35 cylinders).
4707
DEFB 09H 09
4707H, drive 0, +07H: 09H, highest sector 9 (10 sectors a track, single density), one head.
4708
DEFB 24H 24
4708H, drive 0, +08H: 24H, 5 sectors to a granule (bits 4-0 plus 1) and 2 granules on a track (bits 7-5 plus 1).
4709
DEFB 11H 11
4709H, drive 0, +09H: 11H, directory cylinder 17. The reset stores the directory cylinder from byte 2 of the boot sector here (4E76H-4E79H).
470A-4713
DEFB C3H, FBH, 45H, 03H, 02H, 11H, 22H, 09H, 24H, 11H C3 FB 45 03 02 11 22 09 24 11
470AH-4713H, drive 1: JP 45FBH (present), +03H 03H step rate 3, +04H 02H select line 2, +05H 11H head on cylinder 17, +06H 22H 35 cylinders, +07H 09H 10 sectors, +08H 24H 2 granules of 5 sectors, +09H 11H directory cylinder 17. Replaced by the reset from the system information sector.
4714-471D
DEFB C3H, FBH, 45H, 03H, 04H, 11H, 22H, 09H, 24H, 11H C3 FB 45 03 04 11 22 09 24 11
4714H-471DH, drive 2: JP 45FBH (present), step rate 3, select line 4, head on cylinder 17, 35 cylinders of 10 sectors, 2 granules of 5 sectors, directory cylinder 17. Replaced by the reset.
471E-4727
DEFB C3H, FBH, 45H, 03H, 08H, 11H, 22H, 09H, 24H, 11H C3 FB 45 03 08 11 22 09 24 11
471EH-4727H, drive 3: JP 45FBH (present), step rate 3, select line 8, head on cylinder 17, 35 cylinders of 10 sectors, 2 granules of 5 sectors, directory cylinder 17. Replaced by the reset.
4728
DEFB C9H C9
4728H, drive 4, +00H: C9H (RET), not present. Replaced by the reset.
4729-4731
DEFB 00H x 9 00 x 9
4729H-4731H, drive 4, +01H-+09H: 00H, no driver and no geometry.
4732
DEFB C9H C9
4732H, drive 5, +00H: C9H (RET), not present. Replaced by the reset.
4733-473B
DEFB 00H x 9 00 x 9
4733H-473BH, drive 5, +01H-+09H: 00H, no driver and no geometry.
473C
DEFB C9H C9
473CH, drive 6, +00H: C9H (RET), not present. Replaced by the reset.
473D-4745
DEFB 00H x 9 00 x 9
473DH-4745H, drive 6, +01H-+09H: 00H, no driver and no geometry.
4746
DEFB C9H C9
4746H, drive 7, +00H: C9H (RET), not present. Replaced by the reset.
4747-474F
DEFB 00H x 9 00 x 9
4747H-474FH, drive 7, +01H-+09H: 00H, no driver and no geometry.

4750H - The Disk Primitives

The named entry points the system and the utilities use for a sector operation: each loads the driver function into Register A and joins 4779H, which calls the driver of the drive in Register C through its drive code table. Each entry is five bytes, and the fifth byte of most is a variable. 4750H is the same with the drive of the last call (LDRV$, 4308H).

4750
LD A,(4308H) 3A 08 43
Fetch LDRV$, the drive of the last primitive call, from 4308H into Register A. The interrupt routine calls 4750H on SHIFT BREAK (4552H).
4753
LD C,A 4F
Copy Register A (the last drive) into Register C, the drive for the select below.
4754
LD A,01H 3E 01
SELECT: Load Register A with 01H, the driver's function select the drive.
4756
JUMP to 4779H to call the driver of drive Register C with the function in Register A.
4758
DEFB 00H 00
4758H: the fifth byte of SELECT, the status byte of the command interpreter. SYS1/SYS clears it for every command line typed or given to @CMNDI, sets bit 1 for a line from a program (function 20H) and bit 2 while a line is typed, and tests bit 4 (no program run) and bit 1 (its 4E22H-4E53H, 4E8EH, 4E97H). Members of SYS6/SYS and SYS7/SYS test bit 1 and set bit 3, which KI/DVR tests (its 520BH); SYS4/SYS skips the error message when bit 6 is set and gives the short message when bit 7 is set (its 4EC7H-4EDDH) and clears bit 7, which TED/CMD sets (its 56AFH).
4759
LD A,07H 3E 07
RSELCT: Load Register A with 07H, the driver's function wait until the controller is not busy.
475B
JUMP to 4779H to call the driver of drive Register C with the function in Register A.
475D
DEFB 00H 00
475DH: the fifth byte of RSELCT, the date stamping flags that SYS2/SYS (its 4EA7H) and SYS3/SYS (its 4E99H) use when they open and close files; BACKUP/CMD, SYS6/SYS and SYS7/SYS read it too.
475E
LD A,06H 3E 06
SEEK: Load Register A with 06H, the driver's function seek cylinder Register D for sector Register E.
4760
JUMP to 4779H to call the driver of drive Register C with the function in Register A.
4762
DEFB FFH FF
4762H: the fifth byte of SEEK, FFH. No code of the LDOS files on this diskette addresses it.
4763
LD A,0DH 3E 0D
WRSECT: Load Register A with 0DH, the driver's function write the sector at Register Pair HL to cylinder Register D, sector Register E.
4765
JUMP to 4779H to call the driver of drive Register C with the function in Register A.
4767
DEFB 01H 01
4767H: the fifth byte of WRSECT, 01H: the cylinder where SYS8/SYS starts its search for free space (its 4EBFH). Nothing writes it, so every search starts at cylinder 1.
4768
LD A,0EH 3E 0E
WRPROT: Load Register A with 0EH, the driver's function write a sector with the deleted data mark, used for every directory sector (4B25H).
476A
JUMP to 4779H to call the driver of drive Register C with the function in Register A.
476C
DEFB 00H 00
476CH: the fifth byte of WRPROT, 00H. No code of the LDOS files on this diskette addresses it.
476D
LD A,0FH 3E 0F
WRTRK: Load Register A with 0FH, the driver's function write a track (FORMAT/CMD) from the buffer at Register Pair HL.
476F
JUMP to 4779H to call the driver of drive Register C with the function in Register A.
4771
DEFB 00H 00
4771H: the fifth byte of WRTRK, 00H. No code of the LDOS files on this diskette addresses it.
4772
LD A,0AH 3E 0A
VERSEC: Load Register A with 0AH, the driver's function verify (read without storing) cylinder Register D, sector Register E.
4774
JUMP to 4779H to call the driver of drive Register C with the function in Register A.
4776
DEFB 00H 00
4776H: the fifth byte of VERSEC, 00H. No code of the LDOS files on this diskette addresses it.
4777
LD A,09H 3E 09
RDSECT: Load Register A with 09H, the driver's function read cylinder Register D, sector Register E into the buffer at Register Pair HL. The code goes on into 4779H.
4779
PUSH BC C5
Save Register Pair BC (Register C = the drive) to the stack; the driver gets the function in Register B.
477A
LD B,A 47
Copy Register A (the function) into Register B.
477B
LD A,C 79
Copy Register C (the drive number) into Register A to keep it.
477C
LD (4308H),A 32 08 43
Store Register A (the drive) at 4308H, LDRV$, for 4750H.
477F
PUSH IY FD E5
Save Index Register IY to the stack: the caller's Index Register IY comes back.
4781
GOSUB to 478FH to point Index Register IY at the drive code table of drive Register C.
4784
LD A,20H 3E 20
Load Register A with 20H. SYS0/SYS's own driver does not use it (it takes the function from Register B); it is passed with the flags of the OR below.
4786
OR A B7
Set the flags from Register A (OR A): NZ, CARRY clear.
4787
GOSUB to 4BCBH, which jumps to the drive code table at Index Register IY: its first three bytes are a JP to the drive's driver (45FBH) or a RET for a drive that is not present. The driver returns with the Z FLAG set and Register A = 00H on success, else the error number in Register A.
478A
POP IY FD E1
Restore the caller's Index Register IY from the stack.
478C
POP BC C1
Restore the caller's Register Pair BC from the stack.
478D
RET C9
RETurn to the caller with the driver's result in Register A and the flags.
478E
DEFB 00H 00
478EH: 00H, the spare byte after the primitives.

478FH - GETDCT and DCTBYT: Find a Drive's Code Table

478FH (GETDCT) points Index Register IY at the drive code table of drive Register C (bits 2-0). 479CH (DCTBYT) returns in Register A byte Register A (an offset 0-9) of drive Register C's table; 4797H does that for byte +08H of the drive in byte +06H of the file control block at Index Register IX. 47A5H works out the address.

478F
PUSH HL E5
Save the caller's Register Pair HL to the stack.
4790
GOSUB to 47A5H: Register Pair HL comes back pointing at drive Register C's entry in DCT$ (4700H + the drive x 10).
4793
EX (SP),HL E3
Exchange Register Pair HL with the top of the stack (the Stack Pointer is not changed): the entry's address goes onto the stack and the caller's Register Pair HL comes back.
4794
POP IY FD E1
Restore the entry's address from the stack into Index Register IY.
4796
RET C9
RETurn with Index Register IY pointing at the drive code table.
4797
LD C,(IX+06H) DD 4E 06
Fetch byte +06H of the file control block at Index Register IX into Register C: the file's drive.
479A
LD A,08H 3E 08
Load Register A with 08H, the offset of the byte with the sectors in a granule and the granules on a track.
479C
PUSH HL E5
DCTBYT: Save the caller's Register Pair HL to the stack.
479D
LD H,A 67
Copy Register A (the offset in the table) into Register H, for 47A5H to add.
479E
GOSUB to 47A5H: Register A comes back as the low byte of drive Register C's entry plus the offset in Register H.
47A1
LD L,A 6F
Copy Register A (the low byte of the byte's address) into Register L. Register H is 47H from 47A5H: Register Pair HL = the address of the byte.
47A2
LD A,(HL) 7E
Fetch the byte of the drive code table at Register Pair HL into Register A.
47A3
POP HL E1
Restore the caller's Register Pair HL from the stack.
47A4
RET C9
RETurn with the byte of the drive code table in Register A.
47A5
LD A,C 79
Copy Register C (the drive number) into Register A.
47A6
AND 07H E6 07
Mask Register A to bits 2-0: the drive number, 0-7.
47A8
ADD A,A 87
Double Register A (ADD A,A): Register A = the drive x 2.
47A9
LD L,A 6F
Copy Register A (the drive x 2) into Register L.
47AA
ADD A,A 87
Double Register A again: Register A = the drive x 4.
47AB
ADD A,A 87
Double Register A again: Register A = the drive x 8.
47AC
ADD A,L 85
ADD Register L (the drive x 2) to Register A: Register A = the drive x 10, the offset of its entry.
47AD
ADD A,00H C6 00
ADD 00H to Register A: the operand at 47AEH is the low byte of DCT$, 00H for 4700H.
47AF
LD L,A 6F
Copy Register A (the low byte of the entry's address) into Register L.
47B0
ADD A,H 84
ADD Register H (an offset within the entry, from DCTBYT) to Register A: the low byte of that byte's address.
47B1
LD H,47H 26 47
Load Register H with 47H. Register Pair HL = the entry's address (4700H + the drive x 10).
47B3
RET C9
RETurn to the caller with the entry's address in Register Pair HL.

47B4H - Copy a System File's Extents into SFCB$

The overlay loader (4C37H) calls this with Register A = the low byte of the first extent's address in the directory record in the buffer at 4200H (the record + 16H). It copies the first extent (cylinder, granule byte) to 44AEH-44AFH, stores the number of granules of that extent as a word at 44B0H-44B1H, and copies the second extent (record + 18H) to 44B2H-44B3H.

47B4
LD L,A 6F
Copy Register A (the low byte of the extent's address) into Register L. Register H is 42H from the directory read: Register Pair HL = the first extent in the buffer.
47B5
LD DE,44AEH 11 AE 44
Point Register Pair DE to 44AEH, the extent area of SFCB$.
47B8
GOSUB to 47C3H to copy two bytes from Register Pair HL to Register Pair DE: the first extent's cylinder and granule byte. Register A comes back holding the granule byte.
47BB
AND 1FH E6 1F
Mask Register A (the granule byte) to bits 4-0: the granules of the extent less one.
47BD
INC A 3C
INCrement Register A: the number of granules in the first extent.
47BE
LD (DE),A 12
Store Register A (the granules) at Register Pair DE (44B0H), the low byte of the count.
47BF
INC DE 13
INCrement Register Pair DE to 44B1H, the high byte of the count.
47C0
XOR A AF
Set Register A to 00H (XOR A) for the high byte of the count.
47C1
LD (DE),A 12
Store Register A (00H) at Register Pair DE (44B1H), the high byte of the count.
47C2
INC DE 13
INCrement Register Pair DE to 44B2H. The code goes on into 47C3H to copy the second extent.
47C3
GOSUB to 47C6H to copy one byte from Register Pair HL to Register Pair DE; the code then falls into 47C6H for the second byte.
47C6
LD A,(HL) 7E
Fetch the byte at Register Pair HL into Register A.
47C7
LD (DE),A 12
Store Register A (the byte) at Register Pair DE in SFCB$.
47C8
INC HL 23
INCrement Register Pair HL to the next byte of the directory record.
47C9
INC DE 13
INCrement Register Pair DE to the next byte of SFCB$.
47CA
RET C9
RETurn to the caller (once to 47C6H, then to the caller of 47C3H).

47CBH - @SKIP and @POSN: Position a File

47CBH (@SKIP) works out the current record (484DH) and positions to the next one; 47CFH (@POSN) positions to record Register Pair BC. Register Pair DE = the file control block (Index Register IX after the prologue). In byte mode (bit 7 of +01H) with a record length below 256, the record number is turned into a sector and an offset (record x length); otherwise the record is the sector. When the buffer already holds that sector only the offset changes; else the buffer is written if it was changed, the next record number (+0AH-+0BH) becomes the sector and bit 5 of +01H marks the buffer to be read before the next byte. Then the end of file is tested (4A1DH).

47CB
@SKIP: GOSUB to 484DH (@LOC) to work out the current record number into Register Pair BC.
47CE
INC BC 03
INCrement Register Pair BC: the record after the current one.
47CF
@POSN: GOSUB to 49F3H, the file prologue: it checks that the control block at Register Pair DE is open, points Index Register IX at it, saves Register Pairs BC, DE and HL and Index Register IX for the return, and comes back with Register A = 00H.
47D2
SET 6,(IX+01H) DD CB 01 F6
Set bit 6 of byte +01H of the file control block at Index Register IX: the file has been positioned, so a write inside the file does not move its end (49DBH, 493BH).
47D6
BIT 7,(IX+01H) DD CB 01 7E
Test bit 7 of byte +01H of the file control block at Index Register IX: byte mode, the file used a byte at a time.
47DA
If the Z FLAG is set (not byte mode), JUMP to 47FAH: the record in Register Pair BC is a sector, at offset 0 (Register A = 00H).
47DC
LD H,B 60
Copy Register B (the record number's high byte) into Register H.
47DD
LD L,C 69
Copy Register C (the record number's low byte) into Register L. Register Pair HL = the record number.
47DE
OR (IX+09H) DD B6 09
OR byte +09H of the file control block at Index Register IX (the record length, 0 for 256) into Register A (00H): the Z FLAG is set for 256 byte records.
47E1
If the Z FLAG is set (records of 256 bytes), JUMP to 47FAH: the record is the sector.
47E3
GOSUB to 4B8FH to multiply Register Pair HL (the record number) by Register A (the record length): Register Pair HL = the product's high 16 bits (the sector), Register A = its low 8 bits (the offset in the sector).
47E6
LD B,H 44
Copy Register H (the sector's high byte) into Register B.
47E7
LD C,L 4D
Copy Register L (the sector's low byte) into Register C. Register Pair BC = the sector of the record.
47E8
LD (IX+05H),A DD 77 05
Store Register A (the offset of the record in its sector) into byte +05H of the file control block at Index Register IX, the position in the buffer.
47EB
BIT 5,(IX+01H) DD CB 01 6E
Test bit 5 of byte +01H of the file control block at Index Register IX: set when the buffer does not hold the sector before the next record number.
47EF
If the NZ FLAG is set (the buffer has to be read anyway), JUMP to 47FDH to set the next record number to Register Pair BC.
47F1
GOSUB to 497EH: Register Pair HL = the next record number (+0AH-+0BH) of the file at Index Register IX.
47F4
SCF 37
Set the CARRY FLAG, so the SBC below takes away one more.
47F5
SBC HL,BC ED 42
SUBtract Register Pair BC (the sector wanted) and the CARRY FLAG from Register Pair HL (the next record number): the Z FLAG is set when the sector wanted is the one before the next record number, the sector the buffer holds.
47F7
If the Z FLAG is set (the buffer holds the sector wanted), JUMP to 4A1DH to test the end of file: only the offset changed.
47FA
LD (IX+05H),A DD 77 05
Store Register A (the offset: 00H, or the end of file byte from @PEOF) into byte +05H of the file control block at Index Register IX. @REW, @PEOF and the record mode path come here.
47FD
PUSH BC C5
Save Register Pair BC (the sector wanted) to the stack.
47FE
GOSUB to 4993H to write the buffer back to its sector if the file is in byte mode and the buffer was changed. @BKSP and @RREAD join here with the sector on the stack.
4801
POP BC C1
Restore Register Pair BC (the sector wanted) from the stack.
4802
RET NZ C0
If the NZ FLAG is set (the buffer could not be written), RETurn with the error number in Register A.
4803
LD (IX+0AH),C DD 71 0A
Store Register C (the low byte of the sector wanted) into byte +0AH of the file control block at Index Register IX.
4806
LD (IX+0BH),B DD 70 0B
Store Register B (the high byte of the sector wanted) into byte +0BH of the file control block at Index Register IX: the next record number is now the sector wanted.
4809
GOSUB to 4914H to set bit 5 of byte +01H: the buffer must be read before the next byte is taken.
480C
JUMP to 4A1DH to test the end of file at the new position; its result is the result of the call.

480FH - @RREAD and @BKSP

480FH (@RREAD) marks the sector the buffer holds to be read again; 4816H (@BKSP) moves back one record (in byte mode by the record length within the buffer when it can, else to the sector before). Both end at 47FEH with the new next record number on the stack.

480F
@RREAD: GOSUB to 49F3H, the file prologue (Index Register IX = the file control block, Register A = 00H).
4812
LD C,01H 0E 01
Load Register C with 01H, so that 4D95H counts the position as inside the buffer's sector.
4814
JUMP to 482BH to set the next record number to the buffer's sector and read it again.
4816
@BKSP: GOSUB to 49F3H, the file prologue (Index Register IX = the file control block, Register A = 00H).
4819
LD C,A 4F
Copy Register A (00H) into Register C: no count of bytes for 4D95H.
481A
LD B,(IX+09H) DD 46 09
Fetch byte +09H of the file control block at Index Register IX into Register B: the record length (0 for 256).
481D
OR B B0
OR Register B (the record length) into Register A (00H): the Z FLAG is set for 256 byte records.
481E
If the Z FLAG is set (256 byte records), JUMP to 482BH to step back one sector.
4820
LD A,(IX+05H) DD 7E 05
Fetch byte +05H of the file control block at Index Register IX into Register A: the position in the buffer.
4823
SUB B 90
SUBtract Register B (the record length) from Register A (the position): the CARRY FLAG is set when the record before starts in the sector before.
4824
LD (IX+05H),A DD 77 05
Store Register A (the position one record back, in this sector or the one before) into byte +05H of the file control block at Index Register IX.
4827
If the CARRY FLAG is set (the position went back past the start of the buffer), JUMP to 482BH to step back one sector.
4829
XOR A AF
Set Register A to 00H (XOR A) with the Z FLAG set: done, the buffer still holds the sector.
482A
RET C9
RETurn through the prologue's restore (4A14H).
482B
GOSUB to 497EH: Register Pair HL = the next record number (+0AH-+0BH).
482E
DEC HL 2B
DECrement Register Pair HL: the sector before the next record number.
482F
GOSUB to 4D95H to adjust Register Pair HL for byte mode: there it adds 1 when Register C is not 0 and takes 1 away when the buffer holds the sector before the next record number (bit 5 clear); in record mode Register Pair HL is left as it is. Register Pair HL ends as the sector to read.
4832
PUSH HL E5
Save Register Pair HL (the sector to read) to the stack, where 47FEH-4801H takes it as Register Pair BC.
4833
JUMP to 47FEH to write the buffer if it changed and make the sector in Register Pair HL the next record number.

4835H - @REW and @PEOF

4835H (@REW) positions the file at its first record; 483CH (@PEOF) at its end of file: the ending record number (+0CH-+0DH), less one when the end of file byte (+08H) is not 0, with the end of file byte as the offset.

4835
@REW: GOSUB to 49F3H, the file prologue (Index Register IX = the file control block, Register A = 00H).
4838
LD B,A 47
Copy Register A (00H) into Register B, the high byte of the sector.
4839
LD C,A 4F
Copy Register A (00H) into Register C. Register Pair BC = 0000H, the first sector.
483A
JUMP to 47FAH to make sector 0 the next record number with the offset 00H in Register A.
483C
@PEOF: GOSUB to 49F3H, the file prologue (Index Register IX = the file control block, Register A = 00H).
483F
LD C,(IX+0CH) DD 4E 0C
Fetch byte +0CH of the file control block at Index Register IX into Register C: the ending record number's low byte.
4842
LD B,(IX+0DH) DD 46 0D
Fetch byte +0DH of the file control block at Index Register IX into Register B. Register Pair BC = the ending record number, the sectors in the file.
4845
OR (IX+08H) DD B6 08
OR byte +08H of the file control block at Index Register IX (the end of file byte: the bytes used in the last sector, 0 for a full sector) into Register A (00H).
4848
If the Z FLAG is set (the last sector is full), JUMP to 47FAH: the end is at offset 0 of sector Register Pair BC.
484A
DEC BC 0B
DECrement Register Pair BC: the end is inside the last sector of the file.
484B
JUMP to 47FAH with Register A = the end of file byte as the offset in that sector.

484DH - @LOC and @LOF

484DH (@LOC) returns in Register Pair BC the current record number of the file; 4878H (@LOF) the number of records (from the ending record number and the end of file byte). A position in sectors and bytes is divided by the record length; a partial record counts as one. Register A returns the high byte of the sector quotient. The result is put where the prologue's restore (4A14H) takes Register Pair BC from.

484D
@LOC: GOSUB to 49F3H, the file prologue (Index Register IX = the file control block, Register A = 00H).
4850
GOSUB to 497EH: Register Pair HL = the next record number (+0AH-+0BH).
4853
GOSUB to 4D92H: Register C = the position in the buffer (+05H) and Register Pair HL adjusted to the sector of the current position.
4856
LD E,(IX+09H) DD 5E 09
Fetch byte +09H of the file control block at Index Register IX into Register E: the record length (0 for 256). @LOF joins here with Register Pair HL = the ending record number and Register C = the end of file byte.
4859
LD A,E 7B
Copy Register E (the record length) into Register A.
485A
OR A B7
Set the flags from Register A (OR A): the Z FLAG is set for 256 byte records.
485B
If the Z FLAG is set (256 byte records: the record is the sector), JUMP to 4873H with Register Pair HL as the result.
485D
INC C 0C
INCrement Register C (the position in the sector)...
485E
DEC C 0D
...and DECrement it again: the pair only sets the Z FLAG from Register C, set when the position is 0.
485F
If the Z FLAG is set (the position in Register C is 0), JUMP to 4862H.
4861
DEC HL 2B
DECrement Register Pair HL: the bytes of the position are in the sector before.
4862
GOSUB to 4BA9H to divide Register Pair HL (the sector) by Register A (the record length): Register Pair HL = the quotient, Register A = the remainder.
4865
LD B,L 45
Copy Register L (the quotient's low byte) into Register B.
4866
LD D,H 54
Copy Register H (the quotient's high byte) into Register D.
4867
LD H,A 67
Copy Register A (the remainder) into Register H.
4868
LD L,C 69
Copy Register C (the position in the sector) into Register L. Register Pair HL = the remainder x 256 + the position: the bytes left over.
4869
LD A,E 7B
Copy Register E (the record length) into Register A.
486A
GOSUB to 4BA9H to divide Register Pair HL (the bytes left over) by Register A (the record length): Register L = the records in them, Register A = the bytes of a partial record.
486D
LD H,B 60
Copy Register B (the first quotient's low byte) into Register H. Register Pair HL = the record number (the first quotient x 256 + the second).
486E
OR A B7
Set the flags from Register A (OR A): the Z FLAG is set when no partial record is left.
486F
If the Z FLAG is set (no partial record), JUMP to 4872H.
4871
INC HL 23
INCrement Register Pair HL: a partial record counts as one.
4872
LD A,D 7A
Copy Register D (the first quotient's high byte) into Register A.
4873
POP BC C1
Restore the prologue's return address (4A14H) from the stack into Register Pair BC.
4874
EX (SP),HL E3
Exchange Register Pair HL (the result) with the top of the stack (the Stack Pointer is not changed): the result replaces the saved Register Pair BC, and the caller's Register Pair BC comes into Register Pair HL.
4875
PUSH BC C5
Save Register Pair BC (4A14H) back on the stack, so the RET below goes to the prologue's restore, which gives the result in Register Pair BC.
4876
OR A B7
Set the flags from Register A (OR A). SYS5/SYS (DEBUG) calls 4876H through 4310H as the default for an unknown command.
4877
RET C9
RETurn: to 4A14H after @LOC and @LOF, or to SYS5/SYS.
4878
@LOF: GOSUB to 49F3H, the file prologue (Index Register IX = the file control block, Register A = 00H).
487B
LD L,(IX+0CH) DD 6E 0C
Fetch byte +0CH of the file control block at Index Register IX into Register L: the ending record number's low byte.
487E
LD H,(IX+0DH) DD 66 0D
Fetch byte +0DH of the file control block at Index Register IX into Register H. Register Pair HL = the ending record number.
4881
LD C,(IX+08H) DD 4E 08
Fetch byte +08H of the file control block at Index Register IX into Register C: the end of file byte.
4884
JUMP to 4856H to turn the end of file in Register Pair HL and Register C into records.

4886H - @WEOF: Write the End of File to the Directory

Writes the buffer if it changed, then reads the file's directory record (drive +06H, record number +07H) and stores the end of file byte (record +03H) and the ending record number (record +14H-+15H) from the file control block. 49EDH enters at 488CH after a write when bit 3 of +01H asks for it.

4886
@WEOF: GOSUB to 49F3H, the file prologue (Index Register IX = the file control block, Register A = 00H).
4889
GOSUB to 4993H to write the buffer back if the file is in byte mode and the buffer was changed.
488C
LD B,(IX+07H) DD 46 07
Fetch byte +07H of the file control block at Index Register IX into Register B: the number of the file's directory record.
488F
LD C,(IX+06H) DD 4E 06
Fetch byte +06H of the file control block at Index Register IX into Register C: the file's drive.
4892
GOSUB to 4B10H (DIRRD) to read the directory sector of record Register B on drive Register C into 4200H; Register Pair HL comes back pointing at the record.
4895
RET NZ C0
If the NZ FLAG is set (the directory could not be read), RETurn with the error number in Register A (11H).
4896
INC L 2C
INCrement Register L: Register Pair HL points at record +01H.
4897
INC L 2C
INCrement Register L: Register Pair HL points at record +02H.
4898
INC L 2C
INCrement Register L: record +03H, the end of file byte.
4899
LD A,(IX+08H) DD 7E 08
Fetch byte +08H of the file control block at Index Register IX into Register A: the end of file byte.
489C
LD (HL),A 77
Store Register A (the end of file byte) into the directory record at Register Pair HL (+03H).
489D
LD DE,0011H 11 11 00
Load Register Pair DE with 0011H, the distance from +03H to +14H.
48A0
ADD HL,DE 19
ADD Register Pair DE to Register Pair HL: Register Pair HL points at record +14H, the ending record number.
48A1
LD A,(IX+0CH) DD 7E 0C
Fetch byte +0CH of the file control block at Index Register IX into Register A: the low byte of the ending record number.
48A4
LD (HL),A 77
Store Register A into the directory record at Register Pair HL (+14H).
48A5
INC HL 23
INCrement Register Pair HL to record +15H, the high byte of the ending record number.
48A6
LD A,(IX+0DH) DD 7E 0D
Fetch byte +0DH of the file control block at Index Register IX into Register A: the high byte of the ending record number.
48A9
LD (HL),A 77
Store Register A into the directory record at Register Pair HL (+15H).
48AA
JUMP to 4B1FH (DIRWR) to write the directory sector back and check it; its result is the result of the call.

48ADH - @READ, @WRITE and @VER

48ADH reads the next record: with 256 byte records the next sector is read into the file's buffer (494FH); with shorter records the record's bytes are taken one by one into the record area at Register Pair HL. 48CBH writes the next record the same way (from the buffer, 49ABH, or byte by byte from Register Pair HL), and 48E6H does the same with the verify switch (49CFH) on.

48AD
@READ: GOSUB to 49F3H, the file prologue (Index Register IX = the file control block, Register A = 00H).
48B0
PUSH HL E5
Save Register Pair HL (the caller's record area) to the stack.
48B1
GOSUB to 4993H to write the buffer back if the file is in byte mode and the buffer was changed.
48B4
POP HL E1
Restore Register Pair HL (the record area) from the stack.
48B5
RET NZ C0
If the NZ FLAG is set (the write failed), RETurn with the error number in Register A.
48B6
LD B,(IX+09H) DD 46 09
Fetch byte +09H of the file control block at Index Register IX into Register B: the record length (0 for 256).
48B9
LD A,B 78
Copy Register B (the record length) into Register A.
48BA
OR A B7
Set the flags from Register A (OR A): the Z FLAG is set for 256 byte records.
48BB
If the Z FLAG is set (256 byte records), JUMP to 494FH to read the next sector into the file's buffer.
48BE
PUSH HL E5
Save Register Pair HL (the record area pointer) to the stack: the byte fetch changes it. 48C8H loops back here.
48BF
PUSH BC C5
Save Register Pair BC (Register B = the bytes left in the record) to the stack.
48C0
GOSUB to 48FCH to take the next byte of the file into Register A (reading the next sector when the buffer is used up).
48C3
POP BC C1
Restore Register Pair BC (Register B = the bytes left) from the stack.
48C4
POP HL E1
Restore Register Pair HL (the record area pointer) from the stack.
48C5
RET NZ C0
If the NZ FLAG is set (the end of file or a read error), RETurn with the error number in Register A.
48C6
LD (HL),A 77
Store Register A (the byte) into the record area at Register Pair HL.
48C7
INC HL 23
INCrement Register Pair HL to the next byte of the record area.
48C8
DECrement Register B (the bytes left) and LOOP BACK to 48BEH until the record is complete.
48CA
RET C9
RETurn with Register A from the last fetch (00H) and the Z FLAG set.
48CB
@WRITE: GOSUB to 49F3H, the file prologue (Index Register IX = the file control block, Register A = 00H). @VER joins at 48CEH with Register A = 01H.
48CE
LD (49CFH),A 32 CF 49
Store Register A (00H, or 01H from @VER) at 49CFH, the operand of the LD A at 49CEH: the switch that makes 49B8H verify each sector it writes.
48D1
LD B,(IX+09H) DD 46 09
Fetch byte +09H of the file control block at Index Register IX into Register B: the record length (0 for 256).
48D4
LD A,B 78
Copy Register B (the record length) into Register A.
48D5
OR A B7
Set the flags from Register A (OR A): the Z FLAG is set for 256 byte records.
48D6
If the Z FLAG is set (256 byte records), JUMP to 49ABH to write the file's buffer as the next sector.
48D9
LD A,(HL) 7E
Fetch the next byte of the record from the record area at Register Pair HL into Register A. 48E3H loops back here.
48DA
INC HL 23
INCrement Register Pair HL to the next byte of the record area.
48DB
PUSH HL E5
Save Register Pair HL (the record area pointer) to the stack.
48DC
PUSH BC C5
Save Register Pair BC (Register B = the bytes left) to the stack.
48DD
GOSUB to 4919H to put the byte in Register A into the file (writing the buffer out when it fills).
48E0
POP BC C1
Restore Register Pair BC (Register B = the bytes left) from the stack.
48E1
POP HL E1
Restore Register Pair HL (the record area pointer) from the stack.
48E2
RET NZ C0
If the NZ FLAG is set (the write failed), RETurn with the error number in Register A.
48E3
DECrement Register B (the bytes left) and LOOP BACK to 48D9H until the record is written.
48E5
RET C9
RETurn with Register A = 00H and the Z FLAG set.
48E6
@VER: GOSUB to 49F3H, the file prologue (Index Register IX = the file control block, Register A = 00H).
48E9
INC A 3C
INCrement Register A: Register A = 01H, the verify switch on.
48EA
JUMP to 48CEH to write the record with every sector verified.

48ECH - A File Used as a Device

@DVRHK (44D7H) comes here when a device's control block is an open file (type above 10H): Index Register IX = the file control block, Register B = the request (01H input, 02H output, 04H control), Register C = the character. The file is put into byte mode (bit 7 of +01H) and one byte is taken from it or put into it. 48FCH, the byte fetch, is also used by @READ.

48EC
PUSH IX DD E5
Save Index Register IX (the file control block) to the stack.
48EE
POP DE D1
Restore it into Register Pair DE: the prologue takes the control block in Register Pair DE.
48EF
GOSUB to 49F3H, the file prologue (checks that the file is open; Index Register IX = the file control block, Register A = 00H).
48F2
SET 7,(IX+01H) DD CB 01 FE
Set bit 7 of byte +01H of the file control block at Index Register IX: the file is now used in byte mode.
48F6
LD A,B 78
Copy Register B (the request) into Register A.
48F7
CP 02H FE 02
Compare Register A (the request) against 02H: the NO CARRY FLAG is set for output (02H) and control (04H).
48F9
LD A,C 79
Copy Register C (the character) into Register A. LD does not change the flags.
48FA
If the NO CARRY FLAG is set (output or control), JUMP to 4919H to put the byte in Register A into the file.
48FC
GOSUB to 4A1DH to test the end of file: the NZ FLAG is set (Register A = 1CH or 1DH) at or past the end. @READ calls 48FCH for each byte.
48FF
RET NZ C0
If the NZ FLAG is set (no more bytes), RETurn with the error number in Register A.
4900
BIT 5,(IX+01H) DD CB 01 6E
Test bit 5 of byte +01H of the file control block at Index Register IX: set when the buffer must be read first.
4904
If the NZ FLAG is set (the buffer must be read), GOSUB to 494FH to read the sector of the next record number into the buffer.
4907
RET NZ C0
If the NZ FLAG is set (the read failed), RETurn with the error number in Register A.
4908
GOSUB to 4985H: Register Pair DE = the address in the buffer of the next byte (the buffer +03H-+04H plus the position +05H).
490B
LD A,(DE) 1A
Fetch the byte at Register Pair DE into Register A: the next byte of the file.
490C
INC (IX+05H) DD 34 05
INCrement byte +05H of the file control block at Index Register IX, the position in the buffer. The Z FLAG is set when it wraps to 00H: the buffer is used up.
490F
If the Z FLAG is set (the last byte of the buffer was taken), GOSUB to 4914H to set bit 5: the next byte comes from the next sector.
4912
CP A BF
Compare Register A with itself: the Z FLAG is set (no error) and Register A keeps the byte.
4913
RET C9
RETurn with the byte in Register A and the Z FLAG set.
4914
SET 5,(IX+01H) DD CB 01 EE
Set bit 5 of byte +01H of the file control block at Index Register IX: the buffer must be read (the sector of the next record number) before the next byte is used.
4918
RET C9
RETurn to the caller with the flags as they were.

4919H - Put a Byte into a File

Puts the byte in Register A at the current position of the file at Index Register IX: reads the sector first if needed, stores the byte, marks the buffer changed (bit 4 of +01H), and moves the end of file (+08H, +0CH-+0DH) when the byte is at or past it, unless the file was positioned inside (bit 6 of +01H). When the buffer fills it is written out (49A1H).

4919
PUSH AF F5
Save Register Pair AF (Register A = the byte to put) to the stack.
491A
BIT 5,(IX+01H) DD CB 01 6E
Test bit 5 of byte +01H of the file control block at Index Register IX: set when the buffer must be read first.
491E
If the NZ FLAG is set (the buffer must be read), GOSUB to 4953H to read the sector of the next record number (without the end of file test). It returns with the Z FLAG set on success.
4921
If the Z FLAG is set (the buffer is ready), JUMP to 4926H to store the byte.
4923
EX (SP),HL E3
Exchange Register Pair HL with the top of the stack (the Stack Pointer is not changed): the saved Register Pair AF goes into Register Pair HL and the caller's Register Pair HL onto the stack.
4924
POP HL E1
Restore the caller's Register Pair HL from the stack. The byte is dropped; Register A keeps the error number.
4925
RET C9
RETurn with the error number in Register A and the NZ FLAG set.
4926
GOSUB to 4985H: Register Pair DE = the address in the buffer for the byte (the buffer +03H-+04H plus the position +05H).
4929
POP AF F1
Restore Register Pair AF (Register A = the byte) from the stack.
492A
LD (DE),A 12
Store Register A (the byte) into the buffer at Register Pair DE.
492B
SET 4,(IX+01H) DD CB 01 E6
Set bit 4 of byte +01H of the file control block at Index Register IX: the buffer has been changed and must be written.
492F
INC (IX+05H) DD 34 05
INCrement byte +05H of the file control block at Index Register IX, the position in the buffer. The Z FLAG is set when it wraps to 00H: the buffer is full.
4932
PUSH AF F5
Save Register Pair AF (the Z FLAG = the buffer is full) to the stack.
4933
If the Z FLAG is set (the buffer is full), GOSUB to 4914H to set bit 5 for the next byte.
4936
GOSUB to 4A1DH to compare the new position with the end of file: the NZ FLAG is set at or past the end, and Register Pair HL comes back as the next record number and Register C as the position in the buffer.
4939
If the NZ FLAG is set (the byte was written at or past the end), JUMP to 4941H to move the end of file to this position.
493B
BIT 6,(IX+01H) DD CB 01 76
Test bit 6 of byte +01H of the file control block at Index Register IX: set when the file has been positioned.
493F
If the NZ FLAG is set (positioned inside the file), JUMP to 494AH, keeping the end of file.
4941
LD (IX+08H),C DD 71 08
Store Register C (the position in the buffer) into byte +08H of the file control block at Index Register IX, the end of file byte.
4944
LD (IX+0CH),L DD 75 0C
Store Register L (the next record number's low byte) into byte +0CH of the file control block at Index Register IX.
4947
LD (IX+0DH),H DD 74 0D
Store Register H (the next record number's high byte) into byte +0DH of the file control block at Index Register IX: the ending record number.
494A
POP AF F1
Restore Register Pair AF (the Z FLAG = the buffer is full) from the stack.
494B
If the Z FLAG is set (the buffer is full), JUMP to 49A1H to write it to its sector.
494D
XOR A AF
Set Register A to 00H (XOR A) with the Z FLAG set: the byte is stored.
494E
RET C9
RETurn to the caller with the byte stored in the buffer.

494FH - Read the Sector of the Next Record Number

494FH tests the end of file first; 4953H does not. The file's access (bits 2-0 of +01H) must allow reading (below 6, else error 25H). The next record number is turned into a cylinder and sector (4A41H, which allocates space when needed), the sector is read into the buffer through RDSECT (4777H), bit 5 is cleared and the next record number goes up by one. A sector with the deleted data mark (error 06H) is accepted.

494F
GOSUB to 4A1DH to test the end of file: the NZ FLAG is set (Register A = 1CH or 1DH) at or past it.
4952
RET NZ C0
If the NZ FLAG is set (at or past the end), RETurn with the error number in Register A.
4953
LD A,(IX+01H) DD 7E 01
Fetch byte +01H of the file control block at Index Register IX into Register A.
4956
AND 07H E6 07
Mask Register A to bits 2-0: the access the file was opened with (0 the most, 7 none).
4958
CP 06H FE 06
Compare Register A (the access) against 06H, the first value that forbids reading.
495A
If the CARRY FLAG is set (the access is below 6: reading is allowed), JUMP to 495EH.
495C
JUMP to 49B4H to return error 25H, illegal access to a protected file.
495E
GOSUB to 4A41H to work out the cylinder (Register D) and sector (Register E) of the next record number on drive Register C, asking SYS8/SYS for space when the file has none there.
4961
RET NZ C0
If the NZ FLAG is set (no such sector), RETurn with the error number in Register A.
4962
RES 5,(IX+01H) DD CB 01 AE
Clear bit 5 of byte +01H of the file control block at Index Register IX: the buffer is being filled.
4966
LD L,(IX+03H) DD 6E 03
Fetch byte +03H of the file control block at Index Register IX into Register L: the buffer address's low byte.
4969
LD H,(IX+04H) DD 66 04
Fetch byte +04H of the file control block at Index Register IX into Register H. Register Pair HL = the file's buffer.
496C
GOSUB to 4777H (RDSECT) to read cylinder Register D, sector Register E of drive Register C into the buffer at Register Pair HL.
496F
If the Z FLAG is set (the sector was read), JUMP to 4974H to count it.
4971
CP 06H FE 06
Compare Register A (the error number) against 06H: a sector with the deleted data mark (a directory or system sector) was read.
4973
RET NZ C0
If the NZ FLAG is set (another error), RETurn with the error number in Register A.
4974
INC (IX+0AH) DD 34 0A
INCrement byte +0AH of the file control block at Index Register IX, the next record number's low byte. 49D5H calls this entry after a write.
4977
If the NZ FLAG is set (no carry out of the low byte), JUMP to 497CH.
4979
INC (IX+0BH) DD 34 0B
INCrement byte +0BH of the file control block at Index Register IX, the next record number's high byte.
497C
XOR A AF
Set Register A to 00H (XOR A) with the Z FLAG set: success.
497D
RET C9
RETurn to the caller with Register A = 00H and the Z FLAG set.
497E
LD L,(IX+0AH) DD 6E 0A
Fetch byte +0AH of the file control block at Index Register IX into Register L: the next record number's low byte.
4981
LD H,(IX+0BH) DD 66 0B
Fetch byte +0BH of the file control block at Index Register IX into Register H. Register Pair HL = the next record number.
4984
RET C9
RETurn with the next record number in Register Pair HL.
4985
LD A,(IX+05H) DD 7E 05
Fetch byte +05H of the file control block at Index Register IX into Register A: the position in the buffer.
4988
ADD A,(IX+03H) DD 86 03
ADD byte +03H of the file control block at Index Register IX (the buffer address's low byte) to Register A.
498B
LD E,A 5F
Copy Register A (the low byte of the byte's address) into Register E.
498C
LD A,(IX+04H) DD 7E 04
Fetch byte +04H of the file control block at Index Register IX into Register A: the buffer address's high byte.
498F
ADC A,00H CE 00
ADD the CARRY FLAG from the addition above to Register A (ADC A,00H).
4991
LD D,A 57
Copy Register A into Register D. Register Pair DE = the buffer + the position: the address of the current byte.
4992
RET C9
RETurn with the byte's address in Register Pair DE.

4993H - Write the Buffer When It Was Changed

4993H writes the buffer to the sector before the next record number only when the file is in byte mode (bit 7 of +01H) and the buffer was changed (bit 4); 499EH (@RWRIT) always writes it, 49A1H writes it after the prologue and 49ABH writes it as the next sector. The access (bits 2-0 of +01H) must allow writing (below 5, else error 25H). After the write (and a verify when 49CFH is 01H) the next record number goes up by one; when the write was at or past the end of file and the file was not positioned inside, the ending record number moves up, and bit 3 of +01H makes the directory record follow at once (488CH).

4993
LD A,(IX+01H) DD 7E 01
Fetch byte +01H of the file control block at Index Register IX into Register A.
4996
AND 90H E6 90
Mask Register A to bits 7 and 4: byte mode and buffer changed.
4998
CP 90H FE 90
Compare Register A against 90H: the Z FLAG is set when both bits are on.
499A
If the Z FLAG is set (a changed buffer of a file in byte mode), JUMP to 49A1H to write it.
499C
JUMP to 497CH to return Register A = 00H and the Z FLAG: nothing to write.
499E
@RWRIT: GOSUB to 49F3H, the file prologue (Index Register IX = the file control block, Register A = 00H).
49A1
GOSUB to 497EH: Register Pair HL = the next record number.
49A4
DEC HL 2B
DECrement Register Pair HL: the sector the buffer holds.
49A5
LD (IX+0AH),L DD 75 0A
Store Register L into byte +0AH of the file control block at Index Register IX.
49A8
LD (IX+0BH),H DD 74 0B
Store Register H into byte +0BH of the file control block at Index Register IX: the next record number is now the buffer's sector, which is written below.
49AB
LD A,(IX+01H) DD 7E 01
Fetch byte +01H of the file control block at Index Register IX into Register A. @WRITE joins here for 256 byte records.
49AE
AND 07H E6 07
Mask Register A to bits 2-0: the access the file was opened with.
49B0
CP 05H FE 05
Compare Register A (the access) against 05H, the first value that forbids writing.
49B2
If the CARRY FLAG is set (the access is below 5: writing is allowed), JUMP to 49B8H.
49B4
LD A,25H 3E 25
Load Register A with 25H, error 37: illegal access attempted to protected file. 495CH comes here for a read that is not allowed.
49B6
OR A B7
Set the flags from Register A (OR A): the NZ FLAG is set.
49B7
RET C9
RETurn with the error number in Register A (25H) and the NZ FLAG set.
49B8
GOSUB to 4A41H to work out the cylinder (Register D) and sector (Register E) of the next record number on drive Register C, allocating space through SYS8/SYS when the file has none there.
49BB
RET NZ C0
If the NZ FLAG is set (no space or a read error of the allocation table), RETurn with the error number in Register A.
49BC
LD L,(IX+03H) DD 6E 03
Fetch byte +03H of the file control block at Index Register IX into Register L: the buffer address's low byte.
49BF
LD H,(IX+04H) DD 66 04
Fetch byte +04H of the file control block at Index Register IX into Register H. Register Pair HL = the file's buffer.
49C2
RES 4,(IX+01H) DD CB 01 A6
Clear bit 4 of byte +01H of the file control block at Index Register IX: the buffer is about to be written, so it is no longer changed.
49C6
SET 2,(IX+00H) DD CB 00 D6
Set bit 2 of byte +00H of the file control block at Index Register IX: the file has been written, so SYS3/SYS stamps its date when it is closed.
49CA
GOSUB to 4763H (WRSECT) to write the buffer at Register Pair HL to cylinder Register D, sector Register E of drive Register C.
49CD
RET NZ C0
If the NZ FLAG is set (the write failed), RETurn with the error number in Register A.
49CE
LD A,00H 3E 00
Load Register A with the verify switch: the operand at 49CFH is 00H in the file; @WRITE stores 00H and @VER 01H there (48CEH).
49D0
OR A B7
Set the flags from Register A (OR A): the NZ FLAG is set when the sector is to be verified.
49D1
If the NZ FLAG is set (verify), GOSUB to 4772H (VERSEC) to read the sector just written back without storing it.
49D4
RET NZ C0
If the NZ FLAG is set (the verify failed), RETurn with the error number in Register A.
49D5
GOSUB to 4974H to count the sector: the next record number goes up by one.
49D8
GOSUB to 4A1DH to compare the position with the end of file: Register A = 00H before it, 1CH at it, 1DH past it; Register Pair HL = the next record number.
49DB
DEC A 3D
DECrement Register A: FFH before the end of file, 1BH or 1CH at or past it.
49DC
AND (IX+01H) DD A6 01
AND byte +01H of the file control block at Index Register IX into Register A: before the end, Register A keeps the flags of +01H.
49DF
AND 40H E6 40
Mask Register A to bit 6: the Z FLAG is clear only when the write was before the end of file of a positioned file.
49E1
If the NZ FLAG is set (a positioned file written inside its end), JUMP to 497CH to return success without moving the end.
49E3
LD (IX+0CH),L DD 75 0C
Store Register L (the next record number's low byte) into byte +0CH of the file control block at Index Register IX.
49E6
LD (IX+0DH),H DD 74 0D
Store Register H (its high byte) into byte +0DH of the file control block at Index Register IX: the ending record number is now the next record number.
49E9
BIT 3,(IX+01H) DD CB 01 5E
Test bit 3 of byte +01H of the file control block at Index Register IX: set when the directory must follow every change of the end.
49ED
If the NZ FLAG is set (bit 3 on), GOSUB to 488CH to write the end of file into the directory record now.
49F0
RET C9
RETurn with the result of the write (or of the directory update) in Register A.

49F1H - The File Prologue

Every file routine calls 49F3H first (49F1H skips the open test). Register Pair DE = the file control block. 49F3H loads byte +00H and rotates bit 7 (open) into the CARRY FLAG; 49F1H sets the CARRY FLAG instead (the JP NC that follows it is never taken: its bytes 1AH 07H are the LD A,(DE) / RLCA of 49F3H). The routine notes the caller's address in JRET$ (430CH) and the control block in JDCB$ (430AH), returns error 26H (file not open) when bit 7 is clear, and otherwise points Index Register IX at the block, saves Register Pairs BC, DE and HL and Index Register IX under the caller's return address with 4A14H on top, and returns with Register A = 00H. The caller's final RET then goes to 4A14H, which restores them.

49F1
SCF 37
Set the CARRY FLAG: the entry that does not test whether the file is open.
49F2
JP NC,071AH D2 1A 07
Jump to 071AH if the NO CARRY FLAG is set. Never taken from 49F1H, where the CARRY FLAG was just set. Entered at 49F3H, the bytes 1AH 07H are LD A,(DE) (byte +00H of the control block at Register Pair DE into Register A) and RLCA (bit 7, open, into the CARRY FLAG): the normal entry.
49F5
EX (SP),HL E3
Exchange Register Pair HL with the top of the stack (the Stack Pointer is not changed): Register Pair HL = the address the prologue returns to (just after the caller's CALL 49F3H), and the caller's Register Pair HL is kept on the stack.
49F6
LD (430CH),HL 22 0C 43
Store Register Pair HL (the address after the CALL 49F3H in the file routine) at 430CH-430DH, JRET$, which SYS4/SYS reports for an error.
49F9
LD (430AH),DE ED 53 0A 43
Store Register Pair DE (the file control block) at 430AH-430BH, JDCB$, so SYS4/SYS can name the file in an error message.
49FD
EX (SP),HL E3
Exchange Register Pair HL with the word at the top of the stack again (the Stack Pointer is not changed): the caller's Register Pair HL comes back and the return address is on top.
49FE
If the NO CARRY FLAG is set (bit 7 of byte +00H clear: the file is not open), JUMP to 4A0FH to return error 26H.
4A00
POP AF F1
Take the return address off the stack into Register Pair AF: it is put back at 4A0CH above the saved registers.
4A01
PUSH DE D5
Save Register Pair DE (the file control block) to the stack.
4A02
EX (SP),IX DD E3
Exchange Index Register IX with the top of the stack (the Stack Pointer is not changed): Index Register IX = the file control block, and the caller's Index Register IX is kept on the stack.
4A04
PUSH HL E5
Save the caller's Register Pair HL to the stack.
4A05
PUSH DE D5
Save the caller's Register Pair DE to the stack.
4A06
PUSH BC C5
Save the caller's Register Pair BC to the stack.
4A07
PUSH HL E5
Save Register Pair HL to the stack as a place for 4A14H.
4A08
LD HL,4A14H 21 14 4A
Load Register Pair HL with 4A14H, the routine that restores the saved registers.
4A0B
EX (SP),HL E3
Exchange Register Pair HL with the top of the stack (the Stack Pointer is not changed): 4A14H goes on the stack above the saved registers and the caller's Register Pair HL comes back.
4A0C
PUSH AF F5
Save Register Pair AF (the return address taken off at 4A00H) to the stack again, on top.
4A0D
XOR A AF
Set Register A to 00H (XOR A) with the Z FLAG set.
4A0E
RET C9
RETurn into the file routine (after its CALL 49F3H) with Index Register IX = the file control block and Register A = 00H. Its own RET goes to 4A14H.
4A0F
POP AF F1
Discard the return address into Register Pair AF: the file routine is not continued.
4A10
LD A,26H 3E 26
Load Register A with 26H, error 38: file not open.
4A12
OR A B7
Set the flags from Register A (OR A): the NZ FLAG is set.
4A13
RET C9
RETurn with the error number in Register A straight to the program that called the file routine.
4A14
POP BC C1
Restore the caller's Register Pair BC from the stack (@LOC and @LOF have put their result here, 4873H-4875H).
4A15
POP DE D1
Restore the caller's Register Pair DE from the stack.
4A16
POP HL E1
Restore the caller's Register Pair HL from the stack.
4A17
POP IX DD E1
Restore the caller's Index Register IX from the stack.
4A19
RET C9
RETurn to the program that called the file routine, with Register A and the flags from the routine.

4A1AH - @CKEOF: Test the End of File

4A1AH (@CKEOF) runs the prologue first; 4A1DH is called by the file routines. It compares the current position (the sector worked out from the next record number by 4D8FH, and the byte position +05H) with the ending record number (+0CH-+0DH) and the end of file byte (+08H). Returns Register A = 00H with the Z FLAG before the end, 1CH (error 28, end of file encountered) at the end, 1DH (error 29, record number out of range) past it, with the NZ FLAG. Register Pair HL comes back as the next record number and Register C as the position in the buffer.

4A1A
@CKEOF: GOSUB to 49F3H, the file prologue (Index Register IX = the file control block, Register A = 00H).
4A1D
GOSUB to 497EH: Register Pair HL = the next record number (+0AH-+0BH).
4A20
GOSUB to 4D8FH: it saves Register Pair HL (the next record number) on the stack under the return address, loads Register C with the position in the buffer and adjusts Register Pair HL to the sector of the current position.
4A23
LD A,H 7C
Copy Register H (the current sector's high byte) into Register A.
4A24
CP (IX+0DH) DD BE 0D
Compare Register A against byte +0DH of the file control block at Index Register IX, the ending record number's high byte.
4A27
If the NZ FLAG is set (the high bytes differ; the CARRY FLAG says the position is before the end), JUMP to 4A37H.
4A29
LD A,L 7D
Copy Register L (the current sector's low byte) into Register A.
4A2A
CP (IX+0CH) DD BE 0C
Compare Register A against byte +0CH of the file control block at Index Register IX, the ending record number's low byte.
4A2D
If the NZ FLAG is set (the sectors differ; the CARRY FLAG says before the end), JUMP to 4A37H.
4A2F
DEC C 0D
DECrement Register C (the position in the buffer): a position of 00H becomes FFH, the last byte of a full sector.
4A30
LD A,(IX+08H) DD 7E 08
Fetch byte +08H of the file control block at Index Register IX into Register A: the end of file byte.
4A33
DEC A 3D
DECrement Register A in the same way (00H becomes FFH).
4A34
SUB C 91
SUBtract Register C from Register A: the Z FLAG is set when the position is the end of file byte, the CARRY FLAG when the position is past it.
4A35
CCF 3F
Flip the CARRY FLAG (CCF): it is now set when the position is before the end of file byte.
4A36
INC BC 03
INCrement Register Pair BC: Register C holds the position again (INC BC does not change the flags).
4A37
POP HL E1
Restore Register Pair HL from the stack: the next record number saved by 4D8FH.
4A38
LD A,1DH 3E 1D
Load Register A with 1DH, error 29: record number out of range. LD does not change the flags.
4A3A
If the NZ FLAG is set (the position is not the end itself), JUMP to 4A3EH.
4A3C
DEC A 3D
DECrement Register A: 1CH, error 28: end of file encountered (the NZ FLAG is set).
4A3D
RET C9
RETurn with Register A = 1CH: the position is the end of the file.
4A3E
RET NC D0
If the NO CARRY FLAG is set (the position is past the end), RETurn with Register A = 1DH and the NZ FLAG.
4A3F
XOR A AF
Set Register A to 00H (XOR A) with the Z FLAG set: the position is before the end.
4A40
RET C9
RETurn with Register A = 00H and the Z FLAG set: before the end of file.

4A41H - Find the Sector of the Next Record Number

Turns the next record number (+0AH-+0BH) of the file at Index Register IX into a cylinder (Register D) and sector (Register E) on drive Register C. The record number divided by the sectors in a granule gives the file's granule and the sector in it (kept in the operand at 4B0CH). The file's extents are searched in the control block (+0EH-+1FH: the first extent at +0EH-+0FH starting at granule 0, then four entries of a starting granule word, a cylinder and a granule byte); an entry not in use has FFH as its cylinder. When the granule is in none of them, SYS8/SYS (request 9AH, @ALLOC) finds or allocates it and updates the entries. A hit in the third to fifth entry is moved to the second entry. The granule then becomes a cylinder (granules a cylinder from byte +08H and +04H bit 5 of the drive code table) and a sector. Returns with Register A = 00H and the Z FLAG set, or with the error number from SYS8/SYS.

4A41
GOSUB to 497EH: Register Pair HL = the next record number (+0AH-+0BH) of the file at Index Register IX.
4A44
GOSUB to 4797H: Register C = the file's drive (+06H) and Register A = byte +08H of its drive code table (bits 4-0 the sectors in a granule less one).
4A47
AND 1FH E6 1F
Mask Register A to bits 4-0: the sectors in a granule less one.
4A49
INC A 3C
INCrement Register A: the sectors in a granule.
4A4A
GOSUB to 4BA9H to divide Register Pair HL (the record number) by Register A (the sectors in a granule): Register Pair HL = the granule of the file, Register A = the sector within it.
4A4D
LD (4B0CH),A 32 0C 4B
Store Register A (the sector within the granule) at 4B0CH, the operand of the ADD A at 4B0BH.
4A50
PUSH IX DD E5
Save Index Register IX (the file control block) to the stack.
4A52
EX (SP),HL E3
Exchange Register Pair HL with the top of the stack (the Stack Pointer is not changed): Register Pair HL = the file control block, and the granule number goes onto the stack.
4A53
LD BC,000EH 01 0E 00
Load Register Pair BC with 000EH, the offset of the extents in the control block.
4A56
ADD HL,BC 09
ADD Register Pair BC to Register Pair HL: Register Pair HL points at +0EH, the first extent.
4A57
POP BC C1
Restore the granule number from the stack into Register Pair BC: the granule of the file wanted.
4A58
LD A,05H 3E 05
Load Register A with 05H, the five extent slots.
4A5A
LD DE,0000H 11 00 00
Load Register Pair DE with 0000H: the first extent starts at granule 0 of the file.
4A5D
PUSH AF F5
Save Register Pair AF (Register A = the slots left) to the stack. 4A77H loops back here.
4A5E
LD A,(HL) 7E
Fetch the slot's cylinder byte at Register Pair HL into Register A.
4A5F
INC HL 23
INCrement Register Pair HL to the slot's granule byte.
4A60
INC A 3C
INCrement Register A: the Z FLAG is set when the cylinder byte was FFH, a slot not in use.
4A61
If the Z FLAG is set (the slot is not in use), JUMP to 4A6EH to go on to the next slot.
4A63
PUSH HL E5
Save Register Pair HL (the slot's granule byte) to the stack.
4A64
LD H,D 62
Copy Register D (the high byte of the slot's starting granule) into Register H.
4A65
LD L,E 6B
Copy Register E (its low byte) into Register L. Register Pair HL = the granule of the file where this extent starts.
4A66
XOR A AF
Set Register A to 00H (XOR A), which clears the CARRY FLAG for the SBC.
4A67
SBC HL,BC ED 42
SUBtract Register Pair BC (the granule wanted) from Register Pair HL (the extent's start): the CARRY FLAG is set when the wanted granule is at or beyond the start plus one, the Z FLAG when it is the extent's first granule.
4A69
If the CARRY FLAG is set (the wanted granule is past the extent's first), JUMP to 4A79H to see whether it is inside the extent.
4A6B
POP HL E1
Restore Register Pair HL (the slot's granule byte) from the stack.
4A6C
If the Z FLAG is set (the wanted granule is the extent's first: Register A = 00H, its offset), JUMP to 4AB6H.
4A6E
INC HL 23
INCrement Register Pair HL to the next slot's starting granule word. 4A86H and 4A7CH come back here.
4A6F
POP AF F1
Restore Register Pair AF (Register A = the slots left) from the stack.
4A70
DEC A 3D
DECrement Register A, the slots left to search.
4A71
If the Z FLAG is set (all five slots searched), JUMP to 4A8CH to ask SYS8/SYS.
4A73
LD E,(HL) 5E
Fetch the low byte of the next slot's starting granule at Register Pair HL into Register E.
4A74
INC HL 23
INCrement Register Pair HL to the high byte of the starting granule.
4A75
LD D,(HL) 56
Fetch the high byte at Register Pair HL into Register D. Register Pair DE = the granule of the file where the next slot's extent starts.
4A76
INC HL 23
INCrement Register Pair HL to the next slot's cylinder byte.
4A77
LOOP BACK to 4A5DH to look at the next slot at Register Pair HL.
4A79
INC H 24
INCrement Register H: the Z FLAG is set when the difference (the start less the wanted granule) is FF00H-FFFFH, a distance of 1-256.
4A7A
LD A,L 7D
Copy Register L (the low byte of the difference) into Register A.
4A7B
POP HL E1
Restore Register Pair HL (the slot's granule byte) from the stack.
4A7C
If the NZ FLAG is set (the wanted granule is more than 256 past the start), JUMP to 4A6EH for the next slot.
4A7E
PUSH DE D5
Save Register Pair DE (the extent's start) to the stack.
4A7F
LD E,A 5F
Copy Register A (the negative distance) into Register E.
4A80
LD A,(HL) 7E
Fetch the slot's granule byte at Register Pair HL into Register A.
4A81
AND 1FH E6 1F
Mask Register A to bits 4-0: the granules of the extent less one.
4A83
ADD A,E 83
ADD Register E (minus the distance from the start) to Register A: the CARRY FLAG is set when the distance is within the granules of the extent.
4A84
LD A,E 7B
Copy Register E (minus the distance) into Register A. LD does not change the flags.
4A85
POP DE D1
Restore Register Pair DE (the extent's start) from the stack.
4A86
If the NO CARRY FLAG is set (the granule is past this extent), JUMP to 4A6EH for the next slot.
4A88
NEG ED 44
Negate Register A: Register A = the distance, the granule's offset in the extent.
4A8A
JUMP to 4AB6H with the granule's offset in the extent in Register A.
4A8C
LD A,(4B0CH) 3A 0C 4B
Fetch the sector within the granule from 4B0CH into Register A: the SYS8/SYS call below can load a file and change it.
4A8F
LD (4AABH),A 32 AB 4A
Store Register A (the sector within the granule) at 4AABH, the operand of the LD A at 4AAAH, to be put back afterwards.
4A92
LD A,(430EH) 3A 0E 43
Fetch OVRLY$ from 430EH into Register A: the request code of the system file now at 4E00H.
4A95
LD (4A9DH),A 32 9D 4A
Store Register A (that request code) at 4A9DH, the operand of the LD A at 4A9CH, to reload the file afterwards.
4A98
GOSUB to 4AB3H, which issues request 9AH: SYS8/SYS (@ALLOC) finds the granule Register Pair BC of the file at Index Register IX, allocating space when needed. It returns Register A = the granule's offset in its extent, Register Pair HL = the extent (Register H the granule byte, Register L the cylinder), and the CARRY FLAG set when it has made room in the first slot (Register Pairs BC and DE to be stored there).
4A9B
PUSH AF F5
Save Register Pair AF (SYS8/SYS's result and flags) to the stack.
4A9C
LD A,00H 3E 00
Load Register A with the request code saved at 4A9DH (00H in the file): the system file that was at 4E00H before SYS8/SYS was loaded over it.
4A9E
AND 8FH E6 8F
Mask Register A (the request code) to bits 7 and 3-0, dropping the function bits 6-4.
4AA0
CP 83H FE 83
Compare Register A against 83H: the Z FLAG is set when the file was SYS1/SYS (request codes 83H-0F3H of file 3).
4AA2
If the Z FLAG is set (SYS1/SYS had been loaded), GOSUB to 4AB5H to issue the RST 28H with the request code in Register A and load SYS1/SYS again, since the command interpreter must still be there when the program returns.
4AA5
POP AF F1
Restore Register Pair AF (SYS8/SYS's result and flags) from the stack.
4AA6
RET NZ C0
If the NZ FLAG is set (SYS8/SYS failed: no space, or the allocation table could not be read), RETurn with the error number in Register A.
4AA7
LD (4AE5H),A 32 E5 4A
Store Register A (the granule's offset in its extent) at 4AE5H, the operand of the ADD A at 4AE4H.
4AAA
LD A,00H 3E 00
Load Register A with the sector within the granule saved at 4AABH (00H in the file).
4AAC
LD (4B0CH),A 32 0C 4B
Store Register A at 4B0CH, the operand of the ADD A at 4B0BH, again.
4AAF
If the NO CARRY FLAG is set (SYS8/SYS updated a slot in place), JUMP to 4ADEH with the extent in Register Pair HL.
4AB1
JUMP to 4AD5H to store Register Pairs BC and DE in the first slot at Register Pair HL.
4AB3
LD A,9AH 3E 9A
Load Register A with 9AH, the request code of SYS8/SYS's function 10H, @ALLOC.
4AB5
RST 28H EF
RST 28H: call the supervisor dispatcher with the request code in Register A (9AH, or the request code of SYS1/SYS from 4AA2H).
4AB6
LD (4AE5H),A 32 E5 4A
Store Register A (the granule's offset in its extent) at 4AE5H, the operand of the ADD A at 4AE4H.
4AB9
LD B,(HL) 46
Fetch the slot's granule byte at Register Pair HL into Register B.
4ABA
DEC HL 2B
DECrement Register Pair HL to the slot's cylinder byte.
4ABB
LD C,(HL) 4E
Fetch the cylinder byte at Register Pair HL into Register C. Register Pair BC = the extent (Register B the granule byte, Register C the cylinder).
4ABC
INC HL 23
INCrement Register Pair HL back to the granule byte.
4ABD
POP AF F1
Restore Register Pair AF (Register A = the slots left when the hit was found: 5 for the first slot, 1 for the fifth) from the stack.
4ABE
CPL 2F
Complement Register A (CPL), the slots left: Register A = minus the slots left, less one.
4ABF
ADD A,04H C6 04
ADD 04H to Register A: Register A = 3 less the slots left. The NO CARRY FLAG is set for the first and second slots.
4AC1
If the NO CARRY FLAG is set (the hit is in the first or second slot), JUMP to 4ADCH, leaving the slots as they are.
4AC3
INC A 3C
INCrement Register A: 1, 2 or 3 for the third, fourth or fifth slot.
4AC4
RLCA 07
Rotate Register A left one bit: the count x 2.
4AC5
RLCA 07
Rotate Register A left one bit again: the count x 4, the bytes of the slots to move down.
4AC6
PUSH BC C5
Save Register Pair BC (the extent) to the stack.
4AC7
PUSH DE D5
Save Register Pair DE (the extent's starting granule) to the stack.
4AC8
LD C,A 4F
Copy Register A (the bytes to move) into Register C.
4AC9
LD B,00H 06 00
Load Register B with 00H. Register Pair BC = the byte count of the LDDR below.
4ACB
EX DE,HL EB
Exchange Register Pairs DE and HL: Register Pair DE = the hit slot's granule byte, the last byte to receive.
4ACC
LD HL,FFFCH 21 FC FF
Load Register Pair HL with FFFCH (minus 4), the size of one slot.
4ACF
ADD HL,DE 19
ADD Register Pair DE to Register Pair HL: Register Pair HL = the same byte of the slot before, the last byte to copy.
4AD0
LDDR ED B8
Copy Register Pair BC bytes downward from Register Pair HL to Register Pair DE (LDDR): the slots from the second up to the one before the hit move one slot on, over the hit slot.
4AD2
EX DE,HL EB
Exchange Register Pairs DE and HL: Register Pair HL = the second slot's granule byte, now free.
4AD3
POP DE D1
Restore Register Pair DE (the extent's starting granule) from the stack.
4AD4
POP BC C1
Restore Register Pair BC (the extent) from the stack.
4AD5
LD (HL),B 70
Store Register B (the granule byte) at Register Pair HL. 4AB1H joins here with SYS8/SYS's extent in Register Pairs BC and DE.
4AD6
DEC HL 2B
DECrement Register Pair HL to the cylinder byte.
4AD7
LD (HL),C 71
Store Register C (the cylinder) at Register Pair HL.
4AD8
DEC HL 2B
DECrement Register Pair HL to the high byte of the starting granule.
4AD9
LD (HL),D 72
Store Register D (the starting granule's high byte) at Register Pair HL.
4ADA
DEC HL 2B
DECrement Register Pair HL to the low byte of the starting granule.
4ADB
LD (HL),E 73
Store Register E (the starting granule's low byte) at Register Pair HL: the hit extent is now the second slot.
4ADC
LD H,B 60
Copy Register B (the granule byte) into Register H.
4ADD
LD L,C 69
Copy Register C (the cylinder) into Register L. Register Pair HL = the extent.
4ADE
LD A,H 7C
Copy Register H (the extent's granule byte) into Register A.
4ADF
RLCA 07
Rotate Register A left one bit: first of three rotations that bring the first granule from bits 7-5 to bits 2-0.
4AE0
RLCA 07
Rotate Register A left one bit again: second of three rotations.
4AE1
RLCA 07
Rotate Register A left one bit again: bits 7-5 are now bits 2-0.
4AE2
AND 07H E6 07
Mask Register A to bits 2-0: the extent's first granule on its cylinder.
4AE4
ADD A,00H C6 00
ADD the granule's offset in the extent to Register A: the operand at 4AE5H (00H in the file) is stored by 4AA7H or 4AB6H. Register A = the granule counted from the extent's cylinder.
4AE6
LD E,A 5F
Copy Register A (the granule from the extent's cylinder) into Register E.
4AE7
GOSUB to 4797H: Register C = the file's drive, Register A = byte +08H of its drive code table.
4AEA
PUSH AF F5
Save Register Pair AF (byte +08H) to the stack.
4AEB
RLCA 07
Rotate Register A left one bit: first of three rotations that bring bits 7-5 (the granules on a track less one) to bits 2-0.
4AEC
RLCA 07
Rotate Register A left one bit again: second of three rotations.
4AED
RLCA 07
Rotate Register A left one bit again: third rotation.
4AEE
AND 07H E6 07
Mask Register A to bits 2-0: the granules on a track less one.
4AF0
INC A 3C
INCrement Register A: the granules on a track.
4AF1
LD D,A 57
Copy Register A (the granules on a track) into Register D.
4AF2
LD A,04H 3E 04
Load Register A with 04H, the offset of byte +04H in the drive code table.
4AF4
GOSUB to 479CH (DCTBYT): Register A = byte +04H of drive Register C's table.
4AF7
BIT 5,A CB 6F
Test bit 5 of Register A: set for a drive with two sides.
4AF9
LD A,D 7A
Copy Register D (the granules on a track) into Register A. LD does not change the flags.
4AFA
If the Z FLAG is set (one side), JUMP to 4AFDH.
4AFC
RLCA 07
Rotate Register A left one bit: the granules on a cylinder of two sides.
4AFD
GOSUB to 4B7BH (DIVEA) to divide Register E (the granule from the extent's cylinder) by Register A (the granules on a cylinder): Register A = the cylinders to add, Register E = the granule on its cylinder.
4B00
ADD A,L 85
ADD Register L (the extent's cylinder) to Register A: the cylinder of the granule.
4B01
LD D,A 57
Copy Register A (the cylinder) into Register D.
4B02
POP AF F1
Restore Register Pair AF (byte +08H of the drive code table) from the stack.
4B03
AND 1FH E6 1F
Mask Register A to bits 4-0: the sectors in a granule less one.
4B05
INC A 3C
INCrement Register A: the sectors in a granule.
4B06
PUSH DE D5
Save Register Pair DE (Register D = the cylinder) to the stack: MULTEA uses Register D.
4B07
GOSUB to 4B6CH (MULTEA) to multiply Register A (the sectors in a granule) by Register E (the granule on its cylinder): Register A = the granule's first sector.
4B0A
POP DE D1
Restore Register Pair DE (Register D = the cylinder) from the stack.
4B0B
ADD A,00H C6 00
ADD the sector within the granule to Register A: the operand at 4B0CH (00H in the file) is stored by 4A4DH and 4AACH.
4B0D
LD E,A 5F
Copy Register A (the sector) into Register E. Register D = the cylinder, Register E = the sector, Register C = the drive.
4B0E
XOR A AF
Set Register A to 00H (XOR A) with the Z FLAG set: success.
4B0F
RET C9
RETurn with the cylinder and sector in Register Pair DE.

4B10H - DIRRD and DIRWR: Read and Write a Directory Sector

4B10H (DIRRD) reads the directory sector that holds record Register B of drive Register C into 4200H and returns Register Pair HL pointing at the record (error 11H, directory read error, on failure). 4B1FH (DIRWR) writes the sector at 4200H back with the deleted data mark and verifies it (error 12H, directory write error, or 0FH, write protected). Directory record B is the 32 byte slot (B AND E0H) of sector (B AND 1FH) + 2 of the directory cylinder. Register Pair DE is kept.

4B10
PUSH DE D5
DIRRD: Save the caller's Register Pair DE to the stack.
4B11
GOSUB to 4B37H: Register Pair HL = the record's address in the buffer (4200H + (B AND E0H)), Register D = the directory cylinder, Register E = the record's sector.
4B14
PUSH HL E5
Save Register Pair HL (the record's address) to the stack.
4B15
LD L,00H 2E 00
Load Register L with 00H: Register Pair HL = 4200H, the start of the buffer.
4B17
GOSUB to 4B45H (RDSSEC) to read cylinder Register D, sector Register E of drive Register C into the buffer at Register Pair HL. The Z FLAG is set on success.
4B1A
POP HL E1
Restore Register Pair HL (the record's address) from the stack.
4B1B
LD A,11H 3E 11
Load Register A with 11H, error 17: directory read error, in case the read failed. LD does not change the flags.
4B1D
POP DE D1
Restore the caller's Register Pair DE from the stack.
4B1E
RET C9
RETurn: the Z FLAG set and Register Pair HL at the record, or the NZ FLAG with Register A = 11H.
4B1F
PUSH DE D5
DIRWR: Save the caller's Register Pair DE to the stack.
4B20
GOSUB to 4B37H: Register D = the directory cylinder and Register E = the sector of record Register B (Register Pair HL is not needed).
4B23
LD L,00H 2E 00
Load Register L with 00H: Register Pair HL = 4200H, the buffer to write.
4B25
GOSUB to 4768H (WRPROT) to write the buffer to cylinder Register D, sector Register E of drive Register C with the deleted data mark that marks every directory sector.
4B28
If the Z FLAG is set (the write succeeded), GOSUB to 4772H (VERSEC) to read the sector back. A directory sector reads back with error 06H (the deleted data mark), which is the good result.
4B2B
SUB 06H D6 06
SUBtract 06H from Register A (the error number): Register A = 00H with the Z FLAG set when the verify gave 06H.
4B2D
POP DE D1
Restore the caller's Register Pair DE from the stack.
4B2E
RET Z C8
If the Z FLAG is set (written and verified), RETurn with Register A = 00H.
4B2F
CP 09H FE 09
Compare Register A (the error number less 6) against 09H: the Z FLAG is set when the error was 0FH, write protected.
4B31
LD A,12H 3E 12
Load Register A with 12H, error 18: directory write error. LD does not change the flags.
4B33
RET NZ C0
If the NZ FLAG is set (another error), RETurn with Register A = 12H.
4B34
SUB 03H D6 03
SUBtract 03H from Register A: Register A = 0FH, error 15, write protected disk (the NZ FLAG stays set).
4B36
RET C9
RETurn with Register A = 0FH (write protected) and the NZ FLAG.
4B37
GOSUB to 4B65H: Register D = the directory cylinder of drive Register C (byte +09H of its drive code table).
4B3A
LD A,B 78
Copy Register B (the directory record number) into Register A.
4B3B
AND E0H E6 E0
Mask Register A to bits 7-5: the record's slot in its sector times 32, its offset in the buffer.
4B3D
LD L,A 6F
Copy Register A (the offset) into Register L.
4B3E
LD H,42H 26 42
Load Register H with 42H. Register Pair HL = 4200H + the offset: where the record will be in the buffer.
4B40
XOR B A8
Exclusive OR Register B (the record number) into Register A (its bits 7-5): Register A = bits 4-0 of the record number, its sector less 2.
4B41
ADD A,02H C6 02
ADD 02H to Register A: the directory's records start at sector 2 (sector 0 is the allocation table and sector 1 the hash index table).
4B43
LD E,A 5F
Copy Register A (the record's sector) into Register E.
4B44
RET C9
RETurn with Register D = the cylinder, Register E = the sector and Register Pair HL = the record's address.

4B45H - RDSSEC: Read a Directory Sector

Reads cylinder Register D, sector Register E of drive Register C into the buffer at Register Pair HL and accepts it only when it carries the deleted data mark (read error 06H). When it does not, the diskette in the drive may have its directory on another cylinder: the boot sector (cylinder 0, sector 0) is read, byte 2 (the directory cylinder) is stored in the drive's code table (+09H) and the sector is read again from that cylinder. Returns the Z FLAG set on success; Register A = the read result less 6.

4B45
GOSUB to 4B5EH to read the sector and compare the result with 06H: the Z FLAG is set when it is a directory sector.
4B48
RET Z C8
If the Z FLAG is set (a directory sector was read), RETurn.
4B49
PUSH DE D5
Save Register Pair DE (the cylinder and sector wanted) to the stack.
4B4A
LD DE,0000H 11 00 00
Load Register Pair DE with 0000H: cylinder 0, sector 0, the boot sector.
4B4D
GOSUB to 4777H (RDSECT) to read the boot sector of drive Register C into the buffer at Register Pair HL.
4B50
POP DE D1
Restore Register Pair DE (the cylinder and sector wanted) from the stack.
4B51
RET NZ C0
If the NZ FLAG is set (the boot sector could not be read), RETurn with the error number in Register A.
4B52
PUSH HL E5
Save Register Pair HL (the buffer) to the stack.
4B53
INC HL 23
INCrement Register Pair HL to byte 1 of the boot sector.
4B54
INC HL 23
INCrement Register Pair HL to byte 2, the directory cylinder (the operand of the boot sector's CP at 4201H).
4B55
LD D,(HL) 56
Fetch the directory cylinder from Register Pair HL into Register D: the cylinder to read from now.
4B56
LD H,09H 26 09
Load Register H with 09H, the offset of the directory cylinder byte in the drive code table, for 47A5H.
4B58
GOSUB to 47A5H: Register A = the low byte of the address of byte +09H of drive Register C's table.
4B5B
LD L,A 6F
Copy Register A into Register L. Register H is 47H from 47A5H: Register Pair HL = the drive's directory cylinder byte.
4B5C
LD (HL),D 72
Store Register D (the directory cylinder of this diskette) into the drive code table at Register Pair HL (+09H).
4B5D
POP HL E1
Restore Register Pair HL (the buffer) from the stack.
4B5E
GOSUB to 4777H (RDSECT) to read cylinder Register D, sector Register E of drive Register C into the buffer at Register Pair HL.
4B61
SUB 06H D6 06
SUBtract 06H from Register A (the read's error number): the Z FLAG is set when it was 06H, a sector with the deleted data mark.
4B63
RET C9
RETurn with the Z FLAG set for a directory sector.
4B64
DEFB 00H 00
4B64H: 00H, a spare byte. No code addresses it.
4B65
LD A,09H 3E 09
DIRCYL: Load Register A with 09H, the offset of the directory cylinder in a drive code table.
4B67
GOSUB to 479CH (DCTBYT): Register A = byte +09H of drive Register C's table, the directory cylinder.
4B6A
LD D,A 57
Copy Register A (the directory cylinder) into Register D.
4B6B
RET C9
RETurn with the directory cylinder in Register D.

4B6CH - MULTEA, DIVEA, @MULT and @DIV

Four arithmetic routines. 4B6CH (MULTEA): Register A = Register A x Register E (8 bits). 4B7BH (DIVEA): Register E / Register A, the quotient in Register A and the remainder in Register E. 4B8FH (@MULT, 44C1H): Register Pair HL x Register A, a 24 bit product in Register Pair HL (high 16 bits) and Register A (low 8 bits). 4BA9H (@DIV, 44C4H): Register Pair HL / Register A, the quotient in Register Pair HL and the remainder in Register A. Register Pair BC is kept by all four.

4B6C
PUSH BC C5
MULTEA: Save Register Pair BC to the stack: Register B is the bit counter.
4B6D
LD D,A 57
Copy Register A (the first factor) into Register D, the value added for each set bit of Register E.
4B6E
XOR A AF
Set Register A to 00H (XOR A): the product so far.
4B6F
LD B,08H 06 08
Load Register B with 08H, one pass for each bit of Register E.
4B71
ADD A,A 87
Double Register A, the product so far (ADD A,A). 4B77H loops back here.
4B72
SLA E CB 23
Shift Register E (the second factor) left one bit: its bit 7 goes into the CARRY FLAG.
4B74
If the NO CARRY FLAG is set (that bit of Register E was 0), JUMP to 4B77H without adding.
4B76
ADD A,D 82
ADD Register D (the first factor) to Register A (the product so far).
4B77
DECrement Register B and LOOP BACK to 4B71H until all 8 bits of Register E are done.
4B79
POP BC C1
Restore the caller's Register Pair BC from the stack.
4B7A
RET C9
RETurn with the product in Register A (Register D = the first factor, Register E = 00H).
4B7B
PUSH BC C5
DIVEA: Save the caller's Register Pair BC to the stack.
4B7C
LD C,A 4F
Copy Register A (the divisor) into Register C.
4B7D
LD B,08H 06 08
Load Register B with 08H, one pass for each bit of the dividend in Register E.
4B7F
XOR A AF
Set Register A to 00H (XOR A): the remainder so far.
4B80
SLA E CB 23
Shift Register E (the dividend, then the quotient bits) left one bit: its bit 7 goes into the CARRY FLAG. 4B88H loops back here.
4B82
RLA 17
Rotate the CARRY FLAG into Register A (the remainder so far) through bit 0 (RLA).
4B83
CP C B9
Compare Register A (the remainder) against Register C (the divisor).
4B84
If the CARRY FLAG is set (the remainder is below the divisor), JUMP to 4B88H.
4B86
SUB C 91
SUBtract Register C (the divisor) from Register A (the remainder).
4B87
INC E 1C
INCrement Register E: a quotient bit of 1 into bit 0.
4B88
DECrement Register B and LOOP BACK to 4B80H until all 8 bits are done: Register E = the quotient, Register A = the remainder.
4B8A
LD C,A 4F
Copy Register A (the remainder) into Register C.
4B8B
LD A,E 7B
Copy Register E (the quotient) into Register A.
4B8C
LD E,C 59
Copy Register C (the remainder) into Register E.
4B8D
POP BC C1
Restore the caller's Register Pair BC from the stack.
4B8E
RET C9
RETurn with the quotient in Register A and the remainder in Register E.
4B8F
PUSH BC C5
@MULT: Save the caller's Register Pair BC to the stack.
4B90
EX DE,HL EB
Exchange Register Pairs DE and HL: Register Pair DE = the 16 bit factor (Register Pair HL on entry).
4B91
LD C,A 4F
Copy Register A (the 8 bit factor) into Register C.
4B92
LD HL,0000H 21 00 00
Load Register Pair HL with 0000H: the product's low 16 bits so far.
4B95
LD A,L 7D
Copy Register L (00H) into Register A: the product's high 8 bits so far.
4B96
LD B,08H 06 08
Load Register B with 08H, one pass for each bit of Register C.
4B98
ADD HL,HL 29
Double Register Pair HL (ADD HL,HL): the product so far moves up one bit and bit 15 goes into the CARRY FLAG. 4BA1H loops back here.
4B99
RLA 17
Rotate Register A left through the CARRY FLAG (RLA): the bit out of the top of Register Pair HL comes into bit 0 of Register A. While the product is built, Register A is its high byte and Register Pair HL its low 16 bits.
4B9A
RLC C CB 01
Rotate Register C (the 8 bit factor) left: its top bit goes into the CARRY FLAG.
4B9C
If the NO CARRY FLAG is set (that bit of Register C was 0), JUMP to 4BA1H without adding.
4B9E
ADD HL,DE 19
ADD Register Pair DE (the 16 bit factor) to Register Pair HL.
4B9F
ADC A,00H CE 00
ADD the CARRY FLAG out of Register Pair HL to Register A (ADC A,00H), the product's high byte.
4BA1
DECrement Register B and LOOP BACK to 4B98H until all 8 bits of Register C are done.
4BA3
LD C,A 4F
Copy Register A (the product's high byte) into Register C.
4BA4
LD A,L 7D
Copy Register L (the product's low byte) into Register A.
4BA5
LD L,H 6C
Copy Register H (the product's middle byte) into Register L.
4BA6
LD H,C 61
Copy Register C into Register H. Register Pair HL and Register A now hold the 24 bit product: Register Pair HL the high 16 bits and Register A the low 8 bits.
4BA7
POP BC C1
Restore the caller's Register Pair BC from the stack.
4BA8
RET C9
RETurn with the product in Register Pair HL and Register A (Register Pair DE = the 16 bit factor).
4BA9
PUSH DE D5
@DIV: Save the caller's Register Pair DE to the stack.
4BAA
LD D,A 57
Copy Register A (the divisor) into Register D.
4BAB
LD E,10H 1E 10
Load Register E with 10H, one pass for each of the 16 bits of Register Pair HL.
4BAD
XOR A AF
Set Register A to 00H (XOR A): the remainder so far.
4BAE
ADD HL,HL 29
Double Register Pair HL (ADD HL,HL): the next bit of the dividend goes into the CARRY FLAG and a 0 comes into bit 0 for the quotient. 4BB8H loops back here.
4BAF
RLA 17
Rotate the CARRY FLAG into Register A, the remainder (RLA).
4BB0
If the CARRY FLAG is set (the remainder overflowed 8 bits), JUMP to 4BB5H to subtract.
4BB2
CP D BA
Compare Register A (the remainder) against Register D (the divisor).
4BB3
If the CARRY FLAG is set (the remainder is below the divisor), JUMP to 4BB7H.
4BB5
SUB D 92
SUBtract Register D (the divisor) from Register A (the remainder).
4BB6
INC L 2C
INCrement Register L: a quotient bit of 1 at bit 0 of Register Pair HL.
4BB7
DEC E 1D
DECrement Register E, the bits of the dividend left to do.
4BB8
If the NZ FLAG is set (bits remain in Register E), LOOP BACK to 4BAEH.
4BBA
POP DE D1
Restore the caller's Register Pair DE from the stack.
4BBB
RET C9
RETurn with the quotient in Register Pair HL and the remainder in Register A.
4BBC-4BC8
DEFB 00H x 13 00 x 13
4BBCH-4BC8H: 13 bytes of 00H. SYS1/SYS stores a word at 4BC0H (its 4F43H).
4BC9-4BCA
DEFB 00H x 2 00 x 2
4BC9H-4BCAH: every system file 1-12 starts with a load block for these two bytes: the length of the file's part at 4E00H (for example 03AFH for SYS4/SYS), so they always hold the length of the system file in the overlay area. SYS7/SYS reads and writes them (its 5764H, 5812H).

4BCBH - Call a Drive's Driver

The disk primitives (4787H) CALL here: the jump goes to the drive code table at Index Register IY, whose first three bytes are a JP to the driver or a RET.

4BCB
JP (IY) FD E9
JUMP to the address in Index Register IY: the drive code table, whose bytes +00H-+02H are JP 45FBH (or another driver), or C9H (RET) for a drive that is not present.

4BCDH - The Supervisor Dispatcher (RST 28H)

ROM 0028H jumps to 400CH and so here with the request code in Register A. A code below 80H is handled at 4BEFH. For 80H and above, the return address of the RST is dropped (the overlay returns straight to the program that called the request stub), the BREAK trap switch (4315H) is turned off and saved, the system file the code names is loaded when it is not already at 4E00H (4BF5H), and its entry is called with Register A = the request code from OVRLY$ (430EH). Then the BREAK trap switch is put back.

4BCD
OR A B7
Set the flags from Register A (OR A), the request code: the SIGN FLAG is set for 80H and above.
4BCE
If the SIGN FLAG is clear (POSITIVE: the code is below 80H), JUMP to 4BEFH.
4BD1
EX (SP),HL E3
Exchange Register Pair HL with the top of the stack (the Stack Pointer is not changed): Register Pair HL = the return address of the RST 28H (the byte after the request stub) and the caller's Register Pair HL is on the stack.
4BD2
PUSH AF F5
Save Register Pair AF (the request code) to the stack.
4BD3
LD HL,4315H 21 15 43
Point Register Pair HL to 4315H, the BREAK trap switch. The RST's return address in Register Pair HL is dropped here.
4BD6
LD A,(HL) 7E
Fetch the switch at Register Pair HL (C3H on, C9H off) into Register A.
4BD7
LD (4BE9H),A 32 E9 4B
Store Register A (the switch) at 4BE9H, the operand of the LD A at 4BE8H, to be put back after the overlay.
4BDA
LD (HL),C9H 36 C9
Store C9H at Register Pair HL (4315H): the BREAK trap is off while the overlay runs.
4BDC
POP AF F1
Restore Register Pair AF (the request code) from the stack.
4BDD
POP HL E1
Restore the caller's Register Pair HL from the stack. The top of the stack is now the return address into the program that called the request stub.
4BDE
GOSUB to 4BF5H to make sure the system file of request Register A is loaded (and, for 88H and 89H, the library command Register B); it stores the file's entry at 4BE5H.
4BE1
LD A,(430EH) 3A 0E 43
Fetch OVRLY$ from 430EH into Register A: the request code (for the libraries, the code of the file already at 4E00H).
4BE4
GOSUB to the system file's entry: the operand at 4BE5H-4BE6H is 0000H in the file; 4C46H stores the entry address there (SYS7/SYS stores one too, its 580EH).
4BE7
PUSH AF F5
Save Register Pair AF (the overlay's result in Register A and the flags) to the stack.
4BE8
LD A,00H 3E 00
Load Register A with the BREAK trap switch saved at 4BE9H (00H in the file; 4BD7H stores the value of 4315H here).
4BEA
LD (4315H),A 32 15 43
Store Register A at 4315H: the BREAK trap switch is as it was before the request.
4BED
POP AF F1
Restore Register Pair AF (the overlay's result and flags) from the stack.
4BEE
RET C9
RETurn to the program that called the request stub.
4BEF
DEC A 3D
A request code below 80H. DECrement Register A: the Z FLAG is set for code 01H.
4BF0
NOP 00
No operation in the file. SYS0/SYS's reset stores C8H (RET Z) here when the AUTO command starts with 2AH (500BH-500DH), and BASIC/CMD (its 57AFH) and SYS7/SYS (its 528CH) store into it too; then code 01H returns at once with Register A = 00H.
4BF1
If the NZ FLAG is set (the code was not 01H), JUMP to 4C4BH to display SYS Error and abort.
4BF3
INC A 3C
INCrement Register A: Register A = 01H (the NZ FLAG is set).
4BF4
RET C9
RETurn with Register A = 01H for request code 01H.

4BF5H - Load the System File of a Request

Register A = the request code, Register B = the library command (for 88H and 89H). A library request (88H, SYS6/SYS, or 89H, SYS7/SYS) always loads, because each command is its own member of the file. For the others nothing is loaded when the file named by the low four bits is already at 4E00H (OVRLY$, 430EH). Otherwise OVRLY$ gets the new code and the file is read through SFCB$ (44A0H): its directory record (3-7, or 20H-26H for the files from 8 on) is read from drive 0, its first extents copied, and the module loader (4C8DH) loads it, returning its entry address. A file missing from the directory or a load error displays SYS Error and aborts.

4BF5
PUSH HL E5
Save the caller's Register Pair HL to the stack.
4BF6
LD H,A 67
Copy Register A (the request code) into Register H.
4BF7
LD A,B 78
Copy Register B (the library command number) into Register A.
4BF8
LD (4C3BH),A 32 3B 4C
Store Register A (the library command) at 4C3BH, the operand of the LD B at 4C3AH that tells the module loader which member to load.
4BFB
LD A,H 7C
Copy Register H (the request code) into Register A.
4BFC
OR 01H F6 01
OR 01H into Register A: 88H and 89H both become 89H.
4BFE
CP 89H FE 89
Compare Register A against 89H: the Z FLAG is set for a library request.
4C00
LD A,H 7C
Copy Register H (the request code) into Register A. LD does not change the flags.
4C01
If the Z FLAG is set (a library request), JUMP to 4C12H to load the command's member.
4C03
LD A,(430EH) 3A 0E 43
Fetch OVRLY$ from 430EH into Register A: the request code of the file now at 4E00H.
4C06
XOR H AC
Exclusive OR Register H (the new request code) into Register A.
4C07
AND 0FH E6 0F
Mask Register A to bits 3-0: the Z FLAG is set when both codes name the same system file.
4C09
LD A,H 7C
Copy Register H (the new request code) into Register A. LD does not change the flags.
4C0A
LD (430EH),A 32 0E 43
Store Register A (the new request code) at 430EH, OVRLY$.
4C0D
LD HL,4E00H 21 00 4E
Load Register Pair HL with 4E00H, the entry of a file already in place.
4C10
If the Z FLAG is set (the file is already at 4E00H), JUMP to 4C46H to use the entry in Register Pair HL.
4C12
PUSH DE D5
Save the caller's Register Pair DE to the stack.
4C13
PUSH BC C5
Save the caller's Register Pair BC to the stack (Register B = the library command).
4C14
AND 0FH E6 0F
Mask Register A (the request code) to bits 3-0: the system file's number plus 2.
4C16
BIT 3,A CB 5F
Test bit 3 of Register A: set for the files from SYS6/SYS on (8 and up).
4C18
If the Z FLAG is set (SYS1/SYS-SYS5/SYS), JUMP to 4C1CH: their directory records are 3-7.
4C1A
ADD A,18H C6 18
ADD 18H to Register A: the records of SYS6/SYS-SYS12/SYS are 20H-26H (the second slot of the directory's sectors 2-8).
4C1C
LD (44A7H),A 32 A7 44
Store Register A (the directory record number) at 44A7H, byte +07H of SFCB$.
4C1F
LD B,A 47
Copy Register A (the directory record number) into Register B, for DIRRD.
4C20
LD A,20H 3E 20
Load Register A with 20H: full access and bit 5, the buffer must be read first.
4C22
LD (44A1H),A 32 A1 44
Store Register A (20H) at 44A1H, byte +01H of SFCB$.
4C25
SBC HL,HL ED 62
SUBtract Register Pair HL and the CARRY FLAG from Register Pair HL (SBC HL,HL; the CARRY FLAG is clear after the AND above): Register Pair HL = 0000H.
4C27
LD (44AAH),HL 22 AA 44
Store Register Pair HL (0000H) at 44AAH-44ABH, the next record number of SFCB$: read from the start.
4C2A
LD C,H 4C
Copy Register H (00H) into Register C: drive 0.
4C2B
GOSUB to 4B10H (DIRRD) to read the directory sector of record Register B on drive Register C into 4200H; Register Pair HL comes back pointing at the record.
4C2E
If the NZ FLAG is set (the directory could not be read), JUMP to 4C4BH: SYS Error.
4C30
BIT 4,(HL) CB 66
Test bit 4 of byte +00H of the directory record at Register Pair HL: set when the record is in use.
4C32
If the Z FLAG is set (the system file is not on the diskette), JUMP to 4C4BH: SYS Error.
4C34
LD A,L 7D
Copy Register L (the record's low byte in the buffer) into Register A.
4C35
ADD A,16H C6 16
ADD 16H to Register A: the low byte of the record's first extent (+16H).
4C37
GOSUB to 47B4H to copy the first two extents into SFCB$ (44AEH-44B3H).
4C3A
LD B,00H 06 00
Load Register B with the library command number: the operand at 4C3BH (00H in the file) is stored by 4BF8H.
4C3C
LD DE,44A0H 11 A0 44
Point Register Pair DE to 44A0H, SFCB$, the system files' control block.
4C3F
GOSUB to 4C8DH to load the module through the control block at Register Pair DE (for a library, member Register B). It returns the entry address in Register Pair HL with the Z FLAG set.
4C42
If the NZ FLAG is set (the load failed), JUMP to 4C4BH: SYS Error.
4C44
POP BC C1
Restore the caller's Register Pair BC from the stack.
4C45
POP DE D1
Restore the caller's Register Pair DE from the stack.
4C46
LD (4BE5H),HL 22 E5 4B
Store Register Pair HL (the entry address: 4E00H, or the one the loader returned) at 4BE5H-4BE6H, the operand of the CALL at 4BE4H.
4C49
POP HL E1
Restore the caller's Register Pair HL from the stack.
4C4A
RET C9
RETurn to the dispatcher (4BE1H) with the entry stored.
4C4B
LD HL,4C54H 21 54 4C
Point Register Pair HL to 4C54H, the text SYS Error.
4C4E
GOSUB to 447BH (@LOGOT) to display the text at Register Pair HL (and send it to the job log).
4C51
JUMP to 4030H, @ABORT: the program is ended and LDOS READY follows.
4C54-4C5C
DEFM "SYS Error" 53 59 53 20 45 72 72 6F 72
4C54H-4C5CH: the message displayed when a request cannot be served: an unknown request code below 80H, or a system file that is missing or cannot be loaded.
4C5D
DEFB 0DH 0D
4C5DH: 0DH, the end of the SYS Error text (displayed: the line ends).

4C5EH - @RUN and @LOAD

4C5EH (@RUN) sets bit 2 of SFLAG$ (430FH), loads the program file named in the control block at Register Pair DE (@LOAD) and runs it at its transfer address; when DEBUG is on (bit 7 of 430FH) and bit 1 is clear, it enters DEBUG at the program's first instruction instead. An error goes to @ERROR (4409H). 4C77H (@LOAD) opens the file with the buffer 4200H and loads it (4C8DH), returning the transfer address in Register Pair HL; a file not found becomes error 1FH (program not found), and bit 6 is set in every error number.

4C5E
PUSH HL E5
@RUN: Save Register Pair HL (the command line pointer) to the stack.
4C5F
LD HL,430FH 21 0F 43
Point Register Pair HL to 430FH, SFLAG$, the system flags.
4C62
SET 2,(HL) CB D6
Set bit 2 of SFLAG$ at Register Pair HL: a program load by @RUN is in progress.
4C64
GOSUB to 4430H (@LOAD) to load the program named in the control block at Register Pair DE; it returns the transfer address in Register Pair HL and the Z FLAG on success.
4C67
If the NZ FLAG is set (the load failed), JUMP to 4409H (@ERROR) with the error number in Register A.
4C6A
EX (SP),HL E3
Exchange Register Pair HL with the top of the stack (the Stack Pointer is not changed): the transfer address goes on the stack and the command line pointer comes back into Register Pair HL for the program.
4C6B
LD A,(430FH) 3A 0F 43
Fetch SFLAG$, the system flags, from 430FH into Register A.
4C6E
BIT 1,A CB 4F
Test bit 1 of Register A (SFLAG$): when it is set the program runs without DEBUG.
4C70
RET NZ C0
If the NZ FLAG is set (bit 1 on), RETurn: the RET takes the transfer address and runs the program.
4C71
BIT 7,A CB 7F
Test bit 7 of Register A: set when DEBUG is turned on.
4C73
If the NZ FLAG is set (DEBUG is on), JUMP to 400FH to enter DEBUG with the transfer address on the stack as the program's address.
4C76
RET C9
RETurn: the RET takes the transfer address and runs the program.

4C77H - @LOAD: Load a Program File

Register Pair DE = a file control block with the program's file specification. The file is opened with the buffer 4200H and 256 byte records (@OPEN) and loaded by 4C8DH, which returns the transfer address in Register Pair HL. On failure bit 6 is set in the error number (the short message), and 18H (file not in directory) becomes 1FH (program not found).

4C77
LD B,00H 06 00
@LOAD: Load Register B with 00H, the record length for @OPEN: 256 bytes.
4C79
LD HL,4200H 21 00 42
Point Register Pair HL to 4200H, the buffer for the file's sectors (the module loader takes its bytes from 4200H-42FFH).
4C7C
GOSUB to 4424H (@OPEN) to open the file named in the control block at Register Pair DE with the buffer at Register Pair HL and the record length in Register B.
4C7F
PUSH DE D5
Save Register Pair DE (the control block) to the stack.
4C80
If the Z FLAG is set (the file is open), GOSUB to 4C8DH to load it: Register Pair HL = its transfer address.
4C83
POP DE D1
Restore Register Pair DE (the control block) from the stack.
4C84
RET Z C8
If the Z FLAG is set (opened and loaded), RETurn with the transfer address in Register Pair HL.
4C85
SET 6,A CB F7
Set bit 6 of Register A (the error number): SYS4/SYS gives the short message.
4C87
CP 58H FE 58
Compare Register A against 58H (18H, file not in directory, with bit 6).
4C89
RET NZ C0
If the NZ FLAG is set (another error), RETurn with the error number in Register A.
4C8A
ADD A,07H C6 07
ADD 07H to Register A: 5FH, error 1FH (program not found) with bit 6.
4C8C
RET C9
RETurn with Register A = 5FH and the NZ FLAG set.

4C8DH - The Module Loader

Loads the load module of the open file whose control block is at Register Pair DE, its sectors read into 4200H. Register B = the library member wanted (for SYS6/SYS and SYS7/SYS). Record types: 01H a load block (length, address, data), 02H the transfer address, 04H the end of a library member, 08H a library member's header (its number, entry address, the record of the file where it starts and the byte in that record), 0AH and 20H-FFH are a load file format error (22H), every other type below 20H is passed over by its length. Each data byte is checked after it is stored: a byte that does not stay is error 23H (memory fault) or 24H (read only memory), with bit 6 set. Returns the Z FLAG and the transfer (or member entry) address in Register Pair HL.

4C8D
LD A,B 78
Copy Register B (the library member wanted) into Register A.
4C8E
LD (4CF9H),A 32 F9 4C
Store Register A at 4CF9H, the operand of the CP at 4CF8H that picks the member.
4C91
PUSH DE D5
Save Register Pair DE (the file control block) to the stack.
4C92
EX (SP),IX DD E3
Exchange Index Register IX with the top of the stack (the Stack Pointer is not changed): Index Register IX = the file control block, and the caller's Index Register IX is kept on the stack.
4C94
LD DE,42FFH 11 FF 42
Load Register Pair DE with 42FFH: the pointer to the byte before the buffer at 4200H, so the first fetch (INC E gives 00H) reads the first sector.
4C97
GOSUB to 4C9DH to load the records of the module, one by one.
4C9A
POP IX DD E1
Restore the caller's Index Register IX from the stack.
4C9C
RET C9
RETurn with the result of the load (Register Pair HL, Register A, the flags).
4C9D
GOSUB to 4D1CH to fetch the next byte of the file into Register A: the record type. 4CC5H, 4CE2H and the member search come back here.
4CA0
CP 01H FE 01
Compare Register A (the record type) against 01H, a load block.
4CA2
If the Z FLAG is set (type 01H), JUMP to 4CCEH to load the block.
4CA4
CP 02H FE 02
Compare Register A (the record type) against 02H, the transfer address.
4CA6
If the Z FLAG is set (type 02H), JUMP to 4CC7H to take the transfer address and return.
4CA8
CP 04H FE 04
Compare Register A (the record type) against 04H, the end of a library member.
4CAA
If the Z FLAG is set (type 04H), JUMP to 4CEEH to return the member's entry address.
4CAC
CP 08H FE 08
Compare Register A (the record type) against 08H, a library member's header.
4CAE
If the Z FLAG is set (type 08H), JUMP to 4CF0H to see whether it is the member wanted.
4CB0
CP 0AH FE 0A
Compare Register A (the record type) against 0AH.
4CB2
If the Z FLAG is set (type 0AH, not allowed in a load module), JUMP to 4CB8H: load file format error.
4CB4
CP 20H FE 20
Compare Register A (the record type) against 20H.
4CB6
If the CARRY FLAG is set (another type below 20H: a name, a comment or a copyright record), JUMP to 4CBCH to pass over it.
4CB8
LD A,22H 3E 22
Load Register A with 22H, error 34: load file format error (the file is not a load module).
4CBA
OR A B7
Set the flags from Register A (OR A): the NZ FLAG is set.
4CBB
RET C9
RETurn with Register A = 22H and the NZ FLAG set.
4CBC
GOSUB to 4D1CH to fetch the record's length byte into Register A.
4CBF
LD B,A 47
Copy Register A (the length) into Register B: the bytes to pass over (00H passes over 256).
4CC0
GOSUB to 4D1CH to fetch the next byte of the record into Register A, which is not used. 4CC3H loops back here; 4CFAH joins here for a member that is not wanted.
4CC3
DECrement Register B and LOOP BACK to 4CC0H until the record is passed over.
4CC5
JUMP to 4C9DH for the next record of the module.
4CC7
Type 02H: GOSUB to 4D1CH to fetch the record's length byte (02H), which is not used.
4CCA
GOSUB to 4D30H to fetch the transfer address into Register Pair HL; it returns with the Z FLAG set.
4CCD
RET C9
RETurn with the transfer address in Register Pair HL and the Z FLAG set: the load is complete.
4CCE
Type 01H: GOSUB to 4D1CH to fetch the record's length byte into Register A.
4CD1
LD B,A 47
Copy Register A (the length: the address and the data) into Register B.
4CD2
GOSUB to 4D30H to fetch the load address into Register Pair HL.
4CD5
RET NZ C0
If the NZ FLAG is set (a read error), RETurn with the error number in Register A.
4CD6
DEC B 05
DECrement Register B for the low address byte.
4CD7
DEC B 05
DECrement Register B for the high address byte: Register B = the data bytes (00H counts as 256).
4CD8
GOSUB to 4D1CH to fetch the next data byte into Register A. 4CE0H loops back here.
4CDB
LD (HL),A 77
Store Register A (the data byte) at the load address in Register Pair HL.
4CDC
CP (HL) BE
Compare Register A against the byte at Register Pair HL: the Z FLAG is set when the store took.
4CDD
If the NZ FLAG is set (the memory did not keep the byte), JUMP to 4CE4H to find out why.
4CDF
INC HL 23
INCrement Register Pair HL, the load address.
4CE0
DECrement Register B and LOOP BACK to 4CD8H until the block is loaded.
4CE2
JUMP to 4C9DH for the next record of the module.
4CE4
LD B,(HL) 46
Fetch the byte the memory at Register Pair HL holds into Register B.
4CE5
CPL 2F
Complement Register A (the data byte) to write a different value.
4CE6
LD (HL),A 77
Store Register A (the complement) at Register Pair HL.
4CE7
LD A,(HL) 7E
Fetch the byte at Register Pair HL back into Register A.
4CE8
CP B B8
Compare Register A against Register B (what the memory held before): the Z FLAG is set when the memory did not change at all, read only memory.
4CE9
LD A,63H 3E 63
Load Register A with 63H: error 23H (35, memory fault) with bit 6. LD does not change the flags.
4CEB
RET NZ C0
If the NZ FLAG is set (the memory changes but did not keep the data byte), RETurn with Register A = 63H.
4CEC
INC A 3C
INCrement Register A: 64H, error 24H (36, attempted to load read only memory) with bit 6.
4CED
RET C9
RETurn with Register A = 64H and the NZ FLAG set.
4CEE
POP HL E1
Type 04H, the end of the member: Restore the member's entry address (pushed at 4CFFH) from the stack into Register Pair HL.
4CEF
RET C9
RETurn with the member's entry address in Register Pair HL; the Z FLAG is set (from the CP at 4CA8H).
4CF0
Type 08H: GOSUB to 4D1CH to fetch the record's length byte into Register A.
4CF3
LD B,A 47
Copy Register A (the length) into Register B.
4CF4
GOSUB to 4D1CH to fetch the member number into Register A.
4CF7
DEC B 05
DECrement Register B for the member number just read.
4CF8
CP 00H FE 00
Compare Register A (the member number) against the member wanted: the operand at 4CF9H is 00H in the file; 4C8EH stores Register B there.
4CFA
If the NZ FLAG is set (another member), JUMP to 4CC0H to pass over the rest of the record (Register B bytes).
4CFC
GOSUB to 4D30H to fetch the member's entry address into Register Pair HL.
4CFF
PUSH HL E5
Save Register Pair HL (the member's entry address) to the stack, for 4CEEH.
4D00
If the Z FLAG is set (no read error), GOSUB to 4D30H to fetch the next word into Register Pair HL: the record of the file where the member starts.
4D03
If the NZ FLAG is set (a read error), JUMP to 4D2CH to drop the entry address and return the error.
4D05
GOSUB to 4D1CH to fetch the next byte into Register A: the position of the member's first byte in that record.
4D08
LD E,A 5F
Copy Register A (the byte position) into Register E: the low byte of the fetch pointer in Register Pair DE.
4D09
PUSH BC C5
Save Register Pair BC (Register B = the bytes of the record left) to the stack.
4D0A
LD B,H 44
Copy Register H (the record's high byte) into Register B.
4D0B
LD C,L 4D
Copy Register L (the record's low byte) into Register C. Register Pair BC = the record where the member starts.
4D0C
PUSH DE D5
Save Register Pair DE (the fetch pointer) to the stack.
4D0D
PUSH IX DD E5
Save Index Register IX (the file control block) to the stack.
4D0F
POP DE D1
Restore it into Register Pair DE: @POSN takes the control block in Register Pair DE.
4D10
GOSUB to 4442H (@POSN) to position the file at record Register Pair BC.
4D13
POP DE D1
Restore Register Pair DE (the fetch pointer, Register E = the byte position) from the stack.
4D14
POP BC C1
Restore Register Pair BC (Register B = the bytes left) from the stack.
4D15
If the NZ FLAG is set (the position failed), JUMP to 4D2CH to drop the entry address and return the error.
4D17
GOSUB to 4D21H to read the record into the buffer and fetch the byte at the pointer: Register A = the type of the member's first record.
4D1A
JUMP to 4CA0H to act on that record type in Register A.
4D1C
INC E 1C
INCrement Register E, the fetch pointer in the buffer (Register Pair DE, 42xxH). The Z FLAG is set when it wraps to 00H: the buffer is used up.
4D1D
If the Z FLAG is set (the buffer is used up), JUMP to 4D21H to read the next sector.
4D1F
LD A,(DE) 1A
Fetch the byte at Register Pair DE (the buffer) into Register A.
4D20
RET C9
RETurn with the byte of the file in Register A.
4D21
PUSH HL E5
Save the caller's Register Pair HL to the stack.
4D22
PUSH DE D5
Save Register Pair DE (the fetch pointer) to the stack.
4D23
PUSH BC C5
Save the caller's Register Pair BC to the stack.
4D24
GOSUB to 494FH to read the sector of the file's next record number into its buffer (4200H): the file at Index Register IX.
4D27
POP BC C1
Restore the caller's Register Pair BC from the stack.
4D28
POP DE D1
Restore Register Pair DE (the fetch pointer) from the stack.
4D29
POP HL E1
Restore the caller's Register Pair HL from the stack.
4D2A
If the Z FLAG is set (the sector was read), JUMP to 4D1FH to fetch the byte at Register Pair DE.
4D2C
POP BC C1
Drop a word from the stack into Register Pair BC: the return address into the loader (or the member's entry address), so the RET below leaves the loader.
4D2D
OR 40H F6 40
OR 40H into Register A (the error number): bit 6, the short message (the NZ FLAG is set).
4D2F
RET C9
RETurn with the error number in Register A and the NZ FLAG set.
4D30
GOSUB to 4D1CH to fetch the next byte into Register A: the low byte of a word.
4D33
LD L,A 6F
Copy Register A (the low byte of the word) into Register L.
4D34
GOSUB to 4D1CH to fetch the next byte into Register A: the high byte.
4D37
LD H,A 67
Copy Register A into Register H. Register Pair HL = the word.
4D38
CP A BF
Compare Register A with itself: the Z FLAG is set.
4D39
RET C9
RETurn with the word in Register Pair HL and the Z FLAG set.

4D3AH - The Clock Display Task and @TIME, @DATE

4D3AH is a task block that SYS7/SYS puts into task slot 6 (its 532AH-5330H): 5 times a second it counts 5 calls and then writes the time as HH:MM:SS at 3C35H, the top right of the screen. 4D48H (@TIME, 446DH) writes the time and 4D63H (@DATE, 4470H) the date (MM/DD/YY) as 8 characters at Register Pair HL.

4D3A-4D3B
DEFW 4D3DH 3D 4D
4D3AH-4D3BH: the task block's first word: 4D3DH, its routine.
4D3C
DEFB 05H 05
4D3CH, the block's byte +02H: the calls left before the next display, 05H.
4D3D
DEC (IX+02H) DD 35 02
DECrement byte +02H of the task block at Index Register IX (4D3CH), the calls left before the next display.
4D40
RET NZ C0
If the NZ FLAG is set (the count in byte +02H has not reached 0), RETurn.
4D41
LD (IX+02H),05H DD 36 02 05
Store 05H into byte +02H of the task block at Index Register IX: the next display is 5 calls away.
4D45
LD HL,3C35H 21 35 3C
Point Register Pair HL to 3C35H, row 0, column 53 of the screen.
4D48
LD DE,4043H 11 43 40
@TIME: Point Register Pair DE to 4043H, the hours of TIME$ (the fields are taken downwards: hours, minutes, seconds).
4D4B
LD C,3AH 0E 3A
Load Register C with 3AH, the character : between the fields.
4D4D
LD B,03H 06 03
Load Register B with 03H, the three fields. @DATE joins here.
4D4F
LD A,(DE) 1A
Fetch the next field from Register Pair DE into Register A. 4D61H loops back here.
4D50
DEC DE 1B
DECrement Register Pair DE to the field after it.
4D51
LD (HL),2FH 36 2F
Store 2FH (the character before 0) at Register Pair HL, the tens digit.
4D53
INC (HL) 34
INCrement the tens digit at Register Pair HL. 4D56H loops back here.
4D54
SUB 0AH D6 0A
SUBtract 0AH from Register A (the field), one ten at a time.
4D56
If the NO CARRY FLAG is set (10 or more were left), LOOP BACK to 4D53H to count another ten.
4D58
ADD A,3AH C6 3A
ADD 3AH to Register A (the field less one ten too many): the units digit as a character (30H-39H).
4D5A
INC HL 23
INCrement Register Pair HL to the units digit.
4D5B
LD (HL),A 77
Store Register A (the units digit) at Register Pair HL.
4D5C
INC HL 23
INCrement Register Pair HL to the next character.
4D5D
DEC B 05
DECrement Register B, the fields still to write.
4D5E
RET Z C8
If the Z FLAG is set (all three fields written), RETurn with Register Pair HL after the text.
4D5F
LD (HL),C 71
Store Register C (the separator) at Register Pair HL.
4D60
INC HL 23
INCrement Register Pair HL past the separator.
4D61
LOOP BACK to 4D4FH for the next field at Register Pair DE.
4D63
LD DE,4046H 11 46 40
@DATE: Point Register Pair DE to 4046H, the month of DATE$ (taken downwards: month, day, year).
4D66
LD C,2FH 0E 2F
Load Register C with 2FH, the character / between the fields.
4D68
JUMP to 4D4DH to write the three fields at Register Pair HL.

4D6AH - The Program Counter Display Task

4D6AH is a task block that SYS7/SYS puts into task slot 11 (its 53A7H-53B1H): on every clock tick it writes the address the interrupted program was at as four hex digits at 3C2EH. 4D76H and 4D7BH write a word or a byte as hex characters at Register Pair HL; SYS6/SYS and SYS7/SYS use them too.

4D6A-4D6B
DEFW 4D6CH 6C 4D
4D6AH-4D6BH: the task block's first word: 4D6CH, its routine.
4D6C
LD HL,0012H 21 12 00
Load Register Pair HL with 0012H, the distance from the Stack Pointer to the interrupted program's return address while a task runs (the interrupt routine's saved registers and return addresses lie between).
4D6F
ADD HL,SP 39
ADD the Stack Pointer to Register Pair HL: Register Pair HL points at the interrupted program's address on the stack.
4D70
LD E,(HL) 5E
Fetch the low byte of the interrupted address at Register Pair HL into Register E.
4D71
INC HL 23
INCrement Register Pair HL to the high byte of the interrupted address.
4D72
LD D,(HL) 56
Fetch the high byte at Register Pair HL into Register D. Register Pair DE = the address the program was interrupted at.
4D73
LD HL,3C2EH 21 2E 3C
Point Register Pair HL to 3C2EH, row 0, column 46 of the screen.
4D76
LD A,D 7A
Copy Register D (the word's high byte) into Register A. SYS6/SYS and SYS7/SYS call 4D76H to write Register Pair DE as four hex digits at Register Pair HL.
4D77
GOSUB to 4D7BH to write Register A as two hex digits at Register Pair HL.
4D7A
LD A,E 7B
Copy Register E (the word's low byte) into Register A; the code goes on into 4D7BH for its two digits.
4D7B
PUSH AF F5
Save Register Pair AF (the byte) to the stack. 4D7BH writes Register A as two hex digits at Register Pair HL.
4D7C
RRA 1F
Rotate Register A right one bit: first of four rotations that bring the high four bits down.
4D7D
RRA 1F
Rotate Register A right one bit again: second of four rotations.
4D7E
RRA 1F
Rotate Register A right one bit again: third of four rotations.
4D7F
RRA 1F
Rotate Register A right one bit again: the high four bits are now bits 3-0.
4D80
GOSUB to 4D84H to write the digit of bits 3-0 of Register A.
4D83
POP AF F1
Restore Register Pair AF (the byte) from the stack; the code goes on into 4D84H for the low digit.
4D84
AND 0FH E6 0F
Mask Register A to bits 3-0: one hex digit, 0-15.
4D86
ADD A,90H C6 90
ADD 90H to Register A (the digit 0-15): 90H-9FH.
4D88
DAA 27
Decimal adjust Register A (DAA): 90H-99H stay for 0-9 with the CARRY FLAG clear; 9AH-9FH become 00H-05H with the CARRY FLAG set for 10-15.
4D89
ADC A,40H CE 40
ADD 40H and the CARRY FLAG to Register A (ADC A,40H): D0H-D9H for 0-9, 41H-46H for 10-15.
4D8B
DAA 27
Decimal adjust Register A again: D0H-D9H become 30H-39H (the characters 0-9), 41H-46H stay (the characters A-F).
4D8C
LD (HL),A 77
Store Register A (the hex character) at Register Pair HL.
4D8D
INC HL 23
INCrement Register Pair HL to the next character position.
4D8E
RET C9
RETurn to the caller with Register Pair HL after the digit.

4D8FH - The Current Sector of a File

4D8FH saves Register Pair HL under the return address and goes on into 4D92H; 4D92H loads Register C with the position in the buffer (+05H); 4D95H (Register C given) adjusts Register Pair HL, the next record number less one or the next record number, to the sector of the current position: in byte mode (bit 7 of +01H) one is added when Register C is not 0, and one is taken away when the buffer holds the sector before the next record number (bit 5 clear). In record mode Register Pair HL is not changed.

4D8F
POP BC C1
Take the return address off the stack into Register Pair BC.
4D90
PUSH HL E5
Save Register Pair HL (the next record number) to the stack, under the return address.
4D91
PUSH BC C5
Save Register Pair BC (the return address) back on top.
4D92
LD C,(IX+05H) DD 4E 05
Fetch byte +05H of the file control block at Index Register IX into Register C: the position in the buffer.
4D95
BIT 7,(IX+01H) DD CB 01 7E
Test bit 7 of byte +01H of the file control block at Index Register IX: byte mode.
4D99
RET Z C8
If the Z FLAG is set (not byte mode), RETurn with Register Pair HL unchanged.
4D9A
LD A,C 79
Copy Register C (the position in the buffer) into Register A.
4D9B
OR A B7
Set the flags from Register A (OR A): the Z FLAG is set when the position is 0.
4D9C
If the Z FLAG is set (the position is 0), JUMP to 4D9FH.
4D9E
INC HL 23
INCrement Register Pair HL: the position is inside the sector after.
4D9F
BIT 5,(IX+01H) DD CB 01 6E
Test bit 5 of byte +01H of the file control block at Index Register IX: set when the buffer must be read before the next byte.
4DA3
RET NZ C0
If the NZ FLAG is set (the buffer does not hold the sector), RETurn.
4DA4
DEC HL 2B
DECrement Register Pair HL: the buffer holds the sector before the next record number.
4DA5
RET C9
RETurn with the current sector in Register Pair HL.

4DA6H - The Keyboard Scan of Every Interrupt

Called by the interrupt routine (452FH) on every interrupt. It reads the keyboard rows directly: SHIFT (3880H, bits 1-0) with @ (3801H, bit 0) sets bit 1 of KFLAG$ (4423H), the pause; ENTER (3840H, bit 0) sets bit 2; BREAK (3840H, bit 2) without SHIFT sets bit 0 unless BREAK is disabled (bit 4 of 430FH). Returns with the NZ FLAG set when BREAK is held and the CARRY FLAG set when a SHIFT key is held.

4DA6
PUSH HL E5
Save the interrupted program's Register Pair HL to the stack.
4DA7
LD HL,4423H 21 23 44
Point Register Pair HL to 4423H, KFLAG$, the keyboard flags.
4DAA
LD A,(3880H) 3A 80 38
Fetch keyboard row 7 from 3880H into Register A: bit 0 the left SHIFT, bit 1 the right SHIFT.
4DAD
AND 03H E6 03
Mask Register A to bits 1-0, the two SHIFT keys.
4DAF
NEG ED 44
Negate Register A: the CARRY FLAG is set when a SHIFT key is held (Register A was not 0).
4DB1
LD A,(3801H) 3A 01 38
Fetch keyboard row 0 from 3801H into Register A: bit 0 is the @ key. LD does not change the flags.
4DB4
BIT 0,A CB 47
Test bit 0 of Register A (row 0): the @ key, held or not.
4DB6
If the Z FLAG is set (@ is not held), JUMP to 4DBCH.
4DB8
If the NO CARRY FLAG is set (no SHIFT key), JUMP to 4DBCH.
4DBA
SET 1,(HL) CB CE
Set bit 1 of KFLAG$ at Register Pair HL: SHIFT @, the pause key.
4DBC
LD A,(3840H) 3A 40 38
Fetch keyboard row 6 from 3840H into Register A: bit 0 ENTER, bit 2 BREAK.
4DBF
BIT 0,A CB 47
Test bit 0 of Register A (row 6): the ENTER key.
4DC1
If the Z FLAG is set (ENTER is not held), JUMP to 4DC5H.
4DC3
SET 2,(HL) CB D6
Set bit 2 of KFLAG$ at Register Pair HL: ENTER was held.
4DC5
BIT 2,A CB 57
Test bit 2 of Register A (row 6): BREAK. The Z FLAG is clear when BREAK is held.
4DC7
PUSH AF F5
Save Register Pair AF (the Z FLAG for BREAK and the CARRY FLAG for SHIFT) to the stack, to return them.
4DC8
If the Z FLAG is set (BREAK is not held), JUMP to 4DD5H.
4DCA
If the CARRY FLAG is set (SHIFT BREAK), JUMP to 4DD5H without setting the BREAK bit.
4DCC
LD A,(430FH) 3A 0F 43
Fetch SFLAG$, the system flags, from 430FH into Register A.
4DCF
BIT 4,A CB 67
Test bit 4 of Register A (SFLAG$): BREAK disabled.
4DD1
If the NZ FLAG is set (BREAK is disabled), JUMP to 4DD5H.
4DD3
SET 0,(HL) CB C6
Set bit 0 of KFLAG$ at Register Pair HL: BREAK was pressed.
4DD5
POP AF F1
Restore Register Pair AF (the BREAK and SHIFT flags) from the stack.
4DD6
POP HL E1
Restore the interrupted program's Register Pair HL from the stack.
4DD7
RET C9
RETurn to the interrupt routine with the BREAK and SHIFT flags.
4DD8-4DEF
DEFS 24
Not in the file: 4DD8H-4DEFH. No code of the LDOS files on this diskette addresses these bytes.

4DF0H - Base Cells for Resident Modules

Sixteen bytes before the reset code. Modules that install themselves in high memory keep their addresses here: SYS6/SYS (4DF0H, 4DF1H, 4DF6H, 4DF7H), KI/DVR (4DF2H, 4DF4H, 4DF8H), PR/FLT (4DF0H, 4DF6H), SYS7/SYS (4DF2H, 4DF6H). The reset code from 4E00H on is overwritten by the system files after the boot, but these bytes stay.

4DF0-4DFD
DEFB 00H x 14 00 x 14
4DF0H-4DFDH: 14 bytes of 00H, the cells listed above, empty at boot.
4DFE-4DFF
DEFW 43B0H B0 43
4DFEH-4DFFH: 43B0H, the address of the eight bytes 43B0H-43B7H. No code of the LDOS files on this diskette reads this word.

4E00H - The Reset: Memory, Video and Drive 0

The transfer address of SYS0/SYS: the boot sector jumps here with interrupts off. Sector 0 of BOOT/SYS leaves Index Register IY = 0000H; sector 1 (a boot through a disk driver) leaves Index Register IY pointing at drive 0's drive code table. The reset finds the top of memory, sets the speed and the cassette latch, saves the ROM's driver addresses, installs the lower case video driver when the video memory has it, clears the spare device control blocks, sets up drive 0 from the boot, enables the interrupts and reads the system information sector (cylinder 0, sector 2) into 4200H. All of 4E00H-50FFH is used only here; the system files load over it afterwards.

4E00
DI F3
Disable interrupts (they are already off after the boot sector).
4E01
IM 1 ED 56
Set interrupt mode 1: every interrupt goes to ROM 0038H and from there through 4012H to 4518H.
4E03
LD SP,41DEH 31 DE 41
Load the Stack Pointer with 41DEH. The word at 41DEH-41DFH (0000H from the last load record, or 4277H after sector 0's CALLs) is what a RET with nothing pushed takes (4E8FH).
4E06
LD HL,FFFFH 21 FF FF
Point Register Pair HL to FFFFH, the highest byte a 48K computer has.
4E09
LD A,(HL) 7E
Fetch the byte at Register Pair HL into Register A. 4E15H loops back here.
4E0A
LD B,A 47
Copy Register A (the byte) into Register B, to put it back.
4E0B
CPL 2F
Complement Register A, so every bit of the test byte changes.
4E0C
LD (HL),A 77
Store Register A (the complement) at Register Pair HL.
4E0D
CP (HL) BE
Compare Register A with the byte at Register Pair HL: the Z FLAG is set when the memory kept the complement, so it is RAM.
4E0E
LD (HL),B 70
Store Register B (the byte as it was) back at Register Pair HL.
4E0F
If the Z FLAG is set (RAM is there), JUMP to 4E17H: Register Pair HL is the top of memory.
4E11
LD A,H 7C
Copy Register H (the high byte of the address tested) into Register A.
4E12
SUB 40H D6 40
SUBtract 40H from Register A: the address tested moves 16K lower.
4E14
LD H,A 67
Copy Register A into Register H: Register Pair HL = BFFFH, then 7FFFH.
4E15
LOOP BACK to 4E09H to test the byte at the address 16K lower.
4E17
LD (4049H),HL 22 49 40
Store Register Pair HL (the top of memory: 7FFFH, BFFFH or FFFFH) at 4049H-404AH, HIGH$: all memory up to it is free for programs.
4E1A
LD (4403H),HL 22 03 44
Store Register Pair HL (the top of memory) at 4403H-4404H as well, to keep the physical top when HIGH$ is lowered.
4E1D
LD A,00H 3E 00
Load Register A with 00H, the value for the speed control port.
4E1F
OUT (FEH),A D3 FE
Write Register A (00H) to port FEH, the speed control: the normal clock speed (bit 0 clear).
4E21
XOR A AF
Set Register A to 00H (XOR A) for the cassette select latch.
4E22
LD (37E4H),A 32 E4 37
Store Register A (00H) to the cassette select latch at 37E4H: cassette 1, as the ROM's 0212H does.
4E25
LD HL,(4016H) 2A 16 40
Fetch KIDCB$'s driver address from 4016H-4017H into Register Pair HL (03E3H, the ROM's keyboard driver).
4E28
LD (43B8H),HL 22 B8 43
Store Register Pair HL (the keyboard driver) at 43B8H-43B9H, KISV$.
4E2B
LD HL,3C00H 21 00 3C
Point Register Pair HL to 3C00H, the first byte of video memory.
4E2E
CPL 2F
Complement Register A: Register A = FFH, the video memory test byte.
4E2F
LD (HL),A 77
Store Register A (FFH) at 3C00H (Register Pair HL).
4E30
CP (HL) BE
Compare Register A (FFH) with the byte at Register Pair HL: the Z FLAG is set when the video memory kept all eight bits, which only a computer with lower case does (without it bit 6 is lost and the byte reads back as BFH).
4E31
LD (HL),20H 36 20
Store 20H (a space) at 3C00H (Register Pair HL), the first character of the title line.
4E33
LD HL,(401EH) 2A 1E 40
Fetch DODCB$'s driver address from 401EH-401FH into Register Pair HL (0458H, the ROM's video driver). LD does not change the flags.
4E36
If the NZ FLAG is set (no lower case), JUMP to 4E3EH to keep the ROM's video driver.
4E38
LD HL,4378H 21 78 43
Load Register Pair HL with 4378H, SYS0/SYS's video driver, which shows lower case.
4E3B
LD (401EH),HL 22 1E 40
Store Register Pair HL (4378H) at 401EH-401FH, DODCB$'s driver address.
4E3E
LD (43BAH),HL 22 BA 43
Store Register Pair HL (the video driver in force) at 43BAH-43BBH, DOSV$.
4E41
LD HL,(4026H) 2A 26 40
Fetch PRDCB$'s driver address from 4026H-4027H into Register Pair HL (058DH, the ROM's printer driver).
4E44
LD (43BCH),HL 22 BC 43
Store Register Pair HL (the printer driver) at 43BCH-43BDH, PRSV$.
4E47
LD HL,43D8H 21 D8 43
Point Register Pair HL to 43D8H, the five spare device control blocks.
4E4A
LD (HL),00H 36 00
Store 00H at Register Pair HL. 4E4DH loops back here.
4E4C
INC L 2C
INCrement Register L to the next byte of the device control blocks.
4E4D
If the NZ FLAG is set (Register L has not wrapped to 00H, 4400H), LOOP BACK to 4E4AH: 43D8H-43FFH are cleared.
4E4F
PUSH IY FD E5
Save Index Register IY (from the boot sector) to the stack.
4E51
POP HL E1
Restore the boot's Index Register IY into Register Pair HL.
4E52
LD A,H 7C
Copy Register H (the high byte of the boot's Index Register IY) into Register A.
4E53
OR L B5
OR Register L into Register A: the Z FLAG is set when Index Register IY was 0000H, a boot by sector 0.
4E54
If the Z FLAG is set (a boot by sector 0), JUMP to 4E66H, inside the LD BC below, where the bytes 2EH BCH read as LD L,0BCH.
4E56
LD DE,4700H 11 00 47
A boot through a disk driver: Point Register Pair DE to 4700H, drive 0's drive code table.
4E59
LD BC,000AH 01 0A 00
Load Register Pair BC with 000AH, the 10 bytes of a drive code table.
4E5C
LDIR ED B0
Copy the 10 bytes from Register Pair HL (the boot's drive code table at Index Register IY) to Register Pair DE (4700H), counting Register Pair BC down: drive 0 now uses the boot's driver.
4E5E
LD HL,442FH 21 2F 44
Point Register Pair HL to 442FH, MFLAG$, the system flags.
4E61
SET 0,(HL) CB C6
Set bit 0 of MFLAG$ at Register Pair HL: a boot through a disk driver (the drive tables of the system information sector's first block are used, 4FCEH).
4E63
LD L,10H 2E 10
Load Register L with 10H: Register Pair HL will be 4210H, the bootstrap step rate operand in sector 1 of BOOT/SYS, still at 4200H.
4E65
LD BC,BC2EH 01 2E BC
Load Register Pair BC with BC2EH: Register Pair BC is not used, so the instruction only passes over its two operand bytes. Entered at 4E66H (from 4E54H), the bytes 2EH BCH are LD L,0BCH: Register Pair HL will be 42BCH, the Seek command of sector 0 of BOOT/SYS, whose bits 1-0 are the bootstrap step rate.
4E68
LD H,42H 26 42
Load Register H with 42H. Register Pair HL = 4210H (driver boot) or 42BCH (boot by sector 0).
4E6A
LD A,(HL) 7E
Fetch the byte of the boot sector at Register Pair HL into Register A.
4E6B
AND 03H E6 03
Mask Register A to bits 1-0: the bootstrap step rate FORMAT/CMD wrote.
4E6D
LD B,A 47
Copy Register A (the step rate) into Register B.
4E6E
LD HL,4703H 21 03 47
Point Register Pair HL to 4703H, byte +03H of drive 0's drive code table.
4E71
LD A,(HL) 7E
Fetch byte +03H at Register Pair HL into Register A.
4E72
AND 7CH E6 7C
Mask Register A to bits 6-2: the step rate (bits 1-0) and the write protect (bit 7) are cleared.
4E74
OR B B0
OR Register B (the bootstrap step rate) into Register A.
4E75
LD (HL),A 77
Store Register A at 4703H (Register Pair HL): drive 0 steps at the bootstrap rate.
4E76
LD A,(4202H) 3A 02 42
Fetch the directory cylinder from 4202H, byte 2 of the boot sector, into Register A.
4E79
LD (4709H),A 32 09 47
Store Register A (the directory cylinder) at 4709H, byte +09H of drive 0's drive code table.
4E7C
LD A,(37ECH) 3A EC 37
Fetch the disk controller's status from 37ECH into Register A: reading it clears the controller's interrupt request.
4E7F
LD HL,404CH 21 4C 40
Point Register Pair HL to 404CH, INTMSK$, the interrupt mask.
4E82
LD (HL),C0H 36 C0
Store C0H at INTMSK$ (Register Pair HL): the clock (bit 7) and the disk controller (bit 6) interrupts are served.
4E84
EI FB
Enable interrupts: from now on the clock runs the task slots (TIMER$ counts and the clock task keeps the time).
4E85
LD DE,0002H 11 02 00
Load Register Pair DE with 0002H: Register D = cylinder 0, Register E = sector 2, the system information sector.
4E88
LD C,D 4A
Copy Register D (00H) into Register C: drive 0.
4E89
LD HL,4200H 21 00 42
Point Register Pair HL to 4200H, where the sector is read (over the boot sector).
4E8C
GOSUB to 4777H (RDSECT) to read cylinder Register D, sector Register E of drive Register C into the buffer at Register Pair HL.
4E8F
RET NZ C0
If the NZ FLAG is set (the sector could not be read), RETurn through the word at 41DEH-41DFH: 0000H, the ROM's restart, or 4277H after a boot by sector 0 (see 41DEH).

4E90H - The Reset: The Date

The system information sector is now at 4200H. Its byte 01H (the configuration file flag) is saved for later and replaced by 00H. When its date prompt switch (42C2H) is not 00H the date is skipped. When the date was set before a reset (4306H holds a month OR 50H) it is used again without a prompt; 4306H = 50H skips the date and the time. Otherwise Date? is asked at 3F17H until three good fields are typed (MM/DD/YY, years 80-99 for 1980-1999 and 00-11 for 2000-2011).

4E90
LD L,01H 2E 01
Load Register L with 01H: Register Pair HL = 4201H, the configuration file flag of the system information sector (Register H is 42H from 4E89H).
4E92
LD A,(HL) 7E
Fetch the flag at Register Pair HL into Register A: C9H no CONFIG/SYS, 00H load it.
4E93
LD (HL),00H 36 00
Store 00H at 4201H (Register Pair HL): the byte before the month table, so the sum of the months at 4F12H starts from 0.
4E95
PUSH AF F5
Save Register Pair AF (Register A = the configuration file flag) to the stack, for 5022H.
4E96
LD A,(42C2H) 3A C2 42
Fetch the date prompt switch from 42C2H into Register A.
4E99
OR A B7
Set the flags from Register A (OR A): the Z FLAG is set when the date is to be asked.
4E9A
If the NZ FLAG is set (no date prompt), JUMP to 4F89H for the time prompt.
4E9D
LD A,(4306H) 3A 06 43
Fetch SVDAT1$ from 4306H into Register A: the month of the date set before this reset, OR 50H (the byte is not in the file, so a reset keeps it).
4EA0
XOR 50H EE 50
Exclusive OR 50H into Register A: Register A = the month (1-12) when a date was kept.
4EA2
If the Z FLAG is set (4306H held 50H), JUMP to 4FBDH, skipping the date and the time.
4EA5
CP 0DH FE 0D
Compare Register A (the month kept) against 0DH: the CARRY FLAG is set for 1-12, a good month.
4EA7
If the CARRY FLAG is set (a date was kept), JUMP to 4EF4H to use it again with the day at 4307H.
4EA9
LD HL,3F17H 21 17 3F
Point Register Pair HL to 3F17H, row 12, column 23 of the screen: where Date? is asked. 4EB5H, 4EC2H, 4EDDH and 4EE9H come back here when the date typed is not good.
4EAC
LD DE,50B6H 11 B6 50
Point Register Pair DE to 50B6H, the prompt text Date ? .
4EAF
LD BC,0830H 01 30 08
Load Register Pair BC with 0830H: Register B = 8, the characters accepted, and Register C = 30H, the separator limit (any character below 0 separates the fields).
4EB2
GOSUB to 431BH to display the prompt, take the line and parse it: the CARRY FLAG is set when three two digit fields were typed, stored at 431AH (month), 4319H (day) and 4318H (year), Register Pair DE = 4318H.
4EB5
If the NO CARRY FLAG is set (not three fields), LOOP BACK to 4EA9H to ask again.
4EB7
LD A,(DE) 1A
Fetch the year field from Register Pair DE (4318H) into Register A.
4EB8
CP 0CH FE 0C
Compare Register A (the year) against 0CH: the CARRY FLAG is set for 00-11, the years 2000-2011.
4EBA
If the NO CARRY FLAG is set (12-99), JUMP to 4EBEH.
4EBC
ADD A,64H C6 64
ADD 64H (100) to Register A: 2000-2011 count as 100-111.
4EBE
SUB 50H D6 50
SUBtract 50H (80) from Register A: Register A = the years since 1980.
4EC0
CP 20H FE 20
Compare Register A against 20H: the years 1980-2011 are 0-31.
4EC2
If the NO CARRY FLAG is set (outside 1980-2011), LOOP BACK to 4EA9H to ask again.
4EC4
LD (4466H),A 32 66 44
Store Register A (the years since 1980) at 4466H.
4EC7
AND 03H E6 03
Mask Register A to bits 1-0: the Z FLAG is set for a leap year (1980, 1984 ... 2008).
4EC9
LD A,1CH 3E 1C
Load Register A with 1CH (28), the days of February. LD does not change the flags.
4ECB
If the NZ FLAG is set (not a leap year), JUMP to 4ED3H with 28 days.
4ECD
LD HL,4048H 21 48 40
Point Register Pair HL to 4048H, the date flags.
4ED0
SET 7,(HL) CB FE
Set bit 7 of 4048H (Register Pair HL): a leap year.
4ED2
INC A 3C
INCrement Register A: 1DH (29) days of February in a leap year.
4ED3
LD HL,4203H 21 03 42
Point Register Pair HL to 4203H, the days of February in the system information sector's month table.
4ED6
LD (HL),A 77
Store Register A (28 or 29) at 4203H (Register Pair HL).
4ED7
LD A,(431AH) 3A 1A 43
Fetch the month field from 431AH into Register A.
4EDA
DEC A 3D
DECrement Register A: the month counted from 0.
4EDB
CP 0CH FE 0C
Compare Register A against 0CH: the CARRY FLAG is set for 0-11, a good month.
4EDD
If the NO CARRY FLAG is set (not 1-12), LOOP BACK to 4EA9H to ask again.
4EDF
DEC HL 2B
DECrement Register Pair HL: Register Pair HL = 4202H, the days of January.
4EE0
ADD A,L 85
ADD Register L (02H) to Register A (the month less 1).
4EE1
LD L,A 6F
Copy Register A into Register L: Register Pair HL = the days of the month typed.
4EE2
INC DE 13
INCrement Register Pair DE to 4319H, the day field.
4EE3
LD A,(DE) 1A
Fetch the day field from Register Pair DE into Register A.
4EE4
LD (4307H),A 32 07 43
Store Register A (the day) at 4307H, SVDAT2$.
4EE7
DEC A 3D
DECrement Register A: the day counted from 0.
4EE8
CP (HL) BE
Compare Register A against the days of the month at Register Pair HL: the CARRY FLAG is set for a good day.
4EE9
If the NO CARRY FLAG is set (the day is 0 or past the end of the month), LOOP BACK to 4EA9H to ask again.
4EEB
INC DE 13
INCrement Register Pair DE to 431AH, the month field.
4EEC
LD A,(DE) 1A
Fetch the month field from Register Pair DE into Register A.
4EED
OR 50H F6 50
OR 50H into Register A: the mark of a date that has been set.
4EEF
LD (4306H),A 32 06 43
Store Register A (the month OR 50H) at 4306H, SVDAT1$, so a later reset can keep the date.
4EF2
XOR 50H EE 50
Exclusive OR 50H into Register A: the month again.

4EF4H - The Reset: Store and Display the Date

Stores the month, the day and the year in DATE$ (4044H-4046H), works out the day of the year (4047H, bit 0 of 4048H) and the day of the week (bits 3-1 of 4048H, from 1 for Sunday), and displays the date at 3F17H as, for example, Tue, Jan 1, 1980.

4EF4
LD (4046H),A 32 46 40
Store Register A (the month) at 4046H. The date kept from before the reset joins here from 4EA7H.
4EF7
LD B,A 47
Copy Register A (the month) into Register B: the number of months to add up below.
4EF8
LD A,(4466H) 3A 66 44
Fetch the years since 1980 from 4466H into Register A.
4EFB
PUSH AF F5
Save Register Pair AF (the years since 1980) to the stack.
4EFC
AND 03H E6 03
Mask Register A to bits 1-0: the Z FLAG is set for a leap year.
4EFE
LD HL,4203H 21 03 42
Point Register Pair HL to 4203H, the days of February.
4F01
LD (HL),1CH 36 1C
Store 1CH (28) at 4203H (Register Pair HL): the days of February.
4F03
If the NZ FLAG is set (not a leap year), JUMP to 4F06H.
4F05
INC (HL) 34
INCrement the days of February at Register Pair HL: 29.
4F06
LD A,(4307H) 3A 07 43
Fetch the day of the month from 4307H, SVDAT2$, into Register A.
4F09
LD (4045H),A 32 45 40
Store Register A (the day) at 4045H, the day of DATE$.
4F0C
LD L,A 6F
Copy Register A (the day) into Register L, the low byte of the sum.
4F0D
LD H,00H 26 00
Load Register H with 00H. Register Pair HL = the day: the day of the year so far.
4F0F
LD DE,4201H 11 01 42
Point Register Pair DE to 4201H, the byte before the month table (00H since 4E93H).
4F12
LD A,(DE) 1A
Fetch the days of a month from Register Pair DE into Register A (00H the first time). 4F19H loops back here.
4F13
ADD A,L 85
ADD Register L (the low byte of the sum) to Register A (the days of the month).
4F14
LD L,A 6F
Copy Register A (the new low byte of the sum) into Register L.
4F15
ADC A,H 8C
ADD Register H and the CARRY FLAG to Register A (ADC A,H).
4F16
SUB L 95
SUBtract Register L from Register A: Register A = Register H plus the carry.
4F17
LD H,A 67
Copy Register A into Register H: Register Pair HL = the day of the year so far plus that month's days.
4F18
INC DE 13
INCrement Register Pair DE to the next month.
4F19
DECrement Register B (the months left) and LOOP BACK to 4F12H: the days of every month before the current one are added.
4F1B
EX DE,HL EB
Exchange Register Pairs DE and HL: Register Pair DE = the day of the year (1-366).
4F1C
LD HL,4047H 21 47 40
Point Register Pair HL to 4047H, the day of the year's low byte.
4F1F
LD (HL),E 73
Store Register E (the day of the year's low byte) at 4047H (Register Pair HL).
4F20
INC HL 23
INCrement Register Pair HL to 4048H, the date flags.
4F21
LD A,D 7A
Copy Register D (the day of the year's high byte, 0 or 1) into Register A.
4F22
OR (HL) B6
OR the date flags at Register Pair HL (4048H) into Register A.
4F23
LD (HL),A 77
Store Register A at 4048H (Register Pair HL): bit 0 is now bit 8 of the day of the year.
4F24
EX DE,HL EB
Exchange Register Pairs DE and HL: Register Pair HL = the day of the year.
4F25
POP AF F1
Restore Register Pair AF (the years since 1980) from the stack.
4F26
LD E,A 5F
Copy Register A (the years since 1980) into Register E.
4F27
ADD A,50H C6 50
ADD 50H (80) to Register A: the years 80-111 counted from 1900.
4F29
CP 64H FE 64
Compare Register A (the year from 1900) against 64H (100).
4F2B
If the CARRY FLAG is set (1980-1999), JUMP to 4F2FH.
4F2D
SUB 64H D6 64
SUBtract 64H from Register A: 0-11 for 2000-2011.
4F2F
LD (4044H),A 32 44 40
Store Register A (the year as two digits) at 4044H.
4F32
LD A,E 7B
Copy Register E (the years since 1980) into Register A.
4F33
ADD A,03H C6 03
ADD 03H to Register A (the years since 1980), so the division rounds up.
4F35
RRCA 0F
Rotate Register A right one bit: first of two rotations that divide by 4.
4F36
RRCA 0F
Rotate Register A right one bit again: Register A is divided by 4.
4F37
AND 0FH E6 0F
Mask Register A to bits 3-0: (the years since 1980 + 3) / 4, the leap days before this year.
4F39
ADD A,E 83
ADD Register E (the years since 1980) to Register A: each year moves the day of the week on by 1, each leap day by 1 more.
4F3A
LD E,A 5F
Copy Register A (the shift of the day of the week) into Register E.
4F3B
LD D,00H 16 00
Load Register D with 00H. Register Pair DE = the shift.
4F3D
ADD HL,DE 19
ADD Register Pair DE to Register Pair HL (the day of the year).
4F3E
INC HL 23
INCrement Register Pair HL: 1 January 1980 was a Tuesday.
4F3F
LD A,07H 3E 07
Load Register A with 07H, the days of a week.
4F41
GOSUB to 4BA9H to divide Register Pair HL by Register A (7): Register A = the remainder.
4F44
INC A 3C
INCrement Register A: the day of the week, 1 (Sunday) to 7 (Saturday).
4F45
LD B,A 47
Copy Register A (the day of the week) into Register B, for the display below.
4F46
RLCA 07
Rotate Register A left one bit: the day of the week in bits 3-1.
4F47
LD C,A 4F
Copy Register A (the day of the week in bits 3-1) into Register C.
4F48
LD HL,4048H 21 48 40
Point Register Pair HL to 4048H, the date flags.
4F4B
LD A,(HL) 7E
Fetch the date flags at Register Pair HL into Register A.
4F4C
AND F1H E6 F1
Mask Register A to clear bits 3-1 (AND F1H): the old day of the week.
4F4E
OR C B1
OR Register C (the day of the week in bits 3-1) into Register A.
4F4F
LD (HL),A 77
Store Register A at 4048H (Register Pair HL).
4F50
LD HL,3F17H 21 17 3F
Point Register Pair HL to 3F17H, where the Date? prompt was.
4F53
LD (4020H),HL 22 20 40
Store Register Pair HL at 4020H-4021H: the cursor goes back there.
4F56
LD HL,42C7H 21 C7 42
Point Register Pair HL to 42C7H, the names of the days of the week in the system information sector.
4F59
GOSUB to 5084H to display name number Register B (the day of the week) of the table at Register Pair HL.
4F5C
GOSUB to 5094H to display a comma and a space.
4F5F
LD A,(4046H) 3A 46 40
Fetch the month from 4046H, the month of DATE$, into Register A.
4F62
LD B,A 47
Copy Register A (the month) into Register B, the name number.
4F63
LD L,DCH 2E DC
Load Register L with DCH: Register Pair HL = 42DCH, the names of the months.
4F65
GOSUB to 5084H to display name number Register B (the month) of the table at Register Pair HL.
4F68
GOSUB to 5099H to display a space after the name of the month.
4F6B
LD A,(4045H) 3A 45 40
Fetch the day from 4045H, the day of DATE$, into Register A.
4F6E
LD D,00H 16 00
Load Register D with 00H: a leading 0 is not displayed.
4F70
GOSUB to 509EH to display Register A (the day) as one or two digits.
4F73
GOSUB to 5094H to display a comma and a space.
4F76
LD A,(4044H) 3A 44 40
Fetch the year from 4044H, the year of DATE$, into Register A.
4F79
LD D,14H 16 14
Load Register D with 14H (20), the century of the years 00-11.
4F7B
CP 0CH FE 0C
Compare Register A (the year) against 0CH: the CARRY FLAG is set for 00-11.
4F7D
If the CARRY FLAG is set (00-11), JUMP to 4F80H.
4F7F
DEC D 15
DECrement Register D: 13H (19), the century of the years 80-99.
4F80
PUSH AF F5
Save Register Pair AF (the year) to the stack.
4F81
LD A,D 7A
Copy Register D (the century) into Register A.
4F82
GOSUB to 509EH to display Register A (19 or 20) as two digits (Register D is not 0).
4F85
POP AF F1
Restore Register Pair AF (the year) from the stack.
4F86
GOSUB to 509EH to display Register A (the year) as two digits, a leading 0 included.

4F89H - The Reset: The Time

When the time prompt switch (42C3H) is 00H, Time? is asked at 3F57H: hours, minutes and seconds, two digits each, separated by any character below 3BH (the : included). Seconds, or minutes and seconds, may be left out (they count as 0). A field out of range asks again; a good time goes into TIME$ (4041H-4043H).

4F89
LD A,(42C3H) 3A C3 42
Fetch the time prompt switch from 42C3H into Register A.
4F8C
OR A B7
Set the flags from Register A (OR A): the Z FLAG is set when the time is to be asked.
4F8D
If the NZ FLAG is set (no time prompt), JUMP to 4FBDH.
4F8F
XOR A AF
Set Register A to 00H (XOR A). 4FA9H, 4FAFH and 4FB3H come back here.
4F90
LD HL,4318H 21 18 43
Point Register Pair HL to 4318H, the field of the seconds.
4F93
LD (HL),A 77
Store Register A (00H) at 4318H (Register Pair HL), the seconds.
4F94
INC HL 23
INCrement Register Pair HL to 4319H, the minutes.
4F95
LD (HL),A 77
Store Register A (00H) at 4319H (Register Pair HL), the minutes.
4F96
INC HL 23
INCrement Register Pair HL to 431AH, the hours.
4F97
LD (HL),A 77
Store Register A (00H) at 431AH (Register Pair HL), the hours: fields left out count as 0.
4F98
PUSH HL E5
Save Register Pair HL (431AH, the hours) to the stack.
4F99
LD HL,3F57H 21 57 3F
Point Register Pair HL to 3F57H, row 13, column 23: where Time? is asked.
4F9C
LD DE,50BFH 11 BF 50
Point Register Pair DE to 50BFH, the prompt text Time ? .
4F9F
LD BC,083BH 01 3B 08
Load Register Pair BC with 083BH: Register B = 8, the characters accepted, Register C = 3BH, the separator limit.
4FA2
GOSUB to 431BH to display the prompt, take the line and parse it into 431AH (hours), 4319H (minutes) and 4318H (seconds). Its result is not tested: a line that ends early leaves the missing fields at 0.
4FA5
POP HL E1
Restore Register Pair HL (431AH) from the stack.
4FA6
LD A,17H 3E 17
Load Register A with 17H (23), the highest hour.
4FA8
CP (HL) BE
Compare Register A against the hours at Register Pair HL: the CARRY FLAG is set for an hour above 23.
4FA9
If the CARRY FLAG is set (a bad hour), LOOP BACK to 4F8FH to ask again.
4FAB
DEC HL 2B
DECrement Register Pair HL to 4319H, the minutes.
4FAC
LD A,3BH 3E 3B
Load Register A with 3BH (59), the highest minute and second.
4FAE
CP (HL) BE
Compare Register A against the minutes at Register Pair HL.
4FAF
If the CARRY FLAG is set (a minute above 59), LOOP BACK to 4F8FH.
4FB1
DEC HL 2B
DECrement Register Pair HL to 4318H, the seconds.
4FB2
CP (HL) BE
Compare Register A (59) against the seconds at Register Pair HL.
4FB3
If the CARRY FLAG is set (a second above 59), LOOP BACK to 4F8FH.
4FB5
LD DE,4041H 11 41 40
Point Register Pair DE to 4041H, TIME$, the seconds of the clock.
4FB8
LD BC,0003H 01 03 00
Load Register Pair BC with 0003H, three bytes.
4FBB
LDIR ED B0
Copy the Register Pair BC (3) bytes 4318H-431AH (Register Pair HL) to 4041H-4043H (Register Pair DE): seconds, minutes and hours.

4FBDH - The Reset: Clock, Drives and the Diskette

Starts the clock task in slot 7, copies the drive code tables of drives 1-7 from the system information sector (the first block after a driver boot, the second otherwise), reads the allocation table of the diskette in drive 0 into 4200H, notes a diskette with two sides in drive 0's table and shows the diskette's name and date on the screen (3CD6H, 3CE0H).

4FBD
LD DE,45BEH 11 BE 45
Point Register Pair DE to 45BEH, the clock task's block.
4FC0
LD A,07H 3E 07
Load Register A with 07H, task slot 7, the clock task's slot.
4FC2
GOSUB to 4410H (@ADTSK) to put the task block at Register Pair DE into slot Register A: the clock now counts the seconds.
4FC5
LD HL,422AH 21 2A 42
Point Register Pair HL to 422AH, drive 1's entry of the first block of drive code tables in the system information sector.
4FC8
LD DE,470AH 11 0A 47
Point Register Pair DE to 470AH, drive 1's entry in DCT$.
4FCB
LD BC,0046H 01 46 00
Load Register Pair BC with 0046H, the 70 bytes of drives 1-7.
4FCE
LD A,(442FH) 3A 2F 44
Fetch MFLAG$ from 442FH, the system flags, into Register A.
4FD1
RRCA 0F
Rotate Register A right one bit: bit 0 (a boot through a disk driver) goes into the CARRY FLAG.
4FD2
If the CARRY FLAG is set (a driver boot), JUMP to 4FD6H to use the first block.
4FD4
LD L,7AH 2E 7A
Load Register L with 7AH: Register Pair HL = 427AH, drive 1's entry of the second block.
4FD6
LDIR ED B0
Copy Register Pair BC bytes (70) from Register Pair HL to Register Pair DE (470AH): drives 1-7 are set up as SYSTEM (DRIVE) saved them.
4FD8
GOSUB to 4B65H (DIRCYL): Register D = the directory cylinder of drive Register C (0, Register Pair BC being 0000H after the LDIR).
4FDB
LD E,C 59
Copy Register C (00H) into Register E: sector 0, the granule allocation table.
4FDC
LD L,C 69
Copy Register C (00H) into Register L: Register Pair HL = 4200H (Register H is 42H after the LDIR).
4FDD
GOSUB to 4B45H (RDSSEC) to read the allocation table of drive 0 into 4200H (correcting the directory cylinder from the boot sector when needed).
4FE0
If the NZ FLAG is set (the table could not be read), JUMP to 4409H (@ERROR) with the result in Register A.
4FE3
LD L,CDH 2E CD
Load Register L with CDH: Register Pair HL = 42CDH, the high byte of the diskette's configuration word.
4FE5
LD A,(HL) 7E
Fetch the configuration byte at Register Pair HL into Register A.
4FE6
AND 20H E6 20
Mask Register A to bit 5 of the configuration byte: two sides.
4FE8
LD B,A 47
Copy Register A (20H or 00H) into Register B.
4FE9
LD A,(4704H) 3A 04 47
Fetch byte +04H of drive 0's drive code table from 4704H into Register A.
4FEC
OR B B0
OR Register B (the two sides bit) into Register A.
4FED
LD (4704H),A 32 04 47
Store Register A at 4704H: drive 0 is double sided when its diskette is.
4FF0
LD L,D0H 2E D0
Load Register L with D0H: Register Pair HL = 42D0H, the diskette's name.
4FF2
LD DE,3CD6H 11 D6 3C
Point Register Pair DE to 3CD6H, row 3, column 22 of the screen.
4FF5
LD BC,0008H 01 08 00
Load Register Pair BC with 0008H, the 8 characters of the name.
4FF8
LDIR ED B0
Copy the name from Register Pair HL to the screen at Register Pair DE, counting Register Pair BC down.
4FFA
LD C,08H 0E 08
Load Register C with 08H, the 8 characters of the date.
4FFC
INC DE 13
INCrement Register Pair DE past the end of the name on the screen.
4FFD
INC DE 13
INCrement Register Pair DE again: two columns between the name and the date (3CE0H).
4FFE
LDIR ED B0
Copy the date (42D8H-42DFH, Register Pair HL) to the screen at Register Pair DE, counting Register Pair BC down. Register Pair HL ends at 42E0H, the AUTO command.

5000H - The Reset: AUTO, CONFIG/SYS and the Return to LDOS

Decides what runs after the boot. An AUTO command (the allocation table's 42E0H) is taken unless it is empty (0DH) or ENTER is held; one that starts with 2AH cannot be stopped that way and runs with BREAK disabled. D (or DOWN ARROW) held enters DEBUG. The AUTO command is copied to INBUF$ (4318H). The end of the reset is copied to 405DH and run there, because loading CONFIG/SYS (through @LOAD, 4430H) loads system files over 4E00H-51FFH. CONFIG/SYS is loaded unless the flag says none (bit 7) or CLEAR (or 9) or SPACE (or /) is held. The return addresses pushed make the last RET display the AUTO command (4467H) and carry it out (4405H), or go to LDOS READY (4400H).

5000
LD A,(HL) 7E
Fetch the first character of the AUTO command (42E0H, Register Pair HL) into Register A.
5001
CP 2AH FE 2A
Compare Register A against 2AH: an AUTO command that cannot be broken.
5003
If the NZ FLAG is set (no 2AH), JUMP to 5012H.
5005
INC HL 23
INCrement Register Pair HL past the 2AH, to the command itself.
5006
LD A,E6H 3E E6
Load Register A with E6H, the second byte of SET 4,(HL).
5008
LD (505EH),A 32 5E 50
Store Register A at 505EH: the RES 4,(HL) at 505DH becomes SET 4,(HL), so BREAK is disabled (bit 4 of 430FH) while the AUTO command runs.
500B
LD A,C8H 3E C8
Load Register A with C8H, the opcode of RET Z.
500D
LD (4BF0H),A 32 F0 4B
Store Register A at 4BF0H, so request code 01H returns at once (4BEFH).
5010
JUMP to 501FH: this AUTO command runs even when ENTER is held.
5012
LD A,(3841H) 3A 41 38
Fetch keyboard rows 0 and 6 together from 3841H into Register A: bit 0 is @ or ENTER, bit 4 is D or DOWN ARROW.
5015
BIT 4,A CB 67
Test bit 4 of Register A: D (or DOWN ARROW) held.
5017
If the NZ FLAG is set (D held), GOSUB to 440DH (@DEBUG) to enter the DEBUG monitor before the system starts.
501A
CPL 2F
Complement Register A (the keyboard rows): a key held reads as 0.
501B
AND 01H E6 01
Mask Register A to bit 0: the Z FLAG is set when ENTER (or @) is held.
501D
If the Z FLAG is set (ENTER held), JUMP to 5022H with the Z FLAG set: no AUTO command.
501F
LD A,(HL) 7E
Fetch the first character of the AUTO command at Register Pair HL into Register A.
5020
CP 0DH FE 0D
Compare Register A against 0DH: the Z FLAG is set when there is no AUTO command.
5022
POP DE D1
Restore Register Pair AF pushed at 4E95H into Register Pair DE: Register D = the configuration file flag. POP does not change the flags.
5023
LD A,D 7A
Copy Register D (the configuration file flag) into Register A. LD does not change the flags.
5024
LD DE,4400H 11 00 44
Point Register Pair DE to 4400H, @CMD (LDOS READY).
5027
If the Z FLAG is set (no AUTO command to run), JUMP to 502FH to push only 4400H.
5029
LD E,05H 1E 05
Load Register E with 05H: Register Pair DE = 4405H, @CMNDI.
502B
PUSH DE D5
Save Register Pair DE (4405H) to the stack: the last RET carries out the AUTO command.
502C
LD DE,4467H 11 67 44
Point Register Pair DE to 4467H, @DSPLY, the display of a line.
502F
PUSH DE D5
Save Register Pair DE (4467H, or 4400H) to the stack.
5030
LD DE,4318H 11 18 43
Point Register Pair DE to 4318H, INBUF$, the command line buffer.
5033
PUSH DE D5
Save Register Pair DE (4318H) to the stack: the relocated code pops it into Register Pair HL for @DSPLY and @CMNDI.
5034
LD BC,0020H 01 20 00
Load Register Pair BC with 0020H, the 32 bytes of the AUTO command.
5037
LDIR ED B0
Copy the Register Pair BC (32) bytes of the AUTO command field from Register Pair HL to INBUF$ (Register Pair DE).
5039
LD HL,505AH 21 5A 50
Point Register Pair HL to 505AH, the end of the reset.
503C
LD DE,405DH 11 5D 40
Point Register Pair DE to 405DH, DBGSV$, DEBUG's register save area, which is free at this point.
503F
PUSH DE D5
Save Register Pair DE (405DH) to the stack: the return address of @LOAD below, or of the RET at 5059H.
5040
LD C,2AH 0E 2A
Load Register C with 2AH (Register B is 00H): the 42 bytes 505AH-5083H.
5042
LDIR ED B0
Copy the Register Pair BC (42) bytes of the end of the reset from Register Pair HL (505AH) to Register Pair DE (405DH).
5044
LD HL,3860H 21 60 38
Point Register Pair HL to 3860H, keyboard rows 5 and 6 together: bit 1 is 9 or CLEAR, bit 7 is / or SPACE.
5047
OR (HL) B6
OR the keyboard rows at Register Pair HL into Register A (the configuration file flag).
5048
LD DE,4700H 11 00 47
Point Register Pair DE to 4700H, DCT$: the destination of the drive tables CONFIG/SYS brings.
504B
LD HL,4152H 21 52 41
Point Register Pair HL to 4152H, where CONFIG/SYS loads its copy of the drive tables.
504E
LD C,50H 0E 50
Load Register C with 50H: Register Pair BC = 0050H, the 80 bytes of eight drive code tables.
5050
EXX D9
Exchange Register Pairs BC, DE and HL with the alternate set: the copy's registers wait there for 4073H.
5051
LD DE,4338H 11 38 43
Point Register Pair DE to 4338H, the file specification CONFIG/SYS.CCC:0.
5054
AND 82H E6 82
Mask Register A to bits 7 and 1: the flag's bit 7 (no CONFIG/SYS), or a key held. The Z FLAG is set when CONFIG/SYS is to be loaded.
5056
If the Z FLAG is set (load it), JUMP to 4430H (@LOAD) to load CONFIG/SYS; it returns to 405DH with the Z FLAG set when it was loaded.
5059
RET C9
RETurn to 405DH with the NZ FLAG set: no configuration.
505A
LD HL,430FH 21 0F 43
(Runs at 405DH.) Point Register Pair HL to 430FH, SFLAG$.
505D
RES 4,(HL) CB A6
(Runs at 4060H.) Clear bit 4 of SFLAG$ at Register Pair HL: BREAK is enabled. For an AUTO command that starts with 2AH the operand at 505EH was changed to E6H (5008H), and the instruction is SET 4,(HL): BREAK disabled.
505F
(Runs at 4062H.) If the NZ FLAG is set (no CONFIG/SYS was loaded), JUMP to 5076H (4079H).
5061
BIT 3,(HL) CB 5E
(Runs at 4064H.) Test bit 3 of SFLAG$ at Register Pair HL: FAST, which CONFIG/SYS can set.
5063
(Runs at 4066H.) If the Z FLAG is set (not FAST), JUMP to 5070H (4073H).
5065
LD BC,01FEH 01 FE 01
(Runs at 4068H.) Load Register Pair BC with 01FEH: Register B = 01H (bit 0, the fast clock), Register C = FEH, the port.
5068
LD HL,4427H 21 27 44
(Runs at 406BH.) Point Register Pair HL to 4427H, the copy of port FEH.
506B
LD A,(HL) 7E
(Runs at 406EH.) Fetch the copy at Register Pair HL into Register A.
506C
OR B B0
(Runs at 406FH.) OR Register B (01H) into Register A.
506D
LD (HL),A 77
(Runs at 4070H.) Store Register A at 4427H (Register Pair HL).
506E
OUT (C),A ED 79
(Runs at 4071H.) Write Register A to the port in Register C (FEH): the computer runs at the fast speed.
5070
EXX D9
(Runs at 4073H.) Exchange Register Pairs BC, DE and HL with the alternate set: Register Pair HL = 4152H, Register Pair DE = 4700H, Register Pair BC = 0050H.
5071
LDIR ED B0
(Runs at 4074H.) Copy the Register Pair BC (80) bytes of drive tables CONFIG/SYS loaded at 4152H (Register Pair HL) to DCT$ at 4700H (Register Pair DE).
5073
(Runs at 4076H.) GOSUB to 4303H (@ICNFG), which CONFIG/SYS can point at its own start up code.
5076
LD HL,3F40H 21 40 3F
(Runs at 4079H.) Point Register Pair HL to 3F40H, row 13, column 0 of the screen.
5079
LD (4020H),HL 22 20 40
(Runs at 407CH.) Store Register Pair HL at 4020H-4021H: the cursor starts at row 13.
507C
LD HL,4012H 21 12 40
(Runs at 407FH.) Point Register Pair HL to 4012H, the RST 38H vector.
507F
LD (HL),C3H 36 C3
(Runs at 4082H.) Store C3H (JP) at 4012H (Register Pair HL): the vector jumps to 4518H again (CONFIG/SYS loads a C9H, RET, there while it is read).
5081
POP HL E1
(Runs at 4084H.) Restore Register Pair HL from the stack: 4318H, INBUF$.
5082
EI FB
(Runs at 4085H.) Enable interrupts, which CONFIG/SYS may have turned off.
5083
RET C9
(Runs at 4086H.) RETurn to 4467H (@DSPLY: the AUTO command is displayed) and then 4405H (@CMNDI: it is carried out), or to 4400H (@CMD: LDOS READY).

5084H - The Reset's Display Helpers

5084H displays three letter name number Register B of the table at Register Pair HL; 5094H a comma and a space; 5099H a space; 509EH Register A (0-99) as two digits, the tens left out when it is 0 and Register D is 0. All display through the ROM at 0033H.

5084
DEC B 05
DECrement Register B: the name number counted from 0.
5085
LD A,L 7D
Copy Register L (the table's low byte) into Register A.
5086
ADD A,B 80
ADD Register B (the name number) to Register A (the low byte).
5087
ADD A,B 80
ADD Register B (the name number) to Register A again.
5088
ADD A,B 80
ADD Register B to Register A a third time: Register A = the table's low byte + 3 x the number.
5089
LD L,A 6F
Copy Register A into Register L: Register Pair HL points at the name (the tables lie within 42C7H-42FFH).
508A
LD B,03H 06 03
Load Register B with 03H, the three letters of a name.
508C
LD A,(HL) 7E
Fetch the next letter at Register Pair HL into Register A. 5091H loops back here.
508D
INC HL 23
INCrement Register Pair HL to the next letter of the name.
508E
GOSUB to the ROM at 0033H to display the letter in Register A.
5091
DECrement Register B and LOOP BACK to 508CH for the next letter.
5093
RET C9
RETurn to the caller with the name displayed.
5094
LD A,2CH 3E 2C
Load Register A with 2CH, a comma, to display before a space.
5096
GOSUB to the ROM at 0033H to display the comma in Register A.
5099
LD A,20H 3E 20
Load Register A with 20H, a space, to display.
509B
JUMP to the ROM at 0033H to display the space in Register A; its RET returns to the caller.
509E
LD E,2FH 1E 2F
Load Register E with 2FH, the character before 0.
50A0
INC E 1C
INCrement Register E: the tens digit as a character. 50A3H loops back here.
50A1
SUB 0AH D6 0A
SUBtract 0AH (10) from Register A (the number).
50A3
If the NO CARRY FLAG is set (another ten), LOOP BACK to 50A0H.
50A5
PUSH AF F5
Save Register Pair AF (Register A = the units less 10) to the stack.
50A6
LD A,D 7A
Copy Register D (0: leave out a leading 0) into Register A.
50A7
OR A B7
Set the flags from Register A (OR A): the Z FLAG is set when Register D was 0.
50A8
LD A,E 7B
Copy Register E (the tens digit) into Register A. LD does not change the flags.
50A9
If the NZ FLAG is set (Register D not 0: always both digits), JUMP to 50ADH.
50AB
CP 30H FE 30
Compare Register A (the tens digit) against 30H, the character 0: the Z FLAG is set for a leading 0.
50AD
If the NZ FLAG is set, GOSUB to the ROM at 0033H to display the tens digit in Register A.
50B0
POP AF F1
Restore Register Pair AF (the units less 10) from the stack.
50B1
ADD A,3AH C6 3A
ADD 3AH to Register A: the units digit as a character.
50B3
JUMP to the ROM at 0033H to display the units digit in Register A; its RET returns to the caller.
50B6
DEFB 1EH 1E
50B6H: 1EH, clear to the end of the line, the first byte of the date prompt (4EACH).
50B7-50BD
DEFM "Date ? " 44 61 74 65 20 3F 20
50B7H-50BDH: the prompt Date ? followed by a space.
50BE
DEFB 03H 03
50BEH: 03H, the end of text mark of the date prompt.
50BF
DEFB 1EH 1E
50BFH: 1EH, clear to the end of the line, the first byte of the time prompt (4F9CH).
50C0-50C6
DEFM "Time ? " 54 69 6D 65 20 3F 20
50C0H-50C6H: the prompt Time ? followed by a space.
50C7
DEFB 03H 03
50C7H: 03H, the end of text mark of the time prompt.
50C8-50FF
DEFB 00H x 56 00 x 56
50C8H-50FFH: 56 bytes of 00H, the end of the file's last block before 5100H.