
An FCB names a file, but nothing has checked that the file exists. Before the BDOS will read a file it must open it: find the name in the directory and fill in the rest of the FCB from the entry.
Put the FCB's address in DE, 15 in C, and CALL 5. What comes back
in A:
So test with CP 0FFH, never OR A: a file found in the first place of
four gives 0, and OR A would call that a failure.
When the open succeeds, the BDOS has copied the entry into the FCB: byte 12 the extent, byte 15 the record count, bytes 16-31 the block numbers. It also sets byte 14 to 80h for its own use. Leave bytes 12-35 alone while the file is open: they are the BDOS's notes.
O opens a file and shows A, and the FCB as the BDOS left it.
NEEDDOS does nothing yet - it simply returns - but every command that
calls the BDOS calls it first; in Part four it will matter.
After the line JP Z,CMDF, add:
CP 'O'
JP Z,CMDO
After the last line of CMDF (JP MAIN), add:
; O name: open the file; show what the BDOS says and the FCB after.
CMDO: CALL NEEDDOS
LD DE,FCB
CALL GETNAME
JP C,WHAT
LD DE,FCB
LD C,15
CALL 5
PUSH AF
LD HL,OPENM
CALL PRINT
POP AF
PUSH AF
CALL PHEX
CALL NEWLINE
POP AF
CP 0FFH
LD HL,NOTFM
JP Z,DONE
LD HL,FCB
LD BC,32
CALL SHOWBLK
JP MAIN
After the last line of CMDO (JP MAIN), add:
; NEEDDOS: back to MAIN with a message if there is no DOS to call.
NEEDDOS:
After the line NEEDDOS:, add:
RET
After the line FCB: DEFS 36, add:
OPENM: DEFB 'OPEN: ',0
NOTFM: DEFB 'NOT FOUND',13,10,0
Run it as in S6, on a copy of PRIMER.DSK, and type:
O 1:POEM.TXT
O 1:ROOMS.DAT
O POEM.TXT
Q
What you should see
> O 1:POEM.TXT
OPEN: 00
0000 02 50 4F 45 4D 20 20 20 .POEM
0008 20 54 58 54 00 00 80 03 TXT....
0010 01 00 00 00 00 00 00 00 ........
0018 00 00 00 00 00 00 00 00 ........
> O 1:ROOMS.DAT
OPEN: 01
0000 02 52 4F 4F 4D 53 20 20 .ROOMS
0008 20 44 41 54 00 00 80 80 DAT....
0010 02 00 03 00 04 00 05 00 ........
0018 06 00 07 00 08 00 09 00 ........
> O POEM.TXT
OPEN: FF
NOT FOUND
>
POEM.TXT: record count 3 (byte 15), one block, block 1 - the same as its
directory entry (edisc.py entries PRIMER.DSK shows it). ROOMS.DAT is in
the next entry, so A is 1; its first extent holds 80h - 128 - records
in blocks 2 to 9. And O POEM.TXT, with no drive, looked on the current
drive - drive 0, the system disc - where there is no POEM.TXT.
1:ROOMS.DAT again, then look at its directory with edisc.py
entries. There are two entries for it. Which one did the open copy into
the FCB?CP 0FFH after the open to OR A. Which of the three opens
above would now say NOT FOUND?Function 15 opens a file: FFh means not found, anything else found. The open fills the FCB from the directory entry, and from now on the FCB is how the BDOS keeps track of the file.
S8 reads the opened file, 128 bytes at a time.
This form is protected by reCAPTCHA, and the Google Privacy Policy and Terms of Service apply.