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

Page Customization

Description:

SYS18/SYS is the BASIC Direct Statement Executor for NEWDOS/80 v2.0. This system file must be present on the system diskette whenever BASIC is active, as it handles the immediate execution of direct commands (commands entered at the BASIC prompt without a line number) and manages the sophisticated LIST command with its various display modes.

Core Functionality:

The module implements an advanced LIST command dispatcher that supports multiple input modes for flexible program viewing:

  • Colon (:) - Lists the entire program starting from line 0
  • Up-arrow ([) - Lists the previous line (relative to last listed line)
  • Down-arrow (LF) - Lists the next line (relative to last listed line)
  • Period (.) or Comma (,) - Continues listing from last position
  • At-sign (@) - Lists 13 lines of context around current position
  • AUTO modes (^Z, /) - Automatic line numbering for program entry

Screen Management:

The LIST implementation includes sophisticated screen handling that manages display bounds (15 lines maximum per screen), tracks cursor position across 64-column lines with automatic wrapping, and maintains a "last listed line" pointer at memory location 40ECH for seamless continuation commands. The system uses screen control codes (1CH = cursor right, 1FH = cursor home) to prepare the display area before listing program lines.

EDIT Command Support:

Beyond LIST functionality, SYS18 handles the EDIT command (triggered by semicolon or ESC key), which allows interactive line editing of existing BASIC program lines. The EDIT mode provides cursor positioning and character manipulation capabilities for modifying program statements in place.

Integration with BASIC/CMD:

The module works closely with the main BASIC/CMD interpreter, calling ROM routines for actual statement execution and screen output. It uses self-modifying code techniques (storing command characters at 5227H) to maintain state across complex control flow paths, and integrates with BASIC's work pointer (40A7H) and program text area (TXTTAB at 40A4H) to navigate the program structure.

Technical Implementation:

The code demonstrates advanced programming techniques including:

  • Linked-list traversal through BASIC program lines using 2-byte forward pointers
  • Bidirectional line offset calculations with underflow protection (clamping to line 0)
  • Line counting and skip-ahead algorithms for efficient positioning
  • Register-based state machines for multi-mode command processing
  • Stack manipulation for nested call structures and state preservation

The module occupies approximately 1256 bytes (5200H-56E7H) with substantial NOP padding in the upper range (5650H-56E7H) reserved for future expansion or system compatibility. This padding suggests the module was designed with room for additional features or to maintain specific memory boundaries within the NEWDOS/80 architecture.

Variables:

AddressBytesPurpose
5227H1Self-modifying code: Stored command character for later comparison. Modified by instruction at 522FH to preserve the user's input command (colon, arrows, at-sign, etc.) for subsequent conditional logic.
40A4H2TXTTAB - BASIC program text start pointer. Points to the first byte of the BASIC program in memory (standard BASIC system variable).
40A7H2BASIC work pointer. Used by ROM routines and BASIC/CMD for statement processing and expression evaluation.
40ECH2Last listed line number. Stores the line number of the most recently displayed program line, enabling continuation LIST commands (period, comma, arrows) to resume from the correct position.
4369H1System flag byte. Bit 5 indicates special system state; when set, triggers alternate processing path through ROM 05D9H with B=F0H.
5272HTemporary line number storage (to be copied to 40ECH).
5373HSaved line pointer (for EDIT or continuation).
6421H1Chaining flag. Non-zero value indicates program chaining is active; when set, control passes to ROM routine at 2831H for chain execution.

Note: SYS18 relies heavily on BASIC system variables and ROM entry points rather than maintaining extensive local storage. The module's design favors stateless operation with minimal memory footprint, using the stack and CPU registers for transient data during command processing.

Routine Overview:

Command Dispatcher (5200H-527AH):

AddressPurpose
5200HEntry point - CP A self-test, RET
5202HInitialize with 0EH output, call ROM 0033H
5207HCheck system flag at 4369H bit 5 for special state
520EHIf bit 5 set, push BC, load BASIC work pointer, call ROM 05D9H with B=F0H
521AHMain path - call ROM 0049H to get input character
521EHCheck chaining flag at 6421H, jump to ROM 2831H if set
5226HInitialize L=00H as flag register
5228HBacktick (60H) converted to at-sign (40H)
522FHSelf-modifying code stores command character at 5227H
5271HCommand character tests

Command character tests:

CharacterHexMeaningTargetList Offset
:3AHList entire program5271H → 5280HStart from line 0, list with -13 offset (show 13 lines context)
LF0AHList next line (down)527CH → 5280HCurrent line + 1
[5BHList previous line (up)527CH → 5280HCurrent line - 1
.2EHList continuation527CH → 5280HCurrent line (continuation from 40ECH)
,2CHList continuation527CH → 5280HCurrent line (continuation from 40ECH)
@40HList @ mode527CH → 5280HCurrent position, no offset
`60HConverted to @ (40H)522CH → 527CH
;3BHEDIT command524FH → 537AH
ESC1BHEDIT command524FH → 537AH
^Z1AHAUTO mode5257H → 5280H
/2FHAUTO mode5259H → 5280H
OTHERnnHPass to ROM BASIC executor5261H

Edit Command Path (524FH-526EH):

  • 524FH: EDIT entry point (for 3BH or 1BH)
  • Loads HL from 40A4H (TXTTAB), jumps to 537AH
  • Alternate path at 5261H for non-LIST commands
  • Pushes 53CBH as return address
  • Loads BASIC work pointer from 40A7H
  • Sets B=F0H, C=B, pushes HL
  • Jumps to ROM 05E3H to execute via standard BASIC

List Command Setup (5271H-527CH):

AddressPurpose
5271HColon LIST - sets DE=0000H (list from beginning)
5274HSelf-check using L register (initially 00H)
  • First pass: Z flag set, jump to 5280H
  • Second pass: Load stored command from L, check for 40H (@)
527CHLoad last listed line from 40ECH into DE

Line Number Scan Loop (5280H-52ACH):

AddressPurpose
5280HLoad TXTTAB (program start) into HL
5283HInitialize BC=0000H as line counter
5286H[LOOP START] Load link pointer (2 bytes at HL)
5288HOR test for 0000H (end of program)
528AHIf end found, jump to 537AH (exit)
528DHSkip to line number (HL+3 = high byte)
5290HCompare line number high byte (D)
5292HBack to low byte, compare if high matched
5297HCheck carry flag - if current < target, continue
5299HIf current >= target, jump to 52ADH (found range)
529BH[CONTINUE SCAN] Push HL, follow link pointer
529CH-529FHLoad next line address into HL
52A0HCheck if next line exists (link != 0000H)
52A3HIf end, jump to 52A9H
52A5HIncrement BC (line counter)
52A7HLoop back to 528EH
52A9H[END REACHED] Restore HL, pop AF, jump to 52BFH

Range Adjustment (52ADH-52CDH):

AddressPurpose
52ADHPop DE (restore command), check if exact match
52B1HDown-arrow (0AH): DE=0001H (+1 line)
52B8HUp-arrow (5BH): DE=FFFFH (-1 line)
52BFHDefault: DE=0000H (no offset)
52C6HColon: DE=FFF3H (-13 lines for @ mode)
52CEHAll paths converge

Offset Application (52CEH-52FFH):

AddressPurpose
52CEHSave AF, swap DE?HL
52D0HAdd BC to HL (apply offset)
52D2HCheck for underflow (high byte = FFH)
52D6HClamp to 0000H if underflow
52D9HCalculate remaining lines (original - skip)
52E1HReload TXTTAB, begin skip loop
52E4H[SKIP LOOP] Follow link pointers BC times
52ECHLoop back if more to skip
52EEHRestore remaining line count to BC
52F1HRestore command character to AF
52F4HStore command in B for later
52FCHFinal AF pop
52FDHLoad 1CH (cursor right) for screen clear
52FFHCall 5D66H (output character)
5302HContinue setup with 1FH

Screen Management Algorithm:

Row/Column Tracking:

  • Register D: Row counter (starts at 1 after line number display)
  • Register E: Column counter (0-63, wraps at 64 via BIT 6 test)
  • Maximum rows per screen: 15 (0FH)
  • Screen width: 64 columns (40H)

Column Wrap Detection:

The code uses a clever optimization at 5330H:

BIT 6,E ; Test bit 6 of column counter

When E reaches 40H (64 decimal), bit 6 becomes set:

  • E=3FH (63): bit 6 = 0 (within line)
  • E=40H (64): bit 6 = 1 (wrap needed)

This single instruction replaces: CP 40H; JR NC,wrap

Screen Full Algorithm:

  1. Display line, counting rows used (handle 64-column wrapping)/li>
  2. Add to accumulated row count (D register)/li>
  3. Compare to 15 (0FH)/li>
  4. If >= 15:
    • @ command: Exit to 5367H
    • Colon command: Reset counters, display next page from 5307H
  5. If < 15: Continue to next line at 530BH

Disassembly:

5200H - Entry Point and Command Type Dispatcher

SYS18 is the BASIC direct statement executor that processes immediate-mode commands entered at the BASIC prompt. When BASIC encounters a direct command (one without a line number), it loads and calls this module to parse and route the command to the appropriate handler. The entry point validates the environment, checks for system chaining mode, and dispatches to specialized handlers based on command type (LIST variants, EDIT, AUTO, etc.).

5200
CP A BF
Compare Register A to itself (always sets Z FLAG). This ensures a successful return status for the caller.
5201
RET C9
Return to caller with Z FLAG set (indicating success).

[MAIN ENTRY POINT] Entry at 5202H indicates this is the primary entry point for SYS18.

5202
LD A,0EH 3E 0E
Load Register A with 0EH (14 decimal), which is the SYS file number for SYS18 itself.
5204
Call ROM routine at 0033H to register this SYS file as active in memory. This allows BASIC to track which system files are currently loaded.

[SYSTEM CHAINING CHECK] Before processing the command, check if the system is in chaining mode (transferring control to another program).

5207
LD A,(4369H) 3A 69 43
Load Register A with the system flag byte at 4369H. This byte tracks various system states including output operations and chaining mode.
520A
BIT 5,A CB 6F
Test bit 5 of Register A. If this bit is set, it indicates a special system state that requires alternate handling. Sets the Z FLAG if bit 5 is clear (normal operation).
520C
JR Z,521AH 28 0C
If the Z FLAG is set (bit 5 was clear, normal operation), JUMP ahead to 521AH for standard command processing.

[SPECIAL STATE PATH] If bit 5 of 4369H was set, this indicates a special system state that requires custom handling through the ROM.

520E
PUSH BC C5
Preserve Register BC on the stack before calling the ROM routine.
520F
LD HL,(40A7H) 2A A7 40
Load Register HL with the BASIC work pointer at 40A7H. This points to the current position in the command being processed.
5212
LD B,F0H 06 F0
Load Register B with F0H (240 decimal), a parameter for the ROM routine that follows.
5214
Call ROM routine at 05D9H to handle the special state. This is likely a BASIC statement dispatcher that processes commands during special system states.
5217
JUMP to cleanup and exit routine at 53CBH after special state processing completes.

[STANDARD COMMAND PROCESSING] Normal entry path for direct commands entered at the BASIC prompt.

521A
Call ROM routine at 0049H to fetch the next character from the BASIC input buffer. Returns the character in Register A.
521D
PUSH AF F5
Preserve Register AF (containing the command character) on the stack for later use.

[CHAINING MODE CHECK] Check if the system is in program chaining mode (loading another program).

521E
LD A,(6421H) 3A 21 64
Load Register A with the system flag at 6421H. This is a self-modifying location that indicates whether program chaining is active.
5221
OR A B7
Test if Register A is zero. Sets the Z FLAG if no chaining is active, clears it if chaining mode is enabled.
5222
If the NZ FLAG is set (chaining is active), JUMP to ROM routine at 2831H to handle the chained program transfer instead of processing the direct command.

[COMMAND CHARACTER PROCESSING] Extract and normalize the command character for dispatcher routing.

5225
POP AF F1
Restore Register AF from the stack, recovering the command character in Register A.
5226
LD L,00H 2E 00
Initialize Register L to 00H. This will be used as a flag to track command type variations.
5228
CP 60H FE 60
Compare Register A to 60H (the ` backtick character). Sets the Z FLAG if the character matches.
522A
JR NZ,522EH 20 02
If the NZ FLAG is set (character is not backtick), JUMP ahead to 522EH to continue processing.

The backtick character (60H) is converted to @ sign (40H) for processing - they are treated as equivalent command prefixes.

522C
LD A,40H 3E 40
Load Register A with 40H (the @ at-sign character), replacing the backtick with its functional equivalent.

[SELF-MODIFICATION SETUP] Store the normalized command character for later comparison in a self-modifying instruction.

522E
PUSH AF F5
Preserve Register AF (with normalized command character) on the stack again.
522F
LD (5227H),A 32 27 52
Store the command character from Register A into self-modifying location 5227H. This is the immediate value in the "LD L,xxH" instruction at 5226H, effectively changing which character is compared later.

[COMMAND TYPE DISPATCHER] Route to appropriate handler based on command character.

5232
CP 3AH FE 3A
Compare Register A to 3AH (the : colon character, used for LIST :). Sets the Z FLAG if this is a colon command.
5234
JR Z,5271H 28 3B
If the Z FLAG is set (colon command), JUMP to 5271H to handle LIST with no line number range.
5236
CP 0AH FE 0A
Compare Register A to 0AH (line feed character, used for LIST with down-arrow). Sets the Z FLAG if this is a down-arrow LIST command.
5238
JR Z,527CH 28 42
If the Z FLAG is set (down-arrow), JUMP to 527CH to handle sequential listing downward.
523A
CP 5BH FE 5B
Compare Register A to 5BH (left bracket [, used for LIST [ up-arrow). Sets the Z FLAG if this is an up-arrow LIST command.
523C
JR Z,527CH 28 3E
If the Z FLAG is set (up-arrow), JUMP to 527CH to handle sequential listing upward.
523E
CP 2EH FE 2E
Compare Register A to 2EH (period ., used for LIST .). Sets the Z FLAG if this is a current-line LIST command.
5240
JR Z,527CH 28 3A
If the Z FLAG is set (period command), JUMP to 527CH to list the current line.
5242
CP 2CH FE 2C
Compare Register A to 2CH (comma ,, used for LIST ,end). Sets the Z FLAG if this is a list-to-end command.
5244
JR Z,527CH 28 36
If the Z FLAG is set (comma command), JUMP to 527CH to list from beginning to specified line.

[PROGRAM BOUNDARY SETUP] Load the start of the BASIC program for LIST and EDIT commands.

5246
LD HL,(40A4H) 2A A4 40
Load Register HL with TXTTAB at 40A4H, which points to the start of the BASIC program in memory. This is used as the starting point for list operations.
5249
CP 3BH FE 3B
Compare Register A to 3BH (semicolon ;, used for EDIT). Sets the Z FLAG if this is an EDIT command.
524B
JR Z,524FH 28 02
If the Z FLAG is set (semicolon), skip ahead to 524FH to continue EDIT processing.
524D
CP 1BH FE 1B
Compare Register A to 1BH (ESCAPE character, also used for EDIT). Sets the Z FLAG if this is an alternate EDIT command prefix.
524F
If the Z FLAG is set (EDIT command detected), JUMP to 537AH to handle the EDIT function.

[AUTO COMMAND DISPATCHER] Process AUTO command with optional line number and increment parameters.

5252
LD DE,FFFFH 11 FF FF
Load Register DE with FFFFH (-1 in two's complement). This will be used as a default increment value for AUTO commands.
5255
CP 1AH FE 1A
Compare Register A to 1AH (SUB character, used for AUTO decrement). Sets the Z FLAG if this is AUTO with down-arrow.
5257
JR Z,5280H 28 27
If the Z FLAG is set (AUTO down), JUMP to 5280H to process AUTO with negative increment.
5259
CP 2FH FE 2F
Compare Register A to 2FH (slash /, alternate for AUTO). Sets the Z FLAG if this is a slash AUTO command.
525B
JR Z,5280H 28 23
If the Z FLAG is set (slash AUTO), JUMP to 5280H to process AUTO command.
525D
CP 40H FE 40
Compare Register A to 40H (at-sign @, used for LIST @). Sets the Z FLAG if this is an at-sign LIST command.
525F
JR Z,527CH 28 1B
If the Z FLAG is set (at-sign), JUMP to 527CH to handle LIST from current position.

[UNKNOWN COMMAND HANDLER] If none of the direct command characters matched, pass the command to the ROM's statement executor.

5261
POP AF F1
Restore Register AF from the stack, recovering the original command character.
5262
PUSH BC C5
Preserve Register BC on the stack before calling the ROM routine.
5263
LD HL,53CBH 21 CB 53
Load Register HL with 53CBH, the address of the cleanup/exit routine. This will be the return address after the ROM processes the statement.
5266
PUSH HL E5
Push the cleanup address onto the stack, so when the ROM routine returns, it will continue at 53CBH.
5267
LD HL,(40A7H) 2A A7 40
Load Register HL with the BASIC work pointer at 40A7H, which points to the current position in the command input buffer.
526A
LD B,F0H 06 F0
Load Register B with F0H (240 decimal), a parameter code for the ROM statement executor.
526C
LD C,B 48
Copy Register B to Register C, setting C to F0H as well.
526D
PUSH HL E5
Push the BASIC work pointer onto the stack for the ROM routine to use.
526E
JUMP to ROM routine at 05E3H to handle the statement using BASIC's standard executor. The ROM will process the command and return to 53CBH.

[LIST WITH NO RANGE] Handle LIST : (colon) command which lists the entire program.

5271
LD DE,0000H 11 00 00
Load Register DE with 0000H, indicating no line number range specified. This will cause the LIST to start from the beginning.
5274
CP L BD
Compare Register A to Register L. Since L was set to 00H at 5226H (or modified by self-modifying code at 522FH), this checks if we've processed this path before. Sets Z FLAG if A equals L.
5275
JR Z,5280H 28 09
If the Z FLAG is set (first time through), JUMP to 5280H to begin LIST processing.
5277
LD A,L 7D
Load Register A with the value from Register L (the stored command character from earlier).
5278
CP 40H FE 40
Compare Register A to 40H (at-sign). This checks if this is a LIST @ command variant. Sets Z FLAG if matches.
527A
JR Z,5280H 28 04
If the Z FLAG is set (at-sign LIST), JUMP to 5280H to process.

At this point we've fallen through from the @ comparison check. The code continues to check if we need to use the last listed line number stored at 40ECH for continuation listing.

527C
LD DE,(40ECH) ED 5B EC 40
Load Register pair DE with the 2-byte value from memory location 40ECH. This is the last listed line number, used for continuation when using up/down arrows, comma, or period commands. This provides the starting point for incremental LIST operations.

[LIST INITIALIZATION] We now have the starting line number in DE (either 0000H for colon/first-time, FFFFH for AUTO mode, or the last listed line from 40ECH). Next we load the program start pointer and initialize the line counter.

5280
LD HL,(40A4H) 2A A4 40
Load Register pair HL with the 2-byte value from memory location 40A4H (TXTTAB). This is the start of the BASIC program text. HL now points to the beginning of the program in memory.
5283
LD BC,0000H 01 00 00
Load Register pair BC with 0000H. Register BC will be used as a line counter to track how many program lines exist before the target line.

[PROGRAM SCAN LOOP] The following loop scans through the BASIC program to find the starting line number in DE. It counts lines in BC to handle special cases like @ (which lists from line -13).

5286
LD A,(HL) 7E
Load Register A with the byte from memory location HL. This gets the low byte of the current line's link pointer (next line address).
5287
INC HL 23
Increment Register pair HL to point to the next byte (the high byte of the link pointer).
5288
OR (HL) B6
Perform a bitwise OR of Register A with the byte at memory location HL (high byte of link). This tests if both bytes are 00H, which marks the end of the program. Sets Z FLAG if both are zero.
5289
DEC HL 2B
Decrement Register pair HL to point back to the low byte of the link pointer.
528A
If the Z FLAG is set (end of program found - no more lines), JUMP to 537AH to exit the LIST routine. This happens when the program is empty or we've scanned past all lines.

Not at end of program, so we have a valid line. Check if this line's number matches our target.

528D
INC HL 23
Increment Register pair HL to skip the low byte of the link pointer.
528E
INC HL 23
Increment Register pair HL to skip the high byte of the link pointer.
528F
INC HL 23
Increment Register pair HL. Now HL points to the high byte of the line number.
5290
LD A,(HL) 7E
Load Register A with the byte from memory location HL. This is the high byte of the current line number.
5291
CP D BA
Compare Register A to Register D (high byte of target line). Sets Z FLAG if they match, C FLAG if current line < target.
5292
DEC HL 2B
Decrement Register pair HL to point to the low byte of the current line number.
5293
JR NZ,5297H 20 02
If the NZ FLAG is set (high bytes don't match), JUMP to 5297H to check carry flag. If high bytes differ, we don't need to check low bytes.

High bytes match, so check low byte to see if we have an exact match.

5295
LD A,(HL) 7E
Load Register A with the byte from memory location HL. This is the low byte of the current line number.
5296
CP E BB
Compare Register A to Register E (low byte of target line). Sets Z FLAG if exact match, C FLAG if current < target.

After this comparison, the flags tell us: Z FLAG = exact match, C FLAG = current line < target, NC FLAG = current line >= target.

5297
DEC HL 2B
Decrement Register pair HL to point back to the high byte of the link pointer.
5298
DEC HL 2B
Decrement Register pair HL to point to the low byte of the link pointer (start of this line's structure).
5299
JR NC,52ADH 30 12
If the NC FLAG is set (current line number >= target), JUMP to 52ADH. We've found our starting line or passed it, so we're done searching forward.

[CONTINUE FORWARD SCAN] Current line < target, so we need to keep scanning. Increment the line counter and advance to the next line.

529B
PUSH HL E5
Push Register pair HL onto the stack. Save current line pointer while we follow the link to the next line.
529C
LD A,(HL) 7E
Load Register A with the byte from memory location HL (low byte of link to next line).
529D
INC HL 23
Increment Register pair HL to point to the high byte of the link.
529E
LD H,(HL) 66
Load Register H with the byte from memory location HL (high byte of link). Now H has the high byte.
529F
LD L,A 6F
Load Register L with the value from Register A (low byte of link saved earlier). HL now points to the next line.

Check if this next line exists (link is not 0000H which marks end of program).

52A0
LD A,(HL) 7E
Load Register A with the byte from memory location HL (low byte of the next line's link).
52A1
INC HL 23
Increment Register pair HL to point to the high byte of the next line's link.
52A2
OR (HL) B6
Perform a bitwise OR of Register A with the byte at memory location HL. Test if both bytes are 00H (end of program). Sets Z FLAG if true.
52A3
JR Z,52A9H 28 04
If the Z FLAG is set (end of program reached), JUMP to 52A9H to restore pointers and exit the scan loop.

Valid next line exists, so increment line counter and continue scanning.

52A5
INC BC 03
Increment Register pair BC. This increments the line counter since we're advancing past another line in the search.
52A6
POP AF F1
Pop the top value from the stack into Register pair AF. This discards the saved line pointer since we're moving to the next line.
52A7
JR 528EH 18 E5
JUMP to 528EH to continue the scan loop with the next line. [LOOP BACK]

End of program reached while scanning - restore stack and exit search.

52A9
POP HL E1
Pop the top value from the stack into Register pair HL. Restore the last valid line pointer.
52AA
POP AF F1
Pop the top value from the stack into Register pair AF. Restore the command character (was pushed at 52CEH or earlier).
52AB
JR 52BFH 18 12
JUMP to 52BFH to set up for listing from line 0 (program start).

52ADH - LIST Range Adjustment for Special Commands

Handles special LIST command modifiers: up-arrow/down-arrow for ±1 line, colon for -13 lines (@ mode), and validates against available lines.

[RANGE FOUND] We've found a starting line >= target. Now adjust based on command type: down-arrow (+1), up-arrow (-1), or @ (-13).

52AD
POP DE D1
Pop the top value from the stack into Register pair DE. Restore the original command character and flags.
52AE
LD A,D 7A
Load Register A with the value from Register D (original command character or flags).
52AF
JR NZ,52B8H 20 07
If the NZ FLAG is set (not an exact match - we're past the target line), JUMP to 52B8H to handle up-arrow mode.

Exact match found. Check if this is a down-arrow command (0AH = line feed).

52B1
LD DE,0001H 11 01 00
Load Register pair DE with 0001H. Set offset to +1 line (for down-arrow).
52B4
CP 0AH FE 0A
Compare Register A to 0AH (line feed character = down-arrow). Sets Z FLAG if this is a down-arrow LIST command.
52B6
JR Z,52CEH 28 16
If the Z FLAG is set (down-arrow command), JUMP to 52CEH to apply the +1 offset and begin listing.

Not down-arrow. Check for up-arrow (5BH = left bracket).

52B8
LD DE,FFFFH 11 FF FF
Load Register pair DE with FFFFH (signed -1). Set offset to -1 line (for up-arrow).
52BB
CP 5BH FE 5B
Compare Register A to 5BH (left bracket = up-arrow on TRS-80). Sets Z FLAG if this is an up-arrow LIST command.
52BD
JR Z,52CEH 28 0F
If the Z FLAG is set (up-arrow command), JUMP to 52CEH to apply the -1 offset and begin listing.

Not up or down arrow. Set DE to 0 for default LIST, then check for @ special case.

52BF
LD DE,0000H 11 00 00
Load Register pair DE with 0000H. Set offset to 0 (no adjustment for standard LIST or period/comma).
52C2
CP 40H FE 40
Compare Register A to 40H (at-sign @). Sets Z FLAG if this is an @ LIST command.
52C4
JR Z,52CEH 28 08
If the Z FLAG is set (@ command), JUMP to 52CEH to process. Note: DE=0000H but BC holds line count which will be adjusted.

Must be colon command. Set offset to -13 lines (FFF3H) for @ mode backwards listing.

52C6
LD DE,FFF3H 11 F3 FF
Load Register pair DE with FFF3H (signed -13). Set offset to -13 lines for colon LIST command.
52C9
CP 3AH FE 3A
Compare Register A to 3AH (colon). Sets Z FLAG if this is a colon LIST command. This is a safety check.
52CB
If the NZ FLAG is set (not a colon - should never happen), JUMP to 5379H to exit. This is an error path.

52CEH - Apply Line Offset and Calculate Screen Bounds

Applies the calculated offset (±1, -13, or 0) to the line counter, checks for underflow, and calculates how many lines will fit on screen based on line length and 15-line limit.

[APPLY OFFSET] DE contains the offset to apply to the line counter BC. This adjusts the starting position based on command type.

52CE
PUSH AF F5
Push Register pair AF onto the stack. Save the command character for later use.
52CF
EX DE,HL EB
Exchange Register pair DE with Register pair HL. Now HL = offset, DE = line pointer.
52D0
ADD HL,BC 09
Add Register pair BC to Register pair HL. Calculate adjusted line position = current line count + offset. This may underflow for up-arrow or @ commands.
52D1
LD A,H 7C
Load Register A with the value from Register H (high byte of result).
52D2
CP FFH FE FF
Compare Register A to FFH. Check if high byte is FFH, indicating negative result (underflow). Sets Z FLAG if underflowed.
52D4
JR NZ,52D9H 20 03
If the NZ FLAG is set (no underflow - result is positive), JUMP to 52D9H to continue normally.

Underflow detected - tried to go before line 0. Clamp to line 0.

52D6
LD HL,0000H 21 00 00
Load Register pair HL with 0000H. Set result to 0 since we can't go before the first line.

HL now contains the number of lines to skip from program start. Swap registers and calculate how many lines we actually need to skip.

52D9
PUSH BC C5
Push Register pair BC onto the stack. Save original line count.
52DA
LD B,H 44
Load Register B with the value from Register H. Transfer high byte of skip count.
52DB
LD C,L 4D
Load Register C with the value from Register L. Transfer low byte. BC now = number of lines to skip.
52DC
POP HL E1
Pop the top value from the stack into Register pair HL. Restore original line count to HL.
52DD
OR A B7
Perform a bitwise OR of Register A with itself. This clears the CARRY FLAG to prepare for subtraction.
52DE
SBC HL,BC ED 42
Subtract with Carry Register pair BC from Register pair HL. Calculate remaining lines = total lines found - lines to skip. This tells us how many lines remain to list.
52E0
PUSH HL E5
Push Register pair HL onto the stack. Save remaining line count for later.

[SKIP TO START LINE] Now skip forward BC lines to reach the actual starting line for the LIST display.

52E1
LD HL,(40A4H) 2A A4 40
Load Register pair HL with the 2-byte value from memory location 40A4H (TXTTAB). Reset to program start to begin skipping lines.
52E4
LD E,(HL) 5E
Load Register E with the byte from memory location HL (low byte of link to next line).
52E5
INC HL 23
Increment Register pair HL to point to high byte of link.
52E6
LD D,(HL) 56
Load Register D with the byte from memory location HL (high byte of link). DE now = next line address.
52E7
DEC HL 2B
Decrement Register pair HL back to low byte of link (just for consistency).
52E8
LD A,B 78
Load Register A with the value from Register B (high byte of lines to skip).
52E9
OR C B1
Perform a bitwise OR of Register A with Register C. Test if BC = 0 (no more lines to skip). Sets Z FLAG if BC is zero.
52EA
DEC BC 0B
Decrement Register pair BC. Reduce the skip counter by 1.
52EB
EX DE,HL EB
Exchange Register pair DE with Register pair HL. Now HL points to the next line.
52EC
JR NZ,52E4H 20 F6
If the NZ FLAG is set (more lines to skip), JUMP to 52E4H to continue skipping. [LOOP BACK]

Finished skipping to the starting line. HL now points to the first line we want to LIST. Restore remaining line count and prepare for display loop.

52EE
POP BC C1
Pop the top value from the stack into Register pair BC. Restore the remaining line count (how many lines are left to potentially display).
52EF
EX DE,HL EB
Exchange Register pair DE with Register pair HL. Now DE = start line pointer, HL = (undefined, will be set).
52F0
INC BC 03
Increment Register pair BC. Adjust line count (compensate for earlier DEC).
52F1
POP AF F1
Pop the top value from the stack into Register pair AF. Restore the command character saved at 52CEH.
52F2
CP 3AH FE 3A
Compare Register A to 3AH (colon). Check if this is a colon LIST command. Sets Z FLAG if match.
52F4
LD B,A 47
Load Register B with the value from Register A. Store command character in B for later reference.
52F5
JR Z,52FCH 28 05
If the Z FLAG is set (colon command), JUMP to 52FCH to continue setup.
52F7
CP 40H FE 40
Compare Register A to 40H (at-sign). Check if this is an @ LIST command. Sets Z FLAG if match.
52F9
JR NZ,5379H 20 7E
If the NZ FLAG is set (not @ either - unexpected), JUMP to 5379H to exit. Error path.
52FB
LD C,A 4F
Load Register C with the value from Register A. Store @ character in C as well.

[PREPARE DISPLAY] Call ROM routines to clear screen region and prepare for line-by-line display.

52FC
POP AF F1
Pop the top value from the stack into Register pair AF. Restore original entry AF (from very early in routine).
52FD
LD A,1CH 3E 1C
Load Register A with 1CH. This is the cursor right control character, used to clear the bottom portion of screen.
52FF
CALL BASIC/CMD routine at 5D66H. This outputs the character in A to the screen (cursor right moves cursor and may clear area).
5302
LD A,1FH 3E 1F
Load Register A with 1FH. This is the cursor home control character.
5304
CALL BASIC/CMD routine at 5D66H. Output cursor home character.

5307H - Main LIST Display Loop

Core listing loop that displays BASIC program lines with sophisticated screen management.

5307
PUSH HL E5
Push Register pair HL onto the stack. Save line pointer.
5308
LD DE,0000H 11 00 00
Load Register pair DE with 0000H. Initialize D=row counter, E=column counter.
530B
PUSH HL E5
Push Register pair HL onto the stack. Save current line pointer.
530C
PUSH DE D5
Push Register pair DE onto the stack. Save row/column counters.
530D
PUSH BC C5
Push Register pair BC onto the stack. Save command character and line count.
530E
INC HL 23
Increment Register pair HL to skip low byte of link pointer.
530F
INC HL 23
Increment Register pair HL to skip high byte of link pointer.
5310
LD E,(HL) 5E
Load Register E with the byte from memory location HL (low byte of line number).
5311
INC HL 23
Increment Register pair HL to point to high byte of line number.
5312
LD D,(HL) 56
Load Register D with the byte from memory location HL (high byte of line number). DE = line number.
5313
PUSH DE D5
Push Register pair DE onto the stack. Save line number for later.
5314
INC HL 23
Increment Register pair HL. HL now points to BASIC line text.
5315
CALL ROM routine at 2B7EH. Converts line number in DE to ASCII and displays it.
5318
POP DE D1
Pop the top value from the stack into Register pair DE. Restore line number.
5319
PUSH DE D5
Push Register pair DE onto the stack again. Keep line number saved.
531A
CALL BASIC/CMD routine at 5D32H. Output space after line number.
531D
XOR A AF
Perform XOR of Register A with itself. Sets A to 00H.
531E
LD D,01H 16 01
Load Register D with 01H. Initialize row counter to 1.
5320
INC E 1C
Increment Register E. Adjust column counter.
5321
LD (BC),A 02
Store the value in Register A (00H) to memory location pointed to by BC.
5322
LD HL,(40A7H) 2A A7 40
Load Register pair HL with 2-byte value from 40A7H (BASIC work pointer).
5325
JR 5337H 18 10
JUMP to 5337H to enter character output loop.
5327
CP 0DH FE 0D
Compare Register A to 0DH (CR). Check for end of line. Sets Z FLAG if match.
5329
JR Z,5334H 28 09
If the Z FLAG is set (CR found), JUMP to 5334H to advance row.
532B
CP 0AH FE 0A
Compare Register A to 0AH (LF). Check for line feed. Sets Z FLAG if match.
532D
JR Z,5334H 28 05
If the Z FLAG is set (LF found), JUMP to 5334H to advance row.
532F
INC E 1C
Increment Register E. Advance column counter for displayed character.
5330
BIT 6,E CB 73
Test bit 6 of Register E. Check if E >= 64 (screen width). Sets Z FLAG if within line.
5332
JR Z,5337H 28 03
If the Z FLAG is set (not at 64 columns), JUMP to 5337H for next character.
5334
INC D 14
Increment Register D. Advance to next row (wrap or line end).
5335
LD E,00H 1E 00
Load Register E with 00H. Reset column counter to 0.
5337
LD A,(HL) 7E
Load Register A with byte from memory location HL. Get next character from BASIC line.
5338
OR A B7
Perform a bitwise OR of Register A with itself. Test for 00H (end marker). Sets Z FLAG if zero.
5339
INC HL 23
Increment Register pair HL to point to next character.
533A
JR NZ,5327H 20 EB
If the NZ FLAG is set (not end), JUMP to 5327H. [LOOP BACK]
533C
LD A,D 7A
Load Register A with the value from Register D (row count for this line).
533D
POP HL E1
Pop the top value from the stack into Register pair HL. Restore line number.
533E
POP BC C1
Pop the top value from the stack into Register pair BC. Restore command/count.
533F
POP DE D1
Pop the top value from the stack into Register pair DE. Restore row/column counters.
5340
ADD A,D 82
Add Register D to Register A. Calculate total rows used.
5341
LD D,A 57
Load Register D with the value from Register A. Store new total row count.
5342
CP 0FH FE 0F
Compare Register A to 0FH (15 rows). Check screen limit. Sets C FLAG if <15.
5344
JR C,5354H 38 0E
If the C FLAG is set (<15 rows), JUMP to 5354H to continue.
5346
POP HL E1
Pop the top value from the stack into Register pair HL. Clean up stack.
5347
LD A,B 78
Load Register A with the value from Register B (command character).
5348
CP 40H FE 40
Compare Register A to 40H (@ command). Sets Z FLAG if match.
534A
JR Z,5367H 28 1B
If the Z FLAG is set (@ command), JUMP to 5367H to exit.
534C
POP HL E1
Pop the top value from the stack into Register pair HL. Restore line pointer.
534D
DEC C 0D
Decrement Register C. Reduce remaining line count.
534E
LD A,(HL) 7E
Load Register A with byte from memory location HL (low byte of link).
534F
INC HL 23
Increment Register pair HL to point to high byte of link.
5350
LD H,(HL) 66
Load Register H with byte from memory location HL (high byte of link).
5351
LD L,A 6F
Load Register L with the value from Register A. HL points to next line.
5352
JR 5307H 18 B3
JUMP to 5307H to display next page. [LOOP TO TOP]
5354
LD (5373H),HL 22 73 53
Store Register pair HL to memory location 5373H. Save pointer for later.
5357
POP HL E1
Pop the top value from the stack into Register pair HL. Restore line pointer.
5358
LD A,(HL) 7E
Load Register A with byte from memory location HL (low byte of link).
5359
INC HL 23
Increment Register pair HL to point to high byte of link.
535A
LD H,(HL) 66
Load Register H with byte from memory location HL (high byte of link).
535B
LD L,A 6F
Load Register L with the value from Register A. HL points to next BASIC line.
535C
LD A,(HL) 7E
Load Register A with byte from memory location HL (low byte of next link).
535D
INC HL 23
Increment Register pair HL to point to high byte of next link.
535E
OR (HL) B6
Perform a bitwise OR of Register A with byte at HL. Test for 0000H (end of program). Sets Z FLAG if true.
535F
DEC HL 2B
Decrement Register pair HL to point back to low byte of link.
5360
JR Z,5367H 28 05
If the Z FLAG is set (end of program), JUMP to 5367H to exit.
5362
INC E 1C
Increment Register E. Advance line display counter.
5363
LD A,E 7B
Load Register A with the value from Register E (lines displayed).
5364
CP C B9
Compare Register A to Register C (remaining count). Sets C FLAG if A<C.
5365
JR C,530BH 38 A4
If the C FLAG is set (more to display), JUMP to 530BH. [LOOP BACK]
5367
POP HL E1
Pop the top value from the stack into Register pair HL. Restore final line pointer.
5368
PUSH HL E5
Push Register pair HL onto the stack again. Keep it saved.
5369
INC HL 23
Increment Register pair HL to skip low byte of link.
536A
INC HL 23
Increment Register pair HL to skip high byte of link.
536B
LD E,(HL) 5E
Load Register E with byte from memory location HL (low byte of last line number).
536C
INC HL 23
Increment Register pair HL to point to high byte of line number.
536D
LD D,(HL) 56
Load Register D with byte from memory location HL (high byte). DE = last displayed line number.
536E
LD (5272H),DE ED 53 72 52
Store Register pair DE to memory location 5272H. Save line number temporarily.
5372
LD HL,0000H 21 00 00
Load Register pair HL with 0000H. Clear HL for cleanup.
5375
EX (SP),HL E3
Exchange Register pair HL with value on top of stack. Replace with 0000H.
5376
PUSH HL E5
Push Register pair HL onto the stack. Save retrieved value.
5377
JR 53BEH 18 45
JUMP to 53BEH to continue cleanup and exit.

5379H - EXIT/EDIT Entry Point

Alternative exit path for LIST command and entry point for EDIT mode. In the EDIT mode, This section checks if the cursor is positioned within the valid video buffer range (3C00H-3FFFH) when EDIT mode is requested. If the cursor position minus 40H (64 decimal) falls below the video RAM area, the routine exits EDIT mode and returns to BASIC ready state.

5379
PUSH AF F5
Push Register pair AF onto the stack. Save accumulator and flags.
537A
LD A,1DH 3E 1D
Load Register A with 1DH. Screen control code.
537C
CALL ROM routine at 0033H. Output control character to screen.
537F
POP AF F1
Pop the top value from the stack into Register pair AF. Restore accumulator and flags.
5380
POP BC C1
Pop the top value from the stack into Register pair BC. Restore saved values.
5381
LD B,H 44
Load Register B with the value from Register H.
5382
LD C,L 4D
Load Register C with the value from Register L. BC = HL.
5383
INC HL 23
Increment Register pair HL.
5384
INC HL 23
Increment Register pair HL again.
5385
LD E,(HL) 5E
Load Register E with byte from memory location HL.
5386
INC HL 23
Increment Register pair HL.
5387
LD D,(HL) 56
Load Register D with byte from memory location HL. DE loaded with 2-byte value.
5388
CP 2CH FE 2C
Compare Register A to 2CH (comma). Check for EDIT mode. Sets Z FLAG if match.
538A
If the Z FLAG is set (comma), JUMP to ROM routine at 2E65H for EDIT processing.
538D
PUSH DE D5
Push Register pair DE onto the stack.
538E
PUSH BC C5
Push Register pair BC onto the stack.
538F
LD A,0FH 3E 0F
Load Register A with 0FH. Screen control code.
5391
CALL ROM routine at 0033H. Output control character.
5394
LD HL,(4020H) 2A 20 40
Load Register pair HL with 2-byte value from 4020H (cursor position).
5397
LD DE,FFC0H 11 C0 FF
Load Register DE with FFC0H (-40H in two's complement = -64 decimal). This will be used to subtract one full screen row (64 characters) from the cursor position.
539A
ADD HL,DE 19
Add Register DE to Register HL. This subtracts 64 from the cursor position, moving it back one full row. The result checks if there's room above the cursor for EDIT display.
539B
LD A,H 7C
Load Register A with the high byte of HL (the result of the subtraction). This allows checking if the position has fallen below valid video RAM.
539C
CP 3CH FE 3C
Compare Register A with 3CH (the high byte of video RAM start at 3C00H). If Register A is less than 3CH, the CARRY FLAG is set; otherwise it is cleared.
539E
If the CARRY FLAG is set (meaning the calculated position is below 3C00H), JUMP to 53B9H to exit EDIT mode because the cursor is too close to the top of the screen to display the EDIT interface properly.

[EDIT BUFFER CHECK PASSED - Check for "READY" Command]
The cursor position is valid for EDIT mode. Now check if the user typed the word "READY" to exit or perform special actions.

53A0
EX DE,HL EB
Exchange Register DE with Register HL. Now DE contains the cursor position minus 64, which points to the line above the cursor where a command might have been typed.
53A1
LD B,0AH 06 0A
Load Register B with 0AH (10 decimal). This is the character count for the comparison loop - checking for the 10-character string "READY " (5 letters plus 5 spaces).
53A3
LD HL,53C1H 21 C1 53
Load Register HL with 53C1H, pointing to the comparison string data at that address (contains "READY " with trailing spaces).

[LOOP START - Compare Screen Buffer with "READY"]
Loop through 10 characters comparing what's on the screen with the expected "READY" command.

53A6
LD A,(DE) 1A
Load Register A with the character from video RAM pointed to by DE (the screen position being checked).
53A7
INC DE 13
Increment Register DE to point to the next character position on the screen.
53A8
CP 20H FE 20
Compare Register A with 20H (space character). If Register A is less than 20H, the CARRY FLAG is set (control character); if A equals 20H, the Z FLAG is set.
53AA
If NO CARRY FLAG (character >= 20H), JUMP to 53AEH to compare it directly. This handles normal printable characters.
53AC
OR 40H F6 40
Convert control character to uppercase equivalent by setting bit 6. Control characters 00H-1FH map to 40H-5FH (@ through _), which allows comparison with the alphabetic characters in the "READY" string.
53AE
CP (HL) BE
Compare Register A with the expected character pointed to by HL (from the "READY" string at 53C1H). If they match, the Z FLAG is set; otherwise the NZ FLAG is set.
53AF
INC HL 23
Increment Register HL to point to the next character in the comparison string.
53B0
If the NZ FLAG is set (characters didn't match), JUMP to 53B9H to exit this check - the user didn't type "READY".
53B2
DJNZ 53A6H 10 F2
Decrement B and JUMP to 53A6H if B is not zero. This continues the loop for all 10 characters. When B reaches zero, all characters matched.

[ALL CHARACTERS MATCHED - "READY" Command Detected]
The user typed "READY" on the line above the cursor. Send cursor positioning codes and return to BASIC.

53B4
Load Register A with 1BH (ESC character). This will be output to initiate a cursor positioning sequence.
53B6
CALL ROM routine at 0033H to output the character in Register A (ESC) to the screen/display device.

[EXIT EDIT MODE - Restore BASIC]
Whether the READY check passed or failed, clean up and return to BASIC ready state.

53B9
Load Register A with 1EH (cursor home control code). This will position the cursor at the home position.
53BB
CALL ROM routine at 0033H to output the character in Register A (home cursor) to the display.
53BE
JUMP to ROM routine at 2B33H which handles return to BASIC ready state, displaying the "Ready" prompt and accepting new commands.

53C1H - "READY" Comparison String Data

This is the data string used for comparison in the EDIT mode check at 53A3H. It contains the text "READY" followed by trailing spaces (total 10 bytes) used to detect if the user typed this command.

53C1
DEFB 52H 52
Define byte 'R' (first character of "READY").
53C2
DEFB 45H 45
Define byte 'E'.
53C3
DEFB 41H 41
Define byte 'A'.
53C4
DEFB 44H 44
Define byte 'D'.
53C5
DEFB 59H 59
Define byte 'Y' (last letter of "READY").
53C6
DEFB 20H,20H 20 20
Define two space characters.
53C8
DEFB 20H,20H 20 20
Define two more space characters.
53CA
DEFB 20H 20
Define final space character (total of 10 bytes: "READY" + 5 spaces).

53CBH - Return from LIST/EDIT - Update Line Number

This is the common return point from LIST and EDIT commands. It updates the BASIC system variable at 40ECH with the last displayed line number (stored temporarily at 5272H), then performs stack cleanup and returns to the BASIC command processor.

53CB
POP AF F1
Pop Register AF from the stack, discarding the saved AF value that was pushed earlier during command setup.
53CC
If the CARRY FLAG is set, JUMP to 5455H. This handles a special exit path for certain command conditions.
53CF
PUSH DE D5
Push Register DE onto the stack to preserve the current line pointer or state during command dispatch processing.
53D0
PUSH BC C5
Push Register BC onto the stack to preserve command character and counters.
53D1
PUSH HL E5
Push Register HL onto the stack to preserve the current position pointer.
53D2
DEC HL 2B
Decrement Register HL to point to the previous character position, preparing for input processing.
53D3
Call RST 10H (ROM routine at 0010H) to get next character from the input buffer or keyboard. Returns character in Register A with CARRY FLAG set if numeric digit.
53D4
If NO CARRY FLAG (not a numeric digit), JUMP to 53E0H to handle command dispatch for non-numeric commands.

[NUMERIC LINE NUMBER ENTRY]
User entered a line number. Parse it and execute the appropriate action.

53D6
CALL ROM routine at 1E5AH to convert ASCII line number to binary. Returns 16-bit value in Register DE.
53D9
CP 0DH FE 0D
Compare Register A with 0DH (carriage return). If A equals 0DH, the Z FLAG is set; otherwise the NZ FLAG is set.
53DB
If the NZ FLAG is set (not a carriage return - invalid entry), JUMP to 5452H for stack cleanup and error handling.
53DD
JUMP to ROM routine at 1997H to execute or insert the line with the parsed line number now in Register DE.

[COMMAND DISPATCH - Non-Numeric Input]
Check for special command keywords (RENEW, RENUM, REF, etc.) by scanning the command table.

53E0
EX DE,HL EB
Exchange Register DE with Register HL. Now DE points to the input buffer position and HL can be used for command table scanning.
53E1
LD HL,54B7H 21 B7 54
Load Register HL with 54B7H, pointing to the command dispatch table that contains keywords like "RENEW", "RENUM", "REF".

[COMMAND SCAN LOOP]
Loop through the command table to find a match with user input.

53E4
PUSH DE D5
Push Register DE (input buffer position) onto the stack to save the starting position for potential restart of comparison.
53E5
LD A,(DE) 1A
Load Register A with the next character from input buffer pointed to by DE.
53E6
INC DE 13
Increment Register DE to point to the next input character.
53E7
CALL subroutine at 57BAH to convert character to uppercase and handle special character processing.
53EA
CP (HL) BE
Compare Register A with the command table character pointed to by HL. If they match, the Z FLAG is set; otherwise the NZ FLAG is set.
53EB
If the Z FLAG is set (characters match), JUMP to 53FBH to continue checking the rest of the command word.

[NO MATCH - Skip to Next Command]
The input didn't match this command entry. Skip to the next command in the table.

53ED
BIT 7,(HL) CB 7E
Test bit 7 of the byte at (HL). If bit 7 is set (value >= 80H), the Z FLAG is cleared (indicating end of command word); if bit 7 is clear, the Z FLAG is set.
53EF
INC HL 23
Increment Register HL to point to the next byte in command table.
53F0
If the Z FLAG is set (bit 7 was clear), JUMP to 53EDH to continue skipping characters in this command word until the end marker (bit 7 set) is found.
53F2
INC HL 23
Increment Register HL past the low byte of jump address.
53F3
INC HL 23
Increment Register HL past the high byte of jump address. HL now points to the next command entry.
53F4
POP DE D1
Pop Register DE from the stack to restore the input buffer starting position.
53F5
LD A,(HL) 7E
Load Register A with the first character of the next command in the table (or 00H if end of table).
53F6
OR A B7
Perform OR A to test if Register A is zero. If A = 0, the Z FLAG is set (end of table); otherwise the NZ FLAG is set.
53F7
If the NZ FLAG is set (not end of table), JUMP to 53E4H to try matching against the next command entry.
53F9
JUMP to 5452H for cleanup and return - no command matched in the table.

[CHARACTER MATCH FOUND - Continue Checking]
One character matched. Continue comparing the rest of the command word.

53FB
INC HL 23
Increment Register HL to point to the next character in command name.
53FC
LD A,(HL) 7E
Load Register A with the next command table character.
53FD
BIT 7,A CB 7F
Test bit 7 of Register A. If bit 7 is set (A >= 80H), the Z FLAG is cleared (last character of command); if bit 7 is clear, the Z FLAG is set.
53FF
If the Z FLAG is set (not last character), JUMP to 53E5H to continue comparing more characters.

[COMPLETE COMMAND MATCH - Get Jump Address]
All characters matched. Extract the jump address and check command flags.

5401
INC HL 23
Increment Register HL to point to the low byte of the command handler address.
5402
LD C,(HL) 4E
Load Register C with the low byte of handler address.
5403
INC HL 23
Increment Register HL to point to the high byte of the command handler address.
5404
LD B,(HL) 46
Load Register B with the high byte of handler address. Now BC contains the complete jump address.
5405
POP HL E1
Pop Register HL from the stack to restore the input buffer position.
5406
BIT 6,A CB 77
Test bit 6 of Register A (the last character of the matched command). If bit 6 is set, the Z FLAG is cleared (special flag indicating command needs input processing); if clear, the Z FLAG is set.
5408
If the Z FLAG is set (bit 6 clear - no special processing), JUMP to 5419H to execute the command directly.

[SPECIAL PROCESSING - Clear Input Buffer]
Bit 6 was set, indicating this command requires clearing the input buffer before execution.

540A
LD (57B6H),BC ED 43 B6 57
Store Register BC (command handler address) at memory location 57B6H for later retrieval after buffer clearing.
540E
LD (HL),20H 36 20
Store 20H (space character) at the location pointed to by HL, clearing the input buffer.
5410
INC HL 23
Increment Register HL to the next buffer position.
5411
Call RST 18H (ROM routine at 0018H) to compare (HL) with space. Returns CARRY FLAG if (HL) is not a space, number, or colon.
5412
If the CARRY FLAG is set (non-space, non-numeric character found), JUMP to 540EH to continue clearing the buffer.
5414
DEC HL 2B
Decrement Register HL to point back to the last cleared position.
5415
LD (HL),FFH 36 FF
Store FFH (end marker) at the location pointed to by HL, marking the end of the cleared buffer.
5417
JUMP to 5452H for stack cleanup and command execution.

[DIRECT COMMAND EXECUTION]
Bit 6 was clear. Execute the command directly without buffer clearing.

5419
EX DE,HL EB
Exchange Register DE with Register HL. Swap buffer pointer positions for command parameter processing.
541A
DEC HL 2B
Decrement Register HL to point to the previous position in the input stream.
541B
BIT 5,A CB 6F
Test bit 5 of Register A (command flag byte). If bit 5 is set, the Z FLAG is cleared (indicating special parameter handling needed); if clear, the Z FLAG is set.
541D
If the NZ FLAG is set (bit 5 set), JUMP to 5458H for special parameter processing (used by commands with complex syntax).

[STANDARD PARAMETER PROCESSING]
Parse line number and comma-separated parameters for standard commands.

541F
Call RST 10H (ROM routine at 0010H) to get next character. Returns character in Register A with CARRY FLAG set if numeric digit.
5420
If the CARRY FLAG is set (numeric digit), JUMP to 5426H to parse the line number.
5422
CP 2EH FE 2E
Compare Register A with 2EH (period '.'). If A equals 2EH, the Z FLAG is set; otherwise the NZ FLAG is set. Period is used to mean "current line".
5424
If the NZ FLAG is set (not a period), JUMP to 5452H for error handling - invalid syntax.
5426
CALL subroutine at 65CFH to parse line number or period notation. Returns line number in Register DE.
5429
If the Z FLAG is set (parsing error), JUMP to 5452H for error cleanup.
542B
CP 0DH FE 0D
Compare Register A with 0DH (carriage return). If A equals 0DH, the Z FLAG is set; otherwise the NZ FLAG is set.
542D
If the NZ FLAG is set (not carriage return - more parameters follow), JUMP to 5426H to continue parsing.

[PREPARE FOR COMMAND EXECUTION]
All parameters parsed. Set up registers and execute the command handler.

542F
POP HL E1
Pop Register HL from the stack to restore a saved pointer.
5430
POP DE D1
Pop Register DE from the stack to restore another saved value.
5431
LD A,D 7A
Load Register A with the high byte of Register D (line number high byte).
5432
EX AF,AF' 08
Exchange AF with AF' (shadow registers) to temporarily save the high byte.
5433
LD A,(BC) 0A
Load Register A with the byte at address BC (command-specific parameter or configuration byte).
5434
DEC A 3D
Decrement Register A by 1, adjusting the parameter value.
5435
ADD A,D 82
Add Register D to Register A. This calculates adjusted line number or offset.
5436
LD D,A 57
Load Register D with Register A, storing the adjusted high byte back into DE.
5437
CP E BB
Compare Register A with Register E (low byte). If A < E, the CARRY FLAG is set; if A = E, the Z FLAG is set.
5438
If NO CARRY FLAG (A >= E - valid range), JUMP to 53DDH to execute the BASIC line.

[PREPARE FOR LINE INSERTION]
Calculate buffer offsets and prepare to insert/move BASIC program lines.

543A
PUSH DE D5
Push Register DE (line number) onto the stack to preserve it during buffer operations.
543B
PUSH HL E5
Push Register HL onto the stack to preserve the buffer pointer.
543C
LD A,(BC) 0A
Load Register A with the byte at address BC (length or count parameter).
543D
EX AF,AF' 08
Exchange AF with AF' to retrieve the previously saved value.
543E
INC BC 03
Increment Register BC to point to the next parameter or data.
543F
PUSH BC C5
Push Register BC onto the stack to save the updated parameter pointer.
5440
LD C,A 4F
Load Register C with Register A, preparing a 16-bit offset in BC.
5441
LD B,00H 06 00
Load Register B with 00H, completing the 16-bit value in BC with high byte = 0.
5443
ADD HL,BC 09
Add Register BC to Register HL. This calculates the target address for the buffer operation.
5444
EX DE,HL EB
Exchange Register DE with Register HL. Now DE contains the target address and HL contains the line number.
5445
EX AF,AF' 08
Exchange AF with AF' to retrieve the count value.
5446
LD H,B 60
Load Register H with Register B (00H), setting up HL for address calculation.
5447
LD L,A 6F
Load Register L with Register A, completing the offset value in HL.
5448
DEC L 2D
Decrement Register L by 1, adjusting the offset.
5449
ADD HL,DE 19
Add Register DE to Register HL. This calculates the source end address for the block move.
544A
EX DE,HL EB
Exchange Register DE with Register HL. Now DE points to source end and HL points to destination end.
544B
LDDR ED B8
Load, Decrement, Repeat: Copy BC bytes from (HL) to (DE), decrementing both HL and DE after each byte, moving data downward in memory to make space.
544D
EX DE,HL EB
Exchange Register DE with Register HL, restoring pointer orientation.
544E
POP HL E1
Pop Register HL from the stack to restore the parameter pointer.
544F
LD C,A 4F
Load Register C with Register A, setting up the byte count for forward copy.
5450
LDIR ED B0
Load, Increment, Repeat: Copy BC bytes from (HL) to (DE), incrementing both HL and DE after each byte, filling the opened space with new data.

[CLEANUP AND RETURN]
Restore saved registers and return to BASIC command processor.

5452
POP HL E1
Pop Register HL from the stack to restore the pointer.
5453
POP BC C1
Pop Register BC from the stack to restore the command info.
5454
POP DE D1
Pop Register DE from the stack to restore the line pointer.
5455
JUMP to ROM routine at 0375H which handles return to BASIC ready state, cleaning up any remaining state and displaying the "Ready" prompt.

5458H - Special Parameter Command Handler (Bit 5 Set)

This section handles commands that have bit 5 set in their flag byte (from 53FDH), indicating they require special parameter parsing different from standard line-number commands. This is used for commands with complex syntax like line-range specifications or period-based current-line references.

5458
LD (54A6H),A 32 A6 54
Store Register A (the command flag byte with bit 5 set) at memory location 54A6H for later reference during parameter processing.
545B
Call RST 10H (ROM routine at 0010H) to get next character from input. Returns character in Register A with CARRY FLAG set if numeric digit.
545C
If the CARRY FLAG is set (numeric digit found), JUMP to 5469H to parse the line number.
545E
CP 2EH FE 2E
Compare Register A with 2EH (period '.'). If A equals 2EH, the Z FLAG is set; otherwise the NZ FLAG is set. Period represents "current line".
5460
If the NZ FLAG is set (not a period or digit), JUMP to 5452H for error cleanup - invalid syntax.

[PERIOD FOUND - Use Current Line]
Period notation used. Get current line number from 40ECH.

5462
LD BC,(40ECH) ED 4B EC 40
Load Register BC with the current line number from memory location 40ECH. This is the line number of the last displayed or executed line.
5466
Call RST 10H to get next character after the period.
5467
JUMP to 546EH to continue processing with the current line number now in BC.

[NUMERIC LINE NUMBER]
Parse the numeric line number from input.

5469
CALL ROM routine at 1E5AH to convert ASCII line number to binary. Returns 16-bit line number in Register DE.
546C
LD B,D 42
Load Register B with Register D, copying the high byte of line number to B.
546D
LD C,E 4B
Load Register C with Register E, copying the low byte of line number to C. Now BC contains the complete line number.

[CHECK FOR COMMA SEPARATOR]
Look for comma to see if this is a range specification (start,end).

546E
CP 2CH FE 2C
Compare Register A with 2CH (comma). If A equals 2CH, the Z FLAG is set; otherwise the NZ FLAG is set.
5470
If the NZ FLAG is set (not a comma), JUMP to 5452H for cleanup - single line number only, not a range.

[COMMA FOUND - Parse End Line Number]
This is a range specification. Parse the second line number.

5472
Call RST 10H to get next character after the comma (should be start of second line number).
5473
If NO CARRY FLAG (not a numeric digit), JUMP to 5452H for error - invalid second line number.
5475
CALL ROM routine at 1E5AH to parse second line number. Returns value in Register DE.
5478
CP 0DH FE 0D
Compare Register A with 0DH (carriage return). If A equals 0DH, the Z FLAG is set; otherwise the NZ FLAG is set.
547A
If the NZ FLAG is set (not carriage return - extra characters present), JUMP to 5452H for error handling - invalid syntax.

[VALID RANGE - Clean Stack and Execute]
Both line numbers parsed successfully. Clean up the stack and execute the command with the range.

547C
POP AF F1
Pop and discard AF from stack (cleanup).
547D
POP AF F1
Pop and discard AF from stack (cleanup).
547E
POP AF F1
Pop and discard AF from stack (cleanup).
547F
POP AF F1
Pop and discard AF from stack (cleanup).
5480
POP AF F1
Pop and discard AF from stack (cleanup).
5481
POP AF F1
Pop and discard AF from stack (cleanup). Total of 6 stack pops to remove all saved state.
5482
PUSH DE D5
Push Register DE (second line number) onto the stack to preserve the end line number.
5483
LD D,B 50
Load Register D with Register B (high byte of first line number).
5484
LD E,C 59
Load Register E with Register C (low byte of first line number). Now DE contains the starting line number.
5485
CALL ROM routine at 1B2CH to find BASIC program line with line number in DE. Returns pointer in HL and BC, CARRY FLAG clear if found.
5488
If NO CARRY FLAG (line not found), JUMP to ROM error handler at 1ED9H to generate "Undefined statement" error.
548B
LD DE,(40A7H) ED 5B A7 40
Load Register DE with the BASIC work pointer from memory location 40A7H.
548F
LD H,B 60
Load Register H with Register B.
5490
LD L,C 69
Load Register L with Register C. Now HL contains the line pointer from the earlier CALL.
5491
DEC DE 1B
Decrement Register DE by 1.
5492
DEC DE 1B
Decrement Register DE by 1 again. Total adjustment of -2 bytes to point to link bytes.
5493
PUSH DE D5
Push Register DE onto the stack to save the adjusted pointer.
5494
PUSH BC C5
Push Register BC onto the stack to preserve the line position.
5495
LD BC,0004H 01 04 00
Load Register BC with 0004H (4 decimal). This is the offset to skip the line link bytes and line number to reach the actual BASIC code.
5498
ADD HL,BC 09
Add Register BC to Register HL. Now HL points to the first byte of BASIC code in the line (after the 2-byte link and 2-byte line number).

[COPY LINE CONTENT LOOP]
Copy the BASIC line content to work area until end of line (00H terminator).

5499
LD A,(HL) 7E
Load Register A with the byte from BASIC line pointed to by HL.
549A
OR A B7
Perform OR A to test if Register A is zero (line terminator). If A = 0, the Z FLAG is set; otherwise the NZ FLAG is set.
549B
LD (DE),A 12
Store Register A at the location pointed to by DE (copying byte to work area).
549C
INC HL 23
Increment Register HL to point to the next source byte.
549D
INC DE 13
Increment Register DE to point to the next destination byte.
549E
INC BC 03
Increment Register BC (byte counter).
549F
If the NZ FLAG is set (not end of line yet), JUMP to 5499H to continue copying bytes.

[PREPARE FOR COMMAND EXECUTION]
Line copied. Set up registers and call the command handler.

54A1
LD D,B 50
Load Register D with Register B (high byte of count).
54A2
LD E,C 59
Load Register E with Register C (low byte of count). Now DE contains the byte count copied.
54A3
POP BC C1
Pop Register BC from the stack to restore the line pointer.
54A4
PUSH DE D5
Push Register DE (byte count) onto the stack to preserve it.
54A5
LD A,00H 3E 00
Load Register A with 00H. This value will be modified by self-modifying code at 54A6H (set earlier at 5458H).
54A7
RRCA 0F
Rotate Right Circular A. Bit 0 goes into CARRY FLAG and bit 7. This tests bit 0 of the command flag byte.
54A8
If NO CARRY FLAG (bit 0 was clear), JUMP to 54B0H to skip special processing.

[SPECIAL PROCESSING - Bit 0 Set]
Bit 0 of command flag was set, requiring additional setup before execution.

54AA
CALL ROM routine at 2BE4H for special setup (likely related to tokenization or line preparation).
54AD
CALL ROM routine at 1AF8H for additional processing (likely memory allocation or buffer setup).

[FINAL CLEANUP AND RETURN]
Restore all registers and return to BASIC.

54B0
POP BC C1
Pop Register BC from the stack.
54B1
POP HL E1
Pop Register HL from the stack.
54B2
POP DE D1
Pop Register DE from the stack.
54B3
DEC HL 2B
Decrement Register HL by 1 to adjust pointer position.
54B4
JUMP to ROM routine at 1AA7H to complete command execution and return to BASIC ready state.

54B7H - Command Dispatch Table

This table contains the command keywords (RENEW, RENUM, REF) with their associated flag bytes and jump addresses. Each entry consists of the command name (with bit 7 set on the last character), followed by a flag byte, then a 2-byte jump address. The flag byte controls parameter processing behavior at 5406H and 541BH.

54B7
DEFB 52H,45H,4EH,45H,57H 52 45 4E 45 57
Define bytes for "RENEW" command name (52H='R', 45H='E', 4EH='N', 45H='E', 57H='W').
54BC
DEFB C0H C0
Define flag byte C0H (binary 11000000). Bit 7 marks end of command name, bit 6 indicates buffer clearing required (see 5406H).
54BD
DEFW 5201H 01 52
Define word (2 bytes) 5201H - the jump address for RENEW command handler.
54BF
DEFB 52H,45H,4EH,55H,4DH 52 45 4E 55 4D
Define bytes for "RENUM" command name (52H='R', 45H='E', 4EH='N', 55H='U', 4DH='M').
54C4
DEFB C0H C0
Define flag byte C0H (binary 11000000). Same flags as RENEW - bit 7 (end marker), bit 6 (buffer clear).
54C5
DEFW 524FH 4F 52
Define word 524FH - the jump address for RENUM command handler (SYS11).
54C7
DEFB 52H,45H,46H 52 45 46
Define bytes for "REF" command name (52H='R', 45H='E', 46H='F').
54CA
DEFB C0H C0
Define flag byte C0H (binary 11000000). Same flags - bit 7 (end), bit 6 (buffer clear).
54CB
DEFW 012EH 2E 01
Define word 012EH - the jump address for REF command handler (SYS12).
54CD
DEFB 44H,49H 44 49
Define bytes for "DI" command prefix (44H='D', 49H='I').
54CF
DEFB A1H A1
Define flag byte A1H (binary 10100001). Bit 7 (end), bit 5 (special parameter processing, see 541BH), bit 0 (additional setup).
54D0
DEFW 0000H 00 00
Define word 0000H - placeholder jump address (command may be incomplete or uses alternate dispatch).
54D2
DEFB 44H,55H 44 55
Define bytes for "DU" command prefix (44H='D', 55H='U').
54D4
DEFB A0H A0
Define flag byte A0H (binary 10100000). Bit 7 (end), bit 5 (special parameter processing).
54D5
DEFW 0000H 00 00
Define word 0000H - placeholder jump address.
54D7
DEFB 41H 41
Define byte for "A" command (41H='A').
54D8
DEFB 80H 80
Define flag byte 80H (binary 10000000). Only bit 7 set (end marker) - minimal flags for simple command.
54D9
DEFW 54FAH FA 54
Define word 54FAH - jump address for "A" command handler.
54DB
DEFB 44H 44
Define byte for "D" command (44H='D').
54DC
DEFB 80H 80
Define flag byte 80H - only end marker, no special processing.
54DD
DEFW 54F3H F3 54
Define word 54F3H - jump address for "D" command handler.
54DF
DEFB 45H 45
Define byte for "E" command (45H='E').
54E0
DEFB 80H 80
Define flag byte 80H - simple command.
54E1
DEFW 54EEH EE 54
Define word 54EEH - jump address for "E" command handler.
54E3
DEFB 4CH 4C
Define byte for "L" command (4CH='L' for LIST).
54E4
DEFB 80H 80
Define flag byte 80H - simple command.
54E5
DEFW 54E8H E8 54
Define word 54E8H - jump address for LIST command handler.
54E7
DEFB 00H 00
Define byte 00H - end of command table marker. When scanning reaches this, no command matched.

54E8H - "LIST" Command Handler

This is the entry point for the LIST command (single letter "L"). It displays either a line number or text string on the output device.

54E8
DEFB 04H 04
Define byte 04H - parameter count or configuration byte for LIST command.
54E9
DEFB 4CH,49H,53H,54H 4C 49 53 54
Define bytes for text string "LIST" (4CH='L', 49H='I', 53H='S', 54H='T').
54ED
DEFB 0DH 0D
Define byte 0DH (carriage return) - terminates the string.

54EEH - "EDIT" Command Handler

This is the entry point for the EDIT command (single letter "E").

54EE
DEFB 04H 04
Define byte 04H - parameter count or configuration byte for EDIT command.
54EF
DEFB 45H,44H,49H,54H 45 44 49 54
Define bytes for text string "EDIT" (45H='E', 44H='D', 49H='I', 54H='T').

54F3H - "DELETE" Command Handler

This is the entry point for the DELETE command (single letter "D").

54F3
DEFB 06H 06
Define byte 06H - parameter count or configuration byte for DELETE command (6 characters in "DELETE").
54F4
DEFB 44H,45H,4CH,45H,54H,45H 44 45 4C 45 54 45
Define bytes for text string "DELETE" (44H='D', 45H='E', 4CH='L', 45H='E', 54H='T', 45H='E').

54FAH - "AUTO" Command Handler

This is the entry point for the AUTO command (single letter "A"). AUTO enables automatic line numbering mode for entering BASIC programs.

54FA
DEFB 04H 04
Define byte 04H - parameter count or configuration byte for AUTO command.
54FB
DEFB 41H,55H,54H,4FH 41 55 54 4F
Define bytes for text string "AUTO" (41H='A', 55H='U', 54H='T', 4FH='O').

54FFH - DOS System Flag Check and AUTO Processing

This section checks a DOS system flag to determine if chaining is active, then processes AUTO command parameters including output control and file operations.

54FF
LD A,(436CH) 3A 6C 43
Load Register A with the DOS system flags byte from memory location 436CH. This byte controls various DOS operational modes.
5502
BIT 0,A CB 47
Test bit 0 of Register A. If bit 0 is set (1), the Z FLAG is cleared; if bit 0 is clear (0), the Z FLAG is set. Bit 0 indicates if chaining mode is active.
5504
If the Z FLAG is set (bit 0 clear - chaining not active), JUMP to 5522H to skip quote-removal processing.

[CHAINING ACTIVE - Remove Quotes from String]
When chaining is active (typically during CMD"F" execution), remove embedded quotes from strings in BASIC program.

5506
PUSH HL E5
Push Register HL onto the stack to preserve the current line pointer.
5507
INC HL 23
Increment Register HL to point to the next character in the line.
5508
LD A,(HL) 7E
Load Register A with the character at (HL).
5509
CP 22H FE 22
Compare Register A with 22H (double quote character). If A equals 22H, the Z FLAG is set; otherwise the NZ FLAG is set.
550B
If the NZ FLAG is set (not a quote), JUMP to 551AH to check for end of line.

[QUOTE FOUND - Check for Double Quotes]
Found a quote character. Check if it's a doubled quote (escaped quote within string).

550D
INC HL 23
Increment Register HL to look at the next character.
550E
LD A,(HL) 7E
Load Register A with the next character.
550F
CP 22H FE 22
Compare Register A with 22H (quote) to check if this is a doubled quote.
5511
If the Z FLAG is set (doubled quote found - literal quote in string), JUMP to 5507H to continue scanning.

[NOT A DOUBLED QUOTE - Convert Character]
This is the closing quote. Convert the character for processing.

5513
CALL subroutine at 57BAH to convert character to uppercase or perform special character processing.
5516
OR A B7
Perform OR A to test if Register A is zero. If A = 0, the Z FLAG is set; otherwise the NZ FLAG is set.
5517
LD (HL),A 77
Store the converted character back to memory at (HL), replacing the original.
5518
If the NZ FLAG is set (character was not zero), JUMP to 550DH to continue processing characters.

[CHECK FOR END OF LINE]
Check if we've reached the end marker or special token.

551A
OR A B7
Perform OR A to test if Register A is zero (line terminator).
551B
If the Z FLAG is set (end of line), JUMP to 5521H to finish.
551D
CP 93H FE 93
Compare Register A with 93H (BASIC token - likely REM or a string delimiter token). If A equals 93H, the Z FLAG is set.
551F
If the NZ FLAG is set (not the special token), JUMP to 5507H to continue scanning the line.
5521
POP HL E1
Pop Register HL from the stack to restore the original line pointer.

[PREPARE FOR OUTPUT CONTROL]
Set up for checking output redirection and file operations.

5522
PUSH HL E5
Push Register HL onto the stack to save the line pointer.
5523
LD BC,(57B6H) ED 4B B6 57
Load Register BC with the stored value from memory location 57B6H (command handler address or parameter, stored earlier at 540AH).
5527
XOR A AF
XOR A with itself to set Register A to 00H and clear all flags. The Z FLAG is now set.
5528
LD (57B7H),A 32 B7 57
Store 00H at memory location 57B7H, clearing a control flag (high byte of the address stored at 57B6H).
552B
Call RST 10H (ROM routine at 0010H) to get next character from input. Returns character in Register A with CARRY FLAG set if numeric digit.
552C
INC A 3C
Increment Register A by 1. This converts FFH (end marker) to 00H, making it easier to test for end of input.
552D
If the Z FLAG is set (A was FFH - end of input), JUMP to 5539H to handle end-of-input processing.

[NORMAL EXIT PATH]
Not end of input. Clean up and return.

552F
POP HL E1
Pop Register HL from the stack.
5530
POP BC C1
Pop Register BC from the stack.
5531
POP AF F1
Pop Register AF from the stack.
5532
RET C D8
If the CARRY FLAG is set, RETURN immediately. This exits the routine conditionally based on the restored flags.
5533
CALL subroutine at 63A9H to check/manipulate the guard flag. If the guard is set (C9H = RET instruction), this call returns immediately without executing further code.
5536
JUMP to 5DDFH to continue processing (likely error handling or file operations based on context from BASIC/CMD).

[END OF INPUT - Stack Cleanup Loop]
End of input detected (FFH marker found). Clean up stack and prepare for AUTO mode execution.

5539
DJNZ 552FH 10 F4
Decrement B and JUMP to 552FH if B is not zero. This loops to pop additional items from the stack. Register B was set earlier and determines how many pops are needed.
553B
POP AF F1
Pop Register AF from the stack (cleanup).
553C
POP AF F1
Pop Register AF from the stack (cleanup).
553D
POP AF F1
Pop Register AF from the stack (cleanup).
553E
POP AF F1
Pop Register AF from the stack (cleanup). Total of 4 additional stack pops to clear nested state.

[AUTO MODE PROCESSING]
Stack cleaned. Now set up for AUTO mode line numbering or special command execution.

553F
Call RST 10H to get next character from input.
5540
LD DE,1A25H 11 25 1A
Load Register DE with 1A25H - a ROM address, likely a return address for AUTO mode processing.
5543
PUSH DE D5
Push Register DE onto the stack, setting up the return address for when the called routine completes.
5544
LD A,C 79
Load Register A with Register C (low byte of the value from 57B6H, loaded at 5523H).
5545
CP 20H FE 20
Compare Register A with 20H (space character / 32 decimal). If A < 20H, CARRY FLAG is set; if A = 20H, Z FLAG is set; if A > 20H, NO CARRY FLAG.
5547
If NO CARRY FLAG (A >= 20H), JUMP to 5559H for alternate processing path.

[SPECIAL MODE - Value Less Than 20H]
The command byte is less than 32 (space). Process as special command code.

554A
DEC A 3D
Decrement Register A by 1, adjusting the command value.
554B
If the NZ FLAG is set (A was not 01H before decrement), JUMP to ROM routine at 1997H to execute or insert line.

[A WAS 01H - Clear Program and Reset]
The command value was 01H (decremented to 00H). This triggers program clearing.

554E
LD HL,(40A4H) 2A A4 40
Load Register HL with the start of BASIC program from TXTTAB at memory location 40A4H.
5551
LD (HL),FFH 36 FF
Store FFH (end marker) at the start of the program area, effectively erasing all BASIC program lines.
5553
CALL ROM routine at 1AF8H to perform memory management and pointer updates after clearing the program.
5556
JUMP to ROM routine at 1B59H to complete the reset and return to BASIC ready state.

[ALTERNATE PATH - Value >= 20H]
Command byte is 32 or greater. Use different processing.

5559
LD DE,6445H 11 45 64
Load Register DE with 6445H - address of a routine or data location for this processing path.
555C
PUSH DE D5
Push Register DE onto the stack, setting up another return address.
555D
Call RST 28H (ROM routine at 0028H) which typically handles BASIC statement dispatch. The routine will return to the address on the stack (6445H).

555EH - NOP Padding Area (Reserved Space)

From 555EH through 56E7H is filled with NOP (No Operation) instructions. This reserved space of approximately 394 bytes allows for future expansion or modifications without requiring relocation of code that follows. The NOP padding creates a memory boundary and simplifies version updates.

555E-56E7
NOP (x394) 00 00 00...
394 bytes of NOP instructions providing reserved expansion space. NOPs execute quickly and allow future code patches without relocating subsequent addresses.