4E00H - Enter DEBUG: Save the Program's Registers
The transfer address of SYS5/SYS, overlay 7. DEBUG (440DH), RST 30H (400FH), the BREAK key while the BREAK vector 4316H is 400FH, and 4030H while DEBUG is on (CALL 400FH) all reach 44B4H, which pushes Register Pair AF and gives request code 87H to the overlay dispatcher; the dispatcher calls 4E00H. On the stack are the dispatcher's return address 4BFEH, the program's Register Pair AF and the program's address (the return address of the RST 30H or CALL, or the address the BREAK interrupt left). SYS5/SYS never returns into the dispatcher: it saves every register in the area at 4065H-407CH and runs its own command loop on the program's stack.
4E00
POP AF F1
Load Register Pair AF from the stack at the Stack Pointer: it takes 4BFEH, the dispatcher's return address, which is dropped, so the dispatcher never puts back the BREAK flag it cleared at 4315H.
4E01
POP AF F1
Load Register Pair AF from the stack at the Stack Pointer: the program's own Register Pair AF, pushed by 44B4H before the request code 87H was put in Register A.
4E02
PUSH AF F5
Save the program's Register Pair AF on the stack at the Stack Pointer again: with the program's address above it, it is the first word of the twelve saved.
4E03
PUSH IY FD E5
Save the program's Index Register IY on the stack at the Stack Pointer; the copy at 4E1DH puts it at 4077H.
4E05
PUSH IX DD E5
Save the program's Index Register IX on the stack at the Stack Pointer; the copy at 4E1DH puts it at 4075H.
4E07
EX AF,AF' 08
Exchange Register Pair AF with the alternate Register Pair AF' so that the program's Register Pair AF' can be pushed next.
4E08
EXX D9
Exchange Register Pairs BC, DE and HL with the alternate set (EXX) so that the program's alternate registers can be pushed next.
4E09
PUSH HL E5
Save the program's alternate Register Pair HL' on the stack at the Stack Pointer, through Register Pair HL after the EXX; it goes to 4073H.
4E0A
PUSH DE D5
Save the program's alternate Register Pair DE' on the stack at the Stack Pointer, through Register Pair DE after the EXX; it goes to 4071H.
4E0B
PUSH BC C5
Save the program's alternate Register Pair BC' on the stack at the Stack Pointer, through Register Pair BC after the EXX; it goes to 406FH.
4E0C
PUSH AF F5
Save the program's alternate Register Pair AF' on the stack at the Stack Pointer, through Register Pair AF after the exchange; it goes to 406DH.
4E0D
EX AF,AF' 08
Exchange Register Pair AF with the alternate Register Pair AF' again: Register Pair AF is the program's own once more.
4E0E
EXX D9
Exchange Register Pairs BC, DE and HL with the alternate set again (EXX): the program's main registers are back in place.
4E0F
PUSH HL E5
Save the program's Register Pair HL on the stack at the Stack Pointer; the copy at 4E1DH puts it at 406BH.
4E10
PUSH DE D5
Save the program's Register Pair DE on the stack at the Stack Pointer; the copy at 4E1DH puts it at 4069H.
4E11
PUSH BC C5
Save the program's Register Pair BC on the stack at the Stack Pointer; the copy at 4E1DH puts it at 4067H.
4E12
PUSH AF F5
Save the program's Register Pair AF on the stack at the Stack Pointer; the copy at 4E1DH puts it at 4065H, the first word of the register area.
4E13
LD HL,0000H 21 00 00
Load Register Pair HL with 0000H, so that the ADD at 4E16H gives the Stack Pointer in Register Pair HL.
4E16
ADD HL,SP 39
Add the Stack Pointer to Register Pair HL (0000H): Register Pair HL points at the twelve words just pushed, the lowest first.
4E17
LD DE,4065H 11 65 40
Load Register Pair DE with 4065H, the register area: AF, BC, DE, HL, AF', BC', DE', HL', IX, IY, SP and PC, two bytes each, in the order of the names at 4F54H.
4E1A
LD BC,0018H 01 18 00
Load Register Pair BC with 0018H, the 24 bytes of the twelve words on the stack.
4E1D
LDIR ED B0
Copy the twelve words from the stack at Register Pair HL to 4065H-407CH at Register Pair DE, Register Pair BC (0018H) bytes; Register Pair HL ends past them, at the program's own stack.
4E1F
LD (4079H),HL 22 79 40
Store Register Pair HL at 4079H, the place of SP in the register area: the program's Stack Pointer before the RST 30H, CALL or interrupt. It replaces the second copy of Register Pair AF.
4E22
LD SP,HL F9
Load the Stack Pointer from Register Pair HL: DEBUG runs on the program's stack, with the saved words given up.
4E23
LD HL,(407BH) 2A 7B 40
Load Register Pair HL with the program's address, the saved PC at 407BH.
4E26
DEC HL 2B
Decrement Register Pair HL to the byte before the program's address.
4E27
LD A,(HL) 7E
Load Register A with the byte at Register Pair HL, the byte before the program's address.
4E28
CP F7H FE F7
Compare Register A with F7H, the RST 30H instruction that a breakpoint puts in place.
4E2A
If the NZ FLAG is set (the byte is not F7H), jump to 4E2FH, leaving the saved PC as it is.
4E2C
LD (407BH),HL 22 7B 40
Store Register Pair HL at 407BH: the saved PC points back at the RST 30H, the place of the breakpoint. This is done for any F7H before the address, also when DEBUG was entered by BREAK or by the program's own RST 30H (a bug: the Bugs part of the introduction).
4E2FH - Take the Breakpoints Out
The two breakpoints of G and of the single step are three bytes each: breakpoint 2 at 405DH-405FH and breakpoint 1 at 4060H-4062H, each the address (low byte first) and the byte that RST 30H replaced. Each address that is not 0000H and still holds F7H gets its byte back. Both addresses are cleared, which also clears 405DH-405EH, the A or H display and the S or X screen, and 4060H-4061H, the address of M: they share these bytes.
4E2F
LD HL,405DH 21 5D 40
Load Register Pair HL with 405DH, the first of the two breakpoint entries. 4FD1H jumps here when a breakpoint cannot be placed.
4E32
LD B,02H 06 02
Load Register B with 02H, the count of the breakpoint entries.
4E34
XOR A AF
Clear Register A to 00H, the byte with which the address of the entry is cleared.
4E35
LD C,02H 0E 02
Load Register C with 02H. Register C is not used again: the loop is counted by Register B.
4E37
LD E,(HL) 5E
Load Register E with the low byte of the breakpoint address at Register Pair HL.
4E38
LD (HL),A 77
Store Register A (00H) at Register Pair HL, clearing the low byte of the breakpoint address.
4E39
INC HL 23
Increment Register Pair HL to the high byte of the breakpoint address.
4E3A
LD D,(HL) 56
Load Register D with the high byte of the breakpoint address at Register Pair HL: Register Pair DE is the address.
4E3B
LD (HL),A 77
Store Register A (00H) at Register Pair HL, clearing the high byte of the breakpoint address.
4E3C
INC HL 23
Increment Register Pair HL to the saved byte of the entry.
4E3D
LD A,E 7B
Copy the low byte of the address from Register E into Register A for the test of Register Pair DE against 0000H.
4E3E
OR D B2
OR Register A with Register D: the Z FLAG is set when the address in Register Pair DE is 0000H, no breakpoint.
4E3F
If the Z FLAG is set (no breakpoint in this entry), jump to 4E48H.
4E41
LD A,(DE) 1A
Load Register A with the byte at the breakpoint address in Register Pair DE.
4E42
CP F7H FE F7
Compare Register A with F7H, the RST 30H of a breakpoint.
4E44
If the NZ FLAG is set (the program has changed the byte since), jump to 4E48H without writing it.
4E46
LD A,(HL) 7E
Load Register A with the saved byte at Register Pair HL, the byte the RST 30H replaced.
4E47
LD (DE),A 12
Store Register A, the saved byte, at the breakpoint address in Register Pair DE: the program's byte is back.
4E48
INC HL 23
Increment Register Pair HL past the saved byte to the next entry.
4E49
Decrement Register B and, if it is not zero, jump back to 4E34H for the second entry.
4E4BH - The Command Loop
The display is shown (X: the registers and four lines of memory, S: a full screen of memory), the cursor goes to 3FC0H, the start of the last line, and one key is read and shown. The letter chooses the command; every command but G returns to 4E4BH, the address pushed at 4E63H. Invalid hexadecimal input in any command also comes back here (51ADH). There is no command to leave DEBUG: G with an address, such as G 402D for DOS READY, does that.
4E4B
LD SP,(4079H) ED 7B 79 40
Load the Stack Pointer from 4079H, the program's Stack Pointer as saved (or as changed by R SP): each command starts on a clean stack.
4E4F
Call 4ECFH to show the display chosen by 405EH: the registers and four lines of memory, or sixteen lines of memory.
4E52
LD HL,3FC0H 21 C0 3F
Load Register Pair HL with 3FC0H, the first character of the last line of the screen.
4E55
LD (4020H),HL 22 20 40
Store Register Pair HL at 4020H, the cursor address of the display driver: the command is typed at the left of the last line.
4E58
Call 518AH to wait for a key and show it; Register A is the key.
4E5B
CP 47H FE 47
Compare Register A, the key, with 47H, the letter G.
4E5D
If the Z FLAG is set (G), jump to 4F80H to go to the program; G does not come back to the loop.
4E60
LD HL,4E4BH 21 4B 4E
Load Register Pair HL with 4E4BH, the start of the command loop.
4E63
PUSH HL E5
Save Register Pair HL (4E4BH) on the stack at the Stack Pointer: each command returns to the loop.
4E64
CP 53H FE 53
Compare Register A, the key, with 53H, the letter S.
4E66
If the Z FLAG is set (S), jump to 4E9AH to store 53H at 405EH: the full screen of memory.
4E68
CP 3BH FE 3B
Compare Register A, the key, with 3BH, the semicolon.
4E6A
If the Z FLAG is set (the semicolon), jump to 4EAEH to move the memory display forward.
4E6C
CP 2DH FE 2D
Compare Register A, the key, with 2DH, the minus sign.
4E6E
If the Z FLAG is set (the minus sign), jump to 4EC6H to move the memory display back.
4E70
CP 41H FE 41
Compare Register A, the key, with 41H, the letter A.
4E72
If the Z FLAG is set (A), jump to 4ECBH to store 41H at 405DH: memory is shown as characters.
4E74
CP 43H FE 43
Compare Register A, the key, with 43H, the letter C.
4E76
If the Z FLAG is set (C), jump to 4E82H, the JP Z,505DH, with the Z FLAG still set: single step that runs a CALL whole.
4E78
CP 44H FE 44
Compare Register A, the key, with 44H, the letter D.
4E7A
If the Z FLAG is set (D), jump to 4EA8H to take the address of the memory display.
4E7C
CP 48H FE 48
Compare Register A, the key, with 48H, the letter H.
4E7E
If the Z FLAG is set (H), jump to 4ECBH to store 48H at 405DH: memory is shown in hexadecimal.
4E80
CP 49H FE 49
Compare Register A, the key, with 49H, the letter I.
4E82
If the Z FLAG is set (I, or C from 4E76H), jump to 505DH to single step the instruction at the saved PC.
4E85
CP 4DH FE 4D
Compare Register A, the key, with 4DH, the letter M.
4E87
If the Z FLAG is set (M), jump to 4FDBH to change memory.
4E8A
CP 52H FE 52
Compare Register A, the key, with 52H, the letter R.
4E8C
If the Z FLAG is set (R), jump to 5011H to change a register.
4E8F
CP 55H FE 55
Compare Register A, the key, with 55H, the letter U.
4E91
If the Z FLAG is set (U), jump to 4E9EH to show the display over and over until a key.
4E93
CP 58H FE 58
Compare Register A, the key, with 58H, the letter X.
4E95
If the Z FLAG is set (X), jump to 4E99H to clear 405EH: the registers and four lines of memory.
4E97
RST 28H EF
Any other key: call the overlay dispatcher through RST 28H (400CH, 4BA2H) with the key in Register A. Bit 7 of a key is clear, so the dispatcher drops the RST return address and returns with Register A 00H (4312H) to 4E4BH, the address pushed at 4E63H.
4E98
RET C9
Return to 4E4BH, the command loop. No instruction reaches this byte: the dispatcher at 4BA2H drops the return address of the RST 28H at 4E97H.
4E99H - S and X: Choose the Display
X clears 405EH and S stores 53H there. With 405EH 00H the display shows the twelve registers and four lines of memory from 4063H; with any other value it shows sixteen lines of memory from the page of 4063H.
4E99
XOR A AF
Clear Register A to 00H for 405EH: X, the registers and four lines of memory.
4E9A
LD (405EH),A 32 5E 40
Store Register A at 405EH: 00H from 4E99H for X, or 53H, the letter S, for the full screen of memory.
4E9D
RET C9
Return to 4E4BH, the command loop, which shows the display in the new form.
4E9EH - U: Show the Display Until a Key
The display is shown again and again, so that memory changed by interrupt tasks or by hardware is seen as it changes. Any key ends it; the key is not taken as a command.
4E9E
Call 002BH, the ROM's keyboard scan: Register A is the key pressed, or 00H when there is none. 4EA6H jumps back here.
4EA1
OR A B7
Set the flags from Register A, the key from 002BH.
4EA2
RET NZ C0
If the NZ FLAG is set (a key was pressed), return to 4E4BH, the command loop; the key is dropped.
4EA3
Call 4ECFH to show the display again with the memory as it is now.
4EA6
Jump back to 4E9EH to test the keyboard again.
4EA8H - D: Set the Address of the Memory Display
D followed by a hexadecimal address sets 4063H, the first address shown. With no address (ENTER, a space or a comma at once) nothing changes.
4EA8
Call 51A3H to read a hexadecimal number: Register Pair HL is the number and the NZ FLAG is set when one was typed.
4EAB
RET Z C8
If the Z FLAG is set (no number was typed), return to 4E4BH, the command loop.
4EAC
Jump to 4EC2H to store Register Pair HL, the new address, at 4063H.
4EAEH - Semicolon and Minus Sign: Move the Memory Display
The semicolon moves the memory display forward and the minus sign back: by 40H bytes (four lines) with the X display, by 100H bytes (sixteen lines) with the S display.
4EAE
LD BC,0040H 01 40 00
Load Register Pair BC with 0040H, the four lines of 16 bytes that the semicolon moves forward.
4EB1
LD HL,(4063H) 2A 63 40
Load Register Pair HL with the address of the memory display at 4063H. 4EC9H jumps here with Register Pair BC FFC0H.
4EB4
LD A,(405EH) 3A 5E 40
Load Register A with 405EH, 00H for the X display, otherwise the S display.
4EB7
OR A B7
Set the flags from Register A, the display choice from 405EH.
4EB8
If the Z FLAG is set (the X display), jump to 4EC1H to move by Register Pair BC, 40H bytes.
4EBA
LD C,00H 0E 00
Load Register C with 00H: Register Pair BC becomes 0000H (forward) or FF00H (back).
4EBC
LD A,B 78
Copy Register B into Register A for the test of the direction.
4EBD
OR A B7
Set the flags from Register A, Register B: 00H forward, FFH back.
4EBE
If the NZ FLAG is set (back: Register Pair BC is FF00H, minus 100H), jump to 4EC1H.
4EC0
INC B 04
Increment Register B: Register Pair BC becomes 0100H, the sixteen lines forward.
4EC1
ADD HL,BC 09
Add Register Pair BC, the step, to Register Pair HL, the address of the memory display.
4EC2
LD (4063H),HL 22 63 40
Store Register Pair HL at 4063H, the address of the memory display. D (4EACH) also stores its address here.
4EC5
RET C9
Return to 4E4BH, the command loop, which shows the moved memory.
4EC6
LD BC,FFC0H 01 C0 FF
Load Register Pair BC with FFC0H, minus 40H, the four lines that the minus sign moves back.
4EC9
Jump back to 4EB1H to add the step in Register Pair BC to the address at 4063H.
4ECBH - A and H: Characters or Hexadecimal
A stores 41H and H stores 48H at 405DH. The memory lines (5131H) show the bytes as characters when 405DH is 41H, in hexadecimal otherwise.
4ECB
LD (405DH),A 32 5D 40
Store Register A, the key, at 405DH: 41H (A) for characters, 48H (H) for hexadecimal.
4ECE
RET C9
Return to 4E4BH, the command loop, which shows memory in the new form.
4ECFH - Show the Display
With 405EH 00H (X) the screen is cleared to the top and the twelve registers are shown, one a line: the name, an equals sign and the value as two hexadecimal bytes, then for AF and AF' the eight flags and for the others the sixteen bytes the register points to; four lines of memory from 4063H follow. With 405EH not 00H (S) sixteen lines of memory are shown from the page of 4063H. Both displays start one character early (the last register line is 63 characters, the S display starts at 3BFFH), so that the last character goes to 3FFEH: writing 3FFFH would make the ROM scroll the screen (0541H).
4ECF
LD A,(405EH) 3A 5E 40
Load Register A with 405EH, 00H for the X display, otherwise the S display.
4ED2
OR A B7
Set the flags from Register A, the display choice from 405EH.
4ED3
If the NZ FLAG is set (the S display), jump to 4F45H to show sixteen lines of memory.
4ED5
LD A,1CH 3E 1C
Load Register A with 1CH, the display code that puts the cursor at 3C00H, the top left of the screen.
4ED7
Call 0033H, the ROM's display routine, with Register A 1CH: the cursor goes home.
4EDA
LD HL,4065H 21 65 40
Load Register Pair HL with 4065H, the register area, the saved Register Pair AF first.
4EDD
PUSH HL E5
Save Register Pair HL (4065H) on the stack at the Stack Pointer; the loop exchanges it with the pointer to the names.
4EDE
LD HL,4F54H 21 54 4F
Load Register Pair HL with 4F54H, the twelve names of three characters.
4EE1
LD B,0CH 06 0C
Load Register B with 0CH, the twelve registers.
4EE3
Jump to 4EEAH: the first line needs no carriage return before it.
4EE5
LD A,0DH 3E 0D
Load Register A with 0DH, the carriage return that ends the line before. 4F2CH jumps here for each register after the first.
4EE7
Call 0033H, the ROM's display routine, with Register A 0DH: the cursor goes to the next line.
4EEA
Call 51F6H to show the three characters of the name at Register Pair HL; Register Pair HL steps past them.
4EED
EX (SP),HL E3
Exchange Register Pair HL with the top of the stack at the Stack Pointer: Register Pair HL is the place in the register area, the pointer to the names is kept.
4EEE
LD E,(HL) 5E
Load Register E with the low byte of the register's value at Register Pair HL.
4EEF
INC HL 23
Increment Register Pair HL to the high byte of the register's value.
4EF0
LD D,(HL) 56
Load Register D with the high byte of the register's value at Register Pair HL: Register Pair DE is the value.
4EF1
INC HL 23
Increment Register Pair HL to the next register's place in the register area.
4EF2
PUSH HL E5
Save Register Pair HL, the next place in the register area, on the stack at the Stack Pointer.
4EF3
EX DE,HL EB
Exchange Register Pairs DE and HL: Register Pair HL is the register's value.
4EF4
LD A,3DH 3E 3D
Load Register A with 3DH, the equals sign after the name.
4EF6
Call 0033H, the ROM's display routine, to show the equals sign in Register A.
4EF9
Call 51F2H to show a space between the equals sign and the value.
4EFC
LD A,H 7C
Copy the high byte of the value from Register H into Register A.
4EFD
Call 51EFH to show Register A, the high byte, as two hexadecimal digits and a space.
4F00
LD A,L 7D
Copy the low byte of the value from Register L into Register A.
4F01
Call 51EFH to show Register A, the low byte, as two hexadecimal digits and a space.
4F04
LD A,B 78
Copy the count from Register B into Register A: 0CH for AF, 08H for AF'.
4F05
AND 0BH E6 0B
AND Register A with 0BH: only the counts 0CH and 08H, AF and AF', give 08H.
4F07
CP 08H FE 08
Compare Register A with 08H, the mark of a Register Pair AF.
4F09
If the NZ FLAG is set (not AF or AF'), jump to 4F27H to show the sixteen bytes the register points to.
4F0B
LD C,L 4D
Copy the flags from Register L, the low byte of Register Pair AF, into Register C.
4F0C
PUSH BC C5
Save Register Pair BC, the count in Register B and the flags in Register C, on the stack at the Stack Pointer.
4F0D
LD HL,4F78H 21 78 4F
Load Register Pair HL with 4F78H, the names of the eight flags, SZ1H1PNC.
4F10
LD B,08H 06 08
Load Register B with 08H, the eight flag bits.
4F12
SLA C CB 21
Shift Register C left: the C FLAG is the flag bit, bit 7 (S) first.
4F14
LD A,(HL) 7E
Load Register A with the flag's letter at Register Pair HL.
4F15
If the C FLAG is set (the flag bit is 1), jump to 4F19H to show the letter.
4F17
LD A,2DH 3E 2D
Load Register A with 2DH, the minus sign shown for a flag bit that is 0.
4F19
Call 0033H, the ROM's display routine, to show Register A, the flag's letter or the minus sign.
4F1C
INC HL 23
Increment Register Pair HL to the next flag's letter.
4F1D
Decrement Register B and, if it is not zero, jump back to 4F12H for the next flag bit.
4F1F
POP BC C1
Restore Register Pair BC, the count of the registers in Register B, from the stack at the Stack Pointer.
4F20
LD A,ECH 3E EC
Load Register A with ECH, the space compression code for 44 spaces (ECH minus C0H is 2CH), which fill the line to 63 characters.
4F22
Call 0033H, the ROM's display routine, with Register A ECH: 44 spaces.
4F25
Jump to 4F2AH to go on with the next register.
4F27
Call 5131H to show the sixteen bytes at Register Pair HL, the register's value.
4F2A
POP HL E1
Restore Register Pair HL, the next place in the register area, from the stack at the Stack Pointer.
4F2B
EX (SP),HL E3
Exchange Register Pair HL with the top of the stack at the Stack Pointer: Register Pair HL is the pointer to the names again, the place in the register area is kept.
4F2C
Decrement Register B and, if it is not zero, jump back to 4EE5H for the next register.
4F2E
POP HL E1
Restore Register Pair HL from the stack at the Stack Pointer, the place in the register area, which is not needed.
4F2F
LD HL,(4063H) 2A 63 40
Load Register Pair HL with the address of the memory display at 4063H.
4F32
LD B,04H 06 04
Load Register B with 04H, the four lines of memory under the registers.
4F34
LD A,C7H 3E C7
Load Register A with C7H, the space compression code for seven spaces. 4F52H jumps here for the S display.
4F36
Call 0033H, the ROM's display routine, with Register A C7H: seven spaces, the first of them at the end of the line before, the place of the command letter.
4F39
Call 51D4H to show the address in Register Pair HL as four hexadecimal digits.
4F3C
Call 51F2H to show a space between the address and the arrow.
4F3F
Call 5131H to show the sixteen bytes at Register Pair HL; Register Pair HL steps past them.
4F42
Decrement Register B and, if it is not zero, jump back to 4F34H for the next line of memory.
4F44
RET C9
Return to the caller. The last line ends at 3FFEH.
4F45
LD HL,3BFFH 21 FF 3B
Load Register Pair HL with 3BFFH, the byte before the screen: the first of the seven spaces goes there, so that sixteen lines of 64 characters end at 3FFEH.
4F48
LD (4020H),HL 22 20 40
Store Register Pair HL at 4020H, the cursor address of the display driver.
4F4B
LD HL,(4063H) 2A 63 40
Load Register Pair HL with the address of the memory display at 4063H.
4F4E
LD L,00H 2E 00
Load Register L with 00H: the S display starts at the beginning of the page of Register Pair HL.
4F50
LD B,10H 06 10
Load Register B with 10H, the sixteen lines of the S display.
4F52
Jump to 4F34H to show the sixteen lines of memory from Register Pair HL.
4F54H - The Names of the Registers and the Flags
Twelve names of three characters, in the order of the register area at 4065H-407CH, read by the display (4EDEH) and by R (5029H), then the names of the eight flag bits, read by 4F0DH.
4F54-4F56
DEFM "AF " 41 46 20
The name AF of the word at 4065H-4066H, the program's Register Pair AF, with a space to make three characters.
4F57-4F59
DEFM "BC " 42 43 20
The name BC of the word at 4067H-4068H, the program's Register Pair BC, with a space to make three characters.
4F5A-4F5C
DEFM "DE " 44 45 20
The name DE of the word at 4069H-406AH, the program's Register Pair DE, with a space to make three characters.
4F5D-4F5F
DEFM "HL " 48 4C 20
The name HL of the word at 406BH-406CH, the program's Register Pair HL, with a space to make three characters.
4F60-4F62
DEFM "AF'" 41 46 27
The name AF' of the word at 406DH-406EH, the program's alternate Register Pair AF', with a quote as the third character.
4F63-4F65
DEFM "BC'" 42 43 27
The name BC' of the word at 406FH-4070H, the program's alternate Register Pair BC', with a quote as the third character.
4F66-4F68
DEFM "DE'" 44 45 27
The name DE' of the word at 4071H-4072H, the program's alternate Register Pair DE', with a quote as the third character.
4F69-4F6B
DEFM "HL'" 48 4C 27
The name HL' of the word at 4073H-4074H, the program's alternate Register Pair HL', with a quote as the third character.
4F6C-4F6E
DEFM "IX " 49 58 20
The name IX of the word at 4075H-4076H, the program's Index Register IX, with a space to make three characters.
4F6F-4F71
DEFM "IY " 49 59 20
The name IY of the word at 4077H-4078H, the program's Index Register IY, with a space to make three characters.
4F72-4F74
DEFM "SP " 53 50 20
The name SP of the word at 4079H-407AH, the program's Stack Pointer, with a space to make three characters.
4F75-4F77
DEFM "PC " 50 43 20
The name PC of the word at 407BH-407CH, the program's address, where G goes on, with a space to make three characters.
4F78-4F7F
DEFM "SZ1H1PNC" 53 5A 31 48 31 50 4E 43
The names of the flag bits 7-0 shown by 4F12H for a 1 bit: S, Z, the digit 1 for bit 5, H, the digit 1 for bit 3, P, N and C. A 0 bit is shown as a minus sign.
4F80H - G: Go to the Program
G, then an optional hexadecimal address (the new PC), then up to two breakpoint addresses, each ended by a space or a comma; ENTER ends the line at any point. Each breakpoint gets an RST 30H (F7H), its address and the byte it replaced kept at 4060H-4062H (the first) and 405DH-405FH (the second). The BREAK vector is set to DEBUG and the program's registers are put back.
4F80
LD B,02H 06 02
Load Register B with 02H, the most breakpoints G takes.
4F82
LD DE,4062H 11 62 40
Load Register Pair DE with 4062H, the end of the first breakpoint entry, which 4FCAH fills downwards.
4F85
Call 51A3H to read the new PC: Register Pair HL is the number and the NZ FLAG is set when one was typed; the C FLAG is set when ENTER ended it.
4F88
If the Z FLAG is set (no address after G), jump to 4F8DH: the program goes on at the saved PC.
4F8A
LD (407BH),HL 22 7B 40
Store Register Pair HL, the address typed, at 407BH, the saved PC.
4F8D
If the C FLAG is set (ENTER ended the line), jump to 4F99H to go to the program. 4F97H jumps here after each breakpoint.
4F8F
Call 51A3H to read a breakpoint address: Register Pair HL is the number, the NZ FLAG is set when one was typed.
4F92
PUSH AF F5
Save Register Pair AF, the flags of the input, on the stack at the Stack Pointer.
4F93
If the NZ FLAG is set (an address was typed), call 4FCAH to put an RST 30H at Register Pair HL and keep its byte and address downwards from Register Pair DE.
4F96
POP AF F1
Restore Register Pair AF, the flags of the input, from the stack at the Stack Pointer.
4F97
Decrement Register B and, if it is not zero, jump back to 4F8DH for the second breakpoint.
4F99
LD HL,400FH 21 0F 40
Load Register Pair HL with 400FH, the RST 30H vector (JP 44B4H, DEBUG).
4F9C
LD (4316H),HL 22 16 43
Store Register Pair HL (400FH) at 4316H, the BREAK vector: BREAK comes back to DEBUG.
4F9F
LD A,C3H 3E C3
Load Register A with C3H for the BREAK flag: any value but 00H arms BREAK.
4FA1
LD (4315H),A 32 15 43
Store Register A (C3H) at 4315H, the BREAK flag: the interrupt routine of SYS0/SYS takes BREAK through the vector at 4316H.
4FA4H - Put the Registers Back and Go
The eleven words AF to SP of the register area are pushed, from SP down to AF, and popped into the registers, the alternate set through EX AF,AF' and EXX; the Stack Pointer becomes the saved SP and the saved PC is reached through a RET. The single step (50B4H) also goes to the program here. The interrupts are left as they are.
4FA4
LD HL,407AH 21 7A 40
Load Register Pair HL with 407AH, the high byte of the saved SP, the last word to be put back but the first to be pushed.
4FA7
LD B,0BH 06 0B
Load Register B with 0BH, the eleven words from SP down to AF.
4FA9
LD D,(HL) 56
Load Register D with the high byte of the word at Register Pair HL.
4FAA
DEC HL 2B
Decrement Register Pair HL to the low byte of the word.
4FAB
LD E,(HL) 5E
Load Register E with the low byte of the word at Register Pair HL.
4FAC
DEC HL 2B
Decrement Register Pair HL to the high byte of the word below.
4FAD
PUSH DE D5
Save Register Pair DE, the word, on the stack at the Stack Pointer.
4FAE
Decrement Register B and, if it is not zero, jump back to 4FA9H for the next word: Register Pair AF's word is pushed last.
4FB0
POP AF F1
Load Register Pair AF from the stack at the Stack Pointer: the saved Register Pair AF of 4065H.
4FB1
POP BC C1
Load Register Pair BC from the stack at the Stack Pointer: the saved Register Pair BC of 4067H.
4FB2
POP DE D1
Load Register Pair DE from the stack at the Stack Pointer: the saved Register Pair DE of 4069H.
4FB3
POP HL E1
Load Register Pair HL from the stack at the Stack Pointer: the saved Register Pair HL of 406BH.
4FB4
EX AF,AF' 08
Exchange Register Pair AF with the alternate Register Pair AF', to load the alternate set next.
4FB5
EXX D9
Exchange Register Pairs BC, DE and HL with the alternate set (EXX), to load the alternate set next.
4FB6
POP AF F1
Load Register Pair AF from the stack at the Stack Pointer: the saved alternate Register Pair AF' of 406DH.
4FB7
POP BC C1
Load Register Pair BC from the stack at the Stack Pointer: the saved alternate Register Pair BC' of 406FH.
4FB8
POP DE D1
Load Register Pair DE from the stack at the Stack Pointer: the saved alternate Register Pair DE' of 4071H.
4FB9
POP HL E1
Load Register Pair HL from the stack at the Stack Pointer: the saved alternate Register Pair HL' of 4073H.
4FBA
EX AF,AF' 08
Exchange Register Pair AF with the alternate Register Pair AF' again: both sets of Register Pair AF hold the program's values.
4FBB
EXX D9
Exchange Register Pairs BC, DE and HL with the alternate set again (EXX): both sets hold the program's values.
4FBC
POP IX DD E1
Load Index Register IX from the stack at the Stack Pointer: the saved Index Register IX of 4075H.
4FBE
POP IY FD E1
Load Index Register IY from the stack at the Stack Pointer: the saved Index Register IY of 4077H.
4FC0
POP HL E1
Load Register Pair HL from the stack at the Stack Pointer: the saved SP of 4079H.
4FC1
LD SP,HL F9
Load the Stack Pointer from Register Pair HL: the program's stack.
4FC2
LD HL,(407BH) 2A 7B 40
Load Register Pair HL with the saved PC at 407BH, the address where the program goes on.
4FC5
PUSH HL E5
Save Register Pair HL, the program's address, on the stack at the Stack Pointer, for the RET at 4FC9H.
4FC6
LD HL,(406BH) 2A 6B 40
Load Register Pair HL with the saved Register Pair HL at 406BH, the last register put back.
4FC9
RET C9
Return to the program's address on the stack at the Stack Pointer: the program runs with every register as saved or changed.
4FCAH - Place a Breakpoint
Register Pair HL is the address and Register Pair DE the last byte of the entry, filled downwards: the byte at the address, then its high and low bytes. The address gets F7H, RST 30H. A byte that does not keep the F7H (ROM, or no memory) ends the command: 4E2FH takes out the breakpoints placed and the command loop starts again.
4FCA
LD A,(HL) 7E
Load Register A with the program's byte at the breakpoint address in Register Pair HL.
4FCB
LD (DE),A 12
Store Register A, the program's byte, at Register Pair DE, the last byte of the entry.
4FCC
DEC DE 1B
Decrement Register Pair DE to the place of the high byte of the address.
4FCD
LD A,F7H 3E F7
Load Register A with F7H, the RST 30H instruction.
4FCF
LD (HL),A 77
Store Register A (F7H) at the breakpoint address in Register Pair HL.
4FD0
CP (HL) BE
Compare Register A (F7H) with the byte at Register Pair HL: the Z FLAG is set when the F7H stayed.
4FD1
If the NZ FLAG is set (the address cannot hold the RST 30H), jump to 4E2FH to take out the breakpoints and start the command loop again.
4FD4
LD A,H 7C
Copy the high byte of the address from Register H into Register A.
4FD5
LD (DE),A 12
Store Register A, the high byte of the address, at Register Pair DE.
4FD6
DEC DE 1B
Decrement Register Pair DE to the place of the low byte of the address.
4FD7
LD A,L 7D
Copy the low byte of the address from Register L into Register A.
4FD8
LD (DE),A 12
Store Register A, the low byte of the address, at Register Pair DE.
4FD9
DEC DE 1B
Decrement Register Pair DE to the end of the next entry (405FH after the first entry).
4FDA
RET C9
Return to the caller with Register Pair DE at the end of the next entry.
4FDBH - M: Change Memory
M, then an optional hexadecimal address (else the address at 4060H, which the entry to DEBUG clears to 0000H), then the new bytes, each ended by a space or a comma; ENTER ends. Before each byte the display is shown with the byte marked (AAH before it, 95H after it, at 5165H), its address on the line at 3F40H and its value and a minus sign at 3F80H. A space or a comma with no number leaves the byte as it is and goes to the next.
4FDB
LD HL,(4060H) 2A 60 40
Load Register Pair HL with the address of M at 4060H.
4FDE
Call 51A3H to read an address: Register Pair HL is the number when one was typed, else Register Pair HL stays the address of M.
4FE1
LD (4060H),HL 22 60 40
Store Register Pair HL at 4060H, the address of M, marked in the display. 500FH jumps here with the next address.
4FE4
RET C D8
If the C FLAG is set (ENTER ended the input), return to 4E4BH, the command loop.
4FE5
PUSH HL E5
Save Register Pair HL, the address of the byte, on the stack at the Stack Pointer.
4FE6
Call 4ECFH to show the display with the byte marked.
4FE9
LD HL,3F40H 21 40 3F
Load Register Pair HL with 3F40H, the start of the fourteenth line of the screen.
4FEC
LD (4020H),HL 22 20 40
Store Register Pair HL (3F40H) at 4020H, the cursor address of the display driver.
4FEF
LD HL,(4060H) 2A 60 40
Load Register Pair HL with the address of M at 4060H.
4FF2
Call 51D4H to show the address in Register Pair HL as four hexadecimal digits.
4FF5
PUSH HL E5
Save Register Pair HL, the address of M, on the stack at the Stack Pointer while the cursor is moved.
4FF6
LD HL,3F80H 21 80 3F
Load Register Pair HL with 3F80H, the start of the fifteenth line of the screen.
4FF9
LD (4020H),HL 22 20 40
Store Register Pair HL (3F80H) at 4020H, the cursor address of the display driver.
4FFC
POP HL E1
Restore Register Pair HL, the address of M, from the stack at the Stack Pointer.
4FFD
Call 51D0H to show the byte at Register Pair HL as two hexadecimal digits; Register Pair HL steps past it.
5000
LD A,2DH 3E 2D
Load Register A with 2DH, the minus sign after the byte.
5002
Call 0033H, the ROM's display routine, to show the minus sign in Register A.
5005
POP DE D1
Restore Register Pair DE from the stack at the Stack Pointer: the address of the byte, pushed at 4FE5H.
5006
Call 51A3H to read the new byte: Register Pair HL is the number and the NZ FLAG is set when one was typed.
5009
EX DE,HL EB
Exchange Register Pairs DE and HL: Register Pair HL is the address of the byte and Register E the low byte of the number.
500A
If the Z FLAG is set (no number was typed), jump to 500DH, leaving the byte as it is.
500C
LD (HL),E 73
Store Register E, the low byte of the number, at Register Pair HL, the address of the byte.
500D
RET C D8
If the C FLAG is set (ENTER ended the input), return to 4E4BH, the command loop.
500E
INC HL 23
Increment Register Pair HL to the next byte, the new address of M.
500F
Jump back to 4FE1H to store the address and show the next byte.
5011H - R: Change a Register
R, the two letters of a register's name and, for an alternate register, a quote, then a space or a comma and the new value in hexadecimal. The name is looked up in the twelve names at 4F54H and the value stored in the register area, from which G and the single step put it back. A name that is not found, or ENTER after the name, does nothing.
5011
Call 518AH to read the first letter of the name in Register A; the Z FLAG is set for ENTER, a space or a comma.
5014
RET Z C8
If the Z FLAG is set (no letter), return to 4E4BH, the command loop.
5015
LD C,A 4F
Copy the first letter from Register A into Register C.
5016
Call 518AH to read the second letter of the name in Register A.
5019
RET Z C8
If the Z FLAG is set (no second letter), return to 4E4BH, the command loop.
501A
LD D,A 57
Copy the second letter from Register A into Register D.
501B
LD E,20H 1E 20
Load Register E with 20H, a space, the third character of a name with no quote.
501D
Call 518AH to read the next character in Register A.
5020
RET C D8
If the C FLAG is set (ENTER), return to 4E4BH, the command loop: no value follows.
5021
If the Z FLAG is set (a space or a comma), jump to 5029H to look up the name with the space in Register E.
5023
LD E,A 5F
Copy the third character, the quote of an alternate register, from Register A into Register E.
5024
Call 518AH to read the character after the quote in Register A.
5027
RET NZ C0
If the NZ FLAG is set (not a space or a comma), return to 4E4BH, the command loop.
5028
RET C D8
If the C FLAG is set (ENTER), return to 4E4BH, the command loop: no value follows.
5029
LD HL,4F54H 21 54 4F
Load Register Pair HL with 4F54H, the twelve names of the registers.
502C
LD B,0CH 06 0C
Load Register B with 0CH, the twelve names to compare with the name typed.
502E
LD A,(HL) 7E
Load Register A with the first character of the name at Register Pair HL.
502F
CP C B9
Compare Register A with Register C, the first letter typed.
5030
If the Z FLAG is set (the first letters agree), jump to 5038H to compare the second character.
5032
INC HL 23
Increment Register Pair HL past the first character of the name.
5033
INC HL 23
Increment Register Pair HL past the second character of the name. 503BH jumps here.
5034
INC HL 23
Increment Register Pair HL past the third character to the next name. 5040H jumps here.
5035
Decrement Register B and, if it is not zero, jump back to 502EH for the next name.
5037
RET C9
Return to 4E4BH, the command loop: the name is not one of the twelve.
5038
INC HL 23
Increment Register Pair HL to the second character of the name.
5039
LD A,(HL) 7E
Load Register A with the second character of the name at Register Pair HL.
503A
CP D BA
Compare Register A with Register D, the second letter typed.
503B
If the NZ FLAG is set (the second letters differ), jump back to 5033H for the next name.
503D
INC HL 23
Increment Register Pair HL to the third character of the name.
503E
LD A,(HL) 7E
Load Register A with the third character of the name at Register Pair HL, a space or a quote.
503F
CP E BB
Compare Register A with Register E, the space or the quote typed.
5040
If the NZ FLAG is set (the third characters differ), jump back to 5034H for the next name.
5042
LD A,18H 3E 18
Load Register A with 18H, 24, twice the twelve names.
5044
SUB B 90
Subtract Register B, 0CH less the number of the name counted from 0, from Register A (18H).
5045
SUB B 90
Subtract Register B again from Register A: Register A is twice the number of the name from 0, the offset of the register's word.
5046
LD C,A 4F
Copy the offset from Register A into Register C.
5047
LD B,00H 06 00
Load Register B with 00H: Register Pair BC is the offset of the register's word.
5049
LD HL,4065H 21 65 40
Load Register Pair HL with 4065H, the register area.
504C
ADD HL,BC 09
Add Register Pair BC, the offset, to Register Pair HL: Register Pair HL points at the register's word.
504D
PUSH HL E5
Save Register Pair HL, the place of the register's word, on the stack at the Stack Pointer.
504E
LD A,1EH 3E 1E
Load Register A with 1EH, the display code that clears from the cursor to the end of the line.
5050
Call 0033H, the ROM's display routine, with Register A 1EH: the rest of the line is cleared for the value.
5053
POP DE D1
Restore Register Pair DE from the stack at the Stack Pointer: the place of the register's word.
5054
Call 51A3H to read the value: Register Pair HL is the number and the NZ FLAG is set when one was typed.
5057
RET Z C8
If the Z FLAG is set (no value was typed), return to 4E4BH, the command loop.
5058
EX DE,HL EB
Exchange Register Pairs DE and HL: Register Pair HL is the place of the register's word, Register Pair DE the value.
5059
LD (HL),E 73
Store Register E, the low byte of the value, at Register Pair HL.
505A
INC HL 23
Increment Register Pair HL to the high byte of the register's word.
505B
LD (HL),D 72
Store Register D, the high byte of the value, at Register Pair HL.
505C
RET C9
Return to 4E4BH, the command loop, which shows the new value.
505DH - I and C: Single Step
The instruction at the saved PC is looked up in one of three tables of three byte entries (mask, value, kind and length): 50E0H for an instruction without a prefix, 510EH after EDH, 5115H after DDH or FDH. The first entry whose mask, ANDed with the opcode (the byte after the prefix), gives its value is taken; a byte below 05H ends a table and is the kind and length of every other instruction. Breakpoint 1 goes after the instruction, and for a jump, call or return breakpoint 2 goes at its target. Then the program runs (4FA4H) until one of them is reached. C differs from I only at a CALL: C lets the called routine run whole, I stops at its first instruction.
505D
PUSH AF F5
Save Register Pair AF, the command letter (I or C) in Register A, on the stack at the Stack Pointer for the test at 50B0H.
505E
LD DE,(407BH) ED 5B 7B 40
Load Register Pair DE with the saved PC at 407BH, the address of the instruction to step.
5062
LD A,(DE) 1A
Load Register A with the first byte of the instruction at Register Pair DE.
5063
LD HL,5115H 21 15 51
Load Register Pair HL with 5115H, the table of the instructions after DDH or FDH.
5066
CP DDH FE DD
Compare Register A, the first byte, with DDH, the prefix of Index Register IX.
5068
If the Z FLAG is set (DDH), jump to 5078H to take the byte after the prefix.
506A
CP FDH FE FD
Compare Register A, the first byte, with FDH, the prefix of Index Register IY.
506C
If the Z FLAG is set (FDH), jump to 5078H to take the byte after the prefix.
506E
LD HL,50E0H 21 E0 50
Load Register Pair HL with 50E0H, the table of the instructions without a prefix.
5071
CP EDH FE ED
Compare Register A, the first byte, with EDH, the prefix of the extended instructions.
5073
If the NZ FLAG is set (no prefix), jump to 507BH with the first byte in Register A.
5075
LD HL,510EH 21 0E 51
Load Register Pair HL with 510EH, the table of the instructions after EDH.
5078
INC DE 13
Increment Register Pair DE to the byte after the prefix.
5079
LD A,(DE) 1A
Load Register A with the byte after the prefix at Register Pair DE, the opcode looked up.
507A
DEC DE 1B
Decrement Register Pair DE back to the address of the instruction.
507B
LD C,A 4F
Copy the opcode from Register A into Register C for the tests against each entry.
507C
LD A,(HL) 7E
Load Register A with the mask of the entry at Register Pair HL. 5087H jumps here for each entry.
507D
AND C A1
AND Register A, the mask, with Register C, the opcode.
507E
INC HL 23
Increment Register Pair HL to the value of the entry.
507F
CP (HL) BE
Compare Register A, the masked opcode, with the value at Register Pair HL.
5080
INC HL 23
Increment Register Pair HL to the kind and length byte of the entry.
5081
If the Z FLAG is set (the entry matches), jump to 5089H with Register Pair HL at its kind and length byte.
5083
INC HL 23
Increment Register Pair HL to the next entry.
5084
LD A,(HL) 7E
Load Register A with the next entry's mask at Register Pair HL, or the end byte of the table.
5085
CP 05H FE 05
Compare Register A with 05H: the end byte of each table is below 05H.
5087
If the NC FLAG is set (another entry), jump back to 507CH; else Register Pair HL is at the end byte, the kind and length of every other instruction.
5089
LD A,(HL) 7E
Load Register A with the kind and length byte at Register Pair HL: bits 7-4 the kind, bits 3-0 the length.
508A
LD B,A 47
Copy the kind and length from Register A into Register B for the test of the kind at 5099H.
508B
AND 0FH E6 0F
AND Register A with 0FH to keep the length of the instruction.
508D
LD L,A 6F
Copy the length from Register A into Register L.
508E
LD H,00H 26 00
Load Register H with 00H: Register Pair HL is the length.
5090
ADD HL,DE 19
Add Register Pair DE, the address of the instruction, to Register Pair HL: Register Pair HL is the address of the next instruction.
5091
PUSH DE D5
Save Register Pair DE, the address of the instruction, on the stack at the Stack Pointer.
5092
LD DE,4062H 11 62 40
Load Register Pair DE with 4062H, the end of the entry of breakpoint 1.
5095
Call 4FCAH to put breakpoint 1 at Register Pair HL, the next instruction; Register Pair DE ends at 405FH, the entry of breakpoint 2.
5098
POP HL E1
Restore Register Pair HL from the stack at the Stack Pointer: the address of the instruction.
5099
LD A,B 78
Copy the kind and length from Register B into Register A.
509A
AND F0H E6 F0
AND Register A with F0H to keep the kind: 00H for an instruction that always goes on to the next.
509C
If the Z FLAG is set (kind 0), jump to 50B4H to run it: breakpoint 1 is enough.
509E
INC HL 23
Increment Register Pair HL to the byte after the opcode: the displacement or the low byte of the address of the instruction.
509F
CP 20H FE 20
Compare Register A, the kind, with 20H, to tell the kinds 10H and 20H apart.
50A1
If the C FLAG is set (kind 10H, JP (HL)), jump to 50D8H: the target is the saved Register Pair HL.
50A3
If the Z FLAG is set (kind 20H, JP (IX) or JP (IY)), jump to 50CCH: the target is an Index Register.
50A5
CP 40H FE 40
Compare Register A, the kind, with 40H, to tell the kinds 30H and 40H apart.
50A7
If the C FLAG is set (kind 30H, JR or DJNZ), jump to 50C0H to add the displacement.
50A9
If the Z FLAG is set (kind 40H, JP), jump to 50BAH: the target is the address after the opcode.
50AB
CP 60H FE 60
Compare Register A, the kind, with 60H, to tell the kinds 50H and 60H apart.
50AD
If the C FLAG is set (kind 50H, RET or RETN or RETI), jump to 50B7H: the target is the word at the saved SP.
50AF
POP AF F1
Restore Register Pair AF from the stack at the Stack Pointer: the command letter in Register A (kind 60H, CALL).
50B0
CP 49H FE 49
Compare Register A, the command letter, with 49H, the letter I.
50B2
If the Z FLAG is set (I), jump to 50BAH to put breakpoint 2 at the called address too.
50B4
Jump to 4FA4H to put the registers back and run the instruction. 509CH and 50DEH also come here.
50B7
LD HL,(4079H) 2A 79 40
Load Register Pair HL with the saved SP at 4079H: a return goes to the word at the top of the program's stack.
50BA
LD A,(HL) 7E
Load Register A with the low byte of the target at Register Pair HL.
50BB
INC HL 23
Increment Register Pair HL to the high byte of the target.
50BC
LD H,(HL) 66
Load Register H with the high byte of the target at Register Pair HL.
50BD
LD L,A 6F
Copy the low byte from Register A into Register L: Register Pair HL is the target.
50BE
Jump to 50DBH to put breakpoint 2 at the target.
50C0
LD C,(HL) 4E
Load Register C with the displacement at Register Pair HL, the byte after the opcode.
50C1
XOR A AF
Clear Register A to 00H, the high byte of a forward displacement.
50C2
BIT 7,C CB 79
Test bit 7 of Register C, the sign of the displacement.
50C4
If the Z FLAG is set (bit 7 clear, a forward jump), jump to 50C7H with Register A 00H.
50C6
CPL 2F
Complement Register A to FFH, the high byte of a backward displacement.
50C7
LD B,A 47
Copy the high byte from Register A into Register B: Register Pair BC is the displacement as a 16 bit number.
50C8
INC HL 23
Increment Register Pair HL past the displacement to the next instruction, from which a relative jump counts.
50C9
ADD HL,BC 09
Add Register Pair BC, the displacement, to Register Pair HL: Register Pair HL is the target of the JR or DJNZ.
50CA
Jump to 50DBH to put breakpoint 2 at the target.
50CC
LD HL,(4075H) 2A 75 40
Load Register Pair HL with the saved Index Register IX at 4075H.
50CF
BIT 5,C CB 69
Test bit 5 of Register C. Register C is the opcode E9H, whose bit 5 is always set, and not the prefix DDH or FDH (bit 5 clear for IX, set for IY), so the test always chooses IY (a bug: the Bugs part of the introduction).
50D1
If the Z FLAG is set (never, Register C is E9H), jump to 50DBH with the saved Index Register IX in Register Pair HL.
50D3
LD HL,(4077H) 2A 77 40
Load Register Pair HL with the saved Index Register IY at 4077H.
50D6
Jump to 50DBH to put breakpoint 2 at the target in Register Pair HL.
50D8
LD HL,(406BH) 2A 6B 40
Load Register Pair HL with the saved Register Pair HL at 406BH, the target of JP (HL).
50DB
Call 4FCAH to put breakpoint 2 at Register Pair HL, the target, with its entry ending at Register Pair DE (405FH).
50DE
Jump back to 50B4H to put the registers back and run the instruction.
50E0H - The Table of the Instructions Without a Prefix
Each entry is a mask, a value and a byte whose bits 7-4 give the kind (00H goes on to the next instruction only, 10H JP (HL), 20H JP (IX) or JP (IY), 30H a relative jump, 40H a jump to an address, 50H a return, 60H a call) and bits 3-0 the length. The opcode ANDed with the mask must give the value.
50E0-50E2
DEFB C7H,C0H,51H C7 C0 51
Opcodes 11xxx000, mask C7H value C0H: RET cc, a conditional return, kind 50H, one byte: breakpoints after it and at the word at the saved SP.
50E3-50E5
DEFB FFH,C9H,51H FF C9 51
Opcode C9H, RET, kind 50H, one byte: breakpoints after it (which is never reached) and at the word at the saved SP.
50E6-50E8
DEFB FFH,E9H,11H FF E9 11
Opcode E9H, JP (HL), kind 10H, one byte: breakpoints after it and at the saved Register Pair HL.
50E9-50EB
DEFB CFH,01H,03H CF 01 03
Opcodes 00xx0001, mask CFH value 01H: LD BC,nn, LD DE,nn, LD HL,nn and LD SP,nn, kind 00H, three bytes.
50EC-50EE
DEFB E7H,22H,03H E7 22 03
Opcodes 001xx010, mask E7H value 22H: LD (nn),HL, LD HL,(nn), LD (nn),A and LD A,(nn), kind 00H, three bytes.
50EF-50F1
DEFB C7H,C2H,43H C7 C2 43
Opcodes 11xxx010, mask C7H value C2H: JP cc,nn, kind 40H, three bytes: breakpoints after it and at nn.
50F2-50F4
DEFB FFH,C3H,43H FF C3 43
Opcode C3H, JP nn, kind 40H, three bytes: breakpoints after it (never reached) and at nn.
50F5-50F7
DEFB C7H,C4H,63H C7 C4 63
Opcodes 11xxx100, mask C7H value C4H: CALL cc,nn, kind 60H, three bytes: with I a breakpoint at nn too.
50F8-50FA
DEFB FFH,CDH,63H FF CD 63
Opcode CDH, CALL nn, kind 60H, three bytes: with I a breakpoint at nn too, with C only after it.
50FB-50FD
DEFB C7H,06H,02H C7 06 02
Opcodes 00xxx110, mask C7H value 06H: LD r,n and LD (HL),n, kind 00H, two bytes.
50FE-5100
DEFB F7H,D3H,02H F7 D3 02
Opcodes 11010011 and 11011011, mask F7H value D3H: OUT (n),A and IN A,(n), kind 00H, two bytes.
5101-5103
DEFB C7H,C6H,02H C7 C6 02
Opcodes 11xxx110, mask C7H value C6H: ADD, ADC, SUB, SBC, AND, XOR, OR and CP with an immediate byte, kind 00H, two bytes.
5104-5106
DEFB FFH,CBH,02H FF CB 02
Opcode CBH, the prefix of the shifts and bit instructions, kind 00H, two bytes.
5107-5109
DEFB F7H,10H,32H F7 10 32
Opcodes 10H and 18H, mask F7H value 10H: DJNZ e and JR e, kind 30H, two bytes: breakpoints after it and at the target.
510A-510C
DEFB E7H,20H,32H E7 20 32
Opcodes 001xx000, mask E7H value 20H: JR NZ,e, JR Z,e, JR NC,e and JR C,e, kind 30H, two bytes.
510D
DEFB 01H 01
The end of the table: every other instruction without a prefix is kind 00H, one byte. RST n is among them, so a step of an RST lets its routine run whole.
510EH - The Table of the Instructions After EDH
Opcodes after the prefix EDH; the length counts the prefix.
510E-5110
DEFB C7H,43H,04H C7 43 04
Opcodes 01xxx011 after EDH, mask C7H value 43H: LD (nn),rr and LD rr,(nn), kind 00H, four bytes.
5111-5113
DEFB F7H,45H,52H F7 45 52
Opcodes 45H and 4DH after EDH, mask F7H value 45H: RETN and RETI, kind 50H, two bytes: a breakpoint at the word at the saved SP.
5114
DEFB 02H 02
The end of the table: every other instruction after EDH is kind 00H, two bytes.
5115H - The Table of the Instructions After DDH or FDH
Opcodes after the prefix of Index Register IX or IY; the length counts the prefix.
5115-5117
DEFB FEH,34H,03H FE 34 03
Opcodes 34H and 35H, mask FEH value 34H: INC (IX+d) and DEC (IX+d), kind 00H, three bytes.
5118-511A
DEFB C0H,40H,03H C0 40 03
Opcodes 40H-7FH, mask C0H value 40H: LD r,(IX+d) and LD (IX+d),r, kind 00H, three bytes.
511B-511D
DEFB C0H,80H,03H C0 80 03
Opcodes 80H-BFH, mask C0H value 80H: ADD, ADC, SUB, SBC, AND, XOR, OR and CP with (IX+d), kind 00H, three bytes.
511E-5120
DEFB FFH,21H,04H FF 21 04
Opcode 21H, LD IX,nn or LD IY,nn, kind 00H, four bytes with the prefix.
5121-5123
DEFB FFH,22H,04H FF 22 04
Opcode 22H, LD (nn),IX, kind 00H, four bytes.
5124-5126
DEFB FFH,2AH,04H FF 2A 04
Opcode 2AH, LD IX,(nn), kind 00H, four bytes.
5127-5129
DEFB FFH,36H,04H FF 36 04
Opcode 36H, LD (IX+d),n, kind 00H, four bytes.
512A-512C
DEFB FFH,CBH,04H FF CB 04
Opcode CBH, the shifts and bit instructions on (IX+d), kind 00H, four bytes.
512D-512F
DEFB FFH,E9H,22H FF E9 22
Opcode E9H, JP (IX) or JP (IY), kind 20H, two bytes: a breakpoint at the saved Index Register (50CCH).
5130
DEFB 02H 02
The end of the table: every other instruction after DDH or FDH (PUSH, POP, ADD, INC, DEC, EX (SP), LD SP) is kind 00H, two bytes.
5131H - Show Sixteen Bytes
An equals sign, a greater than sign and a space, then the sixteen bytes at Register Pair HL, each after a separator (5165H) and with an extra space after the eighth: in hexadecimal, or with A (405DH 41H) as a space and the character, a period for a byte below 20H or from C0H. Register Pair HL steps past the bytes; Register Pair BC is kept.
5131
PUSH BC C5
Save Register Pair BC on the stack at the Stack Pointer: Register B is the caller's count of lines or registers.
5132
LD A,3DH 3E 3D
Load Register A with 3DH, the equals sign, the first character of the arrow.
5134
Call 0033H, the ROM's display routine, to show the equals sign in Register A.
5137
LD A,3EH 3E 3E
Load Register A with 3EH, the greater than sign: with the equals sign before it, an arrow to the bytes.
5139
Call 0033H, the ROM's display routine, to show the greater than sign in Register A.
513C
Call 51F2H to show a space between the arrow and the first byte.
513F
LD B,10H 06 10
Load Register B with 10H, the sixteen bytes of the line.
5141
Call 5165H to show the separator before the byte at Register Pair HL. 5161H jumps here for each byte.
5144
LD A,(405DH) 3A 5D 40
Load Register A with 405DH, 41H (A) for characters, otherwise hexadecimal.
5147
CP 41H FE 41
Compare Register A with 41H, the letter A stored at 405DH by the A command.
5149
If the NZ FLAG is set (hexadecimal), jump to 515EH with the NZ FLAG still set, to call 51D0H.
514B
Call 51F2H to show a space before the character.
514E
LD A,(HL) 7E
Load Register A with the byte at Register Pair HL.
514F
CP 20H FE 20
Compare Register A, the byte, with 20H, the space, the first character shown.
5151
If the C FLAG is set (a control code below 20H), jump to 5157H to show a period.
5153
CP C0H FE C0
Compare Register A with C0H, the first space compression code.
5155
If the C FLAG is set (20H-BFH: a character or a graphics block), jump to 5159H to show it as it is.
5157
LD A,2EH 3E 2E
Load Register A with 2EH, the period shown for a byte below 20H or from C0H.
5159
Call 0033H, the ROM's display routine, to show Register A, the character or the period.
515C
INC HL 23
Increment Register Pair HL to the next byte after showing it as a character.
515D
XOR A AF
Clear Register A to 00H and set the Z FLAG, so that the CALL NZ at 515EH is passed over.
515E
If the NZ FLAG is set (hexadecimal), call 51D0H to show the byte at Register Pair HL as two hexadecimal digits; Register Pair HL steps past it.
5161
Decrement Register B and, if it is not zero, jump back to 5141H for the next byte.
5163
POP BC C1
Restore Register Pair BC, the caller's count, from the stack at the Stack Pointer.
5164
RET C9
Return to the caller with Register Pair HL past the sixteen bytes.
5165H - Show the Separator Before a Byte
Normally a space. Before the byte at the address of M (4060H) it is AAH, a graphics block with the left column lit, and before the byte after it 95H, a block with the right column lit, so the byte M changes is framed. Before the ninth byte (Register B 08H) an extra space splits the line in two.
5165
LD DE,(4060H) ED 5B 60 40
Load Register Pair DE with the address of M at 4060H.
5169
INC DE 13
Increment Register Pair DE to the byte after the address of M.
516A
PUSH HL E5
Save Register Pair HL, the address of the byte, on the stack at the Stack Pointer.
516B
XOR A AF
Clear Register A to 00H, which clears the C FLAG for the SBC.
516C
SBC HL,DE ED 52
Subtract Register Pair DE, the byte after the address of M, from Register Pair HL: the Z FLAG is set when this byte follows the byte of M.
516E
LD A,95H 3E 95
Load Register A with 95H, the graphics block that closes the frame of the byte of M.
5170
If the Z FLAG is set (this byte follows the byte of M), jump to 5180H to show 95H.
5172
Call 5184H to show the extra space when this is the ninth byte (Register B 08H).
5175
INC HL 23
Increment Register Pair HL, the difference: it is 0000H when this byte is the byte of M.
5176
LD A,L 7D
Copy the low byte of the difference from Register L into Register A.
5177
OR H B4
OR Register A with Register H: the Z FLAG is set when the difference in Register Pair HL is 0000H.
5178
POP HL E1
Restore Register Pair HL, the address of the byte, from the stack at the Stack Pointer.
5179
LD A,AAH 3E AA
Load Register A with AAH, the graphics block that opens the frame of the byte of M.
517B
If the Z FLAG is set (this is the byte of M), jump to 0033H, the ROM's display routine, which shows AAH and returns to the caller.
517E
Jump to 5188H to show a space, the separator before an ordinary byte.
5180
Call 0033H, the ROM's display routine, to show Register A, 95H.
5183
POP HL E1
Restore Register Pair HL, the address of the byte, from the stack at the Stack Pointer.
5184
LD A,B 78
Load Register A with the count of the bytes from Register B: 08H before the ninth byte.
5185
CP 08H FE 08
Compare Register A, the count in Register B, with 08H, the ninth byte.
5187
RET NZ C0
If the NZ FLAG is set (not the ninth byte), return to the caller.
5188
Jump to 51F2H to show a space, which returns to the caller.
518AH - Read and Show a Key
Wait for a key through ROM 0049H. ENTER returns with the C FLAG and the Z FLAG set and is not shown; the other control codes below 20H are ignored. Every other key is shown and returned in Register A, with the Z FLAG set for a comma or a space and the C FLAG clear. Register Pair DE is kept.
518A
PUSH DE D5
Save Register Pair DE on the stack at the Stack Pointer.
518B
Call 0049H, the ROM's routine that waits for a key: Register A is the key. 5194H jumps back here.
518E
CP 0DH FE 0D
Compare Register A, the key, with 0DH, ENTER.
5190
If the Z FLAG is set (ENTER), jump to 51A0H to return with the C FLAG set.
5192
CP 20H FE 20
Compare Register A, the key, with 20H, the space.
5194
If the C FLAG is set (another control code), jump back to 518BH for the next key.
5196
Call 0033H, the ROM's display routine, to show the key in Register A.
5199
POP DE D1
Restore Register Pair DE from the stack at the Stack Pointer.
519A
CP 2CH FE 2C
Compare Register A, the key, with 2CH, the comma.
519C
RET Z C8
If the Z FLAG is set (a comma), return to the caller with the C FLAG clear.
519D
CP 20H FE 20
Compare Register A, the key, with 20H: the Z FLAG is set for a space, and the C FLAG is clear, since every key here is 20H or more.
519F
RET C9
Return to the caller with the key in Register A.
51A0
POP DE D1
Restore Register Pair DE from the stack at the Stack Pointer (ENTER).
51A1
SCF 37
Set the C FLAG: ENTER; the Z FLAG is still set from the compare at 518EH.
51A2
RET C9
Return to the caller with Register A 0DH and the C FLAG and the Z FLAG set.
51A3H - Read a Hexadecimal Number
Keys are read through 518AH and shown. ENTER, a comma or a space at once returns the Z FLAG set and Register Pair HL unchanged (with the C FLAG for ENTER). Otherwise hexadecimal digits are taken into Register Pair HL, the last four counting, until ENTER, a comma or a space: the NZ FLAG is returned, with the C FLAG set when ENTER ended the number. Any other key ends the command: the command loop starts again at 4E4BH.
51A3
Call 518AH to read the first key in Register A.
51A6
RET Z C8
If the Z FLAG is set (ENTER, a comma or a space at once), return to the caller: no number.
51A7
LD HL,0000H 21 00 00
Load Register Pair HL with 0000H, the number before the first digit.
51AA
Call 51BFH to change the key in Register A into a digit 00H-0FH; the C FLAG is set when it is not a hexadecimal digit. 51B9H jumps back here.
51AD
If the C FLAG is set (not a hexadecimal digit), jump to 4E4BH, the command loop, which resets the Stack Pointer from 4079H.
51B0
ADD HL,HL 29
Add Register Pair HL to itself: the number times 2.
51B1
ADD HL,HL 29
Add Register Pair HL to itself: the number times 4.
51B2
ADD HL,HL 29
Add Register Pair HL to itself: the number times 8.
51B3
ADD HL,HL 29
Add Register Pair HL to itself: the number times 16, the low four bits free for the digit.
51B4
OR L B5
OR Register A, the digit, with Register L, the low byte of the number.
51B5
LD L,A 6F
Copy Register A into Register L: the digit is the low four bits of Register Pair HL.
51B6
Call 518AH to read the next key in Register A.
51B9
If the NZ FLAG is set (another key), jump back to 51AAH to take it as a digit.
51BB
RRA 1F
Rotate Register A right through the carry: the C FLAG (set for ENTER) goes into bit 7. Register A was 0DH, 2CH or 20H, so it becomes 86H, 16H or 10H.
51BC
ADC A,81H CE 81
Add 81H and the C FLAG to Register A: 86H plus 81H plus 1 is 108H, so ENTER gives the C FLAG; 16H and 10H give 97H and 91H with the C FLAG clear. The result is never 00H, so the NZ FLAG is set.
51BE
RET C9
Return to the caller with the number in Register Pair HL, the NZ FLAG set and the C FLAG set when ENTER ended it.
51BF
SUB 30H D6 30
Subtract 30H, the digit 0, from Register A, the key: the C FLAG is set for a key below 0.
51C1
RET C D8
If the C FLAG is set (below 0), return with the C FLAG set: not a digit.
51C2
ADD A,E9H C6 E9
Add E9H to Register A: the C FLAG is set for a key from 47H (G) on, which is past F.
51C4
RET C D8
If the C FLAG is set (G or more), return with the C FLAG set: not a digit.
51C5
ADD A,06H C6 06
Add 06H to Register A: the C FLAG is set for the letters A-F (41H-46H).
51C7
If the C FLAG is set (A-F), jump to 51CCH, where adding 0AH gives 0AH-0FH.
51C9
ADD A,07H C6 07
Add 07H to Register A: the C FLAG is set for the keys 3AH-40H between 9 and A.
51CB
RET C D8
If the C FLAG is set (3AH-40H), return with the C FLAG set: not a digit.
51CC
ADD A,0AH C6 0A
Add 0AH to Register A: the digit 0-9 or A-F is now 00H-0FH. 51C7H jumps here.
51CE
OR A B7
Clear the C FLAG from Register A (OR A): a hexadecimal digit.
51CF
RET C9
Return to the caller with the digit in Register A and the C FLAG clear.
51D0H - Show Bytes in Hexadecimal
51D0H shows the byte at Register Pair HL and steps Register Pair HL past it; 51D4H shows Register Pair HL as four digits; 51D9H shows Register A as two digits; 51E2H shows the low four bits of Register A as one digit; 51EFH shows Register A as two digits and a space; 51F2H shows a space; 51F6H shows the three characters at Register Pair HL. All of them leave through 51ECH to ROM 0033H.
51D0
LD A,(HL) 7E
Load Register A with the byte at Register Pair HL.
51D1
INC HL 23
Increment Register Pair HL past the byte, so that the caller goes on after it.
51D2
Jump to 51D9H to show Register A as two hexadecimal digits.
51D4
LD A,H 7C
Copy the high byte of the number from Register H into Register A.
51D5
Call 51D9H to show Register A, the high byte, as two hexadecimal digits.
51D8
LD A,L 7D
Copy the low byte of the number from Register L into Register A, to be shown by 51D9H, which follows.
51D9
PUSH AF F5
Save Register Pair AF, the byte in Register A, on the stack at the Stack Pointer for its low digit.
51DA
RRA 1F
Rotate Register A right through the carry: the first of four rotations that bring the high four bits down.
51DB
RRA 1F
Rotate Register A right through the carry, the second of four rotations.
51DC
RRA 1F
Rotate Register A right through the carry, the third of four rotations.
51DD
RRA 1F
Rotate Register A right through the carry, the fourth: the high four bits of the byte are bits 3-0 of Register A.
51DE
Call 51E2H to show the low four bits of Register A, the high digit of the byte.
51E1
POP AF F1
Restore Register Pair AF, the byte in Register A, from the stack at the Stack Pointer, to show its low digit next.
51E2
AND 0FH E6 0F
AND Register A with 0FH to keep the digit, 00H-0FH.
51E4
ADD A,30H C6 30
Add 30H to Register A, the digit 0, so that 00H-09H become the digits 0-9.
51E6
CP 3AH FE 3A
Compare Register A with 3AH, the character after 9.
51E8
If the C FLAG is set (0-9), jump to 51ECH to show the digit.
51EA
ADD A,07H C6 07
Add 07H to Register A: 3AH-3FH become the letters A-F.
51EC
Jump to 0033H, the ROM's display routine, which shows Register A and returns to the caller. 51E8H, 51F4H and 51FEH jump here.
51EF
Call 51D9H to show Register A as two hexadecimal digits, then fall into 51F2H for a space.
51F2
LD A,20H 3E 20
Load Register A with 20H, the space, to be shown through ROM 0033H.
51F4
Jump to 51ECH to show Register A, the space, through ROM 0033H.
51F6
Call 51FCH to show the first character at Register Pair HL.
51F9
Call 51FCH to show the second character at Register Pair HL; the third follows in 51FCH.
51FC
LD A,(HL) 7E
Load Register A with the character at Register Pair HL.
51FD
INC HL 23
Increment Register Pair HL to the next character.
51FE
Jump to 51ECH to show the character in Register A through ROM 0033H.