Metropoli BBS
VIEWER: inkey.c MODE: TEXT (ASCII)
/*
Copyright (C) Magna Carta Software, Inc. 1987-1991.  All Rights Reserved.
BIOS KEYBOARD FUNCTIONS
*/

#include <compat.h>
#include <stdio.h>

#define FALSE               0
#define TRUE                1
#define _KEYBRD_READ        0
#define _KEYBRD_READY       1
#define _KEYBRD_SHIFTSTATUS 2

unsigned short kbd_clear = 0;       /* is_key() does not clear kbd. */

extern unsigned short enhanced_kbd;

short  CDECL_  bios_kbd(unsigned short func);

#if !defined(USE_CWT)
    #define get_key(a)              bios_key(a)
#endif

/*
BIOS_KEY -- Function to use the BIOS keyboard interrupt 16H.
If the global variable enhanced_kbd is TRUE, calls to functions
0, 1, and 2 are translated into calls to 10H, 11H and 12H in order
to return the additional information available from the enhanced
keyboard.
Return code:
    EOF -- No character ready (service 1/11);
    else function information
*/
short bios_key(unsigned short func)
{
    short ret;

    if (enhanced_kbd && func <= 2) func+=0x10;
    ret = bios_kbd(func);

    return (ret);
}



/*
INKEY -- Test to see if a character is ready in the keyboard buffer.
Return value:
    TRUE  character in keyboard buffer;
    FALSE no character in keyboard buffer;
    Else
        Low byte  = ASCII value (if regular key pressed);
        High byte = scan code (special key pressed);
*/
short inkey(void)
{
    return ( (get_key(_KEYBRD_READY) != EOF) ? get_key(_KEYBRD_READ) : FALSE);
}



/*
IS_KEY -- Test to see if a specific key code is ready in the keyboard
buffer.
If it is, flush it and return TRUE.
For any other key, return FALSE and, if the global variable 'kbd_clear' is
TRUE, flush it and repeat. Else, leave it in the buffer (default);
Parameters:
    unsigned short key -- the key to be found, as ((scan << 8) | ascii);
Return value:
    TRUE    -- specified key found;
    FALSE   -- specified keycode not in keyboard buffer;
*/
short is_key(unsigned short key)
{
    short ret;

    if (key) while (1) {
        ret = get_key(_KEYBRD_READY);       /* see if key ready in buffer */
        if (ret == EOF) break;
        if ((unsigned short) ret == key) {
            get_key(_KEYBRD_READ);          /* our key found -- flush buffer */
            return (TRUE);
        }
        if (!kbd_clear) break;
        get_key(_KEYBRD_READ);              /* flush buffer */
    }

    return (FALSE);
}
[ RETURN TO DIRECTORY ]