--- np2/keystat.c 2004/02/18 03:24:48 1.1 +++ np2/keystat.c 2004/02/18 18:29:29 1.2 @@ -2,59 +2,29 @@ #include "pccore.h" #include "iocore.h" #include "keystat.h" +#include "keystat.tbl" -static UINT8 keystat[0x80]; - +typedef struct { + UINT8 refer[0x80]; + UINT8 joysync; + UINT8 joylast; + UINT8 mouselast; + UINT8 padding; + UINT8 d_up; + UINT8 d_dn; + UINT8 d_lt; + UINT8 d_rt; +} KEYSTAT; -static const UINT8 joykeytable[12] = { - 0x2a, 0x34, - 0x29, 0x1c, - 0x3c, 0x48, - 0x3b, 0x46, - 0x3d, 0x4b, - 0x3a, 0x43}; - -static const UINT8 kbexflag[0x80] = { - // ESC, £±, £², £³, £´, £µ, £¶, £· ; 00h - 0, 0, 0, 0, 0, 0, 0, 0, - // £¸, £¹, £°, ¡Ý, ¡°, ¡ï, BS, TAB ; 08h - 0, 0, 0, 0, 0, 0, 0, 0, - // £Ñ, £×, £Å, £Ò, £Ô, £Ù, £Õ, £É ; 10h - 0, 0, 0, 0, 0, 0, 0, 0, - // £Ï, £Ð, ¡÷, ¡Î, Ret, £Á, £Ó, £Ä ; 18h - 0, 0, 0, 0, 1, 0, 0, 0, - // £Æ, £Ç, £È, £Ê, £Ë, £Ì, ¡¨, ¡§ ; 20h - 0, 0, 0, 0, 0, 0, 0, 0, - // ¡Ï, £Ú, £Ø, £Ã, £Ö, £Â, £Î, £Í ; 28h - 0, 1, 1, 0, 0, 0, 0, 0, - // ¡¤, ¡¥, ¡¿, ¡², SPC,XFER,RLUP,RLDN ; 30h - 0, 0, 0, 0, 1, 0, 0, 0, - // INS, DEL, ¢¬, ¢«, ¢ª, ¢­,HMCR,HELP ; 38h - 2, 0, 1, 1, 1, 1, 0, 0, - // <¡Ý>,<¡¿>,<£·>,<£¸>,<£¹>,<¡ö>,<£´>,<£µ> ; 40h - 0, 0, 0, 1, 0, 0, 1, 0, - // <£¶>,<¡Ü>,<£±>,<£²>,<£³>,<¡á>,<£°>,<¡¤> ; 48h - 1, 0, 0, 1, 0, 0, 0, 0, - // <¡¥>,NFER,vf.1,vf.2,vf.3,vf.4,vf.5, ; 50h - 0, 0, 2, 2, 2, 2, 2, 0, - // , , , , , ,HOME, ; 58h - 0, 0, 0, 0, 0, 0, 0, 0, - // STOP,COPY, f.1, f.2, f.3, f.4, f.5, f.6 ; 60h - 0, 0, 2, 2, 2, 2, 2, 2, - // f.7, f.8, f.9, f10, , , , ; 68h - 2, 2, 2, 2, 0, 0, 0, 0, - // SFT,CAPS,KANA,GRPH,CTRL, , , ; 70h - 2, 2, 2, 2, 2, 0, 0, 0, - // , , , , , , , ; 78h - 0, 0, 0, 0, 0, 0, 0, 0}; +static KEYSTAT keystat; // ---- void keystat_reset(void) { - ZeroMemory(keystat, sizeof(keystat)); + ZeroMemory(keystat.refer, sizeof(keystat.refer)); } void keystat_senddata(REG8 data) { @@ -72,15 +42,15 @@ const _NKEYM *user; if (data & 0x80) { return; } - data = key | (keystat[key] & 0x80); - keystat[key] ^= 0x80; + data = key | (keystat.refer[key] & 0x80); + keystat.refer[key] ^= 0x80; } else if ((key == 0x76) || (key == 0x77)) { // user key user = np2cfg.userkey + (key - 0x76); for (i=0; ikeys; i++) { key = user->key[i] & 0x7f; - if (!((keystat[key] ^ data) & 0x80)) { - keystat[key] ^= 0x80; + if (!((keystat.refer[key] ^ data) & 0x80)) { + keystat.refer[key] ^= 0x80; keyboard_send((REG8)(key | (data & 0x80))); } } @@ -94,8 +64,8 @@ const _NKEYM *user; if (data & 0x80) { return; } - data = key | (keystat[key] & 0x80); - keystat[key] ^= 0x80; + data = key | (keystat.refer[key] & 0x80); + keystat.refer[key] ^= 0x80; } else { // CTRL:¥«¥Ê 0x79,0x7a bit7¤ò¤½¤Î¤Þ¤ÞÄÌÃÎ @@ -104,8 +74,8 @@ const _NKEYM *user; key -= 0x08; data -= 0x08; } - if (!((keystat[key] ^ data) & 0x80)) { - keystat[key] ^= 0x80; + if (!((keystat.refer[key] ^ data) & 0x80)) { + keystat.refer[key] ^= 0x80; } else { keynochange = TRUE; @@ -134,8 +104,8 @@ const _NKEYM *user; key = value & 0x7f; if ((key != 0x76) && (key != 0x77)) { - if (keystat[key] & 0x80) { - keystat[key] &= ~0x80; + if (keystat.refer[key] & 0x80) { + keystat.refer[key] &= ~0x80; keyboard_send((REG8)(key | 0x80)); } } @@ -143,33 +113,21 @@ const _NKEYM *user; user = np2cfg.userkey + (key - 0x76); for (i=0; ikeys; i++) { key = user->key[i] & 0x7f; - if (keystat[key] & 0x80) { - keystat[key] &= ~0x80; + if (keystat.refer[key] & 0x80) { + keystat.refer[key] &= ~0x80; keyboard_send((REG8)(key | 0x80)); } } } } -void keystat_resetcopyhelp(void) { - - REG8 i; - - for (i=0x60; i<0x62; i++) { - if (keystat[i] & 0x80) { - keystat[i] &= 0x7f; - keyboard_send((REG8)(i | 0x80)); - } - } -} - void keystat_allrelease(void) { REG8 i; for (i=0; i<0x80; i++) { - if (keystat[i] & 0x80) { - keystat[i] &= ~0x80; + if (keystat.refer[i] & 0x80) { + keystat.refer[i] &= ~0x80; keyboard_send((REG8)(i | 0x80)); } } @@ -182,8 +140,8 @@ void keystat_resetjoykey(void) { for (i=0; i<12; i++) { key = joykeytable[i]; - if (keystat[key] & 0x80) { - keystat[key] &= 0x7f; + if (keystat.refer[key] & 0x80) { + keystat.refer[key] &= 0x7f; keyboard_send((REG8)(key | 0x80)); } } @@ -194,7 +152,7 @@ void keystat_resendstat(void) { int i; for (i=0; i<0x80; i++) { - if (keystat[i]) { + if (keystat.refer[i]) { keyboard_send((REG8)i); } } @@ -203,105 +161,90 @@ void keystat_resendstat(void) { // ---- -typedef struct { - UINT8 joysync; - UINT8 joylast; - UINT8 mouselast; - UINT8 padding; - UINT8 d_up; - UINT8 d_dn; - UINT8 d_lt; - UINT8 d_rt; -} KEYEXT; - -static KEYEXT keyext; -static const UINT8 mousedelta[] = {1, 1, 1, 1, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 4}; -#define MOUSESTEPMAX ((sizeof(mousedelta) / sizeof(UINT8)) - 1) - void keystat_sync(void) { - keyext.joysync = 0; + keystat.joysync = 0; } REG8 keystat_getjoy(void) { - BYTE flg; + UINT8 flg; const BYTE *p; - BYTE bit; + UINT8 bit; - if (!keyext.joysync) { - keyext.joysync = 1; + if (!keystat.joysync) { + keystat.joysync = 1; flg = 0xff; p = joykeytable; for (bit=0x20; bit; bit>>=1) { - if ((keystat[p[0]] & 0x80) || (keystat[p[1]] & 0x80)) { + if ((keystat.refer[p[0]] & 0x80) || + (keystat.refer[p[1]] & 0x80)) { flg ^= bit; } p += 2; } - keyext.joylast = flg; + keystat.joylast = flg; } - return(keyext.joylast); + return(keystat.joylast); } REG8 keystat_getmouse(SINT16 *x, SINT16 *y) { REG8 btn; - BYTE acc; + UINT8 acc; SINT16 tmp; - BYTE ret; + REG8 ret; btn = keystat_getjoy(); - acc = btn | keyext.mouselast; - keyext.mouselast = (UINT8)btn; + acc = btn | keystat.mouselast; + keystat.mouselast = (UINT8)btn; tmp = 0; if (!(btn & 1)) { - tmp -= mousedelta[keyext.d_up]; + tmp -= mousedelta[keystat.d_up]; } if (!(acc & 1)) { - if (keyext.d_up < MOUSESTEPMAX) { - keyext.d_up++; + if (keystat.d_up < MOUSESTEPMAX) { + keystat.d_up++; } } else { - keyext.d_up = 0; + keystat.d_up = 0; } if (!(btn & 2)) { - tmp += mousedelta[keyext.d_dn]; + tmp += mousedelta[keystat.d_dn]; } if (!(acc & 2)) { - if (keyext.d_dn < MOUSESTEPMAX) { - keyext.d_dn++; + if (keystat.d_dn < MOUSESTEPMAX) { + keystat.d_dn++; } } else { - keyext.d_dn = 0; + keystat.d_dn = 0; } *y += tmp; tmp = 0; if (!(btn & 4)) { - tmp -= mousedelta[keyext.d_lt]; + tmp -= mousedelta[keystat.d_lt]; } if (!(acc & 4)) { - if (keyext.d_lt < MOUSESTEPMAX) { - keyext.d_lt++; + if (keystat.d_lt < MOUSESTEPMAX) { + keystat.d_lt++; } } else { - keyext.d_lt = 0; + keystat.d_lt = 0; } if (!(btn & 8)) { - tmp += mousedelta[keyext.d_rt]; + tmp += mousedelta[keystat.d_rt]; } if (!(acc & 8)) { - if (keyext.d_rt < MOUSESTEPMAX) { - keyext.d_rt++; + if (keystat.d_rt < MOUSESTEPMAX) { + keystat.d_rt++; } } else { - keyext.d_rt = 0; + keystat.d_rt = 0; } *x += tmp;