/************************************************************************ * * * KL_API.C KEYBIT Lite API access module * * Public Domain 1996 Pino Navato * * * ************************************************************************/ #include #include #include "kl_api.h" #define AMIS_INSTCHECK 0 /* installation check */ #define KLAPI_GET_SB_PTR 0x10 /* get pointer to status byte */ #define AMIS_SUCCESSFUL 0xFF static int mpx; static union REGS regs; /* +----- search4keybit() ---------------------------------------------+ | Purpose: Search for KEYBIT Lite v5+ in memory. | | Note: This function sets the global variable mpx used | | by get_sb_ptr(). | | Return: Full version number if found, 0 if not found. | +---------------------------------------------------------------------+ */ unsigned search4keybit(void) { char far *sig; /* generic AMIS signature */ const char far *KL_sig = "Pino NavKeybit "; /* KEYBIT's AMIS signature */ for (mpx = 0; mpx <= 255; mpx++) { regs.h.ah = mpx; regs.h.al = AMIS_INSTCHECK; /* installation check */ int86(0x2D, ®s, ®s); if (regs.h.al == AMIS_SUCCESSFUL) /* installed? */ { sig = (char far *) MK_FP(regs.x.dx, regs.x.di); if (_fstrcmp(sig, KL_sig) == 0) /* KEYBIT Lite? */ if (regs.h.ch >= 5) /* v5+ ? */ return regs.x.cx; /* YES! Return full version number */ else break; /* NO, it's an older version. Stop searching */ } } return 0; } /* +----- get_sb_ptr() ------------------------------------------------+ | Purpose: Get a far pointer to KEYBIT Lite status byte. | | Return: Far pointer to KEYBIT Lite status byte | | or NULL if KEYBIT Lite v5+ not installed. | +---------------------------------------------------------------------+ */ unsigned char far *get_sb_ptr(void) { if (search4keybit() == 0) return NULL; regs.h.ah = mpx; regs.h.al = KLAPI_GET_SB_PTR; int86(0x2D, ®s, ®s); return (unsigned char far *) MK_FP(regs.x.dx, regs.x.bx); } static unsigned char far *status_ptr; static unsigned char old_status; /* +----- enable_emailsupport() ---------------------------------------+ | Purpose: Set e-mail support flag to 1 and save original status | | in the global variable old_status. | | Note: This function has no effect if KEYBIT Lite isn't in | | memory. | | Return: Nothing. | +---------------------------------------------------------------------+ */ void enable_emailsupport(void) { if ((status_ptr = get_sb_ptr()) != NULL) { old_status = *status_ptr; *status_ptr |= EMAILSUPPORT_FLAG; } } /* +----- restore_keybit_status() -------------------------------------+ | Purpose: Restore KEYBIT Lite's original status from the global | | variable old_status. | | Note: This function has no effect if KEYBIT Lite isn't in | | memory or if enable_emailsupport() hasn't been called. | | Return: Nothing. | +---------------------------------------------------------------------+ */ void restore_keybit_status(void) { if (status_ptr != NULL) *status_ptr = old_status; }