4E00H - The Routine Table
Data: SYS8/SYS's table of routines 2-6, one word each, used by SYS0/SYS's overlay request handler (its 49D3H-49E6H) for the request codes 72H-76H: SORT@ (4482H) requests 73H, CAT@ (4419H) 74H, FILPTR@ (428DH) 75H and RAMDIR@ (4290H) 76H. No file of the diskette requests 72H; SORT@ is called by SYS9/SYS, and no file calls CAT@, FILPTR@ or RAMDIR@.
4E00-4E01
DEFW 4E0AH 0A 4E
Routine 2: 4E0AH, XOR A and RET, which SYS0/SYS's record locator requests when it loads SYS8/SYS back (its 4D5FH-4D6CH).
4E02-4E03
DEFW 4E0CH 0C 4E
Routine 3: 4E0CH, SORT@, which sorts a list of entries of one length in memory by a key inside them.
4E04-4E05
DEFW 4F23H 23 4F
Routine 4: 4F23H, CAT@, which displays the names of the files of a drive, four to a line.
4E06-4E07
DEFW 502DH 2D 50
Routine 5: 502DH, FILPTR@, which takes the drive and logical file number of an open file from its control block.
4E08-4E09
DEFW 5037H 37 50
Routine 6: 5037H, RAMDIR@, which copies directory entries, or the space used and free, of a drive to memory.
4E0AH - Routine 2
Nothing to do when SYS0/SYS's record locator brings SYS8/SYS back.
4E0A
XOR A AF
Set Register A to 00H by XORing it with itself, and set the Z FLAG: routine 2 has no work to do.
4E0B
RET C9
RETurn to SYS0/SYS's overlay request handler (49E7H) with Register A = 00H.
4E0CH - SORT@
Routine 3, requested by SORT@ (4482H). Index Register IX = the first entry, Register Pair DE = the last entry, Register C = the length of an entry, Register B = the offset of the key in the entry, Register L = the length of the key, Register H = 00H for an ascending sort, else descending. The entries are sorted in place by a Shell sort: the gap starts at half the number of entries and is halved after each pass; entries a gap apart are compared byte by byte from the key's first byte and swapped when out of order. Returns the Z FLAG and Register A = 00H, or the NZ FLAG and Register A = 01H-05H when the parameters are wrong (4EF8H). The registers other than Register Pair AF are saved (4485H).
4E0C
GOSUB to 4485H, which calls 4E0FH with Register Pairs BC, DE, HL and Index Registers IX and IY saved, and returns to the caller of SORT@.
4E0F
GOSUB to 4EBEH for the number of entries in Register Pair DE, from the first and last entries' addresses.
4E12
JUMP to 4E17H, past a second entry with the register saving that nothing in the file uses.
4E14
GOSUB to 4485H, which would call 4E17H with the registers saved; no jump and no table word of SYS8/SYS leads to 4E14H.
4E17
GOSUB to 4ECEH to check the parameters and store them in the work area 4F15H-4F1EH; Register A = the error code.
4E1A
RET NZ C0
If the NZ FLAG is set (a wrong parameter), RETurn with Register A = 01H-05H.
4E1BH - A Pass
4F1DH holds the gap; a gap of 0 ends the sort. For each entry i from 0 to the number of entries less the gap, the entry is compared with the one a gap after it and, while they are out of order, swapped and followed back down the list a gap at a time (4F1BH).
4E1B
LD HL,(4F1DH) 2A 1D 4F
Load Register Pair HL with the gap from 4F1DH.
4E1E
LD A,H 7C
Load Register A with Register H, the high byte of the gap.
4E1F
OR L B5
OR Register A with Register L: the Z FLAG when the gap is 0000H.
4E20
RET Z C8
If the Z FLAG is set (the gap is 0), RETurn with Register A = 00H: the list is sorted.
4E21
LD HL,(4F19H) 2A 19 4F
Load Register Pair HL with the number of entries from 4F19H.
4E24
LD DE,(4F1DH) ED 5B 1D 4F
Load Register Pair DE with the gap from 4F1DH.
4E28
SBC HL,DE ED 52
SUBtract Register Pair DE (the gap) from Register Pair HL with the C FLAG (clear): the number of entries less the gap.
4E2A
LD (4F21H),HL 22 21 4F
Store Register Pair HL to 4F21H, the limit of the entry counter i.
4E2D
SBC HL,HL ED 62
SUBtract Register Pair HL from itself with the C FLAG (clear): Register Pair HL = 0000H.
4E2F
LD (4F1FH),HL 22 1F 4F
Store Register Pair HL (0000H) to 4F1FH: the entry counter i starts at 0.
4E32
LD HL,(4F1FH) 2A 1F 4F
Load Register Pair HL with the entry counter i from 4F1FH.
4E35
LD (4F1BH),HL 22 1B 4F
Store Register Pair HL to 4F1BH: the entry j to compare starts at i.
4E38
LD HL,(4F1BH) 2A 1B 4F
Load Register Pair HL with the entry j from 4F1BH.
4E3B
LD DE,(4F1DH) ED 5B 1D 4F
Load Register Pair DE with the gap from 4F1DH.
4E3F
GOSUB to 4E84H for the addresses of the entries j (Register Pair HL) and j plus the gap (Register Pair DE).
4E42
GOSUB to 4EA4H to compare the keys of the two entries: the Z FLAG when equal, the C FLAG when the key of j is lower.
4E45
If the Z FLAG is set (equal keys), JUMP to 4E67H: the entries stay as they are.
4E47
If the C FLAG is set (in order for an ascending sort), JUMP to 4E67H; 4EF3H stores the opcode, 38H JR C or 30H JR NC (descending).
4E49
LD A,(4F18H) 3A 18 4F
Load Register A with the length of an entry from 4F18H.
4E4C
LD B,A 47
Load Register B with Register A, the number of bytes to swap.
4E4D
LD A,(DE) 1A
Load Register A with the byte of entry j plus the gap at Register Pair DE.
4E4E
LD C,(HL) 4E
Load Register C with the byte of entry j at Register Pair HL.
4E4F
LD (HL),A 77
Store Register A to entry j at Register Pair HL.
4E50
LD A,C 79
Load Register A with Register C, the byte of entry j.
4E51
LD (DE),A 12
Store Register A to entry j plus the gap at Register Pair DE: the two bytes are swapped.
4E52
INC HL 23
INCrement Register Pair HL by 1 to the next byte of entry j.
4E53
INC DE 13
INCrement Register Pair DE by 1 to the next byte of the other entry.
4E54
DECrement Register B and loop back to 4E4DH while Register B is not zero.
4E56
LD HL,(4F1BH) 2A 1B 4F
Load Register Pair HL with the entry j from 4F1BH.
4E59
LD DE,(4F1DH) ED 5B 1D 4F
Load Register Pair DE with the gap from 4F1DH.
4E5D
OR A B7
OR Register A with itself, to clear the C FLAG for the SBC below.
4E5E
SBC HL,DE ED 52
SUBtract Register Pair DE (the gap) from Register Pair HL (the entry j) with the C FLAG.
4E60
If the C FLAG is set (j less the gap is below 0), JUMP to 4E67H.
4E62
LD (4F1BH),HL 22 1B 4F
Store Register Pair HL to 4F1BH: j moves down by the gap.
4E65
JUMP back to 4E38H to compare the entry j with the one a gap after it.
4E67
LD HL,(4F1FH) 2A 1F 4F
Load Register Pair HL with the entry counter i from 4F1FH.
4E6A
INC HL 23
INCrement Register Pair HL by 1 to the next entry i.
4E6B
LD (4F1FH),HL 22 1F 4F
Store Register Pair HL to 4F1FH, the entry counter i.
4E6E
LD DE,(4F21H) ED 5B 21 4F
Load Register Pair DE with the limit of the entry counter from 4F21H.
4E72
OR A B7
OR Register A with itself, to clear the C FLAG for the SBC below.
4E73
SBC HL,DE ED 52
SUBtract Register Pair DE (the limit) from Register Pair HL (i) with the C FLAG: the C FLAG while i is below the limit.
4E75
If the C FLAG is set (more entries in this pass), JUMP back to 4E32H.
4E77
LD HL,(4F1DH) 2A 1D 4F
Load Register Pair HL with the gap from 4F1DH.
4E7A
SRL H CB 3C
Shift Register H right by one bit, its bit 0 going to the C FLAG.
4E7C
RR L CB 1D
Rotate Register L right through the C FLAG: Register Pair HL = half the gap.
4E7E
LD (4F1DH),HL 22 1D 4F
Store Register Pair HL to 4F1DH, the gap of the next pass.
4E81
JUMP back to 4E1BH for the next pass with the halved gap.
4E84H - The Addresses of Two Entries
Register Pair HL = an entry number j, Register Pair DE = the gap: returns Register Pair HL = the address of entry j and Register Pair DE = the address of entry j plus the gap.
4E84
PUSH HL E5
Save Register Pair HL, the entry number j, to the top of the stack.
4E85
GOSUB to 4E90H for the address of entry j in Register Pair HL.
4E88
EX (SP),HL E3
Exchange the word at the top of the Stack Pointer with Register Pair HL: the address goes to the stack and Register Pair HL = j.
4E89
ADD HL,DE 19
ADD Register Pair DE (the gap) to Register Pair HL: the entry number j plus the gap.
4E8A
GOSUB to 4E90H for the address of that entry in Register Pair HL.
4E8D
EX DE,HL EB
Exchange Register Pairs DE and HL: Register Pair DE = the address of entry j plus the gap.
4E8E
POP HL E1
Restore Register Pair HL, the address of entry j, from the top of the stack.
4E8F
RET C9
RETurn with the two addresses in Register Pairs HL and DE.
4E90H - The Address of an Entry
Register Pair HL = the entry number: returns Register Pair HL = Index Register IX (the first entry) plus the number times the entry length.
4E90
PUSH DE D5
Save Register Pair DE to the top of the stack.
4E91
LD A,(4F18H) 3A 18 4F
Load Register A with the length of an entry from 4F18H.
4E94
GOSUB to 444EH, MULT@, for Register Pair HL times Register A: the 24 bit product in Register Pair HL and Register A.
4E97
LD E,A 5F
Load Register E with Register A, the low byte of the product.
4E98
LD D,L 55
Load Register D with Register L, the middle byte: Register Pair DE = the offset of the entry.
4E99
PUSH IX DD E5
Save Index Register IX, the first entry, to the top of the stack.
4E9B
ADD IX,DE DD 19
ADD Register Pair DE (the offset) to Index Register IX.
4E9D
PUSH IX DD E5
Save Index Register IX, the entry's address, to the top of the stack.
4E9F
POP HL E1
Restore Register Pair HL from the top of the stack: Register Pair HL = the entry's address.
4EA0
POP IX DD E1
Restore Index Register IX, the first entry, from the top of the stack.
4EA2
POP DE D1
Restore Register Pair DE from the top of the stack, as it was.
4EA3
RET C9
RETurn with Register Pair HL = the address of the entry.
4EA4H - Compare Two Keys
Compares the keys of the entries at Register Pair HL (j) and Register Pair DE (j plus the gap), byte by byte from the offset at 4F15H for the length at 4F16H: the Z FLAG when equal, else the flags of the first byte that differs (the C FLAG when the key of entry j is lower).
4EA4
PUSH DE D5
Save Register Pair DE, the entry j plus the gap, to the top of the stack.
4EA5
PUSH HL E5
Save Register Pair HL, the entry j, to the top of the stack.
4EA6
LD A,(4F15H) 3A 15 4F
Load Register A with the offset of the key in an entry from 4F15H.
4EA9
LD C,A 4F
Load Register C with Register A, the offset of the key.
4EAA
LD B,00H 06 00
Load Register B with 00H: Register Pair BC = the offset of the key.
4EAC
ADD HL,BC 09
ADD Register Pair BC to Register Pair HL: the key of entry j.
4EAD
EX DE,HL EB
Exchange Register Pairs DE and HL: Register Pair DE = the key of entry j, Register Pair HL = the other entry.
4EAE
ADD HL,BC 09
ADD Register Pair BC to Register Pair HL: the key of entry j plus the gap.
4EAF
LD A,(4F16H) 3A 16 4F
Load Register A with the length of the key from 4F16H.
4EB2
LD B,A 47
Load Register B with Register A, the number of bytes to compare.
4EB3
LD A,(DE) 1A
Load Register A with the byte of the key of entry j at Register Pair DE.
4EB4
CP (HL) BE
Compare Register A against the byte of the other key at Register Pair HL.
4EB5
If the NZ FLAG is set (they differ), JUMP to 4EBBH with the flags of the compare.
4EB7
INC DE 13
INCrement Register Pair DE by 1 to the next byte of the key of entry j.
4EB8
INC HL 23
INCrement Register Pair HL by 1 to the next byte of the other key.
4EB9
DECrement Register B and loop back to 4EB3H while Register B is not zero.
4EBB
POP HL E1
Restore Register Pair HL, the entry j, from the top of the stack.
4EBC
POP DE D1
Restore Register Pair DE, the entry j plus the gap, from the top of the stack.
4EBD
RET C9
RETurn with the flags of the compare: the Z FLAG for equal keys.
4EBEH - The Number of Entries
Register Pair DE = the last entry, Index Register IX = the first, Register C = the entry length: returns Register Pair DE = (the last less the first) divided by the length, plus 1.
4EBE
PUSH HL E5
Save Register Pair HL (the key length and the sort switch) to the top of the stack.
4EBF
PUSH IX DD E5
Save Index Register IX, the first entry, to the top of the stack.
4EC1
POP HL E1
Restore Register Pair HL from the top of the stack: Register Pair HL = the first entry.
4EC2
EX DE,HL EB
Exchange Register Pairs DE and HL: Register Pair HL = the last entry, Register Pair DE = the first.
4EC3
OR A B7
OR Register A with itself, to clear the C FLAG for the SBC below.
4EC4
SBC HL,DE ED 52
SUBtract Register Pair DE (the first entry) from Register Pair HL (the last) with the C FLAG: the bytes between them.
4EC6
LD A,C 79
Load Register A with Register C, the length of an entry.
4EC7
GOSUB to 4451H, DIVD@, for Register Pair HL divided by Register A: the quotient in Register Pair HL.
4ECA
EX DE,HL EB
Exchange Register Pairs DE and HL: Register Pair DE = the number of entries less 1.
4ECB
POP HL E1
Restore Register Pair HL, the key length and the sort switch, from the top of the stack.
4ECC
INC DE 13
INCrement Register Pair DE by 1: Register Pair DE = the number of entries.
4ECD
RET C9
RETurn with the number of entries in Register Pair DE.
4ECEH - Store the Parameters
Checks the parameters (4EF8H), then stores the number of entries (4F19H), half of it as the first gap (4F1DH), the key's length (4F16H) and offset (4F15H), the entry length (4F18H), and the order: the opcode at 4E47H becomes 38H (JR C) for an ascending sort, 30H (JR NC) for a descending one.
4ECE
GOSUB to 4EF8H to check the parameters; Register A = 00H or an error code 01H-05H.
4ED1
OR A B7
OR Register A with itself: the NZ FLAG for an error.
4ED2
RET NZ C0
If the NZ FLAG is set (a wrong parameter), RETurn with the error code in Register A.
4ED3
LD (4F19H),DE ED 53 19 4F
Store Register Pair DE, the number of entries, to 4F19H.
4ED7
SRL D CB 3A
Shift Register D right by one bit, its bit 0 going to the C FLAG.
4ED9
RR E CB 1B
Rotate Register E right through the C FLAG: Register Pair DE = half the number of entries.
4EDB
LD (4F1DH),DE ED 53 1D 4F
Store Register Pair DE to 4F1DH, the gap of the first pass.
4EDF
LD A,L 7D
Load Register A with Register L, the length of the key.
4EE0
LD (4F16H),A 32 16 4F
Store Register A to 4F16H, the length of the key.
4EE3
LD A,B 78
Load Register A with Register B, the offset of the key in an entry.
4EE4
LD (4F15H),A 32 15 4F
Store Register A to 4F15H, the offset of the key.
4EE7
LD A,C 79
Load Register A with Register C, the length of an entry.
4EE8
LD (4F18H),A 32 18 4F
Store Register A to 4F18H, the length of an entry.
4EEB
LD A,38H 3E 38
Load Register A with 38H, the opcode of JR C, for an ascending sort.
4EED
INC H 24
INCrement Register H by 1; with the DECrement after it, this sets the Z FLAG when Register H is 00H.
4EEE
DEC H 25
DECrement Register H by 1, back to the sort switch: the Z FLAG when Register H is 00H, ascending.
4EEF
If the Z FLAG is set (ascending), JUMP to 4EF3H.
4EF1
LD A,30H 3E 30
Load Register A with 30H, the opcode of JR NC, for a descending sort.
4EF3
LD (4E47H),A 32 47 4E
Store Register A to 4E47H, the opcode of the jump that keeps two entries in their order.
4EF6
XOR A AF
Set Register A to 00H by XORing it with itself, and set the Z FLAG: the parameters are good.
4EF7
RET C9
RETurn with the Z FLAG set and Register A = 00H.
4EF8H - Check the Parameters
Returns Register A = 04H when the key length (Register L) is 0, 03H when the entry length (Register C) is 0, 02H when the key's offset (Register B) is not below the entry length, 01H when the key runs past the end of the entry, 05H when there are no entries (Register Pair DE = 0000H), else 00H. SORT@ returns these as its error codes.
4EF8
LD A,L 7D
Load Register A with Register L, the length of the key.
4EF9
OR A B7
OR Register A with itself: the Z FLAG when the key length is 0.
4EFA
LD A,04H 3E 04
Load Register A with 04H, the code for a key of no length.
4EFC
RET Z C8
If the Z FLAG is set (the key length is 0), RETurn with Register A = 04H.
4EFD
LD A,C 79
Load Register A with Register C, the length of an entry.
4EFE
OR A B7
OR Register A with itself: the Z FLAG when the entry length is 0.
4EFF
LD A,03H 3E 03
Load Register A with 03H, the code for an entry of no length.
4F01
RET Z C8
If the Z FLAG is set (the entry length is 0), RETurn with Register A = 03H.
4F02
LD A,B 78
Load Register A with Register B, the offset of the key.
4F03
CP C B9
Compare Register A against Register C, the entry length: the NC FLAG when the offset is not inside the entry.
4F04
LD A,02H 3E 02
Load Register A with 02H, the code for a key that starts outside the entry.
4F06
RET NC D0
If the NC FLAG is set (the offset is too large), RETurn with Register A = 02H.
4F07
LD A,L 7D
Load Register A with Register L, the length of the key.
4F08
ADD A,B 80
ADD Register B, the offset, to Register A: the end of the key plus 1.
4F09
DEC A 3D
DECrement Register A by 1 to the offset of the key's last byte.
4F0A
CP C B9
Compare Register A against Register C, the entry length: the NC FLAG when the key's last byte is outside the entry.
4F0B
LD A,01H 3E 01
Load Register A with 01H, the code for a key that runs past the entry.
4F0D
RET NC D0
If the NC FLAG is set (the key is too long), RETurn with Register A = 01H.
4F0E
LD A,D 7A
Load Register A with Register D, the high byte of the number of entries.
4F0F
OR E B3
OR Register A with Register E: the Z FLAG when there are no entries.
4F10
LD A,05H 3E 05
Load Register A with 05H, the code for an empty list.
4F12
RET Z C8
If the Z FLAG is set (no entries), RETurn with Register A = 05H.
4F13
XOR A AF
Set Register A to 00H by XORing it with itself, and set the Z FLAG: the parameters are good.
4F14
RET C9
RETurn with the Z FLAG set and Register A = 00H.
4F15H - SORT@'s Work Area
Not in the file: no load block fills 4F15H-4F22H, which SORT@ uses for its parameters and counters.
4F15
DEFS 1
The offset of the key in an entry, from Register B (4EE4H, 4EA6H).
4F16
DEFS 1
The length of the key, from Register L (4EE0H, 4EAFH).
4F17
DEFS 1
Not used by SORT@ or any other routine of SYS8/SYS.
4F18
DEFS 1
The length of an entry, from Register C (4EE8H, 4E49H, 4E91H).
4F19-4F1A
DEFS 2
The number of entries in the list, from 4EBEH (4ED3H, 4E21H).
4F1B-4F1C
DEFS 2
The entry j being moved down the list (4E35H, 4E62H).
4F1D-4F1E
DEFS 2
The gap, half the number of entries at first, halved after each pass (4EDBH, 4E7EH).
4F1F-4F20
DEFS 2
The entry counter i of a pass (4E2FH, 4E6BH).
4F21-4F22
DEFS 2
The limit of the entry counter: the number of entries less the gap (4E2AH, 4E6EH).
4F23H - CAT@
Routine 4, requested by CAT@ (4419H). The drive is the ASCII digit 0-7 at 4271H, which is then cleared, or else the drive number in Register C. Unless the display is FORCEd or JOINed (error 27H), CAT@ clears the screen, shows FILE CATALOG: with the drive's name and the diskette's name from its GAT, then the names of the files, four to a line, 15 characters each, pausing after 13 lines and then every 15 (until a key is pressed) and when the space bar is pressed. Only directory entries whose flag byte is exactly 10H are shown: active, not a system file, not invisible, protection level 0. An error goes to ERROR@ (4409H) with bits 7 and 6 set. The registers other than Register Pair AF are saved (4485H).
4F23
GOSUB to 4485H, which calls 4F26H with Register Pairs BC, DE, HL and Index Registers IX and IY saved, and returns to the caller of CAT@.
4F26
LD A,01H 3E 01
Load Register A with 01H, the device number of @DO, the video display.
4F28
GOSUB to 44A0H, LOCDCB%, for the address of the display's DCB in Register Pair DE.
4F2B
LD A,(DE) 1A
Load Register A with the type byte of the display's DCB at Register Pair DE.
4F2C
AND 30H E6 30
AND Register A with 30H, the FORCE (bit 4) and JOIN (bit 5) flags of the type byte.
4F2E
LD A,27H 3E 27
Load Register A with 27H, the error code of Device in use; the flags of the AND are kept.
4F30
If the NZ FLAG is set (the display is FORCEd or JOINed), JUMP to 5007H to post error 27H.
4F33
LD HL,4271H 21 71 42
Point Register Pair HL to 4271H, where a program may put the drive as an ASCII digit.
4F36
LD A,(HL) 7E
Load Register A with the byte at Register Pair HL.
4F37
LD (HL),00H 36 00
Store 00H to the byte at Register Pair HL: the digit is used only once.
4F39
CP 30H FE 30
Compare Register A against 30H, the digit 0, the lowest drive.
4F3B
If the C FLAG is set (below 0), JUMP to 4F41H to take the drive from Register C.
4F3D
CP 38H FE 38
Compare Register A against 38H, one above the digit 7.
4F3F
If the C FLAG is set (a digit 0-7), JUMP to 4F42H to use it.
4F41
LD A,C 79
Load Register A with Register C, the drive number given in Register C.
4F42
AND 07H E6 07
AND Register A with 07H: the drive number 0-7, from the digit or from Register C.
4F44
LD C,A 4F
Load Register C with Register A, the drive number for the disk routines.
4F45
LD A,00H 3E 00
Load Register A with 00H, function 0 of DISKIO%, DCHECK, which checks that the drive is ready.
4F47
GOSUB to 4488H, DISKIO%, to check drive Register C.
4F4A
LD A,08H 3E 08
Load Register A with 08H, the error code of Drive not available; the flags are kept.
4F4C
If the NZ FLAG is set (the drive is not ready), JUMP to 5007H to post error 08H.
4F4F
LD E,00H 1E 00
Load Register E with 00H, sector 0 of the directory, the GAT.
4F51
LD HL,4300H 21 00 43
Point Register Pair HL to 4300H, SYS0/SYS's system buffer.
4F54
LD A,06H 3E 06
Load Register A with 06H, function 6 of DISKIO%, SREAD, which reads a directory sector.
4F56
GOSUB to 4488H, DISKIO%, to read the GAT of drive Register C into the buffer at Register Pair HL.
4F59
If the NZ FLAG is set (a read error), JUMP to 5007H to post the error in Register A.
4F5C
GOSUB to 44A3H, LOCDCT%, for the drive control table of drive Register C in Index Register IY.
4F5F
PUSH BC C5
Save Register Pair BC, the drive in Register C, to the top of the stack.
4F60
PUSH DE D5
Save Register Pair DE, the cylinder and sector, to the top of the stack.
4F61
LD DE,501CH 11 1C 50
Point Register Pair DE to 501CH, the place of the drive's name in the heading.
4F64
GOSUB to 514EH to copy the two character name of drive Register C from DCTTBL to Register Pair DE.
4F67
LD HL,43D0H 21 D0 43
Point Register Pair HL to 43D0H, the diskette's name, eight characters at +D0H of the GAT.
4F6A
LD DE,5021H 11 21 50
Point Register Pair DE to 5021H, the place of the diskette's name in the heading.
4F6D
LD BC,0008H 01 08 00
Load Register Pair BC with 0008H, the eight characters of the name.
4F70
LDIR ED B0
Copy Register Pair BC bytes from Register Pair HL (the GAT) to Register Pair DE (the heading).
4F72
LD HL,500CH 21 0C 50
Point Register Pair HL to 500CH, the heading.
4F75
GOSUB to 4467H, DSPLY@, to clear the screen and show the heading at Register Pair HL.
4F78
POP DE D1
Restore Register Pair DE, the cylinder and sector, from the top of the stack.
4F79
POP BC C1
Restore Register Pair BC, the drive in Register C, from the top of the stack.
4F7A
LD A,04H 3E 04
Load Register A with 04H, the four names on a line.
4F7C
LD (502BH),A 32 2B 50
Store Register A to 502BH, the count of names left on the line.
4F7F
LD A,0DH 3E 0D
Load Register A with 0DH, the thirteen lines before the first pause.
4F81
LD (502CH),A 32 2C 50
Store Register A to 502CH, the count of lines left before a pause.
4F84
LD E,02H 1E 02
Load Register E with 02H, sector 2 of the directory, the first sector of entries.
4F86H - A Directory Sector
Reads sector Register E of the directory and shows each of its eight entries whose flag byte is 10H.
4F86
LD HL,4300H 21 00 43
Point Register Pair HL to 4300H, SYS0/SYS's system buffer.
4F89
LD A,06H 3E 06
Load Register A with 06H, function 6 of DISKIO%, SREAD, which reads a directory sector.
4F8B
GOSUB to 4488H, DISKIO%, to read directory sector Register E of drive Register C into the buffer.
4F8E
If the NZ FLAG is set (a read error), JUMP to 5007H to post the error in Register A.
4F91
PUSH BC C5
Save Register Pair BC, the drive, to the top of the stack.
4F92
PUSH DE D5
Save Register Pair DE, the sector, to the top of the stack.
4F93
PUSH HL E5
Save Register Pair HL, the entry, to the top of the stack.
4F94
LD A,(HL) 7E
Load Register A with the flag byte of the entry at Register Pair HL.
4F95
CP 10H FE 10
Compare Register A against 10H: an active entry with no other flag set and protection level 0.
4F97
If the NZ FLAG is set (any other entry), JUMP to 4FEEH for the next entry.
4F99
LD BC,080FH 01 0F 08
Load Register Pair BC with 080FH: Register B = 8, the characters of a name, Register C = 15, the width of a column.
4F9C
LD A,05H 3E 05
Load Register A with 05H, the offset of the name in a directory entry.
4F9E
ADD A,L 85
ADD Register L to Register A, the low byte of the entry's address.
4F9F
LD L,A 6F
Load Register L with Register A: Register Pair HL = the name of the entry.
4FA0
LD A,(HL) 7E
Load Register A with the character of the name at Register Pair HL.
4FA1
CP 20H FE 20
Compare Register A against 20H, a space, which ends the name.
4FA3
If the Z FLAG is set (the end of the name), JUMP to 4FACH.
4FA5
GOSUB to 0033H, the ROM's display routine, to show the character in Register A.
4FA8
INC L 2C
INCrement Register L by 1 to the next character of the name.
4FA9
DEC C 0D
DECrement Register C by 1, the places left in the column.
4FAA
DECrement Register B and loop back to 4FA0H while Register B is not zero.
4FAC
LD A,B 78
Load Register A with Register B, the characters of the name not shown.
4FAD
ADD A,L 85
ADD Register L to Register A, to pass over them.
4FAE
LD L,A 6F
Load Register L with Register A: Register Pair HL = the extension at +0DH.
4FAF
LD A,(HL) 7E
Load Register A with the first character of the extension at Register Pair HL.
4FB0
CP 20H FE 20
Compare Register A against 20H, a space: the file has no extension.
4FB2
If the Z FLAG is set (no extension), JUMP to 4FC4H.
4FB4
LD A,2FH 3E 2F
Load Register A with 2FH, the slash before an extension.
4FB6
GOSUB to 0033H, the ROM's display routine, to show the slash in Register A.
4FB9
DEC C 0D
DECrement Register C by 1, the places left in the column.
4FBA
LD B,03H 06 03
Load Register B with 03H, the three characters of an extension.
4FBC
LD A,(HL) 7E
Load Register A with the character of the extension at Register Pair HL.
4FBD
GOSUB to 0033H, the ROM's display routine, to show the character in Register A.
4FC0
INC L 2C
INCrement Register L by 1 to the next character of the extension.
4FC1
DEC C 0D
DECrement Register C by 1, the places left in the column.
4FC2
DECrement Register B and loop back to 4FBCH while Register B is not zero.
4FC4
LD A,20H 3E 20
Load Register A with 20H, a space, to fill the column.
4FC6
GOSUB to 0033H, the ROM's display routine, to show the space in Register A.
4FC9
DEC C 0D
DECrement Register C by 1, the places left in the column.
4FCA
If the NZ FLAG is set (more places), JUMP back to 4FC4H.
4FCC
LD HL,502BH 21 2B 50
Point Register Pair HL to 502BH, the count of names left on the line.
4FCF
DEC (HL) 35
DECrement the count at Register Pair HL by 1.
4FD0
If the NZ FLAG is set (the line is not full), JUMP to 4FEEH.
4FD2
LD (HL),04H 36 04
Store 04H to the count at Register Pair HL: four names on the next line.
4FD4
LD A,0DH 3E 0D
Load Register A with 0DH, a carriage return, to end the line.
4FD6
GOSUB to 0033H, the ROM's display routine, to start a new line.
4FD9
LD HL,502CH 21 2C 50
Point Register Pair HL to 502CH, the count of lines left before a pause.
4FDC
DEC (HL) 35
DECrement the count at Register Pair HL by 1.
4FDD
If the NZ FLAG is set (no pause yet), JUMP to 4FE6H.
4FDF
LD (HL),0FH 36 0F
Store 0FH to the count at Register Pair HL: fifteen lines to the next pause.
4FE1
GOSUB to 0049H, the ROM's routine that waits for a key: the pause after a screen.
4FE4
JUMP to 4FEEH for the next entry of the directory sector.
4FE6
GOSUB to 002BH, the ROM's keyboard scan, for a key in Register A (00H when none).
4FE9
CP 20H FE 20
Compare Register A against 20H, the space bar, which pauses the listing.
4FEB
If the Z FLAG is set (the space bar), GOSUB to 0049H to wait for another key.
4FEE
POP HL E1
Restore Register Pair HL, the entry, from the top of the stack.
4FEF
POP DE D1
Restore Register Pair DE, the sector, from the top of the stack.
4FF0
POP BC C1
Restore Register Pair BC, the drive, from the top of the stack.
4FF1
LD A,20H 3E 20
Load Register A with 20H, the length of a directory entry.
4FF3
ADD A,L 85
ADD Register L to Register A, the low byte of the entry's address.
4FF4
LD L,A 6F
Load Register L with Register A: Register Pair HL = the next entry.
4FF5
If the NC FLAG is set (still in the buffer), JUMP back to 4F91H.
4FF8
LD A,(IY+0EH) FD 7E 0E
Load Register A with the directory's length in sectors from the drive control table at Index Register IY+0EH.
4FFB
DEC A 3D
DECrement Register A by 1 to the last sector of the directory.
4FFC
INC E 1C
INCrement Register E by 1 to the next directory sector.
4FFD
CP E BB
Compare Register A against Register E: the NC FLAG while the sector is inside the directory.
4FFE
If the NC FLAG is set (another sector), JUMP back to 4F86H.
5001
LD A,0DH 3E 0D
Load Register A with 0DH, a carriage return, to end the last line.
5003
GOSUB to 0033H, the ROM's display routine, to end the listing with a new line.
5006
RET C9
RETurn through 4485H, which restores the registers, to the caller of CAT@.
5007H - Posting an Error
Register A = the error code. Bits 7 and 6 are set, so ERROR@ displays the message without its frame and returns to the caller of CAT@ (SYS5/SYS).
5007
OR C0H F6 C0
OR Register A with C0H, to set bits 7 and 6 of the error code.
5009
JUMP to 4409H, ERROR@, to display the message of the error in Register A.
500CH - The Heading
Data: the heading of CAT@, displayed by DSPLY@ (4F75H) after CAT@ has put in the drive's name and the diskette's name.
500C-500D
DEFB 1CH,1FH 1C 1F
1CH moves the cursor to the top left corner of the screen and 1FH clears the screen from there.
500E-501B
DEFM "FILE CATALOG: " 46 49 4C 45 20 43 41 54 41 4C 4F 47 3A 20
The text of the heading, before the name of the drive.
501C-501D
DEFM "0 " 30 20
The drive's two character name, copied from DCTTBL (4F61H-4F64H); the file holds the name of drive 0.
501E-5020
DEFM " - " 20 2D 20
A dash with a space on either side, between the drive's name and the diskette's.
5021-5028
DEFM "DISKNAME" 44 49 53 4B 4E 41 4D 45
The diskette's name, eight characters copied from +D0H of its GAT (4F67H-4F70H).
5029-502A
DEFB 0AH,0DH 0A 0D
0AH, a line feed, and 0DH, which ends the text for DSPLY@.
502B
DEFB 04H 04
The count of names left on the line, set to 04H by 4F7AH and 4FD2H.
502C
DEFB 0DH 0D
The count of lines left before a pause, set to 0DH by 4F7FH and to 0FH by 4FDFH.
502DH - FILPTR@
Routine 5, requested by FILPTR@ (428DH). Register Pair DE = an open file control block. The routine loads Register B with the drive (+06H) and Register C with the logical file number (+07H), but it runs inside SYS0/SYS's file routine wrapper (448EH), whose return through 4CFAH restores Register Pair BC as the caller had it: FILPTR@ returns only Register A = 00H with the Z FLAG, or error 26H (I/O attempted to unopen file) when the control block is not open. The manual's B and C results do not reach the caller.
502D
GOSUB to 448EH, which returns error 26H at once for a closed control block, else saves the registers and runs the rest with Index Register IX = the control block (448EH jumps to 4CE5H).
5030
LD B,(IX+06H) DD 46 06
Load Register B with the drive number from the file control block at Index Register IX+06H.
5033
LD C,(IX+07H) DD 4E 07
Load Register C with the logical file number from the file control block at Index Register IX+07H.
5036
RET C9
RETurn to 4CFAH, which restores Register Pairs BC, DE, HL and Index Registers IX and IY, so the caller gets its own Register Pair BC back.
5037H - RAMDIR@
Routine 6, requested by RAMDIR@ (4290H). Register B = the drive, Register C = the function, Register Pair HL = the buffer. Function 00H: every entry of the directory whose flag byte has bit 4 set and bit 7 clear (system and invisible files too) is copied as a 22 byte record (5083H), with a + (2BH) after the last. Functions 01H-FEH: the entry whose logical file number is Register C, whatever its flags. Function FFH: four bytes, the kilobytes used and free on the diskette. Errors: 08H when the drive is not ready, 10H when the logical file number is outside the directory (5165H), or a read error. The registers other than Register Pair AF are saved (4485H).
5037
GOSUB to 4485H, which calls 503AH with Register Pairs BC, DE, HL and Index Registers IX and IY saved, and returns to the caller of RAMDIR@.
503A
EX DE,HL EB
Exchange Register Pairs DE and HL: Register Pair DE = the buffer.
503B
PUSH BC C5
Save Register Pair BC (Register B the drive, Register C the function) to the top of the stack.
503C
LD B,C 41
Load Register B with Register C, the function.
503D
POP AF F1
Restore Register Pair AF from the top of the stack: Register A = the drive, from Register B.
503E
LD C,A 4F
Load Register C with Register A: Register C = the drive and Register B = the function.
503F
INC B 04
INCrement Register B by 1: the Z FLAG when the function is FFH.
5040
If the Z FLAG is set (function FFH), JUMP to 50E4H for the space used and free.
5043
DEC B 05
DECrement Register B by 1, back to the function: the Z FLAG for function 00H.
5044
If the NZ FLAG is set (functions 01H-FEH), JUMP to 5077H for one entry.
5046
LD A,00H 3E 00
Load Register A with 00H, function 0 of DISKIO%, DCHECK, which checks that the drive is ready.
5048
GOSUB to 4488H, DISKIO%, to check drive Register C.
504B
LD A,08H 3E 08
Load Register A with 08H, the error code of Drive not available; the flags are kept.
504D
RET NZ C0
If the NZ FLAG is set (the drive is not ready), RETurn with error 08H.
504E
GOSUB to 44A3H, LOCDCT%, for the drive control table of drive Register C in Index Register IY.
5051
LD B,02H 06 02
Load Register B with 02H, sector 2 of the directory, the first sector of entries.
5053
PUSH DE D5
Save Register Pair DE, the place in the buffer, to the top of the stack.
5054
LD E,B 58
Load Register E with Register B, the directory sector to read.
5055
LD HL,4300H 21 00 43
Point Register Pair HL to 4300H, SYS0/SYS's system buffer.
5058
LD A,06H 3E 06
Load Register A with 06H, function 6 of DISKIO%, SREAD, which reads a directory sector.
505A
GOSUB to 4488H, DISKIO%, to read directory sector Register E of drive Register C into the buffer.
505D
POP DE D1
Restore Register Pair DE, the place in the buffer, from the top of the stack; the flags are kept.
505E
RET NZ C0
If the NZ FLAG is set (a read error), RETurn with the error code in Register A.
505F
LD A,(HL) 7E
Load Register A with the flag byte of the entry at Register Pair HL.
5060
AND 90H E6 90
AND Register A with 90H, bit 7 (an extended entry) and bit 4 (active).
5062
CP 10H FE 10
Compare Register A against 10H: an active entry that is not an extended one.
5064
If the Z FLAG is set (a file's entry), GOSUB to 5083H to copy it to the buffer at Register Pair DE.
5067
LD A,20H 3E 20
Load Register A with 20H, the length of a directory entry.
5069
ADD A,L 85
ADD Register L to Register A, the low byte of the entry's address.
506A
LD L,A 6F
Load Register L with Register A: Register Pair HL = the next entry.
506B
If the NC FLAG is set (still in the sector), JUMP back to 505FH.
506D
LD A,(IY+0EH) FD 7E 0E
Load Register A with the directory's length in sectors from the drive control table at Index Register IY+0EH.
5070
DEC A 3D
DECrement Register A by 1 to the last sector of the directory.
5071
INC B 04
INCrement Register B by 1 to the next directory sector.
5072
CP B B8
Compare Register A against Register B: the NC FLAG while the sector is inside the directory.
5073
If the NC FLAG is set (another sector), JUMP back to 5053H.
5075
XOR A AF
Set Register A to 00H by XORing it with itself, and set the Z FLAG: the directory is copied.
5076
RET C9
RETurn through 4485H to the caller of RAMDIR@ with the Z FLAG set.
5077
LD A,00H 3E 00
Load Register A with 00H, function 0 of DISKIO%, DCHECK, which checks that the drive is ready.
5079
GOSUB to 4488H, DISKIO%, to check drive Register C.
507C
LD A,08H 3E 08
Load Register A with 08H, the error code of Drive not available; the flags are kept.
507E
RET NZ C0
If the NZ FLAG is set (the drive is not ready), RETurn with error 08H.
507F
GOSUB to 5165H to read the directory sector of logical file number Register B (a patch block: this was CALL 449AH).
5082
RET NZ C0
If the NZ FLAG is set (error 10H or a read error), RETurn with the error code in Register A.
5083H - Copy an Entry
Register Pair HL = a directory entry, Register Pair DE = the buffer, Register C = the drive. Writes a 22 byte record and a + after it, and returns Register Pair DE at the +, where the next record goes: +00H-+0EH the name, /extension and :drive padded with spaces (only the drive name's first character stays), +0FH the entry's flag byte, +10H the end of file byte, +11H the logical record length, +12H-+13H the number of sectors, +14H-+15H FFH FFH.
5083
PUSH BC C5
Save Register Pair BC, the drive in Register C, to the top of the stack.
5084
PUSH HL E5
Save Register Pair HL, the entry, to the top of the stack.
5085
PUSH HL E5
Save Register Pair HL, the entry, to the top of the stack again.
5086
PUSH BC C5
Save Register Pair BC, the drive in Register C, to the top of the stack again.
5087
LD BC,080FH 01 0F 08
Load Register Pair BC with 080FH: Register B = 8, the characters of a name, Register C = 15, the width of the field.
508A
LD A,05H 3E 05
Load Register A with 05H, the offset of the name in a directory entry.
508C
ADD A,L 85
ADD Register L to Register A, the low byte of the entry's address.
508D
LD L,A 6F
Load Register L with Register A: Register Pair HL = the name of the entry.
508E
LD A,(HL) 7E
Load Register A with the character of the name at Register Pair HL.
508F
CP 20H FE 20
Compare Register A against 20H, a space, which ends the name.
5091
If the Z FLAG is set (the end of the name), JUMP to 5099H.
5093
LD (DE),A 12
Store Register A, the character, to the buffer at Register Pair DE.
5094
INC DE 13
INCrement Register Pair DE by 1 to the next place in the buffer.
5095
INC L 2C
INCrement Register L by 1 to the next character of the name.
5096
DEC C 0D
DECrement Register C by 1, the places left in the field.
5097
DECrement Register B and loop back to 508EH while Register B is not zero.
5099
LD A,B 78
Load Register A with Register B, the characters of the name not copied.
509A
ADD A,L 85
ADD Register L to Register A, to pass over them.
509B
LD L,A 6F
Load Register L with Register A: Register Pair HL = the extension at +0DH.
509C
LD A,(HL) 7E
Load Register A with the first character of the extension at Register Pair HL.
509D
CP 20H FE 20
Compare Register A against 20H, a space: the file has no extension.
509F
If the Z FLAG is set (no extension), JUMP to 50B3H.
50A1
LD A,2FH 3E 2F
Load Register A with 2FH, the slash before an extension.
50A3
LD (DE),A 12
Store Register A (/) to the buffer at Register Pair DE.
50A4
INC DE 13
INCrement Register Pair DE by 1 to the next place in the buffer.
50A5
DEC C 0D
DECrement Register C by 1, the places left in the field.
50A6
LD B,03H 06 03
Load Register B with 03H, the three characters of an extension.
50A8
LD A,(HL) 7E
Load Register A with the character of the extension at Register Pair HL.
50A9
CP 20H FE 20
Compare Register A against 20H, a space, which ends the extension.
50AB
If the Z FLAG is set (the end of the extension), JUMP to 50B3H.
50AD
LD (DE),A 12
Store Register A, the character, to the buffer at Register Pair DE.
50AE
INC DE 13
INCrement Register Pair DE by 1 to the next place in the buffer.
50AF
INC L 2C
INCrement Register L by 1 to the next character of the extension.
50B0
DEC C 0D
DECrement Register C by 1, the places left in the field.
50B1
DECrement Register B and loop back to 50A8H while Register B is not zero.
50B3
LD A,3AH 3E 3A
Load Register A with 3AH, the colon before the drive.
50B5
LD (DE),A 12
Store Register A (colon) to the buffer at Register Pair DE.
50B6
INC DE 13
INCrement Register Pair DE by 1 to the place of the drive's name.
50B7
DEC C 0D
DECrement Register C by 1, the places left in the field.
50B8
LD A,C 79
Load Register A with Register C, the places left in the field.
50B9
POP BC C1
Restore Register Pair BC (Register C = the drive) from the top of the stack.
50BA
LD B,A 47
Load Register B with Register A, the places left in the field.
50BB
GOSUB to 514EH to copy the two character name of drive Register C from DCTTBL to Register Pair DE.
50BE
INC DE 13
INCrement Register Pair DE by 1, past the first character of the drive's name only.
50BF
DEC B 05
DECrement Register B by 1, for the first character of the drive's name.
50C0
LD A,20H 3E 20
Load Register A with 20H, a space, to fill the field.
50C2
LD (DE),A 12
Store Register A (a space) to the buffer at Register Pair DE: the first one goes over the drive name's second character.
50C3
INC DE 13
INCrement Register Pair DE by 1 to the next place in the buffer.
50C4
DECrement Register B and loop back to 50C0H while Register B is not zero.
50C6
POP HL E1
Restore Register Pair HL, the entry, from the top of the stack.
50C7
LDI ED A0
Copy the flag byte (+00H) from Register Pair HL to +0FH of the record at Register Pair DE, INCrementing both and DECrementing Register Pair BC.
50C9
INC HL 23
INCrement Register Pair HL by 1, past +01H of the directory entry.
50CA
INC HL 23
INCrement Register Pair HL by 1, past +02H, to the end of file byte at +03H.
50CB
LDI ED A0
Copy the end of file byte (+03H) from Register Pair HL to +10H at Register Pair DE, INCrementing both and DECrementing Register Pair BC.
50CD
LDI ED A0
Copy the logical record length (+04H) from Register Pair HL to +11H at Register Pair DE, INCrementing both and DECrementing Register Pair BC.
50CF
LD A,L 7D
Load Register A with Register L, the low byte of the entry's address plus 5.
50D0
ADD A,0FH C6 0F
ADD 0FH to Register A, to point to the number of sectors at +14H.
50D2
LD L,A 6F
Load Register L with Register A: Register Pair HL = the number of sectors of the entry.
50D3
LDI ED A0
Copy the low byte of the number of sectors from Register Pair HL to +12H at Register Pair DE, INCrementing both and DECrementing Register Pair BC.
50D5
LDI ED A0
Copy the high byte from Register Pair HL to +13H at Register Pair DE, INCrementing both and DECrementing Register Pair BC.
50D7
LD A,FFH 3E FF
Load Register A with FFH, for the two unused bytes of the record.
50D9
LD (DE),A 12
Store Register A (FFH) to +14H of the record at Register Pair DE.
50DA
INC DE 13
INCrement Register Pair DE by 1 to +15H of the record.
50DB
LD (DE),A 12
Store Register A (FFH) to +15H of the record at Register Pair DE.
50DC
INC DE 13
INCrement Register Pair DE by 1 to the place after the record.
50DD
LD A,2BH 3E 2B
Load Register A with 2BH, the + that ends the list.
50DF
LD (DE),A 12
Store Register A (+) to the buffer at Register Pair DE; Register Pair DE stays on it, so the next record goes over it.
50E0
POP HL E1
Restore Register Pair HL, the entry, from the top of the stack.
50E1
POP BC C1
Restore Register Pair BC, the drive in Register C, from the top of the stack.
50E2
XOR A AF
Set Register A to 00H by XORing it with itself, and set the Z FLAG: the entry is copied.
50E3
RET C9
RETurn with the Z FLAG set and Register Pair DE at the + after the record.
50E4H - The Space Used and Free
Function FFH of RAMDIR@: counts the granules of the GAT, bit by bit for each cylinder (the cylinders less 35 at +CCH), the granules per cylinder from the drive control table, and stores the kilobytes used at +00H-+01H and the kilobytes free at +02H-+03H of the buffer.
50E4
LD A,00H 3E 00
Load Register A with 00H, function 0 of DISKIO%, DCHECK, which checks that the drive is ready.
50E6
GOSUB to 4488H, DISKIO%, to check drive Register C.
50E9
LD A,08H 3E 08
Load Register A with 08H, the error code of Drive not available; the flags are kept.
50EB
RET NZ C0
If the NZ FLAG is set (the drive is not ready), RETurn with error 08H.
50EC
GOSUB to 44A3H, LOCDCT%, for the drive control table of drive Register C in Index Register IY.
50EF
PUSH DE D5
Save Register Pair DE, the buffer, to the top of the stack.
50F0
LD E,00H 1E 00
Load Register E with 00H, sector 0 of the directory, the GAT.
50F2
LD HL,4300H 21 00 43
Point Register Pair HL to 4300H, SYS0/SYS's system buffer.
50F5
LD A,06H 3E 06
Load Register A with 06H, function 6 of DISKIO%, SREAD, which reads a directory sector.
50F7
GOSUB to 4488H, DISKIO%, to read the GAT of drive Register C into the buffer at Register Pair HL.
50FA
POP DE D1
Restore Register Pair DE, the buffer, from the top of the stack; the flags are kept.
50FB
RET NZ C0
If the NZ FLAG is set (a read error), RETurn with the error code in Register A.
50FC
PUSH DE D5
Save Register Pair DE, the buffer, to the top of the stack, for Index Register IX at 511BH.
50FD
LD DE,0000H 11 00 00
Load Register Pair DE with 0000H, the count of free granules.
5100
LD BC,0000H 01 00 00
Load Register Pair BC with 0000H, the count of granules in use.
5103
LD A,(43CCH) 3A CC 43
Load Register A with the number of cylinders less 35 from +CCH of the GAT at 43CCH.
5106
ADD A,23H C6 23
ADD 23H to Register A: the number of cylinders of the diskette.
5108
PUSH AF F5
Save Register Pair AF, the cylinders left, to the top of the stack.
5109
LD A,(IY+10H) FD 7E 10
Load Register A with the granules per cylinder from the drive control table at Index Register IY+10H.
510C
RRC (HL) CB 0E
Rotate the GAT byte at Register Pair HL right: the C FLAG = the bit of the next granule, set when it is in use.
510E
If the C FLAG is set (in use), JUMP to 5112H.
5110
INC DE 13
INCrement Register Pair DE by 1, the count of free granules.
5111
DEC BC 0B
DECrement Register Pair BC by 1, so the INCrement after it leaves the count in use as it was.
5112
INC BC 03
INCrement Register Pair BC by 1, the count of granules in use.
5113
DEC A 3D
DECrement Register A by 1, the granules of this cylinder left.
5114
If the NZ FLAG is set (more granules), JUMP back to 510CH.
5116
INC L 2C
INCrement Register L by 1 to the GAT byte of the next cylinder.
5117
POP AF F1
Restore Register Pair AF, the cylinders left, from the top of the stack.
5118
DEC A 3D
DECrement Register A by 1, the cylinders left.
5119
If the NZ FLAG is set (more cylinders), JUMP back to 5108H.
511B
POP IX DD E1
Restore Index Register IX, the buffer, from the top of the stack.
511D
GOSUB to 5133H to turn the count of free granules in Register Pair DE into kilobytes.
5120
LD (IX+02H),E DD 73 02
Store Register E, the low byte of the kilobytes free, to the buffer at Index Register IX+02H.
5123
LD (IX+03H),D DD 72 03
Store Register D, the high byte of the kilobytes free, to the buffer at Index Register IX+03H.
5126
PUSH BC C5
Save Register Pair BC, the count of granules in use, to the top of the stack.
5127
POP DE D1
Restore Register Pair DE from the top of the stack: Register Pair DE = the count of granules in use.
5128
GOSUB to 5133H to turn the count of granules in use in Register Pair DE into kilobytes.
512B
LD (IX+00H),E DD 73 00
Store Register E, the low byte of the kilobytes used, to the buffer at Index Register IX+00H.
512E
LD (IX+01H),D DD 72 01
Store Register D, the high byte of the kilobytes used, to the buffer at Index Register IX+01H.
5131
XOR A AF
Set Register A to 00H by XORing it with itself, and set the Z FLAG: the space is counted.
5132
RET C9
RETurn through 4485H to the caller of RAMDIR@ with the Z FLAG set.
5133H - Granules to Kilobytes
Register Pair DE = a count of granules: returns Register Pair DE = the count times the sectors per granule (Index Register IY+0FH) divided by 4, the kilobytes of 256 byte sectors.
5133
PUSH BC C5
Save Register Pair BC to the top of the stack.
5134
PUSH HL E5
Save Register Pair HL to the top of the stack.
5135
EX DE,HL EB
Exchange Register Pairs DE and HL: Register Pair HL = the count of granules.
5136
LD A,(IY+0FH) FD 7E 0F
Load Register A with the sectors per granule from the drive control table at Index Register IY+0FH.
5139
GOSUB to 444EH, MULT@, for Register Pair HL times Register A: the 24 bit number of sectors in Register Pair HL (high) and Register A (low).
513C
LD B,A 47
Load Register B with Register A, the low byte of the number of sectors.
513D
LD A,04H 3E 04
Load Register A with 04H, the sectors in a kilobyte.
513F
GOSUB to 4451H, DIVD@, to divide the high bytes in Register Pair HL by Register A: the quotient in Register Pair HL, the remainder in Register A.
5142
LD D,L 55
Load Register D with Register L, the high byte of the kilobytes.
5143
LD H,A 67
Load Register H with Register A, the remainder, above the low byte.
5144
LD L,B 68
Load Register L with Register B: Register Pair HL = the remainder and the low byte of the number of sectors.
5145
LD A,04H 3E 04
Load Register A with 04H, the sectors in a kilobyte.
5147
GOSUB to 4451H, DIVD@, to divide Register Pair HL by Register A: the low byte of the kilobytes in Register L.
514A
LD E,L 5D
Load Register E with Register L: Register Pair DE = the kilobytes.
514B
POP HL E1
Restore Register Pair HL from the top of the stack.
514C
POP BC C1
Restore Register Pair BC from the top of the stack.
514D
RET C9
RETurn with the kilobytes in Register Pair DE.
514EH - Copy a Drive's Name
Copies the two character name of drive Register C from its DCTTBL entry (+02H) to Register Pair DE, which is kept. Register Pair HL returns past the name. A patch (one byte blocks at 514FH and 5162H) changed PUSH HL and POP HL into PUSH BC and POP BC, so Register Pair BC, which the two LDI count down, is kept instead of Register Pair HL.
514E
PUSH DE D5
Save Register Pair DE, the place for the name, to the top of the stack.
514F
PUSH BC C5
Save Register Pair BC to the top of the stack (a patch block: this was PUSH HL).
5150
PUSH DE D5
Save Register Pair DE, the place for the name, to the top of the stack again.
5151
LD A,C 79
Load Register A with Register C, the drive number.
5152
LD HL,44E8H 21 E8 44
Point Register Pair HL to 44E8H, DCTTBL, four bytes for each drive.
5155
ADD A,A 87
ADD Register A to itself: twice the drive number.
5156
ADD A,A 87
ADD Register A to itself: four times the drive number, the offset of its entry.
5157
ADD A,02H C6 02
ADD 02H to Register A, the offset of the name in the entry.
5159
LD E,A 5F
Load Register E with Register A, the offset of the drive's name.
515A
LD D,00H 16 00
Load Register D with 00H: Register Pair DE = the offset of the drive's name.
515C
ADD HL,DE 19
ADD Register Pair DE to Register Pair HL: Register Pair HL = the drive's name in DCTTBL.
515D
POP DE D1
Restore Register Pair DE, the place for the name, from the top of the stack.
515E
LDI ED A0
Copy the first character of the name from Register Pair HL to Register Pair DE, INCrementing both and DECrementing Register Pair BC.
5160
LDI ED A0
Copy the second character from Register Pair HL to Register Pair DE, INCrementing both and DECrementing Register Pair BC.
5162
POP BC C1
Restore Register Pair BC from the top of the stack (a patch block: this was POP HL).
5163
POP DE D1
Restore Register Pair DE, the place of the name, from the top of the stack.
5164
RET C9
RETurn with Register Pair DE at the copied name; a patch block loads this byte again (C9H) before 5165H.
5165H - Read an Entry's Sector
Added by a patch block (5164H-5176H, with the CALL at 507FH): reads the directory sector of logical file number Register B (SYS0/SYS's 449AH) only when its sector, bits 4-0 plus 2, is inside the directory; otherwise returns error 10H (Illegal logical file number) with the NZ FLAG.
5165
GOSUB to 44A3H, LOCDCT%, for the drive control table of drive Register C in Index Register IY.
5168
LD A,B 78
Load Register A with Register B, the logical file number.
5169
AND 1FH E6 1F
AND Register A with 1FH, bits 4-0: the directory sector less 2.
516B
ADD A,02H C6 02
ADD 02H to Register A: the directory sector of the entry.
516D
CP (IY+0EH) FD BE 0E
Compare Register A against the directory's length at Index Register IY+0EH: the C FLAG when the sector is inside it.
5170
LD A,0FH 3E 0F
Load Register A with 0FH, one below the error code 10H.
5172
INC A 3C
INCrement Register A by 1 to 10H, Illegal logical file number, with the NZ FLAG; the C FLAG is kept.
5173
If the C FLAG is set (the sector is in the directory), GOSUB to 449AH to read it: Register Pair HL = the entry.
5176
RET C9
RETurn with the result of 449AH, or with the NZ FLAG and Register A = 10H.