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

Page Customization

Introduction/Summary

NEWDOS/80 v2.0 SYS1/SYS Disassembly - The Command Interpreter (Model III)

SYS1/SYS is the overlay (directory slot 03H) that runs the DOS command level. SYS0/SYS loads it into the overlay area at 4D00H through RST 28H and enters it at its first byte with the RST 28H code in Register A. It shows the NewDos/80 Ready and Mini-NewDos/80 Ready prompts, reads command lines into the command buffer at 4225H, looks the command name up in its table of 47 entries, parses the filespecs the command needs, opens the file if the command wants it, and starts the overlay function that carries out the command. It also handles DOS-CALL (commands run from a program, which can nest), MINI-DOS (entered with D-F-G from a running program), the exit after every command, filespec extraction, default extensions and the LIB, CLS, MDBORT and MDRET commands.

The file is 1,248 bytes in five load records, 4D00H-51DFH, transfer address 4D00H. Every byte is shown once on this page, checked against S:\1\SYS1.SYS and its listing.

Functions

CodeFunction
23HFunction 1: DOS READY with no error (SYS0/SYS 4400H, 402DH), 4D8AH.
43HFunction 2: the exit after an error that has already been displayed (SYS0/SYS 4030H), 4D7CH.
63HFunction 3: execute the command at Register Pair HL (SYS0/SYS 4405H), 4E47H.
83HFunction 4: extract a filespec (SYS0/SYS 441CH), 5154H.
A3HFunction 5: insert a default extension (SYS0/SYS 4473H), 4F41H.
C3HFunction 6: DOS-CALL (SYS0/SYS 4419H), 4D5BH.
E3HFunction 7, sub-function in Register C: 01H drop a word and return (4D59H), 02H LIB (50CEH), 03H refused (error 2AH), 04H enter MINI-DOS (50F2H, from D-F-G), 05H MDBORT (4D80H), 06H MDRET (5111H), 07H drop two words and exit (4D78H), 08H run the line typed at DOS READY (4E4BH), 09H CLS (4D48H), 0BH parse a filespec (5167H), 0CH the same as MDBORT; anything else error 2AH.

How a Command Runs

The line is copied into 4225H in upper case (at most 80 characters, else error 36H). With option BE a line of just R repeats the previous command, whose first two characters were saved at 42C7H. The name is looked up in the table at 4F6FH; its three attribute bytes give the sub-function and MINI-DOS restriction (byte 1), the RST 28H code of the overlay function (byte 2) and the filespec handling (byte 3: parse into 4480H, open the file existing or new, a second filespec into 51E0H, nothing may follow, keep the command line pointer, default extension /CMD or /JCL). A name that is not in the table is a program to run (SYS2/SYS function 7, sub-function 03H, default extension /CMD); a name that starts with an asterisk is a named routine (SYS9/SYS function 7, sub-function 07H). The overlay is started through SYS0/SYS 4978H, and every command returns to SYS0/SYS 4408H, which goes on to DOS READY (402DH) or to the error exit (4409H).

The Command Exit (4D8BH)

Every command ends at 4D8BH with Register A and the flags giving the result. An error at reset (bit 2 of 428AH) calls SYS9/SYS's DOS FATAL ERROR (sub-function 0BH); an error while chaining calls SYS9/SYS sub-function 04H; RUN-ONLY at DOS READY shows 'RUN ONLY' STOPPED (sub-function 0CH). A DOS-CALL returns to its caller with the result (4E27H). Otherwise the stack is reset to 41E0H, the BREAK hook at 4478H is set from option AG, the prompt is shown (not while chaining), the ROM's protected screen lines, its BREAK vector and the cassette motor are reset at plain DOS READY, and the next line is read with the ROM's line input.

Notes from the Code

  • 4D4EH-4D58H is never reached: nothing jumps there and SYS0/SYS enters the overlay only at 4D00H.
  • Sub-function 03H of function 7 is tested but always ends with error 2AH (4D24H).
  • The R command restores only the first two characters of the buffer: the ROM's line input overwrites only what is typed (4E76H-4E89H).
  • The letter test (51A0H) accepts lower case letters, so filespecs may be typed in lower case; the command line itself is converted to upper case (4E66H).
  • The table has an entry R (5087H) that runs SYS1/SYS function 1, DOS READY, when option BE is N.

Variables

Addresses Used by SYS1/SYS

AddressContents
4022H
1 byte
The ROM's cursor flag (00H = off), saved and restored by MINI-DOS (50FEH, 512BH).
4204H-4205H
2 bytes
The address part of the ROM's BREAK and disk error vector, set to 4030H at DOS READY (4E0BH).
4214H
1 byte
The ROM's count of protected screen lines, cleared at DOS READY (4E05H).
4225H-4274H
80 bytes
The command buffer (4E5AH-4E6BH); the line input reads into it (4E21H).
4289H
1 byte
System flags: bit 5 chaining (4DA8H, 4E00H), bit 6 an overlay function running (cleared 4DACH), bit 4 (cleared 4E3CH).
428AH
1 byte
DOS state flags: bit 7 MINI-DOS (5106H, 512FH), bit 6 DOS-CALL (4D67H, 4E3AH), bit 5 waiting at DOS READY (4DF8H, 4E58H), bit 4 a chain file at this DOS-CALL level (4E30H), bit 2 an error at reset (set by SYS4/SYS, tested 4D98H).
428BH
1 byte
The overlays' temporary flags, cleared after every command (4D8FH).
428CH
1 byte
Options: bit 6 AB RUN-ONLY (4DB5H), bit 5 AG BREAK as a key (4DCBH).
428DH
1 byte
Options: bit 5 BE, the R command (4E79H).
42BBH-42BCH
2 bytes
The Stack Pointer saved when MINI-DOS was entered (5102H; read 4DE3H, 5119H).
42BDH-42BEH
2 bytes
The Stack Pointer of the current DOS-CALL level (4D70H, 4E28H, 4E3EH).
42C7H-42C8H
2 bytes
The first two characters of the previous command line, for R (4E1CH, 4E86H).
4478H-447AH
3 bytes
The BREAK key hook, set to JP 4546H or RET from option AG (4DD0H, 4DD9H).
4480H-449FH
32 bytes
The DOS FCB, which receives a command's filespec (5164H) and is opened by 4F3BH/4F3EH.
4300H
256 bytes
The buffer given to the open (4F36H).
51E0H-51FFH
32 bytes
The second filespec of a command (4F01H), just past the end of the file.
41E0H
stack
The top of the DOS stack (4DC8H, 4E47H).

Disassembly

4D00H - Overlay Entry: Function Dispatcher

SYS0/SYS enters every overlay at its first byte. Register A holds the RST 28H code that loaded SYS1/SYS (xxx00011B: bits 5-7 are the function number). Functions 1-6 are chosen by Register A alone. Function 7 (E3H) uses Register C as a sub-function number, which the DEC C chain below counts down.

4D00
CP 23H FE 23
Compare Register A (the RST 28H code) against 23H, function 1: DOS READY (SYS0/SYS 4400H and 402DH).
4D02
If the Z FLAG is set (Register A = 23H), JUMP to 4D8AH to end with no error and show DOS READY.
4D05
CP 43H FE 43
Compare Register A (the RST 28H code) against 43H, function 2: error already displayed (SYS0/SYS 4030H).
4D07
If the Z FLAG is set (Register A = 43H), JUMP to 4D7CH to end with an error exit that shows nothing.
4D09
CP 63H FE 63
Compare Register A (the RST 28H code) against 63H, function 3: execute the DOS command at Register Pair HL (SYS0/SYS 4405H).
4D0B
If the Z FLAG is set (Register A = 63H), JUMP to 4E47H to run the command.
4D0E
CP 83H FE 83
Compare Register A (the RST 28H code) against 83H, function 4: extract a filespec from Register Pair HL into Register Pair DE (SYS0/SYS 441CH).
4D10
If the Z FLAG is set (Register A = 83H), JUMP to 5154H.
4D13
CP A3H FE A3
Compare Register A (the RST 28H code) against A3H, function 5: insert a default extension (SYS0/SYS 4473H).
4D15
If the Z FLAG is set (Register A = A3H), JUMP to 4F41H.
4D18
CP C3H FE C3
Compare Register A (the RST 28H code) against C3H, function 6: DOS-CALL (SYS0/SYS 4419H).
4D1A
If the Z FLAG is set (Register A = C3H), JUMP to 4D5BH.

Function 7 Sub-Function Chain
Anything else is taken as function 7 (E3H). Register C holds the sub-function number; each DEC C sets the Z FLAG when Register C reaches that number.

4D1C
DEC C 0D
DECrement Register C (the sub-function). The Z FLAG is set for sub-function 01H.
4D1D
If the Z FLAG is set (sub-function 01H), JUMP to 4D59H to drop one stack word and return.
4D1F
DEC C 0D
DECrement Register C. The Z FLAG is set for sub-function 02H.
4D20
If the Z FLAG is set (sub-function 02H, the LIB command), JUMP to 50CEH to list the command table.
4D23
DEC C 0D
DECrement Register C. The Z FLAG is set for sub-function 03H.
4D24
If the Z FLAG is set (sub-function 03H), JUMP to 4D32H. Register C is now 00H, so the countdown from 4D32H never reaches 0 again and the code ends at 4D44H with error 2AH: sub-function 03H is refused.
4D27
DEC C 0D
DECrement Register C. The Z FLAG is set for sub-function 04H.
4D28
If the Z FLAG is set (sub-function 04H, enter MINI-DOS, from SYS0/SYS's D-F-G check 45B0H), JUMP to 50F2H.
4D2B
DEC C 0D
DECrement Register C. The Z FLAG is set for sub-function 05H.
4D2C
If the Z FLAG is set (sub-function 05H, the MDBORT command), JUMP to 4D80H.
4D2E
DEC C 0D
DECrement Register C. The Z FLAG is set for sub-function 06H.
4D2F
If the Z FLAG is set (sub-function 06H, the MDRET command), JUMP to 5111H.
4D32
DEC C 0D
DECrement Register C. The Z FLAG is set for sub-function 07H. 4D24H also arrives here with Register C = 00H, which becomes FFH.
4D33
If the Z FLAG is set (sub-function 07H), JUMP to 4D78H.
4D35
DEC C 0D
DECrement Register C. The Z FLAG is set for sub-function 08H.
4D36
If the Z FLAG is set (sub-function 08H: a command line has been typed at DOS READY, see 4E11H), JUMP to 4E4BH to execute it.
4D39
DEC C 0D
DECrement Register C. The Z FLAG is set for sub-function 09H.
4D3A
If the Z FLAG is set (sub-function 09H, the CLS command), JUMP to 4D48H.
4D3C
DEC C 0D
DECrement Register C past sub-function 0AH, which has no handler and is not tested.
4D3D
DEC C 0D
DECrement Register C. The Z FLAG is set for sub-function 0BH.
4D3E
If the Z FLAG is set (sub-function 0BH), JUMP to 5167H to parse a filespec from the text at Register Pair HL into the buffer at Register Pair DE.
4D41
DEC C 0D
DECrement Register C. The Z FLAG is set for sub-function 0CH.
4D42
If the Z FLAG is set (sub-function 0CH), JUMP to 4D80H, the same code as MDBORT.

No Function Matched
Return error 2AH to the caller.

4D44
LD A,2AH 3E 2A
Load Register A with error code 2AH (ILLEGAL DOS FUNCTION). Also reached from 5116H (MDRET when MINI-DOS is not active).
4D46
OR A B7
OR Register A (2AH) with itself to set the NZ FLAG: an error.
4D47
RET C9
RETurn to the caller of the RST 28H with error 2AH in Register A.

4D48H - CLS Command (Function 7, Sub-Function 09H)

Clears the screen by sending the three bytes at 51DCH (1CH cursor home, 1FH clear to end of screen, 03H end of message) to the display.

4D48
LD HL,51DCH 21 DC 51
Point Register Pair HL to 51DCH, the clear-screen string (1CH, 1FH, 03H).
4D4B
JUMP to 4467H, the SYS0/SYS vector that displays the message at Register Pair HL. It returns straight to the caller of the CLS command.

4D4EH - Unreferenced Code

Nothing in SYS1/SYS jumps or calls to 4D4EH, and SYS0/SYS enters the overlay only at 4D00H. The bytes push E301H (function 7, sub-function 01H) and 4978H (the SYS0/SYS routine that issues an RST 28H with the word on the stack) and then do an RST 28H with whatever is in Register A.

4D4E
EXX D9
Exchange Register Pairs BC, DE and HL with the alternate set, so that the main BC, DE and HL are kept. Never executed.
4D4F
LD BC,E301H 01 01 E3
Load the alternate Register Pair BC with E301H: Register B = E3H (SYS1/SYS function 7), Register C = 01H (sub-function 01H). Never executed.
4D52
LD DE,4978H 11 78 49
Load the alternate Register Pair DE with 4978H, the SYS0/SYS routine that takes an RST 28H code and sub-function from the stack. Never executed.
4D55
PUSH BC C5
Save Register Pair BC (E301H) onto the stack. Never executed.
4D56
PUSH DE D5
Save Register Pair DE (4978H) onto the stack as a return address. Never executed.
4D57
EXX D9
Exchange back to the main register set (alternate set restored). Never executed.
4D58
RST 28H EF
RST 28H with whatever Register A holds. Never executed (nothing reaches 4D4EH).

4D59H - Sub-Function 01H: Discard a Word and Return

Also the end of the unreferenced 4D4EH block. Used by callers that pushed E301H and 4978H to get back from another overlay function (the word E301H is dropped here).

4D59
POP AF F1
Restore Register Pair AF from the stack to drop the top word (Register A and the flags are not used).
4D5A
RET C9
RETurn to the address below it on the stack, the caller that pushed the dropped word.

4D5BH - Function 6: DOS-CALL

Entered through SYS0/SYS 4419H with Register Pair HL pointing to a DOS command. All registers are saved (5142H). DOS-CALLs can nest: bit 6 of 428AH shows that one is active, and each level pushes the previous level's saved Stack Pointer (42BDH) before storing its own. The command is then run by the normal command code at 4E4CH. When it finishes, the exit code at 4E27H unwinds one level and returns to the caller.

4D5B
GOSUB to 5142H to save Register Pairs HL, DE, BC, the alternate set, AF', IX and IY on the stack.
4D5E
LD BC,0000H 01 00 00
Load Register Pair BC with 0000H: no previous DOS-CALL level so far.
4D61
EX DE,HL EB
Exchange Register Pairs DE and HL: Register Pair DE keeps the command pointer while Register Pair HL is used.
4D62
LD HL,428AH 21 8A 42
Point Register Pair HL to 428AH, the DOS state flags (bit 6 = DOS-CALL active).
4D65
BIT 6,(HL) CB 76
Test bit 6 of the flags at Register Pair HL (428AH): a DOS-CALL is already active. The Z FLAG is set for the first level.
4D67
SET 6,(HL) CB F6
Set bit 6 of the flags at Register Pair HL (428AH): a DOS-CALL is now active. SET does not change the flags.
4D69
If the Z FLAG is set (the first level), JUMP to 4D6FH with Register Pair BC = 0000H.
4D6B
LD BC,(42BDH) ED 4B BD 42
A nested DOS-CALL: load Register Pair BC with the previous level's saved Stack Pointer from 42BDH.
4D6F
PUSH BC C5
Save Register Pair BC (the previous level's Stack Pointer, or 0000H) onto the stack; 4E34H takes it back.
4D70
LD (42BDH),SP ED 73 BD 42
Store the Stack Pointer at 42BDH for this level; 4E28H reloads it when the command ends.
4D74
EX DE,HL EB
Exchange Register Pairs DE and HL: Register Pair HL = the command pointer again.
4D75
JUMP to 4E4CH to copy and run the command at Register Pair HL.

4D78H - Sub-Function 07H

Discards two words from the stack and goes to the exit code. The second word popped into Register Pair AF becomes the command's result that 4D8BH examines.

4D78
POP AF F1
Restore Register Pair AF from the stack to drop the top word.
4D79
POP AF F1
Restore Register Pair AF from the stack: the next word, whose high byte becomes Register A and low byte the flags, the result 4D8BH examines.
4D7A
JUMP to 4D8BH, the command exit, with Register Pair AF = the word just popped.

4D7CH - Function 2: Error Already Displayed

Used by SYS0/SYS at 4030H after an error message has been shown. Register A = 00H with the CARRY FLAG set tells 4D8BH that this is an error exit.

4D7C
XOR A AF
Set Register A to 00H (no error code to show) and clear the flags.
4D7D
SCF 37
Set the CARRY FLAG: the mark of an error exit whose message has already been displayed.
4D7E
JUMP to 4D8BH, the command exit, with Register A = 00H and the CARRY FLAG set.

4D80H - MDBORT Command (Sub-Functions 05H and 0CH)

Clears the MINI-DOS, DOS-CALL and bit 4 flags in 428AH and bit 5 of 4289H, then exits with no error. With the MINI-DOS flag gone, 4D8BH resets the stack and shows NEWDOS/80 READY, so the program that was interrupted by MINI-DOS is abandoned.

4D80
LD HL,428AH 21 8A 42
Point Register Pair HL to 428AH, the DOS state flags.
4D83
LD A,(HL) 7E
Fetch the flags at Register Pair HL (428AH) into Register A.
4D84
AND 2FH E6 2F
AND Register A with 2FH, clearing bit 7 (MINI-DOS active), bit 6 (DOS-CALL active) and bit 4 (chaining under DOS-CALL).
4D86
LD (HL),A 77
Store Register A (the cleared flags) back at Register Pair HL (428AH).
4D87
DEC HL 2B
DECrement Register Pair HL to 4289H, the DOS flags.
4D88
RES 5,(HL) CB AE
Clear bit 5 of the flags at Register Pair HL (4289H): chaining stops.

4D8AH - Function 1: DOS READY (No Error)

Also reached from 510EH after MINI-DOS is entered.

4D8A
XOR A AF
Set Register A to 00H with the Z FLAG set and the CARRY FLAG clear: a no-error exit. Falls into 4D8BH.

4D8BH - Command Exit Processing

Every command ends here, with Register A and the flags giving the result: Z and NO CARRY = no error; CARRY = error already displayed; NZ = error code in Register A. The flag bytes decide what happens next: SYS9/SYS function 7 is called for sub-functions 0BH, 04H or 0CH; a DOS-CALL is unwound at 4E27H; otherwise the DOS READY (or MINI-DOS READY) prompt is shown and a new command line is read. Register B holds the flags from 428AH and Register C those from 4289H throughout.

4D8B
DI F3
Disable interrupts while the flags and the stack are looked at.
4D8C
LD HL,428BH 21 8B 42
Point Register Pair HL to 428BH, the overlays' temporary flags.
4D8F
LD (HL),00H 36 00
Store 00H at Register Pair HL (428BH): every temporary flag is cleared at the end of a command.
4D91
DEC HL 2B
DECrement Register Pair HL to 428AH, the DOS state flags.
4D92
LD B,(HL) 46
Load Register B with the flags at Register Pair HL (428AH): bit 7 MINI-DOS, 6 DOS-CALL, 4 chaining under DOS-CALL, 2 an error at reset.
4D93
DEC HL 2B
DECrement Register Pair HL to 4289H, the DOS flags.
4D94
LD C,(HL) 4E
Load Register C with the flags at Register Pair HL (4289H): bit 5 chaining.
4D95
LD E,0BH 1E 0B
Load Register E with 0BH, the SYS9/SYS sub-function that shows DOS FATAL ERROR and waits for R to reset (4DACH of SYS9/SYS), used when bit 2 of 428AH is set.
4D97
PUSH AF F5
Save Register Pair AF (the command's result) onto the stack.
4D98
BIT 2,B CB 50
Test bit 2 of Register B (428AH): an error happened at reset (set by SYS4/SYS function 2).
4D9A
If the NZ FLAG is set (bit 2 set), JUMP to 4DBFH to call SYS9/SYS function 7 with Register E = 0BH.
4D9C
POP AF F1
Restore Register Pair AF from the stack: the command's result in Register A and the flags.
4D9D
PUSH AF F5
Save Register Pair AF back onto the stack, keeping the result there.
4D9E
If the CARRY FLAG is set (error already displayed), JUMP to 4DA2H; Register A is 00H there, so the test goes on to 4DA6H.
4DA0
If the Z FLAG is set (no error), JUMP to 4DACH.
4DA2
CP 38H FE 38
Compare Register A (the error code) against 38H, ILLEGAL MINI DOS FUNCTION (set at 4ED3H).
4DA4
If the Z FLAG is set (error 38H), JUMP to 4DACH: it is handled like no error, without stopping chaining.

An Error Occurred
Any error other than 38H.

4DA6
LD E,04H 1E 04
Load Register E with 04H, the SYS9/SYS sub-function used after an error while chaining (4EE2H of SYS9/SYS ends the chain and leaves through the error exit).
4DA8
BIT 5,C CB 69
Test bit 5 of Register C (4289H): chaining is running.
4DAA
If the NZ FLAG is set (chaining), JUMP to 4DBFH to call SYS9/SYS function 7 with Register E = 04H.
4DAC
RES 6,(HL) CB B6
Clear bit 6 of the flags at Register Pair HL (4289H): no overlay function is running.
4DAE
BIT 6,B CB 70
Test bit 6 of Register B (428AH): a DOS-CALL is active.
4DB0
If the NZ FLAG is set (inside a DOS-CALL), JUMP to 4E27H to return to its caller.
4DB2
LD A,(428CH) 3A 8C 42
Fetch the options at 428CH into Register A (bit 6 AB RUN-ONLY, bit 5 AG BREAK is a key).
4DB5
BIT 6,A CB 77
Test bit 6 of Register A (428CH): option AB, RUN-ONLY.
4DB7
If the Z FLAG is set (not RUN-ONLY), JUMP to 4DC4H.
4DB9
BIT 5,C CB 69
Test bit 5 of Register C (4289H): chaining is running.
4DBB
If the NZ FLAG is set (chaining), JUMP to 4DC4H: RUN-ONLY does not stop a chain file.
4DBD
LD E,0CH 1E 0C
RUN-ONLY at DOS READY: load Register E with 0CH, the SYS9/SYS sub-function that shows 'RUN ONLY' STOPPED and waits for R to reset (4DB1H of SYS9/SYS).
4DBF
LD D,EBH 16 EB
Load Register D with EBH, the RST 28H code of SYS9/SYS function 7.
4DC1
LD A,D 7A
Load Register A with Register D (EBH), the RST 28H code of SYS9/SYS function 7.
4DC2
LD C,E 4B
Load Register C with Register E, the sub-function (0BH, 04H or 0CH).
4DC3
RST 28H EF
RST 28H with Register A = EBH and Register C = the sub-function: SYS9/SYS function 7. When it returns, execution continues at 4DC4H.
4DC4
BIT 7,B CB 78
Test bit 7 of Register B (428AH): MINI-DOS is active.
4DC6
If the NZ FLAG is set (MINI-DOS), JUMP to 4DDCH, keeping the current stack.
4DC8
LD SP,41E0H 31 E0 41
Load the Stack Pointer with 41E0H, the DOS stack. The saved result and everything below it are dropped.
4DCB
BIT 5,A CB 6F
Test bit 5 of Register A (the 428CH options loaded at 4DB2H): option AG, BREAK is a key.
4DCD
LD HL,4546H 21 46 45
Load Register Pair HL with 4546H, the SYS0/SYS routine that returns Register A = 00H.
4DD0
LD (4479H),HL 22 79 44
Store Register Pair HL (4546H) at 4479H-447AH, the address of the BREAK hook's JP at 4478H.
4DD3
LD A,C3H 3E C3
Load Register A with C3H, the opcode of JP: the hook becomes JP 4546H and BREAK is ignored. LD does not change the flags.
4DD5
If the Z FLAG is set (option AG = N), JUMP to 4DD9H to store C3H.
4DD7
LD A,C9H 3E C9
Option AG = Y: load Register A with C9H, the opcode of RET: BREAK returns code 01H as a key.
4DD9
LD (4478H),A 32 78 44
Store Register A (C3H or C9H) at 4478H, the BREAK key hook.

Show the Prompt and Read a Command Line

4DDC
LD HL,51CCH 21 CC 51
Point Register Pair HL to 51CCH, the message NEWDOS/80 READY. Also reached from 4E32H.
4DDF
BIT 7,B CB 78
Test bit 7 of Register B (428AH): MINI-DOS is active.
4DE1
If the Z FLAG is set (not MINI-DOS), JUMP to 4DEAH.
4DE3
LD SP,(42BBH) ED 7B BB 42
MINI-DOS: load the Stack Pointer from 42BBH, saved when MINI-DOS was entered (5102H).
4DE7
LD HL,51C7H 21 C7 51
Point Register Pair HL to 51C7H, so the message reads MINI-NEWDOS/80 READY.
4DEA
EI FB
Enable interrupts again before the prompt is shown and the keyboard is read.
4DEB
LD A,0DH 3E 0D
Load Register A with 0DH (carriage return), to start the prompt on a new line.
4DED
GOSUB to the ROM display routine at 0033H to display Register A (0DH): start a new line.
4DF0
BIT 5,C CB 69
Test bit 5 of Register C (4289H): chaining is running.
4DF2
If the Z FLAG is set (not chaining), GOSUB to 4467H to display the READY message at Register Pair HL. While chaining the message is not shown.
4DF5
LD HL,428AH 21 8A 42
Point Register Pair HL to 428AH, the DOS state flags.
4DF8
SET 5,(HL) CB EE
Set bit 5 of the flags at Register Pair HL (428AH): waiting for a command line at DOS READY (cleared at 4E58H).
4DFA
LD A,(HL) 7E
Fetch the DOS state flags at Register Pair HL (428AH) into Register A.
4DFB
AND C0H E6 C0
Keep bit 7 (MINI-DOS) and bit 6 (DOS-CALL) of Register A (AND C0H). The NZ FLAG is set if either is active.
4DFD
DEC HL 2B
DECrement Register Pair HL to 4289H, the system flags. DEC HL does not change the flags.
4DFE
If the NZ FLAG is set (MINI-DOS or a DOS-CALL), JUMP to 4E02H, where the NZ FLAG skips the screen and cassette reset.
4E00
BIT 5,(HL) CB 6E
Test bit 5 of the system flags at Register Pair HL (4289H): a chain file is supplying the keys.
4E02
If the NZ FLAG is set (MINI-DOS, DOS-CALL or chaining), JUMP to 4E11H to read the command line at once.
4E04
XOR A AF
Plain DOS READY: set Register A to 00H, the value for the ROM's protected line count.
4E05
LD (4214H),A 32 14 42
Store Register A (00H) at 4214H, the ROM's count of protected screen lines: the whole screen scrolls again.
4E08
LD HL,4030H 21 30 40
Point Register Pair HL to 4030H, the DOS's exit after a displayed error.
4E0B
LD (4204H),HL 22 04 42
Store Register Pair HL (4030H) at 4204H, the address part of the ROM's BREAK and disk error vector at 4203H: a BREAK in a ROM cassette routine returns to DOS READY.
4E0E
GOSUB to the ROM at 01F8H, which jumps through 300CH to turn the cassette motor off.
4E11
LD BC,E308H 01 08 E3
Load Register Pair BC with E308H: Register B = E3H (SYS1/SYS function 7), Register C = 08H (sub-function 08H, run the typed line).
4E14
LD DE,497BH 11 7B 49
Load Register Pair DE with 497BH, the SYS0/SYS return point that issues RST 28H with the word below it on the stack.
4E17
PUSH BC C5
Save Register Pair BC (E308H) onto the stack.
4E18
PUSH DE D5
Save Register Pair DE (497BH) onto the stack as the return address of the line input.
4E19
LD HL,(4225H) 2A 25 42
Load Register Pair HL from 4225H-4226H: the first two characters of the previous command line.
4E1C
LD (42C7H),HL 22 C7 42
Store Register Pair HL (those two characters) at 42C7H-42C8H for the R (repeat) command at 4E76H.
4E1F
LD B,4FH 06 4F
Load Register B with 4FH (79), the most characters the ROM line input accepts.
4E21
LD HL,4225H 21 25 42
Point Register Pair HL to 4225H, the DOS command buffer.
4E24
JUMP to the ROM line input at 0040H with Register Pair HL = 4225H and Register B = 4FH. It returns to 497BH, which issues RST 28H with E3H and sub-function 08H: SYS1/SYS runs the typed line at 4E4BH.

4E27H - Return From a DOS-CALL

Reached from 4DB0H when bit 6 of 428AH is set. Register B = the 428AH flags, Register C = the 4289H flags, Register Pair HL = 4289H. Restores this level's stack, removes the level, and returns to the DOS-CALL caller with the command's result in Register A and the flags.

4E27
POP DE D1
Restore Register Pair DE from the stack: the result saved at 4D97H (Register D = the error code, Register E = the flags).
4E28
LD SP,(42BDH) ED 7B BD 42
Load the Stack Pointer from 42BDH, saved for this DOS-CALL level at 4D70H.
4E2C
BIT 5,C CB 69
Test bit 5 of Register C (4289H): chaining is running.
4E2E
If the Z FLAG is set (not chaining), JUMP to 4E34H.
4E30
BIT 4,B CB 60
Chaining: test bit 4 of Register B (428AH), set when the chain file runs at this DOS-CALL level.
4E32
If the NZ FLAG is set (both set), JUMP to 4DDCH to show the READY prompt and read another command instead of returning.
4E34
POP BC C1
Restore Register Pair BC from the stack: the previous level's Stack Pointer, pushed at 4D6FH (0000H at the outermost level).
4E35
LD A,B 78
Load Register A with Register B, its high byte.
4E36
OR C B1
OR Register C (the low byte) into Register A. The Z FLAG is set if Register Pair BC is 0000H.
4E37
If the NZ FLAG is set (an outer DOS-CALL is still active), JUMP to 4E3CH with Register Pair HL = 4289H.
4E39
INC HL 23
The outermost level: INCrement Register Pair HL to 428AH.
4E3A
RES 6,(HL) CB B6
Clear bit 6 of the flags at Register Pair HL (428AH): no DOS-CALL is active any more.
4E3C
RES 4,(HL) CB A6
Clear bit 4 of the flags at Register Pair HL (428AH at the outermost level; 4289H otherwise, where bit 4 is option AG's mark).
4E3E
LD (42BDH),BC ED 43 BD 42
Store Register Pair BC (the previous level's Stack Pointer, or 0000H) back at 42BDH.
4E42
PUSH DE D5
Save Register Pair DE (the command's result) onto the stack.
4E43
POP AF F1
Restore it into Register Pair AF: Register A = the error code, the flags as the command left them.
4E44
JUMP to 5132H to restore the registers saved by 5142H at 4D5BH and return to the DOS-CALL caller with Register Pair AF.

4E47H - Function 3: Execute a DOS Command

Entered through SYS0/SYS 4405H with Register Pair HL pointing to a command line. 4E4BH is the entry for sub-function 08H (a line typed at DOS READY). Both reach 4E4CH with one word less on the stack than they had at entry.

4E47
LD SP,41E0H 31 E0 41
Load the Stack Pointer with 41E0H, the DOS stack: function 3 never returns to its caller.
4E4A
PUSH AF F5
Save Register Pair AF onto the stack, a word for 4E4BH to drop.
4E4B
POP AF F1
Restore Register Pair AF from the stack to drop the top word (for sub-function 08H, the word E308H pushed at 4E17H).

4E4CH - Copy the Command Line and Look It Up

Pushes 402DH and 4408H so that a command which RETurns goes to 4408H in SYS0/SYS (RET Z to 402DH, DOS READY, if there was no error; otherwise the DOS error exit at 4409H). Copies the line from Register Pair HL into the command buffer at 4225H, converting it to upper case, and handles the R command. The line may be at most 80 characters including the carriage return. Also entered from 4D75H for a DOS-CALL.

4E4C
LD BC,402DH 01 2D 40
Load Register Pair BC with 402DH, the SYS0/SYS no-error exit (DOS READY).
4E4F
LD DE,4408H 11 08 44
Load Register Pair DE with 4408H, the SYS0/SYS return point (RET Z, otherwise the DOS error exit).
4E52
PUSH BC C5
Save Register Pair BC (402DH) onto the stack, where the RET Z at 4408H finds it.
4E53
PUSH DE D5
Save Register Pair DE (4408H) onto the stack: every command returns there.
4E54
EX DE,HL EB
Exchange Register Pairs DE and HL: Register Pair DE = the command line's source.
4E55
LD HL,428AH 21 8A 42
Point Register Pair HL to 428AH, the DOS state flags.
4E58
RES 5,(HL) CB AE
Clear bit 5 of the flags at Register Pair HL (428AH): no longer waiting at DOS READY.
4E5A
LD HL,4225H 21 25 42
Point Register Pair HL to 4225H, the command buffer.
4E5D
LD B,50H 06 50
Load Register B with 50H (80), the length of the command buffer.
4E5F
LD A,(HL) 7E
Fetch the first byte of the buffer at Register Pair HL (4225H) into Register A.
4E60
CP 0DH FE 0D
Compare Register A against 0DH (carriage return). The test is made on the buffer before anything is copied, so it catches an empty line typed at DOS READY, where the source is the buffer itself.
4E62
RET Z C8
If the Z FLAG is set (an empty line), RETurn to 4408H with the Z FLAG: DOS READY again.
4E63
PUSH HL E5
Save Register Pair HL (4225H) onto the stack.

Copy Loop
Register Pair DE = the source, Register Pair HL = the buffer, Register B = room left.

4E64
LD A,(DE) 1A
Fetch the next character of the command line at Register Pair DE into Register A.
4E65
INC DE 13
INCrement Register Pair DE to the next source character.
4E66
GOSUB to 4548H (SYS0/SYS) to convert Register A to upper case if it is a lower case letter.
4E69
CP 0DH FE 0D
Compare Register A (the character) against 0DH, the end of the line.
4E6B
LD (HL),A 77
Store Register A (the character) in the buffer at Register Pair HL.
4E6C
INC HL 23
INCrement Register Pair HL to the next buffer byte. INC HL does not change the flags.
4E6D
If the Z FLAG is set (the 0DH was copied), JUMP to 4E76H.
4E6F
DECrement Register B (room left) and, if it is not 0, LOOP BACK to 4E64H.
4E71
POP AF F1
80 characters without a carriage return: restore Register Pair AF from the stack to drop the saved buffer address.
4E72
LD A,36H 3E 36
Load Register A with error code 36H (COMMAND TOO LONG).
4E74
OR A B7
OR Register A (36H) with itself to set the NZ FLAG.
4E75
RET C9
RETurn to 4408H with error 36H in Register A.

The R Command
R repeats the previous command. The ROM line input overwrites only as much of the buffer as is typed, so after R and ENTER only the first two bytes of the previous line are lost; they were saved at 42C7H before the input.

4E76
LD A,(428DH) 3A 8D 42
Fetch the options at 428DH into Register A (bit 5 = option BE, the R command).
4E79
BIT 5,A CB 6F
Test bit 5 of Register A (428DH): option BE. The Z FLAG is set when R is not enabled.
4E7B
If the Z FLAG is set (BE = N), JUMP to 4E8CH.
4E7D
LD HL,(4225H) 2A 25 42
Load Register Pair HL with the first two bytes of the line from 4225H-4226H.
4E80
LD DE,D52H 11 52 0D
Load Register Pair DE with 0D52H: R (52H) followed by a carriage return (0DH), as they lie in memory.
4E83
RST 18H DF
RST 18H: compare Register Pair HL (the line's first two bytes) with Register Pair DE (R and 0DH) through the ROM. The Z FLAG is set if equal.
4E84
If the NZ FLAG is set (the line is not just R), JUMP to 4E8CH.
4E86
LD HL,(42C7H) 2A C7 42
Load Register Pair HL with the two bytes saved at 42C7H-42C8H by 4E1CH.
4E89
LD (4225H),HL 22 25 42
Store Register Pair HL at 4225H-4226H, which restores the previous command in the buffer.
4E8C
POP HL E1
Restore Register Pair HL from the stack: 4225H, the start of the command.

Command Table Search
The table at 4F6FH: each entry is the name followed by three attribute bytes, the first of which has bit 7 set; the table ends with 00H.

4E8D
LD DE,4F6FH 11 6F 4F
Point Register Pair DE to 4F6FH, the command table.
4E90
PUSH HL E5
Save Register Pair HL (the start of the command) onto the stack.
4E91
LD A,(DE) 1A
Fetch the next table byte at Register Pair DE into Register A.
4E92
CP (HL) BE
Compare Register A (the table byte) against the command character at Register Pair HL.
4E93
INC DE 13
INCrement Register Pair DE, the table pointer. INC does not change the flags.
4E94
INC HL 23
INCrement Register Pair HL, the command pointer.
4E95
If the Z FLAG is set (they match), LOOP BACK to 4E91H.
4E97
DEC HL 2B
DECrement Register Pair HL back to the command character that did not match.
4E98
DEC DE 1B
DECrement Register Pair DE back to the table byte.
4E99
RLCA 07
Rotate Register A (the table byte) left: bit 7 goes into the CARRY FLAG.
4E9A
If the NO CARRY FLAG is set (a name character did not match), JUMP to 4EA1H to try the next entry.
4E9C
The whole name matched (the mismatch was the attribute byte): GOSUB to 4C7AH (SYS0/SYS), which returns the Z FLAG at a carriage return, or NO CARRY after a comma or spaces with Register Pair HL past them, or CARRY for any other character.
4E9F
If the NO CARRY FLAG is set (the command word ends here), JUMP to 4EBEH to run it.
4EA1
POP HL E1
Not this entry: restore Register Pair HL from the stack, the start of the command.
4EA2
LD A,(DE) 1A
Fetch the table byte at Register Pair DE into Register A.
4EA3
RLCA 07
Rotate Register A left: bit 7 (the first attribute byte) goes into the CARRY FLAG.
4EA4
INC DE 13
INCrement Register Pair DE, the table pointer.
4EA5
If the NO CARRY FLAG is set (still in the name), LOOP BACK to 4EA2H.
4EA7
INC DE 13
INCrement Register Pair DE past the second attribute byte.
4EA8
INC DE 13
INCrement Register Pair DE past the third attribute byte.
4EA9
LD A,(DE) 1A
Fetch the first byte of the next entry at Register Pair DE into Register A.
4EAA
OR A B7
OR Register A with itself. The Z FLAG is set at the 00H end of the table.
4EAB
If the NZ FLAG is set (another entry), LOOP BACK to 4E90H.

Not a Command Name
A command beginning with an asterisk goes to SYS9/SYS function 7, sub-function 07H. Anything else is taken as the name of a program to run: SYS2/SYS function 7, sub-function 03H, with the attributes 43H (sub-function 03H, not under MINI-DOS) and 41H (parse the filespec, default extension /CMD).

4EAD
LD BC,E443H 01 43 E4
Load Register Pair BC with E443H: Register B = E4H (SYS2/SYS function 7), Register C = 43H (byte 1: not under MINI-DOS, sub-function 03H).
4EB0
LD D,41H 16 41
Load Register D with 41H (byte 3: parse a filespec into 4480H, default extension /CMD).
4EB2
LD A,(HL) 7E
Fetch the first character of the command at Register Pair HL into Register A.
4EB3
CP 2AH FE 2A
Compare Register A (the first character) against 2AH, an asterisk: the start of a command that runs a named routine (manual 3.31).
4EB5
If the NZ FLAG is set (not an asterisk), JUMP to 4EC7H to run the program named at Register Pair HL.
4EB7
LD A,EBH 3E EB
Load Register A with EBH, the RST 28H code of SYS9/SYS function 7.
4EB9
LD C,07H 0E 07
Load Register C with 07H, SYS9/SYS's sub-function that runs a named routine.
4EBB
RST 28H EF
RST 28H with Register A = EBH and Register C = 07H: SYS9/SYS runs the named routine whose name follows the asterisk at Register Pair HL.
4EBC
POP BC C1
Restore Register Pair BC from the stack to drop the word on top. The error exits from 4EEFH, 4EFEH, 4F0AH and 4F11H also come here.
4EBD
RET C9
RETurn (to 4408H in SYS0/SYS) with Register A and the flags as they are.

4EBEH - Run a Command

The name matched. Register Pair DE points to the first attribute byte and Register Pair HL to the rest of the command line. The attributes are:
Byte 1 (Register C): bit 7 always set (end of name); bit 6 = not allowed under MINI-DOS; bits 0-4 = the sub-function number passed to the overlay.
Byte 2 (Register B): the RST 28H code of the overlay function that does the work.
Byte 3 (Register D): bit 7 = open the file (with bit 6: new or existing, 4420H; without: existing, 4424H); bit 6 or 7 = parse a filespec into 4480H; bit 5 = a second filespec follows, optionally after TO, parsed into 51E0H; bit 4 = nothing may follow; bit 3 = leave the command line pointer on the stack for the overlay; bits 0-2 = default extension (1 = /CMD, 2 = /JCL).
The overlay is started by pushing 4978H and returning to it: 4978H goes to the DOS error exit if the Z FLAG is clear, otherwise issues RST 28H with the code and sub-function left on the stack.

4EBE
POP BC C1
Restore Register Pair BC from the stack to drop the saved start of the command.
4EBF
LD A,(DE) 1A
Fetch attribute byte 1 at Register Pair DE into Register A.
4EC0
LD C,A 4F
Copy Register A (attribute byte 1) into Register C: MINI-DOS bit and sub-function.
4EC1
INC DE 13
INCrement Register Pair DE to attribute byte 2.
4EC2
LD A,(DE) 1A
Fetch attribute byte 2 at Register Pair DE (the RST 28H code) into Register A.
4EC3
LD B,A 47
Copy Register A (attribute byte 2) into Register B: the RST 28H code of the overlay.
4EC4
INC DE 13
INCrement Register Pair DE to attribute byte 3.
4EC5
LD A,(DE) 1A
Fetch attribute byte 3 at Register Pair DE into Register A.
4EC6
LD D,A 57
Copy Register A (attribute byte 3) into Register D: the filespec flags.
4EC7
BIT 6,C CB 71
Test bit 6 of Register C (byte 1): not allowed under MINI-DOS. Also the entry from 4EB5H for a program name.
4EC9
If the Z FLAG is set (allowed), JUMP to 4EDAH.
4ECB
LD A,(428AH) 3A 8A 42
Fetch the DOS state flags at 428AH into Register A.
4ECE
RLCA 07
Rotate Register A left: bit 7 (MINI-DOS active) goes into the CARRY FLAG and bit 6 (DOS-CALL active) moves to bit 7.
4ECF
If the NO CARRY FLAG is set (not in MINI-DOS), JUMP to 4EDAH.
4ED1
AND 80H E6 80
AND Register A with 80H, testing the DOS-CALL bit (now bit 7).
4ED3
LD A,38H 3E 38
Load Register A with error code 38H (ILLEGAL MINI DOS FUNCTION). LD does not change the flags.
4ED5
If the NZ FLAG is set (a DOS-CALL is active), JUMP to 4D8BH to end the command with error 38H.
4ED8
OR A B7
OR Register A (38H) with itself to set the NZ FLAG.
4ED9
RET C9
RETurn to 4408H with error 38H in Register A.
4EDA
LD A,C 79
Load Register A with Register C, attribute byte 1.
4EDB
AND 1FH E6 1F
AND Register A with 1FH, keeping bits 0-4: the sub-function number.
4EDD
LD C,A 4F
Copy Register A (the sub-function) into Register C.
4EDE
PUSH BC C5
Save Register Pair BC onto the stack: Register B = the RST 28H code, Register C = the sub-function. 497EH takes them from here.
4EDF
LD C,D 4A
Load Register C with Register D, attribute byte 3.
4EE0
LD A,C 79
Load Register A with Register C (attribute byte 3, the filespec flags).
4EE1
AND C0H E6 C0
AND Register A with C0H, keeping bits 6-7. The NZ FLAG is set if a filespec is wanted.
4EE3
If the NZ FLAG is set, GOSUB to 5164H to parse a filespec from the command line at Register Pair HL into 4480H.
4EE6
If the NZ FLAG is set (the filespec could not be parsed), JUMP to 4F08H for error 30H.
4EE8
BIT 5,C CB 69
Test bit 5 of Register C (byte 3): a second filespec follows.
4EEA
If the Z FLAG is set (no second filespec), JUMP to 4F0CH.
4EEC
GOSUB to 4C7EH (SYS0/SYS), which returns NO CARRY after a comma or spaces with Register Pair HL past them.
4EEF
If the CARRY FLAG is set (no separator; Register A = 34H), JUMP to 4EBCH to return the error.
4EF1
PUSH BC C5
Save Register Pair BC (Register C = byte 3) onto the stack.
4EF2
LD BC,51C4H 01 C4 51
Point Register Pair BC to 51C4H, the word TO ended by 00H.
4EF5
GOSUB to 4C6AH (SYS0/SYS) to compare the command line at Register Pair HL with the word at Register Pair BC. On a match it returns the Z FLAG with Register Pair HL past it.
4EF8
POP BC C1
Restore Register Pair BC from the stack (Register C = byte 3).
4EF9
If the NZ FLAG is set (no TO), JUMP to 4F00H.
4EFB
GOSUB to 4C7EH (SYS0/SYS) to step over the comma or spaces after TO at Register Pair HL.
4EFE
If the CARRY FLAG is set (no separator after TO; Register A = 34H), JUMP to 4EBCH to return the error.
4F00
PUSH DE D5
Save Register Pair DE (4480H, from 5164H) onto the stack.
4F01
LD DE,51E0H 11 E0 51
Point Register Pair DE to 51E0H, the second filespec buffer.
4F04
GOSUB to 5167H to parse the second filespec at Register Pair HL into the buffer at Register Pair DE.
4F07
POP DE D1
Restore Register Pair DE from the stack: 4480H.
4F08
LD A,30H 3E 30
Load Register A with error code 30H (BAD FILESPEC). LD does not change the flags.
4F0A
If the NZ FLAG is set (the parse failed), JUMP to 4EBCH to return error 30H.
4F0C
BIT 4,C CB 61
Test bit 4 of Register C (byte 3): nothing may follow.
4F0E
If the NZ FLAG is set, GOSUB to 4C7AH (SYS0/SYS), which returns the Z FLAG only at the carriage return at Register Pair HL; anything else gives the NZ FLAG with Register A = 34H.
4F11
If the NZ FLAG is set (something follows), JUMP to 4EBCH to return error 34H.
4F13
BIT 3,C CB 59
Test bit 3 of Register C (byte 3): leave the command line pointer for the overlay.
4F15
If the Z FLAG is set (bit 3 clear), JUMP to 4F19H.
4F17
EX (SP),HL E3
Exchange Register Pair HL (the command line pointer) with the word on top of the stack (the Stack Pointer's target, the code/sub-function word).
4F18
PUSH HL E5
Save Register Pair HL (the code/sub-function word) back on top: the command line pointer now lies below it for the overlay.
4F19
LD A,C 79
Load Register A with Register C, attribute byte 3.
4F1A
AND 07H E6 07
AND Register A with 07H, keeping bits 0-2: the default extension number.
4F1C
If the Z FLAG is set (bits 0-2 = 0: no default extension), JUMP to 4F2CH.
4F1E
PUSH HL E5
Save Register Pair HL (the command line pointer) onto the stack.
4F1F
LD HL,51BBH 21 BB 51
Point Register Pair HL to 51BBH, three bytes before the extension list at 51BEH.
4F22
INC HL 23
INCrement Register Pair HL, the first of three steps to the next extension.
4F23
INC HL 23
INCrement Register Pair HL again (second of three steps to the next extension).
4F24
INC HL 23
INCrement Register Pair HL a third time: three bytes further.
4F25
DEC A 3D
DECrement Register A, the extension number still to count. The Z FLAG is set at 0.
4F26
If the NZ FLAG is set (Register A is not 0), LOOP BACK to 4F22H. Register Pair HL ends at the wanted extension: 51BEH CMD or 51C1H JCL.
4F28
GOSUB to 4F41H to insert the extension at Register Pair HL into the filespec at Register Pair DE (4480H) if it has none.
4F2B
POP HL E1
Restore Register Pair HL from the stack: the command line pointer.
4F2C
LD A,C 79
Load Register A with Register C, attribute byte 3.
4F2D
LD BC,4978H 01 78 49
Load Register Pair BC with 4978H, the SYS0/SYS return point that starts the overlay function named on the stack.
4F30
PUSH BC C5
Save Register Pair BC (4978H) onto the stack as the return address.
4F31
BIT 7,A CB 7F
Test bit 7 of Register A (byte 3): open the file.
4F33
RET Z C8
If the Z FLAG is set (no file to open), RETurn to 4978H with the Z FLAG set, which starts the overlay.
4F34
LD B,00H 06 00
Load Register B with 00H: the record length (LRL) for the open, 256.
4F36
LD HL,4300H 21 00 43
Point Register Pair HL to 4300H, the buffer for the FCB at 4480H.
4F39
BIT 6,A CB 77
Test bit 6 of Register A (byte 3): open a new or existing file.
4F3B
If the Z FLAG is set (bit 6 clear), JUMP to 4424H (SYS0/SYS) to open the existing file in the FCB at Register Pair DE (4480H). It returns to 4978H, which starts the overlay or, on an error, goes to the DOS error exit.
4F3E
JUMP to 4420H (SYS0/SYS) to open a new or existing file in the FCB at Register Pair DE (4480H). It returns to 4978H in the same way.

4F41H - Function 5: Insert a Default Extension

Entered through SYS0/SYS 4473H and from 4F28H. Register Pair DE points to a filespec, Register Pair HL to a three-character extension. The filespec is scanned for up to nine characters. If a / is found it already has an extension and nothing changes. Otherwise, at the first : or character below / (such as the . before a password or the 03H end marker), the rest of the filespec is moved four bytes to the right and / plus the extension is inserted. The move covers 1CH bytes counted from the start of the filespec. Register Pairs DE and BC are preserved.

4F41
PUSH DE D5
Save Register Pair DE (the filespec) onto the stack.
4F42
PUSH BC C5
Save Register Pair BC (the caller's) onto the stack.
4F43
LD BC,091CH 01 1C 09
Load Register Pair BC with 091CH: Register B = 09H (characters to scan), Register C = 1CH (bytes of the filespec area left to move).

Scan Loop

4F46
LD A,(DE) 1A
Fetch the next filespec character at Register Pair DE into Register A.
4F47
CP 3AH FE 3A
Compare Register A against 3AH (ASCII colon, the drive number).
4F49
If the Z FLAG is set (a drive number follows), JUMP to 4F55H to insert the extension here.
4F4B
CP 2FH FE 2F
Compare Register A against 2FH (ASCII slash).
4F4D
If the CARRY FLAG is set (Register A is below /: the 03H end, a . before a password or another terminator), JUMP to 4F55H to insert the extension here.
4F4F
If the Z FLAG is set (a /: the filespec already has an extension), JUMP to 4F6CH.
4F51
DEC C 0D
DECrement Register C: one byte fewer left to move.
4F52
INC DE 13
INCrement Register Pair DE to the next filespec character.
4F53
DECrement Register B and, if it is not 0, LOOP BACK to 4F46H (up to nine characters).
4F55
INC HL 23
INCrement Register Pair HL, the extension pointer, towards its last character.
4F56
INC HL 23
INCrement Register Pair HL again: the last character of the extension.
4F57
PUSH HL E5
Save Register Pair HL (the extension's last character) onto the stack.
4F58
EX DE,HL EB
Exchange Register Pairs DE and HL: Register Pair HL = the insertion point in the filespec, Register Pair DE = the extension's last character.
4F59
LD B,00H 06 00
Load Register B with 00H: Register Pair BC = Register C, the bytes to move.
4F5B
ADD HL,BC 09
ADD Register Pair BC to Register Pair HL: the end of the bytes to move.
4F5C
LD D,H 54
Copy Register H (the high byte of the end of the move) into Register D.
4F5D
LD E,L 5D
Copy Register L into Register E: Register Pair DE = Register Pair HL.
4F5E
DEC HL 2B
DECrement Register Pair HL to the last byte to move.
4F5F
INC DE 13
INCrement Register Pair DE, the first of three steps.
4F60
INC DE 13
INCrement Register Pair DE again (second of three steps beyond Register Pair HL).
4F61
INC DE 13
INCrement Register Pair DE a third time: Register Pair DE = four bytes past Register Pair HL.
4F62
LDDR ED B8
Move Register Pair BC bytes from Register Pair HL down to Register Pair DE, last byte first: the rest of the filespec shifts four bytes to the right.
4F64
POP HL E1
Restore Register Pair HL from the stack: the extension's last character.
4F65
LD C,03H 0E 03
Load Register C with 03H; with Register B = 0 after the LDDR, Register Pair BC = 3.
4F67
LDDR ED B8
Copy Register Pair BC (3) bytes from Register Pair HL (the extension) down to Register Pair DE, last first, into the gap. Register Pair DE ends at the gap's first byte.
4F69
LD A,2FH 3E 2F
Load Register A with 2FH (ASCII slash), the character that starts an extension.
4F6B
LD (DE),A 12
Store Register A (/) at Register Pair DE, in front of the extension.
4F6C
POP BC C1
Restore Register Pair BC from the stack (the caller's).
4F6D
POP DE D1
Restore Register Pair DE from the stack: the filespec.
4F6E
RET C9
RETurn with the filespec at Register Pair DE carrying the extension.

4F6FH - Command Table (Data)

One entry per DOS command handled by an overlay: the name in ASCII, then three attribute bytes (see 4EBEH). Byte 1 has bit 7 set and ends the name; bit 6 = not allowed under MINI-DOS; bits 0-4 = the sub-function. Byte 2 = the RST 28H code of the overlay function. Byte 3 = the filespec flags. The table ends with 00H at 50CDH. LIB (50CEH) lists the names.

4F6F-4F77
DEFM "APPEND" / DEFB C0H, 68H, 00H 41 50 50 45 4E 44 C0 68 00
Command table entry for APPEND (4F6FH): byte 1 = C0H: not allowed under MINI-DOS (bit 6), sub-function 00H; byte 2 = 68H: RST 28H code of SYS6/SYS function 3; byte 3 = 00H: no filespec handling.
4F78-4F80
DEFM "ATTRIB" / DEFB 85H, E9H, 88H 41 54 54 52 49 42 85 E9 88
Command table entry for ATTRIB (4F78H): byte 1 = 85H: sub-function 05H; byte 2 = E9H: RST 28H code of SYS7/SYS function 7; byte 3 = 88H: open the file in 4480H (existing, 4424H); the command line pointer is left on the stack for the overlay.
4F81-4F87
DEFM "AUTO" / DEFB 84H, E9H, 00H 41 55 54 4F 84 E9 00
Command table entry for AUTO (4F81H): byte 1 = 84H: sub-function 04H; byte 2 = E9H: RST 28H code of SYS7/SYS function 7; byte 3 = 00H: no filespec handling.
4F88-4F8F
DEFM "BLINK" / DEFB 81H, E5H, 00H 42 4C 49 4E 4B 81 E5 00
Command table entry for BLINK (4F88H): byte 1 = 81H: sub-function 01H; byte 2 = E5H: RST 28H code of SYS3/SYS function 7; byte 3 = 00H: no filespec handling.
4F90-4F96
DEFM "BOOT" / DEFB 8AH, EBH, 10H 42 4F 4F 54 8A EB 10
Command table entry for BOOT (4F90H): byte 1 = 8AH: sub-function 0AH; byte 2 = EBH: RST 28H code of SYS9/SYS function 7; byte 3 = 10H: nothing may follow.
4F97-4F9E
DEFM "BREAK" / DEFB 85H, E5H, 00H 42 52 45 41 4B 85 E5 00
Command table entry for BREAK (4F97H): byte 1 = 85H: sub-function 05H; byte 2 = E5H: RST 28H code of SYS3/SYS function 7; byte 3 = 00H: no filespec handling.
4F9F-4FA6
DEFM "CHAIN" / DEFB C3H, EBH, 8AH 43 48 41 49 4E C3 EB 8A
Command table entry for CHAIN (4F9FH): byte 1 = C3H: not allowed under MINI-DOS (bit 6), sub-function 03H; byte 2 = EBH: RST 28H code of SYS9/SYS function 7; byte 3 = 8AH: open the file in 4480H (existing, 4424H); the command line pointer is left on the stack for the overlay; default extension /JCL.
4FA7-4FAE
DEFM "CHNON" / DEFB C5H, EBH, 00H 43 48 4E 4F 4E C5 EB 00
Command table entry for CHNON (4FA7H): byte 1 = C5H: not allowed under MINI-DOS (bit 6), sub-function 05H; byte 2 = EBH: RST 28H code of SYS9/SYS function 7; byte 3 = 00H: no filespec handling.
4FAF-4FB6
DEFM "CLEAR" / DEFB 84H, F0H, 00H 43 4C 45 41 52 84 F0 00
Command table entry for CLEAR (4FAFH): byte 1 = 84H: sub-function 04H; byte 2 = F0H: RST 28H code of SYS14/SYS function 7; byte 3 = 00H: no filespec handling.
4FB7-4FBE
DEFM "CLOCK" / DEFB 82H, E5H, 00H 43 4C 4F 43 4B 82 E5 00
Command table entry for CLOCK (4FB7H): byte 1 = 82H: sub-function 02H; byte 2 = E5H: RST 28H code of SYS3/SYS function 7; byte 3 = 00H: no filespec handling.
4FBF-4FC4
DEFM "CLS" / DEFB 89H, E3H, 10H 43 4C 53 89 E3 10
Command table entry for CLS (4FBFH): byte 1 = 89H: sub-function 09H; byte 2 = E3H: RST 28H code of SYS1/SYS function 7; byte 3 = 10H: nothing may follow.
4FC5-4FCB
DEFM "COPY" / DEFB C0H, 48H, 00H 43 4F 50 59 C0 48 00
Command table entry for COPY (4FC5H): byte 1 = C0H: not allowed under MINI-DOS (bit 6), sub-function 00H; byte 2 = 48H: RST 28H code of SYS6/SYS function 2; byte 3 = 00H: no filespec handling.
4FCC-4FD4
DEFM "CREATE" / DEFB 82H, F0H, 40H 43 52 45 41 54 45 82 F0 40
Command table entry for CREATE (4FCCH): byte 1 = 82H: sub-function 02H; byte 2 = F0H: RST 28H code of SYS14/SYS function 7; byte 3 = 40H: parse a filespec into 4480H.
4FD5-4FDB
DEFM "DATE" / DEFB 8BH, E9H, 00H 44 41 54 45 8B E9 00
Command table entry for DATE (4FD5H): byte 1 = 8BH: sub-function 0BH; byte 2 = E9H: RST 28H code of SYS7/SYS function 7; byte 3 = 00H: no filespec handling.
4FDC-4FE3
DEFM "DEBUG" / DEFB 83H, E5H, 00H 44 45 42 55 47 83 E5 00
Command table entry for DEBUG (4FDCH): byte 1 = 83H: sub-function 03H; byte 2 = E5H: RST 28H code of SYS3/SYS function 7; byte 3 = 00H: no filespec handling.
4FE4-4FE9
DEFM "DIR" / DEFB 80H, 2AH, 00H 44 49 52 80 2A 00
Command table entry for DIR (4FE4H): byte 1 = 80H: sub-function 00H; byte 2 = 2AH: RST 28H code of SYS8/SYS function 1; byte 3 = 00H: no filespec handling.
4FEA-4FEE
DEFM "DO" / DEFB C3H, EBH, 8AH 44 4F C3 EB 8A
Command table entry for DO (4FEAH): byte 1 = C3H: not allowed under MINI-DOS (bit 6), sub-function 03H; byte 2 = EBH: RST 28H code of SYS9/SYS function 7; byte 3 = 8AH: open the file in 4480H (existing, 4424H); the command line pointer is left on the stack for the overlay; default extension /JCL.
4FEF-4FF5
DEFM "DUMP" / DEFB 87H, E9H, C8H 44 55 4D 50 87 E9 C8
Command table entry for DUMP (4FEFH): byte 1 = 87H: sub-function 07H; byte 2 = E9H: RST 28H code of SYS7/SYS function 7; byte 3 = C8H: open the file in 4480H (new or existing, 4420H); the command line pointer is left on the stack for the overlay.
4FF6-4FFD
DEFM "ERROR" / DEFB 87H, F0H, 00H 45 52 52 4F 52 87 F0 00
Command table entry for ERROR (4FF6H): byte 1 = 87H: sub-function 07H; byte 2 = F0H: RST 28H code of SYS14/SYS function 7; byte 3 = 00H: no filespec handling.
4FFE-5006
DEFM "FORMAT" / DEFB C0H, 28H, 00H 46 4F 52 4D 41 54 C0 28 00
Command table entry for FORMAT (4FFEH): byte 1 = C0H: not allowed under MINI-DOS (bit 6), sub-function 00H; byte 2 = 28H: RST 28H code of SYS6/SYS function 1; byte 3 = 00H: no filespec handling.
5007-500E
DEFM "FORMS" / DEFB 81H, F1H, 00H 46 4F 52 4D 53 81 F1 00
Command table entry for FORMS (5007H): byte 1 = 81H: sub-function 01H; byte 2 = F1H: RST 28H code of SYS15/SYS function 7; byte 3 = 00H: no filespec handling.
500F-5015
DEFM "FREE" / DEFB 80H, 4AH, 00H 46 52 45 45 80 4A 00
Command table entry for FREE (500FH): byte 1 = 80H: sub-function 00H; byte 2 = 4AH: RST 28H code of SYS8/SYS function 2; byte 3 = 00H: no filespec handling.
5016-501D
DEFM "HIMEM" / DEFB 82H, E9H, 00H 48 49 4D 45 4D 82 E9 00
Command table entry for HIMEM (5016H): byte 1 = 82H: sub-function 02H; byte 2 = E9H: RST 28H code of SYS7/SYS function 7; byte 3 = 00H: no filespec handling.
501E-5023
DEFM "JKL" / DEFB 80H, A5H, 10H 4A 4B 4C 80 A5 10
Command table entry for JKL (501EH): byte 1 = 80H: sub-function 00H; byte 2 = A5H: RST 28H code of SYS3/SYS function 5; byte 3 = 10H: nothing may follow.
5024-502A
DEFM "KILL" / DEFB 80H, 45H, 90H 4B 49 4C 4C 80 45 90
Command table entry for KILL (5024H): byte 1 = 80H: sub-function 00H; byte 2 = 45H: RST 28H code of SYS3/SYS function 2; byte 3 = 90H: open the file in 4480H (existing, 4424H); nothing may follow.
502B-502F
DEFM "LC" / DEFB 89H, E5H, 00H 4C 43 89 E5 00
Command table entry for LC (502BH): byte 1 = 89H: sub-function 09H; byte 2 = E5H: RST 28H code of SYS3/SYS function 7; byte 3 = 00H: no filespec handling.
5030-5035
DEFM "LIB" / DEFB 82H, E3H, 00H 4C 49 42 82 E3 00
Command table entry for LIB (5030H): byte 1 = 82H: sub-function 02H; byte 2 = E3H: RST 28H code of SYS1/SYS function 7; byte 3 = 00H: no filespec handling.
5036-503C
DEFM "LIST" / DEFB 85H, F0H, 88H 4C 49 53 54 85 F0 88
Command table entry for LIST (5036H): byte 1 = 85H: sub-function 05H; byte 2 = F0H: RST 28H code of SYS14/SYS function 7; byte 3 = 88H: open the file in 4480H (existing, 4424H); the command line pointer is left on the stack for the overlay.
503D-5043
DEFM "LOAD" / DEFB 80H, A4H, 50H 4C 4F 41 44 80 A4 50
Command table entry for LOAD (503DH): byte 1 = 80H: sub-function 00H; byte 2 = A4H: RST 28H code of SYS2/SYS function 5; byte 3 = 50H: parse a filespec into 4480H; nothing may follow.
5044-504C
DEFM "MDBORT" / DEFB 85H, E3H, 00H 4D 44 42 4F 52 54 85 E3 00
Command table entry for MDBORT (5044H): byte 1 = 85H: sub-function 05H; byte 2 = E3H: RST 28H code of SYS1/SYS function 7; byte 3 = 00H: no filespec handling.
504D-5055
DEFM "MDCOPY" / DEFB 82H, EBH, B0H 4D 44 43 4F 50 59 82 EB B0
Command table entry for MDCOPY (504DH): byte 1 = 82H: sub-function 02H; byte 2 = EBH: RST 28H code of SYS9/SYS function 7; byte 3 = B0H: open the file in 4480H (existing, 4424H); a second filespec follows (optionally after TO), parsed into 51E0H; nothing may follow.
5056-505D
DEFM "MDRET" / DEFB 86H, E3H, 00H 4D 44 52 45 54 86 E3 00
Command table entry for MDRET (5056H): byte 1 = 86H: sub-function 06H; byte 2 = E3H: RST 28H code of SYS1/SYS function 7; byte 3 = 00H: no filespec handling.
505E-5065
DEFM "PAUSE" / DEFB 88H, EBH, 00H 50 41 55 53 45 88 EB 00
Command table entry for PAUSE (505EH): byte 1 = 88H: sub-function 08H; byte 2 = EBH: RST 28H code of SYS9/SYS function 7; byte 3 = 00H: no filespec handling.
5066-506E
DEFM "PDRIVE" / DEFB 83H, E9H, 00H 50 44 52 49 56 45 83 E9 00
Command table entry for PDRIVE (5066H): byte 1 = 83H: sub-function 03H; byte 2 = E9H: RST 28H code of SYS7/SYS function 7; byte 3 = 00H: no filespec handling.
506F-5076
DEFM "PRINT" / DEFB 86H, F0H, 88H 50 52 49 4E 54 86 F0 88
Command table entry for PRINT (506FH): byte 1 = 86H: sub-function 06H; byte 2 = F0H: RST 28H code of SYS14/SYS function 7; byte 3 = 88H: open the file in 4480H (existing, 4424H); the command line pointer is left on the stack for the overlay.
5077-507D
DEFM "PROT" / DEFB 86H, E9H, 00H 50 52 4F 54 86 E9 00
Command table entry for PROT (5077H): byte 1 = 86H: sub-function 06H; byte 2 = E9H: RST 28H code of SYS7/SYS function 7; byte 3 = 00H: no filespec handling.
507E-5085
DEFM "PURGE" / DEFB 89H, E9H, 00H 50 55 52 47 45 89 E9 00
Command table entry for PURGE (507EH): byte 1 = 89H: sub-function 09H; byte 2 = E9H: RST 28H code of SYS7/SYS function 7; byte 3 = 00H: no filespec handling.
5086-5089
DEFM "R" / DEFB 80H, 23H, 00H 52 80 23 00
Command table entry for R (5086H): byte 1 = 80H: sub-function 00H; byte 2 = 23H: RST 28H code of SYS1/SYS function 1; byte 3 = 00H: no filespec handling.
508A-5092
DEFM "RENAME" / DEFB 81H, E4H, B0H 52 45 4E 41 4D 45 81 E4 B0
Command table entry for RENAME (508AH): byte 1 = 81H: sub-function 01H; byte 2 = E4H: RST 28H code of SYS2/SYS function 7; byte 3 = B0H: open the file in 4480H (existing, 4424H); a second filespec follows (optionally after TO), parsed into 51E0H; nothing may follow.
5093-509A
DEFM "ROUTE" / DEFB 81H, F0H, 00H 52 4F 55 54 45 81 F0 00
Command table entry for ROUTE (5093H): byte 1 = 81H: sub-function 01H; byte 2 = F0H: RST 28H code of SYS14/SYS function 7; byte 3 = 00H: no filespec handling.
509B-50A3
DEFM "SETCOM" / DEFB 82H, F1H, 00H 53 45 54 43 4F 4D 82 F1 00
Command table entry for SETCOM (509BH): byte 1 = 82H: sub-function 02H; byte 2 = F1H: RST 28H code of SYS15/SYS function 7; byte 3 = 00H: no filespec handling.
50A4-50AA
DEFM "STMT" / DEFB 89H, EBH, 00H 53 54 4D 54 89 EB 00
Command table entry for STMT (50A4H): byte 1 = 89H: sub-function 09H; byte 2 = EBH: RST 28H code of SYS9/SYS function 7; byte 3 = 00H: no filespec handling.
50AB-50B3
DEFM "SYSTEM" / DEFB 81H, E9H, 00H 53 59 53 54 45 4D 81 E9 00
Command table entry for SYSTEM (50ABH): byte 1 = 81H: sub-function 01H; byte 2 = E9H: RST 28H code of SYS7/SYS function 7; byte 3 = 00H: no filespec handling.
50B4-50BA
DEFM "TIME" / DEFB 8AH, E9H, 00H 54 49 4D 45 8A E9 00
Command table entry for TIME (50B4H): byte 1 = 8AH: sub-function 0AH; byte 2 = E9H: RST 28H code of SYS7/SYS function 7; byte 3 = 00H: no filespec handling.
50BB-50C3
DEFM "VERIFY" / DEFB 84H, E5H, 00H 56 45 52 49 46 59 84 E5 00
Command table entry for VERIFY (50BBH): byte 1 = 84H: sub-function 04H; byte 2 = E5H: RST 28H code of SYS3/SYS function 7; byte 3 = 00H: no filespec handling.
50C4-50CC
DEFM "WRDIRP" / DEFB 80H, 53H, 00H 57 52 44 49 52 50 80 53 00
Command table entry for WRDIRP (50C4H): byte 1 = 80H: sub-function 00H; byte 2 = 53H: RST 28H code of SYS17/SYS function 2; byte 3 = 00H: no filespec handling.
50CD
DEFB 00H 00
The end of the command table: 4EA9H and 50E2H stop at this 00H.

50CEH - LIB Command (Sub-Function 02H)

Lists the command names from the table at 4F6FH, eight to a line, each in an eight-character column.

50CE
LD HL,4F6FH 21 6F 4F
Point Register Pair HL to 4F6FH, the command table.
50D1
LD C,08H 0E 08
Load Register C with 08H, the names per line. 50EBH comes back here for each new line.
50D3
LD B,08H 06 08
Load Register B with 08H, the column width in characters.

Name Loop
Register Pair HL = the table, Register B = columns left, Register C = names left on the line.

50D5
LD A,(HL) 7E
Fetch the next table byte at Register Pair HL into Register A.
50D6
BIT 7,A CB 7F
Test bit 7 of Register A: the first attribute byte, which ends the name.
50D8
INC HL 23
INCrement Register Pair HL to the next table byte. INC HL does not change the flags.
50D9
If the NZ FLAG is set (the end of the name), JUMP to 50E0H.
50DB
GOSUB to 51B6H to display the name character in Register A.
50DE
DECrement Register B (columns left) and, if it is not 0, LOOP BACK to 50D5H for the next character.
50E0
INC HL 23
INCrement Register Pair HL past the second attribute byte.
50E1
INC HL 23
INCrement Register Pair HL past the third attribute byte.
50E2
LD A,(HL) 7E
Fetch the first byte of the next entry at Register Pair HL into Register A.
50E3
OR A B7
OR Register A with itself. The Z FLAG is set at the 00H end of the table.
50E4
If the Z FLAG is set (the end of the table), JUMP to 51B4H to end the line and return.
50E7
DEC C 0D
DECrement Register C, the names left on this line.
50E8
If the Z FLAG is set (eight names shown), GOSUB to 51B4H to start a new line; it keeps the flags.
50EB
If the Z FLAG is set (a new line was started), JUMP to 50D1H to reset both counts in Registers B and C.
50ED
GOSUB to 51ACH to pad the column with the Register B spaces left.
50F0
JUMP to 50D3H to show the next name in a new column.

50F2H - Enter MINI-DOS (Sub-Function 04H)

Saves every register, remembers the Stack Pointer at 42BBH and the cursor state from 4022H, sets bit 7 of 428AH, starts a new line and goes to the exit code, which shows MINI-NEWDOS/80 READY and reads commands. If MINI-DOS or a DOS-CALL is already active it just returns.

50F2
DI F3
Disable interrupts while the state of the interrupted program is saved.
50F3
GOSUB to 5142H to save Register Pairs HL, DE, BC, the alternate set, AF', IX and IY on the stack.
50F6
LD HL,428AH 21 8A 42
Point Register Pair HL to 428AH, the DOS state flags.
50F9
LD A,(HL) 7E
Fetch the flags at Register Pair HL (428AH) into Register A.
50FA
AND C0H E6 C0
AND Register A with C0H, keeping bit 7 (MINI-DOS active) and bit 6 (DOS-CALL active).
50FC
If the NZ FLAG is set (either is active), JUMP to 5131H to restore the registers and return with Register A = 00H.
50FE
LD A,(4022H) 3A 22 40
Fetch the ROM's cursor flag at 4022H into Register A (00H = cursor off, any other value = cursor on).
5101
PUSH AF F5
Save Register Pair AF (Register A = the cursor byte) onto the stack.
5102
LD (42BBH),SP ED 73 BB 42
Store the Stack Pointer at 42BBH; 4DE3H and 5119H reload it.
5106
SET 7,(HL) CB FE
Set bit 7 of the flags at Register Pair HL (428AH): MINI-DOS is active.
5108
EI FB
Enable interrupts again: the interrupted program's state is saved on the stack.
5109
LD A,0DH 3E 0D
Load Register A with 0DH (carriage return), to start MINI-DOS on a new line.
510B
GOSUB to the ROM display routine at 0033H to display Register A (0DH): a new line.
510E
JUMP to 4D8AH to end with no error, which shows the MINI-DOS prompt (bit 7 of 428AH).

5111H - MDRET Command (Sub-Function 06H)

Leaves MINI-DOS and returns to the interrupted program. Restores the stack saved at 5102H, turns the cursor on (0EH) and back off (0FH) if it was off, restores 4022H, clears the MINI-DOS flag and restores all registers. Error 2AH if MINI-DOS is not active.

5111
LD HL,428AH 21 8A 42
Point Register Pair HL to 428AH, the DOS state flags.
5114
BIT 7,(HL) CB 7E
Test bit 7 of the flags at Register Pair HL (428AH): MINI-DOS active.
5116
If the Z FLAG is set (not in MINI-DOS), JUMP to 4D44H for error 2AH.
5119
LD SP,(42BBH) ED 7B BB 42
Load the Stack Pointer from 42BBH, saved at 5102H when MINI-DOS was entered.
511D
LD A,0EH 3E 0E
Load Register A with 0EH, the cursor-on control code.
511F
GOSUB to the ROM display routine at 0033H to display Register A (0EH): the cursor is turned on.
5122
POP AF F1
Restore Register Pair AF from the stack: Register A = the cursor flag saved at 5101H.
5123
OR A B7
OR Register A with itself. The Z FLAG is set if the cursor was off.
5124
LD B,A 47
Copy Register A (the saved cursor flag) into Register B.
5125
LD A,0FH 3E 0F
Load Register A with 0FH, the cursor-off control code. LD does not change the flags.
5127
If the Z FLAG is set (the cursor was off), GOSUB to 0033H to display Register A (0FH) and turn it off again.
512A
LD A,B 78
Load Register A with Register B, the saved cursor flag.
512B
LD (4022H),A 32 22 40
Store Register A at 4022H, the cursor flag as it was when MINI-DOS was entered.
512E
DI F3
Disable interrupts while the registers are restored.
512F
RES 7,(HL) CB BE
Clear bit 7 of the flags at Register Pair HL (428AH): MINI-DOS is no longer active.

5131H - Restore All Registers and Return

Undoes 5142H. 5131H returns Register A = 00H with the Z FLAG set; 5132H (from 4E44H) returns the Register A and flags it is entered with. The EX AF,AF' pair keeps the result in AF while the saved AF' is popped.

5131
XOR A AF
Set Register A to 00H with the Z FLAG set: the result for the caller.
5132
EX AF,AF' 08
Exchange Register Pair AF with the alternate AF': the result is kept in AF'.
5133
POP IY FD E1
Restore Index Register IY from the stack (saved at 514EH).
5135
POP IX DD E1
Restore Index Register IX from the stack (saved at 514CH).
5137
POP AF F1
Restore Register Pair AF from the stack: the caller's AF' value (saved at 514BH), in AF for now.
5138
POP BC C1
Restore Register Pair BC from the stack: the caller's BC' (saved at 514AH), in the main set for now.
5139
POP DE D1
Restore Register Pair DE from the stack: the caller's DE' (saved at 5149H).
513A
POP HL E1
Restore Register Pair HL from the stack: the caller's HL' (saved at 5148H).
513B
EXX D9
Exchange with the alternate set: the three pairs just popped become BC', DE' and HL' again.
513C
POP BC C1
Restore Register Pair BC from the stack: the caller's BC (saved at 5145H).
513D
POP DE D1
Restore Register Pair DE from the stack: the caller's DE (saved at 5144H).
513E
POP HL E1
Restore Register Pair HL from the stack: the caller's HL (saved at 5143H).
513F
EX AF,AF' 08
Exchange Register Pair AF with the alternate AF': the result is back in AF, the caller's AF' in AF'.
5140
EI FB
Enable interrupts again (they were disabled at 512EH or by the caller) before returning.
5141
RET C9
RETurn to the caller of the DOS-CALL or of the MINI-DOS request with Register A and the flags = the result.

5142H - Save All Registers

Pushes Register Pairs HL, DE, BC, HL', DE', BC', AF', IX and IY under the return address. The caller's AF is not saved: the POP AF at 5142H takes the return address into it, and EX AF,AF' parks it while AF' is pushed.

5142
POP AF F1
Restore Register Pair AF from the stack: the return address of this call (the caller's AF is lost).
5143
PUSH HL E5
Save Register Pair HL (the caller's) onto the stack.
5144
PUSH DE D5
Save Register Pair DE (the caller's) onto the stack.
5145
PUSH BC C5
Save Register Pair BC (the caller's) onto the stack.
5146
EX AF,AF' 08
Exchange Register Pair AF with the alternate AF': the return address goes to AF', the caller's AF' comes into AF.
5147
EXX D9
Exchange Register Pairs BC, DE and HL with the alternate set: the caller's BC', DE', HL' are now in the main registers.
5148
PUSH HL E5
Save Register Pair HL (the caller's HL') onto the stack.
5149
PUSH DE D5
Save Register Pair DE (the caller's DE') onto the stack.
514A
PUSH BC C5
Save Register Pair BC (the caller's BC') onto the stack.
514B
PUSH AF F5
Save Register Pair AF (the caller's AF') onto the stack.
514C
PUSH IX DD E5
Save Index Register IX (the caller's) onto the stack.
514E
PUSH IY FD E5
Save Index Register IY (the caller's) onto the stack.
5150
EXX D9
Exchange back to the main register set (the alternate set holds the caller's values again).
5151
EX AF,AF' 08
Exchange Register Pair AF with the alternate AF': the return address comes back into AF.
5152
PUSH AF F5
Save Register Pair AF (the return address) onto the stack.
5153
RET C9
RETurn to it, with the nine words saved below.

5154H - Function 4: Extract a Filespec

Entered through SYS0/SYS 441CH with Register Pair HL pointing to the text and Register Pair DE to a 32-byte buffer. Parses the filespec (5167H), then moves Register Pair HL past the character that ended it unless that character is 03H or 0DH. Returns the Z FLAG if the filespec was valid.

5154
GOSUB to 5167H to parse the filespec at Register Pair HL into the buffer at Register Pair DE. The Z FLAG returns for a valid filespec.
5157
PUSH AF F5
Save Register Pair AF (the parse result) onto the stack.
5158
LD A,(HL) 7E
Fetch the character that ended the filespec at Register Pair HL into Register A.
5159
SUB 03H D6 03
SUBtract 03H from Register A. The Z FLAG is set if it was 03H.
515B
If the Z FLAG is set (03H), JUMP to 515FH; the Z FLAG is still set there, so it goes on to 5162H.
515D
SUB 0AH D6 0A
SUBtract 0AH more from Register A. The Z FLAG is set if the character was 0DH.
515F
If the Z FLAG is set (03H or 0DH), JUMP to 5162H without moving Register Pair HL.
5161
INC HL 23
INCrement Register Pair HL past the character that ended the filespec.
5162
POP AF F1
Restore Register Pair AF from the stack: the parse result.
5163
RET C9
RETurn with the Z FLAG for a valid filespec, Register Pair HL at the next item.

5164H - Parse a Filespec

5164H parses into the buffer at 4480H (called from 4EE3H). 5167H parses into the buffer at Register Pair DE (from 4F04H, 5154H and sub-function 0BH at 4D3EH). At most 32 bytes are used. Register Pair DE is preserved and Register B is returned as 00H.

5164
LD DE,4480H 11 80 44
Point Register Pair DE to 4480H, the DOS FCB, as the buffer.
5167
PUSH DE D5
Save Register Pair DE (the buffer address) onto the stack.
5168
LD B,20H 06 20
Load Register B with 20H (32), the size of the buffer.
516A
GOSUB to 5171H to copy the filespec from Register Pair HL to Register Pair DE.
516D
POP DE D1
Restore Register Pair DE from the stack: the buffer address.
516E
LD B,00H 06 00
Load Register B with 00H (the record length for the open that may follow). LD does not change the flags.
5170
RET C9
RETurn with the parse result in the flags: the Z FLAG for a valid filespec.

5171H - Copy the Filespec Characters

An optional asterisk is copied first. The next character must be a digit or a letter. Then digits, letters, ., / and : are copied until any other character, which is left at Register Pair HL; the filespec in the buffer is ended with 03H and the routine returns with Register A = 00H and the Z FLAG. If the first character is not a digit or letter, or the buffer fills, it returns NZ with Register Pair HL back at the start and Register A = that character.

5171
LD A,(HL) 7E
Fetch the first character at Register Pair HL into Register A.
5172
CP 2AH FE 2A
Compare Register A (the first character) against 2AH, an asterisk, which may start a filespec.
5174
If the NZ FLAG is set (not an asterisk), JUMP to 517AH.
5176
LD (DE),A 12
Store Register A (the asterisk) in the buffer at Register Pair DE.
5177
INC DE 13
INCrement Register Pair DE, the buffer pointer.
5178
INC HL 23
INCrement Register Pair HL, the text pointer.
5179
DEC B 05
DECrement Register B: one byte less room in the buffer.
517A
PUSH HL E5
Save Register Pair HL (the start of the name) onto the stack.
517B
LD A,(HL) 7E
Fetch the character at Register Pair HL into Register A.
517C
SUB 30H D6 30
SUBtract 30H (ASCII 0) from Register A, so that the digits become 00H-09H.
517E
CP 0AH FE 0A
Compare Register A against 0AH. The CARRY FLAG is set for a digit.
5180
GOSUB to 51A0H, which also sets the CARRY FLAG for a letter at Register Pair HL.
5183
If the NO CARRY FLAG is set (neither a digit nor a letter), JUMP to 519BH to return NZ.

Copy Loop

5185
LD A,(HL) 7E
Fetch the character at Register Pair HL into Register A.
5186
SUB 2EH D6 2E
SUBtract 2EH (ASCII period) from Register A, so that . / 0-9 : become 00H-0CH.
5188
CP 0DH FE 0D
Compare Register A against 0DH. The CARRY FLAG is set for . / 0-9 : (2EH-3AH).
518A
GOSUB to 51A0H, which also sets the CARRY FLAG for a letter at Register Pair HL.
518D
If the CARRY FLAG is set (a filespec character), JUMP to 5195H to copy it.
518F
LD A,03H 3E 03
Any other character ends the filespec: load Register A with 03H.
5191
LD (DE),A 12
Store Register A (03H) in the buffer at Register Pair DE, the end marker.
5192
POP AF F1
Restore Register Pair AF from the stack to drop the saved text pointer.
5193
XOR A AF
Set Register A to 00H with the Z FLAG set: a valid filespec.
5194
RET C9
RETurn with Register Pair HL at the character that ended the filespec.
5195
LD A,(HL) 7E
Fetch the character at Register Pair HL into Register A.
5196
LD (DE),A 12
Store Register A in the buffer at Register Pair DE.
5197
INC DE 13
INCrement Register Pair DE, the buffer pointer.
5198
INC HL 23
INCrement Register Pair HL, the text pointer.
5199
DECrement Register B (room left) and, if it is not 0, LOOP BACK to 5185H.
519B
OR 01H F6 01
Error: OR Register A with 01H to set the NZ FLAG.
519D
POP HL E1
Restore Register Pair HL from the stack: the start of the filespec.
519E
LD A,(HL) 7E
Fetch the character at Register Pair HL into Register A, for the caller.
519F
RET C9
RETurn with the NZ FLAG: no valid filespec; Register Pair HL is back at its start.

51A0H - Letter Test

Entered with the CARRY FLAG already set if an earlier test passed. Returns the CARRY FLAG set if the character at Register Pair HL is A-Z or a-z (or if it was set on entry).

51A0
RET C D8
If the CARRY FLAG is set (the caller's test already accepted it), RETurn at once.
51A1
LD A,(HL) 7E
Fetch the character at Register Pair HL into Register A.
51A2
SUB 41H D6 41
SUBtract 41H (ASCII A) from Register A, so that A-Z become 00H-19H.
51A4
CP 1AH FE 1A
Compare Register A against 1AH (26). The CARRY FLAG is set for A-Z.
51A6
RET C D8
If the CARRY FLAG is set (an upper case letter), RETurn with it.
51A7
SUB 20H D6 20
SUBtract 20H more from Register A, so that 00H stands for a.
51A9
CP 1AH FE 1A
Compare Register A against 1AH. The CARRY FLAG is set for a-z.
51AB
RET C9
RETurn with the CARRY FLAG set for a lower case letter.

51ACH - Display Spaces

Displays Register B spaces. Called from 50EDH.

51AC
LD A,20H 3E 20
Load Register A with 20H (ASCII space), the padding character.
51AE
GOSUB to 51B6H to display Register A (a space).
51B1
DECrement Register B and, if it is not 0, LOOP BACK to 51ACH.
51B3
RET C9
RETurn with Register B = 00H: the column is filled with spaces.

51B4H - Display a Carriage Return

51B6H displays the character in Register A, keeping Register Pairs AF and DE.

51B4
LD A,0DH 3E 0D
Load Register A with 0DH (carriage return) and fall into 51B6H to display it.
51B6
PUSH DE D5
Save Register Pair DE onto the stack (the ROM routine uses it).
51B7
PUSH AF F5
Save Register Pair AF onto the stack (the character and the flags).
51B8
GOSUB to the ROM display routine at 0033H to display Register A.
51BB
POP AF F1
Restore Register Pair AF from the stack. 4F1FH also uses 51BBH as a base address.
51BC
POP DE D1
Restore Register Pair DE from the stack, as the caller had it.
51BD
RET C9
RETurn with Register Pairs AF and DE as they were.

51BEH - Extensions and Messages (Data)

The default extensions, the word TO, the two READY prompts and the CLS message.

51BE-51C0
DEFM "CMD" 43 4D 44
Default extension 1, CMD, found by 4F1FH-4F26H (51BBH + 3 x 1) for attribute byte 3 bits 0-2 = 1.
51C1-51C3
DEFM "JCL" 4A 43 4C
Default extension 2, JCL (51BBH + 3 x 2), used for CHAIN and DO.
51C4-51C6
DEFM "TO" / DEFB 00H 54 4F 00
The word TO ended by 00H, which 4EF5H compares with the command line through 4C6AH before a second filespec.
51C7-51CB
DEFM "Mini-" 4D 69 6E 69 2D
The start of the MINI-DOS prompt: 4DE7H points here, so the message reads Mini-NewDos/80 Ready.
51CC-51DB
DEFM "NewDos/80 Ready" / DEFB 0DH 4E 65 77 44 6F 73 2F 38 30 20 52 65 61 64 79 0D
The DOS READY prompt, displayed by 4DF2H from 4DDCH (or from 51C7H in MINI-DOS), ended by a carriage return.
51DC-51DE
DEFB 1CH, 1FH, 03H 1C 1F 03
The CLS message (4D48H): 1CH cursor to the top left, 1FH erase to the end of the screen, 03H end of message.
51DF
DEFB 00H 00
A byte of 00H at the end of the file. SYS1/SYS does not refer to it.