4D00H - Module Entry and Stack Adjustment
Entry point for SYS21 CMD"O" command processor. Adjusts the stack by removing two bytes (discarding a return address or parameter), then validates the command character to determine processing path. The character must be either '7' (37H) or 'W' (57H) for valid CMD"O" operations.
4D00
INC SP 33
Increment the Stack Pointer by 1, effectively discarding the low byte of a return address or parameter that was pushed onto the stack.
4D01
INC SP 33
Increment the Stack Pointer again, discarding the high byte. Together, these two INC SP instructions remove a 16-bit value from the stack without using it.
4D02
CP 37H FE 37
Compare Register A to 7 (37H). This checks if the CMD"O" command includes a '7' parameter character.
4D04
If the Z FLAG is set (character is '7'), JUMP to 4DBAH to handle the FCB initialization routine. This is the CMD"O7" path.
4D07
CP 57H FE 57
Compare Register A to W (57H). This checks if the command is CMD"OW" for write operations.
4D09
LD A,2AH 3E 2A
Load Register A with 2AH (asterisk character '*'). This will be used as an error code or marker if the command character is invalid.
4D0B
If the NZ FLAG is set (character is neither '7' nor 'W'), JUMP to 5E16H (BASIC/CMD error handler) with error code 2AH in Register A. Invalid command character generates an error.
4D0EH - CMD"OW" Parameter Setup
Processes the 'W' command path for CMD"OW" operations. Stores the parameter byte, sets up a callback address for return/continuation, and begins parsing the command string for comma-separated parameters.
4D0E
LD A,B 78
Copy Register B to Register A. Register B contains a parameter or count value from the calling routine.
4D0F
LD (4D8DH),A 32 8D 4D
Store Register A at 4D8DH, which is a self-modifying code location. This value will be checked later at 4D8BH to determine processing behavior.
4D12
LD BC,4D67H 01 67 4D
Load BC with 4D67H, which is the address of a continuation point in this routine. This will serve as a callback address.
4D15
Store BC (4D67H) at 644EH, a callback storage location in BASIC/CMD. This sets up a return address for operations that need to come back to this module.
4D19
DEC HL 2B
Decrement HL to point to the previous character in the BASIC text (before the current command position).
4D1A
RST 10H D7
Call RST 10H - ROM routine at 0010H, which compares HL with DE. This checks if we're at a specific position in the command string.
4D1B
If the Z FLAG is set (positions match), JUMP to 4D62H to begin the main processing loop. No parameters to parse.
4D1D
RST 08H CF
Call RST 08H - ROM routine at 0008H, which compares (HL) with Register A. This checks if the next character matches what's expected.
4D1E
INC L 2C
Increment the low byte of HL, moving to the next character in the command string. Note this only increments L, not HL, which is unusual and may be intentional for specific parsing.
4D1F
If the NZ FLAG is set (character doesn't match), JUMP to 4D2BH to process the string parameter differently.
[COMMA-SEPARATED PARAMETER LOOP] The following code handles parsing comma-separated parameters in the CMD"OW" command string. Each parameter is processed, and the loop continues until no more commas are found.
4D21
[PARAMETER LOOP START] Call 5D9FH (BASIC/CMD routine to skip to next statement or parameter). Advances past the current parameter.
4D24
RST 10H D7
Call RST 10H to compare pointers, checking if we've reached the end of parameters.
4D25
If the Z FLAG is set (end reached), JUMP back to 4D21H to process the next parameter. Continue the loop.
4D27
CP 93H FE 93
Compare Register A to 93H, which is the tokenized BASIC code for a specific statement or keyword (possibly REM or another statement separator).
4D29
If the Z FLAG is set (token 93H found), JUMP back to 4D21H to continue processing. [LOOP POINT]
4D2BH - String Parameter Processing
Processes string parameters from the CMD"OW" command. Evaluates the string expression, validates it's a string type, then performs complex memory boundary checking against MEMSIZ and string space limits to ensure the operation won't overflow available memory.
4D2B
Call 5BDDH (BASIC/CMD string expression evaluator). Evaluates the string parameter following CMD"OW" and returns with the result. Returns NZ if result is a string, Z if not.
4D2E
LD DE,(40FBH) ED 5B FB 40
Load DE with the value at 40FBH, which is a working string pointer used during string operations. This marks the current position in string space.
4D32
If the NZ FLAG is set (result is a string), JUMP to 4D4CH to handle string result processing with different boundary checks.
[NUMERIC RESULT PATH] The parameter evaluated to a numeric value (Z FLAG was set from CALL 5BDDH). Now perform memory validation against MEMSIZ to ensure sufficient space for operations.
4D34
Call 5C48H (BASIC/CMD memory allocation or validation routine). Checks if there's enough memory space for the upcoming operation.
4D37
If the C FLAG is set (insufficient memory), JUMP to ROM routine 1997H, which generates an "Out of Memory" error (OM ERROR).
4D3A
PUSH HL E5
Push HL onto the stack, preserving the current text pointer for later restoration.
4D3B
LD HL,(40FDH) 2A FD 40
[MEMSIZ BOUNDARY CHECK LOOP] Load HL with the value at 40FDH, which is MEMSIZ - the highest usable memory address. This is the upper boundary for memory operations.
4D3E
EX DE,HL EB
Exchange DE and HL. HL now contains the working string pointer (from 40FBH), DE contains MEMSIZ.
4D3F
RST 18H DF
[COMPARISON LOOP] Call RST 18H - ROM routine at 0018H, which compares HL with DE. Sets Z if HL=DE, C if HL<DE.
4D40
If the Z FLAG is set (pointers are equal, reached MEMSIZ), JUMP to 4D5DH for cleanup and exit. Boundary reached.
4D42
Call 5C21H (BASIC/CMD routine to process or validate current memory position). Returns Z if processing complete, NZ to continue.
4D45
If the Z FLAG is set (processing complete), JUMP to 4D5BH to set a flag and exit the loop.
4D47
Call 5C3FH (BASIC/CMD routine to advance pointer or process next element). Moves to the next memory position.
4D4A
JUMP to 4D3FH to continue the comparison loop. Keep checking memory boundaries. [LOOP CONTINUES]
[STRING RESULT PATH] Alternative processing path when the parameter was a string (NZ FLAG at 4D32H). Checks against string space boundary (40F9H) instead of MEMSIZ.
4D4C
PUSH HL E5
Push HL, saving the current position.
4D4D
LD HL,(40F9H) 2A F9 40
Load HL with the value at 40F9H, which is the string space boundary pointer. This is the lower limit for string storage.
4D50
RST 18H DF
[STRING BOUNDARY LOOP] Compare HL with DE (string space check).
4D51
If Z (reached string boundary), JUMP to 4D5DH for cleanup.
4D53
Call processing routine.
4D56
If NZ (continue processing), Call 5C34H (BASIC/CMD secondary processing routine).
4D59
If NZ (not done), JUMP to 4D50H to continue string boundary check loop. [LOOP CONTINUES]
4D5B
SET 4,(HL) CB E6
[PROCESSING COMPLETE] Set bit 4 of the byte at (HL). This marks the current position with a flag (bit 4 = 1) to indicate completion or a special state.
4D5D
POP HL E1
[CLEANUP] Pop HL, restoring the saved text pointer from 4D3AH or 4D4CH.
4D5E
DEC HL 2B
Decrement HL to adjust the pointer back one position.
4D5F
RST 10H D7
Call RST 10H to compare positions.
4D60
If NZ (more parameters to process), JUMP back to 4D1DH to continue parsing the command string. Loop continues until all parameters processed.
4D62H - Main FCB Processing Loop Setup
Sets up the main File Control Block (FCB) processing loop. Establishes continuation address, loads initial pointers for string space boundaries, and begins iterating through the FCB table at 4200H. The loop at 4D6CH processes each FCB entry.
4D62
PUSH HL E5
Push HL onto the stack, preserving the current text pointer position for potential later use.
4D63
LD HL,5881H 21 81 58
Load HL with 5881H, which is a continuation address or return point in BASIC/CMD code. This will be pushed as a return address.
4D66
PUSH HL E5
Push HL (5881H) onto the stack, establishing it as the return address when the current operation completes.
4D67
LD HL,(40F9H) 2A F9 40
[CALLBACK ENTRY POINT] This is the address stored at 644EH (set at 4D15H). Load HL with the value at 40F9H, the string space boundary pointer (lower limit of string storage).
4D6A
LD D,H 54
Copy H to D, beginning to transfer HL to DE.
4D6B
LD E,L 5D
Copy L to E, completing the transfer. DE now holds the string space boundary (40F9H value).
4D6C
PUSH DE D5
[FCB TABLE LOOP START] Push DE (string boundary) onto the stack for safekeeping during FCB processing.
4D6D
LD DE,(40FBH) ED 5B FB 40
Load DE with the value at 40FBH, the working string pointer (current position in string operations). This is the upper boundary for the current operation.
4D71
RST 18H DF
Call RST 18H to compare HL (string space boundary) with DE (working pointer). Sets Z if equal, C if HL<DE.
4D72
POP DE D1
Pop DE, restoring the string space boundary pushed at 4D6CH.
4D73
If the Z FLAG is set (boundaries match, no space to process), JUMP to 4D94H to finalize and exit the FCB loop.
4D75
LD BC,4D6CH 01 6C 4D
Load BC with 4D6CH, the address of the FCB loop start. This will be pushed as a return address to create a loop.
4D78
PUSH BC C5
Push BC (4D6CH) onto the stack. When the subroutine at 4D79H returns, it will jump back to 4D6CH, continuing the loop.
[FCB ENTRY PROCESSING] Process the current FCB entry. Examines the FCB flags, determines the operation type (copy or skip), and handles the entry appropriately based on bit flags.
4D79
LD A,(HL) 7E
Load Register A with the byte at (HL), which is the first byte of the current FCB entry. This byte contains status flags.
4D7A
AND 0FHAND 00001111 E6 0F
Mask Register A to keep only the lower 4 bits (bits 0-3). This extracts a count or type field from the FCB flags.
4D7C
ADD 03H C6 03
Add 03H to Register A. This adjusts the count (e.g., if lower 4 bits were 00H, result is 03H; if 02H, result is 05H).
4D7E
LD C,A 4F
Copy Register A to Register C. C now contains the byte count for an operation (minimum 3 bytes).
4D7F
LD B,00H 06 00
Load Register B with 00H, making BC a 16-bit count with high byte = 00H.
4D81
INC HL 23
Increment HL to point to the next byte in the FCB entry (offset +1).
4D82
INC HL 23
Increment HL again (now at offset +2 from FCB start).
4D83
BIT 7,(HL) CB 7E
Test bit 7 of the byte at (HL) (FCB offset +2). This bit indicates a special condition or operation mode.
4D85
DEC HL 2B
Decrement HL back to offset +1.
4D86
DEC HL 2B
Decrement HL again back to offset +0 (FCB start). HL now points back to the beginning of the FCB entry.
4D87
If bit 7 was set (NZ), JUMP to 4D91H to perform an LDIR copy operation. This FCB entry needs its data copied.
4D89
BIT 4,(HL) CB 66
Test bit 4 of the byte at (HL) (FCB offset +0). This is another flag controlling processing.
4D8B
RES 4,(HL) CB A6
Clear bit 4 at (HL), resetting the flag. The FCB entry is being marked as processed.
4D8D
Self-modifying location: The byte at 4D8DH (currently 20H = JR NZ) was set at 4D0FH. If the stored value makes bit 4 significant, jump to copy; otherwise fall through to skip.
4D8F
ADD HL,BC 09
[SKIP FCB ENTRY] Add BC (byte count) to HL, skipping over this FCB entry without copying it. HL now points to the next FCB entry.
4D90
RET C9
Return to the address on stack (4D6CH from 4D78H), continuing the FCB processing loop with the next entry.
4D91
LDIR ED B0
[COPY FCB ENTRY] Block copy: Copy BC bytes from (HL) to (DE), incrementing both pointers. This copies the FCB entry data to its destination. After LDIR, HL and DE point past the copied data.
4D93
RET C9
Return to 4D6CH, continuing the loop with the next FCB entry. The copy operation is complete.
4D94H - FCB Loop Finalization
Finalizes the FCB processing loop after all entries have been processed. Updates the string pointers (40FBH and 40FDH) to reflect the new memory boundaries after all FCB operations, then jumps to continuation code at 64BEH.
4D94
LD (40FBH),DE ED 53 FB 40
[FINALIZATION] Store DE at 40FBH, updating the working string pointer to its new position after all FCB processing. This marks where string operations stopped.
4D98
PUSH DE D5
Push DE onto the stack, preserving the updated working pointer for comparison.
4D99
LD DE,(40FDH) ED 5B FD 40
Load DE with the value at 40FDH (MEMSIZ - highest usable memory address). This is the upper memory boundary.
4D9D
RST 18H DF
Call RST 18H to compare HL with DE (MEMSIZ). Checks if there's more memory to process.
4D9E
POP DE D1
Pop DE, restoring the working pointer saved at 4D98H.
4D9F
If the Z FLAG is set (reached MEMSIZ, no more memory), JUMP to 4DB3H to finalize and exit.
[ADDITIONAL MEMORY PROCESSING] There's more memory between the current position and MEMSIZ. Process any remaining FCB entries or data in this range.
4DA1
PUSH HL E5
Push HL, saving the current position.
4DA2
INC HL 23
Increment HL to offset +1.
4DA3
INC HL 23
Increment to offset +2.
4DA4
INC HL 23
Increment to offset +3. HL now points to offset +3 from the FCB entry start.
4DA5
LD C,(HL) 4E
Load Register C with the byte at (HL) (offset +3), which is the low byte of a count or size.
4DA6
INC HL 23
Increment to offset +4.
4DA7
LD B,(HL) 46
Load Register B with the byte at (HL) (offset +4), the high byte of the count. BC now contains a 16-bit size value.
4DA8
INC BC 03
Increment BC by 1.
4DA9
INC BC 03
Increment BC again (BC = BC + 2).
4DAA
INC BC 03
Increment BC again (BC = BC + 3).
4DAB
INC BC 03
Increment BC again (BC = BC + 4).
4DAC
INC BC 03
Increment BC one more time (BC = BC + 5). BC now holds the original size + 5, which is the total FCB entry size including overhead.
4DAD
POP HL E1
Pop HL, restoring the FCB entry start address saved at 4DA1H.
4DAE
Call 4D89H, which checks bit 4 of the FCB and either skips (ADD HL,BC) or copies (LDIR) the entry. Processes this additional FCB entry.
4DB1
JUMP back to 4D98H to check for more memory to process. Continue the finalization loop until MEMSIZ is reached. [LOOP CONTINUES]
4DB3
LD (40FDH),DE ED 53 FD 40
[EXIT FINALIZATION] Store DE at 40FDH, updating MEMSIZ to reflect the new highest usable memory after all FCB operations.
4DB7
JUMP to 64BEH (BASIC/CMD continuation routine). All FCB processing is complete, return to BASIC for next operation.
4DBAH - CMD"O7" FCB Initialization
Handles the CMD"O7" command which initializes all File Control Blocks. Clears system flags, then creates 9 FCB entries at 4200H (each 23 bytes = 17H), initializing them with default values: file number (01H-09H), status byte (01H/FFH), mode flags (01H), and zeroing all other fields.
4DBA
XOR A AF
Set Register A to 00H by XORing with itself. This will be used to clear various locations.
4DBB
LD (4317H),A 32 17 43
Store 00H at 4317H, clearing a system flag used by BASIC/CMD operations. This indicates a clean state.
4DBE
LD (576EH),A 32 6E 57
Store 00H at 576EH, clearing the return value storage location in BASIC/CMD. Resets previous operation results.
4DC1
PUSH HL E5
Push HL onto the stack, preserving the current text pointer position.
4DC2
LD HL,4200H 21 00 42
Load HL with 4200H, the FCB table base address. This is where the 9 FCB entries will be created.
4DC5
LD C,09H 0E 09
Load Register C with 09H (9 decimal), the number of FCB entries to initialize. The system supports 9 open files.
4DC7
LD DE,0000H 11 00 00
Load DE with 0000H. D will be used for zero values, E will be incremented for file numbers.
[FCB INITIALIZATION LOOP] Create 9 FCB entries, each 23 bytes (17H). Each entry gets: file number (01H-09H), status byte (01H/FFH), mode (01H), and 19 zero bytes.
4DCA
INC E 1C
[OUTER LOOP START] Increment E, making it 01H on first iteration, 02H on second, etc. This is the file number for the current FCB entry.
4DCB
LD (HL),E 73
Store E at (HL), writing the file number (01H-09H) as the first byte of the FCB entry (offset +0).
4DCC
INC HL 23
Increment HL to offset +1.
4DCD
LD (HL),D 72
Store D (00H) at (HL), initializing offset +1 to zero (will be changed next).
4DCE
INC HL 23
Increment to offset +2.
4DCF
LD (HL),01H 36 01
Store 01H at (HL), setting offset +2 to 01H. This is a mode or status flag indicating the file is available/initialized.
4DD1
INC HL 23
Increment to offset +3.
4DD2
LD (HL),FFH 36 FF
Store FFH at (HL), setting offset +3 to FFH. This is likely an uninitialized marker or special flag (-1 in signed).
4DD4
INC HL 23
Increment to offset +4, preparing to zero the remaining bytes.
4DD5
LD B,13H 06 13
Load Register B with 13H (19 decimal), the count of remaining bytes to clear in this FCB entry. 23 total - 4 initialized = 19 to zero.
4DD7
LD (HL),D 72
[INNER LOOP - ZERO FILL] Store D (00H) at (HL), clearing one byte of the FCB entry.
4DD8
INC HL 23
Increment HL to the next byte position.
4DD9
Decrement B and JUMP to 4DD7H if not zero. Continue zeroing bytes until all 19 are cleared. [INNER LOOP END]
4DDB
DEC C 0D
Decrement C (FCB entry counter). One FCB entry is complete.
4DDC
If NZ (more FCB entries to initialize), JUMP to 4DCAH to create the next entry. Continue until all 9 FCBs are initialized. [OUTER LOOP END]
4DDE
LD (HL),D 72
Store D (00H) at (HL), writing one final zero byte after the 9th FCB entry (table terminator).
4DDF
INC HL 23
Increment HL past the terminator.
4DE0
LD (HL),D 72
Store another D (00H), ensuring the FCB table is properly terminated with zeros.
4DE1
POP HL E1
Pop HL, restoring the original text pointer saved at 4DC1H.
4DE2H - String Parameter Parsing
Parses comma-separated string parameters from the CMD"O7" command. Uses RST 08H to check for commas, calls the string expression evaluator, and stores the resulting string pointer for later use. Continues parsing until no more commas are found.
4DE2
RST 08H CF
Call RST 08H (0008H) - ROM routine that compares (HL) with Register A to check for specific characters (likely comma or separator).
4DE3
INC L 2C
Increment the low byte of HL. Note this only increments L, not HL, which may be intentional for specific boundary handling.
4DE4
Call ROM routine 1E46H, which likely performs string expression evaluation or parameter parsing for BASIC commands.
4DE7
LD IX,4200H DD 21 00 42
Load Index Register IX with 4200H, the FCB table base. IX will be used to index through FCB entries efficiently.
4DEB
LD (4F27H),DE ED 53 27 4F
Store DE at 4F27H, a self-modifying code location. This address is part of a "LD (nnnn),DE" instruction that will be modified to store string pointers dynamically.
4DEF
LD A,(IX+00H) DD 7E 00
Load Register A with the byte at IX+0 (first byte of first FCB entry at 4200H), which is the file number or status byte.
4DF2
OR A B7
Set flags based on Register A. If A is 00H (unused FCB), Z FLAG will be set.
4DF3
If the Z FLAG is set (FCB is unused/invalid), JUMP to ROM routine 1997H to generate an "Out of Memory" or initialization error.
4DF6
RST 08H CF
Call RST 08H to check the current character against Register A.
4DF7
INC L 2C
Increment L to move to the next character position.
4DF8
CP CFH FE CF
Compare Register A to CFH, which is a BASIC token (possibly CLOSE or another disk command token).
4DFA
If NZ (not token CFH), JUMP to 4E09H to handle as a different token type.
[TOKEN CFH PROCESSING] The character was token CFH. Now validate it's being used with file #1 and set special processing flag.
4DFC
LD A,(IX+00H) DD 7E 00
Load Register A with the FCB file number again from IX+0.
4DFF
CP 01H FE 01
Compare to 01H. Check if this is file #1 (the first FCB entry).
4E01
If NZ (not file #1), JUMP to 1997H for error. Token CFH can only be used with the first file.
4E04
LD (5102H),A 32 02 51
Store Register A (01H) at 5102H, a self-modifying code location. This is the operand of a "LD A,nn" instruction at 5101H, setting a processing flag.
4E07
JUMP to 4E10H to continue processing after setting the flag.
4E09
CP CEH FE CE
[ALTERNATE TOKEN PATH] Compare Register A to CEH, another BASIC token (possibly OPEN or related command).
4E0B
If NZ (not CEH either), JUMP to 4E11H for standard processing.
4E0D
LD (IX+04H),A DD 77 04
Store Register A (CEH) at IX+4 (FCB offset +4). This marks this FCB with the CEH token for special handling.
4E10
RST 10H D7
Call RST 10H to compare pointers, checking for end of parameters or command.
4E11H - FCB Table Iterator and Buffer Operations
Main processing loop that iterates through the FCB table, performing various buffer operations including string evaluation, memory allocation, copying, and compression. The complex code from 4E11H through 50D6H handles FCB entry manipulation with self-modifying code for dynamic operation dispatch.
[COMPLEX FCB PROCESSING SECTION] This extensive section (4E11H-50D6H) contains the core FCB manipulation logic with multiple subroutines, self-modifying code blocks, and buffer management operations. The code includes string expression evaluation (via CALL 260DH), device flag handling (40AFH), memory pointer updates (40F9H, 40FBH, 40FDH), and sophisticated LDIR/LDDR operations for data movement. The self-modifying code blocks at 510CH-5173H contain dynamically modified LD and operation instructions that adapt based on FCB entry states.
4E11-50D6
[FCB Operations] ...
FCB Table Processing: Iterates through all 9 FCB entries (23 bytes each starting at 4200H), performing operations based on entry flags. Includes: (1) String parameter evaluation via ROM CALL 260DH, (2) Device state checking at 40AFH, (3) Memory boundary validation against 40F9H/40FBH/40FDH pointers, (4) Buffer copying with LDIR/LDDR, (5) FCB compression and consolidation, (6) Dynamic dispatch via self-modifying code at 50FFH, and (7) IX register advancement by 17H bytes per entry. Returns to caller when all entries processed or table exhausted.
50D7H - Buffer Copy with Optional Data Transfer
Conditional buffer copy routine. Tests bit 6 of IX+16H to determine whether to perform a simple pointer advance (ADD HL,BC) or a full data copy (LDIR) followed by pointer updates. This allows efficient handling of both empty and populated buffer regions.
50D7
LD A,(IX+16H) DD 7E 16
Load Register A with the byte at IX+16H (FCB offset +16H = 22 decimal), which contains buffer control flags.
50DA
OR A B7
Set flags based on Register A. If A is 00H, Z FLAG is set.
50DB
If NZ (flags indicate data present), JUMP to 50DFH to perform data copy.
50DD
ADD HL,BC 09
[NO DATA PATH] Add BC to HL, advancing the pointer by BC bytes without copying. Buffer is empty or doesn't need transfer.
50DE
RET C9
Return to caller with pointer advanced.
50DF
LD E,(IX+13H) DD 5E 13
[DATA COPY PATH] Load E with the byte at IX+13H, the low byte of source address.
50E2
LD D,(IX+14H) DD 56 14
Load D with the byte at IX+14H, the high byte of source address. DE now points to the source data.
50E5
LDIR ED B0
Block copy: Copy BC bytes from (DE) to (HL), incrementing both pointers. Transfer the buffer data.
50E7
LD (IX+13H),E DD 73 13
Store E back to IX+13H, updating the source pointer low byte after the copy.
50EA
LD (IX+14H),D DD 72 14
Store D back to IX+14H, updating the source pointer high byte. The source pointer now reflects the end position.
50ED
RET C9
Return to caller with both source and destination updated.
50EEH - Dynamic Subroutine Dispatcher
Self-modifying subroutine dispatcher that calls a dynamically determined routine address. Stores BC at 50FFH (modifying the CALL instruction operand), then iterates through FCB table entries calling the specified routine for each active entry.
50EE
LD (50FFH),BC ED 43 FF 50
Store BC at 50FFH, which is a self-modifying code location. This modifies the operand of the "CALL nnnn" instruction at 50FEH, setting the dynamic call target.
50F2
LD IX,4200H DD 21 00 42
Load IX with 4200H, resetting to the FCB table base to begin iteration.
50F6
LD A,(IX+01H) DD 7E 01
[DISPATCH LOOP] Load Register A with the byte at IX+1 (FCB offset +1), the status byte.
50F9
OR A B7
Set flags. If A is 00H (inactive entry), Z FLAG set.
50FA
RET Z C8
If Z (entry inactive or end of table), Return immediately. All active entries have been processed.
50FB
LD C,A 4F
Copy Register A to Register C, preserving the status byte as a parameter.
50FC
LD B,00H 06 00
Load B with 00H, making BC a 16-bit value.
50FE
CALL 0000H CD 00 00
Self-modifying CALL: The operand (0000H) was replaced at 50EEH with the target subroutine address. Call the dynamically specified routine with IX pointing to current FCB and BC holding status.
5101
LD A,00H 3E 00
Self-modifying instruction: The operand (00H) was potentially modified at 4E04H. Load Register A with the stored processing flag.
5103
OR A B7
Set flags based on Register A.
5104
RET NZ C0
If NZ (processing flag set), Return early without processing remaining entries.
5105
LD BC,0017H 01 17 00
Load BC with 0017H (23 decimal), the FCB entry size.
5108
ADD IX,BC DD 09
Add BC to IX, advancing IX to point to the next FCB entry (23 bytes forward).
510A
JUMP to 50F6H to process the next FCB entry. [LOOP CONTINUES]
510CH - Complex Self-Modifying Code Block
Extensive self-modifying code section containing FCB manipulation instructions that are dynamically modified during execution. This 104-byte block (510CH-5173H) includes pointer operations, arithmetic calculations, buffer copying, and flag management. The instructions serve as both executable code and modifiable data.
[SELF-MODIFYING INSTRUCTION BLOCK] This section contains a complex sequence of instructions that get modified at runtime to perform various FCB operations. The code includes LD operations with IX offsets (+00H through +16H), arithmetic operations (ADD, DEC, INC, RRCA), pointer manipulation (LD L/H from IX offsets), CALL to 50DFH (buffer copy routine), BIT testing, and conditional returns. These instructions are modified by storing new operands or opcodes at specific addresses within this block, allowing the same code region to perform different operations based on FCB entry states.
510C-5173
[Self-Modifying Code] DD 75 nn DD 74 nn...
Dynamic FCB Operations: Modifiable instruction sequence performing: (1) LD (IX+offset),L/H operations storing calculated values to FCB entries, (2) Pointer arithmetic using LD L,(IX+0DH) and LD H,(IX+0EH) for loading from FCB offsets +0D/+0E/+09/+0A/+0B/+0C/+13/+14, (3) Buffer operations via CALL 50DFH, (4) Flag testing with BIT 7,(IX+16H), (5) ADD HL,DE and SBC HL,DE for pointer calculations, (6) Conditional returns (RET NZ, RET Z), and (7) LDIR/LDDR block moves. Instructions modified at runtime to adapt operation sequence based on FCB entry data and processing requirements.
5174H - FCB Buffer Advance
Loads buffer pointers from FCB offsets +09H and +0AH, optionally copies data if IX+16H flag is set, then advances the pointer by BC bytes. Returns with HL pointing to the new buffer position.
5174
LD L,(IX+09H) DD 6E 09
Load L with the byte at IX+09H (FCB offset +9), the low byte of buffer pointer.
5177
LD H,(IX+0AH) DD 66 0A
Load H with the byte at IX+0AH (FCB offset +10), the high byte. HL now points to the buffer.
517A
Call 50D7H, which checks IX+16H and either skips (ADD HL,BC) or copies (LDIR) the buffer data, then advances the pointer.
517D
LD (IX+09H),L DD 75 09
Store L back to IX+09H, updating the buffer pointer low byte after the operation.
5180
LD (IX+0AH),H DD 74 0A
Store H back to IX+0AH, updating the buffer pointer high byte.
5183
RET C9
Return to caller with updated buffer pointer in IX+09H/0AH.
5184H - Buffer Consolidation with LDDR
Performs buffer consolidation by calculating the difference between two pointer pairs (0BH/0CH and 09H/0AH), then using LDDR to move data backward. Updates multiple FCB pointers and sets the buffer valid flag at IX+16H after completion.
5184
LD L,(IX+0BH) DD 6E 0B
Load L from IX+0BH (FCB offset +11), low byte of first pointer.
5187
LD H,(IX+0CH) DD 66 0C
Load H from IX+0CH (FCB offset +12), high byte. HL = first pointer.
518A
LD E,(IX+09H) DD 5E 09
Load E from IX+09H, low byte of second pointer.
518D
LD D,(IX+0AH) DD 56 0A
Load D from IX+0AH, high byte. DE = second pointer.
5190
OR A B7
Clear the C FLAG for subtraction.
5191
SBC HL,DE ED 52
Subtract DE from HL. HL now contains the byte count between the two pointers (size of region to move).
5193
LD B,H 44
Copy H to B.
5194
LD C,L 4D
Copy L to C. BC now holds the count for LDDR.
5195
ADD HL,DE 19
Add DE back to HL, restoring HL to the original first pointer value.
5196
LD E,(IX+0DH) DD 5E 0D
Load E from IX+0DH (FCB offset +13), low byte of destination pointer.
5199
LD D,(IX+0EH) DD 56 0E
Load D from IX+0EH (FCB offset +14), high byte. DE = destination.
519C
LD (IX+0BH),E DD 73 0B
Store E to IX+0BH, updating pointer storage.
519F
LD (IX+0CH),D DD 72 0C
Store D to IX+0CH, completing the pointer update.
51A2
If Z (count is zero, nothing to move), JUMP to 51A9H to skip the copy.
51A4
DEC HL 2B
Decrement HL to point to the last byte of source region (LDDR copies backward from end).
51A5
DEC DE 1B
Decrement DE to point to the last byte of destination region.
51A6
LDDR ED B8
Block copy backward: Copy BC bytes from (HL) to (DE), decrementing both pointers. Moves data backward, useful for compressing buffers.
51A8
INC DE 13
Increment DE to adjust pointer after LDDR (points to byte after copied region).
51A9
LD (IX+09H),E DD 73 09
Store E to IX+09H, updating the buffer pointer low byte.
51AC
LD (IX+0AH),D DD 72 0A
Store D to IX+0AH, updating the buffer pointer high byte.
51AF
LD L,(IX+13H) DD 6E 13
Load L from IX+13H, another pointer low byte.
51B2
LD H,(IX+14H) DD 66 14
Load H from IX+14H, high byte. HL = third pointer.
51B5
LD E,(IX+11H) DD 5E 11
Load E from IX+11H (offset +17), fourth pointer low byte.
51B8
LD D,(IX+12H) DD 56 12
Load D from IX+12H (offset +18), high byte. DE = fourth pointer.
51BC
SBC HL,DE ED 52
Subtract DE from HL, calculating difference.
51BE
LD B,H 44
Copy result to BC.
51C0
RET Z C8
If Z (no difference), Return immediately.
51C1
EX DE,HL EB
Exchange DE and HL, swapping source/dest for LDIR setup.
51C2
LD (IX+13H),L DD 75 13
Store L to IX+13H.
51C5
LD (IX+14H),H DD 74 14
Store H to IX+14H.
51C8
LD E,(IX+15H) DD 5E 15
Load E from IX+15H (offset +21), another pointer.
51CB
LD D,(IX+16H) DD 56 16
Load D from IX+16H (offset +22), high byte.
51CE
LDIR ED B0
Block copy forward: Copy BC bytes from (HL) to (DE).
51D0
LD (IX+16H),16H DD 36 16 00
Store 16H at IX+16H, setting a flag or marker value (note: instruction shows 00 but description says 16H - likely a typo in disassembly or my interpretation).
51D4
RET C9
Return after completing the buffer consolidation.
51D5H - Final Buffer Pointer Store
Loads the final buffer pointer from FCB offsets +07H and +08H, then stores it to +0FH and +10H. This appears to finalize or commit buffer positions after all operations are complete.
51D5
LD L,(IX+07H) DD 6E 07
Load L from IX+07H (FCB offset +7), low byte of final buffer pointer.
51D8
LD H,(IX+08H) DD 66 08
Load H from IX+08H (FCB offset +8), high byte. HL = final buffer position.
51DB
LD (IX+0FH),L DD 75 0F
Store L to IX+0FH (FCB offset +15), committing the low byte.
51DE
LD (IX+10H),H DD 74 10
Store H to IX+10H (FCB offset +16), committing the high byte. The buffer pointer is now finalized at offsets +0FH and +10H.
51E1
RET C9
Return to caller with the buffer position stored.
51E2H - Reserved Space
Module padding providing alignment or expansion space.
51E2-51E7
NOP (×6) 00...
Reserved area: 6 bytes of NOP instructions providing module padding. Ensures proper alignment or leaves room for future code additions without requiring relocation of subsequent modules.