Diff for /np2/nevent.c between versions 1.3 and 1.9

version 1.3, 2003/10/25 11:37:40 version 1.9, 2011/01/15 18:04:42
Line 1 Line 1
 #include        "compiler.h"  #include        "compiler.h"
 #include        "i286.h"  #include        "cpucore.h"
 #include        "pccore.h"  #include        "pccore.h"
   
   
         _NEVENT         nevent;          _NEVENT         nevent;
   
   
 void nevent_init(void) {  void nevent_allreset(void) {
   
         // すべてをリセット          // すべてをリセット
         ZeroMemory(&nevent, sizeof(nevent));          ZeroMemory(&nevent, sizeof(nevent));
Line 16  void nevent_get1stevent(void) { Line 16  void nevent_get1stevent(void) {
   
         // 最短のイベントのクロック数をセット          // 最短のイベントのクロック数をセット
         if (nevent.readyevents) {          if (nevent.readyevents) {
                 I286_BASECLOCK = nevent.item[nevent.level[0]].clock;                  CPU_BASECLOCK = nevent.item[nevent.level[0]].clock;
         }          }
         else {          else {
                 // イベントがない場合のクロック数をセット                  // イベントがない場合のクロック数をセット
                 I286_BASECLOCK = NEVENT_MAXCLOCK;                  CPU_BASECLOCK = NEVENT_MAXCLOCK;
         }          }
   
         // カウンタへセット          // カウンタへセット
         I286_REMCLOCK = I286_BASECLOCK;          CPU_REMCLOCK = CPU_BASECLOCK;
 }  }
   
 static void nevent_execute(void) {  static void nevent_execute(void) {
Line 64  void nevent_progress(void) { Line 64  void nevent_progress(void) {
         UINT            curid;          UINT            curid;
         NEVENTITEM      item;          NEVENTITEM      item;
   
         I286_CLOCK += I286_BASECLOCK;          CPU_CLOCK += CPU_BASECLOCK;
         eventnum = 0;          eventnum = 0;
         nextbase = NEVENT_MAXCLOCK;          nextbase = NEVENT_MAXCLOCK;
         for (i=0; i<nevent.readyevents; i++) {          for (i=0; i<nevent.readyevents; i++) {
                 curid = nevent.level[i];                  curid = nevent.level[i];
                 item = &nevent.item[curid];                  item = &nevent.item[curid];
                 item->clock -= I286_BASECLOCK;                  item->clock -= CPU_BASECLOCK;
                 if (item->clock > 0) {                  if (item->clock > 0) {
                         // イベント待ち中                          // イベント待ち中
                         nevent.level[eventnum++] = curid;                          nevent.level[eventnum++] = curid;
Line 85  void nevent_progress(void) { Line 85  void nevent_progress(void) {
                         }                          }
                         item->flag |= NEVENT_SETEVENT;                          item->flag |= NEVENT_SETEVENT;
                         item->flag &= ~(NEVENT_ENABLE);                          item->flag &= ~(NEVENT_ENABLE);
   //                      TRACEOUT(("event = %x", curid));
                 }                  }
         }          }
         nevent.readyevents = eventnum;          nevent.readyevents = eventnum;
         I286_BASECLOCK = nextbase;          CPU_BASECLOCK = nextbase;
         I286_REMCLOCK += nextbase;          CPU_REMCLOCK += nextbase;
         nevent_execute();          nevent_execute();
 //      TRACEOUT((buf, "nextbase = %d (%d)", nextbase, I286_REMCLOCK));  //      TRACEOUT(("nextbase = %d (%d)", nextbase, CPU_REMCLOCK));
 }  }
   
   
Line 137  void nevent_waitreset(UINT id) { Line 138  void nevent_waitreset(UINT id) {
   
 void nevent_set(UINT id, SINT32 eventclock, NEVENTCB proc, BOOL absolute) {  void nevent_set(UINT id, SINT32 eventclock, NEVENTCB proc, BOOL absolute) {
   
         SINT32          clock;          SINT32          clk;
         NEVENTITEM      item;          NEVENTITEM      item;
         UINT            eventid;          UINT            eventid;
         UINT            i;          UINT            i;
   
         clock = I286_BASECLOCK - I286_REMCLOCK;  //      TRACEOUT(("event %d - %xclocks", id, eventclock));
   
           clk = CPU_BASECLOCK - CPU_REMCLOCK;
         item = &nevent.item[id];          item = &nevent.item[id];
         item->proc = proc;          item->proc = proc;
         item->flag = 0;          item->flag = 0;
         if (absolute) {          if (absolute) {
                 item->clock = eventclock + clock;                  item->clock = eventclock + clk;
         }          }
         else {          else {
                 item->clock += eventclock;                  item->clock += eventclock;
         }          }
 #if 0  #if 0
         if (item->clock < clock) {          if (item->clock < clk) {
                 item->clock = clock;                  item->clock = clk;
         }          }
 #endif  #endif
         // イベントの削除          // イベントの削除
Line 176  void nevent_set(UINT id, SINT32 eventclo Line 179  void nevent_set(UINT id, SINT32 eventclo
   
         // もし最短イベントだったら...          // もし最短イベントだったら...
         if (eventid == 0) {          if (eventid == 0) {
                 clock = I286_BASECLOCK - item->clock;                  clk = CPU_BASECLOCK - item->clock;
                 I286_BASECLOCK -= clock;                  CPU_BASECLOCK -= clk;
                 I286_REMCLOCK -= clock;                  CPU_REMCLOCK -= clk;
 //              TRACEOUT(("reset nextbase -%d (%d)", clock, I286_REMCLOCK));  //              TRACEOUT(("reset nextbase -%d (%d)", clock, CPU_REMCLOCK));
         }          }
 }  }
   
 void nevent_setbyms(UINT id, SINT32 ms, NEVENTCB proc, BOOL absolute) {  void nevent_setbyms(UINT id, SINT32 ms, NEVENTCB proc, BOOL absolute) {
   
         nevent_set(id, (pc.realclock / 1000) * ms, proc, absolute);          nevent_set(id, (pccore.realclock / 1000) * ms, proc, absolute);
 }  }
   
 BOOL nevent_iswork(UINT id) {  BOOL nevent_iswork(UINT id) {
Line 208  SINT32 nevent_getremain(UINT id) { Line 211  SINT32 nevent_getremain(UINT id) {
         // 現在進行してるイベントを検索          // 現在進行してるイベントを検索
         for (i=0; i<nevent.readyevents; i++) {          for (i=0; i<nevent.readyevents; i++) {
                 if (nevent.level[i] == id) {                  if (nevent.level[i] == id) {
                         return(nevent.item[id].clock - (I286_BASECLOCK - I286_REMCLOCK));                          return(nevent.item[id].clock - (CPU_BASECLOCK - CPU_REMCLOCK));
                 }                  }
         }          }
         return(-1);          return(-1);
Line 216  SINT32 nevent_getremain(UINT id) { Line 219  SINT32 nevent_getremain(UINT id) {
   
 void nevent_forceexit(void) {  void nevent_forceexit(void) {
   
         if (I286_REMCLOCK > 0) {          if (CPU_REMCLOCK > 0) {
                 I286_BASECLOCK -= I286_REMCLOCK;                  CPU_BASECLOCK -= CPU_REMCLOCK;
                 I286_REMCLOCK = 0;                  CPU_REMCLOCK = 0;
         }          }
 }  }
   

Removed from v.1.3  
changed lines
  Added in v.1.9


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