• Keine Ergebnisse gefunden

BASIC Branching on Inteiiupts

Im Dokument Manual For the HP 9845 (Seite 187-190)

The handling of interrupts can be integrated into BASIC programs by using the ON INT statement. The object is to allow the flexibility of combining the high-level features of BASIC with the capabilities of assembly language in asynchronous I/O applications. And since ISRs cannot use the system utilities, in particular those that access a BASIC variable, a means of taking action on an interrupt after completion of the ISR is a necessity.

ON INT Statement

The ON INT statement is an executable BASIC statement which acts in a similar fashion to the ON KEY statement (see the System 45 Operating and Programming Manual). The statement allows the BASIC programmer to specify where, in his BASIC program, to branch whenever an End-of-line branch is Signalled for the select code he specifies.

As with the ON KEY statement, there are three ways these branches can be taken

-CH"~ I 1"<T # {select code} [~{priority} ] CALL {subprogram name}

U'F # {select code} [~ {priority}

J

Cc::;t.J:t: {line identifier}

1 !'i i # {select code} [~ {priority} ]

c;cru

{line identifier}

Whenever an interrupt is signalled from an ISR for a particular select code, if ON INT has been executed for that select code, then at the end of execution of the BASIC line which was executing when the signal came, the indicated branch in the ON INT is taken.

In the GOTO version, the branch is "absolute", which is to say that the program goes to the line indicated and picks up its execution there, forgetting where it was before. This has the effect of an "abortive" type of branch, and should only be used by the BASIC programmer when he wants the program to resume execution at some pre-determined point after handling an interrupt, without regard to where the program was before the interrupt occurred.

In the CALL and GOSUB versions, the branch is only temporary. After the subprogram or subroutine has been executed and the SUB EXIT, SUBEND, or RETURN (as appropriate) has been executed, then the program returns to the line following the one where it was interrupted.

This is the same as if the CALL or GOSUB was in between the interrupted line and the one following it.

The {line identifier} and {subprogram name} in the CALL, GOSUB, and GOTO statements are the same as elsewheie in BASIC, except that a CALL may not have any parameters.

The {select code} specified in an ON INT statement restricts the branching action to occurring only when the assembly language triggers the ON INT condition for that select code. The interrupt may have occurred in actuality on another select code. This can be a way of allowing more than one branch for interrupts from a single interrupting device.

As an example

-100 ON INT#3 GOSUB Print result li0 Ot·~ IHT#5 GO::;UB End d-3.ta

Should an interrupt occur anywhere in the program, causing an assembly language interrupt service routine to be executed, that assembly language ISR has the capability to cause either the branch of line 100 or the branch of line 110 to be taken. Thus, an assembly language ISR signals BASIC either to print an intermediate result or to note that all data has been processed.

Signalling

The {select code} specified in an ON INT statement restricts the branching action to occurring only when a branch is "signalled" for that select code. In actuality, an interrupt may not have occurred on that select code at all. Conversely, an interrupt may occur on the select code, but BASIC and its ON INT condition may never hear about it. It is necessary for the ISH which does the actual handling of an interrupt to inform, or "signal", the operating system that the inter-rupt occurred and trigger the ON INT conditions which may be set up at the time.

The responsibility of the ISR to signal the ON INT is also an opportunity. This signalling allows you in an ISR to decide whether or not you want BASIC to know about the interrupt. If you do not want BASIC to know, simply do not signal the condition. The signalling also allows you to signal different interrupt conditions. An example of doing this might be a case where, after an interrupt, a peripheral indicates whether it wants to input or output data. Your routine could signal one select code to execute an input routine and signal another select code to execute an output routine.

To signal an ON INT, your ISR must execute the following

instructions-::;QUPCE

Mask necessarily contains the select code to be signalled, Rather than containing the number of the select code, however, it has the bit set for the appropriate select code. For example, if you are signalling select code 2, you set bit 2 to 1 in Mask and leave the others O. Similarly, if you are signalling select code 5, you set bit 5. Thus, the statement containing Mask in the above could just as easily be a literal. For example

-would signal select code 5.

If the select code is not known at assembly time or if the ISR is shared by more than one select code, the following segment of code can be used to build the appropriate mask. (Pa cannot be zero, because zero is not a valid select code for the Isr _access utility.)

T :-...

.L " •• : =_::_; ~: ~_: t.

:"'~:Q:::~3

ADA =-1

c:·'·.·::···· -; i

~=;t:::!E-·.3.:;It:· ~.I)::::rM.;j f':::r' tt-~E' r(.3.::.k = Shift n iet·t instr~:tion.

When you want to signal a select code after others have already been signalled, a slightly different instruction sequence is required

-I::;OUPCE E;C1UPCE I::;CUPCE I ::;OUPCE

LDB l:::T p:::.i ... i

LIlA =1~Y':::E:

::;TA B,I ADB=:3 LIlA rt:I.:::.k

: : T l t

Lllr:.

EIF.:

Mask is the same as above.

Drs in the select code

As a further example, suppose you want both to signal BASIC when a device sends a line-feed character to the computer, and to terminate the ISR's linkage. Then the ISR might appear

as-I::;OUF.:CE I ::;OU F-::CE

I::;OU~~CE

LIlA ~~4

CPA =Lt

.. Tl'1F' T ,::rm i nat,::

:::;TA F.:7

LItE: I:::T p:::.i .. J

LIlA =iO:::::t:

ADB _.-, LilA =1

D T

.l..1, ..i..

Im Dokument Manual For the HP 9845 (Seite 187-190)