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 ...
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
LD HL,FCBX+9 ;Point <strong>to</strong> the LRL field<br />
LD B,(HL) ;P/u the current LRL<br />
LD (HL),1 ; & reset <strong>to</strong> LRL=1<br />
LD A,@BKSP ;Identify the SVC request<br />
RST 40 ;Invoke the SVC<br />
LD (HL),B ;Reset <strong>to</strong> original LRL<br />
JP NZ,IOERR ;Transfer on error<br />
If you want <strong>to</strong> add sequential data <strong>to</strong> the end of an existing file, you will need <strong>to</strong><br />
position <strong>to</strong> the end of the file after it is opened. Use the @PEOF SuperVisor Call request<br />
for this purpose. <strong>The</strong> SVC will return an "End of file encountered" error if the request<br />
is successful. Any other error code indicates a malfunction. This is one of the few<br />
system requests that return an error code upon success so you should be careful when you<br />
use it.<br />
<strong>The</strong> @RREAD request is useful when reading nested files. Nested files are those where you<br />
are accessing each consecutively but not coincidentally. In this case, the same disk file<br />
I/O buffer can be used for each file. When you switch from one file <strong>to</strong> another, issue a<br />
@RREAD so that the system reloads the buffer with the sec<strong>to</strong>r that was being accessed for<br />
the last record read or for the last character obtained from @GET. <strong>The</strong> @RREAD request<br />
will force a rereading of the sec<strong>to</strong>r identified by the NRN provided that the LRL is<br />
either 1-255 or the file was accessed via @PUT or @GET. What do you do if you were using<br />
LRL=256 and @READ requests while maintaining your own offset pointer. All you need do in<br />
this case is <strong>to</strong> decrement the NRN and issue another @READ. For example, the PRO-CREATE<br />
edi<strong>to</strong>r assembler available from MISOSYS uses sec<strong>to</strong>r I/O for reading source files. PRO-<br />
CREATE maintains its own offset pointer as it extracts lines of code from the disk<br />
buffer. When it detects the "*GET filespec" request for including a nested file, it saves<br />
the current FCB in a save area and then opens the requested file using the same file<br />
buffer. When the end of the second file is reached, PRO-CREATE res<strong>to</strong>res the saved FCB of<br />
the original file and executes the following code:<br />
LD DE,FCB ;Point <strong>to</strong> the opened FCB<br />
LD HL,(FCB+10) ;Obtain the current NRN,<br />
DEC HL ; decrement by one<br />
LD (FCB+10),HL ; and update the FCB<br />
LD A,@READ ;Identify the SVC function<br />
RST 40 ;Invoke the SVC<br />
JP NZ,IOERR ;Transfer on error<br />
<strong>The</strong> @RWRIT SuperVisor Call request would be used where you want <strong>to</strong> read a full sec<strong>to</strong>r<br />
(LRL=256) in<strong>to</strong> the disk file I/O buffer, alter it directly in the buffer, then<br />
immediately write that buffer back <strong>to</strong> disk. <strong>The</strong> @RWRIT will force the NRN that was<br />
au<strong>to</strong>matically advanced by the @READ request <strong>to</strong> be decremented by one so that it repoints<br />
<strong>to</strong> the sec<strong>to</strong>r corresponding <strong>to</strong> the buffer contents. It then performs the requests<br />
necessary <strong>to</strong> write the buffer <strong>to</strong> disk. Note that @RWRIT is not <strong>to</strong> be used when the LRL is<br />
not equal <strong>to</strong> 256 as this SuperVisor Call does not reference the user record buffer.<br />
<strong>The</strong> @WEOF SuperVisor Call request allows you <strong>to</strong> update the end-of-file (EOF) information<br />
in the direc<strong>to</strong>ry while still keeping the file in an open state. Obviously, a similar<br />
function can be performed with an @CLOSE followed by an @OPEN; however, complications can<br />
prevail with a CLOSE-OPEN combination. Remember that the close operation res<strong>to</strong>res the<br />
filespec <strong>to</strong> the FCB but cannot reclaim the password. <strong>The</strong>refore, if the FCB was<br />
referencing a password protected file, the subsequent OPEN will fail unless you had saved<br />
the original filespec somewhere in the program and restuffed the FCB prior <strong>to</strong> the second<br />
OPEN request. Also, the CLOSE-OPEN combination updates the MOD flag and date as required,<br />
and checks <strong>to</strong> see if it can deallocate any unused file space. This takes time. If all you<br />
want <strong>to</strong> do is <strong>to</strong> update the EOF, use the @WEOF function.<br />
One last function that can be performed by the file access routines is the allocation of<br />
disk space <strong>to</strong> a file. A file can be pre-allocated by the CREATE library command but that<br />
6-12