home *** CD-ROM | disk | FTP | other *** search
- /******************************************
- * ONKEY.C *
- * Copyright TimeSlice, Inc. 1985, 86, 87. *
- ******************************************/
-
- #include <ts.h>
-
- SHIFT *_shfrnt; /*head of shift structs list*/
-
- void kbd_isr();
-
- /***
- * ON_KEY( STATUS, FUNCPTR )
- * This function attaches an isr to interrupt # 9. The isr executes a user
- * function if the keyboard shift status is equal to a trigger value (hot key).
- ***/
- void on_key( status , func )
- int status ; /* hot key value */
- void (*func)() ; /* user function to execute if hot key pressed */
- {
- SHIFT *sp;
- char *malloc();
- int cpuflags;
- static installed;
-
- critstart( DOS_CRCLASS );
-
- /*if called for the first time, install kbd_isr*/
- if( !installed ) {
- intatt( 0x09, 0x300, kbd_isr, REPLACE ) ;
- installed = 1;
- }
-
- /*search for existing SHIFT with same status*/
- for( sp = _shfrnt ; sp && sp->status!=status ; sp = sp->nxt );
-
- /*if not found, allocate a new SHIFT and put it in front of _shfrnt list*/
- if( !sp ) {
- #if defined(TURBOC)
- sp = (SHIFT *)_ts_malloc( sizeof( SHIFT ) );
- #else
- sp = (SHIFT *)malloc( sizeof( SHIFT ) );
- #endif
- cpuflags = cli();
- sp->nxt = _shfrnt;
- _shfrnt = sp;
- putf( cpuflags );
- sp->status = status;
- }
- sp->infunc = 0; /*always reset when onkey called*/
- sp->func = func;
- critend( DOS_CRCLASS );
- }
-
- /*****
- * KBD_ISR()
- * This isr is attached to the keyboard interrupt.
- * It obtains the keyboard shift status and compares it with
- * the status contained in the shift structure. If keyboard status
- * is a superset of the SHIFT status, then it enables interrupts,
- * sets a flag to indicate that the user function is being executed
- * and then executes it.
- *****/
- void kbd_isr( ip, ro, rseg )
- INTLST *ip ;
- int ro ,
- rseg ;
- {
- int cpuflags ;
- SHIFT *sp; /* Pointer to shift structure */
- char status ;
-
- oisr( ip , ro , rseg ); /* Execute original Keyboard ISR */
- peek( 0x40, 0x17, &status, sizeof( status ) ); /*get kbd shift status*/
-
- /*look if there is a SHIFT for that status*/
- for( sp = _shfrnt ; sp ; sp = sp->nxt )
- if( (sp->status & status) == sp->status )
- break;
-
- /*only if found and not already in func, execute func*/
- if( sp && !sp->infunc ) {
- cpuflags = getf() ; /*get a copy of the cpu flags */
- sp->infunc = 1 ; /*set infunc flag for recursive calls*/
- putf( cpuflags | 0x200 ) ; /*enable interrupts for the duration of the user function */
- (*sp->func)() ; /*execute user function */
- sp->infunc = 0 ; /* reset flag */
- putf( cpuflags ) ; /* restore cpu flags */
- }
- }
-