|
|
| version 1.4, 2003/10/25 21:03:43 | version 1.9, 2003/12/01 17:13:36 |
|---|---|
| Line 10 | Line 10 |
| #include "beep.h" | #include "beep.h" |
| // #define uPD71054 // NP2はuPD8253Cベース | // #define uPD71054 // NP2はuPD8253Cベース |
| #define BEEPCOUNTEREX // BEEPアイドル時のカウンタをα倍に | |
| // --- Interval timer | // --- Interval timer |
| Line 32 static void setsystimerevent(BOOL absolu | Line 33 static void setsystimerevent(BOOL absolu |
| SINT32 cnt; | SINT32 cnt; |
| cnt = pit.value[0].w; | cnt = pit.value[0]; |
| if (cnt > 8) { // 根拠なし | if (cnt > 8) { // 根拠なし |
| cnt *= pc.multiple; | cnt *= pc.multiple; |
| } | } |
| Line 45 static void setsystimerevent(BOOL absolu | Line 46 static void setsystimerevent(BOOL absolu |
| void systimer(NEVENTITEM item) { | void systimer(NEVENTITEM item) { |
| if (item->flag & NEVENT_SETEVENT) { | if (item->flag & NEVENT_SETEVENT) { |
| if (pit.intr[0]) { | |
| pit.intr[0] = 0; | |
| pic_setirq(0); | |
| } | |
| if ((pit.mode[0] & 0x0c) == 0x04) { | if ((pit.mode[0] & 0x0c) == 0x04) { |
| // レートジェネレータ | // レートジェネレータ |
| pit.intr[0] = 1; | |
| setsystimerevent(NEVENT_RELATIVE); | setsystimerevent(NEVENT_RELATIVE); |
| } | } |
| else { | else { |
| setsystimerevent_noint(NEVENT_RELATIVE); | nevent_set(NEVENT_ITIMER, pc.multiple << 16, |
| systimer, NEVENT_RELATIVE); | |
| } | } |
| } | } |
| pic_setirq(0); | |
| } | } |
| // --- Beep | // --- Beep |
| #if defined(BEEPCOUNTEREX) | |
| static void setbeepeventex(BOOL absolute) { | |
| UINT32 cnt; | |
| cnt = pit.value[1]; | |
| if (cnt > 2) { | |
| cnt *= pc.multiple; | |
| } | |
| else { | |
| cnt = pc.multiple << 16; | |
| } | |
| while(cnt < 0x100000) { | |
| cnt <<= 1; | |
| } | |
| nevent_set(NEVENT_BEEP, (SINT32)cnt, beeponeshot, absolute); | |
| } | |
| #endif | |
| static void setbeepevent(BOOL absolute) { | static void setbeepevent(BOOL absolute) { |
| SINT32 cnt; | SINT32 cnt; |
| cnt = pit.value[1].w; | cnt = pit.value[1]; |
| if (cnt > 2) { | if (cnt > 2) { |
| cnt *= pc.multiple; | cnt *= pc.multiple; |
| } | } |
| Line 85 void beeponeshot(NEVENTITEM item) { | Line 110 void beeponeshot(NEVENTITEM item) { |
| if (pit.mode[1] & 0x02) | if (pit.mode[1] & 0x02) |
| #endif | #endif |
| { | { |
| #if defined(BEEPCOUNTEREX) | |
| setbeepeventex(NEVENT_RELATIVE); | |
| #else | |
| setbeepevent(NEVENT_RELATIVE); | setbeepevent(NEVENT_RELATIVE); |
| #endif | |
| } | } |
| } | } |
| } | } |
| Line 97 static void setrs232cevent(BOOL absolute | Line 126 static void setrs232cevent(BOOL absolute |
| SINT32 cnt; | SINT32 cnt; |
| if (pit.value[2].w > 1) { | if (pit.value[2] > 1) { |
| cnt = pc.multiple * pit.value[2].w * rs232c.mul; // ver0.29 | cnt = pc.multiple * pit.value[2] * rs232c.mul; |
| } | } |
| else { | else { |
| cnt = (pc.multiple << 16) * rs232c.mul; // ver0.29 | cnt = (pc.multiple << 16) * rs232c.mul; |
| } | } |
| nevent_set(NEVENT_RS232C, cnt, rs232ctimer, absolute); | nevent_set(NEVENT_RS232C, cnt, rs232ctimer, absolute); |
| } | } |
| Line 117 void rs232ctimer(NEVENTITEM item) { | Line 146 void rs232ctimer(NEVENTITEM item) { |
| rs232c_callback(); | rs232c_callback(); |
| } | } |
| // --------------------------------------------------------------------------- | // --------------------------------------------------------------------------- |
| static UINT16 itimer_latch(int ch) { | static UINT16 itimer_latch(int ch) { |
| Line 127 static UINT16 itimer_latch(int ch) { | Line 157 static UINT16 itimer_latch(int ch) { |
| switch(pit.mode[1] & 0x06) { | switch(pit.mode[1] & 0x06) { |
| case 0x00: | case 0x00: |
| case 0x04: | case 0x04: |
| return(pit.value[1].w); | return(pit.value[1]); |
| #ifdef uPD71054 | #ifdef uPD71054 |
| case 0x06: | case 0x06: |
| return(pit.value[1].w & 0xfffe); | return(pit.value[1] & 0xfffe); |
| #endif | #endif |
| } | } |
| #if defined(BEEPCOUNTEREX) | |
| clock = nevent_getremain(NEVENT_ITIMER + ch); | |
| if (clock < 0) { | |
| return(0); | |
| } | |
| clock /= pc.multiple; | |
| if (pit.value[1] > 2) { | |
| clock %= pit.value[1]; | |
| } | |
| else { | |
| clock >>= 16; | |
| } | |
| return((UINT16)clock); | |
| #endif | |
| } | } |
| clock = nevent_getremain(NEVENT_ITIMER + ch); | clock = nevent_getremain(NEVENT_ITIMER + ch); |
| if (clock >= 0) { | if (clock >= 0) { |
| Line 141 static UINT16 itimer_latch(int ch) { | Line 185 static UINT16 itimer_latch(int ch) { |
| return(0); | return(0); |
| } | } |
| void itimer_setflag(int ch, BYTE value) { | void itimer_setflag(int ch, BYTE value) { |
| pit.flag[ch] = 0; | pit.flag[ch] = 0; |
| Line 150 void itimer_setflag(int ch, BYTE value) | Line 193 void itimer_setflag(int ch, BYTE value) |
| } | } |
| else { // latch | else { // latch |
| pit.mode[ch] &= ~0x30; | pit.mode[ch] &= ~0x30; |
| pit.latch[ch].w = itimer_latch(ch); | pit.latch[ch] = itimer_latch(ch); |
| } | } |
| } | } |
| Line 158 BOOL itimer_setcount(int ch, BYTE value) | Line 201 BOOL itimer_setcount(int ch, BYTE value) |
| switch(pit.mode[ch] & 0x30) { | switch(pit.mode[ch] & 0x30) { |
| case 0x10: // access low | case 0x10: // access low |
| pit.value[ch].w = value; | pit.value[ch] = value; |
| break; | break; |
| case 0x20: // access high | case 0x20: // access high |
| pit.value[ch].w = value << 8; | pit.value[ch] = value << 8; |
| break; | break; |
| case 0x30: // access word | case 0x30: // access word |
| if (!(pit.flag[ch] & 2)) { | if (!(pit.flag[ch] & 2)) { |
| pit.value[ch].w &= 0xff00; | pit.value[ch] &= 0xff00; |
| pit.value[ch].w += value; | pit.value[ch] += value; |
| pit.flag[ch] ^= 2; | pit.flag[ch] ^= 2; |
| return(TRUE); | return(TRUE); |
| } | } |
| pit.value[ch].w &= 0x00ff; | pit.value[ch] &= 0x00ff; |
| pit.value[ch].w += value << 8; | pit.value[ch] += value << 8; |
| pit.flag[ch] ^= 2; | pit.flag[ch] ^= 2; |
| break; | break; |
| } | } |
| Line 183 BOOL itimer_setcount(int ch, BYTE value) | Line 226 BOOL itimer_setcount(int ch, BYTE value) |
| BYTE itimer_getcount(int ch) { | BYTE itimer_getcount(int ch) { |
| BYTE ret; | BYTE ret; |
| union { | UINT16 w; |
| BYTE b[2]; | |
| UINT16 w; | |
| } tim; | |
| if (!(pit.mode[ch] & 0x30)) { | if (!(pit.mode[ch] & 0x30)) { |
| tim.w = pit.latch[ch].w; | w = pit.latch[ch]; |
| } | } |
| else { | else { |
| tim.w = itimer_latch(ch); // ver0.30 | w = itimer_latch(ch); |
| } | } |
| switch(pit.mode[ch] & 0x30) { | switch(pit.mode[ch] & 0x30) { |
| case 0x10: // access low | case 0x10: // access low |
| return((BYTE)tim.w); | return((BYTE)w); |
| case 0x20: // access high | case 0x20: // access high |
| return((BYTE)(tim.w >> 8)); | return((BYTE)(w >> 8)); |
| } | } |
| // access word | // access word |
| if (!(pit.flag[ch] & 1)) { | if (!(pit.flag[ch] & 1)) { |
| ret = (BYTE)tim.w; | ret = (BYTE)w; |
| } | } |
| else { | else { |
| ret = (BYTE)(tim.w >> 8); | ret = (BYTE)(w >> 8); |
| } | } |
| pit.flag[ch] ^= 1; | pit.flag[ch] ^= 1; |
| return(ret); | return(ret); |
| Line 218 BYTE itimer_getcount(int ch) { | Line 258 BYTE itimer_getcount(int ch) { |
| // system timer | // system timer |
| static void IOOUTCALL pit_o71(UINT port, BYTE dat) { | static void IOOUTCALL pit_o71(UINT port, BYTE dat) { |
| // TRACEOUT(("pic71: %d", dat)); | // TRACEOUT(("pic o71: %x [%.4x %.4x]", dat, I286_CS, I286_IP)); |
| if (itimer_setcount(0, dat)) { | if (itimer_setcount(0, dat)) { |
| return; | return; |
| } | } |
| pic.pi[0].irr &= (~1); | pic.pi[0].irr &= (~1); |
| pit.intr[0] = 1; | |
| setsystimerevent(NEVENT_ABSOLUTE); | setsystimerevent(NEVENT_ABSOLUTE); |
| (void)port; | (void)port; |
| } | } |
| Line 238 static void IOOUTCALL pit_o73(UINT port, | Line 279 static void IOOUTCALL pit_o73(UINT port, |
| beep_lheventset(1); | beep_lheventset(1); |
| } | } |
| else { | else { |
| beep_hzset(pit.value[1].w); | beep_hzset(pit.value[1]); |
| } | } |
| (void)port; | (void)port; |
| } | } |
| Line 259 static void IOOUTCALL pit_o77(UINT port, | Line 300 static void IOOUTCALL pit_o77(UINT port, |
| int ch; | int ch; |
| // TRACEOUT(("pic77: %x", dat)); | // TRACEOUT(("pic o77: %x", dat)); |
| ch = (dat >> 6) & 3; | ch = (dat >> 6) & 3; |
| if (ch != 3) { | if (ch != 3) { |
| itimer_setflag(ch, dat); | itimer_setflag(ch, dat); |
| if (ch == 0) { // 書込みで itimerのirrがリセットされる… | if (ch == 0) { // 書込みで itimerのirrがリセットされる… |
| pic.pi[0].irr &= (~1); | pic.pi[0].irr &= (~1); |
| if (dat & 0x30) { // 一応ラッチ時は割り込みをセットしない | if (dat & 0x30) { // 一応ラッチ時は割り込みをセットしない |
| setsystimerevent(NEVENT_ABSOLUTE); | pit.intr[0] = 1; |
| // setsystimerevent(NEVENT_ABSOLUTE); | |
| } | } |
| } | } |
| if (ch == 1) { | if (ch == 1) { |
| Line 294 void itimer_reset(void) { | Line 336 void itimer_reset(void) { |
| ZeroMemory(&pit, sizeof(pit)); | ZeroMemory(&pit, sizeof(pit)); |
| if (pc.cpumode & CPUMODE_8MHz) { | if (pc.cpumode & CPUMODE_8MHz) { |
| pit.value[1].w = 998; // 4MHz | pit.value[1] = 998; // 4MHz |
| } | } |
| else { | else { |
| pit.value[1].w = 1229; // 5MHz | pit.value[1] = 1229; // 5MHz |
| } | } |
| pit.mode[0] = 0x30; | pit.mode[0] = 0x30; |
| pit.mode[1] = 0x56; | pit.mode[1] = 0x56; |
| pit.mode[2] = 0xb6; | pit.mode[2] = 0xb6; |
| pit.mode[3] = 0x36; | pit.mode[3] = 0x36; |
| setsystimerevent(NEVENT_ABSOLUTE); | setsystimerevent(NEVENT_ABSOLUTE); |
| beep_hzset(pit.value[1].w); | beep_hzset(pit.value[1]); |
| } | } |
| void itimer_bind(void) { | void itimer_bind(void) { |