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.

CKPAWS LD A,@FLAGS$ ;Get Flags pointer<br />

RST 40 ; in<strong>to</strong> reg IY<br />

LD A,(IY+'K'-'A') ;P/u the KFLAG$<br />

RRCA ;Bit 0 <strong>to</strong> carry<br />

JP C,GOTBRK ;Go on BREAK<br />

RRCA ;Bit 1 <strong>to</strong> carry<br />

RET NC ;Return if no pause<br />

reads the KFLAG$ contents. <strong>The</strong> @FLAGS$ SuperVisor Call is used <strong>to</strong> obtain the flags<br />

pointer from the DOS. Be aware that if your application is using the IY index register,<br />

then you better save and res<strong>to</strong>re it within the CKPAWS routine (alternatively, you could<br />

use memory loads in lieu of IY indexing, use @FLAGS at the beginning of your application<br />

<strong>to</strong> calculate the location of KFLAG$, and stuff the address in<strong>to</strong> the CKPAWS memory LD<br />

instructions.) <strong>The</strong> first rotate instruction places the BREAK bit in<strong>to</strong> the carry flag.<br />

Thus, if a condition was in effect, the sub-routine would branch <strong>to</strong> "GOTBRK" -<br />

which is your break handling routine. If there is no pending BREAK, the second rotate<br />

places what was originally in the PAUSE bit in<strong>to</strong> the carry flag. If a condition<br />

is not in effect, the routine returns <strong>to</strong> the caller. This sequence of code gives a higher<br />

priority <strong>to</strong> (i.e. if both BREAK and PAUSE conditions are pending, the <br />

condition has precedence). It is important <strong>to</strong> note that the GOTBRK routine needs <strong>to</strong> clear<br />

the KFLAG$ bits after it services the condition. This is simply done via a call<br />

<strong>to</strong> RESKFL.<br />

<strong>The</strong> next part of the routine is executed on a condition.<br />

CALL RESKFL ;Reset the flag<br />

PUSH DE ;Don't alter reg DE<br />

FLUSH LD A,@KBD ;Flush type-ahead<br />

RST 40 ; buffer while<br />

JR Z,FLUSH ; ignoring errors<br />

POP DE<br />

First the KFLAG$ bits are reset via the call <strong>to</strong> RESKFL. Next, we take care of removing<br />

any characters that are s<strong>to</strong>red in the type-ahead buffer (the system will au<strong>to</strong>matically<br />

clear the type-ahead buffer when a BREAK condition is latched). This can be done by<br />

repeatedly invoking the @KBD request until it returns a "no character available"<br />

condition code.<br />

Now that the routine is in a PAUSEd state and the type-ahead buffer is cleared, it must<br />

wait for a key input. <strong>The</strong> following routine does this:<br />

PROMPT PUSH DE<br />

LD A,@KEY ;Wait on key entry<br />

RST 40<br />

POP DE<br />

CP 80H ;Go on <br />

JP Z,GOTBRK<br />

CP 60H ;Ignore <br />

JR Z,PROMPT ; else ...<br />

<strong>The</strong> PROMPT routine is coded <strong>to</strong> accept a and branch <strong>to</strong> your BREAK handling routine<br />

so that the user can "abort" from a PAUSE. It will ignore repeated entries (the<br />

60H is the standard byte value that is interpreted as a PAUSE entry). Any other character<br />

will cause it <strong>to</strong> fall through <strong>to</strong> the following routine which clears the KFLAG$ latch.<br />

RESKFL PUSH HL ;Reset KFLAG$ without<br />

PUSH AF ; altering AF or HL<br />

LD A,@FLAGS$ ;P/u flags pointer<br />

RST 40 ; in<strong>to</strong> reg IY<br />

RESKFL1 LD A,(IY+'K'-'A') ;P/u the flag<br />

AND 0F8H ;Strip ENTER,<br />

8-4

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

Saved successfully!

Ooh no, something went wrong!