
3030 GOSUB 59990
3040
INPUT#
l ,NA$,SA$,CS$,ZP$
3050 GOSUB 59990
3060PRINT#15
,
"P"
+ CHR$(96 + 3) +
CHR$(RL) + CHR$(RH)
Check for disk errors
Read
in
fields
Re-position for safety
Here are the lines needed
to
read back the version with fixed length fields :
3000
RH=
INT(RE/256)
3010
RL=RE-256*RH
3020
PRINT#l5
,
"P"
+CHR$(96+
3)
+CHR$
( RL) + CHR$(RH)
3030 GOSUB 59990
3040
INPUT#
1,DA$
3050 GOSUB 59990
3060
PRINT#l5
,
"P"
+CHR$(96+3)+
CHR$(RL) + CHR$(RH)
3070
NA$=
LEFf$(DA$,27)
3080
SA$=
MID$(DA$,28,27)
3090
CS$=
MID$(DA$,
55
,23)
3100 ZP$ = RIGHT$(DA$, 10)
Read
in
entire record
Split data into fields
This ends our discussion
of
relative files . A complete "RELATIVE FILE" pro
gram
,
similar to the examples
in
this chapter,
is
included on the Test/Demo diskette.
THE
VALUE
OF
INDEX FILES (ADVANCED USERS)
In
the last two chapters we have learned how to use sequential and relative
files
separately. But they are often used together, witti the sequentia.1
file
used to keep
brief
records
of
which name
in
the relative
file
is
stored
in
each record number. That way
the
contents
of
the sequential
file
can
be
read into a string array and sorted alphabetic
ally
.
After sorting, a technique
known as a binary search can be used to very quickly
fin
d
an
entered name
in
the array , and read
in
or write the associated record in the relative
file
.
Advanced programs can.maintain two or more such index files , sorted
in
differing
ways
simultaneously.
64
CHAPTER 7
DIRECT
ACCESS COMMANDS
!t
fOOL
FOR ADVANCED USERS
Direct access commands specify individual sectors on the diskette, reading and
writing
information entirely under your direction. This gives them
aln:io
.
st
.complete
oexibility in data-handling proerams, but also imposes tremendous respons1b1httes on
t~e
programmer, to
be
sure nothing goes awry .
As
a
res~Jt,
they
a~e
normally used only. m
complex
commercial programs able
to
properly organize data without help from the disk
drive
itself. . . . .
A far more common use
of
direct access commands
1s
m utility programs used to
view
and alter parts
of
the diskette that are not normally seen directly. For i.nstance,
su~h
onunands can be used to change the name of a diskette without erasing all of
it
s
~grams,
to
lock a program so
it
can't be erased, or hide your name
in
a location where
it
won't
be
expected.
DISKETTE
ORGANIZ~
TION
There are a total
of
683 blocks
on
a
1541
diskette,
of
which 664 are available for use ,
with
the rest reserved for the BAM (Block Availability Map) and the Directory.
The diskette's surface
is
divided into tracks, which are laid out as concentric circles
on
the
surface
of
the diskette. There are
35
different tracks, starting with track I
at
the
outside
of
the diskette
to
track
35
at the center. Track
18
is
used for the directory, and
th
e
DOS
fills
up the diskette from the center outward, alternately
in
both directions.
Each track
is
subdivided into sectors (also called blocks). Because there
is
more
room
on the outer tracks, there are more sectors per track there. The outermost tracks
contain
21
sectors each, while the innermost ones only have
17
sectors each . The table
below
shows the number
of
sectors per track.
Table 6.1: Track and Sector Format
TRACK NUMBER SECTOR NUMBERS TOTAL SECTORS
I to
17
18
to 24
25
to 30
31
to 35
0 through 20
0
through
18
0 through
17
0 through
16
21
19
18
17
In
this chapter we will describe the DOS commands for directly reading and writing
any
track and block mi the diskette, as well as the commands used
to
mark blocks as used
or
unused. Unless otherwise notes, all direct access commands are
th
e same
in
both Basic
2and Basic 3.5.
OPENING
A DATA CHANNEL FOR DIRECT ACCESS
When working with direct access data, you.need two channels open to the disk:
th
e
conunand
channel
we
've used throughout the book, and another for data. The command
Channel
is
opened with the usual OPEN
15
,8,
15
or equivalent. A direct
ac
ce
ss
data
65
Kommentare zu diesen Handbüchern