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.

the hash code in the proper DEC, and reallocating the space in the GAT provided the space<br />

has not been reused by some other file.<br />

Two other lesser used SuperVisor Call requests are @LOAD and @RUN. It's more important <strong>to</strong><br />

explain their use rather than illustrate their use. Most programs are stand-alone<br />

programs. <strong>The</strong>y are <strong>to</strong>tally self contained in terms of the program code. When programs get<br />

large or when programs must access large amounts of data in memory, it may be necessary<br />

<strong>to</strong> segment the program in<strong>to</strong> two or more sub-programs. Depending on the functions<br />

performed by the program, this segmentation can take two forms. Where the functions can<br />

be divided in<strong>to</strong> separately chained processes (such as a language compiler that can<br />

separate parsing from code generation), one sub-process can RUN the other sub-process.<br />

Where the functions of the program must be divided up and controlled by a supervising<br />

sub-program, the available memory can be divided in<strong>to</strong> a resident sub-program region and<br />

an overlay sub-program region - similar <strong>to</strong> the overlay structure of the operating system.<br />

Thus the supervisor will LOAD each overlay as required and transfer control in<strong>to</strong> the<br />

loaded sub-program.<br />

When an executing program needs <strong>to</strong> either @RUN or @LOAD another program, there is one<br />

point that is most important <strong>to</strong> understand. Although the @RUN and @LOAD functions utilize<br />

the system file buffer, they require a user File Control Block. Also, either request will<br />

return <strong>to</strong> the calling program if an error is detected in the loading of the program file.<br />

<strong>The</strong>refore, it is essential that the program being loaded must not overwrite either the<br />

FCB used <strong>to</strong> access it nor the error handling routines following the @LOAD or @RUN linkage<br />

requests! To ignore this situation is <strong>to</strong> invite disaster <strong>to</strong> come knocking at your door.<br />

6.3 ACCESSING DISK FILES<br />

<strong>The</strong> concept of accessing disk files conveys the idea of transferring data <strong>to</strong> and from the<br />

disk file. Before the file can be accessed, it must be opened as discussed in the<br />

preceding section. Once a file has been opened, any of a number of file access SuperVisor<br />

Call requests can be made depending on the specific nature of the desired function.<br />

It may be useful <strong>to</strong> understand exactly how the operating system's file access routines<br />

react in order <strong>to</strong> satisfy our request. Let us say, for example, that we want <strong>to</strong> read the<br />

100th record of the BULKLOAD/DAT file. <strong>The</strong> 100th record has a record number of 99 since<br />

records are numbered starting from record 0. We establish the linkage <strong>to</strong> accomplish this<br />

as follows:<br />

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

LD BC,99 ;Specify the record number<br />

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

RST 40 ;Invoke the SVC function<br />

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

LD HL,UREC1 ;Point <strong>to</strong> our record buffer<br />

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

RST 40 ;Invoke the SVC<br />

JP NZ,IOERR ;Transfer on an error return<br />

<strong>The</strong> first part of the linkage positions the FCB so that the next I/O operation will deal<br />

with record number 99 - the 100th record. After a successful positioning, the record will<br />

be read in<strong>to</strong> the record buffer. This is a very brief explanation. Let's examine in<br />

detail, the sequence of steps actually executed by the file positioning routine, @POSN.<br />

First, since the file's LRL is less than 256, the 100th record must be deblocked from the<br />

sec<strong>to</strong>r containing the record (or sec<strong>to</strong>rs if by chance the 100th record spans two<br />

sec<strong>to</strong>rs). By multiplying the record number (99) by the logical record length (80), the<br />

value 7920 is obtained. This represents the first byte of the record in OFFSET position<br />

240 of relative sec<strong>to</strong>r number 30.<br />

6-9

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

Saved successfully!

Ooh no, something went wrong!