TRS-80 DOS - NEWDOS/80 v2.0 for the Model I - DISASSEM/CMD Disassembled

Page Customization

DISASSEM/CMD - NEWDOS/80 v2.0 Disassembler

Program Overview

APPARAT DISASSEMBLER 3.0 is a Z80 disassembler utility for the TRS-80 Model I running NEWDOS/80 v2.0. This program converts machine code (either from memory or disk files) into human-readable Z80 assembly language listings. It was developed by Apparat, Inc., the creators of NEWDOS/80.

Features

  • Disassembles Z80 machine code from main memory or disk files
  • Supports virtual address mapping (allows code to be disassembled as if loaded at a different address)
  • Handles all Z80 instruction prefixes (CB, DD, ED, FD)
  • Generates formatted output with addresses, hex bytes, mnemonics, and operands
  • Supports printer output with form-feed prompts
  • Identifies program entry points

Memory Layout

Address RangeSizeDescription
55E4H - 5613H48 bytesVariables and work area
5614H - 681BH4,616 bytesProgram code (entry point at 5614H)
681CH - 6927H268 bytesZ80 mnemonic lookup tables
6928H - 6B1BH500 bytesUser prompts and message strings
6B1CH - 6E18H765 bytesAdditional code and output routines
6E19H - 6E7BH99 bytesUninitialized buffer area
6F60H - 6FA0H+VariableStack and runtime buffers

Program Flow

  1. Initialization (5614H): Set up stack, display title, initialize variables
  2. Source Selection: Prompt user for memory or disk input
  3. Address Configuration: Get virtual base, real base, byte count, and offset values
  4. Disassembly Loop: Fetch bytes, decode opcodes, format output
  5. Output Generation: Display/print formatted assembly listing

Technical Notes

The disassembler uses a sophisticated table-driven approach for opcode decoding. Z80 instructions are organized by their prefix bytes:

  • Unprefixed: Main instruction set (00-FF)
  • CB prefix: Bit manipulation instructions
  • DD prefix: IX register operations
  • ED prefix: Extended instructions
  • FD prefix: IY register operations
  • DDCB/FDCB: Indexed bit operations

DOS Interface

The program interfaces with NEWDOS/80 through several system calls:

  • 4411H: HIGH$ memory pointer - used to determine available memory
  • File I/O routines for loading object files from disk
  • Console and printer output routines

Variable and Memory Map

Work Area (55E4H - 5613H)

The program maintains its state in a 48-byte work area at the beginning of the code. These variables are initialized to zero at load time and configured during program startup.

AddressSizeNameDescription
55E4H1SOURCE_TYPESource selection flag: 'M' for memory, 'D' for disk
55E5H-55E6H2VIRTUAL_ADDRCurrent virtual address being disassembled
55E7H-55E8H2REAL_ADDRCurrent real address in source data
55E9H-55EAH2WORK_ADDRWorking address pointer
55EBH-55ECH2END_ADDREnd address for disassembly range
55EDH-55EEH2RESERVED_1Reserved/unused
55EFH1FLAGSOperation flags and mode settings
55F0H1INIT_FLAGInitialization status flag
55F1H1BIT_FLAGSBit flags for tracking processed addresses
55F2H-55F3H2HIGH_MEMHigh memory limit (from DOS 4411H)
55F4H-55F5H2BUFFER_PTRCurrent buffer pointer
55F6H-55F7H2IY_SAVEIY register save area
55F8H1TEMP_BYTETemporary byte storage
55F9H-55FAH2TEMP_WORD_1Temporary word storage
55FBH-55FCH2TEMP_WORD_2Temporary word storage
55FDH-55FEH2RESERVED_2Reserved/unused
55FFH-5600H2OFFSET_VALAddress offset value
5601H1OUTPUT_FLAGOutput mode flag
5602H1STATUS_FLAGStatus/state flag
5603H1RESERVED_3Reserved/unused
5604H1CONFIG_1Configuration byte 1 (preset to 3CH)
5605H1CONFIG_2Configuration byte 2
5606H-5608H3CONFIG_3Configuration bytes (preset to 40H each)
5609H-560AH2WORK_PTRWorking pointer
560BH-560CH2BYTE_COUNTByte count for disassembly (FFFFH = until end)
560DH1OPCODE_LENCurrent opcode length counter
560EH1RESERVED_4Reserved/unused
560FH1PREFIX_FLAGInstruction prefix flag (CB/DD/ED/FD)
5610H1INDEX_REGIndex register indicator (IX/IY)
5611H1DISPLACEMENTIndex displacement byte
5612H1RESERVED_5Reserved (contains 20H 80H as data)
5613H1OUTPUT_MODEOutput mode (80H = screen)

Self Modifying Code

  • 5AAAH: Output buffer pointer (LD HL,nnnn)
  • 599DH: Transfer address storage
  • 5F2EH: Label buffer pointer
  • 6187H: Stack pointer save for restart
  • 618BH: Stack pointer save for state restoration

Variable Usage Patterns

Analysis of the code reveals the following variable access patterns:

  • 55EFH (FLAGS): Most frequently accessed - read 12+ times, written 4 times. Controls program operation mode.
  • 55E5H-55E7H (addresses): Heavily used for tracking disassembly position.
  • 560BH (BYTE_COUNT): Initialized to FFFFH for "disassemble all" mode, or set to specific count.
  • 560DH-5611H: Used during opcode decoding for prefix and index handling.

Major Routines

Subroutine Index

The following table lists the major subroutines identified in APPARAT DISASSEMBLER 3.0, organized by function.

Initialization and Main Flow

AddressNameDescription
5614HENTRY_POINTProgram entry - initializes stack, displays title, begins main flow
5748HSETUP_OUTPUTConfigure output mode and parameters
5765HINIT_CHECKCheck initialization status
579AHMAIN_SETUPMain setup routine, configure flags
57B7HDISK_MODEHandle disk file input mode

Input and Parsing

AddressNameDescription
5B08HGET_RESPONSEGet single character response from user (M/D selection)
5B22HGET_HEX_ADDRPrompt for and parse hexadecimal address input
5B29HGET_HEX_OPTGet optional hexadecimal value (allows empty input)
5B7DHPARSE_FILESPECParse file specification for disk input
58BAHINPUT_HANDLERGeneral input handling routine (8 calls)

Disassembly Engine

AddressNameDescription
5CFAHDISASM_MAINMain disassembly dispatch
5CFDHDISASM_LOOPMain disassembly loop
5CC5HFETCH_BYTEFetch next byte from source (8 calls)
5EA9HDECODE_OPCODEDecode opcode and determine instruction type (8 calls)
5E63HHANDLE_PREFIXHandle instruction prefix bytes (CB/DD/ED/FD)
6592HPROCESS_INSTRProcess decoded instruction (8 calls)

Output Formatting

AddressNameDescription
674EHOUTPUT_LINEPrimary output routine - formats and displays line (19 calls)
673BHOUTPUT_STRINGOutput null-terminated string (10 calls)
67CEHOUTPUT_CHAROutput single character (10 calls)
6789HOUTPUT_HEXOutput value in hexadecimal (6 calls)
66A0HFORMAT_ADDRFormat address for display (5 calls)
66C1HFORMAT_LINEFormat complete output line
67F5HNEWLINEOutput newline/carriage return

String and Display

AddressNameDescription
5D17HPRINT_STRINGPrint string pointed to by DE (7 calls)
5D1AHPRINT_STRING_CONTString print continuation entry (6 calls)
5D2DHCLEAR_SCREENClear screen/initialize display
5D47HPRINT_PROMPTPrint prompt and get input (5 calls)

Mnemonic Lookup

AddressNameDescription
655CHLOOKUP_MNEMONICLook up instruction mnemonic from opcode (4 calls)
669BHGET_REG_NAMEGet register name string (4 calls)
668BHGET_OPERANDFormat operand for display (3 calls)

Utility Routines

AddressNameDescription
5AA8HHEX_TO_BINConvert hex ASCII to binary (4 calls)
5ABEHBIN_TO_HEXConvert binary to hex ASCII (3 calls)
5A6EHCOMPARE_HL_DECompare HL and DE registers (3 calls)
5F02HADD_OFFSETAdd offset to address (3 calls)
5F4DHCHECK_RANGECheck if address in valid range (3 calls)
67CBHOUTPUT_SPACEOutput space character (5 calls)

Error Handling

AddressNameDescription
5F47HMEM_ERRORMemory error handler (insufficient memory)
6A52HBAD_REPLY_MSG"BAD REPLY" error message location

Call Frequency Analysis

The most frequently called routines indicate the program's core functionality:

  1. 674EH (19 calls): Primary output - called for every line of disassembly
  2. 673BH, 67CEH (10 calls each): String and character output - fundamental display operations
  3. 5CC5H, 5EA9H, 6592H, 58BAH (8 calls each): Core disassembly engine routines
  4. 5D17H (7 calls): String printing for prompts and messages

Subroutine Map

The following diagram shows the approximate memory layout of major subroutines:

5614H ─────────────┬─── Entry Point & Initialization
                   │
5748H-57B6H ───────┼─── Setup routines
                   │
58BAH-5B07H ───────┼─── Input handling & parsing
                   │
5B08H-5C87H ───────┼─── User input routines
                   │
5CC5H-5CFDH ───────┼─── Disassembly engine core
                   │
5D17H-5E52H ───────┼─── String/display routines
                   │
5EA9H-5F92H ───────┼─── Opcode decoding
                   │
6065H-618AH ───────┼─── Extended processing
                   │
6592H-6639H ───────┼─── Instruction processing
                   │
66A0H-6788H ───────┼─── Output formatting
                   │
6789H-681BH ───────┼─── Output helpers
                   │
681CH-6927H ───────┼─── Mnemonic tables (DATA)
                   │
6928H-6B1BH ───────┴─── Message strings (DATA)

Disassembly:

55E4H - Variable and Work Area

This region (55E4H-5613H) contains runtime variables and configuration bytes used throughout the disassembler. These locations are initialized to 00H at load time and populated during program execution. The variables track source mode (memory vs disk), virtual/real addresses, byte counts, output state, and various operational flags.

Variable Storage Area - These are NOT executable instructions. The disassembler interprets them as NOPs (00H bytes) but they serve as runtime storage locations.

55E4
DEFB 00H 00
Source Mode Flag - 00H = Memory mode, non-zero = Disk mode. Set at 5671H after user selects 'M' or 'D' in response to source prompt.
55E5
DEFW 0000H 00 00
Object Virtual Base Address - The virtual (logical) base address of the object being disassembled. User enters this in response to "OBJECT VIRTUAL BASE ADDRESS?" prompt. Stored at 5682H.
55E7
DEFW 0000H 00 00
Object Real Base Address - The actual memory location where the object code resides. If user presses ENTER at the "OBJECT REAL BASE ADDRESS?" prompt, this defaults to the virtual address. Updated at 5690H and 5796H.
55E9
DEFW 0000H 00 00
Reserved/Work Area - Used during address calculations.
55EB
DEFW 0000H 00 00
Current Disassembly Address - Tracks the current address being disassembled. Referenced throughout the main disassembly loop.
55ED
DEFW 0000H 00 00
Work Variable - Temporary storage for address calculations.
55EF
DEFB 00H 00
Mode/Option Flags - Bit flags controlling output options: Bit 0 = printer output enabled, Bit 1 = show byte count, Bit 5 = show entry point markers. Initialized to 04H at 5679H for memory mode.
55F0
DEFB 00H 00
Printer State Flag - Controls printer output state. Bit 7 set indicates printer active. Initialized to 00H at 5627H.
55F1
DEFB 00H 00
Entry Point Bitmap - Bit field tracking which entry points (0-7) have been displayed. Used for showing "= PROGRAM ENTRY POINT" markers.
55F2
DEFW 0000H 00 00
High Memory Limit - Upper boundary for buffer allocation. Calculated from DOS HIGH$ pointer (4411H) minus 6 bytes. Stored at 5644H.
55F4
DEFW 0000H 00 00
Buffer Pointer - Current position in the label/reference buffer. Updated as labels are recorded during disassembly. Stored at 5651H.
55F6
DEFW 0000H 00 00
Work Variable - Temporary storage.
55F8
DEFB 00H 00
Current Instruction Type - Tracks the type of instruction being processed for label generation.
55F9
DEFW 0000H 00 00
Address Offset - Offset value for adjusting virtual addresses. User enters this in response to "OFFSET OBJECT VIRTUAL ADDRESSES BY?" prompt (disk mode). Stored at 57CEH.
55FB
DEFW 0000H 00 00
Disk File Position - Current read position within the disk file being disassembled. Used in disk mode to track progress through the file.
55FD
DEFW 0000H 00 00
Work Variable - Temporary storage for calculations.
55FF
DEFW 0000H 00 00
End Address (Disk Mode) - The ending address for disk-based disassembly.
5601
DEFB 00H 00
Line Counter - Counts lines of output for page formatting. Initialized to 10H (16 decimal) at 5752H. Decremented at 573AH; when zero, triggers page break handling.
5602
DEFB 00H 00
Output State Flags - Bit 0 = header printed, Bit 6 = printer output active. Initialized to 00H at 562AH.
5603
DEFB 00H 00
Current Column Position - Tracks horizontal position on output line for formatting.
5604
DEFB 3CH 3C
Screen Width - Number of columns for screen display. Default 3CH = 60 columns (for 64-column display with margins).
5605
DEFB 00H 00
Current Output Width - Active width setting (screen or printer). Copied from 5606H or 5607H/5608H depending on output mode.
5606
DEFB 40H 40
Active Line Width - Current maximum line width. Default 40H = 64 columns.
5607
DEFB 40H 40
Screen Line Width - Width setting for screen output. Default 40H = 64 columns.
5608
DEFB 40H 40
Printer Line Width - Width setting for printer output. Default 40H = 64 columns. Can be changed by user.
5609
DEFB 00H 00
Reserved - Unused, initialized to 00H.
560A
DEFB 00H 00
Reserved - Unused, initialized to 00H.
560B
DEFW 0000H 00 00
Byte Count - Number of bytes to disassemble. User enters this in response to "BYTE COUNT?" prompt. Initialized to FFFFH at 5623H (meaning "until end"). Updated at 56ADH.
560D
DEFB 00H 00
Current Opcode Byte - Holds the current instruction byte being decoded. Referenced by opcode lookup routines.
560E
DEFB 00H 00
Reserved - Unused.
560F
DEFB 00H 00
Index Register Mode - Tracks IX/IY prefix state: 00H = no prefix, 01H = DD prefix (IX), 02H = FD prefix (IY). Set by prefix detection code.
5610
DEFB 00H 00
Saved Index Mode - Preserves index register mode across nested operations.
5611
DEFB 00H 00
Reserved - Unused.
5612
DEFB 20H 20
Page Line Counter - Counts lines remaining on current page for form feed handling. Value 20H = 32 lines. Referenced at 5ECDH.
5613
DEFB 80H 80
Initialization Flag - Set to 80H at 562FH during initialization. Bit 7 indicates first-run state for header printing.

5614H - Program Entry Point and Initialization

This is the main entry point of APPARAT DISASSEMBLER 3.0. The initialization sequence sets up the stack, clears the screen, displays the program title, initializes all working variables, calculates buffer space from available memory, and prompts the user to select memory or disk mode for disassembly.

Program entry point - execution begins here when the program is loaded and run.

5614
LD SP,6F60H 31 60 6F
Initialize the stack pointer to 6F60H. This establishes the program's stack area just below the buffer workspace. The stack grows downward from this address.
5617
Call the clear screen routine. This sends control code 1CH (clear screen) followed by 1FH (home cursor) to prepare the display for output.
561A
LD DE,6992H 11 92 69
Load DE with pointer to the program title string "APPARAT DISASSEMBLER 3.0" located at 6992H. This string is null-terminated.
561D
Call the display string routine. This outputs the null-terminated string pointed to by DE to the screen, followed by a carriage return.
5620
LD HL,FFFFH 21 FF FF
Load HL with FFFFH (-1 or 65535). This value represents "no limit" for the byte count - disassemble until manually stopped or end of data.
5623
LD (560BH),HL 22 0B 56
Store FFFFH to the byte count variable at 560BH. This initializes the default behavior to disassemble without a byte limit.
5626
XOR A AF
Clear register A to 00H. This value will be used to initialize several flag variables to their default (off) state.
5627
LD (55F0H),A 32 F0 55
Initialize the printer state flag at 55F0H to 00H. Printer output is disabled by default.
562A
LD (5602H),A 32 02 56
Initialize the output state flags at 5602H to 00H. Clears the header-printed flag and printer-active bit.
562D
LD A,80H 3E 80
Load A with 80H. Bit 7 set indicates this is the first initialization - header has not yet been printed.
562F
LD (5613H),A 32 13 56
Store 80H to the initialization flag at 5613H. This flag is checked to determine if the program header needs to be displayed.

Copy default ORG template - Initialize the address display format string from ROM defaults.

5632
LD HL,698DH 21 8D 69
Load HL with source address 698DH. This points to the default ORG format template containing format control bytes.
5635
LD DE,6987H 11 87 69
Load DE with destination address 6987H. This is the working copy of the ORG format template that gets modified during operation.
5638
LD BC,0005H 01 05 00
Load BC with byte count 5. The ORG format template is 5 bytes long.
563B
LDIR ED B0
Block copy 5 bytes from 698DH to 6987H. This initializes the working ORG template from the default values.

Calculate available buffer space from DOS HIGH$ pointer.

563D
LD HL,(4411H) 2A 11 44
Load HL from DOS location 4411H. This is the HIGH$ pointer - the highest usable memory address as reported by NEWDOS/80.
5640
LD DE,FFFAH 11 FA FF
Load DE with FFFAH (-6 in two's complement). This provides a 6-byte safety margin below HIGH$.
5643
ADD HL,DE 19
Add DE to HL, effectively subtracting 6 from HIGH$. Result is the upper limit for buffer allocation.
5644
LD (55F2H),HL 22 F2 55
Store the calculated upper limit to the high memory limit variable at 55F2H. Buffers must not exceed this address.

Initialize the label buffer chain with sentinel markers.

5647
LD DE,6FA0H 11 A0 6F
Load DE with 6FA0H. This is the start of the label buffer area, located above the stack.
564A
LD A,C0H 3E C0
Load A with C0H. This is a sentinel marker byte used to mark the beginning and end of the label buffer chain.
564C
LD (DE),A 12
Store the sentinel marker C0H at address 6FA0H. This marks the start of the label chain.
564D
INC DE 13
Increment DE to 6FA1H. Move to the next buffer position.
564E
INC DE 13
Increment DE to 6FA2H. Skip past the address field (2 bytes).
564F
INC DE 13
Increment DE to 6FA3H. This is where the end sentinel will be placed.
5650
LD (DE),A 12
Store the sentinel marker C0H at 6FA3H. This marks the current end of the label chain.
5651
LD (55F4H),DE ED 53 F4 55
Store DE (6FA3H) to the buffer pointer variable at 55F4H. This tracks where new labels will be added.

Verify sufficient memory is available for operation.

5655
OR A B7
Clear the carry flag by ORing A with itself. Prepares for the 16-bit subtraction that follows.
5656
SBC HL,DE ED 52
Subtract DE (current buffer end 6FA3H) from HL (high memory limit). If result is negative (carry set), there is insufficient memory.
5658
If carry is set (not enough memory), jump to the memory error handler at 5F47H. This displays an error and exits.

Initialize the buffer chain pointer table at 6F60H.

565B
DEC DE 1B
Decrement DE to 6FA2H. Adjust pointer back to the address field of the first buffer entry.
565C
DEC DE 1B
Decrement DE to 6FA1H. Now points to the low byte of the address field.
565D
LD HL,6F60H 21 60 6F
Load HL with 6F60H. This is the buffer chain index table located at the stack base. It contains 16 two-byte pointers.
5660
LD (HL),E 73
Store low byte of buffer pointer (A1H) to current index table position. [LOOP START] - Initialize all 16 index entries.
5661
INC HL 23
Increment HL to next byte in index table.
5662
LD (HL),D 72
Store high byte of buffer pointer (6FH) to index table.
5663
INC HL 23
Increment HL to next index entry.
5664
INC HL 23
Increment HL again (each entry is 2 bytes, but we only store to alternating bytes in this initialization).
5665
INC HL 23
Increment HL to align to next 4-byte boundary.
5666
LD A,L 7D
Load A with low byte of HL. Used to check if we've initialized all 16 entries (table ends at 6FA0H).
5667
CP A0H FE A0
Compare A with A0H. When L reaches A0H, we've filled all 16 index entries and reached the buffer area.
5669
If not at A0H yet, loop back to 5660H to initialize the next index entry. [LOOP END]

Prompt user to select memory or disk source mode.

566B
Load DE with pointer to the prompt string "OBJECT FROM MAIN MEMORY OR DISK? (M OR D)" at 69ACH.
566E
Call the prompt and single-key input routine. Displays the prompt and waits for user to press a key. Returns with A = key pressed, Z flag set if 'M' (memory), NZ if 'D' (disk).
5671
LD (55E4H),A 32 E4 55
Store the user's response to the source mode flag at 55E4H. 00H = memory mode, non-zero = disk mode.
5674
If user selected 'D' (disk mode, NZ flag set), jump to the disk mode initialization at 57B7H.

5677H - Memory Mode Initialization

This section handles initialization when the user selects memory mode ('M'). It sets up the mode flags, prompts for virtual and real base addresses, optionally prompts for byte count, and then proceeds to display the ORG directive and begin disassembly.

Set memory mode flags and prompt for base addresses.

5677
LD A,04H 3E 04
Load A with 04H. This sets bit 2 of the mode flags, indicating memory mode with default options.
5679
LD (55EFH),A 32 EF 55
Store 04H to the mode/option flags at 55EFH. In memory mode, bit 2 is set, bits 0-1 are clear.
567C
LD DE,69D8H 11 D8 69
Load DE with pointer to the prompt "OBJECT VIRTUAL BASE ADDRESS? (HEX)" at 69D8H.
567F
Call the hex address input routine. Displays prompt, accepts hex input, returns 16-bit value in HL.
5682
LD (55E5H),HL 22 E5 55
Store the entered address to the object virtual base address at 55E5H.
5685
LD (55E7H),HL 22 E7 55
Also store it to the object real base address at 55E7H as the default value.
5688
Load DE with pointer to the prompt "OBJECT REAL BASE ADDRESS? (HEX)" at 69FCH.
568B
Call the optional hex input routine. If user just presses ENTER, Z flag is set and HL is unchanged. Otherwise returns new address in HL.
568E
JR Z,5693H 28 03
If Z flag set (user pressed ENTER without input), skip storing - keep the default value already in 55E7H.
5690
LD (55E7H),HL 22 E7 55
Store the user-entered real base address to 55E7H, overriding the virtual address default.
5693
Call the additional options routine. This may prompt for printer settings, output width, etc.

Check mode flags to determine if byte count prompt is needed.

5696
LD BC,(55EFH) ED 4B EF 55
Load BC with the mode/option flags from 55EFH. B contains the high byte, C contains the low byte of flags.
569A
LD DE,6D21H 11 21 6D
Load DE with address 6D21H. This is a work buffer address used during output formatting.
569D
LD A,C 79
Load A with the low byte of mode flags from C.
569E
AND 38HAND 00111000 E6 38
Mask with 38H (bits 3-5). These bits indicate special modes that affect processing.
56A0
If any of bits 3-5 are set, jump to 5CFAH to handle the special mode initialization.
56A3
BIT 1,B CB 48
Test bit 1 of B (high byte of flags). This bit indicates whether to prompt for byte count.
56A5
JR Z,56B0H 28 09
If bit 1 is clear, skip the byte count prompt and jump to 56B0H.
56A7
LD DE,6A1DH 11 1D 6A
Load DE with pointer to the prompt "BYTE COUNT? (HEX)" at 6A1DH.
56AA
Call the hex input routine to get the byte count from the user.
56AD
LD (560BH),HL 22 0B 56
Store the entered byte count to the byte count variable at 560BH.
56B0
Call the output header routine. This displays the ORG directive and column headers if configured.
56B3
Call the page setup routine. Initializes line counter and page formatting.
56B6
Jump to the main disassembly loop entry point at 5CFDH to begin disassembling code.

56B9H - Main Disassembly Loop Entry Point Check

This is the main loop that processes each instruction. It first checks for entry point markers to display, then fetches and disassembles the next instruction, handles output formatting, and checks for user keyboard input to pause, print, or exit. Control returns here after each instruction is processed.

[MAIN LOOP] - Entry point marker detection and display logic.

56B9
LD A,(55EFH) 3A EF 55
Load A with the mode/option flags from 55EFH. Check which output options are enabled.
56BC
AND 21HAND 00100001 E6 21
Mask with 21H (bits 0 and 5). Bit 0 = printer mode, Bit 5 = show entry point markers.
56BE
CP 20H FE 20
Compare with 20H. If exactly 20H (entry points enabled, printer off), we need to check for entry point display.
56C0
If not showing entry points on screen, skip to 56F8H to continue with normal disassembly flow.

Entry point detection - check if current address matches any of the 8 possible entry points.

56C2
LD HL,(55E5H) 2A E5 55
Load HL with the virtual base address. Entry points are relative to this base.
56C5
LD DE,(55EBH) ED 5B EB 55
Load DE with the current disassembly address.
56C9
OR A B7
Clear carry flag for subtraction.
56CA
SBC HL,DE ED 52
Subtract current address from base. Result is negative offset indicating how far past base we are.
56CC
LD C,08H 0E 08
Load C with 08H. This is the entry point bit mask starting at bit 3 (checking entry points 0-7).
56CE
LD B,L 45
Load B with L (low byte of offset). Used as entry point number (0-7) to check.
56CF
LD HL,55F1H 21 F1 55
Load HL with address of the entry point bitmap at 55F1H.
56D2
INC DE 13
Increment DE (current address counter). [LOOP] - Scan through entry points.
56D3
DEC B 05
Decrement B (entry point counter). Check if this entry point matches current position.
56D4
SRL C CB 39
Shift C right, moving the bit mask to check the next entry point.
56D6
If C becomes zero (checked all 8 entry points), jump to 56F8H - no entry point at this address.
56D8
LD A,(HL) 7E
Load A with the entry point bitmap byte from 55F1H.
56D9
AND C A1
AND with current bit mask. Tests if this entry point has already been displayed.
56DA
If bit is clear (not displayed yet or not an entry point), continue loop to check next entry point.

Found an entry point to display - mark it as shown and output the marker.

56DC
LD A,(HL) 7E
Load the entry point bitmap again.
56DD
XOR C A9
XOR with bit mask to clear the bit - marks this entry point as displayed.
56DE
LD (HL),A 77
Store updated bitmap back to 55F1H.
56DF
LD A,B 78
Load A with B (entry point number 0-7).
56E0
ADD A,30H C6 30
Add 30H to convert to ASCII digit ('0'-'7'). Entry point 0 becomes '0', entry point 1 becomes '1', etc.
56E2
LD (6970H),A 32 70 69
Store the ASCII digit into the entry point message template at 6970H. The template reads "0000 = PROGRAM ENTRY POINT".
56E5
LD A,03H 3E 03
Load A with 03H. This is the output line count for the entry point marker display.
56E7
LD HL,6966H 21 66 69
Load HL with 6966H. This points to the entry point display format string.
56EA
PUSH HL E5
Save HL (format string pointer) for later use.
56EB
Call the format output routine. Prepares the entry point marker for display.
56EE
Call the output buffer flush routine. Displays the formatted entry point marker.
56F1
POP HL E1
Restore HL (format string pointer).
56F2
Call the line termination routine. Outputs carriage return and handles line counting.
56F5
Jump to 5755H to check for keyboard input and continue the main loop.

56F8H - Byte Count Check and Instruction Fetch

This section checks if there are more bytes to disassemble (based on byte count limit), handles the differences between memory and disk modes, and calls the main disassembly routine to process the next instruction.

Check if byte count has been exhausted.

56F8
LD HL,(560BH) 2A 0B 56
Load HL with the remaining byte count from 560BH.
56FB
LD A,H 7C
Load A with high byte of byte count.
56FC
OR L B5
OR with low byte. If HL is 0000H, Z flag will be set.
56FD
RET Z C8
If byte count is zero, return - disassembly is complete. Returns to caller (DOS or restart routine).

Check source mode and handle disk-specific end conditions.

56FE
LD A,(55E4H) 3A E4 55
Load A with the source mode flag. 00H = memory mode, non-zero = disk mode.
5701
OR A B7
Test if A is zero (memory mode).
5702
If memory mode (Z set), skip disk-specific checks and jump to 570FH.

Disk mode: check if we've reached the end address.

5704
LD HL,(55E7H) 2A E7 55
Load HL with the current real address in disk mode.
5707
LD DE,(55FFH) ED 5B FF 55
Load DE with the end address for disk mode from 55FFH.
570B
OR A B7
Clear carry for subtraction.
570C
SBC HL,DE ED 52
Subtract end address from current address. If current ≥ end, no carry (NC).
570E
RET NC D0
If no carry (current address ≥ end address), return - disk file disassembly is complete.

Disassemble the next instruction.

570F
Call the main instruction disassembly routine at 60EDH. This fetches the opcode, decodes it, looks up the mnemonic, and formats the output.

Check if entry point markers need to be displayed after this instruction.

5712
LD A,(55EFH) 3A EF 55
Load A with mode/option flags.
5715
AND 21HAND 00100001 E6 21
Mask with 21H (bits 0 and 5).
5717
CP 20H FE 20
Check if entry point display is enabled (bit 5 set, bit 0 clear).
5719
If entry point display enabled, call 5A5BH to check and display entry point marker if at an entry point address.

Handle screen output vs printer output.

571C
LD A,(55EFH) 3A EF 55
Load A with mode/option flags again.
571F
AND 01HAND 00000001 E6 01
Mask with 01H to isolate bit 0 (printer mode flag).
5721
If printer mode is active, skip screen formatting and jump to keyboard check at 5755H.

Screen output: format and display the disassembled line.

5723
LD HL,55E4H 21 E4 55
Load HL with 55E4H. Points to end of the output line buffer (buffer is at 55A4H-55E3H).
5726
LD B,40H 06 40
Load B with 40H (64). Maximum characters to scan for trailing spaces.
5728
DEC HL 2B
Decrement HL to previous character. [LOOP] - Trim trailing spaces from output line.
5729
LD A,(HL) 7E
Load A with character at current position.
572A
CP 20H FE 20
Compare with SPACE (20H).
572C
If not a space, found end of actual content - exit loop.
572E
Decrement B and loop back if not zero. Continue trimming spaces. [LOOP END]
5730
INC B 04
If all 64 characters were spaces, increment B to 1 (output at least one character).
5731
LD DE,55A4H 11 A4 55
Load DE with start of output buffer at 55A4H.
5734
Call the display buffer routine. Outputs B characters starting at DE to the screen.

Handle page breaks and line counting.

5737
LD HL,5601H 21 01 56
Load HL with address of line counter at 5601H.
573A
DEC (HL) 35
Decrement the line counter. When it reaches zero, a page break is needed.
573B
If line counter is now zero, jump to 5742H to handle page break.
573D
Call the output newline routine. Outputs a carriage return to move to next line.
5740
Jump to keyboard check at 5755H.
5742
Call the page break handler at 5765H. Waits for user input if printer is active.
5745
Call newline routine after page break handling.

5748H - Page Setup and Line Counter Reset

This routine resets the line counter for a new page and optionally clears the screen. It is called at initialization and after each page break.

5748
LD A,(55EFH) 3A EF 55
Load A with mode/option flags.
574B
AND 01HAND 00000001 E6 01
Mask with 01H to test printer mode bit.
574D
If not in printer mode (screen output), call clear screen routine at 5D2DH.
5750
LD A,10H 3E 10
Load A with 10H (16 decimal). This is the number of lines per screen page.
5752
LD (5601H),A 32 01 56
Store 16 to the line counter at 5601H. Screen will pause after 16 lines.

5755H - Keyboard Check and Command Processing

This routine checks for keyboard input during disassembly. It handles commands: X to exit, P to toggle printer, and any other key to pause/continue. Control then returns to the main loop.

5755
Call the keyboard scan routine at 5CE0H. Returns key in A if pressed, or continues if no key.
5758
CP 58H FE 58
Compare with 58H (X). This is the exit command.
575A
If X pressed, jump to the exit routine at 5CF2H to terminate disassembly.
575D
CP 50H FE 50
Compare with 50H (P). This is the printer toggle command.
575F
If P pressed, call the printer toggle routine at 576BH.
5762
Jump back to 56B9H to continue the main disassembly loop.

5765H - Printer Page Break Handler

This routine handles page breaks when printer output is active. It checks if the printer is enabled and if so, waits for user input to continue, allowing paper alignment between pages.

5765
LD A,(55F0H) 3A F0 55
Load A with the printer state flag from 55F0H.
5768
AND 80HAND 10000000 E6 80
Mask with 80H to test bit 7 (printer active flag).
576A
RET Z C8
If printer not active (bit 7 clear), return - no page break handling needed.

576BH - Printer Control and Virtual Restart

This routine handles printer toggling and the virtual restart feature. When P is pressed, it prompts for printer commands. When V is pressed, it allows changing the virtual restart location to continue disassembly from a different address.

576B
Call the get key with wait routine at 5CD2H. Waits for user to press a key.
576E
CP 0DH FE 0D
Compare with 0DH (ENTER). ENTER continues without changes.
5770
RET Z C8
If ENTER pressed, return - continue disassembly normally.
5771
CP 58H FE 58
Compare with 58H (X) for exit.
5773
If X pressed, jump to exit routine.
5776
CP 56H FE 56
Compare with 56H (V). This is the virtual restart command.
5778
If not V, loop back to 576BH to wait for a valid command.

Handle virtual restart - only available in memory mode.

577B
LD A,(55E4H) 3A E4 55
Load A with source mode flag. Check if in memory mode.
577E
OR A B7
Test if zero (memory mode).
577F
If disk mode (non-zero), virtual restart not available - loop back for another command.
5781
Load DE with pointer to prompt "VIRTUAL RESTART LOCATION? (HEX)" at 6A30H.
5784
Call hex input routine to get new virtual address from user.
5787
LD DE,(55E5H) ED 5B E5 55
Load DE with current virtual base address.
578B
LD (55E5H),HL 22 E5 55
Store new virtual address to 55E5H (update virtual base).
578E
OR A B7
Clear carry for subtraction.
578F
SBC HL,DE ED 52
Calculate offset: new_virtual - old_virtual. This is how much to adjust the real address.
5791
EX DE,HL EB
Move offset to DE.
5792
LD HL,(55E7H) 2A E7 55
Load HL with current real base address.
5795
ADD HL,DE 19
Add offset to real address. New_real = old_real + (new_virtual - old_virtual).
5796
LD (55E7H),HL 22 E7 55
Store updated real address to 55E7H.
5799
RET C9
Return to caller. Disassembly will continue from the new location.

579AH - Output Header Display

This routine displays the ORG directive and optional column headers at the start of disassembly output. It checks mode flags to determine what header information to show.

579A
LD BC,(55EFH) ED 4B EF 55
Load BC with mode/option flags. B = high byte, C = low byte.
579E
Load DE with 6DC1H. This points to the ORG directive output buffer.
57A1
LD A,C 79
Load A with low byte of flags.
57A2
AND 01HAND 00000001 E6 01
Test bit 0 (printer mode).
57A4
If printer mode, jump to display the header string and return.
57A7
BIT 0,B CB 40
Test bit 0 of B (high byte). This indicates if ORG display is suppressed.
57A9
JR NZ,57ADH 20 02
If bit set, skip setting the initialization flag.
57AB
SET 7,B CB F8
Set bit 7 of B to indicate header has been displayed.
57AD
LD (55EFH),BC ED 43 EF 55
Store updated flags back to 55EFH.
57B1
BIT 1,B CB 48
Test bit 1 of B. This indicates if byte count display is enabled.
57B3
If bit 1 set, call 5DC6H to display byte count information.
57B6
RET C9
Return to caller.

57B7H - Disk Mode Initialization

This section handles initialization when the user selects disk mode ('D'). It prompts for the filespec, opens the file through NEWDOS/80 DOS calls, reads file header information to determine load addresses, and sets up for disk-based disassembly.

Prompt for filename and copy to FCB area.

57B7
Load DE with pointer to the prompt "FILESPEC?" at 6A88H.
57BA
Call the filename input routine. Displays prompt and accepts filename from user.
57BD
LD DE,5500H 11 00 55
Load DE with 5500H. This is the File Control Block (FCB) area for DOS operations.
57C0
LD BC,001FH 01 1F 00
Load BC with 001FH (31 decimal). This is the size of the filename/FCB data to copy.
57C3
LDIR ED B0
Block copy 31 bytes from input buffer to FCB area at 5500H.
57C5
LD A,0DH 3E 0D
Load A with 0DH (carriage return). This terminates the filespec string.
57C7
LD (DE),A 12
Store CR at end of the FCB filename to properly terminate it for DOS.

Prompt for address offset value.

57C8
Load DE with pointer to prompt "OFFSET OBJECT VIRTUAL ADDRESSES BY? (HEX)" at 6A5CH.
57CB
Call optional hex input routine. Returns offset value in HL, or 0 if user just pressed ENTER.
57CE
LD (55F9H),HL 22 F9 55
Store the address offset value to 55F9H.
57D1
Call routine at 5ADAH to validate and process the offset.

Set disk mode flags and open file.

57D4
LD A,01H 3E 01
Load A with 01H. Set mode flags for disk operation with printer output.
57D6
LD (55EFH),A 32 EF 55
Store 01H to mode/option flags. Bit 0 set = printer mode enabled for disk output.
57D9
LD C,01H 0E 01
Load C with 01H. File access mode: read-only.
57DB
LD A,41H 3E 41
Load A with 41H. DOS function code for @OPEN (open existing file).
57DD
Call the DOS function wrapper. Opens the file specified in the FCB at 5500H.
57E0
Call additional options routine for output configuration.

Initialize file position and read first record.

57E3
LD HL,0001H 21 01 00
Load HL with 0001H. Initialize file position to byte 1 (after header byte).
57E6
LD (55FBH),HL 22 FB 55
Store initial file position to 55FBH.
57E9
XOR A AF
Clear A to 00H.
57EA
LD (55F1H),A 32 F1 55
Clear the entry point bitmap at 55F1H.
57ED
Call output header display routine to show ORG directive.

Set up DOS read parameters and read first sector.

57F0
LD HL,5300H 21 00 53
Load HL with 5300H. This is the sector read buffer address.
57F3
LD DE,5500H 11 00 55
Load DE with 5500H. Points to the FCB for the DOS read call.
57F6
LD B,00H 06 00
Load B with 00H. Record number 0 = read next sequential record.
57F8
CALL 4424H CD 24 44
Call DOS @READ routine at 4424H. Reads a 256-byte sector into buffer at 5300H.
57FB
If the DOS @READ call returned non-zero (NZ = error), jump to the DOS error handler at 5CE6H. This displays the error and exits gracefully.
57FE
LD DE,5200H 11 00 52
Load DE with 5200H. This is the working buffer address where object code bytes will be assembled for disassembly. Sector data at 5300H is parsed and copied here.

5801H - Disk Mode /CMD File Header Parsing

This section continues disk mode initialization by parsing the /CMD file header. TRS-80 /CMD files have a specific format with load blocks, each containing a type byte, length, load address, and data. This routine parses the header to determine where the code should be loaded and sets up the virtual addresses accordingly.

5801
LD (55E7H),DE ED 53 E7 55
Store 5200H to real base address. This is the working buffer where disk data is processed.
5805
LD B,01H 06 01
Load B with 01H. Flag to read from sector buffer at 5300H on first call.
5807
Call get next byte from file. Returns byte in A.
580A
CP 01H FE 01
Compare with 01H. Type 01 = object code block (load data).
580C
If not type 01, jump to 590EH to handle other block types (02=transfer, etc.).
580F
Call get next byte - this is the block length byte.
5812
LD C,A 4F
Store block length in C.
5813
Call get 16-bit address. Returns load address in HL.
5816
PUSH DE D5
Save DE (current buffer position).
5817
LD DE,(55FBH) ED 5B FB 55
Load DE with file position counter.
581B
Call compare HL to DE. Sets Z if equal.
581E
If at start of desired block, skip to data copy.
5820
ADD HL,DE 19
Add file position to load address for absolute address.
5821
PUSH HL E5
Save calculated address.
5822
Call initialize label buffer for this block.
5825
POP DE D1
Restore calculated address to DE.
5826
LD (55E5H),DE ED 53 E5 55
Store as virtual base address.

Check if entry point display is enabled and show ORG if so.

582A
LD A,(55EFH) 3A EF 55
Load mode/option flags.
582D
AND 21HAND 00100001 E6 21
Mask bits 0 and 5.
582F
CP 20H FE 20
Check if entry point display enabled.
5831
If not, skip ORG display.
5833
PUSH DE D5
Save virtual address.
5834
PUSH BC C5
Save block length.
5835
LD HL,6977H 21 77 69
Load HL with ORG format buffer address.
5838
Call format address as hex. Converts DE to ASCII hex in buffer.
583B
LD DE,6972H 11 72 69
Load DE with ORG output string address.
583E
Call display string routine to show ORG directive.
5841
POP BC C1
Restore block length.
5842
POP DE D1
Restore virtual address.

5843H - Calculate Next File Position

Calculates the next file position after the current block and updates the file position counter.

5843
LD L,C 69
Load L with C (block length). Start calculating end position.
5844
LD H,00H 26 00
Clear H. HL now contains block length as 16-bit value.
5846
ADD HL,DE 19
Add current position to length = end position.
5847
LD A,C 79
Load A with block length.
5848
OR A B7
Test if length is zero.
5849
If not zero, skip increment.
584B
INC H 24
If length was 0, means 256 bytes - increment H.
584C
POP DE D1
Restore original buffer position.
584D
LD (55FBH),HL 22 FB 55
Store new file position.
5850
Jump to buffer boundary check.

5852H - Block Data Read Loop

Main loop for reading data bytes from the /CMD file block. Reads bytes sequentially and stores them in the working buffer, checking for sector boundaries.

5852
DEC C 0D
Decrement C (remaining bytes in block). [LOOP START]
5853
If block finished (C=0), go read next block header.
5855
LD HL,AD00H 21 00 AD
Load HL with AD00H. This is a boundary check value.
5858
ADD HL,DE 19
Add current buffer position. Checks if near end of buffer.
5859
If no carry (not at boundary), continue reading bytes.

Buffer boundary reached - need to process and refill.

585B
PUSH BC C5
Save remaining byte count.
585C
LD DE,5200H 11 00 52
Load DE with working buffer start.
585F
LD HL,(55E7H) 2A E7 55
Load HL with current real address.
5862
Compare buffer position to start.
5865
If not at start, skip page setup.

At buffer start - set up for new page of disassembly.

5867
LD HL,52FCH 21 FC 52
Load HL with 52FCH - end of buffer marker.
586A
LD (55FFH),HL 22 FF 55
Store as end address for this buffer.
586D
Call page setup - clear screen/reset line counter.
5870
PUSH HL E5
Save HL.
5871
PUSH DE D5
Save DE.
5872
Call printer page break handler.
5875
POP DE D1
Restore DE.
5876
POP HL E1
Restore HL.
5877
ADD HL,DE 19
Calculate new position.
5878
EX DE,HL EB
Swap - DE now has new position.
5879
LD HL,5300H 21 00 53
Load HL with sector buffer address.
587C
Compare to calculate bytes to copy.
587F
LD C,L 4D
Load C with low byte of difference (bytes to copy).
5880
LD B,00H 06 00
Clear B. BC = bytes to copy.
5882
LD HL,5200H 21 00 52
Load HL with working buffer start.
5885
LD (55E7H),HL 22 E7 55
Reset real address to buffer start.
5888
EX DE,HL EB
Swap for LDIR source/dest.
5889
If no bytes to copy, skip LDIR.
588B
LDIR ED B0
Block copy remaining bytes to working buffer.
588D
POP BC C1
Restore remaining byte count.

588EH - Read and Store Data Byte

Reads the next byte from the file and stores it in the working buffer, checking for end-of-block conditions.

588E
Call get next byte from file.
5891
LD HL,(55E9H) 2A E9 55
Load HL with remaining count variable.
5894
LD (DE),A 12
Store byte to working buffer.
5895
INC DE 13
Increment buffer pointer.
5896
LD A,H 7C
Load A with high byte of remaining count.
5897
OR L B5
OR with low byte. Z if count is zero.
5898
If count zero, loop back for next byte.

Check mode flags for printer output status.

589A
LD A,(55EFH) 3A EF 55
Load mode flags.
589D
AND 01HAND 00000001 E6 01
Test printer mode bit.
589F
If printer mode, just loop back.

Screen mode - track position relative to virtual address.

58A1
PUSH DE D5
Save buffer pointer.
58A2
LD DE,(55E5H) ED 5B E5 55
Load virtual address.
58A6
Compare current position to virtual address.
58A9
If at target address, store remaining count.
58AB
INC DE 13
Increment virtual address.
58AC
LD (55E5H),DE ED 53 E5 55
Update virtual address.
58B0
POP DE D1
Restore buffer pointer.
58B1
DEC DE 1B
Decrement buffer pointer (compensate for earlier INC).
58B2
Loop back to continue reading. [LOOP END]
58B4
LD (55E9H),HL 22 E9 55
Store remaining count.
58B7
POP DE D1
Restore buffer pointer.
58B8
Loop back.

58BAH - Get Next Byte From File

Reads the next sequential byte from the disk file. Handles sector boundaries by reading new sectors as needed. Returns byte in A register.

58BA
PUSH DE D5
Save DE (caller's buffer pointer).
58BB
LD DE,(55FDH) ED 5B FD 55
Load DE with sector buffer pointer (current read position in sector).
58BF
Decrement B; if not zero, skip sector read. B=1 means read new sector.

B was 1, need to read next sector from disk.

58C1
LD DE,5500H 11 00 55
Load DE with FCB address.
58C4
CALL 4436H CD 36 44
Call DOS @RREAD at 4436H. Reads next 256-byte sector to buffer at 5300H.
58C7
If read error, jump to error handler.
58CA
LD DE,5300H 11 00 53
Reset DE to sector buffer start.
58CD
LD A,(DE) 1A
Load A with byte at current sector buffer position.
58CE
INC DE 13
Increment sector buffer pointer.
58CF
LD (55FDH),DE ED 53 FD 55
Store updated sector buffer pointer.
58D3
POP DE D1
Restore caller's buffer pointer.
58D4
RET C9
Return with byte in A.

58D5H - Initialize Label Buffer

Initializes the label tracking buffer for a new code block. The label buffer tracks addresses that are referenced as jump/call targets so they can be marked with labels in the output.

58D5
LD HL,6FA1H 21 A1 6F
Load HL with 6FA1H - start of label buffer data area (after sentinel).
58D8
LD (55F6H),HL 22 F6 55
Store to label buffer pointer at 55F6H.
58DB
LD DE,(55E5H) ED 5B E5 55
Load DE with virtual base address.
58DF
LD HL,(55FBH) 2A FB 55
Load HL with file position.
58E2
DEC HL 2B
Decrement file position for comparison.
58E3
Call compare routine.
58E6
RET Z C8
If equal, return - nothing to initialize.
58E7
INC HL 23
Restore file position.
58E8
Call another compare.
58EB
RET Z C8
If equal, return.
58EC
LD (560BH),HL 22 0B 56
Store to byte count variable.
58EF
LD HL,FFFFH 21 FF FF
Load HL with FFFFH (no limit).
58F2
LD (55FFH),HL 22 FF 55
Store to end address.
58F5
PUSH BC C5
Save BC.
58F6
Call page setup.
58F9
LD HL,FFFFH 21 FF FF
Reload FFFFH.
58FC
LD (560BH),HL 22 0B 56
Reset byte count to no limit.
58FF
Call printer page break handler.
5902
LD C,03H 0E 03
Load C with 3 - number of blank lines.
5904
LD A,(55F0H) 3A F0 55
Load printer state flag.
5907
AND 02HAND 00000010 E6 02
Test bit 1.
5909
If set, call output blank lines.
590C
POP BC C1
Restore BC.
590D
RET C9
Return.

590EH - Handle Non-Data Block Types

Handles /CMD file block types other than 01 (object code). Type 02 is the transfer address (entry point), other types are skipped. This is critical for properly parsing TRS-80 executable files.

590E
CP 02H FE 02
Compare A with 02H. Type 02 = transfer address block (program entry point).
5910
If type 02, jump to handle transfer address.

Not type 01 or 02 - skip this block entirely.

5912
Get next byte - this is block length.
5915
LD C,A 4F
Store length in C.
5916
[LOOP] Get next byte from block.
5919
DEC C 0D
Decrement remaining count.
591A
If more bytes, loop back. [LOOP END]
591C
Jump back to read next block header.

591FH - Process Transfer Address (Entry Point)

Handles the type 02 transfer address block. This contains the program entry point - the address where execution begins when the program is run. The disassembler displays this and optionally records it for label generation.

591F
Call initialize label buffer.
5922
Get next byte (length, typically 02).
5925
Call get 16-bit address. Returns transfer address in HL.
5928
LD (599DH),HL 22 9D 59
Store transfer address to 599DH (self-modifying code location for later reference).
592B
EX DE,HL EB
Exchange DE and HL. Transfer address now in DE.
592C
LD A,(55EFH) 3A EF 55
Load mode/option flags.
592F
AND 21HAND 00100001 E6 21
Mask bits 0 and 5 (printer mode and entry point display).
5931
CP 21H FE 21
Check if both printer AND entry point display enabled.
5933
If not both, skip label buffer update.

Both printer and entry point enabled - add to label buffer.

5935
Call search label buffer for this address.
5938
If already exists (Z), skip adding.
593A
LD A,03H 3E 03
Load A with 03H - entry size for label buffer.
593C
Call allocate label buffer entry.
593F
LD (HL),D 72
Store high byte of address.
5940
INC HL 23
Increment buffer pointer.
5941
LD (HL),E 73
Store low byte of address.
5942
INC HL 23
Increment buffer pointer.
5943
LD (HL),40H 36 40
Store 40H - entry point marker flag.

5945H - Display Entry Point Message

Displays the "0000 = PROGRAM ENTRY POINT" message with the actual address filled in. Then branches based on output mode.

5945
Load HL with 6A93H - pointer to "0000 = PROGRAM ENTRY POINT" template.
5948
Call format address into template. Fills in the "0000" with actual address.
594B
Call clear screen.
594E
LD A,(55EFH) 3A EF 55
Load mode flags.
5951
AND 01HAND 00000001 E6 01
Test printer mode bit.
5953
If printer mode, jump to printer-specific handling.

Screen mode - display entry point message.

5956
LD DE,6A93H 11 93 6A
Load DE with entry point message.
5959
Call display string routine.
595C
LD A,(55EFH) 3A EF 55
Load mode flags again.
595F
AND 20HAND 00100000 E6 20
Test bit 5 (entry point labels enabled).
5961
If disabled, jump to close file.

5963H - Generate EQU Statements for Labels

Scans the label buffer and outputs EQU statements for each recorded address. This creates symbolic labels for all jump/call targets found during disassembly.

5963
LD HL,6FA0H 21 A0 6F
Load HL with label buffer start.
5966
LD BC,(5FC1H) ED 4B C1 5F
Load BC with label counter from 5FC1H.
596A
DEC BC 0B
Decrement label counter (adjust for 1-based indexing).
596B
INC HL 23
[LOOP] Move to next buffer entry.
596C
LD D,(HL) 56
Load high byte of address into D.
596D
INC HL 23
Increment pointer.
596E
LD E,(HL) 5E
Load low byte of address into E. DE = label address.
596F
INC HL 23
Increment pointer to flags byte.
5970
BIT 7,(HL) CB 7E
Test bit 7 - end of buffer marker.
5972
If end marker, jump to finalize output.
5974
BIT 6,(HL) CB 76
Test bit 6 - label was referenced.
5976
If not referenced, skip - loop to next entry.
5978
INC BC 03
Increment label counter.
5979
BIT 5,(HL) CB 6E
Test bit 5 - already output.
597B
If already output, skip to next.

Output EQU statement for this label.

597D
PUSH HL E5
Save buffer pointer.
597E
PUSH BC C5
Save label counter.
597F
PUSH DE D5
Save label address.
5980
LD H,B 60
Copy BC to HL for label number.
5981
LD L,C 69
HL = label number.
5982
LD DE,6957H 11 57 69
Load DE with EQU output buffer.
5985
Call format label number. Creates "Lnnnn" label name.
5988
LD HL,695FH 21 5F 69
Load HL with EQU template address field.
598B
POP DE D1
Restore label address to DE.
598C
Call format address as hex.
598F
LD DE,6957H 11 57 69
Load DE with complete EQU line.
5992
Call output string.
5995
POP BC C1
Restore label counter.
5996
POP HL E1
Restore buffer pointer.
5997
Loop back for next label. [LOOP END]

5999H - Finalize Output and Write END Statement

Outputs the END statement with the transfer address and closes the output file.

5999
LD HL,6983H 21 83 69
Load HL with END template buffer address.
599C
LD DE,0000H 11 00 00
Load DE with 0000H (placeholder - gets modified). Self-modifying: 599DH holds actual transfer address.
599F
LD A,01H 3E 01
Load A with 01H - format type.
59A1
Call format END line.
59A4
LD DE,697EH 11 7E 69
Load DE with END output string.
59A7
Call output string.
59AA
LD A,1AH 3E 1A
Load A with 1AH (Ctrl-Z) - end-of-file marker.
59AC
Call output character.
59AF
LD A,(5AAAH) 3A AA 5A
Load A from 5AAAH (file write position).
59B2
SUB 00H D6 00
Subtract 00H (placeholder for adjustment).
59B4
LD (5537H),A 32 37 55
Store to FCB end-of-file marker.
59B7
LD (553AH),A 32 3A 55
Store to FCB backup position.
59BA
If not zero, call flush write buffer.
59BD
LD DE,5532H 11 32 55
Load DE with output FCB address.
59C0
CALL 4428H CD 28 44
Call DOS @CLOSE at 4428H.
59C3
If error, jump to error handler.
59C6
Jump to final cleanup routine.

59C9H - Printer Mode File Handling

Handles file output when in printer mode. Closes the input file and processes additional options.

59C9
LD DE,5500H 11 00 55
Load DE with input FCB address.
59CC
CALL 4428H CD 28 44
Call DOS @CLOSE.
59CF
If error, jump to handler.
59D2
Call clear screen.
59D5
LD A,(55EFH) 3A EF 55
Load mode flags.
59D8
AND 10HAND 00010000 E6 10
Test bit 4 - output file enabled.
59DA
If not enabled, skip file output.

Output file processing for label data.

59DC
LD DE,6C77H 11 77 6C
Load DE with output filename buffer.
59DF
Call filename setup routine.
59E2
Call prepare output buffer.
59E5
LD (IX+00H),L DD 75 00
[LOOP] Store low byte to IX+0.
59E8
INC BC 03
Increment counter.
59E9
LD (IX+00H),H DD 74 00
Store high byte to IX+0.
59EC
INC B 04
Increment B.
59ED
LD DE,5532H 11 32 55
Load DE with output FCB.
59F0
CALL 443CH CD 3C 44
Call DOS @WRITE at 443CH.
59F3
If error, jump to handler.
59F6
LD DE,0100H 11 00 01
Load DE with 256 (sector size).
59F9
ADD HL,DE 19
Add sector size to position.
59FA
If overflow (carry), done with buffer.
59FC
EX DE,HL EB
Exchange for comparison.
59FD
LD HL,(55F4H) 2A F4 55
Load buffer end pointer.
5A00
OR A B7
Clear carry.
5A01
SBC HL,DE ED 52
Compare position to buffer end.
5A03
EX DE,HL EB
Restore registers.
5A04
If not done, loop back. [LOOP END]
5A04
LD DE,5532H 11 32 55
Load output FCB address.
5A07
CALL 4428H CD 28 44
Call DOS @CLOSE.
5A0A
If error, jump to handler.

5A0DH - Toggle Mode and Continue

Toggles mode flags and either continues with more processing or returns to disk file reading.

5A0D
LD HL,55EFH 21 EF 55
Load HL with mode flags address.
5A10
LD A,(HL) 7E
Load current flags.
5A11
XOR 03H EE 03
Toggle bits 0 and 1.
5A13
LD (HL),A 77
Store updated flags.
5A14
BIT 3,A CB 5F
Test bit 3.
5A16
If set, jump to cleanup.
5A19
Call reset buffer routine.
5A1C
LD A,(55EFH) 3A EF 55
Reload mode flags.
5A1F
AND 20HAND 00100000 E6 20
Test bit 5 (entry point labels).
5A21
If not set, skip output file setup.
5A23
LD DE,6C98H 11 98 6C
Load DE with filename buffer.
5A26
Call filename setup.
5A29
LD (5AAAH),HL 22 AA 5A
Store result to 5AAAH.
5A2C
Jump back to disk read loop.

5A2FH - Output File Setup

Sets up an output file by prompting for a filename, copying it to the FCB area, and opening the file for writing.

5A2F
Call filename input routine. Prompts user and reads filename.
5A32
LD DE,5532H 11 32 55
Load DE with output FCB address at 5532H.
5A35
LD BC,001FH 01 1F 00
Load BC with 31 - bytes to copy for filespec.
5A38
PUSH DE D5
Save FCB address.
5A39
LDIR ED B0
Block copy filename to FCB.
5A3B
LD A,0DH 3E 0D
Load A with CR (0DH) - string terminator.
5A3D
LD (DE),A 12
Store CR at end of filename.
5A3E
POP DE D1
Restore FCB address.
5A3F
LD HL,5400H 21 00 54
Load HL with 5400H - output buffer address.
5A42
CALL 4420H CD 20 44
Call DOS @INIT at 4420H. Creates/opens file for writing.
5A45
RET Z C8
If success (Z), return.
5A46
If error, jump to error handler.

5A49H - Get 16-Bit Address From File

Reads two bytes from the file and combines them into a 16-bit address in HL. Adds the user-specified offset to support relocated code.

5A49
Call get next byte. Returns low byte of address in A.
5A4C
LD L,A 6F
Store low byte in L.
5A4D
DEC C 0D
Decrement block byte counter.
5A4E
Call get next byte. Returns high byte of address in A.
5A51
LD H,A 67
Store high byte in H. HL now contains raw address.
5A52
DEC C 0D
Decrement block byte counter.
5A53
PUSH DE D5
Save DE.
5A54
LD DE,(55F9H) ED 5B F9 55
Load DE with address offset from 55F9H.
5A58
ADD HL,DE 19
Add offset to raw address. HL = adjusted address.
5A59
POP DE D1
Restore DE.
5A5A
RET C9
Return with 16-bit address in HL.

5A5BH - Output Entry Point Line

Outputs a formatted line showing an entry point, including the ORG prefix, address columns, and a carriage return.

5A5B
Call output ORG prefix. Outputs line number and formatting.
5A5E
LD HL,55B5H 21 B5 55
Load HL with 55B5H - points to formatted output buffer (middle of line).
5A61
Call output 8 chars with tab. Outputs first address column.
5A64
Call again for second address column.
5A67
Call output until space. Outputs mnemonic/operand.
5A6A
LD A,0DH 3E 0D
Load A with CR (carriage return).
5A6C
Jump to output character and return.

5A6EH - Output ORG Line Prefix

Outputs the ORG line number prefix. Increments a 5-digit BCD counter and outputs the formatted line number followed by the ORG template.

5A6E
LD HL,698BH 21 8B 69
Load HL with 698BH - points to line number counter (5 BCD digits).
5A71
LD B,05H 06 05
Load B with 5 - number of digits to process.
5A73
INC (HL) 34
[LOOP] Increment current digit.
5A74
LD A,(HL) 7E
Load the digit value.
5A75
CP 0BAH FE BA
Compare with BAH (ASCII ':' = one past '9').
5A77
If less than BAH (valid digit), jump to output.
5A79
LD (HL),0B0H 36 B0
Reset digit to B0H (ASCII '0') - carry to next digit.
5A7B
DEC HL 2B
Move to next higher digit.
5A7C
Loop for next digit. [LOOP END]

Line counter overflow - too many lines.

5A7E
Load DE with overflow error message.
5A81
Jump to error exit.

Output the ORG template string.

5A84
LD HL,6987H 21 87 69
Load HL with 6987H - ORG template (line number + "ORG").
5A87
LD B,06H 06 06
Load B with 6 - characters to output.
5A89
LD A,(HL) 7E
[LOOP] Load character from template.
5A8A
INC HL 23
Increment template pointer.
5A8B
Call output character.
5A8E
Loop for all 6 characters. [LOOP END]
5A90
RET C9
Return.

5A91H - Output 8 Characters With Tab

Outputs up to 8 characters from the buffer, skipping trailing spaces, followed by a tab character for column alignment.

5A91
LD B,08H 06 08
Load B with 8 - max characters per column.
5A93
Call output until space.
5A96
INC HL 23
[LOOP] Skip remaining characters in column.
5A97
Loop until 8 chars processed. [LOOP END]
5A99
LD A,09H 3E 09
Load A with 09H - tab character.
5A9B
Jump to output character and return.

5A9DH - Output Characters Until Space

Outputs characters from the buffer until a space is encountered or the count (B) is exhausted.

5A9D
LD A,(HL) 7E
[LOOP] Load character from buffer.
5A9E
CP 20H FE 20
Compare with SPACE (20H).
5AA0
RET Z C8
If space, return - stop output.
5AA1
INC HL 23
Increment buffer pointer.
5AA2
Call output character.
5AA5
Decrement B and loop if not zero. [LOOP END]
5AA7
RET C9
Return.

5AA8H - Output Buffer Character Storage

This routine stores a single character from Register A into the output buffer. The buffer pointer at 5AAAH is self-modifying code - the LD HL,0000H instruction has its address operand updated to point to the current buffer position. When the low byte of the pointer wraps to 00H (buffer page full), the buffer is flushed to disk by calling the sector write routine at 5AD0H.

5AA8
PUSH HL E5
Preserve HL register pair on the stack.
5AA9
LD HL,0000H 21 00 00
Load HL with the current buffer pointer. Note: This is self-modifying code - the address 0000H is patched at runtime by the instruction at 5AB9H to hold the actual buffer position.
5AAC
LD (HL),A 77
Store the character from Register A into the buffer at the current position.
5AAD
INC HL 23
Advance the buffer pointer to the next position.
5AAE
LD A,L 7D
Load the low byte of the pointer into Register A to check for page boundary.
5AAF
CP 00H FE 00
Compare low byte against 00H. If L wrapped from FFH to 00H, we've filled a 256-byte page.
5AB1
If the NZ flag is set (low byte not zero, buffer page not full), skip the flush and jump to save the pointer.

Buffer page is full (256 bytes written). Flush buffer to disk.

5AB3
PUSH DE D5
Preserve DE register pair before the disk write operation.
5AB4
Call the sector write routine to flush the 256-byte buffer to disk.
5AB7
DEC H 25
Decrement H to move the pointer back to the start of the buffer page just written (since INC HL at 5AADH moved it to the next page).
5AB8
POP DE D1
Restore DE register pair.
5AB9
LD (5AAAH),HL 22 AA 5A
Store the updated buffer pointer back into the self-modifying code at 5AAAH. This patches the operand of the LD HL,nnnn instruction.
5ABC
POP HL E1
Restore the original HL register pair.
5ABD
RET C9
Return to caller. The character has been stored in the buffer.

5ABEH - Output Line with ORG Prefix

This routine outputs a complete source line to the buffer. It first stores a carriage return (0DH) at the current position, calls the ORG prefix output routine at 5A6EH, then copies characters from the line buffer pointed to by HL until a carriage return is encountered.

5ABE
LD (HL),0DH 36 0D
Store a carriage return (0DH) at the memory location pointed to by HL. This terminates any previous content.
5AC0
PUSH DE D5
Preserve DE register pair on the stack.
5AC1
Call the ORG prefix output routine to emit the address prefix for this line.
5AC4
POP HL E1
Pop the preserved value into HL. This sets up HL to point to the line content to output (was in DE).

[LOOP START] - Output characters from the line buffer until carriage return.

5AC5
LD A,(HL) 7E
Load the next character from the line buffer into Register A.
5AC6
Call the output buffer routine to store the character.
5AC9
LD A,(HL) 7E
Reload the character from the buffer (needed after the call which may have modified A).
5ACA
CP 0DH FE 0D
Compare against carriage return (0DH) to check for end of line.
5ACC
INC HL 23
Advance pointer to the next character in the line buffer.
5ACD
If not a carriage return (NZ flag set), [LOOP] back to output the next character.
5ACF
RET C9
Return to caller. The complete line has been output to the buffer.

5AD0H - Write Sector to Output File

This routine writes a sector (256 bytes) to the output file using the DOS @WRITE function. The FCB at 5532H is used for the file operation. If a write error occurs, execution jumps to the error handler at 5CE6H.

5AD0
LD DE,5532H 11 32 55
Load DE with the address of the output file FCB at 5532H.
5AD3
Call DOS @WRITE function to write a sector to the output file.
5AD6
RET Z C8
If the Z flag is set (no error), return to caller.
5AD7
On error, jump to the DOS error handler which displays the error message and prompts for restart.

5ADAH - Get Virtual Restart Location

Prompts the user for the "VIRTUAL RESTART LOCATION" using the message at 6A30H, then parses the hex input and stores the result in the work variable at 55E9H.

5ADA
LD DE,6A30H 11 30 6A
Load DE with the address of the prompt string "VIRTUAL RESTART LOCATION? (HEX)" at 6A30H.
5ADD
Call the hex input with prompt routine to display the message and get a hex value from the user.
5AE0
LD (55E9H),HL 22 E9 55
Store the parsed 16-bit hex value into the work variable at 55E9H.
5AE3
RET C9
Return to caller with the restart location stored.

5AE4H - Prompt for Yes/No (Default Yes)

Displays the prompt at DE and waits for a Yes/No response. ENTER defaults to Yes. Returns with Z flag set and A=0 if No, NZ flag set and A=1 if Yes.

5AE4
Call the display prompt and get key routine. Returns with the pressed key in Register A.
5AE7
If Z flag is set (ENTER was pressed), jump to the return handler with default Yes.
5AE9
Otherwise, jump to the "BAD REPLY" error handler (invalid key was pressed).

5AEBH - Prompt for Yes/No (Default No)

Displays the prompt at DE and waits for a Yes/No response. ENTER defaults to No. Returns with Z flag set and A=0 if No, NZ flag set and A=1 if Yes.

5AEB
Call the display prompt and get key routine.
5AEE
If NZ flag is set (a key other than ENTER), jump to process it. Otherwise default to No.
5AF0
Jump to the "BAD REPLY" handler (default No triggers re-prompt).

5AF2H - Prompt for Y/N Response

Displays the prompt at DE and waits for an explicit Y or N response. Returns with C=1 and NZ if Yes, C=0 and Z if No. Used for critical yes/no questions where a default is not appropriate.

5AF2
Call the display prompt and get key routine.
5AF5
If Z flag is set (ENTER pressed), jump to return with current C value (may be 0).
5AF7
CP 4EH FE 4E
Compare the key against N (4EH).
5AF9
If Z flag is set (user pressed N), jump to handle No response.
5AFB
CP 59H FE 59
Compare the key against Y (59H).
5AFD
If NZ flag is set (not Y), jump to "BAD REPLY" handler.
5AFF
INC C 0C
Increment C to 1 to indicate Yes response.
5B00
DEC B 05
Decrement B (the parameter count from the input routine).
5B01
If NZ flag is set (extra characters after Y or N), jump to "BAD REPLY".

Valid response received - clean up and return result.

5B03
POP DE D1
Pop the return address adjustment (discard pushed DE from 5CC5H).
5B04
POP AF F1
Pop the flags/A register from the calling routine.
5B05
LD A,C 79
Load A with the result from C (0=No, 1=Yes).
5B06
OR A B7
Set flags based on A. Z flag set if No, NZ flag set if Yes.
5B07
RET C9
Return to caller with result in A and flags.

5B08H - Prompt for M/D (Memory or Disk)

Displays the prompt at DE and waits for M (Memory) or D (Disk) response. Returns with C=1 and NZ if Memory, C=0 and Z if Disk. ENTER defaults to Memory.

5B08
Call the display prompt and get key routine.
5B0B
LD C,01H 0E 01
Pre-load C with 01H as default (Memory mode).
5B0D
If Z flag is set (ENTER pressed), jump to return with default Memory.
5B0F
CP 44H FE 44
Compare the key against D (44H) for Disk mode.
5B11
If Z flag is set (user pressed D), jump to handle Disk selection (C will be decremented to 0).
5B13
DEC C 0D
Decrement C from 1 to 0 in preparation for Memory check.
5B14
CP 4DH FE 4D
Compare the key against M (4DH) for Memory mode.
5B16
If Z flag is set (user pressed M), jump to handle Memory selection.

Invalid key - display "BAD REPLY" and re-prompt.

5B18
LD DE,6A52H 11 52 6A
Load DE with the address of the "BAD REPLY" error message at 6A52H.
5B1B
Call the display string with CR routine to show the error message.
5B1E
POP DE D1
Pop the original prompt address back into DE.
5B1F
Jump back to display prompt and get key routine to re-prompt the user.

5B22H - Get Hex Input with Prompt (No Default)

Displays the prompt at DE and waits for hex input. Does not accept ENTER alone as a valid response - some input is required.

5B22
Call the display prompt and get key routine.
5B25
If NZ flag is set (user entered something), jump to the hex parsing code.
5B27
If just ENTER, jump to "BAD REPLY" handler.

5B29H - Get Hex Input with Prompt (Allow Default)

Displays the prompt at DE and parses a 16-bit hexadecimal value from user input. Returns the parsed value in HL. If ENTER is pressed alone, returns with HL=0000H and Z flag set.

5B29
Call the display prompt and get key routine. Returns input buffer pointer in DE and character count in B.
5B2C
EX DE,HL EB
Exchange DE and HL. Now HL points to the input buffer.
5B2D
LD HL,0000H 21 00 00
Initialize HL to 0000H as the accumulator for the hex value.
5B30
If Z flag is set (no input), jump to return with HL=0000H.

[LOOP START] - Parse each hex digit from the input buffer.

5B32
LD A,H 7C
Load the high byte of the accumulator into A.
5B33
CP 10H FE 10
Compare against 10H. If H >= 10H, the value would overflow 16 bits on the next shift.
5B35
If NC flag is set (overflow would occur), jump to "BAD REPLY".
5B37
LD A,(DE) 1A
Load the next character from the input buffer into A.
5B38
SUB 30H D6 30
Subtract ASCII '0' (30H) to convert digit. Result: 0-9 for digits, 11H-16H for A-F.
5B3A
CP 0AH FE 0A
Compare against 0AH. If less than 0AH, it's a valid decimal digit (0-9).
5B3C
INC DE 13
Advance the input buffer pointer to the next character.
5B3D
If C flag is set (digit 0-9), jump to accumulate the value.
5B3F
SUB 11H D6 11
Subtract 11H more to adjust for hex letters. 'A' (41H-30H=11H) becomes 0, 'F' becomes 5.
5B41
CP 06H FE 06
Compare against 06H. If >= 6, it's not a valid hex letter A-F.
5B43
If NC flag is set (invalid character), jump to "BAD REPLY".
5B45
ADD A,0AH C6 0A
Add 0AH to convert 0-5 to 10-15 (A-F hex values).

Accumulate the hex digit into HL by shifting left 4 bits and adding.

5B47
ADD HL,HL 29
Shift HL left by 1 bit (multiply by 2).
5B48
ADD HL,HL 29
Shift HL left by 1 bit (now multiplied by 4).
5B49
ADD HL,HL 29
Shift HL left by 1 bit (now multiplied by 8).
5B4A
ADD HL,HL 29
Shift HL left by 1 bit (now multiplied by 16 - shifted left 4 bits total).
5B4B
ADD A,L 85
Add the new hex digit in A to the low byte of HL.
5B4C
LD L,A 6F
Store the result back into L.
5B4D
Decrement B (character count) and [LOOP] back if more characters remain.
5B4F
INC C 0C
Increment C to indicate valid input was parsed (C=1 means success).
5B50
Jump to the return handler to clean up stack and return.

5B52H - Get Decimal Input with Prompt

Displays the prompt string pointed to by DE and parses a 16-bit decimal value from user input. Returns the parsed value in HL. Does not accept ENTER alone - input is required. Uses a multiply-by-10 algorithm: HL = HL*4 + HL, then HL = HL*2 + digit.

5B52
Call the display prompt and get input routine. On return: DE = pointer to input buffer at 5564H, B = character count, Z flag set if empty input.
5B55
If Z flag is set (user pressed ENTER with no input), jump to "BAD REPLY" error handler at 5B18H.
5B57
EX DE,HL EB
Exchange DE and HL. Now HL holds the input buffer pointer (5564H), DE is free.
5B58
LD HL,0000H 21 00 00
Initialize HL to 0000H. This is the accumulator that will hold the parsed decimal value.

[LOOP START] - Parse each decimal digit, multiply accumulator by 10, and add the new digit.

5B5B
LD A,(DE) 1A
Load the next character from the input buffer (pointed to by DE) into Register A.
5B5C
SUB 30H D6 30
Subtract ASCII '0' (30H) to convert the character to a numeric value 0-9. Non-digits will result in values >= 10.
5B5E
CP 0AH FE 0A
Compare the result against 10 (0AH). If the value is >= 10, it's not a valid decimal digit.
5B60
INC DE 13
Advance the input buffer pointer (DE) to the next character position.
5B61
If NC flag is set (value >= 10, invalid digit), jump to "BAD REPLY" error handler.

Multiply HL by 10 and add the new digit. Algorithm: HL*10 = (HL*4 + HL)*2 = HL*8 + HL*2

5B63
PUSH BC C5
Preserve BC on stack. B holds the remaining character count, C holds the success flag (initially 0).
5B64
PUSH DE D5
Preserve DE on stack. DE holds the current input buffer pointer.
5B65
LD C,A 4F
Copy the digit value (0-9) from A into C for later addition.
5B66
LD B,00H 06 00
Clear B so BC now holds just the digit value (0-9) as a 16-bit number.
5B68
LD D,H 54
Copy H (high byte of accumulator) into D.
5B69
LD E,L 5D
Copy L (low byte of accumulator) into E. Now DE = original HL value.
5B6A
XOR A AF
Clear A to use as an overflow detector. Any carry during multiplication will accumulate here.
5B6B
ADD HL,HL 29
Shift HL left by 1 bit (multiply by 2). Now HL = original * 2.
5B6C
ADC A,A 8F
Rotate carry into A. If the shift overflowed, A will become non-zero.
5B6D
ADD HL,HL 29
Shift HL left by 1 bit again (multiply by 2). Now HL = original * 4.
5B6E
ADC A,A 8F
Rotate carry into A to track overflow.
5B6F
ADD HL,DE 19
Add original value (in DE) to HL. Now HL = original * 4 + original = original * 5.
5B70
POP DE D1
Restore DE from stack. DE again points to the input buffer.
5B71
ADC A,A 8F
Rotate carry from the ADD HL,DE into A.
5B72
ADD HL,HL 29
Shift HL left by 1 bit (multiply by 2). Now HL = original * 10.
5B73
ADC A,A 8F
Rotate carry into A.
5B74
ADD HL,BC 09
Add the new digit value (in BC, which is 0-9) to HL. Now HL = original * 10 + digit.
5B75
POP BC C1
Restore BC from stack. B = remaining character count, C = success flag.
5B76
ADC A,A 8F
Final carry check into A.
5B77
If NZ flag is set (A is non-zero, meaning overflow occurred), jump to "BAD REPLY". Value exceeded 16 bits.
5B79
Decrement B (character count) and [LOOP] back to 5B5BH if more characters remain to parse.
5B7B
All digits parsed successfully. Jump to 5B4FH which sets C=1 (success) and returns via 5B03H.

5B7DH - Command Line Option Parser Entry

Entry point for the command line option parser. Prompts for options using the input buffer at 6C69H, then matches user input against the option lookup table at 5C8EH. When a match is found, the associated handler routine is called. Empty input (just ENTER) signals end of options and jumps to finalization at 5C1DH.

5B7D
LD DE,6C69H 11 69 6C
Load DE with 6C69H, the address of the option input buffer. This buffer receives user-typed option names.
5B80
Call the display prompt and get input routine. Returns: DE = input buffer, B = character count, Z flag set if empty.
5B83
If Z flag is set (empty input, user pressed ENTER), jump to option finalization at 5C1DH to resolve flag conflicts and complete setup.
5B86
LD DE,5C8EH 11 8E 5C
Load DE with 5C8EH, the address of the option lookup table. This table contains option names, flag bytes, and handler addresses.

[OUTER LOOP START] - Try to match input against each option table entry.

5B89
PUSH HL E5
Preserve HL on stack. HL points to the start of user input in the buffer.
5B8A
PUSH BC C5
Preserve BC on stack. B = input character count, C = flags/result.

[INNER LOOP START] - Compare characters between input and current table entry.

5B8B
LD A,(DE) 1A
Load the current character from the option table entry into Register A.
5B8C
CP (HL) BE
Compare the table character against the user input character at (HL).
5B8D
INC DE 13
Advance DE to the next character in the option table.
5B8E
INC HL 23
Advance HL to the next character in the user input.
5B8F
If NZ flag is set (characters don't match), jump to 5B9AH to skip to the next table entry.
5B91
LD A,(DE) 1A
Load the next byte from the option table. This could be the terminator byte (with bit 7 set) or another character.
5B92
XOR 80H EE 80
Toggle bit 7 of A. If the original byte had bit 7 set (end marker), this clears it to reveal the option flag value.
5B94
LD C,A 4F
Store the result (option flag with bit 7 cleared) into C for the handler routine.
5B95
If P flag is set (bit 7 was set in original = end of option name found), jump to 5BAAH to execute the handler.
5B98
Decrement B (remaining input characters) and [LOOP] back to compare the next character if more remain.

Mismatch detected or need to skip to next table entry.

5B9A
LD A,(DE) 1A
Load the current byte from the option table into A.
5B9B
RLCA 07
Rotate A left through carry. This moves bit 7 into the carry flag to test for end marker.
5B9C
INC DE 13
Advance DE to the next byte in the option table.
5B9D
If NC flag is set (bit 7 was 0, not yet at end marker), [LOOP] to skip more characters in this entry.
5B9F
INC DE 13
Skip past the handler address low byte in the table.
5BA0
INC DE 13
Skip past the handler address high byte. DE now points to the next table entry.
5BA1
POP BC C1
Restore BC from stack. B = original input character count.
5BA2
POP HL E1
Restore HL from stack. HL = original input buffer pointer.
5BA3
LD A,(DE) 1A
Load the first byte of the next table entry into A.
5BA4
OR A B7
Test if A is 00H (end of table marker).
5BA5
If NZ flag is set (not end of table), [LOOP] back to try matching against this new entry.
5BA7
No match found in entire table. Jump to "BAD REPLY" error handler to display error and re-prompt.

5BAAH - Execute Option Handler

Called when an option name matches in the lookup table. Extracts the 16-bit handler address from the table entry and executes it via JP (HL). The handler address follows the option name and flag byte in the table.

5BAA
POP AF F1
Discard the saved BC from the stack (no longer needed after successful match).
5BAB
POP AF F1
Discard the saved HL from the stack (no longer needed).
5BAC
INC DE 13
Advance DE past the terminator/flag byte to point to the handler address in the table.
5BAD
EX DE,HL EB
Exchange DE and HL. Now HL points to the handler address in the table.
5BAE
LD A,(HL) 7E
Load the low byte of the handler address from the table into A.
5BAF
INC HL 23
Advance HL to point to the high byte of the handler address.
5BB0
LD H,(HL) 66
Load the high byte of the handler address into H.
5BB1
LD L,A 6F
Load the low byte (saved in A) into L. Now HL = complete handler address.
5BB2
JP (HL) E9
Jump to the option handler routine. Execution continues at the handler address.

5BB3H - Set Printer Mode Flag Handler

Option handler that sets a bit in the printer state flag byte at 55F0H. The bit mask to set is passed in Register C (from the option table). Used for printer-related options like PTR.

5BB3
LD HL,55F0H 21 F0 55
Load HL with 55F0H, the address of the printer state flag byte. Bit 7 of this byte indicates printer mode is active.
5BB6
Jump to the common flag-setting code at 5BBBH.

5BB8H - Set Mode Flag Handler

Option handler that sets a bit in the mode flags word at 55EFH. The bit mask to set is passed in Register C. Used for most options like NCR, NIP, RTD, STD, RE, RI, etc.

5BB8
LD HL,55EFH 21 EF 55
Load HL with 55EFH, the address of the mode flags byte. This byte contains option bits: bit 0=printer, bit 1=byte count, bit 2=memory mode, bit 3=complete, bit 4=output file, bit 5=entry labels.
5BBB
LD A,(HL) 7E
Load the current flag byte value from memory into A.
5BBC
OR C B1
OR the current flags with the bit mask in C to set the new option bit.
5BBD
LD (HL),A 77
Store the updated flag byte back to memory.
5BBE
Call the option continuation check routine at 5C88H to verify no extra characters follow the option name.
5BC1
Jump to 5B1EH to re-prompt for the next option. This restores DE and calls 5CC5H again.

5BC4H - Column Format Handler (FGN= Option)

Option handler for the FGN= (format/column) option. Processes a column identifier character and builds the output format template at 60E2H based on the column template at 60D7H. The template controls which columns appear in the disassembly output.

5BC4
DEC B 05
Decrement B (remaining input character count) since we've consumed the option name characters.
5BC5
Call the option continuation check. If B=0 (no more chars), returns. Otherwise verifies more input follows.
5BC8
LD A,(DE) 1A
Load the next character from input (the column identifier) into A. Could be 'A' for All, or a specific column letter.
5BC9
LD HL,5BC1H 21 C1 5B
Load HL with 5BC1H, the return address for after column processing completes.
5BCC
PUSH HL E5
Push the return address onto the stack. The RET at 5BF2H will return here.
5BCD
LD DE,60E2H 11 E2 60
Load DE with 60E2H, the address of the output format buffer. This buffer receives the customized column layout.
5BD0
LD HL,60D7H 21 D7 60
Load HL with 60D7H, the address of the column template. This contains the default column identifiers.
5BD3
LD B,0BH 06 0B
Set B to 11 (0BH), the number of column positions to process.

[LOOP START] - Process each column position in the template.

5BD5
CP 41H FE 41
Compare the column identifier in A against A (41H) for "All columns".
5BD7
If Z flag is set (user specified 'A' for all), jump to include this column in output.
5BD9
CP (HL) BE
Compare the user's column identifier against the template column identifier at (HL).
5BDA
If NZ flag is set (no match), jump to skip this column (leave as space).
5BDC
CP 20H FE 20
Compare against space (20H). Spaces in the template are separators, not selectable columns.
5BDE
If it's a space, skip this position (don't allow selecting space characters).
5BE0
PUSH AF F5
Preserve the column identifier in A on the stack.
5BE1
LD A,(HL) 7E
Load the template column character from (HL) into A.
5BE2
BIT 0,C CB 41
Test bit 0 of C (column enable flag from option table).
5BE4
If bit 0 is set (column enabled), keep the template character and jump to store it.
5BE6
LD A,20H 3E 20
Load A with space (20H) to blank out this column position in the output.
5BE8
LD (DE),A 12
Store the column character (or space) into the output format buffer at (DE).
5BE9
POP AF F1
Restore the user's column identifier from the stack.
5BEA
SET 1,C CB C9
Set bit 1 of C to indicate at least one column was processed/matched.
5BEC
INC HL 23
Advance HL to the next position in the column template.
5BED
INC DE 13
Advance DE to the next position in the output format buffer.
5BEE
Decrement B (column count) and [LOOP] back for the next column position.
5BF0
BIT 1,C CB 49
Test bit 1 of C to check if any column was successfully matched.
5BF2
RET NZ C0
If NZ flag is set (at least one column matched), return to 5BC1H (pushed earlier).
5BF3
POP AF F1
Discard the return address from the stack (won't return normally).
5BF4
No valid column matched. Jump to 5BA7H which goes to "BAD REPLY" error handler.

5BF6H - Parse Three-Letter Label Code

Parses a three-letter alphabetic code from user input and converts it to a unique numeric value using base-26 arithmetic. Used for custom label prefixes. The computed value is stored at 5FC1H. Each letter position is multiplied by 26 and added to create a unique index.

5BF6
LD HL,0000H 21 00 00
Initialize HL to 0000H. This is the accumulator for the base-26 calculation.
5BF9
LD C,03H 0E 03
Set C to 3, the letter count. We expect exactly 3 uppercase letters.

[LOOP START] - Parse each letter and compute base-26 value: result = result*26 + letter_index

5BFB
LD A,(DE) 1A
Load the next character from the input buffer (pointed to by DE) into A.
5BFC
SUB 41H D6 41
Subtract ASCII 'A' (41H) to convert letter to index 0-25. 'A'=0, 'B'=1, ..., 'Z'=25.
5BFE
CP 1AH FE 1A
Compare against 26 (1AH). If >= 26, it's not a valid uppercase letter A-Z.
5C00
INC DE 13
Advance DE to point to the next character in input.
5C01
If NC flag is set (value >= 26, invalid letter), jump to "BAD REPLY" via 5BA7H.

Multiply HL by 26 by adding HL to itself 25 times, then add the new letter index.

5C03
PUSH DE D5
Preserve DE (input buffer pointer) on the stack.
5C04
LD D,H 54
Copy H into D.
5C05
LD E,L 5D
Copy L into E. Now DE = original HL (accumulator value).
5C06
LD B,19H 06 19
Set B to 25 (19H) for the multiplication loop counter.
5C08
ADD HL,DE 19
Add original value (DE) to HL. After 25 iterations: HL = original * 26.
5C09
Decrement B and [LOOP] back until 25 additions complete.
5C0B
LD E,A 5F
Load the letter index (0-25) from A into E.
5C0C
LD D,00H 16 00
Clear D so DE = letter index as 16-bit value.
5C0E
ADD HL,DE 19
Add the letter index to HL. Now HL = (old_HL * 26) + letter_index.
5C0F
POP DE D1
Restore DE (input buffer pointer) from the stack.
5C10
DEC C 0D
Decrement C (remaining letter count).
5C11
If NZ flag is set (more letters to process), [LOOP] back for the next letter.
5C13
LD A,(DE) 1A
Load the character following the three letters from input.
5C14
CP 0DH FE 0D
Compare against carriage return (0DH). Input should end here.
5C16
If NZ flag is set (extra characters after the 3 letters), jump to "BAD REPLY".
5C18
LD (5FC1H),HL 22 C1 5F
Store the computed label code value (0-17575) at 5FC1H for use in label generation.
5C1B
Jump to 5BC1H to re-prompt for the next option.

5C1DH - Option Processing Finalization

Called when option input is complete (user pressed ENTER on empty line). This routine resolves conflicting options by applying priority rules: output file mode disables memory mode, memory mode disables printer mode, entry labels enable certain features, etc. May prompt for additional parameters if extended options are enabled.

5C1D
POP AF F1
Discard saved value from stack (cleanup from option parser).
5C1E
POP AF F1
Discard another saved value from stack.
5C1F
LD BC,(55EFH) ED 4B EF 55
Load the mode flags word from 55EFH into BC. C=low byte (main flags), B=high byte (extended flags).
5C23
LD A,C 79
Copy the low flag byte into A for bit testing.
5C24
AND 30H E6 30
Mask with 30H to isolate bits 4-5 (output file enabled, entry point labels enabled).
5C26
If Z flag is set (neither output file nor entry labels), skip the adjustment.
5C28
RES 2,C CB 91
Reset bit 2 of C (memory mode indicator). Output file/entry labels modes override memory mode.
5C2A
BIT 2,C CB 51
Test bit 2 of C (memory mode indicator).
5C2C
If Z flag is set (not in memory mode), skip the printer disable.
5C2E
RES 0,C CB 81
Reset bit 0 of C (printer mode). Memory mode disables printer output.
5C30
BIT 5,C CB 69
Test bit 5 of C (entry point labels enabled).
5C32
If Z flag is set (entry labels not enabled), skip these adjustments.
5C34
RES 3,C CB 99
Reset bit 3 of C (processing complete flag). Entry labels require additional processing.
5C36
SET 0,B CB C0
Set bit 0 of B (high byte flag) to enable entry point processing.
5C38
BIT 1,B CB 48
Test bit 1 of B (extended options/prompts enabled).
5C3A
If Z flag is set (extended prompts not enabled), skip.
5C3C
SET 0,B CB C0
Set bit 0 of B to ensure entry point processing when extended options are used.
5C3E
LD (55EFH),BC ED 43 EF 55
Store the adjusted mode flags back to 55EFH.
5C42
BIT 1,B CB 48
Test bit 1 of B again (extended prompts enabled).
5C44
If Z flag is set (no extended prompts), skip to return at 5C87H.

Extended options mode - prompt for screen width.

5C46
LD DE,6D4EH 11 4E 6D
Load DE with 6D4EH, the address of the screen width prompt string.
5C49
Call the decimal input routine to get the screen width from the user.
5C4C
LD A,H 7C
Load the high byte of the entered value into A.
5C4D
OR A B7
Test if H is non-zero (value > 255).
5C4E
If NZ flag is set (value too large), [LOOP] back to re-prompt.
5C50
OR L B5
OR H (which is 0) with L to test if value is 0.
5C51
If Z flag is set (value is 0), [LOOP] back to re-prompt. Width must be > 0.
5C53
LD A,L 7D
Load the valid screen width value (1-255) into A.
5C54
LD (5604H),A 32 04 56
Store the screen width at 5604H (screen width configuration variable).

Prompt for page length (lines per page).

5C57
LD DE,6D8EH 11 8E 6D
Load DE with 6D8EH, the address of the page length prompt string.
5C5A
Call the decimal input routine to get page length.
5C5D
LD A,H 7C
Load the high byte of the entered value.
5C5E
OR A B7
Test if value > 255.
5C5F
If too large, re-prompt.
5C61
LD A,L 7D
Load the page length value into A.
5C62
CP 0BH FE 0B
Compare against 11 (0BH). Page length must be less than 11 for valid output.
5C64
If NC flag is set (value >= 11), re-prompt for a smaller value.
5C66
LD (5E36H),A 32 36 5E
Store page length at 5E36H (page length variable #1).
5C69
LD (5E2FH),A 32 2F 5E
Store page length at 5E2FH (page length variable #2, used in different context).

Prompt for printer form positioning.

5C6C
LD DE,6AAEH 11 AE 6A
Load DE with 6AAEH, the address of "REPLY ENTER WHEN PRINTER AT TOP OF FORM" prompt.
5C6F
Call the Yes/No prompt (default Yes) routine. Waits for user to position paper.

Prompt for starting page number.

5C72
LD DE,6CD4H 11 D4 6C
Load DE with 6CD4H, the address of the page number prompt string.
5C75
Call the hex input (no default) routine to get starting page number.
5C78
LD A,H 7C
Load high byte of entered value.
5C79
OR A B7
Test if value > 255.
5C7A
If too large, re-prompt.
5C7C
INC L 2C
Increment L to adjust the page number (convert from 0-based to 1-based or similar).
5C7D
LD A,L 7D
Load the adjusted page number into A.
5C7E
LD (5613H),A 32 13 56
Store at 5613H (initialization/page counter flag).
5C81
SUB 5BH D6 5B
Subtract 91 (5BH) to check if value is in valid range.
5C83
CP 26H FE 26
Compare against 38 (26H). Valid range is 91-128 (5BH-80H) after increment.
5C85
If NC flag is set (out of valid range), re-prompt.
5C87
RET C9
Return to caller. Option processing is complete.

5C88H - Option Continuation Check

Verifies that the option name has been fully consumed and no extra characters remain. If B=0, returns normally. If B>0 but more input exists unexpectedly, jumps to "BAD REPLY" error.

5C88
DEC B 05
Decrement B (remaining input character count).
5C89
RET Z C8
If Z flag is set (B became 0, no more characters), return normally.
5C8A
POP AF F1
Discard the return address from the stack (won't return to caller).
5C8B
Extra characters found after option. Jump to "BAD REPLY" error handler.

5C8EH - Option Lookup Table (DATA)

This is a DATA table, not executable code. Each entry contains: option name (ASCII), terminator byte with bit 7 set containing the flag mask, and a 2-byte handler address. The table ends with a 00H byte. Options include: NCR (No CR), NIP (No Input Pause), RTD, STD, RE, RI, PTR (Printer), BFSP, FGN (Format Generator).

5C8E
DEFM "NCR" 4E 43 52
Option name: "NCR" (No Carriage Return) - suppresses CR in output.
5C91
DEFB 84H 84
Terminator + Flag: 84H = 80H (end marker) + 04H (bit 2 mask).
5C92
DEFW 5BB8H B8 5B
Handler address: 5BB8H (Set Mode Flag handler).
5C94
DEFM "NIP" 4E 49 50
Option name: "NIP" (No Input Pause).
5C97
DEFB 88H 88
Terminator + Flag: 88H = 80H + 08H (bit 3 mask).
5C98
DEFW 5BB8H B8 5B
Handler address: 5BB8H.
5C9A
DEFM "RTD" 52 54 44
Option name: "RTD" (Real-Time Display).
5C9D
DEFB 90H 90
Terminator + Flag: 90H = 80H + 10H (bit 4 mask).
5C9E
DEFW 5BB8H B8 5B
Handler address: 5BB8H.
5CA0
DEFM "STD" 53 54 44
Option name: "STD" (Standard output).
5CA3
DEFB A0H A0
Terminator + Flag: A0H = 80H + 20H (bit 5 mask).
5CA4
DEFW 5BB8H B8 5B
Handler address: 5BB8H.
5CA6
DEFM "RE" 52 45
Option name: "RE" (Register Equates).
5CA8
DEFB 81H 81
Terminator + Flag: 81H = 80H + 01H (bit 0 mask).
5CA9
DEFW 5BC4H C4 5B
Handler address: 5BC4H (Column Format handler).
5CAB
DEFM "RI" 52 49
Option name: "RI" (Register Index).
5CAD
DEFB 80H 80
Terminator + Flag: 80H = end marker only, flag = 00H.
5CAE
DEFW 5BC4H C4 5B
Handler address: 5BC4H.
5CB0
DEFM "PTR" 50 54 52
Option name: "PTR" (Printer output).
5CB3
DEFB 82H 82
Terminator + Flag: 82H = 80H + 02H (bit 1 mask for printer flag at 55F0H).
5CB4
DEFW 5BB3H B3 5B
Handler address: 5BB3H (Set Printer Mode Flag handler).
5CB6
DEFM "BFSP" 42 46 53 50
Option name: "BFSP" (Buffer Space).
5CBA
DEFB 81H 81
Terminator + Flag: 81H = 80H + 01H.
5CBB
DEFW 5BB3H B3 5B
Handler address: 5BB3H.
5CBD
DEFM "FGN=" 46 47 4E 3D
Option name: "FGN=" (Format Generator with parameter).
5CC1
DEFB 80H 80
Terminator + Flag: 80H = end marker, flag = 00H.
5CC2
DEFW 5BF6H F6 5B
Handler address: 5BF6H (Three-Letter Label Code parser).
5CC4
DEFB 00H 00
End of table marker: 00H signals no more options.

5CC5H - Display Prompt and Get Input Line

Main input routine that displays a null-terminated prompt string pointed to by DE, then reads a line of user input into the buffer at 5564H. Returns with: DE = pointer to input buffer (5564H), B = character count entered, HL = pointer past last character, Z flag set if input was empty (just ENTER). This is the core input routine called by all the prompt functions.

5CC5
POP AF F1
Pop the return address from the stack into AF (temporarily).
5CC6
PUSH AF F5
Push the return address back onto the stack (restoring it).
5CC7
PUSH DE D5
Push DE (the prompt string address) onto the stack for later re-prompting if needed.
5CC8
PUSH AF F5
Push the return address again (creating a stack frame for nested returns).
5CC9
Call the display null-terminated string routine to print the prompt message at DE to screen.
5CCC
Call the input line reader routine at 5DA6H to read user input into buffer at 5564H.
5CCF
LD C,00H 0E 00
Initialize C to 00H (result/flag register, will be set to 1 by success paths).
5CD1
RET C9
Return to caller. Z flag is set based on whether input was empty or not.

5CD2H - Get Key with Uppercase Conversion (Blocking)

Waits for a keypress using ROM routine 0049H (blocking wait), then converts lowercase letters a-z to uppercase A-Z. Returns the key in Register A. Preserves DE across the call.

5CD2
PUSH DE D5
Preserve DE (often holds prompt address or buffer pointer) on the stack.
5CD3
Call ROM @KBD routine at 0049H. This waits for a keypress and returns the ASCII code in A.
5CD6
POP DE D1
Restore DE from the stack.
5CD7
CP 61H FE 61
Compare key against a (61H), the start of lowercase letters.
5CD9
RET C D8
If C flag is set (key < 'a', not lowercase), return with key unchanged.
5CDA
CP 7BH FE 7B
Compare key against { (7BH), which is just past z.
5CDC
RET NC D0
If NC flag is set (key >= '{', not lowercase), return with key unchanged.
5CDD
SUB 20H D6 20
Subtract 20H to convert lowercase (61H-7AH) to uppercase (41H-5AH).
5CDF
RET C9
Return with the uppercase key in A.

5CE0H - Get Key with Uppercase Conversion (Non-Blocking)

Scans the keyboard using ROM routine 002BH (non-blocking scan), then converts any lowercase to uppercase. Returns Z flag set if no key pressed, otherwise key in Register A.

5CE0
PUSH DE D5
Preserve DE on the stack.
5CE1
Call ROM @KEY routine at 002BH. Non-blocking keyboard scan. Returns key in A, or 0 if no key.
5CE4
Jump to 5CD6H to restore DE and perform uppercase conversion.

5CE6H - DOS Error Handler

Handles DOS errors by displaying the error message, then prompting user whether to restart or exit. Called when file operations fail. Uses DOS routine 4409H to display the system error message.

5CE6
PUSH AF F5
Preserve AF (contains the DOS error code in A) on the stack.
5CE7
LD B,03H 06 03
Set B to 3 for the number of blank lines to output.
5CE9
Call the output multiple CRs routine to print 3 carriage returns (blank lines).
5CEC
POP AF F1
Restore the DOS error code from the stack into A.
5CED
OR C0H F6 C0
OR with C0H to set bits 6-7 of the error code. This formats it for the DOS error display routine.
5CEF
Call DOS @ERROR routine at 4409H to display the error message for the error code in A.
5CF2
LD DE,6AD8H 11 D8 6A
Load DE with 6AD8H, address of an error/status message string.
5CF5
Jump to 5CFAH to display the message and prompt for restart.

5CF7H - Display Error and Prompt Restart

Entry point for displaying a different error message (at 6B0CH) then prompting for restart/exit.

5CF7
Load DE with 6B0CH, address of an error message string.
5CFA
Call the display string with extra CRs routine to show the error message.
5CFD
Call the screen mode setup routine at 5DD8H to prepare for prompt.
5D00
LD DE,6D01H 11 01 6D
Load DE with 6D01H, address of the "RESTART? (Y/N)" prompt string.
5D03
Call the Y/N prompt routine. Returns NZ if Yes, Z if No.
5D06
If NZ flag is set (user chose Yes), jump to program entry point at 5614H to restart.
5D09
User chose No. Jump to DOS @EXIT at 402DH to exit to NEWDOS/80 Ready prompt.

5D0CH - Display String with Extra Line Spacing

Displays a string followed by multiple carriage returns for line spacing. First ensures cursor is at start of a fresh line, then displays the string, then outputs 3 more CRs.

5D0C
Call the screen mode setup routine to ensure proper cursor positioning.
5D0F
Call the display string with CR routine to output the string at DE followed by CR.
5D12
LD B,03H 06 03
Set B to 3 for the number of trailing carriage returns.
5D14
Jump to the output multiple CRs routine.

5D17H - Display Null-Terminated String with CR

Displays a null-terminated string pointed to by DE, then outputs a single carriage return. This is the standard string display routine used throughout the program.

5D17
Call the display null-terminated string routine to output the string at DE.
5D1A
LD B,01H 06 01
Set B to 1 for a single carriage return.

[LOOP] - Output B carriage returns.

5D1C
LD A,0DH 3E 0D
Load A with carriage return character (0DH).
5D1E
Call the output character routine to display the CR.
5D21
Decrement B and [LOOP] back if more CRs needed.
5D23
RET C9
Return to caller.

5D24H - Display Null-Terminated String

Outputs characters from the string pointed to by DE until a null terminator (00H) is encountered. Does not add a trailing carriage return. Advances DE past the null terminator on return.

[LOOP START] - Output each character until null terminator.

5D24
LD A,(DE) 1A
Load the next character from the string buffer (pointed to by DE) into A.
5D25
OR A B7
Test if A is 00H (null terminator) by ORing with itself.
5D26
INC DE 13
Advance DE to point to the next character in the string.
5D27
RET Z C8
If Z flag is set (null terminator found), return. String output is complete.
5D28
Call the output character routine to display the character in A.
5D2B
[LOOP] back to get and display the next character.

5D2DH - Clear Screen

Clears the screen by outputting the TRS-80 clear screen control code (1CH) followed by the home cursor code (1FH).

5D2D
Call the routine at 5D35H which outputs clear screen code (1CH).
5D30
LD A,1FH 3E 1F
Load A with home cursor control code (1FH).
5D32
Jump to the output character routine to send the home cursor code.

5D35H - Output Clear Screen Code

Outputs the TRS-80 clear screen control code (1CH).

5D35
LD A,1CH 3E 1C
Load A with clear screen control code (1CH) for TRS-80.
5D37
Jump to the output character routine.

5D3AH - Display B Characters from DE with CR

Outputs B characters from the buffer at DE, then outputs a carriage return.

5D3A
Call the display B characters routine to output B bytes from DE.
5D3D
Jump to 5D1AH to output a single carriage return.

5D3FH - Display B Characters from DE

Outputs exactly B characters from the buffer pointed to by DE. Does not check for null terminators.

[LOOP START] - Output B characters from buffer.

5D3F
LD A,(DE) 1A
Load the next character from the buffer (pointed to by DE) into A.
5D40
INC DE 13
Advance DE to point to the next character.
5D41
Call the output character routine to display the character.
5D44
Decrement B (character count) and [LOOP] back if more characters to output.
5D46
RET C9
Return to caller. DE points past the last character output.

5D47H - Output Single Character

The main character output routine. Outputs the character in Register A to the screen, with special handling for control characters and line width management. Tracks cursor position in the variable at 5605H. Handles CR, backspace, and screen width wrapping. This routine is called by all display functions.

5D47
PUSH HL E5
Preserve HL on the stack.
5D48
PUSH DE D5
Preserve DE on the stack.
5D49
PUSH BC C5
Preserve BC on the stack.
5D4A
PUSH AF F5
Preserve AF (the character to output in A) on the stack.
5D4B
LD HL,5605H 21 05 56
Load HL with 5605H, the address of the cursor column position variable.
5D4E
CP 0EH FE 0E
Compare the character against 0EH (a control code threshold).
5D50
If NC flag is set (character >= 0EH), jump to the main output path at 5D56H.
5D52
CP 0AH FE 0A
Compare against line feed (0AH).
5D54
If character is 0AH-0DH (LF through CR range), jump to 5D7CH for special handling.
5D56
Call the low-level character output routine at 5E63H to actually display the character.
5D59
CP 20H FE 20
Compare the character against space (20H).
5D5B
If NC flag is set (printable character, >= space), jump to 5D79H to increment column counter.
5D5D
CP 08H FE 08
Compare against backspace (08H).
5D5F
If NZ flag is set (not backspace), jump to 5D6DH to handle other control codes.

Handle backspace - decrement column position, wrapping if needed.

5D61
LD A,(5606H) 3A 06 56
Load A with the line width value from 5606H.
5D64
DEC A 3D
Decrement to get the maximum column index (0-based).
5D65
CP (HL) BE
Compare max column against current column position at (5605H).
5D66
INC (HL) 34
Increment the column position (will be decremented next, net effect is no change if not at margin).
5D67
If NC flag is set (was at right margin), jump to exit without further adjustment.
5D69
LD (HL),01H 36 01
Reset the column position to 1 (backspace wrapped to previous line end).
5D6B
Jump to exit.

Handle control codes in range 1CH-38H (cursor positioning).

5D6D
SUB 1CH D6 1C
Subtract 1CH from the character to check if it's a cursor position code.
5D6F
CP 1DH FE 1D
Compare against 1DH (maximum range for position codes).
5D71
If NC flag is set (not a position code), jump to exit.
5D73
LD A,(5606H) 3A 06 56
Load the line width from 5606H into A.
5D76
LD (HL),A 77
Set the column position to the line width (cursor moved to end of line).
5D77
Jump to exit.

Handle printable characters - increment column and check for line wrap.

5D79
DEC (HL) 35
Decrement the column position (pre-decrement before increment check).
5D7A
If NZ flag is set (not at column 0), jump to exit.

Column wrapped to 0 - handle end of line.

5D7C
LD A,(5606H) 3A 06 56
Load the line width from 5606H.
5D7F
CP (HL) BE
Compare line width against current column position.
5D80
LD A,20H 3E 20
Load A with space character (20H).
5D82
If Z flag is set (at line width), call low-level output to print a space (line padding).
5D85
LD A,0DH 3E 0D
Load A with carriage return (0DH).
5D87
Call low-level output to print the carriage return.
5D8A
Call the line handling routine at 5E20H for pagination and line counting.
5D8D
LD A,(3840H) 3A 40 38
Load A with the value at 3840H (TRS-80 keyboard memory-mapped I/O status byte).
5D90
AND 04H E6 04
Mask with 04H to test bit 2 (BREAK key or specific status).
5D92
If Z flag is set (bit not set), jump to exit normally.

Pause output - wait for keypress or condition clear.

5D94
LD BC,0000H 01 00 00
Load BC with 0000H (parameter for delay routine).
5D97
Call ROM routine at 0060H (delay or wait routine).
5D9A
LD A,(3840H) 3A 40 38
Load A with the keyboard status byte again.
5D9D
AND 01H E6 01
Mask with 01H to test bit 0.
5D9F
If Z flag is set (condition not met), [LOOP] back to keep waiting.

Restore registers and return.

5DA1
POP AF F1
Restore AF from the stack.
5DA2
POP BC C1
Restore BC from the stack.
5DA3
POP DE D1
Restore DE from the stack.
5DA4
POP HL E1
Restore HL from the stack.
5DA5
RET C9
Return to caller.

5DA6H - Input Line Reader

This routine reads a line of input from the keyboard into the 64-byte input buffer at 5564H. It uses the ROM line input routine at 0040H, then converts all characters to uppercase and checks for the BREAK key. On entry, no specific registers are required. On exit: HL points to 5564H (the input buffer), the Z flag is set if the first character is a carriage return (empty line), and all characters in the buffer have been converted to uppercase.

5DA6
LD HL,5564H 21 64 55
Load HL with 5564H, the address of the 64-byte input buffer where keyboard input will be stored.
5DA9
LD B,40H 06 40
Load B with 40H (64 decimal), specifying the maximum buffer length in bytes for the ROM input routine.
5DAB
PUSH HL E5
Save HL (5564H, the input buffer address) onto the stack for later restoration after the ROM call.
5DAC
Call the ROM line input routine at 0040H. This displays a cursor, waits for keyboard input, and stores characters at the address in HL. The routine fills the buffer until ENTER is pressed (0DH terminator) or the buffer is full.
5DAF
LD A,(3840H) 3A 40 38
Load A with the byte at 3840H, a keyboard status/modifier byte in the TRS-80 memory-mapped keyboard area (3800H-3FFFH). This location contains special key status bits.
5DB2
AND 08H E6 08
Isolate bit 3 of the keyboard status byte. Bit 3 indicates if the BREAK key was pressed during input.
5DB4
If the NZ flag is set (BREAK key was pressed), jump to 5CF2H which handles the program restart sequence. This allows the user to abort input and restart the disassembler.

[LOOP START] The following loop converts all characters in the buffer to uppercase until the carriage return terminator is found.

5DB7
LD A,(HL) 7E
Load A with the character at the current buffer position pointed to by HL.
5DB8
Call the uppercase conversion routine at 5CD7H. If A contains a lowercase letter (61H-7AH), it is converted to uppercase (41H-5AH). Other characters are unchanged.
5DBB
CP 0DH FE 0D
Compare A with 0DH (carriage return). If equal, the Z flag is set, indicating end of input line.
5DBD
LD (HL),A 77
Store the (possibly uppercased) character back into the buffer at the current position pointed to by HL.
5DBE
INC HL 23
Increment HL to point to the next character position in the input buffer.
5DBF
If the NZ flag is set (current character was not a carriage return), loop back to 5DB7H to process the next character. [LOOP]

After the loop, HL points past the carriage return. The following code restores HL to the buffer start and sets the Z flag based on whether the input is empty.

5DC1
POP HL E1
Restore HL from the stack, setting it back to 5564H (the start of the input buffer).
5DC2
LD A,(HL) 7E
Load A with the first character of the input buffer at 5564H.
5DC3
CP 0DH FE 0D
Compare A with 0DH (carriage return). If the first character is CR, the Z flag is set indicating the user pressed ENTER without typing anything (empty input).
5DC5
RET C9
Return to the caller. On exit: HL=5564H (buffer address), Z flag=set if empty input, NZ flag=set if input was entered.

5DC6H - Initialize Screen Mode (Narrow)

This routine initializes the display for narrow screen mode (32 columns). It sets A=00H to indicate narrow mode, then calls the common screen mode setup routine at 5DDAH. It also checks if output initialization has been done and performs first-time setup if needed. On exit: the screen mode variables at 5605H-5608H are configured for narrow display.

5DC6
LD A,00H 3E 00
Load A with 00H, indicating narrow screen mode (32 columns). This value is distinct from 18H which indicates wide mode.
5DC8
Call the screen mode setup routine at 5DDAH which configures the line width variables based on the mode value in A.
5DCB
PUSH HL E5
Save HL onto the stack to preserve it during initialization check.
5DCC
LD HL,5602H 21 02 56
Load HL with 5602H, the address of the output state flags byte. Bit 0 of this byte indicates whether output initialization has been performed.
5DCF
BIT 0,(HL) CB 46
Test bit 0 of the output state flags at (5602H). If bit 0 is 0, initialization has not been done yet and the Z flag is set.
5DD1
If the Z flag is set (initialization not done), call 5E34H to perform first-time output initialization. This routine outputs blank lines for screen positioning.
5DD4
SET 0,(HL) CB C6
Set bit 0 of the output state flags at (5602H), marking that initialization is complete. Future calls will skip the initialization.
5DD6
POP HL E1
Restore HL from the stack to its original value.
5DD7
RET C9
Return to the caller with screen mode configured for narrow display.

5DD8H - Initialize Screen Mode (Wide)

This routine is the entry point for wide screen mode initialization (64 columns). It loads A=18H to indicate wide mode and falls through to the common screen mode setup routine.

5DD8
LD A,18H 3E 18
Load A with 18H (24 decimal), indicating wide screen mode (64 columns). This falls through to the common setup at 5DDAH.

5DDAH - Screen Mode Setup (Common)

This is the common screen mode configuration routine called by both the narrow (5DC6H) and wide (5DD8H) entry points. On entry: A contains the mode value (00H=narrow, 18H=wide). The routine outputs a carriage return if needed, then configures the line width variables at 5605H-5608H based on the selected mode. The mode value is stored at 5E68H for later reference.

5DDA
PUSH AF F5
Save AF (the mode value in A and flags) onto the stack for later restoration.
5DDB
PUSH BC C5
Save BC onto the stack to preserve it during the routine.
5DDC
PUSH HL E5
Save HL onto the stack to preserve it during the routine.
5DDD
LD HL,5605H 21 05 56
Load HL with 5605H, the address of the cursor column position variable which tracks the current output column.
5DE0
LD A,(5606H) 3A 06 56
Load A with the byte at 5606H, the active line width variable which contains the current maximum column count.
5DE3
CP (HL) BE
Compare the active line width (in A) with the current column position at (5605H). If they are equal, the cursor is at the end of a line.
5DE4
If the NZ flag is set (cursor not at line start), call 5D1AH to output a carriage return. This ensures the new screen mode begins on a fresh line.
5DE7
POP HL E1
Restore HL from the stack.
5DE8
POP BC C1
Restore BC from the stack.
5DE9
POP AF F1
Restore AF from the stack, recovering the mode value in A (00H for narrow, 18H for wide).
5DEA
CP 18H FE 18
Compare A with 18H. If equal (wide mode), the Z flag is set; otherwise NZ indicates narrow mode.
5DEC
LD (5E68H),A 32 68 5E
Store the mode value in A to the screen mode state variable at 5E68H. This preserves the current mode (00H or 18H) for later checks.
5DEF
LD A,(5607H) 3A 07 56
Load A with the byte at 5607H, which contains the screen mode width 1 (narrow mode line width value).
5DF2
If the Z flag is set (wide mode selected at 5DEAH), jump to 5DF7H to skip loading the alternate width. Otherwise continue for narrow mode.
5DF4
LD A,(5608H) 3A 08 56
Load A with the byte at 5608H, which contains the screen mode width 2 (wide mode line width value). This overrides the narrow mode width.
5DF7
LD (5606H),A 32 06 56
Store the selected width value to 5606H, setting the active line width for the current screen mode.
5DFA
LD (5605H),A 32 05 56
Also store the width value to 5605H, resetting the cursor column position to the line width (indicating a fresh line).
5DFD
RET C9
Return to the caller with screen mode variables configured. 5605H and 5606H now contain the appropriate line width for the selected mode.

5DFEH - Enable Printer Output

This short routine enables printer output by setting bit 6 of the output state flags at 5602H. When bit 6 is set, all character output will be sent to the printer in addition to the screen. On exit: bit 6 of 5602H is set, enabling printer output.

5DFE
LD A,(5602H) 3A 02 56
Load A with the byte at 5602H, the output state flags. Bit 0 indicates initialization done; bit 6 indicates printer output enabled.
5E01
SET 6,A CB F7
Set bit 6 of A, which enables printer output. When this bit is set, characters sent via the output routine will also go to the printer.
5E03
LD (5602H),A 32 02 56
Store the modified flags back to 5602H, persisting the printer-enabled state for subsequent output operations.
5E06
RET C9
Return to the caller with printer output now enabled.

5E07H - Fill Remaining Line with Carriage Returns

This routine fills the remaining space on the current output line by repeatedly outputting carriage returns until the line is complete. It is used for formatting output, ensuring proper line endings. The routine loops until the screen mode check at 5E10H indicates the line is full or wide mode is active. On entry: no specific registers required. On exit: the current line has been filled with carriage returns as needed.

[LOOP START] This loop outputs carriage returns until the line position check indicates completion.

5E07
Call the line position check routine at 5E10H. This routine returns Z flag set if in wide mode (5E68H=18H) or if the current line position equals the screen width. Returns NZ if more output space remains.
5E0A
RET Z C8
If the Z flag is set (line complete or wide mode), return to the caller. No more carriage returns are needed.
5E0B
Call 5D1AH to output a carriage return. This advances the output position and may trigger line counting.
5E0E
Jump back to 5E07H to continue the loop, checking if more carriage returns are needed. [LOOP]

5E10H - Check Line Position Status

This routine checks whether the current output line is complete or if wide mode is active. It is used by line-filling routines to determine when to stop outputting. On entry: no specific registers required. On exit: Z flag is set if wide mode (5E68H=18H) or if current line position (5603H) equals screen width (5604H); NZ otherwise. HL is preserved.

5E10
LD A,(5E68H) 3A 68 5E
Load A with the byte at 5E68H, the screen mode state variable. Value 00H indicates narrow mode; 18H indicates wide mode.
5E13
CP 18H FE 18
Compare A with 18H (wide mode indicator). If equal, the Z flag is set.
5E15
RET Z C8
If Z flag is set (wide mode active), return immediately. Wide mode does not require line filling.
5E16
PUSH HL E5
Save HL onto the stack to preserve it during the position check.
5E17
LD HL,5604H 21 04 56
Load HL with 5604H, the address of the screen width variable (default 3CH = 60 decimal).
5E1A
LD A,(5603H) 3A 03 56
Load A with the byte at 5603H, the current line number (or output position counter).
5E1D
CP (HL) BE
Compare A (current position) with the value at (5604H) (screen width). If equal, the Z flag is set indicating the line is complete.
5E1E
POP HL E1
Restore HL from the stack to its original value.
5E1F
RET C9
Return to the caller. Z flag indicates line complete; NZ indicates more space remains on the line.

5E20H - Reset Line Position for New Output

This routine resets the line position counters for starting a new page or section of output. In narrow mode, it may output leading blank lines for formatting. It resets the line counter (5603H) and cursor column (5605H) to their initial values. On entry: no specific registers required. On exit: line position variables are reset for new output.

5E20
LD A,(5E68H) 3A 68 5E
Load A with the byte at 5E68H, the screen mode state (00H=narrow, 18H=wide).
5E23
CP 18H FE 18
Compare A with 18H to check if wide mode is active.
5E25
If Z flag is set (wide mode), jump to 5E41H to skip the narrow mode formatting and just reset the column position.
5E27
LD A,(5603H) 3A 03 56
Load A with the byte at 5603H, the current line number counter.
5E2A
DEC A 3D
Decrement A to check if the line counter was 1 (meaning we're on the first line of a page).
5E2B
If NZ (line counter was not 1), jump to 5E3EH to just store the screen width as the new line counter, skipping the blank line output.
5E2D
PUSH BC C5
Save BC onto the stack to preserve it during the blank line output.
5E2E
LD B,03H 06 03
Load B with 03H, specifying 3 blank lines to output for top-of-page formatting.
5E30
Call 5E53H to output B blank lines (3 lines with space and carriage return each). This provides top-of-page spacing.
5E33
POP BC C1
Restore BC from the stack.

5E34H - Output Section Separator Lines

This routine outputs 3 blank lines as a section separator. It is called during first-time initialization (from 5DD1H) and for page formatting. On entry: no specific registers required. On exit: 3 blank lines have been output, BC is preserved.

5E34
PUSH BC C5
Save BC onto the stack to preserve it during blank line output.
5E35
LD B,03H 06 03
Load B with 03H, specifying 3 blank lines to output for section separation.
5E37
Call 5E53H to output B blank lines. Each blank line consists of a space (20H) followed by a carriage return (0DH).
5E3A
POP BC C1
Restore BC from the stack to its original value.
5E3B
LD A,(5604H) 3A 04 56
Load A with the byte at 5604H, the screen width value (default 3CH = 60).
5E3E
LD (5603H),A 32 03 56
Store the screen width value to 5603H, resetting the line counter to indicate a fresh page/section.
5E41
LD A,(5606H) 3A 06 56
Load A with the byte at 5606H, the active line width for the current screen mode.
5E44
LD (5605H),A 32 05 56
Store the line width to 5605H, resetting the cursor column position to the start of a line (actually set to max, indicating a fresh line).
5E47
RET C9
Return to the caller with line position variables reset for new output.

5E48H - Output Multiple Carriage Returns

This routine outputs C carriage returns, checking line position between each one. It is used for multi-line spacing. On entry: C contains the number of carriage returns to output. On exit: C carriage returns have been output (or fewer if line position check returns Z), C is decremented to 0.

[LOOP START] This loop outputs carriage returns until C reaches zero or the line check indicates completion.

5E48
Call 5E10H to check line position status. Returns Z if in wide mode or line is complete.
5E4B
RET Z C8
If Z flag is set (wide mode or line complete), return early. No more output needed.
5E4C
Call 5D1AH to output a carriage return.
5E4F
DEC C 0D
Decrement C, the count of remaining carriage returns to output.
5E50
If NZ (C is not zero), jump back to 5E48H to continue the loop. [LOOP]
5E52
RET C9
Return to the caller after outputting all requested carriage returns.

5E53H - Output B Blank Lines

This routine outputs B blank lines, where each blank line consists of a space character (20H) followed by a carriage return (0DH). It is used for page formatting and section separation. On entry: B contains the number of blank lines to output. On exit: B blank lines have been output, B is decremented to 0.

[LOOP START] This loop outputs blank lines (space + CR) until B reaches zero.

5E53
LD A,B 78
Load A with B, the count of remaining blank lines to output.
5E54
OR A B7
Perform OR A to set flags based on the count value. If A is zero, the Z flag is set.
5E55
RET Z C8
If Z flag is set (B was zero), return immediately. No more blank lines to output.
5E56
DEC B 05
Decrement B, the count of remaining blank lines.
5E57
LD A,20H 3E 20
Load A with 20H (ASCII space character).
5E59
Call 5E63H to output the space character to both screen and printer (if enabled).
5E5C
LD A,0DH 3E 0D
Load A with 0DH (ASCII carriage return).
5E5E
Call 5E63H to output the carriage return, completing the blank line.
5E61
Jump back to 5E53H to continue the loop for the next blank line. [LOOP]

5E63H - Low-Level Character Output

This is the core low-level character output routine that sends characters to both the screen and printer (if enabled). It handles special characters (CR, LF, control codes) and manages column position for printer output. On entry: A contains the character to output. On exit: the character has been sent to screen and/or printer as appropriate, all registers preserved.

5E63
PUSH HL E5
Save HL onto the stack to preserve it during character output.
5E64
PUSH DE D5
Save DE onto the stack to preserve it during character output.
5E65
PUSH BC C5
Save BC onto the stack to preserve it during character output.
5E66
PUSH AF F5
Save AF onto the stack. A contains the character to output; flags are preserved for later restoration.
5E67
Jump to 5E81H to begin the output processing. This skips the mid-routine entry point at 5E69H.

5E69H - Character Output Filter

This is a mid-routine entry point that filters characters before sending to the screen. Printable characters (20H and above), plus LF (0AH) and CR (0DH) are sent to the screen. Control characters below 20H (except 0AH and 0DH) are blocked from screen output. On entry: A contains the character to check and output. On exit: character has been sent to screen if printable, then printer check follows.

5E69
CP 20H FE 20
Compare A with 20H (ASCII space). If A >= 20H, it's a printable character and the carry flag is clear.
5E6B
If the carry flag is clear (A >= 20H, printable character), jump to 5E75H to output to screen.
5E6D
CP 0AH FE 0A
Compare A with 0AH (ASCII line feed).
5E6F
If Z flag is set (A = 0AH, line feed), jump to 5E75H to output to screen. LF is allowed.
5E71
CP 0DH FE 0D
Compare A with 0DH (ASCII carriage return).
5E73
If NZ flag is set (A is neither LF nor CR nor printable), jump to 5E7AH to skip screen output and proceed to printer check.
5E75
PUSH AF F5
Save AF onto the stack to preserve the character during the ROM call.
5E76
Call the ROM screen output routine at 003BH. This displays the character in A on the video display.
5E79
POP AF F1
Restore AF from the stack, recovering the original character in A.
5E7A
LD HL,5602H 21 02 56
Load HL with 5602H, the address of the output state flags. Bit 6 indicates whether printer output is enabled.
5E7D
BIT 6,(HL) CB 76
Test bit 6 of the output state flags at (5602H). If bit 6 is set, printer output is enabled.
5E7F
If Z flag is set (bit 6 = 0, printer disabled), jump to 5E97H to skip printer output and restore registers.

5E81H - Printer Output Handler

This section handles printer output, including special CR handling to manage column position. When outputting a CR, it checks if padding spaces are needed to reach the full line width. On entry: A contains the character to send to printer. On exit: character has been sent to printer via ROM routine at 0033H.

5E81
CP 0DH FE 0D
Compare A with 0DH (carriage return). CR requires special handling for column position management.
5E83
If NZ (not a carriage return), jump to 5E94H to output the character directly to the printer.

The following code handles CR output with column position tracking. If the cursor is not at line start, padding may be needed.

5E85
LD HL,5605H 21 05 56
Load HL with 5605H, the address of the cursor column position variable.
5E88
LD A,(5606H) 3A 06 56
Load A with the byte at 5606H, the active line width for the current screen mode.
5E8B
SUB (HL) 96
Subtract the current column position (at 5605H) from the line width. Result in A is the difference.
5E8C
If Z flag is set (column position equals line width, meaning cursor at line start), jump to 5E92H to output CR normally.
5E8E
AND 3FH E6 3F
Mask the difference with 3FH (63 decimal) to keep only the lower 6 bits. This limits the value range.
5E90
If Z flag is set (after masking), jump to 5E97H to skip the CR output. This handles special column wrap cases.
5E92
LD A,0DH 3E 0D
Load A with 0DH (carriage return) to send to the printer.
5E94
Call the ROM printer output routine at 0033H. This sends the character in A to the printer device.

5E97H - Character Output Cleanup

This section restores all registers after character output operations and returns to the caller. It is the common exit point for the character output routine.

5E97
POP AF F1
Restore AF from the stack, recovering the original character and flags.
5E98
POP BC C1
Restore BC from the stack to its original value.
5E99
POP DE D1
Restore DE from the stack to its original value.
5E9A
POP HL E1
Restore HL from the stack to its original value.
5E9B
RET C9
Return to the caller with all registers restored to their original values.

5E9CH - Initialize Input Buffer with Spaces

This routine fills the 64-byte input buffer at 5564H with space characters (20H), preparing it for new input. On entry: no specific registers required. On exit: HL points to 5564H (buffer start), the entire 64-byte buffer is filled with spaces.

5E9C
LD HL,5564H 21 64 55
Load HL with 5564H, the address of the 64-byte input buffer used for keyboard input and command parsing.
5E9F
LD B,40H 06 40
Load B with 40H (64 decimal), the buffer size in bytes.
5EA1
PUSH HL E5
Save HL (5564H, buffer start address) onto the stack for later restoration.

[LOOP START] The following loop fills the buffer with space characters.

5EA2
LD (HL),20H 36 20
Store 20H (ASCII space character) at the current buffer position pointed to by HL.
5EA4
INC HL 23
Increment HL to point to the next buffer position.
5EA5
Decrement B and jump back to 5EA2H if B is not zero. This loops 64 times to fill the entire buffer. [LOOP]
5EA7
POP HL E1
Restore HL from the stack, setting it back to 5564H (the start of the input buffer).
5EA8
RET C9
Return to the caller. HL points to 5564H and the buffer is filled with spaces.

5EA9H - Compare HL with DE (Signed)

This utility routine performs a comparison between the 16-bit values in HL and DE. It subtracts DE from HL and sets flags based on the result. On entry: HL and DE contain the 16-bit values to compare. On exit: Z flag is set if HL = DE, carry flag reflects the subtraction result. HL is modified (contains HL - DE), A contains the high byte of the result.

5EA9
OR A B7
Perform OR A to clear the carry flag. This ensures the following SBC is a pure subtraction without borrow.
5EAA
SBC HL,DE ED 52
Subtract DE from HL with borrow (but carry was cleared). Result HL = HL - DE. Flags are set: Z if result is zero, S if result is negative.
5EAC
LD A,H 7C
Load A with H, the high byte of the result (HL - DE).
5EAD
OR A B7
Perform OR A to set flags based on the high byte. If H is zero, the Z flag is set (result < 256). If H is non-zero, NZ is set.
5EAE
RET NZ C0
If NZ (high byte is non-zero), return immediately. The values differ by more than 255.
5EAF
LD A,L 7D
Load A with L, the low byte of the result.
5EB0
CP H BC
Compare A (low byte) with H (high byte, which is 0). If L is also 0, Z flag is set (HL = DE). Otherwise NZ indicates HL > DE.
5EB1
RET C9
Return to the caller. Z flag indicates HL = DE; NZ indicates HL > DE (and HL was < DE + 256).

5EB2H - Add Entry to Label Buffer

This routine adds a new entry to the label buffer for automatic label generation during disassembly. It first checks if the program is in a mode that uses label buffers, then searches for the correct insertion point and creates the new entry. The label buffer stores jump/call target addresses for generating symbolic labels in the output. On entry: DE contains the address to add to the label buffer. On exit: entry added to buffer if not already present and memory available, all registers preserved.

5EB2
LD A,(55EFH) 3A EF 55
Load A with the byte at 55EFH, the mode/option flags. Bits indicate various operational modes.
5EB5
AND 06H E6 06
Isolate bits 1 and 2 of the mode flags. Bit 1 indicates show byte count; bit 2 indicates memory mode.
5EB7
RET NZ C0
If NZ (either bit 1 or 2 is set), return immediately. Label buffer operations are not used in these modes.
5EB8
PUSH HL E5
Save HL onto the stack to preserve it during label buffer operations.
5EB9
PUSH DE D5
Save DE (the address to add) onto the stack for preservation.
5EBA
PUSH BC C5
Save BC onto the stack to preserve it.
5EBB
Call 5F4DH, the label buffer search routine. This searches the buffer for the address in DE and returns the insertion point in HL. Z flag set if address already exists.
5EBE
If Z flag is set (address already in buffer), jump to 5EE5H to update the existing entry instead of creating a new one.

The address is not in the buffer. Create a new 6-byte entry at the insertion point.

5EC0
LD A,06H 3E 06
Load A with 06H, specifying a 6-byte entry size for a new label buffer entry. Each entry contains: 2 bytes target address, 1 byte flags, 2 bytes source address, 1 byte instruction type.
5EC2
Call 5F02H, the buffer space allocation routine. This shifts existing entries to make room for A bytes at the position in HL.
5EC5
LD (HL),D 72
Store D (high byte of target address) at the current buffer position. This is the first byte of the new entry.
5EC6
INC HL 23
Increment HL to point to the next byte in the entry.
5EC7
LD (HL),E 73
Store E (low byte of target address) as the second byte of the entry.
5EC8
INC HL 23
Increment HL to point to the flags byte position.
5EC9
LD (HL),40H 36 40
Store 40H as the flags byte. Bit 6 set (40H) indicates this is a valid, referenced label entry.
5ECB
INC HL 23
Increment HL to point to the source address storage position.
5ECC
PUSH HL E5
Save HL (current buffer position) onto the stack temporarily.
5ECD
LD HL,5612H 21 12 56
Load HL with 5612H, the address of the page line counter variable (tracks entries per page, max 64).
5ED0
DEC (HL) 35
Decrement the page line counter at (5612H) to account for the new entry.
5ED1
If Z flag is set (counter reached zero), call 5F93H to reset the page counter and handle page overflow for the label buffer.
5ED4
POP HL E1
Restore HL (buffer position for source address) from the stack.

5ED5H - Store Source Address in Label Entry

This section stores the current disassembly address (from 55EBH) and instruction type (from 55F8H) into the label buffer entry. This records where the jump/call instruction was found.

5ED5
LD DE,(55EBH) ED 5B EB 55
Load DE with the 16-bit value at 55EBH, the current disassembly address. This is the source location of the jump/call instruction.
5ED9
LD (HL),D 72
Store D (high byte of source address) at the current buffer position.
5EDA
INC HL 23
Increment HL to point to the next byte.
5EDB
LD (HL),E 73
Store E (low byte of source address) as the next byte of the entry.
5EDC
INC HL 23
Increment HL to point to the instruction type byte position.
5EDD
LD A,(55F8H) 3A F8 55
Load A with the byte at 55F8H, the current byte/instruction type being processed. This indicates the type of jump/call.
5EE0
LD (HL),A 77
Store the instruction type byte as the final byte of the 6-byte label entry.
5EE1
POP BC C1
Restore BC from the stack.
5EE2
POP DE D1
Restore DE from the stack (the original address being added).
5EE3
POP HL E1
Restore HL from the stack to its original value.
5EE4
RET C9
Return to the caller. The new label entry has been added to the buffer.

5EE5H - Update Existing Label Entry

This routine is called when a label address already exists in the buffer (Z flag set from 5F4DH search). It scans through existing reference entries to find an insertion point for a new reference, then adds a 3-byte reference entry (source address + instruction type). On entry: HL points to the start of an existing label entry, DE contains the current disassembly address (55EBH). On exit: new reference added to the entry chain, registers restored.

5EE5
LD DE,(55EBH) ED 5B EB 55
Load DE with the 16-bit value at 55EBH, the current disassembly address. This is the address of the instruction referencing the label.

[LOOP START] Scan through reference entries to find the correct insertion point based on address ordering.

5EE9
INC HL 23
Increment HL to skip to the next field in the entry structure.
5EEA
LD B,(HL) 46
Load B with the byte at (HL), the high byte of a reference address in the entry chain.
5EEB
INC HL 23
Increment HL to point to the low byte of the reference address.
5EEC
LD C,(HL) 4E
Load C with the byte at (HL), the low byte of the reference address. BC now contains a complete reference address.
5EED
INC HL 23
Increment HL to point to the flags/type byte of this reference.
5EEE
LD A,(HL) 7E
Load A with the byte at (HL), the flags/type byte of the current reference entry.
5EEF
AND C0H E6 C0
Isolate the upper 2 bits (bits 6-7) of the flags byte. These bits indicate entry type/status.
5EF1
If NZ (either bit 6 or 7 is set), jump to 5EFBH. This indicates end of chain (bit 7) or special entry (bit 6).

Compare the reference address (BC) with the current address (DE) to find the insertion point.

5EF3
LD A,D 7A
Load A with D, the high byte of the current disassembly address.
5EF4
CP B B8
Compare A (D) with B (high byte of reference). Sets flags for address comparison.
5EF5
If NZ (high bytes differ), jump to 5EF9H to check the comparison result.
5EF7
LD A,E 7B
Load A with E, the low byte of the current disassembly address.
5EF8
CP C B9
Compare A (E) with C (low byte of reference). Full 16-bit comparison now complete.
5EF9
If carry is clear (DE >= BC), loop back to 5EE9H to continue scanning. We need to find where DE < existing reference. [LOOP]

Found the insertion point. Add a 3-byte reference entry here.

5EFB
LD A,03H 3E 03
Load A with 03H, specifying a 3-byte entry size for an additional reference (address + type, no target since that's shared).
5EFD
Call 5F02H, the buffer space allocation routine. This shifts existing entries to make room for 3 bytes at position HL.
5F00
Jump to 5ED5H to store the source address and instruction type in the newly allocated space.

5F02H - Allocate Space in Label Buffer

This routine allocates space in the label buffer by shifting existing entries to make room for new data. It uses block memory moves to shift data and updates the buffer pointer at 55F4H. On entry: A contains the number of bytes to allocate, HL points to the insertion position, DE is on the stack. On exit: space is allocated, HL points to the insertion position, pointers updated. Jumps to error handler if insufficient memory.

5F02
DEC HL 2B
Decrement HL to adjust the insertion position back by one byte.
5F03
DEC HL 2B
Decrement HL again. The insertion position is now 2 bytes before the original position.
5F04
PUSH HL E5
Save HL (adjusted insertion position) onto the stack for later use.
5F05
PUSH DE D5
Save DE onto the stack to preserve it.
5F06
PUSH HL E5
Save HL again onto the stack for the upcoming calculation.
5F07
LD HL,(55F2H) 2A F2 55
Load HL with the 16-bit value at 55F2H, the high memory limit pointer. This marks the top of available memory.
5F0A
LD DE,FFFAH 11 FA FF
Load DE with FFFAH (-6 in two's complement). This will be used to calculate available space with safety margin.
5F0D
ADD HL,DE 19
Add DE (-6) to HL (high memory limit). Result is the maximum usable address with 6-byte safety margin.
5F0E
LD DE,(55F4H) ED 5B F4 55
Load DE with the 16-bit value at 55F4H, the current buffer pointer. This is where new data would be added.
5F12
OR A B7
Perform OR A to clear the carry flag for the following subtraction.
5F13
SBC HL,DE ED 52
Subtract DE (buffer pointer) from HL (adjusted high limit). Result is available free space.
5F15
If carry is set (buffer pointer exceeds high limit), jump to 5F47H to display an out of memory error.

Sufficient memory is available. Perform the block move to create space.

5F17
EX DE,HL EB
Exchange DE and HL. DE now contains the available space amount, HL contains the buffer pointer.
5F18
POP DE D1
Pop DE from the stack, retrieving the original insertion position.
5F19
OR A B7
Perform OR A to clear the carry flag.
5F1A
SBC HL,DE ED 52
Subtract DE (insertion position) from HL (buffer pointer). Result is the number of bytes to move.
5F1C
PUSH HL E5
Save HL (byte count to move) onto the stack.
5F1D
ADD HL,DE 19
Add DE back to HL to restore HL to the original buffer pointer value.
5F1E
LD D,H 54
Copy H to D, starting to set up DE as the source address for LDDR.
5F1F
LD E,L 5D
Copy L to E. DE now points to the end of data to move.
5F20
LD C,A 4F
Copy A (bytes to allocate) to C for use in pointer update.
5F21
LD B,00H 06 00
Load B with 00H. BC now contains the byte count to allocate (A was the count, now in C).
5F23
ADD HL,BC 09
Add BC (allocation size) to HL. HL now points to the destination for the block move.
5F24
LD (55F4H),HL 22 F4 55
Store the new HL value to 55F4H, updating the buffer pointer to reflect the allocation.
5F27
POP BC C1
Pop BC from the stack, retrieving the byte count to move.
5F28
INC BC 03
Increment BC to include one extra byte in the move count.
5F29
EX DE,HL EB
Exchange DE and HL. HL is now the source, DE is the destination for LDDR.
5F2A
LDDR ED B8
Execute LDDR (block move decrementing). Copies BC bytes from (HL) to (DE), moving backwards. This shifts existing data to make room.
5F2C
LD C,A 4F
Copy A (original allocation size) back to C.
5F2D
LD HL,0000H 21 00 00
Load HL with 0000H. SELF-MODIFYING: The operand at 5F2EH is modified at runtime to contain the label buffer base pointer.

5F30H - Update Label Buffer Pointers

This routine updates all label buffer pointers that were affected by the memory shift. It traverses the label buffer and adjusts pointer values by the allocation amount. The base pointer at 5F2EH is self-modified during execution. On entry: HL contains the buffer base (from self-modified instruction), BC contains the adjustment amount. On exit: all affected pointers have been updated.

[LOOP START] Traverse label buffer entries and update pointers affected by the shift.

5F30
INC HL 23
Increment HL to move to the next byte in the buffer structure.
5F31
INC HL 23
Increment HL again (advance by 2 bytes total).
5F32
INC HL 23
Increment HL again (advance by 3 bytes total).
5F33
INC HL 23
Increment HL again. HL now points to the next entry's pointer field (4 bytes per entry stride).
5F34
LD A,L 7D
Load A with L, the low byte of the current buffer position.
5F35
CP A0H FE A0
Compare A with A0H. This checks if we've reached the end of the label buffer page at address xxA0H.
5F37
If NZ (not at end of buffer page), jump to 5F3CH to continue processing entries.
5F39
POP DE D1
Pop DE from the stack, restoring the original value.
5F3A
POP HL E1
Pop HL from the stack, restoring the insertion position.
5F3B
RET C9
Return to the caller. Space allocation and pointer updates are complete.
5F3C
LD E,(HL) 5E
Load E with the byte at (HL), the low byte of a pointer in the buffer.
5F3D
INC HL 23
Increment HL to point to the high byte of the pointer.
5F3E
LD D,(HL) 56
Load D with the byte at (HL), the high byte of the pointer. DE now contains the full pointer value.
5F3F
EX DE,HL EB
Exchange DE and HL. HL now contains the pointer value, DE points to the buffer location.
5F40
ADD HL,BC 09
Add BC (the allocation adjustment) to HL. This updates the pointer to account for shifted data.
5F41
EX DE,HL EB
Exchange DE and HL back. HL points to the buffer, DE contains the adjusted pointer.
5F42
LD (HL),D 72
Store D (high byte of adjusted pointer) back to the buffer.
5F43
DEC HL 2B
Decrement HL to point to the low byte position.
5F44
LD (HL),E 73
Store E (low byte of adjusted pointer) back to the buffer.
5F45
Jump back to 5F30H to continue processing the next entry. [LOOP]

5F47H - Out of Memory Error Handler

This routine handles the out-of-memory condition when the label buffer cannot allocate more space. It displays an error message and jumps to the error handler for program restart.

5F47
LD DE,6AF8H 11 F8 6A
Load DE with 6AF8H, the address of the "INSUFFICIENT MEMORY" error message string in the message table.
5F4A
Jump to 5CFAH, the error display and restart handler. This displays the error message at DE and prompts for program restart.

5F4DH - Label Buffer Search

This routine searches the label buffer for a specific address. The label buffer is organized as a sorted list of entries, each containing a target address and references to that address. The search uses a linked-list traversal through buffer pages. On entry: DE contains the address to search for. On exit: Z flag is set if address was found (HL points to the matching entry), NZ if not found (HL points to where it should be inserted), BC contains reference count information.

5F4D
LD HL,6FA0H 21 A0 6F
Load HL with 6FA0H, the label buffer header address. This is the starting point for the linked-list traversal.

[OUTER LOOP] Traverse through buffer pages following the linked list.

5F50
LD A,L 7D
Load A with L, the low byte of the current buffer position.
5F51
CP 64H FE 64
Compare A with 64H (100 decimal). This checks if we've reached the end marker position within the page.
5F53
DEC HL 2B
Decrement HL to point to the previous byte in the buffer structure.
5F54
LD B,(HL) 46
Load B with the byte at (HL), the high byte of the link pointer to the next buffer page.
5F55
DEC HL 2B
Decrement HL to point to the low byte of the link pointer.
5F56
LD C,(HL) 4E
Load C with the byte at (HL), the low byte of the link pointer. BC now contains the link to the next page.
5F57
DEC HL 2B
Decrement HL to point to the flags/type byte.
5F58
LD A,(HL) 7E
Load A with the byte at (HL), the flags byte for this entry.
5F59
DEC HL 2B
Decrement HL to position before this entry.
5F5A
LD (5F2EH),HL 22 2E 5F
Store HL to 5F2EH, saving the current buffer position for the self-modifying code in the allocation routine.
5F5D
LD L,(HL) 6E
Load L with the byte at (HL), the low byte of the next entry pointer.
5F5E
LD H,A 67
Load H with A (the flags byte). HL is now constructed from the flags and pointer low byte.
5F5F
PUSH BC C5
Save BC (link to next page) onto the stack for later use.
5F60
LD B,(HL) 46
Load B with the byte at (HL), the high byte of the target address in this entry.
5F61
INC HL 23
Increment HL to point to the low byte of the target address.
5F62
LD C,(HL) 4E
Load C with the byte at (HL), the low byte of the target address. BC now contains the target address.
5F63
INC HL 23
Increment HL to point to the flags byte of this entry.
5F64
If Z flag is set (from the CP 64H at 5F51H), jump to 5F7FH. This indicates we've reached the end of the current page.
5F66
BIT 7,(HL) CB 7E
Test bit 7 of the flags byte at (HL). Bit 7 set indicates end of buffer marker.
5F68
If NZ (bit 7 is set), jump to 5F72H to handle the end of buffer condition.

Compare the target address (BC) with the search address (DE).

5F6A
LD A,D 7A
Load A with D, the high byte of the address we're searching for.
5F6B
CP B B8
Compare A (D) with B (high byte of target). Sets flags for address comparison.
5F6C
If NZ (high bytes differ), jump to 5F70H to check the comparison result.
5F6E
LD A,E 7B
Load A with E, the low byte of the search address.
5F6F
CP C B9
Compare A (E) with C (low byte of target). Full 16-bit comparison now complete.
5F70
If carry is clear (DE >= BC, search address >= target), jump to 5F8EH to continue or return match.

Search address is less than current target. Return to previous page and search there.

5F72
POP BC C1
Pop BC from the stack, retrieving the link pointer to the previous buffer page.
5F73
LD HL,(5F2EH) 2A 2E 5F
Load HL with the value at 5F2EH, the saved buffer position from before this entry.
5F76
Jump back to 5F50H to continue the outer loop and search the previous page. [LOOP]

5F78H - Continue Within Page Search

This section continues searching within the current buffer page when more entries exist. It handles the inner loop that scans through entries within a single page.

5F78
INC BC 03
Increment BC to count the number of entries checked (reference counter).
5F79
PUSH BC C5
Save BC (reference count) onto the stack.

[INNER LOOP] Scan through entries within the current page.

5F7A
INC HL 23
Increment HL to move to the next field in the current entry.
5F7B
LD B,(HL) 46
Load B with the byte at (HL), the high byte of an address in the entry.
5F7C
INC HL 23
Increment HL to point to the low byte.
5F7D
LD C,(HL) 4E
Load C with the byte at (HL), the low byte of the address. BC now contains a complete address.
5F7E
INC HL 23
Increment HL to point to the flags byte.
5F7F
LD A,(HL) 7E
Load A with the byte at (HL), the flags byte for this entry.
5F80
RLC A CB 07
Rotate A left through carry. This puts bit 7 (end marker) into the carry flag.
5F82
If carry is set (bit 7 was set, end marker), jump to 5F8EH to handle end of buffer.
5F84
BIT 6,(HL) CB 76
Test bit 6 of the flags byte. Bit 6 indicates a valid entry marker.
5F86
If Z flag is set (bit 6 = 0, not a valid entry boundary), loop back to 5F7AH to continue scanning. [LOOP]

Found a valid entry boundary. Compare addresses.

5F88
LD A,D 7A
Load A with D, the high byte of the search address.
5F89
CP B B8
Compare A (D) with B (high byte of entry address).
5F8A
If NZ (high bytes differ), jump to 5F8EH to evaluate the result.
5F8C
LD A,E 7B
Load A with E, the low byte of the search address.
5F8D
CP C B9
Compare A (E) with C (low byte of entry address). Full comparison complete.

5F8EH - Search Result Handler

This section handles the search result, determining whether to return a match (Z flag), continue searching (NZ flag and continue loop), or indicate not found (NZ flag and exit). On exit: Z flag set if exact match found, NZ if not found. HL points to the entry (if found) or insertion point (if not found). BC contains reference information.

5F8E
POP BC C1
Pop BC from the stack, retrieving the reference count information.
5F8F
RET C D8
If carry is set (search address < entry address), return with NZ flag set. HL points to the insertion point.
5F90
If NZ (addresses not equal), jump back to 5F78H to continue searching. [LOOP]
5F92
RET C9
Return with Z flag set. Exact match found. HL points to the matching entry, BC contains reference count.

5F93H - Reset Page Line Counter and Initialize Label Buffer

This routine resets the page line counter to 64 (40H) and initializes the label buffer structure. It calculates the number of valid entries in the buffer and sets up the page linking structure. The label buffer is organized as a series of 4-byte entries with page headers at xxA0H boundaries. On entry: none. On exit: page counter at 5612H reset to 40H, label buffer structure initialized with entry counts.

5F93
LD A,40H 3E 40
Load A with 40H (64 decimal), the maximum number of entries per page in the label buffer.
5F95
LD (5612H),A 32 12 56
Store 40H to 5612H, resetting the page line counter to 64 entries remaining.
5F98
XOR A AF
XOR A with itself to set A = 0 and set the Z flag. This initializes the entry counter.
5F99
LD HL,6FA0H 21 A0 6F
Load HL with 6FA0H, the label buffer header address. This is the base of the buffer structure.
5F9C
LD D,A 57
Copy A (0) to D, initializing the high byte of the entry count to zero.
5F9D
LD E,A 5F
Copy A (0) to E, initializing the low byte of the entry count to zero. DE = 0.
5F9E
LD B,04H 06 04
Load B with 04H, setting up a 4-iteration loop for bit shifting operations.

5FA0H - Count Valid Entries in Label Buffer

This routine counts the number of valid entries in the label buffer by scanning through the structure and checking flag bits. Valid entries have bit 6 set in their flags byte. On entry: HL points to buffer header, DE = 0 (entry count), B = 4 (shift counter). On exit: DE contains the count of valid entries, A contains a compressed count value.

[OUTER LOOP START] Scan through buffer pages and count entries with bit 6 set.

5FA0
PUSH HL E5
Save HL (current buffer position) onto the stack for later restoration.

[INNER LOOP] Advance through entries checking flag bits.

5FA1
INC HL 23
Increment HL to move to the next byte in the buffer.
5FA2
INC HL 23
Increment HL again (total advance: 2 bytes).
5FA3
INC HL 23
Increment HL again (total advance: 3 bytes). HL now points to the flags byte of an entry.
5FA4
BIT 7,(HL) CB 7E
Test bit 7 of the flags byte at (HL). Bit 7 set indicates end of buffer marker.
5FA6
If NZ (bit 7 is set), jump to 5FAFH to handle end of this page.
5FA8
BIT 6,(HL) CB 76
Test bit 6 of the flags byte. Bit 6 set indicates a valid entry boundary.
5FAA
If Z (bit 6 = 0, not a valid entry), loop back to 5FA1H to continue scanning. [INNER LOOP]
5FAC
INC DE 13
Increment DE to count this valid entry.
5FAD
Jump back to 5FA1H to continue counting. [INNER LOOP]

5FAFH - Process Page Entry Count

This section processes the entry count for the current page by compressing DE into a smaller value through bit shifting. It performs 4 right shifts on DE, accumulating the carry bits into A.

[SHIFT LOOP] Compress the entry count DE by shifting right 4 times.

5FAF
SRL D CB 3A
Shift D right logically. The low bit of D moves into the carry flag, a 0 enters the high bit.
5FB1
RR E CB 1B
Rotate E right through carry. The carry (from D) enters the high bit of E, E's low bit goes to carry.
5FB3
ADC A,A 8F
Add A to itself plus carry (A = A*2 + carry). This accumulates the shifted bits from DE into A.
5FB4
Decrement B and jump back to 5FAFH if not zero. This loops 4 times to shift DE right by 4 bits. [SHIFT LOOP]
5FB6
If Z flag is set (result is zero), jump to 5FB9H to skip the increment.
5FB8
INC DE 13
Increment DE to round up the compressed count value.
5FB9
POP HL E1
Restore HL from the stack (the page start position).
5FBA
INC HL 23
Increment HL to position for storing page data.
5FBB
PUSH DE D5
Save DE (compressed count) onto the stack.
5FBC
LD DE,6F60H 11 60 6F
Load DE with 6F60H, the next page base address (or stack area base).
5FBF
EX DE,HL EB
Exchange DE and HL. HL = 6F60H, DE = buffer position + 1.

5FC0H - Initialize Label Buffer Page Structure

This routine initializes the label buffer page structure by writing the page header (link pointer and flags) and then scanning through to count and process entries. It sets up each 4-byte slot with proper linking.

5FC0
LD BC,0000H 01 00 00
Load BC with 0000H, initializing the link pointer value for page connections.

[PAGE INIT LOOP] Write page header and initialize slots.

5FC3
LD (HL),E 73
Store E (low byte of link) at the current position in the page header.
5FC4
INC HL 23
Increment HL to point to the next byte.
5FC5
LD (HL),D 72
Store D (high byte of link) at the current position.
5FC6
INC HL 23
Increment HL to point to the flags byte position.
5FC7
LD (HL),C 71
Store C (low byte of count/flags) at the current position.
5FC8
INC HL 23
Increment HL to point to the high count byte position.
5FC9
LD (HL),B 70
Store B (high byte of count/flags) at the current position.
5FCA
INC HL 23
Increment HL to point to the next slot.
5FCB
LD A,L 7D
Load A with L, the low byte of the current position.
5FCC
CP A0H FE A0
Compare A with A0H to check if we've reached the end of the page (xxA0H boundary).
5FCE
EXX D9
Exchange register banks (BC/DE/HL with BC'/DE'/HL'). This switches to the alternate register set.
5FCF
POP DE D1
Pop DE from the stack, retrieving the compressed count value.
5FD0
RET Z C8
If Z flag is set (reached end of page), return to the caller. Page initialization is complete.
5FD1
PUSH DE D5
Save DE (compressed count) back onto the stack.
5FD2
LD A,D 7A
Load A with D, the high byte of the count.
5FD3
OR E B3
OR A with E. If both D and E are zero, Z flag is set (count exhausted).
5FD4
DEC DE 1B
Decrement DE, reducing the remaining count.
5FD5
EXX D9
Exchange register banks back to the primary set.
5FD6
If Z flag is set (count was zero before decrement), jump back to 5FC3H to write zeros. [LOOP]

Count is not zero. Read existing entry data and update pointers.

5FD8
INC DE 13
Increment DE by 2 to skip the first 2 bytes of the entry.
5FD9
INC DE 13
Increment DE again (total: +2).
5FDA
LD A,(DE) 1A
Load A with the byte at (DE), reading a flags byte from the existing buffer.
5FDB
RLCA 07
Rotate A left. This puts bit 7 into the carry flag and bit 0.
5FDC
If carry is set (bit 7 was set, end marker), jump to 5FE7H to handle end of entries.

Scan through reference chain until finding a valid boundary (bit 6 set).

5FDE
INC DE 13
Increment DE to move to next byte.
5FDF
INC DE 13
Increment DE again.
5FE0
INC DE 13
Increment DE again (advance by 3 bytes).
5FE1
LD A,(DE) 1A
Load A with the byte at (DE), reading the next flags byte.
5FE2
BIT 6,A CB 77
Test bit 6 of A. Bit 6 indicates a valid entry boundary.
5FE4
If Z (bit 6 = 0, not a boundary), loop back to 5FDEH to continue scanning. [LOOP]
5FE6
INC BC 03
Increment BC to count this valid entry.
5FE7
DEC DE 1B
Decrement DE by 2 to point back to the entry start.
5FE8
DEC DE 1B
Decrement DE again.
5FE9
EXX D9
Exchange register banks to alternate set.
5FEA
Jump back to 5FD2H to continue processing. [OUTER LOOP]

5FECH - Check Mode and Begin Output

This routine checks the current operating mode flags and begins the main disassembly output process. It determines whether to use memory mode or file mode, initializes the screen display, outputs the column header template, and compares the template with the current output format buffer. On entry: disassembly parameters have been configured in variables 55E4H-5613H. On exit: screen initialized and column headers displayed, IX points to label buffer at 6FA0H.

5FEC
LD A,(55EFH) 3A EF 55
Load A with the byte at 55EFH, the mode/option flags. Bit 0=printer, bit 1=show byte count, bit 2=memory mode, bit 4=output file, bit 5=entry point labels.
5FEF
AND 04H E6 04
Isolate bit 2 of the mode flags. Bit 2 set indicates memory mode (disassembling directly from RAM rather than disk file).
5FF1
If NZ (bit 2 set, memory mode active), jump to 6075H to use the simplified memory mode exit which skips file-based label processing.
5FF4
LD A,(55F0H) 3A F0 55
Load A with the byte at 55F0H, the printer state flag. Bit 7=printer active, bit 1=specific printer state.
5FF7
AND 02H E6 02
Isolate bit 1 of the printer state flag. Bit 1 indicates printer requires narrow screen mode initialization.
5FF9
If NZ (bit 1 set), call 5DC6H to initialize narrow screen mode (32 columns) for printer-friendly output formatting.
5FFC
Call 5E07H to fill remaining line with carriage returns, ensuring clean line endings before starting new output section.
5FFF
LD DE,6B1CH 11 1C 6B
Load DE with 6B1CH, the address of the column header template string in the message area. This string contains labels for disassembly output columns.
6002
Call 5D17H to display the null-terminated string at DE followed by carriage return. This outputs the column header line.
6005
Call 5D1AH to output an additional carriage return for spacing between header and data.
6008
LD HL,60D7H 21 D7 60
Load HL with 60D7H, the address of the column template buffer containing "STUVWX PLR" (11 bytes representing column type codes).
600B
LD DE,60E2H 11 E2 60
Load DE with 60E2H, the address of the output format buffer (11 bytes, initialized to spaces). This tracks which columns are active.
600E
LD B,0BH 06 0B
Load B with 0BH (11 decimal), the number of column positions to process in the template comparison loop.
6010
LD C,00H 0E 00
Load C with 00H, initializing the non-space column counter to zero. This counts how many columns differ from spaces.

[LOOP START] Compare template columns with output buffer to identify active columns.

6012
LD A,(DE) 1A
Load A with the byte at (DE), reading a character from the output format buffer at 60E2H.
6013
CP 20H FE 20
Compare A with 20H (ASCII space). If not a space, this column has been activated.
6015
If NZ (output buffer has non-space), jump to 6024H to skip column output - column is already active.
6017
CP (HL) BE
Compare A (space from buffer) with the byte at (HL) from the column template. Checks if template also has a space.
6018
If Z (both are spaces), jump to 6024H to skip - neither has active content for this column.

Template has a column code but output buffer has space - output the column code with separator.

601A
LD A,(HL) 7E
Load A with the byte at (HL), the column type code from the template (e.g., 'S', 'T', 'U', 'V', 'W', 'X', 'P', 'L', 'R').
601B
Call 5D47H to output the column code character in A with line width management.
601E
INC C 0C
Increment C, the active column counter, to track how many columns were output.
601F
LD A,2CH 3E 2C
Load A with 2CH (ASCII comma) as a column separator character.
6021
Call 5D47H to output the comma separator after the column code.
6024
INC HL 23
Increment HL to point to the next byte in the column template buffer.
6025
INC DE 13
Increment DE to point to the next byte in the output format buffer.
6026
Decrement B and jump back to 6012H if not zero. [LOOP] Process all 11 column positions.

After loop: C contains count of active columns that were output.

6028
LD A,C 79
Load A with C, the count of active columns that were output.
6029
OR A B7
Perform OR A to set flags based on the column count. Z flag set if no columns were output.
602A
If Z (no columns output), jump to 6032H to skip the column separator message.
602C
LD DE,6C40H 11 40 6C
Load DE with 6C40H, the address of a column separator/label message in the message area.
602F
Call 5D17H to display the column separator message with trailing carriage return.
6032
Call 5D1AH to output a carriage return for line spacing.
6035
LD IX,6FA0H DD 21 A0 6F
Load IX with 6FA0H, the address of the label buffer header. IX will be used as an index register for label buffer traversal.
6039
LD HL,5564H 21 64 55
Load HL with 5564H, the address of the 64-byte input buffer. This will be used for output line construction.
603C
Jump to 60ADH to begin the main label buffer processing loop.

603EH - User Interaction Handler

This routine handles user interaction during label output, allowing the user to pause, continue, or exit. It compares the current output position with the input buffer start, displays output if needed, then waits for user keypress. Pressing 'X' exits, 'P' enters printer pause mode. On entry: DE preserved on stack contains current label address. On exit: DE restored, input buffer cleared with spaces.

603E
PUSH DE D5
Save DE (current label address being processed) onto the stack for later restoration.
603F
LD DE,5564H 11 64 55
Load DE with 5564H, the address of the input buffer for comparison with current output position.
6042
Call 5EA9H to compare HL with DE. This checks if the current output position (HL) differs from buffer start (5564H).
6045
LD B,L 45
Load B with L, saving the low byte of the comparison result (offset into buffer).
6046
If NZ (output position differs from buffer start), call 5D3AH to output B characters from the buffer.
6049
Call 5CE0H to wait for and read a keyboard character. The character is returned in A (uppercase converted).
604C
CP 58H FE 58
Compare A with 58H (ASCII X). This checks if user pressed X to exit.
604E
If Z (user pressed X), jump to 5CF2H to restart the program from the beginning.
6051
CP 50H FE 50
Compare A with 50H (ASCII P). This checks if user pressed P for printer pause mode.
6053
If NZ (not P), jump to 6061H to continue without entering printer pause mode.

[PRINTER PAUSE LOOP] User pressed P - wait for X (exit) or ENTER (continue).

6055
Call 5CD2H to read another keyboard character while in printer pause mode.
6058
CP 58H FE 58
Compare A with 58H (ASCII X) to check for exit request.
605A
If Z (user pressed X), jump to 5CF2H to restart the program.
605D
CP 0DH FE 0D
Compare A with 0DH (carriage return/ENTER). This checks if user pressed ENTER to continue.
605F
If NZ (not ENTER), loop back to 6055H to keep waiting in printer pause mode. [LOOP]
6061
Call 5E9CH to initialize the input buffer with spaces (64 bytes at 5564H), clearing it for next output.
6064
POP DE D1
Restore DE from the stack, recovering the current label address being processed.
6065
RET C9
Return to the caller to continue label processing.

6066H - Process Label Entry with End Check

This routine processes a label buffer entry, first calling the user interaction handler, then checking if the end of the label buffer has been reached. If at end, it displays "NO MORE LABELS" and exits. Otherwise, it continues to process the label entry. On entry: IX points to current position in label buffer at 6FA0H area. On exit: either exits program (if end of labels) or continues processing.

6066
Call 603EH, the user interaction handler, to allow user to pause, continue (any key), or exit (X). DE is preserved.
6069
BIT 7,(IX+00H) DD CB 00 7E
Test bit 7 of the byte at (IX+0), the flags byte of current label entry. Bit 7 set indicates end of label buffer.
606D
If Z (bit 7 not set, not at end), jump to 6078H to continue processing this label entry.

End of label buffer reached - display message and exit.

606F
LD DE,6C20H 11 20 6C
Load DE with 6C20H, the address of the "NO MORE LABELS" message string in the message area.
6072
Call 5D17H to display the "NO MORE LABELS" message with trailing carriage return.
6075
Jump to 5CFDH, the program exit/restart handler. This prompts the user to restart or exit the disassembler.

6078H - Skip Empty Columns in Label Entry

This routine scans through the label entry to skip columns that are marked as empty (space characters) in the output format buffer. It uses IY to index into the format buffer at 60E2H and advances IX through the label buffer entries. On entry: IX points to current label entry, bit 7 of (IX+0) is not set. On exit: IX advanced past empty columns, processing continues at 60ADH or 6098H.

6078
LD IY,60E2H FD 21 E2 60
Load IY with 60E2H, the address of the output format buffer (11 bytes tracking active columns).
607C
LD B,00H 06 00
Load B with 00H, initializing the high byte of an offset calculation to zero.
607E
LD A,20H 3E 20
Load A with 20H (ASCII space), the value to compare against in the format buffer.

[LOOP START] Check if current column is empty and should be skipped.

6080
LD C,(IX+03H) DD 4E 03
Load C with the byte at (IX+3), the column index/offset stored in the label entry. BC now contains the offset.
6083
ADD IY,BC FD 09
Add BC (column offset) to IY. IY now points to the specific column in the format buffer.
6085
CP (IY+00H) FD BE 00
Compare A (space, 20H) with the byte at (IY+0), the column value in format buffer.
6088
If NZ (column is not a space, meaning it's active), jump to 6098H to process this column.

Column is empty (space) - advance to next entry in label buffer.

608A
INC IX DD 23
Increment IX to advance through the label buffer entry (first byte).
608C
INC IX DD 23
Increment IX again (second byte).
608E
INC IX DD 23
Increment IX again (third byte). IX has advanced by 3 bytes total.
6090
BIT 6,(IX+03H) DD CB 03 76
Test bit 6 of the byte at (IX+3), checking if this is a valid entry boundary in the label buffer.
6094
If Z (bit 6 not set, not a boundary), jump back to 6078H to continue checking columns. [LOOP]
6096
Jump to 60ADH to process the next label entry (found a valid boundary).

6098H - Output Label Address and Check Buffer Position

This routine outputs the current label address using the hex conversion routine, then checks if the output buffer position has exceeded the available space. If so, it triggers user interaction. On entry: IX points to current label entry. On exit: HL advanced by 2, processing continues at 60ADH or loops back.

6098
Call 669BH, the hex address output routine. This converts and outputs the current address in standard hex format.
609B
INC HL 23
Increment HL (output buffer pointer) to advance past the first output byte.
609C
INC HL 23
Increment HL again to advance past the second output byte.
609D
LD DE,559FH 11 9F 55
Load DE with 559FH, a buffer boundary address used to check if output has exceeded available space.
60A0
Call 5EA9H to compare HL with DE. This checks if current output position exceeds the boundary.
60A3
ADD HL,DE 19
Add DE back to HL to restore HL (5EA9H modified it during comparison).
60A4
If the sign flag is set (result is negative, meaning HL < boundary), jump to 60ADH to continue processing.

Output buffer near full - trigger user interaction and reset buffer pointer.

60A7
Call 603EH, the user interaction handler, to display current buffer and wait for user input.
60AA
LD HL,556AH 21 6A 55
Load HL with 556AH, resetting the output buffer pointer to a position within the secondary work buffer area.

60ADH - Main Label Buffer Traversal Loop

This is the main loop that traverses through the label buffer, extracting target addresses and checking entry flags. It reads each label entry's address and determines whether to process it or continue to the next entry. On entry: IX points to current position in label buffer. On exit: loops through entries calling 6066H for valid entries, or continues scanning.

60AD
INC IX DD 23
Increment IX to move to the next byte in the label buffer structure.
60AF
LD D,(IX+00H) DD 56 00
Load D with the byte at (IX+0), the high byte of the target address for this label entry.
60B2
INC IX DD 23
Increment IX to move to the next byte.
60B4
LD E,(IX+00H) DD 5E 00
Load E with the byte at (IX+0), the low byte of the target address. DE now contains the complete target address.
60B7
INC IX DD 23
Increment IX to move to the flags byte position.
60B9
BIT 6,(IX+00H) DD CB 00 76
Test bit 6 of the byte at (IX+0), the flags byte. Bit 6 set indicates a valid entry boundary.
60BD
If NZ (bit 6 set, valid boundary), jump to 6066H to process this label entry with user interaction.

Not a valid boundary - check column mapping and continue.

60BF
LD B,00H 06 00
Load B with 00H, initializing the high byte of an offset to zero.
60C1
LD C,(IX+00H) DD 4E 00
Load C with the byte at (IX+0), the column offset/index for this reference. BC is the offset.
60C4
PUSH HL E5
Save HL (current output buffer position) onto the stack.
60C5
LD HL,60E2H 21 E2 60
Load HL with 60E2H, the address of the output format buffer.
60C8
ADD HL,BC 09
Add BC (column offset) to HL. HL now points to the specific column in the format buffer.
60C9
LD A,(HL) 7E
Load A with the byte at (HL), the column value from the format buffer.
60CA
CP 20H FE 20
Compare A with 20H (space). Checks if this column is empty/inactive.
60CC
POP HL E1
Restore HL (output buffer position) from the stack.
60CD
If Z (column is space, inactive), jump to 609BH to advance and continue without outputting.

Column is active - output the address and store the column code.

60CF
PUSH AF F5
Save AF (column code in A) onto the stack for later use.
60D0
Call 669BH to output the address in DE as hex to the current output position.
60D3
POP AF F1
Restore AF, recovering the column code in A.
60D4
LD (HL),A 77
Store the column code in A to the output buffer at position (HL).
60D5
Jump to 609BH to advance output position and continue the loop.

60D7H - Column Template Data Table

This is a DATA section containing an 11-byte column template buffer. The template contains single-character codes representing different output columns: S=Source, T=Target, U=Unknown, V=Virtual, W=Work, X=eXit, P=Print, L=Label, R=Reference. The disassembler uses this to format output into aligned columns.

DATA: 11-byte column template "STUVWX PLR" - column type identifiers

60D7
DEFB 53H 53
DATA: ASCII 'S' (53H) - Source column identifier.
60D8
DEFB 54H 54
DATA: ASCII 'T' (54H) - Target column identifier.
60D9
DEFB 55H 55
DATA: ASCII 'U' (55H) - column U identifier.
60DA
DEFB 56H 56
DATA: ASCII 'V' (56H) - Virtual address column identifier.
60DB
DEFB 57H 57
DATA: ASCII 'W' (57H) - Work column identifier.
60DC
DEFB 58H 58
DATA: ASCII 'X' (58H) - column X identifier.
60DD
DEFB 20H 20
DATA: ASCII space (20H) - unused column position.
60DE
DEFB 20H 20
DATA: ASCII space (20H) - unused column position.
60DF
DEFB 50H 50
DATA: ASCII 'P' (50H) - Print/Printer column identifier.
60E0
DEFB 4CH 4C
DATA: ASCII 'L' (4CH) - Label column identifier.
60E1
DEFB 52H 52
DATA: ASCII 'R' (52H) - Reference column identifier.

60E2H - Output Format Buffer

This is a DATA section containing an 11-byte output format buffer, initialized to spaces. During operation, this buffer is updated to track which columns are active for the current disassembly pass. Each byte position corresponds to the same position in the column template at 60D7H.

DATA: 11-byte output format buffer - initialized to spaces (20H)

60E2
DEFB 20H,20H,20H,20H 20 20 20 20
DATA: Four space bytes (20H) - format buffer positions 0-3, initially inactive.
60E6
DEFB 20H,20H,20H,20H 20 20 20 20
DATA: Four space bytes (20H) - format buffer positions 4-7, initially inactive.
60EA
DEFB 20H,20H,20H 20 20 20
DATA: Three space bytes (20H) - format buffer positions 8-10, initially inactive.

60EDH - Entry Point Bitmap Marker

This byte appears to be part of the initialization sequence, storing the entry point bitmap flag value.

60ED
DEFB 20H 20
DATA: Space byte or initialization marker.

60EEH - Initialize Disassembly Engine

This routine initializes the main disassembly engine by setting up the entry point bitmap, clearing work buffers, outputting the virtual base address, and initializing various state variables. It prepares for the main disassembly loop. On entry: A may contain FFH from restart path (618AH). On exit: state variables initialized, stack pointer saved, ready to begin disassembly.

60EE
LD (55F1H),A 32 F1 55
Store A to 55F1H, the entry point bitmap variable. This tracks which entry points have been processed.
60F1
LD HL,55A4H 21 A4 55
Load HL with 55A4H, the address of the secondary work buffer (64 bytes for line construction).
60F4
LD B,40H 06 40
Load B with 40H (64 decimal), the buffer size in bytes to clear.

[LOOP START] Clear the secondary work buffer with spaces.

60F6
LD (HL),20H 36 20
Store 20H (ASCII space) at the current buffer position (HL).
60F8
INC HL 23
Increment HL to point to the next buffer position.
60F9
Decrement B and jump back to 60F6H if not zero. [LOOP] Clears all 64 bytes.
60FB
LD HL,55A6H 21 A6 55
Load HL with 55A6H, an offset within the secondary work buffer where address output begins.
60FE
LD DE,(55E5H) ED 5B E5 55
Load DE with the 16-bit value at 55E5H, the virtual base address for disassembly.
6102
PUSH DE D5
Save DE (virtual base address) onto the stack for later use.
6103
Call 669BH to output the virtual base address in hex to the work buffer at HL.
6106
LD A,(55EFH) 3A EF 55
Load A with the byte at 55EFH, the mode/option flags.
6109
AND 21H E6 21
Isolate bits 0 and 5 (21H mask). Bit 0=printer mode, bit 5=entry point labels enabled.
610B
CP 20H FE 20
Compare result with 20H. Z flag set if bit 5 is set but bit 0 is clear (entry point labels without printer).
610D
POP DE D1
Restore DE (virtual base address) from the stack.
610E
LD A,02H 3E 02
Load A with 02H, a label type indicator value.
6110
LD HL,55B5H 21 B5 55
Load HL with 55B5H, the label output position within the work buffer.
6113
If Z flag is set (entry point labels enabled, no printer), call 66C1H to generate a label for this address.
6116
LD A,02H 3E 02
Load A with 02H, the initial value for the processing counter.
6118
LD (5610H),A 32 10 56
Store 02H to 5610H, initializing a counter/state variable for disassembly passes.
611B
XOR A AF
XOR A with itself to set A = 0.
611C
LD (560FH),A 32 0F 56
Store 00H to 560FH, clearing the processing state flag.
611F
LD (560EH),A 32 0E 56
Store 00H to 560EH, clearing another processing state variable.

6122H - Save State and Begin Disassembly Pass

This routine saves the current stack pointer and initializes the address pointers for a disassembly pass. It copies the virtual and real base addresses to working variables and saves key state on the stack for potential restart. On entry: state variables at 55E5H-560FH configured. On exit: SP saved at 6187H, addresses copied to working locations, state saved on stack.

6122
LD (6187H),SP ED 73 87 61
Store the current stack pointer value to 6187H. This allows restoration if the disassembly needs to restart.
6126
LD HL,(55E5H) 2A E5 55
Load HL with the 16-bit value at 55E5H, the virtual base address.
6129
LD (55EBH),HL 22 EB 55
Store HL to 55EBH, initializing the current disassembly address to the virtual base.
612C
PUSH HL E5
Save HL (virtual base address) onto the stack for potential restart restoration.
612D
LD HL,(55E7H) 2A E7 55
Load HL with the 16-bit value at 55E7H, the real base address.
6130
LD (55EDH),HL 22 ED 55
Store HL to 55EDH, initializing the working real address copy.
6133
PUSH HL E5
Save HL (real base address) onto the stack for potential restart.
6134
LD HL,(560BH) 2A 0B 56
Load HL with the 16-bit value at 560BH, the byte count remaining.
6137
PUSH HL E5
Save HL (byte count) onto the stack for potential restart.
6138
LD HL,(55F6H) 2A F6 55
Load HL with the 16-bit value at 55F6H, the label buffer pointer.
613B
PUSH HL E5
Save HL (label buffer pointer) onto the stack for potential restart.
613C
LD (618BH),SP ED 73 8B 61
Store the current stack pointer to 618BH. This captures the state after pushing all restart data.
6140
LD HL,55ABH 21 AB 55
Load HL with 55ABH, an offset in the secondary work buffer for output construction.
6143
LD (5609H),HL 22 09 56
Store HL to 5609H, setting the output pointer variable.
6146
LD HL,55C5H 21 C5 55
Load HL with 55C5H, another work buffer offset for instruction output.
6149
Call 61A2H, the main opcode decoder routine, to begin disassembling the current instruction.

614CH - Check Processing State and Build ASCII Display

This routine checks if processing should continue after decoding an instruction, then builds the ASCII representation of the disassembled bytes for display. It reads bytes from the real address and converts them to printable characters (replacing control characters with dots). On entry: 61A2H has returned from decoding, 560FH contains processing state. On exit: ASCII display built at 55D3H, or jumps to restart path.

614C
LD A,(560FH) 3A 0F 56
Load A with the byte at 560FH, the processing state flag. Non-zero indicates restart needed.
614F
OR A B7
Perform OR A to set flags based on the processing state value.
6150
If NZ (processing state non-zero), jump to 618AH to restore state and restart the disassembly pass.

Processing continues normally. Build ASCII representation of disassembled bytes.

6153
LD DE,(55EDH) ED 5B ED 55
Load DE with the 16-bit value at 55EDH, the working real address pointing to the actual bytes in memory.
6157
LD HL,55D3H 21 D3 55
Load HL with 55D3H, the address of the ASCII display buffer within the work area.
615A
LD A,(5613H) 3A 13 56
Load A with the byte at 5613H, the initialization/page flag (used here as character limit for ASCII display).
615D
LD C,A 4F
Copy A to C, saving the character limit for comparison.
615E
LD A,(55E7H) 3A E7 55
Load A with the low byte of 55E7H (real base address low byte), used to calculate byte count.
6161
SUB E 93
Subtract E (low byte of working real address) from A. Result is offset/byte count.
6162
LD B,A 47
Copy result to B, setting the loop counter for number of bytes to display.

[LOOP START] Convert each byte to printable ASCII or dot.

6163
LD A,(DE) 1A
Load A with the byte at (DE), reading the next instruction byte from memory.
6164
CP 20H FE 20
Compare A with 20H (space). If A < 20H, it's a control character.
6166
INC DE 13
Increment DE to point to the next byte in memory.
6167
If carry set (A < 20H, control character), jump to 616CH to substitute a dot.
6169
CP C B9
Compare A with C (upper limit from 5613H). If A >= C, it's beyond printable range.
616A
If carry set (A < C, within printable range), jump to 616EH to store the character.
616C
LD A,2EH 3E 2E
Load A with 2EH (ASCII dot/period) to substitute for non-printable characters.
616E
LD (HL),A 77
Store the character (original or dot) to the ASCII display buffer at (HL).
616F
INC HL 23
Increment HL to point to the next position in the display buffer.
6170
Decrement B and jump back to 6163H if not zero. [LOOP] Process all instruction bytes.

6172H - Check Entry Point Label and Finalize Output

This routine checks if entry point labels are enabled and formats the output line accordingly. If bit 7 is set in the entry point bitmap, it checks for trailing '8' characters and replaces them with spaces. On entry: ASCII display complete, 55F1H contains entry point bitmap. On exit: output line finalized, returns via self-modified SP at 6187H.

6172
LD A,(55F1H) 3A F1 55
Load A with the byte at 55F1H, the entry point bitmap tracking processed entry points.
6175
OR A B7
Perform OR A to set flags based on the bitmap value.
6176
If Z (bitmap is zero, no entry points marked), jump to 6186H to skip label processing.
6178
LD HL,55A4H 21 A4 55
Load HL with 55A4H, the address of the secondary work buffer containing the output line.
617B
Call 66A0H to process the output line (format adjustment or output routine).
617E
DEC HL 2B
Decrement HL to point to the previous character in the buffer.
617F
LD A,(HL) 7E
Load A with the byte at (HL), reading the last output character.
6180
CP 38H FE 38
Compare A with 38H (ASCII '8'). Checks for a specific trailing character pattern.
6182
If NZ (character is not '8'), jump to 6186H to skip the replacement.
6184
LD (HL),20H 36 20
Store 20H (space) to (HL), replacing the trailing '8' with a space for cleaner output.
6186
LD SP,0000H 31 00 00
Load SP with 0000H. SELF-MODIFYING: The operand at 6187H is modified at runtime to contain the saved stack pointer from 6122H.
6189
RET C9
Return to the caller using the restored stack pointer, resuming execution after the CALL 61A2H at 6149H.

618AH - Restore State for Restart

This routine restores the saved state from the stack when a restart is required during disassembly. It pops the saved values (label buffer pointer, byte count, real address, virtual address) and restores them to their respective variables, then jumps back to 60EEH to reinitialize. On entry: 560FH was non-zero indicating restart needed. On exit: state restored, jumps to 60EEH with A=FFH.

618A
LD SP,0000H 31 00 00
Load SP with 0000H. SELF-MODIFYING: The operand at 618BH is modified at runtime to contain the saved stack pointer from 613CH.
618D
POP HL E1
Pop HL from the stack, retrieving the saved label buffer pointer.
618E
LD (55F6H),HL 22 F6 55
Store HL to 55F6H, restoring the label buffer pointer variable.
6191
POP HL E1
Pop HL from the stack, retrieving the saved byte count remaining.
6192
LD (560BH),HL 22 0B 56
Store HL to 560BH, restoring the byte count variable.
6195
POP HL E1
Pop HL from the stack, retrieving the saved real base address.
6196
LD (55E7H),HL 22 E7 55
Store HL to 55E7H, restoring the real base address variable.
6199
POP HL E1
Pop HL from the stack, retrieving the saved virtual base address.
619A
LD (55E5H),HL 22 E5 55
Store HL to 55E5H, restoring the virtual base address variable.
619D
LD A,FFH 3E FF
Load A with FFH, setting the restart indicator value for the entry point bitmap.
619F
Jump to 60EEH to reinitialize the disassembly engine with A=FFH marking this as a restart pass.

61A2H - Main Opcode Decoder

This is the main opcode decoder entry point. It first checks for entry point label mode, then fetches the next opcode byte and routes it to the appropriate decoder based on its value range. Opcodes are divided into ranges: 00H-3FH (miscellaneous), 40H-7FH (LD r,r' and HALT), 80H-BFH (arithmetic/logic), and C0H-FFH (control/extended). On entry: HL points to output position in work buffer at 55C5H, 55F1H contains entry point bitmap. On exit: instruction decoded and output, processing continues or restarts.

61A2
LD A,(55F1H) 3A F1 55
Load A with the byte at 55F1H, the entry point bitmap. Non-zero indicates entry point labels are being generated.
61A5
OR A B7
Perform OR A to set flags based on the bitmap value.
61A6
If NZ (entry point labels active), jump to 626DH to handle entry point label mode which outputs special formatting.
61A9
Call 6592H to fetch the next opcode byte from the source (memory or disk) and advance the address pointers.
61AC
LD (560DH),A 32 0D 56
Store the fetched opcode to 560DH, the current opcode storage variable for later reference during decoding.
61AF
CP 40H FE 40
Compare A with 40H. If A < 40H, it's in the miscellaneous opcode range (00H-3FH).
61B1
If carry set (opcode < 40H), jump to 61EAH to decode miscellaneous opcodes (NOP, LD, INC, DEC, etc.).
61B4
CP C0H FE C0
Compare A with C0H. If A >= C0H, it's in the control/extended range (C0H-FFH).
61B6
If no carry (opcode >= C0H), jump to 62F3H to decode control opcodes (RET, JP, CALL, RST, prefix bytes).
61B9
CP 80H FE 80
Compare A with 80H. If A < 80H, it's in the LD r,r' / HALT range (40H-7FH).
61BB
If no carry (opcode >= 80H), jump to 61D4H to decode arithmetic/logic opcodes (80H-BFH).

61BDH - Decode LD r,r' Instructions (40H-7FH)

This section decodes the LD r,r' register-to-register load instructions (opcodes 40H-7FH), with special handling for HALT (76H). The source and destination registers are extracted from the opcode bits. On entry: A contains opcode in range 40H-7FH (excluding 76H which is handled separately). On exit: LD instruction decoded and output.

61BD
LD DE,6886H 11 86 68
Load DE with 6886H, the address of the "LD " mnemonic string in the instruction lookup table.
61C0
CP 76H FE 76
Compare A with 76H (the HALT opcode). HALT is a special case in the LD r,r' range.
61C2
If Z (opcode is 76H), jump to 67CEH to output "HALT" instead of a LD instruction.
61C5
Call 67CBH to output the "LD " mnemonic from the address in DE.
61C8
Call 673BH to decode and output the destination register (bits 3-5 of the opcode).
61CB
Call 655CH to output a comma separator between operands.
61CE
Call 674EH to decode and output the source register (bits 0-2 of the opcode).
61D1
Jump to 6559H to finalize the instruction output and return to the main loop.

61D4H - Decode Arithmetic/Logic Instructions (80H-BFH)

This section decodes the arithmetic and logic instructions (ADD, ADC, SUB, SBC, AND, XOR, OR, CP) that operate on register A with another register. The operation type is determined by bits 3-5 of the opcode. On entry: A contains opcode in range 80H-BFH. On exit: arithmetic/logic instruction decoded and output.

61D4
Call 673BH to decode and output the operation mnemonic based on bits 3-5 (ADD, ADC, SUB, SBC, AND, XOR, OR, CP).
61D7
Call 67A3H to output "A," prefix for operations that explicitly show the accumulator as first operand.
61DA
LD A,(560DH) 3A 0D 56
Load A with the byte at 560DH, reloading the current opcode for further bit testing.
61DD
CP 90H FE 90
Compare A with 90H. Opcodes below 90H (80H-8FH) are ADD/ADC which need special "A," formatting.
61DF
If carry (opcode < 90H), jump to 61E5H to check if "A," prefix is needed.
61E1
SUB 98H D6 98
Subtract 98H from A. This adjusts opcode for SBC range check (98H-9FH are SBC r).
61E3
CP 08H FE 08
Compare result with 08H. If A < 08H after subtraction, it was an SBC instruction which also needs "A," prefix.
61E5
If carry (ADD, ADC, or SBC), call 6752H to output "A," prefix before the source register.
61E8
Jump to 61D1H to output the source register and finalize the instruction.

61EAH - Decode Miscellaneous Opcodes (00H-3FH)

This section decodes the miscellaneous opcodes in the 00H-3FH range using bit testing to determine the specific instruction type. This range includes NOP, LD instructions, INC, DEC, JR, DJNZ, and various other instructions. The opcode bits are tested individually to route to the correct handler. On entry: A contains opcode in range 00H-3FH. On exit: instruction decoded via appropriate sub-handler.

61EA
BIT 0,A CB 47
Test bit 0 of A. If set, the opcode is odd, indicating certain instruction types.
61EC
If NZ (bit 0 set, odd opcode), jump to 62A9H to decode odd-numbered miscellaneous opcodes.
61EF
BIT 1,A CB 4F
Test bit 1 of A. If set, opcode has bit pattern xx1x (02H, 06H, 0AH, etc.).
61F1
If NZ (bit 1 set), jump to 624BH to decode LD (BC/DE),A and similar instructions.
61F3
BIT 2,A CB 57
Test bit 2 of A. If set, opcode is in pattern xx1xx (04H, 0CH, 14H, etc.).
61F5
If NZ (bit 2 set), jump to 6242H to decode INC/DEC register instructions.
61F7
BIT 5,A CB 6F
Test bit 5 of A. If set, opcode is 20H or higher in this even-bit0 group.
61F9
If NZ (bit 5 set), jump to 6225H to decode JR and conditional JR instructions.
61FB
BIT 3,A CB 5F
Test bit 3 of A. If set, opcode is 08H, 10H, or 18H in this pattern.
61FD
If NZ (bit 3 set), jump to 6233H to decode EX AF,AF' and DJNZ type instructions.

Remaining cases: NOP (00H) or DJNZ (10H).

61FF
LD DE,686AH 11 6A 68
Load DE with 686AH, the address of the "NOP" mnemonic string in the lookup table.
6202
BIT 4,A CB 67
Test bit 4 of A. If clear and other bits were clear, this is NOP (00H).
6204
If Z (bit 4 clear, opcode is 00H), jump to 67CEH to output "NOP".

Bit 4 is set (opcode 10H): this is DJNZ instruction.

6207
LD DE,6866H 11 66 68
Load DE with 6866H, the address of the "DJNZ" mnemonic string.
620A
Call 67CEH to output "DJNZ" mnemonic.
620D
Call 6592H to fetch the next byte (the relative displacement for DJNZ).
6210
LD B,00H 06 00
Load B with 00H, initializing the high byte for sign extension of the displacement.
6212
LD DE,(55E5H) ED 5B E5 55
Load DE with the 16-bit value at 55E5H, the virtual base address for calculating the target.
6216
OR A B7
Perform OR A to set flags. The sign flag reflects bit 7 of A (negative displacement if set).
6217
If the sign flag is clear (positive displacement), jump to 621BH to skip negative extension.
621A
DEC B 05
Decrement B to FFH, sign-extending the negative displacement to 16 bits.
621B
ADD A,E 83
Add E (low byte of virtual address) to A (displacement). Result is low byte of target.
621C
LD E,A 5F
Copy the result to E.
621D
LD A,D 7A
Load A with D (high byte of virtual address).
621E
ADC A,B 88
Add B (sign extension, 00H or FFH) to A with carry. Result is high byte of target.
621F
LD D,A 57
Copy the result to D. DE now contains the complete target address.
6220
LD A,0AH 3E 0A
Load A with 0AH, a label type indicator for DJNZ targets.
6222
Jump to 665CH to output the target address and add it to the label buffer.

6225H - Decode JR Instructions (20H-3FH with bit 5 set)

This section decodes the JR (Jump Relative) family of instructions: JR e (18H), JR NZ,e (20H), JR Z,e (28H), JR NC,e (30H), and JR C,e (38H). It outputs the mnemonic, then calls the displacement calculator routine used by DJNZ. On entry: A contains opcode with bit 5 set (in 20H-3FH range). On exit: JR instruction decoded with target address calculated.

6225
Call 6703H to decode and output the condition code (NZ, Z, NC, C) based on bits 3-4 of the opcode. For unconditional JR (18H), no condition is output.
6228
Call 674EH to output any additional formatting or comma separator after the condition code.
622B
LD DE,685AH 11 5A 68
Load DE with 685AH, the address of the "JR " mnemonic string in the lookup table.
622E
Call 67CEH to output "JR " mnemonic to the output buffer.
6231
Jump to 620DH to fetch the displacement byte and calculate the target address (shared code with DJNZ).

6233H - Decode EX AF,AF' and Related (08H-18H with bit 3 set)

This section handles opcodes with bit 3 set in the low nibble, including EX AF,AF' (08H) and instructions that need the lookup table at 6C92H. On entry: A contains opcode with bit 3 set. On exit: instruction decoded and output.

6233
BIT 4,A CB 67
Test bit 4 of A. This distinguishes between different sub-groups of opcodes.
6235
If NZ (bit 4 set, opcode 18H = JR unconditional), jump back to 622BH to handle as a JR instruction.
6237
LD DE,6C92H 11 92 6C
Load DE with 6C92H, the address of a secondary mnemonic lookup table for special instructions like EX AF,AF'.
623A
LD B,06H 06 06
Load B with 06H, specifying 6 bytes per entry in the lookup table.
623C
Call 6815H to look up and output the instruction from the table at DE with B-byte entries.
623F
Jump to 67BCH to finalize the output and return to the main decoder loop.

6242H - Decode INC/DEC Register (04H, 0CH, etc.)

This section decodes INC r and DEC r instructions for 8-bit registers (opcodes with bit 2 set in the 00H-3FH range). On entry: A contains opcode with bit 2 set. On exit: INC or DEC instruction decoded with register operand.

6242
Call 67C1H to decode and output the INC/DEC mnemonic based on opcode bits.
6245
Call 673BH to decode and output the register operand from bits 3-5 of the opcode.
6248
Jump to 655CH to finalize the instruction and return to the main loop.

624BH - Decode LD (BC/DE),A and Related (02H, 0AH, etc.)

This section decodes various instructions with bit 1 set, including LD (BC),A, LD (DE),A, LD A,(BC), LD A,(DE), and related memory access instructions. The specific instruction is determined by further bit testing. On entry: A contains opcode with bit 1 set. On exit: instruction decoded and output.

624B
Call 67CBH to output a preliminary mnemonic (typically "LD").
624E
LD A,(560DH) 3A 0D 56
Load A with the byte at 560DH, reloading the current opcode for further bit analysis.
6251
BIT 2,A CB 57
Test bit 2 of A. Distinguishes LD immediate from LD memory indirect.
6253
If NZ (bit 2 set), jump to 6279H to handle LD r,n (immediate) instructions.
6255
BIT 3,A CB 5F
Test bit 3 of A. Distinguishes between register pairs.
6257
If NZ (bit 3 set), jump to 6263H to handle LD A,(DE) or related.
6259
BIT 5,A CB 6F
Test bit 5 of A. Further distinguishes instruction types.
625B
If NZ (bit 5 set), jump to 6287H to handle LD (nn),A or LD A,(nn) direct addressing.
625D
Call 67D9H to output "(BC)" or "(DE)" register pair indirect addressing.
6260
Jump to 6760H to complete the instruction with accumulator operand.

6263H - Continue LD (DE),A / LD A,(DE) Decoding

This section continues decoding for instructions involving the DE register pair with indirect addressing.

6263
BIT 5,A CB 6F
Test bit 5 of A to determine the exact instruction variant.
6265
If NZ (bit 5 set), jump to 629AH to handle LD (nn),HL or LD HL,(nn).
6267
Call 6752H to output "A," prefix for accumulator as destination.
626A
Jump to 67D9H to output the indirect addressing and complete the instruction.

626DH - Entry Point Label Mode Handler

This routine handles the special entry point label generation mode. When the entry point bitmap (55F1H) is non-zero, this path is taken instead of normal disassembly. It outputs a special label format and adjusts the mnemonic pointer. On entry: 55F1H is non-zero. On exit: entry point label output, returns to normal disassembly mode.

626D
XOR A AF
XOR A with itself to set A = 0 and clear flags.
626E
LD (55F1H),A 32 F1 55
Store 00H to 55F1H, clearing the entry point bitmap to exit entry point label mode.
6271
LD DE,68A2H 11 A2 68
Load DE with 68A2H, the address of a special label format string in the mnemonic table.
6274
Call 67CEH to output the label format string.
6277
Jump to 6282H to set the return type and exit.

6279H - LD r,n Immediate Load Decoder

Handles opcodes 06H, 0EH, 16H, 1EH, 26H, 2EH, 36H, 3EH (LD B/C/D/E/H/L/(HL)/A,n). Extracts the destination register from bits 3-5 of the opcode, outputs the mnemonic "LD", then the register name, followed by a comma and the immediate byte value in hex. The immediate value is fetched and formatted as a 2-digit hex operand.

6279
C5 C5
PUSH BC - Save Register BC (contains opcode byte in C) onto the stack.
627A
CD3B67 CD 3B 67
GOSUB to 673BH to decode and output the destination register name (from bits 3-5 of opcode). Register name is output to the disassembly line.
627D
CD5C65 CD 5C 65
GOSUB to 655CH to output a comma separator between the register operand and the immediate value.
6280
CD9265 CD 92 65
GOSUB to 6592H to fetch the next byte from the source (the immediate value n).
6283
C1 C1
POP BC - Restore Register BC from the stack.
6284
C33867 C3 38 67
JUMP to 6738H to format and output the immediate byte value as a 2-digit hex number, then finalize the instruction.

6287H - LD (nn),A Direct Store Accumulator

Handles opcode 32H (LD (nn),A). Outputs the mnemonic "LD", followed by the 16-bit address in parentheses (fetched as next two bytes), then comma, then "A". This stores the accumulator to the specified memory address. The address is added to the label buffer for cross-referencing.

6287
113368 11 33 68
Point Register Pair DE to address 6833H (mnemonic table entry for "LD").
628A
CDCB67 CD CB 67
GOSUB to 67CBH to output the mnemonic "LD" from the table.
628D
CD5C66 CD 5C 66
GOSUB to 665CH to output the target address in parentheses and add it to the label buffer. The address is fetched as the next two bytes (low, high) from the source.
6290
CD5C65 CD 5C 65
GOSUB to 655CH to output a comma separator.
6293
C3A367 C3 A3 67
JUMP to 67A3H to output "A" and finalize the instruction.

6296H - LD A,(nn) Direct Load Accumulator

Handles opcode 3AH (LD A,(nn)). Outputs the mnemonic "LD", then "A", followed by comma, then the 16-bit address in parentheses. This loads the accumulator from the specified memory address. The address is added to the label buffer for cross-referencing.

6296
113368 11 33 68
Point Register Pair DE to address 6833H (mnemonic table entry for "LD").
6299
CDCB67 CD CB 67
GOSUB to 67CBH to output the mnemonic "LD" from the table.
629C
CDA367 CD A3 67
GOSUB to 67A3H to output "A" as the destination register.
629F
CD5C65 CD 5C 65
GOSUB to 655CH to output a comma separator.
62A2
C35C66 C3 5C 66
JUMP to 665CH to output the source address in parentheses, add it to the label buffer, and finalize the instruction.

62A5H - LD (nn),HL Direct Store HL

Handles opcode 22H (LD (nn),HL). Outputs the mnemonic "LD", followed by the 16-bit address in parentheses, comma, then "HL". This stores the HL register pair to the specified memory address. The address is added to the label buffer.

62A5
113368 11 33 68
Point Register Pair DE to address 6833H (mnemonic table entry for "LD").
62A8
CDCB67 CD CB 67
GOSUB to 67CBH to output the mnemonic "LD" from the table.
62AB
CD5C66 CD 5C 66
GOSUB to 665CH to output the target address in parentheses and add it to the label buffer.
62AE
CD5C65 CD 5C 65
GOSUB to 655CH to output a comma separator.
62B1
115468 11 54 68
Point Register Pair DE to address 6854H (string "HL" in register name table).
62B4
C3CE67 C3 CE 67
JUMP to 67CEH to output the string "HL" and finalize the instruction.

62B7H - LD HL,(nn) Direct Load HL

Handles opcode 2AH (LD HL,(nn)). Outputs the mnemonic "LD", then "HL", followed by comma, then the 16-bit address in parentheses. This loads the HL register pair from the specified memory address. The address is added to the label buffer.

62B7
113368 11 33 68
Point Register Pair DE to address 6833H (mnemonic table entry for "LD").
62BA
CDCB67 CD CB 67
GOSUB to 67CBH to output the mnemonic "LD" from the table.
62BD
115468 11 54 68
Point Register Pair DE to address 6854H (string "HL" in register name table).
62C0
CDCE67 CD CE 67
GOSUB to 67CEH to output the string "HL" as the destination.
62C3
CD5C65 CD 5C 65
GOSUB to 655CH to output a comma separator.
62C6
C35C66 C3 5C 66
JUMP to 665CH to output the source address in parentheses, add it to the label buffer, and finalize the instruction.

62C9H - LD SP,HL Load Stack Pointer

Handles opcode F9H (LD SP,HL). Outputs the mnemonic "LD", followed by "SP", comma, then "HL". This instruction copies the value in HL to the stack pointer register.

62C9
113368 11 33 68
Point Register Pair DE to address 6833H (mnemonic table entry for "LD").
62CC
CDCB67 CD CB 67
GOSUB to 67CBH to output the mnemonic "LD" from the table.
62CF
115868 11 58 68
Point Register Pair DE to address 6858H (string "SP" in register name table).
62D2
CDCE67 CD CE 67
GOSUB to 67CEH to output the string "SP" as the destination.
62D5
CD5C65 CD 5C 65
GOSUB to 655CH to output a comma separator.
62D8
115468 11 54 68
Point Register Pair DE to address 6854H (string "HL" in register name table).
62DB
C3CE67 C3 CE 67
JUMP to 67CEH to output the string "HL" as the source and finalize the instruction.

62DEH - LD rr,nn 16-bit Immediate Load

Handles opcodes 01H, 11H, 21H, 31H (LD BC/DE/HL/SP,nn). Extracts the destination register pair from bits 4-5 of the opcode, outputs "LD", the register pair name, comma, then the 16-bit immediate value. The register pair decoder at 6744H handles BC/DE/HL/SP decoding. The immediate word is fetched low byte first, then high byte, and formatted as a 4-digit hex address.

62DE
113368 11 33 68
Point Register Pair DE to address 6833H (mnemonic table entry for "LD").
62E1
CDCB67 CD CB 67
GOSUB to 67CBH to output the mnemonic "LD" from the table.
62E4
CD4467 CD 44 67
GOSUB to 6744H to decode and output the destination register pair name (BC, DE, HL, or SP from bits 4-5 of opcode in Register C).
62E7
CD5C65 CD 5C 65
GOSUB to 655CH to output a comma separator.
62EA
CD9265 CD 92 65
GOSUB to 6592H to fetch the low byte of the immediate 16-bit value into Register A.
62ED
67 67
Load Register H with the value in Register A (store low byte temporarily in H).
62EE
CD9265 CD 92 65
GOSUB to 6592H to fetch the high byte of the immediate 16-bit value into Register A.
62F1
6F 6F
Load Register L with the value in Register A (now HL contains the full 16-bit immediate value with H=high, L=low).
62F2
1814 18 14
JUMP RELATIVE forward 14H (20 decimal) bytes to 6308H to format and output the 16-bit value in HL as a hex address.

62F3H - Control Flow Opcode Decoder (C0H-FFH Range)

This section handles opcodes in the C0H-FFH range, which includes RET, POP, JP, CALL, PUSH, RST, and prefix bytes (CB, DD, ED, FD). Entry: A holds the opcode byte. Exit: Mnemonic and operands stored in output buffer, control returns to main decoder.

62F3
FE C9 FE C9
Compare Register A (current opcode) against C9H (RET instruction). If A = C9H, the Z FLAG is set; otherwise the NZ FLAG is set.
62F5
If the Z FLAG (Zero) has been set (meaning opcode = C9H = RET), JUMP to 6408H to handle the RET instruction (simple mnemonic output, no operands).
62F8
AND 07H E6 07
Mask Register A to keep only bits 0-2 (the lower 3 bits of the opcode). This isolates the register/condition code portion of instructions like POP rp, PUSH rp, RET cc, JP cc, CALL cc.
62FA
LD C,A 4F
Store the masked value (bits 0-2 of opcode) into Register C for later use as an index.
62FB
LD A,(55F8H) 3A F8 55
Load Register A with the current opcode byte from temporary storage at 55F8H (the original unmasked opcode).
62FE
CP E9H FE E9
Compare Register A against E9H (JP (HL) instruction). If A = E9H, the Z FLAG is set; otherwise the NZ FLAG is set.
6300
If the Z FLAG has been set (meaning opcode = E9H = JP (HL)), JUMP to 6425H to handle the JP (HL) instruction with special operand formatting.
6303
CP D9H FE D9
Compare Register A against D9H (EXX instruction). If A = D9H, the Z FLAG is set; otherwise the NZ FLAG is set.
6305
If the Z FLAG has been set (meaning opcode = D9H = EXX), JUMP to 6408H to handle the EXX instruction (simple mnemonic, no operands).
6308
CP E3H FE E3
Compare Register A against E3H (EX (SP),HL instruction). If A = E3H, the Z FLAG is set; otherwise the NZ FLAG is set.
630A
If the Z FLAG has been set (meaning opcode = E3H = EX (SP),HL), JUMP to 6433H to handle this instruction with special (SP) operand formatting.
630D
CP EBH FE EB
Compare Register A against EBH (EX DE,HL instruction). If A = EBH, the Z FLAG is set; otherwise the NZ FLAG is set.
630F
If the Z FLAG has been set (meaning opcode = EBH = EX DE,HL), JUMP to 643BH to handle this instruction with both register operands.
6312
CP F9H FE F9
Compare Register A against F9H (LD SP,HL instruction). If A = F9H, the Z FLAG is set; otherwise the NZ FLAG is set.
6314
If the Z FLAG has been set (meaning opcode = F9H = LD SP,HL), JUMP to 6447H to handle the LD SP,HL instruction.

[POP/PUSH Register Pair Check - opcodes C1H/C5H/D1H/D5H/E1H/E5H/F1H/F5H]

6317
AND C7H E6 C7
Mask Register A to keep bits 7, 6, 2, 1, 0 (pattern 11000111). This checks for POP/PUSH instructions which have pattern 11xx01x1.
6319
CP C1H FE C1
Compare Register A against C1H (POP BC pattern after masking). If A = C1H, the Z FLAG is set; otherwise the NZ FLAG is set.
631B
If the Z FLAG has been set (meaning this is a POP rp instruction), JUMP to 6454H to handle POP with register pair operand from bits 4-5.
631E
CP C5H FE C5
Compare Register A against C5H (PUSH BC pattern after masking). If A = C5H, the Z FLAG is set; otherwise the NZ FLAG is set.
6320
If the Z FLAG has been set (meaning this is a PUSH rp instruction), JUMP to 645FH to handle PUSH with register pair operand from bits 4-5.

[RST Instruction Check - opcodes C7H/CFH/D7H/DFH/E7H/EFH/F7H/FFH]

6323
LD A,(55F8H) 3A F8 55
Reload Register A with the original opcode byte from 55F8H (needed because we've been modifying A).
6326
AND C7H E6 C7
Mask Register A to keep bits 7, 6, 2, 1, 0. RST instructions have pattern 11xxx111.
6328
CP C7H FE C7
Compare Register A against C7H (RST pattern after masking). If A = C7H, the Z FLAG is set; otherwise the NZ FLAG is set.
632A
If the Z FLAG has been set (meaning this is an RST n instruction), JUMP to 646AH to handle RST with the restart address calculated from bits 3-5.

[Prefix Byte Check - CB/DD/ED/FD opcodes]

632D
LD A,(55F8H) 3A F8 55
Reload Register A with the original opcode byte from 55F8H once again.
6330
CP CBH FE CB
Compare Register A against CBH (CB prefix for bit manipulation instructions). If A = CBH, the Z FLAG is set; otherwise the NZ FLAG is set.
6332
If the Z FLAG has been set (meaning opcode = CBH), JUMP to 647EH to handle CB-prefixed instructions (bit manipulation).
6335
CP DDH FE DD
Compare Register A against DDH (DD prefix for IX register instructions). If A = DDH, the Z FLAG is set; otherwise the NZ FLAG is set.
6337
If the Z FLAG has been set (meaning opcode = DDH), JUMP to 6551H to handle DD-prefixed instructions (IX register operations).
633A
CP EDH FE ED
Compare Register A against EDH (ED prefix for extended instructions). If A = EDH, the Z FLAG is set; otherwise the NZ FLAG is set.
633C
If the Z FLAG has been set (meaning opcode = EDH), JUMP to 655BH to handle ED-prefixed instructions (block operations, I/O, etc.).
633F
CP FDH FE FD
Compare Register A against FDH (FD prefix for IY register instructions). If A = FDH, the Z FLAG is set; otherwise the NZ FLAG is set.
6341
If the Z FLAG has been set (meaning opcode = FDH), JUMP to 6551H to handle FD-prefixed instructions (IY register operations, shares handler with DD).

[Conditional RET Check - opcodes C0H/C8H/D0H/D8H/E0H/E8H/F0H/F8H]

6344
LD A,(55F8H) 3A F8 55
Reload Register A with the original opcode byte from 55F8H.
6347
AND C7H E6 C7
Mask Register A to isolate bits 7, 6, 2, 1, 0. Conditional RET instructions have pattern 11xxx000.
6349
CP C0H FE C0
Compare Register A against C0H (RET cc pattern after masking). If A = C0H, the Z FLAG is set; otherwise the NZ FLAG is set.
634B
If the Z FLAG has been set (meaning this is a conditional RET instruction like RET NZ/RET Z/etc.), JUMP to 6478H to handle RET with condition code.

[Conditional JP Check - opcodes C2H/CAH/D2H/DAH/E2H/EAH/F2H/FAH]

634E
LD A,(55F8H) 3A F8 55
Reload Register A with the original opcode byte from 55F8H.
6351
AND C7H E6 C7
Mask Register A to keep bits 7, 6, 2, 1, 0. Conditional JP instructions have pattern 11xxx010.
6353
CP C2H FE C2
Compare Register A against C2H (JP cc,nnnn pattern after masking). If A = C2H, the Z FLAG is set; otherwise the NZ FLAG is set.
6355
If the Z FLAG has been set (meaning this is a conditional JP instruction like JP NZ,nnnn), JUMP to 648FH to handle JP with condition code and 16-bit address operand.

[Unconditional JP Check - opcode C3H]

6358
LD A,(55F8H) 3A F8 55
Reload Register A with the original opcode byte from 55F8H.
635B
CP C3H FE C3
Compare Register A against C3H (JP nnnn instruction). If A = C3H, the Z FLAG is set; otherwise the NZ FLAG is set.
635D
If the Z FLAG has been set (meaning opcode = C3H = JP nnnn), JUMP to 649EH to handle unconditional JP with 16-bit address operand.

[Conditional CALL Check - opcodes C4H/CCH/D4H/DCH/E4H/ECH/F4H/FCH]

6360
AND C7H E6 C7
Mask Register A to keep bits 7, 6, 2, 1, 0. Conditional CALL instructions have pattern 11xxx100.
6362
CP C4H FE C4
Compare Register A against C4H (CALL cc,nnnn pattern after masking). If A = C4H, the Z FLAG is set; otherwise the NZ FLAG is set.
6364
If the Z FLAG has been set (meaning this is a conditional CALL instruction like CALL NZ,nnnn), JUMP to 64B0H to handle CALL with condition code and address operand.

[Unconditional CALL Check - opcode CDH]

6367
LD A,(55F8H) 3A F8 55
Reload Register A with the original opcode byte from 55F8H.
636A
CP CDH FE CD
Compare Register A against CDH (CALL nnnn instruction). If A = CDH, the Z FLAG is set; otherwise the NZ FLAG is set.
636C
If the Z FLAG has been set (meaning opcode = CDH = CALL nnnn), JUMP to 64BFH to handle unconditional CALL with 16-bit address operand.

[IN/OUT Instruction Check - opcodes D3H/DBH]

636F
CP D3H FE D3
Compare Register A against D3H (OUT (n),A instruction). If A = D3H, the Z FLAG is set; otherwise the NZ FLAG is set.
6371
If the Z FLAG has been set (meaning opcode = D3H = OUT (n),A), JUMP to 64D1H to handle OUT instruction with port number and A register.
6374
CP DBH FE DB
Compare Register A against DBH (IN A,(n) instruction). If A = DBH, the Z FLAG is set; otherwise the NZ FLAG is set.
6376
If the Z FLAG has been set (meaning opcode = DBH = IN A,(n)), JUMP to 64E4H to handle IN instruction with A register and port number.

[Immediate Operand Arithmetic - opcodes C6H/CEH/D6H/DEH/E6H/EEH/F6H/FEH]

6379
LD A,(55F8H) 3A F8 55
Reload Register A with the original opcode byte from 55F8H.
637C
AND C7H E6 C7
Mask Register A to keep bits 7, 6, 2, 1, 0. Immediate arithmetic instructions have pattern 11xxx110.
637E
CP C6H FE C6
Compare Register A against C6H (arithmetic with immediate operand pattern). If A = C6H, the Z FLAG is set; otherwise the NZ FLAG is set.
6380
If the Z FLAG has been set (meaning this is an immediate arithmetic instruction like ADD A,n / ADC A,n / SUB n / etc.), JUMP to 64F7H to handle the operation with 8-bit immediate operand.

[If none of the above patterns matched, this is an unrecognized opcode - should not happen with valid Z80 code]

6383
JUMP to 678DH (likely an error handler or default case for unrecognized opcodes in the C0H-FFH range).

6386H - Build Label Reference in Output Buffer

This routine formats a label reference by outputting 'L' followed by the 4-digit hex address. Used when an instruction references a memory location that should be represented as a label rather than a raw address. Entry: DE holds the target address. Exit: Label formatted in output buffer.

6386
GOSUB to 669BH to output the hex address in DE as a 4-character string to the output buffer.
6389
LD A,4CH 3E 4C
Load Register A with 4CH (ASCII 'L' character) to prepend to the address for label format.
638B
LD (HL),A 77
Store the 'L' character into the output buffer at the position pointed to by HL (the start of the hex address just written).
638C
INC HL 23
INCrement HL to point to the next position in the output buffer (past the 'L').
638D
INC HL 23
INCrement HL again.
638E
INC HL 23
INCrement HL again.
638F
INC HL 23
INCrement HL again. After these 4 INC operations, HL points past the complete label (L + 4 hex digits).
6390
RET C9
RETURN to caller with label formatted in output buffer.

6391H - Fetch Next Byte and Convert to Hex String

This routine fetches the next byte from the instruction stream and converts it to a 2-character hex string in the output buffer. Used for immediate 8-bit operands. Entry: Instruction pointer set up. Exit: A holds the fetched byte, 2-character hex representation in output buffer at HL.

6391
GOSUB to 6592H to fetch the next byte from the instruction stream (reads from memory or disk based on mode) and store it in Register A.
6394
GOSUB to 66A0H to convert the byte in Register A to a 2-character hex string and store it in the output buffer at position HL.
6397
JUMP to 6799H to continue with output processing (likely adds the hex string to the operand field).

639AH - Fetch 16-bit Address and Format as Label or Hex

This routine fetches a 16-bit address (low byte first, then high byte) from the instruction stream and formats it for output. If the address is in the valid range for labeling, formats as "Lxxxx". Otherwise formats as raw hex "xxxxH". Entry: Instruction pointer set up. Exit: DE holds the 16-bit address, formatted representation in output buffer.

639A
GOSUB to 6592H to fetch the low byte of the 16-bit address from the instruction stream into Register A.
639D
LD E,A 5F
Store the low byte into Register E.
639E
GOSUB to 6592H again to fetch the high byte of the 16-bit address into Register A.
63A1
LD D,A 57
Store the high byte into Register D. Now DE holds the complete 16-bit address.
63A2
GOSUB to 66B6H to check if the address in DE should be represented as a label (within valid code range) or as raw hex.
63A5
GOSUB to 5EB2H to add this address reference to the label buffer (for cross-reference tracking).
63A8
LD A,D 7A
Load Register A with the high byte of the address from Register D.
63A9
CP A0H FE A0
Compare Register A against A0H. If the high byte >= A0H, this address is in the high memory region. If A >= A0H, the NO CARRY FLAG is set; otherwise the CARRY FLAG is set.
63AB
If the NO CARRY FLAG has been set (high byte >= A0H), GOSUB to 6795H to handle special formatting for high memory addresses (or perhaps mark them differently).
63AE
GOSUB to 6386H to build the label reference (Lxxxx format) in the output buffer.
63B1
JUMP to 678DH to finalize the output and continue with disassembly processing.

63B4H - LD BC,nn Immediate Load Decoder

Handles opcode 01H - Load Register Pair BC with 16-bit immediate value. Fetches the next two bytes from the source code stream and outputs them as the immediate operand. Entry: Register A contains opcode 01H. Exit: Mnemonic "LD BC," output with 16-bit immediate value formatted as hex.

63B4
If the Z FLAG (Zero) has been set (meaning this is the first pass through the disassembly engine), JUMP to 61A9H to begin processing this instruction normally. The value in Register A (01H) was just stored into memory location 560FH (processing state flag) to indicate that the disassembly engine has been initialized.
63B7
If execution reaches here (NZ FLAG set, meaning this is a continuation of processing), JUMP to 618AH to restore the saved state and continue disassembly. This happens when the code needs to output the operand portion of a CB-prefixed instruction after first outputting the CB prefix itself.

63BAH - Handle RET Conditional Instructions (C0H-C7H, C8H-CFH, D0H-D7H, D8H-DFH, E0H-E7H, E8H-EFH, F0H-F7H, F8H-FFH)

This section processes RET conditional instructions and RST restart instructions. Entry: Register A contains the current opcode (already stored at 560DH). The opcode has bit 0 set (indicating it's in the C1H-FFH range with odd first nibble). Exit: Instruction has been formatted and output, control returns to main disassembly loop.

63BA
BIT 2,A CB 57
Test bit 2 of the current opcode (held in Register A). If bit 2 is set, this indicates opcodes in the range C4H-C7H, CCH-CFH, D4H-D7H, DCH-DFH, E4H-E7H, ECH-EFH, F4H-F7H, or FCH-FFH (CALL conditional and RST instructions).
63BC
JR NZ,6414H 20 56
If the NZ FLAG (Not Zero) has been set (meaning bit 2 is set in the opcode), JUMP ahead to 6414H to handle CALL conditional instructions and RST restart instructions.

[RET CONDITIONAL PATH] - Opcodes C0H, C8H, D0H, D8H, E0H, E8H, F0H, F8H (RET with condition codes)

63BE
BIT 3,A CB 5F
Test bit 3 of the current opcode. If bit 3 is set, this indicates opcodes in the range C8H-CFH, D8H-DFH, E8H-EFH, or F8H-FFH.
63C0
JR NZ,63ECH 20 2A
If the NZ FLAG (Not Zero) has been set (meaning bit 3 is set), JUMP ahead to 63ECH to handle additional instruction variants.

[OPCODES C0H, D0H, E0H, F0H] - RET NZ, RET NC, RET PO, RET P

63C2
BIT 5,A CB 6F
Test bit 5 of the current opcode. This distinguishes between the four remaining RET conditional opcodes: C0H (RET NZ), D0H (RET NC), E0H (RET PO), F0H (RET P).
63C4
JR NZ,63D6H 20 10
If the NZ FLAG (Not Zero) has been set (meaning bit 5 is set - opcodes E0H or F0H), JUMP ahead to 63D6H to handle RET PO or RET P.

[OPCODES C0H, D0H] - RET NZ or RET NC

63C6
BIT 4,A CB 67
Test bit 4 of the current opcode. This distinguishes between C0H (RET NZ) and D0H (RET NC).
63C8
If the Z FLAG (Zero) has been set (meaning bit 4 is clear - opcode C0H), JUMP to 6321H to output the RET instruction with condition code and finalize the instruction.

[OPCODE D0H] - RET NC

63CB
LD A,05H 3E 05
Load Register A with 05H. This is a table index that will be used to look up and output the mnemonic "RET" followed by the condition code "NC" (No Carry).
63CD
GOSUB to 6672H to output the mnemonic using the table index in Register A (05H for RET with condition code processing).
63D0
GOSUB to 6760H to output the actual register or condition code operand.
63D3
JUMP to 67B2H to finalize the instruction output and return to the main disassembly loop.

63D6H - Handle RET PO or RET P (Opcodes E0H, F0H)

This section handles RET instructions with parity/sign condition codes. Entry: Register A contains opcode E0H (RET PO) or F0H (RET P). Exit: Instruction formatted and output.

63D6
LD DE,6947H 11 47 69
Point Register Pair DE to 6947H, which contains the mnemonic text "RET" in the instruction lookup table.
63D9
BIT 4,A CB 67
Test bit 4 of the current opcode (held in Register A). This distinguishes between E0H (RET PO, bit 4 clear) and F0H (RET P, bit 4 set).
63DB
If the NZ FLAG (Not Zero) has been set (meaning bit 4 is set - opcode F0H for RET P), JUMP to 67CEH to output the "RET" mnemonic pointed to by DE, then continue with condition code processing.

[OPCODE E0H] - RET PO (Parity Odd)

63DE
GOSUB to 67BCH to finalize and output the current instruction (RET PO).
63E1
LD A,03H 3E 03
Load Register A with 03H. This is a formatting code or table index used by the next routine.
63E3
GOSUB to 67E0H to perform additional formatting or output processing based on the value 03H in Register A.
63E6
GOSUB to 674EH to decode and output the source register or operand.
63E9
JUMP to 67FCH to complete the instruction formatting and return to the main disassembly loop.

63ECH - Handle RET Z, RET C, RET PE, RET M (Opcodes C8H, D8H, E8H, F8H)

This section processes RET instructions with the alternate set of condition codes (Z, C, PE, M). Entry: Register A contains the current opcode with bit 3 set. Exit: Instruction output complete.

63EC
BIT 5,A CB 6F
Test bit 5 of the current opcode. This distinguishes between opcodes C8H/D8H (bit 5 clear) and E8H/F8H (bit 5 set).
63EE
JR NZ,6400H 20 10
If the NZ FLAG (Not Zero) has been set (meaning bit 5 is set - opcodes E8H or F8H), JUMP ahead to 6400H to handle RET PE or RET M.

[OPCODES C8H, D8H] - RET Z or RET C

63F0
BIT 4,A CB 67
Test bit 4 of the current opcode. This distinguishes between C8H (RET Z, bit 4 clear) and D8H (RET C, bit 4 set).
63F2
If the Z FLAG (Zero) has been set (meaning bit 4 is clear - opcode C8H), JUMP to 641FH to handle the RET Z instruction.

[OPCODE D8H] - RET C (Return if Carry)

63F5
GOSUB to 6752H to output the "A," prefix or perform related operand formatting for this instruction type.
63F8
LD A,01H 3E 01
Load Register A with 01H. This is a table index or formatting code for the RET C instruction.
63FA
GOSUB to 6672H to output the mnemonic using the table index in Register A.
63FD
JUMP to 67B7H to finalize the instruction and return to the main disassembly loop.

6400H - Handle RET PE or RET M (Opcodes E8H, F8H)

This section handles RET instructions with parity even (PE) or minus (M) condition codes. Entry: Register A contains opcode E8H or F8H. Exit: Instruction formatted and output.

6400
LD DE,694BH 11 4B 69
Point Register Pair DE to 694BH, which contains mnemonic text in the instruction lookup table (likely "RET" or a related string).
6403
BIT 4,A CB 67
Test bit 4 of the current opcode. This distinguishes between E8H (RET PE, bit 4 clear) and F8H (RET M, bit 4 set).
6405
If the NZ FLAG (Not Zero) has been set (meaning bit 4 is set - opcode F8H for RET M), JUMP to 67CEH to output the mnemonic string pointed to by Register Pair DE.

[OPCODE E8H] - RET PE (Return if Parity Even)

6408
GOSUB to 67BCH to finalize and output the RET PE instruction.
640B
GOSUB to 67E8H to perform additional instruction formatting or operand processing.
640E
GOSUB to 674EH to decode and output the source register or operand.
6411
JUMP to 67ECH to complete the instruction formatting and return to the main disassembly loop.

6414H - CB Prefix Handler - Bit Manipulation and Rotate/Shift Instructions

This section handles all CB-prefixed Z80 instructions (bit operations, rotates, shifts). Entry: A contains the CB-prefixed opcode byte. The routine decodes the opcode bits to determine the specific operation and operand register.

6414
LD A,B 78
Load Register A with the value from Register B. Register B contains the CB-prefixed opcode byte that needs to be decoded.
6415
AND 07H E6 07
Mask off bits 7-3, leaving only bits 2-0 in Register A. These three bits (000-111) identify which register the CB operation targets: B, C, D, E, H, L, (HL), or A.
6417
LD C,A 4F
Save the register code (0-7) into Register C for later use in selecting the target register name.
6418
LD A,B 78
Reload Register A with the full CB opcode byte from Register B.
6419
AND 38H E6 38
Mask to isolate bits 5-3 of the opcode. These three bits determine the operation type: RLC, RRC, RL, RR, SLA, SRA, SLL, SRL for opcodes 00H-3FH, or the bit number (0-7) for BIT/RES/SET instructions (opcodes 40H-FFH).
641B
RRCA 0F
Rotate Register A right through carry. This shifts bits 5-3 down to positions 2-0, effectively dividing the masked value by 8.
641C
RRCA 0F
Rotate Register A right through carry again.
641D
RRCA 0F
Rotate Register A right through carry a third time. After three rotations, bits 5-3 of the original opcode are now in bits 2-0 of Register A, giving a value 0-7.
641E
LD E,A 5F
Store the operation type/bit number (0-7) into Register E for later use.
641F
LD A,B 78
Reload Register A with the full CB opcode byte from Register B once more.
6420
AND C0H E6 C0
Mask to isolate bits 7-6 of the opcode. These two bits determine the instruction class: 00=Rotate/Shift (00H-3FH), 01=BIT (40H-7FH), 10=RES (80H-BFH), 11=SET (C0H-FFH).
6422
JP Z,6476H CA 76 64
If bits 7-6 are both 0 (Z FLAG set), this is a Rotate/Shift instruction (00H-3FH range). JUMP to 6476H to handle RLC, RRC, RL, RR, SLA, SRA, SLL, SRL instructions.

[BIT/RES/SET INSTRUCTION PATH] - Execution continues here for CB opcodes 40H-FFH (BIT, RES, SET instructions). Register E contains the bit number (0-7), Register C contains the target register code (0-7).

6425
CP 40H FE 40
Compare Register A (which holds bits 7-6 of the opcode, shifted to bits 7-6 position) against 40H. If Register A equals 40H, this is a BIT instruction (opcodes 40H-7FH). The Z FLAG will be set if true.
6427
LD HL,681CH 21 1C 68
Point Register Pair HL to address 681CH, which is the start of the Z80 mnemonic lookup table. This table contains the ASCII text for instruction names.
642A
LD BC,0004H 01 04 00
Load Register Pair BC with 0004H. This is the offset within the mnemonic table to the "BIT" instruction mnemonic (each table entry is 4 bytes).
642D
JP Z,6447H CA 47 64
If the Z FLAG is set (meaning this is a BIT instruction), JUMP to 6447H to output the "BIT" mnemonic and operands.
6430
INC BC 03
INCrement Register Pair BC from 0004H to 0005H. This points to the next mnemonic in the table.
6431
CP 80H FE 80
Compare Register A against 80H. If Register A equals 80H, this is a RES (reset bit) instruction (opcodes 80H-BFH). The Z FLAG will be set if true.
6433
JP Z,6447H CA 47 64
If the Z FLAG is set (meaning this is a RES instruction), JUMP to 6447H to output the "RES" mnemonic (BC now points to offset 0005H in the mnemonic table).
6436
INC BC 03
INCrement Register Pair BC from 0005H to 0006H. This points to the "SET" mnemonic in the table (opcodes C0H-FFH are SET instructions by elimination).

[COMMON BIT/RES/SET OUTPUT PATH] - At this point, BC points to the correct mnemonic offset (0004H for BIT, 0005H for RES, 0006H for SET), Register E contains the bit number (0-7), and Register C contains the target register code (0-7).

6447
ADD HL,BC 09
ADD the mnemonic offset in Register Pair BC to the table base address in Register Pair HL. Register Pair HL now points to the start of the correct mnemonic string (BIT, RES, or SET).
6448
CALL 67CEH CD CE 67
GOSUB to 67CEH to output the mnemonic string pointed to by Register Pair HL. This displays "BIT", "RES", or "SET" followed by a space.
644B
LD A,E 7B
Load Register A with the bit number (0-7) from Register E. This is the bit position that will be tested (BIT), reset (RES), or set (SET).
644C
ADD A,30H C6 30
ADD 30H to Register A to convert the binary bit number (0-7) to its ASCII digit equivalent ('0'-'7'). This converts 0→'0', 1→'1', ..., 7→'7'.
644E
CALL 5D47H CD 47 5D
GOSUB to 5D47H to output the ASCII character in Register A (the bit number '0'-'7') to the screen and/or printer.
6451
CALL 655CH CD 5C 65
GOSUB to 655CH to output a comma separator character between the bit number and the register operand.
6454
LD A,C 79
Load Register A with the register code (0-7) from Register C. This identifies which register is the target: 0=B, 1=C, 2=D, 3=E, 4=H, 5=L, 6=(HL), 7=A.
6455
CALL 674EH CD 4E 67
GOSUB to 674EH to output the register name corresponding to the code in Register A. This displays "B", "C", "D", "E", "H", "L", "(HL)", or "A".
6458
JP 6559H C3 59 65
JUMP to 6559H to finalize the instruction output and return to the main disassembly loop. The complete instruction now reads like "BIT 3,E" or "RES 7,(HL)" or "SET 0,B".

6476H - Rotate and Shift Instructions (CB 00H-3FH)

Handles CB-prefixed rotate and shift instructions: RLC, RRC, RL, RR, SLA, SRA, SLL (undocumented), SRL. Entry: Register E contains operation type (0-7), Register C contains target register code (0-7).

6476
LD HL,681CH 21 1C 68
Point Register Pair HL to address 681CH, the start of the Z80 mnemonic lookup table containing ASCII instruction names.
6479
LD D,00H 16 00
Load Register D with 00H to prepare Register Pair DE as a 16-bit offset. Register E already contains the operation type (0-7) from earlier decoding.
647B
ADD HL,DE 19
ADD the operation type offset in Register Pair DE to the table base in Register Pair HL. Each mnemonic entry is 4 bytes, so this calculation gives: HL = 681CH + (operation_type). Since operation_type is 0-7, this points to one of the first 8 entries in the mnemonic table.

The operation type in Register E maps to these mnemonics: 0=RLC, 1=RRC, 2=RL, 3=RR, 4=SLA, 5=SRA, 6=SLL (undocumented shift left logical), 7=SRL.

647C
CALL 67CEH CD CE 67
GOSUB to 67CEH to output the mnemonic string pointed to by Register Pair HL. This displays the rotate or shift instruction name (RLC, RRC, RL, RR, SLA, SRA, SLL, or SRL) followed by a space.
647F
LD A,C 79
Load Register A with the target register code (0-7) from Register C. This identifies which register receives the rotate/shift operation.
6480
CALL 674EH CD 4E 67
GOSUB to 674EH to output the register name for the code in Register A. This completes the instruction, displaying something like "RLC B" or "SRL (HL)" or "RL E".
6483
JP 6559H C3 59 65
JUMP to 6559H to finalize the instruction output and return to the main disassembly loop.

6487H - ED/DD/FD Prefix Handler - Load Mnemonic String Pointer

This code handles opcodes with the ED, DD, or FD prefix bytes (values A0H-BFH after subtracting A0H). The routine adjusts the opcode value and loads a pointer to the appropriate mnemonic string for output. Register A contains the adjusted opcode value (00H-1FH after adjustment), and Register DE is loaded with the address of the mnemonic string table at 68E6H.

6487
LD DE,68E6H 11 E6 68
Load Register DE with 68E6H, the base address of the ED/DD/FD prefix mnemonic string table
648A
JUMP to 67A6H to output the mnemonic string from the table at 68E6H using the adjusted opcode value in Register A as the index, then return to finalize the instruction

648DH - CB Prefix Handler - Bit Operation Decoder

This section handles CB-prefixed opcodes (bit manipulation instructions). Entry point from 6475H when bit 7 of the opcode (stored in 560DH) is clear, indicating a CB prefix opcode in the range 40H-7FH. The code tests various bits to decode the specific operation and operands.

648D
BIT 6,A CB 77
Test bit 6 of Register A (the current opcode value stored in 560DH). If bit 6 is 0 (opcodes 00H-3FH: shift/rotate operations), the Z FLAG is set; if bit 6 is 1 (opcodes 40H-7FH or C0H-FFH: BIT/RES/SET operations), the NZ FLAG is set
648F
If the Z FLAG is set (bit 6 is 0, indicating shift/rotate operations), JUMP to 64E0H to handle those opcodes as invalid (should not reach here in normal flow)

[BIT/RES/SET Operations Path] - Opcode has bit 6 set, indicating BIT, RES, or SET instruction

6491
BIT 2,A CB 57
Test bit 2 of Register A (the current opcode value). Bit 2 being set indicates this is a RES or SET instruction rather than a BIT instruction
6493
If the NZ FLAG is set (bit 2 is 1), JUMP to 6502H to handle RES/SET instructions which use a different mnemonic table

[BIT Instruction Path] - Bit 2 is 0, this is a BIT instruction

6495
BIT 1,A CB 4F
Test bit 1 of Register A (the current opcode value). Bit 1 determines the specific BIT instruction variant
6497
If the NZ FLAG is set (bit 1 is 1), JUMP to 64C6H to handle BIT instructions with bit 1 set (opcodes 4AH, 4BH, 4EH, 4FH, etc.)
6499
BIT 0,A CB 47
Test bit 0 of Register A (the current opcode value). Bit 0 determines the final operand format
649B
If the NZ FLAG is set (bit 0 is 1), JUMP to 64B0H to handle BIT instructions with bit 0 set (odd opcodes: 41H, 45H, 49H, etc.)

649DH - BIT Instruction Handler - Even Opcodes with Bits 1,0 Clear

Handles BIT instructions where bits 1 and 0 are both clear (opcodes 40H, 44H, 48H, 4CH, etc.). These are BIT n,r instructions where the destination register is decoded from bits 3-5 of the opcode.

649D
CALL 673BH to decode the destination register (from bits 3-5 of the opcode stored in 560DH) and store the result in Register A. Returns with A containing the register index (0-7)
64A0
CP 06H FE 06
Compare Register A with 06H. If A equals 06H (indicating register code 110 = (HL) indirect addressing), the Z FLAG is set; otherwise the NZ FLAG is set
64A2
If the Z FLAG is set (register is (HL) indirect), JUMP to 64AAH to output the bit number and (HL) operand without a comma separator

[Register Direct Path] - Destination is a register, not (HL)

64A4
CALL 655CH to output a comma separator to the output buffer at (5AAAH)
64A7
CALL 674EH to decode and output the source register name (from bits 0-2 of the opcode, but in this case we use the result from 673BH which already has the destination register)
64AA
CALL 6757H to output the bit number (extracted from bits 3-5 of the opcode in 560DH) to the output buffer
64AD
JUMP to 67B7H to finalize the instruction output and return to the main processing loop

64B0H - BIT Instruction Handler - Odd Opcodes with Bit 0 Set

Handles BIT instructions where bit 0 is set but bit 1 is clear (opcodes 41H, 45H, 49H, 4DH, etc.). These instructions output the bit number first, then a comma, then the register.

64B0
CALL 6757H to output the bit number (extracted from bits 3-5 of the opcode stored in 560DH) to the output buffer
64B3
CALL 674EH to decode and output the source register name (from bits 0-2 of the opcode in 560DH) to the output buffer
64B6
CALL 673BH to decode the destination register from bits 3-5 of the opcode and return the register index in Register A
64B9
CP 06H FE 06
Compare Register A with 06H to check if the destination register is (HL) indirect addressing. If equal, the Z FLAG is set; otherwise the NZ FLAG is set
64BB
If the Z FLAG is set (destination is (HL)), JUMP to 64E0H to handle this as an error condition (invalid opcode format)
64BD
CALL 655CH to output a comma separator to the output buffer
64C0
JUMP to 67B2H to complete the instruction output and return to the main processing loop
64C3
JUMP to 67B2H (duplicate/unreachable code path for instruction completion)

64C6H - BIT Instruction Handler - Bit 1 Set Path

Handles BIT instructions where bit 1 is set (opcodes with bit pattern xx1x in the low nibble). Tests bit 0 and bit 3 to determine the output format, then outputs either "IN" or "IM" mnemonic prefix.

64C6
BIT 0,A CB 47
Test bit 0 of Register A (the current opcode value stored in 560DH). If bit 0 is 0, the Z FLAG is set; if bit 0 is 1, the NZ FLAG is set
64C8
If the NZ FLAG is set (bit 0 is 1), JUMP to 64E3H to handle opcodes with bit 0 set

[IN/IM Instruction Path] - Bit 0 is clear, preparing to output either "IN" or "IM" mnemonic

64CA
LD DE,686EH 11 6E 68
Load Register DE with 686EH, the address of the "IN" mnemonic string
64CD
BIT 3,A CB 5F
Test bit 3 of Register A (the current opcode value). If bit 3 is 0, the Z FLAG is set and we use "IN"; if bit 3 is 1, the NZ FLAG is set and we use "IM"
64CF
If the NZ FLAG is set (bit 3 is 1), JUMP to 64D4H to skip the IM mnemonic load and use the "IN" mnemonic already in DE
64D1
LD DE,6872H 11 72 68
Load Register DE with 6872H, the address of the "IM" mnemonic string, overwriting the "IN" address
64D4
CALL 67CEH to output the mnemonic string pointed to by Register DE (either "IN" from 686EH or "IM" from 6872H) to the output buffer
64D7
CALL 67ECH to output additional instruction formatting or operand information
64DA
CALL 674EH to decode and output the source register name from bits 0-2 of the opcode stored in 560DH
64DD
JUMP to 67F0H to finalize the instruction output and return to the main processing loop

64E0H - Invalid Opcode Handler - Restart Processing

This is an error handler for invalid or unrecognized opcode sequences. When the decoder encounters an opcode it cannot process, execution jumps here to restart the disassembly from a safe state.

64E0
JUMP to 618AH to restore the saved state (stack pointer from 618BH) and restart the disassembly processing loop from a known good state

64E3H - BIT Instruction with Bit 0 Set - OUT/OUTI/OUTD Handler

Handles BIT-prefixed instructions where bit 0 is set. Tests bit 3 to determine whether to output an OUT-family instruction with immediate operand or register operand.

64E3
BIT 3,A CB 5F
Test bit 3 of Register A (the current opcode value stored in 560DH). If bit 3 is 0, the Z FLAG is set; if bit 3 is 1, the NZ FLAG is set
64E5
If the NZ FLAG is set (bit 3 is 1), JUMP to 64F5H to handle OUTI/OUTD instructions

[OUT Instruction Path] - Bit 3 is clear, this is an OUT instruction with immediate port address

64E7
CALL 67CBH to output the instruction mnemonic (determined by other opcode bits) to the output buffer
64EA
LD A,04H 3E 04
Load Register A with 04H, indicating a 4-operand format code
64EC
CALL 6646H to output the operand format specified by Register A (04H = 4-operand format)
64EF
CALL 674EH to decode and output the source register name from bits 0-2 of the opcode stored in 560DH
64F2
JUMP to 67F0H to finalize the instruction output and return to the main processing loop

64F5H - OUTI/OUTD Instruction Handler

Handles OUTI and OUTD instructions (opcodes with bit 3 set in the CB-prefix range). Outputs the operand first, then a comma, then the mnemonic.

64F5
CALL 67F0H to output the first operand to the output buffer
64F8
CALL 674EH to decode and output the source register name from bits 0-2 of the opcode stored in 560DH
64FB
XOR A AF
Set Register A to 00H by XORing it with itself, clearing all flags and preparing for the next operation
64FC
CALL 6646H to output the operand format specified by Register A (00H = zero-operand format)
64FF
JUMP to 67CBH to output the instruction mnemonic and return to the main processing loop

6502H - RES/SET Instruction Handler - Register Table Lookup

Handles RES and SET instructions (CB-prefixed opcodes with bit 2 set). Uses a lookup table at 692AH to identify special register names (I, R, IXH, IXL, IYH, IYL) and outputs the appropriate mnemonic.

6502
EX DE,HL EB
Exchange Register DE with Register HL, saving the current HL value in DE for later restoration
6503
LD HL,692AH 21 2A 69
Load Register HL with 692AH, the address of a special register code lookup table containing values for I, R, IXH, IXL, IYH, IYL registers
6506
LD B,05H 06 05
Load Register B with 05H, the count of special register codes in the lookup table (5 entries to check)

[LOOP START - Table Search] - Search backwards through the table for a matching register code

6508
CP (HL) BE
Compare Register A (the current opcode value from 560DH) with the value at the memory address in Register HL. If equal, the Z FLAG is set; otherwise the NZ FLAG is set
6509
DEC HL 2B
Decrement Register HL to point to the previous entry in the lookup table at 692AH, moving backwards through the table
650A
If the Z FLAG is set (found a match in the table), JUMP to 6511H to process the special register code
650C
Decrement Register B (loop counter) and JUMP back to 6508H if B is not zero, continuing the table search. If B reaches zero, fall through to 650EH

[LOOP END - No Match Found] - Register code not found in special table, use standard register handling

650E
EX DE,HL EB
Exchange Register DE with Register HL, restoring the original HL value that was saved at 6502H
650F
JUMP to 651AH to handle standard register codes (not special registers like I, R, IXH, etc.)

[Match Found Path] - Special register code found in lookup table

6511
EX DE,HL EB
Exchange Register DE with Register HL, restoring the original HL value
6512
LD DE,692BH 11 2B 69
Load Register DE with 692BH, the base address of the special register name string table (containing "I", "R", "IXH", "IXL", "IYH", "IYL")
6515
LD A,B 78
Load Register A with the value from Register B (the remaining loop count, which indicates which special register was matched)
6516
DEC A 3D
Decrement Register A to convert the loop count (1-5) to a table index (0-4) for indexing into the string table at 692BH
6517
JUMP to 67A6H to output the special register name string from the table at 692BH using the index in Register A, then return to finalize the instruction

651AH - Standard Register Handler - Check for Special Opcodes

This section handles standard register codes that were not found in the special register table. It checks for specific opcode values (47H, 57H, 4FH, 5FH) that correspond to LD I,A / LD R,A / LD A,I / LD A,R instructions, then handles indexed register operations.

651A
CP 47H FE 47
Compare Register A (the current opcode value from 560DH) with 47H (LD I,A opcode). If equal, the Z FLAG is set; otherwise the NZ FLAG is set
651C
LD B,49H 06 49
Load Register B with 49H, the ASCII code for 'I', preparing to output "I" as the destination register
651E
If the NZ FLAG is set (opcode is not 47H), JUMP to 6529H to check for other special opcodes

[LD I,A Path] - Opcode is 47H, output "LD I,A"

6520
CALL 679DH to output the character in Register B (49H = 'I') as the destination register to the output buffer
6523
CALL 6760H to output a comma separator and prepare for the source operand
6526
JUMP to 67CBH to output the source register (A) and finalize the instruction
6529
CP 57H FE 57
Compare Register A with 57H (LD R,A opcode). If equal, the Z FLAG is set; otherwise the NZ FLAG is set
652B
If the NZ FLAG is set (opcode is not 57H), JUMP to 6535H to check for other special opcodes

[LD R,A Path] - Opcode is 57H, output "LD R,A"

652D
CALL 6752H to output "A," prefix to the output buffer (for LD R,A format)
6530
CALL 679DH to output the character in Register B (52H = 'R', loaded at 651CH or updated elsewhere) to the output buffer
6533
JUMP back to 6526H to complete the instruction output by calling 67CBH
6535
CP 4FH FE 4F
Compare Register A with 4FH (LD A,I opcode). If equal, the Z FLAG is set; otherwise the NZ FLAG is set
6537
LD B,52H 06 52
Load Register B with 52H, the ASCII code for 'R', preparing to potentially output "R" as the source register
6539
If the Z FLAG is set (opcode is 4FH = LD A,I), JUMP back to 6520H to output "LD A,I" (using 'I' already in B from earlier)
653B
CP 5FH FE 5F
Compare Register A with 5FH (LD A,R opcode). If equal, the Z FLAG is set; otherwise the NZ FLAG is set
653D
If the Z FLAG is set (opcode is 5FH = LD A,R), JUMP back to 652DH to output "LD A,R" (using 'R' in B from 6537H)

[Indexed Register Operations] - Check for IX/IY register operations (opcodes 46H, 56H, 5EH)

653F
LD B,30H 06 30
Load Register B with 30H, preparing an index or offset value for indexed register operations
6541
CP 46H FE 46
Compare Register A with 46H (indexed operation opcode). If equal, the Z FLAG is set; otherwise the NZ FLAG is set
6543
If the Z FLAG is set (opcode is 46H), JUMP to 6550H to handle this indexed register operation
6545
INC B 04
Increment Register B from 30H to 31H, adjusting the index value
6546
CP 56H FE 56
Compare Register A with 56H (another indexed operation opcode). If equal, the Z FLAG is set; otherwise the NZ FLAG is set
6548
If the Z FLAG is set (opcode is 56H), JUMP to 6550H to handle this indexed register operation
654A
INC B 04
Increment Register B from 31H to 32H, adjusting the index value again
654B
CP 5EH FE 5E
Compare Register A with 5EH (third indexed operation opcode). If equal, the Z FLAG is set; otherwise the NZ FLAG is set
654D
If the NZ FLAG is set (opcode is not 5EH, and not any of the recognized opcodes), JUMP to 64E0H to handle this as an invalid opcode error
6550
CALL 679DH to output the character in Register B (30H, 31H, or 32H) to the output buffer as part of the indexed register operation
6553
LD DE,689EH 11 9E 68
Load Register DE with 689EH, the address of a mnemonic or format string for indexed register operations
6556
JUMP to 67CEH to output the string at 689EH and finalize the instruction, returning to the main processing loop

6559H - Finalize Instruction Output

This is the main instruction finalization routine called from many decoder paths. It performs final operand processing, handles ASCII display generation, checks for entry points, and returns control to the main disassembly loop. Entry: various opcode decoders. Exit: returns to main loop at 678DH.

6559
CALL 6743H to perform final register or operand processing, returning with Register A containing a result code
655C
CP 06H FE 06
Compare Register A with 06H to check if the result indicates a special condition (06H = (HL) indirect addressing or special operand type). If equal, the Z FLAG is set; otherwise the NZ FLAG is set
655E
If the NZ FLAG is set (result is not 06H), JUMP to 67D1H to handle the non-special operand case and continue instruction processing
6561
CALL 6789H to process the special operand case (likely outputting (HL) or similar indirect addressing)
6564
LD A,(5610H) 3A 10 56
Load Register A with the value from memory address 5610H (counter/state variable used for tracking instruction processing state)
6567
CALL 6803H to perform additional processing based on the state value in Register A from 5610H
656A
LD A,(560FH) 3A 0F 56
Load Register A with the value from memory address 560FH (processing state flag that controls branching and output behavior)
656D
BIT 0,A CB 47
Test bit 0 of Register A (the processing state flag from 560FH). If bit 0 is 0, the Z FLAG is set; if bit 0 is 1, the NZ FLAG is set
656F
If the Z FLAG is set (bit 0 of the processing state flag is 0), JUMP to 658FH to skip the ASCII display generation and go directly to output finalization

[ASCII Display Generation Path] - Bit 0 of state flag is set, generate ASCII representation of instruction bytes

6571
BIT 1,A CB 4F
Test bit 1 of Register A (the processing state flag from 560FH). This determines whether to fetch another byte for the ASCII display
6573
LD A,00H 3E 00
Load Register A with 00H, preparing to clear the processing state flag
6575
LD (560FH),A 32 0F 56
Store Register A (00H) to memory address 560FH, clearing the processing state flag to reset it for the next instruction
6578
LD A,(5611H) 3A 11 56
Load Register A with the value from memory address 5611H (likely contains a byte value or displacement for ASCII display)
657B
If the Z FLAG is set (bit 1 of the state flag from 6571H was 0), conditionally CALL 6592H to fetch the next byte from the source file/memory into Register A
657E
CP 80H FE 80
Compare Register A with 80H to check if the byte value is negative (bit 7 set). If A is less than 80H, the C FLAG is set; otherwise the NC FLAG is set
6580
If the C FLAG is set (value in A is less than 80H, i.e., positive or zero), JUMP to 6589H to handle the positive value case

[Negative Value Path] - Byte value is >= 80H, handle as negative displacement

6582
CALL 6781H to output a minus sign ('-') to the output buffer, indicating a negative displacement
6585
NEG ED 44
Negate Register A (two's complement), converting the negative value to its positive magnitude for display (e.g., FFH becomes 01H)
6587
JUMP to 658CH to output the positive magnitude of the displacement value

[Positive Value Path] - Byte value is < 80H, handle as positive displacement

6589
CALL 6785H to output a plus sign ('+') to the output buffer, indicating a positive displacement
658C
CALL 668BH to convert Register A (the displacement magnitude) to hexadecimal and output it to the output buffer
658F
JUMP to 678DH to finalize the instruction line output, add it to the label buffer if needed, and return to the main disassembly loop

6592H - Fetch Next Byte from Source (Memory or Disk)

This critical routine fetches the next byte from the source being disassembled, whether from memory or from disk. It decrements the byte counter at 560BH, manages the label buffer pointer at 55F6H when reading from disk, and returns the fetched byte in Register A. Entry: called when next instruction byte is needed. Exit: A contains the fetched byte, HL preserved via stack.

6592
PUSH HL E5
Save Register HL to the stack to preserve its value during the byte fetch operation
6593
LD HL,(560BH) 2A 0B 56
Load Register HL with the 16-bit value from memory address 560BH (byte count remaining - number of bytes left to disassemble in the current block or file)
6596
LD A,H 7C
Load Register A with the high byte of the byte count from Register H
6597
OR L B5
OR Register A with Register L to test if HL is zero. If HL is zero (no bytes remaining), the Z FLAG is set; otherwise the NZ FLAG is set
6598
If the Z FLAG is set (byte count is zero, no more bytes to disassemble), JUMP to 618AH to restore state and exit the disassembly
659B
DEC HL 2B
Decrement Register HL (the byte count remaining) by 1 since we are about to fetch one byte
659C
LD (560BH),HL 22 0B 56
Store the decremented byte count from Register HL back to memory address 560BH to update the remaining count
659F
LD A,(55EFH) 3A EF 55
Load Register A with the value from memory address 55EFH (mode/option flags word - bit 1 indicates disk vs memory mode)
65A2
AND 02H E6 02
Mask Register A with 02H to isolate bit 1 of the flags. If bit 1 is 0 (memory mode), the Z FLAG is set; if bit 1 is 1 (disk mode), the NZ FLAG is set
65A4
If the Z FLAG is set (bit 1 is 0, memory mode), JUMP to 6620H to fetch the byte directly from memory without label buffer processing

[Disk Mode Path - Label Buffer Processing] - Source is on disk, need to manage label buffer entries

65A6
PUSH DE D5
Save Register DE to the stack to preserve it during label buffer processing
65A7
LD DE,(55E5H) ED 5B E5 55
Load Register DE with the 16-bit value from memory address 55E5H (virtual base address - the current logical address being disassembled)
65AB
LD IY,(55F6H) FD 2A F6 55
Load Index Register IY with the 16-bit value from memory address 55F6H (label buffer pointer - current position in the label buffer for this page)

[LOOP START - Label Buffer Entry Search] - Check if current address matches any label buffer entries

65AF
BIT 7,(IY+02H) FD CB 02 7E
Test bit 7 of the byte at (IY+02H) in the label buffer (flag byte indicating end of entries or special status). If bit 7 is 0, the Z FLAG is set; if bit 7 is 1, the NZ FLAG is set (end marker)
65B3
If the NZ FLAG is set (bit 7 is 1, end of label entries), JUMP to 661FH to exit the label buffer search and proceed with byte fetch
65B5
LD A,D 7A
Load Register A with the high byte of the virtual base address from Register D
65B6
CP (IY+00H) FD BE 00
Compare Register A with the byte at (IY+00H) (high byte of the label address in the buffer entry). If equal, the Z FLAG is set; otherwise the NZ FLAG is set
65B9
If the NZ FLAG is set (high bytes don't match), JUMP to 65BFH to skip the low byte comparison and move to the next entry
65BB
LD A,E 7B
Load Register A with the low byte of the virtual base address from Register E
65BC
CP (IY+01H) FD BE 01
Compare Register A with the byte at (IY+01H) (low byte of the label address in the buffer entry). If equal, the Z FLAG is set; otherwise the NZ FLAG is set
65BF
If the C FLAG is set (current address is less than the label entry address), JUMP to 661FH since we've gone past where we need to be in the buffer
65C1
If the Z FLAG is set (exact match - current address matches the label entry), JUMP to 65D5H to process this matching entry

[No Match - Advance to Next Entry] - Current address is greater than this entry, move to next

65C3
INC IY FD 23
Increment Index Register IY by 1 to point to the next byte in the label buffer entry structure
65C5
INC IY FD 23
Increment Index Register IY by 1 again (total +2 bytes)
65C7
INC IY FD 23
Increment Index Register IY by 1 again (total +3 bytes, moving to the next 3-byte entry in the label buffer)
65C9
BIT 6,(IY+02H) FD CB 02 76
Test bit 6 of the byte at (IY+02H) in the new label buffer entry (flag indicating page boundary or continuation). If bit 6 is 0, the Z FLAG is set (continue); if bit 6 is 1, the NZ FLAG is set (boundary)
65CD
If the Z FLAG is set (bit 6 is 0, not at a boundary), JUMP back to 65C3H to advance to the next entry and continue searching
65CF
LD (55F6H),IY FD 22 F6 55
Store Index Register IY to memory address 55F6H, updating the label buffer pointer to the current position (at a page boundary)
65D3
JUMP back to 65AFH to restart the label buffer entry search from the new position

[Exact Match Found] - Current address matches a label entry, process it

65D5
LD HL,(55EBH) 2A EB 55
Load Register HL with the 16-bit value from memory address 55EBH (current disassembly address - the actual address being processed)
65D8
CALL 5EA9H to compare HL with DE (16-bit signed comparison), determining if the current disassembly address matches the virtual base address
65DB
LD A,10H 3E 10
Load Register A with 10H (16 decimal), initializing a bit rotation counter for processing the label entry flags

[LOOP START - Bit Rotation] - Rotate through bits to identify which bit position is set in the entry

65DD
DEC L 2D
Decrement Register L by 1 to adjust the comparison or counter value
65DE
RRCA 0F
Rotate Register A right through the carry flag, shifting the bit pattern right by 1 position. The bit that exits the right goes into the carry flag
65DF
INC L 2C
Increment Register L by 1 to restore or advance the counter
65E0
If the NZ FLAG is set (rotation not complete), JUMP back to 65DEH to continue rotating bits. Loop continues until the Z FLAG is set

[LOOP END - Bit Position Identified] - Register A now contains the rotated bit pattern

65E2
INC IY FD 23
Increment Index Register IY by 1 to advance to the next byte in the label buffer entry
65E4
INC IY FD 23
Increment Index Register IY by 1 again (total +2 bytes)
65E6
INC IY FD 23
Increment Index Register IY by 1 again (total +3 bytes, moving to the next label buffer entry)
65E8
BIT 6,(IY+02H) FD CB 02 76
Test bit 6 of the byte at (IY+02H) in the label buffer entry (page boundary flag). If bit 6 is 0, the Z FLAG is set; if bit 6 is 1, the NZ FLAG is set
65EC
If the NZ FLAG is set (bit 6 is 1, at page boundary), JUMP to 660EH to finalize the label buffer pointer update
65EE
PUSH AF F5
Save Register AF (including flags) to the stack to preserve the rotated bit pattern and flags during processing
65EF
LD A,(55E6H) 3A E6 55
Load Register A with the value from memory address 55E6H (high byte of virtual base address offset or configuration flag)
65F2
OR A B7
OR Register A with itself to test if it is zero and set flags. If A is zero, the Z FLAG is set; otherwise the NZ FLAG is set
65F3
If the NZ FLAG is set (value at 55E6H is not zero), JUMP to 6605H to skip the entry type check
65F5
LD A,(IY+02H) FD 7E 02
Load Register A with the byte at (IY+02H) (flag byte from the current label buffer entry being examined)
65F8
CP 08H FE 08
Compare Register A with 08H to check if the entry flag byte indicates a specific type (bit 3 set). If A >= 08H, the NC FLAG is set; if A < 08H, the C FLAG is set
65FA
If the NC FLAG is set (flag byte is >= 08H), JUMP to 6605H to skip the additional entry type filtering
65FC
AND 03H E6 03
Mask Register A with 03H to isolate the lower 2 bits of the flag byte (bits 0-1)
65FE
XOR 03H EE 03
XOR Register A with 03H to flip the lower 2 bits. If result is zero (original bits were 11), the Z FLAG is set; otherwise the NZ FLAG is set
6600
If the NZ FLAG is set (lower 2 bits were not both 1), JUMP to 6605H to skip this entry and continue searching
6602
POP AF F1
Restore Register AF from the stack, retrieving the saved rotated bit pattern and flags from 65EEH
6603
JUMP back to 65E2H to advance to the next label buffer entry and continue the search
6605
POP AF F1
Restore Register AF from the stack, retrieving the saved bit pattern value from 65EEH
6606
CP F0H FE F0
Compare Register A with F0H to check if the rotated bit pattern is in the upper range. If A >= F0H, the NC FLAG is set; if A < F0H, the C FLAG is set
6608
If the NC FLAG is set (A >= F0H), JUMP back to 65E2H to skip this entry and continue to the next label buffer entry
660A
ADD 10H C6 10
Add 10H (16 decimal) to Register A, adjusting the bit pattern value upward
660C
JUMP back to 65E2H to advance to the next label buffer entry with the adjusted value in Register A
660E
LD (55F6H),IY FD 22 F6 55
Store Index Register IY to memory address 55F6H, updating the label buffer pointer to the current position (at page boundary)
6612
CP 10H FE 10
Compare Register A with 10H to check if the bit pattern value is less than 16. If A < 10H, the C FLAG is set; if A >= 10H, the NC FLAG is set
6614
If the C FLAG is set (A < 10H), JUMP to 661FH to exit the label buffer processing
6616
LD HL,55F1H 21 F1 55
Load Register HL with 55F1H, the address of the entry point bitmap flag (tracks which addresses are entry points)
6619
ADD A,(HL) 86
Add the value at (HL) (current entry point bitmap at 55F1H) to Register A, combining the new bit pattern with the existing bitmap. The C FLAG is set if the addition overflows; otherwise it is clear
661A
If the NC FLAG is set (no carry from the addition, no overflow), JUMP to 661EH to skip the overflow handling and store the result
661C
OR F0H F6 F0
OR Register A with F0H to set the upper 4 bits to 1, marking an overflow or saturation condition in the entry point bitmap
661E
LD (HL),A 77
Store Register A to the memory address in HL (55F1H), updating the entry point bitmap with the new combined value
661F
POP DE D1
Restore Register DE from the stack, retrieving the saved DE value from 65A6H

[Memory/Disk Fetch Common Path] - Both memory and disk modes converge here to fetch the actual byte

6620
LD HL,(55E7H) 2A E7 55
Load Register HL with the 16-bit value from memory address 55E7H (real base address - the actual memory address where the code being disassembled is located)
6623
LD A,(HL) 7E
Load Register A with the byte at the memory address in Register HL (fetch the next instruction byte from the real base address)
6624
INC HL 23
Increment Register HL to point to the next byte in memory (advance the real base address pointer)
6625
LD (55E7H),HL 22 E7 55
Store the incremented Register HL back to memory address 55E7H, updating the real base address for the next fetch
6628
LD HL,(55E5H) 2A E5 55
Load Register HL with the 16-bit value from memory address 55E5H (virtual base address - the logical disassembly address)
662B
INC HL 23
Increment Register HL to advance the virtual base address to the next byte position
662C
LD (55E5H),HL 22 E5 55
Store the incremented Register HL back to memory address 55E5H, updating the virtual base address for the next instruction
662F
LD HL,(5609H) 2A 09 56
Load Register HL with the 16-bit value from memory address 5609H (ASCII display buffer pointer or similar tracking variable)
6632
CALL 66A0H to process the fetched byte for ASCII display or buffer management, updating the buffer pointer in Register HL
6635
LD (5609H),HL 22 09 56
Store the updated Register HL back to memory address 5609H, saving the new ASCII display buffer pointer or tracking value
6638
POP HL E1
Restore Register HL from the stack, retrieving the original HL value that was saved at 6592H
6639
RET C9
RETURN from the subroutine with the fetched byte in Register A and all other registers restored

663AH - Process Operand with Optional Bit Flag

This routine processes an operand and optionally sets bit 0 based on bit 4 of the current opcode. It checks the opcode at 560DH and conditionally ORs the input value in Register A with 01H if bit 4 is set. Entry: A contains operand type code. Exit: calls 6789H and 664FH, then jumps to 678DH.

663A
LD IY,560DH FD 21 0D 56
Load Index Register IY with 560DH, the address of the current opcode storage location
663E
BIT 4,(IY+00H) FD CB 00 66
Test bit 4 of the byte at (IY+00H) which is the current opcode stored at 560DH. If bit 4 is 0, the Z FLAG is set; if bit 4 is 1, the NZ FLAG is set
6642
If the Z FLAG is set (bit 4 of the opcode is 0), JUMP to 6646H to skip the OR operation
6644
OR 01H F6 01
OR Register A with 01H to set bit 0, modifying the operand type code in Register A
6646
CALL 6789H to process or output the operand based on the (possibly modified) type code in Register A
6649
CALL 664FH to perform additional operand processing, fetching bytes and handling address output
664C
JUMP to 678DH to finalize the instruction output and return to the main disassembly loop

664FH - Fetch 16-bit Address and Add to Label Buffer

This routine fetches two bytes from the source to form a 16-bit address, stores the fetch count in 55F8H, and adds the address to the label buffer. Entry: A contains fetch count. Exit: DE contains the 16-bit address, label added to buffer.

664F
LD (55F8H),A 32 F8 55
Store Register A to memory address 55F8H, saving the fetch count or operand type code for later use
6652
CALL 6592H to fetch the next byte from the source (memory or disk) into Register A, advancing the source pointers and updating the byte count at 560BH
6655
LD E,A 5F
Load Register E with the value from Register A (low byte of the 16-bit address)
6656
CALL 6592H again to fetch the next byte from the source into Register A (high byte of the 16-bit address)
6659
LD D,A 57
Load Register D with the value from Register A, forming the complete 16-bit address in Register DE (D=high byte, E=low byte)
665A
JUMP to 665FH to continue with label buffer processing using the 16-bit address now in Register DE

665CH - Output Comma Separator

This simple routine stores a value to 55F8H and then processes a 16-bit address for output. It's used to output a comma separator between instruction operands. Entry: called when comma separator needed. Exit: processes address and adds to label buffer.

665C
LD (55F8H),A 32 F8 55
Store Register A to memory address 55F8H, saving the current value (typically a separator type code)
665F
CALL 66B6H to generate or format the address in Register DE for output to the disassembly buffer
6662
CALL 5EB2H to add the address in Register DE to the label buffer, creating a new label entry or updating an existing one
6665
LD A,D 7A
Load Register A with the high byte of the address from Register D
6666
CP A0H FE A0
Compare Register A with A0H to check if the high byte indicates an address in the upper memory range. If A >= A0H, the NC FLAG is set; if A < A0H, the C FLAG is set
6668
If the NC FLAG is set (high byte >= A0H), conditionally CALL 6795H to handle high memory address output or special processing
666B
CALL 66A0H to perform additional address processing or buffer management
666E
LD A,E 7B
Load Register A with the low byte of the address from Register E
666F
JUMP to 6690H to complete the address output processing and return

6672H - Process Operand and Output with 8-bit Immediate

This routine processes an operand by calling 6789H, then fetches and outputs an 8-bit immediate value. Entry: called for instructions with 8-bit immediate operands. Exit: outputs operand and immediate value.

6672
CALL 6789H to process or output the current operand based on the instruction context
6675
CALL 667BH to fetch and process an 8-bit immediate value from the source
6678
JUMP to 678DH to finalize the instruction output and return to the main disassembly loop

667BH - Fetch 8-bit Immediate and Output

This routine fetches an 8-bit immediate value from the source, stores it in 55F8H, forms a 16-bit value with the high byte as 00H, adds it to the label buffer, and outputs it. Entry: called for 8-bit immediate operands. Exit: E contains the immediate value.

667B
LD (55F8H),A 32 F8 55
Store Register A to memory address 55F8H, saving the current operand type code or counter value
667E
CALL 6592H to fetch the next byte from the source (the 8-bit immediate value) into Register A
6681
LD E,A 5F
Load Register E with the value from Register A (the 8-bit immediate value)
6682
LD D,00H 16 00
Load Register D with 00H, forming a 16-bit value in Register DE with the high byte as 00H and low byte as the immediate value
6684
CALL 66B6H to format or process the 16-bit value in Register DE for output
6687
CALL 5EB2H to add the address in Register DE to the label buffer (even though it's an immediate value, it may be used as a reference)
668A
LD A,E 7B
Load Register A with the low byte (the 8-bit immediate value) from Register E
668B
CP A0H FE A0
Compare Register A with A0H to check if the value is in the upper range (>= A0H). If A >= A0H, the NC FLAG is set; if A < A0H, the C FLAG is set
668D
If the NC FLAG is set (value >= A0H), conditionally CALL 6795H to handle high-value immediate output or special processing
6690
CALL 66A0H to perform buffer management or additional processing with the immediate value

6693H - Complete Hex Output with 'H' Suffix

This routine completes hex value output by calling the buffer management routine and then jumping to output the 'H' suffix. Entry: previous hex processing complete. Exit: jumps to 6799H to add 'H' suffix.

6693
JUMP to 6799H to output the 'H' suffix character after the hex digits, completing the hexadecimal number output

6696H - Convert 16-bit Value to Hex Digits

This routine converts a 16-bit value in Register DE to hexadecimal ASCII digits and stores them in the output buffer. It processes both high byte (D) and low byte (E). Entry: DE contains the 16-bit value to convert. Exit: buffer contains hex ASCII digits.

6696
PUSH BC C5
Save Register BC to the stack to preserve it during the hex conversion process
6697
LD B,01H 06 01
Load Register B with 01H, setting up a counter for processing 1 byte (will be used for the high byte first)
6699
JUMP to 66A7H to begin the hex digit conversion process

669BH - Convert Address to Hex and Output

This routine converts a 16-bit address in Register DE to hexadecimal ASCII and outputs it. It first converts the high byte (D), then the low byte (E). Entry: DE contains the address to output. Exit: address output as hex ASCII.

669B
LD A,D 7A
Load Register A with the high byte of the address from Register D
669C
CALL 66A0H to convert the high byte in Register A to two hex ASCII digits and store them in the buffer pointed to by HL
669F
LD A,E 7B
Load Register A with the low byte of the address from Register E

66A0H - Convert Byte to Hex ASCII Digits

This is the core hex conversion routine. It converts a single byte in Register A to two hexadecimal ASCII characters and stores them in the buffer at HL. Entry: A contains byte to convert, HL points to output buffer. Exit: HL advanced by 2, BC preserved via stack.

66A0
PUSH BC C5
Save Register BC to the stack to preserve it during conversion
66A1
LD B,02H 06 02
Load Register B with 02H, setting up a loop counter to process 2 hex digits (one byte = two hex digits)
66A3
LD C,A 4F
Load Register C with the value from Register A, making a working copy of the byte to convert
66A4
CALL 6730H to rotate the byte in Register A right by 4 bits, moving the high nibble into the low nibble position

[LOOP START - Convert Two Hex Digits] - Process high nibble first, then low nibble

66A7
AND 0FH E6 0F
Mask Register A with 0FH to isolate the lower 4 bits (one hex digit, value 0-15)
66A9
ADD 90H C6 90
Add 90H to Register A as part of the BCD conversion algorithm to convert the nibble to ASCII hex digit
66AB
DAA 27
Decimal Adjust Accumulator - adjusts Register A after the addition for BCD arithmetic, preparing for hex ASCII conversion
66AC
ADC 40H CE 40
Add 40H plus the carry flag to Register A, completing the conversion to ASCII hex digit (0-9 become 30H-39H, A-F become 41H-46H)
66AE
DAA 27
Decimal Adjust Accumulator again to finalize the ASCII hex character in Register A
66AF
LD (HL),A 77
Store the ASCII hex character from Register A to the memory address in Register HL (output buffer)
66B0
LD A,C 79
Load Register A with the value from Register C (the original byte value), preparing to process the low nibble
66B1
INC HL 23
Increment Register HL to point to the next position in the output buffer
66B2
Decrement Register B (loop counter) and JUMP back to 66A7H if B is not zero, processing the second hex digit (low nibble)

[LOOP END] - Both hex digits converted and stored

66B4
POP BC C1
Restore Register BC from the stack, retrieving the saved BC value from 66A0H or 6696H
66B5
RET C9
RETURN from the subroutine with the hex ASCII digits stored in the buffer and HL pointing past them

66B6H - Generate Label for Address

This routine checks the mode flags at 55EFH and generates a label for the address in Register DE if label generation is enabled. It searches the label buffer and returns either a generated label or continues with hex output. Entry: DE contains address. Exit: may generate label or return for hex output.

66B6
LD A,(55EFH) 3A EF 55
Load Register A with the value from memory address 55EFH (mode/option flags word - bit 0 and bit 5 control label generation)
66B9
AND 21H E6 21
Mask Register A with 21H to isolate bit 0 and bit 5 of the flags. If both bits are set (21H), label generation is enabled; otherwise it is disabled
66BB
CP 20H FE 20
Compare Register A with 20H to check if only bit 5 is set (label mode enabled). If equal, the Z FLAG is set; otherwise the NZ FLAG is set
66BD
RET NZ C0
If the NZ FLAG is set (label generation not enabled or wrong mode), RETURN immediately without generating a label

[Label Generation Path] - Labels are enabled, proceed to generate label

66BE
POP AF F1
Remove the return address from the stack (discarding the caller's return address since we will not return there)
66BF
LD A,01H 3E 01
Load Register A with 01H, setting a flag to indicate label generation mode
66C1
PUSH HL E5
Save Register HL to the stack to preserve the output buffer pointer during label search
66C2
PUSH AF F5
Save Register AF (including the label mode flag) to the stack for later retrieval
66C3
CALL 5F4DH to search the label buffer for the address in Register DE, returning with Z FLAG set if found, BC pointing to the entry
66C6
If the Z FLAG is set (address found in label buffer), JUMP to 66D0H to generate the label string for this address

[Address Not Found in Label Buffer] - Check if error should be raised

66C8
POP AF F1
Restore Register AF from the stack, retrieving the label mode flag from 66C2H
66C9
BIT 0,A CB 47
Test bit 0 of Register A (the label mode flag). If bit 0 is 0, the Z FLAG is set; if bit 0 is 1, the NZ FLAG is set
66CB
If the NZ FLAG is set (label mode flag is 1, indicating strict label mode), JUMP to 5CF7H to display an error message about missing label
66CE
POP AF F1
Remove the extra AF value from the stack (cleaning up the stack before return)
66CF
RET C9
RETURN from the subroutine since label was not found and error was not required

66D0H - Generate Label String from Buffer Entry

This routine generates the actual label string (like "L0001", "L0002", etc.) from a label buffer entry. It uses the entry position to calculate the label number and outputs the label characters. Entry: BC points to label buffer entry, DE on stack. Exit: HL points to output buffer with label string.

66D0
POP AF F1
Restore Register AF from the stack, retrieving the label mode flag from 66C2H
66D1
BIT 1,A CB 4F
Test bit 1 of Register A to check if this is a special label type. If bit 1 is 0, the Z FLAG is set; if bit 1 is 1, the NZ FLAG is set
66D3
If the Z FLAG is set (bit 1 is 0, normal label), JUMP to 66D7H to skip the special flag setting
66D5
SET 5,(HL) CB EE
Set bit 5 of the byte at (HL) in the label buffer entry, marking this as a special entry point or reference label
66D7
LD H,B 60
Load Register H with the value from Register B (high byte of the label buffer entry pointer)
66D8
LD L,C 69
Load Register L with the value from Register C (low byte of the label buffer entry pointer), forming the complete address in HL
66D9
POP DE D1
Restore Register DE from the stack, retrieving the output buffer pointer that was saved at 66C1H
66DA
PUSH HL E5
Save Register HL (label buffer entry pointer) to the stack for later use in calculating the label number
66DB
LD HL,66FBH 21 FB 66
Load Register HL with 66FBH, the address of a data table containing divisor values for label number calculation

[LOOP START - Calculate Label Digit Values] - Convert entry position to decimal label number

66DE
LD C,(HL) 4E
Load Register C with the byte at (HL) (low byte of the divisor from the table at 66FBH)
66DF
INC HL 23
Increment Register HL to point to the next byte in the divisor table
66E0
LD B,(HL) 46
Load Register B with the byte at (HL) (high byte of the divisor), forming a 16-bit divisor in Register BC
66E1
LD A,40H 3E 40
Load Register A with 40H (ASCII '@', which is one less than 'A'), initializing the digit counter for this position
66E3
INC HL 23
Increment Register HL to point to the next entry in the divisor table
66E4
EX (SP),HL E3
Exchange the value at the top of the stack with Register HL, bringing the label buffer entry pointer into HL and saving the table pointer on the stack

[INNER LOOP - Division by Subtraction] - Count how many times divisor fits into entry position

66E5
INC A 3C
Increment Register A (the digit counter), counting one more subtraction of the divisor
66E6
ADD HL,BC 09
Add Register BC (the divisor) to Register HL (the entry position). The C FLAG is set if the addition overflows past FFFFH; otherwise it is clear
66E7
If the C FLAG is set (addition caused overflow, meaning we need to subtract more), JUMP back to 66E5H to continue counting

[INNER LOOP END] - Counted all subtractions, subtract back the last one that caused underflow

66E9
SBC HL,BC ED 42
Subtract Register BC (with carry) from Register HL to remove the last addition that caused the overflow, leaving the remainder
66EB
LD (DE),A 12
Store Register A (the digit counter, now containing an ASCII character '0'-'9' or 'A'-'Z') to the output buffer at (DE)
66EC
INC DE 13
Increment Register DE to point to the next position in the output buffer
66ED
EX (SP),HL E3
Exchange the value at the top of the stack with Register HL, restoring the table pointer to HL and saving the remainder on the stack
66EE
LD A,L 7D
Load Register A with the low byte of the table pointer from Register L
66EF
CP FFH FE FF
Compare Register A with FFH to check if we've reached the end marker in the divisor table. If equal, the Z FLAG is set; otherwise the NZ FLAG is set
66F1
If the NZ FLAG is set (not at end of table, more digits to process), JUMP back to 66DEH to process the next digit position

[LOOP END - All Digits Processed] - Add label prefix character

66F3
POP HL E1
Remove the final remainder from the stack (discarding it as we're done with the calculation)
66F4
LD A,L 7D
Load Register A with the low byte from Register L (the final remainder or offset)
66F5
ADD 41H C6 41
Add 41H (ASCII 'A') to Register A, converting the remainder to a letter A-Z for the label prefix or suffix
66F7
LD (DE),A 12
Store the label letter character from Register A to the output buffer at (DE)
66F8
INC DE 13
Increment Register DE to point past the completed label string in the output buffer
66F9
EX DE,HL EB
Exchange Register DE with Register HL, putting the updated output buffer pointer in HL for return
66FA
RET C9
RETURN from the subroutine with HL pointing past the generated label string in the output buffer

66FBH - Label Divisor Table (DATA)

This data table contains 16-bit divisor values used to convert label buffer entry positions into decimal label numbers. The values are in descending order (10000, 1000, etc.) followed by an FFH end marker.

66FB
DEFB 5CH 5C
DATA: Low byte of first divisor (FD5CH = -668 in signed 16-bit, or 64860 unsigned - appears to be a negative divisor for two's complement calculation)
66FC
DEFB FDH FD
DATA: High byte of first divisor (forms FD5CH with previous byte)
66FD
DEFB E6H E6
DATA: Low byte of second divisor or next table entry
66FE
DEFB FFH FF
DATA: High byte or end marker (FFH indicates end of divisor table)

66FFH - Decode Condition Code from Opcode

This routine decodes the condition code (NZ, Z, NC, C, PO, PE, P, M) from bits of the current opcode and outputs the appropriate string. Entry: A contains opcode or bit pattern. Exit: condition code string output to buffer.

66FF
BIT 5,A CB 6F
Test bit 5 of Register A (the opcode value from 560DH). If bit 5 is 0, the Z FLAG is set; if bit 5 is 1, the NZ FLAG is set
6701
If the NZ FLAG is set (bit 5 is 1), JUMP to 6710H to handle condition codes with bit 5 set (P, M, PE, PO)

[Bit 5 Clear Path] - Condition codes: NZ, Z, NC, C

6703
BIT 3,A CB 5F
Test bit 3 of Register A to determine which pair of conditions (NZ/Z or NC/C). If bit 3 is 0, the Z FLAG is set; if bit 3 is 1, the NZ FLAG is set
6705
If the Z FLAG is set (bit 3 is 0, indicating NZ/Z conditions), conditionally CALL 6765H to output the 'Z' character for Z or NZ
6708
BIT 4,A CB 67
Test bit 4 of Register A to determine if this is the negated form (NZ or NC). If bit 4 is 0, the Z FLAG is set (Z or C); if bit 4 is 1, the NZ FLAG is set (NZ or NC)
670A
If the Z FLAG is set (bit 4 is 0, non-negated form Z or C), JUMP to 6769H to output just the base condition character
670D
JUMP to 676DH to output the 'N' prefix for negated conditions (NZ or NC)

6710H - Decode P/M/PE/PO Condition Codes

This section handles condition codes when bit 5 of the opcode is set, covering P (Plus), M (Minus), PE (Parity Even), and PO (Parity Odd). Entry: A contains opcode with bit 5 set. Exit: appropriate condition code output.

6710
BIT 4,A CB 67
Test bit 4 of Register A (the opcode). If bit 4 is 0, the Z FLAG is set (PE/PO conditions); if bit 4 is 1, the NZ FLAG is set (P/M conditions)
6712
If the NZ FLAG is set (bit 4 is 1, P or M condition), JUMP to 671FH to handle sign conditions

[Parity Conditions Path] - PE or PO

6714
CALL 6775H to output the 'P' character (for PE or PO parity conditions)
6717
BIT 3,A CB 5F
Test bit 3 of Register A to distinguish between PE and PO. If bit 3 is 0, the Z FLAG is set (PO); if bit 3 is 1, the NZ FLAG is set (PE)
6719
If the Z FLAG is set (bit 3 is 0, Parity Odd), JUMP to 677DH to output 'O' for PO
671C
JUMP to 6779H to output 'E' for PE (Parity Even)

671FH - Decode P/M Sign Conditions

This section handles the P (Plus/Positive) and M (Minus/Negative) sign-based condition codes. Entry: A contains opcode with bits 5 and 4 both set. Exit: 'P' or 'M' output.

671F
BIT 3,A CB 5F
Test bit 3 of Register A to distinguish between P and M conditions. If bit 3 is 0, the Z FLAG is set (P); if bit 3 is 1, the NZ FLAG is set (M)
6721
If the Z FLAG is set (bit 3 is 0, Plus condition), JUMP to 6775H to output 'P'
6724
JUMP to 6771H to output 'M' for Minus condition

6727H - Get Low 2 Bits of Opcode

This utility routine extracts bits 0-1 from the current opcode stored at 560DH. Entry: none. Exit: A contains bits 0-1 of opcode (value 0-3).

6727
LD A,(560DH) 3A 0D 56
Load Register A with the value from memory address 560DH (current opcode storage)
672A
CALL 6749H to rotate Register A right by 4 bits, moving bits 4-7 into positions 0-3
672D
AND 03H E6 03
Mask Register A with 03H to isolate bits 0-1 of the rotated value (which were originally bits 4-5 of the opcode)
672F
RET C9
RETURN from the subroutine with bits 0-1 of the opcode in Register A

6730H - Get Low Nibble After Right Rotate

This routine rotates Register A right by 4 bits and then masks to get the low nibble. Entry: A contains value to rotate. Exit: A contains low 4 bits after rotation.

6730
CALL 6749H to rotate Register A right by 4 bits, moving the high nibble into the low nibble position
6733
JUMP to 6738H to mask the low nibble and return

6735H - Get Low Nibble of Opcode

This routine loads the opcode and extracts its low 4 bits (nibble). Entry: none. Exit: A contains bits 0-3 of opcode (value 0-15).

6735
LD A,(560DH) 3A 0D 56
Load Register A with the value from memory address 560DH (current opcode storage)
6738
AND 0FH E6 0F
Mask Register A with 0FH to isolate the low 4 bits (low nibble) of the opcode or rotated value
673A
RET C9
RETURN from the subroutine with the low nibble in Register A

673BH - Decode Destination Register (Bits 3-5)

This routine extracts bits 3-5 from the current opcode to decode the destination register in LD and arithmetic instructions. Entry: none. Exit: A contains register code 0-7.

673B
LD A,(560DH) 3A 0D 56
Load Register A with the value from memory address 560DH (current opcode storage)
673E
RRCA 0F
Rotate Register A right through carry by 1 bit position, moving bit 0 into carry and bit 7 into bit 0
673F
RRCA 0F
Rotate Register A right through carry by 1 bit position again (total 2 bits rotated)
6740
RRCA 0F
Rotate Register A right through carry by 1 bit position again (total 3 bits rotated, moving bits 3-5 into positions 0-2)
6741
JUMP to 6746H to mask bits 0-2 and return the destination register code

6743H - Decode Source Register (Bits 0-2)

This routine extracts bits 0-2 from the current opcode to decode the source register in LD and arithmetic instructions. Entry: none. Exit: A contains register code 0-7.

6743
LD A,(560DH) 3A 0D 56
Load Register A with the value from memory address 560DH (current opcode storage)
6746
AND 07H E6 07
Mask Register A with 07H to isolate bits 0-2 (the source register code, value 0-7 corresponding to B, C, D, E, H, L, (HL), A)
6748
RET C9
RETURN from the subroutine with the source register code (0-7) in Register A

6749H - Rotate Right 4 Bits

This utility routine rotates Register A right by 4 bit positions, effectively swapping the high and low nibbles. Entry: A contains value to rotate. Exit: A rotated right by 4 bits.

6749
RRCA 0F
Rotate Register A right through carry by 1 bit position
674A
RRCA 0F
Rotate Register A right through carry by 1 bit position (total 2 bits)
674B
RRCA 0F
Rotate Register A right through carry by 1 bit position (total 3 bits)
674C
RRCA 0F
Rotate Register A right through carry by 1 bit position (total 4 bits, high nibble is now in low nibble position)
674D
RET C9
RETURN from the subroutine with Register A rotated right by 4 bits

674EH - Output Source Register Name

This routine outputs the source register name by calling the register decoder and outputting a comma separator. Entry: none. Exit: comma stored in buffer at (HL), HL incremented.

674E
LD (HL),2CH 36 2C
Store 2CH (ASCII comma ',') to the memory address in Register HL (output buffer), adding a separator before the register name
6750
INC HL 23
Increment Register HL to point to the next position in the output buffer
6751
RET C9
RETURN from the subroutine with HL pointing past the comma in the output buffer

6752H - Output "A," Prefix

This routine outputs the accumulator register name "A" followed by a comma, used for ADD A,r and similar instructions. Entry: HL points to output buffer. Exit: "A," stored in buffer.

6752
CALL 6791H to output the 'A' character to the buffer at (HL)
6755
JUMP back to 674EH to output the comma separator after the 'A' character

6757H - Output Bit Number and Finalize

This routine processes bit number output for BIT/RES/SET instructions, then calls helper routines to complete the instruction. Entry: opcode contains bit number. Exit: instruction finalized.

6757
CALL 6789H to process or output the current operand (likely the bit number from bits 3-5 of the opcode)
675A
CALL 676DH to output additional formatting or operand information
675D
JUMP to 678DH to finalize the instruction line output and return to the main disassembly loop

6760H - Output Comma and Register A

This routine outputs a comma separator followed by the 'A' register name. Entry: HL points to output buffer. Exit: ",A" stored in buffer.

6760
CALL 674EH to output a comma separator to the buffer at (HL) and increment HL
6763
JUMP to 6791H to output the 'A' character after the comma

6765H - Output 'Z' Character

Outputs the letter 'Z' to the buffer, used for Z/NZ condition codes and Z80 register names. Entry: HL points to output buffer. Exit: 'Z' stored.

6765
LD (HL),5AH 36 5A
Store 5AH (ASCII 'Z') to the memory address in Register HL (output buffer)
6767
INC HL 23
Increment Register HL to point to the next position in the output buffer
6768
RET C9
RETURN from the subroutine

6769H - Output 'C' Character

Outputs the letter 'C' to the buffer, used for C/NC condition codes and C register name. Entry: HL points to output buffer. Exit: 'C' stored.

6769
LD (HL),43H 36 43
Store 43H (ASCII 'C') to the memory address in Register HL (output buffer)
676B
INC HL 23
Increment Register HL to point to the next position in the output buffer
676C
RET C9
RETURN from the subroutine

676DH - Output 'N' Character

Outputs the letter 'N' to the buffer, used as a prefix for negated conditions (NZ, NC). Entry: HL points to output buffer. Exit: 'N' stored.

676D
LD (HL),4EH 36 4E
Store 4EH (ASCII 'N') to the memory address in Register HL (output buffer)
676F
INC HL 23
Increment Register HL to point to the next position in the output buffer
6770
RET C9
RETURN from the subroutine

6771H - Output 'M' Character

Outputs the letter 'M' to the buffer, used for M (Minus/Negative) condition code and M register references. Entry: HL points to output buffer. Exit: 'M' stored.

6771
LD (HL),4DH 36 4D
Store 4DH (ASCII 'M') to the memory address in Register HL (output buffer)
6773
INC HL 23
Increment Register HL to point to the next position in the output buffer
6774
RET C9
RETURN from the subroutine

6775H - Output 'P' Character

Outputs the letter 'P' to the buffer, used for P (Plus/Positive) condition code and as a prefix for PE/PO parity conditions. Entry: HL points to output buffer. Exit: 'P' stored.

6775
LD (HL),50H 36 50
Store 50H (ASCII 'P') to the memory address in Register HL (output buffer)
6777
INC HL 23
Increment Register HL to point to the next position in the output buffer
6778
RET C9
RETURN from the subroutine

6779H - Output 'E' Character

Outputs the letter 'E' to the buffer, used for the E register name and as a suffix for PE (Parity Even) condition. Entry: HL points to output buffer. Exit: 'E' stored.

6779
LD (HL),45H 36 45
Store 45H (ASCII 'E') to the memory address in Register HL (output buffer)
677B
INC HL 23
Increment Register HL to point to the next position in the output buffer
677C
RET C9
RETURN from the subroutine

677DH - Output 'O' Character

Outputs the letter 'O' to the buffer, used as a suffix for PO (Parity Odd) condition. Entry: HL points to output buffer. Exit: 'O' stored.

677D
LD (HL),4FH 36 4F
Store 4FH (ASCII 'O') to the memory address in Register HL (output buffer)
677F
INC HL 23
Increment Register HL to point to the next position in the output buffer
6780
RET C9
RETURN from the subroutine

6781H - Output Minus Sign

Outputs a minus sign '-' to the buffer, used for negative displacements in indexed addressing. Entry: HL points to output buffer. Exit: '-' stored.

6781
LD (HL),2DH 36 2D
Store 2DH (ASCII minus sign '-') to the memory address in Register HL (output buffer)
6783
INC HL 23
Increment Register HL to point to the next position in the output buffer
6784
RET C9
RETURN from the subroutine

6785H - Output Plus Sign

Outputs a plus sign '+' to the buffer, used for positive displacements in indexed addressing. Entry: HL points to output buffer. Exit: '+' stored.

6785
LD (HL),2BH 36 2B
Store 2BH (ASCII plus sign '+') to the memory address in Register HL (output buffer)
6787
INC HL 23
Increment Register HL to point to the next position in the output buffer
6788
RET C9
RETURN from the subroutine

6789H - Output Opening Parenthesis

Outputs an opening parenthesis '(' to the buffer, used for indirect addressing modes like (HL), (IX+d), etc. Entry: HL points to output buffer. Exit: '(' stored.

6789
LD (HL),28H 36 28
Store 28H (ASCII opening parenthesis '(') to the memory address in Register HL (output buffer)
678B
INC HL 23
Increment Register HL to point to the next position in the output buffer
678C
RET C9
RETURN from the subroutine

678DH - Output Closing Parenthesis

Outputs a closing parenthesis ')' to the buffer, completing indirect addressing notation. Entry: HL points to output buffer. Exit: ')' stored.

678D
LD (HL),29H 36 29
Store 29H (ASCII closing parenthesis ')') to the memory address in Register HL (output buffer)
678F
INC HL 23
Increment Register HL to point to the next position in the output buffer
6790
RET C9
RETURN from the subroutine

6791H - Output 'A' Character

Outputs the letter 'A' to the buffer, used for the accumulator register name. Entry: HL points to output buffer. Exit: 'A' stored.

6791
LD (HL),41H 36 41
Store 41H (ASCII 'A') to the memory address in Register HL (output buffer)
6793
INC HL 23
Increment Register HL to point to the next position in the output buffer

6794H - Return After Outputting 'A'

Completes the output of 'A' character by returning from the subroutine. Entry: HL incremented by 6791H. Exit: returns to caller.

6794
RET C9
RETURN from the subroutine with 'A' character stored in the buffer and HL pointing past it

6795H - Output '0' Character

Outputs the digit '0' to the buffer, used for high-value addresses or special formatting. Entry: HL points to output buffer. Exit: '0' stored.

6795
LD (HL),30H 36 30
Store 30H (ASCII '0') to the memory address in Register HL (output buffer)
6797
INC HL 23
Increment Register HL to point to the next position in the output buffer
6798
RET C9
RETURN from the subroutine

6799H - Output 'H' Suffix

Outputs the 'H' suffix character used to denote hexadecimal numbers in assembly language. Entry: HL points to output buffer. Exit: 'H' stored.

6799
LD (HL),48H 36 48
Store 48H (ASCII 'H') to the memory address in Register HL (output buffer), marking the end of a hexadecimal number
679B
INC HL 23
Increment Register HL to point to the next position in the output buffer
679C
RET C9
RETURN from the subroutine

679DH - Output Character from Register B

Outputs a single character from Register B to the buffer at HL. This is used for variable character output. Entry: B contains ASCII character, HL points to buffer. Exit: character stored.

679D
LD (HL),B 70
Store the value in Register B (ASCII character code) to the memory address in Register HL (output buffer)
679E
INC HL 23
Increment Register HL to point to the next position in the output buffer
679F
RET C9
RETURN from the subroutine

67A0H - Output Destination Register from Opcode

Decodes the destination register from bits 3-5 of the opcode and outputs it to the buffer using a table lookup. Entry: HL points to output buffer. Exit: register name output.

67A0
CALL 673BH to decode the destination register from bits 3-5 of the opcode stored at 560DH, returning the register code (0-7) in Register A
67A3
LD DE,6832H 11 32 68
Load Register DE with 6832H, the base address of a register name lookup table
67A6
PUSH HL E5
Save Register HL (output buffer pointer) to the stack to preserve it during the table lookup
67A7
LD HL,55BDH 21 BD 55
Load Register HL with 55BDH, the address of a working buffer area for string manipulation
67AA
LD C,A 4F
Load Register C with the value from Register A (the register code 0-7), preserving it for the table lookup calculation
67AB
LD A,04H 3E 04
Load Register A with 04H, the number of bytes per entry in the register name table (each register name is 4 bytes)
67AD
CALL 680BH to perform table lookup and copy the register name string from the table at 6832H to the working buffer at 55BDH
67B0
POP HL E1
Restore Register HL from the stack, retrieving the original output buffer pointer from 67A6H
67B1
RET C9
RETURN from the subroutine with the register name looked up and ready for output

67B2H - Load Mnemonic String Pointer for Register Pair

Loads the address of a mnemonic string for register pair operations. Entry: none. Exit: DE contains string address, jumps to output routine.

67B2
LD DE,693FH 11 3F 69
Load Register DE with 693FH, the address of a mnemonic string or format template
67B5
JUMP to 67CEH to output the string pointed to by Register DE

67B7H - Load Mnemonic String for Final Output

Loads the address of another mnemonic string for instruction finalization. Entry: none. Exit: DE contains string address.

67B7
LD DE,6943H 11 43 69
Load Register DE with 6943H, the address of a mnemonic string or closing format template
67BA
JUMP to 67CEH to output the string pointed to by Register DE

67BCH - Load String at 687EH

Loads the address of a string at 687EH for output. Entry: none. Exit: DE contains string address.

67BC
LD DE,687EH 11 7E 68
Load Register DE with 687EH, the address of a mnemonic or format string
67BF
JUMP to 67CEH to output the string pointed to by Register DE

67C1H - Load String at 6876H

Loads the address of a string at 6876H for output. Entry: none. Exit: DE contains string address.

67C1
LD DE,6876H 11 76 68
Load Register DE with 6876H, the address of a mnemonic or format string
67C4
JUMP to 67CEH to output the string pointed to by Register DE

67C6H - Load String at 687AH

Loads the address of a string at 687AH for output. Entry: none. Exit: DE contains string address.

67C6
LD DE,687AH 11 7A 68
Load Register DE with 687AH, the address of a mnemonic or format string
67C9
JUMP to 67CEH to output the string pointed to by Register DE

67CBH - Load Default Mnemonic String

Loads the address of the default mnemonic string at 6852H and prepares for output. Entry: none. Exit: DE contains string address, jumps to output.

67CB
LD DE,6852H 11 52 68
Load Register DE with 6852H, the address of a default mnemonic string table
67CE
XOR A AF
Set Register A to 00H by XORing it with itself, clearing the accumulator and setting the Z FLAG
67CF
JUMP back to 67A6H to perform the table lookup and string output with A=00H indicating the default table mode

67D1H - Output Register Name from Table

Outputs a register name from the standard register table at 681CH. Entry: A contains register code. Exit: register name output to buffer.

67D1
LD C,A 4F
Load Register C with the value from Register A (register code 0-7), preserving it for the table lookup
67D2
LD DE,681CH 11 1C 68
Load Register DE with 681CH, the base address of the standard register name table (B, C, D, E, H, L, (HL), A)
67D5
LD A,01H 3E 01
Load Register A with 01H, the number of bytes per entry in this register table (single character register names)
67D7
JUMP to 680FH to perform the table lookup and copy the register name to the output buffer

67D9H - Output Register Pair Indirect (BC or DE)

Outputs indirect addressing notation for BC or DE register pairs, e.g., (BC) or (DE). Entry: opcode bit 4 determines which pair. Exit: indirect notation output.

67D9
BIT 4,A CB 67
Test bit 4 of Register A (the opcode value from 560DH). If bit 4 is 0, the Z FLAG is set (BC pair); if bit 4 is 1, the NZ FLAG is set (DE pair)
67DB
LD A,00H 3E 00
Load Register A with 00H, preparing to use BC pair as the default (table index 0)
67DD
If the Z FLAG is set (bit 4 is 0, use BC), JUMP to 67E0H to output "(BC)" using index 0
67DF
INC A 3C
Increment Register A from 00H to 01H to select DE pair instead (table index 1)
67E0
CALL 6789H to output an opening parenthesis '(' to the buffer
67E3
CALL 6803H to output the register pair name (BC or DE) based on the index in Register A
67E6
JUMP to 678DH to output the closing parenthesis ')' and return

67E8H - Output Register Pair at Index 1

Outputs a register pair name using table index 1. Entry: HL points to buffer. Exit: register pair name output.

67E8
LD A,01H 3E 01
Load Register A with 01H, setting the table index to 1 for the register pair lookup
67EA
JUMP to 6803H to output the register pair name at index 1 from the table

67ECH - Output Register Pair at Index 2

Outputs a register pair name using table index 2. Entry: HL points to buffer. Exit: register pair name output.

67EC
LD A,02H 3E 02
Load Register A with 02H, setting the table index to 2 for the register pair lookup
67EE
JUMP to 6803H to output the register pair name at index 2 from the table

67F0H - Get Register Pair Code from Low 2 Bits

Extracts bits 0-1 from the opcode to determine register pair and outputs it. Entry: none. Exit: register pair name output.

67F0
CALL 6727H to get bits 0-1 of the opcode (register pair code 0-3), returning the value in Register A
67F3
JUMP to 6803H to output the register pair name corresponding to the code in Register A

67F5H - Get Register Pair and Check for AF

Gets the register pair code from bits 0-1 of the opcode and checks if it equals 02H (AF pair). If so, clears processing state. Entry: none. Exit: A contains pair code.

67F5
CALL 6727H to get bits 0-1 of the opcode from 560DH, returning the register pair code (0-3) in Register A
67F8
CP 02H FE 02
Compare Register A with 02H to check if the register pair is AF (code 2). If equal, the Z FLAG is set; otherwise the NZ FLAG is set
67FA
If the NZ FLAG is set (pair is not AF, code is 0, 1, or 3), JUMP to 6803H to output the register pair name normally
67FC
XOR A AF
Set Register A to 00H by XORing it with itself, clearing the accumulator
67FD
LD (560FH),A 32 0F 56
Store Register A (00H) to memory address 560FH, clearing the processing state flag to reset it for the next instruction
6800
LD A,(5610H) 3A 10 56
Load Register A with the value from memory address 5610H (counter/state variable for tracking)

6803H - Output Register Pair Name from Table

Outputs a register pair name (BC, DE, HL, SP, AF, IX, IY) using table lookup. Entry: A contains pair code (0-3 or higher). Exit: pair name output to buffer.

6803
LD C,A 4F
Load Register C with the value from Register A (register pair code), preserving it for table index calculation
6804
LD DE,6824H 11 24 68
Load Register DE with 6824H, the base address of the register pair name table (BC, DE, HL, SP, AF, IX, IY, etc.)
6807
LD A,02H 3E 02
Load Register A with 02H, the number of bytes per entry in the register pair table (2-character pair names)
6809
JUMP to 680DH to prepare for table lookup by shifting the index left

680BH - Shift Index Left Once Before Lookup

Shifts the table index in Register C left by one bit before the main shift, used for 4-byte table entries. Entry: C contains index. Exit: C shifted left 1 bit.

680B
SLA C CB 21
Shift Register C left arithmetically by 1 bit position, doubling the value (for 4-byte table entries, this is the first shift)

680DH - Table Lookup and Copy to Output Buffer

This is the main table lookup routine. It calculates the offset into the table using the shifted index, copies the entry bytes to the output buffer, and returns. Entry: A=entry size, C=index, DE=table base, HL=output buffer. Exit: entry copied to buffer.

680D
SLA C CB 21
Shift Register C left arithmetically by 1 bit position, doubling the value (second shift, so C is now multiplied by entry size for 2-byte entries, or by 4 for 4-byte entries)
680F
LD B,00H 06 00
Load Register B with 00H, forming a 16-bit offset in Register BC (high byte = 0, low byte = shifted index)
6811
EX DE,HL EB
Exchange Register DE with Register HL, moving the table base address to HL and the output buffer pointer to DE
6812
ADD HL,BC 09
Add Register BC (the calculated offset) to Register HL (table base address), pointing HL to the correct table entry
6813
EX DE,HL EB
Exchange Register DE with Register HL again, moving the table entry address to DE and restoring the output buffer pointer to HL
6814
LD B,A 47
Load Register B with the value from Register A (entry size in bytes, e.g., 1, 2, or 4), using it as a loop counter

[LOOP START - Copy Table Entry to Output] - Copy each byte of the table entry to the output buffer

6815
LD A,(DE) 1A
Load Register A with the byte at the memory address in Register DE (current byte from the table entry)
6816
LD (HL),A 77
Store Register A (the table byte) to the memory address in Register HL (output buffer position)
6817
INC HL 23
Increment Register HL to point to the next position in the output buffer
6818
INC DE 13
Increment Register DE to point to the next byte in the table entry
6819
Decrement Register B (byte counter) and JUMP back to 6815H if B is not zero, continuing to copy the remaining bytes of the table entry

[LOOP END] - All bytes of the table entry have been copied to the output buffer

681B
RET C9
RETURN from the subroutine with the table entry copied to the output buffer and HL pointing past the copied data

681CH - DATA: Standard Register Name Table

This data table contains single-character register names for the Z80's 8-bit registers in standard opcode bit order: B, C, D, E, H, L, (HL indicator), A. Each entry is 1 byte. The table is indexed 0-7 corresponding to the 3-bit register encoding in Z80 opcodes.

681C
DEFB 42H 42
DATA: Register code 0 = 'B' (ASCII 42H)
681D
DEFB 43H 43
DATA: Register code 1 = 'C' (ASCII 43H)
681E
DEFB 44H 44
DATA: Register code 2 = 'D' (ASCII 44H)
681F
DEFB 45H 45
DATA: Register code 3 = 'E' (ASCII 45H)
6820
DEFB 48H 48
DATA: Register code 4 = 'H' (ASCII 48H)
6821
DEFB 4CH 4C
DATA: Register code 5 = 'L' (ASCII 4CH)
6822
DEFB 20H 20
DATA: Register code 6 = space (ASCII 20H) - placeholder for (HL) indirect which is handled separately
6823
DEFB 41H 41
DATA: Register code 7 = 'A' (ASCII 41H, accumulator)

6824H - DATA: Register Pair Name Table

This data table contains 2-character register pair names for the Z80's 16-bit register pairs. Each entry is 2 bytes (2 ASCII characters). Indexed 0-3+ for: BC, DE, HL, SP, AF, IX, IY.

6824
DEFB 42H 42
DATA: Pair code 0 = "BC" - first character 'B' (ASCII 42H)
6825
DEFB 43H 43
DATA: Pair code 0 = "BC" - second character 'C' (ASCII 43H)
6826
DEFB 44H 44
DATA: Pair code 1 = "DE" - first character 'D' (ASCII 44H)
6827
DEFB 45H 45
DATA: Pair code 1 = "DE" - second character 'E' (ASCII 45H)
6828
DEFB 48H 48
DATA: Pair code 2 = "HL" - first character 'H' (ASCII 48H)
6829
DEFB 4CH 4C
DATA: Pair code 2 = "HL" - second character 'L' (ASCII 4CH)

682AH - DATA: Register Pair Name Table (Continued)

Continuation of the register pair name table. This section contains additional 2-character register pair names: SP (Stack Pointer), IX (Index Register X), IY (Index Register Y), AF (Accumulator/Flags). Each entry is 2 bytes.

682A
DEFM "SP" 53 50
DATA: Pair code 3 = "SP" (Stack Pointer)
682C
DEFM "IX" 49 58
DATA: Pair code 4 = "IX" (Index Register X)
682E
DEFM "IY" 49 59
DATA: Pair code 5 = "IY" (Index Register Y)
6830
DEFM "AF" 41 46
DATA: Pair code 6 = "AF" (Accumulator/Flags pair)

6832H - DATA: Extended Register Name Table (4 bytes per entry)

This table contains 4-character register name strings used for special addressing modes and extended instruction formats. Each entry is 4 bytes and includes padding spaces where needed. Used by the table lookup routine at 680BH with entry size of 04H.

6832
DEFM "ADD " 41 44 44 20
DATA: Entry 0 = "ADD " (Add instruction mnemonic)
6836
DEFM "ADC " 41 44 43 20
DATA: Entry 1 = "ADC " (Add with Carry)
683A
DEFM "SUB " 53 55 42 20
DATA: Entry 2 = "SUB " (Subtract)
683E
DEFM "SBC " 53 42 43 20
DATA: Entry 3 = "SBC " (Subtract with Carry)
6842
DEFM "AND " 41 4E 44 20
DATA: Entry 4 = "AND " (Logical AND)
6846
DEFM "XOR " 58 4F 52 20
DATA: Entry 5 = "XOR " (Exclusive OR)
684A
DEFM "OR " 4F 52 20 20
DATA: Entry 6 = "OR " (Logical OR)
684E
DEFM "CP " 43 50 20 20
DATA: Entry 7 = "CP " (Compare)

6852H - DATA: Main Z80 Mnemonic Table

This is the primary mnemonic lookup table containing strings for all Z80 instruction mnemonics. Each entry is 4 bytes padded with spaces. This table is referenced by opcode decoders throughout the disassembler to output the correct instruction mnemonic. The table is indexed by instruction type and used by the output routine at 67CEH.

6852
DEFM "LD " 4C 44 20 20
DATA: "LD " (Load - the most common Z80 instruction)
6856
DEFM "JP " 4A 50 20 20
DATA: "JP " (Jump unconditional)
685A
DEFM "JR " 4A 52 20 20
DATA: "JR " (Jump Relative)
685E
DEFM "CALL" 43 41 4C 4C
DATA: "CALL" (Call subroutine)
6862
DEFM "RET " 52 45 54 20
DATA: "RET " (Return from subroutine)
6866
DEFM "DJNZ" 44 4A 4E 5A
DATA: "DJNZ" (Decrement B and Jump if Not Zero)
686A
DEFM "NOP " 4E 4F 50 20
DATA: "NOP " (No Operation)
686E
DEFM "ADC " 41 44 43 20
DATA: "ADC " (Add with Carry - duplicate for different opcode contexts)
6872
DEFM "SBC " 53 42 43 20
DATA: "SBC " (Subtract with Carry - duplicate for different opcode contexts)
6876
DEFM "INC " 49 4E 43 20
DATA: "INC " (Increment)
687A
DEFM "DEC " 44 45 43 20
DATA: "DEC " (Decrement)
687E
DEFM "EX " 45 58 20 20
DATA: "EX " (Exchange registers)
6882
DEFM "RST " 52 53 54 20
DATA: "RST " (Restart - call to fixed vector address)
6886
DEFM "HALT" 48 41 4C 54
DATA: "HALT" (Halt processor until interrupt)
688A
DEFM "PUSH" 50 55 53 48
DATA: "PUSH" (Push register pair onto stack)
688E
DEFM "POP " 50 4F 50 20
DATA: "POP " (Pop register pair from stack)
6892
DEFM "BIT " 42 49 54 20
DATA: "BIT " (Test bit - CB prefix instruction)
6896
DEFM "RES " 52 45 53 20
DATA: "RES " (Reset bit to 0 - CB prefix instruction)
689A
DEFM "SET " 53 45 54 20
DATA: "SET " (Set bit to 1 - CB prefix instruction)
689E
DEFM "IM " 49 4D 20 20
DATA: "IM " (Set Interrupt Mode - ED prefix instruction)
68A2
DEFM "DEFB" 44 45 46 42
DATA: "DEFB" (Define Byte - pseudo-op used for invalid/unrecognized opcodes)
68A6
DEFM "RLCA" 52 4C 43 41
DATA: "RLCA" (Rotate Left Circular Accumulator)
68AA
DEFM "RRCA" 52 52 43 41
DATA: "RRCA" (Rotate Right Circular Accumulator)
68AE
DEFM "RLA " 52 4C 41 20
DATA: "RLA " (Rotate Left Accumulator through carry)
68B2
DEFM "RRA " 52 52 41 20
DATA: "RRA " (Rotate Right Accumulator through carry)
68B6
DEFM "DAA " 44 41 41 20
DATA: "DAA " (Decimal Adjust Accumulator for BCD arithmetic)
68BA
DEFM "CPL " 43 50 4C 20
DATA: "CPL " (Complement Accumulator - one's complement)
68BE
DEFM "SCF " 53 43 46 20
DATA: "SCF " (Set Carry Flag)
68C2
DEFM "CCF " 43 43 46 20
DATA: "CCF " (Complement Carry Flag)
68C6
DEFM "RLD " 52 4C 44 20
DATA: "RLD " (Rotate Left Digit - BCD nibble shift left, ED prefix)
68CA
DEFM "NEG " 4E 45 47 20
DATA: "NEG " (Negate Accumulator - two's complement, ED prefix)
68CE
DEFM "RETN" 52 45 54 4E
DATA: "RETN" (Return from Non-Maskable Interrupt, ED prefix)
68D2
DEFM "RETI" 52 45 54 49
DATA: "RETI" (Return from Interrupt, ED prefix)
68D6
DEFM "OUT " 4F 55 54 20
DATA: "OUT " (Output to I/O port)
68DA
DEFM "IN " 49 4E 20 20
DATA: "IN " (Input from I/O port)
68DE
DEFM "DI " 44 49 20 20
DATA: "DI " (Disable Interrupts)
68E2
DEFM "EI " 45 49 20 20
DATA: "EI " (Enable Interrupts)

68E6H - DATA: ED/DD/FD Prefix Mnemonics

Extended mnemonic table for ED, DD, and FD prefix instructions (block operations, extended I/O, and special operations). These 4-byte entries are used when processing opcodes with prefix bytes A0H-BFH (after subtracting A0H). Referenced by routine at 6487H.

68E6
DEFM "LDIR" 4C 44 49 52
DATA: "LDIR" (Load, Increment, Repeat - block memory copy, ED B0H)
68EA
DEFM "CPIR" 43 50 49 52
DATA: "CPIR" (Compare, Increment, Repeat - search memory, ED B1H)
68EE
DEFM "INIR" 49 4E 49 52
DATA: "INIR" (Input, Increment, Repeat - block input, ED B2H)
68F2
DEFM "OTIR" 4F 54 49 52
DATA: "OTIR" (Output, Increment, Repeat - block output, ED B3H)
68F6
DEFM "LDDR" 4C 44 44 52
DATA: "LDDR" (Load, Decrement, Repeat - backward block copy, ED B8H)
68FA
DEFM "CPDR" 43 50 44 52
DATA: "CPDR" (Compare, Decrement, Repeat - backward search, ED B9H)
68FE
DEFM "INDR" 49 4E 44 52
DATA: "INDR" (Input, Decrement, Repeat - backward block input, ED BAH)
6902
DEFM "OTDR" 4F 54 44 52
DATA: "OTDR" (Output, Decrement, Repeat - backward block output, ED BBH)
6906
DEFM "LDI " 4C 44 49 20
DATA: "LDI " (Load and Increment - single byte transfer, ED A0H)
690A
DEFM "CPI " 43 50 49 20
DATA: "CPI " (Compare and Increment - single byte compare, ED A1H)
690E
DEFM "INI " 49 4E 49 20
DATA: "INI " (Input and Increment - single byte input, ED A2H)
6912
DEFM "OUTI" 4F 55 54 49
DATA: "OUTI" (Output and Increment - single byte output, ED A3H)
6916
DEFM "LDD " 4C 44 44 20
DATA: "LDD " (Load and Decrement - single byte transfer backward, ED A8H)
691A
DEFM "CPD " 43 50 44 20
DATA: "CPD " (Compare and Decrement - single byte compare backward, ED A9H)
691E
DEFM "IND " 49 4E 44 20
DATA: "IND " (Input and Decrement - single byte input backward, ED AAH)
6922
DEFM "OUTD" 4F 55 54 44
DATA: "OUTD" (Output and Decrement - single byte output backward, ED ABH)
6926
DEFM "RRD " 52 52 44 20
DATA: "RRD " (Rotate Right Digit - BCD nibble shift right, ED 67H)

692AH - DATA: Special Register Code Lookup Table

This 5-byte table is used by the RES/SET instruction handler at 6502H to identify special register codes for I, R, IXH, IXL, IYH, IYL registers. The table is searched backwards.

692A
DEFB 4DH 4D
DATA: Special register code for 'M' register (used in lookup)
692B
DEFM "RRD " 52 52 44 20
DATA: String continuation or register name table entry
692F
DEFM "RLD " 52 4C 44 20
DATA: String continuation or register name table entry
6933
DEFM "NEG " 4E 45 47 20
DATA: String continuation or register name table entry
6937
DEFM "RETN" 52 45 54 4E
DATA: "RETN" mnemonic string
693B
DEFM "RETI" 52 45 54 49
DATA: "RETI" mnemonic string
693F
DEFM "OUT " 4F 55 54 20
DATA: "OUT " mnemonic string
6943
DEFM "IN " 49 4E 20 20
DATA: "IN " mnemonic string
6947
DEFM "DI " 44 49 20 20
DATA: "DI " mnemonic string
694B
DEFM "EI " 45 49 20 20
DATA: "EI " mnemonic string
694F
DEFM "EXX " 45 58 58 20
DATA: "EXX " (Exchange alternate register set)
6953
DEFM "ADD " 41 44 44 20
DATA: "ADD " mnemonic string
6957
DEFM "AAA " 41 41 41 20
DATA: "AAA " (appears to be padding or template)

695BH - DATA: Assembler Directive and Format Strings

This section contains assembler directive strings and output formatting templates used when generating the disassembly output. These include pseudo-ops like EQU, ORG, END, and formatting strings with special characters (09H = TAB, 0DH = CR).

695B
DEFM "EQU" 45 51 55
DATA: "EQU" pseudo-op for equate directive
695E
DEFB 09H 09
DATA: TAB character (ASCII 09H) - used for formatting output columns
695F
DEFM "0000H" 30 30 30 30 48
DATA: "0000H" template string for hex address output
6964
DEFB 0DH 0D
DATA: CR (Carriage Return, ASCII 0DH) - end of line marker
6965
DEFM "AAA" 41 41 41
DATA: "AAA" template (address/label placeholder)
6968
DEFB 09H 09
DATA: TAB character for column alignment
6969
DEFM "EQU" 45 51 55
DATA: "EQU" directive (duplicate or template)
696C
DEFB 09H 09
DATA: TAB character
696D
DEFM "$-" 24 2D
DATA: "$-" current address minus operator (for relative calculations)
696F
DEFB 30H 30
DATA: '0' character (ASCII 30H)
6970
DEFB 0DH 0D
DATA: CR (end of line)
6971
DEFB 09H 09
DATA: TAB character
6972
DEFM "ORG" 4F 52 47
DATA: "ORG" directive (set origin address)
6975
DEFB 09H 09
DATA: TAB character
6976
DEFM "0000H" 30 30 30 30 48
DATA: "0000H" template for ORG address
697B
DEFB 0DH 0D
DATA: CR (end of line)
697C
DEFB 09H 09
DATA: TAB character
697D
DEFM "END" 45 4E 44
DATA: "END" directive (end of assembly source)
6980
DEFB 09H 09
DATA: TAB character
6981
DEFM "AAA" 41 41 41
DATA: "AAA" template (end address placeholder)
6984
DEFB 0DH 0D
DATA: CR (end of line)
6985
DEFM "0000 " 30 30 30 30 20
DATA: "0000 " template (4-digit hex with space)
698A
DEFB B0H B0
DATA: Graphics character B0H (shaded block - column separator for output formatting)
698B
DEFB B0H B0
DATA: Graphics character B0H (shaded block)
698C
DEFB B0H B0
DATA: Graphics character B0H (shaded block)
698D
DEFB B0H B0
DATA: Graphics character B0H (shaded block)
698E
DEFB B0H B0
DATA: Graphics character B0H (shaded block - end of 5-character separator)

698FH - DATA: User Prompt Strings Section

This section (698FH-6D1FH) contains all the user-facing prompt strings, error messages, help text, and interactive prompts used by the disassembler. The section includes strings for the main menu, option descriptions, error messages, and command syntax help. This section has been documented separately by the user and is not included in this part.

698F
[USER PROMPT STRINGS - 698FH through 6D1FH]
6992-69A7
DEFM "DISASSEMBLER 3.0" + 00H
69AC-69B1
DEFM "OBJECT " + 00H
69B2-69B9
DEFM "FROM MAIN " + 00H
69B9-69C3
DEFM "MEMORY OR DISK? " + 00H
69C5-69D6
DEFM "(M OR D) " + 00H
69D8-69F3
DEFM "OBJECT VIRTUAL BASE ADDRESS? (HEX) " + 00H
69FC-6A15
DEFM "OBJECT REAL BASE ADDRESS? (HEX) " + 00H
6A1D-6A2E
DEFM "BYTE COUNT? (HEX) " + 00H
6A30-6A48
DEFM "VIRTUAL RESTART LOCATION? (HEX) " + 00H
6A52-6A5B
DEFM "BAD REPLY" + 00H
6A5C-6A87
DEFM "OFFSET OBJECT VIRTUAL ADDRESSES BY? (HEX) " + 00H
6A88-6A91
DEFM "FILESPEC? " + 00H
6A93-6AAD
DEFM "0000 = PROGRAM ENTRY POINT" + 00H
6AAE-6AB3
DEFM "REP" + 00H
6AB5-6AD7
DEFM "ENTER " W" + 00H
6AD8-6AE3
DEFM "***" + 00H
6AE4-6AF7
DEFM "FUNCTION CANCELLED" + 00H
6AF8-6B0B
DEFM "INSUFFICIENT MEMORY" + 00H
6B0C-6B1B
DEFM "BAD MEMORY" + 00H
6B1C-6B34
DEFM "LOCATION REFERENCED" + 0DH
6B35-6B64
DEFM "REFERENCED SUFFIX INDICATES RESERVED" + 0DH
6B66-6B6F
DEFM "TYPE" + 0DH
6B73-6B79
DEFM "P = JP" + 0DH
6B7C-6B82
DEFM "R = JR" + 0DH
6B85-6B95
DEFM "S = LD ,NN)" + 0DH
6B98-6BA8
DEFM "T = LD A,NN)" + 0DH
6BB9-6BC9
DEFM "U = LD (NN),A" + 0DH
6BEA-6BFC
DEFM "W = LD (NN),A" + 0DH
6BFD-6C1E
DEFM "X = OUT (N),A" + 00H
6C20-6C3F
DEFM "END OF LOCATION REFERENCED TABLE" + 00H
6C40-6C6C
DEFM "REFERENCED TYPE(S) ARE NOT PRINTED" + 00H
6C69-6C75
DEFM "ANY OPTIONS? " + 00H
6C77-6C8F
DEFM "REFERENCED TABLE FILESPEC? " + 00H
6C92-6CBE
DEFM "AF,'ASSEMBLER SOURCE TEXT OUTPUT FILESPEC? " + 00H
6CC0-6CD3
DEFM "SEQUENCE # OVERFLOW" + 00H
6CD4-6CF0
DEFM "HIGH ASCII CODE FOR PRINTER?" + 00H
6CF2-6CFF
DEFM "(5A - 7F HEX) " + 00H
6D01-6D1F
DEFM "ANOTHER DISASSEMBLED? (Y OR N) " + 00H

6D20H - DATA: Additional User Prompt Strings

This section contains error messages and user prompts displayed when configuring output options for the disassembler. These strings are displayed during interactive setup to guide the user through pagination and margin settings.

6D21-6D4D
DEFM "ATLEAST ONE OPTION REQUIRES OBJECT FROM DISK" + 00H
6D4E-6D8C
DEFM "# LINES PER PAGE, EXCLUDING TOP AND BOTTOM MARGINS? (1 - 255)" + 0DH
6D8E-6DC0
DEFM "# LINES EACH FOR TOP AND BOTTOM MARGINS? (0 - 10)" + 00H
6DC1-6DDF
DEFM "BUILDING CROSS-REFERENCE TABLE" + 00H

6DE0H - Initialize Label Buffer Pointer

This short routine initializes the label buffer by setting up the IX register to point to the label buffer start. Entry: DE contains a value. Exit: IX points to 6FA0H (label buffer header), HL loaded with 6FA0H.

6DE0
PUSH DE D5
Save Register DE to the stack to preserve it during initialization
6DE1
POP IX DD E1
Restore the value from the stack into Index Register IX, effectively copying DE to IX
6DE3
LD HL,6FA0H 21 A0 6F
Load Register HL with 6FA0H, the start address of the label buffer header area in high memory
6DE6
RET C9
RETURN from the subroutine with IX and HL both pointing to the label buffer initialization structure

6DE7H - DATA: Padding/Unused Space

This section contains padding bytes (00H/NOP) between the end of executable code and the start of the uninitialized buffer area. This space may have been reserved for future expansion or to align the buffer on a specific boundary.

6DE7
DEFB 00H 00
DATA: Padding byte (NOP/unused)
6DE8
DEFB 00H 00
DATA: Padding byte
6DE9
DEFB 00H 00
DATA: Padding byte
6DEA
DEFB 00H 00
DATA: Padding byte
6DEB
DEFB 00H 00
DATA: Padding byte
6DEC
DEFB 00H 00
DATA: Padding byte
6DED
DEFB 00H 00
DATA: Padding byte
6DEE
DEFB 00H 00
DATA: Padding byte
6DEF
DEFB 00H 00
DATA: Padding byte
6DF0
DEFB 00H 00
DATA: Padding byte
6DF1
DEFB 00H 00
DATA: Padding byte
6DF2
DEFB 00H 00
DATA: Padding byte
6DF3
DEFB 00H 00
DATA: Padding byte
6DF4
DEFB 00H 00
DATA: Padding byte
6DF5
DEFB 00H 00
DATA: Padding byte
6DF6
DEFB 00H 00
DATA: Padding byte
6DF7
DEFB 00H 00
DATA: Padding byte
6DF8
DEFB 00H 00
DATA: Padding byte
6DF9
DEFB 00H 00
DATA: Padding byte
6DFA
DEFB 00H 00
DATA: Padding byte
6DFB
DEFB 00H 00
DATA: Padding byte
6DFC
DEFB 00H 00
DATA: Padding byte
6DFD
DEFB 00H 00
DATA: Padding byte
6DFE
DEFB 00H 00
DATA: Padding byte
6DFF
DEFB 00H 00
DATA: Padding byte (25 bytes total padding from 6DE7H-6DFFH)

6E00H - Uninitialized Buffer Area

This large section (6E00H-6E7BH, 124 bytes) represents uninitialized buffer space that will be used at runtime for temporary storage, label buffer overflow, or dynamic data structures. The area is filled with 00H bytes in the /CMD file but will be overwritten during program execution. This marks the end of the APPARAT DISASSEMBLER 3.0 program image.

6E00
[UNINITIALIZED BUFFER - 6E00H through 6E7BH]
124 bytes of uninitialized buffer space (00H padding in file image)
Used at runtime for: temporary storage, dynamic buffers, overflow space
This area is not documented in detail as it contains no executable code.
End of APPARAT DISASSEMBLER 3.0 Program - Total Size: 6,808 bytes (55E4H-6E7BH)