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 ...
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
ENTRY JR BEGIN ;Branch around linkage<br />
STUFHI DW $-$ ;To contain last byte used<br />
DB MODDCB-BEGIN-5 ;Calculate length of 'NAME'<br />
DB 'MODNAME' ;Name of this module<br />
MODDCB DW $-$ ;To contain DCB pointer for module<br />
DW 0 ;Reserved by the DOS<br />
BEGIN EQU $<br />
;*=*=*<br />
; Actual module code start<br />
;*=*=*<br />
JR C,WASGET ;Go if @GET request<br />
JR Z,WASPUT ;Go if @PUT request<br />
JR WASCTL ;Was @CTL request<br />
At the entry of the driver, an absolute relative jump instruction executes which causes a<br />
branch around some data. Ignore, for a moment, the header data which is discussed in the<br />
Chapter 8, appendix. At the label "BEGIN", a test is made on the CARRY FLAG. If the CARRY<br />
was set, then it must have been the result of an input request (@GET). Thus, an input<br />
request could be directed <strong>to</strong> that part of the module which handles character INPUT.<br />
If the request was not from the @GET primitive, the CARRY will not be set. <strong>The</strong> next test<br />
is if the ZERO FLAG is set. <strong>The</strong> ZERO condition prevailed when an @PUT primitive was the<br />
initial request. Thus the jump <strong>to</strong> WASPUT can transfer <strong>to</strong> that part of the module that<br />
deals specifically with character OUTPUT.<br />
If neither the ZERO nor CARRY flags are set, the routine falls through <strong>to</strong> the next<br />
instruction, a jump <strong>to</strong> WASCTL - that part of the module that would handle @CTL requests.<br />
Obviously, the module code that handles @CTL requests could be placed immediately after<br />
the first two tests thereby obviating the need for the "JR WASCTL". Some modules are<br />
written <strong>to</strong> assume that @CTL requests are <strong>to</strong> be handled exactly like @PUT requests<br />
although this is not recommended. <strong>The</strong> processing of @CTL requests is entirely up <strong>to</strong> the<br />
function of the driver and the author thereof with the exception that the author should<br />
not deviate from the functions identified in the @CTL INTERFACING section. When a device<br />
has been routed <strong>to</strong> a disk file, the DOS will ignore @CTL requests. That is, the @CTL<br />
codes will not be written <strong>to</strong> the disk file. <strong>The</strong> functions of @CTL requests are covered as<br />
a separate <strong>to</strong>pic later in this chapter.<br />
3.5.3 Device Driver/Filter Return Codes<br />
One last <strong>to</strong>pic needs <strong>to</strong> be discussed relating <strong>to</strong> drivers - the subject of register<br />
handshaking conventions. On @GET requests, the character input should be placed in the<br />
accumula<strong>to</strong>r. On output requests (either @PUT or @CTL), the character is obtained from<br />
register C. It is extremely important for drivers and filters <strong>to</strong> observe return codes.<br />
Specifically, if the request is @GET and no byte is available, the driver returns an NZ<br />
condition with the accumula<strong>to</strong>r containing a zero (i.e. OR 1 : LD A,0 : RET). If a byte is<br />
available, the byte is placed in the accumula<strong>to</strong>r and the Z-flag is set (i.e. LD A,CHAR :<br />
CP A : RET). If there is an input error, the error code is returned in the accumula<strong>to</strong>r<br />
and the Z-flag is reset (i.e. LD A,ERRNUM : OR A : RET). On output requests, the Z-flag<br />
is set if no output error occurred. <strong>The</strong> accumula<strong>to</strong>r may be loaded with the character that<br />
was output; however, applications invoking an @PUT cannot depend on the accumula<strong>to</strong>r<br />
containing the output character on return from the SVC - the character will, however,<br />
still be contained in the C register! In the case of an output error, the accumula<strong>to</strong>r<br />
must be loaded with the error code and the Z-flag reset as shown above.<br />
3.5.4 Filter Interfacing<br />
A filter module is inserted between the DCB and driver routine (or between the DCB and<br />
the current filter when applied <strong>to</strong> a DCB already filtered). <strong>The</strong> application of insertion<br />
is performed by the DOS FILTER command once the filter module is resident and associated<br />
3-11