--- np2/io/pit.c 2003/10/25 20:51:53 1.3 +++ np2/io/pit.c 2003/11/28 08:01:33 1.8 @@ -32,7 +32,7 @@ static void setsystimerevent(BOOL absolu SINT32 cnt; - cnt = pit.value[0].w; + cnt = pit.value[0]; if (cnt > 8) { // 根拠なし cnt *= pc.multiple; } @@ -45,15 +45,21 @@ static void setsystimerevent(BOOL absolu void systimer(NEVENTITEM item) { if (item->flag & NEVENT_SETEVENT) { + if (pit.intr[0]) { + pit.intr[0] = 0; + pic_setirq(0); +// TRACEOUT(("int-08 [%.2x]", pit.mode[0])); + } if ((pit.mode[0] & 0x0c) == 0x04) { // レートジェネレータ + pit.intr[0] = 1; setsystimerevent(NEVENT_RELATIVE); } else { - setsystimerevent_noint(NEVENT_RELATIVE); + nevent_set(NEVENT_ITIMER, pc.multiple << 16, + systimer, NEVENT_RELATIVE); } } - pic_setirq(0); } @@ -63,7 +69,7 @@ static void setbeepevent(BOOL absolute) SINT32 cnt; - cnt = pit.value[1].w; + cnt = pit.value[1]; if (cnt > 2) { cnt *= pc.multiple; } @@ -97,11 +103,11 @@ static void setrs232cevent(BOOL absolute SINT32 cnt; - if (pit.value[2].w > 1) { - cnt = pc.multiple * pit.value[2].w * rs232c.mul; // ver0.29 + if (pit.value[2] > 1) { + cnt = pc.multiple * pit.value[2] * rs232c.mul; } else { - cnt = (pc.multiple << 16) * rs232c.mul; // ver0.29 + cnt = (pc.multiple << 16) * rs232c.mul; } nevent_set(NEVENT_RS232C, cnt, rs232ctimer, absolute); } @@ -117,6 +123,7 @@ void rs232ctimer(NEVENTITEM item) { rs232c_callback(); } + // --------------------------------------------------------------------------- static UINT16 itimer_latch(int ch) { @@ -127,10 +134,10 @@ static UINT16 itimer_latch(int ch) { switch(pit.mode[1] & 0x06) { case 0x00: case 0x04: - return(pit.value[1].w); + return(pit.value[1]); #ifdef uPD71054 case 0x06: - return(pit.value[1].w & 0xfffe); + return(pit.value[1] & 0xfffe); #endif } } @@ -141,7 +148,6 @@ static UINT16 itimer_latch(int ch) { return(0); } - void itimer_setflag(int ch, BYTE value) { pit.flag[ch] = 0; @@ -150,7 +156,7 @@ void itimer_setflag(int ch, BYTE value) } else { // latch pit.mode[ch] &= ~0x30; - pit.latch[ch].w = itimer_latch(ch); + pit.latch[ch] = itimer_latch(ch); } } @@ -158,22 +164,22 @@ BOOL itimer_setcount(int ch, BYTE value) switch(pit.mode[ch] & 0x30) { case 0x10: // access low - pit.value[ch].w = value; + pit.value[ch] = value; break; case 0x20: // access high - pit.value[ch].w = value << 8; + pit.value[ch] = value << 8; break; case 0x30: // access word if (!(pit.flag[ch] & 2)) { - pit.value[ch].w &= 0xff00; - pit.value[ch].w += value; + pit.value[ch] &= 0xff00; + pit.value[ch] += value; pit.flag[ch] ^= 2; return(TRUE); } - pit.value[ch].w &= 0x00ff; - pit.value[ch].w += value << 8; + pit.value[ch] &= 0x00ff; + pit.value[ch] += value << 8; pit.flag[ch] ^= 2; break; } @@ -183,30 +189,27 @@ BOOL itimer_setcount(int ch, BYTE value) BYTE itimer_getcount(int ch) { BYTE ret; - union { - BYTE b[2]; - UINT16 w; - } tim; + UINT16 w; if (!(pit.mode[ch] & 0x30)) { - tim.w = pit.latch[ch].w; + w = pit.latch[ch]; } else { - tim.w = itimer_latch(ch); // ver0.30 + w = itimer_latch(ch); } switch(pit.mode[ch] & 0x30) { case 0x10: // access low - return((BYTE)tim.w); + return((BYTE)w); case 0x20: // access high - return((BYTE)(tim.w >> 8)); + return((BYTE)(w >> 8)); } // access word if (!(pit.flag[ch] & 1)) { - ret = (BYTE)tim.w; + ret = (BYTE)w; } else { - ret = (BYTE)(tim.w >> 8); + ret = (BYTE)(w >> 8); } pit.flag[ch] ^= 1; return(ret); @@ -218,11 +221,12 @@ BYTE itimer_getcount(int ch) { // system timer 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)) { return; } pic.pi[0].irr &= (~1); + pit.intr[0] = 1; setsystimerevent(NEVENT_ABSOLUTE); (void)port; } @@ -238,7 +242,7 @@ static void IOOUTCALL pit_o73(UINT port, beep_lheventset(1); } else { - beep_hzset(pit.value[1].w); + beep_hzset(pit.value[1]); } (void)port; } @@ -259,13 +263,16 @@ static void IOOUTCALL pit_o77(UINT port, int ch; -// TRACEOUT(("pic77: %x", dat)); +// TRACEOUT(("pic o77: %x", dat)); ch = (dat >> 6) & 3; if (ch != 3) { itimer_setflag(ch, dat); if (ch == 0) { // 書込みで itimerのirrがリセットされる… pic.pi[0].irr &= (~1); - setsystimerevent(NEVENT_ABSOLUTE); + if (dat & 0x30) { // 一応ラッチ時は割り込みをセットしない + pit.intr[0] = 1; +// setsystimerevent(NEVENT_ABSOLUTE); + } } if (ch == 1) { beep_modeset(); @@ -292,17 +299,17 @@ void itimer_reset(void) { ZeroMemory(&pit, sizeof(pit)); if (pc.cpumode & CPUMODE_8MHz) { - pit.value[1].w = 998; // 4MHz + pit.value[1] = 998; // 4MHz } else { - pit.value[1].w = 1229; // 5MHz + pit.value[1] = 1229; // 5MHz } pit.mode[0] = 0x30; pit.mode[1] = 0x56; pit.mode[2] = 0xb6; pit.mode[3] = 0x36; setsystimerevent(NEVENT_ABSOLUTE); - beep_hzset(pit.value[1].w); + beep_hzset(pit.value[1]); } void itimer_bind(void) {