Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!rex!uflorida!kluge!serss0.fiu.edu From: acmfiu@serss0.fiu.edu (ACMFIU) Newsgroups: comp.sys.apple2 Subject: heartbeat interrupts Message-ID: <2037@kluge.fiu.edu> Date: 18 Jan 91 04:49:58 GMT Sender: news@kluge.fiu.edu Organization: Florida International University, Miami Lines: 102 Awhile back I posted a message concerning HeartBeat interrupts. I wanted to, when a key was pressed, pause my program and, if oa-period was pressed, terminate the program. Thanks to Tim Meekins and Jawaid Bazyar for their responses. I have come up with the following code, although their remains to be one bug. int main (void) { char *kybdvector; EMStartup (blah); kybdvector = GetVector (kybdIntHnd); SetVector (kybdIntHnd, check_key); bye (); } void bye (void) { SetVector (kybdIntHnd, kybdvector); EMShutDown (); Close (0); /* close all files */ exit (1); } asm void check_key (void) { rep #$30 /* just to make sure */ php phb phk plb jsl incbusyflag lda $e0c000 bpl end cmp #"." bne wait lda $ cmp # bne wait pha /* space for result */ pushlong #bye _SchAddTask pla /* i KNOW it worked */ bra end wait pha pushlong #pause _SchAddTask pla end plb plp jsl decbusyflag rtl } asm void pause (void) { lda $e0c000 wait lda $e0c010 bpl wait lda $e0c000 rtl } What I basically do is startup the Event Manager which automatically makes keyboard interrupts available (ala IntSource) and then I modify the interrupt handler that the Event Manger uses for the keyboard interrupts to my own. When I run my program, pressing any key appropriately causes the program to pause, then I press the key again and it resumes execution. The problem comes with oa-period. When I press it, the program ends and I'm back in the shell. however, when I run it again, NO key I press does anything. It's like the keyboard interrupts were disabled. If I press "AAAAAAAAAAAAAAA", they will appear on the command line AFTER the program is finished executing. My question is, how in the world do keyboard interrupts get disabled from the above code (the above code is not 100% correct but you should get the idea). Since I get the keyboard interrupt vector used by the Event Manager and restore it before I EMShutDown(), how does it get corrupted? I also used the above code without the Event Manager. Using the Misc Tool Set you can do it via: IntSource (kybdEnable); kybdvector = GetVector (kybdIntHnd); SetVector (kybdIntHnd, check_key); SetVector (kybdIntHnd, kybdvector); exit (0); Any ideas? albert