home *** CD-ROM | disk | FTP | other *** search
- /* 89-03-02 Jahns _kbbgd() with two parameter */
-
-
-
-
- /* (c) 1985, Phoenix Computer Products Corp. and Novum Organum, Inc. */
- /***
- * name kbnec - used by library high level functions to get input.
- * kbrdy - used by library high level function to check keyboard.
- *
- * synopsis key = kbnec()
- * f_hit = kbrdy()
- * f_hit flags if a key is waiting at the input.
- *
- * discussion: Higher level functions, such as field input, must
- * get keys from the input stream. When your program
- * begins to run, Kbnec() will be directed through
- * DOS.
- *
- * returns: kbnec() - a word is returned.
- * The key type is in the upper byte and the key code is in
- * the lower bytes. Ascii characters are just returned as
- * the character with zero in the upper bytes.
- *
- * See 'pfdefs.h' for list of key types.
- *
- * returns : kbrdy() - returns non-zero if a key is waiting at input.
- * kbsetnec- .
- ***/
- #include "pdefs.h"
-
- static kbstdinnec ()
- {
- FAST int key;
- /* this is done in case input redirection is being used when system*/
- /* is entered. so keep using DOS until all initial input eaten */
- /* then switch to using BIOS functions. */
- key = RC_EOF;
- do {
- if (kbdoshit())
- {
- key = kbdosnec();
- if (KEY_TYPE(key) == KB_ASCII)
- {
- if (key == LNFEED) /* eat line feeds */
- key = RC_EOF;
- else
- if (key == CPMEOF)/*<control-z> at end of redirection file*/
- {
- key = RC_EOF;
- break;
- }
- }
- }
- else
- break; /* nothing waiting at DOS, break. */
- }
- while (key==RC_EOF);
-
- return (key);
- }
-
- int kbbiosnec(), kbbioshit();
- int kbdoshit(), kbdosnec();
- static PFI _kbnec=kbbiosnec, _kbhit=kbbioshit;
-
- #ifdef use
- static PFI _preprc= 0 /*NULLPFI*/; /* CI86 won't take defines */
- static PFI _wndmov= 0 /*NULLPFI*/;
- #endif
-
- static kbsetnec (nec, hit)
- PFI nec, hit;
- {
- _kbnec = nec;
- _kbhit = hit;
- }
-
- #ifdef use
-
- PFI kbpreprc (preprc)
- PFI preprc;
- {
- PFI prv;
-
- prv = _preprc;
- _preprc = preprc;
- return (prv);
- }
-
- #endif
-
-
- kbrdy()
- {
- return ((*_kbhit)());
- }
-
- int kbsource (source)
- int source;
- {
- switch (source)
- {
- case KB_DOS:
- kbsetnec(kbdosnec, kbdoshit);
- break;
- case KB_STDIN:
- kbsetnec(kbstdinnec, kbdoshit);
- break;
- default:
- case KB_BIOS:
- kbsetnec(kbbiosnec, kbbioshit);
- break;
- }
- }
-
-
- kbnec ()
- {
- FAST int key;
-
- do {
- key = (*_kbnec)();
- #ifdef use
- if (_preprc)
- key = (*_preprc)(key);
- if ((key) && (_wndmov))
- key = (*_wndmov)(key);
- #endif
- }
- while (!key);
-
- return (key);
- }
-
-
- #ifdef use
-
- _kbsetwnd( wndmov )
- PFI wndmov;
- {
- _wndmov = wndmov;
- }
-
- #endif
-
-
- /*
- * name : kbpeek - peek ahead at the next key waiting at the keyboard.
- *
- * synopsis : key = kbpeek()
- *
- * description : this function is returns the <type,code> of the next
- * key waiting at the keyboard. the key is still be returned
- * by the next call to kbnec(). NOTE, uses the BIOS call.
- *
- * returns NFAIL if no key is waiting. Otherwise a word is returned.
- * The key type is in the upper byte and the key code is in
- * the lower bytes. Ascii characters are just returned as
- * the character with zero in the upper bytes.
- *
- * version 1.0 (c) novum organum, inc. 1985
- **/
-
- #define NO_C_WAITING -1
- #define BIO_KBGET 0 /* interrupt 0x16 - read keyboard op */
- #define BIO_KBPEEK 1 /* interrupt 0x16 - peek at keyboard op */
- #define EXTNDD_ASCII 0 /* keyboard returned extended ascii char*/
-
-
- int kbpeek()
- {
- return (kbbios(BIO_KBPEEK));
- }
-
- /***
- * kbbios() is the work-horse for the above routines.
- * it calls bioskey() to get the next key and then
- * is
- ***/
-
-
- static int kbbios(bioscall)
- int bioscall;
- {
- int key;
-
- key = kbgate(bioscall);
-
- if ((bioscall == BIO_KBPEEK) && (key == NO_C_WAITING))
- key = NOTFND;
- else
- key = _kbencode (key);
- return (key);
- }
-
- /*
- * name : kbbiosnec - return the next character from the keyboard.
- *
- * synopsis : key = kbbiosnec()
- *
- * description : this function is returns the <type,code> of the next
- * key waiting at the keyboard. _kbbgd() will execute
- * background tasks if no key is waiting at the keyboard.
- * NOTE, uses the BIOS call.
- *
- * returns Otherwise a word is returned.
- * The key type is in the upper byte and the key code is in
- * the lower bytes. Ascii characters are just returned as
- * the character with zero in the upper bytes.
- *
- * version 1.0 (c) novum organum, inc. 1985
- **/
-
- int kbbiosnec ()
- {
- int kbbioshit();
- // _kbbgd (kbbioshit, 0); /* execute any background tasks */
- return (kbbios(BIO_KBGET)); /* get input key */
- }
-
- /*
- * name : kbbioshit - check if a key is waiting at the keyboard.
- *
- * synopsis : f_waiting = kbbioshit();
- *
- * description : this function tells if the user has pressed a key
- * and whether that key is waiting at the keyboard.
- *
- * returns non-zero if key is waiting
- * zero if no key is waiting.
- *
- * version 1.0 (c) novum organum, inc. 1985
- **/
-
- int kbbioshit()
- {
- return (kbpeek() != NOTFND);
- }
-
- kbdirect()
- {
- return ((kbbioshit()) ? kbbiosnec() : NOTFND);
- }
-
- static int _esc_key=ASCII_KEY(ESC);
-
- int kbesckey()
- {
- return(_esc_key);
- }
-
- #ifdef use
-
- kbsetesckey(key)
- int key;
- {
- _esc_key = key;
- }
-
- #endif
-
-
- int kbhitesc()
- {
- return (kbdirect()==_esc_key); /* ESCAPE pressed ? */
- }
- /*
- * name : kbdosnec - get next key from input without echoing it on crt.
- *
- * synopsis : key = kbdosnec()
- *
- * description : kbdosnec() gets the next character from the input stream,
- * nomally the keyboard, although input can be redirected
- * from another device or from a file. _kbbgd() executes
- * background tasks if nothing is waiting at the input
- * stream.
- *
- * returns Otherwise a word is returned.
- * The key type is in the upper byte and the key code is in
- * the lower bytes. Ascii characters are just returned as
- * the character with zero in the upper bytes.
- *
- * version 1.0 (c) novum organum, inc. 1985
- **/
-
- /*
- * name : kbdoshit - check if a key is waiting at standard input device,
- * normally the keyboard.
- *
- * synopsis : f_waiting = kbdoshit();
- *
- * description : this function checks to see if a key is waiting on
- * this input stream read by kbdosnec(). this is normally
- * the keyboard, but may be redirected from another device.
- *
- * returns YES key is waiting.
- * NO no key is waiting.
- *
- * version 1.0 (c) novum organum, inc. 1985
- **/
-
- /***
- * internal function which calls DOS to get the characters.
- * if an extended ascii character is found, _kbencode() is
- * called to get its corresponding <type,code> pair.
- ***/
-
- #define DOS_NEC 0x0700 /* dos no-echo character function */
-
- static _kbbyte()
- {
- REGIS regs;
-
- regs.ax = DOS_NEC;
- dosgate(®s);
-
- return ((int)(regs.ax & 0xff)); /* get char out of AX regs */
- }
-
- static int kbdos()
- {
- FAST int key;
-
- key = _kbbyte();
-
- if (key == EXTNDD_ASCII)
- key = TOHIBYTE(_kbbyte());
-
- return (_kbencode(key));
- }
-
- int kbdosnec ()
- {
- int kbdoshit();
-
- // _kbbgd (kbdoshit, 0); /* execute any background tasks */
- return (kbdos()); /* wait until user presses key */
- }
-
- int kbdoshit()
- {
- REGIS regs;
-
- regs.ax = 0x0b00;
- dosgate(®s);
- return ((LOBYTE(regs.ax)) ? YES : NO);
- }
- /***********************************************************************
- *
- * these routines allow input from the keyboard or via
- * a batch file. they also allow the last character input
- * to be pushed back onto a 'one-byte' stack.
- *
- * the next character is read. if the character is a NULL,
- * then it is assumed that the input is part of the extended
- * ascii codes for the PC. A second character is read and
- * the key is 'decoded' into a character type and character
- * code.
- *
- * the character type and code are returned.
- *
- * key entered type code
- *
- * ascii code KB_ASCII (0) ascii code
- *
- * cursor key KB_CURS (1)
- *
- * <end> 1
- * <dn> 2
- * <pgdn> 3
- * <lf> 4
- * <rt> 6
- * <home> 7
- * <up> 8
- * <pgup> 9
- * <ctl><end> 11
- * <ctl><pgdn> 13
- * <ctl><lf> 14
- * <ctl><rt> 16
- * <ctl><home> 17
- * <ctl><pgup> 19
- * <shift><tab> 20
- *
- * function key KB_FNC (2)
- * <fi> 1 to 10
- * <shift><fi> 11 to 20
- * <ctl> <fi> 21 to 30
- * <alt> <fi> 31 to 40
- *
- * edit key KB_EDIT (3)
- *
- * <ins> 1
- * <del> 2
- * <ctl-prtsc> 3
- * <numeric pad '*'> 4
- * <numeric pad '-'> 5
- * <numeric pad '+'> 6
- * <ctl-break> 7
- *
- *
- * <alt> <key> KB_ALT (4) <key>
- *
- *************************************************/
-
- #define NPAD_STAR 0x372a /* scan code | '*' */
- #define NPAD_MINUS 0x4a2d /* scan code | '-' */
- #define NPAD_PLUS 0x4e2b /* scan code | '+' */
-
- static char *_qwerty = "QWERTYUIOP ASDFGHJKL ZXCVBNM";
- #define IBMFNCKEYS " ;<=>?@ABCDTUVWXYZ[\\]^_`abcdefghijklmnopq"
-
- static char _otherspecial[]={3,15,
- 71,72,73,75,
- 77,79,80,81,
- 82,83,
- 114,115,116,
- 117,118,119,
- 132,EOS};
- static char _othercodes[] ={0/*NULLVAL*/, K_SHIFTTAB,
- K_HOME, K_UP, K_PGUP, K_LF,
- K_RT, K_END, K_DOWN, K_PGDOWN,
- K_INSERT, K_DEL,
- K_CTLPRTSC, K_CTLLF, K_CTLRT,
- K_CTLEND, K_CTLPGDOWN, K_CTLHOME,
- K_CTLPGUP};
- static char _othertyps[] = {KB_ASCII,KB_CSR,
- KB_CSR, KB_CSR, KB_CSR, KB_CSR,
- KB_CSR, KB_CSR, KB_CSR, KB_CSR,
- KB_EDIT, KB_EDIT,
- KB_EDIT, KB_CSR, KB_CSR,
- KB_CSR, KB_CSR, KB_CSR,
- KB_CSR};
- static char *_altkeys = "1234567890-=";
-
- static _f_redef_esc=NO; /* if the programmer wants to avoid having */
- /* input functions perform certain tasks when */
- /* when the <esc> key is pressed. he can set */
- /* the 'no-escape' flag. <esc>'s are then */
- /* mapped into function key zero and handled */
- /* as special keys. */
- kbredefesc (setting)
- int setting;
- {
- _f_redef_esc = setting;
- }
-
- _kbencode (key)
- FAST int key;
- {
- int i;
-
- if (LOBYTE(key)==EXTNDD_ASCII)
- {
- key = TOLOBYTE(key);
-
- if (key==0)
- key = EDIT_KEY(K_CTL_BRK);
- else
- if ((i = stridxc (key,IBMFNCKEYS)) > 0)
- key = FNC_KEY(i);
- else
- if ((key >= 16) && (key <= 50)) /* <alt> alphabetics */
- key = ALT_KEY(_qwerty[key-16]);/*<alt><A> ==> <KB_ALT,'A'>*/
- else
- if ((key >= 120) && (key <= 131)) /* <alt> numbers */
- key = ALT_KEY(_altkeys[key - 120]);
- else
- {
- i = stridxc (key, _otherspecial);
- key = (i > NOTFND)
- ? MAKEWORD(_othertyps[i],_othercodes[i])
- : ASCII_KEY(NULLVAL);/* UNDEFINED KEY ! */
- }
- }
- else
- {/* ASCII characters. */
- switch (key)
- {
- case NPAD_STAR:
- key = EDIT_KEY(K_STAR_NUMPAD);
- break;
- case NPAD_PLUS:
- key = EDIT_KEY(K_PLUS_NUMPAD);
- break;
- case NPAD_MINUS:
- key = EDIT_KEY(K_MINUS_NUMPAD);
- break;
- default:
- key = LOBYTE(key); /* key type is ASCII (0), so zero high byte */
- if ((key == ESC) && (_f_redef_esc))
- key = FNC_KEY(0);/* make <esc> == <function key zero> */
- break;
- }
- }
- return (key);
- }
-