コード例 #1
0
ファイル: timer.cs プロジェクト: DarrenRainey/xnamame036
 public static void timer_remove(timer_entry timer)
 {
     timer_list_remove(timer);
     timer.next = timer_free_head;
     timer_free_head = timer;
 }
コード例 #2
0
ファイル: timer.cs プロジェクト: DarrenRainey/xnamame036
            /*
             *		adjust the current CPU's timer so that a new event will fire at the right time
             */
            public static void timer_adjust(timer_entry timer, double time, double period)
            {
                int newicount, diff;

                /* compute a new icount for the current CPU */
                if (period == TIME_NOW)
                    newicount = 0;
                else
                    newicount = (int)((timer.expire - time) * cpudata[activecpu].sec_to_cycles) + 1;

                /* determine if we're scheduled to run more cycles */
                diff = cpudata[activecpu].icount[0] - newicount;

                /* if so, set the new icount and compute the amount of "lost" time */
                if (diff > 0)
                {
                    cpudata[activecpu].lost += diff;
                    if (cpudata[activecpu].burn != null)
                        cpudata[activecpu].burn(diff);  /* let the CPU burn the cycles */
                    else
                        cpudata[activecpu].icount[0] = newicount;  /* CPU doesn't care */
                }
            }
コード例 #3
0
ファイル: timer.cs プロジェクト: DarrenRainey/xnamame036
 public static double timer_firetime(timer_entry which)
 {
     timer_entry timer = (timer_entry)which;
     return global_offset + timer.expire;
 }
コード例 #4
0
ファイル: timer.cs プロジェクト: DarrenRainey/xnamame036
            public static bool timer_schedule_cpu(ref int cpu, ref int cycles)
            {
                double end;

                /* then see if there are any CPUs that aren't suspended and haven't yet been updated */
                if (pick_cpu(ref cpu, ref cycles, timer_head.expire) )
                    return true;

                /* everyone is up-to-date; expire any timers now */
                end = timer_head.expire;
                while (timer_head.expire <= end)
                {
                    timer_entry timer = timer_head;

                    /* the base time is now the time of the timer */
                    base_time = timer.expire;

                    /* set the global state of which callback we're in */
                    callback_timer_modified = 0;
                    callback_timer = timer;

                    /* call the callback */
                    if (timer.callback != null)
                    {
                        timer.callback(timer.callback_param);
                    }

                    /* clear the callback timer global */
                    callback_timer = null;

                    /* reset or remove the timer, but only if it wasn't modified during the callback */
                    if (callback_timer_modified == 0)
                    {
                        if (timer.period != 0)
                        {
                            timer.start = timer.expire;
                            timer.expire += timer.period;

                            timer_list_remove(timer);
                            timer_list_insert(timer);
                        }
                        else
                            timer_remove(timer);
                    }
                }

                /* reset scheduling so it starts with CPU 0 */
                last_activecpu = lastcpu;

                /* go back to scheduling */
                return pick_cpu(ref cpu, ref cycles, timer_head.expire);
            }
コード例 #5
0
ファイル: timer.cs プロジェクト: DarrenRainey/xnamame036
            public static double timer_timeleft(timer_entry which)
            {
                double time = getabsolutetime();
                timer_entry timer = (timer_entry)which;

                return timer.expire - time;
            }
コード例 #6
0
ファイル: timer.cs プロジェクト: DarrenRainey/xnamame036
 public static double timer_starttime(timer_entry which)
 {
     timer_entry timer = (timer_entry)which;
     return global_offset + timer.start;
 }
コード例 #7
0
ファイル: timer.cs プロジェクト: DarrenRainey/xnamame036
            public static int timer_enable(timer_entry which, int enable)
            {
                timer_entry timer = (timer_entry)which;
                int old;

#if VERBOSE
		if (enable) verbose_print("T=%.6g: Enabled %08X\n", getabsolutetime() + global_offset, timer);
		else verbose_print("T=%.6g: Disabled %08X\n", getabsolutetime() + global_offset, timer);
#endif

                /* set the enable flag */
                old = timer.enabled;
                timer.enabled = enable;

                /* remove the timer and insert back into the list */
                timer_list_remove(timer);
                timer_list_insert(timer);

                return old;
            }
コード例 #8
0
ファイル: timer.cs プロジェクト: DarrenRainey/xnamame036
            public static double timer_timeelapsed(timer_entry which)
            {
                double time = getabsolutetime();
                timer_entry timer = (timer_entry)which;

                return time - timer.start;
            }
コード例 #9
0
ファイル: timer.cs プロジェクト: DarrenRainey/xnamame036
            public static void timer_remove(object which)
            {
                timer_entry timer = (timer_entry)which;

                /* remove it from the list */
                timer_list_remove(timer);

                /* free it up by adding it back to the free list */
                timer.next = timer_free_head;
                timer_free_head = timer;

#if VERBOSE
		verbose_print("T=%.6g: Removed %08X\n", getabsolutetime() + global_offset, timer);
#endif
            }
コード例 #10
0
ファイル: timer.cs プロジェクト: DarrenRainey/xnamame036
            public static void timer_init()
            {
                /* keep a local copy of how many total CPU's */
                lastcpu = cpu_gettotalcpu() - 1;

                /* we need to wait until the first call to timer_cyclestorun before using real CPU times */
                base_time = 0.0;
                global_offset = 0.0;
                callback_timer = null;
                callback_timer_modified = 0;

                /* reset the timers */
                //memset(timers, 0, sizeof(timers));
                for (int i = 0; i < MAX_TIMERS; i++)
                    timers[i] = new timer_entry();

                /* initialize the lists */
                timer_head = null;
                timer_free_head = timers[0];
                for (int i = 0; i < MAX_TIMERS - 1; i++)
                    timers[i].next = timers[i + 1];

                /* reset the CPU timers */
                //memset(cpudata, 0, sizeof(cpudata));
                for (int i = 0; i < cpudata.Length; i++)
                    cpudata[i] = new cpu_entry();
                activecpu = -1;
                last_activecpu = lastcpu;

                /* compute the cycle times */
                for (int i = 0; i <= lastcpu; i++)
                {
                    /* make a pointer to this CPU's interface functions */
                    cpudata[i].icount = cpuintf[Machine.drv.cpu[i].cpu_type & ~CPU_FLAGS_MASK].icount;
                    cpudata[i].burn = cpuintf[Machine.drv.cpu[i].cpu_type & ~CPU_FLAGS_MASK].burn;

                    /* get the CPU's overclocking factor */
                    cpudata[i].overclock = cpuintf[Machine.drv.cpu[i].cpu_type & ~CPU_FLAGS_MASK].overclock;

                    /* everyone is active but suspended by the reset line until further notice */
                    cpudata[i].suspended = SUSPEND_REASON_RESET;

                    /* set the CPU index */
                    cpudata[i].index = i;

                    /* compute the cycle times */
                    cpudata[i].sec_to_cycles = sec_to_cycles[i] = cpudata[i].overclock * Machine.drv.cpu[i].cpu_clock;
                    cpudata[i].cycles_to_sec = cycles_to_sec[i] = 1.0 / sec_to_cycles[i];
                }
            }
コード例 #11
0
ファイル: timer.cs プロジェクト: DarrenRainey/xnamame036
 public static void timer_list_remove(timer_entry timer)
 {
     /* remove it from the list */
     if (timer.prev != null)
         timer.prev.next = timer.next;
     else
         timer_head = timer.next;
     if (timer.next != null)
         timer.next.prev = timer.prev;
 }
コード例 #12
0
ファイル: timer.cs プロジェクト: DarrenRainey/xnamame036
            /*
             *		insert a new timer into the list at the appropriate location
             */
            public static void timer_list_insert(timer_entry timer)
            {
                double expire = timer.enabled != 0 ? timer.expire : TIME_NEVER;
                timer_entry t, lt = null;

                /* loop over the timer list */
                for (t = timer_head; t != null; lt = t, t = t.next)
                {
                    /* if the current list entry expires after us, we should be inserted before it */
                    /* note that due to floating point rounding, we need to allow a bit of slop here */
                    /* because two equal entries -- within rounding precision -- need to sort in */
                    /* the order they were inserted into the list */
                    if ((t.expire - expire) > TIME_IN_NSEC(1))
                    {
                        /* link the new guy in before the current list entry */
                        timer.prev = t.prev;
                        timer.next = t;

                        if (t.prev != null)
                            t.prev.next = timer;
                        else
                            timer_head = timer;
                        t.prev = timer;
                        return;
                    }
                }

                /* need to insert after the last one */
                if (lt != null)
                    lt.next = timer;
                else
                    timer_head = timer;
                timer.prev = lt;
                timer.next = null;
            }
コード例 #13
0
ファイル: timer.cs プロジェクト: DarrenRainey/xnamame036
            /*
             *		allocate a new timer
             */
            public static timer_entry timer_new()
            {
                timer_entry timer;

                /* remove an empty entry */
                if (timer_free_head == null)
                    return null;
                timer = timer_free_head;
                timer_free_head = timer.next;

                return timer;
            }