LS-DOS 6.3.1 for the Model 4 - SYS2/SYS Disassembled

Page Customization

Introduction/Summary

LS-DOS 6.3.1 SYS2/SYS Disassembly (Model 4)

SYS2/SYS is the system overlay of LS-DOS 6.3.1 that opens files and devices. It is a load module of 1222 bytes in seven load records covering three ranges: 1E00H-22BDH, 22D5H-22DAH and the length word at 23FEH-23FFH, with its transfer address at 1E00H. CKMOD@ on the SYS0/SYS page reads it into 1E00H whenever an SVC asks for overlay 4 and it is not already resident, and RST28 calls 1E00H with the request in Register A: 94H @OPEN, A4H @INIT, B4H @GTDCB, C4H @CKDRV or F4H @RENAME from the SVC stubs, and D4H or E4H from programs that want a name or a password hashed. Bits 6-4 of the request pick the function (1E00H).

@OPEN (1F5EH) takes a specification as @FSPEC leaves it in an FCB. A device (an asterisk and two letters) is found among the device control blocks at 0208H-02FFH (1E59H) and the FCB is routed to it (1F43H). For a file, XFRSPEC (219EH) copies the name, extension and password into work fields, the name and extension are hashed into one byte and the password into a word (1E1EH), and the hash is looked for in the Hash Index Table of the drive given, or of drives 0 to 7 in turn; each drive is first checked by CKDRV (1E7AH), which also reads the GAT and sets the drive's geometry and its bit of YFLAG$ from it. A slot that holds the hash leads to its directory entry, whose name is compared. The owner password gives full access; otherwise the file's protection level is the access, and NO ACCESS refuses the open (2000H). OPNCB (204CH) builds the 32 byte open FCB, with the buffer, the drive, the DEC, the record length and the extents, and checks the record length against the directory.

@INIT (2118H) opens a file or, when it is not found, creates it in a free slot of the directory, trying the middle of the directory first (220AH). @RENAME (2217H) gives a file a new name on the same drive, or a device new letters (229AH). @GTDCB finds a device control block by name, and @CKDRV tells whether a drive is ready and write protected.

The bytes are those of the LS-DOS 6.3.1 level 1H system diskette. The labels are those of the LS-DOS 6.3.1 source code of SYS2, which assembles to this file byte for byte.

Notes

The hash of a name is the eleven characters of name and extension added bit by bit with a rotate after each, never 00H, which marks a free HIT slot. A password hashes to a word; eight spaces, no password, give 4296H. The slot of a file in the HIT is the DEC of its directory entry: bits 7-5 the entry in the sector, bits 4-0 the directory sector less 2.

Only the owner password (DIR+16) is compared. DIR+18 and DIR+19, once the user password, hold the time of the last change in this version; @INIT still writes the password hash there. A file created with a password gets protection NO ACCESS. With bit 7 of NFLAG$ set every password matches. The open bit of DIR+1 is set in the copy of the entry, but written to the disk only when bit 0 of NFLAG$ is set, which it is not in the file.

An FCB that starts with D2H (the letter R with bit 7 set) given to @RENAME is a request of the BACKUP utility: REN0 (2210H) changes the JR Z at 2023H into a JR, so that every open grants full access without the password, until SYS2 is next loaded into the overlay area.

Two places hide an instruction: 2167H and 216AH are 01H bytes (LD BC,nnnn) that pass over the LD A of the next error code. Several operands are changed while SYS2 runs: 1ED7H (the long count of the index test), 1F0AH (a SET or RES instruction for YFLAG$), 1F94H (the drive), 2023H (the opcode patched by REN0), 2036H (SFLAG$ on entry), 2080H (the write protect state), 20B5H (the access level), 20BDH (the exclamation mark bit), 20C5H-20C6H (the buffer) and 2132H (the attribute byte of a new file); SYS2 also stores C9H at 1A79H in SYS0/SYS to keep the debugger off for an EXEC only file.

A successful open of a file with its checks returns Z with Register A = 2AH, the code of the record length error, not 00H (a device, or an open with SFLAG$ bit 0, returns 00H). A drive given that is not ready makes @OPEN return error 24, not a drive error. An open that finds the file marked open in the directory, or the record lengths different, still leaves the FCB open and returns error 41 or 42. With no drive given, @INIT reports error 26 (No directory space available) when no drive can take the file, even when the drives are only write protected or not ready.

Bugs (listed on the LS-DOS reference page): B16, when the GAT cannot be read CKDRV returns the flags of the controller status saved before the read, not the error, and would report the drive ready if that status were 00H (1EF1H, latent); B17, an extension or a password that starts with a digit is taken as missing and the rest of the specification is ignored, so REPORT/1A:1 opens or creates REPORT on any drive (21C3H); B18, @RENAME writes a colon, a drive digit and 0DH into the caller's new name, two bytes past its end when it has no drive, and when the new name exists a whole FCB over it (225AH, latent); B19, @INIT writes the password hash into DIR+18 and DIR+19, the time field of a new entry (218BH, latent); B20, @INIT writes the HIT slot before the directory entry, so a failed directory read or write leaves a slot taken with no entry (2174H, latent).

Variables

Memory Used by SYS2/SYS

Address
Size
Contents
000EH
1 byte
FDDINT$
F3H (DI) when SYSTEM (SMOOTH) is on: CKDRV then halves its index count and tests with interrupts off (1EBAH).
0077H
1 byte
NFLAG$
Bit 7, the network bit, makes every password match (2016H); bit 0 has the open bit written to the directory (2088H). 00H in the file.
007CH
1 byte
SFLAG$
Saved at 1F64H and bits 0-2 cleared on each open; bit 0 (no checks) set by RENAME (2229H, 2265H), bit 1 set for an EXEC only file run by @RUN (203EH), bit 2 reset by INIT (2127H).
0082H
1 byte
YFLAG$
One bit for each drive, set or reset by CKDRV from GAT+CDH bit 3, the new style of directory dating (1F09H).
0208H-02FFH
248 bytes
Device control blocks
Searched by name (DCB+6, DCB+7) by GTDCB (1E5FH); RENDEV writes a new name (22B9H).
1A79H
1 byte
SET@EXEC
The debugger hook that RST28 puts back after the SVC; C9H is stored for an EXEC only file (2045H).
1D00H-1DFFH
256 bytes
SBUFF$
The GAT read by CKDRV (1EEEH, GAT+CCH and GAT+CDH at 1DCCH), the HIT (1F9FH) and the directory sectors (1FD3H) in turn.
1ED7H
1 byte
CDCNT operand
The high byte of the long index count, 09H or 04H (1EC5H).
1F0AH
1 byte
BIT1
The second byte of SET n,(HL) or RES n,(HL) for YFLAG$ (1F03H).
1F94H
1 byte
OPEN2 operand
The drive asked for, FFH for none (21ABH, 21D4H), then the drive the file was found on (1FF8H).
2023H
1 byte
WASMAT
The opcode of JR Z, made a JR by REN0 (2212H).
2036H
1 byte
OPEN14 operand
SFLAG$ as it was on entry to OPEN1 (1F64H), tested for bits 2 (2037H) and 0 (2059H).
2080H
1 byte
OPNCB9 operand
80H when the drive last checked by CKDRV is write protected (1F2AH).
20B5H
1 byte
OPNCB1 operand
The access level for FCB+1 (2047H, 211BH).
20BDH
1 byte
OPNCB3 operand
08H when the specification ends with an exclamation mark (21E5H).
20C5H-20C6H
2 bytes
OPNCB4 operand
The buffer address for FCB+3 and FCB+4 (1F77H).
2132H
1 byte
INIT0
The attribute byte of a new file: 10H (2120H), or 17H with a password (21EBH).
22BEH-22C5H
8 bytes
PSWDBUF
The password of the specification, padded with spaces (21A0H, 21CAH).
22C6H-22D0H
11 bytes
NAME$EXT and FILE$EXT
The name and the extension, padded with spaces (21B0H, 21C3H).
22D1H-22D4H
4 bytes
PW$HASH1 and PW$HASH2
The hash of the password given, twice (1F8DH, 1F90H).
22D5H-22DAH
6 bytes
ERN init and DIR$INIT
0000H and four bytes for DIR+20, DIR+21 and DIR+0 to DIR+3 of a new entry (2133H, 2184H).
22DBH
1 byte
LREC$
The logical record length asked for (1F74H).
22DCH
1 byte
FILEHASH
The hash of the name and extension (1E2AH).
23FEH-23FFH
2 bytes
Overlay length
04DBH, the length of SYS2 read by SYSTEM (SYSRES).

Routines of Other Files Called

AddressRoutine
1566HLNKFCB@ (SYS0/SYS): saves the registers, points Index Register IX at the FCB and plants RESTREG (1F5EH, 2118H, 2217H).
1803H@DIRWR (SYS0/SYS): writes a directory sector (208DH, 2194H, 2287H).
181FH@SCNHIT (SYS0/SYS): finds a free HIT slot (220CH).
1897H, 1898H@HITRD and @HITWR (SYS0/SYS): read and write the HIT (1F9FH, 1FC9H, 2147H, 228AH; 2174H, 2297H).
18BBH@DIRRD (SYS0/SYS): reads the directory sector of an entry (1FD3H, 2177H, 2274H).
18D8H@RDSSC (SYS0/SYS): reads the GAT (1EEEH).
18F7H@DIRCYL (SYS0/SYS): the directory cylinder of a drive (1EE7H).
19C8H, 19D0H, 19D4H@RSTOR, @SEEK and @RSLCT (SYS0/SYS): restore, seek and the controller status (1E97H, 1EA2H, 1EA8H, 1F39H).
1A1EH@GTDCT (SYS0/SYS): the drive code table entry of a drive (1E7CH).

Disassembly

1E00H - SYS2: Entry and the Function Dispatcher

SYS2/SYS is loaded at 1E00H by CKMOD@ (1A7FH on the SYS0/SYS page) whenever an SVC asks for overlay 4 and it is not already resident, and RST28 calls 1E00H with Register A holding the request. Bits 6-4 of the request pick the function: 94H @OPEN, A4H @INIT, B4H @GTDCB, C4H @CKDRV and F4H @RENAME come from the SVC stubs at 198AH-1996H; D4H hashes a file name and E4H hashes a password for the utilities that issue those requests themselves (ATTRIB, PURGE, BACKUP, FORMAT and REPAIR use E4H). Request 84H only loads the overlay and returns (BACKUP sends it to have SYS2 in memory).

1E00SYS2
AND 70H E6 70
SYS2: mask Register A (the request handed over by RST28: 94H, A4H, B4H, C4H, D4H, E4H or F4H) with 70H, keeping bits 6-4, the function number times 10H.
1E02
RET Z C8
Return at once if Register A is 00H: function 0 (request 84H) only gets SYS2 loaded; no SVC stub sends it, BACKUP does (GETSYS2).
1E03
CP 10H FE 10
Compare Register A with 10H, the function of @OPEN (request 94H, SVC 59, from the stub at 198AH).
1E05
If Register A is 10H, jump to 1F5EH (OPEN) to open an existing file or device named in the FCB at Register Pair DE.
1E08
CP 20H FE 20
Compare Register A with 20H, the function of @INIT (request A4H, SVC 58, from the stub at 198DH).
1E0A
If Register A is 20H, jump to 2118H (INIT) to open the file named in the FCB at Register Pair DE, creating it if it does not exist.
1E0D
CP 70H FE 70
Compare Register A with 70H, the function of @RENAME (request F4H, SVC 56, from the stub at 1996H).
1E0F
If Register A is 70H, jump to 2217H (RENAME) to give the file or device in the FCB at Register Pair DE the name at Register Pair HL.
1E12
CP 30H FE 30
Compare Register A with 30H, the function of @GTDCB (request B4H, SVC 82, from the stub at 1990H).
1E14
If Register A is 30H, jump relative to 1E5FH (GTDCB) to find the device control block whose name is in Register Pair DE.
1E16
CP 40H FE 40
Compare Register A with 40H, the function of @CKDRV (request C4H, SVC 33, from the stub at 1993H).
1E18
If Register A is 40H, jump relative to 1E7AH (CKDRV) to check that drive Register C is ready with a formatted diskette.
1E1A
CP 60H FE 60
Compare Register A with 60H, function 6 (request E4H), which hashes the 8 character password at Register Pair DE into Register Pair HL.
1E1C
If Register A is 60H, jump relative to 1E2EH (HASHPSWD). What is left is 50H (request D4H), which falls into HASHNAME below.
1E1EHASHNAME
LD B,0BH 06 0B
HASHNAME: load Register B with 0BH (11), the length of a name and extension field. Function 5 (request D4H) comes here with Register Pair HL at the 11 characters; OPEN (1F84H) and RENAME (2293H) call here with Register Pair HL = 22C6H (NAME$EXT).
1E20
XOR A AF
Clear Register A to 00H, the hash so far; each character is added into it below.
1E21HNAME1
XOR (HL) AE
HNAME1: Exclusive OR the character at Register Pair HL into Register A (an addition of the bits modulo 2).
1E22
INC HL 23
Increment Register Pair HL to the next character of the field.
1E23
RLCA 07
Rotate Register A left one bit (bit 7 into bit 0), so that each character's bits fall on different places of the hash.
1E24
Decrement Register B and loop back to 1E21H (HNAME1) until all 11 characters are added in.
1E26
OR A B7
OR Register A with itself to test the hash for zero.
1E27
If the hash is not zero, jump relative to 1E2AH (HNAME2) to keep it.
1E29
INC A 3C
Increment Register A from 00H to 01H: 00H marks a free slot of the Hash Index Table, so no file may hash to it.
1E2AHNAME2
LD (22DCH),A 32 DC 22LD (FILEHASH),A
HNAME2: store Register A (the hash, 01H to FFH) into 22DCH (FILEHASH), where OPEN looks for it in the HIT (1FA8H) and INIT stores it into a free slot (2170H).
1E2D
RET C9
Return with the hash in Register A and Register Pair HL past the 11 characters.
1E2EHASHPSWD
LD HL,0007H 21 07 00
HASHPSWD: load Register Pair HL with 0007H, the offset of the last of the 8 characters of the password field at Register Pair DE.
1E31
ADD HL,DE 19
Add Register Pair DE (the password field: 22BEH from OPEN, the caller's field for request E4H) to Register Pair HL: Register Pair HL points to the last character, because the hash runs from right to left.
1E32
EX DE,HL EB
Exchange Register Pair DE with Register Pair HL: Register Pair DE = the last character of the password, Register Pair HL = the start of the field, which is replaced below.
1E33
LD HL,FFFFH 21 FF FF
Load Register Pair HL with FFFFH: the 16 bit shift register that becomes the hash starts with all its bits set.
1E36
LD B,08H 06 08
Load Register B with 08H, the number of characters of a password.
1E38HPSWD1
LD A,(DE) 1A
HPSWD1: load Register A with the character of the password at Register Pair DE.
1E39
PUSH DE D5
Save Register Pair DE (the pointer into the password) on the stack, which frees Register Pair DE for the work below.
1E3A
LD D,A 57
Copy Register A (the character) into Register D.
1E3B
LD E,H 5C
Copy Register H (the high byte of the shift register) into Register E.
1E3C
LD A,L 7D
Load Register A with Register L, the low byte of the shift register.
1E3D
AND 07H E6 07
Mask Register A with 07H, keeping bits 2-0 of the low byte.
1E3F
RRCA 0F
Rotate Register A right one bit: bits 2-0 start to move toward bits 7-5.
1E40
RRCA 0F
Rotate Register A right a second time, moving the three bits on toward bits 7-5.
1E41
RRCA 0F
Rotate Register A right a third time: bits 2-0 of the low byte are now in bits 7-5 of Register A.
1E42
XOR L AD
Exclusive OR Register L (the low byte) into Register A: bits 7-5 of the low byte get its bits 2-0 added modulo 2.
1E43
LD L,A 6F
Copy Register A into Register L, the new low byte of the shift register.
1E44
LD H,00H 26 00
Load Register H with 00H, so that Register Pair HL holds the low byte alone.
1E46
ADD HL,HL 29
Add Register Pair HL to itself: the low byte is shifted left one bit.
1E47
ADD HL,HL 29
Add Register Pair HL to itself again: shifted left two bits.
1E48
ADD HL,HL 29
Add Register Pair HL to itself a third time: shifted left three bits.
1E49
ADD HL,HL 29
Add Register Pair HL to itself a fourth time: Register H holds bits 7-4 of the low byte in its bits 3-0, Register L holds bits 3-0 in its bits 7-4.
1E4A
XOR H AC
Exclusive OR Register H into Register A (the low byte of 1E42H): its bits 7-4 are added into bits 3-0.
1E4B
XOR D AA
Exclusive OR Register D (the password character) into Register A.
1E4C
LD D,A 57
Copy Register A into Register D, the new high byte of the shift register.
1E4D
LD A,L 7D
Load Register A with Register L (bits 3-0 of the low byte, now in bits 7-4).
1E4E
ADD HL,HL 29
Add Register Pair HL to itself once more: Register H holds bits 7-3 of the low byte in its bits 4-0.
1E4F
XOR H AC
Exclusive OR Register H into Register A, the bits of the low byte shifted once more.
1E50
XOR E AB
Exclusive OR Register E (the old high byte of the shift register, copied at 1E3BH) into Register A.
1E51
LD E,A 5F
Copy Register A into Register E, the new low byte of the shift register.
1E52
EX DE,HL EB
Exchange Register Pair DE with Register Pair HL: Register Pair HL is the new shift register (high byte from Register D, low byte from Register E).
1E53
POP DE D1
Restore Register Pair DE from the stack: the pointer into the password.
1E54
DEC DE 1B
Decrement Register Pair DE to the character to the left.
1E55
Decrement Register B and loop back to 1E38H (HPSWD1) until all 8 characters are worked in.
1E57
XOR A AF
Clear Register A to 00H, which also sets the Z flag: success.
1E58
RET C9
Return with the password hash in Register Pair HL. OPEN stores it at 1F8DH; ATTRIB, PURGE, BACKUP, FORMAT and REPAIR take it from Register Pair HL after a request E4H. Eight spaces, a blank password, hash to 4296H.

1E59H - GETDCB and GTDCB: @GTDCB, Find a Device Control Block

@GTDCB (SVC 82, request B4H) looks through the device control blocks at 0208H-02FFH, 31 blocks of 8 bytes, for one whose name (DCB+6 and DCB+7) is the two letters in Register Pair DE, Register E the first. It returns Z with Register Pair HL at the block, or NZ with error 8 (Device not available). A name of 0000H finds the first free block. GETDCB takes the name from FCB+1 and FCB+2, the letters after the asterisk of a device specification, for DEVOPEN and RENDEV.

1E59GETDCB
LD E,(IX+01H) DD 5E 01
GETDCB: load Register E with FCB+1 at Index Register IX+01H, the first letter of the device name after the asterisk.
1E5C
LD D,(IX+02H) DD 56 02
Load Register D with FCB+2 at Index Register IX+02H, the second letter of the device name.
1E5FGTDCB
LD HL,0208H 21 08 02LD HL,KIDCB$
GTDCB: point Register Pair HL to 0208H (KIDCB$), the first device control block. @GTDCB (request B4H from 1990H) enters here with the name in Register Pair DE.
1E62DEV1
PUSH HL E5
DEV1: save Register Pair HL (the start of this DCB) on the stack.
1E63
LD A,L 7D
Load Register A with Register L, the low byte of the DCB's address.
1E64
ADD A,06H C6 06
Add 06H to Register A, the offset of the name field.
1E66
LD L,A 6F
Copy Register A into Register L: Register Pair HL points to DCB+6, the first letter of the DCB's name.
1E67
LD A,(HL) 7E
Load Register A with the first letter of the name at Register Pair HL.
1E68
INC L 2C
Increment Register L: Register Pair HL points to DCB+7, the second letter.
1E69
CP E BB
Compare Register A with Register E, the first letter asked for.
1E6A
If they differ, jump relative to 1E72H (DEV2) to try the next DCB.
1E6C
LD A,(HL) 7E
Load Register A with the second letter of the name at Register Pair HL.
1E6D
CP D BA
Compare Register A with Register D, the second letter asked for.
1E6E
If they differ, jump relative to 1E72H (DEV2) to try the next DCB.
1E70
POP HL E1
Restore Register Pair HL from the stack: the start of the DCB whose name matches.
1E71
RET C9
Return Z (from the CP) with Register Pair HL at the device control block.
1E72DEV2
POP AF F1
DEV2: restore the saved start of the DCB from the stack into Register Pair AF, only to drop it; Register Pair HL stays at DCB+7.
1E73
INC L 2C
Increment Register L: Register Pair HL points to DCB+8, the start of the next block.
1E74
If Register L did not wrap to 00H, jump back to 1E62H (DEV1): the last block is 02F8H-02FFH.
1E76
LD A,08H 3E 08
Load Register A with 08H, error 8 (Device not available): no DCB has the name.
1E78
OR A B7
OR Register A with itself to set the NZ flag.
1E79
RET C9
Return NZ with Register A = 08H; Register Pair HL is left at 0200H.

1E7AH - CKDRV: @CKDRV, Check a Drive

@CKDRV (SVC 33, request C4H) checks that drive Register C is enabled and holds a formatted diskette that turns. For a floppy drive it brings the head to a valid cylinder, waits for an index pulse (unless bit 7 of DCT+4 says not to), reads the GAT and updates the drive code table from it: the highest cylinder from GAT+CCH and the sides from GAT+CDH bit 5. For every drive it sets or resets the drive's bit of YFLAG$ from GAT+CDH bit 3. It returns Z when the drive is ready, with the Carry flag set for a write protected diskette or drive, and NZ when it is not. OPEN and INIT call it for each drive they search, and leave the write protect state at 2080H for OPNCB.

1E7ACKDRV
PUSH IY FD E5
CKDRV: save Index Register IY (the caller's value) on the stack, as the disk calls below need it. @CKDRV (request C4H from 1993H) enters here with the drive number in Register C; OPEN (1F9AH) and INIT (2140H) call here.
1E7C
Call @GTDCT at 1A1EH (on the SYS0/SYS page): Index Register IY = the drive code table entry of drive Register C.
1E7F
LD A,(IY+00H) FD 7E 00
Load Register A with DCT+0 at Index Register IY+00H: C3H (JP) when the drive is enabled, C9H (RET) when it is disabled.
1E82
CP C3H FE C3
Compare Register A with C3H, the JP of an enabled drive.
1E84
If the drive is disabled, jump to 1F31H (CKDR5) to restore Index Register IY and return NZ, with Register A = the RET byte C9H and the Carry flag clear.
1E87
PUSH HL E5
Save Register Pair HL (the caller's value) on the stack.
1E88
PUSH DE D5
Save Register Pair DE (the caller's value) on the stack.
1E89
BIT 3,(IY+03H) FD CB 03 5E
Test bit 3 of DCT+3 at Index Register IY+03H, set for a hard drive.
1E8D
For a hard drive, jump relative to 1EA8H (CKDRV1A): no cylinder check and no seek.
1E8F
LD A,(IY+06H) FD 7E 06
Load Register A with DCT+6 at Index Register IY+06H, the highest cylinder of the drive.
1E92
CP (IY+05H) FD BE 05
Compare Register A with DCT+5 at Index Register IY+05H, the cylinder the head is on (FFH when it is not known, as the start-up leaves it).
1E95
If the current cylinder is not above the highest (No Carry), jump relative to 1E9DH (CKDRV1).
1E97
Call @RSTOR at 19C8H (on the SYS0/SYS page) to step drive Register C back to cylinder 0.
1E9A
If the restore failed (NZ, Register A the error), jump to 1F40H (CKDR7A) to return NZ.
1E9DCKDRV1
LD D,(IY+05H) FD 56 05
CKDRV1: load Register D with DCT+5 at Index Register IY+05H, the cylinder the head is on.
1EA0
LD E,00H 1E 00
Load Register E with 00H, sector 0, the head stays on the cylinder it is on.
1EA2
Call @SEEK at 19D0H (on the SYS0/SYS page) to seek drive Register C to cylinder Register D, sector Register E: the drive is selected, its motor started and the controller's track register set.
1EA5
If the seek failed (NZ, Register A the error), jump to 1F40H (CKDR7A) to return NZ.
1EA8CKDRV1A
CKDRV1A: call @RSLCT at 19D4H (on the SYS0/SYS page), the driver's function 7, which waits until the controller is not busy and returns Z with the controller status in Register A.
1EAB
If the drive does not answer (NZ), jump to 1F40H (CKDR7A) to return NZ.
1EAE
BIT 3,(IY+03H) FD CB 03 5E
Test bit 3 of DCT+3 at Index Register IY+03H again, the hard drive bit.
1EB2
For a hard drive, jump relative to 1EE6H (CKDR2B): there are no index pulses to test.
1EB4
BIT 4,(IY+04H) FD CB 04 66
Test bit 4 of DCT+4 at Index Register IY+04H, set for an alien drive (one with a driver of its own).
1EB8
For an alien drive, jump relative to 1EE6H (CKDR2B) without the index pulse test.
1EBA
LD A,(000EH) 3A 0E 00LD A,(FDDINT$)
Load Register A with the byte at 000EH (FDDINT$): F3H (DI) when SYSTEM (SMOOTH) is on, 00H (NOP) when it is off; the file has SMOOTH on.
1EBD
OR A B7
OR Register A with itself to test it for zero.
1EBE
LD A,09H 3E 09
Load Register A with 09H, the high byte of the long count of index tests; the LD keeps the Z flag of the OR.
1EC0
If SMOOTH is off (Register A was 00H), jump relative to 1EC5H (INTRON) with the count 09H.
1EC2
SRL A CB 3F
Shift Register A right one bit: 04H, about half the count, as the loop below runs faster with no interrupts.
1EC4
DI F3
Disable interrupts for the index test when SMOOTH is on; they come back on at 1EDDH or 1F2EH.
1EC5INTRON
LD (1ED7H),A 32 D7 1E
INTRON: store Register A (09H, or 04H with SMOOTH) into 1ED7H, the operand of the LD H at 1ED6H (CDCNT).
1EC8
LD HL,0020H 21 20 00
Load Register Pair HL with 0020H (32), the short count of index tests.
1ECBCKDR1
CKDR1: call INDEX at 1F34H, which counts Register Pair HL down and returns NZ while the index hole is under the sensor (status bit 1 in Register A); when the count runs out it leaves through CKDR7 with NZ.
1ECE
Loop back to 1ECBH (CKDR1) while an index pulse is on: first wait for it to end.
1ED0
BIT 7,(IY+04H) FD CB 04 7E
Test bit 7 of DCT+4 at Index Register IY+04H, the bit that skips the wait for an index pulse (set in the file for drive 0, DCT+4 = C1H).
1ED4
If it is set, jump relative to 1EE6H (CKDR2B) without waiting for a pulse.
1ED6CDCNT
LD H,00H 26 00
CDCNT: load Register H with the long count's high byte, the operand at 1ED7H stored at 1EC5H (09H, or 04H with SMOOTH; 00H in the file). Register L keeps what the short count left.
1ED8CKDR2
CKDR2: call INDEX at 1F34H: Z while there is no index pulse.
1EDB
Loop back to 1ED8H (CKDR2) until an index pulse comes, which shows that a diskette turns in the drive. When none comes before Register Pair HL runs out, INDEX leaves through CKDR7 with NZ: no diskette, or an open door.
1EDD
EI FB
Enable interrupts again; they were off from 1EC4H when SMOOTH is on.
1EDE
LD HL,0020H 21 20 00
Load Register Pair HL with 0020H (32), the short count for the end of the pulse.
1EE1CKDR2A
CKDR2A: call INDEX at 1F34H: NZ while the index pulse is on.
1EE4
Loop back to 1EE1H (CKDR2A) until the pulse ends, so the drive is left between two pulses.
1EE6CKDR2B
PUSH AF F5
CKDR2B: save Register Pair AF on the stack: Register A = the last controller status read, whose bit 6 is set for a write protected diskette.
1EE7
Call @DIRCYL at 18F7H (on the SYS0/SYS page): Register D = DCT+9 of drive Register C, the directory cylinder.
1EEA
LD HL,1D00H 21 00 1DLD HL,SBUFF$
Point Register Pair HL to 1D00H (SBUFF$), the system buffer.
1EED
LD E,L 5D
Copy Register L (00H) into Register E: sector 0 of the directory cylinder, the GAT.
1EEE
Call @RDSSC at 18D8H (on the SYS0/SYS page) to read cylinder Register D, sector Register E into SBUFF$ at Register Pair HL: Z when the GAT is read with its system data mark.
1EF1
If the GAT could not be read, jump relative to 1F3FH (CKDR7). CKDR7 restores the saved Register Pair AF and returns the flags of OR A on the controller status, not the read error; were that status 00H, the drive would be reported ready, with 2080H, YFLAG$ and DCT+6 left as an earlier call set them (bug B16).
1EF3
LD DE,(1DCCH) ED 5B CC 1D
Load Register Pair DE from 1DCCH-1DCDH, GAT+CCH and GAT+CDH: Register E = the number of cylinders above 35, Register D = the format byte (bit 5 two sided, bit 3 the new style of directory dating).
1EF7
LD A,C 79
Copy Register C (the drive number, 0 to 7) into Register A.
1EF8
RLCA 07
Rotate Register A left: the drive number starts to move toward bits 5-3.
1EF9
RLCA 07
Rotate Register A left a second time, moving the drive number on toward bits 5-3.
1EFA
RLCA 07
Rotate Register A left a third time: the drive number is in bits 5-3 of Register A.
1EFB
OR C6H F6 C6
OR C6H into Register A: C6H plus 8 times the drive is the second byte of SET n,(HL), with n = the drive number.
1EFD
BIT 3,D CB 5A
Test bit 3 of Register D (GAT+CDH), set on a diskette that uses the new style of directory dating.
1EFF
If it is set, jump relative to 1F03H (FIXBIT) with the SET instruction.
1F01
XOR 40H EE 40
Exclusive OR 40H into Register A: 86H plus 8 times the drive, the second byte of RES n,(HL).
1F03FIXBIT
LD (1F0AH),A 32 0A 1FLD (BIT1),A
FIXBIT: store Register A into 1F0AH, the second byte of the instruction at 1F09H.
1F06
LD HL,0082H 21 82 00LD HL,YFLAG$
Point Register Pair HL to 0082H (YFLAG$), which has one bit for each drive: set when the diskette in that drive uses the new style of directory dating.
1F09
RLC B CB 00
Set or reset bit n of YFLAG$ at Register Pair HL (0082H) for drive n, with the instruction built at 1F03H: CBH and C6H plus 8n (SET n,(HL)) or 86H plus 8n (RES n,(HL)). In the file the second byte is 00H, which would read as RLC B on Register B; it is always rewritten before it runs.
1F0B
BIT 3,(IY+03H) FD CB 03 5E
Test bit 3 of DCT+3 at Index Register IY+03H, the hard drive bit.
1F0F
For a hard drive, jump relative to 1F23H (CKDR3): its geometry is not taken from the GAT.
1F11
LD A,22H 3E 22
Load Register A with 22H (34), the highest cylinder of a 35 cylinder diskette.
1F13
ADD A,E 83
Add Register E (GAT+CCH, the cylinders above 35) to Register A: the highest cylinder of this diskette, 27H (39) for a 40 cylinder one.
1F14
LD (IY+06H),A FD 77 06
Store Register A into DCT+6 at Index Register IY+06H, the highest cylinder of the drive.
1F17
RES 5,(IY+04H) FD CB 04 AE
Reset bit 5 of DCT+4 at Index Register IY+04H: one sided, until the GAT says otherwise.
1F1B
BIT 5,D CB 6A
Test bit 5 of Register D (GAT+CDH), set for a two sided diskette.
1F1D
If it is one sided, jump relative to 1F23H (CKDR3).
1F1F
SET 5,(IY+04H) FD CB 04 EE
Set bit 5 of DCT+4 at Index Register IY+04H: the diskette is two sided.
1F23CKDR3
POP AF F1
CKDR3: restore Register Pair AF from the stack: Register A = the controller status saved at 1EE6H.
1F24CKDR3A
RLCA 07
CKDR3A: rotate Register A left: status bit 6 (write protect) moves to bit 7.
1F25
OR (IY+03H) FD B6 03
OR DCT+3 at Index Register IY+03H into Register A: its bit 7 is the software write protect of the drive.
1F28
AND 80H E6 80
Mask Register A with 80H: bit 7 is set if the diskette or the drive is write protected.
1F2A
LD (2080H),A 32 80 20
Store Register A (80H or 00H) into 2080H, the operand of the LD A at 207FH (OPNCB9), which OPEN tests before it marks a file open.
1F2D
ADD A,A 87
Add Register A to itself: bit 7 goes into the Carry flag (set for write protect) and Register A becomes 00H with the Z flag set, the drive is ready.
1F2E
EI FB
CKDR4: enable interrupts, which also ends the DI of 1EC4H; EI changes no flags.
1F2F
POP DE D1
Restore Register Pair DE (the caller's value) from the stack.
1F30
POP HL E1
Restore Register Pair HL (the caller's value) from the stack.
1F31CKDR5
POP IY FD E1
CKDR5: restore Index Register IY (the caller's value) from the stack.
1F33
RET C9
Return: Z (ready) with Carry for write protect and Register A = 00H, or NZ (not ready or disabled). Register C is the drive number still.
1F34INDEX
LD A,H 7C
INDEX: load Register A with Register H, the high byte of the count.
1F35
OR L B5
OR Register L into Register A: zero when the count in Register Pair HL has run out.
1F36
When the count is 0000H, jump relative to 1F3FH (CKDR7): the index pulse did not change in time.
1F38
DEC HL 2B
Decrement Register Pair HL, the count of tests.
1F39
Call @RSLCT at 19D4H (on the SYS0/SYS page) to read the controller status into Register A once it is not busy.
1F3C
BIT 1,A CB 4F
Test bit 1 of Register A, the index bit of the controller status.
1F3E
RET C9
Return NZ while the index hole is under the sensor, Z otherwise.
1F3FCKDR7
POP AF F1
CKDR7: restore Register Pair AF from the stack. Coming from INDEX this is the return address of its CALL (1ECEH, 1EDBH or 1EE4H), so Register A = 1EH; coming from 1EF1H it is the controller status saved at 1EE6H.
1F40CKDR7A
OR A B7
CKDR7A: OR Register A with itself: NZ unless Register A is 00H, and the Carry flag clear. Register A holds the error of @RSTOR, @SEEK or @RSLCT, 1EH after a time-out, or the saved controller status after a GAT read error.
1F41
Jump relative to 1F2EH (CKDR4) to enable interrupts, restore Register Pairs DE and HL and Index Register IY, and return NZ.

1F43H - DEVOPEN: Open a Device

A specification that starts with an asterisk names a device. DEVOPEN finds its DCB with GETDCB and turns the FCB into a DCB routed to it: FCB+0 = 10H (routed), FCB+1 and FCB+2 the address of the device's DCB, FCB+3 to FCB+5 zero, FCB+6 and FCB+7 the device name. Character I/O through the FCB then goes to the device.

1F43DEVOPEN
DEVOPEN: call GETDCB at 1E59H to find the DCB named by FCB+1 and FCB+2 (Index Register IX+01H and IX+02H), the two letters after the asterisk; it returns Z with Register Pair HL at the DCB and the name in Register Pair DE.
1F46
RET NZ C0
Return NZ with Register A = 08H (error 8, Device not available) if no DCB has that name.
1F47DEV4
LD B,H 44
DEV4: copy Register H (the high byte of the DCB's address) into Register B.
1F48
LD C,L 4D
Copy Register L (the low byte) into Register C: Register Pair BC = the address of the device's DCB.
1F49
PUSH IX DD E5
Save Index Register IX (the FCB) on the stack, to copy it into Register Pair HL.
1F4B
POP HL E1
Restore it into Register Pair HL: Register Pair HL = the FCB.
1F4C
LD (HL),10H 36 10
Store 10H at FCB+0 (Register Pair HL): bit 4, routed, so the FCB acts as a DCB that passes every request on to the device.
1F4E
INC HL 23
Increment Register Pair HL to FCB+1, the low byte of the routing address.
1F4F
LD (HL),C 71
Store Register C (the low byte of the device's DCB address) at FCB+1 (Register Pair HL).
1F50
INC HL 23
Increment Register Pair HL to FCB+2, the high byte of the routing address.
1F51
LD (HL),B 70
Store Register B (the high byte of the device's DCB address) at FCB+2 (Register Pair HL).
1F52
INC HL 23
Increment Register Pair HL to FCB+3, the first of three bytes cleared.
1F53
XOR A AF
Clear Register A to 00H, which also sets the Z flag returned below.
1F54
LD (HL),A 77
Store Register A (00H) at FCB+3 (Register Pair HL).
1F55
INC HL 23
Increment Register Pair HL to FCB+4, the second byte cleared.
1F56
LD (HL),A 77
Store Register A (00H) at FCB+4 (Register Pair HL).
1F57
INC HL 23
Increment Register Pair HL to FCB+5, the third byte cleared.
1F58
LD (HL),A 77
Store Register A (00H) at FCB+5 (Register Pair HL).
1F59
INC HL 23
Increment Register Pair HL to FCB+6, the first letter of the device name.
1F5A
LD (HL),E 73
Store Register E (the first letter of the device name) at FCB+6 (Register Pair HL).
1F5B
INC HL 23
Increment Register Pair HL to FCB+7, the second letter of the device name.
1F5C
LD (HL),D 72
Store Register D (the second letter) at FCB+7 (Register Pair HL).
1F5D
RET C9
Return Z with Register A = 00H: the device is open. Register Pairs BC, DE and HL are given back their values by RESTREG on the way out.

1F5EH - OPEN: @OPEN, Open an Existing File

@OPEN (SVC 59, request 94H) has Register Pair DE at an FCB holding a specification (as @FSPEC leaves it, ended by 03H), Register Pair HL at a 256 byte buffer and Register B = the logical record length (00H for 256). OPEN copies the parts of the specification into the fields at 22BEH-22D0H, hashes the name and the password, and looks for the hash in the Hash Index Table of the drive given, or of each drive from 0 to 7. For each slot that holds the hash it reads the directory entry (the slot's place is the entry's DEC) and compares the name and extension. INIT (212AH) and RENAME (222BH, 2267H) call OPEN1, after LNKFCB@.

1F5EOPEN
OPEN: call LNKFCB@ at 1566H (on the SYS0/SYS page), which saves Register Pairs HL, DE and BC and the caller's Index Register IX, points Index Register IX at the FCB in Register Pair DE and plants RESTREG (1589H) as the return address; it returns Z with Register A = 00H.
1F61OPEN1
LD A,(007CH) 3A 7C 00LD A,(SFLAG$)
OPEN1: load Register A with SFLAG$ (007CH), the system flags.
1F64
LD (2036H),A 32 36 20
Store Register A into 2036H, the operand of the LD B at 2035H (OPEN14), and the byte OPNCB tests at 2059H: the flags as they were on entry.
1F67
AND F8H E6 F8
Mask Register A with F8H, clearing bits 0 (no file open bit, no LRL test), 1 (an EXEC only file opened by @RUN) and 2 (@LOAD called from @RUN): each open uses them once.
1F69
LD (007CH),A 32 7C 00LD (SFLAG$),A
Store Register A back into SFLAG$ at 007CH, the system flags.
1F6C
LD A,(IX+00H) DD 7E 00
Load Register A with FCB+0 at Index Register IX+00H, the first character of the specification.
1F6F
CP 2AH FE 2A
Compare Register A with 2AH, the asterisk that starts a device specification.
1F71
If it is a device, jump relative to 1F43H (DEVOPEN).
1F73
LD A,B 78
Copy Register B (the logical record length asked for) into Register A.
1F74
LD (22DBH),A 32 DB 22LD (LREC$),A
Store Register A into 22DBH (LREC$), which OPNCB0 puts into FCB+9 and INIT into DIR+4.
1F77
LD (20C5H),HL 22 C5 20
Store Register Pair HL (the buffer) into 20C5H-20C6H, the operand of the LD DE at 20C4H (OPNCB4), which puts it into FCB+3 and FCB+4.
1F7A
PUSH IX DD E5
Save Index Register IX (the FCB) on the stack, to copy it into Register Pair HL.
1F7C
POP HL E1
Restore it into Register Pair HL: Register Pair HL points to the text of the specification.
1F7D
Call XFRSPEC at 219EH to check the specification and copy the password to 22BEH, the name to 22C6H, the extension to 22CEH, the drive into 1F94H and the exclamation mark into 20BDH.
1F80
RET NZ C0
Return NZ with Register A = 13H (error 19, Illegal file name) or 20H (error 32, Illegal drive number) for a bad specification.
1F81
LD HL,22C6H 21 C6 22LD HL,NAME$EXT
Point Register Pair HL to 22C6H (NAME$EXT), the 11 characters of name and extension.
1F84
Call HASHNAME at 1E1EH to hash them into 22DCH (FILEHASH).
1F87
LD DE,22BEH 11 BE 22LD DE,PSWDBUF
Point Register Pair DE to 22BEH (PSWDBUF), the 8 characters of the password (spaces if none was given).
1F8A
Call HASHPSWD at 1E2EH: Register Pair HL = the password hash (4296H for no password).
1F8D
LD (22D1H),HL 22 D1 22LD (PW$HASH1),HL
Store Register Pair HL into 22D1H-22D2H (PW$HASH1), the owner password that INIT writes to DIR+16 of a new file.
1F90
LD (22D3H),HL 22 D3 22LD (PW$HASH2),HL
Store Register Pair HL into 22D3H-22D4H (PW$HASH2), compared with the owner password at 200DH and written by INIT into DIR+18 and DIR+19 of a new file, the field that holds the time of the last change in this version (bug B19).
1F93OPEN2
LD A,00H 3E 00
OPEN2: load Register A with the drive asked for, the operand at 1F94H set by XFRSPEC: 00H to 07H, or FFH when the specification has no drive (00H in the file).
1F95
LD C,A 4F
Copy Register A (the drive) into Register C, the drive to try first.
1F96
INC A 3C
Increment Register A: 00H only when no drive was given (FFH).
1F97
If a drive was given, jump relative to 1F9AH (OPEN3) with it in Register C.
1F99
LD C,A 4F
No drive was given: copy Register A (00H) into Register C, so the search starts with drive 0.
1F9AOPEN3
OPEN3: call CKDRV at 1E7AH: Z if drive Register C is ready with a formatted diskette.
1F9D
If the drive is not ready, jump relative to 1FB2H (OPEN6) to go on with the next drive. When the drive was given, TESTDRV ends the search and the error is 24 (File not in directory), not a drive error.
1F9F
Call @HITRD at 1897H (on the SYS0/SYS page) to read the Hash Index Table of drive Register C into SBUFF$; Register Pair HL = 1D00H, its first slot.
1FA2
RET NZ C0
On a HIT read error return NZ with Register A = 16H (error 22, HIT read error): the search ends here and the other drives are not tried.
1FA3OPEN4
LD A,(HL) 7E
OPEN4: load Register A with the HIT byte at Register Pair HL: the hash of the file whose directory entry has this slot's number as its DEC, or 00H for a free slot.
1FA4
OR A B7
OR Register A with itself to test for a free slot.
1FA5
If the slot is free, jump relative to 1FAFH (OPEN5).
1FA7
PUSH HL E5
Save Register Pair HL (the slot) on the stack.
1FA8
LD HL,22DCH 21 DC 22LD HL,FILEHASH
Point Register Pair HL to 22DCH (FILEHASH), the hash of the name asked for.
1FAB
CP (HL) BE
Compare Register A (the slot's hash) with the hash at Register Pair HL.
1FAC
POP HL E1
Restore Register Pair HL (the slot) from the stack; the POP keeps the flags.
1FAD
If the hashes match, jump relative to 1FD0H (OPEN9) to read the entry.
1FAFOPEN5
INC L 2C
OPEN5: increment Register L to the next slot.
1FB0
Loop back to 1FA3H (OPEN4) until Register L wraps to 00H: all 256 slots are looked at.
1FB2OPEN6
OPEN6: call TESTDRV at 1FBBH: Carry, with Register C advanced, when another drive is to be searched.
1FB5
If there is another drive, jump back to 1F9AH (OPEN3).
1FB7OPEN7
LD A,18H 3E 18
OPEN7: load Register A with 18H, error 24 (File not in directory).
1FB9
OR A B7
OR Register A with itself to set the NZ flag.
1FBA
RET C9
Return NZ with error 24; INIT (212EH) takes this error as the sign to create the file.
1FBBTESTDRV
LD A,(1F94H) 3A 94 1F
TESTDRV: load Register A with the drive asked for, the operand at 1F94H.
1FBE
INC A 3C
Increment Register A: 00H only when no drive was given (FFH).
1FBF
OR A B7
OR Register A with itself: the Carry flag is cleared and the Z flag says whether a drive was given.
1FC0
RET NZ C0
If a drive was given, return No Carry: only that drive is searched.
1FC1
INC C 0C
Increment Register C to the next drive: drives 0 to 7 are searched in turn.
1FC2
LD A,C 79
Copy Register C (the next drive) into Register A.
1FC3
CP 08H FE 08
Compare Register A with 08H: Carry while it is below 8.
1FC5
RET C9
Return Carry if drive Register C (1 to 7) is still to be searched, No Carry after drive 7.
1FC6OPEN8
POP BC C1
OPEN8: the entry is an extended one, not in use, or another name with the same hash. Restore Register Pair BC from the stack (pushed at 1FDCH) to drop it.
1FC7
POP HL E1
Restore Register Pair HL from the stack (the entry, pushed at 1FDBH) to drop it.
1FC8
POP BC C1
Restore Register Pair BC from the stack (pushed at 1FD1H): Register C = the drive.
1FC9
Call @HITRD at 1897H (on the SYS0/SYS page) to read the HIT again into SBUFF$, where the directory read at 1FD3H put its sector.
1FCC
POP HL E1
Restore Register Pair HL from the stack (pushed at 1FD0H): the HIT slot that matched; the POP keeps the flags.
1FCD
RET NZ C0
Return NZ with error 22 (HIT read error) if the read failed.
1FCE
Jump relative to 1FAFH (OPEN5) to go on with the next slot.
1FD0OPEN9
PUSH HL E5
OPEN9: the slot holds the hash. Save Register Pair HL (the slot) on the stack.
1FD1
PUSH BC C5
Save Register Pair BC (Register C the drive) on the stack.
1FD2
LD B,L 45
Copy Register L (the slot, which is the DEC of the directory entry) into Register B.
1FD3
Call @DIRRD at 18BBH (on the SYS0/SYS page) to read the directory sector of entry Register B on drive Register C into SBUFF$: Register Pair HL = the entry.
1FD6
If the read worked, jump relative to 1FDBH (OPEN10).
1FD8
POP BC C1
Restore Register Pair BC from the stack, to leave the stack as it was.
1FD9
POP HL E1
Restore Register Pair HL from the stack, the HIT slot pushed at 1FD0H.
1FDA
RET C9
Return NZ with Register A = 11H (error 17, Directory read error).
1FDBOPEN10
PUSH HL E5
OPEN10: save Register Pair HL (the directory entry) on the stack.
1FDC
PUSH BC C5
Save Register Pair BC (Register B the DEC, Register C the drive) on the stack.
1FDD
BIT 7,(HL) CB 7E
Test bit 7 of DIR+0 at Register Pair HL, set for an extended directory entry (FXDE), which has no name.
1FDF
If it is an extended entry, jump relative to 1FC6H (OPEN8) to go on with the next slot.
1FE1
BIT 4,(HL) CB 66
Test bit 4 of DIR+0 at Register Pair HL, set when the entry is in use.
1FE3
If the entry is not in use, jump relative to 1FC6H (OPEN8).
1FE5
LD A,05H 3E 05
Load Register A with 05H, the offset of the name field in an entry.
1FE7
ADD A,L 85
Add Register L (the low byte of the entry's address) to Register A.
1FE8
LD L,A 6F
Copy Register A into Register L: Register Pair HL points to DIR+5, the name in the entry.
1FE9
LD DE,22C6H 11 C6 22LD DE,NAME$EXT
Point Register Pair DE to 22C6H (NAME$EXT), the name and extension asked for.
1FEC
LD B,0BH 06 0B
Load Register B with 0BH (11), the characters of name and extension.
1FEEOPEN11
LD A,(DE) 1A
OPEN11: load Register A with the character asked for at Register Pair DE.
1FEF
CP (HL) BE
Compare Register A with the character of the entry at Register Pair HL.
1FF0
If they differ, jump relative to 1FC6H (OPEN8): a different file with the same hash.
1FF2
INC HL 23
Increment Register Pair HL to the entry's next character.
1FF3
INC DE 13
Increment Register Pair DE to the next character asked for.
1FF4
Decrement Register B and loop back to 1FEEH (OPEN11) for all 11 characters.
1FF6
POP BC C1
The name matches. Restore Register Pair BC from the stack (pushed at 1FDCH): Register B = the DEC, Register C = the drive.
1FF7
LD A,C 79
Copy Register C (the drive the file is on) into Register A.
1FF8
LD (1F94H),A 32 94 1F
Store Register A into 1F94H, the drive operand of OPEN2: it now names the drive where the file was found.
1FFB
POP HL E1
Restore Register Pair HL from the stack: the directory entry (pushed at 1FDBH).
1FFC
POP AF F1
Restore Register Pair AF from the stack, dropping the Register Pair BC pushed at 1FD1H.
1FFD
POP AF F1
Restore Register Pair AF from the stack, dropping the HIT slot pushed at 1FD0H.
1FFE
PUSH BC C5
Save Register Pair BC (the DEC and the drive) on the stack for OPNCB.
1FFF
PUSH HL E5
Save Register Pair HL (the directory entry) on the stack.

2000H - OPEN: the Password and the Access Level

The file's owner password hash (DIR+16) is compared with the hash of the password given. A match gives full access (level 0). Without it the file's protection level (DIR+0 bits 2-0) is the access, unless it is 7 (NO ACCESS), which returns error 25. An EXEC only file (level 6) opened for @RUN gets READ access for the loader, and the debugger is turned off for any EXEC only open. DIR+18 and DIR+19, once the user password, hold the time of the last change in this version and are not compared. With bit 7 of NFLAG$ set every password matches.

2000
LD A,(HL) 7E
Load Register A with DIR+0 at Register Pair HL, the attribute byte of the entry.
2001
LD (22D7H),A 32 D7 22LD (DIR$INIT),A
Store Register A into 22D7H (DIR$INIT); the byte is not read again on this path (INIT uses the field for a new entry).
2004
AND 07H E6 07
Mask Register A with 07H, keeping bits 2-0, the protection level of the file (0 FULL to 7 NO ACCESS).
2006
LD C,A 4F
Copy Register A (the protection level) into Register C.
2007
LD B,00H 06 00
Load Register B with 00H: Register Pair BC = the protection level; the DEC and the drive are on the stack.
2009
LD A,10H 3E 10
Load Register A with 10H, the offset of the owner password hash in the entry.
200B
ADD A,L 85
Add Register L (the low byte of the entry's address) to Register A.
200C
LD L,A 6F
Copy Register A into Register L: Register Pair HL points to DIR+16, the owner password hash.
200D
LD DE,(22D3H) ED 5B D3 22LD DE,(PW$HASH2)
Load Register Pair DE with the hash of the password given, at 22D3H-22D4H (PW$HASH2).
2011
LD A,(HL) 7E
Load Register A with DIR+16 at Register Pair HL, the low byte of the owner password hash.
2012
INC HL 23
Increment Register Pair HL to DIR+17, the high byte of the owner password hash.
2013
PUSH HL E5
Save Register Pair HL (DIR+17) on the stack, to be restored after the compare.
2014
LD H,(HL) 66
Load Register H with DIR+17 at Register Pair HL, the high byte of the owner password hash.
2015
LD L,A 6F
Copy Register A (the low byte) into Register L: Register Pair HL = the owner password hash.
2016
LD A,(0077H) 3A 77 00LD A,(NFLAG$)
Load Register A with NFLAG$ (0077H), the network flags.
2019
BIT 7,A CB 7F
Test bit 7 of Register A, the network bit, set when the system runs on a network.
201B
If it is clear, jump relative to 201FH (USEPWD) to compare the passwords.
201D
LD D,H 54
Copy Register H into Register D: with the network bit set, the hash given is made the owner's own.
201E
LD E,L 5D
Copy Register L into Register E: Register Pair DE = Register Pair HL, so the compare below always matches.
201FUSEPWD
XOR A AF
USEPWD: clear Register A to 00H (access level 0, FULL) and the Carry flag, for the SBC.
2020
SBC HL,DE ED 52
Subtract Register Pair DE (the password given) from Register Pair HL (the owner password) with the Carry: Z when they are the same.
2022
POP HL E1
Restore Register Pair HL from the stack (DIR+17); the POP keeps the flags.
2023WASMAT
WASMAT: if the owner password was given (Z), jump relative to 2047H (OPEN16) with Register A = 00H: full access. REN0 (2212H) stores 18H over the opcode 28H at 2023H, which makes this a JR 2047H: every open then gets full access, whatever the password, until SYS2 is next loaded into the overlay area.
2025
LD A,C 79
Load Register A with Register C, the protection level of the file.
2026
CP 07H FE 07
Compare Register A with 07H, protection NO ACCESS.
2028
If it is not NO ACCESS, jump relative to 2030H (OPEN13): the protection level is the access granted.
202AOPEN12
POP HL E1
OPEN12: restore Register Pair HL from the stack (the entry, pushed at 1FFFH) to drop it.
202B
POP BC C1
Restore Register Pair BC from the stack (the DEC and the drive) to drop it.
202C
LD A,19H 3E 19
Load Register A with 19H, error 25 (File access denied).
202E
OR A B7
OR Register A with itself to set the NZ flag.
202F
RET C9
Return NZ with error 25: the file needs its owner password.
2030OPEN13
LD A,C 79
OPEN13: load Register A with Register C, the protection level, which is the access granted.
2031
CP 06H FE 06
Compare Register A with 06H, protection EXEC (execute only).
2033
If it is not EXEC, jump relative to 2047H (OPEN16) with the protection level in Register A.
2035OPEN14
LD B,00H 06 00
OPEN14: load Register B with SFLAG$ as it was on entry, the operand at 2036H stored at 1F64H (00H in the file).
2037
BIT 2,B CB 50
Test bit 2 of Register B: set when @RUN called @LOAD, which is opening the file.
2039
If the open is not for @RUN, jump relative to 2042H (OPEN15) with Register A = 06H, EXEC access.
203B
LD HL,007CH 21 7C 00LD HL,SFLAG$
Point Register Pair HL to 007CH (SFLAG$), the system flags.
203E
SET 1,(HL) CB CE
Set bit 1 of SFLAG$ at Register Pair HL: an EXEC only file is being run, so @RUN does not enter the debugger for it.
2040
LD A,05H 3E 05
Load Register A with 05H, READ access, so that the loader can read the file.
2042OPEN15
LD HL,1A79H 21 79 1ALD HL,SET@EXEC
OPEN15: point Register Pair HL to 1A79H (SET@EXEC on the SYS0/SYS page), the operand of the LD A at 1A78H that holds the debugger hook to put back after this SVC.
2045
LD (HL),C9H 36 C9
Store C9H (RET) at 1A79H (Register Pair HL): when RST28 returns from SYS2 it stores C9H into @DBGHK (199FH), and the debugger is off while the EXEC only file is used.
2047OPEN16
LD (20B5H),A 32 B5 20
OPEN16: store Register A (the access level: 00H with the owner password, else the protection level, 05H for an EXEC only file opened by @RUN) into 20B5H, the operand of the LD A at 20B4H (OPNCB1), which becomes bits 2-0 of FCB+1.
204A
POP HL E1
Restore Register Pair HL from the stack: the directory entry in SBUFF$.
204B
POP BC C1
Restore Register Pair BC from the stack: Register B = the DEC, Register C = the drive.

204CH - OPNCB: Open the FCB and Check It

OPNCB has Register Pair HL at the directory entry in SBUFF$, Register B = its DEC, Register C = the drive and Index Register IX = the FCB. It builds the open FCB (OPNCB0) and, unless bit 0 of SFLAG$ was set on entry, checks it: a file marked open in the directory (DIR+1 bit 5) is given READ access with error 41 (File already open); for an access of UPDATE or more on a write protected drive the access becomes READ; otherwise the directory entry is marked open (written to the disk only when bit 0 of NFLAG$ is set) and FCB+0 bit 6 lets the FCB write. Last, the logical record length asked for is compared with DIR+4: a difference returns error 42, with the file open all the same.

204COPNCB
PUSH IY FD E5
OPNCB: save Index Register IY (the caller's value) on the stack. OPEN falls in here; INIT calls here at 2199H for a new file.
204E
PUSH HL E5
Save Register Pair HL (the directory entry) on the stack, to copy it into Index Register IY.
204F
POP IY FD E1
Restore it into Index Register IY: Index Register IY = the directory entry in SBUFF$.
2051
PUSH BC C5
Save Register Pair BC (the DEC and the drive) on the stack.
2052
Call OPNCB0 at 20A5H to build the open FCB at Index Register IX from the entry at Register Pair HL and Register Pair BC.
2055
POP BC C1
Restore Register Pair BC (Register B the DEC, Register C the drive) from the stack.
2056
LD HL,2036H 21 36 20
Point Register Pair HL to 2036H, the operand that holds SFLAG$ as it was on entry (stored at 1F64H).
2059
BIT 0,(HL) CB 46
Test bit 0 of the byte at Register Pair HL (2036H): set by @LOAD, by RENAME (2229H, 2265H) and by programs that want no file open bit.
205B
If bit 0 is clear, jump relative to 2061H (OPNEX1) to do the checks.
205D
XOR A AF
Clear Register A to 00H and set the Z flag: open, with no checks.
205EOPNEX
POP IY FD E1
OPNEX: restore Index Register IY (the caller's value) from the stack.
2060
RET C9
Return with the flags and Register A of the path that came here: Z and 00H (no checks), Z and 2AH (the record lengths agree), NZ and 2AH (error 42), or NZ and the error of @DIRWR.
2061OPNEX1
BIT 5,(IY+01H) FD CB 01 6E
OPNEX1: test bit 5 of DIR+1 at Index Register IY+01H, set while the file is open with UPDATE access or more.
2065
If the file is not marked open, jump relative to 2076H (OPNCB8).
2067
POP IY FD E1
Restore Index Register IY (the caller's value) from the stack.
2069OPNEX2
LD A,(IX+01H) DD 7E 01
OPNEX2: load Register A with FCB+1 at Index Register IX+01H, whose bits 2-0 are the access level just set.
206C
AND F8H E6 F8
Mask Register A with F8H, clearing the access level.
206E
OR 05H F6 05
OR 05H into Register A: access level 5, READ.
2070
LD (IX+01H),A DD 77 01
Store Register A back into FCB+1 at Index Register IX+01H: the FCB may only read.
2073
LD A,29H 3E 29
Load Register A with 29H, error 41 (File already open); the LD keeps the NZ flag of the OR.
2075
RET C9
Return NZ with error 41: the FCB is open with READ access. FRCREAD (20A0H) calls here only for the change to READ.
2076OPNCB8
LD A,(IX+01H) DD 7E 01
OPNCB8: load Register A with FCB+1 at Index Register IX+01H.
2079
AND 07H E6 07
Mask Register A with 07H, keeping the access level.
207B
CP 05H FE 05
Compare Register A with 05H, READ, the levels 5 and up cannot write.
207D
For READ, EXEC or NO ACCESS (5 or more), jump relative to 2096H (OPNCB10): nothing to mark and nothing to protect.
207FOPNCB9
LD A,00H 3E 00
OPNCB9: load Register A with the write protect state, the operand at 2080H stored by CKDRV at 1F2AH for the drive last checked: 80H when it is write protected, 00H otherwise (00H in the file).
2081
RLCA 07
Rotate Register A left: bit 7 (write protected) goes into the Carry flag.
2082
If the drive is write protected, jump relative to 20A0H (FRCREAD) to give READ access only.
2084
SET 5,(IY+01H) FD CB 01 EE
Set bit 5 of DIR+1 at Index Register IY+01H in SBUFF$: the file is open with UPDATE access or more.
2088
LD A,(0077H) 3A 77 00LD A,(NFLAG$)
Load Register A with NFLAG$ (0077H), the network flags.
208B
BIT 0,A CB 47
Test bit 0 of Register A, which asks for the open bit to be written to the directory; NFLAG$ is 00H in the file.
208D
If bit 0 is set, call @DIRWR at 1803H (on the SYS0/SYS page) to write SBUFF$ back to the directory sector of entry Register B on drive Register C.
2090
If the write failed (NZ), jump relative to 205EH (OPNEX) to return its error. When bit 0 was clear the flags are those of the BIT (Z) and the jump is not taken.
2092
SET 6,(IX+00H) DD CB 00 F6
Set bit 6 of FCB+0 at Index Register IX+00H: the file was opened with UPDATE access or more, so the FCB may write to it.
2096OPNCB10
LD A,(IX+09H) DD 7E 09
OPNCB10: load Register A with FCB+9 at Index Register IX+09H, the logical record length asked for.
2099
CP (IY+04H) FD BE 04
Compare Register A with DIR+4 at Index Register IY+04H, the logical record length the file was created with.
209C
LD A,2AH 3E 2A
Load Register A with 2AH, error 42 (Logical record length open fault); the LD keeps the flags of the CP.
209E
Jump relative to 205EH (OPNEX): Z when the lengths agree (Register A is left 2AH), NZ with error 42 when they differ; the FCB is open either way.
20A0FRCREAD
FRCREAD: call OPNEX2 at 2069H to make the access in FCB+1 READ; the 29H it leaves in Register A is not used.
20A3
Jump relative to 2096H (OPNCB10) for the record length check.

20A5H - OPNCB0: Build the Open FCB

OPNCB0 fills the 32 bytes of the FCB at Index Register IX from the directory entry at Register Pair HL and from what OPEN kept: +0 open (80H) with the PDS bit of DIR+0; +1 bit 7 for record I/O (any LRL but 256), bit 5 (the buffer holds no sector yet), bit 3 (the exclamation mark) and the access level; +2 zero; +3 and +4 the buffer; +5 zero; +6 the drive; +7 the DEC; +8 the EOF offset (DIR+3); +9 the LRL asked for; +10 and +11 zero (the next record); +12 and +13 the ending record number (DIR+20); +14 and +15 the first extent, then for each further extent of the entry the count of granules before it and the extent, FFH where there is none.

20A5OPNCB0
EX DE,HL EB
OPNCB0: exchange Register Pair DE with Register Pair HL: Register Pair DE = the directory entry in SBUFF$.
20A6
PUSH IX DD E5
Save Index Register IX (the FCB) on the stack, to copy it into Register Pair HL.
20A8
POP HL E1
Restore it into Register Pair HL: Register Pair HL = FCB+0.
20A9
LD A,(DE) 1A
Load Register A with DIR+0 at Register Pair DE, the attribute byte of the entry.
20AA
AND 20H E6 20
Mask Register A with 20H, keeping bit 5, the Partitioned Data Set bit.
20AC
OR 80H F6 80
OR 80H into Register A: bit 7, the FCB is open.
20AE
LD (HL),A 77
Store Register A at FCB+0 (Register Pair HL).
20AF
INC HL 23
Increment Register Pair HL to FCB+1, the flags byte of the FCB.
20B0
LD A,(22DBH) 3A DB 22LD A,(LREC$)
Load Register A with the logical record length asked for, at 22DBH (LREC$).
20B3
OR A B7
OR Register A with itself: Z for 00H, records of 256 bytes.
20B4OPNCB1
LD A,00H 3E 00
OPNCB1: load Register A with the access level, the operand at 20B5H stored at 2047H (OPEN) or 211BH (INIT, 00H); the LD keeps the flags of the OR.
20B6
For records of 256 bytes, jump relative to 20BAH (OPNCB2): whole sectors are read and written.
20B8
OR 80H F6 80
OR 80H into Register A: bit 7, records shorter than a sector go through the buffer.
20BAOPNCB2
OR 20H F6 20
OPNCB2: OR 20H into Register A: bit 5, the buffer does not hold a sector of the file yet.
20BCOPNCB3
OR 00H F6 00
OPNCB3: OR the operand at 20BDH into Register A: 08H (bit 3, update the directory on each write that moves the end of the file) when the specification ended with an exclamation mark, stored by XFRSPEC at 21E5H; 00H in the file.
20BE
LD (HL),A 77
Store Register A at FCB+1 (Register Pair HL).
20BF
INC HL 23
Increment Register Pair HL to FCB+2, a byte kept at zero by the open.
20C0
XOR A AF
Clear Register A to 00H, the value of FCB+2 and FCB+5.
20C1
LD (HL),A 77
Store Register A (00H) at FCB+2 (Register Pair HL).
20C2
INC HL 23
Increment Register Pair HL to FCB+3, the low byte of the buffer address.
20C3
PUSH DE D5
Save Register Pair DE (the directory entry) on the stack.
20C4OPNCB4
LD DE,0000H 11 00 00
OPNCB4: load Register Pair DE with the buffer address, the operand at 20C5H-20C6H stored at 1F77H (0000H in the file).
20C7
LD (HL),E 73
Store Register E (the low byte of the buffer) at FCB+3 (Register Pair HL).
20C8
INC HL 23
Increment Register Pair HL to FCB+4, the high byte of the buffer address.
20C9
LD (HL),D 72
Store Register D (the high byte of the buffer) at FCB+4 (Register Pair HL).
20CA
INC HL 23
Increment Register Pair HL to FCB+5, the offset in the buffer.
20CB
POP DE D1
Restore Register Pair DE (the directory entry) from the stack.
20CC
LD (HL),A 77
Store Register A (00H) at FCB+5 (Register Pair HL), the offset in the buffer.
20CD
INC HL 23
Increment Register Pair HL to FCB+6, the drive number of the file.
20CE
LD (HL),C 71
Store Register C (the drive) at FCB+6 (Register Pair HL).
20CF
INC HL 23
Increment Register Pair HL to FCB+7, the DEC of its directory entry.
20D0
LD (HL),B 70
Store Register B (the DEC of the directory entry) at FCB+7 (Register Pair HL).
20D1
INC HL 23
Increment Register Pair HL to FCB+8, the EOF offset of the file.
20D2
INC DE 13
Increment Register Pair DE to DIR+1, the directory entry's flags and month.
20D3
INC DE 13
Increment Register Pair DE to DIR+2, the directory entry's day and year.
20D4
INC DE 13
Increment Register Pair DE to DIR+3, the EOF offset.
20D5
LD A,(DE) 1A
Load Register A with DIR+3 at Register Pair DE, the offset of the end of file in its last sector.
20D6
LD (HL),A 77
Store Register A at FCB+8 (Register Pair HL).
20D7
INC HL 23
Increment Register Pair HL to FCB+9, the logical record length.
20D8
INC DE 13
Increment Register Pair DE to DIR+4, the record length of the file.
20D9
LD A,(22DBH) 3A DB 22LD A,(LREC$)
Load Register A with the logical record length asked for, at 22DBH (LREC$).
20DC
LD (HL),A 77
Store Register A at FCB+9 (Register Pair HL): the FCB uses the length asked for, which OPNCB10 compares with DIR+4.
20DD
INC HL 23
Increment Register Pair HL to FCB+10, the low byte of the next record number.
20DE
XOR A AF
Clear Register A to 00H, the value of the next record number: the file starts at record 0.
20DF
LD (HL),A 77
Store Register A (00H) at FCB+10 (Register Pair HL), the low byte of the next record number.
20E0
INC HL 23
Increment Register Pair HL to FCB+11, the high byte of the next record number.
20E1
LD (HL),A 77
Store Register A (00H) at FCB+11 (Register Pair HL), the high byte of the next record number.
20E2
INC HL 23
Increment Register Pair HL to FCB+12, the low byte of the ending record number.
20E3
SET 4,E CB E3
Set bit 4 of Register E: Register Pair DE goes from DIR+4 to DIR+20, the ending record number (entries start on 32 byte boundaries).
20E5
LD BC,0002H 01 02 00
Load Register Pair BC with 0002H, the two bytes of the ending record number.
20E8
EX DE,HL EB
Exchange Register Pair DE with Register Pair HL: Register Pair HL = DIR+20, Register Pair DE = FCB+12.
20E9
LDIR ED B0
Copy Register Pair BC (2) bytes from Register Pair HL to Register Pair DE: FCB+12 and FCB+13 = DIR+20 and DIR+21. Register Pair BC ends at 0000H, the count of granules below.
20EB
EX DE,HL EB
Exchange Register Pair DE with Register Pair HL: Register Pair DE = DIR+22, the first extent, Register Pair HL = FCB+14.
20EC
LD A,05H 3E 05
Load Register A with 05H, the extent fields of a directory entry (DIR+22 to DIR+31).
20EE
PUSH AF F5
Save Register Pair AF (the count of fields) on the stack.
20EFOPNCB5
LD A,(DE) 1A
OPNCB5: load Register A with the first byte of the extent at Register Pair DE, its cylinder.
20F0
LD (HL),A 77
Store Register A in the FCB at Register Pair HL.
20F1
INC HL 23
Increment Register Pair HL in the FCB, the second byte of the extent goes next.
20F2
INC DE 13
Increment Register Pair DE to the extent's second byte.
20F3
LD A,(DE) 1A
Load Register A with the second byte of the extent at Register Pair DE: bits 7-5 the first granule, bits 4-0 the granules less one.
20F4
LD (HL),A 77
Store Register A in the FCB at Register Pair HL.
20F5
INC HL 23
Increment Register Pair HL in the FCB, the next field of the FCB.
20F6
AND 1FH E6 1F
Mask Register A with 1FH, the granules of the extent less one.
20F8
INC A 3C
Increment Register A: the number of granules of the extent.
20F9
ADD A,C 81
Add Register C (the low byte of the granules so far) to Register A.
20FA
LD C,A 4F
Copy Register A into Register C, the low byte of the granules so far.
20FB
If there was no carry, jump relative to 20FEH.
20FD
INC B 04
Increment Register B, the high byte of the granules so far: Register Pair BC = the granules of the file up to the end of this extent.
20FE
POP AF F1
Restore Register Pair AF from the stack: Register A = the fields still to look at.
20FF
DEC A 3D
Decrement Register A, one extent field fewer to look at.
2100
RET Z C8
Return when all 5 fields are moved (Register A is 00H).
2101
PUSH AF F5
Save Register Pair AF (the count of fields) on the stack again.
2102
INC DE 13
Increment Register Pair DE to the next extent field of the entry.
2103
LD A,(DE) 1A
Load Register A with its first byte at Register Pair DE: the cylinder, FEH for a link to an extended entry, FFH when unused.
2104
CP FEH FE FE
Compare Register A with FEH. FEH links to an extended entry, FFH is unused.
2106
For FEH or FFH (No Carry), jump relative to 210EH (OPNCB6): no more extents in this entry.
2108
LD (HL),C 71
Store Register C (the low byte of the granules before this extent) in the FCB at Register Pair HL.
2109
INC HL 23
Increment Register Pair HL in the FCB, the high byte of the count goes next.
210A
LD (HL),B 70
Store Register B (the high byte) in the FCB at Register Pair HL.
210B
INC HL 23
Increment Register Pair HL in the FCB, where the extent itself goes next.
210C
Jump relative to 20EFH (OPNCB5) to move the extent itself.
210EOPNCB6
POP AF F1
OPNCB6: restore Register Pair AF from the stack: Register A = the fields not filled (1 to 4).
210F
RLCA 07
Rotate Register A left: twice the count, the fields not filled times two.
2110
RLCA 07
Rotate Register A left again: four bytes of the FCB for each field not filled.
2111
LD B,A 47
Copy Register A into Register B, the count of bytes to fill.
2112OPNCB7
LD (HL),FFH 36 FF
OPNCB7: store FFH in the FCB at Register Pair HL. INIT calls here (2190H) to fill the extent fields of a new entry with Register B = 0AH.
2114
INC HL 23
Increment Register Pair HL to the next byte, of the FCB or the directory entry.
2115
Decrement Register B and loop back to 2112H (OPNCB7) until Register B bytes are filled.
2117
RET C9
Return to OPNCB or INIT: all 32 bytes of the FCB are now set.

2118H - INIT: @INIT, Open or Create a File

@INIT (SVC 58, request A4H) takes the same registers as @OPEN. It first tries OPEN1: an existing file is opened (Z, Carry clear). On error 24 it creates the file: on the drive given, or on the first drive from 0 up that is ready, not write protected and has a free HIT slot. The new entry gets the attribute byte 10H (in use, FULL) or 17H (protection NO ACCESS) when a password was given, the record length asked for, the name, the owner password (DIR+16) and the time field (DIR+18) both set to the hash of the password given (bug B19), an ending record number of 0 and no extents; the HIT slot gets the name's hash. OPNCB then opens it, and INIT returns with the Carry flag set. With no drive given and no drive usable the error is 26 (No directory space available); for the drive given it is 32 (not ready), 15 (write protected) or 26.

2118INIT
INIT: call LNKFCB@ at 1566H (on the SYS0/SYS page) to save Register Pairs HL, DE and BC and the caller's Index Register IX, point Index Register IX at the FCB in Register Pair DE and plant RESTREG; it returns Register A = 00H.
211B
LD (20B5H),A 32 B5 20
Store Register A (00H, FULL) into 20B5H, the access level that OPNCB1 puts into FCB+1 for a new file; OPEN stores the real access there when the file exists.
211E
LD A,10H 3E 10
Load Register A with 10H, the attribute byte of a new entry: bit 4 in use, protection 0 (FULL).
2120
LD (2132H),A 32 32 21LD (INIT0),A
Store Register A into 2132H, the operand of the LD A at 2131H; XFRSPEC replaces it with 17H (protection NO ACCESS) when the specification has a password.
2123
PUSH HL E5
Save Register Pair HL (the buffer) on the stack.
2124
LD HL,007CH 21 7C 00LD HL,SFLAG$
Point Register Pair HL to 007CH (SFLAG$), the system flags.
2127
RES 2,(HL) CB 96
Reset bit 2 of SFLAG$ at Register Pair HL: this open is not one by @RUN, so an EXEC only file keeps EXEC access.
2129
POP HL E1
Restore Register Pair HL (the buffer) from the stack.
212A
Call OPEN1 at 1F61H to open the file if it exists.
212D
RET Z C8
Return Z (Carry clear) if the file existed and is now open.
212E
CP 18H FE 18
Compare Register A (the error) with 18H, error 24 (File not in directory).
2130
RET NZ C0
Return NZ with any other error, such as 19, 22, 25 or 42.
2131
LD A,10H 3E 10
Load Register A with the attribute byte of the new entry, the operand at 2132H: 10H, or 17H when a password was given.
2133
LD (22D7H),A 32 D7 22LD (DIR$INIT),A
Store Register A into 22D7H (DIR$INIT), the first of the five bytes copied into DIR+0 to DIR+4 at 2184H.
2136
LD A,(1F94H) 3A 94 1F
Load Register A with the drive asked for, the operand at 1F94H: 00H to 07H, or FFH.
2139
LD C,A 4F
Copy Register A (the drive) into Register C, the drive to try first.
213A
INC A 3C
Increment Register A: 00H only when no drive was given (FFH).
213B
PUSH AF F5
Save Register Pair AF (the result of the INC) on the stack; INIT1 takes it off again.
213C
If a drive was given, jump relative to 213FH (INIT1) with it in Register C.
213E
LD C,A 4F
No drive was given: copy Register A (00H) into Register C, to try drive 0 first.
213FINIT1
POP AF F1
INIT1: restore Register Pair AF from the stack (pushed at 213BH or 2151H); it is dropped, the POP keeps the stack even.
2140
Call CKDRV at 1E7AH: Z if drive Register C is ready, with the Carry flag set when it is write protected.
2143
If the drive is not ready, jump relative to 2151H (INIT2).
2145
If the drive is write protected (Carry), jump relative to 2151H (INIT2).
2147
Call @HITRD at 1897H (on the SYS0/SYS page) to read the Hash Index Table of drive Register C into SBUFF$.
214A
RET NZ C0
Return NZ with error 22 (HIT read error) if it could not be read.
214B
Call SPRHIT at 220AH to find a free slot in the HIT: Z with Register Pair HL at it.
214E
If there is a free slot, jump relative to 216FH (INIT4) to make the entry.
2150
XOR A AF
Clear Register A to 00H: the flags Z and No Carry stand for a drive that is ready but whose directory is full.
2151INIT2
PUSH AF F5
INIT2: save Register Pair AF on the stack: the result for the drive just tried (NZ not ready, Carry write protected, Z and No Carry full).
2152
Call TESTDRV at 1FBBH: Carry, with Register C advanced, when another drive is to be tried.
2155
If there is another drive, jump back to 213FH (INIT1).
2157
LD A,(1F94H) 3A 94 1F
Load Register A with the drive asked for, the operand at 1F94H.
215A
INC A 3C
Increment Register A: 00H only when no drive was given (FFH).
215B
If a drive was given, jump relative to 2160H (INIT2A) to report why it could not be used.
215D
POP AF F1
No drive was given: restore Register Pair AF from the stack, dropping the last drive's result.
215E
Jump relative to 2165H (ERR26): every drive is not ready, write protected or full, and the error is always 26.
2160INIT2A
POP AF F1
INIT2A: restore Register Pair AF from the stack: the result for the drive asked for.
2161
If that drive is not ready (NZ), jump relative to 216BH (ERR32).
2163
If that drive is write protected (Carry), jump relative to 2168H (ERR15).
2165ERR26
LD A,1AH 3E 1A
ERR26: load Register A with 1AH, error 26 (No directory space available).
2167
DEFB 01H 01
2167H: 01H, the opcode of LD BC,nnnn. Reached from 2165H, it takes 3EH 0FH (the LD A,0FH at 2168H) as its operand, so Register Pair BC gets 0F3EH and error 26 stays in Register A; Register Pair BC is given back its value by RESTREG.
2168ERR15
LD A,0FH 3E 0F
ERR15: load Register A with 0FH, error 15 (Write protected disk).
216A
DEFB 01H 01
216AH: 01H, the opcode of LD BC,nnnn. Reached from 2165H or 2168H, it takes 3EH 20H (the LD A,20H at 216BH) as its operand, so Register Pair BC gets 203EH and error 26 or 15 stays in Register A.
216BERR32
LD A,20H 3E 20
ERR32: load Register A with 20H, error 32 (Illegal drive number): the drive asked for is not ready.
216D
OR A B7
OR Register A with itself to set the NZ flag.
216E
RET C9
Return NZ with the error in Register A (15, 26 or 32) to the caller of @INIT.
216FINIT4
LD B,L 45
INIT4: copy Register L (the free slot, which becomes the DEC of the new entry) into Register B.
2170
LD A,(22DCH) 3A DC 22LD A,(FILEHASH)
Load Register A with the hash of the new name at 22DCH (FILEHASH), made by HASHNAME at 1F84H.
2173
LD (HL),A 77
Store Register A in the HIT slot at Register Pair HL.
2174
Call @HITWR at 1898H (on the SYS0/SYS page) to write the HIT of drive Register C back, before the entry is made: if the directory read or write below fails, the slot stays taken with no entry in use (bug B20).
2177
If it was written (Z), call @DIRRD at 18BBH (on the SYS0/SYS page) to read the directory sector of entry Register B into SBUFF$: Register Pair HL = the entry.
217A
RET NZ C0
Return NZ with error 23 (HIT write error) or 17 (Directory read error).
217B
PUSH HL E5
Save Register Pair HL (the entry) on the stack.
217C
PUSH BC C5
Save Register Pair BC (the DEC and the drive) on the stack.
217D
EX DE,HL EB
Exchange Register Pair DE with Register Pair HL: Register Pair DE = the entry, the destination of the copies.
217E
LD BC,0005H 01 05 00
Load Register Pair BC with 0005H, the bytes DIR+0 to DIR+4.
2181
LD HL,22D7H 21 D7 22LD HL,DIR$INIT
Point Register Pair HL to 22D7H (DIR$INIT): the attribute byte, three zero bytes and LREC$ at 22DBH.
2184
LDIR ED B0
Copy Register Pair BC (5) bytes from Register Pair HL to the entry at Register Pair DE: DIR+0 the attributes, DIR+1 to DIR+3 zero (no date, an EOF offset of 0), DIR+4 the record length asked for.
2186
LD C,11H 0E 11
Load Register C with 11H (17); Register B is 00H after the LDIR: the bytes DIR+5 to DIR+21.
2188
LD HL,22C6H 21 C6 22LD HL,NAME$EXT
Point Register Pair HL to 22C6H (NAME$EXT), followed by the password hashes and the ERN of 0000H.
218B
LDIR ED B0
Copy Register Pair BC (17) bytes from Register Pair HL to Register Pair DE: DIR+5 to DIR+15 the name and extension, DIR+16 and DIR+17 the owner password hash, DIR+18 and DIR+19 (the time field) the same hash, DIR+20 and DIR+21 the ending record number 0000H.
218D
EX DE,HL EB
Exchange Register Pair DE with Register Pair HL: Register Pair HL = DIR+22, the first extent field.
218E
LD B,0AH 06 0A
Load Register B with 0AH (10), the bytes of the five extent fields DIR+22 to DIR+31.
2190INIT5
INIT5: call OPNCB7 at 2112H to fill Register B (10) bytes at Register Pair HL with FFH: no extents and no link.
2193
POP BC C1
Restore Register Pair BC (Register B the DEC, Register C the drive) from the stack.
2194
Call @DIRWR at 1803H (on the SYS0/SYS page) to write the directory sector with the new entry.
2197
POP HL E1
Restore Register Pair HL (the entry in SBUFF$) from the stack; the POP keeps the flags.
2198
RET NZ C0
Return NZ with error 18 (Directory write error) or 15 if the write failed.
2199
Call OPNCB at 204CH to open the FCB at Index Register IX on the new entry.
219C
SCF 37
Set the Carry flag, which tells the caller of @INIT that a new file was created.
219D
RET C9
Return with the Carry flag set and the Z flag of OPNCB (Z, or NZ with an error of @DIRWR); the record lengths always agree for a new file.

219EH - XFRSPEC: Take the Specification Apart

XFRSPEC reads the specification text at Register Pair HL (the FCB, as @FSPEC left it) and fills the fields that OPEN and INIT use: up to 8 characters of the name at 22C6H, after a slash up to 3 of the extension at 22CEH, after a period up to 8 of the password at 22BEH (all three are first blanked with spaces), after a colon the drive number into 1F94H (FFH when there is none), and a closing exclamation mark into 20BDH. The first character of each field must be a letter, the others letters or digits. It returns Z, or NZ with error 19 (Illegal file name) when the name has no valid character or error 32 (Illegal drive number) for a drive that is not 0 to 7. An extension or a password that starts with a digit is taken as missing, and the parts after it are never looked at (bug B17).

219EXFRSPEC
LD B,13H 06 13
XFRSPEC: load Register B with 13H (19), the bytes of the password, name and extension fields at 22BEH-22D0H.
21A0
LD DE,22BEH 11 BE 22LD DE,PSWDBUF
Point Register Pair DE to 22BEH (PSWDBUF), the first of the fields.
21A3
LD A,20H 3E 20
Load Register A with 20H, the space that fills the fields.
21A5XSPEC1
LD (DE),A 12
XSPEC1: store Register A (a space) at Register Pair DE.
21A6
INC DE 13
Increment Register Pair DE to the next byte of the fields.
21A7
Decrement Register B and loop back to 21A5H (XSPEC1) for all 19 bytes; Register Pair DE ends at 22D1H, with Register D = 22H.
21A9
LD A,FFH 3E FF
Load Register A with FFH, the drive value for no drive given.
21AB
LD (1F94H),A 32 94 1F
Store Register A into 1F94H, the drive operand of OPEN2, read again by TESTDRV and INIT.
21AE
LD E,C6H 1E C6
Load Register E with C6H: Register Pair DE = 22C6H (NAME$EXT), Register D being 22H already.
21B0
Call XSPEC8B at 21EEH to copy up to 8 characters of the name from Register Pair HL to Register Pair DE, the first a letter; Register A returns the character that stopped it and Register B the characters not used.
21B3
LD C,A 4F
Copy Register A (the character after the name) into Register C.
21B4
LD A,B 78
Load Register A with Register B, the characters of the 8 that were not used.
21B5
SUB 08H D6 08
Subtract 08H from Register A: zero when no character of the name was taken.
21B7
If the name has at least one character, jump relative to 21BCH (XSPEC3).
21B9
OR 13H F6 13
OR 13H into Register A (00H): error 19 (Illegal file name), with the NZ flag.
21BB
RET C9
Return NZ with error 19: the name has no valid character.
21BCXSPEC3
LD A,C 79
XSPEC3: load Register A with Register C, the character after the name.
21BD
CP 2FH FE 2F
Compare Register A with 2FH, the slash that starts an extension.
21BF
LD E,CEH 1E CE
Load Register E with CEH: Register Pair DE = 22CEH (FILE$EXT); the LD keeps the flags of the CP.
21C1
LD B,03H 06 03
Load Register B with 03H, the most characters of an extension; the LD keeps the flags.
21C3
If there is a slash, call XSPEC8A at 21F0H to copy up to 3 characters of the extension to Register Pair DE; Register A returns the character after it. When the first character is a digit, nothing is copied and that digit comes back as the separator.
21C6
CP 2EH FE 2E
Compare Register A (the separator) with 2EH, the period that starts a password.
21C8
LD E,BEH 1E BE
Load Register E with BEH: Register Pair DE = 22BEH (PSWDBUF); the LD keeps the flags of the CP.
21CA
If there is a period, call XSPEC8 at 21E9H to mark a new file as protected and copy up to 8 characters of the password to Register Pair DE; Register A returns the character after it.
21CDXSPEC3A
CP 3AH FE 3A
XSPEC3A: compare Register A (the separator) with 3AH, the colon that starts a drive number.
21CF
If there is no drive, jump relative to 21DEH (XSPEC6) with the separator in Register A.
21D1
LD A,(HL) 7E
Load Register A with the drive character at Register Pair HL.
21D2
SUB 30H D6 30
Subtract 30H from Register A: the drive number, 0 to 7 for the characters 0 to 7.
21D4
LD (1F94H),A 32 94 1F
Store Register A into 1F94H, the drive operand of OPEN2.
21D7
AND F8H E6 F8
Mask Register A with F8H: zero only for drives 0 to 7.
21D9
LD A,20H 3E 20
Load Register A with 20H, error 32 (Illegal drive number); the LD keeps the flags of the AND.
21DB
RET NZ C0
Return NZ with error 32 for any other character.
21DC
INC HL 23
Increment Register Pair HL past the drive character.
21DD
LD A,(HL) 7E
Load Register A with the character after the drive at Register Pair HL.
21DEXSPEC6
SUB 21H D6 21
XSPEC6: subtract 21H from Register A (the last separator): zero when it is the exclamation mark.
21E0
LD A,08H 3E 08
Load Register A with 08H, the bit 3 of FCB+1 that the exclamation mark asks for; the LD keeps the flags.
21E2
If the specification ends with an exclamation mark, jump relative to 21E5H (XSPEC7) with Register A = 08H.
21E4
XOR A AF
Otherwise clear Register A to 00H, no exclamation mark: bit 3 of FCB+1 stays clear.
21E5XSPEC7
LD (20BDH),A 32 BD 20
XSPEC7: store Register A (08H or 00H) into 20BDH, the operand of the OR at 20BCH (OPNCB3).
21E8
RET C9
Return Z (from the SUB or the XOR): the specification is valid.
21E9XSPEC8
LD A,17H 3E 17
XSPEC8: load Register A with 17H, the attribute byte in use with protection 7 (NO ACCESS).
21EB
LD (2132H),A 32 32 21LD (INIT0),A
Store Register A into 2132H, the operand of the LD A at 2131H: a file that INIT creates with a password needs it for any access.
21EEXSPEC8B
LD B,08H 06 08
XSPEC8B: load Register B with 08H, the most characters of a name or a password. XFRSPEC calls here for the name at 21B0H.
21F0XSPEC8A
LD A,(HL) 7E
XSPEC8A: load Register A with the first character of the field at Register Pair HL. XFRSPEC calls here for the extension, with Register B = 03H.
21F1
INC HL 23
Increment Register Pair HL past the character.
21F2
Jump relative to 21FDH (XSPEC10): the first character must be a letter.
21F4XSPEC9
LD A,(HL) 7E
XSPEC9: load Register A with the next character of the field at Register Pair HL.
21F5
INC HL 23
Increment Register Pair HL past the character.
21F6
CP 30H FE 30
Compare Register A with 30H, the digit 0, the lowest character allowed after the first.
21F8
RET C D8
Return Carry for a character below the digit 0: the field ends, with Register A = that character, Register Pair HL after it and Register B the characters not used.
21F9
CP 3AH FE 3A
Compare Register A with 3AH, the character after the digit 9.
21FB
For a digit 0 to 9, jump relative to 2203H (XSPEC11) to keep it.
21FDXSPEC10
CP 41H FE 41
XSPEC10: compare Register A with 41H, the letter A.
21FF
RET C D8
Return Carry for a character below A (a sign, or a digit as the first character): the field ends there.
2200
CP 5BH FE 5B
Compare Register A with 5BH, the character after the letter Z.
2202
RET NC D0
Return No Carry for a character above Z: the field ends there.
2203XSPEC11
LD (DE),A 12
XSPEC11: store Register A (a letter or a digit) in the field at Register Pair DE.
2204
INC DE 13
Increment Register Pair DE to the next byte of the field.
2205
Decrement Register B and loop back to 21F4H (XSPEC9) while the field has room.
2207
LD A,(HL) 7E
The field is full: load Register A with the character after it at Register Pair HL, the separator.
2208
INC HL 23
Increment Register Pair HL past the separator.
2209
RET C9
Return with Register A = the separator, Register Pair HL after it and Register B = 00H.

220AH - SPRHIT: Find a Free HIT Slot

SPRHIT calls @SCNHIT with 28H as the first slot to try, the second entry of the ninth directory sector (sector 10 of the directory cylinder), so new files go to the middle of the directory first; when that slot is taken, or the diskette has no tenth directory sector, @SCNHIT scans the HIT from slot 02H.

220ASPRHIT
LD A,28H 3E 28
SPRHIT: load Register A with 28H, the first HIT slot to try: bits 7-5 = 1 (the second entry of the sector), bits 4-0 = 08H (directory sector 10).
220C
Call @SCNHIT at 181FH (on the SYS0/SYS page) to find a free slot in the HIT in SBUFF$ for drive Register C, trying slot Register A first.
220F
RET C9
Return Z with Register Pair HL at a free slot (its low byte the DEC of the new entry), or NZ when the HIT is full.

2210H - REN0 and RENAME: @RENAME, Rename a File

@RENAME (SVC 56, request F4H) has Register Pair DE at a closed FCB with the current specification and Register Pair HL at the new name, ended by 0DH or 03H. A device (asterisk) goes to RENDEV. An FCB whose first byte is D2H (the letter R with bit 7 set) is the special request of BACKUP: REN0 patches OPEN so that every open gets full access whatever the password, as long as this copy of SYS2 stays in the overlay area, and returns error 24. For a file, RENAME opens the old name without checks and needs an access of RENAME or better (error 37 otherwise). It forces the drive of the new name to the old one by writing a colon, the drive digit and 0DH into the caller's string, checks with OPEN1 that the new name is not in use (error 19 if it is), and then writes the new name into the directory entry and its hash into the entry's HIT slot.

2210REN0
LD A,18H 3E 18
REN0: load Register A with 18H, the opcode of JR (an unconditional relative jump).
2212
LD (2023H),A 32 23 20LD (WASMAT),A
Store Register A into 2023H (WASMAT), over the opcode 28H of JR Z,2047H: OPEN now goes to OPEN16 with Register A = 00H (full access) after every password compare.
2215
OR A B7
OR Register A (18H) with itself to set the NZ flag.
2216
RET C9
Return NZ with Register A = 18H (error 24, File not in directory), which BACKUP does not look at.
2217RENAME
RENAME: call LNKFCB@ at 1566H (on the SYS0/SYS page) to save Register Pairs HL, DE and BC and the caller's Index Register IX, point Index Register IX at the FCB in Register Pair DE and plant RESTREG.
221A
LD A,(IX+00H) DD 7E 00
Load Register A with FCB+0 at Index Register IX+00H, the first character of the old specification.
221D
SUB 2AH D6 2A
Subtract 2AH (the asterisk) from Register A: zero for a device.
221F
For a device, jump relative to 229AH (RENDEV).
2221
CP A8H FE A8
Compare Register A (FCB+0 less 2AH) with A8H: Z when FCB+0 is D2H, the special request.
2223
For the special request, jump relative to 2210H (REN0).
2225
PUSH HL E5
Save Register Pair HL (the new name) on the stack.
2226
LD HL,007CH 21 7C 00LD HL,SFLAG$
Point Register Pair HL to 007CH (SFLAG$), the system flags.
2229
SET 0,(HL) CB C6
Set bit 0 of SFLAG$ at Register Pair HL: OPNCB returns at 205DH without the open bit, the write protect test or the record length test.
222B
Call OPEN1 at 1F61H to open the old name in the FCB at Index Register IX, with Register B as its record length and Register Pair HL (007CH) as its buffer address in FCB+3 and FCB+4; no buffer is used.
222E
POP HL E1
Restore Register Pair HL (the new name) from the stack; the POP keeps the flags.
222F
RET NZ C0
Return NZ with the error of OPEN (19, 24, 25 and others) if the old file cannot be opened.
2230
LD A,(IX+01H) DD 7E 01
Load Register A with FCB+1 at Index Register IX+01H, whose bits 2-0 are the access granted.
2233
AND 07H E6 07
Mask Register A with 07H, the access level, bits 2-0 of FCB+1 set by OPEN.
2235
CP 03H FE 03
Compare Register A with 03H: FULL (0), REMOVE (1) and RENAME (2) are below it.
2237
If the access allows a rename, jump relative to 223DH (REN1).
2239
LD A,25H 3E 25
Load Register A with 25H, error 37 (Illegal access attempted to protected file).
223B
OR A B7
OR Register A with itself to set the NZ flag.
223C
RET C9
Return NZ with error 37: the file's protection does not allow a rename.
223DREN1
PUSH HL E5
REN1: save Register Pair HL (the start of the new name) on the stack.
223EREN2
LD A,(HL) 7E
REN2: load Register A with the character of the new name at Register Pair HL.
223F
INC HL 23
Increment Register Pair HL past it, to the next character of the new name.
2240
CP 0DH FE 0D
Compare Register A with 0DH, the ENTER that ends the name.
2242
At the end of the name, jump relative to 224CH (REN3).
2244
CP 03H FE 03
Compare Register A with 03H, the ETX that ends the name.
2246
At the end of the name, jump relative to 224CH (REN3).
2248
CP 3AH FE 3A
Compare Register A with 3AH, the colon of a drive number.
224A
Loop back to 223EH (REN2) until the colon or the end of the name.
224CREN3
DEC HL 2B
REN3: decrement Register Pair HL back to the character that ended the scan: the colon, or the 0DH or 03H at the end.
224D
LD (HL),3AH 36 3A
Store 3AH (a colon) at Register Pair HL, the colon of the forced drive number.
224F
INC HL 23
Increment Register Pair HL to the place of the drive digit.
2250
LD A,(IX+06H) DD 7E 06
Load Register A with FCB+6 at Index Register IX+06H, the drive of the old file, set by OPNCB0.
2253
LD C,A 4F
Copy Register A (the drive) into Register C, the drive of the old file for the disk calls below.
2254
AND 07H E6 07
Mask Register A with 07H, the drive number. 0 to 7, without other bits.
2256
ADD A,30H C6 30
Add 30H to Register A: the drive as the character 0 to 7.
2258
LD (HL),A 77
Store Register A (the drive digit) at Register Pair HL.
2259
INC HL 23
Increment Register Pair HL after the digit, to where the 0DH goes.
225A
LD (HL),0DH 36 0D
Store 0DH at Register Pair HL: the new name now ends with the colon, the drive of the old file and 0DH. When it had no drive, the three bytes go over its 0DH or 03H and the two bytes after it, in the caller's memory (bug B18).
225C
LD B,(IX+07H) DD 46 07
Load Register B with FCB+7 at Index Register IX+07H, the DEC of the old file's directory entry.
225F
POP IX DD E1
Restore Index Register IX from the stack: the start of the new name, used as the FCB of the second OPEN1.
2261
PUSH BC C5
Save Register Pair BC (Register B the old DEC, Register C the drive) on the stack.
2262
LD HL,007CH 21 7C 00LD HL,SFLAG$
Point Register Pair HL to 007CH (SFLAG$), the system flags.
2265
SET 0,(HL) CB C6
Set bit 0 of SFLAG$ at Register Pair HL again: no checks in OPNCB.
2267
Call OPEN1 at 1F61H with Index Register IX at the new name: Z if a file of that name is on the drive and may be opened; OPNCB0 then writes a 32 byte FCB over the text of the new name, and a new name that names an existing device gets the 8 byte routed DCB of DEVOPEN (bug B18).
226A
POP BC C1
Restore Register Pair BC (the old DEC and the drive) from the stack; the POP keeps the flags.
226B
If the new name was not opened (NZ), jump relative to 2271H (REN4).
226DREN3A
LD A,13H 3E 13
REN3A: load Register A with 13H, error 19 (Illegal file name): the new name is in use, or (from RENDEV) it is no device name or names a device that exists.
226F
OR A B7
OR Register A with itself to set the NZ flag.
2270
RET C9
Return NZ with error 19 to the caller of @RENAME.
2271REN4
CP 18H FE 18
REN4: compare Register A (the error of the second OPEN1) with 18H, error 24 (File not in directory), the answer wanted.
2273
RET NZ C0
Return NZ with any other error, such as 19 for a bad new name or 25 for a protected file of that name.
2274
Call @DIRRD at 18BBH (on the SYS0/SYS page) to read the directory sector of the old file's entry Register B on drive Register C into SBUFF$: Register Pair HL = the entry.
2277
RET NZ C0
Return NZ with error 17 (Directory read error) if it cannot be read.
2278
PUSH BC C5
Save Register Pair BC (the old DEC and the drive) on the stack.
2279
LD D,H 54
Copy Register H (1DH) into Register D, the page of SBUFF$ that holds the entry.
227A
LD A,L 7D
Load Register A with Register L, the low byte of the entry's address.
227B
ADD A,05H C6 05
Add 05H to Register A, the offset of the name field.
227D
LD E,A 5F
Copy Register A into Register E: Register Pair DE points to DIR+5, the name in the entry.
227E
LD HL,22C6H 21 C6 22LD HL,NAME$EXT
Point Register Pair HL to 22C6H (NAME$EXT), where the second OPEN1 left the new name and extension.
2281
LD BC,000BH 01 0B 00
Load Register Pair BC with 000BH (11), the characters of name and extension.
2284
LDIR ED B0
Copy Register Pair BC (11) bytes from Register Pair HL to Register Pair DE: the entry gets the new name and extension.
2286
POP BC C1
Restore Register Pair BC (Register B the DEC, Register C the drive) from the stack.
2287
Call @DIRWR at 1803H (on the SYS0/SYS page) to write the directory sector of entry Register B back to drive Register C.
228A
If it was written (Z), call @HITRD at 1897H (on the SYS0/SYS page) to read the HIT of drive Register C into SBUFF$; Register Pair HL = 1D00H.
228D
RET NZ C0
Return NZ with error 18, 15 or 22 if a write or the read failed.
228E
LD D,H 54
Copy Register H (1DH) into Register D, the page of SBUFF$ that holds the HIT.
228F
LD E,B 58
Copy Register B (the DEC) into Register E: Register Pair DE points to the entry's slot in the HIT.
2290
LD HL,22C6H 21 C6 22LD HL,NAME$EXT
Point Register Pair HL to 22C6H (NAME$EXT), the new name and extension.
2293
Call HASHNAME at 1E1EH to hash the 11 characters: Register A = the new hash; Register B is used as its count, Register C (the drive) is kept.
2296
LD (DE),A 12
Store Register A (the hash of the new name) in the HIT slot at Register Pair DE.
2297
Jump to @HITWR at 1898H (on the SYS0/SYS page) to write the HIT of drive Register C; its result (Z, or NZ with error 23) goes back through RESTREG to the caller of @RENAME.

229AH - RENDEV: Rename a Device

For a device RENAME finds the old DCB, refuses the system devices KI, DO, PR, SI, SO and JL (their DCBs lie below 0231H) with error 40, needs the new name to be a device specification that names no DCB yet (error 19 otherwise), and then writes the new two letters into DCB+6 and DCB+7.

229ARENDEV
PUSH HL E5
RENDEV: save Register Pair HL (the new name) on the stack.
229B
Call GETDCB at 1E59H to find the DCB named by FCB+1 and FCB+2 of the old specification (Index Register IX): Z with Register Pair HL at it.
229E
POP IX DD E1
Restore Index Register IX from the stack: Index Register IX = the new name; the POP keeps the flags.
22A0
RET NZ C0
Return NZ with error 8 (Device not available) if the old device has no DCB.
22A1
LD A,L 7D
Load Register A with Register L, the low byte of the old DCB's address.
22A2
CP 31H FE 31
Compare Register A with 31H (the value of the symbol DCBKL$): KI 08H, DO 10H, PR 18H, SI 20H, SO 28H and JL 30H are below it.
22A4
LD A,28H 3E 28
Load Register A with 28H, error 40 (Protected system device); the LD keeps the flags of the CP.
22A6
RET C D8
Return Carry with error 40 for a system device; the NZ flag is still that of the CP (the address differs from 31H).
22A7
LD A,(IX+00H) DD 7E 00
Load Register A with the first character of the new name at Index Register IX+00H.
22AA
CP 2AH FE 2A
Compare Register A with 2AH, the asterisk of a device specification.
22AC
If the new name is not a device, jump relative to 226DH (REN3A) for error 19.
22AE
PUSH HL E5
Save Register Pair HL (the old DCB) on the stack.
22AF
Call GETDCB at 1E59H with Index Register IX at the new name: Register Pair DE = its two letters, and Z if a DCB has them already.
22B2
POP HL E1
Restore Register Pair HL (the old DCB) from the stack; the POP keeps the flags.
22B3
If the new name is in use, jump relative to 226DH (REN3A) for error 19.
22B5
LD BC,0006H 01 06 00
Load Register Pair BC with 0006H, the offset of the name in a DCB.
22B8
ADD HL,BC 09
Add Register Pair BC to Register Pair HL: Register Pair HL points to DCB+6 of the old device.
22B9
LD (HL),E 73
Store Register E (the first new letter) at DCB+6 (Register Pair HL).
22BA
INC HL 23
Increment Register Pair HL to DCB+7, the second letter of the name field.
22BB
LD (HL),D 72
Store Register D (the second new letter) at DCB+7 (Register Pair HL).
22BC
XOR A AF
Clear Register A to 00H and set the Z flag: the device is renamed.
22BD
RET C9
Return Z with Register A = 00H; RESTREG gives the caller's registers back.

22BEH - Work Fields, Free Space and the Overlay Length

The fields that XFRSPEC fills and OPEN and INIT read lie after the code. Only 22D5H-22DAH (the ERN of a new entry and four bytes of DIR$INIT) are loaded with the file. The overlay length at 23FEH counts 1E00H to 22DAH, so LREC$ and FILEHASH are left out of it.

22BE-22C5PSWDBUF
DEFS 8
PSWDBUF, 22BEH-22C5H: the password of the specification, filled with spaces by XFRSPEC (21A0H) and then with the password if one is given (21CAH); hashed at 1F8AH. Not loaded.
22C6-22CDNAME$EXT
DEFS 8
NAME$EXT, 22C6H-22CDH: the name, left justified and padded with spaces (21B0H); hashed with the extension at 1F84H, compared with DIR+5 at 1FEEH and copied into a new entry (218BH) or a renamed one (2284H). Not loaded.
22CE-22D0FILE$EXT
DEFS 3
FILE$EXT, 22CEH-22D0H: the extension, padded with spaces (21C3H), the last three of the 11 characters compared and copied with NAME$EXT. Not loaded.
22D1-22D2PW$HASH1
DEFS 2
PW$HASH1, 22D1H-22D2H: the hash of the password given (1F8DH), DIR+16 and DIR+17 of a new entry, the owner password. Not loaded.
22D3-22D4PW$HASH2
DEFS 2
PW$HASH2, 22D3H-22D4H: the hash of the password given again (1F90H), DIR+18 and DIR+19 of a new entry (the time field), and the hash OPEN compares with the owner password (200DH). Not loaded.
22D5-22D6
DEFW 0000H 00 00
22D5H-22D6H = 0000H: the ending record number of a new entry, DIR+20 and DIR+21, the last two of the 17 bytes copied at 218BH. The first loaded bytes after the code.
22D7-22DADIR$INIT
DEFB 00H, 00H, 00H, 00H 00 00 00 00
DIR$INIT, 22D7H-22DAH: DIR+0 to DIR+3 of a new entry. INIT stores the attribute byte at 22D7H (2133H); 22D8H-22DAH stay 00H, so a new file has no date (DIR+1 and DIR+2) and an EOF offset of 0 (DIR+3). OPEN also stores the attribute byte of the file it finds at 22D7H (2001H).
22DBLREC$
DEFS 1
LREC$, 22DBH: the logical record length asked for (1F74H), read for FCB+1 (20B0H), FCB+9 (20D9H) and DIR+4 of a new entry (2184H). Not loaded, and not counted in the overlay length.
22DCFILEHASH
DEFS 1
FILEHASH, 22DCH: the hash of the name and extension (1E2AH), looked for in the HIT (1FA8H) and stored in a new slot (2170H). Not loaded, and not counted in the overlay length.
22DD-23FD
DEFS 289
22DDH-23FDH: the rest of the overlay area, not loaded by SYS2/SYS; it holds what was there before. DIRBUF$ (2300H-23FFH), the GAT buffer of SYS0/SYS, overlaps it and the length word at 23FEH, which each load of SYS2 writes again.
23FE-23FF
DEFW 04DBH DB 04
23FEH-23FFH = 04DBH (1243): the length of SYS2 that SYSTEM (SYSRES) copies, 1E00H to 22DAH (the source's LAST, which 6.3.1 puts before LREC$ and FILEHASH). SYSTEM (SYSRES) reads it when it keeps the overlay in high memory and stores it back when it brings the copy into 1E00H again.