LS-DOS 6.3.1 for the Model 4 - BOOT/SYS Disassembled

Page Customization

Introduction/Summary

LS-DOS 6.3.1 BOOT/SYS Disassembly (Model 4)

BOOT/SYS is the first file of an LS-DOS 6.3.1 diskette: sectors 0 to 15 of cylinder 0, 4096 bytes, written by FORMAT and never copied from disk to disk. It is not a load module. When the Model 4 is reset, its ROM reads sector 1 into 4300H-43FFH and jumps there. That boot code (4300H) sends 86H to the Operation Register, which takes the ROM out of the memory map, clears the screen and reads the whole of BOOT/SYS to 0200H-11FFH. Most of it stays there as part of the resident system. The rows on this page are at the addresses where the bytes are used, 0200H-11FFH, except sector 1, which is shown at 4300H-43FFH, its address in the 0200H image (0300H) given under each row.

With cylinder 0 read in, the boot code initializes the 6845 video controller (02DDH), reads the GAT for the number of sides and the directory sector of SYS0/SYS (4350H), copies its first four extents and jumps to LBOOT (0238H). LBOOT reads SYS0/SYS through the resident floppy driver, record by record (0268H), and jumps to its transfer address, 1E00H.

What stays in memory is: the bank bytes and the device control blocks (0200H); the system information, the command line buffer and the drive code tables (0400H); and the resident I/O code from 0500H to 0FF3H: the character I/O SVCs (@DSPLY, @KEYIN, @GET, @PUT, @CTL and the others), @MUL16, @DIV16 and the decimal and hex conversions, the clock task, the bank switching, the keyboard driver with its type-ahead buffer (08F0H), the video driver with @VDCTL (0B88H), the printer driver (0E01H) and the floppy disk driver (0E3DH). Sectors 14 and 15 hold only format fill; 0FF4H-12FFH is the low I/O zone for added drivers. The resident code runs with the keyboard and video memory switched out; each routine that needs them calls ENADIS_DO_RAM (0817H), which switches them in and arranges for them to be switched out when the routine returns.

The bytes are those of the LS-DOS 6.3.1 level 1H system diskette. The labels are the ones of the LS-DOS 6.3.1 source code, whose LOWCORE build is the first 3572 bytes of this file byte for byte.

Notes

Six places hide an instruction in the operand of another: 4388H (DDH, so GOTERR skips the load of No system), 0C8BH and 0CA5H (21H, LD HL) in the video driver, and 0E68H, 0F07H and 0FB1H (1EH and 06H, LD E and LD B) in the floppy driver. A jump to the hidden instruction runs it; falling into the prefix skips it.

The SVCs here expect their main argument in Register A: the SVC dispatcher of SYS0/SYS copies the caller's Register C into Register A before it jumps to the routine.

Bugs (listed on the LS-DOS reference page): B1, KCK@ at 0805H tests a count, not the keyboard row, as the BREAK key when other routines have the keyboard switched in, so four or more levels give a BREAK nobody pressed (latent); B2, the midnight roll-over (076AH) does not step the day of the year and the day of the week in DATE$+3 and DATE$+4; B3, the new year (0785H) leaves February's length as it was set at start-up.

Variables

Memory Used and Kept by BOOT/SYS

Address
Size
Contents
0000H-01FFH
512 bytes
Low Memory (SYS0/SYS)
Not part of this file: SYS0/SYS loads it. The routines here use these cells of it.
000EH
1 byte
FDDINT$
The floppy driver's interrupt hook, called by RWINIT (0F3FH). LBOOT stores C9H (RET) there for the load of SYS0/SYS (0249H).
001BH
1 byte
PDRV$
The drive select byte last sent to port F4H, stored by SELECT (0ED4H), read by TSTBSY (0E87H) and RWINIT (0F2EH).
002CH
1 byte
TIMER$
The clock interrupt counter, read for the key repeat timing (09A8H, 0A1EH, 0A92H, 0B53H).
002DH-002FH
3 bytes
TIME$
Seconds, minutes and hours, advanced by TIMTSK$ (075BH) and written as text by @TIME (078DH).
0033H-0035H
3 bytes
DATE$
Year (excess 1900), day and month, advanced at midnight (076AH) and written by DATELO$ (07A8H).
0038H
1 byte
Interrupt Vector
Set to C9H (RET) by the boot code (4325H).
0066H-0068H
3 bytes
NMI Vector
Set to JP 43CDH by the boot code (4318H-4320H), for the end of each boot read.
006CH
1 byte
CFLAG$
Bit 2: SYS1/SYS is reading a command line, which allows CTL-R in @KEYIN (05EAH).
006DH
1 byte
DFLAG$
Bit 1: type-ahead on (0B28H). Bit 7: graphic printer, codes 80H-FFH printed as they are by @VDPRT (0935H).
0074H
1 byte
KFLAG$
Bit 0 BREAK (set by 0813H and 0A4EH, tested by @CKBRKC), bit 1 pause (07F1H), bit 2 ENTER (0803H), bit 5 CAPS lock (0A7BH), bit 7 the type-ahead buffer holds keys (0B7DH, 0B6DH).
0076H
1 byte
MODOUT$
The copy of output port ECH: bit 2 40 characters a line, bit 3 the alternate character set (SETMOD 0CB2H).
0077H
1 byte
NFLAG$
Bit 6: @VDCTL is called from a task (0D48H).
0078H
1 byte
OPREG$
The copy of the Operation Register, port 84H: stored by the boot code (4308H), ENADIS_DO_RAM and DIS_DO_RAM (085BH) and @BANK (08D6H).
007BH
1 byte
RFLAG$
The disk retry count, set to 4 by LBOOT (0244H) and read by IORQST (0F46H).
007CH
1 byte
SFLAG$
Bit 4: BREAK disabled (080FH, 0A47H). Bit 5: a JCL file is running (058AH).
007FH
1 byte
VFLAG$
The video flags: bits 3-0 the blink count, bit 4 the clock display, bit 5 the blink phase, bit 6 solid cursor, bit 7 no blink while the video driver works (0DB7H, 0BDAH, 071CH).
0089H
3 bytes
@KITSK
The keyboard task hook, called by KIBGN (0925H).
0200H
1 byte
BUR$
Bank Use RAM: one bit for each memory bank in use, set, reset and tested by @BANK (08AFH).
0201H
1 byte
BAR$
Bank Available RAM: a bit is clear when the bank is present (08C0H). FEH in the file.
0202H
1 byte
LBANK$
The memory bank switched in (0653H, 08DBH-08E2H). 14H in the file.
0203H-0205H
3 bytes
JCLCB$
The mini DCB through which @JCL reads the JCL file (0630H).
0206H-0207H
2 bytes
DVRHI$
The start of the low I/O zone, 0FF4H.
0208H-0237H
48 bytes
Device Control Blocks
KIDCB$ 0208H, DODCB$ 0210H, PRDCB$ 0218H, SIDCB$ 0220H, SODCB$ 0228H, JLDCB$ 0230H, 8 bytes each.
0300H-037FH
128 bytes
System Stack
Sector 1 is read to 0300H-03FFH at boot; 0300H-037FH is then the system stack below STACK$ (0380H). ENADIS_DO_RAM uses 0340H as a stack when the caller's stack is too high (082BH).
0382H@PAUSE
The delay routine of SYS0/SYS (count in Register Pair BC), called at 0563H, 0A8FH, 0E25H, 0EE3H and 0FEFH.
0401H-040DH
13 bytes
ZERO$ and MAXDAY$
The month lengths at 0402H-040DH, indexed by MAXDAY$ 0401H plus the month (0770H).
040EH-040FH
2 bytes
HIGH$
The top of the memory available to programs.
0410H-041FH
16 bytes
PAKNAM$
The system name LS-DOS63Level-1H.
0420H-046FH
80 bytes
INBUF$
The command line input buffer.
0470H-04BFH
80 bytes
DCT$
The drive code tables of drives 0 to 7, 10 bytes each.
04C0H-04FFH
64 bytes
SYSINFO
DSKTYP$, DTPMT$, TMPMT$, RSTOR$, DAYTBL$ and MONTBL$.
051DH-0527H
11 bytes
LOGBUF
The time field of a job log line (0510H).
0598H-0599H
2 bytes
@KEYIN Input Routine
The operand of the CALL at 0597H: 0628H (@KEY) or 0630H (@JCL), stored at 0593H.
070FH-0712H
4 bytes
TIMETBL
The limits 60, 60 and 24 and the interrupt counter of the second.
07AFH-07B0H
2 bytes
PCSAVE$
The program counter at the last interrupt, shown by TRACE_INT.
0835H-0836H
2 bytes
OPREG_SV_PTR
The operand of the LD HL at 0834H: the current level of the Operation Register save stack (086EH at rest).
0863H-0864H
2 bytes
SPSAV
The operand of the LD SP at 0862H: the caller's stack while ENADIS_DO_RAM uses 0340H.
0866H-0867H
2 bytes
AFSAV
The operand of the LD HL at 0865H: Register Pair AF kept by ENADIS_DO_RAM and DIS_DO_RAM.
086BH-086CH
2 bytes
HLSAV
The operand of the LD HL at 086AH: Register Pair HL kept by ENADIS_DO_RAM and DIS_DO_RAM.
086FH-0876H
8 bytes
OPREG_SV_AREA
The saved Operation Register values of up to eight nested ENADIS_DO_RAM calls.
08B0H
1 byte
@BANK Bit Instruction
The second byte of the CB instruction at 08AFH (RES, BIT or SET), stored at 08A5H.
08FCH-0907H
12 bytes
KIDATA$
The last key, the repeat time, the repeat delay (22) and rate (2), and the image of the eight keyboard rows.
095CH
1 byte
@VDPRT Opcode
3EH (LD A,2EH) or FEH (CP 2EH), stored at 093FH.
0B94H-0B98H
5 bytes
DODATA$
The video mode byte (protected lines, tabs or special characters, show controls), CURSOR, CRSAVE and CRSCHAR.
0DCBH
1 byte
INVIDEO
The operand of the LD A at 0DCAH: 80H for reverse video, 00H for normal, stored at 0C9BH.
0E7DH
1 byte
CKVER
NOP for a read, DEC L for a verify, stored at 0E6AH.
0F93H-0F94H
2 bytes
CALLIO
The operand of the CALL at 0F92H: RDIN, VERFIN or WROUT, stored by GRABNDO (0F83H).
0F95H
1 byte
DISKEI
NOP in the file, EI once SYS0/SYS is loaded (0264H).
0FB5H
1 byte
ERRSTRT Operand
The error code base, 1 for a read or verify, 9 for a write, stored at 0F7CH.
0FE8H
1 byte
BUCKET
The byte that receives every byte read by a verify.
0FF4H-12FFH
780 bytes
Low I/O Zone
Free memory for drivers and filters, starting at DVREND$.
1200H-12FFH
256 bytes
BUFFER
The boot code's sector buffer: the GAT, the directory sector of SYS0/SYS and then each sector of SYS0/SYS (4374H, 029EH).
1300H@BYTEIO
The byte I/O of SYS0/SYS for a DCB that is an open file, reached from @CHNIO (0693H).
43EFH-43F6H
8 bytes
BOOTBUF
The four extents of SYS0/SYS copied from its directory entry (4365H), read by GETEXT through Index Register IX.
F401H-F480H
8 bytes
Keyboard Rows
F401H, F402H, F404H, F408H, F410H, F420H, F440H and F480H, read by KISCAN (0983H), KCK@ (07D6H) and CTL FFH (0AECH) while ENADIS_DO_RAM has them in the memory map.
F800H-FF7FH
1920 bytes
Video Memory
The 80 by 24 screen, row 0 first.
FF80H-FFD3H
84 bytes
Type-Ahead Buffer
FF80H the switch, FF81H the PUT offset, FF82H the GET offset, FF83H-FFD3H the keys (TYPAHD 0AD5H, TYPTSK$ 0B26H).

Ports

PortUse
84HOperation Register: 86H at boot (4306H); bits 1-0 the memory map (ENADIS_DO_RAM 0842H), bit 3 inverse video (0C92H), bits 6-4 the memory bank (@BANK 08D3H).
88H, 89HCRTC address and data registers, loaded by INITCRTC (02E4H, 02E6H).
E4HNMI mask: C0H enables the controller interrupt and time-out (43BBH, 0FCFH), 00H turns them off (43D0H, 0FEAH).
ECHMode output: 40 characters a line (bit 2) and the alternate character set (bit 3), SETMOD 0CB5H.
F0H-F3HWD1793 command or status, track, sector and data registers.
F4HDrive select: drive bits 3-0, side bit 4, precompensation bit 5, wait state generator bit 6, double density bit 7.
F8HPrinter: data out (0E33H), status in (0E36H).

Disassembly

0200H - Page 2: Bank Bytes, JCL Mini-DCB and the Device Control Blocks

BOOT/SYS sector 0 (cylinder 0, sector 0). The boot code at 4300H reads it to 0200H-02FFH with the other sectors of cylinder 0. The first 38H bytes are data that stay resident: the memory bank bytes, the mini DCB for JCL input, the start of the low I/O zone and the device control blocks (DCBs) of the six standard devices. Each DCB is 8 bytes: +0 the type byte (bit 7 an open file, bit 6 filtered, bit 5 linked, bit 4 routed, bit 3 NIL, bit 2 accepts @CTL, bit 1 accepts @PUT, bit 0 accepts @GET), +1 and +2 the driver address (for a routed or linked device the address of another DCB), +3 to +5 for system use (for a routed device the original type byte and vector that RESET copies back), +6 and +7 the two letter device name.

0200BUR$
DEFB 00H 00
BUR$ (Bank Use RAM), 0200H: one bit for each 32K memory bank, set while the bank is in use. The file holds 00H, no bank in use.
0201BAR$
DEFB 0FEH FE
BAR$ (Bank Available RAM), 0201H: one bit for each 32K memory bank (bit 0 bank 0, bit 1 bank 1, bit 2 bank 2), clear when the bank is present: @BANK at 08C3H refuses a bank whose bit is set. The file holds FEH, which allows only bank 0.
0202LBANK$
DEFB 14H 14
LBANK$ (Directory Cylinder and Logical Bank), 0202H. The file holds 14H (20), the directory cylinder of this diskette.
0203-0205JCLCB$
DEFB 01H, 00H, 00H 01 00 00
JCLCB$ (Mini-DCB for JCL Gets), 0203H-0205H: a type byte of 01H (bit 0, the device accepts @GET) and a vector of 0000H, used when a JCL file supplies the keyboard input.
0206-0207DVRHI$
DEFW 0FF4H F4 0F
DVRHI$ (Start of the Low I/O Zone), 0206H-0207H = 0FF4H (DVREND$), the first byte after the resident drivers. Drivers and filters loaded into low memory are placed from this address up to 12FFH, and DVRHI$ is moved up past each one.
0208KIDCB$
DEFB 05H 05
KIDCB$ (Keyboard DCB), 0208H: type byte 05H, bit 2 (accepts @CTL) and bit 0 (accepts @GET).
0209-020A
DEFW 08F0H F0 08
KIDCB$+1, 0209H-020AH = 08F0H, the address of KIDVR, the keyboard driver.
020B-020F
DEFB 00H, 00H, 00H / DEFM "KI" 00 00 00 4B 49
KIDCB$+3 to +7, 020BH-020FH: three system bytes of 00H and the device name KI.
0210DODCB$
DEFB 07H 07
DODCB$ (Video Display DCB), 0210H: type byte 07H, bits 2, 1 and 0 (accepts @CTL, @PUT and @GET).
0211-0212
DEFW 0B88H 88 0B
DODCB$+1, 0211H-0212H = 0B88H, the address of DODVR, the video driver.
0213-0217
DEFB 00H, 00H, 00H / DEFM "DO" 00 00 00 44 4F
DODCB$+3 to +7, 0213H-0217H: three system bytes of 00H and the device name DO.
0218PRDCB$
DEFB 06H 06
PRDCB$ (Printer DCB), 0218H: type byte 06H, bits 2 and 1 (accepts @CTL and @PUT).
0219-021A
DEFW 0E01H 01 0E
PRDCB$+1, 0219H-021AH = 0E01H, the address of PRDVR, the printer driver.
021B-021F
DEFB 00H, 00H, 00H / DEFM "PR" 00 00 00 50 52
PRDCB$+3 to +7, 021BH-021FH: three system bytes of 00H and the device name PR.
0220SIDCB$
DEFB 15H 15
SIDCB$ (Standard Input DCB), 0220H: type byte 15H, bit 4 (routed), bit 2 (@CTL) and bit 0 (@GET): the SI device is routed to the KI device.
0221-0222
DEFW 0208H 08 02
SIDCB$+1, 0221H-0222H = 0208H, the address of KIDCB$, the DCB that the SI device is routed to.
0223-0227
DEFB 0DH, 00H, 00H / DEFM "SI" 0D 00 00 53 49
SIDCB$+3 to +7, 0223H-0227H: the type byte and vector that RESET restores (0DH, a NIL device accepting @CTL and @GET, with vector 0000H) and the device name SI.
0228SODCB$
DEFB 17H 17
SODCB$ (Standard Output DCB), 0228H: type byte 17H, bit 4 (routed) and bits 2, 1 and 0 (@CTL, @PUT, @GET): the SO device is routed to the DO device.
0229-022A
DEFW 0210H 10 02
SODCB$+1, 0229H-022AH = 0210H, the address of DODCB$, the DCB that the SO device is routed to.
022B-022F
DEFB 0FH, 00H, 00H / DEFM "SO" 0F 00 00 53 4F
SODCB$+3 to +7, 022BH-022FH: the type byte and vector that RESET restores (0FH, a NIL device accepting @CTL, @PUT and @GET, with vector 0000H) and the device name SO.
0230-0237JLDCB$
DEFB 0AH, 00H, 00H, 0AH, 00H, 00H / DEFM "JL" 0A 00 00 0A 00 00 4A 4C
JLDCB$ (Job Log DCB), 0230H-0237H: type byte 0AH (bit 3 NIL, bit 1 accepts @PUT), vector 0000H, the restore copy 0AH and 0000H, and the device name JL. The next DCB position, 0238H (S1DCB$), is the first spare DCB once the boot loader that follows here is no longer needed.

0238H - LBOOT: Load SYS0/SYS

The second half of the boot loader, entered by the JP 0238H at 436FH once the boot code at 4300H has read cylinder 0 to 0200H-11FFH, initialized the video controller and found the first four extents of SYS0/SYS in the directory. It sets up the drive code table of drive 0 for the floppy driver, loads the SYS0/SYS load module through the resident floppy driver FDCDVR and jumps to its transfer address. On entry Index Register IX = 43EEH (one byte before the copied extents) and the alternate Register Pair HL = 12FFH (the last byte of the sector buffer at 1200H).

0238LBOOT
LD IY,0470H FD 21 70 04LD IY,DCT$
Load Index Register IY with 0470H (DCT$), the drive code table entry of drive 0. The floppy driver FDCDVR reads the drive parameters through Index Register IY.
023C
LD A,(IY+09H) FD 7E 09
Load Register A with DCT$+9 of drive 0 (address 0479H, Index Register IY+09H), the directory cylinder, which the boot code stored there at 433DH.
023F
LD (IY+05H),A FD 77 05
Store Register A (the directory cylinder) into DCT$+5 of drive 0 (address 0475H, Index Register IY+05H), the drive's current cylinder: the last read of the boot code (the SYS0/SYS directory sector) left the head on the directory cylinder.
0242
LD A,04H 3E 04
Load Register A with 04H, the number of disk retries to use.
0244
LD (007BH),A 32 7B 00
Store Register A (4) into 007BH (RFLAG$, the system's disk retry count, FLGTAB$+R-A).
0247
LD A,C9H 3E C9
Load Register A with C9H, the opcode of RET, to be stored into the FDDINT$ hook.
0249
LD (000EH),A 32 0E 00LD (FDDINT$),A
Store Register A (C9H, RET) into 000EH (FDDINT$), the hook that the floppy driver calls, so that the call returns at once while SYS0/SYS is loaded.
024C
LD A,12H 3E 12
Load Register A with 12H (18), the sectors per track of a 5 inch double density diskette.
024E
BIT 5,(IY+04H) FD CB 04 6E
Test bit 5 of DCT$+4 of drive 0 (address 0474H, Index Register IY+04H), which the boot code set at 434FH when the GAT showed a two sided diskette.
0252
If bit 5 is clear (one sided), jump to 0255H (NOTDBL) and keep 18 sectors a cylinder in Register A.
0254
ADD A,A 87
Two sided: add Register A to itself, giving 24H (36), the sectors per cylinder of both sides.
0255NOTDBL
LD (02A5H),A 32 A5 02LD (SECTRK),A
Store Register A (18 or 36, the sectors per cylinder) into 02A5H, the operand of the SUB at 02A4H (SECTRK) that tests for the end of a cylinder.
0258
EXX D9
Switch to the alternate register set (Register Pairs BC, DE and HL), which holds the disk position while the main set holds the memory pointer and block count.
0259
LD C,06H 0E 06
Load the alternate Register C with 06H, the sectors per granule.
025B
Call GETEXT at 02B1H to load the alternate Register Pair DE with the cylinder and first sector of the first extent of SYS0/SYS, and the alternate Register B with the number of sectors in that extent.
025E
EXX D9
Switch from the alternate register set back to the main register set.
025F
Call LOAD at 0268H to read the SYS0/SYS load module into memory. It returns with Register Pair HL holding the transfer address of the module.
0262
LD A,FBH 3E FB
Load Register A with FBH, the opcode of EI, to be stored into the floppy driver.
0264
LD (0F95H),A 32 95 0FLD (DISKEI),A
Self-Modifying Code
Store Register A (FBH, EI) into 0F95H (DISKEI) in the floppy driver FDCDVR, so that from now on the driver enables interrupts there. The driver ran with interrupts disabled while it loaded SYS0/SYS.
0267
JP (HL) E9
Jump to the address in Register Pair HL, the transfer address of SYS0/SYS (1E00H on this diskette), which continues the system initialization.

0268H - LOAD: Read a Load Module

Reads load module records through RDBYTE and places every load block in memory. Record type 01H is a load block (length byte, two address bytes, then the data); type 02H is the transfer address, which ends the load with the address in Register Pair HL; any other type is skipped by its length byte.

0268LOAD
Call RDBYTE at 0297H to load Register A with the next byte of the file, the record type code.
026B
DEC A 3D
Decrement Register A (the type code); it becomes zero for a type 01H load block.
026C
If Register A is not zero (not a load block), jump to 027AH (LOAD2) to test for the other types.
026E
Call GETADR at 0288H to read the block length into Register B and the load address into Register Pair HL; Register B returns holding the number of data bytes of the block.
0271LOAD1
Call RDBYTE at 0297H to load Register A with the next data byte of the block.
0274
LD (HL),A 77
Store Register A (the data byte) into the memory location pointed to by Register Pair HL (the load address).
0275
INC HL 23
Increment Register Pair HL to the next load address.
0276
Decrement Register B (the bytes of the block still to load) and loop back to 0271H until it reaches zero.
0278
Jump back to LOAD at 0268H to read the next record.
027ALOAD2
DEC A 3D
Decrement Register A again; it becomes zero for a type 02H record, the transfer address.
027B
If Register A is zero (type 02H), jump to GETADR at 0288H, which reads the transfer address into Register Pair HL and returns from LOAD to the caller at 0262H.
027D
Any other record type: call RDBYTE at 0297H to load Register A with the record's length byte.
0280
LD B,A 47
Copy Register A (the record length) into Register B as the count of bytes to skip.
0281LOAD3
Call RDBYTE at 0297H to read one byte of the record into Register A and ignore it.
0284
Decrement Register B (the bytes left to skip) and loop back to 0281H until it reaches zero.
0286
Jump back to LOAD at 0268H to read the next record.

0288H - GETADR: Read a Block Length and Address

Reads the length byte and the two address bytes of a load block (or of the transfer record) and leaves the address in Register Pair HL and the length less two in Register B.

0288GETADR
Call RDBYTE at 0297H to load Register A with the length byte of the record.
028B
LD B,A 47
Copy Register A (the record length, which counts the two address bytes) into Register B.
028C
Call RDBYTE at 0297H to load Register A with the low byte of the load address.
028F
LD L,A 6F
Copy Register A (the low byte of the address) into Register L.
0290
DEC B 05
Decrement Register B (the record length) for the address byte just read.
0291
Call RDBYTE at 0297H to load Register A with the high byte of the load address.
0294
LD H,A 67
Copy Register A (the high byte of the address) into Register H, so Register Pair HL holds the load or transfer address.
0295
DEC B 05
Decrement Register B again for the second address byte; Register B now holds the number of data bytes (0 means 256).
0296
RET C9
Return to the caller with Register Pair HL = the address and Register B = the data byte count.

0297H - RDBYTE: Read the Next Byte of the File

Returns the next byte of SYS0/SYS in Register A. The alternate register set keeps the disk position: Register Pair HL the pointer into the sector buffer at 1200H, Register E the sector, Register D the cylinder, Register B the sectors left in the current extent and Register C the sectors per granule. When the buffer is used up the next sector is read through the drive 0 vector at 0470H.

0297RDBYTE
EXX D9
Switch to the alternate register set (the buffer pointer in Register Pair HL and the disk position in Register Pairs DE and BC); the main set keeps the memory pointer and the block count.
0298
INC L 2C
Increment Register L, the low byte of the buffer pointer. It wraps from FFH to 00H when the 256 byte buffer at 1200H is used up, and Register H stays 12H.
0299
If Register L did not wrap (bytes are left in the buffer), jump to 02AEH (RDB2) to fetch the byte.
029B
PUSH BC C5
Save Register Pair BC (the alternate Register B, the sectors left in this extent, and Register C, the sectors per granule) on the stack.
029C
LD B,09H 06 09
Load Register B with 09H, the floppy driver function code for reading a sector (RDSEC).
029E
Call the drive 0 entry of the drive code table at 0470H (DCT$, a JP to FDCDVR) to read cylinder Register D, sector Register E into the buffer at Register Pair HL (1200H).
02A1
POP BC C1
Restore Register Pair BC (the sectors left in this extent and the sectors per granule) from the stack.
02A2
INC E 1C
Increment Register E to the next sector number.
02A3
LD A,E 7B
Copy Register E (the next sector number) into Register A.
02A4SECTRK
SUB 00H D6 00
Self-Modifying Code
Subtract the sectors per cylinder from Register A (the next sector). The operand byte at 02A5H is 00H in the file; LBOOT stores 18 (one sided) or 36 (two sided) there at 0255H. Register A becomes zero when the sector number has reached the end of the cylinder.
02A6
If Register A is not zero (still inside the cylinder), jump to 02AAH (RDB1).
02A8
LD E,A 5F
End of the cylinder: copy Register A (zero) into Register E to start again at sector 0.
02A9
INC D 14
Increment Register D (the cylinder) to the next cylinder of the file.
02AARDB1
DEC B 05
Decrement Register B, the sectors left in the current extent.
02AB
If Register B has reached zero, call GETEXT at 02B1H to load Register Pairs DE and B with the position and length of the next extent.
02AERDB2
LD A,(HL) 7E
Load Register A with the byte at the buffer pointer in Register Pair HL.
02AF
EXX D9
Switch from the alternate register set back to the main register set, keeping the byte in Register A.
02B0
RET C9
Return to the caller with the next byte of the file in Register A.

02B1H - GETEXT: Get the Next Extent

Advances Index Register IX to the next two byte extent of the SYS0/SYS directory entry, which the boot code copied to 43EFH-43F6H, and turns it into a starting cylinder (Register D), starting sector (Register E) and sector count (Register B). An extent is a cylinder byte followed by a byte whose bits 7-5 are the starting granule and bits 4-0 the number of granules less one.

02B1GETEXT
INC IX DD 23
Increment Index Register IX (one byte before the extent, or the granule byte of the previous extent) to the cylinder byte of the next extent.
02B3
INC IX DD 23
Increment Index Register IX again to the granule byte of the extent.
02B5
LD A,(IX+00H) DD 7E 00
Load Register A with the granule byte of the extent at Index Register IX+00H.
02B8
PUSH AF F5
Save Register Pair AF (the granule byte in Register A) on the stack for the granule count.
02B9
RLCA 07
Rotate Register A left; three rotations bring the starting granule from bits 7-5 down to bits 2-0.
02BA
RLCA 07
Rotate Register A left (second of the three rotations of the starting granule).
02BB
RLCA 07
Rotate Register A left (third rotation); the starting granule is now in bits 2-0 of Register A.
02BC
AND 07H E6 07
Mask Register A with 07H, keeping only the starting granule number (0 to 7).
02BE
Call MULTCA at 02CEH to multiply Register A (the starting granule) by Register C (6 sectors per granule).
02C1
LD E,A 5F
Copy Register A (starting granule times 6) into Register E, the first sector of the extent.
02C2
POP AF F1
Restore Register Pair AF, so Register A holds the granule byte of the extent again.
02C3
AND 1FH E6 1F
Mask Register A with 1FH, keeping bits 4-0, the number of granules in the extent less one.
02C5
INC A 3C
Increment Register A to the number of granules in the extent.
02C6
Call MULTCA at 02CEH to multiply Register A (the granules in the extent) by Register C (6 sectors per granule).
02C9
LD B,A 47
Copy Register A (the sectors in the extent) into Register B, the sector count of this extent.
02CA
LD D,(IX-01H) DD 56 FF
Load Register D with the cylinder byte of the extent at Index Register IX-01H, the starting cylinder.
02CD
RET C9
Return with Register D = cylinder, Register E = first sector and Register B = sectors of the extent.

02CEH - MULTCA: Short Multiply

Multiplies Register A by Register C by shift and add, and returns the low byte of the product in Register A. Register Pair BC is kept; Register D is used.

02CEMULTCA
PUSH BC C5
Save Register Pair BC (Register C holds the sectors per granule, Register B the caller's count) on the stack.
02CF
LD D,A 57
Copy Register A (the multiplicand) into Register D.
02D0
XOR A AF
Clear Register A, the product, before the eight shift and add passes.
02D1
LD B,08H 06 08
Load Register B with 08H, one pass for each bit of the multiplier in Register C.
02D3MLTCA
ADD A,A 87
Add Register A to itself, shifting the product left one bit.
02D4
SLA C CB 21
Shift Register C (the multiplier) left one bit, moving its top bit into the Carry flag.
02D6
If the bit shifted out of Register C was 0, jump to 02D9H (MLTCA1) and do not add.
02D8
ADD A,D 82
Add Register D (the multiplicand) to Register A (the product).
02D9MLTCA1
Decrement Register B (the bits left) and loop back to 02D3H until all eight bits of Register C are done.
02DB
POP BC C1
Restore Register Pair BC (Register C the sectors per granule, Register B the caller's count) from the stack.
02DC
RET C9
Return to the caller with the low byte of the product in Register A.

02DDH - INITCRTC: Initialize the CRTC

Loads the sixteen registers of the 6845 video controller (CRTC), from register 15 down to register 0, from the table at 02EEH-02FDH. Port 88H selects a CRTC register and port 89H writes it. Called by the boot code at 4337H.

02DDINITCRTC
LD BC,0F88H 01 88 0F
Load Register Pair BC with 0F88H: Register B = 0FH (15, the highest CRTC register) and Register C = 88H, the CRTC address register port.
02E0
LD HL,02FDH 21 FD 02LD HL,CRTCTAB
Point Register Pair HL to 02FDH (CRTCTAB), the value of CRTC register 15, the last byte of the table.
02E3
LD A,(HL) 7E
Load Register A with the value at Register Pair HL, the setting for CRTC register Register B.
02E4
OUT (C),B ED 41
Send Register B (the register number) to the port in Register C (88H, the CRTC address register) to select the register.
02E6
OUT (89H),A D3 89
Send Register A (the value) to port 89H, the CRTC data register, writing the selected register.
02E8
DEC HL 2B
Decrement Register Pair HL to the value of the next lower register.
02E9
DEC B 05
Decrement Register B to the next lower CRTC register number.
02EA
Loop back to 02E3H while Register B is still positive (0 or above), so registers 15 down to 0 are all written.
02ED
RET C9
Return to the boot code at 433AH with all sixteen CRTC registers written.
02EE
DEFB 63H 63
CRTC register 0, horizontal total: 63H (99), 100 character times a line.
02EF
DEFB 50H 50
CRTC register 1, horizontal displayed: 50H (80) characters a line.
02F0
DEFB 55H 55
CRTC register 2, horizontal sync position: 55H (85).
02F1
DEFB 0AH 0A
CRTC register 3, horizontal sync width: 0AH (10).
02F2
DEFB 19H 19
CRTC register 4, vertical total: 19H (25), 26 character rows a frame.
02F3
DEFB 04H 04
CRTC register 5, vertical total adjust: 04H scan lines.
02F4
DEFB 18H 18
CRTC register 6, vertical displayed: 18H (24) rows.
02F5
DEFB 18H 18
CRTC register 7, vertical sync position: 18H (24).
02F6
DEFB 00H 00
CRTC register 8, interlace mode: 00H, non interlaced.
02F7
DEFB 09H 09
CRTC register 9, maximum scan line address: 09H, ten scan lines a character row.
02F8
DEFB 65H 65
CRTC register 10, cursor start: 65H, scan line 5 with bits 6-5 = 11 (a blinking cursor at 1/32 of the field rate).
02F9
DEFB 09H 09
CRTC register 11, cursor end: scan line 09H, the bottom line of a character row.
02FA
DEFB 00H 00
CRTC register 12, display start address high byte: 00H.
02FB
DEFB 00H 00
CRTC register 13, display start address low byte: 00H.
02FC
DEFB 00H 00
CRTC register 14, cursor address high byte: 00H.
02FDCRTCTAB
DEFB 00H 00
CRTC register 15, cursor address low byte: 00H. INITCRTC at 02DDH starts here and works down.
02FE-02FF
DEFB 00H x 2 00 x 2
Two zero bytes that fill sector 0 to its end at 02FFH.
0300-03FF
DEFS 256
0300H-03FFH: the second copy of sector 1, read here with the rest of cylinder 0 and never run; its bytes are shown at their run address 4300H-43FFH below. Once the system is up, 0300H-037FH is the system stack (STACK$ is 0380H) and SYS0/SYS loads 0380H-03FFH, which holds @PAUSE at 0382H, @SOUND at 0392H and @DECHEX at 03E1H.

4300H - BOOT: System Boot Entry, Loaded by the ROM

BOOT/SYS sector 1 (cylinder 0, sector 1). The Model 4 ROM reads this sector to 4300H-43FFH and jumps to 4300H; it is also read again to 0300H-03FFH with the rest of cylinder 0, where it is never run (SYS0/SYS later loads 0380H-03FFH, and 0300H-037FH becomes the system stack). The rows show the run address 4300H-43FFH, with the address in the 0200H image of the file under it. BOOT turns on the all RAM memory map, clears the screen, reads cylinder 0 sectors 0 to 15 to 0200H-11FFH, initializes the video controller, reads the GAT and the directory sector of SYS0/SYS, and hands over to LBOOT at 0238H.

4300
0300HBOOT
NOP 00
No operation: the first byte of the boot sector, where the ROM jumps.
4301
0301H
CP 14H FE 14
Compare Register A with 14H. The comparison has no use: the operand byte at 4302H (DIRTRK) is the directory cylinder of the diskette (14H, cylinder 20), read at 433AH, and an instruction that ignores it lets it sit in the code.
4303
0303H
DI F3
Disable interrupts: the boot code owns the machine until SYS0/SYS sets up its own interrupt handling.
4304
0304H
LD A,86H 3E 86
Load Register A with 86H for the Operation Register: bits 1-0 = 10 (Model III ROM off, RAM at 0000H-F3FFH, keyboard at F400H-F7FFH, video at F800H-FFFFH), bit 2 = 1 (80 by 24 display) and bit 7 = 1.
4306
0306H
OUT (84H),A D3 84
Send Register A (86H) to port 84H, the Operation Register, which takes the ROM out of the memory map ("Bring up the RAM" in the source).
4308
0308H
LD (0078H),A 32 78 00LD (OPREG$),A
Store Register A (86H) into 0078H (OPREG$), the system's copy of the Operation Register, since the port cannot be read back.
430B
030BH
LD HL,F800H 21 00 F8LD HL,CRTBGN$
Point Register Pair HL to F800H (CRTBGN$), the first byte of video memory in this memory map.
430E
030EH
LD DE,F801H 11 01 F8
Point Register Pair DE to F801H, one byte past Register Pair HL, so the LDIR copies the first byte through the screen.
4311
0311H
LD BC,077FH 01 7F 07
Load Register Pair BC with 077FH (1919), the size of the 80 by 24 screen (1920 bytes) less the one byte stored first.
4314
0314H
LD (HL),20H 36 20
Store 20H (a space) into the first byte of video memory at Register Pair HL (F800H).
4316
0316H
LDIR ED B0
Copy from Register Pair HL to Register Pair DE for Register Pair BC bytes, spreading the space through F800H-FF7FH: the screen is cleared.
4318
0318H
LD HL,43CDH 21 CD 43LD HL,NMIRET
Point Register Pair HL to 43CDH (NMIRET), where the read routine continues after the disk controller's interrupt.
431B
031BH
LD (0067H),HL 22 67 00
Store Register Pair HL (43CDH) into 0067H-0068H, the address bytes of the jump at the NMI vector 0066H.
431E
031EH
LD A,C3H 3E C3
Load Register A with C3H, the opcode of JP, for the NMI vector at 0066H.
4320
0320H
LD (0066H),A 32 66 00LD (NMIVECT),A
Store Register A (C3H) into 0066H, the NMI vector, which is now JP 43CDH: the end of a disk read arrives as a non maskable interrupt.
4323
0323H
LD A,C9H 3E C9
Load Register A with C9H, the opcode of RET, for the interrupt vector at 0038H.
4325
0325H
LD (0038H),A 32 38 00
Store Register A (C9H, RET) into 0038H, the maskable interrupt vector, so a stray interrupt returns at once.
4328
0328H
LD HL,0200H 21 00 02
Point Register Pair HL to 0200H, the page that receives sector 0 of cylinder 0 (START$+200H).
432B
032BH
LD D,L 55
Copy Register L (00H) into Register D: cylinder 0.
432C
032CH
LD E,L 5D
Copy Register L (00H) into Register E: sector 0.
432D
032DHRDBOOT
Call RDSEQ at 4377H to read cylinder Register D, sector Register E into the page at Register Pair HL, with retries.
4330
0330H
INC H 24
Increment Register H to the next page of memory, 256 bytes on.
4331
0331H
INC E 1C
Increment Register E to the next sector number.
4332
0332H
LD A,10H 3E 10
Load Register A with 10H (16), the number of sectors of cylinder 0 that make up BOOT/SYS.
4334
0334H
CP E BB
Compare Register A (16) with Register E (the next sector).
4335
0335H
If Register E has not reached 16, loop back to 432DH (RDBOOT): sectors 0 to 15 go to 0200H-11FFH.
4337
0337H
Call INITCRTC at 02DDH, just read in with sector 0, to load the sixteen registers of the 6845 video controller.
433A
033AH
LD A,(4302H) 3A 02 43LD A,(DIRTRK)
Load Register A with the byte at 4302H (DIRTRK), the operand of the CP at 4301H: the directory cylinder, 14H on this diskette.
433D
033DH
LD (0479H),A 32 79 04
Store Register A (the directory cylinder) into 0479H (DCT$+9), the directory cylinder field of the drive code table entry of drive 0.
4340
0340H
LD D,A 57
Copy Register A (the directory cylinder) into Register D, the cylinder to read.
4341
0341H
LD E,00H 1E 00
Load Register E with 00H, sector 0 of the directory cylinder, the Granule Allocation Table (GAT).
4343
0343H
Call RDSECT at 4374H to read the GAT into the buffer at 1200H.
4346
0346H
LD A,(12CDH) 3A CD 12
Load Register A with the byte at 12CDH, GAT+CDH, the formatting byte of the diskette (bit 7 data disk, bit 6 double density, bit 5 two sided, bits 2-0 granules per cylinder less one).
4349
0349H
AND 20H E6 20
Mask Register A with 20H, keeping bit 5, the two sided flag.
434B
034BH
LD HL,0474H 21 74 04
Point Register Pair HL to 0474H (DCT$+4), the second flag byte of the drive 0 drive code table entry.
434E
034EH
OR (HL) B6
OR the byte at Register Pair HL (DCT$+4) into Register A (bit 5 from the GAT).
434F
034FH
LD (HL),A 77
Store Register A back into DCT$+4 at Register Pair HL (0474H): bit 5 is now set when the diskette is two sided.
4350
0350H
LD E,04H 1E 04
Load Register E with 04H, the directory sector whose first entry is SYS0/SYS.
4352
0352H
Call RDSECT at 4374H to read that directory sector into the buffer at 1200H (Register D still holds the directory cylinder).
4355
0355H
LD A,(1200H) 3A 00 12LD A,(BUFFER)
Load Register A with the byte at 1200H, the attribute byte of the first directory entry (SYS0/SYS).
4358
0358H
AND 10H E6 10
Mask Register A with 10H, keeping bit 4, which is set when the directory entry is in use.
435A
035AH
If Register A is zero (no SYS0/SYS on the diskette), jump to 4389H (NOTSYS) to show No system.
435C
035CH
LD HL,121DH 21 1D 12
Point Register Pair HL to 121DH, the last byte of the four extents of the SYS0/SYS entry (entry bytes 16H-1DH at 1216H-121DH).
435F
035FH
LD DE,43F6H 11 F6 43LD DE,BOOTBUF
Point Register Pair DE to 43F6H (BOOTBUF), the top of the area that receives the extents, near the end of this sector.
4362
0362H
LD BC,0008H 01 08 00
Load Register Pair BC with 0008H, the 8 bytes of the four extents.
4365
0365H
LDDR ED B8
Copy downward from Register Pair HL to Register Pair DE for Register Pair BC bytes: the extents land at 43EFH-43F6H, and Register Pair DE ends at 43EEH.
4367
0367H
PUSH DE D5
Save Register Pair DE (43EEH, one byte before the extents) on the stack.
4368
0368H
POP IX DD E1
Pop it into Index Register IX: Index Register IX = 43EEH, which GETEXT at 02B1H advances to each extent.
436A
036AH
EXX D9
Switch to the alternate register set to set the buffer pointer of RDBYTE.
436B
036BH
LD HL,12FFH 21 FF 12
Load the alternate Register Pair HL with 12FFH, the last byte of the buffer at 1200H, so the first RDBYTE call reads a sector.
436E
036EH
EXX D9
Switch from the alternate register set back to the main register set.
436F
036FH
Jump to LBOOT at 0238H, read in with sector 0, to load SYS0/SYS.
4372-4373
0372H-0373H
DEFB 00H, 00H 00 00
Two padding bytes that keep the Seek command byte of READ at 439DH (BOOTST$), where the system expects to find the boot step rate.

4374H - RDSECT and RDSEQ: Read a Sector with Retries

RDSECT reads cylinder Register D, sector Register E into the buffer at 1200H; RDSEQ reads it to the address in Register Pair HL. Each makes up to five attempts and returns with Register A holding the masked status (zero for a good read); after five failures it shows Disk error.

4374
0374HRDSECT
LD HL,1200H 21 00 12LD HL,BUFFER
Point Register Pair HL to 1200H (BUFFER), the boot code's sector buffer.
4377
0377HRDSEQ
LD B,05H 06 05
Load Register B with 05H, the number of read attempts.
4379
0379HRDS1
PUSH BC C5
Save Register Pair BC (Register B, the attempts left) on the stack.
437A
037AH
PUSH HL E5
Save Register Pair HL (the buffer address) on the stack, since the read advances it.
437B
037BH
Call READ at 4396H to read cylinder Register D, sector Register E into the memory at Register Pair HL. It returns with the controller status in Register A.
437E
037EH
POP HL E1
Restore Register Pair HL (the buffer address) from the stack.
437F
037FH
POP BC C1
Restore Register Pair BC (Register B, the attempts left) from the stack.
4380
0380H
AND 1CH E6 1C
Mask Register A (the status) with 1CH: bit 4 record not found, bit 3 CRC error, bit 2 lost data.
4382
0382H
RET Z C8
Return to the caller if Register A is zero (the sector was read without error).
4383
0383H
Decrement Register B (the attempts left) and loop back to 4379H (RDS1) to try again.
4385
0385HGOTERR
LD HL,43E0H 21 E0 43LD HL,DISKERR
Five failures: point Register Pair HL to 43E0H, the text Disk error.
4388
0388H
DEFB 0DDH DD
A DDH prefix byte. Falling through from 4385H, the CPU takes it and the next three bytes as LD IX,43EAH, so the LD HL,43EAH at 4389H is skipped and Register Pair HL keeps pointing to Disk error. A jump to 4389H runs the LD HL,43EAH itself.
4389
0389HNOTSYS
LD HL,43EAH 21 EA 43LD HL,NOSYS
Point Register Pair HL to 43EAH, the text No system (entered from 435AH when the diskette has no SYS0/SYS).
438C
038CH
LD BC,000AH 01 0A 00LD BC,ERRLEN
Load Register Pair BC with 000AH, the 10 characters of the message.
438F
038FH
LD DE,FB93H 11 93 FB
Point Register Pair DE to FB93H, row 11, column 35 of the screen (F800H + 80 times 11 + 35), near its middle.
4392
0392H
LDIR ED B0
Copy the message from Register Pair HL to the screen at Register Pair DE, Register Pair BC (10) bytes.
4394
0394HHALTS
Jump to itself at 4394H: the machine waits here until it is reset.

4396H - READ: Read One Sector from Drive 0

Seeks drive 0 to cylinder Register D and reads sector Register E, 256 bytes, to the memory at Register Pair HL. The data bytes are taken with INI while the wait state generator (bit 6 of port F4H) holds the CPU until each byte is ready; the end of the command is signalled by the controller's interrupt, routed to the NMI, which lands at NMIRET 43CDH. Returns with the controller status in Register A.

4396
0396HREAD
LD BC,81F4H 01 F4 81
Load Register Pair BC with 81F4H: Register B = 81H (bit 7 double density, bit 0 drive 0) and Register C = F4H, the drive select port.
4399
0399H
OUT (C),B ED 41
Send Register B (81H) to the port in Register C (F4H), selecting drive 0 in double density and starting its motor.
439B
039BH
DEC C 0D
Decrement Register C to F3H, the data register of the WD1793 floppy disk controller.
439C
039CH
LD A,18H 3E 18
Load Register A with 18H, the FDC Seek command (bit 3 load the head, bits 1-0 the step rate, 00 here). This operand byte at 439DH is BOOTST$, the boot step rate, which the system keeps at this address.
439E
039EH
OUT (C),D ED 51
Send Register D (the cylinder wanted) to the port in Register C (F3H, the FDC data register), the target of the Seek.
43A0
03A0H
Call FDCMD at 43D9H to send the command in Register A (Seek) to the controller and wait for it to start.
43A3
03A3HSEEK1
IN A,(F0H) DB F0
Read the FDC status register from port F0H into Register A.
43A5
03A5H
BIT 0,A CB 47
Test bit 0 of Register A, the controller's Busy bit.
43A7
03A7H
If the controller is still busy with the Seek, loop back to 43A3H (SEEK1).
43A9
03A9H
LD A,E 7B
Copy Register E (the sector wanted) into Register A.
43AA
03AAH
OUT (F2H),A D3 F2
Send Register A (the sector) to port F2H, the FDC sector register.
43AC
03ACH
LD A,81H 3E 81
Load Register A with 81H: double density and drive 0.
43AE
03AEH
OUT (F4H),A D3 F4
Send Register A (81H) to port F4H, selecting drive 0 again to keep its motor running.
43B0
03B0H
PUSH DE D5
Save Register Pair DE (the cylinder and sector) on the stack; Register Pair DE is used for the read loop.
43B1
03B1H
LD DE,C102H 11 02 C1
Load Register Pair DE with C102H: Register D = C1H (drive 0, double density and bit 6, the wait state generator) and Register E = 02H, the mask of the Data Request bit of the status.
43B4
03B4H
LD A,80H 3E 80
Load Register A with 80H, the FDC Read Sector command.
43B6
03B6H
Call FDCMD at 43D9H to send the Read Sector command to the controller; it returns with Register B = 0, a count of 256 for the INI loop.
43B9
03B9H
LD A,C0H 3E C0
Load Register A with C0H: bit 7 enables the controller's interrupt and bit 6 the drive time-out interrupt, both delivered as an NMI.
43BB
03BBH
OUT (E4H),A D3 E4
Send Register A (C0H) to port E4H, the NMI mask register.
43BD
03BDHREADLP1
IN A,(F0H) DB F0
Read the FDC status register from port F0H into Register A.
43BF
03BFH
AND E A3
AND Register A with Register E (02H), keeping the Data Request bit.
43C0
03C0H
Loop back to 43BDH until the controller has the first data byte ready.
43C2
03C2H
INI ED A2
Input the first data byte from the port in Register C (F3H) into the memory at Register Pair HL, increment Register Pair HL and decrement Register B (00H to FFH).
43C4
03C4H
LD A,D 7A
Copy Register D (C1H: drive 0, double density, wait state generator on) into Register A.
43C5
03C5HREADLP2
OUT (F4H),A D3 F4
Send Register A (C1H) to port F4H, keeping the drive selected with the wait state generator on, which makes the next INI wait for its byte.
43C7
03C7H
INI ED A2
Input the next data byte from the port in Register C (F3H) into the memory at Register Pair HL, increment Register Pair HL and decrement Register B.
43C9
03C9H
Loop back to 43C5H (READLP2) until Register B reaches zero: 256 bytes read in all.
43CB
03CBH
Jump to itself at 43CBH, waiting for the controller's interrupt at the end of the command, which arrives as the NMI and goes to NMIRET at 43CDH.
43CD
03CDHNMIRET
POP DE D1
Pop the NMI's return address (43CBH) into Register Pair DE and discard it, so that the RET at 43D8H returns to the caller of READ.
43CE
03CEH
POP DE D1
Pop Register Pair DE, the cylinder and sector saved at 43B0H.
43CF
03CFH
XOR A AF
Clear Register A to 00H for the NMI mask register.
43D0
03D0H
OUT (E4H),A D3 E4
Send Register A (00H) to port E4H, the NMI mask register, turning off the controller and time-out interrupts.
43D2
03D2H
LD A,81H 3E 81
Load Register A with 81H: double density and drive 0, without the wait state generator.
43D4
03D4H
OUT (F4H),A D3 F4
Send Register A (81H) to port F4H, selecting drive 0 again.
43D6
03D6H
IN A,(F0H) DB F0
Read the FDC status register from port F0H into Register A, the result of the read.
43D8
03D8H
RET C9
Return to the caller of READ with the status in Register A.

43D9H - FDCMD: Send a Command to the FDC

Sends Register A to the command register of the WD1793 at port F0H and waits about 24 loop passes, which gives the controller time to set its Busy bit. Returns with Register B = 0.

43D9
03D9HFDCMD
OUT (F0H),A D3 F0
Send Register A (the command) to port F0H, the FDC command register.
43DB
03DBH
LD B,18H 06 18
Load Register B with 18H (24), the length of the delay loop.
43DD
03DDH
Decrement Register B and loop on this instruction at 43DDH until it reaches zero.
43DF
03DFH
RET C9
Return to the caller with Register B = 0 after the delay loop.
43E0-43E9
03E0H-03E9HDISKERR
DEFM "Disk error" 44 69 73 6B 20 65 72 72 6F 72
DISKERR, 43E0H-43E9H: the message shown by GOTERR at 4385H after five failed reads.
43EA-43F3
03EAH-03F3HNOSYS
DEFM "No system " 4E 6F 20 73 79 73 74 65 6D 20
NOSYS, 43EAH-43F3H: the message shown by NOTSYS at 4389H when the diskette has no SYS0/SYS (10 characters with the trailing space, the length in Register Pair BC at 438CH).
43F4-43FF
03F4H-03FFH
DEFB 00H x 12 00 x 12
Twelve zero bytes that fill the sector to 43FFH. The four extents of SYS0/SYS are copied over 43EFH-43F6H at 4365H, the end of the No system text and the start of these zeros.

0400H - Page 4: System Information, the Input Buffer and the Drive Code Tables

BOOT/SYS sector 2, read to 0400H-04FFH. It stays resident: the version byte, the month length table, HIGH$, the system name with its level letter, the 80 byte command line buffer, the drive code tables (DCT$) of the eight logical drives and the system information bytes (SYSINFO) with the day and month names. The SYSTEM and SYSGEN commands change these bytes in memory, and the configuration of a diskette is kept in its own copy of this sector.

0400
DEFB 63H 63
Operating system version byte, 0400H: 63H, version 6.3.
0401ZERO$
DEFB 0C9H C9
ZERO$, 0401H: C9H. The source calls it the configuration on BOOT flag, 0 when the SYSGEN configuration is to be loaded at boot. The same address is MAXDAY$, the base of the month length table that follows, indexed by the month number 1 to 12.
0402-040D
DEFB 1FH, 1CH, 1FH, 1EH, 1FH, 1EH, 1FH, 1FH, 1EH, 1FH, 1EH, 1FH 1F 1C 1F 1E 1F 1E 1F 1F 1E 1F 1E 1F
The days in each month, January to December, 0402H-040DH: 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 (read as MAXDAY$+month, MAXDAY$ being 0401H).
040E-040FHIGH$
DEFW 0000H 00 00
HIGH$, 040EH-040FH: the highest byte of memory available to programs, which the @HIGH$ SVC reads and sets. It is 0000H in the file.
0410-041FPAKNAM$
DEFM "LS-DOS63Level-1H" 4C 53 2D 44 4F 53 36 33 4C 65 76 65 6C 2D 31 48
PAKNAM$, 0410H-041FH: the 16 character system name. The 1 at 041EH and the level letter H at 041FH show which 6.3.1 patch level the system has.
0420INBUF$
DEFB 0DH 0D
INBUF$, 0420H: the first byte of the 80 byte command line input buffer (also used for the AUTO command), 0DH (an empty line ended by ENTER) in the file.
0421-046F
DEFB 00H x 79 00 x 79
INBUF$+1 to INBUF$+79, 0421H-046FH: the rest of the command line input buffer, zero in the file.

0470H - DCT$: The Drive Code Tables

Eight entries of 10 bytes, one for each logical drive 0 to 7. +0 to +2 a JP to the driver, or a RET followed by the driver address when the drive is disabled; +3 flags (bit 7 software write protect, bit 6 double density, bit 5 8 inch, bit 4 side select for the current I/O, bit 3 hard drive, bit 2 a 0.5 second (1) or 1 second (0) delay after selecting a 5 inch drive, bits 1-0 the step rate); +4 flags (bit 6 the controller can do double density, bit 5 two sided diskette, bit 4 alien controller, bits 3-0 the physical drive select bit); +5 the current cylinder; +6 the highest cylinder; +7 the highest sector number (bits 4-0); +8 the granules per track less one (bits 7-5) and sectors per granule less one (bits 4-0); +9 the directory cylinder. Drives 0 and 1 are enabled 40 cylinder double density floppy drives; drives 2 and 3 are floppy drives that start disabled; drives 4 to 7 have no driver.

0470
DCT$, drive 0
Jump to FDCDVR at 0E3DH, the floppy disk driver. A call to 0470H with a function code in Register B reaches the driver with Index Register IY pointing to this entry.
0473
DEFB 44H 44
DCT$+3, drive 0, 0473H: 44H, bit 6 double density and bit 2 the 0.5 second select delay; step rate 00.
0474
DEFB 0C1H C1
DCT$+4, drive 0, 0474H: C1H, bit 6 (the controller can do double density), bit 0 (physical drive select 1) and bit 7. The boot code ORs bit 5 in at 434FH when the diskette is two sided.
0475
DEFB 00H 00
DCT$+5, drive 0, 0475H: the current cylinder, 00H in the file; LBOOT sets it to the directory cylinder at 023FH.
0476
DEFB 27H 27
DCT$+6, drive 0, 0476H: 27H, the highest cylinder, 39 (40 cylinders).
0477
DEFB 11H 11
DCT$+7, drive 0, 0477H: 11H, the highest sector number, 17 (18 sectors a track).
0478
DEFB 45H 45
DCT$+8, drive 0, 0478H: 45H, bits 7-5 = 2 (3 granules a track) and bits 4-0 = 5 (6 sectors a granule).
0479
DEFB 14H 14
DCT$+9, drive 0, 0479H: 14H, the directory cylinder, 20. The boot code stores the cylinder from 4302H here at 433DH.
047A
DCT$, drive 1
Jump to FDCDVR at 0E3DH, the floppy disk driver, for drive 1.
047D-0483
DEFB 44H, 42H, 0FFH, 27H, 11H, 45H, 14H 44 42 FF 27 11 45 14
DCT$+3 to +9, drive 1, 047DH-0483H: 44H (double density, 0.5 second delay), 42H (double density controller, physical drive select 2), current cylinder FFH (not known yet), highest cylinder 27H, highest sector 11H, 45H (3 granules of 6 sectors), directory cylinder 14H.
0484
RET C9
DCT$, drive 2
Return at once: drive 2 is disabled. The two bytes that follow keep the driver address so that SYSTEM (DRIVE=2,ENABLE) can put back a JP.
0485-0486
DEFW 0E3DH 3D 0E
DCT$+1 and +2, drive 2, 0485H-0486H = 0E3DH, the address of FDCDVR, kept for enabling the drive.
0487-048D
DEFB 44H, 44H, 0FFH, 27H, 11H, 45H, 14H 44 44 FF 27 11 45 14
DCT$+3 to +9, drive 2, 0487H-048DH: 44H, 44H (double density controller, physical drive select 3), current cylinder FFH, highest cylinder 27H, highest sector 11H, 45H, directory cylinder 14H.
048E
RET C9
DCT$, drive 3
Return at once: drive 3 is disabled. The two bytes that follow keep the driver address so that SYSTEM (DRIVE=3,ENABLE) can put back a JP.
048F-0490
DEFW 0E3DH 3D 0E
DCT$+1 and +2, drive 3, 048FH-0490H = 0E3DH, the address of FDCDVR, kept for enabling the drive.
0491-0497
DEFB 44H, 48H, 0FFH, 27H, 11H, 45H, 14H 44 48 FF 27 11 45 14
DCT$+3 to +9, drive 3, 0491H-0497H: 44H, 48H (double density controller, physical drive select 4), current cylinder FFH, highest cylinder 27H, highest sector 11H, 45H, directory cylinder 14H.
0498
RET C9
DCT$, drive 4
Return at once: logical drive 4 has no driver until one is set up with SYSTEM (DRIVE=4,DRIVER).
0499-049A
DEFW 0F2AH 2A 0F
DCT$+1 and +2, drive 4, 0499H-049AH = 0F2AH (FDCRET), a return in the floppy driver, as a harmless vector for the unassigned drive.
049B-04A1
DEFB 00H, 00H, 00H, 27H, 00H, 00H, 00H 00 00 00 27 00 00 00
DCT$+3 to +9, drive 4, 049BH-04A1H: all zero except the highest cylinder, 27H.
04A2
RET C9
DCT$, drive 5
Return at once: logical drive 5 has no driver until one is set up with SYSTEM (DRIVE=5,DRIVER).
04A3-04A4
DEFW 0F2AH 2A 0F
DCT$+1 and +2, drive 5, 04A3H-04A4H = 0F2AH (FDCRET), a return in the floppy driver.
04A5-04AB
DEFB 00H, 00H, 00H, 27H, 00H, 00H, 00H 00 00 00 27 00 00 00
DCT$+3 to +9, drive 5, 04A5H-04ABH: all zero except the highest cylinder, 27H.
04AC
RET C9
DCT$, drive 6
Return at once: logical drive 6 has no driver until one is set up with SYSTEM (DRIVE=6,DRIVER).
04AD-04AE
DEFW 0F2AH 2A 0F
DCT$+1 and +2, drive 6, 04ADH-04AEH = 0F2AH (FDCRET), a return in the floppy driver.
04AF-04B5
DEFB 00H, 00H, 00H, 27H, 00H, 00H, 00H 00 00 00 27 00 00 00
DCT$+3 to +9, drive 6, 04AFH-04B5H: all zero except the highest cylinder, 27H.
04B6
RET C9
DCT$, drive 7
Return at once: logical drive 7 has no driver until one is set up with SYSTEM (DRIVE=7,DRIVER).
04B7-04B8
DEFW 0F2AH 2A 0F
DCT$+1 and +2, drive 7, 04B7H-04B8H = 0F2AH (FDCRET), a return in the floppy driver.
04B9-04BF
DEFB 00H, 00H, 00H, 27H, 00H, 00H, 00H 00 00 00 27 00 00 00
DCT$+3 to +9, drive 7, 04B9H-04BFH: all zero except the highest cylinder, 27H.

04C0H - SYSINFO: System Information

Bytes the system and the SYSTEM command keep about the boot diskette and the boot prompts, followed by the day and month names used by the date and time displays.

04C0DSKTYP$
DEFB 0FFH FF
DSKTYP$, 04C0H: FFH. Zero for a data diskette, any other value for a system diskette.
04C1
DEFB 00H 00
04C1H: a reserved byte of the system information, 00H in the file.
04C2DTPMT$
DEFB 00H 00
DTPMT$, 04C2H: the date prompt at boot switch (SYSTEM (DATE=)), 00H in the file.
04C3TMPMT$
DEFB 00H 00
TMPMT$, 04C3H: the time prompt at boot switch (SYSTEM (TIME=)), 00H in the file.
04C4RSTOR$
DEFB 00H 00
RSTOR$, 04C4H: the switch that suppresses the drive restores at boot (SYSTEM (RESTORE=)), 00H in the file.
04C5-04C6
DEFB 00H x 2 00 x 2
04C5H-04C6H: two reserved bytes of the system information, zero in the file.
04C7-04DBDAYTBL$
DEFM "SunMonTueWedThuFriSat" 53 75 6E 4D 6F 6E 54 75 65 57 65 64 54 68 75 46 72 69 53 61 74
DAYTBL$, 04C7H-04DBH: the three letter day names, Sunday first, 21 bytes.
04DC-04FFMONTBL$
DEFM "JanFebMarAprMayJunJulAugSepOctNovDec" 4A 61 6E 46 65 62 4D 61 72 41 70 72 4D 61 79 4A 75 6E 4A 75 6C 41 75 67 53 65 70 4F 63 74 4E 6F 76 44 65 63
MONTBL$, 04DCH-04FFH: the three letter month names, January first, 36 bytes, ending at the last byte of sector 2.

0500H - IODVR: @LOGOT and @LOGER, Log a Message

BOOT/SYS sectors 3 to 13 hold the resident I/O routines and drivers, 0500H-0FF3H, which stay in memory for the life of the system. They begin with the character I/O routines of IODVR. @LOGOT (SVC 12) shows the message at Register Pair HL on the screen and then logs it; @LOGER (SVC 11) only logs it. Logging writes the time and the message to the job log device JL unless that device is NIL. A message ends with 03H (ETX, not sent) or 0DH (ENTER, sent).

0500@LOGOT
Call @DSPLY at 052DH to show the message at Register Pair HL on the video display; then fall into @LOGER to log it.
0503@LOGER
LD A,(0230H) 3A 30 02LD A,(JLDCB$)
Load Register A with the type byte of the job log DCB at 0230H (JLDCB$).
0506
XOR 08H EE 08
Flip bit 3 (the NIL bit) of Register A with XOR 08H, so it is 0 when the JL device is NIL.
0508
AND 08H E6 08
Mask Register A with 08H, keeping the flipped NIL bit; Register A is zero when JL is a NIL device.
050A
RET Z C8
Return with nothing logged if Register A is zero (the job log is NIL).
050B
PUSH HL E5
Save Register Pair HL (the pointer to the message) on the stack.
050C
LD HL,051DH 21 1D 05LD HL,LOGBUF
Point Register Pair HL to 051DH (LOGBUF), the buffer that receives the time.
050F
PUSH HL E5
Save Register Pair HL (051DH) on the stack, since @TIME moves it.
0510
Call @TIME at 078DH to write the current time as hh:mm:ss into the buffer at Register Pair HL (051DH-0524H).
0513
POP HL E1
Restore Register Pair HL (051DH, the time text) from the stack.
0514
LD DE,0230H 11 30 02LD DE,JLDCB$
Point Register Pair DE to 0230H (JLDCB$), the job log DCB.
0517
Call @MSG at 0530H to send the time text at Register Pair HL, ended by its 03H, to the job log DCB at Register Pair DE.
051A
POP HL E1
Restore Register Pair HL (the pointer to the message) from the stack.
051B
Jump to @MSG at 0530H to send the message at Register Pair HL to the job log DCB still in Register Pair DE, and return from there.
051D-0527LOGBUF
DEFM "hh:mm:ss " / DEFB 03H 68 68 3A 6D 6D 3A 73 73 20 20 03
LOGBUF, 051DH-0527H: the time field written by @TIME (8 characters), two spaces and the 03H that ends the text.

0528H - @PRINT, @DSPLY and @MSG: Send a Message to a Device

@MSG sends the text at Register Pair HL to the device whose DCB is at Register Pair DE, one character at a time through @PUT, until a 03H (not sent) or a 0DH (sent). @PRINT (SVC 14) sends it to the printer and @DSPLY (SVC 10) to the video display. Each returns with Register Pair HL unchanged and the Z flag set for success, or NZ and the error code in Register A.

0528@PRINT
LD DE,0218H 11 18 02LD DE,PRDCB$
Point Register Pair DE to 0218H (PRDCB$), the printer DCB.
052B
Jump to @MSG at 0530H to send the message at Register Pair HL to the printer.
052D@DSPLY
LD DE,0210H 11 10 02LD DE,DODCB$
Point Register Pair DE to 0210H (DODCB$), the video display DCB, and fall into @MSG.
0530@MSG
PUSH HL E5
Save Register Pair HL (the pointer to the start of the message) on the stack.
0531
LD A,(HL) 7E
Load Register A with the next character of the message at Register Pair HL.
0532
CP 03H FE 03
Compare Register A with 03H (ETX), the end of a message that is not sent.
0534
If Register A is 03H, jump to 0543H and return.
0536
CP 0DH FE 0D
Compare Register A with 0DH (ENTER), the end of a message that is sent.
0538
If Register A is 0DH, jump to 0540H to send it and return.
053A
Call @PUT at 0645H to send the character in Register A to the DCB at Register Pair DE (the NZ condition is always true here after the compare).
053D
INC HL 23
Increment Register Pair HL to the next character of the message.
053E
If @PUT returned Z (no error), loop back to 0531H for the next character; on an error fall through with NZ.
0540
Reached with Z for the closing 0DH: call @PUT at 0645H to send it. Reached with NZ after an error, the call is skipped.
0543
POP HL E1
Restore Register Pair HL (the start of the message) from the stack.
0544
RET C9
Return to the caller with Z (success) or NZ (the error code in Register A).

0545H - @CLS: Clear the Screen

@CLS (SVC 105) sends 1CH (cursor home) and 1FH (clear to the end of the frame) to the video display. DSPBYT at 054DH sends Register A to the display keeping Register Pair DE.

0545@CLS
LD A,1CH 3E 1C
Load Register A with 1CH, the video control code that moves the cursor home to row 0, column 0.
0547
Call DSPBYT at 054DH to send Register A (1CH) to the video display.
054A
RET NZ C0
Return if DSPBYT returned NZ (an error, its code in Register A).
054B
LD A,1FH 3E 1F
Load Register A with 1FH, the video control code that clears from the cursor to the end of the frame; fall into DSPBYT.
054DDSPBYT
PUSH DE D5
Save Register Pair DE on the stack, since @DSP loads it with the video DCB.
054E
Call @DSP at 0642H to send the character in Register A to the video display.
0551
POP DE D1
Restore Register Pair DE (the caller's value, saved at 054DH) from the stack.
0552
RET C9
Return to the caller with the Z or NZ status of @DSP.

0553H - @CKBRKC: Check for BREAK and Clear It

@CKBRKC (SVC 106) tests the BREAK bit, bit 0 of KFLAG$ (0074H), which the keyboard driver sets. With no BREAK it returns Z at once. When BREAK was pressed it waits for the key to be released, clears the type-ahead buffer with @CTL code 3 and returns NZ. All registers are kept.

0553@CKBRKC
PUSH HL E5
Save Register Pair HL on the stack; every register is kept for the caller.
0554
LD HL,0074H 21 74 00LD HL,KFLAG$
Point Register Pair HL to 0074H (KFLAG$), the keyboard flags, whose bit 0 is the BREAK bit.
0557
BIT 0,(HL) CB 46
Test bit 0 of KFLAG$ at Register Pair HL, the BREAK bit.
0559
If the BREAK bit is clear, jump to 0575H (NOBRK) and return with Z.
055B
PUSH AF F5
Save Register Pair AF on the stack: its flags (NZ from the BIT test) become the return status.
055C
PUSH BC C5
Save Register Pair BC on the stack; the delay below loads it.
055D
PUSH DE D5
Save Register Pair DE on the stack; the @CTL call below loads it.
055EBRKTEST
RES 0,(HL) CB 86
Reset bit 0 of KFLAG$ at Register Pair HL (0074H), the BREAK bit.
0560
LD BC,0B00H 01 00 0B
Load Register Pair BC with 0B00H, the delay count for @PAUSE, more than 1/30 of a second.
0563
Call 0382H (@PAUSE, loaded there by SYS0/SYS) to wait for the count in Register Pair BC.
0566
BIT 0,(HL) CB 46
Test bit 0 of KFLAG$ at Register Pair HL again: the keyboard driver sets it again while BREAK is held down.
0568
If the BREAK bit is set again, loop back to 055EH (BRKTEST) until the key is released.
056A
LD DE,0208H 11 08 02LD DE,KIDCB$
Point Register Pair DE to 0208H (KIDCB$), the keyboard DCB.
056D
LD A,03H 3E 03
Load Register A with 03H, the @CTL function code that clears the keyboard type-ahead buffer.
056F
Call @CTL at 0623H to send the control request in Register A to the keyboard DCB at Register Pair DE.
0572
POP DE D1
Restore Register Pair DE (the caller's value, saved at 055DH) from the stack.
0573
POP BC C1
Restore Register Pair BC (the caller's value, saved at 055CH) from the stack.
0574
POP AF F1
Restore Register Pair AF from the stack: Register A as it was and the NZ flag saved at 055BH.
0575NOBRK
POP HL E1
Restore Register Pair HL from the stack.
0576
RET C9
Return to the caller with Z (no BREAK) or NZ (BREAK was pressed).

0577H - @KEYIN Helper: Backspace to the Start of the Line

Reached through the CTL-X (18H) test at 05B6H, which enters at 0580H. It backspaces one character at a time until the buffer is empty or the character before the cursor is a line feed (0AH). Register B counts the buffer space left and Register C holds the buffer size.

0577
Call 05DBH to backspace one character in the buffer and on the screen.
057A
DEC HL 2B
Decrement Register Pair HL to the character before the cursor position in the buffer.
057B
LD A,(HL) 7E
Load Register A with that character at Register Pair HL.
057C
INC HL 23
Increment Register Pair HL back to the cursor position.
057D
CP 0AH FE 0A
Compare Register A (the character before the cursor) with 0AH, a line feed.
057F
RET Z C8
Return if it is a line feed: the start of the current line has been reached.
0580
LD A,B 78
Copy Register B (the buffer space left) into Register A.
0581
CP C B9
Compare Register A with Register C (the buffer size); they are equal when the buffer is empty.
0582
If the buffer is not empty, loop back to 0577H for the next backspace.
0584
RET C9
Return with the buffer empty; the return address is 0587H, pushed at 05AFH, so @KEYIN waits for the next key.

0585H - @KEYIN: Accept a Line of Input

@KEYIN (SVC 9) reads up to Register B characters into the buffer at Register Pair HL, showing them on the screen, and ends the line with 0DH. Keys come from @KEY (the standard input), or from @JCL while a JCL file is running (bit 5 of SFLAG$). It handles BACKSPACE (08H), CTL-X (18H, back to the start of the line), TAB (09H, spaces to the next multiple of 8), CLEAR (1FH, clear the screen and the line), LINE FEED (0AH), CTL-R (12H, show the previous command again) and BREAK (80H). It returns Register Pair HL = the buffer, Register B = the number of characters typed, Carry set for BREAK, and NZ with the error code in Register A for an I/O error.

0585@KEYIN
PUSH HL E5
Save Register Pair HL (the start of the buffer) on the stack.
0586
LD C,B 48
Copy Register B (the buffer size) into Register C, kept to count the characters typed; Register B counts down the space left.
0587
LD DE,0628H 11 28 06LD DE,@KEY
Point Register Pair DE to 0628H (@KEY), the routine that waits for a key from the standard input.
058A
LD A,(007CH) 3A 7C 00LD A,(SFLAG$)
Load Register A with 007CH (SFLAG$), the system flags; bit 5 is set while a JCL file is running.
058D
AND 20H E6 20
Mask Register A with 20H, keeping bit 5, the JCL active bit.
058F
If no JCL file is running, jump to 0593H with Register Pair DE still 0628H. The test is made for every key, in case the JCL ends (//STOP) during the line.
0591
LD E,30H 1E 30
JCL active: load Register E with 30H, making Register Pair DE 0630H (@JCL), which takes the next character from the JCL file.
0593
LD (0598H),DE ED 53 98 05
Self-Modifying Code
Store Register Pair DE (0628H @KEY, or 0630H @JCL) into 0598H-0599H, the operand of the CALL at 0597H.
0597
CALL 0000H CD 00 00
Self-Modifying Code
Call the input routine whose address was stored at 0593H: 0628H (@KEY) or 0630H (@JCL). The file holds CALL 0000H. Register A returns the key.
059A
If the input routine returned NZ (an error), jump to 05D9H, which ends the line.
059C
CP 80H FE 80
Compare Register A (the key) with 80H, the BREAK key.
059E
If it is BREAK, jump to 0615H to end the line with the Carry flag set.
05A0
CP 20H FE 20
Compare Register A with 20H, the first printable character.
05A2
If Register A is 20H or above (a printable character), jump to 05C4H to store and show it.
05A4
CP 0DH FE 0D
Compare Register A (a control key) with 0DH, the ENTER key.
05A6
If it is ENTER, jump to 0616H to end the line.
05A8
CP 1FH FE 1F
Compare Register A (a control key) with 1FH, the CLEAR key.
05AA
If it is CLEAR, jump to 05D1H to clear the screen and start the line again.
05AC
LD DE,0587H 11 87 05
Point Register Pair DE to 0587H, the top of the key loop, as the return address of the editing routines below.
05AF
PUSH DE D5
Push Register Pair DE (0587H) on the stack, so a RET from an editing routine goes back for the next key.
05B0
CP 08H FE 08
Compare Register A with 08H, the BACKSPACE (left arrow) key.
05B2
If it is BACKSPACE, jump to 05DBH to remove one character.
05B4
CP 18H FE 18
Compare Register A with 18H, CTL-X (shift left arrow), backspace to the start of the line.
05B6
If it is CTL-X, jump to 0580H to remove characters back to the start of the line.
05B8
CP 09H FE 09
Compare Register A with 09H, the TAB (right arrow) key.
05BA
If it is TAB, jump to 05F8H to put spaces up to the next tab stop.
05BC
CP 12H FE 12
Compare Register A with 12H, CTL-R, which shows the previous command again.
05BE
If it is CTL-R, jump to 05EAH to show the previous command.
05C0
CP 0AH FE 0A
Compare Register A with 0AH, the LINE FEED (down arrow) key.
05C2
RET NZ C0
Return to 0587H (the address pushed at 05AFH) for any other control key, which is ignored.
05C3
POP DE D1
LINE FEED: pop the return address 0587H into Register Pair DE and discard it; the line feed is stored like a printable character.
05C4
LD (HL),A 77
Store Register A (the character) into the buffer at Register Pair HL.
05C5
LD A,B 78
Copy Register B (the buffer space left) into Register A.
05C6
OR A B7
Test Register A (the buffer space left) for zero with OR A.
05C7
If the buffer is full, loop back to 0587H without advancing: the character stays in the buffer position and is overwritten by the next key.
05C9
LD A,(HL) 7E
Load Register A with the character just stored at Register Pair HL.
05CA
INC HL 23
Increment Register Pair HL to the next buffer position.
05CB
DEC B 05
Decrement Register B, the buffer space left, for the stored character.
05CC
Call @DSP at 0642H to show the character in Register A on the video display.
05CF
Jump to 05D7H, which loops for the next key if @DSP returned Z.
05D1
CLEAR: call @CLS at 0545H to clear the screen.
05D4
LD B,C 41
Copy Register C (the buffer size) into Register B: the whole buffer is free again.
05D5
POP HL E1
Pop the start of the buffer (saved at 0585H) into Register Pair HL.
05D6
PUSH HL E5
Push Register Pair HL (the start of the buffer) back on the stack for the exit at 0621H.
05D7
If the last call returned Z (no error), loop back to 0587H for the next key.
05D9
An error: jump to 0616H to end the line with the NZ status.

05DBH - @KEYIN Helper: Backspace One Character

Removes the last character from the buffer and backspaces the cursor, unless the buffer is empty or the last character is a line feed. Returns to its caller: to the key loop at 0587H (the address pushed at 05AFH) for BACKSPACE, or to 057AH in the CTL-X loop.

05DB
LD A,B 78
Copy Register B (the buffer space left) into Register A.
05DC
CP C B9
Compare Register A with Register C (the buffer size): equal when the buffer is empty.
05DD
RET Z C8
Return if the buffer is empty: there is nothing to remove.
05DE
DEC HL 2B
Decrement Register Pair HL to the last character stored.
05DF
LD A,(HL) 7E
Load Register A with the last character at Register Pair HL.
05E0
CP 0AH FE 0A
Compare Register A with 0AH, a line feed, which cannot be backspaced over.
05E2
INC HL 23
Increment Register Pair HL back to the cursor position (INC leaves the flags of the compare).
05E3
RET Z C8
Return to the key loop if the last character is a line feed.
05E4
DEC HL 2B
Decrement Register Pair HL, removing the last character from the buffer.
05E5
INC B 04
Increment Register B: one more position of the buffer is free.
05E6
LD A,08H 3E 08
Load Register A with 08H, the video code that backspaces the cursor and erases the character.
05E8
Jump to @DSP at 0642H to send Register A (08H) to the display; its RET goes back to 0587H.

05EAH - @KEYIN Helper: CTL-R, Show the Previous Command

Works only when bit 2 of CFLAG$ (006CH) is set, as it is while SYS1/SYS reads a command line, and only as the first key of the line. The buffer still holds the previous command; it is shown again and @KEYIN returns at once to its caller with it.

05EA
LD A,(006CH) 3A 6C 00LD A,(CFLAG$)
Load Register A with 006CH (CFLAG$), the system's C flags.
05ED
AND 04H E6 04
Mask Register A with 04H, keeping bit 2, set while SYS1/SYS reads a command line.
05EF
RET Z C8
Return to the key loop (0587H) and ignore the key if bit 2 is clear.
05F0
LD A,B 78
Copy Register B (the buffer space left) into Register A.
05F1
CP C B9
Compare Register A with Register C (the buffer size): equal only when nothing has been typed yet.
05F2
RET NZ C0
Return to the key loop and ignore the key if any characters have been typed.
05F3
POP HL E1
Pop the return address 0587H (pushed at 05AFH) into Register Pair HL and discard it.
05F4
POP HL E1
Pop the start of the buffer (saved at 0585H) into Register Pair HL.
05F5
Jump to @DSPLY at 052DH to show the previous command held in the buffer at Register Pair HL; its RET returns to the caller of @KEYIN.

05F8H - @KEYIN Helper: TAB

Puts spaces into the buffer and on the screen up to the next column that is a multiple of 8, as long as the buffer has room.

05F8
PUSH HL E5
Save Register Pair HL (the buffer pointer) on the stack.
05F9
Call ADDR_2_ROWCOL at 0DF1H to load Register Pair HL with the cursor position: Register H the row and Register L the column.
05FC
LD A,L 7D
Copy Register L (the cursor column) into Register A.
05FD
POP HL E1
Restore Register Pair HL (the buffer pointer) from the stack.
05FE
AND 07H E6 07
Mask Register A with 07H, the cursor column modulo 8.
0600
NEG ED 44
Negate Register A (0 minus the column modulo 8).
0602
ADD A,08H C6 08
Add 08H to Register A: 8 minus the column modulo 8, the spaces to the next tab stop (1 to 8).
0604
LD E,A 5F
Copy Register A (the number of spaces) into Register E.
0605
LD A,B 78
Copy Register B (the buffer space left) into Register A.
0606
OR A B7
Test Register A (the buffer space left) for zero with OR A.
0607
RET Z C8
Return to the key loop if the buffer is full.
0608
LD A,20H 3E 20
Load Register A with 20H, a space, to fill toward the tab stop.
060A
LD (HL),A 77
Store Register A (the space) into the buffer at Register Pair HL.
060B
INC HL 23
Increment Register Pair HL to the next buffer position.
060C
Call DSPBYT at 054DH to show the space in Register A on the screen.
060F
RET NZ C0
Return to the key loop if DSPBYT returned NZ (an error).
0610
DEC B 05
Decrement Register B, the buffer space left, for the space stored.
0611
DEC E 1D
Decrement Register E, the spaces still to put.
0612
RET Z C8
Return to the key loop when Register E reaches zero: the tab is complete.
0613
Jump back to 0605H to store and show the next space of the tab.

0615H - @KEYIN Exit: End the Line

Puts 0DH at the end of the line, shows it, sets Register B to the number of characters typed and returns Register Pair HL = the buffer. BREAK enters at 0615H and returns with the Carry flag set.

0615
SCF 37
BREAK: set the Carry flag, the BREAK indication of the return.
0616
PUSH AF F5
Save Register Pair AF (the flags of the return: Z for ENTER, Carry for BREAK, NZ for an error) on the stack.
0617
LD A,0DH 3E 0D
Load Register A with 0DH, the end of line character.
0619
LD (HL),A 77
Store Register A (0DH) into the buffer at Register Pair HL, ending the line.
061A
Call @DSP at 0642H to send the 0DH in Register A to the video display, moving to a new line.
061D
LD A,C 79
Copy Register C (the buffer size) into Register A.
061E
SUB B 90
Subtract Register B (the space left) from Register A, giving the number of characters typed.
061F
LD B,A 47
Copy Register A (the characters typed) into Register B.
0620
POP AF F1
Restore Register Pair AF: Register A and the flags saved at 0616H.
0621
POP HL E1
Restore Register Pair HL, the start of the buffer saved at 0585H.
0622
RET C9
Return to the caller of @KEYIN with Register Pair HL = the buffer and Register B = the characters typed.

0623H - @CTL, @KEY, @JCL, @KBD, @GET, @PRT, @DSP and @PUT

The character I/O SVCs. @GET (SVC 3) reads a character from the device whose DCB is at Register Pair DE, @PUT (SVC 4) sends Register C to it and @CTL (SVC 5) sends it the control request in Register C. @KBD (SVC 8) is @GET from the keyboard, @KEY (SVC 1) waits for a key, @JCL takes a character from the JCL file, @PRT (SVC 6) and @DSP (SVC 2) are @PUT to the printer and the display. Each loads Register B with its request bit (1 GET, 2 PUT, 4 CTL) and goes to IOBGN.

0623@CTL
PUSH BC C5
Save Register Pair BC on the stack (restored by @RSTREG).
0624
LD B,04H 06 04
Load Register B with 04H, the CTL request (bit 2 of the DCB type byte).
0626
Jump to IOBGN at 0648H with the CTL request in Register B.
0628@KEY
Call @KBD at 0635H to scan the keyboard; it returns Z with the key in Register A when one is ready.
062B
RET Z C8
Return with the key in Register A if @KBD returned Z.
062C
OR A B7
Test Register A for zero: NZ with Register A = 0 means no key is ready yet, any other value is an error code.
062D
If Register A is zero (no key yet), loop back to 0628H and wait.
062F
RET C9
Return with NZ and the error code in Register A.
0630@JCL
LD DE,0203H 11 03 02LD DE,JCLCB$
Point Register Pair DE to 0203H (JCLCB$), the mini DCB through which the JCL file supplies characters.
0633
Jump to @GET at 0638H to read a character from it.
0635@KBD
LD DE,0208H 11 08 02LD DE,KIDCB$
Point Register Pair DE to 0208H (KIDCB$), the keyboard DCB, and fall into @GET.
0638@GET
PUSH BC C5
Save Register Pair BC on the stack (restored by @RSTREG).
0639
LD B,01H 06 01
Load Register B with 01H, the GET request (bit 0 of the DCB type byte).
063B
Jump to IOBGN at 0648H with the GET request in Register B.
063D@PRT
LD DE,0218H 11 18 02LD DE,PRDCB$
Point Register Pair DE to 0218H (PRDCB$), the printer DCB.
0640
Jump to @PUT at 0645H to send Register A to the printer.
0642@DSP
LD DE,0210H 11 10 02LD DE,DODCB$
Point Register Pair DE to 0210H (DODCB$), the video display DCB, and fall into @PUT.
0645@PUT
PUSH BC C5
Save Register Pair BC on the stack (restored by @RSTREG).
0646
LD B,02H 06 02
Load Register B with 02H, the PUT request (bit 1 of the DCB type byte), and fall into IOBGN.

0648H - IOBGN: Pass an I/O Request to a Device

Saves the registers, makes sure memory bank 0 is switched in, and passes the request to the driver named in the DCB at Register Pair DE (a type byte below 08H), or to @CHNIO for a NIL, routed, linked, filtered or file device. The driver is entered with Index Register IX = the DCB, Register C = the character, Register B = the request and the flags set by CP 02H on it: Carry for GET, Z for PUT, neither for CTL. The return goes through @RSTREG at 0680H, or RSTBNK at 0679H when a bank had to be switched.

0648IOBGN
PUSH IX DD E5
Save Index Register IX on the stack (restored by @RSTREG at 0682H).
064A
PUSH HL E5
Save Register Pair HL on the stack (restored by @RSTREG at 0681H).
064B
PUSH DE D5
Push Register Pair DE (the DCB address) on the stack to copy it.
064C
POP IX DD E1
Pop it into Index Register IX: Index Register IX = the DCB.
064E
PUSH DE D5
Save Register Pair DE (the DCB) on the stack again, to be restored by @RSTREG.
064F
LD C,A 4F
Copy Register A (the character for @PUT, or the code for @CTL) into Register C.
0650
LD HL,0680H 21 80 06LD HL,@RSTREG
Point Register Pair HL to 0680H (@RSTREG), the routine that restores the registers, as the return address of the driver.
0653
LD A,(0202H) 3A 02 02LD A,(LBANK$)
Load Register A with 0202H (LBANK$), the memory bank now switched in.
0656
OR A B7
Test Register A (the bank switched in) for zero with OR A.
0657
If bank 0 is in place, jump to 0667H with Register Pair HL = 0680H.
0659
PUSH BC C5
Another bank is in place: save Register Pair BC (the request and character) on the stack.
065A
XOR A AF
Clear Register A to 00H for the @BANK call that selects bank 0.
065B
LD B,A 47
Copy Register A (00H) into Register B, the @BANK function code 0.
065C
LD C,A 4F
Copy Register A (00H) into Register C, bank 0.
065D
Call @BANK at 0877H to switch in bank 0; it returns the previous bank data in Register Pair BC.
0660
LD H,B 60
Copy Register B (the previous bank data) into Register H.
0661
LD L,C 69
Copy Register C (the previous bank) into Register L.
0662
POP BC C1
Restore Register Pair BC (the request and character) from the stack.
0663
PUSH HL E5
Push Register Pair HL (the previous bank data) on the stack for RSTBNK.
0664
LD HL,0679H 21 79 06LD HL,RSTBNK
Point Register Pair HL to 0679H (RSTBNK), so the driver's return switches the previous bank back.
0667
PUSH HL E5
Push Register Pair HL (0680H @RSTREG or 0679H RSTBNK) as the return address of the driver.
0668
LD A,(DE) 1A
Load Register A with the type byte of the DCB at Register Pair DE.
0669
OR A B7
Test Register A (the DCB type byte) for zero with OR A.
066A
RET Z C8
Return through @RSTREG or RSTBNK with Z if the type byte is zero: the device is not in use.
066B
CP 08H FE 08
Compare Register A (the DCB type byte) with 08H, the NIL bit.
066D
If any of bits 3 to 7 is set (NIL, routed, linked, filtered or a file), jump to @CHNIO at 0689H.
066F
LD L,(IX+01H) DD 6E 01
Load Register L with DCB+1 at Index Register IX+01H, the low byte of the driver address.
0672
LD H,(IX+02H) DD 66 02
Load Register H with DCB+2 at Index Register IX+02H, the high byte of the driver address.
0675
LD A,B 78
Copy Register B (the request: 1 GET, 2 PUT, 4 CTL) into Register A.
0676
CP 02H FE 02
Compare Register A with 02H, setting the flags the driver tests: Carry for GET (1), Z for PUT (2), neither for CTL (4).
0678
JP (HL) E9
Jump to the driver at Register Pair HL; its RET returns to the address pushed at 0667H.
0679RSTBNK
POP BC C1
Pop the previous bank data (pushed at 0663H) into Register Pair BC.
067A
PUSH AF F5
Save Register Pair AF (the result of the driver) on the stack.
067B
LD A,C 79
Copy Register C (the previous bank) into Register A for @BANK.
067C
Call @BANK at 0877H to switch the previous memory bank back in.
067F
POP AF F1
Restore Register Pair AF, the result of the driver.
0680@RSTREG
POP DE D1
Restore Register Pair DE (the DCB) from the stack.
0681
POP HL E1
Restore Register Pair HL (saved at 064AH) from the stack.
0682
POP IX DD E1
Restore Index Register IX (saved at 0648H) from the stack.
0684
POP BC C1
Restore Register Pair BC (saved by the SVC entry) from the stack.
0685
RET C9
Return to the caller of the I/O SVC with the result in Register A and the flags.

0686H - @CHNIO: Follow a DCB Chain

@CHNIO (SVC 20) passes a request through the special device types. Bit 7 (an open file) goes to @BYTEIO at 1300H in SYS0/SYS. Bit 3 (NIL) returns Z. Bit 4 (routed) follows the vector to another DCB. A filtered device (bit 6 without bits 3, 4 or 5) goes to the filter at its vector. A linked device (bit 5) points to a link DCB whose +1 and +2 lead to the first device and +4 and +5 to the second: output goes to both, input comes from the first that has a character.

0686
PUSH HL E5
Push Register Pair HL (the address of the next DCB in the chain) on the stack.
0687
POP IX DD E1
Pop it into Index Register IX: Index Register IX = the next DCB.
0689@CHNIO
LD L,(IX+01H) DD 6E 01
Load Register L with DCB+1 at Index Register IX+01H, the low byte of the DCB's vector.
068C
LD H,(IX+02H) DD 66 02
Load Register H with DCB+2 at Index Register IX+02H, the high byte of the vector.
068F
LD A,(IX+00H) DD 7E 00
Load Register A with the type byte at Index Register IX+00H.
0692
OR A B7
Test Register A (the type byte): the Sign flag is bit 7, set for an open file.
0693
If bit 7 is set (the DCB is a file control block), jump to @BYTEIO at 1300H in SYS0/SYS to read or write a byte of the file.
0696
BIT 3,A CB 5F
Test bit 3 of Register A (the DCB type byte), the NIL bit.
0698
If the device is NIL, jump to 06BEH, which returns Z.
069A
BIT 4,A CB 67
Test bit 4 of Register A (the DCB type byte), the routed bit.
069C
If routed, jump to 0686H to follow the vector in Register Pair HL to the DCB it is routed to.
069E
BIT 5,A CB 6F
Test bit 5 of Register A (the DCB type byte), the linked bit.
06A0
Not linked, so the device is filtered: jump to 0675H to enter the filter at Register Pair HL with the request flags.
06A2
PUSH HL E5
Linked: push Register Pair HL (the address of the link DCB) on the stack.
06A3
POP IX DD E1
Pop it into Index Register IX: Index Register IX = the link DCB.
06A5
LD (IX+03H),B DD 70 03
Store Register B (the request) into the link DCB at Index Register IX+03H, to be recovered after the first device.
06A8
PUSH IX DD E5
Save Index Register IX (the link DCB) on the stack.
06AA
Call @CHNIO at 0689H to pass the request to the first device, through the vector at the link DCB's +1 and +2.
06AD
POP IX DD E1
Restore Index Register IX (the link DCB) from the stack.
06AF
LD B,(IX+03H) DD 46 03
Load Register B with the request saved at Index Register IX+03H.
06B2
If the first device returned NZ, jump to 06C0H.
06B4
BIT 0,B CB 40
Test bit 0 of Register B: set (NZ) for a GET request, clear (Z) for PUT or CTL.
06B6
LD L,(IX+04H) DD 6E 04
Load Register L with the link DCB's +4 at Index Register IX+04H, the low byte of the second device's DCB.
06B9
LD H,(IX+05H) DD 66 05
Load Register H with the link DCB's +5 at Index Register IX+05H, the high byte of the second device's DCB.
06BC
If Z (an output request, or an input that found no character), jump to 0686H to pass the request to the second device at Register Pair HL.
06BE
CP A BF
Compare Register A with itself, setting Z (success) with Register A unchanged.
06BF
RET C9
Return with Z: a NIL device, or an input character from the first linked device in Register A.
06C0
BIT 0,B CB 40
The first device returned NZ: test bit 0 of Register B, the GET request bit.
06C2
For output (bit 0 clear), jump to 06C7H and return the error.
06C4
OR A B7
Input: test Register A; zero means only that no character was ready.
06C5
If Register A is zero, jump to 06B6H to try the second linked device.
06C7
OR A B7
Test Register A (the error code), giving NZ for a non zero code.
06C8
RET C9
Return with NZ and the error code in Register A.

06C9H - MULDIV: @MUL16 and @DIV16

@MUL16 (SVC 91) multiplies the 16 bit value in Register Pair HL by the 8 bit value in Register A and returns the 24 bit product in Registers H (high), L (middle) and A (low). @DIV16 (SVC 94) divides Register Pair HL by Register A and returns the quotient in Register Pair HL and the remainder in Register A. Called through an SVC, the dispatcher has copied the caller's Register C into Register A.

06C9@MUL16
PUSH BC C5
Save Register Pair BC on the stack; it is used as the multiplier and bit count.
06CA
EX DE,HL EB
Exchange Register Pairs DE and HL: Register Pair DE = the multiplicand (the caller's Register Pair HL).
06CB
LD C,A 4F
Copy Register A (the multiplier) into Register C.
06CC
LD HL,0000H 21 00 00
Load Register Pair HL with 0000H, the low 16 bits of the product.
06CF
LD A,L 7D
Copy Register L (00H) into Register A, the high 8 bits of the product, which Registers A, H and L hold as 24 bits.
06D0
LD B,08H 06 08
Load Register B with 08H, one pass for each bit of the multiplier.
06D2
ADD HL,HL 29
Add Register Pair HL to itself, shifting the low 16 bits of the product left one bit.
06D3
RLA 17
Rotate Register A left through the Carry flag, taking in the bit shifted out of Register Pair HL (bits 16-23 of the product).
06D4
RLC C CB 01
Rotate Register C (the multiplier) left, moving its top bit into the Carry flag.
06D6
If that multiplier bit is 0, jump to 06DBH and do not add.
06D8
ADD HL,DE 19
Add Register Pair DE (the multiplicand) to Register Pair HL, the low 16 bits of the product.
06D9
ADC A,00H CE 00
Add the carry out of Register Pair HL into Register A, the high byte of the product.
06DB
Decrement Register B and loop back to 06D2H until all 8 multiplier bits are done.
06DD
LD C,A 4F
Copy Register A (the high byte of the product) into Register C for the moves below.
06DE
LD A,L 7D
Copy Register L (the low byte of the product) into Register A.
06DF
LD L,H 6C
Copy Register H (the middle byte of the product) into Register L.
06E0
LD H,C 61
Copy Register C (the high byte of the product) into Register H: the product is now H, L and A.
06E1
POP BC C1
Restore Register Pair BC from the stack (Register Pair DE keeps the multiplicand).
06E2
RET C9
Return with the 24 bit product in Registers H, L and A.
06E3@DIV16
PUSH DE D5
Save Register Pair DE on the stack; Register D holds the divisor and Register E the count.
06E4
LD D,A 57
Copy Register A (the divisor) into Register D.
06E5
LD E,10H 1E 10
Load Register E with 10H, one pass for each of the 16 bits of the dividend.
06E7
XOR A AF
Clear Register A, which collects the partial remainder.
06E8
ADD HL,HL 29
Add Register Pair HL to itself, shifting the dividend left; the quotient bits enter at bit 0 of Register L.
06E9
RLA 17
Rotate Register A left through the Carry flag, taking in the top bit of the dividend (the partial remainder).
06EA
If a bit was carried out of Register A, the partial remainder is above 255 and greater than the divisor: jump to 06EFH to subtract.
06EC
CP D BA
Compare Register A (the partial remainder) with Register D (the divisor).
06ED
If Register A is smaller than the divisor, jump to 06F1H without subtracting.
06EF
SUB D 92
Subtract Register D (the divisor) from Register A (the partial remainder).
06F0
INC L 2C
Increment Register L, setting this quotient bit to 1.
06F1
DEC E 1D
Decrement Register E, the count of dividend bits still to shift.
06F2
Loop back to 06E8H until all 16 bits are done.
06F4
POP DE D1
Restore Register Pair DE (saved at 06E3H) from the stack.
06F5
RET C9
Return with the quotient in Register Pair HL and the remainder in Register A.

06F6H - @HEXDEC and @HEXD: Binary to Decimal Text

Write the 16 bit value in Register Pair HL as decimal digits, right justified with leading spaces, into the field at Register Pair DE. @HEXDEC (SVC 97) uses a field of 5 characters; @HEXD (SVC 95) takes the field width in Register B. Returns Register Pair DE = the byte after the field and the Z flag set.

06F6@HEXDEC
LD B,05H 06 05
Load Register B with 05H, the field width of 5 digits, and fall into @HEXD.
06F8@HEXD
LD A,20H 3E 20
Load Register A with 20H, a space, to clear the field.
06FAHEXDEC1
LD (DE),A 12
Store Register A (a space) into the field at Register Pair DE.
06FB
INC DE 13
Increment Register Pair DE to the next position of the field.
06FC
Decrement Register B and loop back to 06FAH until the whole field holds spaces.
06FE
PUSH DE D5
Save Register Pair DE (the byte after the field) on the stack, for the return.
06FF
DEC DE 1B
Decrement Register Pair DE to the last position of the field, where the units digit goes.
0700HEXDEC2
LD A,0AH 3E 0A
Load Register A with 0AH (10), the base of the conversion, the divisor for @DIV16.
0702
Call @DIV16 at 06E3H to divide Register Pair HL by 10: Register Pair HL = the quotient and Register A = the next digit.
0705
ADD A,30H C6 30
Add 30H to Register A, turning the digit into its ASCII character.
0707
LD (DE),A 12
Store Register A (the digit) into the field at Register Pair DE.
0708
DEC DE 1B
Decrement Register Pair DE to the position of the next digit to the left.
0709
LD A,H 7C
Copy Register H (the high byte of the quotient) into Register A.
070A
OR L B5
OR Register L (the low byte of the quotient) into Register A, testing the quotient for zero.
070B
If the quotient is not zero, loop back to 0700H for the next digit.
070D
POP DE D1
Restore Register Pair DE, the byte after the field.
070E
RET C9
Return with Z set (from the OR, the quotient being zero).

070FH - CLOCKS: The Clock Task

The time keeping of the system, run on the real time clock interrupt. TIMETBL holds the limits of the seconds, minutes and hours and a counter of interrupts in the second.

070F-0711TIMETBL
DEFB 3CH, 3CH, 18H 3C 3C 18
TIMETBL, 070FH-0711H: the limits 60 (seconds), 60 (minutes) and 24 (hours), compared with TIME$ (002DH-002FH) by TIMER1.
0712
DEFB 1EH 1E
TIMETBL+3, 0712H: the interrupt counter of the second, counted down from 30 (1EH) by TIMTSK$ at 0749H; the clock interrupt comes 30 times a second.

0713H - TIMTSK$: Blink the Cursor and Keep the Time

The task run on each clock interrupt. Every eighth interrupt it blinks the cursor, unless the cursor is off, is solid or the blink was inhibited for this pass (VFLAG$ 007FH: bit 7 inhibit, bit 6 solid cursor, bit 5 the blink phase, bit 4 clock display, bits 3-0 the interrupt count). Every 30th interrupt it advances TIME$ (002DH seconds, 002EH minutes, 002FH hours) and, past midnight, DATE$ (0033H year, 0034H day, 0035H month), then shows the time on the screen if the clock display is on.

0713TIMTSK$
LD A,(0B97H) 3A 97 0BLD A,(CRSAVE)
Load Register A with 0B97H (CRSAVE), the character under the cursor, kept by the video driver; it is zero while the cursor is off.
0716
OR A B7
Test Register A (the saved character) for zero.
0717
LD HL,007FH 21 7F 00LD HL,VFLAG$
Point Register Pair HL to 007FH (VFLAG$), the video flags.
071A
If the cursor is off (Register A zero), jump to 0745H to keep the time only.
071C
BIT 7,(HL) CB 7E
Test bit 7 of VFLAG$ at Register Pair HL, the blink inhibit bit, set when the video driver has just written the screen.
071E
RES 7,(HL) CB BE
Reset bit 7 of VFLAG$ at Register Pair HL, so the next pass may blink.
0720
If the inhibit bit was set, jump to 0745H without blinking this time.
0722
INC (HL) 34
Increment VFLAG$ at Register Pair HL, counting the interrupt in bits 3-0.
0723
BIT 3,(HL) CB 5E
Test bit 3 of VFLAG$ at Register Pair HL: it becomes 1 on every eighth interrupt.
0725
If bit 3 is still 0, jump to 0745H: no blink on this interrupt.
0727
RES 3,(HL) CB 9E
Reset bit 3 of VFLAG$ at Register Pair HL, starting the count of 8 again.
0729
BIT 6,(HL) CB 76
Test bit 6 of VFLAG$ at Register Pair HL, the solid cursor bit.
072B
If the cursor blinks (bit 6 clear), jump to 072FH.
072D
SET 5,(HL) CB EE
Solid cursor: set bit 5 of VFLAG$ at Register Pair HL, so the flip below always leaves the cursor character showing.
072FNOSOLID
Call ENADIS_DO_RAM at 0817H to bring the video memory into the memory map; it is switched out again when TIMTSK$ returns.
0732
LD A,(HL) 7E
Load Register A with VFLAG$ at Register Pair HL.
0733
XOR 20H EE 20
Flip bit 5 of Register A (the copy of VFLAG$), the blink phase.
0735
LD (HL),A 77
Store Register A (the new VFLAG$) back at Register Pair HL (007FH).
0736
AND 20H E6 20
Mask Register A with 20H, keeping the new blink phase.
0738
LD DE,(0B95H) ED 5B 95 0BLD DE,(CURSOR)
Load Register Pair DE with 0B95H (CURSOR), the video memory address of the cursor.
073C
LD A,(0B97H) 3A 97 0BLD A,(CRSAVE)
Load Register A with 0B97H (CRSAVE), the character under the cursor (LD does not change the flags of the AND).
073F
If the blink phase is 1, jump to 0744H to put back the character under the cursor.
0741
LD A,(0B98H) 3A 98 0BLD A,(CRSCHAR)
Blink phase 0: load Register A with 0B98H (CRSCHAR), the cursor character.
0744
LD (DE),A 12
Store Register A (the cursor character or the character under it) into video memory at Register Pair DE.
0745
LD IX,070FH DD 21 0F 07LD IX,TIMETBL
Point Index Register IX to 070FH (TIMETBL), the limits and the counter of the second.
0749
DEC (IX+03H) DD 35 03
Decrement the interrupt counter of the second at Index Register IX+03H (0712H).
074C
RET NZ C0
Return if the counter has not reached zero: less than a second has passed.
074D
LD (IX+03H),1EH DD 36 03 1E
Reload the counter at Index Register IX+03H (0712H) with 1EH (30) for the next second.
0751
BIT 4,(HL) CB 66
Test bit 4 of VFLAG$ at Register Pair HL (007FH), the clock display bit (SYSTEM (CLOCK)).
0753
If the clock display is off (bit 4 clear), jump to 0759H.
0755
LD DE,0787H 11 87 07LD DE,CLOCK
Point Register Pair DE to 0787H (CLOCK), the routine that shows the time on the screen.
0758
PUSH DE D5
Push Register Pair DE (0787H) on the stack, so the RETs below go to CLOCK.
0759
LD B,03H 06 03
Load Register B with 03H, the three time fields: seconds, minutes and hours.
075B
LD HL,002DH 21 2D 00LD HL,TIME$
Point Register Pair HL to 002DH (TIME$), the seconds.
075E
LD DE,070FH 11 0F 07LD DE,TIMETBL
Point Register Pair DE to 070FH (TIMETBL), the limit of the seconds.
0761TIMER1
INC (HL) 34
Increment the time field at Register Pair HL.
0762
LD A,(DE) 1A
Load Register A with the limit of the field at Register Pair DE.
0763
SUB (HL) 96
Subtract the time field at Register Pair HL from Register A (the limit).
0764
RET NZ C0
Return if the field has not reached its limit (Register A not zero).
0765
LD (HL),A 77
The field reached its limit: store Register A (zero) into the field at Register Pair HL.
0766
INC L 2C
Increment Register L to the next time field (002EH minutes, then 002FH hours).
0767
INC E 1C
Increment Register E to the next limit in TIMETBL.
0768
Decrement Register B and loop back to 0761H to carry into the next field.
076A
LD L,35H 2E 35
The hours passed 24: load Register L with 35H, making Register Pair HL 0035H, the month of DATE$. Bug B2: only the day, month and year are stepped; DATE$+3 and DATE$+4 (the day of the year, the day of the week, the leap flag) keep the values the start-up of SYS0/SYS gave them.
076C
LD A,(HL) 7E
Load Register A with the month at Register Pair HL (0035H).
076D
OR A B7
Test Register A (the month of DATE$) for zero with OR A.
076E
RET Z C8
Return if the month is zero: no date has been set.
076F
DEC L 2D
Decrement Register L to 0034H, the day of the month.
0770
LD DE,0401H 11 01 04LD DE,MAXDAY$
Point Register Pair DE to 0401H (MAXDAY$), the base of the month length table.
0773
INC (HL) 34
Increment the day of the month at Register Pair HL (0034H).
0774
ADD A,E 83
Add Register E (01H) to Register A (the month), giving the low byte of the table entry, 0401H plus the month.
0775
LD E,A 5F
Copy Register A into Register E: Register Pair DE points to the number of days in the month.
0776
LD A,(DE) 1A
Load Register A with the number of days in the month at Register Pair DE.
0777
CP (HL) BE
Compare Register A (the days in the month) with the new day at Register Pair HL.
0778
RET NC D0
Return if the day is still within the month (Register A not below it).
0779
LD (HL),01H 36 01
Past the end of the month: store 01H into the day at Register Pair HL (0034H).
077B
INC L 2C
Increment Register L, making Register Pair HL 0035H, the month.
077C
INC (HL) 34
Increment the month at Register Pair HL (0035H) for the new month.
077D
LD A,(HL) 7E
Load Register A with the new month at Register Pair HL.
077E
SUB 0DH D6 0D
Subtract 0DH (13) from Register A: a borrow means the month is 12 or less.
0780
RET C D8
Return if the month is 12 or less (the subtraction borrowed).
0781
LD (HL),01H 36 01
Past December: store 01H (January) into the month at Register Pair HL.
0783
DEC L 2D
Decrement Register L, making Register Pair HL 0034H, on the way to the year.
0784
DEC L 2D
Decrement Register L again to 0033H, the year.
0785
INC (HL) 34
Increment the year at Register Pair HL (0033H). Bug B3: February's length at 0403H is not set for the new year.
0786
RET C9
Return (to CLOCK at 0787H when the clock display is on).

0787H - CLOCK, @TIME and DATELO$: Time and Date Text

CLOCK shows the time at the top right of the screen (row 0, column 69). @TIME (SVC 19) writes the time as hh:mm:ss (8 characters) from TIME$ into the buffer at Register Pair HL. DATELO$ writes the date as mm/dd/yy from DATE$ the same way. Each field byte is turned into two decimal digits.

0787CLOCK
Call ENADIS_DO_RAM at 0817H to bring the video memory into the memory map.
078A
LD HL,F845H 21 45 F8
Point Register Pair HL to F845H, row 0, column 69 of the screen, and fall into @TIME.
078D@TIME
LD DE,002FH 11 2F 00
Point Register Pair DE to 002FH (TIME$+2), the hours, the first field to write.
0790
LD C,3AH 0E 3A
Load Register C with 3AH, the colon that separates the fields.
0792TIME1
LD B,03H 06 03
Load Register B with 03H, the three fields to write (time or date).
0794TIME2
LD A,(DE) 1A
Load Register A with the field at Register Pair DE (hours, minutes or seconds).
0795
LD (HL),2FH 36 2F
Store 2FH (one less than the digit 0) at Register Pair HL, the tens digit, which is counted up below.
0797TIME3
INC (HL) 34
Increment the tens digit at Register Pair HL.
0798
SUB 0AH D6 0A
Subtract 0AH (10) from Register A, the field value being turned into digits.
079A
If no borrow, loop back to 0797H: the tens digit counts how many 10s Register A held.
079C
ADD A,3AH C6 3A
Add 3AH to Register A, which undoes the last subtraction and makes the units digit into ASCII (A + 10 + 30H).
079E
INC HL 23
Increment Register Pair HL to the units position.
079F
LD (HL),A 77
Store Register A (the units digit) at Register Pair HL.
07A0
INC HL 23
Increment Register Pair HL past the two digits of the field.
07A1
DEC B 05
Decrement Register B, the number of fields still to write.
07A2
RET Z C8
Return when all three fields are written, with Register Pair HL past them.
07A3
LD (HL),C 71
Store Register C (the separator) at Register Pair HL.
07A4
INC HL 23
Increment Register Pair HL past the separator.
07A5
DEC DE 1B
Decrement Register Pair DE to the next field (minutes, then seconds; for DATELO$ day, then year).
07A6
Jump back to 0794H to write the next field at Register Pair HL.
07A8DATELO$
LD DE,0035H 11 35 00
Point Register Pair DE to 0035H (DATE$+2), the month, the first field of the date.
07AB
LD C,2FH 0E 2F
Load Register C with 2FH, the slash that separates the date fields.
07AD
Jump to 0792H to write the three fields at Register Pair HL.
07AF-07B0PCSAVE$
DEFW 0000H 00 00
PCSAVE$, 07AFH-07B0H: the program counter at entry to the interrupt (RST 38H), stored by the interrupt handler and shown by TRACE_INT. 0000H in the file.

07B1H - TRACE_INT, @HEX16 and @HEX8

TRACE_INT is a task: its first word is the address of its code (07B3H). It shows the program counter of the last interrupt, PCSAVE$, as four hex digits at row 0, column 62 of the screen, for SYSTEM (TRACE). @HEX16 (SVC 99) writes Register Pair DE as four hex digits at Register Pair HL; @HEX8 (SVC 98) writes Register A as two.

07B1-07B2TRACE_INT
DEFW 07B3H B3 07
TRACE_INT, 07B1H-07B2H = 07B3H, the address of the task's code, the word after it.
07B3
LD HL,(07AFH) 2A AF 07LD HL,(PCSAVE$)
Load Register Pair HL with 07AFH (PCSAVE$), the program counter of the last interrupt.
07B6
EX DE,HL EB
Exchange Register Pairs DE and HL: Register Pair DE = the program counter to show.
07B7
Call ENADIS_DO_RAM at 0817H to bring the video memory into the memory map.
07BA
LD HL,F83EH 21 3E F8
Point Register Pair HL to F83EH, row 0, column 62 of the screen, and fall into @HEX16.
07BD@HEX16
LD A,D 7A
Copy Register D (the high byte of the value) into Register A.
07BE
Call @HEX8 at 07C2H to write Register A as two hex digits at Register Pair HL.
07C1
LD A,E 7B
Copy Register E (the low byte of the value) into Register A, and fall into @HEX8.
07C2@HEX8
PUSH AF F5
Save Register Pair AF (the byte in Register A) on the stack.
07C3
RRA 1F
Rotate Register A right; four rotations move the high nibble to bits 3-0.
07C4
RRA 1F
Rotate Register A right (second of the four rotations of the high nibble).
07C5
RRA 1F
Rotate Register A right (third of the four rotations of the high nibble).
07C6
RRA 1F
Rotate Register A right (fourth); the high nibble is now in bits 3-0.
07C7
Call HXD1 at 07CBH to write the high nibble as a hex digit at Register Pair HL.
07CA
POP AF F1
Restore Register Pair AF, the byte, for its low nibble.
07CBHXD1
AND 0FH E6 0F
Mask Register A with 0FH, keeping one nibble.
07CD
ADD A,90H C6 90
Add 90H to Register A; with the two DAA steps this turns 0-9 into 30H-39H and 0AH-0FH into 41H-46H.
07CF
DAA 27
Decimal adjust Register A after the ADD of 90H (first of the two DAA steps).
07D0
ADC A,40H CE 40
Add 40H and the Carry flag to Register A (second step of the hex conversion).
07D2
DAA 27
Decimal adjust Register A, giving the ASCII hex digit.
07D3
LD (HL),A 77
Store Register A (the hex digit) at Register Pair HL.
07D4
INC HL 23
Increment Register Pair HL to the next position.
07D5
RET C9
Return with Register Pair HL past the digit just written.

07D6H - KCK@: Check the Special Keys

Reads the keyboard rows directly and sets bits of KFLAG$ (0074H): bit 0 BREAK, bit 1 pause (SHIFT @), bit 2 ENTER. CTRL held down stops the check. BREAK is ignored when shifted or when SFLAG$ bit 4 disables it. Without SHIFT, ENTER is only noted (and BREAK only read from the keyboard) when no other routine has the video and keyboard memory switched in; with SHIFT down the row at F440H is always checked. Returns the Carry flag set when SHIFT is down and NZ when BREAK is down.

07D6KCK@
Call ENADIS_DO_RAM at 0817H to bring the keyboard memory (F400H-F7FFH) into the memory map.
07D9
LD HL,0074H 21 74 00LD HL,KFLAG$
Point Register Pair HL to 0074H (KFLAG$), the keyboard flags.
07DC
LD A,(F480H) 3A 80 F4LD A,(SHIFT)
Load Register A with F480H, the keyboard row of the SHIFT keys (bit 0 left SHIFT, bit 1 right SHIFT, bit 2 CTRL).
07DF
AND 07H E6 07
Mask Register A with 07H, keeping the two SHIFT keys and CTRL.
07E1
CPL 2F
Complement Register A: the three key bits become 1 for a key that is up, and bits 3-7 become 1.
07E2
BIT 2,A CB 57
Test bit 2 of Register A, CTRL (0 when CTRL is down).
07E4
RET Z C8
Return with Z (no special key handled) if CTRL is down.
07E5
ADD A,01H C6 01
Add 01H to Register A: it carries out only when both SHIFT bits are 1 (both keys up).
07E7
CCF 3F
Complement the Carry flag: the Carry flag is now set when a SHIFT key is down.
07E8
If no SHIFT key is down (the Carry flag clear), jump to 07F5H.
07EA
LD A,(F401H) 3A 01 F4LD A,(KB1)
SHIFT down: load Register A with F401H, the keyboard row whose bit 0 is the @ key.
07ED
BIT 0,A CB 47
Test bit 0 of Register A (the keyboard row at F401H), the @ key.
07EF
If @ is not down, jump to 07FCH to check BREAK and ENTER.
07F1
SET 1,(HL) CB CE
SHIFT @: set bit 1 of KFLAG$ at Register Pair HL, the pause bit.
07F3
Jump to 07FCH to check BREAK and ENTER in the keyboard row at F440H.
07F5KCK1
LD A,(0835H) 3A 35 08LD A,(OPREG_SV_PTR)
Load Register A with the low byte at 0835H (OPREG_SV_PTR), the pointer into the Operation Register save area.
07F8
SUB 6FH D6 6F
Subtract 6FH from Register A: zero when the pointer is at 086FH, the first level, set by the ENADIS_DO_RAM call of this routine alone.
07FA
If another routine also has the memory switched in, jump to 0805H and do not note ENTER (on this path Register A holds the difference, not a keyboard row). Bug B1: there Register A is the count of extra levels, which 0805H tests as the BREAK key.
07FCKCK1A
LD A,(F440H) 3A 40 F4LD A,(KB7)
Load Register A with F440H, the keyboard row with ENTER (bit 0), CLEAR (bit 1) and BREAK (bit 2).
07FF
BIT 0,A CB 47
Test bit 0 of Register A (the keyboard row at F440H), the ENTER key.
0801
If ENTER is not down, jump to 0805H to check BREAK.
0803
SET 2,(HL) CB D6
Set bit 2 of KFLAG$ at Register Pair HL, noting ENTER.
0805KCK1B
BIT 2,A CB 57
Test bit 2 of Register A (the keyboard row at F440H), the BREAK key. Bug B1: reached from 07FAH, Register A is the low byte of OPREG_SV_PTR less 6FH, so with four or more other levels open bit 2 is set and BREAK is reported though nobody pressed it.
0807
PUSH AF F5
Save Register Pair AF (Z for no BREAK, Carry for SHIFT) on the stack as the return status.
0808
If BREAK is not down, jump to 0815H and return with Z.
080A
If SHIFT is down with BREAK, jump to 0815H and ignore it.
080C
LD A,(007CH) 3A 7C 00LD A,(SFLAG$)
Load Register A with 007CH (SFLAG$), the system flags.
080F
BIT 4,A CB 67
Test bit 4 of Register A, set when BREAK is disabled (SYSTEM (BREAK=OFF)).
0811
If BREAK is disabled (bit 4 of SFLAG$ set), jump to 0815H.
0813
SET 0,(HL) CB C6
Set bit 0 of KFLAG$ at Register Pair HL, the BREAK bit.
0815KCK2
POP AF F1
Restore Register Pair AF: the Carry flag set for SHIFT and NZ for BREAK.
0816
RET C9
Return (through DIS_DO_RAM, which switches the keyboard memory out).

0817H - ENADIS_DO_RAM and DIS_DO_RAM: Switch the Video and Keyboard In and Out

ENADIS_DO_RAM brings the keyboard (F400H-F7FFH) and video memory (F800H-FFFFH) into the memory map by setting bits 1-0 of the Operation Register to 10, and pushes DIS_DO_RAM as the return address of its caller's caller, so the memory is switched out again when the caller returns. The previous OPREG$ value goes on a small stack at 086FH-0876H, OPREG_SV_PTR (the operand at 0835H) pointing to the current level. If the stack pointer is at F3FDH or above, where the switched in memory would hide it, the stack is moved to 0340H, and bit 7 of the saved value records the move. Register Pairs AF and HL are kept in the operands of two LD HL instructions at 0865H and 086AH rather than on the stack. Both routines end with interrupts enabled.

0817ENADIS_DO_RAM
DI F3
Disable interrupts while the stack and the memory map are changed.
0818
LD (086BH),HL 22 6B 08LD (HLSAV),HL
Self-Modifying Code
Store Register Pair HL into 086BH-086CH (HLSAV), the operand of the LD HL at 086AH that restores it.
081B
PUSH AF F5
Push Register Pair AF on the stack to copy it.
081C
POP HL E1
Pop it into Register Pair HL: Register Pair HL = the caller's Register Pair AF.
081D
LD (0866H),HL 22 66 08LD (AFSAV),HL
Self-Modifying Code
Store Register Pair HL (the caller's AF) into 0866H-0867H (AFSAV), the operand of the LD HL at 0865H.
0820
LD HL,0C03H 21 03 0C
Load Register Pair HL with 0C03H for the stack test.
0823
ADD HL,SP 39
Add the Stack Pointer to Register Pair HL: the Carry flag is set when the Stack Pointer is F3FDH or above.
0824
If the stack is below F3FDH, jump to 082FH and keep it.
0826
POP HL E1
The stack is too high: pop the return address into Register Pair HL.
0827
LD (0863H),SP ED 73 63 08LD (SPSAV),SP
Self-Modifying Code
Store the Stack Pointer into 0863H-0864H (SPSAV), the operand of the LD SP at 0862H that DIS_DO_RAM uses to put it back.
082B
LD SP,0340H 31 40 03
Load the Stack Pointer with 0340H (STACK$-40H), a stack in the system stack page, below the switched memory.
082E
PUSH HL E5
Push Register Pair HL (the return address) onto the new stack.
082F
LD HL,0846H 21 46 08LD HL,DIS_DO_RAM
Point Register Pair HL to 0846H (DIS_DO_RAM).
0832
EX (SP),HL E3
Exchange Register Pair HL with the top of the stack at the Stack Pointer: the stack now holds 0846H, and Register Pair HL the return address.
0833
PUSH HL E5
Push Register Pair HL (the return address) on top: ENADIS_DO_RAM returns to its caller, and the caller's RET goes to DIS_DO_RAM.
0834
LD HL,086EH 21 6E 08LD HL,OPREG_SV_AREA
Self-Modifying Code
Load Register Pair HL with OPREG_SV_PTR, the operand at 0835H-0836H, which points to the current save level; 086EH (OPREG_SV_AREA) in the file, at rest.
0837
INC HL 23
Increment Register Pair HL to the next save level.
0838
LD A,(0078H) 3A 78 00LD A,(OPREG$)
Load Register A with 0078H (OPREG$), the current Operation Register value.
083B
If the stack was not moved (the Carry flag from 0823H is still clear), jump to 083FH.
083D
AND 7FH E6 7F
The stack was moved: clear bit 7 of Register A (the PAGE bit) to record it.
083F
LD (HL),A 77
Store Register A (the previous OPREG$, bit 7 cleared if the stack was moved) into the save level at Register Pair HL.
0840
AND FCH E6 FC
Mask Register A with FCH, clearing bits 1-0 (SEL1 and SEL0), the memory map select.
0842
OR 82H F6 82
Set bits 7 and 1 of Register A with OR 82H: memory map 10 (keyboard and video in) and the PAGE bit, leaving NZ.
0844
Jump to DOOPREG at 0858H to store the pointer and send Register A to the Operation Register.
0846DIS_DO_RAM
DI F3
Disable interrupts while the memory map and the stack are changed.
0847
LD (086BH),HL 22 6B 08LD (HLSAV),HL
Self-Modifying Code
Store Register Pair HL into 086BH-086CH (HLSAV), the operand of the LD HL at 086AH.
084A
PUSH AF F5
Push Register Pair AF on the stack to copy it.
084B
POP HL E1
Pop it into Register Pair HL: Register Pair HL = the Register Pair AF to keep.
084C
LD (0866H),HL 22 66 08LD (AFSAV),HL
Self-Modifying Code
Store Register Pair HL (Register Pair AF) into 0866H-0867H (AFSAV), the operand of the LD HL at 0865H.
084F
LD HL,(0835H) 2A 35 08LD HL,(OPREG_SV_PTR)
Load Register Pair HL with 0835H (OPREG_SV_PTR), the pointer to the current save level.
0852
LD A,(HL) 7E
Load Register A with the OPREG$ value saved at that level, Register Pair HL.
0853
BIT 7,A CB 7F
Test bit 7 of Register A: Z when ENADIS_DO_RAM moved the stack.
0855
SET 7,A CB FF
Set bit 7 of Register A, the PAGE bit, again (SET leaves the Z flag of the test).
0857
DEC HL 2B
Decrement Register Pair HL to the previous save level.
0858DOOPREG
LD (0835H),HL 22 35 08LD (OPREG_SV_PTR),HL
Self-Modifying Code
Store Register Pair HL (the save level) into 0835H-0836H (OPREG_SV_PTR), the operand of the LD HL at 0834H.
085B
LD (0078H),A 32 78 00LD (OPREG$),A
Store Register A (the new Operation Register value) into 0078H (OPREG$).
085E
OUT (84H),A D3 84
Send Register A to port 84H, the Operation Register, switching the memory map.
0860
If NZ (switching in, or switching out with the stack not moved), jump to 0865H.
0862
LD SP,0000H 31 00 00
Self-Modifying Code
Load the Stack Pointer with the stack saved at 0827H, the operand at 0863H-0864H (SPSAV); 0000H in the file.
0865
LD HL,0000H 21 00 00
Self-Modifying Code
Load Register Pair HL with the Register Pair AF saved at 081DH or 084CH (the operand at 0866H-0867H, AFSAV; 0000H in the file).
0868
PUSH HL E5
Push Register Pair HL (the saved AF) on the stack.
0869
POP AF F1
Pop it into Register Pair AF, restoring Register A and the flags.
086A
LD HL,0000H 21 00 00
Self-Modifying Code
Load Register Pair HL with the Register Pair HL saved at 0818H or 0847H (the operand at 086BH-086CH, HLSAV; 0000H in the file).
086D
EI FB
Enable interrupts, which ENADIS_DO_RAM and DIS_DO_RAM disabled on entry.
086E
RET C9
Return. This RET byte is also OPREG_SV_AREA (086EH), the base level of the save stack.
086F-0876
DEFB 00H x 8 00 x 8
OPREG_SV_AREA+1 to +8, 086FH-0876H: the eight save levels of the Operation Register value, one for each nested ENADIS_DO_RAM.

0877H - @BANK: Memory Bank Control

@BANK (SVC 102) with the bank number 0-2 in Register A (the caller's Register C) and the function in Register B. Function 0 switches the bank into the upper 32K, reached at 08B3H (bit 7 of the bank number set: also jump to the address in Register Pair HL in the new bank); functions 1, 2 and 3 reset, test and set the bank's in use bit in BUR$ (0200H) through an instruction that is changed at 08B0H; function 4 returns the current bank in Register A. Bank 0 is the normal upper 32K; banks 1 and 2 are those of a 128K machine. An error goes to PERR at 0DEDH.

0877@BANK
AND 7FH E6 7F
Mask Register A (the bank number) with 7FH, removing the transfer bit 7.
0879
CP 03H FE 03
Compare Register A (the bank number) with 03H, one past the highest bank.
087B
If the bank number is 3 or above, jump to PERR at 0DEDH, the parameter error.
087E
DEC B 05
Decrement Register B, the function code, to test for function 0.
087F
If Register B was 0 (now negative), jump to 08B3H to switch the bank in.
0882
LD C,86H 0E 86
Load Register C with 86H, the second byte of RES 0,(HL), for function 1.
0884
If Register B was 1, jump to 089FH to reset the bank's bit in BUR$ (not in use).
0886
LD C,46H 0E 46
Load Register C with 46H, the second byte of BIT 0,(HL), for function 2.
0888
DEC B 05
Decrement Register B, the function code, to test for function 2.
0889
If Register B was 2, jump to 089FH to test the bank's bit in BUR$.
088B
DEC B 05
Decrement Register B, the function code, to test for function 3.
088C
If Register B was 3, jump to 0897H to set the bank's bit in BUR$ (in use).
088E
DEC B 05
Decrement Register B, the function code, to test for function 4.
088FPERRX
If Register B was not 4, jump to PERR at 0DEDH: no such function.
0892
LD A,(0202H) 3A 02 02LD A,(LBANK$)
Function 4: load Register A with 0202H (LBANK$), the bank now switched in.
0895
CP A BF
Compare Register A with itself, setting Z for success.
0896
RET C9
Return with Z and the current bank number in Register A.
0897
LD B,A 47
Function 3: copy Register A (the bank number) into Register B.
0898
Call 089FH with Register C = 46H to test whether the bank is in use already.
089B
RET NZ C0
Return with NZ (and Register A = 08H, Device not available) if the bank is in use.
089C
LD A,B 78
Copy Register B (the bank number) back into Register A.
089D
LD C,C6H 0E C6
Load Register C with C6H, the second byte of SET 0,(HL).
089F
AND 07H E6 07
Mask Register A (the bank number) with 07H, the bit number in BUR$.
08A1
RLCA 07
Rotate Register A left; three rotations move the bank number to bits 5-3, the bit number field of a CB instruction.
08A2
RLCA 07
Rotate Register A left (second of the three rotations of the bank number).
08A3
RLCA 07
Rotate Register A left (third); Register A = the bank number times 8.
08A4
OR C B1
OR Register C (86H, 46H or C6H) into Register A, giving the second byte of RES, BIT or SET bank,(HL).
08A5
LD (08B0H),A 32 B0 08
Self-Modifying Code
Store Register A into 08B0H, the second byte of the CB instruction at 08AFH.
08A8
XOR A AF
Clear Register A, setting the Z flag for a successful return.
08A9
LD A,08H 3E 08
Load Register A with 08H, the error code Device not available (LD leaves the Z flag).
08AB
PUSH HL E5
Save Register Pair HL on the stack; the caller's value is kept.
08AC
LD HL,0200H 21 00 02LD HL,BUR$
Point Register Pair HL to 0200H (BUR$), the bank use byte.
08AF
BIT 0,(HL) CB 46
Self-Modifying Code
RES, BIT or SET the bank's bit of BUR$ at Register Pair HL, as stored at 08A5H (the file holds BIT 0,(HL)). Only BIT changes the Z flag: NZ when the bank is in use.
08B1
POP HL E1
Restore Register Pair HL (the caller's value) from the stack.
08B2
RET C9
Return with Z, or NZ and Register A = 08H when a tested bank is in use.
08B3
PUSH HL E5
Function 0: save Register Pair HL (the transfer address, when bit 7 is set) on the stack.
08B4
LD HL,8005H 21 05 80
Load Register Pair HL with 8005H for the stack test.
08B7
ADD HL,SP 39
Add the Stack Pointer to Register Pair HL: the Carry flag is set when the Stack Pointer is 7FFBH or above, in the memory being switched.
08B8
POP HL E1
Restore Register Pair HL (the transfer address) from the stack.
08B9
If the stack is in the upper 32K, jump to PERR at 0DEDH.
08BC
CP 01H FE 01
Compare Register A (the bank, 0-2) with 01H: the Carry flag is set for bank 0.
08BE
RLA 17
Rotate Register A left through the Carry flag: banks 0, 1 and 2 become the masks 01H, 02H and 04H.
08BF
LD B,A 47
Copy Register A (the bank mask) into Register B.
08C0
LD A,(0201H) 3A 01 02LD A,(BAR$)
Load Register A with 0201H (BAR$), the bank available byte.
08C3
AND B A0
AND Register B (the bank mask) with Register A: not zero when the bank is not present.
08C4
If the bank is not present, jump to PERRX at 088FH; the NZ flag of the AND at 08C3H makes its JP NZ go on to PERR at 0DEDH.
08C6
LD A,B 78
Copy Register B (the mask 01H, 02H or 04H) into Register A.
08C7
RRA 1F
Rotate Register A right through the Carry flag: 00H, 01H or 02H, the Carry flag set only for bank 0.
08C8
CCF 3F
Complement the Carry flag: clear for bank 0, set for banks 1 and 2.
08C9
ADC A,00H CE 00
Add the Carry flag to Register A: 00H, 02H or 03H, the Operation Register bank bits for banks 0, 1 and 2.
08CB
RLCA 07
Rotate Register A left; four rotations move the value to bits 5-4, the bank select bits of the Operation Register.
08CC
RLCA 07
Rotate Register A left (second of the four rotations of the bank bits).
08CD
RLCA 07
Rotate Register A left (third of the four rotations of the bank bits).
08CE
RLCA 07
Rotate Register A left (fourth); Register A = 00H, 20H or 30H.
08CF
LD B,A 47
Copy Register A (the new bank bits) into Register B.
08D0
LD A,(0078H) 3A 78 00LD A,(OPREG$)
Load Register A with 0078H (OPREG$), the current Operation Register value.
08D3
AND 8FH E6 8F
Mask Register A with 8FH, clearing bits 6-4, the bank bits.
08D5
OR B B0
OR Register B (the new bank bits) into Register A.
08D6
LD (0078H),A 32 78 00LD (OPREG$),A
Store Register A (the new Operation Register value) into 0078H (OPREG$).
08D9
OUT (84H),A D3 84
Send Register A to port 84H, the Operation Register, switching the bank in.
08DB
LD A,(0202H) 3A 02 02LD A,(LBANK$)
Load Register A with 0202H (LBANK$), the bank that was switched in.
08DE
LD B,A 47
Copy Register A (the old bank) into Register B.
08DF
LD A,C 79
Copy Register C (the bank requested, with its bit 7) into Register A.
08E0
AND 7FH E6 7F
Mask Register A (the bank requested) with 7FH, removing the transfer bit 7.
08E2
LD (0202H),A 32 02 02LD (LBANK$),A
Store Register A (the new bank) into 0202H (LBANK$).
08E5
XOR C A9
Exclusive OR Register C into Register A, leaving only bit 7 of the request.
08E6
OR B B0
OR Register B (the old bank) into Register A.
08E7
LD C,A 4F
Copy Register A (bit 7 of the request and the old bank) into Register C.
08E8
BIT 7,C CB 79
Test bit 7 of Register C, the transfer request.
08EA
LD B,00H 06 00
Load Register B with 00H, so Register Pair BC can be passed back to @BANK to restore the old bank.
08EC
RET Z C8
Return with Z, Register C = the old bank, if no transfer was asked for.
08ED
EX (SP),HL E3
Transfer: exchange Register Pair HL with the top of the stack at the Stack Pointer, putting the transfer address there and the caller's return address in Register Pair HL.
08EE
CP A BF
Compare Register A with itself, setting Z for a successful return.
08EF
RET C9
Return, which jumps to the transfer address in the new bank with Register Pair HL = the original return address.

08F0H - KIDVR: The Keyboard Driver

The driver of the KI device (KIDCB$ at 0208H points here). It starts with the standard module header: a jump to the code, the last byte used, the name and the DCB address. KIDATA$ follows: the last key, the repeat timing and an image of the eight keyboard rows. The Model 4 keyboard is read at F401H (row 0, @ and A-G), F402H (H-O), F404H (P-W), F408H (X-Z), F410H (0-7), F420H (8, 9, colon, semicolon, comma, minus, period, slash), F440H (ENTER, CLEAR, BREAK, the four arrows, SPACE) and F480H (left and right SHIFT, CTRL, CAPS, F1, F2, F3), each byte a row with one bit for each key held down.

08F0KIDVR
Jump over the module header to KIBGN at 0923H.
08F2-08F3
DEFW 0B87H 87 0B
KIDVR+2, 08F2H-08F3H = 0B87H (KILAST), the last byte of the keyboard driver.
08F4-08F7
DEFB 03H / DEFM "$KI" 03 24 4B 49
KIDVR+4, 08F4H-08F7H: the name length, 3, and the module name $KI.
08F8-08F9
DEFW 0208H 08 02
KIDVR+8, 08F8H-08F9H = 0208H, the address of KIDCB$, the DCB this driver serves.
08FA-08FB
DEFW 0000H 00 00
KIDVR+10, 08FAH-08FBH: a spare word of the module header, 0000H.
08FCKIDATA$
DEFB 00H 00
KIDATA$+0, 08FCH: the last key code found by KISCAN (00H for none), kept for the repeat.
08FD
DEFB 00H 00
KIDATA$+1, 08FDH: the value of TIMER$ at which the held key repeats next.
08FE
DEFB 16H 16
KIDATA$+2, 08FEH: 16H (22), the delay before a held key first repeats, in clock interrupts of 33.3 ms (0.733 seconds).
08FF
DEFB 02H 02
KIDATA$+3, 08FFH: 02H, the repeat rate, two clock interrupts (0.067 seconds) between repeats.
0900-0907
DEFB 0FFH, 0FFH, 0FFH, 0FFH, 0FFH, 0FFH, 0FFH, 0FFH FF FF FF FF FF FF FF FF
KIDATA$+4 to +11, 0900H-0907H: the image of keyboard rows 0 to 7 as last read, FFH in the file so that the first scan sees every row as changed.
0908-0909KBTBL
DEFB 0DH, 1DH 0D 1D
KBTBL, 0908H-0909H: the codes of ENTER, unshifted 0DH and shifted 1DH. KBTBL holds two codes for each special key, unshifted then shifted, indexed by the key number.
090A-090B
DEFB 1FH, 1FH 1F 1F
KBTBL+2, 090AH-090BH: the codes of CLEAR, 1FH and 1FH.
090C-090D
DEFB 80H, 00H 80 00
KBTBL+4, 090CH-090DH: the codes of BREAK, 80H unshifted and 00H shifted.
090E-090F
DEFB 0BH, 1BH 0B 1B
KBTBL+6, 090EH-090FH: the codes of the up arrow, 0BH and 1BH.
0910-0911
DEFB 0AH, 1AH 0A 1A
KBTBL+8, 0910H-0911H: the codes of the down arrow, 0AH (line feed) and 1AH.
0912-0913
DEFB 08H, 18H 08 18
KBTBL+10, 0912H-0913H: the codes of the left arrow, 08H (backspace) and 18H.
0914-0915
DEFB 09H, 19H 09 19
KBTBL+12, 0914H-0915H: the codes of the right arrow, 09H (tab) and 19H.
0916-0917
DEFB 20H, 20H 20 20
KBTBL+14, 0916H-0917H: the codes of SPACE, 20H shifted or not.
0918-0919
DEFB 81H, 91H 81 91
KBTBL+16, 0918H-0919H: the codes of F1, 81H and 91H.
091A-091B
DEFB 82H, 92H 82 92
KBTBL+18, 091AH-091BH: the codes of F2, 82H and 92H.
091C-091D
DEFB 83H, 93H 83 93
KBTBL+20, 091CH-091DH: the codes of F3, 83H and 93H.
091E-0922SPCLTB
DEFM ",/.;" / DEFB 0DH 2C 2F 2E 3B 0D
SPCLTB, 091EH-0922H: comma, slash, period, semicolon and ENTER. With CLEAR held they give 5BH-5FH ([, backslash, ], ^ and _), and with SHIFT as well 7BH-7FH; with CTRL the first four give 1BH-1EH.

0923H - KIBGN: Keyboard Request Entry

Entered from IOBGN with the request in the flags (Carry for GET, Z for PUT, neither for CTL) and Register C the character or control code. It calls the task hook @KITSK at 0089H, then TYPAHD for the request. When the key returned was typed with CTRL (the Carry flag set) and is CTRL colon, it prints the screen.

0923KIBGN
LD A,C 79
Copy Register C (the character or control code of the request) into Register A.
0924
PUSH AF F5
Save Register Pair AF (Register A and the request flags) on the stack.
0925
Call @KITSK at 0089H, the hook for a keyboard task in low memory.
0928
POP AF F1
Restore Register Pair AF: Register A and the request flags set by IOBGN.
0929
Call TYPAHD at 0AD5H to carry out the request: a GET returns Z and the key in Register A; a key read straight from the keyboard has the Carry flag set for CTRL, while a key from the type-ahead buffer comes back with the Carry flag clear (so a buffered CTRL colon does not print the screen).
092C
RET NC D0
Return with the result unless the Carry flag is set (no CTRL key).
092D
PUSH AF F5
Save Register Pair AF (the CTRL key in Register A and the flags) on the stack.
092E
CP 3AH FE 3A
Compare Register A with 3AH, the colon: CTRL colon prints the screen.
0930
If Register A is CTRL colon, jump to 0934H to print the screen.
0932
POP AF F1
Restore Register Pair AF, the key and its flags, for the caller.
0933
RET C9
Return the CTRL key to the caller of the keyboard driver.
0934
POP AF F1
Discard the saved Register Pair AF from the stack and fall into @VDPRT.

0935H - @VDPRT: Print the Screen

@VDPRT (SVC 107) sends the 24 rows of 80 characters of the screen to the printer, each row ended by 0DH. Control codes 00H-1FH are printed as 40H-5FH, and codes 80H-FFH as a period unless bit 7 of DFLAG$ (006DH, the graphic printer switch) is set. BREAK stops it. It returns NZ with Register A = 0.

0935@VDPRT
LD A,(006DH) 3A 6D 00LD A,(DFLAG$)
Load Register A with 006DH (DFLAG$), the device flags.
0938
RLCA 07
Rotate Register A left, moving bit 7 (the graphic printer switch) into the Carry flag.
0939
LD A,3EH 3E 3E
Load Register A with 3EH, the opcode of LD A,n: codes 80H-FFH are replaced by the period.
093B
If the graphic switch is off, jump to 093FH and keep the 3EH.
093D
LD A,FEH 3E FE
Graphic switch on: load Register A with FEH, the opcode of CP n, which leaves the character in Register A.
093F
LD (095CH),A 32 5C 09
Self-Modifying Code
Store Register A (3EH or FEH) into 095CH, the opcode of the instruction at 095CH.
0942
LD HL,0074H 21 74 00LD HL,KFLAG$
Point Register Pair HL to 0074H (KFLAG$), the keyboard flags.
0945
RES 0,(HL) CB 86
Reset bit 0 of KFLAG$ at Register Pair HL, the BREAK bit, before starting.
0947
PUSH HL E5
Save Register Pair HL (0074H) on the stack, to test BREAK at the end of each row.
0948
LD HL,0000H 21 00 00
Load Register Pair HL with 0000H: Register H the row and Register L the column, both 0.
094B
LD B,01H 06 01
Load Register B with 01H, the @VDCTL function that reads the character at row Register H, column Register L.
094D
Call @VDCTL at 0B99H to read the character at the screen position into Register A.
0950
If @VDCTL returned NZ (an error), jump to 0979H to end.
0952
CP 20H FE 20
Compare Register A (the character) with 20H, the first printable character.
0954
If Register A is 20H or above (printable), jump to 0958H.
0956
ADD A,40H C6 40
A control code 00H-1FH: add 40H to Register A, printing it as 40H-5FH (@, A to Z and the next five).
0958
CP 80H FE 80
Compare Register A (the screen character) with 80H, the first graphic code.
095A
If Register A is below 80H, jump to 095EH and print it.
095C
LD A,2EH 3E 2E
Self-Modifying Code
Codes 80H-FFH: load Register A with 2EH, a period. With the graphic switch on, 093FH has changed the opcode to CP 2EH, which leaves the character as it is.
095E
Call @PRT at 063DH to send Register A to the printer.
0961
If the printer returned NZ (an error), jump to 0979H to end.
0963
INC L 2C
Increment Register L to the next column of the screen row.
0964
LD A,L 7D
Copy Register L (the column) into Register A.
0965
SUB 50H D6 50
Subtract 50H (80) from Register A: zero at the end of the row.
0967
If the row is not finished, loop back to 094BH for the next character.
0969
LD L,A 6F
Copy Register A (zero) into Register L, column 0.
096A
DEC L 2D
Decrement Register L to FFH, so the INC at 0963H after the 0DH below gives column 0.
096B
EX (SP),HL E3
Exchange Register Pair HL with the top of the stack at the Stack Pointer: Register Pair HL = 0074H (KFLAG$), the stack holds the row and column.
096C
BIT 0,(HL) CB 46
Test bit 0 of KFLAG$ at Register Pair HL, the BREAK bit.
096E
EX (SP),HL E3
Exchange Register Pair HL with the top of the stack at the Stack Pointer again: Register Pair HL = the row and column.
096F
If BREAK was pressed (bit 0 of KFLAG$ set), jump to 0979H to end.
0971
INC H 24
Increment Register H to the next row of the screen.
0972
LD A,H 7C
Copy Register H (the new row number) into Register A for the test.
0973
CP 18H FE 18
Compare Register A with 18H (24), one past the last row.
0975
LD A,0DH 3E 0D
Load Register A with 0DH, the end of a printed row (LD leaves the flags of the compare).
0977
If rows remain, jump to 095EH to print the 0DH and go on with the next row.
0979
LD A,0DH 3E 0D
Load Register A with 0DH to end the last printed line.
097B
Call @PRT at 063DH to send the 0DH in Register A to the printer.
097E
POP HL E1
Pop the saved 0074H (KFLAG$) into Register Pair HL.
097F
RES 0,(HL) CB 86
Reset bit 0 of KFLAG$ at Register Pair HL, the BREAK bit.
0981
Jump to NOCHAR at 09B5H to return NZ with Register A = 0.

0983H - KISCAN: Scan the Keyboard

Compares each keyboard row with its image at 0900H-0907H. A newly pressed key is turned into its code; with no change, a key still held repeats after the delay at KIDATA$+2 and then at the rate at KIDATA$+3. Returns Z with the key code in Register A (the Carry flag set for CTRL), or NZ with Register A = 0 for no key. Register E returns the SHIFT row, with bit 0 set for either SHIFT key. Index Register IX = 08FCH (KIDATA$) on return.

0983KISCAN
LD IX,08FCH DD 21 FC 08LD IX,KIDATA$
Point Index Register IX to 08FCH (KIDATA$), the keyboard driver data.
0987
LD HL,0900H 21 00 09
Point Register Pair HL to 0900H, the image of keyboard row 0.
098A
LD BC,F401H 01 01 F4LD BC,KB0
Load Register Pair BC with F401H, the address of keyboard row 0; Register C is shifted left for each row.
098D
LD D,00H 16 00
Load Register D with 00H, the row counter, counting the rows read.
098F
LD A,(BC) 0A
Load Register A with the keyboard row at Register Pair BC.
0990
LD E,A 5F
Copy Register A (the row as read) into Register E.
0991
XOR (HL) AE
Exclusive OR the image of the row at Register Pair HL into Register A: the bits that changed.
0992
If any key of the row changed, jump to 09BAH.
0994
INC D 14
Increment Register D, the row counter, for the next keyboard row.
0995
INC HL 23
Increment Register Pair HL to the image of the next row.
0996
RLC C CB 01
Rotate Register C left: the address of the next row (F402H, F404H, ... F480H).
0998
Loop back to 098FH while Register C is positive, for rows 0 to 6.
099B
LD A,(BC) 0A
Load Register A with keyboard row 7 at Register Pair BC (F480H).
099C
AND 78H E6 78
Mask Register A with 78H, keeping CAPS, F1, F2 and F3 (SHIFT and CTRL alone are not keys).
099E
LD E,A 5F
Copy Register A (row 7 without SHIFT and CTRL) into Register E.
099F
XOR (HL) AE
Exclusive OR the image of row 7 at Register Pair HL into Register A.
09A0
If any of the keys of row 7 changed, jump to 09BAH.
09A2
LD A,(IX+00H) DD 7E 00
No change: load Register A with the last key at Index Register IX+00H (08FCH).
09A5
OR A B7
Test Register A (the last key code at 08FCH) for zero with OR A.
09A6
If no key is held (Register A zero), jump to NOCHAR at 09B5H.
09A8
LD A,(002CH) 3A 2C 00LD A,(TIMER$)
Load Register A with 002CH (TIMER$), the clock interrupt counter.
09AB
SUB (IX+01H) DD 96 01
Subtract the repeat time at Index Register IX+01H (08FDH) from Register A.
09AE
SUB (IX+02H) DD 96 02
Subtract the initial delay at Index Register IX+02H (08FEH) from Register A: a borrow means TIMER$ has reached the repeat time and is less than 22 interrupts past it.
09B1
LD A,(BC) 0A
Load Register A with keyboard row 7 at Register Pair BC (F480H), the SHIFT keys.
09B2
LD E,A 5F
Copy Register A (the SHIFT row) into Register E.
09B3
If the repeat time has come, jump to 0A1EH to repeat the key.
09B5NOCHAR
OR 01H F6 01
Set bit 0 of Register A with OR 01H, giving NZ.
09B7
LD A,00H 3E 00
Load Register A with 00H (LD leaves the NZ flag): no key.
09B9
RET C9
Return NZ with Register A = 0: there is no key to give.
09BA
LD (HL),E 73
A row changed: store Register E (the row as read) into its image at Register Pair HL.
09BB
AND E A3
AND Register E into Register A (the changed bits): the keys just pressed.
09BC
If no key was pressed (only releases), jump to NOKEY at 0A88H.
09BF
LD E,A 5F
Copy Register A (the bit of the key pressed) into Register E.
09C0
LD A,D 7A
Copy Register D (the row number) into Register A.
09C1
RLCA 07
Rotate Register A left; three rotations give 8 times the row.
09C2
RLCA 07
Rotate Register A left (second of three rotations of the row number).
09C3
RLCA 07
Rotate Register A left (third); Register A = 8 times the row.
09C4
LD D,A 57
Copy Register A (8 times the row) into Register D, the key number to be completed.
09C5
LD C,01H 0E 01
Load Register C with 01H, the bit of column 0.
09C7
LD A,C 79
Copy Register C (the column bit) into Register A.
09C8
AND E A3
AND Register E (the bit of the key pressed) into Register A.
09C9
If this is the column of the key, jump to 09E4H with Register D = the key number.
09CB
INC D 14
Increment Register D, the key number, for the next column.
09CC
RLC C CB 01
Rotate Register C left to the bit of the next column.
09CE
Jump back to 09C7H to test the next column of the row.
09D0
SUB 90H D6 90
Not a letter: subtract 90H from Register A (the key number plus 60H), giving the key number less 30H.
09D2
If no borrow (rows 6 and 7, the special keys), jump to 0A26H.
09D4
ADD A,40H C6 40
Rows 4 and 5: add 40H to Register A, giving 30H-3FH (the digits, colon, semicolon, comma, minus, period, slash).
09D6
CP 3CH FE 3C
Compare Register A (the character 30H-3FH) with 3CH.
09D8
If Register A is below 3CH (0-9, colon, semicolon), jump to 09DCH.
09DA
XOR 10H EE 10
Flip bit 4 of Register A: 3CH-3FH become 2CH-2FH (comma, minus, period, slash).
09DC
BIT 0,E CB 43
Test bit 0 of Register E, set when a SHIFT key is down.
09DE
If not shifted, jump to 0A40H with the character.
09E0
XOR 10H EE 10
Shifted: flip bit 4 of Register A (1 becomes the exclamation mark, the comma becomes the less than sign, the slash the question mark).
09E2
Jump to 0A40H with the shifted character in Register A.
09E4
LD A,(F480H) 3A 80 F4LD A,(SHIFT)
Load Register A with F480H, the keyboard row of SHIFT and CTRL.
09E7
LD E,A 5F
Copy Register A (the SHIFT row) into Register E.
09E8
AND 02H E6 02
Mask Register A with 02H, the right SHIFT key.
09EA
RRCA 0F
Rotate Register A right, moving the right SHIFT bit to bit 0.
09EB
OR E B3
OR Register E into Register A: bit 0 is now set for either SHIFT key.
09EC
LD E,A 5F
Copy Register A (the SHIFT row with the merged bit 0) into Register E.
09ED
LD A,D 7A
Copy Register D (the key number) into Register A.
09EE
ADD A,60H C6 60
Add 60H to Register A: rows 0 to 3 give 60H-7FH, the lower case letters with the at sign key at 60H.
09F0
CP 80H FE 80
Compare Register A (the key number plus 60H) with 80H.
09F2
LD HL,0074H 21 74 00LD HL,KFLAG$
Point Register Pair HL to 0074H (KFLAG$), the keyboard flags (LD leaves the flags of the compare).
09F5
If Register A is 80H or above (rows 4 to 7), jump to 09D0H.
09F7
BIT 2,E CB 53
Test bit 2 of Register E (the SHIFT row), the CTRL key.
09F9
If CTRL is down with the letter, jump to CTLA2Z at 0A13H.
09FB
CP 60H FE 60
Compare Register A with 60H, the at sign key.
09FD
If Register A is not the at sign key, jump to 0A03H.
09FF
XOR 20H EE 20
Flip bit 5 of Register A: 60H becomes 40H, the at sign (shifted it gives 60H, the accent).
0A01
Jump to 0A0DH, skipping the CAPS test for the at sign.
0A03
BIT 1,(IX+0AH) DD CB 0A 4E
Test bit 1 of the row 6 image at Index Register IX+0AH (0906H), the CLEAR key.
0A07
If CLEAR is held, jump to 0A0DH without the CAPS test.
0A09
BIT 5,(HL) CB 6E
Test bit 5 of KFLAG$ at Register Pair HL, the CAPS lock.
0A0B
If CAPS is locked, jump to TGLCASE at 0A3EH to make the letter upper case.
0A0D
BIT 0,E CB 43
Test bit 0 of Register E, set when a SHIFT key is down.
0A0F
If not shifted, jump to 0A40H with the lower case letter.
0A11
Shifted: jump to TGLCASE at 0A3EH for the upper case letter.
0A13CTLA2Z
SUB 60H D6 60
Subtract 60H from Register A: CTRL A to Z give 01H-1AH, CTRL at sign gives 00H.
0A15
If not zero, jump to 0A40H with the control code.
0A17
BIT 0,E CB 43
CTRL at sign: test bit 0 of Register E, the SHIFT keys.
0A19
SCF 37
Set the Carry flag, the CTRL indication of the return.
0A1A
RET Z C8
Unshifted: return Z and Carry with Register A = 00H.
0A1B
LD A,1CH 3E 1C
SHIFT CTRL at sign: load Register A with 1CH, the end of file error code.
0A1D
RET C9
Return NZ with Register A = 1CH (end of file).
0A1E
LD A,(002CH) 3A 2C 00LD A,(TIMER$)
Repeat: load Register A with 002CH (TIMER$), the clock interrupt counter.
0A21
ADD A,(IX+03H) DD 86 03
Add the repeat rate at Index Register IX+03H (08FFH) to Register A, the time of the next repeat.
0A24
Jump to 0A98H to store it and return the held key again.
0A26
CP 0BH FE 0B
Special keys: compare Register A (the key number less 30H) with 0BH, the CAPS key.
0A28
If the key is CAPS (0BH), jump to CAPSKEY at 0A79H.
0A2A
If below 0BH (ENTER to SPACE, 0-7), jump to 0A2EH.
0A2C
SUB 04H D6 04
F1, F2 and F3 (0CH-0EH): subtract 04H from Register A, giving 8, 9 and 10 to follow SPACE in KBTBL.
0A2E
LD HL,0908H 21 08 09LD HL,KBTBL
Point Register Pair HL to 0908H (KBTBL), the special key table.
0A31
RLCA 07
Rotate Register A left: two bytes for each key in the table.
0A32
BIT 0,E CB 43
Test bit 0 of Register E, set when a SHIFT key is down.
0A34
If not shifted (bit 0 of Register E clear), jump to 0A37H.
0A36
INC A 3C
Shifted: increment Register A to the shifted code of the key.
0A37
LD C,A 4F
Copy Register A (the table offset) into Register C.
0A38
LD B,00H 06 00
Load Register B with 00H, so Register Pair BC is the offset.
0A3A
ADD HL,BC 09
Add Register Pair BC to Register Pair HL, pointing into KBTBL.
0A3B
LD A,(HL) 7E
Load Register A with the code of the key from KBTBL at Register Pair HL.
0A3C
Jump to 0A40H with the code from KBTBL, skipping the case flip.
0A3ETGLCASE
XOR 20H EE 20
Flip bit 5 of Register A, changing the letter between lower and upper case.
0A40
CP 80H FE 80
Compare Register A (the key code) with 80H, BREAK.
0A42
If Register A is not BREAK (80H), jump to 0A53H.
0A44
LD HL,007CH 21 7C 00LD HL,SFLAG$
Point Register Pair HL to 007CH (SFLAG$), the system flags.
0A47
BIT 4,(HL) CB 66
Test bit 4 of SFLAG$ at Register Pair HL, set when BREAK is disabled.
0A49
If BREAK is disabled (bit 4 of SFLAG$ set), jump to 0A52H.
0A4B
LD HL,0074H 21 74 00LD HL,KFLAG$
Point Register Pair HL to 0074H (KFLAG$), the keyboard flags.
0A4E
SET 0,(HL) CB C6
Set bit 0 of KFLAG$ at Register Pair HL, the BREAK bit.
0A50
Jump to 0A53H with Register A = 80H, the BREAK code.
0A52
RLA 17
BREAK disabled: rotate Register A left, 80H becoming 00H, so the key is dropped.
0A53
BIT 1,(IX+0AH) DD CB 0A 4E
Test bit 1 of the row 6 image at Index Register IX+0AH (0906H), the CLEAR key.
0A57
If CLEAR is not held, jump to NOTALPH at 0A67H.
0A59
LD D,A 57
CLEAR held: copy Register A (the key code) into Register D.
0A5A
RES 5,A CB AF
Reset bit 5 of Register A, making a letter upper case for the test.
0A5C
SUB 41H D6 41
Subtract 41H (the letter A) from Register A for the letter test.
0A5E
CP 1AH FE 1A
Compare Register A with 1AH (26), the number of letters.
0A60
LD A,D 7A
Copy Register D (the key code) back into Register A (LD leaves the flags).
0A61
If Register A was not a letter, jump to 0A65H.
0A63
XOR 20H EE 20
A letter: flip bit 5 of Register A, inverting its case.
0A65
OR 80H F6 80
Set bit 7 of Register A, marking a key pressed with CLEAR.
0A67NOTALPH
BIT 0,E CB 43
Test bit 0 of Register E, set when a SHIFT key is down.
0A69
If not shifted (bit 0 of Register E clear), jump to FIXCLR at 0A84H.
0A6BGOTSHFT
CP 9FH FE 9F
Compare Register A with 9FH, CLEAR with its bit 7 (SHIFT CLEAR).
0A6D
If it is SHIFT CLEAR, jump to FIXSCL at 0A82H.
0A6FTSTSPA
CP 20H FE 20
Compare Register A with 20H: SPACE, or SHIFT 0, which gives 20H too.
0A71
If Register A is neither SPACE nor SHIFT 0, jump to KEYOK at 0A89H.
0A73
BIT 0,(IX+08H) DD CB 08 46
Test bit 0 of the row 4 image at Index Register IX+08H (0904H), the 0 key.
0A77
If the 0 key is not down (SHIFT SPACE), jump to KEYOK at 0A89H with 20H.
0A79CAPSKEY
LD A,20H 3E 20
SHIFT 0 or CAPS: load Register A with 20H, the CAPS lock bit of KFLAG$.
0A7BCASHK$
LD HL,0074H 21 74 00LD HL,KFLAG$
Point Register Pair HL to 0074H (KFLAG$), the keyboard flags.
0A7E
XOR (HL) AE
Exclusive OR KFLAG$ at Register Pair HL into Register A, flipping bit 5, the CAPS lock.
0A7F
LD (HL),A 77
Store Register A (the new KFLAG$) at Register Pair HL (0074H).
0A80
Jump to NOKEY at 0A88H: the CAPS key gives no character.
0A82FIXSCL
XOR 80H EE 80
Flip bit 7 of Register A: SHIFT CLEAR becomes 1FH, the clear screen code.
0A84FIXCLR
CP 9FH FE 9F
Compare Register A with 9FH, CLEAR alone with its bit 7.
0A86
If it is not CLEAR alone, jump to KEYOK at 0A89H.
0A88NOKEY
XOR A AF
Clear Register A: no key (CLEAR alone gives nothing, being a shift key).
0A89KEYOK
LD (IX+00H),A DD 77 00
Store Register A (the key code, or 00H) into KIDATA$+0 at Index Register IX+00H (08FCH), the last key.
0A8C
LD BC,0184H 01 84 01
Load Register Pair BC with 0184H, the debounce delay count.
0A8FTYPHK$
Call 0382H (@PAUSE) to wait the count in Register Pair BC.
0A92
LD A,(002CH) 3A 2C 00LD A,(TIMER$)
Load Register A with 002CH (TIMER$), the clock interrupt counter.
0A95DELAY2
ADD A,(IX+02H) DD 86 02
Add the initial repeat delay at Index Register IX+02H (08FEH) to Register A.
0A98
LD (IX+01H),A DD 77 01
Store Register A (the time of the next repeat) into KIDATA$+1 at Index Register IX+01H (08FDH).
0A9B
LD A,(IX+00H) DD 7E 00
Load Register A with the key code at Index Register IX+00H (08FCH).
0A9E
OR A B7
Test Register A (the key code at 08FCH) for zero with OR A.
0A9F
If there is no key (Register A zero), jump to NOCHAR at 09B5H.
0AA2
BIT 2,E CB 53
Test bit 2 of Register E (the SHIFT row), the CTRL key.
0AA4
SCF 37
Set the Carry flag, the CTRL indication of the return.
0AA5
If CTRL is down, jump to SPECL at 0AABH with the Carry flag set.
0AA7
CCF 3F
Complement the Carry flag, clearing it: CTRL is not down.
0AA8DVREXIT
BIT 7,A CB 7F
Test bit 7 of Register A, set for a key pressed with CLEAR.
0AAA
RET Z C8
Return Z with the key in Register A if CLEAR was not held.
0AABSPECL
PUSH AF F5
Save Register Pair AF (the key code and the CTRL indication in the Carry flag) on the stack.
0AAC
LD HL,091EH 21 1E 09LD HL,SPCLTB
Point Register Pair HL to 091EH (SPCLTB), the table of the keys that make the codes 5BH-5FH.
0AAF
RES 7,A CB BF
Reset bit 7 of Register A, removing the CLEAR mark.
0AB1
LD BC,055BH 01 5B 05
Load Register Pair BC with 055BH: Register B = 5 table entries and Register C = 5BH, the code of the first entry.
0AB4
If CTRL is not down, jump to 0AB7H and search all 5 entries.
0AB6
DEC B 05
With CTRL decrement Register B: only the first 4 entries (not ENTER).
0AB7SPCLLP
CP (HL) BE
Compare Register A (the key) with the table entry at Register Pair HL.
0AB8
If Register A matches the entry, jump to HIT at 0ACCH.
0ABA
XOR 10H EE 10
Flip bit 4 of Register A, the key's other shift state.
0ABC
CP (HL) BE
Compare Register A with the table entry at Register Pair HL again.
0ABD
If the shifted form matches, jump to HITWS at 0ACAH.
0ABF
XOR 10H EE 10
Flip bit 4 of Register A back to the key as typed.
0AC1
INC HL 23
Increment Register Pair HL to the next table entry.
0AC2
INC C 0C
Increment Register C to the code of the next entry.
0AC3
Decrement Register B and loop back to 0AB7H for the next entry.
0AC5
POP AF F1
Not in the table: restore Register Pair AF, the key code (with its CLEAR bit) and the Carry flag.
0AC6
If CTRL is down (the Carry flag set), jump to CKCTL2 at 0AD2H.
0AC8CKCTL1
CP A BF
Compare Register A with itself, setting Z.
0AC9
RET C9
Return Z with the key code in Register A and the Carry flag clear.
0ACAHITWS
SET 5,C CB E9
Set bit 5 of Register C, moving to the codes 7BH-7FH.
0ACCHIT
POP AF F1
Restore Register Pair AF, the Carry flag for CTRL.
0ACD
LD A,C 79
Copy Register C (the converted code) into Register A.
0ACECKCTL
If CTRL is not down, jump to CKCTL1 at 0AC8H.
0AD0
AND 1FH E6 1F
CTRL: mask Register A with 1FH, giving the control code.
0AD2CKCTL2
CP A BF
Compare Register A with itself, setting Z.
0AD3
SCF 37
Set the Carry flag, the CTRL indication of the return.
0AD4
RET C9
Return Z and Carry with the key code in Register A.

0AD5H - TYPAHD: Type-Ahead Buffer and Keyboard Requests

Serves the requests of the KI device. The type-ahead buffer is kept in video memory after the 80 by 24 screen: FF80H a switch (non zero while the driver runs, so the type-ahead task leaves the buffer alone), FF81H the PUT offset, FF82H the GET offset and FF83H-FFD3H the 81 byte buffer. A GET takes the oldest key from the buffer, or scans the keyboard when it is empty. PUT does nothing. CTL 3 empties the buffer and CTL FFH copies the 8 keyboard rows to the buffer at Index Register IY.

0AD5TYPAHD
Call ENADIS_DO_RAM at 0817H to bring the keyboard and video memory into the memory map.
0AD8
LD HL,FF80H 21 80 FFLD HL,TYPBUF
Point Register Pair HL to FF80H (TYPBUF), the type-ahead switch.
0ADB
LD (HL),FFH 36 FF
Store FFH at FF80H (Register Pair HL), stopping the type-ahead task while the driver works.
0ADD
If the request is GET (the Carry flag set by IOBGN), jump to 0AFCH.
0ADF
If the request is PUT (Z), jump to TYPON at 0B23H: nothing can be sent to the keyboard.
0AE1
CP 03H FE 03
CTL: compare Register A (the control code) with 03H.
0AE3
If it is CTL 3, jump to CLRTYP at 0B65H to empty the type-ahead buffer.
0AE6
INC A 3C
Increment Register A (the control code): it becomes zero only for FFH.
0AE7
If it is CTL FFH (Register A now zero), jump to CTLFF at 0AECH.
0AE9
XOR A AF
Any other control code: clear Register A, meaning no action and no error.
0AEA
Jump to TYPON at 0B23H and return Z with Register A = 0.
0AECCTLFF
LD HL,F401H 21 01 F4LD HL,KB0
Point Register Pair HL to F401H, keyboard row 0.
0AEF
LD B,08H 06 08
Load Register B with 08H, the eight keyboard rows.
0AF1
LD A,(HL) 7E
Load Register A with the keyboard row at Register Pair HL.
0AF2
LD (IY+00H),A FD 77 00
Store Register A (the row) into the caller's buffer at Index Register IY+00H.
0AF5
INC IY FD 23
Increment Index Register IY to the next byte of the caller's buffer.
0AF7
RL L CB 15
Rotate Register L left: the address of the next keyboard row.
0AF9
Decrement Register B and loop back to 0AF1H for all eight rows.
0AFB
RET C9
Return; the type-ahead switch at FF80H stays FFH until the next keyboard request.
0AFC
PUSH HL E5
GET: save Register Pair HL (FF80H, the switch) on the stack.
0AFD
INC HL 23
Increment Register Pair HL to FF81H, the PUT offset.
0AFE
LD A,(HL) 7E
Load Register A with the PUT offset at Register Pair HL.
0AFF
INC HL 23
Increment Register Pair HL to FF82H, the GET offset.
0B00
CP (HL) BE
Compare Register A (the PUT offset) with the GET offset at Register Pair HL.
0B01
If they are the same (the buffer is empty), jump to 0B1FH to scan the keyboard.
0B03
PUSH HL E5
Save Register Pair HL (FF82H, the GET offset) on the stack.
0B04
LD E,(HL) 5E
Load Register E with the GET offset at Register Pair HL.
0B05
INC HL 23
Increment Register Pair HL to FF83H, the start of the buffer.
0B06
LD D,00H 16 00
Load Register D with 00H, so Register Pair DE is the GET offset.
0B08
ADD HL,DE 19
Add Register Pair DE to Register Pair HL, pointing to the oldest key in the buffer.
0B09
LD B,(HL) 46
Load Register B with the key at Register Pair HL.
0B0A
POP HL E1
Restore Register Pair HL (FF82H, the GET offset) from the stack.
0B0B
INC (HL) 34
Increment the GET offset at Register Pair HL past the key.
0B0C
LD A,50H 3E 50
Load Register A with 50H (80), the highest offset.
0B0E
CP (HL) BE
Compare Register A (80) with the new GET offset at Register Pair HL.
0B0F
If the GET offset is 80 or less, jump to 0B13H and keep it.
0B11
LD (HL),00H 36 00
The offset passed 80: store 00H at Register Pair HL, back to the start of the buffer.
0B13
LD A,(HL) 7E
Load Register A with the GET offset at Register Pair HL.
0B14
DEC HL 2B
Decrement Register Pair HL to FF81H, the PUT offset.
0B15
CP (HL) BE
Compare Register A (the GET offset) with the PUT offset at Register Pair HL.
0B16
If they are now the same (the buffer is empty), call R7KFLG at 0B6AH to reset bit 7 of KFLAG$.
0B19
POP HL E1
Restore Register Pair HL (FF80H, the switch) from the stack.
0B1A
LD (HL),00H 36 00
Store 00H at FF80H (Register Pair HL), letting the type-ahead task run again.
0B1C
LD A,B 78
Copy Register B (the key from the buffer) into Register A.
0B1D
CP A BF
Compare Register A with itself, setting Z for a key returned.
0B1E
RET C9
Return Z with the key from the type-ahead buffer in Register A.
0B1F
The buffer is empty: call KISCAN at 0983H to scan the keyboard directly.
0B22
POP HL E1
Restore Register Pair HL (FF80H, the switch) from the stack.
0B23TYPON
LD (HL),00H 36 00
Store 00H at FF80H (Register Pair HL), letting the type-ahead task run again.
0B25
RET C9
Return with the result in Register A and the flags.

0B26H - TYPTSK$: The Type-Ahead Task

A task run on the clock interrupt while type-ahead is on (bit 1 of DFLAG$). It scans the keyboard and stores each new key in the type-ahead buffer at FF83H, unless the driver is running or the buffer is full. BREAK empties the buffer before it is stored, and CLEAR @ (C0H) empties it. A held key is not repeated into a buffer that already has keys.

0B26-0B27TYPTSK$
DEFW 0B28H 28 0B
TYPTSK$, 0B26H-0B27H = 0B28H, the address of the task's code, the word after it.
0B28
LD A,(006DH) 3A 6D 00LD A,(DFLAG$)
Load Register A with 006DH (DFLAG$), the device flags.
0B2B
AND 02H E6 02
Mask Register A with 02H, the type-ahead switch (SYSTEM (TYPE)).
0B2D
RET Z C8
Return if type-ahead is off (bit 1 of DFLAG$ clear).
0B2E
Call ENADIS_DO_RAM at 0817H to bring the keyboard and video memory into the memory map.
0B31
LD HL,FF80H 21 80 FFLD HL,TYPBUF
Point Register Pair HL to FF80H (TYPBUF), the type-ahead switch.
0B34
LD A,(HL) 7E
Load Register A with the switch at Register Pair HL.
0B35
OR A B7
Test Register A (the type-ahead switch at FF80H) for zero.
0B36
RET NZ C0
Return if the switch is not zero: the keyboard driver is running.
0B37
INC HL 23
Increment Register Pair HL to FF81H, the PUT offset.
0B38
PUSH HL E5
Save Register Pair HL (FF81H, the PUT offset) on the stack.
0B39KIHOOK
Call KISCAN at 0983H to scan the keyboard for a new key.
0B3C
POP HL E1
Restore Register Pair HL (FF81H, the PUT offset) from the stack.
0B3D
RET NZ C0
Return if KISCAN found no key (NZ with Register A = 0).
0B3E
PUSH AF F5
Push Register Pair AF (the key in Register A and its flags) on the stack.
0B3F
POP BC C1
Pop it into Register Pair BC: Register B = the key, Register C = its flags.
0B40
CP 80H FE 80
Compare Register A (the key) with 80H, BREAK.
0B42
PUSH AF F5
Save Register Pair AF (the result of the compare) on the stack.
0B43
PUSH HL E5
Save Register Pair HL (FF81H, the PUT offset) on the stack.
0B44
If the key is BREAK, call 0B66H to empty the type-ahead buffer.
0B47
POP HL E1
Restore Register Pair HL (FF81H, the PUT offset) from the stack.
0B48
POP AF F1
Restore Register Pair AF, the key in Register A.
0B49
CP C0H FE C0
Compare Register A (the key) with C0H, CLEAR @.
0B4B
If it is CLEAR @, jump to 0B66H to empty the buffer and return.
0B4D
LD E,(HL) 5E
Load Register E with the PUT offset at Register Pair HL.
0B4E
LD A,E 7B
Copy Register E (the PUT offset) into Register A.
0B4F
INC HL 23
Increment Register Pair HL to FF82H, the GET offset.
0B50
CP (HL) BE
Compare Register A (the PUT offset) with the GET offset at Register Pair HL.
0B51
If the buffer is empty, jump to 0B74H to store the key.
0B53
LD A,(002CH) 3A 2C 00LD A,(TIMER$)
Keys are waiting: load Register A with 002CH (TIMER$), the clock interrupt counter.
0B56
ADD A,(IX+03H) DD 86 03
Add the repeat rate at Index Register IX+03H (08FFH, Index Register IX still points to KIDATA$) to Register A.
0B59
CP (IX+01H) DD BE 01
Compare Register A with the repeat time at Index Register IX+01H (08FDH): equal when KISCAN has just set it for a repeat.
0B5C
If the key is not a repeat, jump to 0B70H to store it.
0B5E
ADD A,(IX+03H) DD 86 03
A repeat: add the repeat rate at Index Register IX+03H to Register A again.
0B61
LD (IX+01H),A DD 77 01
Store Register A into the repeat time at Index Register IX+01H, putting the next repeat off.
0B64
RET C9
Return without storing the repeated key in the type-ahead buffer.
0B65CLRTYP
INC HL 23
Increment Register Pair HL from FF80H to FF81H, the PUT offset.
0B66
XOR A AF
Clear Register A, the offset of the start of the buffer.
0B67
LD (HL),A 77
Store Register A (00H) into the PUT offset at Register Pair HL (FF81H).
0B68
INC HL 23
Increment Register Pair HL to FF82H, the GET offset.
0B69
LD (HL),A 77
Store Register A (00H) into the GET offset at Register Pair HL.
0B6AR7KFLG
LD HL,0074H 21 74 00LD HL,KFLAG$
Point Register Pair HL to 0074H (KFLAG$), the keyboard flags.
0B6D
RES 7,(HL) CB BE
Reset bit 7 of KFLAG$ at Register Pair HL: the type-ahead buffer is empty.
0B6F
RET C9
Return with the type-ahead buffer empty (or KFLAG$ updated).
0B70
LD A,E 7B
Copy Register E (the PUT offset) into Register A.
0B71
INC A 3C
Increment Register A to the PUT offset after this key.
0B72
CP (HL) BE
Compare Register A with the GET offset at Register Pair HL.
0B73
RET Z C8
Return if they would meet: the buffer is full and the key is dropped.
0B74
PUSH HL E5
Save Register Pair HL (FF82H, the GET offset) on the stack.
0B75
INC HL 23
Increment Register Pair HL to FF83H, the start of the buffer.
0B76
LD D,00H 16 00
Load Register D with 00H, so Register Pair DE is the PUT offset.
0B78
ADD HL,DE 19
Add Register Pair DE to Register Pair HL, pointing to the free position.
0B79
LD (HL),B 70
Store Register B (the key) into the buffer at Register Pair HL.
0B7A
LD HL,0074H 21 74 00LD HL,KFLAG$
Point Register Pair HL to 0074H (KFLAG$), the keyboard flags.
0B7D
SET 7,(HL) CB FE
Set bit 7 of KFLAG$ at Register Pair HL: the type-ahead buffer holds keys.
0B7F
POP HL E1
Restore Register Pair HL (FF82H) from the stack.
0B80
DEC HL 2B
Decrement Register Pair HL to FF81H, the PUT offset.
0B81
INC (HL) 34
Increment the PUT offset at Register Pair HL past the key.
0B82
LD A,50H 3E 50
Load Register A with 50H (80), the highest offset.
0B84
CP (HL) BE
Compare Register A (80) with the new PUT offset at Register Pair HL.
0B85
RET NC D0
Return if the new PUT offset at Register Pair HL is 80 or less.
0B86
LD (HL),D 72
Store Register D (00H) into the PUT offset at Register Pair HL, back to the start of the buffer.
0B87KILAST
RET C9
Return. This is the last byte of the keyboard driver (KILAST is 0B87H in the module header).

0B88H - DODVR: The Video Driver

The driver of the DO device (DODCB$ at 0210H points here), with the standard module header and DODATA$, the driver's data: the mode byte, the cursor address, the character under the cursor and the cursor character. The screen is 80 by 24 characters at F800H-FF7FH, row 0 first, which the driver switches into the memory map with ENADIS_DO_RAM. A GET returns the character at the cursor; a PUT shows a character (20H-BFH), obeys a control code (00H-1FH) or, for C0H-FFH, puts C0H less than that many spaces (tab mode) or shows the code as a special character.

0B88DODVR
Jump over the module header to DOBGN at 0B9CH.
0B8A-0B8B
DEFW 0E00H 00 0E
DODVR+2, 0B8AH-0B8BH = 0E00H (DOEND), the last byte of the video driver.
0B8C-0B8F
DEFB 03H / DEFM "$DO" 03 24 44 4F
DODVR+4, 0B8CH-0B8FH: the name length, 3, and the module name $DO.
0B90-0B91
DEFW 0210H 10 02
DODVR+8, 0B90H-0B91H = 0210H, the address of DODCB$, the DCB this driver serves.
0B92-0B93
DEFW 0000H 00 00
DODVR+10, 0B92H-0B93H: a reserved word of the module header, 0000H.
0B94
DEFB 00H 00
DODATA$ (DO_MASK), 0B94H: the video mode byte, bits 2-0 the number of protected lines at the top of the screen that do not scroll, bit 3 set for special characters (clear for tabs) from C0H-FFH, bit 4 set to show the next control code as a character. 00H in the file.
0B95-0B96CURSOR
DEFW 0F800H 00 F8
CURSOR, 0B95H-0B96H = F800H, the video memory address of the cursor (row 0, column 0 in the file).
0B97CRSAVE
DEFB 20H 20
CRSAVE, 0B97H: the character under the cursor, saved while the cursor character is shown; 00H when the cursor is off. 20H (a space) in the file.
0B98CRSCHAR
DEFB 5FH 5F
CRSCHAR, 0B98H: the cursor character, 5FH (the underscore) in the file; @VDCTL function 8 changes it.
0B99@VDCTL
Jump to @_VDCTL at 0D42H. @VDCTL (SVC 15) is the video control SVC: function in Register B, row in Register H and column in Register L, character in Register C.

0B9CH - DOBGN: Video Request Entry

Entered from IOBGN with the request in the flags (Carry for GET, Z for PUT, neither for CTL) and the character in Register C.

0B9CDOBGN
LD IX,0B94H DD 21 94 0BLD IX,DODATA$
Point Index Register IX to 0B94H (DODATA$), the video driver's data.
0BA0
Call ENADIS_DO_RAM at 0817H to bring the video memory into the memory map until the driver returns.
0BA3
If the request is GET (the Carry flag set), jump to 0DB3H, which returns the character at the cursor.
0BA6
Call 0DB3H to put back the character under the cursor and load Register Pair DE with the cursor address.
0BA9
PUSH BC C5
Save Register Pair BC (the character in Register C) on the stack.
0BAA
LD A,C 79
Copy Register C (the character to show) into Register A.
0BAB
BIT 4,(IX+00H) DD CB 00 66
Test bit 4 of the mode byte at Index Register IX+00H (0B94H), set to show the next control code as a character.
0BAF
If bit 4 is set, jump to 0BBAH and show Register A as a character.
0BB1
OR A B7
Test Register A (the character to show) for zero with OR A.
0BB2
If it is 00H, jump to TGGLCTL at 0C9FH, which flips bit 4 of the mode byte.
0BB5
CP 20H FE 20
Compare Register A (the character) with 20H, the first printable code.
0BB7
If it is a control code (01H-1FH), jump to DO_CONTROL at 0C44H.
0BBA
CP C0H FE C0
Compare Register A (the character) with C0H, the first tab or special code.
0BBC
If Register A is below C0H, jump to DONORM at 0BC4H to show it.
0BBE
BIT 3,(IX+00H) DD CB 00 5E
Codes C0H-FFH: test bit 3 of the mode byte at Index Register IX+00H (0B94H), set for special characters.
0BC2
If bit 3 is clear (tab mode), jump to DO_TABS at 0BEAH.
0BC4DONORM
Call DO_DSPCHAR at 0CB8H to show the character in Register C at the cursor and move the cursor on.
0BC7
RES 4,(IX+00H) DD CB 00 A6
Reset bit 4 of the mode byte at Index Register IX+00H: the show controls mode lasts one character.
0BCBDO_RET
POP BC C1
Restore Register Pair BC (the character in Register C) from the stack.
0BCCDO_RET1
DI F3
Disable interrupts while the cursor is changed, so the blink task does not interfere.
0BCD
LD A,(0B97H) 3A 97 0BLD A,(CRSAVE)
Load Register A with 0B97H (CRSAVE): non zero when the cursor is on.
0BD0
OR A B7
Test Register A (CRSAVE, the character under the cursor) for zero.
0BD1
If the cursor is off (CRSAVE zero), jump to 0BE3H.
0BD3
LD A,(DE) 1A
Load Register A with the character at the new cursor position, Register Pair DE.
0BD4
LD (0B97H),A 32 97 0BLD (CRSAVE),A
Store Register A (the character under the cursor) into 0B97H (CRSAVE).
0BD7
LD A,(007FH) 3A 7F 00LD A,(VFLAG$)
Load Register A with 007FH (VFLAG$), the video flags.
0BDA
RES 7,A CB BF
Reset bit 7 of Register A, allowing the clock task to blink the cursor again.
0BDC
LD (007FH),A 32 7F 00LD (VFLAG$),A
Store Register A (VFLAG$ with bit 7 clear) back into 007FH.
0BDF
LD A,(0B98H) 3A 98 0BLD A,(CRSCHAR)
Load Register A with 0B98H (CRSCHAR), the cursor character.
0BE2
LD (DE),A 12
Store Register A (the cursor character) at the cursor position, Register Pair DE.
0BE3
LD (0B95H),DE ED 53 95 0BLD (CURSOR),DE
Store Register Pair DE (the new cursor address) into 0B95H-0B96H (CURSOR).
0BE7
CP A BF
Compare Register A with itself, setting Z for success.
0BE8
LD A,C 79
Copy Register C (the character of the request) into Register A.
0BE9
RET C9
Return Z with the character of the request in Register A.

0BEAH - DO_TABS: Codes C0H-FFH as Spaces

In tab mode a code C0H+n puts n spaces (0 to 63) at the cursor.

0BEADO_TABS
SUB C0H D6 C0
Subtract C0H from Register A, giving the number of spaces.
0BEC
If it is zero, jump to DO_RET at 0BCBH with nothing to show.
0BEE
LD B,A 47
Copy Register A (the number of spaces) into Register B.
0BEF
LD C,20H 0E 20
Load Register C with 20H, a space, the character DO_DSPCHAR shows.
0BF1
Call DO_DSPCHAR at 0CB8H to show the space in Register C and move the cursor on.
0BF4
Decrement Register B and loop back to 0BEFH until all the spaces are shown.
0BF6
Jump to DO_RET at 0BCBH to show the cursor and return.

0BF8H - Cursor Movement Routines

Routines for the control codes, each working on the cursor address in Register Pair DE. CRSBOL moves it to the start of its line, CRSON and CRSOFF turn the cursor on and off (CRSAVE non zero or zero), CRSHOME homes it, BACKSPA and CRSBKSP move it back, CRSUP and CRSDOWN up and down, and SET40 sets 40 characters a line. In 40 character mode (bit 2 of MODOUT$, 0076H) each character takes two positions.

0BF8CRSBOL
EX DE,HL EB
Exchange Register Pairs DE and HL: Register Pair HL = the cursor address.
0BF9
Call ADDR1 at 0DF4H to turn the address in Register Pair HL into Register H = row and Register L = column; it returns Register A = 0.
0BFC
LD L,A 6F
Copy Register A (00H) into Register L, column 0.
0BFD
Jump to ROWCOL_2_ADDR at 0DD0H to turn row Register H, column 0 into the address in Register Pair DE.
0C00CRSON
LD A,(DE) 1A
Load Register A with the character at the cursor, Register Pair DE.
0C01CRSOFF
LD (0B97H),A 32 97 0BLD (CRSAVE),A
Store Register A into 0B97H (CRSAVE): the character under the cursor turns the cursor on; 00H (from DO_CONTROL) turns it off.
0C04
RET C9
Return to DO_RET at 0BCBH, which shows the cursor if it is on.
0C05CRSHOME
LD DE,F800H 11 00 F8LD DE,CRTBGN$
Load Register Pair DE with F800H, the home position (row 0, column 0).
0C08
LD A,(0076H) 3A 76 00LD A,(MODOUT$)
Load Register A with 0076H (MODOUT$), the copy of the output port ECH.
0C0B
AND FBH E6 FB
Mask Register A with FBH, clearing bit 2: 80 characters a line.
0C0D
Call SETMOD at 0CB2H to store Register A in MODOUT$ and send it to port ECH.
0C10
Jump to DO_INVERT_DIS at 0C8CH to set normal video as well.
0C12BACKSPA
Call CRSBKSP at 0C1BH to move the cursor back one character.
0C15
RET Z C8
Return if the cursor was already at the home position (Z).
0C16
LD C,20H 0E 20
Load Register C with 20H, a space, to erase the character backspaced over.
0C18
Jump to PUT_@ at 0DCAH to put the space at the new cursor position, erasing the character.
0C1BCRSBKSP
LD A,(0076H) 3A 76 00LD A,(MODOUT$)
Load Register A with 0076H (MODOUT$), the copy of port ECH.
0C1E
AND 04H E6 04
Mask Register A with 04H, bit 2, the 40 character mode.
0C20
In 40 character mode, call 0C23H once first, so the cursor moves back two positions.
0C23
LD HL,F800H 21 00 F8LD HL,CRTBGN$
Load Register Pair HL with F800H, the home position.
0C26
SBC HL,DE ED 52
Subtract Register Pair DE (the cursor) from Register Pair HL: zero when the cursor is at home.
0C28
RET Z C8
Return Z if the cursor is at home and cannot move back.
0C29
DEC DE 1B
Decrement Register Pair DE, moving the cursor back one position.
0C2A
RET C9
Return NZ with the cursor in Register Pair DE moved back one position.
0C2BCRSUP
LD HL,FFB0H 21 B0 FFLD HL,NEGLINE
Load Register Pair HL with FFB0H, minus 80, one line up.
0C2E
Jump to MOVCRS at 0C33H to move the cursor by Register Pair HL.
0C30CRSDOWN
LD HL,0050H 21 50 00LD HL,LINESIZ
Load Register Pair HL with 0050H, plus 80, one line down.
0C33MOVCRS
ADD HL,DE 19
Add Register Pair DE (the cursor) to Register Pair HL, the new position.
0C34
LD A,H 7C
Copy Register H (the high byte of the new position) into Register A.
0C35
CP F8H FE F8
Compare Register A with F8H, the high byte of the start of video memory.
0C37
RET C D8
Return if the new position is above the screen (below F800H): the cursor does not move.
0C38
EX DE,HL EB
Exchange Register Pairs DE and HL: Register Pair DE = the new position.
0C39
DEC DE 1B
Decrement Register Pair DE, since CRSFRW0 increments it.
0C3A
Jump to CRSFRW0 at 0CC3H, which scrolls if the new position is below the screen.
0C3DSET40
LD A,(0076H) 3A 76 00LD A,(MODOUT$)
Load Register A with 0076H (MODOUT$), the copy of port ECH.
0C40
OR 04H F6 04
Set bit 2 of Register A with OR 04H, the 40 character a line mode.
0C42
Jump to SETMOD at 0CB2H to store it and send it to port ECH.

0C44H - DO_CONTROL: Video Control Codes

Codes 01H-1FH: 08H backspace and erase, 0AH and 0DH new line (the next line is cleared), 0EH cursor on, 0FH cursor off, 10H reverse video on, 11H off, 15H swap special characters and tabs, 16H swap the alternate character set, 17H 40 characters a line, 18H cursor back, 19H forward, 1AH down, 1BH up, 1CH home (and 80 characters, normal video), 1DH start of line, 1EH clear to the end of the line, 1FH clear to the end of the screen. Other codes are ignored. Each routine returns to DO_RET.

0C44DO_CONTROL
LD HL,0BCBH 21 CB 0BLD HL,DO_RET
Point Register Pair HL to 0BCBH (DO_RET).
0C47
PUSH HL E5
Push Register Pair HL (0BCBH) on the stack as the return address of the control routine.
0C48
CP 08H FE 08
Compare Register A (the control code) with 08H, backspace.
0C4A
If it is backspace, jump to BACKSPA at 0C12H.
0C4C
CP 0AH FE 0A
Compare Register A (the control code) with 0AH, line feed.
0C4E
If it is line feed, jump to 0C52H with Z, treated like ENTER.
0C50
SUB 0DH D6 0D
Subtract 0DH from Register A: zero for 0DH, ENTER; the codes that follow are counted down from here.
0C52
If Z (the code was 0AH or 0DH), jump to LINFEED at 0D02H.
0C55
DEC A 3D
Decrement Register A (the code less 0DH): zero for 0EH, cursor on.
0C56
If it is 0EH, jump to CRSON at 0C00H to turn the cursor on.
0C58
DEC A 3D
Decrement Register A again: zero for 0FH, cursor off.
0C59
If it is 0FH, jump to CRSOFF at 0C01H with Register A = 0 to turn the cursor off.
0C5B
DEC A 3D
Decrement Register A again: zero for 10H, reverse video on.
0C5C
If it is 10H, jump to DO_INVERT_ENA at 0C89H for reverse video.
0C5E
DEC A 3D
Decrement Register A again: zero for 11H, reverse video off.
0C5F
If it is 11H, jump to DO_INVERT_OFF at 0C9BH with Register A = 0, normal characters.
0C61
SUB 04H D6 04
Subtract 04H from Register A: zero for 15H, swap special characters and tabs.
0C63
If it is 15H, jump to TGGLTAB at 0CA6H to flip bit 3 of the mode byte.
0C65
DEC A 3D
Decrement Register A again: zero for 16H, swap the alternate character set.
0C66
If it is 16H, jump to TGGLALT at 0CADH to flip the alternate character set.
0C68
DEC A 3D
Decrement Register A again: zero for 17H, 40 characters a line.
0C69
If it is 17H, jump to SET40 at 0C3DH for 40 characters a line.
0C6B
DEC A 3D
Decrement Register A again: zero for 18H, cursor back.
0C6C
If it is 18H, jump to CRSBKSP at 0C1BH to move the cursor back.
0C6E
DEC A 3D
Decrement Register A again: zero for 19H, cursor forward.
0C6F
If it is 19H, jump to CRSFRWD at 0CBBH to move the cursor forward.
0C71
DEC A 3D
Decrement Register A again: zero for 1AH, cursor down.
0C72
If it is 1AH, jump to CRSDOWN at 0C30H to move the cursor down.
0C74
DEC A 3D
Decrement Register A again: zero for 1BH, cursor up.
0C75
If it is 1BH, jump to CRSUP at 0C2BH to move the cursor up.
0C77
DEC A 3D
Decrement Register A again: zero for 1CH, cursor home.
0C78
If it is 1CH, jump to CRSHOME at 0C05H to home the cursor.
0C7B
DEC A 3D
Decrement Register A again: zero for 1DH, start of the line.
0C7C
If it is 1DH, jump to CRSBOL at 0BF8H, the start of the line.
0C7F
DEC A 3D
Decrement Register A again: zero for 1EH, clear to the end of the line.
0C80
If it is 1EH, jump to CLREOL at 0D12H to clear to the end of the line.
0C83
DEC A 3D
Decrement Register A again: zero for 1FH, clear to the end of the screen.
0C84
If it is 1FH, jump to CLREOF at 0D1EH to clear to the end of the screen.
0C87
XOR A AF
Any other control code is ignored: clear Register A, setting Z.
0C88
RET C9
Return to DO_RET at 0BCBH (pushed at 0C47H) with nothing done.
0C89DO_INVERT_ENA
LD B,08H 06 08
Load Register B with 08H, bit 3 of the Operation Register, the inverse video bit.
0C8B
DEFB 21H 21
A 21H byte. Falling through from 0C89H, the CPU takes it and the next two bytes as LD HL,0006H, so the LD B,00H at 0C8CH is skipped and Register B keeps 08H.
0C8CDO_INVERT_DIS
LD B,00H 06 00
Load Register B with 00H, inverse video off.
0C8E
LD HL,(0835H) 2A 35 08LD HL,(OPREG_SV_PTR)
Load Register Pair HL with 0835H (OPREG_SV_PTR), the save level holding the Operation Register value that DIS_DO_RAM will restore.
0C91
LD A,(HL) 7E
Load Register A with that saved Operation Register value at Register Pair HL.
0C92
AND F7H E6 F7
Mask Register A with F7H, clearing bit 3, the inverse video bit.
0C94
OR B B0
OR Register B (08H to turn inverse video on, 00H to leave it off) into Register A.
0C95
LD (HL),A 77
Store Register A back at Register Pair HL, so the bit takes effect when the video memory is switched out.
0C96
LD A,B 78
Copy Register B (08H or 00H) into Register A.
0C97
RLCA 07
Rotate Register A left; four rotations turn 08H into 80H (and leave 00H).
0C98
RLCA 07
Rotate Register A left (second of the four rotations of the inverse bit).
0C99
RLCA 07
Rotate Register A left (third of the four rotations of the inverse bit).
0C9A
RLCA 07
Rotate Register A left (fourth); Register A = 80H for reverse video, 00H for normal.
0C9BDO_INVERT_OFF
LD (0DCBH),A 32 CB 0DLD (INVIDEO),A
Self-Modifying Code
Store Register A (80H or 00H) into 0DCBH (INVIDEO), the operand of the LD A at 0DCAH: from now on PUT_@ sets bit 7 of each character for reverse video.
0C9E
RET C9
Return to DO_RET at 0BCBH, pushed by DO_CONTROL at 0C47H.
0C9FTGGLCTL
LD HL,0BCBH 21 CB 0BLD HL,DO_RET
Point Register Pair HL to 0BCBH (DO_RET).
0CA2
PUSH HL E5
Push Register Pair HL (0BCBH) on the stack as the return address.
0CA3
LD A,10H 3E 10
Load Register A with 10H, bit 4 of the mode byte, the show controls bit.
0CA5
DEFB 21H 21
A 21H byte. Falling through from 0CA3H, the CPU takes it and the next two bytes as LD HL,083EH, so the LD A,08H at 0CA6H is skipped and Register A keeps 10H.
0CA6TGGLTAB
LD A,08H 3E 08
Load Register A with 08H, bit 3 of the mode byte, special characters or tabs.
0CA8
XOR (IX+00H) DD AE 00
Exclusive OR the mode byte at Index Register IX+00H (0B94H) into Register A, flipping the bit.
0CAB
Jump to SETMASK at 0CFDH to store the new mode byte.
0CADTGGLALT
LD A,(0076H) 3A 76 00LD A,(MODOUT$)
Load Register A with 0076H (MODOUT$), the copy of port ECH.
0CB0
XOR 08H EE 08
Flip bit 3 of Register A, the alternate character set enable of port ECH.
0CB2SETMOD
LD (0076H),A 32 76 00LD (MODOUT$),A
Store Register A into 0076H (MODOUT$), the copy of port ECH.
0CB5
OUT (ECH),A D3 EC
Send Register A to port ECH, the mode output port.
0CB7
RET C9
Return with the new mode in MODOUT$ (0076H) and port ECH.

0CB8H - DO_DSPCHAR and CRSFRWD: Show a Character and Move On

DO_DSPCHAR puts Register C at the cursor and advances it; CRSFRWD only advances it. Past the end of the screen the cursor goes back to the start of the last line and the screen scrolls.

0CB8DO_DSPCHAR
Call PUT_@ at 0DCAH to put Register C (with the reverse video bit) at the cursor, Register Pair DE.
0CBBCRSFRWD
LD A,(0076H) 3A 76 00LD A,(MODOUT$)
Load Register A with 0076H (MODOUT$), the copy of port ECH.
0CBE
AND 04H E6 04
Mask Register A with 04H, bit 2, the 40 character mode.
0CC0
In 80 character mode, jump to CRSFRW0 at 0CC3H.
0CC2
INC DE 13
40 character mode: increment Register Pair DE once more, two positions a character.
0CC3CRSFRW0
INC DE 13
Increment Register Pair DE, the cursor, to the next position.
0CC4
LD HL,FF7FH 21 7F FFLD HL,CRTEND
Load Register Pair HL with FF7FH (CRTEND), the last byte of the screen.
0CC7
SBC HL,DE ED 52
Subtract Register Pair DE (the cursor) from Register Pair HL.
0CC9
RET NC D0
Return if the cursor in Register Pair DE is still on the screen.
0CCA
Past the end: call CRSUP at 0C2BH to move the cursor back up into the last line.
0CCD
PUSH DE D5
Save Register Pair DE (the cursor) on the stack; CLREOF3 restores it.

0CCEH - DO_SCROLL: Scroll the Screen

Moves the unprotected lines up one line and clears the last line. The number of protected lines at the top (0-7) is bits 2-0 of the mode byte.

0CCEDO_SCROLL
LD A,(IX+00H) DD 7E 00
Load Register A with the mode byte at Index Register IX+00H (0B94H).
0CD1
AND 07H E6 07
Mask Register A with 07H, the number of protected lines.
0CD3
LD HL,F800H 21 00 F8LD HL,CRTBGN$
Point Register Pair HL to F800H, the start of the screen.
0CD6
LD DE,0780H 11 80 07LD DE,CRTSIZE
Load Register Pair DE with 0780H (CRTSIZE), the size of the screen, 1920 bytes.
0CD9
PUSH BC C5
Save Register Pair BC (the caller's character) on the stack.
0CDA
LD BC,0050H 01 50 00LD BC,LINESIZ
Load Register Pair BC with 0050H (LINESIZ), 80 bytes a line.
0CDD
INC A 3C
Increment Register A: the protected lines plus the line that is scrolled off.
0CDE
ADD HL,BC 09
Add Register Pair BC (80) to Register Pair HL, one line further down.
0CDF
EX DE,HL EB
Exchange Register Pairs DE and HL to work on the length.
0CE0
OR A B7
Clear the Carry flag (OR Register A) for the subtraction.
0CE1
SBC HL,BC ED 42
Subtract Register Pair BC (80) from Register Pair HL, the length of the move.
0CE3
EX DE,HL EB
Exchange Register Pairs DE and HL back: Register Pair DE = the length, Register Pair HL = the position.
0CE4
DEC A 3D
Decrement Register A, the lines still to step over.
0CE5
Loop back to 0CDEH until Register Pair HL is past the protected lines and one more.
0CE7
PUSH DE D5
Save Register Pair DE (the number of bytes to move) on the stack.
0CE8
PUSH HL E5
Save Register Pair HL (the source, the first line that moves) on the stack.
0CE9
SBC HL,BC ED 42
Subtract Register Pair BC (80) from Register Pair HL: one line up, the destination.
0CEB
EX DE,HL EB
Exchange Register Pairs DE and HL: Register Pair DE = the destination.
0CEC
POP HL E1
Restore Register Pair HL, the source of the move, from the stack.
0CED
POP BC C1
Restore Register Pair BC, the number of bytes to move.
0CEE
LDIR ED B0
Copy Register Pair BC bytes from Register Pair HL to Register Pair DE, moving the unprotected lines up one line.
0CF0
POP BC C1
Restore Register Pair BC (saved at 0CD9H) from the stack.
0CF1
Jump to CLREOF1 at 0D1FH to clear from Register Pair DE (the start of the last line) to the end of the screen.
0CF3SET_SCROLL
LD A,C 79
@VDCTL function 7: copy Register C (the number of lines to protect) into Register A.
0CF4
AND 07H E6 07
Mask Register A with 07H, keeping 0 to 7 lines.
0CF6
LD C,A 4F
Copy Register A (the protected lines) into Register C.
0CF7
LD A,(0B94H) 3A 94 0BLD A,(DODATA$)
Load Register A with 0B94H (DODATA$), the mode byte.
0CFA
AND F8H E6 F8
Mask Register A with F8H, removing the old number of protected lines.
0CFC
OR C B1
OR Register C (the new number) into Register A.
0CFDSETMASK
LD (0B94H),A 32 94 0BLD (DODATA$),A
Store Register A into 0B94H (DODATA$), the mode byte.
0D00
XOR A AF
Clear Register A, setting Z for a successful return.
0D01
RET C9
Return Z with Register A = 0, the mode byte stored.

0D02H - LINFEED, CLREOL and CLREOF: New Line and Clearing

LINFEED moves the cursor to the start of the next line (scrolling at the bottom) and clears that line. CLREOL clears from the cursor to the end of its line, CLREOF from the cursor to the end of the screen. A clear writes spaces with the current reverse video bit.

0D02LINFEED
Call CRSBOL at 0BF8H to move the cursor to the start of its line.
0D05
PUSH DE D5
Save Register Pair DE (the start of the line) on the stack.
0D06
Call CRSDOWN at 0C30H to move the cursor down one line, scrolling at the bottom.
0D09
OR A B7
Clear the Carry flag (OR Register A) for the subtraction.
0D0A
LD HL,FF80H 21 80 FF
Load Register Pair HL with FF80H (CRTEND+1), the first byte past the screen.
0D0D
SBC HL,DE ED 52
Subtract Register Pair DE (the cursor) from Register Pair HL.
0D0F
If the cursor is at FF80H, past the screen, jump to DO_SCROLL at 0CCEH.
0D11
POP HL E1
Discard the saved start of the old line from the stack into Register Pair HL, and fall into CLREOL.
0D12CLREOL
PUSH DE D5
Save Register Pair DE (the cursor) on the stack.
0D13
Call CRSBOL at 0BF8H to load Register Pair DE with the start of the line.
0D16
LD HL,004FH 21 4F 00
Load Register Pair HL with 004FH (79), the offset of the last byte of a line.
0D19
ADD HL,DE 19
Add Register Pair DE (the start of the line) to Register Pair HL, the last byte of the line.
0D1A
POP DE D1
Restore Register Pair DE (the cursor) from the stack.
0D1B
PUSH DE D5
Save Register Pair DE (the cursor) on the stack again for CLREOF3.
0D1C
Jump to CLREOF2 at 0D22H to clear from the cursor to the end of the line.
0D1ECLREOF
PUSH DE D5
Save Register Pair DE (the cursor) on the stack.
0D1FCLREOF1
LD HL,FF7FH 21 7F FFLD HL,CRTEND
Load Register Pair HL with FF7FH (CRTEND), the last byte of the screen.
0D22CLREOF2
LD A,(0DCBH) 3A CB 0DLD A,(INVIDEO)
Load Register A with 0DCBH (INVIDEO), the reverse video bit (80H or 00H).
0D25
SET 5,A CB EF
Set bit 5 of Register A, giving a space (20H, or A0H in reverse video).
0D27
LD (DE),A 12
Store Register A (the space) at Register Pair DE, the first byte to clear.
0D28
OR A B7
Clear the Carry flag (OR Register A) for the subtraction.
0D29
SBC HL,DE ED 52
Subtract Register Pair DE (the first byte) from Register Pair HL (the last byte), the number of bytes still to clear.
0D2B
If no bytes are left to clear, jump to CLREOF3 at 0D36H.
0D2D
PUSH BC C5
Save Register Pair BC (the caller's character) on the stack.
0D2E
LD B,H 44
Copy Register H into Register B: Register Pair BC = the count.
0D2F
LD C,L 4D
Copy Register L into Register C (the low byte of the count).
0D30
LD H,D 62
Copy Register D into Register H: Register Pair HL = the first byte, holding the space.
0D31
LD L,E 6B
Copy Register E into Register L (the low byte of the first byte).
0D32
INC DE 13
Increment Register Pair DE to the second byte.
0D33
LDIR ED B0
Copy Register Pair BC bytes from Register Pair HL to Register Pair DE, spreading the space to the end.
0D35
POP BC C1
Restore Register Pair BC (the caller's character) from the stack.
0D36CLREOF3
POP DE D1
Restore Register Pair DE (the cursor) from the stack.
0D37
RET C9
Return with the cursor address in Register Pair DE unchanged.

0D38H - @VDCTL Functions

@_VDCTL is @VDCTL (SVC 15). Unless bit 6 of NFLAG$ (0077H) says it is called from a task, it puts back the character under the cursor first and shows the cursor again after. Functions in Register B: 1 read the character at row Register H, column Register L into Register A; 2 put Register C there; 3 move the cursor to H,L; 4 return the cursor row and column in Registers H and L; 5 copy 1920 bytes from Register Pair HL to the screen; 6 copy the screen to the buffer at Register Pair HL (which must be at 2400H-F7FFH); 7 set the protected lines to Register C; 8 set the cursor character to Register C and return the old one; 9 copy row Register H to (Register C non zero) or from (Register C zero) the 80 byte buffer at Register Pair DE. Errors return NZ with Register A = 2BH (43, SVC parameter error).

0D38@VDCTL3
Function 3: call ROWCOL_2_ADDR at 0DD0H to turn row Register H, column Register L into the address in Register Pair DE.
0D3B
RET NZ C0
Return NZ if the row or column is out of range.
0D3C
DI F3
Disable interrupts so the blink task does not use the cursor while it is changed.
0D3D
LD (0B95H),DE ED 53 95 0BLD (CURSOR),DE
Store Register Pair DE (the new address) into 0B95H-0B96H (CURSOR).
0D41
RET C9
Return Z with the cursor address in 0B95H moved.
0D42@_VDCTL
Call ENADIS_DO_RAM at 0817H to bring the video memory into the memory map.
0D45
LD A,(0077H) 3A 77 00LD A,(NFLAG$)
Load Register A with 0077H (NFLAG$), the system's N flags.
0D48
BIT 6,A CB 77
Test bit 6 of Register A, set while a task process calls @VDCTL.
0D4A
If called from a task, jump to VDCTL at 0D61H without the cursor handling.
0D4C
PUSH DE D5
Save Register Pair DE (the caller's buffer for function 9) on the stack.
0D4D
Call 0DB3H to put back the character under the cursor.
0D50
POP DE D1
Restore Register Pair DE (the caller's value) from the stack.
0D51
PUSH DE D5
Save Register Pair DE on the stack again, to be restored at the end.
0D52
Call VDCTL at 0D61H to carry out the function in Register B.
0D55
PUSH AF F5
Save Register Pair AF (the result and its status) on the stack.
0D56
DI F3
Disable interrupts while the cursor is shown again.
0D57
LD DE,(0B95H) ED 5B 95 0BLD DE,(CURSOR)
Load Register Pair DE with 0B95H (CURSOR), the cursor address.
0D5B
Call DO_RET1 at 0BCCH to show the cursor character at the cursor again.
0D5E
POP AF F1
Restore Register Pair AF, the result of the function.
0D5F
POP DE D1
Restore Register Pair DE (the caller's value) from the stack.
0D60
RET C9
Return with the result in Register A and the flags.
0D61VDCTL
LD A,09H 3E 09
Load Register A with 09H for the test of function 9.
0D63
CP B B8
Compare Register A (9) with Register B (the function).
0D64
If it is function 9, jump to VIDLIN at 0D8BH.
0D66
LD A,2BH 3E 2B
Load Register A with 2BH (43), the SVC parameter error, for a bad function.
0D68
DEC B 05
Decrement Register B (the function number): zero for function 1.
0D69
If it is function 1, jump to GET_@_ROWCOL at 0DAEH.
0D6B
DEC B 05
Decrement Register B (the function number): zero for function 2.
0D6C
If it is function 2, jump to PUT_@_ROWCOL at 0DC6H.
0D6E
DEC B 05
Decrement Register B (the function number): zero for function 3.
0D6F
If it is function 3, jump to @VDCTL3 at 0D38H.
0D71
DEC B 05
Decrement Register B (the function number): zero for function 4.
0D72
If it is function 4, jump to ADDR_2_ROWCOL at 0DF1H.
0D74
LD DE,F800H 11 00 F8LD DE,CRTBGN$
Load Register Pair DE with F800H, the start of the screen, for functions 5 and 6.
0D77
DEC B 05
Decrement Register B (the function number): zero for function 5.
0D78
If it is function 5, jump to VIDMOV1 at 0DA7H (the caller's buffer at Register Pair HL to the screen).
0D7A
DEC B 05
Decrement Register B (the function number): zero for function 6.
0D7B
If it is function 6, jump to VIDMOVE at 0D9FH (the screen to the caller's buffer).
0D7D
DEC B 05
Decrement Register B (the function number): zero for function 7.
0D7E
If it is function 7, jump to SET_SCROLL at 0CF3H.
0D81
DEC B 05
Decrement Register B (the function number): zero for function 8.
0D82
RET NZ C0
Return NZ with Register A = 2BH for a function other than 1 to 9.
0D83
PUSH HL E5
Function 8: save Register Pair HL on the stack.
0D84
LD HL,0B98H 21 98 0BLD HL,CRSCHAR
Point Register Pair HL to 0B98H (CRSCHAR), the cursor character.
0D87
LD A,(HL) 7E
Load Register A with the old cursor character at Register Pair HL.
0D88
LD (HL),C 71
Store Register C (the new cursor character) at Register Pair HL.
0D89
POP HL E1
Restore Register Pair HL (the caller's value) from the stack.
0D8A
RET C9
Return Z with the old cursor character in Register A.
0D8BVIDLIN
LD L,00H 2E 00
Function 9: load Register L with 00H, column 0 of row Register H.
0D8D
PUSH DE D5
Save Register Pair DE (the caller's buffer) on the stack.
0D8E
Call ROWCOL_2_ADDR at 0DD0H to load Register Pair DE with the address of the start of row Register H.
0D91
POP HL E1
Restore the caller's buffer into Register Pair HL.
0D92
RET NZ C0
Return NZ (Register A = 2BH) if the row is out of range.
0D93
INC C 0C
Increment Register C, then decrement it, to test it for zero.
0D94
DEC C 0D
Decrement Register C back: Z when Register C is zero.
0D95
If Register C is zero, jump to MOVLIN at 0D98H: the buffer at Register Pair HL goes to the screen at Register Pair DE.
0D97
EX DE,HL EB
Register C not zero: exchange Register Pairs DE and HL, so the screen line goes to the buffer.
0D98MOVLIN
LD BC,0050H 01 50 00LD BC,LINESIZ
Load Register Pair BC with 0050H (LINESIZ), 80 bytes.
0D9B
LDIR ED B0
Copy Register Pair BC bytes from Register Pair HL to Register Pair DE, one line.
0D9D
XOR A AF
Clear Register A, setting Z for a successful return.
0D9E
RET C9
Return Z with Register A = 0 after the line is copied.
0D9FVIDMOVE
LD A,H 7C
Function 6: copy Register H (the high byte of the caller's buffer) into Register A.
0DA0
ADD A,08H C6 08
Add 08H to Register A: buffers at 2400H-F7FFH give 2CH-FFH, others below 2CH.
0DA2
CP 2CH FE 2C
Compare Register A (the buffer's high byte plus 8) with 2CH.
0DA4
If the buffer is below 2400H or at F800H or above, jump to PERR at 0DEDH.
0DA6
EX DE,HL EB
Exchange Register Pairs DE and HL: Register Pair HL = F800H (the screen), Register Pair DE = the buffer.
0DA7VIDMOV1
LD BC,0780H 01 80 07LD BC,CRTSIZE
Load Register Pair BC with 0780H (CRTSIZE), 1920 bytes.
0DAA
LDIR ED B0
Copy Register Pair BC bytes from Register Pair HL to Register Pair DE: the whole screen.
0DAC
CP A BF
Compare Register A with itself, setting Z for success.
0DAD
RET C9
Return Z with the 1920 bytes of the screen copied.
0DAEGET_@_ROWCOL
Function 1: call ROWCOL_2_ADDR at 0DD0H to load Register Pair DE with the address of row Register H, column Register L.
0DB1
LD A,(DE) 1A
Load Register A with the character at Register Pair DE.
0DB2
RET C9
Return with the character (Z), or NZ for a bad position (Register A then holds a byte from the caller's Register Pair DE address).

0DB3H - Put Back the Character Under the Cursor

Used by the driver entry, by @_VDCTL and for a GET. It stops the cursor blink (VFLAG$ bit 7), loads Register Pair DE with the cursor address, puts back the character under the cursor if the cursor is on, and returns Z with that character in Register A.

0DB3
PUSH HL E5
Save Register Pair HL (the caller's value) on the stack.
0DB4
LD HL,007FH 21 7F 00LD HL,VFLAG$
Point Register Pair HL to 007FH (VFLAG$), the video flags.
0DB7
SET 7,(HL) CB FE
Set bit 7 of VFLAG$ at Register Pair HL, stopping the cursor blink while the driver works.
0DB9
POP HL E1
Restore Register Pair HL (the caller's value) from the stack.
0DBA
LD DE,(0B95H) ED 5B 95 0BLD DE,(CURSOR)
Load Register Pair DE with 0B95H (CURSOR), the cursor address.
0DBE
LD A,(0B97H) 3A 97 0BLD A,(CRSAVE)
Load Register A with 0B97H (CRSAVE), the character under the cursor.
0DC1
OR A B7
Test Register A (CRSAVE) for zero: zero when the cursor is off.
0DC2
If the cursor is on, jump to PUTA@DE at 0DCDH to put the character back on the screen.
0DC4
LD A,(DE) 1A
The cursor is off: load Register A with the character at the cursor, Register Pair DE.
0DC5
RET C9
Return Z with the character at the cursor in Register A.
0DC6PUT_@_ROWCOL
Function 2: call ROWCOL_2_ADDR at 0DD0H to load Register Pair DE with the address of row Register H, column Register L.
0DC9
RET NZ C0
Return NZ (Register A = 2BH) if the position is out of range.
0DCAPUT_@
LD A,00H 3E 00
Self-Modifying Code
Load Register A with the reverse video bit, the operand at 0DCBH (INVIDEO): 00H in the file, 80H after control code 10H.
0DCC
OR C B1
OR Register C (the character) into Register A.
0DCDPUTA@DE
LD (DE),A 12
Store Register A (the character) at the video address in Register Pair DE.
0DCE
CP A BF
Compare Register A with itself, setting Z for success.
0DCF
RET C9
Return Z with the character stored in Register A.

0DD0H - ROWCOL_2_ADDR, PERR and ADDR_2_ROWCOL

ROWCOL_2_ADDR turns row Register H (0-23) and column Register L (0-79) into the video address F800H + 80 times the row + the column in Register Pair DE. PERR returns the SVC parameter error, NZ with Register A = 2BH; @BANK uses it too. ADDR_2_ROWCOL (@VDCTL function 4) turns the cursor address back into Register H = row and Register L = column; ADDR1 does it for the address in Register Pair HL.

0DD0ROWCOL_2_ADDR
LD A,4FH 3E 4F
Load Register A with 4FH (79), the last column.
0DD2
CP L BD
Compare Register A (79) with Register L (the column).
0DD3
If the column is above 79, jump to PERR at 0DEDH.
0DD5
LD A,H 7C
Copy Register H (the row number) into Register A for the test.
0DD6
CP 18H FE 18
Compare Register A (the row) with 18H (24), the number of rows.
0DD8
If the row is 24 or more, jump to PERR at 0DEDH.
0DDA
PUSH HL E5
Save Register Pair HL (the row and column) on the stack.
0DDB
PUSH BC C5
Save Register Pair BC (the caller's value) on the stack.
0DDC
LD C,L 4D
Copy Register L (the column) into Register C.
0DDD
LD B,F8H 06 F8
Load Register B with F8H: Register Pair BC = F800H plus the column.
0DDF
LD HL,0050H 21 50 00LD HL,LINESIZ
Load Register Pair HL with 0050H (LINESIZ), 80.
0DE2
Call @MUL16 at 06C9H to multiply Register Pair HL (80) by Register A (the row); the product is in Registers H, L and A.
0DE5
LD H,L 65
Copy Register L (the middle byte of the product) into Register H.
0DE6
LD L,A 6F
Copy Register A (the low byte of the product) into Register L: Register Pair HL = 80 times the row.
0DE7
ADD HL,BC 09
Add Register Pair BC (F800H plus the column) to Register Pair HL, the video address.
0DE8
EX DE,HL EB
Exchange Register Pairs DE and HL: Register Pair DE = the video address.
0DE9
POP BC C1
Restore Register Pair BC (the caller's value) from the stack.
0DEA
POP HL E1
Restore Register Pair HL (the row and column) from the stack.
0DEB
XOR A AF
Clear Register A, setting Z for a successful return.
0DEC
RET C9
Return Z with the address in Register Pair DE.
0DEDPERR
LD A,2BH 3E 2B
Load Register A with 2BH (43), the SVC parameter error code.
0DEF
OR A B7
Test Register A (2BH) with OR A, giving NZ for the error.
0DF0
RET C9
Return NZ with Register A = 2BH, the SVC parameter error.
0DF1ADDR_2_ROWCOL
LD HL,(0B95H) 2A 95 0BLD HL,(CURSOR)
Load Register Pair HL with 0B95H (CURSOR), the cursor address.
0DF4ADDR1
LD A,H 7C
Copy Register H (the high byte of the video address, F8H-FFH) into Register A.
0DF5
AND 07H E6 07
Mask Register A with 07H, the offset from F800H.
0DF7
LD H,A 67
Copy Register A into Register H: Register Pair HL = the offset into the screen.
0DF8
LD A,50H 3E 50
Load Register A with 50H (80), the line length.
0DFA
Call @DIV16 at 06E3H to divide Register Pair HL by 80: Register Pair HL = the row, Register A = the column.
0DFD
LD H,L 65
Copy Register L (the quotient, the row) into Register H.
0DFE
LD L,A 6F
Copy Register A (the column) into Register L.
0DFF
XOR A AF
Clear Register A, setting Z for a successful return.
0E00DOEND
RET C9
Return Z with Register H = row and Register L = column. This is the last byte of the video driver (DOEND, 0E00H, in the module header).

0E01H - PRDVR: The Printer Driver

The driver of the PR device (PRDCB$ at 0218H points here), for the parallel printer at port F8H, with the standard module header. A PUT waits for the printer to be ready and sends Register C; a CTL 0 returns the printer status; a GET, or any other CTL, returns NZ with Register A = 0. The status read at port F8H has bit 7 BUSY, bit 6 paper out, bit 5 selected and bit 4 no fault; 30H in the top four bits means ready.

0E01PRDVR
Jump over the module header to PRBGN at 0E0DH.
0E03-0E04
DEFW 0E3CH 3C 0E
PRDVR+2, 0E03H-0E04H = 0E3CH (PREND), the last byte of the printer driver.
0E05-0E08
DEFB 03H / DEFM "$PR" 03 24 50 52
PRDVR+4, 0E05H-0E08H: the name length, 3, and the module name $PR.
0E09-0E0A
DEFW 0218H 18 02
PRDVR+8, 0E09H-0E0AH = 0218H, the address of PRDCB$, the DCB this driver serves.
0E0B-0E0C
DEFW 0000H 00 00
PRDVR+10, 0E0BH-0E0CH: a reserved word of the module header, 0000H.
0E0DPRBGN
If the request is PUT (Z from IOBGN), jump to 0E19H to print the character.
0E0F
If the request is GET (the Carry flag set), jump to 0E15H: the printer has no input.
0E11
LD A,C 79
CTL: copy Register C (the control code) into Register A.
0E12
OR A B7
Test Register A (the control code) for zero with OR A.
0E13
If it is CTL 0, jump to 0E36H to return the printer status.
0E15
OR FFH F6 FF
Set every bit of Register A with OR FFH, giving NZ.
0E17
CPL 2F
Complement Register A to 00H (CPL leaves the NZ flag): no character.
0E18
RET C9
Return NZ with Register A = 0: no character is available from the printer.
0E19
LD DE,FFFFH 11 FF FF
PUT: load Register Pair DE with FFFFH, the number of times the status is tested before the time-out.
0E1C
Call 0E36H to read the printer status; Z when the printer is ready.
0E1F
If the printer is ready, jump to 0E32H to send the character.
0E21
PUSH BC C5
Not ready: save Register Pair BC (the character in Register C) on the stack.
0E22
LD BC,0008H 01 08 00
Load Register Pair BC with 0008H, a short delay count for @PAUSE.
0E25
Call 0382H (@PAUSE) to wait the count in Register Pair BC.
0E28
POP BC C1
Restore Register Pair BC (the character in Register C) from the stack.
0E29@PRTIMO
DEC DE 1B
Decrement Register Pair DE, the tests left. The SYSTEM command patches this address for its PRTIME option; with PRTIME=OFF the update sheet says the driver waits for the printer without a time-out.
0E2A
LD A,D 7A
Copy Register D (the high byte of the count) into Register A.
0E2B
OR E B3
OR Register E (the low byte of the count) into Register A, testing Register Pair DE for zero.
0E2C
If tests are left (Register Pair DE not zero), loop back to 0E1CH.
0E2E
LD A,08H 3E 08
Time-out: load Register A with 08H, the error code Device not available.
0E30
OR A B7
Test Register A (08H) with OR A, giving NZ for the error return.
0E31
RET C9
Return NZ with Register A = 08H, Device not available.
0E32
LD A,C 79
Copy Register C (the character to print) into Register A.
0E33PVAL3
OUT (F8H),A D3 F8
Send Register A (the character) to port F8H, the printer data port.
0E35
RET C9
Return Z (from the status compare) with the character sent.
0E36
IN A,(F8H) DB F8
Read the printer status from port F8H into Register A.
0E38
AND F0H E6 F0
Mask Register A with F0H, keeping the four status bits 7-4.
0E3A
CP 30H FE 30
Compare Register A with 30H: Z when the printer is not busy, has paper, is selected and has no fault.
0E3CPREND
RET C9
Return with the status in Register A and Z when the printer is ready. This is the last byte of the printer driver (PREND).

0E3DH - FDCDVR: The Floppy Disk Driver

The driver of the floppy drives, reached through the drive code table (DCT$ at 0470H) with Index Register IY = the drive's DCT entry and the function code in Register B: 0 DCSTAT, 1 SELECT, 2 DCINIT, 3 DCRES, 4 RSTOR, 5 STEPI, 6 SEEK, 7 TSTBSY, 8 RDHDR, 9 RDSEC, 10 VRSEC, 11 RDTRK, 12 HDFMT, 13 WRSEC, 14 WRSYS, 15 WRTRK. Register D is the cylinder, Register E the sector and Register Pair HL the buffer. The WD1793 is at ports F0H (command and status), F1H (track), F2H (sector) and F3H (data); port F4H selects the drive (bits 3-0), the side (bit 4), write precompensation (bit 5), the wait state generator (bit 6) and double density (bit 7). Errors return NZ with the DOS error code in Register A: 4-7 for a read, 12-15 for a write (lost data is retried until it clears, so 3 and 11 never come back).

0E3DFDCDVR
Jump over the module header to FDCBGN at 0E8EH.
0E3F-0E40
DEFW 0FF3H F3 0F
FDCDVR+2, 0E3FH-0E40H = 0FF3H (FDCEND), the last byte of the floppy driver.
0E41-0E44
DEFB 03H / DEFM "$FD" 03 24 46 44
FDCDVR+4, 0E41H-0E44H: the name length, 3, and the module name $FD.

0E45H - SWDEN: Switch the Density on Record Not Found

Called by the retry loop when a sector was not found. With 3 tries left it restores the drive instead; otherwise it flips the density bit of DCT+3 and sets DCT+7 and DCT+8 for that density (10 sectors in 2 granules of 5 single density, 18 sectors in 3 granules of 6 double density), so a diskette of the other density can be read.

0E45SWDEN
LD A,03H 3E 03
Load Register A with 03H, the retry count at which a restore is done.
0E47
CP B B8
Compare Register A (3) with Register B, the retries left.
0E48
If 3 retries are left, jump to RESTOR at 0EA8H to restore the drive to cylinder 0.
0E4A
LD A,(IY+03H) FD 7E 03
Load Register A with the flags at DCT+3, Index Register IY+03H.
0E4D
XOR 40H EE 40
Flip bit 6 of Register A, the double density bit.
0E4F
LD (IY+03H),A FD 77 03
Store Register A (the flags with the density flipped) back at Index Register IY+03H.
0E52
LD BC,2409H 01 09 24
Load Register Pair BC with 2409H, the single density layout: Register C = 09H (highest sector 9) and Register B = 24H (2 granules of 5 sectors).
0E55
BIT 6,A CB 77
Test bit 6 of Register A (the new DCT+3 flags), the new density.
0E57
If the drive is now single density, jump to SDEN at 0E5CH with Register Pair BC = 2409H.
0E59
LD BC,4511H 01 11 45
Double density: load Register Pair BC with 4511H, Register C = 11H (highest sector 17) and Register B = 45H (3 granules of 6 sectors).
0E5CSDEN
LD (IY+07H),C FD 71 07
Store Register C (the highest sector) into DCT+7 at Index Register IY+07H.
0E5F
LD (IY+08H),B FD 70 08
Store Register B (the granule layout) into DCT+8 at Index Register IY+08H.
0E62
RET C9
Return to the retry loop with the new density set.

0E63H - VERFIN and RDIN: Read or Verify a Sector

Send the read sector command through RWINIT and take the 256 data bytes with INI under the wait state generator. A verify (VERFIN) reads them all into the one byte BUCKET at 0FE8H, by making the instruction at 0E7DH a DEC L; a read (RDIN) makes it a NOP and stores them at Register Pair HL. Both end in TSTBSY, which waits for the controller to finish.

0E63VERFIN
LD HL,0FE8H 21 E8 0FLD HL,BUCKET
Point Register Pair HL to 0FE8H (BUCKET), the one byte that receives every byte of a verify.
0E66
LD A,2DH 3E 2D
Load Register A with 2DH, the opcode of DEC L, for the instruction at 0E7DH.
0E68
DEFB 1EH 1E
A 1EH byte. Falling through from 0E66H, the CPU takes it and the next byte as LD E,0AFH, so the XOR A at 0E69H is skipped and Register A keeps 2DH.
0E69RDIN
XOR A AF
Clear Register A, the opcode of NOP, for the instruction at 0E7DH.
0E6A
LD (0E7DH),A 32 7D 0ELD (CKVER),A
Self-Modifying Code
Store Register A (2DH, DEC L, for a verify, or 00H, NOP, for a read) into 0E7DH (CKVER).
0E6D
Call RWINIT at 0F2BH to set up the drive select byte in Register D, Register C = F3H (the data port) and send the command in Register C to the controller.
0E70
LD E,16H 1E 16
Load Register E with 16H, the status mask of record not found (bit 4), lost data (bit 2) and data request (bit 1).
0E72RDIN1
IN A,(F0H) DB F0
Read the FDC status from port F0H into Register A.
0E74
AND E A3
AND Register E (16H) into Register A, the status bits to wait for.
0E75
Loop back to 0E72H until the controller has a data byte ready, or reports an error.
0E77
INI ED A2
Input the first data byte from the port in Register C (F3H) to the memory at Register Pair HL, increment Register Pair HL and decrement Register B (from 00H to FFH).
0E79
DI F3
Disable interrupts for the rest of the transfer.
0E7A
LD A,D 7A
Copy Register D (the drive select byte with the wait state bit 6) into Register A.
0E7BRDIN2
OUT (F4H),A D3 F4
Send Register A to port F4H, keeping the drive selected with the wait state generator on, so the next INI waits for its byte.
0E7DCKVER
NOP 00
Self-Modifying Code
No operation for a read. For a verify 0E6AH stores DEC L here, which takes back the INC HL of the INI so every byte goes to the bucket at 0FE8H.
0E7E
INI ED A2
Input the next data byte from the port in Register C (F3H) to the memory at Register Pair HL, increment Register Pair HL and decrement Register B.
0E80
Loop back to 0E7BH until Register B reaches zero (256 bytes), then fall into TSTBSY.
0E82TSTBSY
IN A,(F0H) DB F0
Read the FDC status from port F0H into Register A.
0E84
BIT 0,A CB 47
Test bit 0 of Register A, the controller's Busy bit.
0E86
RET Z C8
Return Z with the status in Register A when the controller is not busy.
0E87
LD A,(001BH) 3A 1B 00LD A,(PDRV$)
Load Register A with 001BH (PDRV$), the drive select byte last sent to port F4H.
0E8A
OUT (F4H),A D3 F4
Send Register A to port F4H again, keeping the drive selected and its motor on.
0E8C
Jump back to TSTBSY at 0E82H until the controller is idle.

0E8EH - FDCBGN: Floppy Driver Entry

Dispatches on the function code in Register B: 0 returns Z (the drive is assigned), 7 waits until not busy, 8-15 go to IORQST, 6 seeks, 1 selects the drive, 5 steps in one cylinder, and 2, 3 and 4 restore the drive to cylinder 0.

0E8EFDCBGN
LD A,B 78
Copy Register B (the function code) into Register A.
0E8F
AND A A7
Test Register A (the function code) for zero with AND A.
0E90
RET Z C8
Return Z for function 0 (DCSTAT): the drive is assigned to this driver.
0E91
CP 07H FE 07
Compare Register A (the function) with 07H, TSTBSY.
0E93
If it is function 7, jump to TSTBSY at 0E82H.
0E95
If the function is 8 or above (an I/O request), jump to IORQST at 0F44H.
0E98
CP 06H FE 06
Compare Register A (the function) with 06H, SEEK.
0E9A
If it is function 6, jump to SEEKTRK at 0EE8H.
0E9C
DEC A 3D
Decrement Register A: zero for function 1, SELECT.
0E9D
If it is function 1, jump to SELECT at 0EB0H.
0E9F
INC (IY+05H) FD 34 05
Functions 2 to 5: increment the current cylinder at DCT+5, Index Register IY+05H, as a step in does.
0EA2
CP 04H FE 04
Compare Register A (the function less one) with 04H: Z for function 5, STEPI.
0EA4
LD B,58H 06 58
Load Register B with 58H, the FDC Step In command with update (LD leaves the flags).
0EA6
If it is function 5, jump to STEPIN at 0F1AH to send the Step In command.
0EA8RESTOR
LD (IY+05H),00H FD 36 05 00
Functions 2, 3 and 4 (and SWDEN): store 00H into the current cylinder at DCT+5, Index Register IY+05H.
0EAC
LD B,08H 06 08
Load Register B with 08H, the FDC Restore command (head loaded).
0EAE
Jump to STEPIN at 0F1AH to select the drive and send the command.

0EB0H - SELECT: Select the Drive

Waits until the controller is idle, then sends the drive select byte to port F4H: the drive's select bit from DCT+4, double density and the side from DCT+3, and write precompensation for double density cylinders beyond the directory cylinder. The byte is kept in PDRV$ (001BH). If the drive was not ready it waits for it to come up to speed, 0.5 or 1 second by bit 2 of DCT+3.

0EB0SELECT
Call TSTBSY at 0E82H to wait until the controller is idle; it returns the status in Register A.
0EB3
RLCA 07
Rotate Register A left: bit 7 of the status, Not Ready, goes into the Carry flag.
0EB4
LD A,(IY+03H) FD 7E 03
Load Register A with the flags at DCT+3, Index Register IY+03H (density, side, select delay).
0EB7
PUSH AF F5
Save Register Pair AF (the flags and the Not Ready bit in the Carry flag) on the stack.
0EB8
PUSH BC C5
Save Register Pair BC (the caller's command in Register B) on the stack.
0EB9
RLA 17
Rotate Register A left through the Carry flag: bit 6 (double density) moves to bit 7 and bit 4 (side) to bit 5.
0EBA
SRA A CB 2F
Shift Register A right, keeping bit 7: the double density bit stays in bit 7 and the side bit moves to bit 4.
0EBC
AND 90H E6 90
Mask Register A with 90H, keeping bit 7 (double density for port F4H) and bit 4 (side select).
0EBE
LD C,A 4F
Copy Register A (the density and side bits) into Register C.
0EBF
BIT 7,A CB 7F
Test bit 7 of Register A (the port F4H bits), double density.
0EC1
If single density, jump to NOPCMP at 0ECBH: no precompensation.
0EC3
LD A,(IY+09H) FD 7E 09
Load Register A with the directory cylinder at DCT+9, Index Register IY+09H.
0EC6
CP D BA
Compare Register A (the directory cylinder) with Register D (the cylinder wanted).
0EC7
If the cylinder wanted is not beyond the directory cylinder, jump to NOPCMP at 0ECBH.
0EC9
SET 5,C CB E9
Set bit 5 of Register C, write precompensation, for the inner cylinders.
0ECBNOPCMP
LD A,(IY+04H) FD 7E 04
Load Register A with DCT+4 at Index Register IY+04H, holding the drive select bit.
0ECE
AND 0FH E6 0F
Mask Register A with 0FH, keeping the drive select bits 3-0.
0ED0
OR C B1
OR Register C (density, side and precompensation) into Register A, the select byte.
0ED1
POP BC C1
Restore Register Pair BC (the caller's command) from the stack.
0ED2
OUT (F4H),A D3 F4
Send Register A (the select byte) to port F4H, selecting the drive.
0ED4
LD (001BH),A 32 1B 00LD (PDRV$),A
Store Register A (the select byte) into 001BH (PDRV$), for TSTBSY and RWINIT.
0ED7
OUT (F4H),A D3 F4
Send Register A to port F4H a second time, to be sure the drive is selected.
0ED9
POP AF F1
Restore Register Pair AF: Register A = the DCT+3 flags and the Carry flag the Not Ready bit.
0EDA
RET NC D0
Return if the drive was ready (the Carry flag clear).
0EDB
BIT 2,A CB 57
Test bit 2 of Register A (DCT+3), the select delay: 1 for 0.5 second, 0 for 1 second.
0EDD
For a 1 second delay, call FDCDLY at 0EE0H once more, then fall into it.
0EE0FDCDLY
PUSH BC C5
Save Register Pair BC (the caller's command) on the stack.
0EE1
LD B,7FH 06 7F
Load Register B with 7FH, making Register Pair BC a long @PAUSE count (7FH in its high byte).
0EE3
Call 0382H (@PAUSE) to wait the count in Register Pair BC.
0EE6
POP BC C1
Restore Register Pair BC (the caller's command) from the stack.
0EE7
RET C9
Return with the drive selected and up to speed.

0EE8H - SEEKTRK: Seek the Cylinder and Set the Sector

Sets the track register from DCT+5, works out the side from the sector number (a sector above the highest of one side is on side 1 of a two sided diskette), loads the sector and data registers and sends a Seek, with verify when the head has to move.

0EE8SEEKTRK
Call TSTBSY at 0E82H to wait until the controller is idle.
0EEB
LD A,(IY+05H) FD 7E 05
Load Register A with the current cylinder at DCT+5, Index Register IY+05H.
0EEE
OUT (F1H),A D3 F1
Send Register A (the current cylinder) to port F1H, the FDC track register.
0EF0
LD A,(IY+07H) FD 7E 07
Load Register A with DCT+7 at Index Register IY+07H.
0EF3
AND 1FH E6 1F
Mask Register A with 1FH, the highest sector number of a side.
0EF5
SUB E 93
Subtract Register E (the sector wanted) from Register A: a borrow means the sector is on side 1.
0EF6
CPL 2F
Complement Register A, giving the sector wanted less the sectors of one side, the sector number on side 1 (CPL leaves the Carry flag).
0EF7
RES 4,(IY+03H) FD CB 03 A6
Reset bit 4 of DCT+3 at Index Register IY+03H, selecting side 0 for now.
0EFB
If the sector is on side 0, jump to SETSECT at 0F08H.
0EFD
BIT 5,(IY+04H) FD CB 04 6E
Test bit 5 of DCT+4 at Index Register IY+04H, the two sided diskette bit.
0F01
If the diskette is one sided, jump to FRCSID0 at 0F09H and stay on side 0.
0F03
SET 4,(IY+03H) FD CB 03 E6
Set bit 4 of DCT+3 at Index Register IY+03H, selecting side 1.
0F07
DEFB 06H 06
A 06H byte. Falling through from 0F03H, the CPU takes it and the next byte as LD B,7BH, so the LD A,E at 0F08H is skipped and Register A keeps the side 1 sector number.
0F08SETSECT
LD A,E 7B
Copy Register E (the sector wanted) into Register A.
0F09FRCSID0
OUT (F2H),A D3 F2
Send Register A (the sector number) to port F2H, the FDC sector register.
0F0B
LD A,D 7A
Copy Register D (the cylinder wanted) into Register A.
0F0C
OUT (F3H),A D3 F3
Send Register A (the cylinder wanted) to port F3H, the FDC data register, the target of the Seek.
0F0E
CP (IY+05H) FD BE 05
Compare Register A (the cylinder wanted) with the current cylinder at DCT+5, Index Register IY+05H.
0F11
LD B,18H 06 18
Load Register B with 18H, the Seek command without verify (LD leaves the flags).
0F13
If the head is already on the cylinder, jump to STEPIN at 0F1AH to send the plain Seek.
0F15
LD (IY+05H),D FD 72 05
Store Register D (the cylinder wanted) into the current cylinder at DCT+5, Index Register IY+05H.
0F18
LD B,1CH 06 1C
Load Register B with 1CH, the Seek command with verify, and fall into STEPIN.
0F1ASTEPIN
Call SELECT at 0EB0H to select the drive (Register B is kept).
0F1D
LD A,(IY+03H) FD 7E 03
Load Register A with the flags at DCT+3, Index Register IY+03H.
0F20
AND 03H E6 03
Mask Register A with 03H, keeping the step rate bits.
0F22
OR B B0
OR Register B (the command) into Register A, adding the step rate to it.
0F23PASSCMD
OUT (F0H),A D3 F0
Send Register A to port F0H, the FDC command register.
0F25
LD B,12H 06 12
Load Register B with 12H, the length of the delay that lets the controller start.
0F27
Decrement Register B and loop on this instruction at 0F27H until it reaches zero.
0F29
XOR A AF
Clear Register A, setting Z for a successful return.
0F2AFDCRET
RET C9
Return Z (Register A = 0). The drive code table entries of drives 4 to 7 point here.

0F2BH - RWINIT: Start a Read or Write

Loads the track register with the cylinder in Register D, makes Register D the select byte with the wait state generator bit, adds the side compare value to the command in Register C, calls the FDDINT$ hook at 000EH (a RET during the boot load) and sends the command. Returns with Register C = F3H (the data port), Register B = 0 and Register A = 0.

0F2BRWINIT
LD A,D 7A
Copy Register D (the cylinder) into Register A.
0F2C
OUT (F1H),A D3 F1
Send Register A (the cylinder) to port F1H, the FDC track register.
0F2E
LD A,(001BH) 3A 1B 00LD A,(PDRV$)
Load Register A with 001BH (PDRV$), the drive select byte.
0F31
OR 40H F6 40
Set bit 6 of Register A, the wait state generator.
0F33
LD D,A 57
Copy Register A (the select byte with the wait state bit) into Register D, for the transfer loops.
0F34
AND 10H E6 10
Mask Register A with 10H, the side select bit.
0F36
RRCA 0F
Rotate Register A right: the side bit moves to bit 3, the side compare bit of the FDC command.
0F37
BIT 1,C CB 49
Test bit 1 of Register C (the command), the side compare enable.
0F39
If side compare is on, jump to GETCMD at 0F3CH with the side bit in Register A.
0F3B
XOR A AF
Side compare off: clear Register A, no side bit in the command.
0F3CGETCMD
OR C B1
OR Register C (the command) into Register A.
0F3D
LD C,F3H 0E F3
Load Register C with F3H, the FDC data port, for INI and OUTI.
0F3F
Call 000EH (FDDINT$), the interrupt hook: a RET while the boot loader runs.
0F42
Jump to PASSCMD at 0F23H to send the command in Register A.

0F44H - IORQST: Read, Verify and Write Requests

Functions 8 to 15. Reads (8, 9 and 11) use the read sector command 82H and RDIN, 10 verifies with VERFIN; writes check the software write protect bit (bit 7 of DCT+3) and use the write sector command A2H (12 and 13), A3H with the system data mark (14, the directory) or the write track command F0H (15), through WROUT. GRABNDO takes the error code base and the transfer routine from the bytes after its CALL.

0F44IORQST
BIT 2,B CB 50
Test bit 2 of Register B (the function): set for functions 12 to 15, the writes.
0F46
LD BC,(007AH) ED 4B 7A 00
Load Register Pair BC with 007AH: Register B = 007BH (RFLAG$), the retry count.
0F4A
LD C,82H 0E 82
Load Register C with 82H, the FDC Read Sector command with side compare.
0F4C
If it is a write (bit 2 of Register B set), jump to WRCMD at 0F5EH.
0F4E
CP 0AH FE 0A
Compare Register A (the function) with 0AH, VRSEC.
0F50
If it is function 10, jump to VERFY at 0F58H.
0F52
Call GRABNDO at 0F79H, which takes the three bytes that follow as data and does not return here.
0F55-0F57
DEFB 01H / DEFW 0E69H 01 69 0E
The data of GRABNDO for a read: the error code base 01H and the transfer routine RDIN at 0E69H.
0F58VERFY
Call GRABNDO at 0F79H with the verify data that follows.
0F5B-0F5D
DEFB 01H / DEFW 0E63H 01 63 0E
The data of GRABNDO for a verify: the error code base 01H and the transfer routine VERFIN at 0E63H.
0F5EWRCMD
BIT 7,(IY+03H) FD CB 03 7E
Test bit 7 of DCT+3 at Index Register IY+03H, the software write protect.
0F62
If the drive is not write protected, jump to WRCMD1 at 0F67H.
0F64
LD A,0FH 3E 0F
Load Register A with 0FH (15), the error code Write protected disk.
0F66
RET C9
Return NZ (from the BIT test) with Register A = 0FH.
0F67WRCMD1
LD C,A2H 0E A2
Load Register C with A2H, the FDC Write Sector command with side compare.
0F69
CP 0EH FE 0E
Compare Register A (the function) with 0EH, WRSYS.
0F6B
For functions 12 and 13, jump to DOWRIT at 0F73H with the Write Sector command.
0F6D
LD C,A3H 0E A3
Load Register C with A3H, the Write Sector command that writes the system (F8H) data mark (LD leaves the flags).
0F6F
For function 14 (a directory sector), jump to DOWRIT at 0F73H.
0F71
LD C,F0H 0E F0
Function 15: load Register C with F0H, the FDC Write Track command.
0F73DOWRIT
Call GRABNDO at 0F79H with the write data that follows.
0F76-0F78
DEFB 09H / DEFW 0FBCH 09 BC 0F
The data of GRABNDO for a write: the error code base 09H and the transfer routine WROUT at 0FBCH.

0F79H - GRABNDO and RETRY: The Retry Loop

GRABNDO stores the error code base and the transfer routine named after its CALL, drops that return address and falls into RETRY. RETRY seeks (except for a write track), waits until idle, calls the transfer routine and tests the status. Lost data is retried without counting; record not found and CRC errors are retried Register B times (record not found also switches the density through SWDEN). The error code is the base plus the number of the lowest status bit set: 4 or 12 CRC error, 5 or 13 record not found, 6 system data mark or 14 write fault, 7 or 15 write protect (lost data, bit 2, never gets here: it is always retried).

0F79GRABNDO
EX (SP),HL E3
Exchange Register Pair HL with the top of the stack at the Stack Pointer: Register Pair HL = the address of the data after the CALL, the stack holds the buffer address.
0F7A
LD A,(HL) 7E
Load Register A with the error code base at Register Pair HL.
0F7B
INC HL 23
Increment Register Pair HL to the address of the transfer routine.
0F7C
LD (0FB5H),A 32 B5 0F
Self-Modifying Code
Store Register A (the error code base, 1 or 9) into 0FB5H, the operand of the LD A at ERRSTRT 0FB4H.
0F7F
LD A,(HL) 7E
Load Register A with the low byte of the transfer routine address at Register Pair HL.
0F80
INC HL 23
Increment Register Pair HL to the high byte of the transfer routine address.
0F81
LD H,(HL) 66
Load Register H with the high byte of the transfer routine address at Register Pair HL.
0F82
LD L,A 6F
Copy Register A (the low byte) into Register L: Register Pair HL = the transfer routine.
0F83
LD (0F93H),HL 22 93 0FLD (CALLIO),HL
Self-Modifying Code
Store Register Pair HL (RDIN, VERFIN or WROUT) into 0F93H-0F94H (CALLIO), the operand of the CALL at 0F92H.
0F86
POP HL E1
Restore Register Pair HL (the buffer address) from the stack; the return address after the CALL to GRABNDO is gone, so RETRY returns to the caller of the driver.
0F87RETRY
PUSH BC C5
Save Register Pair BC (Register B the retries left, Register C the FDC command) on the stack.
0F88
PUSH DE D5
Save Register Pair DE (the cylinder and sector) on the stack.
0F89
PUSH HL E5
Save Register Pair HL (the buffer address) on the stack.
0F8A
BIT 4,C CB 61
Test bit 4 of Register C (the command): set only for the Write Track command F0H.
0F8C
For any command but Write Track, call SEEKTRK at 0EE8H to seek the cylinder and set the sector.
0F8F
Call TSTBSY at 0E82H to wait until the controller is idle.
0F92
CALL 0000H CD 00 00
Self-Modifying Code
Call the transfer routine stored at 0F83H (RDIN, VERFIN or WROUT); the file holds CALL 0000H.
0F95DISKEI
NOP 00
Self-Modifying Code
No operation in the file. LBOOT stores EI here (0264H) once SYS0/SYS is loaded, so interrupts come back on after each transfer.
0F96
IN A,(F0H) DB F0
Read the FDC status from port F0H into Register A.
0F98
AND 7CH E6 7C
Mask Register A with 7CH, keeping bits 6-2: write protect, record type or write fault, record not found, CRC error and lost data.
0F9A
POP HL E1
Restore Register Pair HL (the buffer address) from the stack.
0F9B
POP DE D1
Restore Register Pair DE (the cylinder and sector) from the stack.
0F9C
POP BC C1
Restore Register Pair BC (the retries left and the command) from the stack.
0F9D
RET Z C8
Return Z with Register A = 0 if the transfer had no error.
0F9E
BIT 2,A CB 57
Test bit 2 of Register A (the masked status), lost data.
0FA0
If data was lost, jump back to RETRY at 0F87H without counting the try.
0FA2
PUSH AF F5
Save Register Pair AF (the status) on the stack.
0FA3
AND 18H E6 18
Mask Register A with 18H, record not found (bit 4) and CRC error (bit 3).
0FA5
For any other error (no retry helps), jump to DISKDUN at 0FB2H.
0FA7
BIT 4,A CB 67
Test bit 4 of Register A (the masked status), record not found.
0FA9
PUSH BC C5
Save Register Pair BC (the retries left and the command) on the stack.
0FAA
If the record was not found, call SWDEN at 0E45H to switch the density, or restore the drive.
0FAD
POP BC C1
Restore Register Pair BC (the retries left and the command) from the stack.
0FAE
POP AF F1
Restore Register Pair AF (the status) from the stack.
0FAF
Decrement Register B (the retries left) and loop back to RETRY at 0F87H while tries remain.
0FB1
DEFB 06H 06
A 06H byte. Falling through from 0FAFH, the CPU takes it and the next byte as LD B,0F1H, so the POP AF at 0FB2H is skipped (the status was popped at 0FAEH).
0FB2DISKDUN
POP AF F1
Restore Register Pair AF (the status saved at 0FA2H) from the stack.
0FB3
LD B,A 47
Copy Register A (the status) into Register B.
0FB4ERRSTRT
LD A,00H 3E 00
Self-Modifying Code
Load Register A with the error code base stored at 0F7CH (the operand at 0FB5H): 1 for a read or verify, 9 for a write. The file holds 00H.
0FB6ERRTRAN
RRC B CB 08
Rotate Register B (the status) right, moving its lowest bit into the Carry flag.
0FB8
RET C D8
Return NZ with the error code in Register A when that bit was set.
0FB9
INC A 3C
Increment Register A, the error code, for the next status bit.
0FBA
Jump back to ERRTRAN at 0FB6H for the next bit of the status.

0FBCH - WROUT: Write a Sector or Track

Sends the command through RWINIT, writes the first byte when the controller asks, turns on the controller and time-out NMIs, and writes the other bytes with OUTI under the wait state generator. The loop at 0FE2H never ends by itself: the end of the command raises the NMI, which lands at @RSTNMI 0FE9H and returns to RETRY.

0FBCWROUT
Call RWINIT at 0F2BH to set up the select byte in Register D, Register C = F3H and send the write command.
0FBF
LD E,76H 1E 76
Load Register E with 76H, the status mask of write protect, write fault, record not found, lost data and data request.
0FC1WRO1
IN A,(F0H) DB F0
Read the FDC status from port F0H into Register A.
0FC3
AND E A3
AND Register E (76H) into Register A, the status bits to wait for.
0FC4
Loop back to 0FC1H until the controller asks for a byte or reports an error.
0FC6
OUTI ED A3
Output the first byte from the memory at Register Pair HL to the port in Register C (F3H), increment Register Pair HL and decrement Register B.
0FC8
DI F3
Disable interrupts for the rest of the transfer.
0FC9
IN A,(F0H) DB F0
Read the FDC status from port F0H into Register A.
0FCB
RRA 1F
Rotate Register A right, moving bit 0, Busy, into the Carry flag.
0FCC
RET NC D0
Return if the controller is no longer busy (an error ended the command).
0FCD
LD A,C0H 3E C0
Load Register A with C0H: bit 7 enables the controller's interrupt and bit 6 the time-out, both as an NMI.
0FCF
OUT (E4H),A D3 E4
Send Register A (C0H) to port E4H, the NMI mask register.
0FD1
LD B,50H 06 50
Load Register B with 50H, a delay for the second byte of a sector write.
0FD3
Decrement Register B and loop on this instruction at 0FD3H until it reaches zero.
0FD5
LD B,(HL) 46
Load Register B with the second byte at Register Pair HL, early.
0FD6
INC HL 23
Increment Register Pair HL to the third byte.
0FD7WRO3
LD A,D 7A
Copy Register D (the select byte with the wait state bit) into Register A.
0FD8
OUT (F4H),A D3 F4
Send Register A to port F4H, turning on the wait state generator.
0FDA
IN A,(F0H) DB F0
Read the FDC status from port F0H into Register A.
0FDC
AND E A3
AND Register E (76H) into Register A, the status bits to wait for.
0FDD
Loop back to 0FD7H until the controller asks for the byte (a Write Track can make it wait).
0FDF
OUT (C),B ED 41
Output Register B (the second byte) to the port in Register C (F3H).
0FE1
LD A,D 7A
Copy Register D (the select byte with the wait state bit) into Register A.
0FE2WRO2
OUT (F4H),A D3 F4
Send Register A to port F4H, the wait state generator holding the CPU until the controller takes the next byte.
0FE4
OUTI ED A3
Output the next byte from the memory at Register Pair HL to the port in Register C (F3H), increment Register Pair HL and decrement Register B.
0FE6
Jump back to 0FE2H for ever: the NMI at the end of the command leaves the loop.
0FE8BUCKET
DEFB 53H 53
BUCKET, 0FE8H: the byte that receives every byte read by a verify. 53H (S) in the file.

0FE9H - @RSTNMI: The Disk NMI

Where the NMI of the controller's interrupt or time-out arrives when the system's NMI vector points here. It turns the NMIs off, waits a moment, drops the interrupted address and returns to the routine that called the transfer (RETRY at 0F95H).

0FE9@RSTNMI
XOR A AF
Clear Register A to 00H for the NMI mask register.
0FEA
OUT (E4H),A D3 E4
Send Register A (00H) to port E4H, the NMI mask register, turning off the controller and time-out interrupts.
0FEC
LD BC,0064H 01 64 00
Load Register Pair BC with 0064H (100), a short delay count for @PAUSE.
0FEF
Call 0382H (@PAUSE) to wait the count in Register Pair BC.
0FF2
POP HL E1
Pop the address interrupted by the NMI into Register Pair HL and discard it.
0FF3FDCEND
RET C9
Return to the caller of the transfer routine, RETRY at 0F95H. This is the last byte of the floppy driver (FDCEND) and of the resident drivers; the low I/O zone (DVREND$) starts at 0FF4H.

0FF4H - The Rest of Cylinder 0

The bytes of BOOT/SYS after the drivers. They are read to 0FF4H-11FFH at boot and are free memory of the low I/O zone, which drivers can use up to 12FFH.

0FF4-0FFF
DEFB 00H x 12 00 x 12
0FF4H-0FFFH: twelve zero bytes, the end of sector 13.
1000-10FF
DEFW 0B66DH x 128 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6
BOOT/SYS sector 14, read to 1000H-10FFH: the format fill bytes 6DH and B6H, never written by the system.
1100-11FF
DEFW 0B66DH x 128 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6 6D B6
BOOT/SYS sector 15, read to 1100H-11FFH: the format fill bytes 6DH and B6H, never written by the system.