TRS-80 DOS - NEWDOS/80 v2.0 for the Model III - SYS9/SYS Disassembled

Page Customization

Introduction/Summary

NEWDOS/80 v2.0 SYS9/SYS Disassembly - Chain Files, MDCOPY, Named Routines (Model III)

SYS9/SYS runs chain files (the library commands DO, CHAIN and CHNON, and the keys the keyboard driver takes from the chain file), the commands PAUSE, STMT, BOOT and MDCOPY, the queue of named routines, and the two stops DOS FATAL ERROR and 'RUN ONLY' STOPPED. Its five load records fill 4D00H-51DFH of the overlay area (1,248 bytes) and its transfer address is 4D00H; 5128H-51DFH are 00H.

The page shows every byte of the file once, in address order. Bytes that are not in the file are shown as a DEFS row without a byte column.

Functions

CodeFunction
2BHEnqueue a named routine (SYS0/SYS 4461H), 5048H
4BHDequeue a named routine (SYS0/SYS 4464H), 505FH
CBHNext key from the chain file, for the keyboard driver 44EBH, 4E22H
EBH, C = 1Return to the caller of 4DC7H after a call through 4978H, 4DD9H
EBH, C = 2MDCOPY, 4FD7H
EBH, C = 3DO and CHAIN, 4DDCH
EBH, C = 4An error while chaining (from SYS1/SYS's command exit), 4EE2H
EBH, C = 5CHNON, 4D72H
EBH, C = 7Call a named routine (*name), 5070H
EBH, C = 8 and 9PAUSE 4D52H and STMT 4D63H
EBH, C = 0AHBOOT (RST 00H), 4DC6H
EBH, C = 0BH and 0CHDOS FATAL ERROR and 'RUN ONLY' STOPPED, then wait for R and restart, 4DACH

Any other code, and sub-function 6, give error 2AH. MDCOPY copies the file SYS1/SYS opened at 4480H to the file parsed into the FCB at 51E0H, through a buffer inside SYS9/SYS (4DDCH); its file operations are called through 4DC7H, which returns through SYS0/SYS 4978H and sub-function 1 so that SYS9/SYS is loaded again after SYS2/SYS or SYS3/SYS have run.

Chain Files

DO (and CHAIN) copies the opened file's FCB to 44A0H, with its buffer at 4FF7H inside SYS9/SYS, optionally skips to a label, sets 4289H bit 5 (and 428AH bit 4 under a DOS-CALL) and clears the held key at 42C5H. While 4289H bit 5 is set (and bits 3 and 6 are clear) the SYS0/SYS keyboard driver calls SYS9/SYS with code CBH for each key. Without option AT (428DH bit 7) only the ROM's line input routine gets chain keys: 4E35H looks on the stack for the ROM return addresses 0694H and 05E3H. The first request after SYS9/SYS has been loaded marks the chain buffer empty (4E22H patches itself into a JR).

The chain file's bytes are read by 4F50H; 00H bytes are left out, /./0 to /./5 become the codes 80H-85H, and bytes 86H and up lose bit 7.

CodeMeaning
80HStarts a label line (80H label CR); reached while reading, it ends the chain file
81HThe rest of the line is shown, then Chaining PAUSE. waits for ENTER
82HThe rest of the line is skipped
83HThe rest of the line is shown
84HThe rest of the line is a label: the file is rewound and read up to that label
85HThe rest of the line is N, Y or D, as for CHNON

Each ordinary key is given with the next byte read ahead into 42C5H, so that the end of the file or a following label line ends the chain file after the last key. With option BC (428DH bit 6) the up arrow (3840H bit 3) aborts the chain file and the right arrow (bit 6) pauses it.

Named Routines

The queue starts at 4058H. A block, at 5200H or above, holds at +0 the address of +2 (a check), at +2 the link to the next block, at +4 an eight-character name and from +12 the routine. A command line *name runs the routine with Register Pair HL after the name. A block whose check word is wrong stops the computer with DOS FATAL ERROR.

Variables

Memory Outside SYS9/SYS

Address
Size
Contents
3840H
1 byte
Keyboard Row
Bit 0 ENTER (4F0CH), bit 3 up arrow (4ED3H), bit 6 right arrow (4E5EH).
4058H-4059H
2 bytes
Named Routine Queue
The first block of the queue, 0000H when empty (504DH, 505AH, 50AEH).
4288H
1 byte
Resident Overlay
Set to 00H by MDCOPY after each call through 4DC7H (4FE7H, 5007H).
4289H
1 byte
System Flags
Bit 5: a chain file supplies the keys (set 4DF8H, cleared 4ECDH, CHNON 4D82H).
428AH
1 byte
DOS State Flags
Bit 6: a DOS-CALL is active; bit 4: the chain file belongs to its level (4DFFH, 4ED0H, 4D9FH, 511FH).
428DH
1 byte
Options
Copy of system data sector byte F1H: bit 7 option AT (4E31H), bit 6 option BC (4E5AH, 4EDCH).
42C5H
1 byte
Held Key
The chain byte read ahead, given at the next request (4E69H, 4EA7H, 4F18H); 00H for none.
4480H-449FH
32 bytes
DOS FCB
The file SYS1/SYS opened: the chain file for DO (copied at 4DE3H), the MDCOPY source (4483H buffer, 4488H EOF low, 448CH-448DH EOF middle and high).
44A0H-44BFH
32 bytes
Chain FCB
The chain file: 44A0H byte 0 (open bit 7, cleared at 4EC8H), 44A1H byte 1 (bit 5 set at 4E2CH), 44A3H-44A4H the buffer 4FF7H (4DE8H), 44A5H the position in the sector (4F58H), 44A9H the record length (4F7AH).

SYS9/SYS Buffers

Address
Size
Contents
4DDCH-4EDBH
256 bytes
MDCOPY Buffer
SYS9/SYS's own code used as the buffer of both MDCOPY files (4FDAH).
4FD7H-4FF6H
32 bytes
Chain Line Buffer
The text of an 84H or 85H line (4F1DH), over MDCOPY's code.
4FF7H-50F6H
256 bytes
Chain Buffer
The chain file's sector buffer (4DE5H), over SYS9/SYS's own code.
51E0H-51FFH
32 bytes
Second FCB and Name
Past the end of the file: the MDCOPY destination FCB (51E8H EOF low, 51EAH-51EBH NEXT, 51ECH-51EDH EOF), or the name of a named routine call (51E0H-51E8H).

Operands Changed at Run Time

Address
Size
Contents
4E22H
1 byte
First Request
3EH (LD A,0AH) as loaded; 4E26H stores 18H (JR 4E2EH) after the first chain request.
4FE6H, 5006H
2 bytes
MDCOPY Constants
The 00H operands of the LD A at 4FE5H and 5005H, stored at 4288H; nothing in SYS9/SYS changes them.

Outside Routines and Addresses

AddressContents
0000HROM: restart (RST 00H, 4DC6H).
0013H, 0033H, 0049HROM: read a byte from a control block (4F8FH), display a character (4EF6H), wait for a key (4D5BH, 4DBDH).
0694H, 05E3HROM return addresses looked for on the stack (4E40H, 4E4FH): the keyboard driver call and the line input routine.
402DH, 4030HDOS READY (5124H), the exit after a displayed error (4EE8H).
4409HSYS0/SYS: the DOS error exit (4D4FH, 4EEBH).
4428H, 4436H, 4439H, 443FH, 4445HSYS0/SYS: close, read, write, rewind, back one record (5045H, 5011H, 5019H, 500AH, 4F7DH).
4467H, 4548HSYS0/SYS: display a message, change to upper case (4D58H, 4D8BH).
4978H, 4982HSYS0/SYS: the function chain return and the overlay call (4DCBH, 4DD2H).
4BC2H, 4BC5HSYS0/SYS: the dispatcher's CALL to 4D00H and its return address (4DD9H, 4DEBH, 509DH).
4C7AHSYS0/SYS: end of line or separator test (4DEDH, 5077H).

Disassembly

4D00H - Function Dispatcher

SYS9/SYS (directory slot 0BH) is loaded by the SYS0/SYS RST 28H dispatcher into 4D00H-51DFH and entered at 4D00H by the CALL at 4BC2H, with Register A = the RST 28H code, Register C = the sub-function for function 7, and Register Pairs DE and HL as the caller left them. 2BH (function 1) enqueues a named routine, 4BH (function 2) dequeues one, CBH (function 6) gives the keyboard driver the next key of a chain file, and EBH (function 7) runs the library commands and the services in Register C: 1 return to the caller of 4DC7H, 2 MDCOPY, 3 DO and CHAIN, 4 an error while chaining, 5 CHNON, 7 call a named routine (*name), 8 PAUSE, 9 STMT, 0AH BOOT, 0BH DOS FATAL ERROR, 0CH 'RUN ONLY' STOPPED. Any other code or sub-function returns error 2AH.

4D00
LD IY,4280H FD 21 80 42
Load Index Register IY with 4280H, the base SYS0/SYS and the overlays use for the variables around the current drive's PDRIVE values; SYS9/SYS itself does not use Index Register IY afterwards.
4D04
CP 2BH FE 2B
Compare Register A, the RST 28H code, against 2BH, the code of function 1: enqueue a named routine (SYS0/SYS vector 4461H).
4D06
If the Z FLAG is set (Register A = 2BH), JUMP to 5048H to enqueue the routine block at Register Pair HL.
4D09
CP 4BH FE 4B
Compare Register A, the RST 28H code, against 4BH, the code of function 2: dequeue a named routine (SYS0/SYS vector 4464H).
4D0B
If the Z FLAG is set (Register A = 4BH), JUMP to 505FH to dequeue the routine block at Register Pair HL.
4D0E
CP CBH FE CB
Compare Register A, the RST 28H code, against CBH, the code of function 6: the keyboard driver (SYS0/SYS 44EBH) asks for the next chain file key.
4D10
If the Z FLAG is set (Register A = CBH), JUMP to 4E22H to fetch the next key from the chain file.
4D13
CP EBH FE EB
Compare Register A, the RST 28H code, against EBH, the code of function 7 with a sub-function in Register C.
4D15
If the NZ FLAG is set (Register A is none of the four codes), JUMP to 4D42H for error 2AH.
4D17
DEC C 0D
Decrement Register C, the sub-function: the Z FLAG is set if Register C was 1.
4D18
If the Z FLAG is set (sub-function 1, the return after a call made through 4DC7H), JUMP to 4DD9H.
4D1B
DEC C 0D
Decrement Register C, the sub-function: the Z FLAG is set if Register C was 2 (MDCOPY).
4D1C
If the Z FLAG is set (sub-function 2, the MDCOPY command), JUMP to 4FD7H.
4D1F
DEC C 0D
Decrement Register C, the sub-function: the Z FLAG is set if Register C was 3 (DO and CHAIN).
4D20
If the Z FLAG is set (sub-function 3, DO or CHAIN with the file SYS1/SYS opened in 4480H), JUMP to 4DDCH.
4D23
DEC C 0D
Decrement Register C, the sub-function: the Z FLAG is set if Register C was 4.
4D24
If the Z FLAG is set (sub-function 4, an error while chaining, called by SYS1/SYS's command exit), JUMP to 4EE2H.
4D27
DEC C 0D
Decrement Register C, the sub-function: the Z FLAG is set if Register C was 5 (CHNON).
4D28
If the Z FLAG is set (sub-function 5, the CHNON command), JUMP to 4D72H.
4D2A
DEC C 0D
Decrement Register C, the sub-function: the Z FLAG is set if Register C was 6.
4D2B
If the Z FLAG is set (sub-function 6, which SYS9/SYS does not have), JUMP to 4D42H for error 2AH.
4D2E
DEC C 0D
Decrement Register C, the sub-function: the Z FLAG is set if Register C was 7 (a named routine).
4D2F
If the Z FLAG is set (sub-function 7, a command line starting with an asterisk), JUMP to 5070H to call the named routine.
4D32
DEC C 0D
Decrement Register C, the sub-function: the Z FLAG is set if Register C was 8 (PAUSE).
4D33
If the Z FLAG is set (sub-function 8, the PAUSE command), JUMP to 4D52H.
4D35
DEC C 0D
Decrement Register C, the sub-function: the Z FLAG is set if Register C was 9 (STMT).
4D36
If the Z FLAG is set (sub-function 9, the STMT command), JUMP to 4D63H.
4D38
DEC C 0D
Decrement Register C, the sub-function: the Z FLAG is set if Register C was 0AH (BOOT).
4D39
If the Z FLAG is set (sub-function 0AH, the BOOT command), JUMP to 4DC6H.
4D3C
DEC C 0D
Decrement Register C, the sub-function: the Z FLAG is set if Register C was 0BH (DOS FATAL ERROR).
4D3D
If the Z FLAG is set (sub-function 0BH, called by SYS1/SYS after an error at reset), JUMP to 4DACH.
4D3F
DEC C 0D
Decrement Register C, the sub-function: the Z FLAG is set if Register C was 0CH ('RUN ONLY' STOPPED).
4D40
If the Z FLAG is set (sub-function 0CH, called by SYS1/SYS when RUN-ONLY reaches DOS READY), JUMP to 4DB1H.

4D42H - Error Exits

4D42H returns error 2AH. 4D46H (from the named routine search, 50C9H) reports DOS FATAL ERROR (33H) through SYS4/SYS code 46H, which also sets bit 2 of 428AH, so SYS1/SYS later calls sub-function 0BH. 4D4CH returns error 2FH and 4D4EH returns the error in Register A through the DOS error exit 4409H.

4D42
LD A,2AH 3E 2A
Load Register A with 2AH, the error code ILLEGAL DOS FUNCTION, for a code or sub-function SYS9/SYS does not have.
4D44
JUMP to 4D4EH to return the error in Register A through SYS0/SYS 4409H.
4D46
LD A,33H 3E 33
Load Register A with 33H, the error code DOS FATAL ERROR: a named routine block in the queue at 4058H failed its check (50C9H).
4D48
PUSH AF F5
Save Register Pair AF (Register A = 33H) on the stack, where SYS4/SYS takes the error code from.
4D49
LD A,46H 3E 46
Load Register A with 46H, the RST 28H code of SYS4/SYS function 2: display the error on the stack and set bit 2 of 428AH (a fatal error).
4D4B
RST 28H EF
RST 28H with Register A = 46H: the dispatcher loads SYS4/SYS over SYS9/SYS, which displays Dos Fatal Error, sets 428AH bit 2 and goes on to DOS READY (402DH), where SYS1/SYS calls SYS9/SYS sub-function 0BH.
4D4C
LD A,2FH 3E 2F
Load Register A with 2FH, the error code BAD PARAMETER(S) (a name that is empty or too long at 5086H, or a routine block below 5200H at 50A6H).
4D4E
OR A B7
OR Register A, the error code, with itself: the NZ FLAG is set for any error code (4409H tests it).
4D4F
JUMP to SYS0/SYS 4409H, the DOS error exit, with the error code in Register A; 4409H passes it to SYS4/SYS, which displays the message and ends the command.

4D52H - PAUSE and STMT

PAUSE first does what STMT does, then shows Press 'ENTER' When Ready To Continue and waits for ENTER. STMT shows the rest of its command line (Register Pair HL) only while a DOS-CALL is active (428AH bit 6) and no chain file is running (4289H bit 5); otherwise nothing is shown. Both return Register A = 00H and the Z FLAG.

4D52
PAUSE: GOSUB to 4D63H to show the rest of the command line at Register Pair HL when a DOS-CALL is active and no chain file is running.
4D55
LD HL,4FB2H 21 B2 4F
Load Register Pair HL with 4FB2H, the message Press 'ENTER' When Ready To Continue and a carriage return.
4D58
GOSUB to SYS0/SYS 4467H to display the message at Register Pair HL (4FB2H) up to and including its carriage return.

Wait for ENTER
Register A = the key read.

4D5B
GOSUB to ROM 0049H, which waits for a key and returns it in Register A.
4D5E
SUB 0DH D6 0D
Subtract 0DH, the ENTER key, from Register A, the key: Register A = 00H and the Z FLAG for ENTER.
4D60
If the NZ FLAG is set (Register A was not ENTER), LOOP back to 4D5BH to wait for the next key.
4D62
RET C9
RETURN through the dispatcher's return address 4BC5H to SYS0/SYS 4408H with Register A = 00H and the Z FLAG: PAUSE has ended.
4D63
LD BC,(4289H) ED 4B 89 42
STMT: load Register Pair BC with the two bytes at 4289H-428AH: Register C = 4289H (system flags, bit 5 chaining), Register B = 428AH (DOS state flags, bit 6 DOS-CALL).
4D67
BIT 6,B CB 70
Test bit 6 of Register B, the copy of 428AH: bit 6 is set while a DOS-CALL is active.
4D69
If the Z FLAG is set (no DOS-CALL), JUMP to 4D70H without showing anything.
4D6B
BIT 5,C CB 69
Test bit 5 of Register C, the copy of 4289H: bit 5 is set while a chain file supplies the keys.
4D6D
If the Z FLAG is set (no chain file running), GOSUB to SYS0/SYS 4467H to display the rest of the command line at Register Pair HL up to its carriage return.
4D70
XOR A AF
Load Register A with 00H (XOR A with itself), which also sets the Z FLAG: no error.
4D71
RET C9
RETURN with Register A = 00H and the Z FLAG set (to PAUSE at 4D55H, or through 4BC5H to 4408H for STMT).

4D72H - CHNON Command

CHNON N, Y or D changes the chaining state of the chain file in the FCB at 44A0H, which must be open (byte 0 bit 7), else error 26H. N stops taking keys from it (4289H bit 5 cleared), Y takes keys from it again (bit 5 set), and D, under a DOS-CALL, also marks the chain file as belonging to this DOS-CALL level (428AH bit 4). 4D82H is also used for the 85H lines of a chain file (4E7EH).

4D72
LD A,(44A0H) 3A A0 44
Load Register A with the byte at 44A0H, byte 0 of the chain file's FCB: bit 7 is set while the file is open.
4D75
RLCA 07
Rotate Register A, FCB byte 0, left: bit 7 (open) goes into the CARRY FLAG.
4D76
LD A,26H 3E 26
Load Register A with 26H, the error code FILE NOT OPEN, in case no chain file is open; LD does not change the flags.
4D78
If the NO CARRY FLAG is set (the FCB at 44A0H is not open), JUMP to 4D4EH to return error 26H.
4D7A
GOSUB to 4D82H to read N, Y or D at Register Pair HL and store the new flags in 4289H-428AH; the Z FLAG if the line was right.
4D7D
RET Z C8
If the Z FLAG is set (the parameter was accepted), RETURN through 4BC5H to SYS0/SYS 4408H with Register A = 00H.
4D7E
LD A,34H 3E 34
Load Register A with 34H, the error code ILLEGAL KEYWORD OR SEPARATOR OR TERMINATOR: something other than N, Y or D and a carriage return followed.
4D80
JUMP to 4D4EH to return error 34H through SYS0/SYS 4409H.
4D82
LD BC,(4289H) ED 4B 89 42
Load Register Pair BC with the two bytes at 4289H-428AH: Register C = the system flags (4289H), Register B = the DOS state flags (428AH).
4D86
RES 5,C CB A9
Reset bit 5 of Register C, the copy of 4289H: chaining off unless Y or D sets it again.
4D88
RES 4,B CB A0
Reset bit 4 of Register B, the copy of 428AH: the chain file does not belong to this DOS-CALL level unless D sets it.
4D8A
LD A,(HL) 7E
Load Register A with the byte at Register Pair HL, the parameter character.
4D8B
GOSUB to SYS0/SYS 4548H to change Register A to upper case if it is a lower case letter.
4D8E
CP 4EH FE 4E
Compare Register A, the parameter, against 4EH, the letter N.
4D90
If the Z FLAG is set (N), JUMP to 4DA1H with chaining off in Register C.
4D92
SET 5,C CB E9
Set bit 5 of Register C, the copy of 4289H: chaining on, for Y and D.
4D94
CP 59H FE 59
Compare Register A, the parameter, against 59H, the letter Y.
4D96
If the Z FLAG is set (Y), JUMP to 4DA1H with chaining on in Register C.
4D98
CP 44H FE 44
Compare Register A, the parameter, against 44H, the letter D.
4D9A
RET NZ C0
If the NZ FLAG is set (Register A is not N, Y or D), RETURN with the NZ FLAG; 4289H and 428AH are not changed.
4D9B
BIT 6,B CB 70
Test bit 6 of Register B, the copy of 428AH: bit 6 is set while a DOS-CALL is active.
4D9D
If the Z FLAG is set (no DOS-CALL), JUMP to 4DA1H: D then acts like Y.
4D9F
SET 4,B CB E0
Set bit 4 of Register B, the copy of 428AH: the chain file belongs to this DOS-CALL level.
4DA1
INC HL 23
Increment Register Pair HL past the parameter letter.
4DA2
LD A,(HL) 7E
Load Register A with the byte at Register Pair HL, the character after the letter.
4DA3
CP 0DH FE 0D
Compare Register A, that character, against 0DH, the carriage return that must end the line.
4DA5
RET NZ C0
If the NZ FLAG is set (something follows the letter), RETURN with the NZ FLAG; nothing is changed.
4DA6
LD (4289H),BC ED 43 89 42
Store Register Pair BC at 4289H-428AH: Register C (chaining bit 5) to 4289H and Register B (bit 4) to 428AH.
4DAA
XOR A AF
Load Register A with 00H (XOR A with itself), which also sets the Z FLAG: the parameter was accepted.
4DAB
RET C9
RETURN with Register A = 00H and the Z FLAG set.

4DACH - DOS FATAL ERROR, 'RUN ONLY' STOPPED and BOOT

Sub-functions 0BH and 0CH show DOS FATAL ERROR or 'RUN ONLY' STOPPED, then !! KEY 'R' FOR RESET., wait for R (upper or lower case) and restart the computer with RST 00H, as BOOT (sub-function 0AH) does at once.

4DAC
LD HL,50F4H 21 F4 50
Load Register Pair HL with 50F4H, the text DOS FATAL ERROR ending in 03H.
4DAF
JUMP to 4DB4H to display the text at Register Pair HL.
4DB1
LD HL,50E1H 21 E1 50
Load Register Pair HL with 50E1H, the text 'RUN ONLY' STOPPED ending in 03H.
4DB4
GOSUB to SYS0/SYS 4467H to display the text at Register Pair HL up to its 03H.
4DB7
LD HL,5104H 21 04 51
Load Register Pair HL with 5104H, the text !! KEY 'R' FOR RESET. and a carriage return.
4DBA
GOSUB to SYS0/SYS 4467H to display the text at Register Pair HL (5104H) on the same line.

Wait for R
Register A = the key read.

4DBD
GOSUB to ROM 0049H, which waits for a key and returns it in Register A.
4DC0
RES 5,A CB AF
Reset bit 5 of Register A, the key: a lower case r becomes an upper case R.
4DC2
CP 52H FE 52
Compare Register A, the key, against 52H, the letter R.
4DC4
If the NZ FLAG is set (Register A is not R), LOOP back to 4DBDH; no other key does anything.
4DC6
RST 00H C7
BOOT (and R above): RST 00H, which restarts the computer at ROM 0000H.

4DC7H - Call a Routine and Come Back to SYS9/SYS

Register A = 00H calls the SYS0/SYS routine whose address is in the alternate Register Pair HL; any other value is the RST 28H code of an overlay function, called through SYS0/SYS 4982H. Either way the routine returns to SYS0/SYS 4978H with the word EB01H pushed, so 4978H reloads SYS9/SYS with sub-function 1 (4DD9H), which returns to the instruction after the CALL 4DC7H. An error returns through 4978H to the DOS error exit instead. This lets MDCOPY use SYS2/SYS, and its file I/O, even though they may load another overlay over SYS9/SYS.

4DC7
EXX D9
Exchange Register Pairs BC, DE and HL with the alternate set, keeping the caller's Register Pairs BC, DE and HL there.
4DC8
LD BC,EB01H 01 01 EB
Load Register Pair BC (alternate) with EB01H: Register B = EBH, the RST 28H code of SYS9/SYS function 7, and Register C = 01H, sub-function 1.
4DCB
LD DE,4978H 11 78 49
Load Register Pair DE (alternate) with 4978H, the SYS0/SYS return point that pops a word into Registers A and C and does RST 28H with it.
4DCE
PUSH BC C5
Save Register Pair BC (EB01H) on the stack, the word 4978H will pop.
4DCF
PUSH DE D5
Save Register Pair DE (4978H) on the stack, as the return address of the routine called.
4DD0
EXX D9
Exchange Register Pairs BC, DE and HL with the alternate set again: the caller's Register Pairs BC, DE and HL are back.
4DD1
OR A B7
OR Register A with itself: the Z FLAG is set if Register A is 00H (a SYS0/SYS routine).
4DD2
If the NZ FLAG is set (Register A is an RST 28H code), JUMP to SYS0/SYS 4982H, which does RST 28H with it and returns to 4978H.
4DD5
EXX D9
Exchange Register Pairs BC, DE and HL with the alternate set: the alternate Register Pair HL holds the SYS0/SYS routine's address.
4DD6
PUSH HL E5
Save Register Pair HL, the routine's address (4439H at 4FFDH), on the stack to RETURN to it.
4DD7
EXX D9
Exchange Register Pairs BC, DE and HL with the alternate set again: the caller's registers are back for the routine.
4DD8
RET C9
RETURN, which pops the routine's address and jumps to it with the caller's registers; the routine returns to 4978H.
4DD9
EX (SP),HL E3
Sub-function 1: exchange Register Pair HL with the word at the top of the stack (at the Stack Pointer SP): Register Pair HL = the dispatcher's return address 4BC5H, and the caller's Register Pair HL is on top.
4DDA
POP HL E1
Restore Register Pair HL from the stack: the caller's Register Pair HL; the dispatcher's return address 4BC5H is dropped.
4DDB
RET C9
RETURN to the instruction after the CALL 4DC7H, in SYS9/SYS just reloaded: the routine succeeded (an error would have gone from 4978H to 4409H), Register Pairs DE and HL are as it left them, and Register A = EBH with the Z FLAG from the DEC C at 4D17H.

4DDCH - DO and CHAIN: Start a Chain File

SYS1/SYS has opened the file in the DOS FCB at 4480H (Register Pair DE) and left the command line pointer on the stack under the dispatcher's return address 4BC5H. The FCB is copied to 44A0H, the chain file's FCB, with its buffer at 4FF7H inside SYS9/SYS. A label after the filespec (DO file,label) makes 4E06H skip to the line 80H label. Then chaining starts: 4289H bit 5 set (and 428AH bit 4 under a DOS-CALL) and no key pending (42C5H = 00H). The command returns straight to SYS0/SYS 4408H.

4DDC
EX DE,HL EB
Exchange Register Pairs DE and HL: Register Pair HL = 4480H, the DOS FCB holding the open chain file (from SYS1/SYS in Register Pair DE).
4DDD
LD DE,44A0H 11 A0 44
Load Register Pair DE with 44A0H, the chain file's own FCB (44A0H-44BFH), which the keyboard requests read from.
4DE0
LD BC,0020H 01 20 00
Load Register Pair BC with 0020H, the 32 bytes of an FCB.
4DE3
LDIR ED B0
Copy Register Pair BC (32) bytes from Register Pair HL (the FCB at 4480H) to Register Pair DE (44A0H); Register Pair HL ends at 44A0H and Register Pair DE at 44C0H.
4DE5
LD HL,4FF7H 21 F7 4F
Load Register Pair HL with 4FF7H, the 256 bytes 4FF7H-50F6H inside SYS9/SYS, used as the chain file's sector buffer.
4DE8
LD (44A3H),HL 22 A3 44
Store Register Pair HL, 4FF7H, at 44A3H, bytes 3-4 of the chain FCB at 44A0H: its buffer address.
4DEB
POP AF F1
Restore Register Pair AF from the stack, discarding the dispatcher's return address 4BC5H, so that the command line pointer SYS1/SYS left is on top.
4DEC
POP HL E1
Restore Register Pair HL from the stack: the command line pointer after the filespec.
4DED
GOSUB to SYS0/SYS 4C7AH with Register Pair HL = the command line: the Z FLAG at the carriage return, the NZ FLAG and NO CARRY with Register Pair HL past a comma or spaces, the CARRY FLAG and Register A = 34H before any other character.
4DF0
RET C D8
If the CARRY FLAG is set (no separator after the filespec), RETURN to SYS0/SYS 4408H with error 34H in Register A.
4DF1
If the NZ FLAG is set (a label follows the separator), GOSUB to 4E06H to read the chain file up to the line 80H label, where Register Pair HL points to the label.
4DF4
RET NZ C0
If the NZ FLAG is set (the label was not found, Register A = the error, 1CH at the end of the file), RETURN to SYS0/SYS 4408H with it.
4DF5
LD HL,4289H 21 89 42
Load Register Pair HL with 4289H, the system flags.
4DF8
SET 5,(HL) CB EE
Set bit 5 of the byte at Register Pair HL (4289H): a chain file supplies the keys; the keyboard driver 44EBH now calls 4E22H.
4DFA
INC HL 23
Increment Register Pair HL to 428AH, the DOS state flags.
4DFB
BIT 6,(HL) CB 76
Test bit 6 of the byte at Register Pair HL (428AH): bit 6 is set while a DOS-CALL is active.
4DFD
If the Z FLAG is set (no DOS-CALL), JUMP to 4E01H.
4DFF
SET 4,(HL) CB E6
Set bit 4 of the byte at Register Pair HL (428AH): the chain file belongs to this DOS-CALL level.
4E01
XOR A AF
Load Register A with 00H (XOR A with itself), which also sets the Z FLAG.
4E02
LD (42C5H),A 32 C5 42
Store Register A (00H) at 42C5H, the key held back for the next request: none.
4E05
RET C9
RETURN to SYS0/SYS 4408H with Register A = 00H and the Z FLAG: the chain file is started.

4E06H - Find a Label in the Chain File

Register Pair HL = the label text, ending in a carriage return. Reads the chain file (4F50H) until a byte 80H, then compares the following characters, changed to upper case, with the label; the first line 80H label CR that matches ends the search with the Z FLAG. A mismatch looks for the next 80H. A read error (1CH at the end of the file) returns the NZ FLAG with the error in Register A.

4E06
LD B,H 44
Load Register B with Register H, the high byte of the label's address.
4E07
LD C,L 4D
Load Register C with Register L: Register Pair BC = the label's address, kept to start each comparison again.

Search Loop
Register Pair BC = the label, Register Pair HL = the label character to compare.

4E08
LD H,B 60
Load Register H with Register B, the high byte of the label's address.
4E09
LD L,C 69
Load Register L with Register C: Register Pair HL = the first character of the label again.
4E0A
GOSUB to 4F50H to read the next byte of the chain file into Register A (80H-85H for a code); the NZ FLAG with the error in Register A at the end of the file.
4E0D
RET NZ C0
If the NZ FLAG is set (a read error), RETURN with the error code in Register A.
4E0E
CP 80H FE 80
Compare Register A, the byte read, against 80H, the code that starts a label line.
4E10
If the NZ FLAG is set (Register A is not 80H), LOOP back to 4E0AH to read on.

Compare Loop
Register Pair HL = the label in the command line.

4E12
GOSUB to 4F50H to read the next byte of the chain file, a label character, into Register A.
4E15
RET NZ C0
If the NZ FLAG is set (a read error), RETURN with the error code in Register A.
4E16
GOSUB to SYS0/SYS 4548H to change Register A to upper case if it is a lower case letter.
4E19
CP (HL) BE
Compare Register A, the chain file's character, with the byte at Register Pair HL, the label's character.
4E1A
INC HL 23
Increment Register Pair HL to the label's next character. INC HL does not change the flags.
4E1B
If the NZ FLAG is set (the characters differ), LOOP back to 4E08H to start the label again and look for the next 80H.
4E1D
CP 0DH FE 0D
Compare Register A, the matching character, against 0DH, the carriage return that ends both labels.
4E1F
If the NZ FLAG is set (not the end yet), LOOP back to 4E12H for the next character.
4E21
RET C9
RETURN with the Z FLAG set: the chain file is positioned after the label line.

4E22H - Next Key From the Chain File

Function 6 (code CBH), called by the SYS0/SYS keyboard driver 44EBH through 4982H while 4289H bit 5 is set. Returns the Z FLAG with the next key in Register A, or the NZ FLAG when the chain file gives no key (the driver then reads the keyboard). Without option AT (428DH bit 7) keys are given only to the ROM's line input routine. The chain file's bytes 80H-85H are codes: 80H starts a label line (and ends the chain file when reached while reading), 81H a line to show followed by a pause, 82H a line to skip, 83H a line to show, 84H a label to go to, 85H a CHNON parameter. With option BC (428DH bit 6) the up arrow aborts the chain file and the right arrow pauses it.

4E22
LD A,0AH 3E 0A
Self-Modifying Code
Load Register A with 0AH. 3EH (LD A) in the file, so the first request after SYS9/SYS is loaded goes on to 4E24H; 4E26H then stores 18H here, making the bytes 18H 0AH a JR 4E2EH for every later request while SYS9/SYS stays loaded.
4E24
LD A,18H 3E 18
Load Register A with 18H, the opcode of JR, to store over the LD A at 4E22H.
4E26
LD (4E22H),A 32 22 4E
Self-Modifying Code
Store Register A (18H) at 4E22H: from now on 4E22H jumps straight to 4E2EH.
4E29
LD HL,44A1H 21 A1 44
Load Register Pair HL with 44A1H, byte 1 of the chain FCB at 44A0H.
4E2C
SET 5,(HL) CB EE
Set bit 5 of the byte at Register Pair HL (44A1H): the chain file's buffer at 4FF7H is marked as not holding the sector, because loading SYS9/SYS has just overwritten it, so the next read fetches the sector again.
4E2E
LD A,(428DH) 3A 8D 42
Load Register A with the byte at 428DH, the copy of system data sector byte F1H: bit 7 is option AT (give chain keys to every keyboard request), bit 6 option BC.
4E31
BIT 7,A CB 7F
Test bit 7 of Register A, the 428DH options: option AT.
4E33
If the NZ FLAG is set (option AT), JUMP to 4E57H: every keyboard request gets a chain key.
4E35
LD B,0AH 06 0A
Load Register B with 0AH: up to 9 words of the stack are searched for the ROM's return address 0694H.
4E37
LD HL,FFFFH 21 FF FF
Load Register Pair HL with FFFFH, minus 1, to point one byte below the Stack Pointer.
4E3A
ADD HL,SP 39
Add the Stack Pointer SP to Register Pair HL: Register Pair HL = the Stack Pointer minus 1.

Stack Search
Register Pair HL steps up the stack two bytes at a time, Register B counts the words.

4E3B
DEC B 05
Decrement Register B, the words left to look at.
4E3C
If the Z FLAG is set (Register B is 0, 0694H not found), JUMP to 4E7BH to return the NZ FLAG: no chain key for this request.
4E3E
INC HL 23
Increment Register Pair HL to the low byte of the next word on the stack.
4E3F
LD A,(HL) 7E
Load Register A with the byte at Register Pair HL, the low byte of the stacked word.
4E40
CP 94H FE 94
Compare Register A, the low byte, against 94H, the low byte of 0694H (the ROM's return point after its keyboard driver).
4E42
INC HL 23
Increment Register Pair HL to the high byte of the word. INC HL does not change the flags.
4E43
If the NZ FLAG is set (the low byte is not 94H), LOOP back to 4E3BH for the next word.
4E45
LD A,(HL) 7E
Load Register A with the byte at Register Pair HL, the high byte of the stacked word.
4E46
CP 06H FE 06
Compare Register A, the high byte, against 06H: the Z FLAG is set for the word 0694H.
4E48
If the NZ FLAG is set (not 0694H), LOOP back to 4E3BH for the next word.
4E4A
LD DE,000CH 11 0C 00
Load Register Pair DE with 000CH, the distance from 0694H to the word above it that tells who called the ROM's keyboard routine.
4E4D
ADD HL,DE 19
Add Register Pair DE (000CH) to Register Pair HL: Register Pair HL = the high byte of that return address.
4E4E
LD A,(HL) 7E
Load Register A with the byte at Register Pair HL, the high byte of the caller's return address.
4E4F
CP 05H FE 05
Compare Register A, the high byte, against 05H, the high byte of 05E3H (the return point in the ROM's line input routine 05D9H).
4E51
DEC HL 2B
Decrement Register Pair HL to the low byte of the return address. DEC HL does not change the flags.
4E52
RET NZ C0
If the NZ FLAG is set (not called from the ROM's line input), RETURN with the NZ FLAG: no chain key.
4E53
LD A,(HL) 7E
Load Register A with the byte at Register Pair HL, the low byte of the caller's return address.
4E54
CP E3H FE E3
Compare Register A, the low byte, against E3H, the low byte of 05E3H.
4E56
RET NZ C0
If the NZ FLAG is set (not 05E3H), RETURN with the NZ FLAG: no chain key for this request.
4E57
LD A,(428DH) 3A 8D 42
Load Register A with the byte at 428DH, the options copied from system data sector byte F1H.
4E5A
AND 40H E6 40
Mask Register A against 40H (0100 0000) to keep bit 6, option BC (arrow keys control the chain file).
4E5C
If the Z FLAG is set (no option BC), JUMP to 4E66H.
4E5E
LD A,(3840H) 3A 40 38
Load Register A with the byte at 3840H, the keyboard row with ENTER (bit 0), the up arrow (bit 3) and the right arrow (bit 6).
4E61
AND 40H E6 40
Mask Register A against 40H (0100 0000) to keep bit 6, the right arrow key.
4E63
If the NZ FLAG is set (the right arrow is held down), JUMP to 4F03H to pause the chain file.
4E66
GOSUB to 4ED3H: with option BC, the up arrow held down aborts the chain file there.
4E69
LD A,(42C5H) 3A C5 42
Load Register A with the byte at 42C5H, the key held back by the previous request (00H for none).
4E6C
OR A B7
OR Register A, the held key, with itself: the NZ FLAG is set if one is waiting.
4E6D
If the NZ FLAG is set (a key is held back), JUMP to 4E90H to give it now.
4E6F
GOSUB to 4F50H to read the next byte of the chain file into Register A, with the Z FLAG, or the NZ FLAG and the error in Register A.
4E72
If the Z FLAG is set (a byte was read), JUMP to 4E90H with it in Register A.
4E74
CP 1CH FE 1C
Compare Register A, the error code, against 1CH, END OF FILE ENCOUNTERED.
4E76
If the NZ FLAG is set (any other error), JUMP to 4EE0H to abort the chain file and report the error in Register A.
4E78
GOSUB to 4EC5H to end the chain file: its FCB at 44A0H is closed and the chaining bits in 4289H and 428AH are cleared.
4E7B
OR 01H F6 01
OR Register A with 01H: the NZ FLAG is set, so the keyboard driver reads the keyboard instead.
4E7D
RET C9
RETURN to the keyboard driver with the NZ FLAG: no chain key.

85H Line: a CHNON Parameter
Register Pair HL = the line read into 4FD7H.

4E7E
GOSUB to 4D82H to take N, Y or D from the line at Register Pair HL and store the chaining bits in 4289H-428AH; Register Pair BC comes back with the new values.
4E81
If the NZ FLAG is set (the line was not N, Y or D and a carriage return), JUMP to 4F2EH to abort with error 01H.
4E84
LD A,(42C5H) 3A C5 42
Load Register A with the byte at 42C5H, the key held back while the 85H line was read.
4E87
GOSUB to 511BH with Register A = the held key: a key is given at once through 4E90H, whose RET comes back to 4E8AH; with none, under a DOS-CALL whose level does not own the chain file, 511BH jumps to 402DH.
4E8A
BIT 5,C CB 69
Test bit 5 of Register C: the new copy of 4289H from 4D82H (bit 5 set while chaining stays on), or, after 4E90H has given a held key, that key itself.
4E8C
If the Z FLAG is set (chaining is now off), JUMP to 4E7BH to return the NZ FLAG: no chain key.
4E8E
JUMP to 4E57H to give the next key of the chain file.

A Byte Was Read
Register A = the byte from the chain file or the held key.

4E90
LD B,A 47
Load Register B with Register A, the byte read (or held back).
4E91
LD C,A 4F
Load Register C with Register A, a second copy of the byte.
4E92
XOR A AF
Load Register A with 00H (XOR A with itself).
4E93
LD (42C5H),A 32 C5 42
Store Register A (00H) at 42C5H: no key is held back now.
4E96
LD A,B 78
Load Register A with Register B, the byte read.
4E97
SUB 80H D6 80
Subtract 80H from Register A: the codes 80H-85H become 00H-05H.
4E99
If the Z FLAG is set (80H, the start of a label line), JUMP to 4E78H to end the chain file: the section has ended.
4E9B
CP 04H FE 04
Compare Register A, the byte minus 80H, against 04H: the CARRY FLAG is set for the codes 81H-83H (lines to show or skip).
4E9D
If the CARRY FLAG is set (81H-83H), JUMP to 4EEEH to show or skip the line.
4E9F
CP 06H FE 06
Compare Register A, the byte minus 80H, against 06H: the CARRY FLAG is set for 84H and 85H (lines to act on).
4EA1
If the CARRY FLAG is set (84H or 85H), JUMP to 4F1BH to read the line into 4FD7H.

An Ordinary Key
Register B = the key; the next byte is read ahead into 42C5H.

4EA4
GOSUB to 4F50H to read the byte after the key, with the Z FLAG, or the NZ FLAG and the error in Register A.
4EA7
LD (42C5H),A 32 C5 42
Store Register A, the byte read ahead (or the error code), at 42C5H, the key held back for the next request. LD does not change the flags.
4EAA
If the NZ FLAG is set (a read error), JUMP to 4EB0H.
4EAC
CP 80H FE 80
Compare Register A, the byte read ahead, against 80H: the Z FLAG is set if a label line follows, which ends the chain file.
4EAE
JUMP to 4EB4H with the Z FLAG from the compare: set when the byte read ahead is 80H, a label line.
4EB0
CP 1CH FE 1C
Compare Register A, the error code, against 1CH, END OF FILE ENCOUNTERED: the key in Register B was the file's last byte.
4EB2
If the NZ FLAG is set (any other error), JUMP to 4EE0H to abort the chain file and report the error in Register A.
4EB4
If the Z FLAG is set (the end of the file, or a label line next), GOSUB to 4EC5H to end the chain file after this key.
4EB7
CP 85H FE 85
Compare Register A, the byte read ahead, against 85H, the code of a CHNON line.
4EB9
If the Z FLAG is set (an 85H line follows), JUMP to 4F16H to act on it now and hold the key back.
4EBC
LD A,B 78
Load Register A with Register B, the key to give.
4EBD
CP A BF
Compare Register A with itself: the Z FLAG is set, the sign that Register A holds a key.
4EBE
RET C9
RETURN to the keyboard driver with the key in Register A and the Z FLAG.

4EBFH - Abort or End the Chain File

4EBFH shows Chaining Aborted and falls into 4EC5H, which ends the chain file: byte 0 of its FCB (44A0H) = 00H (not open), 4289H bit 5 and 428AH bit 4 cleared.

4EBF
LD HL,4FA2H 21 A2 4F
Load Register Pair HL with 4FA2H, the text Aborted and a carriage return.
4EC2
GOSUB to 4F45H to display Chaining and the text at Register Pair HL: Chaining Aborted.
4EC5
LD HL,44A0H 21 A0 44
Load Register Pair HL with 44A0H, byte 0 of the chain FCB.
4EC8
LD (HL),00H 36 00
Store 00H at Register Pair HL (44A0H): the chain FCB is no longer open.
4ECA
LD HL,4289H 21 89 42
Load Register Pair HL with 4289H, the system flags.
4ECD
RES 5,(HL) CB AE
Reset bit 5 of the byte at Register Pair HL (4289H): no chain file supplies the keys; the keyboard driver stops calling SYS9/SYS.
4ECF
INC HL 23
Increment Register Pair HL to 428AH, the DOS state flags.
4ED0
RES 4,(HL) CB A6
Reset bit 4 of the byte at Register Pair HL (428AH): no chain file belongs to the DOS-CALL level.
4ED2
RET C9
RETURN with Register A and the flags unchanged.

4ED3H - Up Arrow: Abort the Chain File

With option BC (428DH bit 6), the up arrow held down (3840H bit 3) aborts the chain file through 4EE0H with Register A = 00H; otherwise RETURN.

4ED3
LD A,(3840H) 3A 40 38
Load Register A with the byte at 3840H, the keyboard row with ENTER (bit 0) and the up arrow (bit 3).
4ED6
AND 08H E6 08
Mask Register A against 08H (0000 1000) to keep bit 3, the up arrow key.
4ED8
RET Z C8
If the Z FLAG is set (the up arrow is not held down), RETURN.
4ED9
LD A,(428DH) 3A 8D 42
Load Register A with the byte at 428DH, the options copied from system data sector byte F1H.
4EDC
AND 40H E6 40
Mask Register A against 40H (0100 0000) to keep bit 6, option BC.
4EDE
RET Z C8
If the Z FLAG is set (no option BC), RETURN: the arrow keys do not control the chain file.
4EDF
XOR A AF
Load Register A with 00H (XOR A with itself): no error code to report, only the abort.
4EE0
PUSH AF F5
Save Register Pair AF (Register A = the error code, 00H for an abort by the up arrow) on the stack.
4EE1
PUSH AF F5
Save Register Pair AF on the stack again, so that 4EE5H-4EE6H find the same word as for sub-function 4.
4EE2
Sub-function 4 (SYS1/SYS after an error while chaining, its error word on the stack): GOSUB to 4EBFH to show Chaining Aborted and end the chain file.
4EE5
POP AF F1
Restore Register Pair AF from the stack, discarding a word (the dispatcher's return address 4BC5H for sub-function 4).
4EE6
POP AF F1
Restore Register Pair AF from the stack: Register A = the error code (00H when the chain file was only aborted).
4EE7
OR A B7
OR Register A, the error code, with itself: the Z FLAG is set for 00H.
4EE8
If the Z FLAG is set (no error code), JUMP to 4030H, which ends the command as one whose message has been shown (SYS1/SYS function 2).
4EEB
JUMP to SYS0/SYS 4409H, the DOS error exit, to show the error in Register A.

4EEEH - 81H-83H Lines: Show or Skip

Register B = the code. The characters up to the carriage return are shown (ROM 0033H) for 81H and 83H (bit 0 of Register B set) and skipped for 82H. After an 81H line the chain file pauses (4F03H).

4EEE
GOSUB to 4F50H to read the next character of the line into Register A, with the Z FLAG, or the NZ FLAG and the error.
4EF1
If the NZ FLAG is set (a read error), JUMP to 4EE0H to abort the chain file and report the error in Register A.
4EF3
PUSH AF F5
Save Register Pair AF (Register A = the character) on the stack, because ROM 0033H returns with other flags.
4EF4
BIT 0,B CB 40
Test bit 0 of Register B, the code: bit 0 is set for 81H and 83H, the lines to show.
4EF6
If the NZ FLAG is set (81H or 83H), GOSUB to ROM 0033H to display the character in Register A.
4EF9
POP AF F1
Restore Register Pair AF from the stack: Register A = the character.
4EFA
CP 0DH FE 0D
Compare Register A, the character, against 0DH, the carriage return that ends the line.
4EFC
If the NZ FLAG is set (not the end of the line), LOOP back to 4EEEH for the next character.
4EFE
LD A,B 78
Load Register A with Register B, the code of the line.
4EFF
CP 81H FE 81
Compare Register A, the code, against 81H: the Z FLAG is set for a line followed by a pause.
4F01
If the NZ FLAG is set (82H or 83H), JUMP to 4F13H to give the next key.
4F03
LD HL,4FAAH 21 AA 4F
Load Register Pair HL with 4FAAH, the text PAUSE. Press 'ENTER' When Ready To Continue and a carriage return (also reached with the right arrow, 4E63H).
4F06
GOSUB to 4F45H to display Chaining and the text at Register Pair HL.

Wait for ENTER on the Keyboard Row

4F09
GOSUB to 4ED3H: with option BC, the up arrow aborts the chain file while it waits.
4F0C
LD A,(3840H) 3A 40 38
Load Register A with the byte at 3840H, the keyboard row with ENTER in bit 0.
4F0F
AND 01H E6 01
Mask Register A against 01H (0000 0001) to keep bit 0, the ENTER key.
4F11
If the Z FLAG is set (ENTER is not held down), LOOP back to 4F09H.
4F13
JUMP to 4E57H to give the next key of the chain file.

84H and 85H Lines
Register B = the code, or the key held back (4F16H).

4F16
LD C,A 4F
An 85H line follows the key in Register B: load Register C with Register A, 85H, the code of the line.
4F17
LD A,B 78
Load Register A with Register B, the key read before the 85H line.
4F18
LD (42C5H),A 32 C5 42
Store Register A (the key) at 42C5H, the key held back: it is given after the 85H line has been acted on.
4F1B
LD B,20H 06 20
Load Register B with 20H: the line may have up to 32 characters, the carriage return included.
4F1D
LD HL,4FD7H 21 D7 4F
Load Register Pair HL with 4FD7H, the 32 bytes 4FD7H-4FF6H inside SYS9/SYS (the MDCOPY code, not needed now) used for the line.
4F20
PUSH HL E5
Save Register Pair HL (4FD7H, the start of the line) on the stack.
4F21
GOSUB to 4F50H to read the next character of the line into Register A, with the Z FLAG, or the NZ FLAG and the error.
4F24
If the NZ FLAG is set (a read error), JUMP to 4EE0H to abort the chain file and report the error in Register A.
4F26
CP 0DH FE 0D
Compare Register A, the character, against 0DH, the carriage return that ends the line.
4F28
LD (HL),A 77
Store Register A, the character, at Register Pair HL in the line buffer at 4FD7H-4FF6H. LD does not change the flags.
4F29
INC HL 23
Increment Register Pair HL to the next position of the line buffer. INC HL does not change the flags.
4F2A
If the Z FLAG is set (the carriage return was stored), JUMP to 4F32H.
4F2C
Decrement Register B, the room left; if Register B is not 0, LOOP back to 4F21H.
4F2E
LD A,01H 3E 01
Load Register A with 01H, the error code BAD FILE DATA: the line is too long (or the 85H parameter was wrong, 4E81H), so the chain file is aborted with error 01H.
4F30
JUMP to 4EE0H to abort the chain file and report error 01H in Register A.
4F32
POP HL E1
Restore Register Pair HL from the stack: 4FD7H, the start of the line.
4F33
BIT 0,C CB 41
Test bit 0 of Register C, the code: bit 0 is set for 85H (a CHNON parameter) and clear for 84H (a label to go to).
4F35
If the NZ FLAG is set (85H), JUMP to 4E7EH to act on the parameter.
4F38
LD DE,44A0H 11 A0 44
84H: load Register Pair DE with 44A0H, the chain file's FCB.
4F3B
GOSUB to SYS0/SYS 443FH to rewind the file at Register Pair DE (44A0H) to its first byte.
4F3E
If the Z FLAG is set (rewound), GOSUB to 4E06H to read up to the line 80H label for the label at Register Pair HL (4FD7H).
4F41
If the NZ FLAG is set (the rewind failed or the label was not found), JUMP to 4EE0H to abort and report the error in Register A.
4F43
JUMP to 4F13H, which goes on with the next key after the label line.

4F45H - Show Chaining and a Message

Displays Chaining (4F98H) and then the text at Register Pair HL.

4F45
PUSH HL E5
Save Register Pair HL, the address of the message to follow, on the stack.
4F46
LD HL,4F98H 21 98 4F
Load Register Pair HL with 4F98H, the word Chaining and a space, ending in 03H.
4F49
GOSUB to SYS0/SYS 4467H to display the text at Register Pair HL (4F98H) up to its 03H.
4F4C
POP HL E1
Restore Register Pair HL from the stack: the message to follow.
4F4D
JUMP to SYS0/SYS 4467H to display the message at Register Pair HL and return from there.

4F50H - Read a Chain File Byte

Reads the next byte of the chain file through ROM 0013H, leaving out 00H bytes. The sequences /./0 to /./5 are returned as the codes 80H-85H; if a / is not followed by ./0-5, the file is moved back (4445H with the number of extra bytes read as the record length in 44A9H) and the / is returned. Bytes 86H and up are returned with bit 7 cleared. Returns the Z FLAG with the byte in Register A, or the NZ FLAG with the error code (1CH at the end of the file).

4F50
GOSUB to 4F8CH to read the next byte other than 00H from the chain file into Register A.
4F53
RET NZ C0
If the NZ FLAG is set (a read error), RETURN with the error code in Register A.
4F54
PUSH BC C5
Save Register Pair BC on the stack, because Registers B and C are used here.
4F55
CP 2FH FE 2F
Compare Register A, the byte, against 2FH, the slash that may start a code.
4F57
LD B,A 47
Load Register B with Register A, the byte, to return if no code follows. LD does not change the flags.
4F58
LD A,(44A5H) 3A A5 44
Load Register A with the byte at 44A5H, byte 5 of the chain FCB: the position of the next byte in the sector (NEXT low byte).
4F5B
LD C,A 4F
Load Register C with Register A, the position after the slash, to work out how far to go back.
4F5C
If the Z FLAG is set (the byte was a slash), GOSUB to 4F8CH to read the next byte into Register A.
4F5F
If the NZ FLAG is set (not a slash, or a read error), JUMP to 4F76H.
4F61
CP 2EH FE 2E
Compare Register A, the byte after the slash, against 2EH, a period.
4F63
If the Z FLAG is set (a period), GOSUB to 4F8CH to read the next byte into Register A.
4F66
If the NZ FLAG is set (no period, or a read error), JUMP to 4F76H to go back.
4F68
CP B B8
Compare Register A, the byte after the period, against Register B, the slash.
4F69
If the Z FLAG is set (a second slash), GOSUB to 4F8CH to read the digit into Register A.
4F6C
If the NZ FLAG is set (no second slash, or a read error), JUMP to 4F76H to go back.
4F6E
SUB 30H D6 30
Subtract 30H from Register A, the character after /./: the digits 0-5 become 00H-05H.
4F70
CP 06H FE 06
Compare Register A, the digit's value, against 06H: the CARRY FLAG is set for 0-5.
4F72
SET 7,A CB FF
Set bit 7 of Register A: the digits 0-5 become the codes 80H-85H. SET does not change the flags.
4F74
If the CARRY FLAG is set (a code 80H-85H), JUMP to 4F89H to return it with the Z FLAG.
4F76
LD A,(44A5H) 3A A5 44
Load Register A with the byte at 44A5H, the chain FCB's position in the sector now.
4F79
SUB C 91
Subtract Register C, the position after the slash, from Register A: Register A = the extra bytes read after the slash (0 if none).
4F7A
LD (44A9H),A 32 A9 44
Store Register A (the extra bytes) at 44A9H, byte 9 of the chain FCB, its record length, for the move back.
4F7D
If the NZ FLAG is set (bytes were read after the slash), GOSUB to SYS0/SYS 4445H to move the chain file back one record, that number of bytes.
4F80
If the NZ FLAG is set (the move back failed), JUMP to 4F8AH to return the error.
4F82
LD A,B 78
Load Register A with Register B, the byte read first (the slash or an ordinary byte).
4F83
CP 86H FE 86
Compare Register A, the byte, against 86H: the CARRY FLAG is set for anything below 86H.
4F85
If the CARRY FLAG is set (below 86H), JUMP to 4F89H to return it as it is.
4F87
AND 7FH E6 7F
Mask Register A against 7FH (0111 1111) to clear bit 7: bytes 86H and up come back as 06H-7FH.
4F89
CP A BF
Compare Register A with itself: the Z FLAG is set, the sign that Register A holds a byte.
4F8A
POP BC C1
Restore Register Pair BC from the stack: the caller's Register Pair BC. POP does not change the flags.
4F8B
RET C9
RETURN with the Z FLAG and the byte in Register A, or the NZ FLAG and the error code.
4F8C
LD DE,44A0H 11 A0 44
Load Register Pair DE with 44A0H, the chain file's FCB.
4F8F
GOSUB to ROM 0013H to read a byte from the control block at Register Pair DE: its type byte does not match the input type, so the ROM's dispatcher goes through 4033H to SYS0/SYS 4A80H, which reads the next byte of the file into Register A.
4F92
RET NZ C0
If the NZ FLAG is set (a read error, 1CH at the end of the file), RETURN with the error code in Register A.
4F93
OR A B7
OR Register A, the byte read, with itself: the Z FLAG is set for 00H.
4F94
If the Z FLAG is set (a 00H byte), LOOP back to 4F8CH: 00H bytes in the chain file are left out.
4F96
CP A BF
Compare Register A with itself: the Z FLAG is set, the sign that Register A holds a byte.
4F97
RET C9
RETURN with the Z FLAG and the byte in Register A.

4F98H - Chaining Messages

Shown by 4F45H (Chaining, then Aborted or the PAUSE text) and 4D55H (the PAUSE command, from 4FB2H on). Texts ending in 03H leave the line open; 0DH ends it.

4F98-4FA1
DEFM "Chaining " / DEFB 03H 43 68 61 69 6E 69 6E 67 20 03
The word shown first by 4F45H (4F46H), ending in 03H so that the message follows on the same line.
4FA2-4FA9
DEFM "Aborted" / DEFB 0DH 41 62 6F 72 74 65 64 0D
Shown after Chaining when the chain file is aborted (4EBFH).
4FAA-4FD6
DEFM "PAUSE. Press 'ENTER' When Ready To Continue" / DEFB 0DH 50 41 55 53 45 2E 20 20 50 72 65 73 73 20 27 45 4E 54 45 52 27 20 57 68 65 6E 20 52 65 61 64 79 20 54 6F 20 43 6F 6E 74 69 6E 75 65 0D
Shown after Chaining for an 81H line or the right arrow (4F03H). The PAUSE command shows it from 4FB2H, the word Press, on (4D55H).

4FD7H - MDCOPY Command

SYS1/SYS has opened the source file in the DOS FCB at 4480H and parsed the second filespec into the FCB at 51E0H. The two files share the sector buffer 4DDCH-4EDBH inside SYS9/SYS. The destination is opened (SYS2/SYS code 44H), given its full size by writing its last sector first (4439H at relative sector EOF - 1), then the source is copied sector by sector from the start. The destination gets the source's EOF, is rewound, read through once, and closed (4428H). Each step that may load another overlay is called through 4DC7H, which reloads SYS9/SYS afterwards; 4288H is set to 00H after each, because the buffer has overwritten SYS9/SYS's code and the next overlay load must not find it already resident.

4FD7
LD DE,51E0H 11 E0 51
Load Register Pair DE with 51E0H, the FCB of the destination file that SYS1/SYS parsed from the second filespec. The bytes 4FD7H-4FF6H are later the line buffer of an 84H or 85H chain line (4F1DH).
4FDA
LD HL,4DDCH 21 DC 4D
Load Register Pair HL with 4DDCH, the 256 bytes 4DDCH-4EDBH inside SYS9/SYS (the chain code, not needed now), the buffer of both files.
4FDD
LD (4483H),HL 22 83 44
Store Register Pair HL, 4DDCH, at 4483H, bytes 3-4 of the source FCB at 4480H: its buffer address.
4FE0
LD A,44H 3E 44
Load Register A with 44H, the RST 28H code of SYS2/SYS function 2: open the file at Register Pair DE (51E0H), new or existing, with the buffer at Register Pair HL (4DDCH).
4FE2
GOSUB to 4DC7H to call SYS2/SYS with Register A = 44H and come back to SYS9/SYS reloaded; an error goes to the DOS error exit instead.
4FE5
LD A,00H 3E 00
Self-Modifying Code
Load Register A with 00H, the operand at 4FE6H (no instruction in SYS9/SYS changes it).
4FE7
LD (4288H),A 32 88 42
Store Register A (00H) at 4288H, the slot of the overlay in 4D00H-51FFH: no overlay is marked resident, because the buffer at 4DDCH will overwrite SYS9/SYS's code.
4FEA
LD HL,(448CH) 2A 8C 44
Load Register Pair HL with the 16-bit value at 448CH, bytes 12-13 of the source FCB: the EOF middle and high bytes (the sector count).
4FED
LD A,(4488H) 3A 88 44
Load Register A with the byte at 4488H, byte 8 of the source FCB: the EOF low byte.
4FF0
OR A B7
OR Register A, the EOF low byte, with itself: the Z FLAG is set if the file ends on a sector boundary.
4FF1
If the NZ FLAG is set (a partly used last sector), JUMP to 4FF4H: Register Pair HL is already the number of the last sector.
4FF3
DEC HL 2B
Decrement Register Pair HL: the file ends on a boundary, so its last sector is one below the count.
4FF4
LD A,H 7C
Load Register A with Register H, the high byte of the last sector's number.
4FF5
AND L A5
AND Register A with Register L, the low byte: Register A = FFH only if Register Pair HL is FFFFH (an empty source file).
4FF6
INC A 3C
Increment Register A: the Z FLAG is set if Register Pair HL is FFFFH.
4FF7
If the Z FLAG is set (an empty file), JUMP to 5026H to give the destination the source's EOF. The bytes 4FF7H-50F6H are the chain file's buffer while chaining (4DE5H).
4FF9
LD (51EAH),HL 22 EA 51
Store Register Pair HL, the last sector's number, at 51EAH, bytes 10-11 of the destination FCB at 51E0H: its NEXT, so that the next write goes to that sector.
4FFC
EXX D9
Exchange Register Pairs BC, DE and HL with the alternate set, to load the alternate Register Pair HL.
4FFD
LD HL,4439H 21 39 44
Load Register Pair HL (alternate) with 4439H, the SYS0/SYS write vector, the routine 4DC7H is to call.
5000
EXX D9
Exchange Register Pairs BC, DE and HL with the alternate set again: Register Pair DE = 51E0H, the destination FCB.
5001
XOR A AF
Load Register A with 00H (XOR A with itself): 4DC7H is to call the SYS0/SYS routine in the alternate Register Pair HL.
5002
GOSUB to 4DC7H to write the buffer to the destination's last sector through 4439H; this allocates all the destination's space (SYS2/SYS may be loaded) and SYS9/SYS is reloaded afterwards.
5005
LD A,00H 3E 00
Self-Modifying Code
Load Register A with 00H, the operand at 5006H (no instruction in SYS9/SYS changes it).
5007
LD (4288H),A 32 88 42
Store Register A (00H) at 4288H: no overlay is marked resident while the buffer overwrites SYS9/SYS.
500A
GOSUB to SYS0/SYS 443FH to rewind the file at Register Pair DE (51E0H, the destination) to its first sector.
500D
RET NZ C0
If the NZ FLAG is set (the rewind failed), RETURN through 4BC5H to SYS0/SYS 4408H with the error code in Register A.

Copy Loop
One sector at a time through the buffer at 4DDCH.

500E
LD DE,4480H 11 80 44
Load Register Pair DE with 4480H, the source FCB.
5011
GOSUB to SYS0/SYS 4436H to read the next sector of the file at Register Pair DE (the source) into its buffer at 4DDCH.
5014
If the NZ FLAG is set (no more sectors, or a read error), JUMP to 501FH to look at the error code in Register A.
5016
LD DE,51E0H 11 E0 51
Load Register Pair DE with 51E0H, the destination FCB.
5019
GOSUB to SYS0/SYS 4439H to write the buffer at 4DDCH as the next sector of the file at Register Pair DE (the destination).
501C
RET NZ C0
If the NZ FLAG is set (the write failed), RETURN through 4BC5H to SYS0/SYS 4408H with the error code in Register A.
501D
LOOP back to 500EH to read the next sector of the source (DE = 4480H again there).
501F
CP 1CH FE 1C
Compare Register A, the error code from the read, against 1CH, END OF FILE ENCOUNTERED.
5021
If the Z FLAG is set (1CH, every sector has been copied), JUMP to 5026H.
5023
CP 1DH FE 1D
Compare Register A, the error code, against 1DH, PAST END OF FILE.
5025
RET NZ C0
If the NZ FLAG is set (any other error), RETURN through 4BC5H to SYS0/SYS 4408H with the error code in Register A.
5026
LD HL,(448CH) 2A 8C 44
Load Register Pair HL with the 16-bit value at 448CH, bytes 12-13 of the source FCB: the EOF middle and high bytes.
5029
LD (51ECH),HL 22 EC 51
Store Register Pair HL at 51ECH, bytes 12-13 of the destination FCB: the destination gets the source's EOF middle and high bytes.
502C
LD A,(4488H) 3A 88 44
Load Register A with the byte at 4488H, byte 8 of the source FCB: the EOF low byte.
502F
LD (51E8H),A 32 E8 51
Store Register A, the EOF low byte, at 51E8H, byte 8 of the destination FCB.
5032
LD DE,51E0H 11 E0 51
Load Register Pair DE with 51E0H, the destination FCB.
5035
GOSUB to SYS0/SYS 443FH to rewind the file at Register Pair DE (the destination).
5038
RET NZ C0
If the NZ FLAG is set (the rewind failed), RETURN through 4BC5H to SYS0/SYS 4408H with the error code in Register A.

Read the Destination Through

5039
GOSUB to SYS0/SYS 4436H to read the next sector of the file at Register Pair DE (the destination) into the buffer at 4DDCH.
503C
If the Z FLAG is set (a sector was read), LOOP back to 5039H for the next.
503E
CP 1CH FE 1C
Compare Register A, the error code, against 1CH, END OF FILE ENCOUNTERED.
5040
If the Z FLAG is set (1CH, the whole destination was read), JUMP to 5045H to close it.
5042
CP 1DH FE 1D
Compare Register A, the error code, against 1DH, PAST END OF FILE.
5044
RET NZ C0
If the NZ FLAG is set (any other error), RETURN through 4BC5H to SYS0/SYS 4408H with the error code in Register A.
5045
JUMP to SYS0/SYS 4428H to close the file at Register Pair DE (51E0H, the destination; RST 28H code 25H, SYS3/SYS); the result goes through 4BC5H to SYS0/SYS 4408H.

5048H - Named Routines: Enqueue and Dequeue

A named routine is a block at 5200H or above: +0 the address of +2 (a check), +2 the link to the next block (0000H at the end), +4 the eight-character name, and the routine itself from +12. The queue starts at 4058H. 5048H (code 2BH, vector 4461H) puts the block at Register Pair HL at the head of the queue; error 35H if the name is already queued. 505FH (code 4BH, vector 4464H) takes the block with the name at Register Pair HL + 4 out of the queue; error 18H if there is none.

5048
Enqueue: GOSUB to 50A3H to check that the block at Register Pair HL is at 5200H or above and look for its name (Register Pair HL + 4) in the queue; Register Pair HL comes back pointing to the name.
504B
RET NZ C0
If the NZ FLAG is set (the name is already queued, error 35H in Register A), RETURN through 4BC5H to SYS0/SYS 4408H with it.
504C
DEC HL 2B
Decrement Register Pair HL from the name (block + 4) to block + 3, the high byte of the link word.
504D
LD DE,(4058H) ED 5B 58 40
Load Register Pair DE with the 16-bit value at 4058H, the head of the queue: the first block now (0000H when empty).
5051
LD (HL),D 72
Store Register D, the high byte of the old head, at Register Pair HL (block + 3).
5052
DEC HL 2B
Decrement Register Pair HL to block + 2, the low byte of the link word.
5053
LD (HL),E 73
Store Register E, the low byte of the old head, at Register Pair HL: the block links to the old first block.
5054
LD D,H 54
Load Register D with Register H, the high byte of block + 2.
5055
LD E,L 5D
Load Register E with Register L: Register Pair DE = block + 2, the value the check word must hold.
5056
DEC HL 2B
Decrement Register Pair HL to block + 1, the high byte of the check word.
5057
LD (HL),D 72
Store Register D, the high byte of block + 2, at Register Pair HL (block + 1).
5058
DEC HL 2B
Decrement Register Pair HL to block + 0, the low byte of the check word.
5059
LD (HL),E 73
Store Register E, the low byte of block + 2, at Register Pair HL: the check word at block + 0 = block + 2.
505A
LD (4058H),HL 22 58 40
Store Register Pair HL, the block's address, at 4058H: the block is now the head of the queue.
505D
XOR A AF
Load Register A with 00H (XOR A with itself), which also sets the Z FLAG: no error.
505E
RET C9
RETURN through 4BC5H to the caller of 4461H with Register A = 00H and the Z FLAG set.
505F
Dequeue: GOSUB to 50A3H to look for the name at Register Pair HL + 4 in the queue; when found it returns the NZ FLAG with Register Pair HL = the block + 2 and Register Pair DE = the link word that points to the block.
5062
If the Z FLAG is set (the name is not in the queue), JUMP to 509EH for error 18H.
5064
XOR A AF
Load Register A with 00H (XOR A with itself), which also sets the Z FLAG for the return.
5065
DEC HL 2B
Decrement Register Pair HL from block + 2 to block + 1, the high byte of the check word.
5066
LD (HL),A 77
Store Register A (00H) at Register Pair HL (block + 1): the check word no longer matches, so the block is not valid any more.
5067
INC HL 23
Increment Register Pair HL to block + 2, the low byte of the block's link.
5068
LD C,(HL) 4E
Load Register C with the byte at Register Pair HL, the low byte of the link to the next block.
5069
INC HL 23
Increment Register Pair HL to block + 3, the high byte of the link.
506A
LD B,(HL) 46
Load Register B with the byte at Register Pair HL: Register Pair BC = the next block (0000H if this was the last).
506B
EX DE,HL EB
Exchange Register Pairs DE and HL: Register Pair HL = the link word that pointed to this block (4058H or block + 2 of the one before).
506C
LD (HL),C 71
Store Register C, the low byte of the next block's address, at Register Pair HL.
506D
INC HL 23
Increment Register Pair HL to the high byte of that link word.
506E
LD (HL),B 70
Store Register B, the high byte, at Register Pair HL: the block is taken out of the queue.
506F
RET C9
RETURN through 4BC5H to the caller of 4464H with Register A = 00H and the Z FLAG set.

5070H - Call a Named Routine (*name)

Sub-function 7: the command line is *name. The name (one to eight characters up to a comma, a space or the end of the line) is copied to 51E0H and padded with spaces, looked for in the queue (50ADH) and its routine, at block + 12, is run with Register Pair HL = the command line after the name; it returns to SYS0/SYS 4408H. Error 2FH for an empty or too long name, 18H if the name is not queued.

5070
LD DE,51E0H 11 E0 51
Load Register Pair DE with 51E0H, a buffer past the end of SYS9/SYS's file, for the name.
5073
LD B,09H 06 09
Load Register B with 09H: room for eight characters, the ninth means the name is too long.
5075
PUSH DE D5
Save Register Pair DE (51E0H, the name) on the stack.

Copy the Name
Register Pair HL = the command line, Register Pair DE = the buffer, Register B = the room left.

5076
INC HL 23
Increment Register Pair HL past the asterisk (then past each character copied).
5077
GOSUB to SYS0/SYS 4C7AH with Register Pair HL = the command line: the NO CARRY FLAG at the end of the line or after a separator, the CARRY FLAG before an ordinary character.
507A
If the NO CARRY FLAG is set (the name has ended), JUMP to 5083H with Register B = the room left.
507C
LD A,(HL) 7E
Load Register A with the byte at Register Pair HL, a character of the name.
507D
LD (DE),A 12
Store Register A, the character, at Register Pair DE in the name buffer at 51E0H.
507E
INC DE 13
Increment Register Pair DE to the next position of the name buffer.
507F
Decrement Register B, the room left; if Register B is not 0, LOOP back to 5076H.
5081
LD B,09H 06 09
Load Register B with 09H: nine characters were copied without an end, which 5084H takes as an error, like an empty name.
5083
LD A,B 78
Load Register A with Register B, the room left.
5084
CP 09H FE 09
Compare Register A, the room left, against 09H: the Z FLAG is set if no character was taken (or nine were).
5086
If the Z FLAG is set (an empty or too long name), JUMP to 4D4CH for error 2FH BAD PARAMETER(S).

Pad with Spaces
Register B = the positions left in the nine bytes from 51E0H.

5089
LD A,20H 3E 20
Load Register A with 20H, a space, to pad the name buffer at Register Pair DE.
508B
LD (DE),A 12
Store Register A (a space) at Register Pair DE in the name buffer.
508C
INC DE 13
Increment Register Pair DE to the next position of the name buffer.
508D
Decrement Register B, the positions left; if Register B is not 0, LOOP back to 5089H.
508F
EX (SP),HL E3
Exchange Register Pair HL with the word at the top of the stack (at the Stack Pointer SP): Register Pair HL = 51E0H, the name, and the command line pointer is kept on the stack.
5090
GOSUB to 50ADH to look for the name at Register Pair HL in the queue: the NZ FLAG with Register Pair HL = block + 2 when found, the Z FLAG when not.
5093
LD DE,000AH 11 0A 00
Load Register Pair DE with 000AH, the distance from block + 2 to the routine at block + 12.
5096
ADD HL,DE 19
Add Register Pair DE (000AH) to Register Pair HL: Register Pair HL = block + 12, the routine's entry. ADD HL does not change the Z FLAG.
5097
POP DE D1
Restore Register Pair DE from the stack: the command line pointer after the name.
5098
If the Z FLAG is set (the name is not queued), JUMP to 509EH for error 18H.
509A
EX (SP),HL E3
Exchange Register Pair HL with the word at the top of the stack (at the Stack Pointer SP): the routine's entry goes on the stack and Register Pair HL = the dispatcher's return address 4BC5H.
509B
PUSH HL E5
Save Register Pair HL (4BC5H) on the stack above the routine's entry.
509C
EX DE,HL EB
Exchange Register Pairs DE and HL: Register Pair HL = the command line pointer after the name.
509D
RET C9
RETURN to 4BC5H, the end of the dispatcher, which clears 4289H bit 6 and returns into the routine at block + 12 with Register Pair HL = the command line; the routine returns to SYS0/SYS 4408H.
509E
LD A,18H 3E 18
Load Register A with 18H, the error code FILE NOT IN DIRECTORY: the name is not in the queue.
50A0
JUMP to 4D4EH to return error 18H through SYS0/SYS 4409H.

50A3H - Look for a Named Routine

50A3H: Register Pair HL = a block, which must be at 5200H or above (else error 2FH); the name is at block + 4. 50ADH: Register Pair HL = the name. The queue from 4058H is walked; a block whose check word is not its own address + 2 gives DOS FATAL ERROR (4D46H). Returns the Z FLAG at the end of the queue (Register Pair HL = the name, Register Pair BC = the last link word), or the NZ FLAG with Register A = 35H when the name is found (Register Pair HL = block + 2, Register Pair DE = the link word that points to the block, Register Pair BC = the name).

50A3
LD A,H 7C
Load Register A with Register H, the high byte of the block's address.
50A4
CP 52H FE 52
Compare Register A, the high byte, against 52H: the CARRY FLAG is set for a block below 5200H.
50A6
If the CARRY FLAG is set (the block is below 5200H), JUMP to 4D4CH for error 2FH BAD PARAMETER(S).
50A9
INC HL 23
Increment Register Pair HL, the block pointer, to block + 1.
50AA
INC HL 23
Increment Register Pair HL, the block pointer, to block + 2.
50AB
INC HL 23
Increment Register Pair HL, the block pointer, to block + 3.
50AC
INC HL 23
Increment Register Pair HL, the block pointer, to block + 4, the name.
50AD
PUSH HL E5
Save Register Pair HL, the name to look for, on the stack.
50AE
LD HL,4058H 21 58 40
Load Register Pair HL with 4058H, the head of the queue, the first link word.
50B1
PUSH HL E5
Save Register Pair HL (the link word 4058H) on the stack.
50B2
PUSH HL E5
Save Register Pair HL again: the loop below pops one copy into Register Pair BC and one into Register Pair HL.

Queue Loop
The top two stack words are the link word to follow; Register Pair BC = its address.

50B3
POP BC C1
Restore Register Pair BC from the stack: discarded here, Register Pair BC is set from Register Pair HL below.
50B4
POP HL E1
Restore Register Pair HL from the stack: the address of the link word to follow (4058H, or block + 2 of the block just looked at).
50B5
LD B,H 44
Load Register B with Register H, the high byte of the link word's address.
50B6
LD C,L 4D
Load Register C with Register L: Register Pair BC = the link word's address.
50B7
LD E,(HL) 5E
Load Register E with the byte at Register Pair HL, the low byte of the link: the next block.
50B8
INC HL 23
Increment Register Pair HL to the high byte of the link word.
50B9
LD D,(HL) 56
Load Register D with the byte at Register Pair HL: Register Pair DE = the next block (0000H at the end of the queue).
50BA
LD A,D 7A
Load Register A with Register D, the high byte of the next block's address.
50BB
OR E B3
OR Register A with Register E, the low byte: the Z FLAG is set if the link is 0000H.
50BC
If the NZ FLAG is set (there is a next block), JUMP to 50C0H to check it.
50BE
POP HL E1
Restore Register Pair HL from the stack: the name looked for.
50BF
RET C9
RETURN with the Z FLAG: the name is not in the queue, and Register Pair BC = the address of the last link word.
50C0
EX DE,HL EB
Exchange Register Pairs DE and HL: Register Pair HL = the next block.
50C1
LD E,(HL) 5E
Load Register E with the byte at Register Pair HL, the low byte of the block's check word (block + 0).
50C2
INC HL 23
Increment Register Pair HL, the block pointer, to block + 1, the high byte of the check word.
50C3
LD D,(HL) 56
Load Register D with the byte at Register Pair HL: Register Pair DE = the check word, which must be block + 2.
50C4
INC HL 23
Increment Register Pair HL to block + 2, the block's link word.
50C5
OR A B7
OR Register A with itself to clear the CARRY FLAG before the SBC.
50C6
SBC HL,DE ED 52
Subtract Register Pair DE (the check word) from Register Pair HL (block + 2): the Z FLAG is set if they are equal.
50C8
POP HL E1
Restore Register Pair HL from the stack: the name looked for. POP does not change the flags.
50C9
If the NZ FLAG is set (the check word is wrong: the queue is damaged), JUMP to 4D46H for DOS FATAL ERROR.
50CC
PUSH HL E5
Save Register Pair HL, the name looked for, on the stack.
50CD
PUSH DE D5
Save Register Pair DE, block + 2 (the block's link word), on the stack.
50CE
PUSH BC C5
Save Register Pair BC, the link word that points to this block, on the stack.
50CF
INC DE 13
Increment Register Pair DE from block + 2 to block + 3.
50D0
INC DE 13
Increment Register Pair DE to block + 4, the block's name.
50D1
LD B,08H 06 08
Load Register B with 08H, the eight characters of a name.

Compare the Names
Register Pair DE = the block's name, Register Pair HL = the name looked for, Register B = the characters left.

50D3
LD A,(DE) 1A
Load Register A with the byte at Register Pair DE, a character of the block's name.
50D4
SUB (HL) 96
Subtract the byte at Register Pair HL, the character looked for, from Register A: the Z FLAG is set if they are equal.
50D5
INC DE 13
Increment Register Pair DE to the block's next character. INC DE does not change the flags.
50D6
INC HL 23
Increment Register Pair HL to the next character looked for. INC HL does not change the flags.
50D7
If the NZ FLAG is set (the names differ), LOOP back to 50B3H: the two stack words pushed at 50CDH-50CEH give Register Pair HL = block + 2, the link to follow next.
50D9
Decrement Register B, the characters left; if Register B is not 0, LOOP back to 50D3H.
50DB
POP DE D1
The names match: restore Register Pair DE from the stack: the link word that points to this block (pushed as Register Pair BC).
50DC
POP HL E1
Restore Register Pair HL from the stack: block + 2 (pushed as Register Pair DE).
50DD
POP BC C1
Restore Register Pair BC from the stack: the name looked for (pushed as Register Pair HL).
50DE
OR 35H F6 35
OR Register A (00H after the last match) with 35H: Register A = 35H, the error code FILE ALREADY EXISTS, and the NZ FLAG.
50E0
RET C9
RETURN with the NZ FLAG and Register A = 35H: the name is in the queue.

50E1H - Messages for DOS FATAL ERROR and RUN ONLY

Shown by 4DACH-4DBAH.

50E1-50F3
DEFM "'RUN ONLY' STOPPED" / DEFB 03H 27 52 55 4E 20 4F 4E 4C 59 27 20 53 54 4F 50 50 45 44 03
Shown by sub-function 0CH (4DB1H) when RUN-ONLY reaches DOS READY, ending in 03H.
50F4-5103
DEFM "DOS FATAL ERROR" / DEFB 03H 44 4F 53 20 46 41 54 41 4C 20 45 52 52 4F 52 03
Shown by sub-function 0BH (4DACH), ending in 03H.
5104-511A
DEFM "!! KEY 'R' FOR RESET." / DEFB 0DH 21 21 20 20 4B 45 59 20 27 52 27 20 46 4F 52 20 52 45 53 45 54 2E 0D
Shown after either message (4DB7H); the R key restarts the computer.

511BH - After an 85H Line

Register A = the key held back (from 42C5H), Register B = the new 428AH flags from 4D82H. A held key is given through 4E90H. Otherwise, if a DOS-CALL is active (bit 6) and the chain file does not belong to its level (bit 4 clear), the command ends at 402DH; else RETURN.

511B
OR A B7
OR Register A, the key held back, with itself: the NZ FLAG is set if there is one.
511C
If the NZ FLAG is set (a key is held back), JUMP to 4E90H to give it; the RET there returns to the caller's 4E8AH.
511F
LD A,B 78
Load Register A with Register B, the new copy of 428AH from 4D82H.
5120
AND 50H E6 50
Mask Register A against 50H (0101 0000) to keep bit 6 (a DOS-CALL is active) and bit 4 (the chain file belongs to it).
5122
CP 40H FE 40
Compare Register A, those two bits, against 40H: the Z FLAG is set for a DOS-CALL whose level does not own the chain file.
5124
If the Z FLAG is set, JUMP to 402DH (DOS READY), which ends the DOS-CALL.
5127
RET C9
RETURN to 4E8AH with the chaining bits in Register C.
5128-51DF
DEFB 00H x 184 00 x 184
184 bytes of 00H at the end of the file; nothing reads them.
51E0-51FF
DEFS 32
Not in the file: the rest of the overlay area. MDCOPY's destination FCB (51E0H-51FFH, filled by SYS1/SYS from the second filespec; 51E8H, 51EAH and 51ECH written by 4FF9H, 5029H and 502FH) and the name buffer of a named routine call (51E0H-51E8H, 5070H).