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.

8.5 HEADER PROTOCOL OF MEMORY MODULES<br />

A module of code can be relocated in<strong>to</strong> high memory so that it's last byte is positioned<br />

at the value returned from the @HIGH$ SuperVisor Call. <strong>The</strong> module is then protected from<br />

being overwritten by other modules by adjusting HIGH$ <strong>to</strong> point <strong>to</strong> the address preceding<br />

the start of the module. Modules relocated and protected in this manner, must include a<br />

standard header that identifies the module. Modules placed in<strong>to</strong> the low memory I/O driver<br />

region also must adhere <strong>to</strong> this standard. <strong>The</strong> header is used by the system <strong>to</strong> accomplish<br />

a number of important functions. First, it provides a locatable s<strong>to</strong>rage region for<br />

pointers used in the device independent library operations. Second, it provides a name<br />

string used by the @GTMOD SuperVisor Call <strong>to</strong> locate a specific module. Other data<br />

contained in the header provides the information needed <strong>to</strong> identify the entry address of<br />

each module so protected.<br />

<strong>The</strong> following code describes this standard header:<br />

ENTRY JR BEGIN ;Branch around linkage<br />

STUFHI DW $-$ ;To contain last byte used<br />

DB MODDCB-ENTRY-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 />

;*=*=*<br />

; Area that can be used <strong>to</strong> s<strong>to</strong>re data<br />

;*=*=*<br />

.<br />

BEGIN EQU $<br />

;*=*=*<br />

; Actual module code start<br />

;*=*=*<br />

Let's examine this module header line by line so that you gain an understanding of its<br />

purpose. At the label "ENTRY", the header always will have a relative jump instruction.<br />

<strong>The</strong> operand of the jump will almost always reference the starting address of your module.<br />

An exception <strong>to</strong> this would occur if the data area was extensive so that it placed the<br />

label "BEGIN" beyond the range of the jump relative instruction. If such was the case,<br />

you must provide an absolute jump (JP) instruction just prior <strong>to</strong> the data area. <strong>The</strong><br />

address of this instruction will then be used as a reference in the operand field of the<br />

ENTRY jump relative.<br />

It is also possible that the "module" is not a program but rather a data area that you<br />

have reserved. This data area must still have a memory header; however, since there<br />

exists no BEGIN address, it is recommended that you reference the operand of the ENTRY<br />

jump relative instruction so that it jumps <strong>to</strong> ENTRY (i.e. jumps <strong>to</strong> itself). This is the<br />

second exception.<br />

<strong>The</strong> 2-byte s<strong>to</strong>rage region identified by the label STUFHI must be loaded with a value<br />

equal <strong>to</strong> the last memory address used by the module. <strong>The</strong> program routine that relocates<br />

the module in<strong>to</strong> its memory position is responsible for loading this value. <strong>The</strong> system's<br />

@GTMOD routine uses the value <strong>to</strong> be able <strong>to</strong> branch sequentially from module <strong>to</strong> module. If<br />

the module is placed in<strong>to</strong> high memory, this address value is the value returned by<br />

@HIGH$.<br />

<strong>The</strong> next two fields of the header are the name LENGTH and NAME fields. <strong>The</strong> NAME field<br />

will contain the module's name as assigned by the programmer. This is the name string<br />

that is used in the @GTMOD SuperVisor Call <strong>to</strong> locate the module. <strong>The</strong> name must range from<br />

characters in length and cannot have any character value below X'20'. <strong>The</strong> length<br />

of the name is then placed in<strong>to</strong> bit positions 0-3 of the LENGTH field. <strong>The</strong> system uses<br />

the length value <strong>to</strong> determine how many characters must be matched in the NAME field. Bits<br />

4-7 of the LENGTH byte are reserved by the operating system.<br />

8-14

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

Saved successfully!

Ooh no, something went wrong!