Personal Computer News
22nd December 1984Categories: Letter
Author: James Bridson
Published in Personal Computer News #092
Access Open To BBC Disk Sectors
This procedure allows you to access any individual sector on the disk so as to write a copy of a buffer to it, or write a copy of the sector to the buffer. This process is useful when writing programs, such as databases or disk indexes, which are required to access the disk filenames directly or perhaps access the first few bytes of a file for use as a title.
To use the procedure the program must first, on running, initialise an 11-byte control block. This is pointed to by the variable control% and is achieved by including the statement DIM control% and is achieved by including the statement DIM control% in your program. The procedure may then be called at any time by the command PROCsector access (track, sector, buffer, mode). Buffer is an address which points to a 256-byte buffer for the data. This could be reserved using DIM buffer% 255. The value of mode decides whether the operation is a read or a write. Mode is zero to write, one to read.
The listing is for a single drive system. This can be changed for a multidrive system by altering these lines.
Line 30 change the last number in the brackets to your number of drives.
Line 1080 add the parameter drive% after mode%
Line 1100 change to ?control1%=drive%
See Disc System User Guide (page 74) for further information.
10 REM Example
15 REM Save memory for control block and buffer
20 DIM control% 10,buffer% 255
25 REM call routine to read track 0 sector 0 to buffer
30 PROCsector_access(0,0,buffer%,1)
40 REM The catalogue is now at buffer%.....
50 REM Try looking at memory from buffer%.....
60 END
1000 REM
1010 REM This procedure will read/write any single sector from/to disk
1020 REM to/from the 256 byte buffer passed as a parameter.
1030 REM Format: PROCsector_access( track , sector , buffer address , mode
1040 REM where mode is zero to write sector and one to read sector
1050 REM A control block at control% must have previously been reserved
1060 REM by a: DIM control% 10
1070 REM
1080 DEF PROCsector_access(track%,sector%,buffer%,mode%)
1090 REM This sets up a parameter block for the DFS Rom:
1100 ?control%=0
1110 control%!1=buffer%
1120 control%?5=3
1130 control%?6=&48+11*mode%
1140 control%?7=track%
1150 control%?8=sector%
1160 control%?9=&21
1170 control%?10=0
1180 REM Set pointer to control% MOD256:Y%=control% DIV256
1200 CALL&FFF1
1210 REM Test for an error code returned by the DFS:
1220 IF control%?10<>0 THEN VDU7:PRINT ''"Disk error in PROCsector_access":END
1230 ENDPROC
James Bridson
Culcheth, Warrington