--- np2/io/pit.c 2003/11/21 06:51:11 1.6 +++ np2/io/pit.c 2003/12/01 17:13:36 1.9 @@ -10,7 +10,8 @@ #include "beep.h" -// #define uPD71054 // NP2はuPD8253Cベース +// #define uPD71054 // NP2はuPD8253Cベース +#define BEEPCOUNTEREX // BEEPアイドル時のカウンタをα倍に // --- Interval timer @@ -44,23 +45,45 @@ static void setsystimerevent(BOOL absolu void systimer(NEVENTITEM item) { - if (pit.intr[0]) { - pit.intr[0] = 0; - pic_setirq(0); -// TRACEOUT(("int-08 [%.2x]", pit.mode[0])); - } if (item->flag & NEVENT_SETEVENT) { + if (pit.intr[0]) { + pit.intr[0] = 0; + pic_setirq(0); + } if ((pit.mode[0] & 0x0c) == 0x04) { // レートジェネレータ pit.intr[0] = 1; + setsystimerevent(NEVENT_RELATIVE); + } + else { + nevent_set(NEVENT_ITIMER, pc.multiple << 16, + systimer, NEVENT_RELATIVE); } - setsystimerevent(NEVENT_RELATIVE); } } // --- 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) { SINT32 cnt; @@ -87,7 +110,11 @@ void beeponeshot(NEVENTITEM item) { if (pit.mode[1] & 0x02) #endif { +#if defined(BEEPCOUNTEREX) + setbeepeventex(NEVENT_RELATIVE); +#else setbeepevent(NEVENT_RELATIVE); +#endif } } } @@ -119,6 +146,7 @@ void rs232ctimer(NEVENTITEM item) { rs232c_callback(); } + // --------------------------------------------------------------------------- static UINT16 itimer_latch(int ch) { @@ -135,6 +163,20 @@ static UINT16 itimer_latch(int ch) { return(pit.value[1] & 0xfffe); #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); if (clock >= 0) { @@ -143,7 +185,6 @@ static UINT16 itimer_latch(int ch) { return(0); } - void itimer_setflag(int ch, BYTE value) { pit.flag[ch] = 0; @@ -265,10 +306,10 @@ static void IOOUTCALL pit_o77(UINT port, itimer_setflag(ch, dat); if (ch == 0) { // 書込みで itimerのirrがリセットされる… pic.pi[0].irr &= (~1); -// if (dat & 0x30) { // 一応ラッチ時は割り込みをセットしない + if (dat & 0x30) { // 一応ラッチ時は割り込みをセットしない pit.intr[0] = 1; // setsystimerevent(NEVENT_ABSOLUTE); -// } + } } if (ch == 1) { beep_modeset(); @@ -279,12 +320,6 @@ static void IOOUTCALL pit_o77(UINT port, static BYTE IOINPCALL pit_i71(UINT port) { - if (port == 0x71) { - BYTE x; - x = itimer_getcount((port >> 1) & 3); -// TRACEOUT(("pic i71 %x [%.4x %.4x]", x, I286_CS, I286_IP)); - return(x); - } return(itimer_getcount((port >> 1) & 3)); }