--- np2/nevent.c 2003/10/16 17:57:06 1.1.1.1 +++ np2/nevent.c 2011/01/15 18:04:42 1.9 @@ -1,11 +1,12 @@ #include "compiler.h" +#include "cpucore.h" #include "pccore.h" _NEVENT nevent; -void nevent_init(void) { +void nevent_allreset(void) { // すべてをリセット ZeroMemory(&nevent, sizeof(nevent)); @@ -15,15 +16,15 @@ void nevent_get1stevent(void) { // 最短のイベントのクロック数をセット if (nevent.readyevents) { - nevent.baseclock = nevent.item[nevent.level[0]].clock; + CPU_BASECLOCK = nevent.item[nevent.level[0]].clock; } else { // イベントがない場合のクロック数をセット - nevent.baseclock = NEVENT_MAXCLOCK; + CPU_BASECLOCK = NEVENT_MAXCLOCK; } // カウンタへセット - nevent.remainclock = nevent.baseclock; + CPU_REMCLOCK = CPU_BASECLOCK; } static void nevent_execute(void) { @@ -63,13 +64,13 @@ void nevent_progress(void) { UINT curid; NEVENTITEM item; - nevent.clock += nevent.baseclock; + CPU_CLOCK += CPU_BASECLOCK; eventnum = 0; nextbase = NEVENT_MAXCLOCK; for (i=0; iclock -= nevent.baseclock; + item->clock -= CPU_BASECLOCK; if (item->clock > 0) { // イベント待ち中 nevent.level[eventnum++] = curid; @@ -84,13 +85,14 @@ void nevent_progress(void) { } item->flag |= NEVENT_SETEVENT; item->flag &= ~(NEVENT_ENABLE); +// TRACEOUT(("event = %x", curid)); } } nevent.readyevents = eventnum; - nevent.baseclock = nextbase; - nevent.remainclock += nextbase; + CPU_BASECLOCK = nextbase; + CPU_REMCLOCK += nextbase; nevent_execute(); -// TRACEOUT((buf, "nextbase = %d (%d)", nextbase, nevent.remainclock)); +// TRACEOUT(("nextbase = %d (%d)", nextbase, CPU_REMCLOCK)); } @@ -136,24 +138,26 @@ void nevent_waitreset(UINT id) { void nevent_set(UINT id, SINT32 eventclock, NEVENTCB proc, BOOL absolute) { - SINT32 clock; + SINT32 clk; NEVENTITEM item; UINT eventid; UINT i; - clock = nevent.baseclock - nevent.remainclock; +// TRACEOUT(("event %d - %xclocks", id, eventclock)); + + clk = CPU_BASECLOCK - CPU_REMCLOCK; item = &nevent.item[id]; item->proc = proc; item->flag = 0; if (absolute) { - item->clock = eventclock + clock; + item->clock = eventclock + clk; } else { item->clock += eventclock; } #if 0 - if (item->clock < clock) { - item->clock = clock; + if (item->clock < clk) { + item->clock = clk; } #endif // イベントの削除 @@ -175,16 +179,16 @@ void nevent_set(UINT id, SINT32 eventclo // もし最短イベントだったら... if (eventid == 0) { - clock = nevent.baseclock - item->clock; - nevent.baseclock -= clock; - nevent.remainclock -= clock; -// TRACEOUT(("reset nextbase -%d (%d)", clock, nevent.remainclock)); + clk = CPU_BASECLOCK - item->clock; + CPU_BASECLOCK -= clk; + CPU_REMCLOCK -= clk; +// TRACEOUT(("reset nextbase -%d (%d)", clock, CPU_REMCLOCK)); } } 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) { @@ -207,8 +211,7 @@ SINT32 nevent_getremain(UINT id) { // 現在進行してるイベントを検索 for (i=0; i 0) { - nevent.baseclock -= nevent.remainclock; - nevent.remainclock = 0; + if (CPU_REMCLOCK > 0) { + CPU_BASECLOCK -= CPU_REMCLOCK; + CPU_REMCLOCK = 0; } }