4E00H - DEBUG Entry: Save the Registers
SYS5/SYS is loaded at 4E00H by the request handler of SYS0/SYS for request 87H (bits 3-0 = 7, directory entry code 07H), which SYS0/SYS's 44B4H issues after it pushes Register Pair AF. The request handler calls the overlay from 4C48H, so the stack holds the return address 4C4BH, then the program's Register Pair AF, then the address the program is to go on at: after a breakpoint (RST 30H) the address after the F7H byte, after BREAK the interrupted program counter, after a program start the transfer address, after a CALL 440DH its return address. Register Pairs BC, DE and HL, the alternate set and Index Registers IX and IY are the program's. 11 words are pushed below the program counter, and the 12 words are copied to 4065H-407CH.
4E00
POP AF F1
Restore Register Pair AF from the stack: the return address 4C4BH that the request handler's CALL at 4C48H pushed. DEBUG never returns into the request handler, so this word is dropped.
4E01
POP AF F1
Restore Register Pair AF from the stack: the program's Register Pair AF, pushed by SYS0/SYS's 44B4H before its RST 28H.
4E02
PUSH AF F5
Save Register Pair AF (the program's) to the stack again, just below the program counter: this word is copied to 4079H and then replaced there by the program's Stack Pointer (4E1FH).
4E03
PUSH IY FD E5
Save Index Register IY (the program's) to the stack; it is copied to 4077H.
4E05
PUSH IX DD E5
Save Index Register IX (the program's) to the stack; it is copied to 4075H.
4E07
EX AF,AF' 08
Exchange Register Pair AF with the alternate Register Pair AF': Register Pair AF now holds the program's AF'.
4E08
EXX D9
Exchange Register Pairs BC, DE and HL with the alternate set: Register Pairs BC, DE and HL now hold the program's BC', DE' and HL'.
4E09
PUSH HL E5
Save Register Pair HL (the program's HL') to the stack; it is copied to 4073H.
4E0A
PUSH DE D5
Save Register Pair DE (the program's DE') to the stack; it is copied to 4071H.
4E0B
PUSH BC C5
Save Register Pair BC (the program's BC') to the stack; it is copied to 406FH.
4E0C
PUSH AF F5
Save Register Pair AF (the program's AF') to the stack; it is copied 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 AF once more.
4E0E
EXX D9
Exchange Register Pairs BC, DE and HL with the alternate set again: Register Pairs BC, DE and HL are the program's once more.
4E0F
PUSH HL E5
Save Register Pair HL (the program's) to the stack; it is copied to 406BH.
4E10
PUSH DE D5
Save Register Pair DE (the program's) to the stack; it is copied to 4069H.
4E11
PUSH BC C5
Save Register Pair BC (the program's) to the stack; it is copied to 4067H.
4E12
PUSH AF F5
Save Register Pair AF (the program's) to the stack; it is copied to 4065H.
4E13
LD HL,0000H 21 00 00
Load Register Pair HL with 0000H, so that the addition below gives the Stack Pointer.
4E16
ADD HL,SP 39
Add the Stack Pointer to Register Pair HL: Register Pair HL = the address of the last word pushed (Register Pair AF), the first of the 12 words to copy.
4E17
LD DE,4065H 11 65 40
Point Register Pair DE to 4065H, the save area 4065H-407CH.
4E1A
LD BC,0018H 01 18 00
Load Register Pair BC with 0018H, the 24 bytes of the 12 words: AF, BC, DE, HL, AF', BC', DE', HL', IX, IY, the second AF and the program counter.
4E1D
LDIR ED B0
Copy the 24 bytes from the stack at Register Pair HL to the save area at Register Pair DE: 4065H AF, 4067H BC, 4069H DE, 406BH HL, 406DH AF', 406FH BC', 4071H DE', 4073H HL', 4075H IX, 4077H IY, 4079H the second AF, 407BH the program counter. Register Pair HL ends just past the program counter's word, at the program's Stack Pointer as it was before the program counter was pushed; Register Pair BC ends at 0000H.
4E1F
LD (4079H),HL 22 79 40
Store Register Pair HL (the program's Stack Pointer) to 4079H-407AH, over the second copy of Register Pair AF: the SP of the display and of R.
4E22
LD SP,HL F9
Load the Stack Pointer from Register Pair HL: DEBUG works on the program's stack, from the program's Stack Pointer down.
4E23
LD HL,(407BH) 2A 7B 40
Fetch the program counter saved at 407BH-407CH into Register Pair HL.
4E26
DEC HL 2B
Decrement Register Pair HL to the byte before the program counter.
4E27
LD A,(HL) 7E
Fetch the byte at Register Pair HL (the byte before the program counter) into Register A.
4E28
CP F7H FE F7
Compare Register A against F7H, the breakpoint byte RST 30H.
4E2A
If the NZ FLAG is set (the byte is not F7H), JUMP to 4E2FH and keep the program counter as it is.
4E2C
LD (407BH),HL 22 7B 40
Store Register Pair HL (the address of the F7H byte) to 407BH-407CH: the program counter now names the breakpoint, whose own byte 4E2FH puts back. Any entry whose program counter follows a byte F7H is moved back the same way.
4E2FH - Take Out the Breakpoints
The two breakpoint slots are 3 bytes each, the address (low byte first) and the byte that was there: 405DH-405FH (the second breakpoint of G, the branch target of I and C) and 4060H-4062H (the first breakpoint of G, the next instruction of I and C). Each slot's address is set to 0000H, and when the byte at the address is still F7H the saved byte is put back. 405DH (the A or H mode), 405EH (the S mode) and 4060H-4061H (the M address) are the address bytes of the slots, so every entry sets them to 00H. 4FD1H also comes here when a breakpoint cannot be set.
4E2F
LD HL,405DH 21 5D 40
Point Register Pair HL to 405DH, the first byte of the slot 405DH-405FH.
4E32
LD B,02H 06 02
Load Register B with 02H, the count of the two breakpoint slots.
4E34
XOR A AF
Set Register A to 00H, the value that clears the slot's address.
4E35
LD C,02H 0E 02
Load Register C with 02H. Nothing reads this value of Register C: every later use of Register C loads it first.
4E37
LD E,(HL) 5E
Fetch the low byte of the slot's address at Register Pair HL into Register E.
4E38
LD (HL),A 77
Store Register A (00H) to the low byte of the slot's address at Register Pair HL.
4E39
INC HL 23
Increment Register Pair HL to the high byte of the slot's address.
4E3A
LD D,(HL) 56
Fetch the high byte of the slot's address at Register Pair HL into Register D: Register Pair DE = the breakpoint address.
4E3B
LD (HL),A 77
Store Register A (00H) to the high byte of the slot's address at Register Pair HL.
4E3C
INC HL 23
Increment Register Pair HL to the slot's saved byte.
4E3D
LD A,E 7B
Copy Register E (the low byte of the breakpoint address) into Register A.
4E3E
OR D B2
OR Register D (the high byte) into Register A: the Z FLAG is set when the address is 0000H, an empty slot.
4E3F
If the Z FLAG is set (an empty slot), JUMP to 4E48H.
4E41
LD A,(DE) 1A
Fetch the byte at the breakpoint address, Register Pair DE, into Register A.
4E42
CP F7H FE F7
Compare Register A against F7H, the breakpoint byte.
4E44
If the NZ FLAG is set (the byte is no longer F7H), JUMP to 4E48H and leave it.
4E46
LD A,(HL) 7E
Fetch the saved byte of the slot at Register Pair HL into Register A.
4E47
LD (DE),A 12
Store Register A (the original byte) back to the breakpoint address at Register Pair DE.
4E48
INC HL 23
Increment Register Pair HL to the first byte of the next slot (4060H after 405DH-405FH).
4E49
Decrement Register B and LOOP BACK to 4E34H for the second slot until Register B is 00H.
4E4BH - The Command Loop
Each command starts here: the Stack Pointer is set from 4079H, the display is drawn (4ECFH) and a key is read at the start of the bottom line, 3FC0H. G goes to 4F80H; for every other key 4E4BH is pushed as the return address, so each command ends with RET. The keys tested: G, S, ;, -, A, C, D, H, I, M, R, U and X. 51A3H also jumps here when a key that is not a hex digit is typed.
4E4B
LD SP,(4079H) ED 7B 79 40
Load the Stack Pointer from 4079H-407AH: the program's Stack Pointer as saved at the entry or as changed by R SP.
4E4F
GOSUB to 4ECFH to show the registers and memory, or the full screen of memory.
4E52
LD HL,3FC0H 21 C0 3F
Load Register Pair HL with 3FC0H, the start of the bottom line of the screen (line 15).
4E55
LD (4020H),HL 22 20 40
Store Register Pair HL (3FC0H) to 4020H-4021H, the cursor of the display device control block: the command is typed at the start of the bottom line.
4E58
GOSUB to 518AH to wait for a key and show it (ENTER is not shown): Register A = the key.
4E5B
CP 47H FE 47
Compare Register A (the key) against 47H, the command G (go).
4E5D
If the Z FLAG is set (G), JUMP to 4F80H. G runs the program and needs no return address.
4E60
LD HL,4E4BH 21 4B 4E
Point Register Pair HL to 4E4BH, the start of the command loop.
4E63
PUSH HL E5
Save Register Pair HL (4E4BH) to the stack: every command below returns to the command loop with its RET.
4E64
CP 53H FE 53
Compare Register A (the key) against 53H, the command S (the full screen display).
4E66
If the Z FLAG is set (S), JUMP to 4E9AH to store 53H as the screen mode.
4E68
CP 3BH FE 3B
Compare Register A (the key) against 3BH, the semicolon.
4E6A
If the Z FLAG is set (;), JUMP to 4EAEH to move the display address on.
4E6C
CP 2DH FE 2D
Compare Register A (the key) against 2DH, the minus sign.
4E6E
If the Z FLAG is set (the minus sign), JUMP to 4EC6H to move the display address back.
4E70
CP 41H FE 41
Compare Register A (the key) against 41H, the command A (bytes as characters).
4E72
If the Z FLAG is set (A), JUMP to 4ECBH to store 41H as the memory display mode.
4E74
CP 43H FE 43
Compare Register A (the key) against 43H, the command C (step over a CALL).
4E76
If the Z FLAG is set (C), JUMP to 4E82H, the JP Z,505DH below: the Z FLAG is still set, so C goes to 505DH as I does, with Register A = 43H.
4E78
CP 44H FE 44
Compare Register A (the key) against 44H, the command D (the display address).
4E7A
If the Z FLAG is set (D), JUMP to 4EA8H to set the display address.
4E7C
CP 48H FE 48
Compare Register A (the key) against 48H, the command H (bytes in hex).
4E7E
If the Z FLAG is set (H), JUMP to 4ECBH to store 48H as the memory display mode.
4E80
CP 49H FE 49
Compare Register A (the key) against 49H, the command I (step one instruction).
4E82
If the Z FLAG is set (I, or C from 4E76H), JUMP to 505DH to step one instruction; Register A (49H or 43H) tells I from C.
4E85
CP 4DH FE 4D
Compare Register A (the key) against 4DH, the command M (modify memory).
4E87
If the Z FLAG is set (M), JUMP to 4FDBH to set the address to modify or change memory.
4E8A
CP 52H FE 52
Compare Register A (the key) against 52H, the command R (change a register).
4E8C
If the Z FLAG is set (R), JUMP to 5011H to change a saved register.
4E8F
CP 55H FE 55
Compare Register A (the key) against 55H, the command U (update the display).
4E91
If the Z FLAG is set (U), JUMP to 4E9EH to update the display until a key is pressed.
4E93
CP 58H FE 58
Compare Register A (the key) against 58H, the command X (the examine display).
4E95
If the Z FLAG is set (X), JUMP to 4E99H to store 00H as the screen mode.
4E97
RST 28H EF
RST 28H to 400CH and the request handler at 4C31H with Register A = the key (ENTER, a space and a comma included). A code below 80H goes to the address held at 4310H with the return address of RST 28H dropped: from 4C2FH, the address in SYS0/SYS's file, it returns to 4E4BH, the address pushed at 4E63H, and the key is ignored. SYS9/SYS (the EXT parameter of DEBUG) copies its command reader to the top of memory and puts that copy's address at 4310H, passing the keys it does not know on to the address that was there. A code of 80H or more (a key typed with CLEAR held) is taken as a request for a system overlay.
4E98
RET C9
RETURN. No path reaches this byte: the request handler drops the return address of RST 28H, and what the address at 4310H returns to is 4E4BH.
4E99H - X and S: Choose the Display
405EH holds the screen mode: 00H (X) the examine display, the registers and four lines of memory; any other value (S stores 53H) the full screen of memory. Every entry sets 405EH to 00H (4E2FH).
4E99
XOR A AF
X: set Register A to 00H, the value of the examine display.
4E9A
LD (405EH),A 32 5E 40
Store Register A to 405EH, the screen mode: 00H from X, 53H (the key S) from S, which 4ECFH and 4EB4H test.
4E9D
RET C9
RETURN to 4E4BH, the command loop, which draws the display in the new mode.
4E9EH - U: Update the Display
U draws the display again and again until a key is pressed; the key that ends it is not used. Memory that changes while DEBUG waits (the clock of the interrupt tasks) is shown as it changes; the saved registers do not change.
4E9E
GOSUB to the ROM's 002BH to scan the keyboard: Register A = the key pressed, 00H for none.
4EA1
OR A B7
OR Register A (the key) with itself to set the flags: the NZ FLAG for a key.
4EA2
RET NZ C0
If the NZ FLAG is set (a key was pressed), RETURN to 4E4BH; the key is dropped.
4EA3
GOSUB to 4ECFH to draw the registers and memory again with the current contents.
4EA6
JUMP back to 4E9EH to scan the keyboard again.
4EA8H - D: Set the Display Address
D and a hex address store the address at 4063H-4064H, the first byte of the memory lines; D followed at once by a space, a comma or ENTER changes nothing.
4EA8
GOSUB to 51A3H to read a hex number into Register Pair HL: the Z FLAG when no digits were typed.
4EAB
RET Z C8
If the Z FLAG is set (no address), RETURN to 4E4BH with the display address unchanged.
4EAC
JUMP to 4EC2H to store Register Pair HL (the address typed) as the display address.
4EAEH - ; and -: Move the Display
The semicolon moves the display address 4063H-4064H 64 bytes on (the four memory lines of the examine display), the minus sign 64 bytes back; in the full screen display (405EH not 00H) they move it by 256 bytes. The key + is not tested.
4EAE
LD BC,0040H 01 40 00
The semicolon: load Register Pair BC with 0040H, 64 bytes on.
4EB1
LD HL,(4063H) 2A 63 40
Fetch the display address from 4063H-4064H into Register Pair HL.
4EB4
LD A,(405EH) 3A 5E 40
Fetch the screen mode from 405EH into Register A.
4EB7
OR A B7
OR Register A (the screen mode) with itself to set the flags: the Z FLAG for the examine display.
4EB8
If the Z FLAG is set (the examine display), JUMP to 4EC1H to move by Register Pair BC as it is, 0040H or FFC0H.
4EBA
LD C,00H 0E 00
Load Register C with 00H: Register Pair BC = 0000H for the semicolon, FF00H for the minus sign.
4EBC
LD A,B 78
Copy Register B (00H for the semicolon, FFH for the minus sign) into Register A.
4EBD
OR A B7
OR Register A with itself to set the flags: the NZ FLAG for the minus sign.
4EBE
If the NZ FLAG is set (the minus sign: Register Pair BC = FF00H, 256 bytes back), JUMP to 4EC1H.
4EC0
INC B 04
Increment Register B: Register Pair BC = 0100H, 256 bytes on, for the semicolon.
4EC1
ADD HL,BC 09
Add Register Pair BC (the step) to Register Pair HL (the display address).
4EC2
LD (4063H),HL 22 63 40
Store Register Pair HL to 4063H-4064H, the display address (the address typed after D comes here from 4EACH).
4EC5
RET C9
RETURN to 4E4BH, the command loop, which draws the display from the new address.
4EC6
LD BC,FFC0H 01 C0 FF
The minus sign: load Register Pair BC with FFC0H, 64 bytes back.
4EC9
JUMP to 4EB1H to apply the step in Register Pair BC (FFC0H) to the display address.
4ECBH - A and H: Character or Hex
405DH holds the memory display mode: 41H (A) shows each byte as a character, any other value in hex (5144H). Every entry sets 405DH to 00H (4E2FH).
4ECB
LD (405DH),A 32 5D 40
Store Register A, the key (41H for A, 48H for H), to 405DH, the memory display mode.
4ECE
RET C9
RETURN to 4E4BH, the command loop, which draws the display in the new mode.
4ECFH - Show the Registers and Memory
With 405EH = 00H the screen shows, from the top, 12 lines of registers: the 3 characters of the name, =, a space and the value as two bytes in hex, then for AF and AF' the flags as letters (S Z 1 H 1 P N C for bits 7-0, a minus sign for a clear bit) and 44 spaces, for the others => and the 16 bytes at the address the register holds; then four lines of memory from the display address 4063H. Every line fills columns 0-62 of its screen line; lines 0-10 end with a carriage return, line 11 and the memory lines do not, so the first of the 7 spaces in front of each memory line goes to column 63 of the line above. With 405EH not 00H the display is 16 lines of memory (4F45H).
4ECF
LD A,(405EH) 3A 5E 40
Fetch the screen mode from 405EH into Register A.
4ED2
OR A B7
OR Register A (the screen mode) with itself to set the flags: the NZ FLAG for the full screen display.
4ED3
If the NZ FLAG is set (the full screen display), JUMP to 4F45H.
4ED5
LD A,1CH 3E 1C
Load Register A with 1CH, the display code that puts the cursor at the top left of the screen.
4ED7
GOSUB to the ROM's 0033H to send Register A (1CH) to the display.
4EDA
LD HL,4065H 21 65 40
Point Register Pair HL to 4065H, the first word of the save area (Register Pair AF).
4EDD
PUSH HL E5
Save Register Pair HL (the pointer into the save area) to the stack.
4EDE
LD HL,4F54H 21 54 4F
Point Register Pair HL to 4F54H, the table of the register names, 3 characters each.
4EE1
LD B,0CH 06 0C
Load Register B with 0CH, the 12 registers; it counts down to 01H for PC.
4EE3
JUMP to 4EEAH: the first line needs no carriage return in front.
4EE5
LD A,0DH 3E 0D
Load Register A with 0DH, a carriage return, to start the next line.
4EE7
GOSUB to the ROM's 0033H to send Register A (0DH) to the display.
4EEA
GOSUB to 51F6H to show the 3 characters of the name at Register Pair HL; Register Pair HL moves on to the next name.
4EED
EX (SP),HL E3
Exchange Register Pair HL with the top of the stack (the Stack Pointer's word): Register Pair HL = the pointer into the save area, the stack holds the pointer to the next name.
4EEE
LD E,(HL) 5E
Fetch the low byte of the saved register at Register Pair HL into Register E.
4EEF
INC HL 23
Increment Register Pair HL to the high byte of the saved register.
4EF0
LD D,(HL) 56
Fetch the high byte of the saved register at Register Pair HL into Register D: Register Pair DE = the register's value.
4EF1
INC HL 23
Increment Register Pair HL to the next word of the save area.
4EF2
PUSH HL E5
Save Register Pair HL (the pointer to the next word of the save area) to the stack.
4EF3
EX DE,HL EB
Exchange Register Pair DE with Register Pair HL: Register Pair HL = the register's value.
4EF4
LD A,3DH 3E 3D
Load Register A with 3DH, the equals sign that follows the register name.
4EF6
GOSUB to the ROM's 0033H to send Register A (=) to the display.
4EF9
GOSUB to 51F2H to show a space between the equals sign and the value.
4EFC
LD A,H 7C
Copy Register H (the high byte of the register's value) into Register A.
4EFD
GOSUB to 51EFH to show Register A as two hex digits and a space.
4F00
LD A,L 7D
Copy Register L (the low byte of the register's value) into Register A.
4F01
GOSUB to 51EFH to show Register A as two hex digits and a space.
4F04
LD A,B 78
Copy Register B (the count of registers left, 0CH for AF down to 01H for PC) into Register A.
4F05
AND 0BH E6 0B
Mask Register A (the count of registers left) to bits 3, 1 and 0 (0BH).
4F07
CP 08H FE 08
Compare Register A against 08H: equal only for the counts 0CH (AF) and 08H (AF').
4F09
If the NZ FLAG is set (not AF or AF'), JUMP to 4F27H to show the 16 bytes at the address in Register Pair HL.
4F0B
LD C,L 4D
Copy Register L (the flag byte of AF or AF') into Register C.
4F0C
PUSH BC C5
Save Register Pair BC (Register B the count of registers left) to the stack.
4F0D
LD HL,4F78H 21 78 4F
Point Register Pair HL to 4F78H, the 8 flag letters for bits 7-0.
4F10
LD B,08H 06 08
Load Register B with 08H, the 8 flags of the flag byte, bit 7 first.
4F12
SLA C CB 21
Shift Register C (the flag byte) left: the CARRY FLAG = the next flag bit, bit 7 first.
4F14
LD A,(HL) 7E
Fetch the flag's letter at Register Pair HL into Register A.
4F15
If the CARRY FLAG is set (the bit is set), JUMP to 4F19H to show the letter.
4F17
LD A,2DH 3E 2D
Load Register A with 2DH, a minus sign, for a clear bit.
4F19
GOSUB to the ROM's 0033H to send Register A (the letter or the minus sign) to the display.
4F1C
INC HL 23
Increment Register Pair HL to the next flag letter.
4F1D
Decrement Register B and LOOP BACK to 4F12H until the 8 flags are shown.
4F1F
POP BC C1
Restore Register Pair BC from the stack: Register B = the count of registers left.
4F20
LD A,ECH 3E EC
Load Register A with ECH, the space compression code for 44 spaces (ECH less C0H): the line is blanked up to column 62.
4F22
GOSUB to the ROM's 0033H to send Register A (ECH) to the display.
4F25
JUMP to 4F2AH to go on with the next register.
4F27
GOSUB to 5131H to show =>, a space and the 16 bytes from Register Pair HL (the register's value).
4F2A
POP HL E1
Restore Register Pair HL from the stack: the pointer to the next word of the save area.
4F2B
EX (SP),HL E3
Exchange Register Pair HL with the top of the stack (the Stack Pointer's word): Register Pair HL = the pointer to the next name, the stack holds the pointer into the save area.
4F2C
Decrement Register B (the count of registers left) and LOOP BACK to 4EE5H until the 12 registers are shown.
4F2E
POP HL E1
Restore Register Pair HL from the stack: the pointer past the save area (407DH), not used.
4F2F
LD HL,(4063H) 2A 63 40
Fetch the display address from 4063H-4064H into Register Pair HL: the first byte of the four memory lines.
4F32
LD B,04H 06 04
Load Register B with 04H, the four memory lines of the examine display.
4F34
LD A,C7H 3E C7
Load Register A with C7H, the space compression code for 7 spaces: they finish the line before (column 63) and put the address of this line at column 6.
4F36
GOSUB to the ROM's 0033H to send Register A (C7H) to the display.
4F39
GOSUB to 51D4H to show Register Pair HL (the address of the line) as four hex digits.
4F3C
GOSUB to 51F2H to show a space between the address and the bytes of the line.
4F3F
GOSUB to 5131H to show =>, a space and the 16 bytes from Register Pair HL; Register Pair HL ends 16 bytes on.
4F42
Decrement Register B (the lines left) and LOOP BACK to 4F34H until the lines are shown.
4F44
RET C9
RETURN to the caller (the CALL at 4E4FH, 4EA3H or 4FE6H) with the display drawn.
4F45H - The Full Screen of Memory
16 lines of 16 bytes, the 256 bytes of the page that holds the display address (its low byte taken as 00H). The cursor starts at 3BFFH, one place before the screen, so that the 7 spaces in front of the first line put its address at column 6 and the 16 lines of 64 characters end at the last column but one of line 15.
4F45
LD HL,3BFFH 21 FF 3B
Load Register Pair HL with 3BFFH, the place before the first byte of the screen at 3C00H.
4F48
LD (4020H),HL 22 20 40
Store Register Pair HL (3BFFH) to 4020H-4021H, the cursor of the display device control block.
4F4B
LD HL,(4063H) 2A 63 40
Fetch the display address from 4063H-4064H into Register Pair HL.
4F4E
LD L,00H 2E 00
Load Register L with 00H: Register Pair HL = the start of the page of 256 bytes that holds the display address.
4F50
LD B,10H 06 10
Load Register B with 10H, the 16 lines of the full screen display.
4F52
JUMP to 4F34H to show the 16 memory lines from Register Pair HL.
4F54H - Register Names
The names of the 12 saved registers in the order of the save area 4065H-407CH, 3 characters each; the display shows them (4EEAH) and R compares them with the name typed (5029H). Then the letters of the 8 flags.
4F54-4F56
DEFM "AF " 41 46 20
The name AF and a space: the register saved at 4065H-4066H.
4F57-4F59
DEFM "BC " 42 43 20
The name BC and a space: the register saved at 4067H-4068H.
4F5A-4F5C
DEFM "DE " 44 45 20
The name DE and a space: the register saved at 4069H-406AH.
4F5D-4F5F
DEFM "HL " 48 4C 20
The name HL and a space: the register saved at 406BH-406CH.
4F60-4F62
DEFM "AF'" 41 46 27
The name AF and an apostrophe: the alternate register saved at 406DH-406EH.
4F63-4F65
DEFM "BC'" 42 43 27
The name BC and an apostrophe: the alternate register saved at 406FH-4070H.
4F66-4F68
DEFM "DE'" 44 45 27
The name DE and an apostrophe: the alternate register saved at 4071H-4072H.
4F69-4F6B
DEFM "HL'" 48 4C 27
The name HL and an apostrophe: the alternate register saved at 4073H-4074H.
4F6C-4F6E
DEFM "IX " 49 58 20
The name IX and a space: the index register saved at 4075H-4076H.
4F6F-4F71
DEFM "IY " 49 59 20
The name IY and a space: the index register saved at 4077H-4078H.
4F72-4F74
DEFM "SP " 53 50 20
The name SP and a space: the program's stack pointer saved at 4079H-407AH.
4F75-4F77
DEFM "PC " 50 43 20
The name PC and a space: the program counter saved at 407BH-407CH.
4F78-4F7F
DEFM "SZ1H1PNC" 53 5A 31 48 31 50 4E 43
The letters of the flags for bits 7-0 of the flag byte (4F0DH): S sign, Z zero, 1 for bit 5, H half carry, 1 for bit 3, P parity or overflow, N subtract, C carry; a clear bit is shown as a minus sign.
4F80H - G: Go
G, then an optional start address, then up to two breakpoint addresses, separated by spaces or commas, then ENTER. A start address replaces the saved program counter. The first breakpoint goes to the slot 4060H-4062H, the second to 405DH-405FH. Then the BREAK vector is armed to enter DEBUG and the program runs (4FA4H).
4F80
LD B,02H 06 02
Load Register B with 02H, at most two breakpoints.
4F82
LD DE,4062H 11 62 40
Point Register Pair DE to 4062H, the last byte of the slot 4060H-4062H: 4FCAH fills a slot from its last byte down and leaves Register Pair DE at the last byte of the next slot, 405FH.
4F85
GOSUB to 51A3H to read the start address into Register Pair HL: the Z FLAG when none was typed, the CARRY FLAG when ENTER ended it.
4F88
If the Z FLAG is set (no start address), JUMP to 4F8DH and keep the saved program counter.
4F8A
LD (407BH),HL 22 7B 40
Store Register Pair HL (the start address typed) to 407BH-407CH, the program counter the program goes on at.
4F8D
If the CARRY FLAG is set (ENTER ended the field), JUMP to 4F99H to run the program.
4F8F
GOSUB to 51A3H to read a breakpoint address into Register Pair HL: the NZ FLAG when one was typed.
4F92
PUSH AF F5
Save Register Pair AF (the flags of the reading) to the stack.
4F93
If the NZ FLAG is set (an address was typed), GOSUB to 4FCAH to put a breakpoint at Register Pair HL in the slot ending at Register Pair DE.
4F96
POP AF F1
Restore Register Pair AF (the flags of the reading) from the stack.
4F97
Decrement Register B and LOOP BACK to 4F8DH for the next field; after two breakpoint fields go on at 4F99H whatever ended the line.
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) to 4316H-4317H, the address the BREAK key goes to. The address the program had there is not kept.
4F9F
LD A,C3H 3E C3
Load Register A with C3H, the value of 4315H that arms the BREAK key.
4FA1
LD (4315H),A 32 15 43
Store Register A (C3H) to 4315H: BREAK is armed (SYS0/SYS 4568H-4577H), so BREAK during the program enters DEBUG with the interrupted program counter on the stack.
4FA4H - Run the Program
The registers are put back from the save area and the program goes on at the program counter in 407BH. I and C come here from 50B4H without arming BREAK. The 11 words from 4079H (SP) down to 4065H (AF) are pushed below the Stack Pointer and popped into the registers.
4FA4
LD HL,407AH 21 7A 40
Point Register Pair HL to 407AH, the high byte of the saved Stack Pointer.
4FA7
LD B,0BH 06 0B
Load Register B with 0BH, the 11 words SP, IY, IX, HL', DE', BC', AF', HL, DE, BC and AF.
4FA9
LD D,(HL) 56
Fetch the high byte of the saved word at Register Pair HL into Register D.
4FAA
DEC HL 2B
Decrement Register Pair HL to the low byte of the saved word.
4FAB
LD E,(HL) 5E
Fetch the low byte of the saved word at Register Pair HL into Register E: Register Pair DE = the saved word.
4FAC
DEC HL 2B
Decrement Register Pair HL to the high byte of the word before.
4FAD
PUSH DE D5
Save Register Pair DE (the saved word) to the stack; Register Pair AF's word, pushed last, comes off first.
4FAE
Decrement Register B and LOOP BACK to 4FA9H until the 11 words are on the stack.
4FB0
POP AF F1
Restore Register Pair AF from the stack: the value saved at 4065H-4066H.
4FB1
POP BC C1
Restore Register Pair BC from the stack: the value saved at 4067H-4068H.
4FB2
POP DE D1
Restore Register Pair DE from the stack: the value saved at 4069H-406AH.
4FB3
POP HL E1
Restore Register Pair HL from the stack: the value saved at 406BH-406CH (loaded again at 4FC6H).
4FB4
EX AF,AF' 08
Exchange Register Pair AF with the alternate Register Pair AF': the value just put in Register Pair AF goes to the alternate set.
4FB5
EXX D9
Exchange Register Pairs BC, DE and HL with the alternate set: the values just put in them go to the alternate set.
4FB6
POP AF F1
Restore Register Pair AF from the stack: the value saved at 406DH-406EH, the program's AF'.
4FB7
POP BC C1
Restore Register Pair BC from the stack: the value saved at 406FH-4070H, the program's BC'.
4FB8
POP DE D1
Restore Register Pair DE from the stack: the value saved at 4071H-4072H, the program's DE'.
4FB9
POP HL E1
Restore Register Pair HL from the stack: the value saved at 4073H-4074H, the program's HL'.
4FBA
EX AF,AF' 08
Exchange Register Pair AF with the alternate Register Pair AF': Register Pair AF = the program's AF, the alternate AF' = the program's AF'.
4FBB
EXX D9
Exchange Register Pairs BC, DE and HL with the alternate set: Register Pairs BC, DE and HL are the program's, the alternate set holds the program's BC', DE' and HL'.
4FBC
POP IX DD E1
Restore Index Register IX from the stack: the value saved at 4075H-4076H.
4FBE
POP IY FD E1
Restore Index Register IY from the stack: the value saved at 4077H-4078H.
4FC0
POP HL E1
Restore Register Pair HL from the stack: the Stack Pointer saved at 4079H-407AH.
4FC1
LD SP,HL F9
Load the Stack Pointer from Register Pair HL: the program's stack.
4FC2
LD HL,(407BH) 2A 7B 40
Fetch the program counter from 407BH-407CH into Register Pair HL.
4FC5
PUSH HL E5
Save Register Pair HL (the program counter) to the stack, in the 2 bytes below the program's Stack Pointer.
4FC6
LD HL,(406BH) 2A 6B 40
Fetch the program's Register Pair HL from 406BH-406CH.
4FC9
RET C9
RETURN, which takes the program counter off the stack and jumps to it: the program goes on with every register as saved and the Stack Pointer at its saved value.
4FCAH - Set a Breakpoint
Register Pair HL = the address, Register Pair DE = the last byte of a slot (4062H or 405FH). The byte at the address is saved in the slot and replaced by F7H (RST 30H); then the address is stored below it, high byte first, and Register Pair DE returns 3 bytes lower, at the last byte of the next slot. When the byte does not keep the F7H (the ROM, or no memory there) the command ends at 4E2FH without running the program.
4FCA
LD A,(HL) 7E
Fetch the byte at the breakpoint address, Register Pair HL, into Register A.
4FCB
LD (DE),A 12
Store Register A (the original byte) to the slot's last byte at Register Pair DE.
4FCC
DEC DE 1B
Decrement Register Pair DE to the high byte of the slot's address.
4FCD
LD A,F7H 3E F7
Load Register A with F7H, RST 30H, the breakpoint byte.
4FCF
LD (HL),A 77
Store Register A (F7H) to the breakpoint address at Register Pair HL.
4FD0
CP (HL) BE
Compare Register A (F7H) against the byte now at Register Pair HL: the NZ FLAG when the memory did not take it.
4FD1
If the NZ FLAG is set, JUMP to 4E2FH, which takes out the breakpoints set so far and goes back to the command loop: the program is not run.
4FD4
LD A,H 7C
Copy Register H (the high byte of the breakpoint address) into Register A.
4FD5
LD (DE),A 12
Store Register A (the high byte) to the slot at Register Pair DE.
4FD6
DEC DE 1B
Decrement Register Pair DE to the low byte of the slot's address.
4FD7
LD A,L 7D
Copy Register L (the low byte of the breakpoint address) into Register A.
4FD8
LD (DE),A 12
Store Register A (the low byte) to the slot at Register Pair DE.
4FD9
DEC DE 1B
Decrement Register Pair DE: the last byte of the next slot (405FH after the slot 4060H-4062H).
4FDA
RET C9
RETURN to the caller with Register Pair HL unchanged.
4FDBH - M: Modify Memory
M sets the address to modify, 4060H-4061H, which the memory lines mark (5165H). M, an optional address and ENTER only sets it. M, an optional address and a space or a comma starts the change loop: the display is drawn again, the address is shown at 3F40H (line 13) and its byte at 3F80H (line 14) with a minus sign; a hex value typed after it is stored, a space or a comma goes on to the next byte, ENTER ends.
4FDB
LD HL,(4060H) 2A 60 40
Fetch the address to modify from 4060H-4061H into Register Pair HL, kept when no address is typed.
4FDE
GOSUB to 51A3H to read a hex address into Register Pair HL (unchanged when no digits are typed): the CARRY FLAG when ENTER ended it.
4FE1
LD (4060H),HL 22 60 40
Store Register Pair HL to 4060H-4061H, the address to modify.
4FE4
RET C D8
If the CARRY FLAG is set (ENTER), RETURN to 4E4BH, the command loop.
4FE5
PUSH HL E5
Save Register Pair HL (the address to modify) to the stack, for 5005H.
4FE6
GOSUB to 4ECFH to draw the display again, with the mark on the new address.
4FE9
LD HL,3F40H 21 40 3F
Load Register Pair HL with 3F40H, the start of line 13 of the screen.
4FEC
LD (4020H),HL 22 20 40
Store Register Pair HL (3F40H) to 4020H-4021H, the cursor of the display device control block.
4FEF
LD HL,(4060H) 2A 60 40
Fetch the address to modify from 4060H-4061H into Register Pair HL.
4FF2
GOSUB to 51D4H to show Register Pair HL (the address to modify) as four hex digits.
4FF5
PUSH HL E5
Save Register Pair HL (the address to modify) to the stack.
4FF6
LD HL,3F80H 21 80 3F
Load Register Pair HL with 3F80H, the start of line 14 of the screen.
4FF9
LD (4020H),HL 22 20 40
Store Register Pair HL (3F80H) to 4020H-4021H, the cursor of the display device control block.
4FFC
POP HL E1
Restore Register Pair HL from the stack: the address to modify.
4FFD
GOSUB to 51D0H to show the byte at Register Pair HL as two hex digits; Register Pair HL moves on by one.
5000
LD A,2DH 3E 2D
Load Register A with 2DH, a minus sign, after which the new value is typed.
5002
GOSUB to the ROM's 0033H to send Register A (the minus sign) to the display.
5005
POP DE D1
Restore Register Pair DE from the stack: the address to modify, pushed at 4FE5H.
5006
GOSUB to 51A3H to read the new value into Register Pair HL: the Z FLAG when none was typed, the CARRY FLAG when ENTER ended it.
5009
EX DE,HL EB
Exchange Register Pair DE with Register Pair HL: Register Pair HL = the address to modify, Register Pair DE = the value typed. EX does not change the flags.
500A
If the Z FLAG is set (no value typed), JUMP to 500DH and leave the byte as it is.
500C
LD (HL),E 73
Store Register E (the low byte of the value typed) to the byte at Register Pair HL.
500D
RET C D8
If the CARRY FLAG is set (ENTER), RETURN to 4E4BH, the command loop; 4060H-4061H keeps the address of the byte just shown.
500E
INC HL 23
Increment Register Pair HL to the next byte, the next address to modify.
500F
JUMP to 4FE1H to store Register Pair HL as the address to modify and show the next byte.
5011H - R: Change a Register
R, the name of a register as the display shows it (two letters, then an apostrophe for the alternate ones), a space or a comma, and a hex value: the value replaces the saved register in 4065H-407CH. The line is blanked from the cursor on before the value is typed. A name not in the table, a fourth character or ENTER before the value changes nothing.
5011
GOSUB to 518AH to wait for the first letter of the name: Register A = the key.
5014
RET Z C8
If the Z FLAG is set (a space, a comma or ENTER), RETURN to 4E4BH.
5015
LD C,A 4F
Copy Register A (the first letter) into Register C.
5016
GOSUB to 518AH to wait for the second letter of the name: Register A = the key.
5019
RET Z C8
If the Z FLAG is set (a space, a comma or ENTER), RETURN to 4E4BH.
501A
LD D,A 57
Copy Register A (the second letter) into Register D.
501B
LD E,20H 1E 20
Load Register E with 20H, a space: the third character of every name without an apostrophe.
501D
GOSUB to 518AH to wait for the next key: Register A = the key.
5020
RET C D8
If the CARRY FLAG is set (ENTER), RETURN to 4E4BH: no value follows.
5021
If the Z FLAG is set (a space or a comma), JUMP to 5029H with Register E = 20H.
5023
LD E,A 5F
Copy Register A (the third character, the apostrophe of an alternate register) into Register E.
5024
GOSUB to 518AH to wait for the key after it: Register A = the key.
5027
RET NZ C0
If the NZ FLAG is set (not a space, a comma or ENTER), RETURN to 4E4BH: no name has four characters.
5028
RET C D8
If the CARRY FLAG is set (ENTER), RETURN to 4E4BH: no value follows.
5029
LD HL,4F54H 21 54 4F
Point Register Pair HL to 4F54H, the table of the register names.
502C
LD B,0CH 06 0C
Load Register B with 0CH, the 12 names; it counts down to 01H for PC.
502E
LD A,(HL) 7E
Fetch the first character of the entry at Register Pair HL into Register A.
502F
CP C B9
Compare Register A against Register C (the first letter typed).
5030
If the Z FLAG is set, JUMP to 5038H to compare the second character.
5032
INC HL 23
Increment Register Pair HL past the entry's first character.
5033
INC HL 23
Increment Register Pair HL past the entry's second character.
5034
INC HL 23
Increment Register Pair HL past the entry's third character, to the next entry.
5035
Decrement Register B and LOOP BACK to 502EH until the 12 names are tried.
5037
RET C9
RETURN to 4E4BH, the command loop: no register has the name typed.
5038
INC HL 23
Increment Register Pair HL to the entry's second character.
5039
LD A,(HL) 7E
Fetch the entry's second character at Register Pair HL into Register A.
503A
CP D BA
Compare Register A against Register D (the second letter typed).
503B
If the NZ FLAG is set, JUMP to 5033H to go on to the next entry.
503D
INC HL 23
Increment Register Pair HL to the entry's third character.
503E
LD A,(HL) 7E
Fetch the entry's third character at Register Pair HL into Register A.
503F
CP E BB
Compare Register A against Register E (the third character typed, or 20H).
5040
If the NZ FLAG is set, JUMP to 5034H to go on to the next entry.
5042
LD A,18H 3E 18
Load Register A with 18H (24), twice the 12 entries.
5044
SUB B 90
SUBtract Register B (the entries left, 0CH for AF down to 01H for PC) from Register A.
5045
SUB B 90
SUBtract Register B again: Register A = 2 times (12 less the entries left), the offset of the register's word in the save area.
5046
LD C,A 4F
Copy Register A (the offset) into Register C.
5047
LD B,00H 06 00
Load Register B with 00H: Register Pair BC = the offset.
5049
LD HL,4065H 21 65 40
Point Register Pair HL to 4065H, the save area.
504C
ADD HL,BC 09
Add Register Pair BC (the offset) to Register Pair HL: Register Pair HL = the saved register's word.
504D
PUSH HL E5
Save Register Pair HL (the saved register's word) to the stack.
504E
LD A,1EH 3E 1E
Load Register A with 1EH, the display code that blanks the line from the cursor to its end.
5050
GOSUB to the ROM's 0033H to send Register A (1EH) to the display.
5053
POP DE D1
Restore Register Pair DE from the stack: the saved register's word.
5054
GOSUB to 51A3H to read the new value into Register Pair HL: the Z FLAG when none was typed.
5057
RET Z C8
If the Z FLAG is set (no value), RETURN to 4E4BH and leave the register.
5058
EX DE,HL EB
Exchange Register Pair DE with Register Pair HL: Register Pair HL = the saved register's word, Register Pair DE = the value typed.
5059
LD (HL),E 73
Store Register E (the low byte of the value) to the saved register's word at Register Pair HL.
505A
INC HL 23
Increment Register Pair HL to the high byte of the saved register's word.
505B
LD (HL),D 72
Store Register D (the high byte of the value) to Register Pair HL.
505C
RET C9
RETURN to 4E4BH, the command loop, which shows the register with its new value.
505DH - I and C: Step One Instruction
The instruction at the program counter (407BH) is looked up to find its length and the branch it makes: in the table at 5115H by the byte after a DD or FD prefix, at 510EH by the byte after an ED prefix, at 50E0H by the first byte of any other instruction. A breakpoint goes on the next instruction (slot 4060H-4062H) and, for a branch, a second one on its target (slot 405DH-405FH); then the program runs (4FA4H). For a CALL, I puts the second breakpoint on the subroutine and C does not, so that the whole subroutine runs.
505D
PUSH AF F5
Save Register Pair AF (Register A the key, 49H for I or 43H for C) to the stack, for 50AFH.
505E
LD DE,(407BH) ED 5B 7B 40
Fetch the program counter from 407BH-407CH into Register Pair DE: the address of the instruction.
5062
LD A,(DE) 1A
Fetch the first byte of the instruction at Register Pair DE into Register A.
5063
LD HL,5115H 21 15 51
Point Register Pair HL to 5115H, the table for the instructions with a DD or FD prefix.
5066
CP DDH FE DD
Compare Register A (the first byte) against DDH, the prefix of the Index Register IX instructions.
5068
If the Z FLAG is set (DDH), JUMP to 5078H to look up the byte after the prefix.
506A
CP FDH FE FD
Compare Register A (the first byte) against FDH, the prefix of the Index Register IY instructions.
506C
If the Z FLAG is set (FDH), JUMP to 5078H to look up the byte after the prefix.
506E
LD HL,50E0H 21 E0 50
Point Register Pair HL to 50E0H, the table for the instructions with no prefix. LD does not change the flags.
5071
CP EDH FE ED
Compare Register A (the first byte) against EDH, the prefix of the extended instructions.
5073
If the NZ FLAG is set (no ED prefix), JUMP to 507BH to look up the first byte.
5075
LD HL,510EH 21 0E 51
Point Register Pair HL to 510EH, the table for the instructions with an ED prefix.
5078
INC DE 13
Increment Register Pair DE to the byte after the prefix.
5079
LD A,(DE) 1A
Fetch the byte after the prefix at Register Pair DE into Register A.
507A
DEC DE 1B
Decrement Register Pair DE back to the first byte of the instruction.
507B
LD C,A 4F
Copy Register A (the byte to look up) into Register C.
507C
LD A,(HL) 7E
Fetch the mask of the table entry at Register Pair HL into Register A.
507D
AND C A1
AND Register C (the byte to look up) into Register A (the mask).
507E
INC HL 23
Increment Register Pair HL to the entry's value.
507F
CP (HL) BE
Compare Register A (the masked byte) against the entry's value at Register Pair HL.
5080
INC HL 23
Increment Register Pair HL to the entry's kind byte. INC of a register pair does not change the flags.
5081
If the Z FLAG is set (the entry matches), JUMP to 5089H to take its kind byte.
5083
INC HL 23
Increment Register Pair HL to the mask of the next entry.
5084
LD A,(HL) 7E
Fetch the byte at Register Pair HL (the next mask, or the end byte) into Register A.
5085
CP 05H FE 05
Compare Register A against 05H: a byte below 05H ends the table and is itself the kind byte of every instruction not listed.
5087
If the NC FLAG is set (a mask), JUMP back to 507CH to try the next entry.
5089
LD A,(HL) 7E
Fetch the kind byte at Register Pair HL into Register A: bits 3-0 the length of the instruction, bits 7-4 the branch (00H none, 10H JP (HL), 20H JP (IX) or JP (IY), 30H a relative jump, 40H JP, 50H a return, 60H CALL).
508A
LD B,A 47
Copy Register A (the kind byte) into Register B.
508B
AND 0FH E6 0F
Mask Register A to bits 3-0: the length of the instruction.
508D
LD L,A 6F
Copy Register A (the length) into Register L.
508E
LD H,00H 26 00
Load Register H with 00H: Register Pair HL = the length.
5090
ADD HL,DE 19
Add Register Pair DE (the address of the instruction) to Register Pair HL: Register Pair HL = the address of the next instruction.
5091
PUSH DE D5
Save Register Pair DE (the address of the instruction) to the stack.
5092
LD DE,4062H 11 62 40
Point Register Pair DE to 4062H, the last byte of the slot 4060H-4062H.
5095
GOSUB to 4FCAH to put a breakpoint on the next instruction at Register Pair HL; Register Pair DE returns 405FH, the last byte of the slot 405DH-405FH.
5098
POP HL E1
Restore Register Pair HL from the stack: the address of the instruction.
5099
LD A,B 78
Copy Register B (the kind byte) into Register A.
509A
AND F0H E6 F0
Mask Register A (the kind byte) to bits 7-4: the branch the instruction makes.
509C
If the Z FLAG is set (no branch), JUMP to 50B4H to run the program.
509E
INC HL 23
Increment Register Pair HL to the second byte of the instruction: the operand of a JP, a CALL or a relative jump.
509F
CP 20H FE 20
Compare Register A (the branch) against 20H, the branch of JP (IX) and JP (IY).
50A1
If the CARRY FLAG is set (10H, JP (HL)), JUMP to 50D8H: the target is the program's Register Pair HL.
50A3
If the Z FLAG is set (20H, JP (IX) or JP (IY)), JUMP to 50CCH.
50A5
CP 40H FE 40
Compare Register A (the branch) against 40H, the branch of JP.
50A7
If the CARRY FLAG is set (30H, a relative jump), JUMP to 50C0H to add the displacement.
50A9
If the Z FLAG is set (40H, JP), JUMP to 50BAH: the target is the word after the first byte.
50AB
CP 60H FE 60
Compare Register A (the branch) against 60H, the branch of CALL.
50AD
If the CARRY FLAG is set (50H, a return), JUMP to 50B7H: the target is the word on top of the program's stack.
50AF
POP AF F1
Restore Register Pair AF from the stack (60H, a CALL): Register A = the key, 49H for I or 43H for C.
50B0
CP 49H FE 49
Compare Register A (the key) against 49H, the command I, which steps into a subroutine.
50B2
If the Z FLAG is set (I), JUMP to 50BAH to put the second breakpoint on the subroutine at the word after the first byte.
50B4
JUMP to 4FA4H to put the registers back and run the program; BREAK is not armed. The word pushed at 505DH may still be on the stack: 4FC1H sets the Stack Pointer from the saved value.
50B7
LD HL,(4079H) 2A 79 40
Fetch the program's Stack Pointer from 4079H-407AH into Register Pair HL: a return takes its address from the top of the program's stack.
50BA
LD A,(HL) 7E
Fetch the low byte of the target at Register Pair HL (the operand of JP or CALL, or the top of the program's stack) into Register A.
50BB
INC HL 23
Increment Register Pair HL to the high byte of the target.
50BC
LD H,(HL) 66
Fetch the high byte of the target at Register Pair HL into Register H.
50BD
LD L,A 6F
Copy Register A (the low byte) into Register L: Register Pair HL = the target.
50BE
JUMP to 50DBH to put the second breakpoint there.
50C0
LD C,(HL) 4E
Fetch the displacement of the relative jump at Register Pair HL into Register C.
50C1
XOR A AF
Set Register A to 00H, the high byte of a displacement forward.
50C2
BIT 7,C CB 79
Test bit 7 of Register C, the sign of the displacement.
50C4
If the Z FLAG is set (a jump forward), JUMP to 50C7H with Register A = 00H.
50C6
CPL 2F
Complement Register A to FFH, the high byte of a displacement back.
50C7
LD B,A 47
Copy Register A into Register B: Register Pair BC = the displacement as 16 bits.
50C8
INC HL 23
Increment Register Pair HL past the displacement: the address of the next instruction, which the displacement counts from.
50C9
ADD HL,BC 09
Add Register Pair BC (the displacement) to Register Pair HL: the target of the jump.
50CA
JUMP to 50DBH to put the second breakpoint there.
50CC
LD HL,(4075H) 2A 75 40
Fetch the program's Index Register IX from 4075H-4076H into Register Pair HL.
50CF
BIT 5,C CB 69
Test bit 5 of Register C, the byte after the prefix: E9H for both JP (IX) and JP (IY), with bit 5 set, so the test never tells the two apart.
50D1
If the Z FLAG is set (never, since Register C = E9H), JUMP to 50DBH with the value of Index Register IX.
50D3
LD HL,(4077H) 2A 77 40
Fetch the program's Index Register IY from 4077H-4078H into Register Pair HL: the target used for JP (IX) as well as JP (IY).
50D6
JUMP to 50DBH to put the second breakpoint there.
50D8
LD HL,(406BH) 2A 6B 40
Fetch the program's Register Pair HL from 406BH-406CH into Register Pair HL, the target of JP (HL).
50DB
GOSUB to 4FCAH to put the second breakpoint at the target in Register Pair HL, in the slot 405DH-405FH whose last byte is at Register Pair DE.
50DE
JUMP to 50B4H to run the program with the two breakpoints in place.
50E0H - Instruction Table: No Prefix
Three bytes an entry: a mask, a value and a kind byte; the first byte of the instruction ANDed with the mask equals the value. The kind byte: bits 3-0 the length, bits 7-4 the branch (505DH). The table ends at 510DH.
50E0-50E2
DEFB C7H,C0H,51H C7 C0 51
Mask C7H, value C0H: RET with a condition (C0H, C8H, D0H, D8H, E0H, E8H, F0H, F8H); kind 51H, length 1, branch 50H, the return address on top of the program's stack.
50E3-50E5
DEFB FFH,C9H,51H FF C9 51
Mask FFH, value C9H: RET; kind 51H, length 1, branch 50H, the return address on top of the program's stack.
50E6-50E8
DEFB FFH,E9H,11H FF E9 11
Mask FFH, value E9H: JP (HL); kind 11H, length 1, branch 10H, the target in the program's Register Pair HL.
50E9-50EB
DEFB CFH,01H,03H CF 01 03
Mask CFH, value 01H: LD BC, LD DE, LD HL or LD SP with a 16 bit value (01H, 11H, 21H, 31H); kind 03H, length 3, no branch.
50EC-50EE
DEFB E7H,22H,03H E7 22 03
Mask E7H, value 22H: LD (nn),HL 22H, LD HL,(nn) 2AH, LD (nn),A 32H and LD A,(nn) 3AH; kind 03H, length 3, no branch.
50EF-50F1
DEFB C7H,C2H,43H C7 C2 43
Mask C7H, value C2H: JP with a condition (C2H, CAH, D2H, DAH, E2H, EAH, F2H, FAH); kind 43H, length 3, branch 40H, the target in bytes 2 and 3.
50F2-50F4
DEFB FFH,C3H,43H FF C3 43
Mask FFH, value C3H: JP; kind 43H, length 3, branch 40H, the target in bytes 2 and 3.
50F5-50F7
DEFB C7H,C4H,63H C7 C4 63
Mask C7H, value C4H: CALL with a condition (C4H, CCH, D4H, DCH, E4H, ECH, F4H, FCH); kind 63H, length 3, branch 60H, the subroutine in bytes 2 and 3.
50F8-50FA
DEFB FFH,CDH,63H FF CD 63
Mask FFH, value CDH: CALL; kind 63H, length 3, branch 60H, the subroutine in bytes 2 and 3.
50FB-50FD
DEFB C7H,06H,02H C7 06 02
Mask C7H, value 06H: LD of a register or of (HL) with a byte (06H, 0EH, 16H, 1EH, 26H, 2EH, 36H, 3EH); kind 02H, length 2, no branch.
50FE-5100
DEFB F7H,D3H,02H F7 D3 02
Mask F7H, value D3H: OUT (n),A D3H and IN A,(n) DBH; kind 02H, length 2, no branch.
5101-5103
DEFB C7H,C6H,02H C7 C6 02
Mask C7H, value C6H: the arithmetic and logic with a byte (ADD C6H, ADC CEH, SUB D6H, SBC DEH, AND E6H, XOR EEH, OR F6H, CP FEH); kind 02H, length 2, no branch.
5104-5106
DEFB FFH,CBH,02H FF CB 02
Mask FFH, value CBH: the CB prefix, the shifts and the bit instructions; kind 02H, length 2, no branch.
5107-5109
DEFB F7H,10H,32H F7 10 32
Mask F7H, value 10H: DJNZ 10H and JR 18H; kind 32H, length 2, branch 30H, a displacement in byte 2.
510A-510C
DEFB E7H,20H,32H E7 20 32
Mask E7H, value 20H: JR NZ 20H, JR Z 28H, JR NC 30H and JR C 38H; kind 32H, length 2, branch 30H, a displacement in byte 2.
510D
DEFB 01H 01
The end of the table (a byte below 05H) and the kind of every other instruction: length 1, no branch.
510EH - Instruction Table: ED Prefix
The entries are tested against the byte after the ED prefix; the table ends at 5114H.
510E-5110
DEFB C7H,43H,04H C7 43 04
Mask C7H, value 43H: LD (nn) with a register pair and LD of a register pair from (nn) (ED 43H, 4BH, 53H, 5BH, 63H, 6BH, 73H, 7BH); kind 04H, length 4, no branch.
5111-5113
DEFB F7H,45H,52H F7 45 52
Mask F7H, value 45H: RETN (ED 45H) and RETI (ED 4DH); kind 52H, length 2, branch 50H, the return address on top of the program's stack.
5114
DEFB 02H 02
The end of the table and the kind of every other ED instruction: length 2, no branch.
5115H - Instruction Table: DD and FD Prefixes
The entries are tested against the byte after the DD or FD prefix; the table ends at 5130H.
5115-5117
DEFB FEH,34H,03H FE 34 03
Mask FEH, value 34H: INC (IX+d) 34H and DEC (IX+d) 35H, or with IY; kind 03H, length 3, no branch.
5118-511A
DEFB C0H,40H,03H C0 40 03
Mask C0H, value 40H: 40H-7FH, the loads of a register from (IX+d) or (IY+d) and of (IX+d) or (IY+d) from a register; kind 03H, length 3, no branch.
511B-511D
DEFB C0H,80H,03H C0 80 03
Mask C0H, value 80H: 80H-BFH, the arithmetic and logic with (IX+d) or (IY+d); kind 03H, length 3, no branch.
511E-5120
DEFB FFH,21H,04H FF 21 04
Mask FFH, value 21H: LD IX or LD IY with a 16 bit value; kind 04H, length 4, no branch.
5121-5123
DEFB FFH,22H,04H FF 22 04
Mask FFH, value 22H: LD (nn),IX or LD (nn),IY; kind 04H, length 4, no branch.
5124-5126
DEFB FFH,2AH,04H FF 2A 04
Mask FFH, value 2AH: LD IX,(nn) or LD IY,(nn); kind 04H, length 4, no branch.
5127-5129
DEFB FFH,36H,04H FF 36 04
Mask FFH, value 36H: LD (IX+d) or LD (IY+d) with a byte; kind 04H, length 4, no branch.
512A-512C
DEFB FFH,CBH,04H FF CB 04
Mask FFH, value CBH: the shifts and bit instructions on (IX+d) or (IY+d); kind 04H, length 4, no branch.
512D-512F
DEFB FFH,E9H,22H FF E9 22
Mask FFH, value E9H: JP (IX) or JP (IY); kind 22H, length 2, branch 20H, the target in the program's index register (50CCH).
5130
DEFB 02H 02
The end of the table and the kind of every other DD or FD instruction (PUSH, POP, ADD, INC, DEC, EX (SP) and LD SP with an index register): length 2, no branch.
5131H - One Line of Memory
Register Pair HL = the first of 16 bytes. Shows => and a space, then for each byte a mark (5165H) and the byte: in hex as two digits, or in the A mode (405DH = 41H) as a space and its character, a dot for codes below 20H and from C0H up. Register Pair HL ends 16 bytes on; Register Pair BC is kept.
5131
PUSH BC C5
Save Register Pair BC (Register B the caller's count) to the stack.
5132
LD A,3DH 3E 3D
Load Register A with 3DH, the equals sign at the start of the memory line.
5134
GOSUB to the ROM's 0033H to send Register A (=) to the display.
5137
LD A,3EH 3E 3E
Load Register A with 3EH, the greater than sign.
5139
GOSUB to the ROM's 0033H to send Register A (>) to the display.
513C
GOSUB to 51F2H to show a space after the equals sign and the greater than sign.
513F
LD B,10H 06 10
Load Register B with 10H, the 16 bytes of the line; it counts down to 01H.
5141
GOSUB to 5165H to show the mark in front of the byte at Register Pair HL, and the extra space in front of the ninth byte.
5144
LD A,(405DH) 3A 5D 40
Fetch the memory display mode from 405DH into Register A.
5147
CP 41H FE 41
Compare Register A (the mode) against 41H, the A mode.
5149
If the NZ FLAG is set (the hex mode), JUMP to 515EH, where the NZ FLAG makes the CALL show the byte in hex.
514B
GOSUB to 51F2H to show a space in front of the character.
514E
LD A,(HL) 7E
Fetch the byte at Register Pair HL into Register A.
514F
CP 20H FE 20
Compare Register A (the byte) against 20H, the first code that is not a control code.
5151
If the CARRY FLAG is set (a control code below 20H), JUMP to 5157H to show a dot.
5153
CP C0H FE C0
Compare Register A (the byte) against C0H, the first space compression code.
5155
If the CARRY FLAG is set (20H-BFH: a character or a graphics character), JUMP to 5159H to show it.
5157
LD A,2EH 3E 2E
Load Register A with 2EH, a dot, in place of a control code or a code from C0H up (a space compression code).
5159
GOSUB to the ROM's 0033H to send Register A (the character or the dot) to the display.
515C
INC HL 23
Increment Register Pair HL to the next byte of the memory line.
515D
XOR A AF
Set Register A to 00H and the Z FLAG, so that the CALL below is passed over.
515E
If the NZ FLAG is set (the hex mode), GOSUB to 51D0H to show the byte at Register Pair HL as two hex digits and move Register Pair HL on.
5161
Decrement Register B and LOOP BACK to 5141H until the 16 bytes are shown.
5163
POP BC C1
Restore Register Pair BC (the caller's count) from the stack.
5164
RET C9
RETURN to the caller with Register Pair HL 16 bytes on.
5165H - The Mark in Front of a Byte
Register Pair HL = the byte to be shown, Register B = the bytes left in the line. In front of the byte at the M address 4060H the graphics character AAH (the right half of the cell lit), in front of the byte after it 95H (the left half lit), so that the two frame the M byte; a space in front of every other byte. When Register B = 08H (the ninth byte) a space more is shown, after 95H or before the mark.
5165
LD DE,(4060H) ED 5B 60 40
Fetch the M address from 4060H-4061H into Register Pair DE.
5169
INC DE 13
Increment Register Pair DE: the address of the byte after the M byte.
516A
PUSH HL E5
Save Register Pair HL (the byte to be shown) to the stack.
516B
XOR A AF
Set Register A to 00H and clear the CARRY FLAG, for the SBC below.
516C
SBC HL,DE ED 52
SUBtract Register Pair DE (the byte after the M byte) from Register Pair HL: the Z FLAG when the byte to be shown is the one after the M byte.
516E
LD A,95H 3E 95
Load Register A with 95H, the graphics character with the left half of the cell lit, the mark after the M byte. LD does not change the flags.
5170
If the Z FLAG is set (the byte after the M byte), JUMP to 5180H to show 95H.
5172
GOSUB to 5184H to show the extra space when Register B = 08H.
5175
INC HL 23
Increment Register Pair HL (the difference): 0000H when the byte to be shown is the M byte.
5176
LD A,L 7D
Copy Register L (the low byte of the difference) into Register A.
5177
OR H B4
OR Register H (the high byte of the difference) into Register A: the Z FLAG when the byte to be shown is the M byte.
5178
POP HL E1
Restore Register Pair HL from the stack: the byte to be shown.
5179
LD A,AAH 3E AA
Load Register A with AAH, the graphics character with the right half of the cell lit, the mark in front of the M byte. LD does not change the flags.
517B
If the Z FLAG is set (the M byte), JUMP to the ROM's 0033H to send Register A (AAH) to the display; its RETURN goes back to the caller of 5165H.
517E
JUMP to 5188H to show a space in front of a byte that is not the M byte.
5180
GOSUB to the ROM's 0033H to send Register A (95H) to the display.
5183
POP HL E1
Restore Register Pair HL from the stack: the byte to be shown.
5184
LD A,B 78
Copy Register B (the bytes left in the line, 10H down to 01H) into Register A.
5185
CP 08H FE 08
Compare Register A against 08H: equal for the ninth byte of the line.
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; its RETURN goes back to the caller.
518AH - Read a Key
Waits for a key, passes over the codes below 20H other than ENTER and shows the key (ENTER is not shown). Returns Register A = the key and, for ENTER (0DH, not shown), the Z FLAG and the CARRY FLAG; for a comma or a space the Z FLAG and NO CARRY; for any other key the NZ FLAG and NO CARRY. Register Pair DE is kept. SYS9/SYS calls it too.
518A
PUSH DE D5
Save Register Pair DE (the caller's) to the stack.
518B
GOSUB to the ROM's 0049H to wait for a key: Register A = its code.
518E
CP 0DH FE 0D
Compare Register A (the key) against 0DH, ENTER.
5190
If the Z FLAG is set (ENTER), JUMP to 51A0H to return without showing it.
5192
CP 20H FE 20
Compare Register A (the key) against 20H, the first code that is shown.
5194
If the CARRY FLAG is set (a code below 20H, such as BREAK, CLEAR or the left arrow), JUMP back to 518BH and pass over it.
5196
GOSUB to the ROM's 0033H to send Register A (the key) to the display.
5199
POP DE D1
Restore Register Pair DE (the caller's) from the stack.
519A
CP 2CH FE 2C
Compare Register A (the key) against 2CH, a comma.
519C
RET Z C8
If the Z FLAG is set (a comma), RETURN with the Z FLAG and NO CARRY.
519D
CP 20H FE 20
Compare Register A (the key) against 20H, a space.
519F
RET C9
RETURN with the Z FLAG for a space and the NZ FLAG for any other key; the CARRY FLAG is clear, since the key is 20H or more.
51A0
POP DE D1
Restore Register Pair DE (the caller's) from the stack.
51A1
SCF 37
Set the CARRY FLAG; the Z FLAG of the comparison with 0DH stays set.
51A2
RET C9
RETURN with Register A = 0DH, the Z FLAG and the CARRY FLAG.
51A3H - Read a Hex Number
Reads hex digits (0-9, A-F) into Register Pair HL until a space, a comma or ENTER; only the last four digits count. With no digits before the ending key it returns the Z FLAG and Register Pair HL unchanged; with digits, the NZ FLAG and Register Pair HL = the number. The CARRY FLAG is set in both cases when ENTER ended it. Any other key drops the command: JUMP to 4E4BH. SYS9/SYS calls it too.
51A3
GOSUB to 518AH to wait for the first key: Register A = the key.
51A6
RET Z C8
If the Z FLAG is set (a space, a comma or ENTER at once), RETURN with Register Pair HL unchanged; the CARRY FLAG tells ENTER.
51A7
LD HL,0000H 21 00 00
Load Register Pair HL with 0000H, the number so far.
51AA
GOSUB to 51BFH to turn the key in Register A into its value: the CARRY FLAG when it is not a hex digit.
51AD
If the CARRY FLAG is set (not a hex digit), JUMP to 4E4BH, the command loop: the command is dropped, and 4E4BH sets the Stack Pointer again.
51B0
ADD HL,HL 29
Add Register Pair HL to itself: the number so far times 2, the first of the four shifts that make room for the new digit.
51B1
ADD HL,HL 29
Add Register Pair HL to itself: the number so far times 4.
51B2
ADD HL,HL 29
Add Register Pair HL to itself: the number so far times 8.
51B3
ADD HL,HL 29
Add Register Pair HL to itself: the number so far times 16, with bits 3-0 of Register L free for the new digit; the digit four places up leaves Register H, so only the last four digits count.
51B4
OR L B5
OR Register L (its bits 3-0 now 0) into Register A (the digit).
51B5
LD L,A 6F
Copy Register A into Register L: Register Pair HL = the number with the new digit.
51B6
GOSUB to 518AH to wait for the next key: Register A = the key.
51B9
If the NZ FLAG is set (not a space, a comma or ENTER), JUMP back to 51AAH for the next digit.
51BB
RRA 1F
Rotate Register A (0DH, 2CH or 20H) right through the CARRY FLAG: bit 7 = the CARRY FLAG (set for ENTER), and bit 0 goes into the CARRY FLAG (1 for 0DH, 0 for 2CH and 20H).
51BC
ADC A,81H CE 81
Add 81H and the CARRY FLAG to Register A: 86H from ENTER gives 08H with the CARRY FLAG, 16H and 10H from the comma and the space give 97H and 91H with NO CARRY; the result is never 00H, so the NZ FLAG is set.
51BE
RET C9
RETURN with Register Pair HL = the number, the NZ FLAG, and the CARRY FLAG when ENTER ended it.
51BFH - Hex Digit
Register A = a key code. Returns NO CARRY and Register A = 00H-0FH for the keys 0-9 and A-F, the CARRY FLAG for any other code.
51BF
SUB 30H D6 30
SUBtract 30H from Register A: 00H-09H for the keys 0-9; a borrow below 30H.
51C1
RET C D8
If the CARRY FLAG is set (below 0), RETURN: not a hex digit.
51C2
ADD A,E9H C6 E9
Add E9H to Register A (the key less 30H): a carry for 17H and up, the keys from G (47H) up.
51C4
RET C D8
If the CARRY FLAG is set (G or above), RETURN: not a hex digit.
51C5
ADD A,06H C6 06
Add 06H to Register A: a carry for the keys A-F (41H-46H).
51C7
If the CARRY FLAG is set (A-F), JUMP to 51CCH.
51C9
ADD A,07H C6 07
Add 07H to Register A: a carry for the codes 3AH-40H, between 9 and A.
51CB
RET C D8
If the CARRY FLAG is set (3AH-40H), RETURN: not a hex digit.
51CC
ADD A,0AH C6 0A
Add 0AH to Register A: the digit's value, 00H-09H for the keys 0-9 and 0AH-0FH for A-F.
51CE
OR A B7
OR Register A with itself: clears the CARRY FLAG left by the addition.
51CF
RET C9
RETURN with the value in Register A and NO CARRY.
51D0H - Show Hex Digits
51D0H shows the byte at Register Pair HL as two hex digits and moves Register Pair HL on; 51D4H shows Register Pair HL as four hex digits; 51D9H shows Register A as two hex digits; 51EFH as two hex digits and a space; 51F2H shows a space; 51F6H shows the 3 characters at Register Pair HL and moves Register Pair HL on by 3. SYS9/SYS calls 51D0H, 51D4H, 51D9H and 51F2H.
51D0
LD A,(HL) 7E
Fetch the byte at Register Pair HL into Register A.
51D1
INC HL 23
Increment Register Pair HL to the next byte, for the caller.
51D2
JUMP to 51D9H to show Register A as two hex digits.
51D4
LD A,H 7C
Copy Register H (the high byte) into Register A.
51D5
GOSUB to 51D9H to show Register A as two hex digits.
51D8
LD A,L 7D
Copy Register L (the low byte) into Register A, and fall into 51D9H.
51D9
PUSH AF F5
Save Register Pair AF (Register A the byte) to the stack.
51DA
RRA 1F
Rotate Register A right through the carry: the first of the four rotations that bring the high digit (bits 7-4) down to bits 3-0.
51DB
RRA 1F
Rotate Register A right through the carry: the second rotation, bit 5 of the byte now in bit 3.
51DC
RRA 1F
Rotate Register A right through the carry: the third rotation, bit 6 of the byte now in bit 3.
51DD
RRA 1F
Rotate Register A right through the carry: the fourth rotation, bits 3-0 now hold the high digit (bits 7-4 of the byte).
51DE
GOSUB to 51E2H to show bits 3-0 of Register A, the high digit.
51E1
POP AF F1
Restore Register Pair AF from the stack: Register A = the byte, and fall into 51E2H for the low digit.
51E2
AND 0FH E6 0F
Mask Register A to bits 3-0, the hex digit to show.
51E4
ADD A,30H C6 30
Add 30H to Register A: 30H-39H for the digits 0-9.
51E6
CP 3AH FE 3A
Compare Register A (30H plus the digit) against 3AH, the code after 9.
51E8
If the CARRY FLAG is set (0-9), JUMP to 51ECH.
51EA
ADD A,07H C6 07
Add 07H to Register A: 41H-46H, the letters A-F.
51EC
JUMP to the ROM's 0033H to send Register A to the display; its RETURN goes back to the caller.
51EF
GOSUB to 51D9H to show Register A as two hex digits, then fall into 51F2H.
51F2
LD A,20H 3E 20
Load Register A with 20H, the space to send to the display.
51F4
JUMP to 51ECH to send Register A (the space) to the display.
51F6
GOSUB to 51FCH to show the first character at Register Pair HL.
51F9
GOSUB to 51FCH to show the second character at Register Pair HL, then fall into 51FCH for the third.
51FC
LD A,(HL) 7E
Fetch the character at Register Pair HL into Register A.
51FD
INC HL 23
Increment Register Pair HL to the next character.
51FE
JUMP to 51ECH to send Register A (the character) to the display.