#include "ibm.h" #include "io.h" #include "pic.h" int output; int intclear; int keywaiting=0; int pic_intpending; void pic_updatepending() { pic_intpending = (((pic.pend&~pic.mask)&~pic.mask2) || ((pic2.pend&~pic2.mask)&~pic2.mask2)); // pclog("pic_intpending = %i %02X %02X %02X\n", pic_intpending, pic.pend, pic.mask, pic.mask2); } void pic_reset() { pic.icw=0; pic.mask=0xFF; pic.mask2=0; pic.pend=pic.ins=0; pic.vector=8; pic.read=1; pic2.icw=0; pic2.mask=0xFF; pic.mask2=0; pic2.pend=pic2.ins=0; pic_intpending = 0; } void pic_write(uint16_t addr, uint8_t val, void *priv) { int c; // pclog("Write PIC %04X %02X %04X(%06X):%04X\n",addr,val,CS,cs,pc); if (addr&1) { switch (pic.icw) { case 0: /*OCW1*/ // printf("Write mask %02X %04X:%04X\n",val,CS,pc); pic.mask=val; pic_updatepending(); break; case 1: /*ICW2*/ pic.vector=val&0xF8; // printf("PIC vector now %02X\n",pic.vector); // output=1; if (pic.icw1&2) pic.icw=3; else pic.icw=2; break; case 2: /*ICW3*/ if (pic.icw1&1) pic.icw=3; else pic.icw=0; break; case 3: /*ICW4*/ pic.icw=0; break; } } else { if (val&16) /*ICW1*/ { pic.mask=0xFF; pic.mask2=0; pic.icw=1; pic.icw1=val; pic_updatepending(); } else if (!(val&8)) /*OCW2*/ { // printf("Clear ints - %02X %02X\n",pic.ins,val); if ((val&0xE0)==0x60) { // pclog("Specific EOI - %02X %i\n",pic.ins,1<<(val&7)); pic.ins&=~(1<<(val&7)); pic.mask2&=~(1<<(val&7)); // pic.pend&=(1<<(val&7)); // if ((val&7)==1) pollkeywaiting(); pic_updatepending(); } else { for (c=0;c<8;c++) { if (pic.ins&(1<0xFF) { pic2.pend|=(num>>8); } else { pic.pend|=num; } // pclog("picint : PEND now %02X %02X\n", pic.pend, pic2.pend); pic_updatepending(); } void picintlevel(uint16_t num) { int c = 0; while (!(num & (1 << c))) c++; // pclog("INTLEVEL %04X %i\n", num, c); if (!pic_current[c]) { pic_current[c]=1; if (num>0xFF) { pic2.pend|=(num>>8); } else { pic.pend|=num; } } pic_updatepending(); } void picintc(uint16_t num) { int c = 0; while (!(num & (1 << c))) c++; //pclog("INTC %04X %i\n", num, c); pic_current[c]=0; if (num>0xFF) pic2.pend&=~(num>>8); else { pic.pend&=~num; } } uint8_t picinterrupt() { uint8_t temp=pic.pend&~pic.mask; int c; for (c=0;c<8;c++) { if (temp&(1<