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

Page Customization

Introduction/Summary

NEWDOS/80 v2.0 SYS13/SYS Disassembly - BASIC Error Messages and RENUM, First Part (Model III)

SYS13/SYS has two jobs. It loads 4D00H-51E7H in five load records (transfer address 4D0CH): RENUM's parameters with their defaults (4D00H-4D0BH), the entry (4D0CH), the message finder (4D11H-4D45H), the table of 58 error messages (4D46H-50FDH), the first part of RENUM (50FEH-51CCH) and 27 bytes of 00H (51CDH-51E7H). The SYS0/SYS dispatcher calls 4D0CH with Register A = the RST 28H code.

  • Error messages (code 2FH). BASIC/CMD's link at 41A6H (LD A,2FH / RST 28H) is called by the ROM's error routine at 19ECH with Register E = the error code, when no ON ERROR GOTO takes the error. SYS13/SYS finds the message for the code (the item number of a GET or PUT list comes first for codes 9CH-A0H), puts 1A01H in place of the ROM's return address and returns with Register Pair HL at the message: the ROM displays it instead of its own question mark, two-letter code and ERROR, then IN and the line number. After a syntax error 409AH is cleared, so the ROM does not go into EDIT on the line.
  • RENUM (code 4FH, from SYS18/SYS). RENUM sssss,iiiii,ppppp,qqqqq[,U][,X]: each number may be left out (keeping its default, 10, 10, 0, 65529) but not given as 0; RENUM alone is SYNTAX ERROR, RENUM followed by a comma takes every default. The range must not be upside down or above 65529. Every line's link field gets the line's new number (its own number outside the range, or nothing changed with U); a line 0 is Can't Process Line 0, a new number above 65529 Seq # Overflow, a link that does not match its line Dos Error (all through BASIC/CMD 5DE2H, which relinks the program first). Then SYS11/SYS is loaded with RST 28H code 2DH over this code and does the rest.

The page shows every byte of the file once, in address order.

The Error Message Table

The messages are in mixed case, each ended by 00H, after a 00H at 4D46H; a second 00H at 50FDH ends the table. The ROM's codes 00H-2EH give message code / 2 (0 Next Without For ... 23 Undefined User Function); the Disk BASIC codes 64H-A6H give message (code - 34H) / 2 (24 Field Overflow ... 57 Bad File Positioning Param). Codes 2FH-63H, odd codes and codes past the table give message 19, Unprintable Error. The codes 70H, 76H, 78H, 92H and A0H are not used and their messages are a single question mark.

Variables

ROM Addresses

Address
Size
Contents
409AH
1 byte
Last Error Code
Stored by the ROM at 19B7H; 4D30H clears it after a syntax error, so READY (1A2BH-1A30H) does not go into EDIT.
40A4H-40A5H
2 bytes
TXTTAB
The first program line (515FH, 51C7H).

DOS Addresses

Address
Size
Contents
4288H
1 byte
Overlay Slot
SYS0/SYS's slot of the overlay in memory, cleared at 50FFH so that SYS13/SYS is read again next time.
4289H
1 byte
System Flags
Bit 6 is cleared by the dispatcher's 4BC5H, through which 4D45H returns.

RENUM Parameters (4D00H-4D0BH)

Address
Size
Contents
4D00H-4D01H
2 bytes
Next New Number
Default 10.
4D02H-4D03H
2 bytes
Increment
Default 10.
4D04H-4D05H
2 bytes
First Old Number
Default 0.
4D06H-4D07H
2 bytes
Last Old Number
Default 65529 (FFF9H).
4D08H-4D09H
2 bytes
Last New Number
Stored at 518EH.
4D0AH
1 byte
Option U
Not 00H with U.
4D0BH
1 byte
Option X
Not 00H with X.

Outside Routines

WhereAddresses
ROM1997H (SYNTAX ERROR), 1A01H (the error routine after its own message), 1E5AH (LINGET); RST 08H, RST 10H, RST 18H.
BASIC/CMD5CCCH (step to the next line), 5D37H (display the item number), 5DE2H (relink and give an error); the link 41A6H (from 680FH) calls SYS13/SYS.
SYS0/SYSThe dispatcher's return 4BC5H.
SYS11/SYSLoaded at 51CCH with RST 28H code 2DH.

Disassembly

4D00H - RENUM Parameters (Data)

The first twelve bytes of the file are RENUM's parameters with their default values. 50FEH overwrites them from the command line; SYS11/SYS loads from 4D0CH on and finds them here. 50FEH clears 4288H, so SYS13/SYS (and with it these defaults) is read from the diskette again the next time it is called.

4D00-4D01
DEFW 000AH 0A 00
The next new line number, 10 by default (the first number of RENUM): read and advanced by the increment at 518BH-519FH.
4D02-4D03
DEFW 000AH 0A 00
The increment, 10 by default (the second number): added at 519BH-519EH.
4D04-4D05
DEFW 0000H 00 00
The first old line number of the range, 0 by default (the third number): read at 514BH and 517DH, and by SYS11/SYS.
4D06-4D07
DEFW FFF9H F9 FF
The last old line number of the range, 65529 by default (the fourth number): read at 514FH and 5185H, and by SYS11/SYS.
4D08-4D09
DEFW 0000H 00 00
The new number given to the last line of the range, stored at 518EH for SYS11/SYS.
4D0A
DEFB 00H 00
Option U, not 00H when given (5133H stores the letter): only check, change nothing (516BH, and SYS11/SYS).
4D0B
DEFB 00H 00
Option X, not 00H when given (5133H stores the letter): SYS11/SYS lists a missing line only when it lies inside the range.

4D0CH - Entry: Error Message or RENUM

The SYS0/SYS dispatcher calls the transfer address 4D0CH with Register A = the RST 28H code. Code 4FH (function 2) comes from SYS18/SYS for RENUM. Code 2FH (function 1) comes from the Disk BASIC link at 41A6H (LD A,2FH / RST 28H, copied from BASIC/CMD's 680FH), which the ROM's error routine calls at 19ECH with Register E = the error code: SYS13/SYS finds the message and makes the ROM carry on at 1A01H with Register Pair HL at it, past the ROM's own question mark, two-letter code and word ERROR.

4D0C
CP 4FH FE 4F
Compare Register A (the RST 28H code the dispatcher passed) against 4FH, function 2: RENUM.
4D0E
If the Z FLAG is set (Register A is 4FH), JUMP to 50FEH to read RENUM's parameters.
4D11
LD A,E 7B
Load Register A with Register E, the BASIC error code the ROM's error routine passed (an even number).
4D12
PUSH AF F5
Save Register Pair AF (Register A = the error code) on the stack.
4D13
SUB 9CH D6 9C
Subtract 9CH from Register A, the error code.
4D15
CP 06H FE 06
Compare Register A (the error code minus 9CH) against 06H: the CARRY FLAG is set for the codes 9CH-A1H (Igel Item Syntax Error, Bad/Illegal/Missing Igel Item Prefix and the unused A0H).
4D17
If the CARRY FLAG is set, GOSUB to BASIC 5D37H, which displays the item number in its operand 5D38H (stored by SYS10/SYS for each item of a GET or PUT list) and a space, before the message.
4D1A
POP AF F1
Restore Register Pair AF from the stack: Register A = the error code.
4D1B
CP 63H FE 63
Compare Register A (the error code) against 63H: the NO CARRY FLAG is set for a Disk BASIC code (64H and above).
4D1D
If the NO CARRY FLAG is set (a Disk BASIC code), JUMP to 4D25H to subtract 34H.
4D1F
CP 2FH FE 2F
Compare Register A (the error code) against 2FH: the CARRY FLAG is set for a ROM code (00H-2EH).
4D21
If the CARRY FLAG is set (a ROM code), JUMP to 4D27H: the message number is the code halved.
4D23
LD A,5AH 3E 5A
A code from 2FH to 63H, or one past the table (4D39H): load Register A with 5AH, which gives message 19, Unprintable Error.
4D25
SUB 34H D6 34
Subtract 34H from Register A: the Disk BASIC codes follow on from the ROM's (64H becomes 30H, after 2EH).
4D27
RRCA 0F
Rotate Register A right: the code halved, the message number (bit 0 of every code is 0).
4D28
LD B,A 47
Load Register B with Register A, the message number.
4D29
LD HL,4D46H 21 46 4D
Load Register Pair HL with 4D46H, the 00H before message 0.
4D2C
INC B 04
Increment Register B: the number of 00H ends to pass to reach the message (one more than its number).
4D2D
DEC A 3D
Decrement Register A, the message number: the Z FLAG is set for message 1, Syntax Error (code 02H).
4D2E
If the NZ FLAG is set (another message), JUMP to 4D33H.
4D30
LD (409AH),A 32 9A 40
Store Register A (00H) at 409AH, the ROM's last error code (stored at 19B7H): the READY code at 1A2BH-1A30H then does not go into EDIT on the line, which it does when 409AH holds 02H (a syntax error).

MESSAGE SEARCH LOOP
Register Pair HL walks through the texts; Register B counts the 00H ends still to pass.

4D33
LD A,(HL) 7E
Load Register A with the byte at Register Pair HL, a character of the message table.
4D34
OR A B7
OR Register A (the character) with itself to set the flags: the Z FLAG is set at a message's 00H end.
4D35
INC HL 23
Increment Register Pair HL to the next byte of the table (INC HL does not change the flags).
4D36
If the NZ FLAG is set (inside a message), LOOP back to 4D33H.
4D38
OR (HL) B6
OR Register A (00H) with the byte at Register Pair HL, the next message's first character: the Z FLAG is set if it is 00H, the end of the table (50FDH).
4D39
If the Z FLAG is set (the message number is past the table), JUMP to 4D23H for Unprintable Error.
4D3B
Decrement Register B, the 00H ends still to pass, and LOOP back to 4D33H until Register Pair HL is at the wanted message.
4D3D
EX DE,HL EB
Exchange Register Pairs DE and HL: Register Pair DE = the address of the message's text.
4D3E
POP AF F1
Restore Register Pair AF from the stack: it takes the dispatcher's return address 4BC5H.
4D3F
LD HL,1A01H 21 01 1A
Load Register Pair HL with 1A01H, the point in the ROM's error routine after it displays its own question mark, two-letter code and ERROR.
4D42
EX (SP),HL E3
Exchange Register Pair HL with the word at the top of the stack (at the Stack Pointer SP): 1A01H replaces the ROM's return address 19EFH (after its CALL 41A6H at 19ECH), and Register Pair HL = 19EFH.
4D43
EX DE,HL EB
Exchange Register Pairs DE and HL: Register Pair HL = the message's text, Register Pair DE = 19EFH (not used).
4D44
PUSH AF F5
Push Register Pair AF (4BC5H, the dispatcher's return address) back on the stack.
4D45
RET C9
RETURN to SYS0/SYS 4BC5H, which clears bit 6 of 4289H and returns to the ROM at 1A01H with Register Pair HL = the message: 1A01H-1A06H display it (ROM 28A7H) and go on with IN and the line number.

4D46H - Error Messages (Data)

Message n is the text after the n-th 00H from 4D46H; each ends with 00H, the table with a second 00H at 50FDH. ROM codes 00H-2EH give message code / 2, Disk BASIC codes 64H-A6H message (code - 34H) / 2. A ? marks a code that is not used.

4D46
DEFB 00H 00
The 00H before message 0, where the search at 4D29H starts.
4D47-4D57
DEFM "Next Without For" / DEFB 00H 4E 65 78 74 20 57 69 74 68 6F 75 74 20 46 6F 72 00
Message 0, shown for the ROM's error code 00H (the ROM's own short code NF): Next Without For.
4D58-4D64
DEFM "Syntax Error" / DEFB 00H 53 79 6E 74 61 78 20 45 72 72 6F 72 00
Message 1, shown for the ROM's error code 02H (the ROM's own short code SN): Syntax Error. 4D30H also clears 409AH for it.
4D65-4D79
DEFM "Return Without Gosub" / DEFB 00H 52 65 74 75 72 6E 20 57 69 74 68 6F 75 74 20 47 6F 73 75 62 00
Message 2, shown for the ROM's error code 04H (the ROM's own short code RG): Return Without Gosub.
4D7A-4D85
DEFM "Out Of Data" / DEFB 00H 4F 75 74 20 4F 66 20 44 61 74 61 00
Message 3, shown for the ROM's error code 06H (the ROM's own short code OD): Out Of Data.
4D86-4D9B
DEFM "Illegal Function Call" / DEFB 00H 49 6C 6C 65 67 61 6C 20 46 75 6E 63 74 69 6F 6E 20 43 61 6C 6C 00
Message 4, shown for the ROM's error code 08H (the ROM's own short code FC): Illegal Function Call.
4D9C-4DA4
DEFM "Overflow" / DEFB 00H 4F 76 65 72 66 6C 6F 77 00
Message 5, shown for the ROM's error code 0AH (the ROM's own short code OV): Overflow.
4DA5-4DB2
DEFM "Out Of Memory" / DEFB 00H 4F 75 74 20 4F 66 20 4D 65 6D 6F 72 79 00
Message 6, shown for the ROM's error code 0CH (the ROM's own short code OM): Out Of Memory.
4DB3-4DC3
DEFM "Undefined Line #" / DEFB 00H 55 6E 64 65 66 69 6E 65 64 20 4C 69 6E 65 20 23 00
Message 7, shown for the ROM's error code 0EH (the ROM's own short code UL): Undefined Line #.
4DC4-4DDA
DEFM "Subscript Out Of Range" / DEFB 00H 53 75 62 73 63 72 69 70 74 20 4F 75 74 20 4F 66 20 52 61 6E 67 65 00
Message 8, shown for the ROM's error code 10H (the ROM's own short code BS): Subscript Out Of Range.
4DDB-4DEE
DEFM "Redimensioned Array" / DEFB 00H 52 65 64 69 6D 65 6E 73 69 6F 6E 65 64 20 41 72 72 61 79 00
Message 9, shown for the ROM's error code 12H (the ROM's own short code DD): Redimensioned Array.
4DEF-4DFF
DEFM "Division By Zero" / DEFB 00H 44 69 76 69 73 69 6F 6E 20 42 79 20 5A 65 72 6F 00
Message 10, shown for the ROM's error code 14H (the ROM's own short code /0): Division By Zero.
4E00-4E0E
DEFM "Illegal Direct" / DEFB 00H 49 6C 6C 65 67 61 6C 20 44 69 72 65 63 74 00
Message 11, shown for the ROM's error code 16H (the ROM's own short code ID): Illegal Direct.
4E0F-4E1C
DEFM "Type Mismatch" / DEFB 00H 54 79 70 65 20 4D 69 73 6D 61 74 63 68 00
Message 12, shown for the ROM's error code 18H (the ROM's own short code TM): Type Mismatch.
4E1D-4E30
DEFM "Out Of String Space" / DEFB 00H 4F 75 74 20 4F 66 20 53 74 72 69 6E 67 20 53 70 61 63 65 00
Message 13, shown for the ROM's error code 1AH (the ROM's own short code OS): Out Of String Space.
4E31-4E40
DEFM "String Too Long" / DEFB 00H 53 74 72 69 6E 67 20 54 6F 6F 20 4C 6F 6E 67 00
Message 14, shown for the ROM's error code 1CH (the ROM's own short code LS): String Too Long.
4E41-4E5B
DEFM "String Formula Too Complex" / DEFB 00H 53 74 72 69 6E 67 20 46 6F 72 6D 75 6C 61 20 54 6F 6F 20 43 6F 6D 70 6C 65 78 00
Message 15, shown for the ROM's error code 1EH (the ROM's own short code ST): String Formula Too Complex.
4E5C-4E6A
DEFM "Can't Continue" / DEFB 00H 43 61 6E 27 74 20 43 6F 6E 74 69 6E 75 65 00
Message 16, shown for the ROM's error code 20H (the ROM's own short code CN): Can't Continue.
4E6B-4E74
DEFM "No Resume" / DEFB 00H 4E 6F 20 52 65 73 75 6D 65 00
Message 17, shown for the ROM's error code 22H (the ROM's own short code NR): No Resume.
4E75-4E89
DEFM "Resume Without Error" / DEFB 00H 52 65 73 75 6D 65 20 57 69 74 68 6F 75 74 20 45 72 72 6F 72 00
Message 18, shown for the ROM's error code 24H (the ROM's own short code RW): Resume Without Error.
4E8A-4E9B
DEFM "Unprintable Error" / DEFB 00H 55 6E 70 72 69 6E 74 61 62 6C 65 20 45 72 72 6F 72 00
Message 19, shown for the ROM's error code 26H (the ROM's own short code UE): Unprintable Error. Also shown for the codes 2FH-63H and for a code past the table (4D23H).
4E9C-4EAB
DEFM "Missing Operand" / DEFB 00H 4D 69 73 73 69 6E 67 20 4F 70 65 72 61 6E 64 00
Message 20, shown for the ROM's error code 28H (the ROM's own short code MO): Missing Operand.
4EAC-4EB9
DEFM "Bad File Data" / DEFB 00H 42 61 64 20 46 69 6C 65 20 44 61 74 61 00
Message 21, shown for the ROM's error code 2AH (the ROM's own short code FD): Bad File Data.
4EBA-4ECC
DEFM "Disk Basic Feature" / DEFB 00H 44 69 73 6B 20 42 61 73 69 63 20 46 65 61 74 75 72 65 00
Message 22, shown for the ROM's error code 2CH (the ROM's own short code L3): Disk Basic Feature.
4ECD-4EE4
DEFM "Undefined User Function" / DEFB 00H 55 6E 64 65 66 69 6E 65 64 20 55 73 65 72 20 46 75 6E 63 74 69 6F 6E 00
Message 23, shown for the error code 2EH, which has no short code in the ROM's table at 18C9H: Undefined User Function.
4EE5-4EF3
DEFM "Field Overflow" / DEFB 00H 46 69 65 6C 64 20 4F 76 65 72 66 6C 6F 77 00
Message 24, shown for the Disk BASIC error code 64H: Field Overflow.
4EF4-4F02
DEFM "Internal Error" / DEFB 00H 49 6E 74 65 72 6E 61 6C 20 45 72 72 6F 72 00
Message 25, shown for the Disk BASIC error code 66H: Internal Error.
4F03-4F0D
DEFM "Bad File #" / DEFB 00H 42 61 64 20 46 69 6C 65 20 23 00
Message 26, shown for the Disk BASIC error code 68H: Bad File #.
4F0E-4F1C
DEFM "File Not Found" / DEFB 00H 46 69 6C 65 20 4E 6F 74 20 46 6F 75 6E 64 00
Message 27, shown for the Disk BASIC error code 6AH: File Not Found.
4F1D-4F2A
DEFM "Bad File Mode" / DEFB 00H 42 61 64 20 46 69 6C 65 20 4D 6F 64 65 00
Message 28, shown for the Disk BASIC error code 6CH: Bad File Mode.
4F2B-4F3C
DEFM "File Already Open" / DEFB 00H 46 69 6C 65 20 41 6C 72 65 61 64 79 20 4F 70 65 6E 00
Message 29, shown for the Disk BASIC error code 6EH: File Already Open.
4F3D-4F3E
DEFM "?" / DEFB 00H 3F 00
Message 30, for the error code 70H, which is not used: a question mark.
4F3F-4F48
DEFM "Dos Error" / DEFB 00H 44 6F 73 20 45 72 72 6F 72 00
Message 31, shown for the Disk BASIC error code 72H: Dos Error.
4F49-4F5C
DEFM "File Already Exists" / DEFB 00H 46 69 6C 65 20 41 6C 72 65 61 64 79 20 45 78 69 73 74 73 00
Message 32, shown for the Disk BASIC error code 74H: File Already Exists.
4F5D-4F5E
DEFM "?" / DEFB 00H 3F 00
Message 33, for the error code 76H, which is not used: a question mark.
4F5F-4F60
DEFM "?" / DEFB 00H 3F 00
Message 34, for the error code 78H, which is not used: a question mark.
4F61-4F6A
DEFM "Disk Full" / DEFB 00H 44 69 73 6B 20 46 75 6C 6C 00
Message 35, shown for the Disk BASIC error code 7AH: Disk Full.
4F6B-4F79
DEFM "Input Past End" / DEFB 00H 49 6E 70 75 74 20 50 61 73 74 20 45 6E 64 00
Message 36, shown for the Disk BASIC error code 7CH: Input Past End.
4F7A-4F86
DEFM "Bad Record #" / DEFB 00H 42 61 64 20 52 65 63 6F 72 64 20 23 00
Message 37, shown for the Disk BASIC error code 7EH: Bad Record #.
4F87-4F94
DEFM "Bad File Name" / DEFB 00H 42 61 64 20 46 69 6C 65 20 4E 61 6D 65 00
Message 38, shown for the Disk BASIC error code 80H: Bad File Name.
4F95-4FA2
DEFM "Mode Mismatch" / DEFB 00H 4D 6F 64 65 20 4D 69 73 6D 61 74 63 68 00
Message 39, shown for the Disk BASIC error code 82H: Mode Mismatch.
4FA3-4FBB
DEFM "Direct Statement In File" / DEFB 00H 44 69 72 65 63 74 20 53 74 61 74 65 6D 65 6E 74 20 49 6E 20 46 69 6C 65 00
Message 40, shown for the Disk BASIC error code 84H: Direct Statement In File.
4FBC-4FCA
DEFM "Too Many Files" / DEFB 00H 54 6F 6F 20 4D 61 6E 79 20 46 69 6C 65 73 00
Message 41, shown for the Disk BASIC error code 86H: Too Many Files.
4FCB-4FDF
DEFM "Disk Write Protected" / DEFB 00H 44 69 73 6B 20 57 72 69 74 65 20 50 72 6F 74 65 63 74 65 64 00
Message 42, shown for the Disk BASIC error code 88H: Disk Write Protected.
4FE0-4FF2
DEFM "File Access Denied" / DEFB 00H 46 69 6C 65 20 41 63 63 65 73 73 20 44 65 6E 69 65 64 00
Message 43, shown for the Disk BASIC error code 8AH: File Access Denied.
4FF3-5001
DEFM "Seq # Overflow" / DEFB 00H 53 65 71 20 23 20 4F 76 65 72 66 6C 6F 77 00
Message 44, shown for the Disk BASIC error code 8CH: Seq # Overflow.
5002-5011
DEFM "Record Overflow" / DEFB 00H 52 65 63 6F 72 64 20 4F 76 65 72 66 6C 6F 77 00
Message 45, shown for the Disk BASIC error code 8EH: Record Overflow.
5012-5028
DEFM "Illegal To Extend File" / DEFB 00H 49 6C 6C 65 67 61 6C 20 54 6F 20 45 78 74 65 6E 64 20 46 69 6C 65 00
Message 46, shown for the Disk BASIC error code 90H: Illegal To Extend File.
5029-502A
DEFM "?" / DEFB 00H 3F 00
Message 47, for the error code 92H, which is not used: a question mark.
502B-5045
DEFM "Previously Displayed Error" / DEFB 00H 50 72 65 76 69 6F 75 73 6C 79 20 44 69 73 70 6C 61 79 65 64 20 45 72 72 6F 72 00
Message 48, shown for the Disk BASIC error code 94H: Previously Displayed Error.
5046-505A
DEFM "Can't Process Line 0" / DEFB 00H 43 61 6E 27 74 20 50 72 6F 63 65 73 73 20 4C 69 6E 65 20 30 00
Message 49, shown for the Disk BASIC error code 96H: Can't Process Line 0.
505B-5068
DEFM "Bad File Type" / DEFB 00H 42 61 64 20 46 69 6C 65 20 54 79 70 65 00
Message 50, shown for the Disk BASIC error code 98H: Bad File Type.
5069-507A
DEFM "Igel Syntax Error" / DEFB 00H 49 67 65 6C 20 53 79 6E 74 61 78 20 45 72 72 6F 72 00
Message 51, shown for the Disk BASIC error code 9AH: Igel Syntax Error.
507B-5091
DEFM "Igel Item Syntax Error" / DEFB 00H 49 67 65 6C 20 49 74 65 6D 20 53 79 6E 74 61 78 20 45 72 72 6F 72 00
Message 52, shown for the Disk BASIC error code 9CH: Igel Item Syntax Error. The item number is shown before it (4D17H).
5092-50B6
DEFM "Bad/Illegal/Missing Igel Item Prefix" / DEFB 00H 42 61 64 2F 49 6C 6C 65 67 61 6C 2F 4D 69 73 73 69 6E 67 20 49 67 65 6C 20 49 74 65 6D 20 50 72 65 66 69 78 00
Message 53, shown for the Disk BASIC error code 9EH: Bad/Illegal/Missing Igel Item Prefix. The item number is shown before it (4D17H).
50B7-50B8
DEFM "?" / DEFB 00H 3F 00
Message 54, for the error code A0H, which is not used: a question mark. The item number is shown before it (4D17H).
50B9-50CA
DEFM "Bad Record Length" / DEFB 00H 42 61 64 20 52 65 63 6F 72 64 20 4C 65 6E 67 74 68 00
Message 55, shown for the Disk BASIC error code A2H: Bad Record Length.
50CB-50E1
DEFM "Stmt Uses 2 File Areas" / DEFB 00H 53 74 6D 74 20 55 73 65 73 20 32 20 46 69 6C 65 20 41 72 65 61 73 00
Message 56, shown for the Disk BASIC error code A4H: Stmt Uses 2 File Areas.
50E2-50FC
DEFM "Bad File Positioning Param" / DEFB 00H 42 61 64 20 46 69 6C 65 20 50 6F 73 69 74 69 6F 6E 69 6E 67 20 50 61 72 61 6D 00
Message 57, shown for the Disk BASIC error code A6H: Bad File Positioning Param.
50FD
DEFB 00H 00
The second 00H that ends the table: 4D38H-4D39H stop at it when the message number is past the last message (57).

50FEH - RENUM, First Part

Called through RST 28H with code 4FH by SYS18/SYS, with Register Pair HL at the first character after RENUM. Syntax, from the code: RENUM followed by up to four numbers separated by commas (the first new number, the increment, the first and the last old line of the range; a number may be left out, but not given as 0), then the options U and X separated by commas. RENUM with nothing after it is SYNTAX ERROR (RENUM followed by a comma takes every default). Every line's new number (its own number for a line outside the range) is written into the line's link field, the lines are counted, and SYS11/SYS is loaded to do the rest.

50FE
XOR A AF
Load Register A with 00H (XOR A with itself).
50FF
LD (4288H),A 32 88 42
Store Register A (00H) at 4288H, SYS0/SYS's slot of the overlay in 4D00H-51FFH: the next RST 28H for SYS13/SYS reads it from the diskette again, with the default parameters at 4D00H-4D0BH.
5102
LD BC,4D00H 01 00 4D
Load Register Pair BC with 4D00H, the address of the first parameter (the first new line number).
5105
LD A,(HL) 7E
Load Register A with the byte at Register Pair HL, the first character after RENUM.
5106
OR A B7
OR Register A (that character) with itself to set the flags: the Z FLAG is set for 00H, the end of the line.
5107
If the Z FLAG is set (RENUM with nothing after it), JUMP to 5130H for SYNTAX ERROR.
5109
LD A,04H 3E 04
Load Register A with 04H, the number of parameters that may be given.

PARAMETER LOOP
Register Pair BC = the parameter's address (4D00H, 4D02H, 4D04H, 4D06H), Register Pair HL = the text; the count is kept in the alternate Register A'.

510B
EX AF,AF' 08
Exchange Register Pair AF with the alternate AF': the count of parameters left goes to Register A'.
510C
DEC HL 2B
Decrement Register Pair HL, the text pointer, so that the RST 10H that follows reads the current character again.
510D
RST 10H D7
RST 10H: step Register Pair HL to the next character that is not a space and load it into Register A; the CARRY FLAG is set for a digit.
510E
If the CARRY FLAG is set (Register A is a digit: a number), JUMP to 5116H.
5110
CP 2CH FE 2C
Compare Register A (the character) against 2CH, a comma: this parameter is left out and keeps its default.
5112
If the Z FLAG is set (a comma), JUMP to 5126H to pass it and go on with the next parameter.
5114
Anything else: JUMP to 5139H to look for the options U and X.
5116
GOSUB to ROM 1E5AH (LINGET), which reads the decimal number at Register Pair HL into Register Pair DE and returns Register Pair HL after it.
5119
LD A,E 7B
Load Register A with Register E, the low byte of the number read.
511A
LD (BC),A 02
Store Register A (the number's low byte) at Register Pair BC, the parameter's low byte.
511B
INC BC 03
Increment Register Pair BC to the parameter's high byte.
511C
LD A,D 7A
Load Register A with Register D, the high byte of the number read.
511D
LD (BC),A 02
Store Register A (the number's high byte) at Register Pair BC, the parameter's high byte.
511E
DEC BC 0B
Decrement Register Pair BC back to the parameter's low byte.
511F
OR E B3
OR Register A (the number's high byte) with Register E (its low byte): the Z FLAG is set if the number is 0.
5120
If the Z FLAG is set (a 0 was given), JUMP to 5130H for SYNTAX ERROR.
5122
DEC HL 2B
Decrement Register Pair HL, the text pointer, so that the RST 10H that follows reads the character after the number again.
5123
RST 10H D7
RST 10H: step Register Pair HL to that character and load it into Register A; the Z FLAG is set at the end of the statement.
5124
If the Z FLAG is set (nothing follows the number), JUMP to 5148H to check the parameters.
5126
RST 08H => 2CH CF 2C
RST 08H with the byte 2CH: the character at Register Pair HL must be a comma, else the ROM gives SYNTAX ERROR; RST 08H then steps Register Pair HL to the next character, in Register A.
5128
INC BC 03
Increment Register Pair BC, 1 of 2, towards the next parameter.
5129
INC BC 03
Increment Register Pair BC, 2 of 2: Register Pair BC = the next parameter's address.
512A
EX AF,AF' 08
Exchange Register Pair AF with the alternate AF': Register A = the count of parameters left.
512B
DEC A 3D
Decrement Register A, the count of parameters that may still be given.
512C
If the NZ FLAG is set (Register A is not 0: another number may follow), LOOP back to 510BH.
512E
After four parameters: JUMP to 5139H to look for the options.
5130
JUMP to ROM 1997H (SNERR, error code 02H) for SYNTAX ERROR.
5133
LD (DE),A 12
Store Register A (the option letter, 55H U or 58H X) at Register Pair DE, 4D0AH or 4D0BH: the option is on.
5134
RST 10H D7
RST 10H: step Register Pair HL past the letter and load the next character into Register A; the Z FLAG is set at the end of the statement.
5135
If the Z FLAG is set (the end), JUMP to 5148H to check the parameters.
5137
RST 08H => 2CH CF 2C
RST 08H with the byte 2CH: a comma must follow the option, else SYNTAX ERROR; Register Pair HL is stepped to the next character.
5139
LD DE,4D0AH 11 0A 4D
Load Register Pair DE with 4D0AH, the byte of option U.
513C
LD A,(HL) 7E
Load Register A with the byte at Register Pair HL, the character at the text pointer.
513D
CP 55H FE 55
Compare Register A (the character) against 55H, the letter U.
513F
If the Z FLAG is set (U), JUMP to 5133H to store it at 4D0AH (Register Pair DE).
5141
LD DE,4D0BH 11 0B 4D
Load Register Pair DE with 4D0BH, the byte of option X.
5144
CP 58H FE 58
Compare Register A (the character) against 58H, the letter X.
5146
If the Z FLAG is set (X), JUMP to 5133H to store it at 4D0BH (Register Pair DE).
5148
OR A B7
OR Register A (the character at the text pointer) with itself to set the flags: the Z FLAG is set for 00H, the end of the line.
5149
If the NZ FLAG is set (something else follows), JUMP to 5130H for SYNTAX ERROR.
514B
LD DE,(4D04H) ED 5B 04 4D
Load Register Pair DE with the 16-bit value at 4D04H, the first old line number of the range.
514F
LD HL,(4D06H) 2A 06 4D
Load Register Pair HL with the 16-bit value at 4D06H, the last old line number of the range.
5152
RST 18H DF
RST 18H: compare Register Pair HL (the range's last line) with Register Pair DE (its first line). The CARRY FLAG is set if the last is below the first.
5153
If the CARRY FLAG is set (the range is upside down), JUMP to 5130H for SYNTAX ERROR.
5155
EX DE,HL EB
Exchange Register Pairs DE and HL: Register Pair DE = the range's last line.
5156
LD HL,FFF9H 21 F9 FF
Load Register Pair HL with FFF9H (65529), the highest line number allowed.
5159
RST 18H DF
RST 18H: compare Register Pair HL (65529) with Register Pair DE (the range's last line). The CARRY FLAG is set if the last line is above 65529.
515A
If the CARRY FLAG is set, JUMP to 5130H for SYNTAX ERROR.
515C
LD BC,0000H 01 00 00
Load Register Pair BC with 0000H, the count of program lines.
515F
LD HL,(40A4H) 2A A4 40
Load Register Pair HL with the 16-bit value at 40A4H, the ROM's pointer to the first program line.

LINE LOOP
Register Pair HL = the line, Register Pair BC = the lines counted; the new number goes into the line's link field.

5162
LD E,(HL) 5E
Load Register E with the byte at Register Pair HL, the low byte of the line's link field (the address of the next line).
5163
INC HL 23
Increment Register Pair HL to the high byte of the line's link field.
5164
LD D,(HL) 56
Load Register D with the byte at Register Pair HL. Register Pair DE = the next line's address.
5165
LD A,D 7A
Load Register A with Register D, the high byte of the link.
5166
OR E B3
OR Register A with Register E, the low byte: the Z FLAG is set for 0000H, the end marker.
5167
If the Z FLAG is set (every line is done), JUMP to 51B5H with Register A = 00H.
5169
PUSH DE D5
Save Register Pair DE (the next line's address from the link) on the stack.
516A
INC BC 03
Increment Register Pair BC, the count of program lines.
516B
LD A,(4D0AH) 3A 0A 4D
Load Register A with the byte at 4D0AH, option U.
516E
OR A B7
OR Register A (option U) with itself to set the flags: the NZ FLAG is set if U was given.
516F
If the NZ FLAG is set (U: the program is only checked, the links stay), JUMP to 51A9H.
5171
PUSH HL E5
Save Register Pair HL (the address of the link field's high byte) on the stack.
5172
INC HL 23
Increment Register Pair HL to the low byte of the line's number.
5173
LD E,(HL) 5E
Load Register E with the byte at Register Pair HL, the low byte of the line's number.
5174
INC HL 23
Increment Register Pair HL to the high byte of the line's number.
5175
LD D,(HL) 56
Load Register D with the byte at Register Pair HL. Register Pair DE = the line's old number.
5176
LD A,D 7A
Load Register A with Register D, the high byte of the old number.
5177
OR E B3
OR Register A with Register E, the low byte: the Z FLAG is set for line 0.
5178
LD A,96H 3E 96
Load Register A with 96H, BASIC's error code for Can't Process Line 0. LD does not change the flags.
517A
If the Z FLAG is set (a line 0), JUMP to BASIC 5DE2H, which rebuilds the links (ROM 1AF8H), clears the variables (ROM 1B59H) and gives the error in Register A.
517D
LD HL,(4D04H) 2A 04 4D
Load Register Pair HL with the 16-bit value at 4D04H, the first old line number of the range.
5180
EX DE,HL EB
Exchange Register Pairs DE and HL: Register Pair HL = the line's old number, Register Pair DE = the range's first line.
5181
RST 18H DF
RST 18H: compare Register Pair HL (the old number) with Register Pair DE (the range's first line). The CARRY FLAG is set if the line lies below the range.
5182
EX DE,HL EB
Exchange Register Pairs DE and HL back: Register Pair DE = the line's old number (EX does not change the flags).
5183
If the CARRY FLAG is set (below the range), JUMP to 51A4H: the line keeps its number, Register Pair DE.
5185
LD HL,(4D06H) 2A 06 4D
Load Register Pair HL with the 16-bit value at 4D06H, the last old line number of the range.
5188
RST 18H DF
RST 18H: compare Register Pair HL (the range's last line) with Register Pair DE (the old number). The CARRY FLAG is set if the line lies above the range.
5189
If the CARRY FLAG is set (above the range), JUMP to 51A4H: the line keeps its number.
518B
LD HL,(4D00H) 2A 00 4D
Load Register Pair HL with the 16-bit value at 4D00H, the next new line number.
518E
LD (4D08H),HL 22 08 4D
Store Register Pair HL (the new number) at 4D08H, the new number of the last line of the range so far, for SYS11/SYS.
5191
EX DE,HL EB
Exchange Register Pairs DE and HL: Register Pair DE = the line's new number.
5192
LD HL,FFF9H 21 F9 FF
Load Register Pair HL with FFF9H (65529), the highest line number allowed.
5195
RST 18H DF
RST 18H: compare Register Pair HL (65529) with Register Pair DE (the new number). The CARRY FLAG is set if the new number is above 65529.
5196
LD A,8CH 3E 8C
Load Register A with 8CH, BASIC's error code for Seq # Overflow (51A2H enters here). LD does not change the flags.
5198
If the CARRY FLAG is set (the new number is too high), JUMP to BASIC 5DE2H to rebuild the links and give the error in Register A.
519B
LD HL,(4D02H) 2A 02 4D
Load Register Pair HL with the 16-bit value at 4D02H, the increment.
519E
ADD HL,DE 19
Add Register Pair DE (the new number) to Register Pair HL (the increment): the number for the next line in the range.
519F
LD (4D00H),HL 22 00 4D
Store Register Pair HL at 4D00H, the next new line number.
51A2
If the CARRY FLAG is set (the addition passed 65535), JUMP to 5196H for Seq # Overflow.
51A4
POP HL E1
Restore Register Pair HL from the stack: the address of the link field's high byte, saved at 5171H.
51A5
LD (HL),D 72
Store Register D (the high byte of the line's new or kept number) at Register Pair HL, the link field's high byte.
51A6
DEC HL 2B
Decrement Register Pair HL to the link field's low byte.
51A7
LD (HL),E 73
Store Register E (the low byte of the number) at Register Pair HL: the link field now holds the line's number for SYS11/SYS.
51A8
INC HL 23
Increment Register Pair HL back to the link field's high byte.
51A9
GOSUB to BASIC 5CCCH with Register Pair HL at the link field's high byte: it steps past the line number and scans the text to the byte after its 00H end, returning Register Pair HL at the next line.
51AC
POP DE D1
Restore Register Pair DE from the stack: the next line's address from the old link, saved at 5169H.
51AD
RST 18H DF
RST 18H: compare Register Pair HL (where the line really ends) with Register Pair DE (where its link said). The Z FLAG is set if they agree.
51AE
If the Z FLAG is set, LOOP back to 5162H for the next line at Register Pair HL.
51B0
LD A,72H 3E 72
Load Register A with 72H, BASIC's error code for Dos Error: a link does not match its line.
51B2
JUMP to BASIC 5DE2H to rebuild the links and give the error in Register A.
51B5
LD H,B 60
Load Register H with Register B, the high byte of the count of program lines.
51B6
LD L,C 69
Load Register L with Register C, the low byte. Register Pair HL = the count of program lines.
51B7
LD C,A 4F
Load Register C with Register A (00H, from the OR at 5166H that found the end marker).
51B8
LD DE,0080H 11 80 00
Load Register Pair DE with 0080H (128), the number of entries in SYS11/SYS's line table.

LINES PER ENTRY
Register C counts how many times 128 goes into the number of lines, rounded up, at least 1.

51BB
INC C 0C
Increment Register C, one more line per table entry.
51BC
SBC HL,DE ED 52
Subtract Register Pair DE (128) and the CARRY FLAG (clear from the OR at 5166H, then from the previous subtraction) from Register Pair HL, the lines left.
51BE
If the Z FLAG is set (the lines are used up exactly), JUMP to 51C2H.
51C0
If the NO CARRY FLAG is set (lines are left), LOOP back to 51BBH. Register C = the lines per table entry.
51C2
LD DE,64A3H 11 A3 64
Load Register Pair DE with 64A3H, the address of SYS11/SYS's line table (BASIC/CMD's initialization code, used as the input buffer).
51C5
LD B,80H 06 80
Load Register B with 80H (128), the number of table entries.
51C7
LD HL,(40A4H) 2A A4 40
Load Register Pair HL with the 16-bit value at 40A4H, the ROM's pointer to the first program line.
51CA
LD A,2DH 3E 2D
Load Register A with 2DH, the RST 28H code of SYS11/SYS (slot 0DH), function 1.
51CC
RST 28H EF
RST 28H with Register A = 2DH: SYS11/SYS is loaded at 4D0CH-51F3H over this code and goes on with RENUM; it does not come back here.

51CDH - Unused Bytes

The rest of the file.

51CD-51E7
DEFB 00H x 27 00 x 27
27 bytes of 00H to the end of the file (51E7H). Nothing in SYS13/SYS reads or writes them.
51E8-51FF
DEFS 24
Not in the file: the rest of the overlay area. SYS13/SYS neither reads nor writes these bytes.