Diff for /np2/io/serial.c between versions 1.2 and 1.25

version 1.2, 2003/10/21 11:22:05 version 1.25, 2011/01/15 18:04:43
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_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);
         }          }
 }          else {
                   keybrd.mode = 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 keybrdi41[2] = {
                                           keyboard_i41,   keyboard_i43};
   
 static const IOINP keybi41[2] = {  
                                         keyb_i41,       keyb_i43};  
   
   void keyboard_reset(const NP2CFG *pConfig) {
   
 void keyboard_reset(void) {          ZeroMemory(&keybrd, sizeof(keybrd));
           keybrd.data = 0xff;
           keybrd.mode = 0x5e;
   
         ZeroMemory(&keyb, sizeof(keyb));          (void)pConfig;
         keyb.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) {
   
           nevent_reset(NEVENT_KEYBOARD);
           keybrd.cmd = 0;
           keybrd.status = 0;
           keybrd.ctrls = 0;
           keybrd.buffers = 0;
           keystat_ctrlreset();
           keystat_resendstat();
   }
   
   void keyboard_ctrl(REG8 data) {
   
           if ((data == 0xfa) || (data == 0xfc)) {
                   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);
                   }
           }
   }
   
         int             i;  void keyboard_send(REG8 data) {
   
         keyboard_reset();          if (keybrd.buffers < KB_BUF) {
         for (i=0; i<0x80; i++) {                  keybrd.buf[(keybrd.bufpos + keybrd.buffers) & KB_BUFMASK] = data;
                 if (keystat[i]) {                  keybrd.buffers++;
                         keyb_out((BYTE)i);                  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 284  void rs232c_open(void) { Line 168  void rs232c_open(void) {
   
 void rs232c_callback(void) {  void rs232c_callback(void) {
   
         BOOL    interrupt;          BOOL    intr;
   
         interrupt = FALSE;          intr = FALSE;
         if ((cm_rs232c) && (cm_rs232c->read(cm_rs232c, &rs232c.data))) {          if ((cm_rs232c) && (cm_rs232c->read(cm_rs232c, &rs232c.data))) {
                 rs232c.result |= 2;                  rs232c.result |= 2;
                 if (sysport.c & 1) {                  if (sysport.c & 1) {
                         interrupt = TRUE;                          intr = TRUE;
                 }                  }
         }          }
         else {          else {
                 rs232c.result &= (BYTE)~2;                  rs232c.result &= (UINT8)~2;
         }          }
         if (sysport.c & 4) {          if (sysport.c & 4) {
                 if (rs232c.send) {                  if (rs232c.send) {
                         rs232c.send = 0;                          rs232c.send = 0;
                         interrupt = TRUE;                          intr = TRUE;
                 }                  }
         }          }
         if (interrupt) {          if (intr) {
                 pic_setirq(4);                  pic_setirq(4);
         }          }
 }  }
   
 BYTE rs232c_stat(void) {  UINT8 rs232c_stat(void) {
   
         if (cm_rs232c == NULL) {          if (cm_rs232c == NULL) {
                 cm_rs232c = commng_create(COMCREATE_SERIAL);                  cm_rs232c = commng_create(COMCREATE_SERIAL);
Line 325  void rs232c_midipanic(void) { Line 209  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 340  static void IOOUTCALL rs232c_o30(UINT po Line 224  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 392  static void IOOUTCALL rs232c_o32(UINT po Line 276  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);
Line 424  static const IOOUT rs232co30[2] = { Line 310  static const IOOUT rs232co30[2] = {
 static const IOINP rs232ci30[2] = {  static const IOINP rs232ci30[2] = {
                                         rs232c_i30,     rs232c_i32};                                          rs232c_i30,     rs232c_i32};
   
 void rs232c_reset(void) {  void rs232c_reset(const NP2CFG *pConfig) {
   
         commng_destroy(cm_rs232c);          commng_destroy(cm_rs232c);
         cm_rs232c = NULL;          cm_rs232c = NULL;
Line 434  void rs232c_reset(void) { Line 320  void rs232c_reset(void) {
         rs232c.pos = 0;          rs232c.pos = 0;
         rs232c.dummyinst = 0;          rs232c.dummyinst = 0;
         rs232c.mul = 10 * 16;          rs232c.mul = 10 * 16;
   
           (void)pConfig;
 }  }
   
 void rs232c_bind(void) {  void rs232c_bind(void) {

Removed from v.1.2  
changed lines
  Added in v.1.25


RetroPC.NET-CVS <cvs@retropc.net>