home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
rtsi.com
/
2014.01.www.rtsi.com.tar
/
www.rtsi.com
/
OS9
/
OSK
/
TELECOM
/
stg_v4.lzh
/
key.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-11-11
|
4KB
|
187 lines
/*
* 89/??/?? StG original concept and specs for DB9 format
* 90/09/?? StG coding began
* 91/05/27 StG updated to new naming conventions, fixed bugs
*
* DB9 keyboard input routines
* (c) 1990 by StG Computers inc.
* Unauthorized Reproduction Prohibited
*
* code=_Key(wait)
*
* wait= 0 - return key code or 0 for no key pressed yet
* 1 - wait for key pressed, return key code
*
* code= key code as defined in key.h
*/
#define ERR (-1)
#include "key.h"
extern int errno;
/* path descriptor buffers for _Eko() */
#ifdef _OSK
char _pdsav[128];
char _pdwrk[128];
#endif
#ifdef _UNIX
#include <termio.h>
struct termio sTermIO;
struct termio sTermSav;
#endif
/* turn echo off when reading character from keyboard (internal) */
_Eko(iTurnOff)
int iTurnOff;
{
static int iIsOff=0;
/* dufus check */
if (!iTurnOff && !iIsOff) return(0);
if (iTurnOff && iIsOff) return(0);
#ifdef _OSK
if (iIsOff)
{
/* turn back on */
_ss_opt(0,_pdsav);
iIsOff=0;
return(0);
}
/* turn off */
_gs_opt(0,_pdsav);
_gs_opt(0,_pdwrk);
_pdwrk[0x04]=0; /* no echo */
_pdwrk[0x07]=0; /* no pause */
_pdwrk[0x0C]=0; /* no ERR */
_pdwrk[0x10]=0; /* no pause chr */
_pdwrk[0x11]=0; /* no interrupt */
_pdwrk[0x12]=0; /* no abort */
_ss_opt(0,_pdwrk);
iIsOff=1;
return(0);
#endif
#ifdef _UNIX
if (iIsOff)
{
/* turn back on */
ioctl(0,TCSETAF,&sTermSav);
iIsOff=0;
return(0);
}
/* turn off */
ioctl(0,TCGETA,&sTermIO);
ioctl(0,TCGETA,&sTermSav);
sTermIO.c_lflag=0; /* no echo, raw, etc. */
sTermIO.c_cc[4]=0; /* minimum # of chars */
sTermIO.c_cc[5]=1; /* maximum amt of time */
ioctl(0,TCSETAF,&sTermIO);
iIsOff=1;
return(0);
#endif
}
_Key(iWait)
int iWait;
{
char cKey;
#ifdef _OSK
if (!iWait && _gs_rdy(0)==ERR)
return(0);
_Eko(1);
#endif
while (read(0,&cKey,1)!=1)
if (!iWait)
return(0);
#ifdef _OSK
_Eko(0);
#endif
if (cKey==27) goto keyesc;
if (cKey==24) goto keyfun;
return(cKey);
keyesc:
#ifdef _OSK
tsleep(15);
if (_gs_rdy(0)==ERR)
return(cKey);
#endif
keyfun:
#ifdef _OSK
_Eko(1);
#endif
if (read(0,&cKey,1)!=1)
return(27);
#ifdef _OSK
_Eko(0);
#endif
return(cKey+128);
}
#ifdef BOGUS
/* saved MSDOS routine */
unsigned int uKey; /* msdos return code */
char cKey;
if (!iWait && !bioskey(1)) return(0);
uKey=bioskey(0);
cKey=uKey&0xFF;
uKey=(uKey>>8)&0xFF;
if (cKey==24) goto keyfun;
if (!cKey) switch(uKey)
{
/* keypad keys */
case 71: cKey=KY_HOME; break;
case 75: cKey=KY_LEFT; break;
case 82: cKey=KY_INS; break;
case 83: cKey=KY_DEL; break;
case 79: cKey=KY_END; break;
case 77: cKey=KY_RIGHT; break;
case 80: cKey=KY_DOWN; break;
case 72: cKey=KY_UP; break;
case 81: cKey=KY_PGDN; break;
case 73: cKey=KY_PGUP; break;
/* Function Keys */
case 59: cKey=KY_FUN('1'); break;
case 60: cKey=KY_FUN('2'); break;
case 61: cKey=KY_FUN('3'); break;
case 62: cKey=KY_FUN('4'); break;
case 63: cKey=KY_FUN('5'); break;
case 64: cKey=KY_FUN('6'); break;
case 65: cKey=KY_FUN('7'); break;
case 66: cKey=KY_FUN('8'); break;
case 67: cKey=KY_FUN('9'); break;
case 68: cKey=KY_FUN('0'); break;
/* put alt-letter keys here */
default: cKey=KY_ABORT; break;
}
return(cKey);
keyfun:
uKey=bioskey(0);
cKey=uKey&0xFF;
uKey=(uKey>>8)&0xFF;
return(cKey+128);
}
#endif