| version 1.6, 2003/12/08 00:55:32 | version 1.15, 2005/05/20 13:59:47 | 
| Line 3 | Line 3 | 
 | #include        "cpucore.h" | #include        "cpucore.h" | 
 | #include        "pccore.h" | #include        "pccore.h" | 
 | #include        "iocore.h" | #include        "iocore.h" | 
 |  | #include        "keystat.h" | 
 |  |  | 
 |  |  | 
 | // マウス ver0.28 | // マウス ver0.28 | 
| Line 19  void mouseif_sync(void) { | Line 20  void mouseif_sync(void) { | 
 | // 今回の移動量を取得 | // 今回の移動量を取得 | 
 | mouseif.b = mousemng_getstat(&mouseif.sx, &mouseif.sy, 1); | mouseif.b = mousemng_getstat(&mouseif.sx, &mouseif.sy, 1); | 
 | if (np2cfg.KEY_MODE == 3) { | if (np2cfg.KEY_MODE == 3) { | 
| mouseif.b &= keyext_getmouse(&mouseif.sx, &mouseif.sy); | mouseif.b &= keystat_getmouse(&mouseif.sx, &mouseif.sy); | 
 | } | } | 
 | mouseif.rx = mouseif.sx; | mouseif.rx = mouseif.sx; | 
 | mouseif.ry = mouseif.sy; | mouseif.ry = mouseif.sy; | 
| Line 41  static void calc_mousexy(void) { | Line 42  static void calc_mousexy(void) { | 
 | diff /= 1000; | diff /= 1000; | 
 | dx = mouseif.sx; | dx = mouseif.sx; | 
 | if (dx > 0) { | if (dx > 0) { | 
| dx = dx * diff / pc.frame1000; | dx = dx * diff / mouseif.moveclock; | 
 | if (dx > mouseif.rx) { | if (dx > mouseif.rx) { | 
 | dx = mouseif.rx; | dx = mouseif.rx; | 
 | } | } | 
 | } | } | 
 | else if (dx < 0) { | else if (dx < 0) { | 
 | dx *= -1; | dx *= -1; | 
| dx = dx * diff / pc.frame1000; | dx = dx * diff / mouseif.moveclock; | 
 | dx *= -1; | dx *= -1; | 
 | if (dx < mouseif.rx) { | if (dx < mouseif.rx) { | 
 | dx = mouseif.rx; | dx = mouseif.rx; | 
| Line 59  static void calc_mousexy(void) { | Line 60  static void calc_mousexy(void) { | 
 |  |  | 
 | dy = mouseif.sy; | dy = mouseif.sy; | 
 | if (dy > 0) { | if (dy > 0) { | 
| dy = dy * diff / pc.frame1000; | dy = dy * diff / mouseif.moveclock; | 
 | if (dy > mouseif.ry) { | if (dy > mouseif.ry) { | 
 | dy = mouseif.ry; | dy = mouseif.ry; | 
 | } | } | 
 | } | } | 
 | else if (dy < 0) { | else if (dy < 0) { | 
 | dy *= -1; | dy *= -1; | 
| dy = dy * diff / pc.frame1000; | dy = dy * diff / mouseif.moveclock; | 
 | dy *= -1; | dy *= -1; | 
 | if (dy < mouseif.ry) { | if (dy < mouseif.ry) { | 
 | dy = mouseif.ry; | dy = mouseif.ry; | 
| Line 81  static void calc_mousexy(void) { | Line 82  static void calc_mousexy(void) { | 
 | void mouseint(NEVENTITEM item) { | void mouseint(NEVENTITEM item) { | 
 |  |  | 
 | if (item->flag & NEVENT_SETEVENT) { | if (item->flag & NEVENT_SETEVENT) { | 
| if (!(mouseif.portc & 0x10)) { | if (!(mouseif.upd8255.portc & 0x10)) { | 
 | pic_setirq(0x0d); | pic_setirq(0x0d); | 
| nevent_set(NEVENT_MOUSE, pc.mouseclock << mouseif.timing, | nevent_set(NEVENT_MOUSE, mouseif.intrclock << mouseif.timing, | 
 | mouseint, NEVENT_RELATIVE); | mouseint, NEVENT_RELATIVE); | 
 | } | } | 
 | } | } | 
| Line 91  void mouseint(NEVENTITEM item) { | Line 92  void mouseint(NEVENTITEM item) { | 
 |  |  | 
 | static void setportc(REG8 value) { | static void setportc(REG8 value) { | 
 |  |  | 
| if ((value & 0x80) && (!(mouseif.portc & 0x80))) { | if ((value & 0x80) && (!(mouseif.upd8255.portc & 0x80))) { | 
 | calc_mousexy(); | calc_mousexy(); | 
 | mouseif.latch_x = mouseif.x; | mouseif.latch_x = mouseif.x; | 
 | mouseif.x = 0; | mouseif.x = 0; | 
| Line 110  static void setportc(REG8 value) { | Line 111  static void setportc(REG8 value) { | 
 | mouseif.latch_y = -128; | mouseif.latch_y = -128; | 
 | } | } | 
 | } | } | 
| if ((value ^ mouseif.portc) & 0x10) { | if ((value ^ mouseif.upd8255.portc) & 0x10) { | 
 | if (!(value & 0x10)) { | if (!(value & 0x10)) { | 
 | if (!nevent_iswork(NEVENT_MOUSE)) { | if (!nevent_iswork(NEVENT_MOUSE)) { | 
| nevent_set(NEVENT_MOUSE, pc.mouseclock << mouseif.timing, | // 割り込みを入れとく | 
|  | pic_setirq(0x0d); | 
|  | nevent_set(NEVENT_MOUSE, mouseif.intrclock << mouseif.timing, | 
 | mouseint, NEVENT_ABSOLUTE); | mouseint, NEVENT_ABSOLUTE); | 
 | } | } | 
 | } | } | 
 | } | } | 
| mouseif.portc = (UINT8)value; | mouseif.upd8255.portc = (UINT8)value; | 
 | } | } | 
 |  |  | 
 |  |  | 
 | // ---- I/O | // ---- I/O | 
 |  |  | 
 |  | static void IOOUTCALL mouseif_o7fd9(UINT port, REG8 dat) { | 
 |  |  | 
 |  | mouseif.upd8255.porta = dat; | 
 |  | (void)port; | 
 |  | } | 
 |  |  | 
 |  | static void IOOUTCALL mouseif_o7fdb(UINT port, REG8 dat) { | 
 |  |  | 
 |  | mouseif.upd8255.portb = dat; | 
 |  | (void)port; | 
 |  | } | 
 |  |  | 
 | static void IOOUTCALL mouseif_o7fdd(UINT port, REG8 dat) { | static void IOOUTCALL mouseif_o7fdd(UINT port, REG8 dat) { | 
 |  |  | 
 | setportc(dat); | setportc(dat); | 
| Line 132  static void IOOUTCALL mouseif_o7fdd(UINT | Line 147  static void IOOUTCALL mouseif_o7fdd(UINT | 
 |  |  | 
 | static void IOOUTCALL mouseif_o7fdf(UINT port, REG8 dat) { | static void IOOUTCALL mouseif_o7fdf(UINT port, REG8 dat) { | 
 |  |  | 
| if (dat & 0xf0) { | REG8    portc; | 
| mouseif.mode = (UINT8)dat; | UINT    sft; | 
| if (dat == 0x93) { |  | 
| setportc(0); | portc = 0; | 
| } | if (dat & uPD8255_CTRL) { | 
|  | mouseif.upd8255.mode = (UINT8)dat; | 
|  | #if 0 | 
|  | pic_resetirq(0x0d); | 
|  | nevent_set(NEVENT_MOUSE, mouseif.intrclock << mouseif.timing, | 
|  | mouseint, NEVENT_ABSOLUTE); | 
|  | #endif | 
 | } | } | 
 | else { | else { | 
| if (dat & 1) { | sft = (dat >> 1) & 7; | 
| setportc((REG8)(mouseif.portc | (1 << (dat >> 1)))); | portc = mouseif.upd8255.portc; | 
| } | portc &= (~(1 << sft)); | 
| else { | portc |= (dat & 1) << sft; | 
| setportc((REG8)(mouseif.portc & (~(1 << (dat >> 1))))); |  | 
| } |  | 
 | } | } | 
 |  | setportc(portc); | 
 | (void)port; | (void)port; | 
 | } | } | 
 |  |  | 
| Line 156  static REG8 IOINPCALL mouseif_i7fd9(UINT | Line 176  static REG8 IOINPCALL mouseif_i7fd9(UINT | 
 | REG8    ret; | REG8    ret; | 
 | REG8    portc; | REG8    portc; | 
 |  |  | 
| calc_mousexy(); | if (mouseif.upd8255.mode & uPD8255_PORTA) { | 
| ret = mouseif.b; | calc_mousexy(); | 
| if (np2cfg.MOUSERAPID) { | ret = mouseif.b; | 
| ret |= mouseif.rapid; | if (np2cfg.MOUSERAPID) { | 
| } | ret |= mouseif.rapid; | 
| ret &= 0xf0; | } | 
| ret |= 0x50; | ret &= 0xf0; | 
| portc = mouseif.portc; | #if 1 | 
| if (portc & 0x80) { | ret |= 0x40;            // for shizuku | 
| x = mouseif.latch_x; | #else | 
| y = mouseif.latch_y; | ret |= 0x50; | 
| } | #endif | 
| else { | portc = mouseif.upd8255.portc; | 
| x = mouseif.x; | if (portc & 0x80) { | 
| y = mouseif.y; | x = mouseif.latch_x; | 
| } | y = mouseif.latch_y; | 
| if (portc & 0x40) { | } | 
| x = y; | else { | 
| } | x = mouseif.x; | 
| if (!(portc & 0x20)) { | y = mouseif.y; | 
| ret |= x & 0x0f; | } | 
|  | if (portc & 0x40) { | 
|  | x = y; | 
|  | } | 
|  | if (!(portc & 0x20)) { | 
|  | ret |= x & 0x0f; | 
|  | } | 
|  | else { | 
|  | ret |= (x >> 4) & 0x0f; | 
|  | } | 
|  | return(ret); | 
 | } | } | 
 | else { | else { | 
| ret |= (x >> 4) & 0x0f; | return(mouseif.upd8255.porta); | 
 | } | } | 
 | //      TRACEOUT(("%x %x mouse [%x] %d -> %x", CPU_CS, CPU_IP, portc & 0x20, y, ret)); |  | 
 | (void)port; | (void)port; | 
 | return(ret); |  | 
 | } | } | 
 |  |  | 
 | static REG8 IOINPCALL mouseif_i7fdb(UINT port) { | static REG8 IOINPCALL mouseif_i7fdb(UINT port) { | 
 |  |  | 
 |  | if (mouseif.upd8255.mode & uPD8255_PORTB) { | 
 |  | return(0x40); | 
 |  | } | 
 |  | else { | 
 |  | return(mouseif.upd8255.portb); | 
 |  | } | 
 | (void)port; | (void)port; | 
 | return(0x40); |  | 
 | } | } | 
 |  |  | 
 | static REG8 IOINPCALL mouseif_i7fdd(UINT port) { | static REG8 IOINPCALL mouseif_i7fdd(UINT port) { | 
 |  |  | 
 | REG8    ret; |  | 
 | REG8    mode; | REG8    mode; | 
 |  | REG8    ret; | 
 |  |  | 
| ret = mouseif.portc; | mode = mouseif.upd8255.mode; | 
| mode = mouseif.mode; | ret = mouseif.upd8255.portc; | 
| if (mode & 8) { | if (mode & uPD8255_PORTCH) { | 
 | ret &= 0x1f; | ret &= 0x1f; | 
 | } | } | 
| if (mode & 1) { | if (mode & uPD8255_PORTCL) { | 
 | ret &= 0xf0; | ret &= 0xf0; | 
 | ret |= 0x08; | ret |= 0x08; | 
 | ret |= (np2cfg.dipsw[2] >> 5) & 0x04; | ret |= (np2cfg.dipsw[2] >> 5) & 0x04; | 
| Line 212  static REG8 IOINPCALL mouseif_i7fdd(UINT | Line 245  static REG8 IOINPCALL mouseif_i7fdd(UINT | 
 | return(ret); | return(ret); | 
 | } | } | 
 |  |  | 
 |  |  | 
 | static void IOOUTCALL mouseif_obfdb(UINT port, REG8 dat) { | static void IOOUTCALL mouseif_obfdb(UINT port, REG8 dat) { | 
 |  |  | 
 | mouseif.timing = dat & 3; | mouseif.timing = dat & 3; | 
| Line 225  static void IOOUTCALL mouseif_obfdb(UINT | Line 257  static void IOOUTCALL mouseif_obfdb(UINT | 
 | void mouseif_reset(void) { | void mouseif_reset(void) { | 
 |  |  | 
 | ZeroMemory(&mouseif, sizeof(mouseif)); | ZeroMemory(&mouseif, sizeof(mouseif)); | 
| mouseif.mode = 0x93; | mouseif.upd8255.porta = 0x00; | 
| mouseif.portc = 0x10;                                                                                   // ver0.28 | mouseif.upd8255.portb = 0x00; | 
|  | mouseif.upd8255.portc = 0xf0;                                                                   // ver0.82 | 
|  | mouseif.upd8255.mode = 0x93; | 
|  | mouseif.intrclock = pccore.realclock / 120; | 
|  | mouseif.moveclock = pccore.realclock / 56400; | 
|  | mouseif.latch_x = -1; | 
|  | mouseif.latch_y = -1; | 
 | } | } | 
 |  |  | 
 | void mouseif_bind(void) { | void mouseif_bind(void) { | 
 |  |  | 
 |  | iocore_attachout(0x7fd9, mouseif_o7fd9); | 
 |  | iocore_attachout(0x7fdb, mouseif_o7fdb); | 
 | iocore_attachout(0x7fdd, mouseif_o7fdd); | iocore_attachout(0x7fdd, mouseif_o7fdd); | 
 | iocore_attachout(0x7fdf, mouseif_o7fdf); | iocore_attachout(0x7fdf, mouseif_o7fdf); | 
 | iocore_attachinp(0x7fd9, mouseif_i7fd9); | iocore_attachinp(0x7fd9, mouseif_i7fd9); |