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

Page Customization

Introduction/Summary

SYS1/SYS is the DOS command overlay of NEWDOS/80 v2.0 for the Model I. It loads at 4D00H-51DFH (1,248 bytes, entry point 4D00H) and runs whenever SYS0 issues an RST 28H with a code whose low five bits are 03H (directory sector 5, first file). It shows the NEWDOS/80 READY and MINI-NEWDOS/80 READY prompts, reads a command line, looks the command up in its library table and starts the overlay that carries it out. It also provides DOS-CALL, filespec extraction and default extension insertion to the rest of the system, and the LIB, CLS, MDRET and MDBORT commands itself.

SYS1 Functions

SYS0 selects the function with bits 5-7 of the RST 28H code. Function 7 takes a sub-function number in Register C.

CodeHandlerPurpose
23H4D8AHFunction 1: DOS READY with no error (SYS0 4400H, reached from 402DH). Also the target of the R table entry.
43H4D7CHFunction 2: exit after an error has already been displayed (SYS0 4030H).
63H4E30HFunction 3: execute the DOS command at HL (SYS0 4405H).
83H513DHFunction 4: extract a filespec from HL into the buffer at DE (SYS0 441CH).
A3H4F2AHFunction 5: insert the default extension at HL into the filespec at DE (SYS0 4473H).
C3H4D5BHFunction 6: DOS-CALL, execute the command at HL and return (SYS0 4419H).
E3H, C=01H4D59HDiscard one stack word and return.
E3H, C=02H50B7HLIB: list the library commands.
E3H, C=04H50DBHEnter MINI-DOS.
E3H, C=05H4D80HMDBORT: abandon MINI-DOS and the interrupted program.
E3H, C=06H50FAHMDRET: leave MINI-DOS and resume the interrupted program.
E3H, C=07H4D78HDiscard two stack words and exit with no error.
E3H, C=08H4E34HExecute the line just typed at DOS READY (set up at 4DFAH).
E3H, C=09H4D48HCLS: clear the screen.
E3H, C=0BH5150HParse a filespec from HL into the buffer at DE.
E3H, C=0CH4D80HThe same as MDBORT.
other4D44HError 2AH (this includes sub-functions 03H and 0AH).

Command Table Format

The library command table at 4F58H holds 46 commands in alphabetical order. Each entry is the name in plain ASCII followed by three attribute bytes; the table ends with 00H. A command that is not in the table is run as a program (default extension /CMD) by SYS2, unless it starts with *, which goes to SYS9.

ByteMeaning
1Bit 7 always set (marks the end of the name). Bit 6 = not allowed under MINI-DOS (error 38H). Bits 0-4 = sub-function number passed to the overlay in Register C.
2The RST 28H code of the overlay function: bits 0-2 = directory sector minus 2, bits 3-4 = file within that sector, bits 5-7 = function. For example E9H = SYS7 function 7, EBH = SYS9 function 7, E5H = SYS3 function 7, F0H = SYS14 function 7.
3Bit 7 = open the file in the FCB at 4480H (bit 6 also set: new or existing, SYS0 4420H; otherwise existing only, 4424H). Bit 6 or 7 = parse a filespec into 4480H. Bit 5 = a second filespec follows, optionally after TO, into 51E0H. Bit 4 = nothing may follow (error 34H). Bit 3 = leave the command line pointer on the stack for the overlay. Bits 0-2 = default extension: 1 = /CMD, 2 = /JCL.

Error Codes Set by SYS1

  • 2AH - unknown function or sub-function; MDRET when MINI-DOS is not active (4D44H).
  • 30H - a filespec could not be parsed (4EF1H).
  • 34H - a separator was missing or something followed a command that allows nothing after it (set by SYS0 4CD5H/4CD9H).
  • 36H - the command line is longer than 80 characters (4E5BH).
  • 38H - the command is not allowed under MINI-DOS (4EBCH).

Variables

Memory Used by SYS1

Address
Size
Contents
4022H
1 byte
Cursor Byte
The ROM's cursor byte (00H = cursor off, otherwise the character under the cursor). Saved when MINI-DOS is entered (50E7H) and restored by MDRET (5114H).
4200H-42FFH
256 bytes
Sector Buffer
Passed in Register Pair HL when a command's file is opened (4F1FH).
4312H-4314H
3 bytes
BREAK Key Hook
Rewritten at 4DCDH-4DD9H as JP 45B0H (BREAK ignored, Register A = 00H) or RET (BREAK is a key), chosen by option AG (bit 5 of 436CH).
4318H-4367H
80 bytes
Command Buffer
The ROM line input writes here (4E0AH); every command is copied here in upper case (4E43H).
4369H
1 byte
DOS Flags
Bit 5 (chaining): suppresses the READY message (4DF0H), sends errors to SYS9 sub-function 04H (4DA8H), and keeps a DOS-CALL at the prompt when bit 4 of 436AH is also set (4E15H); cleared by MDBORT. Bit 6: cleared at every exit (4DACH). Bit 4: cleared when a nested DOS-CALL returns (4E25H).
436AH
1 byte
DOS State Flags
Bit 7 MINI-DOS active. Bit 6 DOS-CALL active. Bit 5 waiting for a command line at DOS READY (set at 4DF8H, cleared at 4E41H). Bit 4 chaining under DOS-CALL (4E19H); cleared by MDBORT and when the outermost DOS-CALL returns. Bit 2 an error at reset: every exit goes to SYS9 sub-function 0BH (4D98H).
436BH
1 byte
Temporary Flags
Cleared at every exit (4D8FH).
436CH
1 byte
Options F0H
Bit 6 option AB (RUN-ONLY): exits go to SYS9 sub-function 0CH unless chaining (4DB5H). Bit 5 option AG: selects the BREAK hook (4DCBH).
436DH
1 byte
Options F1H
Bit 5 option BE: the R command repeats the previous command (4E62H).
439BH-439CH
2 bytes
MINI-DOS Stack
The Stack Pointer saved when MINI-DOS is entered (50EBH), reloaded at 4DE3H and 5102H.
439DH-439EH
2 bytes
DOS-CALL Stack
The Stack Pointer of the innermost DOS-CALL level (4D70H); each level pushes the previous value (4D6FH).
43A7H-43A8H
2 bytes
Previous Command
The first two bytes of the command buffer before a new line is read (4E05H), for the R command.
41E0HDOS Stack
The Stack Pointer is reset here at DOS READY (4DC8H) and by function 3 (4E30H).
4480H-449FH
32 bytes
First Filespec and FCB
A command's filespec is parsed here (514DH) and the file opened from it (4F24H).
51E0H-51FFH
32 bytes
Second Filespec
Just past the end of the file; used by MDCOPY and RENAME (4EEAH).

Outside Routines Called

Address
Size
Contents
0033HROM: display the character in Register A (4DEDH, 50F4H, 5108H, 5110H, 51A1H).
0040HROM: line input into Register Pair HL, Register B characters (4E0DH).
402DH, 4408H, 4409HSYS0: the exits pushed at 4E35H-4E3CH.
4420H, 4424HSYS0: open a file (4F24H, 4F27H).
4467HSYS0: display a message (4D4BH, 4DF2H).
45B0H, 45B5HSYS0: BREAK ignored (4DCDH) and upper case conversion (4E4FH).
49D3H, 49D6HSYS0: return points that issue RST 28H with the word on the stack (4F16H, 4DFDH).
4CC5H, 4CD5H, 4CD9HSYS0: keyword compare and separator tests (4EDEH, 4E85H, 4ED5H).

SYS1 has no self-modifying code.

Disassembly

4D00H - Overlay Entry: Function Dispatcher

SYS0 enters every overlay at its first byte. Register A holds the RST 28H code that loaded SYS1 (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 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 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 4405H).
4D0B
If the Z FLAG is set (Register A = 63H), JUMP to 4E30H 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 441CH).
4D10
If the Z FLAG is set (Register A = 83H), JUMP to 513DH.
4D13
CP A3H FE A3
Compare Register A (the RST 28H code) against A3H, function 5: insert a default extension (SYS0 4473H).
4D15
If the Z FLAG is set (Register A = A3H), JUMP to 4F2AH.
4D18
CP C3H FE C3
Compare Register A (the RST 28H code) against C3H, function 6: DOS-CALL (SYS0 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 50B7H 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's D-F-G check 45CEH), JUMP to 50DBH.
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 50FAH.
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 4DFAH), JUMP to 4E34H 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 5150H 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 50FFH (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 51C5H (1CH cursor home, 1FH clear to end of screen, 03H end of message) to the display.

4D48
LD HL,51C5H 21 C5 51
Point Register Pair HL to 51C5H, the clear-screen string (1CH, 1FH, 03H).
4D4B
JUMP to 4467H, the SYS0 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 jumps or calls to 4D4EH, and SYS0 enters the overlay only at 4D00H. The bytes push E301H (function 7, sub-function 01H) and 49D3H (the SYS0 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 function 7), Register C = 01H (sub-function 01H). Never executed.
4D52
LD DE,49D3H 11 D3 49
Load the alternate Register Pair DE with 49D3H, the SYS0 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 (49D3H) 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 49D3H 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 4419H with Register Pair HL pointing to a DOS command. All registers are saved (512BH). DOS-CALLs can nest: bit 6 of 436AH shows that one is active, and each level pushes the previous level's saved Stack Pointer (439DH) before storing its own. The command is then run by the normal command code at 4E35H. When it finishes, the exit code at 4E10H unwinds one level and returns to the caller.

4D5B
GOSUB to 512BH 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,436AH 21 6A 43
Point Register Pair HL to 436AH, 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 (436AH): 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 (436AH): 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,(439DH) ED 4B 9D 43
A nested DOS-CALL: load Register Pair BC with the previous level's saved Stack Pointer from 439DH.
4D6F
PUSH BC C5
Save Register Pair BC (the previous level's Stack Pointer, or 0000H) onto the stack; 4E1DH takes it back.
4D70
LD (439DH),SP ED 73 9D 43
Store the Stack Pointer at 439DH for this level; 4E11H 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 4E35H 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 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 436AH and bit 5 of 4369H, 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,436AH 21 6A 43
Point Register Pair HL to 436AH, the DOS state flags.
4D83
LD A,(HL) 7E
Fetch the flags at Register Pair HL (436AH) 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 (436AH).
4D87
DEC HL 2B
DECrement Register Pair HL to 4369H, the DOS flags.
4D88
RES 5,(HL) CB AE
Clear bit 5 of the flags at Register Pair HL (4369H): chaining stops.

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

Also reached from 50F7H 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 function 7 is called for sub-functions 0BH, 04H or 0CH; a DOS-CALL is unwound at 4E10H; otherwise the DOS READY (or MINI-DOS READY) prompt is shown and a new command line is read. Register B holds the flags from 436AH and Register C those from 4369H throughout.

4D8B
DI F3
Disable interrupts while the flags and the stack are looked at.
4D8C
LD HL,436BH 21 6B 43
Point Register Pair HL to 436BH, the overlays' temporary flags.
4D8F
LD (HL),00H 36 00
Store 00H at Register Pair HL (436BH): every temporary flag is cleared at the end of a command.
4D91
DEC HL 2B
DECrement Register Pair HL to 436AH, the DOS state flags.
4D92
LD B,(HL) 46
Load Register B with the flags at Register Pair HL (436AH): 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 4369H, the DOS flags.
4D94
LD C,(HL) 4E
Load Register C with the flags at Register Pair HL (4369H): bit 5 chaining.
4D95
LD E,0BH 1E 0B
Load Register E with 0BH, the SYS9 sub-function (DOS FATAL ERROR) used when bit 2 of 436AH 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 (436AH): an error happened at reset (set by SYS4 function 2).
4D9A
If the NZ FLAG is set (bit 2 set), JUMP to 4DBFH to call SYS9 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 4EBCH).
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 sub-function that aborts chaining after an error.
4DA8
BIT 5,C CB 69
Test bit 5 of Register C (4369H): chaining is running.
4DAA
If the NZ FLAG is set (chaining), JUMP to 4DBFH to call SYS9 function 7 with Register E = 04H.
4DAC
RES 6,(HL) CB B6
Clear bit 6 of the flags at Register Pair HL (4369H): no overlay function is running.
4DAE
BIT 6,B CB 70
Test bit 6 of Register B (436AH): a DOS-CALL is active.
4DB0
If the NZ FLAG is set (inside a DOS-CALL), JUMP to 4E10H to return to its caller.
4DB2
LD A,(436CH) 3A 6C 43
Fetch the options at 436CH 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 (436CH): 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 (4369H): 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 sub-function that shows 'RUN ONLY' STOPPED.
4DBF
LD D,EBH 16 EB
Load Register D with EBH, the RST 28H code of SYS9 function 7.
4DC1
LD A,D 7A
Load Register A with Register D (EBH), the RST 28H code of SYS9 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 function 7. When it returns, execution continues at 4DC4H.
4DC4
BIT 7,B CB 78
Test bit 7 of Register B (436AH): 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 436CH options loaded at 4DB2H): option AG, BREAK is a key.
4DCD
LD HL,45B0H 21 B0 45
Load Register Pair HL with 45B0H, the SYS0 routine that returns Register A = 00H.
4DD0
LD (4313H),HL 22 13 43
Store Register Pair HL (45B0H) at 4313H-4314H, the address of the BREAK hook's JP at 4312H.
4DD3
LD A,C3H 3E C3
Load Register A with C3H, the opcode of JP: the hook becomes JP 45B0H 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 (4312H),A 32 12 43
Store Register A (C3H or C9H) at 4312H, the BREAK key hook.

Show the Prompt and Read a Command Line

4DDC
LD HL,51B5H 21 B5 51
Point Register Pair HL to 51B5H, the message NEWDOS/80 READY. Also reached from 4E1BH.
4DDF
BIT 7,B CB 78
Test bit 7 of Register B (436AH): MINI-DOS is active.
4DE1
If the Z FLAG is set (not MINI-DOS), JUMP to 4DEAH.
4DE3
LD SP,(439BH) ED 7B 9B 43
MINI-DOS: load the Stack Pointer from 439BH, saved when MINI-DOS was entered (50EBH).
4DE7
LD HL,51B0H 21 B0 51
Point Register Pair HL to 51B0H, 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 (4369H): 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,436AH 21 6A 43
Point Register Pair HL to 436AH, the DOS state flags.
4DF8
SET 5,(HL) CB EE
Set bit 5 of the flags at Register Pair HL (436AH): waiting for a command line at DOS READY (cleared at 4E41H).
4DFA
LD BC,E308H 01 08 E3
Load Register Pair BC with E308H: Register B = E3H (SYS1 function 7), Register C = 08H (sub-function 08H, run the typed line).
4DFD
LD DE,49D6H 11 D6 49
Load Register Pair DE with 49D6H, the SYS0 return point that issues RST 28H with the word below it on the stack.
4E00
PUSH BC C5
Save Register Pair BC (E308H) onto the stack.
4E01
PUSH DE D5
Save Register Pair DE (49D6H) onto the stack as the return address of the line input.
4E02
LD HL,(4318H) 2A 18 43
Load Register Pair HL from 4318H-4319H: the first two characters of the previous command line.
4E05
LD (43A7H),HL 22 A7 43
Store Register Pair HL (those two characters) at 43A7H-43A8H for the R (repeat) command at 4E5FH.
4E08
LD B,4FH 06 4F
Load Register B with 4FH (79), the most characters the ROM line input accepts.
4E0A
LD HL,4318H 21 18 43
Point Register Pair HL to 4318H, the DOS command buffer.
4E0D
JUMP to the ROM line input at 0040H with Register Pair HL = 4318H and Register B = 4FH. It returns to 49D6H, which issues RST 28H with E3H and sub-function 08H: SYS1 runs the typed line at 4E34H.

4E10H - Return From a DOS-CALL

Reached from 4DB0H when bit 6 of 436AH is set. Register B = the 436AH flags, Register C = the 4369H flags, Register Pair HL = 4369H. 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.

4E10
POP DE D1
Restore Register Pair DE from the stack: the result saved at 4D97H (Register D = the error code, Register E = the flags).
4E11
LD SP,(439DH) ED 7B 9D 43
Load the Stack Pointer from 439DH, saved for this DOS-CALL level at 4D70H.
4E15
BIT 5,C CB 69
Test bit 5 of Register C (4369H): chaining is running.
4E17
If the Z FLAG is set (not chaining), JUMP to 4E1DH.
4E19
BIT 4,B CB 60
Chaining: test bit 4 of Register B (436AH): the chain file runs under this DOS-CALL (CHNON D).
4E1B
If the NZ FLAG is set (both set), JUMP to 4DDCH to show the READY prompt and read another command instead of returning.
4E1D
POP BC C1
Restore Register Pair BC from the stack: the previous level's Stack Pointer, pushed at 4D6FH (0000H at the outermost level).
4E1E
LD A,B 78
Load Register A with Register B, its high byte.
4E1F
OR C B1
OR Register C (the low byte) into Register A. The Z FLAG is set if Register Pair BC is 0000H.
4E20
If the NZ FLAG is set (an outer DOS-CALL is still active), JUMP to 4E25H with Register Pair HL = 4369H.
4E22
INC HL 23
The outermost level: INCrement Register Pair HL to 436AH.
4E23
RES 6,(HL) CB B6
Clear bit 6 of the flags at Register Pair HL (436AH): no DOS-CALL is active any more.
4E25
RES 4,(HL) CB A6
Clear bit 4 of the flags at Register Pair HL (436AH at the outermost level; 4369H otherwise, where bit 4 is option AG's mark).
4E27
LD (439DH),BC ED 43 9D 43
Store Register Pair BC (the previous level's Stack Pointer, or 0000H) back at 439DH.
4E2B
PUSH DE D5
Save Register Pair DE (the command's result) onto the stack.
4E2C
POP AF F1
Restore it into Register Pair AF: Register A = the error code, the flags as the command left them.
4E2D
JUMP to 511BH to restore the registers saved by 512BH at 4D5BH and return to the DOS-CALL caller with Register Pair AF.

4E30H - Function 3: Execute a DOS Command

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

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

4E35H - Copy the Command Line and Look It Up

Pushes 402DH and 4408H so that a command which RETurns goes to 4408H in SYS0 (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 4318H, 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.

4E35
LD BC,402DH 01 2D 40
Load Register Pair BC with 402DH, the SYS0 no-error exit (DOS READY).
4E38
LD DE,4408H 11 08 44
Load Register Pair DE with 4408H, the SYS0 return point (RET Z, otherwise the DOS error exit).
4E3B
PUSH BC C5
Save Register Pair BC (402DH) onto the stack, where the RET Z at 4408H finds it.
4E3C
PUSH DE D5
Save Register Pair DE (4408H) onto the stack: every command returns there.
4E3D
EX DE,HL EB
Exchange Register Pairs DE and HL: Register Pair DE = the command line's source.
4E3E
LD HL,436AH 21 6A 43
Point Register Pair HL to 436AH, the DOS state flags.
4E41
RES 5,(HL) CB AE
Clear bit 5 of the flags at Register Pair HL (436AH): no longer waiting at DOS READY.
4E43
LD HL,4318H 21 18 43
Point Register Pair HL to 4318H, the command buffer.
4E46
LD B,50H 06 50
Load Register B with 50H (80), the length of the command buffer.
4E48
LD A,(HL) 7E
Fetch the first byte of the buffer at Register Pair HL (4318H) into Register A.
4E49
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.
4E4B
RET Z C8
If the Z FLAG is set (an empty line), RETurn to 4408H with the Z FLAG: DOS READY again.
4E4C
PUSH HL E5
Save Register Pair HL (4318H) onto the stack.

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

4E4D
LD A,(DE) 1A
Fetch the next character of the command line at Register Pair DE into Register A.
4E4E
INC DE 13
INCrement Register Pair DE to the next source character.
4E4F
GOSUB to 45B5H (SYS0) to convert Register A to upper case if it is a lower case letter.
4E52
CP 0DH FE 0D
Compare Register A (the character) against 0DH, the end of the line.
4E54
LD (HL),A 77
Store Register A (the character) in the buffer at Register Pair HL.
4E55
INC HL 23
INCrement Register Pair HL to the next buffer byte. INC HL does not change the flags.
4E56
If the Z FLAG is set (the 0DH was copied), JUMP to 4E5FH.
4E58
DECrement Register B (room left) and, if it is not 0, LOOP BACK to 4E4DH.
4E5A
POP AF F1
80 characters without a carriage return: restore Register Pair AF from the stack to drop the saved buffer address.
4E5B
LD A,36H 3E 36
Load Register A with error code 36H (COMMAND TOO LONG).
4E5D
OR A B7
OR Register A (36H) with itself to set the NZ FLAG.
4E5E
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 43A7H before the input.

4E5F
LD A,(436DH) 3A 6D 43
Fetch the options at 436DH into Register A (bit 5 = option BE, the R command).
4E62
BIT 5,A CB 6F
Test bit 5 of Register A (436DH): option BE. The Z FLAG is set when R is not enabled.
4E64
If the Z FLAG is set (BE = N), JUMP to 4E75H.
4E66
LD HL,(4318H) 2A 18 43
Load Register Pair HL with the first two bytes of the line from 4318H-4319H.
4E69
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.
4E6C
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.
4E6D
If the NZ FLAG is set (the line is not just R), JUMP to 4E75H.
4E6F
LD HL,(43A7H) 2A A7 43
Load Register Pair HL with the two bytes saved at 43A7H-43A8H by 4E05H.
4E72
LD (4318H),HL 22 18 43
Store Register Pair HL at 4318H-4319H, which restores the previous command in the buffer.
4E75
POP HL E1
Restore Register Pair HL from the stack: 4318H, the start of the command.

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

4E76
LD DE,4F58H 11 58 4F
Point Register Pair DE to 4F58H, the command table.
4E79
PUSH HL E5
Save Register Pair HL (the start of the command) onto the stack.
4E7A
LD A,(DE) 1A
Fetch the next table byte at Register Pair DE into Register A.
4E7B
CP (HL) BE
Compare Register A (the table byte) against the command character at Register Pair HL.
4E7C
INC DE 13
INCrement Register Pair DE, the table pointer. INC does not change the flags.
4E7D
INC HL 23
INCrement Register Pair HL, the command pointer.
4E7E
If the Z FLAG is set (they match), LOOP BACK to 4E7AH.
4E80
DEC HL 2B
DECrement Register Pair HL back to the command character that did not match.
4E81
DEC DE 1B
DECrement Register Pair DE back to the table byte.
4E82
RLCA 07
Rotate Register A (the table byte) left: bit 7 goes into the CARRY FLAG.
4E83
If the NO CARRY FLAG is set (a name character did not match), JUMP to 4E8AH to try the next entry.
4E85
The whole name matched (the mismatch was the attribute byte): GOSUB to 4CD5H (SYS0), 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.
4E88
If the NO CARRY FLAG is set (the command word ends here), JUMP to 4EA7H to run it.
4E8A
POP HL E1
Not this entry: restore Register Pair HL from the stack, the start of the command.
4E8B
LD A,(DE) 1A
Fetch the table byte at Register Pair DE into Register A.
4E8C
RLCA 07
Rotate Register A left: bit 7 (the first attribute byte) goes into the CARRY FLAG.
4E8D
INC DE 13
INCrement Register Pair DE, the table pointer.
4E8E
If the NO CARRY FLAG is set (still in the name), LOOP BACK to 4E8BH.
4E90
INC DE 13
INCrement Register Pair DE past the second attribute byte.
4E91
INC DE 13
INCrement Register Pair DE past the third attribute byte.
4E92
LD A,(DE) 1A
Fetch the first byte of the next entry at Register Pair DE into Register A.
4E93
OR A B7
OR Register A with itself. The Z FLAG is set at the 00H end of the table.
4E94
If the NZ FLAG is set (another entry), LOOP BACK to 4E79H.

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

4E96
LD BC,E443H 01 43 E4
Load Register Pair BC with E443H: Register B = E4H (SYS2 function 7), Register C = 43H (byte 1: not under MINI-DOS, sub-function 03H).
4E99
LD D,41H 16 41
Load Register D with 41H (byte 3: parse a filespec into 4480H, default extension /CMD).
4E9B
LD A,(HL) 7E
Fetch the first character of the command at Register Pair HL into Register A.
4E9C
CP 2AH FE 2A
Compare Register A (the first character) against 2AH, an asterisk: the start of a *name command.
4E9E
If the NZ FLAG is set (not an asterisk), JUMP to 4EB0H to run the program named at Register Pair HL.
4EA0
LD A,EBH 3E EB
Load Register A with EBH, the RST 28H code of SYS9 function 7.
4EA2
LD C,07H 0E 07
Load Register C with 07H, SYS9's sub-function for a *name command.
4EA4
RST 28H EF
RST 28H with Register A = EBH and Register C = 07H: SYS9 runs the *name routine named at Register Pair HL.
4EA5
POP BC C1
Restore Register Pair BC from the stack to drop the word on top. The error exits from 4ED8H, 4EE7H, 4EF3H and 4EFAH also come here.
4EA6
RET C9
RETurn (to 4408H in SYS0) with Register A and the flags as they are.

4EA7H - 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 49D3H and returning to it: 49D3H 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.

4EA7
POP BC C1
Restore Register Pair BC from the stack to drop the saved start of the command.
4EA8
LD A,(DE) 1A
Fetch attribute byte 1 at Register Pair DE into Register A.
4EA9
LD C,A 4F
Copy Register A (attribute byte 1) into Register C: MINI-DOS bit and sub-function.
4EAA
INC DE 13
INCrement Register Pair DE to attribute byte 2.
4EAB
LD A,(DE) 1A
Fetch attribute byte 2 at Register Pair DE (the RST 28H code) into Register A.
4EAC
LD B,A 47
Copy Register A (attribute byte 2) into Register B: the RST 28H code of the overlay.
4EAD
INC DE 13
INCrement Register Pair DE to attribute byte 3.
4EAE
LD A,(DE) 1A
Fetch attribute byte 3 at Register Pair DE into Register A.
4EAF
LD D,A 57
Copy Register A (attribute byte 3) into Register D: the filespec flags.
4EB0
BIT 6,C CB 71
Test bit 6 of Register C (byte 1): not allowed under MINI-DOS. Also the entry from 4E9EH for a program name.
4EB2
If the Z FLAG is set (allowed), JUMP to 4EC3H.
4EB4
LD A,(436AH) 3A 6A 43
Fetch the DOS state flags at 436AH into Register A.
4EB7
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.
4EB8
If the NO CARRY FLAG is set (not in MINI-DOS), JUMP to 4EC3H.
4EBA
AND 80H E6 80
AND Register A with 80H, testing the DOS-CALL bit (now bit 7).
4EBC
LD A,38H 3E 38
Load Register A with error code 38H (ILLEGAL MINI DOS FUNCTION). LD does not change the flags.
4EBE
If the NZ FLAG is set (a DOS-CALL is active), JUMP to 4D8BH to end the command with error 38H.
4EC1
OR A B7
OR Register A (38H) with itself to set the NZ FLAG.
4EC2
RET C9
RETurn to 4408H with error 38H in Register A.
4EC3
LD A,C 79
Load Register A with Register C, attribute byte 1.
4EC4
AND 1FH E6 1F
AND Register A with 1FH, keeping bits 0-4: the sub-function number.
4EC6
LD C,A 4F
Copy Register A (the sub-function) into Register C.
4EC7
PUSH BC C5
Save Register Pair BC onto the stack: Register B = the RST 28H code, Register C = the sub-function. 49D9H takes them from here.
4EC8
LD C,D 4A
Load Register C with Register D, attribute byte 3.
4EC9
LD A,C 79
Load Register A with Register C (attribute byte 3, the filespec flags).
4ECA
AND C0H E6 C0
AND Register A with C0H, keeping bits 6-7. The NZ FLAG is set if a filespec is wanted.
4ECC
If the NZ FLAG is set, GOSUB to 514DH to parse a filespec from the command line at Register Pair HL into 4480H.
4ECF
If the NZ FLAG is set (the filespec could not be parsed), JUMP to 4EF1H for error 30H.
4ED1
BIT 5,C CB 69
Test bit 5 of Register C (byte 3): a second filespec follows.
4ED3
If the Z FLAG is set (no second filespec), JUMP to 4EF5H.
4ED5
GOSUB to 4CD9H (SYS0), which returns NO CARRY after a comma or spaces with Register Pair HL past them.
4ED8
If the CARRY FLAG is set (no separator; Register A = 34H), JUMP to 4EA5H to return the error.
4EDA
PUSH BC C5
Save Register Pair BC (Register C = byte 3) onto the stack.
4EDB
LD BC,51ADH 01 AD 51
Point Register Pair BC to 51ADH, the word TO ended by 00H.
4EDE
GOSUB to 4CC5H (SYS0) 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.
4EE1
POP BC C1
Restore Register Pair BC from the stack (Register C = byte 3).
4EE2
If the NZ FLAG is set (no TO), JUMP to 4EE9H.
4EE4
GOSUB to 4CD9H (SYS0) to step over the comma or spaces after TO at Register Pair HL.
4EE7
If the CARRY FLAG is set (no separator after TO; Register A = 34H), JUMP to 4EA5H to return the error.
4EE9
PUSH DE D5
Save Register Pair DE (4480H, from 514DH) onto the stack.
4EEA
LD DE,51E0H 11 E0 51
Point Register Pair DE to 51E0H, the second filespec buffer.
4EED
GOSUB to 5150H to parse the second filespec at Register Pair HL into the buffer at Register Pair DE.
4EF0
POP DE D1
Restore Register Pair DE from the stack: 4480H.
4EF1
LD A,30H 3E 30
Load Register A with error code 30H (BAD FILESPEC). LD does not change the flags.
4EF3
If the NZ FLAG is set (the parse failed), JUMP to 4EA5H to return error 30H.
4EF5
BIT 4,C CB 61
Test bit 4 of Register C (byte 3): nothing may follow.
4EF7
If the NZ FLAG is set, GOSUB to 4CD5H (SYS0), which returns the Z FLAG only at the carriage return at Register Pair HL; anything else gives the NZ FLAG with Register A = 34H.
4EFA
If the NZ FLAG is set (something follows), JUMP to 4EA5H to return error 34H.
4EFC
BIT 3,C CB 59
Test bit 3 of Register C (byte 3): leave the command line pointer for the overlay.
4EFE
If the Z FLAG is set (bit 3 clear), JUMP to 4F02H.
4F00
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).
4F01
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.
4F02
LD A,C 79
Load Register A with Register C, attribute byte 3.
4F03
AND 07H E6 07
AND Register A with 07H, keeping bits 0-2: the default extension number.
4F05
If the Z FLAG is set (bits 0-2 = 0: no default extension), JUMP to 4F15H.
4F07
PUSH HL E5
Save Register Pair HL (the command line pointer) onto the stack.
4F08
LD HL,51A4H 21 A4 51
Point Register Pair HL to 51A4H, three bytes before the extension list at 51A7H.
4F0B
INC HL 23
INCrement Register Pair HL, the first of three steps to the next extension.
4F0C
INC HL 23
INCrement Register Pair HL again (second of three steps to the next extension).
4F0D
INC HL 23
INCrement Register Pair HL a third time: three bytes further.
4F0E
DEC A 3D
DECrement Register A, the extension number still to count. The Z FLAG is set at 0.
4F0F
If the NZ FLAG is set (Register A is not 0), LOOP BACK to 4F0BH. Register Pair HL ends at the wanted extension: 51A7H CMD or 51AAH JCL.
4F11
GOSUB to 4F2AH to insert the extension at Register Pair HL into the filespec at Register Pair DE (4480H) if it has none.
4F14
POP HL E1
Restore Register Pair HL from the stack: the command line pointer.
4F15
LD A,C 79
Load Register A with Register C, attribute byte 3.
4F16
LD BC,49D3H 01 D3 49
Load Register Pair BC with 49D3H, the SYS0 return point that starts the overlay function named on the stack.
4F19
PUSH BC C5
Save Register Pair BC (49D3H) onto the stack as the return address.
4F1A
BIT 7,A CB 7F
Test bit 7 of Register A (byte 3): open the file.
4F1C
RET Z C8
If the Z FLAG is set (no file to open), RETurn to 49D3H with the Z FLAG set, which starts the overlay.
4F1D
LD B,00H 06 00
Load Register B with 00H: the record length (LRL) for the open, 256.
4F1F
LD HL,4200H 21 00 42
Point Register Pair HL to 4200H, the buffer for the FCB at 4480H.
4F22
BIT 6,A CB 77
Test bit 6 of Register A (byte 3): open a new or existing file.
4F24
If the Z FLAG is set (bit 6 clear), JUMP to 4424H (SYS0) to open the existing file in the FCB at Register Pair DE (4480H). It returns to 49D3H, which starts the overlay or, on an error, goes to the DOS error exit.
4F27
JUMP to 4420H (SYS0) to open a new or existing file in the FCB at Register Pair DE (4480H). It returns to 49D3H in the same way.

4F2AH - Function 5: Insert a Default Extension

Entered through SYS0 4473H and from 4F11H. 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.

4F2A
PUSH DE D5
Save Register Pair DE (the filespec) onto the stack.
4F2B
PUSH BC C5
Save Register Pair BC (the caller's) onto the stack.
4F2C
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

4F2F
LD A,(DE) 1A
Fetch the next filespec character at Register Pair DE into Register A.
4F30
CP 3AH FE 3A
Compare Register A against 3AH (ASCII colon, the drive number).
4F32
If the Z FLAG is set (a drive number follows), JUMP to 4F3EH to insert the extension here.
4F34
CP 2FH FE 2F
Compare Register A against 2FH (ASCII slash).
4F36
If the CARRY FLAG is set (Register A is below /: the 03H end, a . before a password or another terminator), JUMP to 4F3EH to insert the extension here.
4F38
If the Z FLAG is set (a /: the filespec already has an extension), JUMP to 4F55H.
4F3A
DEC C 0D
DECrement Register C: one byte fewer left to move.
4F3B
INC DE 13
INCrement Register Pair DE to the next filespec character.
4F3C
DECrement Register B and, if it is not 0, LOOP BACK to 4F2FH (up to nine characters).
4F3E
INC HL 23
INCrement Register Pair HL, the extension pointer, towards its last character.
4F3F
INC HL 23
INCrement Register Pair HL again: the last character of the extension.
4F40
PUSH HL E5
Save Register Pair HL (the extension's last character) onto the stack.
4F41
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.
4F42
LD B,00H 06 00
Load Register B with 00H: Register Pair BC = Register C, the bytes to move.
4F44
ADD HL,BC 09
ADD Register Pair BC to Register Pair HL: the end of the bytes to move.
4F45
LD D,H 54
Copy Register H (the high byte of the end of the move) into Register D.
4F46
LD E,L 5D
Copy Register L into Register E: Register Pair DE = Register Pair HL.
4F47
DEC HL 2B
DECrement Register Pair HL to the last byte to move.
4F48
INC DE 13
INCrement Register Pair DE, the first of three steps.
4F49
INC DE 13
INCrement Register Pair DE again (second of three steps beyond Register Pair HL).
4F4A
INC DE 13
INCrement Register Pair DE a third time: Register Pair DE = four bytes past Register Pair HL.
4F4B
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.
4F4D
POP HL E1
Restore Register Pair HL from the stack: the extension's last character.
4F4E
LD C,03H 0E 03
Load Register C with 03H; with Register B = 0 after the LDDR, Register Pair BC = 3.
4F50
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.
4F52
LD A,2FH 3E 2F
Load Register A with 2FH (ASCII slash), the character that starts an extension.
4F54
LD (DE),A 12
Store Register A (/) at Register Pair DE, in front of the extension.
4F55
POP BC C1
Restore Register Pair BC from the stack (the caller's).
4F56
POP DE D1
Restore Register Pair DE from the stack: the filespec.
4F57
RET C9
RETurn with the filespec at Register Pair DE carrying the extension.

4F58H - Command Table (Data)

One entry per DOS command handled by an overlay: the name in ASCII, then three attribute bytes (see 4EA7H). 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 50B6H. LIB (50B7H) lists the names.

4F58-4F60
DEFM "APPEND" / DEFB C0H, 68H, 00H 41 50 50 45 4E 44 C0 68 00
Command table entry for APPEND (4F58H): byte 1 = C0H: not allowed under MINI-DOS (bit 6), sub-function 00H; byte 2 = 68H: RST 28H code of SYS6 function 3; byte 3 = 00H: no filespec handling.
4F61-4F69
DEFM "ATTRIB" / DEFB 85H, E9H, 88H 41 54 54 52 49 42 85 E9 88
Command table entry for ATTRIB (4F61H): byte 1 = 85H: sub-function 05H; byte 2 = E9H: RST 28H code of SYS7 function 7; byte 3 = 88H: open the file in 4480H (existing, 4424H), the command line pointer is left on the stack for the overlay.
4F6A-4F70
DEFM "AUTO" / DEFB 84H, E9H, 00H 41 55 54 4F 84 E9 00
Command table entry for AUTO (4F6AH): byte 1 = 84H: sub-function 04H; byte 2 = E9H: RST 28H code of SYS7 function 7; byte 3 = 00H: no filespec handling.
4F71-4F79
DEFM "BASIC2" / DEFB 86H, EBH, 00H 42 41 53 49 43 32 86 EB 00
Command table entry for BASIC2 (4F71H): byte 1 = 86H: sub-function 06H; byte 2 = EBH: RST 28H code of SYS9 function 7; byte 3 = 00H: no filespec handling.
4F7A-4F81
DEFM "BLINK" / DEFB 81H, E5H, 00H 42 4C 49 4E 4B 81 E5 00
Command table entry for BLINK (4F7AH): byte 1 = 81H: sub-function 01H; byte 2 = E5H: RST 28H code of SYS3 function 7; byte 3 = 00H: no filespec handling.
4F82-4F88
DEFM "BOOT" / DEFB 8AH, EBH, 10H 42 4F 4F 54 8A EB 10
Command table entry for BOOT (4F82H): byte 1 = 8AH: sub-function 0AH; byte 2 = EBH: RST 28H code of SYS9 function 7; byte 3 = 10H: nothing may follow.
4F89-4F90
DEFM "BREAK" / DEFB 85H, E5H, 00H 42 52 45 41 4B 85 E5 00
Command table entry for BREAK (4F89H): byte 1 = 85H: sub-function 05H; byte 2 = E5H: RST 28H code of SYS3 function 7; byte 3 = 00H: no filespec handling.
4F91-4F98
DEFM "CHAIN" / DEFB C3H, EBH, 8AH 43 48 41 49 4E C3 EB 8A
Command table entry for CHAIN (4F91H): byte 1 = C3H: not allowed under MINI-DOS (bit 6), sub-function 03H; byte 2 = EBH: RST 28H code of SYS9 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.
4F99-4FA0
DEFM "CHNON" / DEFB C5H, EBH, 00H 43 48 4E 4F 4E C5 EB 00
Command table entry for CHNON (4F99H): byte 1 = C5H: not allowed under MINI-DOS (bit 6), sub-function 05H; byte 2 = EBH: RST 28H code of SYS9 function 7; byte 3 = 00H: no filespec handling.
4FA1-4FA8
DEFM "CLEAR" / DEFB 84H, F0H, 00H 43 4C 45 41 52 84 F0 00
Command table entry for CLEAR (4FA1H): byte 1 = 84H: sub-function 04H; byte 2 = F0H: RST 28H code of SYS14 function 7; byte 3 = 00H: no filespec handling.
4FA9-4FB0
DEFM "CLOCK" / DEFB 82H, E5H, 00H 43 4C 4F 43 4B 82 E5 00
Command table entry for CLOCK (4FA9H): byte 1 = 82H: sub-function 02H; byte 2 = E5H: RST 28H code of SYS3 function 7; byte 3 = 00H: no filespec handling.
4FB1-4FB6
DEFM "CLS" / DEFB 89H, E3H, 10H 43 4C 53 89 E3 10
Command table entry for CLS (4FB1H): byte 1 = 89H: sub-function 09H; byte 2 = E3H: RST 28H code of SYS1 function 7; byte 3 = 10H: nothing may follow.
4FB7-4FBD
DEFM "COPY" / DEFB C0H, 48H, 00H 43 4F 50 59 C0 48 00
Command table entry for COPY (4FB7H): byte 1 = C0H: not allowed under MINI-DOS (bit 6), sub-function 00H; byte 2 = 48H: RST 28H code of SYS6 function 2; byte 3 = 00H: no filespec handling.
4FBE-4FC6
DEFM "CREATE" / DEFB 82H, F0H, 40H 43 52 45 41 54 45 82 F0 40
Command table entry for CREATE (4FBEH): byte 1 = 82H: sub-function 02H; byte 2 = F0H: RST 28H code of SYS14 function 7; byte 3 = 40H: parse a filespec into 4480H.
4FC7-4FCD
DEFM "DATE" / DEFB 8BH, E9H, 00H 44 41 54 45 8B E9 00
Command table entry for DATE (4FC7H): byte 1 = 8BH: sub-function 0BH; byte 2 = E9H: RST 28H code of SYS7 function 7; byte 3 = 00H: no filespec handling.
4FCE-4FD5
DEFM "DEBUG" / DEFB 83H, E5H, 00H 44 45 42 55 47 83 E5 00
Command table entry for DEBUG (4FCEH): byte 1 = 83H: sub-function 03H; byte 2 = E5H: RST 28H code of SYS3 function 7; byte 3 = 00H: no filespec handling.
4FD6-4FDB
DEFM "DIR" / DEFB 80H, 2AH, 00H 44 49 52 80 2A 00
Command table entry for DIR (4FD6H): byte 1 = 80H: sub-function 00H; byte 2 = 2AH: RST 28H code of SYS8 function 1; byte 3 = 00H: no filespec handling.
4FDC-4FE0
DEFM "DO" / DEFB C3H, EBH, 8AH 44 4F C3 EB 8A
Command table entry for DO (4FDCH): byte 1 = C3H: not allowed under MINI-DOS (bit 6), sub-function 03H; byte 2 = EBH: RST 28H code of SYS9 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.
4FE1-4FE7
DEFM "DUMP" / DEFB 87H, E9H, C8H 44 55 4D 50 87 E9 C8
Command table entry for DUMP (4FE1H): byte 1 = 87H: sub-function 07H; byte 2 = E9H: RST 28H code of SYS7 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.
4FE8-4FEF
DEFM "ERROR" / DEFB 87H, F0H, 00H 45 52 52 4F 52 87 F0 00
Command table entry for ERROR (4FE8H): byte 1 = 87H: sub-function 07H; byte 2 = F0H: RST 28H code of SYS14 function 7; byte 3 = 00H: no filespec handling.
4FF0-4FF8
DEFM "FORMAT" / DEFB C0H, 28H, 00H 46 4F 52 4D 41 54 C0 28 00
Command table entry for FORMAT (4FF0H): byte 1 = C0H: not allowed under MINI-DOS (bit 6), sub-function 00H; byte 2 = 28H: RST 28H code of SYS6 function 1; byte 3 = 00H: no filespec handling.
4FF9-4FFF
DEFM "FREE" / DEFB 80H, 4AH, 00H 46 52 45 45 80 4A 00
Command table entry for FREE (4FF9H): byte 1 = 80H: sub-function 00H; byte 2 = 4AH: RST 28H code of SYS8 function 2; byte 3 = 00H: no filespec handling.
5000-5007
DEFM "HIMEM" / DEFB 82H, E9H, 00H 48 49 4D 45 4D 82 E9 00
Command table entry for HIMEM (5000H): byte 1 = 82H: sub-function 02H; byte 2 = E9H: RST 28H code of SYS7 function 7; byte 3 = 00H: no filespec handling.
5008-500D
DEFM "JKL" / DEFB 80H, A5H, 10H 4A 4B 4C 80 A5 10
Command table entry for JKL (5008H): byte 1 = 80H: sub-function 00H; byte 2 = A5H: RST 28H code of SYS3 function 5; byte 3 = 10H: nothing may follow.
500E-5014
DEFM "KILL" / DEFB 80H, 45H, 90H 4B 49 4C 4C 80 45 90
Command table entry for KILL (500EH): byte 1 = 80H: sub-function 00H; byte 2 = 45H: RST 28H code of SYS3 function 2; byte 3 = 90H: open the file in 4480H (existing, 4424H), nothing may follow.
5015-5019
DEFM "LC" / DEFB 89H, E5H, 00H 4C 43 89 E5 00
Command table entry for LC (5015H): byte 1 = 89H: sub-function 09H; byte 2 = E5H: RST 28H code of SYS3 function 7; byte 3 = 00H: no filespec handling.
501A-5021
DEFM "LCDVR" / DEFB 88H, E5H, 00H 4C 43 44 56 52 88 E5 00
Command table entry for LCDVR (501AH): byte 1 = 88H: sub-function 08H; byte 2 = E5H: RST 28H code of SYS3 function 7; byte 3 = 00H: no filespec handling.
5022-5027
DEFM "LIB" / DEFB 82H, E3H, 00H 4C 49 42 82 E3 00
Command table entry for LIB (5022H): byte 1 = 82H: sub-function 02H; byte 2 = E3H: RST 28H code of SYS1 function 7; byte 3 = 00H: no filespec handling.
5028-502E
DEFM "LIST" / DEFB 85H, F0H, 88H 4C 49 53 54 85 F0 88
Command table entry for LIST (5028H): byte 1 = 85H: sub-function 05H; byte 2 = F0H: RST 28H code of SYS14 function 7; byte 3 = 88H: open the file in 4480H (existing, 4424H), the command line pointer is left on the stack for the overlay.
502F-5035
DEFM "LOAD" / DEFB 80H, A4H, 50H 4C 4F 41 44 80 A4 50
Command table entry for LOAD (502FH): byte 1 = 80H: sub-function 00H; byte 2 = A4H: RST 28H code of SYS2 function 5; byte 3 = 50H: parse a filespec into 4480H, nothing may follow.
5036-503E
DEFM "MDBORT" / DEFB 85H, E3H, 00H 4D 44 42 4F 52 54 85 E3 00
Command table entry for MDBORT (5036H): byte 1 = 85H: sub-function 05H; byte 2 = E3H: RST 28H code of SYS1 function 7; byte 3 = 00H: no filespec handling.
503F-5047
DEFM "MDCOPY" / DEFB 82H, EBH, B0H 4D 44 43 4F 50 59 82 EB B0
Command table entry for MDCOPY (503FH): byte 1 = 82H: sub-function 02H; byte 2 = EBH: RST 28H code of SYS9 function 7; byte 3 = B0H: open the file in 4480H (existing, 4424H), a second filespec (after an optional TO) into 51E0H, nothing may follow.
5048-504F
DEFM "MDRET" / DEFB 86H, E3H, 00H 4D 44 52 45 54 86 E3 00
Command table entry for MDRET (5048H): byte 1 = 86H: sub-function 06H; byte 2 = E3H: RST 28H code of SYS1 function 7; byte 3 = 00H: no filespec handling.
5050-5057
DEFM "PAUSE" / DEFB 88H, EBH, 00H 50 41 55 53 45 88 EB 00
Command table entry for PAUSE (5050H): byte 1 = 88H: sub-function 08H; byte 2 = EBH: RST 28H code of SYS9 function 7; byte 3 = 00H: no filespec handling.
5058-5060
DEFM "PDRIVE" / DEFB 83H, E9H, 00H 50 44 52 49 56 45 83 E9 00
Command table entry for PDRIVE (5058H): byte 1 = 83H: sub-function 03H; byte 2 = E9H: RST 28H code of SYS7 function 7; byte 3 = 00H: no filespec handling.
5061-5068
DEFM "PRINT" / DEFB 86H, F0H, 88H 50 52 49 4E 54 86 F0 88
Command table entry for PRINT (5061H): byte 1 = 86H: sub-function 06H; byte 2 = F0H: RST 28H code of SYS14 function 7; byte 3 = 88H: open the file in 4480H (existing, 4424H), the command line pointer is left on the stack for the overlay.
5069-506F
DEFM "PROT" / DEFB 86H, E9H, 00H 50 52 4F 54 86 E9 00
Command table entry for PROT (5069H): byte 1 = 86H: sub-function 06H; byte 2 = E9H: RST 28H code of SYS7 function 7; byte 3 = 00H: no filespec handling.
5070-5077
DEFM "PURGE" / DEFB 89H, E9H, 00H 50 55 52 47 45 89 E9 00
Command table entry for PURGE (5070H): byte 1 = 89H: sub-function 09H; byte 2 = E9H: RST 28H code of SYS7 function 7; byte 3 = 00H: no filespec handling.
5078-507B
DEFM "R" / DEFB 80H, 23H, 00H 52 80 23 00
Command table entry for R (5078H): byte 1 = 80H: sub-function 00H; byte 2 = 23H: RST 28H code of SYS1 function 1; byte 3 = 00H: no filespec handling.
507C-5084
DEFM "RENAME" / DEFB 81H, E4H, B0H 52 45 4E 41 4D 45 81 E4 B0
Command table entry for RENAME (507CH): byte 1 = 81H: sub-function 01H; byte 2 = E4H: RST 28H code of SYS2 function 7; byte 3 = B0H: open the file in 4480H (existing, 4424H), a second filespec (after an optional TO) into 51E0H, nothing may follow.
5085-508C
DEFM "ROUTE" / DEFB 81H, F0H, 00H 52 4F 55 54 45 81 F0 00
Command table entry for ROUTE (5085H): byte 1 = 81H: sub-function 01H; byte 2 = F0H: RST 28H code of SYS14 function 7; byte 3 = 00H: no filespec handling.
508D-5093
DEFM "STMT" / DEFB 89H, EBH, 00H 53 54 4D 54 89 EB 00
Command table entry for STMT (508DH): byte 1 = 89H: sub-function 09H; byte 2 = EBH: RST 28H code of SYS9 function 7; byte 3 = 00H: no filespec handling.
5094-509C
DEFM "SYSTEM" / DEFB 81H, E9H, 00H 53 59 53 54 45 4D 81 E9 00
Command table entry for SYSTEM (5094H): byte 1 = 81H: sub-function 01H; byte 2 = E9H: RST 28H code of SYS7 function 7; byte 3 = 00H: no filespec handling.
509D-50A3
DEFM "TIME" / DEFB 8AH, E9H, 00H 54 49 4D 45 8A E9 00
Command table entry for TIME (509DH): byte 1 = 8AH: sub-function 0AH; byte 2 = E9H: RST 28H code of SYS7 function 7; byte 3 = 00H: no filespec handling.
50A4-50AC
DEFM "VERIFY" / DEFB 84H, E5H, 00H 56 45 52 49 46 59 84 E5 00
Command table entry for VERIFY (50A4H): byte 1 = 84H: sub-function 04H; byte 2 = E5H: RST 28H code of SYS3 function 7; byte 3 = 00H: no filespec handling.
50AD-50B5
DEFM "WRDIRP" / DEFB 80H, 53H, 00H 57 52 44 49 52 50 80 53 00
Command table entry for WRDIRP (50ADH): byte 1 = 80H: sub-function 00H; byte 2 = 53H: RST 28H code of SYS17 function 2; byte 3 = 00H: no filespec handling.
50B6
DEFB 00H 00
50B6H: 00H, the end of the command table, where the searches at 4E92H and 50CBH stop.

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

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

50B7
LD HL,4F58H 21 58 4F
Point Register Pair HL to 4F58H, the command table.
50BA
LD C,08H 0E 08
Load Register C with 08H, the names per line. 50D4H comes back here for each new line.
50BC
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.

50BE
LD A,(HL) 7E
Fetch the next table byte at Register Pair HL into Register A.
50BF
BIT 7,A CB 7F
Test bit 7 of Register A: the first attribute byte, which ends the name.
50C1
INC HL 23
INCrement Register Pair HL to the next table byte. INC HL does not change the flags.
50C2
If the NZ FLAG is set (the end of the name), JUMP to 50C9H.
50C4
GOSUB to 519FH to display the name character in Register A.
50C7
DECrement Register B (columns left) and, if it is not 0, LOOP BACK to 50BEH for the next character.
50C9
INC HL 23
INCrement Register Pair HL past the second attribute byte.
50CA
INC HL 23
INCrement Register Pair HL past the third attribute byte.
50CB
LD A,(HL) 7E
Fetch the first byte of the next entry at Register Pair HL into Register A.
50CC
OR A B7
OR Register A with itself. The Z FLAG is set at the 00H end of the table.
50CD
If the Z FLAG is set (the end of the table), JUMP to 519DH to end the line and return.
50D0
DEC C 0D
DECrement Register C, the names left on this line.
50D1
If the Z FLAG is set (eight names shown), GOSUB to 519DH to start a new line; it keeps the flags.
50D4
If the Z FLAG is set (a new line was started), JUMP to 50BAH to reset both counts in Registers B and C.
50D6
GOSUB to 5195H to pad the column with the Register B spaces left.
50D9
JUMP to 50BCH to show the next name in a new column.

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

Saves every register, remembers the Stack Pointer at 439BH and the cursor state from 4022H, sets bit 7 of 436AH, 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.

50DB
DI F3
Disable interrupts while the state of the interrupted program is saved.
50DC
GOSUB to 512BH to save Register Pairs HL, DE, BC, the alternate set, AF', IX and IY on the stack.
50DF
LD HL,436AH 21 6A 43
Point Register Pair HL to 436AH, the DOS state flags.
50E2
LD A,(HL) 7E
Fetch the flags at Register Pair HL (436AH) into Register A.
50E3
AND C0H E6 C0
AND Register A with C0H, keeping bit 7 (MINI-DOS active) and bit 6 (DOS-CALL active).
50E5
If the NZ FLAG is set (either is active), JUMP to 511AH to restore the registers and return with Register A = 00H.
50E7
LD A,(4022H) 3A 22 40
Fetch the cursor byte at 4022H into Register A (00H = cursor off, else the character under the cursor).
50EA
PUSH AF F5
Save Register Pair AF (Register A = the cursor byte) onto the stack.
50EB
LD (439BH),SP ED 73 9B 43
Store the Stack Pointer at 439BH; 4DE3H and 5102H reload it.
50EF
SET 7,(HL) CB FE
Set bit 7 of the flags at Register Pair HL (436AH): MINI-DOS is active.
50F1
EI FB
Enable interrupts again: the interrupted program's state is saved on the stack.
50F2
LD A,0DH 3E 0D
Load Register A with 0DH (carriage return), to start MINI-DOS on a new line.
50F4
GOSUB to the ROM display routine at 0033H to display Register A (0DH): a new line.
50F7
JUMP to 4D8AH to end with no error, which shows the MINI-DOS prompt (bit 7 of 436AH).

50FAH - MDRET Command (Sub-Function 06H)

Leaves MINI-DOS and returns to the interrupted program. Restores the stack saved at 50EBH, 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.

50FA
LD HL,436AH 21 6A 43
Point Register Pair HL to 436AH, the DOS state flags.
50FD
BIT 7,(HL) CB 7E
Test bit 7 of the flags at Register Pair HL (436AH): MINI-DOS active.
50FF
If the Z FLAG is set (not in MINI-DOS), JUMP to 4D44H for error 2AH.
5102
LD SP,(439BH) ED 7B 9B 43
Load the Stack Pointer from 439BH, saved at 50EBH when MINI-DOS was entered.
5106
LD A,0EH 3E 0E
Load Register A with 0EH, the cursor-on control code.
5108
GOSUB to the ROM display routine at 0033H to display Register A (0EH): the cursor is turned on.
510B
POP AF F1
Restore Register Pair AF from the stack: Register A = the cursor byte saved at 50EAH.
510C
OR A B7
OR Register A with itself. The Z FLAG is set if the cursor was off.
510D
LD B,A 47
Copy Register A (the saved cursor byte) into Register B.
510E
LD A,0FH 3E 0F
Load Register A with 0FH, the cursor-off control code. LD does not change the flags.
5110
If the Z FLAG is set (the cursor was off), GOSUB to 0033H to display Register A (0FH) and turn it off again.
5113
LD A,B 78
Load Register A with Register B, the saved cursor byte.
5114
LD (4022H),A 32 22 40
Store Register A at 4022H, the cursor byte as it was when MINI-DOS was entered.
5117
DI F3
Disable interrupts while the registers are restored.
5118
RES 7,(HL) CB BE
Clear bit 7 of the flags at Register Pair HL (436AH): MINI-DOS is no longer active.

511AH - Restore All Registers and Return

Undoes 512BH. 511AH returns Register A = 00H with the Z FLAG set; 511BH (from 4E2DH) 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.

511A
XOR A AF
Set Register A to 00H with the Z FLAG set: the result for the caller.
511B
EX AF,AF' 08
Exchange Register Pair AF with the alternate AF': the result is kept in AF'.
511C
POP IY FD E1
Restore Index Register IY from the stack (saved at 5137H).
511E
POP IX DD E1
Restore Index Register IX from the stack (saved at 5135H).
5120
POP AF F1
Restore Register Pair AF from the stack: the caller's AF' value (saved at 5134H), in AF for now.
5121
POP BC C1
Restore Register Pair BC from the stack: the caller's BC' (saved at 5133H), in the main set for now.
5122
POP DE D1
Restore Register Pair DE from the stack: the caller's DE' (saved at 5132H).
5123
POP HL E1
Restore Register Pair HL from the stack: the caller's HL' (saved at 5131H).
5124
EXX D9
Exchange with the alternate set: the three pairs just popped become BC', DE' and HL' again.
5125
POP BC C1
Restore Register Pair BC from the stack: the caller's BC (saved at 512EH).
5126
POP DE D1
Restore Register Pair DE from the stack: the caller's DE (saved at 512DH).
5127
POP HL E1
Restore Register Pair HL from the stack: the caller's HL (saved at 512CH).
5128
EX AF,AF' 08
Exchange Register Pair AF with the alternate AF': the result is back in AF, the caller's AF' in AF'.
5129
EI FB
Enable interrupts again (they were disabled at 5117H or by the caller) before returning.
512A
RET C9
RETurn to the caller of the DOS-CALL or of the MINI-DOS request with Register A and the flags = the result.

512BH - 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 512BH takes the return address into it, and EX AF,AF' parks it while AF' is pushed.

512B
POP AF F1
Restore Register Pair AF from the stack: the return address of this call (the caller's AF is lost).
512C
PUSH HL E5
Save Register Pair HL (the caller's) onto the stack.
512D
PUSH DE D5
Save Register Pair DE (the caller's) onto the stack.
512E
PUSH BC C5
Save Register Pair BC (the caller's) onto the stack.
512F
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.
5130
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.
5131
PUSH HL E5
Save Register Pair HL (the caller's HL') onto the stack.
5132
PUSH DE D5
Save Register Pair DE (the caller's DE') onto the stack.
5133
PUSH BC C5
Save Register Pair BC (the caller's BC') onto the stack.
5134
PUSH AF F5
Save Register Pair AF (the caller's AF') onto the stack.
5135
PUSH IX DD E5
Save Index Register IX (the caller's) onto the stack.
5137
PUSH IY FD E5
Save Index Register IY (the caller's) onto the stack.
5139
EXX D9
Exchange back to the main register set (the alternate set holds the caller's values again).
513A
EX AF,AF' 08
Exchange Register Pair AF with the alternate AF': the return address comes back into AF.
513B
PUSH AF F5
Save Register Pair AF (the return address) onto the stack.
513C
RET C9
RETurn to it, with the nine words saved below.

513DH - Function 4: Extract a Filespec

Entered through SYS0 441CH with Register Pair HL pointing to the text and Register Pair DE to a 32-byte buffer. Parses the filespec (5150H), 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.

513D
GOSUB to 5150H to parse the filespec at Register Pair HL into the buffer at Register Pair DE. The Z FLAG returns for a valid filespec.
5140
PUSH AF F5
Save Register Pair AF (the parse result) onto the stack.
5141
LD A,(HL) 7E
Fetch the character that ended the filespec at Register Pair HL into Register A.
5142
SUB 03H D6 03
SUBtract 03H from Register A. The Z FLAG is set if it was 03H.
5144
If the Z FLAG is set (03H), JUMP to 5148H; the Z FLAG is still set there, so it goes on to 514BH.
5146
SUB 0AH D6 0A
SUBtract 0AH more from Register A. The Z FLAG is set if the character was 0DH.
5148
If the Z FLAG is set (03H or 0DH), JUMP to 514BH without moving Register Pair HL.
514A
INC HL 23
INCrement Register Pair HL past the character that ended the filespec.
514B
POP AF F1
Restore Register Pair AF from the stack: the parse result.
514C
RET C9
RETurn with the Z FLAG for a valid filespec, Register Pair HL at the next item.

514DH - Parse a Filespec

514DH parses into the buffer at 4480H (called from 4ECCH). 5150H parses into the buffer at Register Pair DE (from 4EEDH, 513DH and sub-function 0BH at 4D3EH). At most 32 bytes are used. Register Pair DE is preserved and Register B is returned as 00H.

514D
LD DE,4480H 11 80 44
Point Register Pair DE to 4480H, the DOS FCB, as the buffer.
5150
PUSH DE D5
Save Register Pair DE (the buffer address) onto the stack.
5151
LD B,20H 06 20
Load Register B with 20H (32), the size of the buffer.
5153
GOSUB to 515AH to copy the filespec from Register Pair HL to Register Pair DE.
5156
POP DE D1
Restore Register Pair DE from the stack: the buffer address.
5157
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.
5159
RET C9
RETurn with the parse result in the flags: the Z FLAG for a valid filespec.

515AH - Copy the Filespec Characters

An optional * 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.

515A
LD A,(HL) 7E
Fetch the first character at Register Pair HL into Register A.
515B
CP 2AH FE 2A
Compare Register A (the first character) against 2AH, an asterisk, which may start a filespec.
515D
If the NZ FLAG is set (not an asterisk), JUMP to 5163H.
515F
LD (DE),A 12
Store Register A (the asterisk) in the buffer at Register Pair DE.
5160
INC DE 13
INCrement Register Pair DE, the buffer pointer.
5161
INC HL 23
INCrement Register Pair HL, the text pointer.
5162
DEC B 05
DECrement Register B: one byte less room in the buffer.
5163
PUSH HL E5
Save Register Pair HL (the start of the name) onto the stack.
5164
LD A,(HL) 7E
Fetch the character at Register Pair HL into Register A.
5165
SUB 30H D6 30
SUBtract 30H (ASCII 0) from Register A, so that the digits become 00H-09H.
5167
CP 0AH FE 0A
Compare Register A against 0AH. The CARRY FLAG is set for a digit.
5169
GOSUB to 5189H, which also sets the CARRY FLAG for a letter at Register Pair HL.
516C
If the NO CARRY FLAG is set (neither a digit nor a letter), JUMP to 5184H to return NZ.

Copy Loop

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

5189H - 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).

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

5195H - Display Spaces

Displays Register B spaces. Called from 50D6H.

5195
LD A,20H 3E 20
Load Register A with 20H (ASCII space), the padding character.
5197
GOSUB to 519FH to display Register A (a space).
519A
DECrement Register B and, if it is not 0, LOOP BACK to 5195H.
519C
RET C9
RETurn with Register B = 00H: the column is filled with spaces.

519DH - Display a Carriage Return

519FH displays the character in Register A, keeping Register Pairs AF and DE.

519D
LD A,0DH 3E 0D
Load Register A with 0DH (carriage return) and fall into 519FH to display it.
519F
PUSH DE D5
Save Register Pair DE onto the stack (the ROM routine uses it).
51A0
PUSH AF F5
Save Register Pair AF onto the stack (the character and the flags).
51A1
GOSUB to the ROM display routine at 0033H to display Register A.
51A4
POP AF F1
Restore Register Pair AF from the stack. 4F08H also uses 51A4H as a base address.
51A5
POP DE D1
Restore Register Pair DE from the stack, as the caller had it.
51A6
RET C9
RETurn with Register Pairs AF and DE as they were.

51A7H - Default Extensions and Messages (Data)

The extensions are selected by bits 0-2 of the third attribute byte (4F08H). The two messages are shown by 4DF2H through SYS0 4467H: NEWDOS/80 READY starts at 51B5H, MINI-NEWDOS/80 READY at 51B0H.

51A7-51A9
DEFM "CMD" 43 4D 44
Default extension 1, CMD: used for program names (4E99H) and commands with byte 3 bits 0-2 = 1.
51AA-51AC
DEFM "JCL" 4A 43 4C
Default extension 2, JCL: used by CHAIN and DO (byte 3 bits 0-2 = 2).
51AD-51AF
DEFM "TO" / DEFB 00H 54 4F 00
The optional word TO between two filespecs, ended by 00H for the SYS0 compare at 4CC5H (called from 4EDEH).
51B0-51B4
DEFM "MINI-" 4D 49 4E 49 2D
The prefix of the MINI-DOS prompt: 4DE7H points Register Pair HL here so the message reads MINI-NEWDOS/80 READY.
51B5-51C4
DEFM "NEWDOS/80 READY", 0DH 4E 45 57 44 4F 53 2F 38 30 20 52 45 41 44 59 0D
The DOS READY prompt, ended by a carriage return, displayed by 4DF2H.
51C5-51C7
DEFB 1CH, 1FH, 03H 1C 1F 03
The CLS string (4D48H): 1CH cursor home, 1FH clear to the end of the screen, 03H end of message.
51C8-51DF
DEFB 00H x 24 00 x 24
Zero bytes to the end of the file (51DFH). No instruction in SYS1 uses them.

51E0H - Second Filespec Buffer

Not part of the file. The second filespec of MDCOPY and RENAME is parsed here by 4EEDH (at most 31 characters and the 03H end marker).

51E0-51FF
DEFS 32
Not in the file: the second filespec buffer (51E0H-51FFH), filled by 4EEAH-4EEDH and read by SYS2 (RENAME) and SYS9 (MDCOPY).