Memory resident workspaces

To process the diskettes, DOS creates various data structures in the last 310 bytes of the available RAM memory, which contain processing vectors, file management blocks and input/output buffers (Figure 1.7).

../_images/Figure7_1.jpg

Figure 7.1 The memory areas of DOS

DOS vectors

The first 67 bytes of this DOS work area contain the DOS vectors.

The address of the start of the DOS vectors is stored by DOS during system initialization to the Z80 register ‘IY’. DOS expects that this register will not be changed by user programs, otherwise a system crash will inevitably occur and data on the diskette may also be destroyed (bitter experience of the author).

The DOS vector area is structured as follows:

DOSVTR = IY

Name

Bytes

Offset

Description

FILNO

1

IY+0

File number.
When processing a data file, this is the
number of the file management block (FCB) used.
0 = FCB1 , 1 = FCB2

FNAM

8

IY+1

Filename
Name of the file to edit. must be
entered by the user program before
each file/program access.

TYPE

2

IY+9

File Type
Byte 1 = target type.
Byte 2 = actual type.
From the user program, the type of file
to be processed is in the first byte.

DK

1

IY+11

Selected Drive.
X’10’ = Drive 1
X’80’ = Drive 2
X’10’ is set during initialization.

RQST

1

IY+12

Access type.
0 = read
1 = write
Must be set by the user program.
With BASIC, this is done with the
OPEN command.

SOURCE

1

IY+13

Starting drive (source) used by
DCOPY command (1 or 2)

UBFR

2

IY+14

Address of a user buffer area to or
from which data is to be transferred.
When loading and saving programs,
this is the program area.
When reading data files, it is the
BASIC input/output buffer

DESTIN

1

IY+16

Target drive for the DCOPY command
(1 or 2)

SCTR

1

IY+17

Number of the Sector to be addressed

TRCK

1

IY+18

Number of the Track to be addressed

RETRY

1

IY+19

Retry counter for read errors
(checksum).
Set to 10 upon initialization.

DTRCK

1

IY+20

Current track number over which the
read/write head is located.

NSCT

1

IY+21

Marker field for the next sector to be
addressed.

NTRK

1

IY+22

Marker field for the next track to be
addressed.

FCB1

13

IY+23

File Control Block 1.
(see Structure description)

FCB2

13

IY+36

File Control Block 2.
(see Structure description)

DBFR

2

IY+49

Pointer to the DOS data buffer for
writing and reading a sector This is
located immediately after the DOS
vectors in the work area.

LTHCPY

1

IY+51

Copy of the command byte sent to the
Floppy Disk Controller.

MAPADR

2

IY+52

Pointer to the DOS buffer in which the
sector allocation map is
temporarily stored.
This is behind the data buffer in the
work area.

TRKCNT

1

IY+54

Track counter for the DCOPY
command

TRKPTR

1

IY+55

Track pointer for the DCOPY
command

PHASE

1

IY+56

Step pulse raster for track adjustment.

DCPYF

1

IY+57

Flag for DCOPY

RESVE

10

IY+58

reserved for extensions.

File Control Blocks (FCB)

Within the DOS vectors are two 13 byte file control blocks, FCB1 and FCB2.

These are required when processing data files in order to keep status and control information about the file being accessed.

A free file control block is determined by the OPEN command and provided with the necessary parameters for the file to be opened.

The IN# and PR# commands are based on the relevant file control block, e.g. which sector of the file is to be read and at which byte of this sector processing is to be continued.

The file control blocks are released again by the CLOSE command.

Since there are only two of these blocks, only two files can be open at the same time.

The File Control Block has the following structure:

FCB1 or FCB2

Name

Bytes

Offset

Description

FLAG

1

0

Indicates the status of the FCB.
0 - FCB not used
1 - FCB used, file currently not active
2 - FCR used, file active.
Active means that a current sector of
this file is in the data buffer for processing

ACCESS

1

1

Access type for this file.
0 - read
1 - write

FNAM

8

2

Filename

TRK#

1

10

Track Number

SCTR#

1

11

Sector Number of currently processed Sector

PTR

1

12

Pointer to the next byte to be processed
in the above sector.

Input/Output Buffer

In the DOS work area there are two buffer areas, one for temporary storage of the sectors to be read or written and a second for the sector occupancy overview.

Data Buffer (DBFR)

This buffer has a size of 154 bytes and serves as a buffer for direct data exchange with the floppy disk.

When writing, the sectors are transferred from the data buffer to the diskette; when reading, the sectors are transferred from the diskette to the data buffer.

During initialization, the 10 bytes of the data mark are set in front of the data buffer, so that a complete information block (data mark + data field) is available when a sector is written.

During normal read/write operations, only the first 128 bytes of the data buffer are used to hold a sector’s data field.

The full length of 154 bytes is only required during diskette initialization to accommodate a complete sector, including all sync fields, address fields, and identifiers.

Allocation Map Sector (MAP)

At the end of the DOS work area there is an 80-byte buffer area in which the Allocation Map from sector 15 of track 0 on the diskette is buffered.

When saving a program or writing a data file, the sectors are selected and allocated exclusively in this buffer area after the current sector has been read in at the beginning. Only when the saving process for the program is complete, the Allocation Map (MAP) is written back to the diskette.