• Keine Ergebnisse gefunden

OF THE FILE TYPE DENOTES A PROTECTED FILE!

Im Dokument THE ANATOMY OF THE 1541 DISK DRIVE (Seite 119-126)

If you set this bit to I, the corresponding file can no longer be deleted. This is designated in the directory listing with a < next to the file type. Because setting this bit requires some complicated commands, you will find a program in chapter 4 of this book with which you can protect, unprotect, and delete files.

Track and sector of the first Data Block

Bytes 1 and 2 of the file entry point to the first data block of the file. The first byte contains the track and the second the sector number where the file begins. The first data block, in turn contains a pointer to the second block of the file (also contained in the first two bytes of the block). The last data block of the file is indicated by a first-byte value of $00. The second byte contains the number of bytes used in this last sector.

This concatenation can be explained with the help of the Dl'S MONITOR, contained in this book:

> :BO AD AD AD AD AD 00 00 00

> :B8 00 00 00 00 00 00 DB 00

· ...

>:CO 00 00 81 13 09 54 31 32 •.••• T12

> :C8 2F 53 30 31 AD AD AD AD /SOI

> :00 AD AD AD AD AD 00 00 00

>: D8 00 00 00 00 00 00 06 00

· ...

):EO 00 00 82 10 00 44 49 53 •••.. DIS ): E8 4B 20 41 44 44 52 20 43 K ADDR C

>:FO 48 41 4E 47 45 00 00 00 BANGE •••

>: F8 00 00 00 00 00 00 04 00

This is an extract from the directory (track 18, sector 1) of the TEST/DEMO diskette. You can follow the organization of the file DISK ADDR CHANGE. The entry of this file begins at byte $E2 and ends with byte $FF. This is a PRG file, which can be recognized by the file type $82 in byte $E2.

This file comprises 4 blocks on the disk. This is evident from bytes $FE and $FF. Bytes SE3 and SE4 of the entry address the f i r s t data block of the file {SID, SOD, corresponding to track 16, sector OJ.

Let's look at a section of this block:

>:00 10 OA 01 04 OF 04 64 00 • •••.• $ •

>:08 97 35 39 34 36 38 2C 31 .59468,1 ):10 32 00 39 04 6E OD 99 22 2.9 ••.•

"

>:18 93 13 11 11 11 11 44 52 • ••••• DR ):20 49 56 45 20 41 44 44 52 IVE ADDR

>: 28 45 53 53 20 43 48 41 4E ESS CHAN

111

Anatomy of the 1541 Disk Drive

>:20 01 98 31 35 2C 22 4D 2D •.

15,"M->:28 52 22 C7 28 31 37 32 29 R" (172)

>: 30 C7 28 31 36 29 3A Al 23 (16) : #

>:38 31 35 2C 5A 43 24 3A SA 15,ZC$:Z

>:40 43 B2 C6 28 5A 43 24 AA C F(ZC$

>:48 C7 28 30 29 29 00 66 07 G(O».&.

Here the end of the program is marked by the value $00 in byte $00. Byte $01 gives the number of bytes in this last block that belong to the program. ($F8 corresponds to 248 bytes). Now we can find out the size of the program:

3 blocks with 254 bytes each = 762 bytes

last block = 248 bytes

Size of the program llOO bytes

The Filename:

The filename is contained in bytes 3-18 of the file entry.

It consists of a maximum of 16 characters. Should the name be shorter than 16 characters, the rest of the name is padded with shifted spaces (SAO).

Track and Sector of the new File for "Overwriting-:

If a file is overwritten by using the @:, the new file is first completely saved. No filename entry is made in the directory for this file because the file already exists under this same name. Instead the address of the first block of the new file is placed in bytes 26 and 27 of the filename entry. If the new program is removed, the old one is deleted, which merely designates the blocks allocated to the file as free in the BAM. Now the address of the first data block of the new file is placed into the filename entry in bytes I and 2 is used and the file is "overwritten".

Number of Blocks in the File:

The length of a file is given in bytes 28 and 29 of its file entry. A file consists of at least one block and as many as 664 blocks. The first byte is the low byte, and the second is the high byte. If, for example, you discovered the file length $IF,SOO with the DISK MONITOR, the file consists of 31 blocks.

113

Anatomy of the 1541 Disk Drive

3.4 The Organization of Relative Piles

Relative files differ from sequential files in that each data record can be accessed directly by a record number.

The 1541 OOS takes care of most of the tasks required to support relative records. Let's take a closer look at the organization of a relative file.

First OPEN a relative file with a record length of 100:

OPEN 2,8,2, "REL-FILE,L,"+CHR$(lOO) Now write data record number 70:

The

>:00

>:08

>:10

>:18

OPEN 1,8,15

PRINTU,"P"+CHR$(2)+CHR$(70)+CHR$(0)+CHR$(1) PRINT*2,DDATA FOR RECORD 70"

CLOSE 2 : CLOSE 1

directory entry then looks like this:

84 11 00 52 45 4C ••• REL 20 46 49 4C 45 AO AO AO -FILE AO AO AO AO AO 11 OA 64 •• $ 00 00 00 00 00 00 10 00

...

The first byte $84 denotes a relative file. The next two bytes denote the first track and sector of the data ($11,

$00: track 17 sector 0): exactly as with a sequential file.

As usual, the name of the file follows (16 characters, padded with shifted spaces, $AO). Following are two fields not used with sequential files. The first field is a two byte pointer to the track and sector of the first side-sector block. A side-side-sector contains the pointers to each data record and is described more in detail later ($11, $OAI track 17, sector 10). The second field is a byte w-hich contains the record length, a value between 1 and 254, in our case $64 (100).

The convenience of being able to access each record individually requires a definite length for each record thet must be defined when establishing a relative file. The rest of the fields in the directory entry have the usual significance; the last two bytes contain the number of blocks in the file (10 and hi byte, $10 and $00 (29».

What does such a side-sector block look like and what is its function?

The side-sector blocks contain the track and sector pointers to the individual data records. For example, if we want to read the 70th record in the relative file, the DOS consults the side-sector block to determine which track and sector contains the record and then read this record directly. As

114

a resul t, you can read the 70th record of the file without having to read the entire file. Now let's take a look at the exact construction of a side-sector block. This s ide-sectc'r block is from our previous file.

>:00 00 47 00 64 11 OA 00 00 .G.$ ••••

>:08 00 00 00 00 00 00 00 00

· ...

>: 10 11 00 11 OB 11 01 11 OC

· ...

>:18 11 02 11 OD 11 03 11 OE

· ...

>:20 11 04 11 OF 11 05 11 10

· ...

>:28 11 06 11 11 11 07 11 12

· ...

>:30 11 08 11 13 11 09 11 14

· ...

>:38 10 08 10 12 10 06 10 10

· ...

>:40 10 04 10 OE 10 02 10 OC

...

>:48 00 00 00 00 00 00 00 00

· ...

>:50 00 00 00 00 00 00 00 00

· ...

etc.

The first two bytes point to the track and sector of the next side-sector block, as usual. In our case, no further side-sector blocks exist ($00) and only $47

=

71 bytes of this sector are used. Byte 2 contains the number of the side-sector block, 00. A relative file can contain a maximum of 6 such blocksl the numbering goes from 0 to 5. The record length, $64 (100), is in byte 3. The next twelve bytes (bytes 4 through 15) contain the track and sector pointers (two bytes each) to the 6 side-sector blocks (00,00 means the block is not yet used). Starting at byte 16 ($10) are the pointers to the data, and the track and sector pointers to the first 120 data blocks (in our case, only ~8

pointers). Using the record number and record length, the DOS can calculate in which block the data lies and at which position within the block the record begins. Take the following example, for instance:

To read the 70th record from the file with a record length of 100 characters, you can perform the following calcula-tions:

(70-1)

*

100 / 254

We get a quotient of 27 and a remainder of 42. The DOS now knows that the record can be found in the 27th data block at the 42+2 or 44th position.

Here's an explanation of the calculation. Each block contains 256 bytes, the first two of which are used as a pOinter to the next block. 254 bytes are then left over for data storage. We can calculate the byte number from the start of the file (which is record 1) from the record number and record length. If we divide this value by the number of bytes per block, we get the number of the block containing the record. The remainder of the division gives the position within the block (add 2, because the first two bytes serve as a pointer). If the record overlaps the end of the block,

115

Anatomy of the 1541 Disk Drive

containing the record length. Two channels are reserved for the relative file,one for the data, the other for the side-sectors. If a record pointer is set to a specific record, the DOS first checks to see if the record already exists. If so, the corresponding block is read and the buffer pointer set so that the contents can be accessed. If not, the record is created. All records preceding this record number that do not already exist are also created. The first byte of a new record is written to contain $FF (255), and the rest of the record is filled with $00.

If the corresponding record is at the beginning of a block, the rest of the block is filled with empty records. Each time a non-existing record is accessed, the error message 50,RECORD NOT PRESENT is returned. When writing a new record, this is not considered an error, but indicates that a new record was created.

You can use this method for creating a new file if you know the maximum number of data records. You simply set the record pointer to this record and write $FF (CHR$(255» to this record. By allocating a file like this, the error message 50 no longer appears. You also know if there is sufficient space on the diskette. If not, the error message 52, FILE TOO LARGE is returned.

With a maximum of 6 side sectors, a relative file can contain 6

*

120

*

254 = 182,880 bytes. In the case of the VIC 1541, this is more than the capacity of the whole diskette. With the bigger 8050 drive, which contains more than 500K of storage, this may present a limitation. But DOS version 2.7 has an expansion of the side-sector procedure ('super side-sector'), with which a relative file mey contain up to 23 MB. DOS 2.7 is contained in the CBM 8250 and the Commodore hard drives as well as the newer 8050 drives (see section 5.2).

Because a relative file requires two data channels, and the VIC 1541 has only 3 channels available, only one relative file can be open at a time. The third channel can still be used for a sequential file open at the same time. With the larger CBM drives, more channels are available (3 relative files open simultaneously, see also section 5.2).

117

Anatomy of the 1541 Disk Drive

interpret command from computer

last drive number

Im Dokument THE ANATOMY OF THE 1541 DISK DRIVE (Seite 119-126)