29.12.2012 Views

The Programmer's Guide to TRSDOS Version 6 - Tim Mann's Home ...

The Programmer's Guide to TRSDOS Version 6 - Tim Mann's Home ...

The Programmer's Guide to TRSDOS Version 6 - Tim Mann's Home ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

of a variable length record. Some systems use CARRIAGE RETURN followed by LINE FEED<br />

(X'0A'). Some languages use a one-byte or two-byte length indica<strong>to</strong>r within the record <strong>to</strong><br />

indicate the actual length of the record. Program files that are directly executable are,<br />

in fact, variable length record files which use a one-byte length field within each<br />

record. <strong>The</strong>se "load module" files even include a record TYPE character which permits the<br />

specification of different records for different purposes within the same file.<br />

Some files may not even be able <strong>to</strong> be conceptualized as containing fixed or variable<br />

length records. You might consider a word processing text file as not falling in<strong>to</strong> the<br />

above classification although each paragraph may, in fact, be a "record". Other files may<br />

be variable length but include an index which points <strong>to</strong> the beginning of each record or<br />

group of records. <strong>The</strong> records are accessed sequentially after the record pointer is<br />

extracted from the index. This type of access is usually called Indexed Sequential Access<br />

Method (ISAM). Both the operating system's library files and the Partitioned Data Set<br />

files supported under the PRO-PaDS utility are ISAM files. <strong>The</strong> bot<strong>to</strong>m line is for you <strong>to</strong><br />

determine the type of access you want <strong>to</strong> employ after exploring the nature of your data<br />

and understanding how the system accesses disk files.<br />

<strong>The</strong>re are three methods which are used in application programs <strong>to</strong> access disk files. <strong>The</strong><br />

first method is <strong>to</strong> consider the file as a stream of characters. This access method uses<br />

the GET and PUT character I/O SuperVisor Call functions and was discussed in chapter 3,<br />

DEVICE INPUT/OUTPUT INTERFACING. <strong>The</strong> second method is where your file contains physically<br />

consistent fixed length records. In this case, it is probably practical <strong>to</strong> consider<br />

RECORD I/O. <strong>The</strong> third method is <strong>to</strong> use 256-byte records and perform your own blocking or<br />

deblocking as required.<br />

<strong>The</strong> following sections describe the methods used <strong>to</strong> control and access files. <strong>The</strong> last<br />

section completely describes the fields in the File Control Block which is used in all<br />

interfacing of disk files.<br />

6.2 CONTROLLING DISK FILES<br />

When a file is <strong>to</strong> be opened for access, the application program initially provides the<br />

file specification <strong>to</strong> the DOS by placing it in the File Control Block (FCB) which will be<br />

used for the file. <strong>The</strong> program then invokes the OPEN function. <strong>The</strong> DOS, in turn, searches<br />

the disk drive(s) for the file's direc<strong>to</strong>ry entry. Once found, it replaces the filespec in<br />

the FCB with information needed by the file access routines. <strong>The</strong> system then manages the<br />

FCB contents according <strong>to</strong> the demands of the file access requests. <strong>The</strong> following sections<br />

will illustrate some of these control functions.<br />

6.2.1 Getting Filespecs<br />

From where does a program obtain the filespec? You are already familiar with the DOS<br />

commands that appear <strong>to</strong> get the filespec from the command line. Let's take a look at this<br />

method. You will learn from the chapter on SuperVisor Calls that when the system<br />

transfers control <strong>to</strong> a program, register pair HL contains a pointer <strong>to</strong> the first nonblank<br />

character on the command line which terminated the name of the executing program.<br />

Let us assume that our program will use a command line syntax as follows:<br />

PROGRAM-NAME FILE-SPECIFICATION (PARAMETERS)<br />

<strong>The</strong> command-line pointer will be pointing <strong>to</strong> the first character of the file<br />

specification. For the moment, let's make the filespec entry manda<strong>to</strong>ry. We can then code<br />

the routine <strong>to</strong> fetch the filespec as follows:<br />

ENTRY LD DE,FCB1 ;Point <strong>to</strong> FCB<br />

LD A,@FSPEC ;Identify the SVC<br />

RST 40 ;Invoke the SVC<br />

JP NZ,SPCERR ;Transfer on error<br />

6-3

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!