Diff for /np2/io/pic.c between versions 1.2 and 1.15

version 1.2, 2003/10/21 11:22:05 version 1.15, 2004/03/05 04:39:59
Line 1 Line 1
 #include        "compiler.h"  #include        "compiler.h"
 #include        "i286.h"  #include        "cpucore.h"
 #include        "pccore.h"  #include        "pccore.h"
 #include        "iocore.h"  #include        "iocore.h"
   
   
 static const _PICITEM def_master = {  static const _PICITEM def_master = {
                                                         0, {0, 0, 0, 0, 0, 0, 0, 0},                                                          0, {0, 0, 0, 0, 0, 0, 0, 0},
                                                         0, {0, 0, 0, 0, 0, 0, 0, 0},  
                                                                 {7, 6, 5, 4, 3, 2, 1, 0},                                                                  {7, 6, 5, 4, 3, 2, 1, 0},
                                                                 {0, 0x08, 0x00, 0},                                                                  {0, 0x08, 0x00, 0},
                                                                 0x7d, 0, 0, 0,                                                                  0x7d, 0, 0, 0,
Line 14  static const _PICITEM def_master = { Line 13  static const _PICITEM def_master = {
   
 static const _PICITEM def_slave = {  static const _PICITEM def_slave = {
                                                         0, {0, 0, 0, 0, 0, 0, 0, 0},                                                          0, {0, 0, 0, 0, 0, 0, 0, 0},
                                                         0, {0, 0, 0, 0, 0, 0, 0, 0},  
                                                                 {7, 6, 5, 4, 3, 2, 1, 0},                                                                  {7, 6, 5, 4, 3, 2, 1, 0},
                                                                 {0, 0x10, 0x07, 0},                                                                  {0, 0x10, 0x07, 0},
                                                                 0x70, 0, 0, 0,                                                                  0x71, 0, 0, 0,
                                                                 0, 0, 0, 0};                                                                  0, 0, 0, 0};
   
   
 // ------------------------------------------------------------ ext. interrupt  // ----
   
 // 外部でISRを待避する割り込み対策  
   
 void extirq_push(void) {  
   
         PIC             p;  
   
         p = &pic;  
         if (!p->ext_irq) {  
                 p->ext_irq = 1;  
   
                 p->pi[0].levelsbak = p->pi[0].levels;  
                 *(UINT32 *)(p->pi[0].levelbak+0) = *(UINT32 *)(p->pi[0].level+0);  
                 *(UINT32 *)(p->pi[0].levelbak+4) = *(UINT32 *)(p->pi[0].level+4);  
                 p->pi[0].isrbak = p->pi[0].isr;  
   
                 p->pi[1].levelsbak = p->pi[1].levels;  
                 *(UINT32 *)(p->pi[1].levelbak+0) = *(UINT32 *)(p->pi[1].level+0);  
                 *(UINT32 *)(p->pi[1].levelbak+4) = *(UINT32 *)(p->pi[1].level+4);  
                 p->pi[1].isrbak = p->pi[1].isr;  
         }  
 }  
   
   
 void extirq_pop(void) {  
   
         PIC             p;  
   
         p = &pic;  
         if (p->ext_irq) {  
                 p->ext_irq = 0;  
   
                 p->pi[0].levels = p->pi[0].levelsbak;  
                 *(UINT32 *)(p->pi[0].level+0) = *(UINT32 *)(p->pi[0].levelbak+0);  
                 *(UINT32 *)(p->pi[0].level+4) = *(UINT32 *)(p->pi[0].levelbak+4);  
                 p->pi[0].isr = p->pi[0].isrbak;  
   
                 p->pi[1].levels = p->pi[1].levelsbak;  
                 *(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;  
         }  
 }  
   
   
 // ---------------------------  
   
 static void pic_rolpry(PICITEM pi) {  static void pic_rolpry(PICITEM pi) {
   
Line 79  static void pic_rolpry(PICITEM pi) { Line 31  static void pic_rolpry(PICITEM pi) {
 }  }
   
   
 static void pic_downbylevel(PICITEM picp, BYTE level) {  static void pic_downbylevel(PICITEM picp, UINT level) {
   
         int             i;          int             i;
   
Line 93  static void pic_downbylevel(PICITEM picp Line 45  static void pic_downbylevel(PICITEM picp
   
   
 // eoi処理  // eoi処理
 static void pic_forceeoibylevel(PICITEM picp, BYTE level) {  static void pic_forceeoibylevel(PICITEM picp, UINT level) {
   
         int             i;          int             i;
   
         if (picp->isr & (1 << level)) {          if (picp->isr & (1 << level)) {
                 picp->isr &= ~(1 << level);                  picp->isr &= ~(1 << level);
                 (picp->levels)--;                  picp->levels--;
                 for (i=0; (i<picp->levels) && (picp->level[i] != level); i++) { }                  for (i=0; (i<picp->levels) && (picp->level[i] != level); i++) { }
                 for (; i<picp->levels; i++) {                  for (; i<picp->levels; i++) {
                         picp->level[i] = picp->level[i+1];                          picp->level[i] = picp->level[i+1];
Line 112  void pic_irq(void) { Line 64  void pic_irq(void) {
   
         int             i;          int             i;
         BYTE    bit;          BYTE    bit;
         char    pry;          SINT8   pry;
         BYTE    irq;          BYTE    irq;
         BYTE    sirq;          BYTE    sirq;
         BYTE    targetbit;          BYTE    targetbit;
Line 121  void pic_irq(void) { Line 73  void pic_irq(void) {
         p = &pic;          p = &pic;
   
         // 割込み許可で 要求あり?          // 割込み許可で 要求あり?
         if ((isI286EI) && (!p->ext_irq) &&          if ((CPU_isEI) &&
                 ((p->pi[0].irr & (~p->pi[0].imr)) ||                          ((p->pi[0].irr & (~p->pi[0].imr)) ||
                         (p->pi[1].irr & (~p->pi[1].imr)))) {                          (p->pi[1].irr & (~p->pi[1].imr)))) {
   
                 // マスターの処理                  // マスターの処理
Line 130  void pic_irq(void) { Line 82  void pic_irq(void) {
                         pry = -1;                          pry = -1;
                 }                  }
                 else {                  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;                  irq = 0xff;
                 targetbit = 0;                  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) &&                          if ((p->pi[0].irr & bit) &&
                                 (!((p->pi[0].imr | p->pi[0].isr) & 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];                                          pry = p->pi[0].pry[i];
                                         irq = (BYTE)i;                                          irq = (BYTE)i;
                                         targetbit = bit;                                          targetbit = bit;
Line 152  void pic_irq(void) { Line 104  void pic_irq(void) {
                         sirq = p->pi[1].icw[2] & 7;                          sirq = p->pi[1].icw[2] & 7;
                         bit = 1 << sirq;                          bit = 1 << sirq;
                         if (!((p->pi[0].imr | p->pi[0].isr) & bit)) {                          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;                                          irq = sirq;
                                         targetbit = bit;                                          targetbit = bit;
                                 }                                  }
Line 161  void pic_irq(void) { Line 113  void pic_irq(void) {
                 // マスタの割込                  // マスタの割込
                 if (irq != sirq) {                  if (irq != sirq) {
                         if (targetbit) {                          if (targetbit) {
                                 if (p->pi[0].ext & targetbit) {                         // ver0.30  
                                         extirq_push();  
                                 }  
                                 p->pi[0].isr |= targetbit;                                  p->pi[0].isr |= targetbit;
                                 p->pi[0].irr &= ~targetbit;                                  p->pi[0].irr &= ~targetbit;
                                 p->pi[0].level[p->pi[0].levels++] = irq;                                  p->pi[0].level[p->pi[0].levels++] = irq;
                                 if (irq == 0) {                                                                 // ver0.28                                  if (irq == 0) {                                                                 // ver0.28
                                         nevent_reset(NEVENT_PICMASK);                                          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;                                  return;
                         }                          }
                         if ((!p->pi[0].levels) ||                          if ((!p->pi[0].levels) ||
Line 183  void pic_irq(void) { Line 133  void pic_irq(void) {
                         pry = -1;                          pry = -1;
                 }                  }
                 else {                  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;                  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) &&                          if ((p->pi[1].irr & bit) &&
                                 (!((p->pi[1].imr | p->pi[1].isr) & 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];                                          pry = p->pi[1].pry[i];
                                         irq = (BYTE)i;                                          irq = (BYTE)i;
                                         targetbit = bit;                                          targetbit = bit;
Line 199  void pic_irq(void) { Line 149  void pic_irq(void) {
                 // スレーヴの割込                  // スレーヴの割込
                 if (targetbit) {                  if (targetbit) {
                         if (!(p->pi[0].icw[2] & targetbit)) {                          if (!(p->pi[0].icw[2] & targetbit)) {
                                 if (p->pi[1].ext & targetbit) {                         // ver0.30  
                                         extirq_push();  
                                 }  
                                 p->pi[1].isr |= targetbit;                                  p->pi[1].isr |= targetbit;
                                 p->pi[1].irr &= ~targetbit;                                  p->pi[1].irr &= ~targetbit;
                                 p->pi[1].level[p->pi[1].levels++] = irq;                                  p->pi[1].level[p->pi[1].levels++] = irq;
Line 211  void pic_irq(void) { Line 158  void pic_irq(void) {
                                         p->pi[0].irr &= ~(1 << sirq);                                          p->pi[0].irr &= ~(1 << sirq);
                                         p->pi[0].level[p->pi[0].levels++] = sirq;                                          p->pi[0].level[p->pi[0].levels++] = sirq;
                                 }                                  }
 // TRACEOUT(("hardware int %.2x", (p->pi[1].icw[1] & 0xf8) | irq));  // TRACEOUT(("hardware-int %.2x", (p->pi[1].icw[1] & 0xf8) | irq));
                                 i286_interrupt((BYTE)((p->pi[1].icw[1] & 0xf8) | irq));                                  CPU_INTERRUPT((REG8)((p->pi[1].icw[1] & 0xf8) | irq));
                         }                          }
                 }                  }
         }          }
Line 230  void picmask(NEVENTITEM item) { Line 177  void picmask(NEVENTITEM item) {
         }          }
 }  }
   
 void pic_setirq(BYTE irq) {  void pic_setirq(REG8 irq) {
   
         PICITEM pi;          PICITEM pi;
         BYTE    bit;          REG8    bit;
   
         pi = pic.pi;          pi = pic.pi;
         bit = 1 << (irq & 7);          bit = 1 << (irq & 7);
Line 243  void pic_setirq(BYTE irq) { Line 190  void pic_setirq(BYTE irq) {
                         if (bit & PIC_SYSTEMTIMER) {                          if (bit & PIC_SYSTEMTIMER) {
                                 if ((pit.mode[0] & 0x0c) == 0x04) {                                  if ((pit.mode[0] & 0x0c) == 0x04) {
                                         SINT32 cnt;                                                                             // ver0.29                                          SINT32 cnt;                                                                             // ver0.29
                                         if (pit.value[0].w > 8) {                                          if (pit.value[0] > 8) {
                                                 cnt = pc.multiple * pit.value[0].w;                                                  cnt = pccore.multiple * pit.value[0];
                                                 cnt >>= 2;                                                  cnt >>= 2;
                                         }                                          }
                                         else {                                          else {
                                                 cnt = pc.multiple << (16 - 2);                                                  cnt = pccore.multiple << (16 - 2);
                                         }                                          }
                                         nevent_set(NEVENT_PICMASK, cnt, picmask, NEVENT_ABSOLUTE);                                          nevent_set(NEVENT_PICMASK, cnt, picmask, NEVENT_ABSOLUTE);
                                 }                                  }
Line 266  void pic_setirq(BYTE irq) { Line 213  void pic_setirq(BYTE irq) {
         }          }
 }  }
   
 void pic_resetirq(BYTE irq) {  void pic_resetirq(REG8 irq) {
   
         PICITEM         pi;          PICITEM         pi;
   
Line 275  void pic_resetirq(BYTE irq) { Line 222  void pic_resetirq(BYTE irq) {
 }  }
   
   
 void pic_registext(BYTE irq) {  
   
         PICITEM         pi;  
   
         pi = pic.pi + ((irq >> 3) & 1);  
         pi->ext |= (1 << (irq & 7));  
 }  
   
   
 // ---- I/O  // ---- I/O
   
 static void IOOUTCALL pic_o00(UINT port, BYTE dat) {  static void IOOUTCALL pic_o00(UINT port, REG8 dat) {
   
         PICITEM         picp;          PICITEM         picp;
         BYTE            level;          UINT            level;
   
   //      TRACEOUT(("pic %x %x", port, dat));
         picp = &pic.pi[(port >> 3) & 1];          picp = &pic.pi[(port >> 3) & 1];
         picp->writeicw = 0;          picp->writeicw = 0;
         switch(dat & 0x18) {          switch(dat & 0x18) {
Line 336  static void IOOUTCALL pic_o00(UINT port, Line 275  static void IOOUTCALL pic_o00(UINT port,
         }          }
 }  }
   
 static void IOOUTCALL pic_o02(UINT port, BYTE dat) {  static void IOOUTCALL pic_o02(UINT port, REG8 dat) {
   
         PICITEM         picp;          PICITEM         picp;
   
   //      TRACEOUT(("pic %x %x", port, dat));
         picp = &pic.pi[(port >> 3) & 1];          picp = &pic.pi[(port >> 3) & 1];
         if (!picp->writeicw) {          if (!picp->writeicw) {
   #if 1
                   UINT8   set;
                   set = picp->imr & (~dat);
                   // リセットされたビットは割り込みある?
                   if ((CPU_isDI) || (!(picp->irr & set))) {
                           picp->imr = dat;
                           return;
                   }
   #endif
                 picp->imr = dat;                  picp->imr = dat;
         }          }
         else {          else {
Line 354  static void IOOUTCALL pic_o02(UINT port, Line 303  static void IOOUTCALL pic_o02(UINT port,
         nevent_forceexit();          nevent_forceexit();
 }  }
   
 static BYTE IOINPCALL pic_i00(UINT port) {  static REG8 IOINPCALL pic_i00(UINT port) {
   
         PICITEM         picp;          PICITEM         picp;
   
Line 371  static BYTE IOINPCALL pic_i00(UINT port) Line 320  static BYTE IOINPCALL pic_i00(UINT port)
         }          }
 }  }
   
 static BYTE IOINPCALL pic_i02(UINT port) {  static REG8 IOINPCALL pic_i02(UINT port) {
   
         PICITEM         picp;          PICITEM         picp;
   

Removed from v.1.2  
changed lines
  Added in v.1.15


RetroPC.NET-CVS <cvs@retropc.net>