| version 1.12, 2003/12/13 19:59:41 | version 1.18, 2004/03/10 23:01:08 | 
| Line 3 | Line 3 | 
 | // | // | 
 |  |  | 
 | #include        "compiler.h" | #include        "compiler.h" | 
 |  | #include        "cpucore.h" | 
 | #include        "pccore.h" | #include        "pccore.h" | 
 | #include        "iocore.h" | #include        "iocore.h" | 
 | #include        "sound.h" | #include        "sound.h" | 
 | #include        "beep.h" | #include        "beep.h" | 
 |  |  | 
 |  |  | 
 | // #define      uPD71054                                        // NP2はuPD8253Cベース |  | 
 | #define BEEPCOUNTEREX                                   // BEEPアイドル時のカウンタをα倍に | #define BEEPCOUNTEREX                                   // BEEPアイドル時のカウンタをα倍に | 
 |  |  | 
 |  |  | 
 | // --- Interval timer | // --- Interval timer | 
 |  |  | 
 | // ver0.31 常に回す… |  | 
 | static void setsystimerevent_noint(BOOL absolute) { |  | 
 |  |  | 
 | nevent_set(NEVENT_ITIMER, pc.multiple << 16, systimer_noint, absolute); |  | 
 | } |  | 
 |  |  | 
 | void systimer_noint(NEVENTITEM item) { |  | 
 |  |  | 
 | if (item->flag & NEVENT_SETEVENT) { |  | 
 | setsystimerevent_noint(NEVENT_RELATIVE); |  | 
 | } |  | 
 | } |  | 
 |  |  | 
 | static void setsystimerevent(BOOL absolute) { | static void setsystimerevent(BOOL absolute) { | 
 |  |  | 
 | SINT32  cnt; | SINT32  cnt; | 
 |  |  | 
 | cnt = pit.value[0]; | cnt = pit.value[0]; | 
 | if (cnt > 8) {                                                                  // 根拠なし | if (cnt > 8) {                                                                  // 根拠なし | 
| cnt *= pc.multiple; | cnt *= pccore.multiple; | 
 | } | } | 
 | else { | else { | 
| cnt = pc.multiple << 16; | cnt = pccore.multiple << 16; | 
 | } | } | 
 | nevent_set(NEVENT_ITIMER, cnt, systimer, absolute); | nevent_set(NEVENT_ITIMER, cnt, systimer, absolute); | 
 | } | } | 
| Line 55  void systimer(NEVENTITEM item) { | Line 42  void systimer(NEVENTITEM item) { | 
 | setsystimerevent(NEVENT_RELATIVE); | setsystimerevent(NEVENT_RELATIVE); | 
 | } | } | 
 | else { | else { | 
| nevent_set(NEVENT_ITIMER, pc.multiple << 16, | nevent_set(NEVENT_ITIMER, pccore.multiple << 16, | 
 | systimer, NEVENT_RELATIVE); | systimer, NEVENT_RELATIVE); | 
 | } | } | 
 | } | } | 
| Line 71  static void setbeepeventex(BOOL absolute | Line 58  static void setbeepeventex(BOOL absolute | 
 |  |  | 
 | cnt = pit.value[1]; | cnt = pit.value[1]; | 
 | if (cnt > 2) { | if (cnt > 2) { | 
| cnt *= pc.multiple; | cnt *= pccore.multiple; | 
 | } | } | 
 | else { | else { | 
| cnt = pc.multiple << 16; | cnt = pccore.multiple << 16; | 
 | } | } | 
 | while(cnt < 0x100000) { | while(cnt < 0x100000) { | 
 | cnt <<= 1; | cnt <<= 1; | 
| Line 89  static void setbeepevent(BOOL absolute) | Line 76  static void setbeepevent(BOOL absolute) | 
 |  |  | 
 | cnt = pit.value[1]; | cnt = pit.value[1]; | 
 | if (cnt > 2) { | if (cnt > 2) { | 
| cnt *= pc.multiple; | cnt *= pccore.multiple; | 
 | } | } | 
 | else { | else { | 
| cnt = pc.multiple << 16; | cnt = pccore.multiple << 16; | 
 | } | } | 
 | nevent_set(NEVENT_BEEP, cnt, beeponeshot, absolute); | nevent_set(NEVENT_BEEP, cnt, beeponeshot, absolute); | 
 | } | } | 
| Line 103  void beeponeshot(NEVENTITEM item) { | Line 90  void beeponeshot(NEVENTITEM item) { | 
 | if (!(pit.mode[1] & 0x0c)) {                                                            // ver0.30 | if (!(pit.mode[1] & 0x0c)) {                                                            // ver0.30 | 
 | beep_lheventset(0); | beep_lheventset(0); | 
 | } | } | 
| #ifdef uPD71054 | #if defined(uPD71054) | 
 | if ((pit.mode[1] & 0x06) == 0x02) | if ((pit.mode[1] & 0x06) == 0x02) | 
 | #else | #else | 
 | if (pit.mode[1] & 0x02) | if (pit.mode[1] & 0x02) | 
| Line 126  static void setrs232cevent(BOOL absolute | Line 113  static void setrs232cevent(BOOL absolute | 
 | SINT32  cnt; | SINT32  cnt; | 
 |  |  | 
 | if (pit.value[2] > 1) { | if (pit.value[2] > 1) { | 
| cnt = pc.multiple * pit.value[2] * rs232c.mul; | cnt = pccore.multiple * pit.value[2] * rs232c.mul; | 
 | } | } | 
 | else { | else { | 
| cnt = (pc.multiple << 16) * rs232c.mul; | cnt = (pccore.multiple << 16) * rs232c.mul; | 
 | } | } | 
 | nevent_set(NEVENT_RS232C, cnt, rs232ctimer, absolute); | nevent_set(NEVENT_RS232C, cnt, rs232ctimer, absolute); | 
 | } | } | 
| Line 154  static UINT pit_latch(int ch) { | Line 141  static UINT pit_latch(int ch) { | 
 |  |  | 
 | if (ch == 1) { | if (ch == 1) { | 
 | switch(pit.mode[1] & 0x06) { | switch(pit.mode[1] & 0x06) { | 
 |  | #ifdef uPD71054                         // ? | 
 | case 0x00: | case 0x00: | 
 |  | #endif | 
 | case 0x04: | case 0x04: | 
 | return(pit.value[1]); | return(pit.value[1]); | 
 | #ifdef uPD71054 | #ifdef uPD71054 | 
| Line 167  static UINT pit_latch(int ch) { | Line 156  static UINT pit_latch(int ch) { | 
 | if (clock < 0) { | if (clock < 0) { | 
 | return(0); | return(0); | 
 | } | } | 
| clock /= pc.multiple; | clock /= pccore.multiple; | 
 | if (pit.value[1] > 2) { | if (pit.value[1] > 2) { | 
 | clock %= pit.value[1]; | clock %= pit.value[1]; | 
 | } | } | 
 | else { | else { | 
| clock >>= 16; | clock = LOW16(clock); | 
 | } | } | 
 | return(clock); | return(clock); | 
 | #endif | #endif | 
 | } | } | 
 | clock = nevent_getremain(NEVENT_ITIMER + ch); | clock = nevent_getremain(NEVENT_ITIMER + ch); | 
 | if (clock >= 0) { | if (clock >= 0) { | 
| return(clock / pc.multiple); | return(clock / pccore.multiple); | 
 | } | } | 
 | return(0); | return(0); | 
 | } | } | 
| Line 313  static void IOOUTCALL pit_o77(UINT port, | Line 302  static void IOOUTCALL pit_o77(UINT port, | 
 | beep_modeset(); | beep_modeset(); | 
 | } | } | 
 | } | } | 
 |  | #if defined(uPD71054) | 
 |  | else { | 
 |  | TRACEOUT(("multiple latch commands - %x", dat)); | 
 |  | for (ch=0; ch<3; ch++) { | 
 |  | if (dat & (2 << ch)) { | 
 |  | if (!(dat & 0x10)) { | 
 |  | } | 
 |  | if (!(dat & 0x20)) { | 
 |  | } | 
 |  | } | 
 |  | } | 
 |  | } | 
 |  | #endif | 
 | (void)port; | (void)port; | 
 | } | } | 
 |  |  | 
 | static REG8 IOINPCALL pit_i71(UINT port) { | static REG8 IOINPCALL pit_i71(UINT port) { | 
 |  |  | 
| return(pit_getcount((port >> 1) & 3)); | int             ch; | 
|  |  | 
|  | ch = (port >> 1) & 3; | 
|  | #if defined(uPD71054) | 
|  | if (pit.stat[ch]) { | 
|  | REG8 ret; | 
|  | ret = pit.stat[ch]; | 
|  | pit.stat[ch] = 0; | 
|  | TRACEOUT(("stat out -> %d-%x", ch, ret)); | 
|  | return(ret); | 
|  | } | 
|  | #endif | 
|  | return(pit_getcount(ch)); | 
 | } | } | 
 |  |  | 
 |  |  | 
| Line 333  static const IOINP piti71[4] = { | Line 347  static const IOINP piti71[4] = { | 
 | void itimer_reset(void) { | void itimer_reset(void) { | 
 |  |  | 
 | ZeroMemory(&pit, sizeof(pit)); | ZeroMemory(&pit, sizeof(pit)); | 
| if (pc.cpumode & CPUMODE_8MHz) { | if (pccore.cpumode & CPUMODE_8MHZ) { | 
 | pit.value[1] = 998;                             // 4MHz | pit.value[1] = 998;                             // 4MHz | 
 | } | } | 
 | else { | else { | 
| Line 352  void itimer_bind(void) { | Line 366  void itimer_bind(void) { | 
 |  |  | 
 | iocore_attachsysoutex(0x0071, 0x0cf1, pito71, 4); | iocore_attachsysoutex(0x0071, 0x0cf1, pito71, 4); | 
 | iocore_attachsysinpex(0x0071, 0x0cf1, piti71, 4); | iocore_attachsysinpex(0x0071, 0x0cf1, piti71, 4); | 
 |  | iocore_attachout(0x3fd9, pit_o71); | 
 | iocore_attachout(0x3fdb, pit_o73); | iocore_attachout(0x3fdb, pit_o73); | 
 |  | iocore_attachout(0x3fdd, pit_o75); | 
 | iocore_attachout(0x3fdf, pit_o77); | iocore_attachout(0x3fdf, pit_o77); | 
 |  | iocore_attachinp(0x3fd9, pit_i71); | 
 | iocore_attachinp(0x3fdb, pit_i71); | iocore_attachinp(0x3fdb, pit_i71); | 
 |  | iocore_attachinp(0x3fdd, pit_i71); | 
 | } | } | 
 |  |  |