Commodore 1541-II User Manual page 66

Hide thumbs Also See for 1541-II:
Table of Contents

Advertisement

FORMAT FOR THE RECORD# COMMAND:
PRINT#15, "Pff + CHR$ (channel # + 96) + CHR$ (<record #) + CHR$
(>record #) + CHR$ (offset)
where "channel #" is the channel number specified in the current Open statement for the
specified file, "<record #" is the low byte of the desired record number, expressed as a
two byte integer, ">record #" is the high byte of the desired record number, and an
optional "offset" vaiue, if present, is the byte within the record at which a following
Read or Write should begin.
To fully understand this command, we must understand how most integers are stored
in computers based on the 6502 and related microprocessors. In the binary arithmetic used
by the microprocessor, it is possible to express any unsigned integer from 0-255 in a
single byte. It is also possible to store any unsigned integer from 0-65535 in 2 bytes, with
1 byte holding the part of the number that is evenly divisible by 256, and any remainder in
the other byte. In machine language, such numbers are written backwards, with the low-
order byte (the remainder) first, followed by the high order byte. In assemhly language
programs written with the Commodore Assembler, the low part of a two byte number is
indicated by preceding its label with the less-than character (<). Similarly, the high part
of the number is indicated by greater-than (>).
SAFETY NOTE: GIVE EACH RECORD# COMMAND TWICE!
To avoid the remote possibility of corrupting relative file data, it is necessary to
give Record# commands twice—once before a record is read or written, and again
immediately afterwards.
EXAMPLES:
To position the record pointer for file number 2 to record number 3, we could type:
PRINT #15, "P" + CHR$ (98) + CHR$ (3) + CHR$ (0)
The CHR$(98) comes from adding the constant (96) to the desired channel number (2).
(96 + 2 = 98) Although the command appears to work even when 96 is not added to the
channel number, the constant is noimally added to maintain compatibility with the way
Record# works on Commodore's CBM and PET computers.
Since 3 is less than 256, the high byte of its binary representation is 0, and the entire
value fits into the low byte. Since we want to read or write from the beginning of the
record, no offset value is needed.
Since these calculations quickly become tedious, most programs urc written to do
them for you. Here is an example of a program which inputs a record number and converts
it into the required low byte/high byte form:
58

Advertisement

Table of Contents
loading

Table of Contents