!pr2
Enable/Disable IRQ from Applesoft..........Bob Sander-Cederlof

If you have applied the patches to DOS 3.3 that we published in the January 1984 issue (pages 10,11), and if you now are using interrupts from such sources as the Timemaster II or a handy pushbutton, you have probably run into the need to enable and disable IRQ from within an Applesoft program.  (That sentence is the kind you have to read without interruption, so I really should have begun the paragraph with SEI and ended it with CLI.)

What is need is four bytes of assembly language, at a location that you can CALL.  For example:

       300- 58    CLI
       301- 60    RTS
       302- 78    SEI
       303- 60    RTS

If those four bytes are in memory as shown, you can CALL 768 to enable IRQ interrupts, and CALL 771 to disable them.  You can install the four bytes like this:

       100 POKE 768,88: POKE 769,96
       110 POKE 770,120:POKE 771,96

Now there are often times when poking into page 3 is not possible.  Are there other tricky ways to get those bytes installed, without using page 3?

I found a half dozen or so.  First, realize that the four bytes only need to be there when you call them.  The rest of the time the same locations could be used for other purposes.  For example, we could poke them into the input buffer at $200, as long as we do it every time we CALL it:

       100 POKE 512,88:POKE 513,96:CALL 512
             to enable interrupts, or

       500 POKE 512,120:POKE 513,96:CALL 512
             to disable them.

The result of a multiplication or division is left, sometimes normalized and sometimes not, in $62...$66.  If we find two numbers whose product leaves the bytes $58 and $60 at $62 and $63, we could CALL 98:

       100 X = 1*707 : CALL 98 : REM ENABLE IRQ
       200 X = 1*963 : CALL 98 : REM DISABLE IRQ

On the next page is a table showing the various methods I found:
!np
Enable (CLI..RTS)      Disable (SEI..RTS)
-------------------------------------------------------
100 POKE 38,88            100 POKE 38,120
110 POKE 39,96            110 POKE 39,96
120 CALL 38               120 CALL 38
-------------------------------------------------------
100 CALL 8411232-8411065  100 CALL 8419424-8419257
-------------------------------------------------------
100 GOSUB 24664           100 GOSUB 24696
...                       ...
24664 CALL 117:RETURN     24696 CALL 117:RETURN
-------------------------------------------------------
100 X = 1*707 : CALL 98   100 X = 1*963 : CALL 98
-------------------------------------------------------
100 X = RND(-8411323.5)   100 X = RND(-8419424.5)
110 CALL 203              110 CALL 203
-------------------------------------------------------
100 HOME:FLASH:PRINT"X "  100 HOME:FLASH:PRINT"8 "
110 NORMAL:CALL1024       110 NORMAL:CALL1024
-------------------------------------------------------

Can you figure out how all these work?  They are pretty tricky!  Can you think of some more?
