--- np2/keystat.c 2004/03/28 10:50:16 1.6 +++ np2/keystat.c 2005/02/07 14:46:07 1.17 @@ -5,10 +5,11 @@ #include "iocore.h" #include "keystat.h" #include "keystat.tbl" +#include "softkbd.h" typedef struct { - UINT8 ref[NKEY_SYSTEM]; + UINT8 ref[0x80]; UINT8 extkey; UINT8 mouselast; UINT8 padding; @@ -18,8 +19,8 @@ typedef struct { UINT8 d_rt; } KEYSTAT; - NKEYTBL nkeytbl; + KEYCTRL keyctrl; static KEYSTAT keystat; @@ -27,6 +28,11 @@ void keystat_initialize(void) { char path[MAX_PATH]; + ZeroMemory(&keyctrl, sizeof(keyctrl)); + keyctrl.keyrep = 0x21; + keyctrl.capsref = NKEYREF_NC; + keyctrl.kanaref = NKEYREF_NC; + ZeroMemory(&keystat, sizeof(keystat)); FillMemory(keystat.ref, sizeof(keystat.ref), NKEYREF_NC); keystat_tblreset(); @@ -82,7 +88,7 @@ const KEYNAME *n; const KEYNAME *nterm; n = keyname; - nterm = keyname + (sizeof(keyname) / sizeof(KEYNAME)); + nterm = keyname + NELEMENTS(keyname); while(n < nterm) { if (!milstr_cmp(n->str, str)) { return(n->num); @@ -156,6 +162,104 @@ kstbl_err: // ---- +static REG8 getledstat(void) { + + REG8 ret; + + ret = 0; + if (keyctrl.kanaref != NKEYREF_NC) { + ret |= 8; + } + if (keyctrl.capsref != NKEYREF_NC) { + ret |= 4; + } + return(ret); +} + +static void reloadled(void) { + + keyctrl.kanaref = keystat.ref[0x72]; + keyctrl.capsref = keystat.ref[0x71]; +#if defined(SUPPORT_SOFTKBD) + softkbd_led(getledstat()); +#endif +} + +void keystat_ctrlreset(void) { + + keyctrl.reqparam = 0; + keystat.ref[0x72] = keyctrl.kanaref; + keystat.ref[0x71] = keyctrl.capsref; +#if defined(SUPPORT_SOFTKBD) + softkbd_led(getledstat()); +#endif +} + +void keystat_ctrlsend(REG8 dat) { + + if (!keyctrl.reqparam) { + keyctrl.mode = dat; + switch(dat) { +#if defined(SUPPORT_PC9801_119) + case 0x95: +#endif + case 0x9c: + case 0x9d: + keyctrl.reqparam = 1; + keyboard_ctrl(0xfa); + break; + +#if defined(SUPPORT_PC9801_119) + case 0x96: + keyboard_ctrl(0xfa); + keyboard_ctrl(0xa0); + keyboard_ctrl(0x83); + break; +#endif + + case 0x9f: + keyboard_ctrl(0xfa); + keyboard_ctrl(0xa0); + keyboard_ctrl(0x80); + break; + + default: + keyboard_ctrl(0xfc); + break; + } + } + else { + switch(keyctrl.mode) { +#if defined(SUPPORT_PC9801_119) + case 0x95: + keyctrl.kbdtype = dat; + keyboard_ctrl(0xfa); + break; +#endif + case 0x9c: + keyboard_ctrl(0xfa); + break; + + case 0x9d: + if (dat == 0x60) { + keyboard_ctrl(0xfa); + keyboard_ctrl((REG8)(0x70 + getledstat())); + } + else if ((dat & 0xf0) == 0x70) { + keyboard_ctrl(0xfa); + keystat.ref[0x72] = (dat & 8)?NKEYREF_uPD8255:NKEYREF_NC; + keystat.ref[0x71] = (dat & 4)?NKEYREF_uPD8255:NKEYREF_NC; + reloadled(); + } + break; + } + keyctrl.reqparam = 0; + } +} + + +// ---- + void keystat_down(const UINT8 *key, REG8 keys, REG8 ref) { UINT8 keydata; @@ -166,13 +270,36 @@ void keystat_down(const UINT8 *key, REG8 keydata = *key++; keycode = (keydata & 0x7f); if (keycode < 0x70) { +#if 1 // 05/02/04 + if (keystat.ref[keycode] != NKEYREF_NC) { + if (!(kbexflag[keycode] & KBEX_NONREP)) { + keyboard_send((REG8)(keycode + 0x80)); + keystat.ref[keycode] = NKEYREF_NC; + } + } + if (keystat.ref[keycode] == NKEYREF_NC) { + keyboard_send(keycode); + } +#else if ((keystat.ref[keycode] == NKEYREF_NC) || (!(kbexflag[keycode] & KBEX_NONREP))) { keyboard_send(keycode); } +#endif keystat.ref[keycode] = ref; } else { +#if defined(SUPPORT_PC9801_119) + if (keyctrl.kbdtype != 0x03) +#endif + { + if (keycode == 0x7d) { + keycode = 0x70; + } + else if (keycode >= 0x75) { + continue; + } + } if ((np2cfg.XSHIFT) && (((keycode == 0x70) && (np2cfg.XSHIFT & 1)) || ((keycode == 0x74) && (np2cfg.XSHIFT & 2)) || @@ -180,26 +307,24 @@ void keystat_down(const UINT8 *key, REG8 keydata |= 0x80; } if (!(keydata & 0x80)) { // シフト - if ((keystat.ref[keycode + 0x00] == NKEYREF_NC) && - (keystat.ref[keycode + 0x10] == NKEYREF_NC)) { - keyboard_send(keycode); - } - if (keystat.ref[keycode] > ref) { + if (keystat.ref[keycode] == NKEYREF_NC) { keystat.ref[keycode] = ref; + keyboard_send(keycode); } } else { // シフトメカニカル処理 - if (keystat.ref[keycode + 0x10] == NKEYREF_NC) { - keystat.ref[keycode + 0x10] = ref; + if (keystat.ref[keycode] == NKEYREF_NC) { + keystat.ref[keycode] = ref; data = keycode; } else { - keystat.ref[keycode + 0x10] = NKEYREF_NC; + keystat.ref[keycode] = NKEYREF_NC; data = (REG8)(keycode + 0x80); } - if (keystat.ref[keycode] == NKEYREF_NC) { - keyboard_send(data); - } + keyboard_send(data); + } + if ((keycode == 0x71) || (keycode == 0x72)) { + reloadled(); } } } @@ -220,6 +345,17 @@ void keystat_up(const UINT8 *key, REG8 k } } else { +#if defined(SUPPORT_PC9801_119) + if (keyctrl.kbdtype != 0x03) +#endif + { + if (keycode == 0x7d) { + keycode = 0x70; + } + else if (keycode >= 0x75) { + continue; + } + } if ((np2cfg.XSHIFT) && (((keycode == 0x70) && (np2cfg.XSHIFT & 1)) || ((keycode == 0x74) && (np2cfg.XSHIFT & 2)) || @@ -227,10 +363,11 @@ void keystat_up(const UINT8 *key, REG8 k keydata |= 0x80; } if (!(keydata & 0x80)) { // シフト - if (keystat.ref[keycode] == ref) { + if (keystat.ref[keycode] != NKEYREF_NC) { keystat.ref[keycode] = NKEYREF_NC; - if (keystat.ref[keycode + 0x10] == NKEYREF_NC) { - keyboard_send((REG8)(keycode + 0x80)); + keyboard_send((REG8)(keycode + 0x80)); + if ((keycode == 0x71) || (keycode == 0x72)) { + reloadled(); } } } @@ -242,17 +379,11 @@ void keystat_resendstat(void) { REG8 i; - for (i=0; i<0x70; i++) { + for (i=0; i<0x80; i++) { if (keystat.ref[i] != NKEYREF_NC) { keyboard_send(i); } } - for (i=0; i<0x10; i++) { - if ((keystat.ref[0x70 + i] != NKEYREF_NC) || - (keystat.ref[0x80 + i] != NKEYREF_NC)) { - keyboard_send((REG8)(i + 0x70)); - } - } } @@ -306,26 +437,12 @@ void keystat_releaseref(REG8 ref) { REG8 i; - for (i=0; i<0x70; i++) { + for (i=0; i<0x80; i++) { if (keystat.ref[i] == ref) { keystat.ref[i] = NKEYREF_NC; keyboard_send((REG8)(i + 0x80)); } } - for (i=0; i<0x10; i++) { - if (keystat.ref[0x70 + i] == ref) { - keystat.ref[0x70 + i] = NKEYREF_NC; - if (keystat.ref[0x80 + i] == NKEYREF_NC) { - keyboard_send((REG8)(0xf0 + i)); - } - } - if (keystat.ref[0x80 + i] == ref) { - keystat.ref[0x80 + i] = NKEYREF_NC; - if (keystat.ref[0x70 + i] == NKEYREF_NC) { - keyboard_send((REG8)(0xf0 + i)); - } - } - } } void keystat_resetjoykey(void) { @@ -344,20 +461,12 @@ void keystat_resetjoykey(void) { void keystat_releasekey(REG8 key) { key &= 0x7f; - if (key < 0x70) { + if ((key != 0x71) && (key != 0x72)) { if (keystat.ref[key] != NKEYREF_NC) { keystat.ref[key] = NKEYREF_NC; keyboard_send((REG8)(key + 0x80)); } } - else { - if ((keystat.ref[key + 0x00] != NKEYREF_NC) || - (keystat.ref[key + 0x10] != NKEYREF_NC)) { - keystat.ref[key + 0x00] = NKEYREF_NC; - keystat.ref[key + 0x10] = NKEYREF_NC; - keyboard_send((REG8)(key + 0x80)); - } - } } void keystat_allrelease(void) {