--- np2/io/pic.c 2003/11/12 00:55:38 1.3 +++ np2/io/pic.c 2004/01/22 01:10:04 1.11 @@ -1,5 +1,5 @@ #include "compiler.h" -#include "i286.h" +#include "cpucore.h" #include "pccore.h" #include "iocore.h" @@ -63,6 +63,7 @@ void extirq_pop(void) { *(UINT32 *)(p->pi[1].level+0) = *(UINT32 *)(p->pi[1].levelbak+0); *(UINT32 *)(p->pi[1].level+4) = *(UINT32 *)(p->pi[1].levelbak+4); p->pi[1].isr = p->pi[1].isrbak; +// TRACEOUT(("iret: extirq_pop")); } } @@ -79,7 +80,7 @@ static void pic_rolpry(PICITEM pi) { } -static void pic_downbylevel(PICITEM picp, BYTE level) { +static void pic_downbylevel(PICITEM picp, UINT level) { int i; @@ -93,13 +94,13 @@ static void pic_downbylevel(PICITEM picp // eoi処理 -static void pic_forceeoibylevel(PICITEM picp, BYTE level) { +static void pic_forceeoibylevel(PICITEM picp, UINT level) { int i; if (picp->isr & (1 << level)) { picp->isr &= ~(1 << level); - (picp->levels)--; + picp->levels--; for (i=0; (ilevels) && (picp->level[i] != level); i++) { } for (; ilevels; i++) { picp->level[i] = picp->level[i+1]; @@ -112,7 +113,7 @@ void pic_irq(void) { int i; BYTE bit; - char pry; + SINT8 pry; BYTE irq; BYTE sirq; BYTE targetbit; @@ -121,7 +122,7 @@ void pic_irq(void) { p = &pic; // 割込み許可で 要求あり? - if ((isI286EI) && (!p->ext_irq) && + if ((CPU_isEI) && (!p->ext_irq) && ((p->pi[0].irr & (~p->pi[0].imr)) || (p->pi[1].irr & (~p->pi[1].imr)))) { @@ -130,14 +131,14 @@ void pic_irq(void) { pry = -1; } else { - pry = (char)p->pi[0].pry[p->pi[0].level[p->pi[0].levels - 1]]; + pry = (SINT8)p->pi[0].pry[p->pi[0].level[p->pi[0].levels - 1]]; } irq = 0xff; targetbit = 0; - for (bit=1, i=0; bit; bit<<=1, i++) { + for (bit=1, i=0; i<8; bit<<=1, i++) { if ((p->pi[0].irr & bit) && (!((p->pi[0].imr | p->pi[0].isr) & bit))) { - if ((char)p->pi[0].pry[i] > pry) { + if ((SINT8)p->pi[0].pry[i] > pry) { pry = p->pi[0].pry[i]; irq = (BYTE)i; targetbit = bit; @@ -152,7 +153,7 @@ void pic_irq(void) { sirq = p->pi[1].icw[2] & 7; bit = 1 << sirq; if (!((p->pi[0].imr | p->pi[0].isr) & bit)) { - if ((char)p->pi[0].pry[sirq] > pry) { + if ((SINT8)p->pi[0].pry[sirq] > pry) { irq = sirq; targetbit = bit; } @@ -170,7 +171,8 @@ void pic_irq(void) { if (irq == 0) { // ver0.28 nevent_reset(NEVENT_PICMASK); } - i286_interrupt((BYTE)((p->pi[0].icw[1] & 0xf8) | irq)); +// TRACEOUT(("hardware-int %.2x", (p->pi[0].icw[1] & 0xf8) | irq)); + CPU_INTERRUPT((REG8)((p->pi[0].icw[1] & 0xf8) | irq)); return; } if ((!p->pi[0].levels) || @@ -183,13 +185,13 @@ void pic_irq(void) { pry = -1; } else { - pry = (char)p->pi[1].pry[p->pi[1].level[p->pi[1].levels - 1]]; + pry = (SINT8)p->pi[1].pry[p->pi[1].level[p->pi[1].levels - 1]]; } targetbit = 0; - for (bit=1, i=0; bit; bit<<=1, i++) { + for (bit=1, i=0; i<8; bit<<=1, i++) { if ((p->pi[1].irr & bit) && (!((p->pi[1].imr | p->pi[1].isr) & bit))) { - if ((char)p->pi[1].pry[i] > pry) { + if ((SINT8)p->pi[1].pry[i] > pry) { pry = p->pi[1].pry[i]; irq = (BYTE)i; targetbit = bit; @@ -211,8 +213,8 @@ void pic_irq(void) { p->pi[0].irr &= ~(1 << sirq); p->pi[0].level[p->pi[0].levels++] = sirq; } -// TRACEOUT(("hardware int %.2x", (p->pi[1].icw[1] & 0xf8) | irq)); - i286_interrupt((BYTE)((p->pi[1].icw[1] & 0xf8) | irq)); +// TRACEOUT(("hardware-int %.2x", (p->pi[1].icw[1] & 0xf8) | irq)); + CPU_INTERRUPT((REG8)((p->pi[1].icw[1] & 0xf8) | irq)); } } } @@ -230,10 +232,10 @@ void picmask(NEVENTITEM item) { } } -void pic_setirq(BYTE irq) { +void pic_setirq(REG8 irq) { PICITEM pi; - BYTE bit; + REG8 bit; pi = pic.pi; bit = 1 << (irq & 7); @@ -243,12 +245,12 @@ void pic_setirq(BYTE irq) { if (bit & PIC_SYSTEMTIMER) { if ((pit.mode[0] & 0x0c) == 0x04) { SINT32 cnt; // ver0.29 - if (pit.value[0].w > 8) { - cnt = pc.multiple * pit.value[0].w; + if (pit.value[0] > 8) { + cnt = pccore.multiple * pit.value[0]; cnt >>= 2; } else { - cnt = pc.multiple << (16 - 2); + cnt = pccore.multiple << (16 - 2); } nevent_set(NEVENT_PICMASK, cnt, picmask, NEVENT_ABSOLUTE); } @@ -266,7 +268,7 @@ void pic_setirq(BYTE irq) { } } -void pic_resetirq(BYTE irq) { +void pic_resetirq(REG8 irq) { PICITEM pi; @@ -274,8 +276,7 @@ void pic_resetirq(BYTE irq) { pi->irr &= ~(1 << (irq & 7)); } - -void pic_registext(BYTE irq) { +void pic_registext(REG8 irq) { PICITEM pi; @@ -286,10 +287,10 @@ void pic_registext(BYTE irq) { // ---- I/O -static void IOOUTCALL pic_o00(UINT port, BYTE dat) { +static void IOOUTCALL pic_o00(UINT port, REG8 dat) { PICITEM picp; - BYTE level; + UINT level; // TRACEOUT(("pic %x %x", port, dat)); picp = &pic.pi[(port >> 3) & 1]; @@ -337,14 +338,33 @@ static void IOOUTCALL pic_o00(UINT port, } } -static void IOOUTCALL pic_o02(UINT port, BYTE dat) { +#if defined(TRACE) +extern int piccnt; +#endif + +static void IOOUTCALL pic_o02(UINT port, REG8 dat) { PICITEM picp; // TRACEOUT(("pic %x %x", port, dat)); picp = &pic.pi[(port >> 3) & 1]; if (!picp->writeicw) { +#if 1 // マスクのセットだけなら nevent_forceexit()をコールしない + if ((CPU_isDI) || (pic.ext_irq) || + ((picp->imr & dat) == picp->imr)) { + picp->imr = dat; + return; + } + // リセットされたビットは割り込みある? + if (!(picp->irr & (picp->imr & (~dat)))) { + picp->imr = dat; + return; + } +#endif picp->imr = dat; +#if defined(TRACE) + piccnt++; +#endif } else { picp->icw[picp->writeicw] = dat; @@ -356,7 +376,7 @@ static void IOOUTCALL pic_o02(UINT port, nevent_forceexit(); } -static BYTE IOINPCALL pic_i00(UINT port) { +static REG8 IOINPCALL pic_i00(UINT port) { PICITEM picp; @@ -373,7 +393,7 @@ static BYTE IOINPCALL pic_i00(UINT port) } } -static BYTE IOINPCALL pic_i02(UINT port) { +static REG8 IOINPCALL pic_i02(UINT port) { PICITEM picp; @@ -394,6 +414,7 @@ void pic_reset(void) { pic.pi[0] = def_master; pic.pi[1] = def_slave; + pic.ext_irq = 0; } void pic_bind(void) {