LD A,(DDRV)
Fetch the DRIVE NUMBER (held in memory location 4FAFH) and store it into Register A.
4EE6
LD C,A
Copy the DRIVE NUMBER into Register C.
4EE7
GOSUB to 4A67H.
NOTE: 4A67H is the SYS00/SYS routine to read the directory entry into RAM (Buffer at 4300H)
4EEA
RET NZ
If the NZ FLAG (Not Zero) has been set then that CALL returned with an error, so RETurn to the caller.
4EEB
BIT 6,(HL)
Check for a SYSTEM FILE by testing Bit Number 6 of Register HL. Z FLAG will be set if that bit is 0, and NZ FLAG will be set if that bit is 1.
4EED
If the file was a SYSTEM FILE then the NZ FLAG (Not Zero) will have been set. JUMP to 4F9CH to zero out all the buffers and return with “FILE ACCESS DENIED” error.
4EF0
LD (DDIR),HL
Store the POINTER TO THE DIRECTORY ENTRY IN RAM (held in Register Pair HL) into memory location 4FB0H.
4EF3
LD DE,0005H
Since the filename starts 5 bytes into a directory entry, set Register Pair DE equal to 0005H.
4EF6
ADD HL,DE
Point the POINTER TO THE DIRECTORY ENTRY IN RAM (HL) at the FILENAME by adding 5.
4EF7
LD DE,(RAMM)
Fetch the pointer to the USER BUFFER (held in memory location 4FADH) and store it into Register Pair DE.
4EFB
LD BC,0008H
Set Register Pair BC equal to 0008H since there are up to 8 bytes in a filename.
4EFE
LD IX,000EH
Set Special Index Register Pair IX equal 000EH (Decimal: 14) since a filespec can be up to 14 bytes (i.e., NNNNNNNN/EEE:D).
4F02
LD A,20H
Let Register A equal 20H (ASCII: SPACE).
Top of a loop.
CP (HL)
Compare a SPACE (held in Register A) against the character at the memory location pointed to by the POINTER TO THE DIRECTORY ENTRY IN RAM (Register Pair HL). If it’s a SPACE ….
4F05
… exit this loop via a JUMP to 4F0EH.
4F07
DEC IX
DECrement the amount of characters left in the filespec (tracked in Special Index Register IX) by 1.
4F09
LDI
Move to the 2nd character of both HL and DE via LDI command; which copies BC number of characters from (HL) to (DE), dropping BC each time. When BC hits 0, the PE flag is reset.
4F0B
If the PARITY/OVERFLOW FLAG has been SET then we are not yet done processing characters, so LOOP BACK to 4F04H.
Bottom of a loop.
LD HL,(DDIR)
Fetch the POINTER TO THE DIRECTORY ENTRY IN RAM (held in memory location 4FB0H) and store it into Register Pair HL.
4F11
LD BC,000DH
Let Register Pair BC equal 000DH (Decimal: 13), which will be an offset to HL to get to the filename extension.
4F14
ADD HL,BC
LET Register Pair HL = Register Pair HL + Register BC, so that HL now points to the extension.
4F15
LD BC,0003H
Since an extension is maximum 3 characters, set Register Pair BC equal 0003H.
4F18
CP (HL)
Compare the value held in Register A (which should be a SPACE) against the FIRST CHARACTER OF THE EXTENSION (held in the memory location pointed to by the value held in Register Pair HL). Results: If Register A equals the value held in Register HL, the Z FLAG is set; otherwise the NZ FLAG is set.
4F19
If the Z FLAG (Zero) has been set, then we hit a space and there is no extension, so stop processing extension characters via a JUMP to 4F2BH.
4F1B
PUSH AF
If we’re here then we know we have at least 1 character of an extension, so save the SPACE (held in Register A) to the top of the stack.
4F1C
LD A,2FH
Let Register A equal 2FH (ASCII: /).
4F1E
LD (DE),A
Store a / into the memory location pointed to by Register Pair DE.
4F1F
INC DE
Since we just filled a character, move the pointer by INCrementing the value stored in Register Pair DE by 1.
4F20
POP AF
Restore the SPACE from the top of the stack into Register A.
Top of a loop to process the 2nd and 3rd characters of the filename extension, if any.
CP (HL)
Compare the value held in the memory location pointed to by the value held in Register Pair HL against a SPACE. If the byte is a SPACE …
4F24
DEC IX
DECrement the amount of space left in the filespec (tracked in Special Index Register IX) by 1.
4F26
LDI
Move to the 2nd character of both HL and DE via LDI command; which copies BC number of characters from (HL) to (DE), dropping BC each time. When BC hits 0, the PE flag is reset.
4F28
If the PARITY/OVERFLOW FLAG has been SET then there are more characters to test, so LOOP BACK to 4F21H.
Bottom of the loop to process the 2nd and 3rd characters of the filename extension, if any.
So now the filename, the “/” (if necessary), and the extension (if any) have been placed into RAM (tracked by DE). Move to the DRIVE NUMBER next. Let Register A equal 3AH (ASCII: :).
4F2D
LD (DE),A
Store the : into the LOCATION IN THE USER BUFFER pointed to by Register Pair DE.
4F2E
INC DE
INCrement the LOCATION IN THE USER BUFFER (stored in Register Pair DE) by 1 to point after the :.
4F2F
LD A,(DDRV)
Fetch the DRIVE NUMBER (held in memory location 4FAFH) and store it into Register A.
4F32
AND 07H
MASK the value of Register A against 07H (0000 0111) to leave only 2, 1, 0 active.
4F34
ADD A,30H
LET Register A = Register A + 30H. Note: Adding 30H to from Register A will convert decimal number 0-9 into its ASCII equivalent (i.e., 6 + 30H = 36H, which, in ASCII, is 6.
4F36
LD (DE),A
Store the DRIVE NUMBER IN ASCII (held in Register A) into the memory location in the LOCATION IN THE USER BUFFER pointed to by Register Pair DE.
4F37
INC DE
INCrement the LOCATION IN THE USER BUFFER (stored in Register Pair DE) by 1 to point after the DRIVE NUMBER IN ASCII.
So now the complete filespec (filename/ext:drive) is in RAM with DE pointing to the drive number. Time to start processing the other information.
4F38
4F3A
DEC IX
DEC IX
DECrement the amount of space left in the filespec (tracked in Special Index Register IX) by 2 as the “:D” has been added.
4F3C
4F3E
PUSH IX
POP BC
Let Register Pair BC = the amount of space left in the filespec.
4F3F
LD B,C
Prepare for a DJNZ loop by copying the LSB of the amount of space left unfilled in the filespec (held in BC) into Register B.
4F40
EX DE,HL
EXchange the value stored in Register Pair HL (i.e., the LOCATION IN THE DIRECTORY ENTRY IN RAM) with the value stored in Register Pair DE (i.e., the LOCATION IN THE USER BUFFER).
Top of a loop to fill the excess characters in the USER BUFFER with SPACES.
LD (HL),20H
Store a : into the USER BUFFER at the memory location pointed to by Register Pair HL.
4F43
INC HL
INCrement the LOCATION IN THE USER BUFFER (stored in Register Pair HL) by 1.
4F44
LOOP back to 4F41H, reducing Register B each time, and continue to LOOP until Register B has been reduced to ZERO, in which case, continue with the next instruction.
Bottom of a loop.
4F46
LD IX,(DDIR)
Fetch the RAM POINTER IN THE DIRECTORY ENTRY (held in memory location 4FB0H) and store it into Special Index Register Pair IX.
4F4A
LD A,(IX+00H)
Fetch the ATTRIBUTE BYTE (held in the memory location pointed to by Special Index Register Pair IX+00H) and store it into Register A.
4F4D
AND 07H
MASK the value of Register A against 07H (0000 0111) to keep only the protection/access level bits active.
4F4F
LD (HL),A
Store the protection level (held in Register A) into the USER BUFFER memory location pointed to by Register Pair HL.
4F50
INC HL
INCrement the LOCATION IN THE USER BUFFER (stored in Register Pair HL) by 1.
4F51
LD A,(IX+03H)
Fetch the EOF BYTE (held in the memory location pointed to by Special Index Register Pair IX+03H) and store it into Register A.
4F54
LD (HL),A
Store the EOF BYTE into the USER BUFFER memory location pointed to by Register Pair HL.
4F55
INC HL
INCrement the LOCATION IN THE USER BUFFER (stored in Register Pair HL) by 1.
4F56
LD A,(IX+04H)
Fetch the LOGICAL RECORD LENGTH (held in the memory location pointed to by Special Index Register Pair IX+04H) and store it into Register A.
4F59
LD (HL),A
Store the LOGICAL RECORD LENGTH into the USER BUFFER memory location pointed to by Register Pair HL.
4F5A
INC HL
INCrement the LOCATION IN THE USER BUFFER (stored in Register Pair HL) by 1.
4F5B
LD A,(IX+14H)
Fetch the LSB of the END OF FILE SECTOR NUMBER (held in the memory location pointed to by Special Index Register Pair IX+14H) and store it into Register A.
4F5E
LD (HL),A
Store the LSB of the END OF FILE SECTOR NUMBER into the USER BUFFER memory location pointed to by Register Pair HL.
4F5F
INC HL
INCrement the LOCATION IN THE USER BUFFER (stored in Register Pair HL) by 1.
4F60
LD A,(IX+15H)
Fetch the MSB of the END OF FILE SECTOR NUMBER (stored in memory location pointed to by Special Index Register Pair IX+15H) and store it into Register A.
4F63
LD (HL),A
Store the LSB of the END OF FILE SECTOR NUMBER into the USER BUFFER memory location pointed to by Register Pair HL.
4F64
INC HL
INCrement the LOCATION IN THE USER BUFFER (stored in Register Pair HL) by 1.
4F65
LD (RAMM),HL
Store the LOCATION IN THE USER BUFFER (held in Register Pair HL) into memory location 4FADH.
4F68
LD IX,(DDIR)
Fetch the RAM POINTER IN THE DIRECTORY ENTRY (held in memory location 4FB0H) and store it into Special Index Register Pair IX.
4F6C
LD DE,0016H
Let Register Pair DE equal 0016H for a byte offset into the directory entry to point to the file extents.
4F6F
ADD IX,DE
Set Register Pair IX to point to the EXTENTS by letting IX = Register Pair IX + 22 (i.e., Register DE).
4F71
LD B,0DH
Let Register B equal 0DH (Decimal: 13) to loop through the 13 extents in each directory entry.
4F73
LD HL,0000H
Let Register Pair HL equal 0000H to be an accumulator for the number of grans in the extent.
Top of a loop to parse all extents and accumulate the number of grans into HL.
INC IX
INCrement IX to point to the next byte in the EXTENTS portion of the directory entry.
4F78
INC (IX+00H)
Test for a FFH in the current EXTENT by INCrementing the value stored in the memory location pointed to by Special Index Register IX+00H by 1.
4F7B
If the Z FLAG (Zero) has been set, then the EXTENT was FFH (or empty), so JUMP to 4F8AH.
4F7D
LD A,(IX+00H)
Fetch a byte of the EXTENT (pointed to by IX+00H) and put it into Register A. THis should be the SIZE byte of the extent.
4F80
AND 1FH
MASK the value of Register A against 1FH (0001 1111). This has the effect of turning off bits 7, 6, 5 (i.e., the starting gran), which are not needed for this calculation.
4F82
4F83
LD E,A
LD D,00H
Let Register Pair DE = the number of grans in the extent (held in Register A).
4F85
ADD HL,DE
Add the number of grans in the extent (held in Register Pair DE) into the accumulator (held in Register Pair HL).
4F86
INC IX
Bump Special Index Register IX to the next extent.
4F88
LOOP back to 4F76H, reducing Register B each time, and continue to LOOP until Register B has been reduced to ZERO, in which case, continue with the next instruction.
End of loop to parse all extents and accumulate the number of grans into HL.
EX DE,HL
EXchange the value stored in Register Pair HL (i.e., the total number of grans in the extents) with the value stored in Register Pair DE.
4F8B
LD HL,(RAMM)
Fetch LOCATION IN THE USER BUFFER (held in memory location 4FADH) and store it into Register Pair HL.
4F8E
LD (HL),E
Store the LSB of the number of grans in the file (held in Register E) into the memory location pointed to by Register Pair HL.
4F8F
INC HL
INCrement the LOCATION IN THE USER BUFFER (stored in Register Pair HL) by 1.
4F90
LD (HL),D
Store the MSB of the number of grans in the file (held in Register D) into the memory location pointed to by Register Pair HL.
4F91
INC HL
INCrement the LOCATION IN THE USER BUFFER (stored in Register Pair HL) by 1.
4F92
LD (HL),2BH
Store a + delimiter into the LOCATION IN THE USER BUFFER (stored in Register Pair HL).
4F94
LD (RAMM),HL
Store the LOCATION IN THE USER BUFFER (held in Register Pair HL) into memory location 4FADH.
4F97
INC HL
INCrement the LOCATION IN THE USER BUFFER (stored in Register Pair HL) by 1.
4F98
LD (HL),2BH
Store a + delimiter into the LOCATION IN THE USER BUFFER (stored in Register Pair HL).
4F9A
XOR A
Set Register A to ZERO and clear all Flags to show NO ERROR.
4F9B
RET
RETurn to the caller.