home *** CD-ROM | disk | FTP | other *** search
- /******************************************
- * ONSHIFT.C *
- * Copyright TimeSlice, Inc. 1985, 86, 87. *
- ******************************************/
-
- #include <ts.h>
-
- SHIFT *_shfrnt; /*head of shift structs list*/
-
- extern void kbd_isr();
-
- /***
- * ONSHIFT( 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).
- * It returns a pointer to the SHIFT structure allocated for that shift. This
- * is the pointer that should be passed to rmvshift.
- ***/
- SHIFT *onshift( 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 );
-
- return sp;
- }
-
-
- /***
- * RMVSHIFT( SP )
- * Remove SHIFT structure *SP from SHIFT list.
- ***/
- void rmvshift( sp )
- SHIFT *sp;
- {
- SHIFT *sp2;
- int cpuflags;
-
- cpuflags = cli();
- for( sp2 = (SHIFT *)&_shfrnt ; sp2->nxt ; sp2 = sp2->nxt )
- if( sp2->nxt == sp ) {
- sp2->nxt = sp->nxt;
- critstart( DOS_CRCLASS );
- #if defined(TURBOC)
- _ts_free( sp );
- #else
- free( sp );
- #endif
- critend( DOS_CRCLASS );
- break;
- }
- putf( cpuflags );
- }
-