home *** CD-ROM | disk | FTP | other *** search
- /*
- * key98.c: hterm keyboard decoder for NEC-PC9801
- * and
- * TSR program 'hkey' which provides hterm like keyboard environment
- *
- *
- * Author: HIRANO Satoshi
- * (C) 1989 Halca Computer Science Laboratory TM
- * University of Tokyo
- *
- * NOTE:
- * Quoting is used to pass HTERM CONTROL KEY to hterm.
- * See putBuf()
- *
- * 'hkey' program should be compiled without stack checking
- * and be linked with crt.obj.
- * masm -Mx crt.asm;
- * cl -DPC98 -DTSR -Ox -c key98.c
- * link crt+key98,hkey;
- *
- * 2.2 89/05/16 Halca.Hirano remove all of kana char in source code
- * ---- V2.2 distribution -----
- * 2.3 89/06/15 Halca.Hirano
- * 1 remove #else
- * 2.4 89/06/20 Halca.Hirano support front end processor
- * change Function-Key send code
- * 2.5 89/06/26 Halca.Hirano fix FEP state bug.
- * restore shift/ctrl status on exit to BIOS
- * add send break
- * 2.6 89/06/29 Halca.Hirano change the way to get a key entirely
- * old: use own interrupt handler, and pass key to hterm directly
- * new: get key from BIOS
- * 2.7 89/07/04 Halca.HIrano change the way to get a key entirely again!!
- * old: get key from BIOS
- * BUT this can not be used with VJE, NEC-AI....
- * new: use original key interrupt handler.
- * Thank you Shikita@titec & Yocchan@kao (UEC ultra-key).
- * 2.8 89/07/18 Halca.Hirano add cursor key, keypad (normal/application mode)
- * add editPFKey function
- * 2.9 89/07/20 Halca.Hirano add shift/ctrl lock
- * 2.10 89/07/26 Halca.Hirano pass kana if fepMode
- * add history Editor, add fep invokation key sequence limitation
- * ----- V2.3.-1 distribution ----
- * 2.11 89/08/03 Halca.Hirano add DOS mode (true BIOS emulator)
- * 2.12 89/08/05 Halca.Hirano add mouse functions
- * 2.13 89/09/14 Halca.Hirano add PC98XA by Mr. blackROSe
- * fix DOS mode space key bug (We could't generate SPACE key.) OH MY GOD!!
- * ---- V2.4.0 distribution ----
- * 2.14 89/09/29 Halca.Hirano
- * add short wait between outp() and inp(). This is needed for PC98XA.
- * 2.15 89/10/14 Halca.Hirano
- * add PC98XA short/long break
- * add PC98XA dos mode ten key
- * 2.16 89/11/28 naka_j@huie.hokudai.ac.jp
- * old MATUTAKE(FEP) eats DEL, then add code change.
- * 2.17 89/11/29 Halca.Hirano
- * fix PC98XA nop bug (increase nullFunction calling)
- * fix set-up mode tenkey bug
- * fix normal keypad mode HOME, HELP key bug
- * 2.18 89/12/03 Halca.Hirano
- * add BS key watcher
- * 2.19 89/12/08 Halca.Hirano
- * re-initialize keyboard bios at exit (but I've abandoned!)
- * 2.20 90/01/16 Halca.Hirano
- * hkey TSR
- * meta-key can be used in DOS mode.
- * 2.21 90/04/30 Halca.Hirano
- * write special C-startup for hkey.exe
- * old size in memory $11030 bytes + environment area
- * new size in memory $1190 bytes
- * support STOP/COPY interrupt if OS mode or TSR mode
- * 2.22 90/05/27 Halca.Hirano
- * new feature! key swapping table
- * now we can assign arbitrary key to arbitrary key.
- * 2.23 90/06/21 Halca.Hirano
- * change key table size from short to u_char
- *
- * $Header: key98.cv 1.17 90/07/05 03:05:38 hirano Exp $
- *
- */
-
- #include <stdio.h>
- #include <string.h>
- #include <io.h>
- #include <stdlib.h>
- #include "option.h"
- #include "config.h"
- #include "hterm.h"
- #include "default.h"
- #include "hkey.h"
-
- #ifdef TSR
- #undef BS_WATCHER
- #undef MOUSE
- #else
- #include "global.h"
- #endif /* TSR */
-
- /*
- * key table magics
- */
- #define BS_SCAN_CODE 0x0e /* BS key scan code */
- #define QUOTE_CHAR 'H' /* keyHander->hterm quote */
-
- #include "keytab98.h" /* key board conversion table */
-
- /*
- * shift state of BIOS work KB_SHFT
- */
- #define S_SHIFT(x) ((x) & 0x01)
- #define S_CAPS(x) ((x) & 0x02)
- #define S_KANA(x) ((x) & 0x04)
- #define S_GRAPH(x) ((x) & 0x08)
- #define S_CTRL(x) ((x) & 0x10)
- #define S_NFER(x) ((x) & 0x20)
- #define S_XFER(x) ((x) & 0x02)
-
- struct _BIOS_WORK {
- short KB_BUF[17]; /* not 16 */
- short KB_HEAD;
- short KB_TAIL;
- short KB_COUNT;
- char KB_STS[16];
- char KB_SHFT;
- };
-
- /*
- * static storage should be initialized for TSR
- */
- int meta = 0;
- int fepMode = 0; /* 1=FEP mode */
- int ctrlLocked = 0; /* CTRL is locked */
- int shiftLocked = 0; /* SHIFT is locked */
-
- #ifdef TSR
- int clickFlag = 0;
- int applKeypad = 0;
- int applCursor = 0;
- int asckey = 0;
- int bsDel = 0;
- int shiftLock = 0;
- int fepInvoke = 0;
- int mouseSpeed = 0;
- int bsKeyCount = 0;
- int bsKeyRatio = 0;
- int keyCount = 0;
- int ctrlSpace = 0;
- void keyInit();
- int mode = 0;
- void (interrupt FAR *getVect(unsigned))();
- #else
- int ctrlSpace;
- #endif /* TSR */
-
- #ifdef PC98XA
- short XAspecial[MAX_FUNKEY] = {0,};
- int XAcount = 0;
- int XAsplpos = 0;
-
- #define KEY_CODE_PF11 0x52
- #define KEY_CODE_PF15 0x56
- #endif /* PC98XA */
-
- void (interrupt FAR *keyVector)() = 0; /* original key handler */
-
- u_char *ctrltbl = 0;
- u_char *noshiftbl = 0;
- u_char *shiftbl = 0;
- u_char *kanatbl = 0;
- u_char *shkanatbl = 0;
- #ifndef TSR
- static u_char keiUnConv[76] = {
- 0x9f, 0xaa, 0xa0, 0xab, 0x9f, 0xaa, 0xa0, 0xab,
- 0x9f, 0xaa, 0xa0, 0xab, 0xa1, 0xa1, 0xa1, 0xac,
- 0xa2, 0xa2, 0xa2, 0xad, 0xa4, 0xa4, 0xa4, 0xaf,
- 0xa3, 0xa3, 0xa3, 0xae, 0xa5, 0xba, 0xa5, 0xa5,
- 0xb5, 0xa5, 0xa5, 0xb0, 0xa7, 0xbc, 0xa7, 0xa7,
- 0xb7, 0xa7, 0xa7, 0xb2, 0xa6, 0xa6, 0xa6, 0xb6,
- 0xbb, 0xa6, 0xa6, 0xb1, 0xa8, 0xa8, 0xa8, 0xb8,
- 0xbd, 0xa8, 0xa8, 0xb3, 0xa9, 0xa9, 0xa9, 0xb9,
- 0xa9, 0xa9, 0xbe, 0xa9, 0xa9, 0xa9, 0xa9, 0xa9,
- 0xa9, 0xa9, 0xa9, 0xb4
- };
- #endif /* TSR */
-
- static void INTERRUPT FAR keyHandler();
- static int keyCtrl(unsigned char keyCode);
- void putFunkey(unsigned char key,unsigned char inCode,unsigned char (*keyTable)[MAX_FUNKEY]);
- void putBuf(short c,int recFlag);
- void mouseSetHandler(int onOff);
- void mouseOnOff(int onOff);
- void mouseSetPosition(int x,int y);
- void far mouseEvent(int event,int x,int y);
- #ifdef TSR
- void nullFunction(void);
- void keyReInit(void);
- void keySetup(void);
- void keyEnd(void);
- void keyMode(void);
- void setBSDel(int);
- void mouseEnd(void);
- void mouseInit(void);
- #endif
-
- #ifdef TSR
- char endAddress = 0; /* break off mark */
- /*
- * data below are detached at exit
- */
- char hkeyVersion[] = HKEY_MARK;
- char TSRMsg[] = "\
- (C) 1990 Halca Computer Science Laboratory (HIRANO)\r\n$";
-
- char syntax1[] = "\
- : hterm like keyboard environment TSR for PC9801\r\n\
- syntax: hkey [-options]\r\n\
- options and special keys: (C-S-x = CTRL-SHIFT-x)\r\n\
- \t-a (C-S-1) ascii keyboard\r\n\
- \t-p (C-S-2) pc9801 keyboard (default)\r\n\
- \t-c (C-S-3) key click\r\n\
- \t-s (C-S-4) silent; no key click (default)\r\n\
- \t-C (C-S-5) CTRL-XFER FEP (default)\r\n\
- $";
- char syntax2[] = "\
- \t-S (C-S-6) SHIFT-XFER FEP\r\n\
- \t-B (C-S-7) CTRL- or SHIFT-XFER FEP\r\n\
- \t-N (C-S-8) NO FEP\r\n\
- \t-@ (C-S-9) toggle CTRL-SPACE enable/disable\r\n\
- \t-H (C-S-HELP) CTRL/SHIFT lock\r\n\
- \t (C-S-HOME) No CTRL/SHIFT lock (default)\r\n\
- \t (C-S-STOP) reset system\r\n\
- $";
- /* \tC-S-ESC terminate hkey\r\n\ */
-
- main(argp)
- char FAR *argp;
- {
- char FAR *p;
- char *q;
- int i;
- extern int pspSeg;
-
- keyInit();
- putMsg(hkeyVersion);
- for (p = argp; *p != CR; p++) {
- switch (*p) {
- case ' ': case '\t': case '-': break;
- case 'a': asckey = YES; break;
- case 'p': asckey = NO; break;
- case 'c': clickFlag = YES; break;
- case 's': clickFlag = NO; break;
- case 'C': fepInvoke = FEP_CTRLXFER; break;
- case 'S': fepInvoke = FEP_SHIFTXFER; break;
- case 'B': fepInvoke = FEP_BOTHXFER; break;
- case 'N': fepInvoke = FEP_NOXFER; break;
- case 'H': shiftLock = YES; break;
- case '@': ctrlSpace = !ctrlSpace; break;
- default:
- putMsg(syntax1); putMsg(syntax2);
- keyEnd();
- _exit(1);
- }
- }
- /*
- * copy command name to parameter area in PSP
- */
- FP_SEG(p) = pspSeg;
- FP_OFF(p) = 0x80;
- *p++ = SIZE_OF_HKEY_MARK; /* size of "hkey1.2" */
- q = hkeyVersion; /* TSRMsg begins with "hkey1.2" */
- for (i = 0; i < SIZE_OF_HKEY_MARK; i++)
- *p++ = *q++;
- *p = CR;
- /*
- * print banner
- */
- putMsg(TSRMsg);
- mode = M_OS;
- fepMode = NO;
- keySetup();
-
- /*
- * terminate but stay the program
- * (in crt:__main)
- */
- }
-
- void click()
- {
- int i;
-
- outp(PORT_C, 0x06); /* buzzar on */
- for (i = 0; i < CLICK_BEEP; i++)
- nullFunction(); /* short wait */
- outp(PORT_C, 0x07);
- }
-
- void nullFunction()
- {}
- #endif /* TSR */
-
- void keyInit()
- /*
- * iniz keyboard mode; set defaults
- */
- {
- clickFlag = DEFAULT_KEY_CLICK;
- applKeypad = DEFAULT_APP_KEYBOARD;
- applCursor = DEFAULT_CURSOR_KEY_MODE;
- asckey = DEFAULT_KEYBOARD;
- bsDel = DEFAULT_BS_KEY;
- shiftLock = DEFAULT_SHIFT_LOCK;
- fepInvoke = DEFAULT_FEP_INVOKE;
- mouseSpeed = DEFAULT_MOUSE_SPEED;
- shiftLocked = ctrlLocked = NO;
- bsKeyCount = keyCount = 0;
- bsKeyRatio = DEFAULT_BS_KEY_RATIO;
- ctrlSpace = YES;
- meta = fepMode = ctrlLocked = shiftLocked = NO;
- keyVector = 0;
- keyReInit();
- }
-
- void keyReInit()
- /*
- * re-initialize keyboard
- */
- {
- /*
- * set key interrupt handler
- */
- #ifdef TSR
- keyVector = getVect(9);
- setVect(9, keyHandler);
- #else
- keyVector = GET_DOSVECT(9);
- SET_DOSVECT(9, keyHandler);
- #endif
- mouseInit();
- }
-
- void keySetup()
- /*
- * setup keyboard mode
- */
- {
- keyMode();
- setBSDel(bsDel);
- }
-
- void keyEnd()
- {
- /*
- * restore key handler
- */
- if (keyVector) {
- #ifdef TSR
- setVect(9, keyVector); /* use own library */
- #else
- SET_DOSVECT(9, keyVector);
- #endif /* TSR */
- mouseEnd();
- }
- keyVector = 0;
- }
-
- void keyMode()
- /*
- * change key board mode (PC9801 or ASCII)
- */
- {
- if (asckey) {
- ctrltbl = actrltbl; noshiftbl = anoshiftbl;
- shiftbl = ashiftbl; kanatbl = akanatbl;
- shkanatbl = ashkanatbl;
- } else {
- ctrltbl = pctrltbl; noshiftbl = pnoshiftbl;
- shiftbl = pshiftbl; kanatbl = akanatbl;
- shkanatbl = ashkanatbl;
- }
- }
-
- void setBSDel(bsDelFlag)
- /*
- * switch BS -> DEL or BS -> BS
- */
- {
- if (bsDelFlag == BS_BS) {
- anoshiftbl[BS_SCAN_CODE] =
- akanatbl[BS_SCAN_CODE] =
- ashkanatbl[BS_SCAN_CODE] =
- pnoshiftbl[BS_SCAN_CODE] = BS;
- } else {
- anoshiftbl[BS_SCAN_CODE] =
- akanatbl[BS_SCAN_CODE] =
- ashkanatbl[BS_SCAN_CODE] =
- pnoshiftbl[BS_SCAN_CODE] = DEL;
- }
- }
-
- #ifndef TSR
- short keyin()
- /*
- * return charactor code if data available, else return -1
- *
- * INTERFACE:
- *
- * if key is hterm special control key, return code is xx00
- * if key is KANJI char, return code is xxyy (JIS without preamble)
- * else return code is 00xx
- *
- * NOTE:
- * we should NOT call outPort() (serial output) in this procedure.
- *
- */
- {
- register short c;
- register short cl;
-
- #ifdef SOFT_FONT
- if (softFont && blinkCursor && (blinkTimer <= 0)) {
- blinkSoftCursor();
- }
- #endif /* SOFT_FONT */
-
- #ifdef PC98XA
- /* first try to get hterm special key */
- if (XAcount > 0) {
- c = XAspecial[XAsplpos];
- ++XAsplpos;
- --XAcount;
- } else {
- /* try to get from DOS */
- XAsplpos = 0;
- if ((c = directConsoleIO()) == -1)
- return(-1);
- }
- #else
- /* try to get from DOS */
- if ((c = directConsoleIO()) == -1)
- return(-1);
- #endif /* PC98XA */
- /*
- * reset screen saver timer because user hits keyboard.
- */
- timerValue = timerLoadValue;
- /*
- * if FEP mode, build hterm kanji code
- */
- if (fepMode) {
- /* THIS IS DANGEROUS, for fast CTRL-XFER */
- if (isSJIS1(c)) {
- /* get SJIS second byte */
- while ((cl = directConsoleIO()) == -1)
- ;
- /*
- * if NEC keisen, convert to JIS-83 keisen
- */
- if (c == 0x86 && 0xa2 <= cl && cl <= 0xed) {
- c = 0x84;
- cl = keiUnConv[cl - 0xa2];
- }
- return(SJIStoJIS(c, cl));
- }
- return(c);
- }
- #ifdef PC98XA
- /* quoting is not used on PC98XA */
- #else
- /*
- * deconpose quoted char if required
- */
- c &= 0x7f;
- if (c == QUOTE_CHAR) {
- /* get quoted char (kana or hterm ctrl char) */
- while ((c = directConsoleIO()) == -1)
- ;
- if (c != QUOTE_CHAR) {
- c |= 0x80;
- if (c == (NE_KEY>>8))
- c = 0xc8; /* kana 'ne' key */
- if (c == DELK_THRU_MTTK)
- c = DEL_KEY; /* matutake taisaku */
- }
- }
- #endif /* PC98XA */
- /*
- * treat break signal here
- */
- if (c == SHORT_BREAK) {
- sendBreak(1);
- return(-1);
- } else if (c == LONG_BREAK) {
- sendBreak(2);
- return(-1);
- }
- /*
- * return hterm internal char code.
- * if special key then $xx00, else $00xx
- */
- return(isHtermCtrl(c) ? (c << 8): c);
- }
- #endif /* TSR */
-
- void interrupt FAR keyHandler()
- /*
- * convert scan code to ASCII code, put chars in BIOS buffer
- *
- * This may look like too complex, but don't worry!
- */
- {
- register u_char keyCode;
- register short inCode = 0;
- int pullFlag;
- register struct _BIOS_WORK FAR *w =
- (struct _BIOS_WORK FAR *)BIOS_KEY_WORK;
- register char shiftState;
-
- outp(ADDR_KEY_STATUS, 0x16); /* no retry */
- nullFunction(); /* short wait */
- nullFunction(); /* short wait */
- nullFunction(); /* short wait */
-
- keyCode = inp(ADDR_KEY_DATA); /* get key code from keyboard */
- pullFlag = (keyCode & 0x80);
- keyCode &= 0x7f;
-
- /*
- * key swapping
- */
- if (keyCode < sizeof(keySwapTable)) {
- if ((keyCode = keySwapTable[(int)keyCode]) == 0xff)
- goto end;
- keyCode &= 0x7f;
- }
-
- /*
- * set/clear key status table
- */
- shiftState = 1 << (keyCode & 0x7);
- if (!shiftLock || (keyCode != 0x70/*shift*/ && keyCode != 0x74/*ctrl*/)) {
- w->KB_STS[keyCode/8] ^= shiftState; /* update BIOS key table */
- w->KB_SHFT = w->KB_STS[0x0e]; /* update BIOS shift status*/
- if (keyCode/8 == 0x0e) /* return if shift/ctrl/kana.. key */
- goto end;
- } else if (!pullFlag) {
- /*
- * process shift/ctrl lock feature
- * CAUTION complex logic
- */
- if (S_SHIFT(shiftState)) {
- if (shiftLocked == 2) { /* double shift */
- w->KB_STS[keyCode/8] = (w->KB_SHFT &= ~0x01);
- shiftLocked = NO;
- } else if (shiftLocked == 1) { /* single shift */
- shiftLocked++;
- click();
- click();
- } else { /* no shift */
- w->KB_STS[keyCode/8] = (w->KB_SHFT |= 0x01);
- shiftLocked++;
- click();
- }
- } else if (S_CTRL(shiftState)) {
- if (ctrlLocked == 2) { /* double shift */
- w->KB_STS[keyCode/8] = (w->KB_SHFT &= ~0x10);
- ctrlLocked = NO;
- } else if (shiftLocked == 1) { /* single shift */
- shiftLocked++;
- click();
- click();
- } else { /* no shift */
- w->KB_STS[keyCode/8] = (w->KB_SHFT |= 0x10);
- ctrlLocked++;
- click();
- }
- }
- goto end;
- }
-
- if (pullFlag)
- goto end;
-
- /*
- * set shift status
- */
- meta = 0;
- shiftState = w->KB_SHFT;
-
- if (S_NFER(w->KB_STS[6]) || S_XFER(w->KB_STS[0x0a]))
- meta = YES;
-
- /*
- * check keyboard control sequence; CTRL-SHIFT
- * otherwise key with shift & ctrl is treated as with ctrl
- */
- if (S_SHIFT(shiftState) && S_CTRL(shiftState)) {
- if (keyCtrl(keyCode))
- goto end;
- shiftState &= ~0x01; /* strip shift */
- }
-
- if (clickFlag == YES)
- click();
- /*
- * key is pressed. reset shift/ctrl lock if single shift
- */
- if (shiftLocked == 1) {
- w->KB_STS[0x0e] = (w->KB_SHFT &= ~0x01);
- shiftLocked = 0; /* reset shiftlock */
- }
- if (ctrlLocked == 1) {
- w->KB_STS[0x0e] = (w->KB_SHFT &= ~0x10);
- ctrlLocked = 0; /* reset ctrllock */
- }
- #ifdef PC98XA
- inCode = shiftState; /* 98XA's inCode is shift state */
- if (keyCode == BS_SCAN_CODE)
- if (noshiftbl[BS_SCAN_CODE] == DEL)
- keyCode = 0x39;
- #endif /* PC98XA */
-
- #ifdef PC98XA
- /*
- * CTRL-ESCAPE / Shift-ESCAPE
- */
- if (keyCode == 0x00) {
- if (S_KANA(shiftState) && fepMode) {
- /* put kana without quoting */
- putBuf((keyCode << 8) | inCode, 1);
- }
- else if (S_CTRL(shiftState)) {
- putBuf(SHORT_BREAK, 0);
- }
- else if (S_SHIFT(shiftState)) {
- putBuf(LONG_BREAK, 0);
- }
- else {
- putBuf((keyCode<<8) | inCode, 1);
- }
- }
- /*
- * typewriter keys
- */
- else if (0 < keyCode && keyCode <= LAST_KEY_TABLE) {
- /* We don't support key mapping on PC98XA */
- if (S_KANA(shiftState) && fepMode) {
- /* put kana without quoting */
- putBuf((keyCode << 8) | inCode, 1);
- } else {
- if (meta)
- putBuf((0x0 /* ESC */<<8) | inCode, 0);
- putBuf((keyCode << 8) | inCode, 0);
- }
- #else
- /*
- * typewriter keys
- */
- if (0 <= keyCode && keyCode <= LAST_KEY_TABLE) {
- if (S_CTRL(shiftState)) /* CTRL- */
- inCode = ctrltbl[keyCode];
- else if (S_KANA(shiftState)) /* KANA- */
- inCode = S_SHIFT(shiftState) ? shkanatbl[keyCode] : kanatbl[keyCode];
- else /* NORMAL */
- inCode = S_SHIFT(shiftState) ? shiftbl[keyCode] : noshiftbl[keyCode];
-
- if (S_CAPS(shiftState)) { /* CAPS */
- if (S_SHIFT(shiftState) && isUpper(inCode))
- inCode += 0x20;
- else if (!S_SHIFT(shiftState) && isLower(inCode))
- inCode -= 0x20;
- }
- if (inCode != NA) {
- if (meta && !fepMode)
- putBuf(ESC, 0);
- if (S_KANA(shiftState) && (fepMode || mode == M_OS)) {
- /* put kana without quoting */
- putBuf(inCode, 1);
- } else {
- if (inCode == 0xc8) /* kana NE key */
- inCode = (NE_KEY >> 8);
- putBuf(inCode, 0);
- }
- }
- #endif /* PC98XA */
- /*
- * NFER
- */
- } else if (keyCode == 0x51) {
- if (fepMode) {
- if (S_SHIFT(shiftState) || S_CAPS(shiftState)) keyCode = 0xa1;
- else if (S_CTRL(shiftState)) keyCode = 0xb1;
- else keyCode = 0x51;
- putBuf((keyCode << 8), 0);
- } /* else ignore NFER, it's meta key */
- /*
- * XFER
- */
- } else if (keyCode == 0x35) {
- if (mode == M_OS || mode == M_COMM || mode == M_HISTORY) {
- if ((fepInvoke == FEP_CTRLXFER && S_CTRL(shiftState)) ||
- (fepInvoke == FEP_SHIFTXFER && S_SHIFT(shiftState)) ||
- (fepInvoke == FEP_BOTHXFER && (S_CTRL(shiftState) || S_SHIFT(shiftState)))) {
- fepMode = !fepMode;
- putBuf(S_CTRL(shiftState) ? 0xb500: 0xa500, 0);
- } else if (fepMode) {
- #if 0
- putBuf((S_SHIFT(shiftState) || S_CAPS(shiftState)) ? 0xa500 : 0x3500, 0);
- #else
- putBuf(0x3500, 0);
- #endif
- }
- }
- /*
- * CTRL-SPACE
- */
- #ifdef PC98XA
- } else if (keyCode == 0x34) {
- if (S_CTRL(shiftState)) {
- keyCode = 0x1a; /* CTRL-@ */
- inCode = shiftState;
- } else {
- keyCode = 0x34; /* Space */
- inCode = 0;
- }
- if (meta)
- putBuf((0<<8) /* ESC */ | inCode, 0);
- putBuf((keyCode << 8) | inCode, 0);
- #else
- } else if (keyCode == 0x34) {
- if (ctrlSpace && S_CTRL(shiftState)) {
- inCode = 0;
- keyCode = 0x1a; /* CTRL-@ */
- } else {
- inCode = SPACE;
- keyCode = 0x34;
- }
- if (meta && !fepMode)
- putBuf((0<<8) | ESC, 0);
- putBuf((keyCode << 8) | inCode, 0);
- #endif /* PC98XA */
- /*
- * function keys
- */
- } else if (KEY_CODE_PF1 <= keyCode && keyCode <= KEY_CODE_PF10) {
- if (fepMode || mode == M_OS) {
- #ifdef PC98XA
- /* scan code will be built in BIOS INT18H */
- putBuf((keyCode << 8)| inCode, 0);
- #else
- if (S_SHIFT(shiftState))
- keyCode += 0x20;
- else if (S_CTRL(shiftState))
- /*
- * CTRL-PF with ATOK makes hterm brain damaged!
- * but this is needed for WXP.
- */
- keyCode += 0x30;
- /* else normal is ok */
- putBuf((keyCode << 8), 0);
- #endif /* PC98XA */
- #ifndef TSR
- } else { /* communication mode */
- if (S_SHIFT(shiftState)) {
- putFunkey(keyCode-KEY_CODE_PF1, 0/*inCode*/, SHIFTFunkey);
- } else if (S_CTRL(shiftState)) {
- putBuf(CTRLFunkey[keyCode - KEY_CODE_PF1]>>8, 0);
- } else if (meta) {
- putBuf(METAFunkey[keyCode - KEY_CODE_PF1]>>8, 0);
- } else {
- putFunkey(keyCode-KEY_CODE_PF1, 0/* inCode*/, NORMALFunkey);
- }
- #endif /* TSR */
- }
- #ifdef PC98XA
- /*
- * function keys PF11 ~ PF15 Sorry, but I want.
- */
- } else if (keyCode >= KEY_CODE_PF11 && keyCode <= KEY_CODE_PF15) {
- putBuf((keyCode << 8) | inCode, 0);
- #endif /* PC98XA */
- /*
- * cursor keys and ten keys
- */
- } else if (SCAN_PAD_BEGIN <= keyCode && keyCode <= SCAN_PAD_END) {
- if (fepMode || mode == M_OS) {
- #ifdef PC98XA
- /* scan code will be built in BIOS INT18H */
- putBuf((keyCode << 8)| inCode, 0);
- #else
- if (keyCode >= 0x40) /* ten key */
- putBuf(CTRLPad[keyCode-SCAN_PAD_BEGIN], 0);
- else
- putBuf((keyCode << 8), 0);
- #endif /* PC98XA */
- #ifndef TSR
- } else if (mode == M_HISTORY || mode == M_SETUP) { /* CTRL-keypad */
- putBuf(CTRLPad[keyCode-SCAN_PAD_BEGIN], 0);
- } else { /* normal condition in comm. mode */
- #ifdef PC98XA
- /* according to BlackROSE@ROS, HOME and HELP key belong to cursor key */
- if ((keyCode >= 0x40 && !applKeypad) || (keyCode < 0x40 && !applCursor)) {
- #else
- if ((keyCode >= 0x3e && !applKeypad) || (keyCode < 0x3e && !applCursor)) {
- #endif /* PC98XA */
- putFunkey(keyCode-SCAN_PAD_BEGIN, 0/* inCode*/, NORMALPad);
- } else {
- putFunkey(keyCode-SCAN_PAD_BEGIN, 0/* inCode*/, APPLPad);
- }
- #endif /* TSR */
- }
- /*
- * copy/stop (set-up/exit)
- */
- } else if (keyCode == KEY_CODE_COPY || keyCode == KEY_CODE_STOP) {
- #ifndef TSR
- if (!fepMode && mode != M_OS) {
- if (!(S_CTRL(shiftState) || S_SHIFT(shiftState)))
- putBuf(((keyCode == KEY_CODE_COPY) ? SETUP_KEY : STOP_KEY)>>8, 0);
- } else if (mode == M_OS)
- #endif /* TSR */
- {
- #ifdef TSR
- outp(ICR, EOI);
- if (keyCode == KEY_CODE_STOP)
- int6();
- else
- int5();
- return;
- #endif /* TSR */
- }
- }
- /*
- * else ignore
- */
- end:
- outp(ICR, EOI); /* end of interrupt */
- }
-
- static int keyCtrl(keyCode)
- /*
- * control TSR program from the keyboard by CTRL-SHIFT-keyCode
- */
- register u_char keyCode;
- {
- struct SREGS segRegs;
- void (FAR *boot)();
- int done = YES;
-
- switch (keyCode) {
- case 0: /* ESC: terminate hkey */
- outp(ICR, EOI); /* end of interrupt */
- keyEnd(); /* restore key interrupt vector */
- #if 0
- /*
- * we should check in dos flag
- */
- segread(&segRegs);
- segRegs.es = pspSegment;
- rg.h.ah = 0x49;
- int86x(0x21, &rg, &rg, &segRegs); /* free memory */
- rg.x.ax = 0x4c00;
- intdos(&rg, &rg); /* terminate process */
- #endif
- break;
- case KEY_CODE_STOP: /* stop: reset system */
- outp(ICR, EOI);
- outp(0x37, 0x0b);
- outp(0x37, 0x0f); /* ??? */
- outp(0x0f0, 0x00); /* reset CPU */
- FP_SEG(boot) = 0xffff;
- FP_OFF(boot) = 0;
- (*boot)(); /* reboot */
- break;
- case 0x4a: /* ten key 1: ascii keyboard */
- asckey = YES; keyMode(); break;
- case 0x4b: /* ten key 2: pc98 keyboard */
- asckey = NO; keyMode(); break;
- case 0x4c: /* ten key 3: key click on */
- clickFlag = YES; break;
- case 0x46: /* ten key 4: key click off */
- clickFlag = NO; break;
- case 0x47: /* ten key 5: CTRL-XFER fep */
- fepInvoke = FEP_CTRLXFER; break;
- case 0x48: /* ten key 6: SHIFT-XFER fep */
- fepInvoke = FEP_SHIFTXFER; break;
- case 0x42: /* ten key 7: BOTH-XFER fep */
- fepInvoke = FEP_BOTHXFER; break;
- case 0x43: /* ten key 8: NO-XFER fep */
- fepInvoke = FEP_NOXFER; break;
- case 0x44: /* ten key 9: toggle CTRL-SPACE */
- ctrlSpace = !ctrlSpace; break;
- case 0x3f: /* ten key HELP: shift/ctrl lock */
- shiftLock = YES; break;
- case 0x3e: /* ten key HELP: shift/ctrl lock */
- shiftLock = NO; break;
- default:
- done = NO;
- }
- return(done);
- }
-
- #ifndef TSR
- static void putFunkey(key, inCode, keyTable)
- /*
- * put a string into BIOS key buffer
- */
- u_char key, inCode;
- u_char (*keyTable)[MAX_FUNKEY];
- {
- u_char *p;
-
- #ifdef PC98XA
- XAcount = 0;
- for (p = keyTable[key]; *p; p++) {
- XAspecial[XAcount++] = *p;
- if (XAcount >= MAX_FUNKEY)
- break;
- }
- #else
- for (p = keyTable[key]; *p; p++)
- putBuf((inCode << 8) | *p, 0);
- #endif /* PC98XA */
- }
- #endif /* TSR */
-
- /*
- * put a char to BIOS key buffer
- */
- static void putBuf(c, recFlag)
- short c;
- int recFlag; /* recursive flag */
- {
- register struct _BIOS_WORK FAR *w =
- (struct _BIOS_WORK FAR *)BIOS_KEY_WORK;
- short FAR *p;
- u_char c0 = (c & 0xff);
-
- #ifdef BS_WATCHER
- /*
- * BS key watcher
- */
- if (recFlag == NO) {
- #ifdef PC98XA
- if ((c >> 8) == 0x39/*DEL*/ || (c >> 8) == BS_SCAN_CODE)
- #else
- if (c0 == BS || c0 == DEL)
- #endif /* PC98XA */
- bsKeyCount++;
- keyCount++;
- }
- #endif /* BS_WATCHER */
-
- #ifdef PC98XA
- /*
- * if special ctrl char, put it on own buffer
- */
- if (!recFlag && mode != M_OS && (c0 > 0x80)) {
- XAspecial[0] = c;
- XAcount = 1;
- return;
- }
- #else
- /*
- * if special ctrl char, quote it
- */
- if (!fepMode && !recFlag && mode != M_OS && ((c0 > 0x80) || c0 == QUOTE_CHAR || c0 == DEL_KEY)) {
- putBuf(QUOTE_CHAR, 1);
- if(c0 == DEL_KEY)
- c = DELK_THRU_MTTK;
- c0 = c &= 0x7f;
- }
- #endif /* PC98XA */
- if (w->KB_COUNT > 16) {
- click();
- return;
- }
- w->KB_COUNT++;
- FP_SEG(p) = 0;
- FP_OFF(p) = w->KB_TAIL;
- #ifdef PC98XA
- /*
- * XA's code is XXYY where XX is scan code and YY is shift state.
- */
- #else
- /*
- * generate scan code
- * upper 8 bit is scan code, lower 8 bit is incode
- */
- if (((c & 0xff00) == 0) && (c0 != ESC))
- c |= ((short)(ASCIItoSCAN[c0]) << 8);
- #endif /* PC98XA */
- /*
- * OK put it on buffer
- */
- *p++ = c;
- if (p >= &(w->KB_BUF[16]))
- p = w->KB_BUF;
- w->KB_TAIL = FP_OFF(p);
- }
-
- #ifndef TSR
- int checkKey()
- /*
- * return non 0 if some key is pressed
- */
- {
- /* check keycode buffer */
- rg.h.ah = 1; /* sense only */
- int86(KEY_BIOS, &rg, &rg);
- if (rg.h.bh)
- return(1);
-
- /* check non lock type ctrl key */
- rg.h.ah = 2;
- int86(KEY_BIOS, &rg, &rg); /* ksens1 */
- if (S_SHIFT(rg.h.al) || S_CTRL(rg.h.al) || meta)
- return(1);
- return(0);
- }
-
- #ifdef SETUP
- void editNormalKeys()
- {
- #ifndef PC98XA
- editKeyTable(normalKeyName, (u_char (*)[MAX_FUNKEY])noshiftbl, NUM_NORMAL_KEY, 1, NORMAL_KEY_NAME_LEN);
- #endif
- }
-
- void editShiftKeys()
- {
- #ifndef PC98XA
- editKeyTable(shiftKeyName, (u_char (*)[MAX_FUNKEY])shiftbl, NUM_NORMAL_KEY, 1, NORMAL_KEY_NAME_LEN);
- #endif
- }
-
- void editCtrlKeys()
- {
- #ifndef PC98XA
- editKeyTable(normalKeyName, (u_char (*)[MAX_FUNKEY])ctrltbl, NUM_NORMAL_KEY, 1, NORMAL_KEY_NAME_LEN);
- #endif
- }
-
- void editKanaKeys()
- {
- #ifndef PC98XA
- editKeyTable(normalKeyName, (u_char (*)[MAX_FUNKEY])akanatbl, NUM_NORMAL_KEY, 1, NORMAL_KEY_NAME_LEN);
- #endif
- }
-
- void editShKanaKeys()
- {
- #ifndef PC98XA
- editKeyTable(normalKeyName, (u_char (*)[MAX_FUNKEY])ashkanatbl, NUM_NORMAL_KEY, 1, NORMAL_KEY_NAME_LEN);
- #endif
- }
-
- void editPFKey()
- {
- editKeyTable(funkeyName, NORMALFunkey, NUM_FUNKEY, MAX_FUNKEY, FUNKEY_NAME_LEN);
- }
-
- void editSPFKey()
- {
- editKeyTable(funkeyName, SHIFTFunkey, NUM_FUNKEY, MAX_FUNKEY, FUNKEY_NAME_LEN);
- }
-
- void editCursorKey()
- {
- editKeyTable(keypadName, NORMALPad, NUM_PADKEY, MAX_FUNKEY, KEYPAD_NAME_LEN);
- }
-
- void editAppCursorKey()
- {
- editKeyTable(keypadName, APPLPad, NUM_PADKEY, MAX_FUNKEY, KEYPAD_NAME_LEN);
- }
-
- void editAppKeyPad()
- {
- putStatus("IBM-PC only (Use Appl. Cursor Keys)");
- }
-
- void editBinding()
- {
- editKeyTable(bindName, (u_char (*)[MAX_FUNKEY])bindTab, NUM_BIND, 1, BIND_NAME_LEN);
- }
-
- void editKeySwapTable()
- {
- #define NUM_LINE 13
- int i, end = NO;
- char buf[8], *junk;
- u_char oldKey, kc;
-
- for (;;) {
- clearCopyright();
- locate(0, 0);
- conPrint("Current key swapping...");
- for (kc = i = 0; kc < sizeof(keySwapTable); kc++) {
- if (keySwapTable[kc] == kc)
- continue;
- locate((i/NUM_LINE)*(14), i%NUM_LINE+1);
- sprintf(tmpBuf, "$%02x -> $%02x", kc, keySwapTable[kc]);
- conPrint(tmpBuf);
- i++;
- }
- if (i == 0)
- conPrint("none");
- if (end)
- break;
- locate(40, 13);
- conPrint("Caution! Effects immediately");
- locate(40, 14);
- conPrint("Enter swappee key code");
- locate(40,15);
- conPrint("ESC for end");
- buf[0] = '\0';
- if (emacs("From Key code: $", buf, 6, E_NO_HELP) == ERR || buf[0] == '\0') {
- end = YES;
- continue;
- }
- if ((oldKey = (u_char)strtol(buf, &junk, 16)) > sizeof(keySwapTable))
- continue;
- sprintf(tmpBuf, "$%02x -> $", oldKey);
- buf[0] = '\0';
- if (emacs(tmpBuf, buf, 6, E_NO_HELP) == ERR || buf[0] == '\0')
- continue;
- keySwapTable[oldKey] = (u_char)strtol(buf, &junk, 16);
- }
- }
-
- void saveKey(fd)
- int fd;
- /*
- * save key pad string, cursor key string, pf key string
- */
- {
- write(fd, (char *)NORMALFunkey, sizeof(NORMALFunkey));
- write(fd, (char *)SHIFTFunkey, sizeof(SHIFTFunkey));
- write(fd, (char *)NORMALPad, sizeof(NORMALPad));
- write(fd, (char *)APPLPad, sizeof(APPLPad));
- write(fd, (char *)keySwapTable, sizeof(keySwapTable));
- write(fd, (char *)anoshiftbl, sizeof(anoshiftbl));
- write(fd, (char *)actrltbl, sizeof(actrltbl));
- write(fd, (char *)ashiftbl, sizeof(ashiftbl));
- write(fd, (char *)akanatbl, sizeof(akanatbl));
- write(fd, (char *)pnoshiftbl, sizeof(pnoshiftbl));
- write(fd, (char *)pctrltbl, sizeof(pctrltbl));
- write(fd, (char *)pshiftbl, sizeof(pshiftbl));
- write(fd, (char *)pctrltbl, sizeof(pctrltbl));
- write(fd, (char *)bindTab, sizeof(bindTab));
- }
- #endif /* SETUP */
-
- void loadKey(fd)
- int fd;
- /*
- * load key pad string, cursor key string, pf key string
- */
- {
- read(fd, (char *)NORMALFunkey, sizeof(NORMALFunkey));
- read(fd, (char *)SHIFTFunkey, sizeof(SHIFTFunkey));
- read(fd, (char *)NORMALPad, sizeof(NORMALPad));
- read(fd, (char *)APPLPad, sizeof(APPLPad));
- read(fd, (char *)keySwapTable, sizeof(keySwapTable));
- read(fd, (char *)anoshiftbl, sizeof(anoshiftbl));
- read(fd, (char *)actrltbl, sizeof(actrltbl));
- read(fd, (char *)ashiftbl, sizeof(ashiftbl));
- read(fd, (char *)akanatbl, sizeof(akanatbl));
- read(fd, (char *)pnoshiftbl, sizeof(pnoshiftbl));
- read(fd, (char *)pctrltbl, sizeof(pctrltbl));
- read(fd, (char *)pshiftbl, sizeof(pshiftbl));
- read(fd, (char *)pctrltbl, sizeof(pctrltbl));
- read(fd, (char *)bindTab, sizeof(bindTab));
- }
- #endif /* TSR */
-
- #ifdef MOUSE
-
- /*
- *
- * mouse related functions
- *
- */
- int mouseExists;
- int mouseOn;
- int mouseX, mouseY, mouseOriginX, mouseOriginY;
- int mouseLowX, mouseHighX, mouseLowY, mouseHighY;
- void (FAR *mouseHandler)();
- #define INT_MOUSE 0x33
-
- void mouseInit()
- /*
- * initialize mouse
- */
- {
- rg.x.ax = 0;
- int86(INT_MOUSE, &rg, &rg); /* check mouse environment */
- if (rg.x.ax == 0)
- return; /* no mouse */
- /* set horizontal mouse space */
- rg.x.ax = 0x10;
- rg.x.cx = 0;
- rg.x.dx = 639;
- int86(INT_MOUSE, &rg, &rg);
- /* set vertical mouse space */
- rg.x.ax = 0x11;
- rg.x.cx = 0;
- rg.x.dx = 399;
- int86(INT_MOUSE, &rg, &rg);
- /* get current position */
- rg.x.ax = 3;
- int86(INT_MOUSE, &rg, &rg);
- mouseOriginX = mouseX = rg.x.cx;
- mouseOriginY = mouseY = rg.x.dx;
- mouseLowX = mouseOriginX - 100; mouseHighX = mouseOriginX + 100;
- mouseLowY = mouseOriginY - 80; mouseHighY = mouseOriginY + 80;
- mouseSetHandler(YES);
- }
-
- void mouseEnd()
- {
- mouseSetHandler(NO); /* remove handler */
- }
-
- void mouseSetHandler(onOff)
- int onOff;
- {
- struct SREGS segRegs;
-
- mouseHandler = getMouseIntAddress();
- segread(&segRegs);
- rg.x.ax = 0x0c;
- /*
- * if onOff = YES, set move, left/right press handler
- * else mask all event
- */
- rg.x.cx = onOff ? 0x0b : 0;
- segRegs.es = FP_SEG(mouseHandler);
- rg.x.dx = FP_OFF(mouseHandler);
- int86x(INT_MOUSE, &rg, &rg, &segRegs); /* set interrupt handler */
- }
-
- void mouseOnOff(onOff)
- int onOff;
- {
- rg.x.ax = onOff ? 1 : 2;
- int86(INT_MOUSE, &rg, &rg);
- }
-
- void mouseSetPosition(x, y)
- int x, y;
- {
- rg.x.ax = 4;
- rg.x.cx = x;
- rg.x.dx = y;
- int86(INT_MOUSE, &rg, &rg);
- }
-
- void FAR mouseEvent(event, x, y)
- /*
- * mouse event interrupt handler
- */
- int event, x, y;
- {
- u_short c = 0;
- int dx = x - mouseX;
- int dy = y - mouseY;
- int thresh = (mouseSpeed + 1) * MOUSE_SPEED_BASE;
-
- spl7();
- switch (event) {
- case 1: /* cursor is moved. */
- if (mode != M_COMM) {
- if (mode == M_SETUP)
- thresh *= 2; /* for selecting menu */
- if (dy > thresh)
- c = DOWN_KEY >> 8;
- else if (dy < -thresh)
- c = UP_KEY >> 8;
- if (c) {
- putBuf(c, 0);
- mouseY = y;
- c = 0;
- }
- if (dx > thresh)
- c = RIGHT_KEY >> 8;
- else if (dx < -thresh)
- c = LEFT_KEY >> 8;
- if (c)
- mouseX = x;
- }
- if (x < mouseLowX || x > mouseHighX || y < mouseLowY || y > mouseHighY) {
- /* recenter mouse position */
- mouseSetPosition(mouseOriginX, mouseOriginY);
- mouseX = mouseOriginX;
- mouseY = mouseOriginY;
- }
- break;
- case 2: /* left botton is pressed. */
- if (mode == M_HISTORY)
- c = INS_KEY >> 8;
- else if (mode == M_SETUP)
- c = CR;
- else /* communication mode */
- c = PF_HIST_EDIT >> 8; /* call history editor */
- break;
- case 8: /* right botton is pressed. */
- if (mode == M_HISTORY)
- c = CR;
- else if (mode == M_SETUP)
- c = ESC;
- else /* communication mode */
- c = SETUP_KEY >> 8; /* call set-up */
- break;
- }
- /*
- * put emulated key into BIOS key buffer
- */
- if (c)
- putBuf(c, 0);
- /*
- * THIS may be bug!
- */
- splx();
- }
- #else
- void FAR mouseEvent(int event, int x, int y) {}
- void mouseOnOff(int onOff) {}
- void mouseSetPosition(int x, int y) {}
- void mouseEnd() {}
- void mouseInit() {}
- #endif /* MOUSE */
-