Blockread
The purpose of a BLOCK-READ is to load the contents of a specified sector into a file buffer. Although the BLOCK-READ command (B-R) is still part of the DOS command set, it is nearly always replaced by the U1 command (See Chapter 6).
FORMAT FOR THE BLOCK-READ COMMAND:
PRINT#15, "Ul"; channel #; drive #; track #; sector #
where "channel #" is the channel number specified when the file into which the block will be read was opened, "drive #" is the drive number, and "track #" and "sector #" are respectively the track and sector numbers containing the desired block of data to be read into the file buffer.
ALTERNATE FORMATS:
PRINT#15,"Ul:"channel #;drive #;track #;sector # PRINT# 15,"UA:"channel #;drive #;track #;sector # PRINT#15,"Ul:channel #,drive #,track #,sector #"
EXAMPLE:
Here is a complete program to read a sector into disk memory using Ul, and from there into computer memory via GET#. (If a carriage return will appear at least once in every 88 characters of data, INPUT# may be used in place of GET#).
110 MB = 7936:REM $1F00 120 INPUT"TRACK TO READ";T 130 INPUT"SECTORTO READ";S 140 OPEN 15,8,15 150 OPEN 5,8,5,"#" 160 PRINT#15,"U1";5;0;T;S 170 FOR I = MB TO MB + 255 180 GET#5A$:IFA$ = " " THEN A$ = CHR$(0) 190 POKE IASC(A$) 200 NEXT
210 CLOSE 5:CLOSE 15 220 END
Define a memory buffer. Select a track and sector.
Open command channel. Open direct access channel. Read sector into disk buffer. Use a loop to copy disk buffer, into computer memory. Tidy up after.
As the loop progresses, the contents of the specified track and sector are copied into computer memory, beginning at the address set by variable MB in line 160, and may be examined and altered there.
The DOS always checks that the track and sector parameters of the BLOCK-READ command are within the proper range. If they're not, a "66 ILLEGAL TRACK AND SECTOR" error occurs. In certain instances it might be necessary to access a track and sector that are not within what the DOS considers the proper bounds. This is a special case and, unless absolutely necessary, should be avoided. Nonetheless, there is a command identical in function to "Ul" that doesn't check to see if the track and sector parameters are. within bounds before attempting to read it. Its format is:
PRINT#15,"B-_"¡channel #;track #;sector #
(The character following the B- is a shifted R.)
PRINT#15,"B-";CHR$(210);channel #;track #;sector #
Post a comment