A92: Re: Thanks Aaron


[Prev][Next][Index][Thread]

A92: Re: Thanks Aaron




> Thanks for the help on the interrupt stuff.  The problem is that I tried 
> that before.  Maybe it has to do with the fact that I'm replacing the 
> keyboard interrupt (Auto_Int_2) at address [$68] in the interrupt vector 
> table.  I guess it is also possible that my code had a bug in it, like a 
> typo or something.  I also remember from creating user interrupts in C++ 
> that if the code for the interrupt is too long it may try to call the 
> interrupt again before the old one is finished, causing it to crash.  This 
> may have also happened.  I guess I will mess around with it a little longer 
> before I give up.  Also I may not really need it anymore since I solved the 
> bug in reading the keypresses (from before).  It seems to run fairly 
> smoothly, and requires little code in the program body, so it's not much of 
> a hassle to handle the key reads manually.  I'll se what I can figure out.  
> Thanks for your help.

If your interrupt code is too long and is becoming reentrant, maybe you should
mask off the interrupt upon entry.  Of course you will want to set what you can
as quickly as possible and get the interrupt active.  Usually the best thing to
do is have the interrupt set some global data and then inside your program you
check the global data and see if you need to do any processing.  Or maybe try
something like this:


main_loop:
    ; Do main_loop stuff

    ; If interrupt happened . . .
    ; . . . Set interrupt_happened to false
    ; . . . Call some_routine

    bra main_loop

interrupt_handler:
    ; Disable interrupt
    ; Set interrupt_happened to true
    ; Call previous interrupt handler
    ; Enable interrupt
    rts

some_routine:
    ; Do whatever is needed
    rts

interrupt_happened      dc.?     0


This code will make sure that no matter how many times the interrupt_handler is
called, your code will not be paused for very long.  You decide when you deal
with the interrupt.  Also the interrupt_handler cannot be interrupted (prevents
endless loops).  For something this small, the interrupt_handler probably doesn't
need to disable the interrupt.  But you never know what interrupt handlers have
been installed.


====
Aaron Hill (Redmond, Wash.)
Electronic Mail: serac@lightmail.com
IRC Nickname: serac (on EF-Net)
ActiveWorlds Citizenship: serac



References: