| version 1.3, 2003/10/23 06:26:16 | version 1.19, 2004/03/31 19:23:37 | 
| Line 1 | Line 1 | 
 | #include        "compiler.h" | #include        "compiler.h" | 
 |  | #include        "cpucore.h" | 
 | #include        "commng.h" | #include        "commng.h" | 
 | #include        "pccore.h" | #include        "pccore.h" | 
 | #include        "iocore.h" | #include        "iocore.h" | 
 |  | #include        "keystat.h" | 
 |  |  | 
 |  |  | 
| static const BYTE joykeytable[12] = { | // ---- Keyboard | 
| 0x2a,   0x34, |  | 
| 0x29,   0x1c, |  | 
| 0x3c,   0x48, |  | 
| 0x3b,   0x46, |  | 
| 0x3d,   0x4b, |  | 
| 0x3a,   0x43}; |  | 
|  |  | 
| static const BYTE 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 void keyb_int(BOOL absolute) { |  | 
|  |  | 
| if (keyb.buffers) { |  | 
| if (!((pic.pi[0].irr | pic.pi[0].isr) & PIC_KEYBOARD)) { |  | 
| keyb.status |= 2; |  | 
| keyb.data = keyb.buf[keyb.pos]; |  | 
| keyb.pos = (keyb.pos + 1) & KB_BUFMASK; |  | 
| keyb.buffers--; |  | 
| pic_setirq(1); |  | 
| } |  | 
| nevent_set(NEVENT_KEYBOARD, pc.keyboardclock, |  | 
| keyb_callback, absolute); |  | 
| } |  | 
| else { |  | 
| keyb.status &= ~2; |  | 
| } |  | 
| } |  | 
 |  |  | 
| void keyb_callback(NEVENTITEM item) { | void keyboard_callback(NEVENTITEM item) { | 
 |  |  | 
 | if (item->flag & NEVENT_SETEVENT) { | if (item->flag & NEVENT_SETEVENT) { | 
| keyb_int(NEVENT_RELATIVE); | if ((keybrd.ctrls) || (keybrd.buffers)) { | 
| } | if (!(keybrd.status & 2)) { | 
| } | keybrd.status |= 2; | 
|  | if (keybrd.ctrls) { | 
| static void keyb_out(BYTE data) { | keybrd.ctrls--; | 
|  | keybrd.data = keybrd.ctr[keybrd.ctrpos]; | 
| if (keyb.buffers < KB_BUF) { | keybrd.ctrpos = (keybrd.ctrpos + 1) & KB_CTRMASK; | 
| keyb.buf[(keyb.pos + keyb.buffers) & KB_BUFMASK] = data; |  | 
| keyb.buffers++; |  | 
| if (!nevent_iswork(NEVENT_KEYBOARD)) { |  | 
| keyb_int(NEVENT_ABSOLUTE); |  | 
| } |  | 
| } |  | 
| else { |  | 
| keyb.status |= 0x10; |  | 
| } |  | 
| } |  | 
|  |  | 
|  |  | 
| // ---- |  | 
|  |  | 
| BYTE    keystat[0x80]; |  | 
|  |  | 
| void keystat_reset(void) { |  | 
|  |  | 
| ZeroMemory(keystat, sizeof(keystat)); |  | 
| } |  | 
|  |  | 
| void keystat_senddata(BYTE data) { |  | 
|  |  | 
| BYTE    key = data & 0x7f; |  | 
| BOOL    keynochange = FALSE; |  | 
|  |  | 
| if ((key == 0x71) || (key == 0x72)) { |  | 
| if (data & 0x80) { |  | 
| return; |  | 
| } |  | 
| data = key | (keystat[key] & 0x80); |  | 
| keystat[key] ^= 0x80; |  | 
| } |  | 
| else { |  | 
| if ((np2cfg.XSHIFT) && |  | 
| (((key == 0x70) && (np2cfg.XSHIFT & 1)) || |  | 
| ((key == 0x74) && (np2cfg.XSHIFT & 2)) || |  | 
| ((key == 0x73) && (np2cfg.XSHIFT & 4)))) { |  | 
| if (data & 0x80) { |  | 
| return; |  | 
| } |  | 
| data = key | (keystat[key] & 0x80); |  | 
| keystat[key] ^= 0x80; |  | 
| } |  | 
| else { |  | 
| if (!((keystat[key] ^ data) & 0x80)) { |  | 
| keystat[key] ^= 0x80; |  | 
| } |  | 
| else { |  | 
| keynochange = TRUE; |  | 
| if (kbexflag[key] & 2) {                        // ¥¡¼¥ê¥Ô¡¼¥È̵¤· |  | 
| return; |  | 
 | } | } | 
 |  | else if (keybrd.buffers) { | 
 |  | keybrd.buffers--; | 
 |  | keybrd.data = keybrd.buf[keybrd.bufpos]; | 
 |  | keybrd.bufpos = (keybrd.bufpos + 1) & KB_BUFMASK; | 
 |  | } | 
 |  | TRACEOUT(("recv -> %02x", keybrd.data)); | 
 | } | } | 
| } | pic_setirq(1); | 
| } | nevent_set(NEVENT_KEYBOARD, keybrd.xferclock, | 
| if ((!np2cfg.KEY_MODE) || (!(kbexflag[key] & 1))) { | keyboard_callback, NEVENT_RELATIVE); | 
| if (keynochange) { |  | 
| if (data & 0x80) {                                              // ver0.30 |  | 
| return; |  | 
| } |  | 
| keyb_out((BYTE)(data ^ 0x80)); |  | 
| } |  | 
| keyb_out(data); |  | 
| } |  | 
| } |  | 
|  |  | 
| void keystat_resetcopyhelp(void) { |  | 
|  |  | 
| BYTE    i; |  | 
|  |  | 
| for (i=0x60; i<0x62; i++) { |  | 
| if (keystat[i] & 0x80) { |  | 
| keystat[i] &= 0x7f; |  | 
| keyb_out((BYTE)(i | 0x80)); |  | 
| } |  | 
| } |  | 
| } |  | 
|  |  | 
| void keystat_allrelease(void) { |  | 
|  |  | 
| UINT    i; |  | 
|  |  | 
| for (i=0; i<0x80; i++) { |  | 
| if (keystat[i] & 0x80) { |  | 
| keystat[i] &= ~0x80; |  | 
| keyb_out((BYTE)(i + 0x80)); |  | 
 | } | } | 
 | } | } | 
 | } | } | 
 |  |  | 
| void keystat_forcerelease(BYTE value) { | static void IOOUTCALL keyboard_o41(UINT port, REG8 dat) { | 
 |  |  | 
| if (keystat[value & 0x7f] & 0x80) { | if (keybrd.cmd & 1) { | 
| keystat[value & 0x7f] &= ~0x80; | TRACEOUT(("send -> %02x", dat)); | 
| keyb_out((BYTE)(value | 0x80)); | keystat_ctrlsend(dat); | 
 | } | } | 
 | } |  | 
 |  |  | 
 | void keystat_resetjoykey(void) { |  | 
 |  |  | 
 | int             i; |  | 
 | BYTE    key; |  | 
 |  |  | 
 | for (i=0; i<12; i++) { |  | 
 | key = joykeytable[i]; |  | 
 | if (keystat[key] & 0x80) { |  | 
 | keystat[key] &= 0x7f; |  | 
 | keyb_out((BYTE)(key | 0x80)); |  | 
 | } |  | 
 | } |  | 
 | } |  | 
 |  |  | 
 | BYTE keystat_getjoy(void) { |  | 
 |  |  | 
 | BYTE    ret = 0xff; |  | 
 | BYTE    *p = (BYTE *)joykeytable; |  | 
 | BYTE    bit; |  | 
 |  |  | 
 | for (bit=0x20; bit; bit>>=1, p+=2) { |  | 
 | if ((keystat[*p] & 0x80) || (keystat[*(p+1)] & 0x80)) { |  | 
 | ret &= ~bit; |  | 
 | } |  | 
 | } |  | 
 | return(ret); |  | 
 | } |  | 
 |  |  | 
 |  |  | 
 | // ---- |  | 
 |  |  | 
 | static void IOOUTCALL keyb_o41(UINT port, BYTE dat) { |  | 
 |  |  | 
 | keyb.mode = dat; |  | 
 | (void)port; | (void)port; | 
 | } | } | 
 |  |  | 
| static void IOOUTCALL keyb_o43(UINT port, BYTE dat) { | static void IOOUTCALL keyboard_o43(UINT port, REG8 dat) { | 
 |  |  | 
| if ((!(dat & 0x08)) && (keyb.cmd & 0x08)) { | TRACEOUT(("out43 -> %02x %.4x:%.8x", dat, CPU_CS, CPU_EIP)); | 
|  | if ((!(dat & 0x08)) && (keybrd.cmd & 0x08)) { | 
 | keyboard_resetsignal(); | keyboard_resetsignal(); | 
 | } | } | 
 | if (dat & 0x10) { | if (dat & 0x10) { | 
| keyb.status &= ~(0x38); | keybrd.status &= ~(0x38); | 
 | } | } | 
| keyb.cmd = dat; | keybrd.cmd = dat; | 
 | (void)port; | (void)port; | 
 | } | } | 
 |  |  | 
| static BYTE IOINPCALL keyb_i41(UINT port) { | static REG8 IOINPCALL keyboard_i41(UINT port) { | 
 |  |  | 
 | (void)port; | (void)port; | 
| return(keyb.data); | keybrd.status &= ~2; | 
|  | pic_resetirq(1); | 
|  | TRACEOUT(("in41 -> %02x %.4x:%.8x", keybrd.data, CPU_CS, CPU_EIP)); | 
|  | return(keybrd.data); | 
 | } | } | 
 |  |  | 
| static BYTE IOINPCALL keyb_i43(UINT port) { | static REG8 IOINPCALL keyboard_i43(UINT port) { | 
 |  |  | 
 | (void)port; | (void)port; | 
| return(keyb.status); | TRACEOUT(("in43 -> %02x %.4x:%.8x", keybrd.status, CPU_CS, CPU_EIP)); | 
|  | return(keybrd.status | 0x85); | 
 | } | } | 
 |  |  | 
 |  |  | 
 | // ---- | // ---- | 
 |  |  | 
| static const IOOUT keybo41[2] = { | static const IOOUT keybrdo41[2] = { | 
| keyb_o41,       keyb_o43}; | keyboard_o41,   keyboard_o43}; | 
 |  |  | 
| static const IOINP keybi41[2] = { | static const IOINP keybrdi41[2] = { | 
| keyb_i41,       keyb_i43}; | keyboard_i41,   keyboard_i43}; | 
 |  |  | 
 |  |  | 
 | void keyboard_reset(void) { | void keyboard_reset(void) { | 
 |  |  | 
| ZeroMemory(&keyb, sizeof(keyb)); | ZeroMemory(&keybrd, sizeof(keybrd)); | 
| keyb.data = 0xff; | keybrd.data = 0xff; | 
| keyb.mode = 0x5e; |  | 
 | } | } | 
 |  |  | 
 | void keyboard_bind(void) { | void keyboard_bind(void) { | 
 |  |  | 
| iocore_attachsysoutex(0x0041, 0x0cf1, keybo41, 2); | keystat_ctrlreset(); | 
| iocore_attachsysinpex(0x0041, 0x0cf1, keybi41, 2); | keybrd.xferclock = pccore.realclock / 1920; | 
|  | iocore_attachsysoutex(0x0041, 0x0cf1, keybrdo41, 2); | 
|  | iocore_attachsysinpex(0x0041, 0x0cf1, keybrdi41, 2); | 
 | } | } | 
 |  |  | 
| void keyboard_resetsignal(void) {                                                                       // ver0.29 | void keyboard_resetsignal(void) { | 
 |  |  | 
| int             i; | nevent_reset(NEVENT_KEYBOARD); | 
|  | keybrd.cmd = 0; | 
|  | keybrd.status = 0; | 
|  | keybrd.ctrls = 0; | 
|  | keybrd.buffers = 0; | 
|  | keystat_ctrlreset(); | 
|  | keystat_resendstat(); | 
|  | } | 
 |  |  | 
| keyboard_reset(); | void keyboard_ctrl(REG8 data) { | 
| for (i=0; i<0x80; i++) { |  | 
| if (keystat[i]) { | if ((data == 0xfa) || (data == 0xfc)) { | 
| keyb_out((BYTE)i); | keybrd.ctrls = 0; | 
|  | } | 
|  | if (keybrd.ctrls < KB_CTR) { | 
|  | keybrd.ctr[(keybrd.ctrpos + keybrd.ctrls) & KB_CTRMASK] = data; | 
|  | keybrd.ctrls++; | 
|  | if (!nevent_iswork(NEVENT_KEYBOARD)) { | 
|  | nevent_set(NEVENT_KEYBOARD, keybrd.xferclock, | 
|  | keyboard_callback, NEVENT_ABSOLUTE); | 
 | } | } | 
 | } | } | 
 | } | } | 
 |  |  | 
 |  | void keyboard_send(REG8 data) { | 
 |  |  | 
 |  | if (keybrd.buffers < KB_BUF) { | 
 |  | keybrd.buf[(keybrd.bufpos + keybrd.buffers) & KB_BUFMASK] = data; | 
 |  | keybrd.buffers++; | 
 |  | if (!nevent_iswork(NEVENT_KEYBOARD)) { | 
 |  | nevent_set(NEVENT_KEYBOARD, keybrd.xferclock, | 
 |  | keyboard_callback, NEVENT_ABSOLUTE); | 
 |  | } | 
 |  | } | 
 |  | else { | 
 |  | keybrd.status |= 0x10; | 
 |  | } | 
 |  | } | 
 |  |  | 
 |  |  | 
 | // ----------------------------------------------------------------------- |  | 
 |  |  | 
 |  | // ---- RS-232C | 
 |  |  | 
 | COMMNG  cm_rs232c; | COMMNG  cm_rs232c; | 
 |  |  | 
| Line 337  void rs232c_midipanic(void) { | Line 203  void rs232c_midipanic(void) { | 
 |  |  | 
 | // ---- | // ---- | 
 |  |  | 
| static void IOOUTCALL rs232c_o30(UINT port, BYTE dat) { | static void IOOUTCALL rs232c_o30(UINT port, REG8 dat) { | 
 |  |  | 
 | if (cm_rs232c) { | if (cm_rs232c) { | 
| cm_rs232c->write(cm_rs232c, dat); | cm_rs232c->write(cm_rs232c, (UINT8)dat); | 
 | } | } | 
 | if (sysport.c & 4) { | if (sysport.c & 4) { | 
 | rs232c.send = 0; | rs232c.send = 0; | 
| Line 352  static void IOOUTCALL rs232c_o30(UINT po | Line 218  static void IOOUTCALL rs232c_o30(UINT po | 
 | (void)port; | (void)port; | 
 | } | } | 
 |  |  | 
| static void IOOUTCALL rs232c_o32(UINT port, BYTE dat) { | static void IOOUTCALL rs232c_o32(UINT port, REG8 dat) { | 
 |  |  | 
 | if (!(dat & 0xfd)) { | if (!(dat & 0xfd)) { | 
 | rs232c.dummyinst++; | rs232c.dummyinst++; | 
| Line 404  static void IOOUTCALL rs232c_o32(UINT po | Line 270  static void IOOUTCALL rs232c_o32(UINT po | 
 | break; | break; | 
 |  |  | 
 | case 0x02:                      // cmd | case 0x02:                      // cmd | 
 |  | sysport.c &= ~7; | 
 |  | sysport.c |= (dat & 7); | 
 | rs232c.pos++; | rs232c.pos++; | 
 | break; | break; | 
 | } | } | 
 | (void)port; | (void)port; | 
 | } | } | 
 |  |  | 
| static BYTE IOINPCALL rs232c_i30(UINT port) { | static REG8 IOINPCALL rs232c_i30(UINT port) { | 
 |  |  | 
 | (void)port; | (void)port; | 
 | return(rs232c.data); | return(rs232c.data); | 
 | } | } | 
 |  |  | 
| static BYTE IOINPCALL rs232c_i32(UINT port) { | static REG8 IOINPCALL rs232c_i32(UINT port) { | 
 |  |  | 
 | if (!(rs232c_stat() & 0x20)) { | if (!(rs232c_stat() & 0x20)) { | 
 | return(rs232c.result | 0x80); | return(rs232c.result | 0x80); |