/// <summary> /// Start /// </summary> public void Start() { InitializeTimer(); _localTime = AttoTime.TIME_ZERO; _th = new Thread(_Run); _th.IsBackground = true; _th.Start(); Task.Factory.StartNew(() => { bool running = true; Thread.Sleep(30000); while (running) { if (!Stopped && !InsideInterrupt) { Interrupt = (0x108 / 4) - 0x18; InterruptMaskLevel = Interrupt - 1; } Thread.Sleep(2000); running = false; } }); }
private void _ExecuteTimeslice() { AttoTime target = _timers[0].Expire; AttoTime tbase = _globalBaseTime; int ran0; AttoTime at0 = target - _localTime; CyclesRunning = (int)((at0.Seconds * CyclesPerSecond) + (at0.AttoSeconds / _attoseconds_per_cycle[0])); if (true)//CyclesRunning > 0) { CyclesStolen = 0; ran0 = ExecuteCycles(CyclesRunning); ran0 -= CyclesStolen; _totalcycles += (ulong)ran0; _localTime = _localTime + new AttoTime((int)(ran0 / CyclesPerSecond), ran0 * _attoseconds_per_cycle[0]); if (_localTime < target) { if (_localTime > tbase) { target = _localTime; } else { target = tbase; } } } TimerSetGlobalTime(target); }
public static AttoTime operator +(AttoTime first, AttoTime second) { var result = new AttoTime(); /* if one of the items is Attotime_never, return Attotime_never */ if (first.Seconds >= TIME_MAX_SECONDS || second.Seconds >= TIME_MAX_SECONDS) { return(AttoTime.TIME_NEVER); } /* add the seconds and Attoseconds */ result.AttoSeconds = first.AttoSeconds + second.AttoSeconds; result.Seconds = first.Seconds + second.Seconds; /* normalize and return */ if (result.AttoSeconds >= AttoTime.SECONDS_PER_SECOND) { result.AttoSeconds -= AttoTime.SECONDS_PER_SECOND; result.Seconds++; } /* overflow */ if (result.Seconds >= AttoTime.TIME_MAX_SECONDS) { return(AttoTime.TIME_NEVER); } return(result); }
/// <summary> /// TimerAllocateCommon /// </summary> /// <param name="callback"></param> /// <param name="func"></param> /// <param name="temp"></param> /// <returns></returns> internal Timer TimerAllocateCommon(TimerFiredDelegate callback, string func, bool temp) { AttoTime time = GetCurrentTime(); var timer = new Timer(); timer.Callback = callback; timer.Enabled = false; timer.Temporary = temp; timer.Period = AttoTime.TIME_ZERO; timer.Func = func; timer.Start = time; timer.Expire = AttoTime.TIME_NEVER; TimerListInsert(timer); return(timer); }
internal void TimerSetGlobalTime(AttoTime newbase) { Timer timer; _globalBaseTime = newbase; return; while (_timers[0].Expire <= _globalBaseTime) { bool was_enabled = _timers[0].Enabled; timer = _timers[0]; if (timer.Period == AttoTime.TIME_ZERO || timer.Period == AttoTime.TIME_NEVER) { timer.Enabled = false; } callback_timer_modified = false; callback_timer = timer; callback_timer_expire_time = timer.Expire; if (was_enabled && timer.Callback != null) { timer.Callback(); } callback_timer = null; if (callback_timer_modified == false) { if (timer.Temporary) { _TimerListRemove(timer); } else { timer.Start = timer.Expire; timer.Expire = timer.Expire + timer.Period; Sort(); } } } }
internal void TimerAdjustPeriodic(Timer which, AttoTime start_delay, AttoTime period) { AttoTime time = GetCurrentTime(); if (which == callback_timer) { callback_timer_modified = true; } which.Enabled = true; if (start_delay.Seconds < 0) { start_delay = AttoTime.TIME_ZERO; } which.Start = time; which.Expire = time + start_delay; which.Period = period; Sort(); if (_timers.IndexOf(which) == 0) { AbortTimeSlice(); } }
/// <summary> /// InitializeTimer /// </summary> public void InitializeTimer() { _globalBaseTime = AttoTime.TIME_ZERO; _timers = new List <Timer>(); }
private void InitTimers() { _timedIntPeriod = new AttoTime(0, (long)(1e18 / 250)); _timedint_timer = TimerAllocateCommon(_DoNothing, "cpunum_set_input_line_and_vector1002", false); TimerAdjustPeriodic(_timedint_timer, _timedIntPeriod, _timedIntPeriod); }