Ejemplo n.º 1
0
        private static void recompute_speed(Atime emutime)
        {
            long delta_emutime;

            if (speed_last_realtime == 0 || Mame.mame_is_paused())
            {
                speed_last_realtime = Wintime.osd_ticks();
                speed_last_emutime  = emutime;
            }
            delta_emutime = Attotime.attotime_to_attoseconds(Attotime.attotime_sub(emutime, speed_last_emutime));
            if (delta_emutime > Attotime.ATTOSECONDS_PER_SECOND / 4)
            {
                long realtime       = Wintime.osd_ticks();
                long delta_realtime = realtime - speed_last_realtime;
                long tps            = Wintime.ticks_per_second;
                speed_percent       = (double)delta_emutime * (double)tps / ((double)delta_realtime * (double)Attotime.ATTOSECONDS_PER_SECOND);
                speed_last_realtime = realtime;
                speed_last_emutime  = emutime;
                overall_valid_counter++;
                if (overall_valid_counter >= 4)
                {
                    overall_real_ticks += delta_realtime;
                    while (overall_real_ticks >= tps)
                    {
                        overall_real_ticks -= tps;
                        overall_real_seconds++;
                    }
                    overall_emutime = Attotime.attotime_add_attoseconds(overall_emutime, delta_emutime);
                }
            }
        }
Ejemplo n.º 2
0
        public static int video_screen_get_vpos()
        {
            long delta = Attotime.attotime_to_attoseconds(Attotime.attotime_sub(Timer.get_current_time(), screenstate.vblank_start_time));
            int  vpos;

            delta += screenstate.pixeltime / 2;
            vpos   = (int)(delta / screenstate.scantime);
            return((screenstate.visarea.max_y + 1 + vpos) % screenstate.height);
        }
Ejemplo n.º 3
0
        public static uint input_port_read_direct(analog_field_state analog)
        {
            uint result;
            int  value;
            long nsec_since_last;

            nsec_since_last = Attotime.attotime_to_attoseconds(Attotime.attotime_sub(Timer.get_current_time(), portdata.last_frame_time)) / Attotime.ATTOSECONDS_PER_NANOSECOND;
            value           = (int)(analog.previous + ((long)(analog.accum - analog.previous) * nsec_since_last / portdata.last_delta_nsec));
            result          = (uint)apply_analog_settings(value);
            return(result);
        }
Ejemplo n.º 4
0
        private static void update_throttle(Atime emutime)
        {
            long real_delta_attoseconds;
            long emu_delta_attoseconds;
            long real_is_ahead_attoseconds;
            long attoseconds_per_tick;
            long ticks_per_second;
            long target_ticks;
            long diff_ticks;

            ticks_per_second     = Wintime.ticks_per_second;
            attoseconds_per_tick = Attotime.ATTOSECONDS_PER_SECOND / ticks_per_second;
            if (Mame.mame_is_paused())
            {
                throttle_emutime  = Attotime.attotime_sub_attoseconds(emutime, Attotime.ATTOSECONDS_PER_SECOND / PAUSED_REFRESH_RATE);
                throttle_realtime = throttle_emutime;
            }
            emu_delta_attoseconds = Attotime.attotime_to_attoseconds(Attotime.attotime_sub(emutime, throttle_emutime));
            if (emu_delta_attoseconds < 0 || emu_delta_attoseconds > Attotime.ATTOSECONDS_PER_SECOND / 10)
            {
                goto resync;
            }
            diff_ticks           = Wintime.osd_ticks() - throttle_last_ticks;
            throttle_last_ticks += diff_ticks;
            if (diff_ticks >= ticks_per_second)
            {
                goto resync;
            }
            real_delta_attoseconds    = diff_ticks * attoseconds_per_tick;
            throttle_emutime          = emutime;
            throttle_realtime         = Attotime.attotime_add_attoseconds(throttle_realtime, real_delta_attoseconds);
            throttle_history          = (throttle_history << 1) | Convert.ToUInt32(emu_delta_attoseconds > real_delta_attoseconds);
            real_is_ahead_attoseconds = Attotime.attotime_to_attoseconds(Attotime.attotime_sub(throttle_emutime, throttle_realtime));
            if ((real_is_ahead_attoseconds < -Attotime.ATTOSECONDS_PER_SECOND / 10) || (real_is_ahead_attoseconds < 0 && popcount[throttle_history & 0xff] < 6))
            {
                goto resync;
            }
            if (real_is_ahead_attoseconds < 0)
            {
                return;
            }
            target_ticks         = throttle_last_ticks + real_is_ahead_attoseconds / attoseconds_per_tick;
            diff_ticks           = throttle_until_ticks(target_ticks) - throttle_last_ticks;
            throttle_last_ticks += diff_ticks;
            throttle_realtime    = Attotime.attotime_add_attoseconds(throttle_realtime, diff_ticks * attoseconds_per_tick);
            return;

resync:
            throttle_realtime = throttle_emutime = emutime;
        }
Ejemplo n.º 5
0
        /*public static bool video_screen_update_partial(int scanline)
         * {
         *  new_clip = screenstate.visarea;
         *  bool result = false;
         *  if (screenstate.last_partial_scan > new_clip.min_y)
         *  {
         *      new_clip.min_y = screenstate.last_partial_scan;
         *  }
         *  if (scanline < new_clip.max_y)
         *  {
         *      new_clip.max_y = scanline;
         *  }
         *  if (new_clip.min_y <= new_clip.max_y)
         *  {
         *      video_update_callback();
         *      result = true;
         *  }
         *  screenstate.last_partial_scan = scanline + 1;
         *  return result;
         * }*/
        /*public static int video_screen_get_vpos()
         * {
         *  long delta = Attotime.attotime_to_attoseconds(Attotime.attotime_sub(Timer.get_current_time(), screenstate.vblank_start_time));
         *  int vpos;
         *  delta += screenstate.pixeltime / 2;
         *  vpos = (int)(delta / screenstate.scantime);
         *  return (screenstate.visarea.max_y + 1 + vpos) % screenstate.height;
         * }*/
        public static Atime video_screen_get_time_until_pos(int vpos, int hpos)
        {
            long curdelta = Attotime.attotime_to_attoseconds(Attotime.attotime_sub(Timer.get_current_time(), screenstate.vblank_start_time));
            long targetdelta;

            //vpos += screenstate.height - (screenstate.visarea.max_y + 1);
            vpos       %= screenstate.height;
            targetdelta = vpos * screenstate.scantime + hpos * screenstate.pixeltime;
            if (targetdelta <= curdelta + screenstate.pixeltime / 2)
            {
                targetdelta += screenstate.frame_period;
            }
            while (targetdelta <= curdelta)
            {
                targetdelta += screenstate.frame_period;
            }
            return(new Atime(0, targetdelta - curdelta));
        }
Ejemplo n.º 6
0
        private static void frame_update()
        {
            Atime curtime = Timer.get_current_time();

            portdata.last_delta_nsec = Attotime.attotime_to_attoseconds(Attotime.attotime_sub(curtime, portdata.last_frame_time)) / Attotime.ATTOSECONDS_PER_NANOSECOND;
            portdata.last_frame_time = curtime;
            if (Mame.playState != Mame.PlayState.PLAY_REPLAYRUNNING)
            {
                if (Mame.is_foreground)
                {
                    loop_inputports_callback();
                }

                /*int i1 = (int)(Video.screenstate.frame_number % 4);
                 * if (i1 == 0)
                 * {
                 *  CPS.short1 = unchecked((short)0xfffb);
                 * }
                 * else if (i1 == 1)
                 * {
                 *  CPS.short1 = unchecked((short)0xffce);
                 * }
                 * else if (i1 == 2)
                 * {
                 *  CPS.short1 = unchecked((short)0xfff7);
                 * }
                 * else if (i1 == 3)
                 * {
                 *  CPS.short1 = unchecked((short)0xffcd);
                 * }*/
            }
            if (Mame.playState == Mame.PlayState.PLAY_RECORDRUNNING)
            {
                record_port_callback();
            }
            else if (Mame.playState == Mame.PlayState.PLAY_REPLAYRUNNING)
            {
                replay_port_callback();
            }
        }
Ejemplo n.º 7
0
        private static void frame_update()
        {
            Atime curtime = Timer.get_current_time();

            portdata.last_delta_nsec = Attotime.attotime_to_attoseconds(Attotime.attotime_sub(curtime, portdata.last_frame_time)) / Attotime.ATTOSECONDS_PER_NANOSECOND;
            portdata.last_frame_time = curtime;
            if (Mame.playState != Mame.PlayState.PLAY_REPLAYRUNNING)
            {
                if (Mame.is_foreground)
                {
                    loop_inputports_callback();
                }
            }
            if (Mame.playState == Mame.PlayState.PLAY_RECORDRUNNING)
            {
                record_port_callback();
            }
            else if (Mame.playState == Mame.PlayState.PLAY_REPLAYRUNNING)
            {
                replay_port_callback();
            }
        }