
A game does not read its data file from the beginning every time the player walks into a room. It works out which record it wants and reads that one. The BDOS calls this random access.
Put the record number - counting from 0 - in FCB bytes 33 and 34, low byte first, and 0 in byte 35. Set the DMA address, put the FCB in DE, 33 in C, and CALL 5. The record arrives at the DMA address, wherever it is in the file: the BDOS works out the extent and the block itself.
If there is no such record, nothing arrives and A is not 0. (S12 says what its values mean.)
R name n. GETNUM reads n into HL, which goes straight into bytes 33-34 with one LD (FCB+33),HL - the Z80 stores L first, which is the order the BDOS wants.
After the line JP Z,CMDT, add:
CP 'R'
JP Z,CMDR
After the last line of OPENIT (JP DONE), add:
; R name n: read record n with read random and show it.
CMDR: CALL NEEDDOS
CALL OPENIT
CALL GETNUM
JP C,WHAT
LD (FCB+33),HL ; the record number, low byte first
XOR A
LD (FCB+35),A
LD DE,RECBUF
LD C,26
CALL 5
LD DE,FCB
LD C,33 ; read random
CALL 5
OR A
JR NZ,CMDR1
LD HL,RECBUF
LD BC,128
CALL SHOWBLK
JP MAIN
After the last line of CMDR (JP MAIN), add:
CMDR1: PUSH AF
LD HL,AM
CALL PRINT ; PRINT leaves A = 0, so keep it
POP AF
CALL PHEX
JP CRMAIN
After the line RECSM: DEFB ' RECORDS',13,10,0, add:
AM: DEFB 'A=',0
Run it on a copy of PRIMER.DSK:
R 1:ROOMS.DAT 150
R 1:ROOMS.DAT 200
What you should see
> R 1:ROOMS.DAT 150
0000 52 4F 4F 4D 20 31 35 30 ROOM 150
0008 3A 20 41 20 44 55 53 54 : A DUST
0010 59 20 48 41 4C 4C 2E 20 Y HALL.
0018 20 20 20 20 20 20 20 20
0020 20 20 20 20 20 20 20 20
0028 20 20 20 20 20 20 20 20
0030 20 20 20 20 20 20 20 20
0038 20 20 20 20 20 20 20 20
0040 20 20 20 20 20 20 20 20
0048 20 20 20 20 20 20 20 20
0050 20 20 20 20 20 20 20 20
0058 20 20 20 20 20 20 20 20
0060 20 20 20 20 20 20 20 20
0068 20 20 20 20 20 20 20 20
0070 20 20 20 20 20 20 20 20
0078 20 20 20 20 20 20 20 20
> R 1:ROOMS.DAT 200
A=01
>
Record 150 is in ROOMS.DAT's second extent, but you did not have to know that. ROOMS.DAT has 200 records, numbered 0-199, so there is no record 200.
XOR A / LD (FCB+35),A. GETNAME cleared the FCB, so it still works the first time. When might byte 35 not be 0?Function 33 reads the record whose number is in FCB bytes 33-35, in any order, from anywhere in the file. That is all a program needs to keep its data on disc and fetch it as it goes.
S10 writes a file.
This form is protected by reCAPTCHA, and the Google Privacy Policy and Terms of Service apply.