|
|
| version 1.3, 2004/02/19 03:04:01 | version 1.4, 2004/02/19 11:32:11 |
|---|---|
| Line 1 | Line 1 |
| #include "compiler.h" | #include "compiler.h" |
| #include "textfile.h" | |
| #include "pccore.h" | #include "pccore.h" |
| #include "iocore.h" | #include "iocore.h" |
| #include "keystat.h" | #include "keystat.h" |
| Line 6 | Line 7 |
| typedef struct { | typedef struct { |
| UINT8 refer[0x80]; | UINT8 ref[0x80]; |
| UINT8 joysync; | UINT8 extkey; |
| UINT8 joylast; | |
| UINT8 mouselast; | UINT8 mouselast; |
| UINT8 padding; | UINT8 padding; |
| UINT8 d_up; | UINT8 d_up; |
| Line 17 typedef struct { | Line 17 typedef struct { |
| UINT8 d_rt; | UINT8 d_rt; |
| } KEYSTAT; | } KEYSTAT; |
| NKEYTBL nkeytbl; | |
| static KEYSTAT keystat; | static KEYSTAT keystat; |
| // ---- | void keystat_initialize(void) { |
| ZeroMemory(&keystat, sizeof(keystat)); | |
| FillMemory(keystat.ref, sizeof(keystat.ref), NKEYREF_NC); | |
| keystat_tblreset(); | |
| } | |
| void keystat_reset(void) { | void keystat_tblreset(void) { |
| ZeroMemory(keystat.refer, sizeof(keystat.refer)); | UINT i; |
| ZeroMemory(&nkeytbl, sizeof(nkeytbl)); | |
| for (i=0; i<0x80; i++) { | |
| nkeytbl.key[i].keys = 1; | |
| nkeytbl.key[i].key[0] = (UINT8)i; | |
| } | |
| } | } |
| void keystat_senddata(REG8 data) { | |
| REG8 key; | // ---- config... |
| BOOL keynochange; | |
| const _NKEYM *user; | static REG8 searchkeynum(const char *str) { |
| UINT i; | |
| const KEYNAME *n; | |
| key = data & 0x7f; | const KEYNAME *nterm; |
| keynochange = FALSE; | |
| n = keyname; | |
| // CTRL:カナ 0x71,0x72 bit7==0でトグル処理 (標準処理) | nterm = keyname + (sizeof(keyname) / sizeof(KEYNAME)); |
| if ((key == 0x71) || (key == 0x72)) { | while(n < nterm) { |
| if (data & 0x80) { | if (!milstr_cmp(n->str, str)) { |
| return; | return(n->num); |
| } | } |
| data = key | (keystat.refer[key] & 0x80); | n++; |
| keystat.refer[key] ^= 0x80; | |
| } | } |
| else if ((key == 0x76) || (key == 0x77)) { // user key | return(0xff); |
| user = np2cfg.userkey + (key - 0x76); | } |
| for (i=0; i<user->keys; i++) { | |
| key = user->key[i] & 0x7f; | void keystat_tblload(const char *filename) { |
| if (!((keystat.refer[key] ^ data) & 0x80)) { | |
| keystat.refer[key] ^= 0x80; | TEXTFILEH tfh; |
| keyboard_send((REG8)(key | (data & 0x80))); | char work[128]; |
| char *p; | |
| char *q; | |
| char *r; | |
| REG8 key; | |
| tfh = textfile_open(filename, 0x800); | |
| if (tfh == NULL) { | |
| goto kstbl_err; | |
| } | |
| while(textfile_read(tfh, work, sizeof(work)) == SUCCESS) { | |
| p = milstr_nextword(work); | |
| q = milstr_chr(p, '\t'); | |
| if (q == NULL) { | |
| q = milstr_chr(p, '='); | |
| } | |
| if (q == NULL) { | |
| continue; | |
| } | |
| *q++ = '\0'; | |
| r = (char *)milstr_chr(p, ' '); | |
| if (r != NULL) { | |
| *r = '\0'; | |
| } | |
| key = searchkeynum(p); | |
| while(q) { | |
| p = milstr_nextword(q); | |
| q = milstr_chr(p, ' '); | |
| if (q != NULL) { | |
| *q++ = '\0'; | |
| } | } |
| key = searchkeynum(p); | |
| } | } |
| return; | |
| } | } |
| else { | textfile_close(tfh); |
| if ((np2cfg.XSHIFT) && | |
| (((key == 0x70) && (np2cfg.XSHIFT & 1)) || | kstbl_err: |
| ((key == 0x74) && (np2cfg.XSHIFT & 2)) || | return; |
| ((key == 0x73) && (np2cfg.XSHIFT & 4)))) { | } |
| if (data & 0x80) { | |
| return; | |
| // ---- | |
| void keystat_down(const UINT8 *key, REG8 keys, REG8 ref) { | |
| UINT8 keycode; | |
| UINT8 shift; | |
| REG8 data; | |
| while(keys--) { | |
| keycode = *key++; | |
| keycode = (keycode & 0x7f); | |
| if (keycode < 0x70) { | |
| if ((keystat.ref[keycode] == NKEYREF_NC) || | |
| (!(kbexflag[keycode] & KBEX_NONREP))) { | |
| keyboard_send(keycode); | |
| } | } |
| data = key | (keystat.refer[key] & 0x80); | keystat.ref[keycode] = ref; |
| keystat.refer[key] ^= 0x80; | |
| } | } |
| else { | else { |
| // CTRL:カナ 0x79,0x7a bit7をそのまま通知 | if ((np2cfg.XSHIFT) && |
| // (ハードウェアでメカニカル処理してる場合) | (((keycode == 0x70) && (np2cfg.XSHIFT & 1)) || |
| if ((key == 0x79) || (key == 0x7a)) { | ((keycode == 0x74) && (np2cfg.XSHIFT & 2)) || |
| key -= 0x08; | ((keycode == 0x73) && (np2cfg.XSHIFT & 4)))) { |
| data -= 0x08; | keycode |= 8; |
| } | } |
| if (!((keystat.refer[key] ^ data) & 0x80)) { | shift = keycode & 0x07; |
| keystat.refer[key] ^= 0x80; | if (!(keycode & 8)) { // シフト |
| if ((keystat.ref[0x70 + shift] == NKEYREF_NC) && | |
| (keystat.ref[0x78 + shift] == NKEYREF_NC)) { | |
| keyboard_send((REG8)(0x70 + shift)); | |
| } | |
| if (keystat.ref[0x70 + shift] > ref) { | |
| keystat.ref[0x70 + shift] = ref; | |
| } | |
| } | } |
| else { | else { // シフトメカニカル処理 |
| keynochange = TRUE; | if (keystat.ref[0x78 + shift] == NKEYREF_NC) { |
| if (kbexflag[key] & 2) { // キーリピート無し | keystat.ref[0x78 + shift] = ref; |
| return; | data = (REG8)(0x70 + shift); |
| } | |
| else { | |
| keystat.ref[0x78 + shift] = NKEYREF_NC; | |
| data = (REG8)(0xf0 + shift); | |
| } | |
| if (keystat.ref[0x70 + shift] == NKEYREF_NC) { | |
| keyboard_send(data); | |
| } | } |
| } | } |
| } | } |
| } | } |
| if ((!np2cfg.KEY_MODE) || (!(kbexflag[key] & 1))) { | } |
| if (keynochange) { | |
| if (data & 0x80) { | void keystat_up(const UINT8 *key, REG8 keys, REG8 ref) { |
| return; | |
| UINT8 keycode; | |
| UINT8 shift; | |
| while(keys--) { | |
| keycode = *key++; | |
| keycode = (keycode & 0x7f); | |
| if (keycode < 0x70) { | |
| if (keystat.ref[keycode] == ref) { | |
| keystat.ref[keycode] = NKEYREF_NC; | |
| keyboard_send((REG8)(keycode + 0x80)); | |
| } | |
| } | |
| else { | |
| if ((np2cfg.XSHIFT) && | |
| (((keycode == 0x70) && (np2cfg.XSHIFT & 1)) || | |
| ((keycode == 0x74) && (np2cfg.XSHIFT & 2)) || | |
| ((keycode == 0x73) && (np2cfg.XSHIFT & 4)))) { | |
| keycode |= 8; | |
| } | |
| shift = keycode & 0x07; | |
| if (!(keycode & 8)) { // シフト | |
| if (keystat.ref[0x70 + shift] == ref) { | |
| keystat.ref[0x70 + shift] = NKEYREF_NC; | |
| if (keystat.ref[0x78 + shift] == NKEYREF_NC) { | |
| keyboard_send((REG8)(shift + 0xf0)); | |
| } | |
| } | |
| } | } |
| keyboard_send((REG8)(data ^ 0x80)); | |
| } | } |
| keyboard_send(data); | |
| } | } |
| } | } |
| void keystat_forcerelease(REG8 value) { | void keystat_resendstat(void) { |
| REG8 key; | REG8 i; |
| const _NKEYM *user; | |
| UINT i; | |
| key = value & 0x7f; | for (i=0; i<0x70; i++) { |
| if ((key != 0x76) && (key != 0x77)) { | if (keystat.ref[i] != NKEYREF_NC) { |
| if (keystat.refer[key] & 0x80) { | keyboard_send(i); |
| keystat.refer[key] &= ~0x80; | |
| keyboard_send((REG8)(key | 0x80)); | |
| } | } |
| } | } |
| for (i=0; i<8; i++) { | |
| if ((keystat.ref[0x70 + i] != NKEYREF_NC) || | |
| (keystat.ref[0x78 + i] != NKEYREF_NC)) { | |
| keyboard_send((REG8)(i + 0x70)); | |
| } | |
| } | |
| } | |
| // ---- | |
| void keystat_keydown(REG8 ref) { | |
| UINT8 keycode; | |
| UINT8 shift; | |
| const NKEYM3 *nkey3; | |
| const NKEYM15 *nkey15; | |
| keycode = ref & 0x7f; | |
| if (np2cfg.KEY_MODE) { | |
| shift = kbexflag[keycode]; | |
| if (shift & KBEX_JOYKEY) { | |
| keystat.extkey |= (1 << (shift & 7)); | |
| return; | |
| } | |
| } | |
| if ((keycode != NKEY_USER1) && (keycode != NKEY_USER2)) { | |
| nkey3 = nkeytbl.key + keycode; | |
| keystat_down(nkey3->key, nkey3->keys, keycode); | |
| } | |
| else { | else { |
| user = np2cfg.userkey + (key - 0x76); | #if 0 |
| for (i=0; i<user->keys; i++) { | nkey15 = nkeytbl.user + (keycode - NKEY_USER1); |
| key = user->key[i] & 0x7f; | #else |
| if (keystat.refer[key] & 0x80) { | nkey15 = (NKEYM15 *)(np2cfg.userkey + (keycode - NKEY_USER1)); |
| keystat.refer[key] &= ~0x80; | #endif |
| keyboard_send((REG8)(key | 0x80)); | keystat_down(nkey15->key, nkey15->keys, NKEYREF_USER); |
| } | } |
| } | |
| void keystat_keyup(REG8 ref) { | |
| UINT8 keycode; | |
| UINT8 shift; | |
| const NKEYM3 *nkey3; | |
| const NKEYM15 *nkey15; | |
| keycode = ref & 0x7f; | |
| if (np2cfg.KEY_MODE) { | |
| shift = kbexflag[keycode]; | |
| if (shift & KBEX_JOYKEY) { | |
| keystat.extkey &= ~(1 << (shift & 7)); | |
| return; | |
| } | } |
| } | } |
| if ((keycode != NKEY_USER1) && (keycode != NKEY_USER2)) { | |
| nkey3 = nkeytbl.key + keycode; | |
| keystat_up(nkey3->key, nkey3->keys, keycode); | |
| } | |
| else { | |
| #if 0 | |
| nkey15 = nkeytbl.user + (keycode - NKEY_USER1); | |
| #else | |
| nkey15 = (NKEYM15 *)(np2cfg.userkey + (keycode - NKEY_USER1)); | |
| #endif | |
| keystat_up(nkey15->key, nkey15->keys, NKEYREF_USER); | |
| } | |
| } | } |
| void keystat_allrelease(void) { | void keystat_releaseref(REG8 ref) { |
| REG8 i; | REG8 i; |
| for (i=0; i<0x80; i++) { | for (i=0; i<0x70; i++) { |
| if (keystat.refer[i] & 0x80) { | if (keystat.ref[i] == ref) { |
| keystat.refer[i] &= ~0x80; | keystat.ref[i] = NKEYREF_NC; |
| keyboard_send((REG8)(i | 0x80)); | 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[0x78 ^ i] == NKEYREF_NC) { | |
| keyboard_send((REG8)((i & 7) + 0xe0)); | |
| } | |
| } | } |
| } | } |
| } | } |
| void keystat_resetjoykey(void) { | void keystat_resetjoykey(void) { |
| int i; | REG8 i; |
| REG8 key; | |
| for (i=0; i<12; i++) { | keystat.extkey = 0; |
| key = joykeytable[i]; | for (i=0; i<0x80; i++) { |
| if (keystat.refer[key] & 0x80) { | if (kbexflag[i] & KBEX_JOYKEY) { |
| keystat.refer[key] &= 0x7f; | keystat_releaseref(i); |
| keyboard_send((REG8)(key | 0x80)); | |
| } | } |
| } | } |
| } | } |
| void keystat_resendstat(void) { | |
| int i; | void keystat_releasekey(REG8 key) { |
| for (i=0; i<0x80; i++) { | key &= 0x7f; |
| if (keystat.refer[i]) { | if (key < 0x70) { |
| keyboard_send((REG8)i); | if (keystat.ref[key] != NKEYREF_NC) { |
| keystat.ref[key] = NKEYREF_NC; | |
| keyboard_send((REG8)(key + 0x80)); | |
| } | |
| } | |
| else { | |
| key &= 0x07; | |
| if ((keystat.ref[0x70 + key] != NKEYREF_NC) || | |
| (keystat.ref[0x78 + key] != NKEYREF_NC)) { | |
| keystat.ref[0x70 + key] = NKEYREF_NC; | |
| keystat.ref[0x78 + key] = NKEYREF_NC; | |
| keyboard_send((REG8)(key + 0xf0)); | |
| } | } |
| } | } |
| } | } |
| void keystat_allrelease(void) { | |
| // ---- | REG8 i; |
| void keystat_sync(void) { | |
| keystat.joysync = 0; | for (i=0; i<0x78; i++) { |
| keystat_releasekey(i); | |
| } | |
| } | } |
| REG8 keystat_getjoy(void) { | REG8 keystat_getjoy(void) { |
| UINT8 flg; | return(~keystat.extkey); |
| const BYTE *p; | |
| UINT8 bit; | |
| if (!keystat.joysync) { | |
| keystat.joysync = 1; | |
| flg = 0xff; | |
| p = joykeytable; | |
| for (bit=0x20; bit; bit>>=1) { | |
| if ((keystat.refer[p[0]] & 0x80) || | |
| (keystat.refer[p[1]] & 0x80)) { | |
| flg ^= bit; | |
| } | |
| p += 2; | |
| } | |
| keystat.joylast = flg; | |
| } | |
| return(keystat.joylast); | |
| } | } |
| REG8 keystat_getmouse(SINT16 *x, SINT16 *y) { | REG8 keystat_getmouse(SINT16 *x, SINT16 *y) { |
| Line 195 REG8 keystat_getmouse(SINT16 *x, SINT16 | Line 344 REG8 keystat_getmouse(SINT16 *x, SINT16 |
| SINT16 tmp; | SINT16 tmp; |
| REG8 ret; | REG8 ret; |
| btn = keystat_getjoy(); | btn = ~keystat.extkey; |
| acc = btn | keystat.mouselast; | acc = btn | keystat.mouselast; |
| keystat.mouselast = (UINT8)btn; | keystat.mouselast = (UINT8)btn; |
| tmp = 0; | tmp = 0; |
| Line 254 REG8 keystat_getmouse(SINT16 *x, SINT16 | Line 403 REG8 keystat_getmouse(SINT16 *x, SINT16 |
| return(ret); | return(ret); |
| } | } |
| // ---- | |
| void keystat_senddata(REG8 data) { | |
| UINT8 keycode; | |
| keycode = data & 0x7f; | |
| if ((keycode == 0x71) || (keycode == 0x72) || | |
| (keycode == 0x79) || (keycode == 0x7a)) { | |
| keycode ^= 8; | |
| } | |
| if (!(data & 0x80)) { | |
| keystat_keydown(keycode); | |
| } | |
| else { | |
| keystat_keyup(keycode); | |
| } | |
| } | |