Newsgroups: comp.sys.apple2.programmer Path: news.uiowa.edu!hobbes.physics.uiowa.edu!math.ohio-state.edu!usc!elroy.jpl.nasa.gov!decwrl!waikato!comp.vuw.ac.nz!actrix.gen.nz!dempson From: dempson@atlantis.actrix.gen.nz (David Empson) Subject: Re: patching out main irq handler under GS/OS Message-ID: Sender: news@actrix.gen.nz (News Administrator) Organization: Actrix - Internet Services Date: Sat, 13 May 1995 03:32:50 GMT References: <3or7nr$m5t@mark.ucdavis.edu> X-Nntp-Posting-Host: atlantis.actrix.gen.nz Lines: 61 In article <3or7nr$m5t@mark.ucdavis.edu>, arekusu wrote: > > My handler checks to see if it's an irq that it knows about (only > SCBs so far) and if not, it restores the orginal handler and does a > cli. Theoretically, this should work. It depends to a very large degree on what the machine state is when the interrupt occurred. If the IIgs was running in emulation mode, and your IRQ handler is not in bank 0, and you enabled interrupts again, then the resulting interrupt would not have pushed the program bank register, and the computer would at least crash on exit from the interrupt (I don't think it would affect the running interrupt handlers). If you had already saved the emulation mode flag and switched to native mode, it should be safe. However, a safer soultion would be to simulate the interrupt yourself, without actually enabling interrupts. Don't restore the original handler either - just jump to the original handler directly. You should also check for whether it was a BRK or an IRQ. In native mode, the master interrupt vector is called with V=0 for a BRK, V=1 for an IRQ. In emulation mode, V=1 always, and you have to check the pushed flag register to see whether it was a BRK. Your handler should start with something like this: CLC XCE ; Set native mode, get emulation mode flag SEP #$30 ; Set 8-bit registers PHA BVC NotMine ; V=0 for native mode BRK BCC NotBrk ; C=0 if was native mode LDA 2,S ; Get flag register from stack BIT #$10 ; Was the BRK flag set? BNE NotMine NotBrk PHP ; Save emulation mode flag (in C) and V=1 ; Add code in here to check for your own interrupt. If it isn't ; yours, branch to NotMine1. ; If it is yours, use the following code to return from the interrupt: IntExit PLP ; Get original emulation mode flag back (in C) PLA ; Restore accumulator BCC Native ; Was native: exit normally XCE ; Restore emulation mode JML $00C072 ; Jump to a known RTI in bank 0 Native RTI ; See you later folks! NotMine1 PLP ; Restore emulation mode flag (in C) and overflow NotMine PLA XCE ; Restore old mode JML OldVector ; (patch old vector in here) I think that covers the main points. -- David Empson dempson@actrix.gen.nz Snail mail: P.O. Box 27-103, Wellington, New Zealand