home *** CD-ROM | disk | FTP | other *** search
/ PC Open 18 / pcopen18_giallo.iso / Msdos / Keybit6 / KL_API.ZIP / KL_API.C next >
Encoding:
C/C++ Source or Header  |  1996-02-22  |  3.3 KB  |  109 lines

  1. /************************************************************************
  2.  *                                    *
  3.  *  KL_API.C   KEYBIT Lite API access module                *
  4.  *  Public Domain 1996 Pino Navato                    *
  5.  *                                    *
  6.  ************************************************************************/
  7.  
  8. #include <dos.h>
  9. #include <string.h>
  10. #include "kl_api.h"
  11.  
  12. #define AMIS_INSTCHECK      0              /* installation check */
  13. #define KLAPI_GET_SB_PTR  0x10           /* get pointer to status byte */
  14.  
  15. #define AMIS_SUCCESSFUL      0xFF
  16.  
  17.  
  18. static int mpx;
  19. static union REGS regs;
  20.  
  21.  
  22. /*
  23.   +-----  search4keybit()  ---------------------------------------------+
  24.   |  Purpose:    Search for KEYBIT Lite v5+ in memory.            |
  25.   |  Note:    This function sets the global variable mpx used        |
  26.   |        by get_sb_ptr().                    |
  27.   |  Return:    Full version number if found, 0 if not found.        |
  28.   +---------------------------------------------------------------------+
  29. */
  30. unsigned search4keybit(void)
  31.    {
  32.    char far *sig;                /* generic AMIS signature */
  33.    const char far *KL_sig = "Pino NavKeybit  "; /* KEYBIT's AMIS signature */
  34.  
  35.    for (mpx = 0; mpx <= 255; mpx++)
  36.       {
  37.       regs.h.ah = mpx;
  38.       regs.h.al = AMIS_INSTCHECK;        /* installation check */
  39.       int86(0x2D, ®s, ®s);
  40.       if (regs.h.al == AMIS_SUCCESSFUL)        /* installed? */
  41.      {
  42.      sig = (char far *) MK_FP(regs.x.dx, regs.x.di);
  43.      if (_fstrcmp(sig, KL_sig) == 0)  /* KEYBIT Lite? */
  44.         if (regs.h.ch >= 5)       /* v5+ ? */
  45.            return regs.x.cx;      /* YES! Return full version number */
  46.         else
  47.            break;              /* NO, it's an older version. Stop searching */
  48.      }
  49.       }
  50.    return 0;
  51.    }
  52.  
  53.  
  54. /*
  55.   +-----  get_sb_ptr()    ------------------------------------------------+
  56.   |  Purpose:    Get a far pointer to KEYBIT Lite status byte.        |
  57.   |  Return:    Far pointer to KEYBIT Lite status byte            |
  58.   |        or NULL if KEYBIT Lite v5+ not installed.        |
  59.   +---------------------------------------------------------------------+
  60. */
  61. unsigned char far *get_sb_ptr(void)
  62.    {
  63.    if (search4keybit() == 0)
  64.       return NULL;
  65.  
  66.    regs.h.ah = mpx;
  67.    regs.h.al = KLAPI_GET_SB_PTR;
  68.    int86(0x2D, ®s, ®s);
  69.    return (unsigned char far *) MK_FP(regs.x.dx, regs.x.bx);
  70.    }
  71.  
  72.  
  73. static unsigned char far *status_ptr;
  74. static unsigned char old_status;
  75.  
  76. /*
  77.   +-----  enable_emailsupport()  ---------------------------------------+
  78.   |  Purpose:    Set e-mail support flag to 1 and save original status    |
  79.   |        in the global variable old_status.            |
  80.   |  Note:    This function has no effect if KEYBIT Lite isn't in    |
  81.   |        memory.                            |
  82.   |  Return:    Nothing.                        |
  83.   +---------------------------------------------------------------------+
  84. */
  85. void enable_emailsupport(void)
  86.    {
  87.    if ((status_ptr = get_sb_ptr()) != NULL)
  88.       {   
  89.       old_status = *status_ptr;
  90.       *status_ptr |= EMAILSUPPORT_FLAG;
  91.       }
  92.    }
  93.  
  94.  
  95. /*
  96.   +-----  restore_keybit_status()  -------------------------------------+
  97.   |  Purpose:    Restore KEYBIT Lite's original status from the global    |
  98.   |        variable old_status.                    |
  99.   |  Note:    This function has no effect if KEYBIT Lite isn't in    |
  100.   |        memory or if enable_emailsupport() hasn't been called.    |
  101.   |  Return:    Nothing.                        |
  102.   +---------------------------------------------------------------------+
  103. */
  104. void restore_keybit_status(void)
  105.    {
  106.    if (status_ptr != NULL)
  107.       *status_ptr = old_status;
  108.    }
  109.