Diff for /xmil/io/ctc.c between versions 1.7 and 1.8

version 1.7, 2004/08/11 16:09:04 version 1.8, 2004/08/13 01:35:59
Line 6 Line 6
 #include        "ievent.h"  #include        "ievent.h"
   
   
   static SINT32 minclock(const CTCCH *ch) {
   
           UINT32  event;
           UINT    i;
           UINT32  clock;
   
           event = 0x01000000;
           for (i=0; i<3; i++) {
                   if ((ch->cmd[i] & 0x82) == 0x80) {
                           clock = ch->count[i];
                           if (ch->cmd[i] & 0x40) {
                                   clock = clock * 2;
                           }
                           event = min(event, clock);
                   }
           }
           if ((ch->cmd[3] & 0x82) == 0x80) {
                   clock = ch->count[3];
                   if (ch->cmd[3] & 0x40) {
                           clock = (clock - 1) * ch->countmax[0];
                           clock += ch->count[0];
                           if (ch->cmd[0] & 0x40) {
                                   clock = clock * 2;
                           }
                   }
                   event = min(event, clock);
           }
           event = event / 2;
           if (event == 0) {
                   event = 1;
           }
           return(event);
   }
   
 static REG8 ctcwork(CTCCH *ch) {  static REG8 ctcwork(CTCCH *ch) {
   
         UINT32  baseclock;          UINT32  baseclock;
Line 100  static void ctcstep(CTCCH *ch) { Line 134  static void ctcstep(CTCCH *ch) {
 static void ctcnextevent(CTCCH *ch) {  static void ctcnextevent(CTCCH *ch) {
   
         UINT32  event;          UINT32  event;
         UINT    i;  
         UINT32  clock;  
   
         if (ch->intr) {          if (ch->intr) {
                 return;                  return;
         }          }
         event = 0x01000000;          event = minclock(ch) * pccore.multiple;
         for (i=0; i<3; i++) {  
                 if ((ch->cmd[i] & 0x82) == 0x80) {  
                         clock = ch->count[i];  
                         if (ch->cmd[i] & 0x40) {  
                                 clock = clock * 2;  
                         }  
                         event = min(event, clock);  
                 }  
         }  
         if ((ch->cmd[3] & 0x82) == 0x80) {  
                 clock = ch->count[3];  
                 if (ch->cmd[3] & 0x40) {  
                         clock = (clock - 1) * ch->countmax[0];  
                         clock += ch->count[0];  
                         if (ch->cmd[0] & 0x40) {  
                                 clock = clock * 2;  
                         }  
                 }  
                 event = min(event, clock);  
         }  
         event *= pccore.multiple;  
         event /= 2;  
         if (event == 0) {  
                 event = 1;  
         }  
         nevent_set(NEVENT_CTC0 + ch->num, event, neitem_ctc, NEVENT_ABSOLUTE);          nevent_set(NEVENT_CTC0 + ch->num, event, neitem_ctc, NEVENT_ABSOLUTE);
 }  }
   
Line 166  BRESULT ieitem_ctc(UINT id) { Line 173  BRESULT ieitem_ctc(UINT id) {
         if (intr) {          if (intr) {
                 for (i=0, bit=1; i<4; i++, bit<<=1) {                  for (i=0, bit=1; i<4; i++, bit<<=1) {
                         if (intr & bit) {                          if (intr & bit) {
 #if 1                   // アークスのタイミング→あとで修正  #if 0                   // アークスのタイミング→あとで修正
                                 if (0)                                  if (0)
   #elif 1
                                   if ((ch->countmax[i] - ch->count[i]) >= 256)
 #elif 0  #elif 0
                                 if (((ch->count[i] * 17) >> 4) < ch->countmax[i])                                  if (((ch->count[i] * 17) >> 4) < ch->countmax[i])
 #else  #else
Line 182  BRESULT ieitem_ctc(UINT id) { Line 191  BRESULT ieitem_ctc(UINT id) {
                                 else if (!r) {                                  else if (!r) {
                                         r = TRUE;                                          r = TRUE;
                                         intr ^= bit;                                          intr ^= bit;
   //                                      TRACEOUT(("ctc int %d", i));
                                         Z80_INTERRUPT((REG8)(ch->vector + (i << 1)));                                          Z80_INTERRUPT((REG8)(ch->vector + (i << 1)));
                                 }                                  }
                         }                          }
Line 223  static void ctcch_o(CTCCH *ch, UINT port Line 233  static void ctcch_o(CTCCH *ch, UINT port
                         }                          }
                 }                  }
                 count <<= scale;                  count <<= scale;
                   ch->scale[port] = scale;
                 ch->countmax[port] = count;                  ch->countmax[port] = count;
                 ch->count[port] = count;                  ch->count[port] = count;
                 ch->cmd[port] &= ~6;                  ch->cmd[port] &= ~6;
Line 240  static void ctcch_o(CTCCH *ch, UINT port Line 251  static void ctcch_o(CTCCH *ch, UINT port
   
 static REG8 ctcch_i(CTCCH *ch, UINT port) {  static REG8 ctcch_i(CTCCH *ch, UINT port) {
   
         REG8    scale;  
   
         port &= 3;          port &= 3;
         if (port != 3) {          if (port != 3) {
                 return(ch->basecnt[port]);                  return(ch->basecnt[port]);
         }          }
         else {          else {
                 ctcstep(ch);                  ctcstep(ch);
                 scale = 0;                  return((REG8)(ch->count[3] >> ch->scale[3]));
                 if (!(ch->cmd[3] & 0x40)) {  
                         if (ch->cmd[3] & 0x20) {  
                                 scale = 8;  
                         }  
                         else {  
                                 scale = 4;  
                         }  
                 }  
                 return((REG8)(ch->count[3] >> scale));  
         }          }
 }  }
   
Line 316  void ctc_reset(void) { Line 316  void ctc_reset(void) {
                 ctc.ch[i].num = (UINT8)i;                  ctc.ch[i].num = (UINT8)i;
                 for (j=0; j<4; j++) {                  for (j=0; j<4; j++) {
                         ctc.ch[i].cmd[j] = 0x03;                          ctc.ch[i].cmd[j] = 0x03;
                           ctc.ch[i].scale[j] = 8;
                         ctc.ch[i].count[j] = 256 << 8;                          ctc.ch[i].count[j] = 256 << 8;
                         ctc.ch[i].countmax[j] = 256 << 8;                          ctc.ch[i].countmax[j] = 256 << 8;
                 }                  }

Removed from v.1.7  
changed lines
  Added in v.1.8


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