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

Page Customization

Introduction/Summary

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

SYS13/SYS holds the texts of all BASIC error messages and the first part of the RENUM command. It loads into the overlay area at 4D00H-51E7H (1,256 bytes in five load records); the transfer address is 4D0CH, as 4D00H-4D0BH are the RENUM parameters. 51CDH-51E7H are unused zero bytes.

BASIC/CMD copies its table of links to 4152H-41E4H; the entry that lands at 41A6H is LD A,2FH / RST 28H (BASIC 680FH). The ROM's error routine calls 41A6H before it prints an error (19ECH), so every BASIC error loads SYS13 and shows the full message text instead of the ROM's two-letter code. RENUM is RST 28H code 4FH from BASIC's direct statement code (SYS18); SYS13 then loads SYS11 for the second part.

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

Error Codes and Messages

Register E holds the ROM's error offset: codes 00H-2EH are the ROM's own (E/2 = the message number), 64H-A6H are Disk BASIC's ((E - 34H)/2). Anything from 2FH to 62H, and any code past the table, shows UNPRINTABLE ERROR. For 9CH-A1H the number of the item (from SYS10) is printed first. The table is on this page at 4D46H; Part 5 of the notes lists the Disk BASIC codes.

Variables

Locations inside SYS13 whose contents change while it runs:

Address RangePurpose
4D00H-4D01H
2 bytes
RENUM: the next new line number (000AH in the file; typed value stored at 511AH, counted up at 519FH).
4D02H-4D03H
2 bytes
RENUM: the increment (000AH in the file).
4D04H-4D07H
4 bytes
RENUM: the first and last old line of the range (0000H and FFF9H in the file).
4D08H-4D09H
2 bytes
RENUM: the last new number given (written at 518EH), read by SYS11.
4D0AH-4D0BH
2 bytes
RENUM options U and X (00H, or the letter; written at 5133H).

Locations outside SYS13 that it reads or writes:

Address RangePurpose
409AH
1 byte
The ROM's saved error code for RESUME, cleared for SYNTAX ERROR (4D30H).
40A4H-40A5H
2 bytes
The ROM's pointer to the first program line (515FH, 51C7H).
4317H
1 byte
SYS0's record of the overlay in 4D00H, cleared at 50FFH so SYS13 is reloaded with its default parameters.
Program lines
link fields
Each line's link field gets its new number (51A5H-51A7H); SYS11 rebuilds the links.
64CAH
SYS11's table
128 entries used by SYS11; its address is passed in Register Pair DE (51C2H).

RENUM

RENUM [new][,[inc][,[first][,[last]]]][,U][,X] as read by the code: new (default 10) is the first new number, inc (10) the increment, first (0) and last (65529) the range of old lines renumbered. A number typed as 0 is a SYNTAX ERROR, as is RENUM with nothing after it. U only lists the problems SYS11 finds; X reports missing target lines only when they lie inside the range. SYS13 stores each line's new number (or, outside the range, its old number) in the line's link field, checks that every link matches the line, counts the lines and loads SYS11 (SYS11/SYS) with RST 28H 2DH. It clears 4317H first, so a later call of SYS13 reloads it with the default parameters.

Errors: SYNTAX ERROR, 96H CAN'T PROCESS LINE 0 (a line numbered 0), 8CH SEQ # OVERFLOW (a new number above 65529), 72H DOS ERROR (a link that does not match the line). They go through BASIC 5E09H, which rebuilds the links first.

Disassembly

4D00H - RENUM Parameters

Data, not code: twelve bytes at the start of the file. SYS13's RENUM part (50FEH) stores the typed values over the defaults, and SYS11, which loads at 4D0CH over the rest of SYS13, reads them. The file's transfer address is 4D0CH.

4D00-4D01
DEFW 000AH 0A 00
DEFW 000AH: the first new line number (default 10); counted up by the increment at 519FH as lines are renumbered.
4D02-4D03
DEFW 000AH 0A 00
DEFW 000AH: the increment between new line numbers (default 10), read at 519BH.
4D04-4D05
DEFW 0000H 00 00
DEFW 0000H: the first old line of the range to renumber (default 0), read at 514BH and 517DH.
4D06-4D07
DEFW FFF9H F9 FF
DEFW FFF9H: the last old line of the range (default 65529), read at 514FH and 5185H.
4D08-4D09
DEFW 0000H 00 00
DEFW 0000H: the last new number given, stored at 518EH for SYS11.
4D0A
DEFB 00H 00
Option U: 00H, or the letter U when given (stored at 5133H): only list the errors, change nothing.
4D0B
DEFB 00H 00
Option X: 00H, or the letter X when given (stored at 5133H): report missing lines only inside the range.

4D0CH - Entry: Error Message or RENUM

The SYS0 dispatcher calls 4D0CH with Register A = the RST 28H code. Code 4FH (function 2) is RENUM. Code 2FH (function 1) comes from BASIC's link at 41A6H (BASIC 680FH copied there), which the ROM's error routine calls at 19ECH with Register E = the error code: SYS13 finds the message and makes the ROM carry on at 1A01H with Register Pair HL pointing at it, past the code that prints the ROM's own two-letter code.

4D0C
CP 4FH FE 4F
Compare Register A (the RST 28H code) against 4FH, function 2: RENUM.
4D0E
If the Z FLAG is set (RENUM), JUMP to 50FEH to read its parameters.
4D11
LD A,E 7B
Load Register A with Register E, the BASIC error code the ROM passed.
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 against 06H: the CARRY FLAG is set for codes 9CH-A1H (IGEL ITEM SYNTAX ERROR and BAD/ILLEGAL/MISSING IGEL ITEM PREFIX).
4D17
If the CARRY FLAG is set, GOSUB to BASIC 5D5EH, which prints the number of the item (BASIC 5D5FH, counted by SYS10) 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 against 63H: the NO CARRY FLAG is set for a Disk BASIC code (63H or above).
4D1D
If the NO CARRY FLAG is set, JUMP to 4D25H to subtract 34H.
4D1F
CP 2FH FE 2F
Compare Register A against 2FH: the CARRY FLAG is set for a ROM code (below 2FH).
4D21
If the CARRY FLAG is set, JUMP to 4D27H: the message number is the code halved.
4D23
LD A,5AH 3E 5A
A code from 2FH to 62H, or past the table: 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 empty entry before message 0.
4D2C
INC B 04
Increment Register B: the number of 00H ends to pass to reach the message.
4D2D
DEC A 3D
Decrement Register A: the Z FLAG is set for message 1, SYNTAX ERROR.
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 saved error code used by RESUME: a SYNTAX ERROR cannot be resumed.

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 table.
4D34
OR A B7
OR Register A 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 (the flags are not changed).
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 byte: the Z FLAG is set if it is 00H, the end of the table.
4D39
If the Z FLAG is set (the number is past the table), JUMP to 4D23H for UNPRINTABLE ERROR.
4D3B
Decrement Register B 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: DE = the message's text.
4D3E
POP AF F1
Restore Register Pair AF from the stack: it takes the dispatcher's return address (4C20H).
4D3F
LD HL,1A01H 21 01 1A
Load Register Pair HL with 1A01H, the point in the ROM's error routine after it prints its own two-letter code.
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), and HL = that old address.
4D43
EX DE,HL EB
Exchange Register Pairs DE and HL: HL = the message's text.
4D44
PUSH AF F5
Push Register Pair AF (the dispatcher's return address) back on the stack.
4D45
RET C9
RETURN through the dispatcher (4C20H clears bit 6 of 4369H), which returns to the ROM at 1A01H with Register Pair HL = the message.

4D46H - BASIC Error Messages

Data, not code: the texts for every BASIC error, each ended by 00H, in the order of the message numbers. Message n is E/2 for the ROM's codes (E below 2FH) and (E - 34H)/2 for Disk BASIC's (E = 64H up). A 00H byte in place of a message ends the table (50FDH).

4D46
DEFB 00H 00
An empty entry, a single 00H: the search at 4D33H starts here and passes this 00H before message 0.
4D47-4D57
DEFM "NEXT WITHOUT FOR", 00H 4E 45 58 54 20 57 49 54 48 4F 55 54 20 46 4F 52 00
Message 0, for error code E = 00H: NEXT WITHOUT FOR, ended by 00H.
4D58-4D64
DEFM "SYNTAX ERROR", 00H 53 59 4E 54 41 58 20 45 52 52 4F 52 00
Message 1, for error code E = 02H: SYNTAX ERROR, ended by 00H.
4D65-4D79
DEFM "RETURN WITHOUT GOSUB", 00H 52 45 54 55 52 4E 20 57 49 54 48 4F 55 54 20 47 4F 53 55 42 00
Message 2, for error code E = 04H: RETURN WITHOUT GOSUB, ended by 00H.
4D7A-4D85
DEFM "OUT OF DATA", 00H 4F 55 54 20 4F 46 20 44 41 54 41 00
Message 3, for error code E = 06H: OUT OF DATA, ended by 00H.
4D86-4D9B
DEFM "ILLEGAL FUNCTION CALL", 00H 49 4C 4C 45 47 41 4C 20 46 55 4E 43 54 49 4F 4E 20 43 41 4C 4C 00
Message 4, for error code E = 08H: ILLEGAL FUNCTION CALL, ended by 00H.
4D9C-4DA4
DEFM "OVERFLOW", 00H 4F 56 45 52 46 4C 4F 57 00
Message 5, for error code E = 0AH: OVERFLOW, ended by 00H.
4DA5-4DB2
DEFM "OUT OF MEMORY", 00H 4F 55 54 20 4F 46 20 4D 45 4D 4F 52 59 00
Message 6, for error code E = 0CH: OUT OF MEMORY, ended by 00H.
4DB3-4DC3
DEFM "UNDEFINED LINE #", 00H 55 4E 44 45 46 49 4E 45 44 20 4C 49 4E 45 20 23 00
Message 7, for error code E = 0EH: UNDEFINED LINE #, ended by 00H.
4DC4-4DDA
DEFM "SUBSCRIPT OUT OF RANGE", 00H 53 55 42 53 43 52 49 50 54 20 4F 55 54 20 4F 46 20 52 41 4E 47 45 00
Message 8, for error code E = 10H: SUBSCRIPT OUT OF RANGE, ended by 00H.
4DDB-4DEE
DEFM "REDIMENSIONED ARRAY", 00H 52 45 44 49 4D 45 4E 53 49 4F 4E 45 44 20 41 52 52 41 59 00
Message 9, for error code E = 12H: REDIMENSIONED ARRAY, ended by 00H.
4DEF-4DFF
DEFM "DIVISION BY ZERO", 00H 44 49 56 49 53 49 4F 4E 20 42 59 20 5A 45 52 4F 00
Message 10, for error code E = 14H: DIVISION BY ZERO, ended by 00H.
4E00-4E0E
DEFM "ILLEGAL DIRECT", 00H 49 4C 4C 45 47 41 4C 20 44 49 52 45 43 54 00
Message 11, for error code E = 16H: ILLEGAL DIRECT, ended by 00H.
4E0F-4E1C
DEFM "TYPE MISMATCH", 00H 54 59 50 45 20 4D 49 53 4D 41 54 43 48 00
Message 12, for error code E = 18H: TYPE MISMATCH, ended by 00H.
4E1D-4E30
DEFM "OUT OF STRING SPACE", 00H 4F 55 54 20 4F 46 20 53 54 52 49 4E 47 20 53 50 41 43 45 00
Message 13, for error code E = 1AH: OUT OF STRING SPACE, ended by 00H.
4E31-4E40
DEFM "STRING TOO LONG", 00H 53 54 52 49 4E 47 20 54 4F 4F 20 4C 4F 4E 47 00
Message 14, for error code E = 1CH: STRING TOO LONG, ended by 00H.
4E41-4E5B
DEFM "STRING FORMULA TOO COMPLEX", 00H 53 54 52 49 4E 47 20 46 4F 52 4D 55 4C 41 20 54 4F 4F 20 43 4F 4D 50 4C 45 58 00
Message 15, for error code E = 1EH: STRING FORMULA TOO COMPLEX, ended by 00H.
4E5C-4E6A
DEFM "CAN'T CONTINUE", 00H 43 41 4E 27 54 20 43 4F 4E 54 49 4E 55 45 00
Message 16, for error code E = 20H: CAN'T CONTINUE, ended by 00H.
4E6B-4E74
DEFM "NO RESUME", 00H 4E 4F 20 52 45 53 55 4D 45 00
Message 17, for error code E = 22H: NO RESUME, ended by 00H.
4E75-4E89
DEFM "RESUME WITHOUT ERROR", 00H 52 45 53 55 4D 45 20 57 49 54 48 4F 55 54 20 45 52 52 4F 52 00
Message 18, for error code E = 24H: RESUME WITHOUT ERROR, ended by 00H.
4E8A-4E9B
DEFM "UNPRINTABLE ERROR", 00H 55 4E 50 52 49 4E 54 41 42 4C 45 20 45 52 52 4F 52 00
Message 19, for error code E = 26H: UNPRINTABLE ERROR, ended by 00H; also used for every code from 2FH to 62H and for codes past the table.
4E9C-4EAB
DEFM "MISSING OPERAND", 00H 4D 49 53 53 49 4E 47 20 4F 50 45 52 41 4E 44 00
Message 20, for error code E = 28H: MISSING OPERAND, ended by 00H.
4EAC-4EB9
DEFM "BAD FILE DATA", 00H 42 41 44 20 46 49 4C 45 20 44 41 54 41 00
Message 21, for error code E = 2AH: BAD FILE DATA, ended by 00H.
4EBA-4ECC
DEFM "DISK BASIC FEATURE", 00H 44 49 53 4B 20 42 41 53 49 43 20 46 45 41 54 55 52 45 00
Message 22, for error code E = 2CH: DISK BASIC FEATURE, ended by 00H.
4ECD-4EE4
DEFM "UNDEFINED USER FUNCTION", 00H 55 4E 44 45 46 49 4E 45 44 20 55 53 45 52 20 46 55 4E 43 54 49 4F 4E 00
Message 23, for error code E = 2EH: UNDEFINED USER FUNCTION, ended by 00H.
4EE5-4EF3
DEFM "FIELD OVERFLOW", 00H 46 49 45 4C 44 20 4F 56 45 52 46 4C 4F 57 00
Message 24, for error code E = 64H: FIELD OVERFLOW, ended by 00H.
4EF4-4F02
DEFM "INTERNAL ERROR", 00H 49 4E 54 45 52 4E 41 4C 20 45 52 52 4F 52 00
Message 25, for error code E = 66H: INTERNAL ERROR, ended by 00H.
4F03-4F0D
DEFM "BAD FILE #", 00H 42 41 44 20 46 49 4C 45 20 23 00
Message 26, for error code E = 68H: BAD FILE #, ended by 00H.
4F0E-4F1C
DEFM "FILE NOT FOUND", 00H 46 49 4C 45 20 4E 4F 54 20 46 4F 55 4E 44 00
Message 27, for error code E = 6AH: FILE NOT FOUND, ended by 00H.
4F1D-4F2A
DEFM "BAD FILE MODE", 00H 42 41 44 20 46 49 4C 45 20 4D 4F 44 45 00
Message 28, for error code E = 6CH: BAD FILE MODE, ended by 00H.
4F2B-4F3C
DEFM "FILE ALREADY OPEN", 00H 46 49 4C 45 20 41 4C 52 45 41 44 59 20 4F 50 45 4E 00
Message 29, for error code E = 6EH: FILE ALREADY OPEN, ended by 00H.
4F3D-4F3E
DEFM "?", 00H 3F 00
Message 30, for error code E = 70H: the text ? and its 00H end; the code has no message of its own.
4F3F-4F48
DEFM "DOS ERROR", 00H 44 4F 53 20 45 52 52 4F 52 00
Message 31, for error code E = 72H: DOS ERROR, ended by 00H.
4F49-4F5C
DEFM "FILE ALREADY EXISTS", 00H 46 49 4C 45 20 41 4C 52 45 41 44 59 20 45 58 49 53 54 53 00
Message 32, for error code E = 74H: FILE ALREADY EXISTS, ended by 00H.
4F5D-4F5E
DEFM "?", 00H 3F 00
Message 33, for error code E = 76H: the text ? and its 00H end; the code has no message of its own.
4F5F-4F60
DEFM "?", 00H 3F 00
Message 34, for error code E = 78H: the text ? and its 00H end; the code has no message of its own.
4F61-4F6A
DEFM "DISK FULL", 00H 44 49 53 4B 20 46 55 4C 4C 00
Message 35, for error code E = 7AH: DISK FULL, ended by 00H.
4F6B-4F79
DEFM "INPUT PAST END", 00H 49 4E 50 55 54 20 50 41 53 54 20 45 4E 44 00
Message 36, for error code E = 7CH: INPUT PAST END, ended by 00H.
4F7A-4F86
DEFM "BAD RECORD #", 00H 42 41 44 20 52 45 43 4F 52 44 20 23 00
Message 37, for error code E = 7EH: BAD RECORD #, ended by 00H.
4F87-4F94
DEFM "BAD FILE NAME", 00H 42 41 44 20 46 49 4C 45 20 4E 41 4D 45 00
Message 38, for error code E = 80H: BAD FILE NAME, ended by 00H.
4F95-4FA2
DEFM "MODE MISMATCH", 00H 4D 4F 44 45 20 4D 49 53 4D 41 54 43 48 00
Message 39, for error code E = 82H: MODE MISMATCH, ended by 00H.
4FA3-4FBB
DEFM "DIRECT STATEMENT IN FILE", 00H 44 49 52 45 43 54 20 53 54 41 54 45 4D 45 4E 54 20 49 4E 20 46 49 4C 45 00
Message 40, for error code E = 84H: DIRECT STATEMENT IN FILE, ended by 00H.
4FBC-4FCA
DEFM "TOO MANY FILES", 00H 54 4F 4F 20 4D 41 4E 59 20 46 49 4C 45 53 00
Message 41, for error code E = 86H: TOO MANY FILES, ended by 00H.
4FCB-4FDF
DEFM "DISK WRITE PROTECTED", 00H 44 49 53 4B 20 57 52 49 54 45 20 50 52 4F 54 45 43 54 45 44 00
Message 42, for error code E = 88H: DISK WRITE PROTECTED, ended by 00H.
4FE0-4FF2
DEFM "FILE ACCESS DENIED", 00H 46 49 4C 45 20 41 43 43 45 53 53 20 44 45 4E 49 45 44 00
Message 43, for error code E = 8AH: FILE ACCESS DENIED, ended by 00H.
4FF3-5001
DEFM "SEQ # OVERFLOW", 00H 53 45 51 20 23 20 4F 56 45 52 46 4C 4F 57 00
Message 44, for error code E = 8CH: SEQ # OVERFLOW, ended by 00H.
5002-5011
DEFM "RECORD OVERFLOW", 00H 52 45 43 4F 52 44 20 4F 56 45 52 46 4C 4F 57 00
Message 45, for error code E = 8EH: RECORD OVERFLOW, ended by 00H.
5012-5028
DEFM "ILLEGAL TO EXTEND FILE", 00H 49 4C 4C 45 47 41 4C 20 54 4F 20 45 58 54 45 4E 44 20 46 49 4C 45 00
Message 46, for error code E = 90H: ILLEGAL TO EXTEND FILE, ended by 00H.
5029-502A
DEFM "?", 00H 3F 00
Message 47, for error code E = 92H: the text ? and its 00H end; the code has no message of its own.
502B-5045
DEFM "PREVIOUSLY DISPLAYED ERROR", 00H 50 52 45 56 49 4F 55 53 4C 59 20 44 49 53 50 4C 41 59 45 44 20 45 52 52 4F 52 00
Message 48, for error code E = 94H: PREVIOUSLY DISPLAYED ERROR, ended by 00H.
5046-505A
DEFM "CAN'T PROCESS LINE 0", 00H 43 41 4E 27 54 20 50 52 4F 43 45 53 53 20 4C 49 4E 45 20 30 00
Message 49, for error code E = 96H: CAN'T PROCESS LINE 0, ended by 00H.
505B-5068
DEFM "BAD FILE TYPE", 00H 42 41 44 20 46 49 4C 45 20 54 59 50 45 00
Message 50, for error code E = 98H: BAD FILE TYPE, ended by 00H.
5069-507A
DEFM "IGEL SYNTAX ERROR", 00H 49 47 45 4C 20 53 59 4E 54 41 58 20 45 52 52 4F 52 00
Message 51, for error code E = 9AH: IGEL SYNTAX ERROR, ended by 00H.
507B-5091
DEFM "IGEL ITEM SYNTAX ERROR", 00H 49 47 45 4C 20 49 54 45 4D 20 53 59 4E 54 41 58 20 45 52 52 4F 52 00
Message 52, for error code E = 9CH: IGEL ITEM SYNTAX ERROR, ended by 00H.
5092-50B6
DEFM "BAD/ILLEGAL/MISSING IGEL ITEM PREFIX", 00H 42 41 44 2F 49 4C 4C 45 47 41 4C 2F 4D 49 53 53 49 4E 47 20 49 47 45 4C 20 49 54 45 4D 20 50 52 45 46 49 58 00
Message 53, for error code E = 9EH: BAD/ILLEGAL/MISSING IGEL ITEM PREFIX, ended by 00H.
50B7-50B8
DEFM "?", 00H 3F 00
Message 54, for error code E = A0H: the text ? and its 00H end; the code has no message of its own.
50B9-50CA
DEFM "BAD RECORD LENGTH", 00H 42 41 44 20 52 45 43 4F 52 44 20 4C 45 4E 47 54 48 00
Message 55, for error code E = A2H: BAD RECORD LENGTH, ended by 00H.
50CB-50E1
DEFM "STMT USES 2 FILE AREAS", 00H 53 54 4D 54 20 55 53 45 53 20 32 20 46 49 4C 45 20 41 52 45 41 53 00
Message 56, for error code E = A4H: STMT USES 2 FILE AREAS, ended by 00H.
50E2-50FC
DEFM "BAD FILE POSITIONING PARAM", 00H 42 41 44 20 46 49 4C 45 20 50 4F 53 49 54 49 4F 4E 49 4E 47 20 50 41 52 41 4D 00
Message 57, for error code E = A6H: BAD FILE POSITIONING PARAM, ended by 00H.
50FD
DEFB 00H 00
The end of the table: a 00H where a message would start, tested at 4D38H.

50FEH - RENUM, First Part

Called through RST 28H with code 4FH by SYS18 after tokenizing, with Register Pair HL = the text after RENUM. Syntax, from the code: 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. It writes each line's new number into the line's link field (SYS11 4D0CH rebuilds the links later), counts the lines and loads SYS11.

50FE
XOR A AF
Load Register A with 00H (XOR A with itself).
50FF
LD (4317H),A 32 17 43
Store Register A (00H) at 4317H, SYS0's record of the overlay in 4D00H: the next RST 28H for SYS13 reloads it from the diskette, with the default parameters again.
5102
LD BC,4D00H 01 00 4D
Load Register Pair BC with 4D00H, 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 with itself to set the flags: the Z FLAG is set if the line ends there.
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 in the alternate Register A.

510B
EX AF,AF' 08
Exchange Register Pair AF with the alternate AF': the parameter count is kept in the alternate Register A.
510C
DEC HL 2B
Decrement Register Pair HL (the text pointer) so the RST 10H that follows fetches the current character again.
510D
RST 10H D7
RST 10H: move Register Pair HL on and load Register A with the character; the CARRY FLAG is set for a digit.
510E
If the CARRY FLAG is set (a number), JUMP to 5116H.
5110
CP 2CH FE 2C
Compare Register A against 2CH, a comma: this parameter is left out.
5112
If the Z FLAG is set (a comma), JUMP to 5126H to skip to the next parameter.
5114
Otherwise JUMP to 5139H for the options U and X.
5116
GOSUB to the ROM's LINGET at 1E5AH, which reads the number at Register Pair HL into Register Pair DE.
5119
LD A,E 7B
Load Register A with Register E, the number's low byte.
511A
LD (BC),A 02
Store Register A 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 number's high byte.
511D
LD (BC),A 02
Store Register A 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 high byte) with Register E (the 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 so the RST 10H that follows fetches the character after the number again.
5123
RST 10H D7
RST 10H: move Register Pair HL on and load Register A with the character; the Z FLAG is set at the end of the statement.
5124
If the Z FLAG is set (the statement ends), JUMP to 5148H.
5126
RST 08H CF
RST 08H: the character at Register Pair HL must be the byte that follows (a comma), else SYNTAX ERROR; then RST 10H moves HL on.
5127
DEFB 2CH 2C
Data byte 2CH (a comma), the character the RST 08H at 5126H requires between the parameters. RST 08H returns past this byte, to 5128H.
5128
INC BC 03
Increment Register Pair BC: 1 of 2 to the next parameter.
5129
INC BC 03
Increment Register Pair BC: BC = the next parameter's address.
512A
EX AF,AF' 08
Exchange Register Pair AF with the alternate AF': Register A = the parameters left.
512B
DEC A 3D
Decrement Register A, the parameters that may still be given.
512C
If the NZ FLAG is set (another may follow), LOOP back to 510BH.
512E
After four numbers: JUMP to 5139H for the options.
5130
JUMP to the ROM's SNERR at 1997H to report SYNTAX ERROR.
5133
LD (DE),A 12
Store Register A (the option letter, U or X) at Register Pair DE (4D0AH or 4D0BH).
5134
RST 10H D7
RST 10H: move Register Pair HL past the letter; Register A holds the next character, the Z FLAG set at the end.
5135
If the Z FLAG is set (the end), JUMP to 5148H.
5137
RST 08H CF
RST 08H: the character at Register Pair HL must be the byte that follows (a comma), else SYNTAX ERROR; then RST 10H moves HL on.
5138
DEFB 2CH 2C
Data byte 2CH (a comma), the character the RST 08H at 5137H requires between the options. RST 08H returns past this byte, to 5139H.
5139
LD DE,4D0AH 11 0A 4D
Load Register Pair DE with 4D0AH, the byte for option U.
513C
LD A,(HL) 7E
Load Register A with the byte at Register Pair HL, the next character.
513D
CP 55H FE 55
Compare Register A against 55H, the letter U.
513F
If the Z FLAG is set (U), JUMP to 5133H to store it at 4D0AH.
5141
LD DE,4D0BH 11 0B 4D
Load Register Pair DE with 4D0BH, the byte for option X.
5144
CP 58H FE 58
Compare Register A against 58H, the letter X.
5146
If the Z FLAG is set (X), JUMP to 5133H to store it at 4D0BH.
5148
OR A B7
OR Register A (the character) with itself to set the flags: the Z FLAG is set at the 00H 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 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 of the range.
5152
RST 18H DF
RST 18H: compare Register Pair HL (the last) with Register Pair DE (the first). The CARRY FLAG is set if the last is below the first.
5153
If the CARRY FLAG is set, JUMP to 5130H for SYNTAX ERROR.
5155
EX DE,HL EB
Exchange Register Pairs DE and HL: DE = the last old line, HL = the first.
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 last). The CARRY FLAG is set if the last 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.
5163
INC HL 23
Increment Register Pair HL to the link's high byte.
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 link's high byte.
5166
OR E B3
OR Register A with Register E: the Z FLAG is set for 0000H, the end of the program.
5167
If the Z FLAG is set (all lines done), JUMP to 51B5H.
5169
PUSH DE D5
Save Register Pair DE (the next line's address) on the stack.
516A
INC BC 03
Increment Register Pair BC, the lines counted.
516B
LD A,(4D0AH) 3A 0A 4D
Load Register A with the byte at 4D0AH, option U.
516E
OR A B7
OR Register A with itself to set the flags: the NZ FLAG is set if U was given.
516F
If the NZ FLAG is set (U: only check, change nothing), JUMP to 51A9H.
5171
PUSH HL E5
Save Register Pair HL (the address of the link's high byte) on the stack.
5172
INC HL 23
Increment Register Pair HL to the line number's low byte.
5173
LD E,(HL) 5E
Load Register E with the byte at Register Pair HL, the line number's low byte.
5174
INC HL 23
Increment Register Pair HL to the line number's high byte.
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 old number's high byte.
5177
OR E B3
OR Register A with Register E: the Z FLAG is set for line 0.
5178
LD A,96H 3E 96
Load Register A with 96H, the BASIC error code CAN'T PROCESS LINE 0. LD does not change the flags.
517A
JP Z,5E09H CA 09 5E
If the Z FLAG is set (a line 0), JUMP to BASIC 5E09H, which rebuilds the links (ROM 1AF8H), clears the variables (ROM 1B59H) and raises 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 of the range.
5180
EX DE,HL EB
Exchange Register Pairs DE and HL: HL = the old number, DE = the range's first line.
5181
RST 18H DF
RST 18H: compare Register Pair HL (the old number) with Register Pair DE. The CARRY FLAG is set if the line lies below the range.
5182
EX DE,HL EB
Exchange Register Pairs DE and HL back: DE = the 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 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 at 4D08H, the last new number given, for SYS11.
5191
EX DE,HL EB
Exchange Register Pairs DE and HL: DE = the 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, the BASIC error code SEQ # OVERFLOW. LD does not change the flags.
5198
JP C,5E09H DA 09 5E
If the CARRY FLAG is set (too high), JUMP to BASIC 5E09H to rebuild the links and raise the error.
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: HL = the number after it.
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's high byte.
51A5
LD (HL),D 72
Store Register D (the new number's high byte) at Register Pair HL, in the link field.
51A6
DEC HL 2B
Decrement Register Pair HL to the link's low byte.
51A7
LD (HL),E 73
Store Register E (the new number's low byte) at Register Pair HL: the link field now holds the line's new number.
51A8
INC HL 23
Increment Register Pair HL back to the link's high byte.
51A9
GOSUB to BASIC 5CF3H, which steps Register Pair HL past the line number to the text and through it to the byte after its 00H end: the next line.
51AC
POP DE D1
Restore Register Pair DE from the stack: the next line's address from the old link.
51AD
RST 18H DF
RST 18H: compare Register Pair HL (where the line really ends) with Register Pair DE (where the link says). The Z FLAG is set if they agree.
51AE
If the Z FLAG is set, LOOP back to 5162H for the next line.
51B0
LD A,72H 3E 72
Load Register A with 72H, the BASIC error code DOS ERROR.
51B2
JP 5E09H C3 09 5E
JUMP to BASIC 5E09H: the program's links do not match its lines; rebuild them and raise the error.
51B5
LD H,B 60
Load Register H with Register B, the high byte of the number of lines.
51B6
LD L,C 69
Load Register L with Register C. Register Pair HL = the number of lines.
51B7
LD C,A 4F
Load Register C with Register A (00H: Register A is 0 after the OR at 5166H found the end).
51B8
LD DE,0080H 11 80 00
Load Register Pair DE with 0080H (128), the number of entries in SYS11's 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 SYS11 table entry.
51BC
SBC HL,DE ED 52
Subtract Register Pair DE (128) from Register Pair HL (the lines left), with the CARRY FLAG (clear after the OR at 5166H).
51BE
If the Z FLAG is set (exactly used up), JUMP to 51C2H.
51C0
If the NO CARRY FLAG is set (lines left), LOOP back to 51BBH. Register C = the lines per table entry of SYS11.
51C2
LD DE,64CAH 11 CA 64
Load Register Pair DE with 64CAH, the address of SYS11's table (in BASIC/CMD's free area).
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 first program line.
51CA
LD A,2DH 3E 2D
Load Register A with 2DH, the RST 28H code for SYS11 (slot 0DH), function 1.
51CC
RST 28H EF
RST 28H with Register A = 2DH: SYS11 is loaded at 4D0CH-51F3H over this code and carries on with RENUM; it does not return here.

51CDH - Unused Bytes

51CDH-51E7H fill the last load record; nothing reads or executes them.

51CD-51E7
NOP x 27 00 x 27
27 zero bytes that fill the end of the file (up to 51E7H). No code jumps, calls or reads here.