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.
7. Interfacing via SuperVisor Calls<br />
7.1 SUPERVISOR CALL LINKAGE<br />
This chapter discusses specific linkage necessary <strong>to</strong> communicate with the operating<br />
system for service requests at the assembly language level. Requests for system resources<br />
are accomplished via SuperVisor Calls (SVCs). <strong>The</strong> following sections describe each SVC<br />
and the register contents passed <strong>to</strong> and from the system.<br />
<strong>The</strong> DOS does not affect the contents of the Z-80's alternate registers (AF', BC', DE',<br />
and HL'). Where the DOS makes use of index registers IX and IY, it will save them prior<br />
<strong>to</strong> their use and res<strong>to</strong>re them when that use is completed. <strong>The</strong> exception, of course, is<br />
where IX and/or IY are used <strong>to</strong> pass information <strong>to</strong> or from the DOS.<br />
Each SVC specifies what registers are altered by the system. <strong>The</strong> AF register will always<br />
be altered. Most SVCs incorporate return codes. Where applicable, the return code is<br />
passed in the accumula<strong>to</strong>r and the Z-flag status is indicative of an error or success [ Z<br />
= success, NZ = error ]. Some SVCs use only the state of the Z-flag <strong>to</strong> indicate a<br />
pass/fail situation. <strong>The</strong> return code convention is specified under the linkage shown for<br />
each SVC.<br />
SuperVisor Calls utilize a number from 0 <strong>to</strong> 127. Numbers from 128 <strong>to</strong> 255 are not<br />
interpreted as SVCs but are used internally by the DOS for other system overlay<br />
invocations. <strong>The</strong> SVC number is placed in the accumula<strong>to</strong>r once the registers particular <strong>to</strong><br />
the SVC are set up and control is passed <strong>to</strong> the operating system by issuing a RST 40 (RST<br />
28H) Z-80 instruction.<br />
7.1.1 Adding or Changing SVC Entries<br />
Some programmers may find it useful <strong>to</strong> alter the performance of existing SuperVisor Calls<br />
<strong>to</strong> suit unique situations. A program may even be written that could utilize additional<br />
SVCs. Four SVC slots [numbers 124-127] have been provided for application programs. An<br />
examination of the following SVC tables will reveal a good handful of SVC numbers that<br />
have not yet been assigned by Logical Systems. Caution is <strong>to</strong> be observed in utilizing any<br />
of these reserved slots since you may find your program unusable with a future release of<br />
the operating system. [Remember that four RST instructions: RST 8, RST 16, RST 24, and<br />
RST 32 are available for use by application software.]<br />
In any event, be it modification of the vec<strong>to</strong>r for an existing SVC or the addition of<br />
your own in<strong>to</strong> a "user" SVC, the interface is simple. <strong>The</strong> SVC table is always (and will<br />
always) be origined at the start of a RAM page. <strong>The</strong> page address (i.e. the high-order<br />
byte of the SVC table) can be obtained from the system via the FLAGS pointer returned by<br />
the @FLAGS SVC. Since the low order byte starts out with 0 for SVC-00, you can locate the<br />
exact address for the SVC vec<strong>to</strong>r by multiplying the SVC number by two, loading the result<br />
in<strong>to</strong> the low order byte of a register pair (say L), then loading the high order byte of<br />
that register pair (say H) with the SVC table base address (FLAGS$+26). This will then<br />
index the low order byte of the SVC vec<strong>to</strong>r. <strong>The</strong> SVC vec<strong>to</strong>rs are s<strong>to</strong>red in standard lowhigh<br />
order.<br />
7.2 PROGRAM ENTRY AND EXIT CONDITIONS<br />
When the operating system executes a program either from DOS Ready or via an SVC (@CMNDI ,<br />
@CMNDR, or @RUN), certain conditions prevail. <strong>The</strong>se conditions relate <strong>to</strong> the register<br />
contents and the stack location. <strong>The</strong> useful register contents are as follows:<br />
BC Contains a pointer <strong>to</strong> the start of the command line. This is useful for<br />
those applications desiring <strong>to</strong> know what program name caused their<br />
invocation (as in the command-line arguments applicable <strong>to</strong> C programs).<br />
7-1