Пример #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);
                }
            }
        }
Пример #2
0
        private static long throttle_until_ticks(long target_ticks)
        {
            long minimum_sleep = Wintime.ticks_per_second / 1000;
            long current_ticks = Wintime.osd_ticks();
            long new_ticks;

            while (current_ticks < target_ticks)
            {
                long delta;
                bool slept = false;
                delta = (target_ticks - current_ticks) * 1000 / (1000 + average_oversleep);
                if (delta >= minimum_sleep)
                {
                    Wintime.osd_sleep(delta);
                    slept = true;
                }
                new_ticks = Wintime.osd_ticks();
                if (slept)
                {
                    long actual_ticks = new_ticks - current_ticks;
                    if (actual_ticks > delta)
                    {
                        long oversleep_milliticks = 1000 * (actual_ticks - delta) / delta;
                        average_oversleep = (average_oversleep * 99 + oversleep_milliticks) / 100;
                    }
                }
                current_ticks = new_ticks;
            }
            return(current_ticks);
        }
Пример #3
0
        public static void GDIDraw()
        {
            try
            {
                bitmapData = bitmapGDI.LockBits(new Rectangle(0, 0, Video.fullwidth, Video.fullheight), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
                Marshal.Copy(Video.bitmapcolor, 0, bitmapData.Scan0, Video.fullwidth * Video.fullheight);
                bitmapGDI.UnlockBits(bitmapData);
                if (Wintime.osd_ticks() < popup_text_end)
                {
                    Machine.FORM.tsslStatus.Text = sDrawText;
                }
                else
                {
                    popup_text_end = 0;
                    if (Mame.paused)
                    {
                        Machine.FORM.tsslStatus.Text = "pause";
                    }
                    else
                    {
                        switch (Mame.playState)
                        {
                        case Mame.PlayState.PLAY_RECORDRUNNING:
                            Machine.FORM.tsslStatus.Text = "record";
                            break;

                        case Mame.PlayState.PLAY_REPLAYRUNNING:
                            Machine.FORM.tsslStatus.Text = "replay";
                            break;

                        default:
                            Machine.FORM.tsslStatus.Text = "run";
                            break;
                        }
                    }
                }
                bbmp[iMode] = (Bitmap)bitmapGDI.Clone(new Rectangle(offsetx, offsety, width, height), PixelFormat.Format32bppArgb);
                switch (Machine.sDirection)
                {
                case "":
                    break;

                case "90":
                    bbmp[iMode].RotateFlip(RotateFlipType.Rotate90FlipNone);
                    break;

                case "180":
                    bbmp[iMode].RotateFlip(RotateFlipType.Rotate180FlipNone);
                    break;

                case "270":
                    bbmp[iMode].RotateFlip(RotateFlipType.Rotate270FlipNone);
                    break;
                }
                Machine.FORM.pictureBox1.Image = bbmp[iMode];
            }
            catch
            {
            }
        }
Пример #4
0
        private static void handle_load()
        {
            sHandle2 = GetForegroundWindow().ToString();
            if (sHandle1 == sHandle2)
            {
                is_foreground = true;
            }
            else
            {
                is_foreground = false;
            }
            if (is_foreground)
            {
                Video.sDrawText      = "Select position to load from";
                Video.popup_text_end = Wintime.osd_ticks() + Wintime.ticks_per_second * 1000;

                /*if (Keyboard.IsTriggered(Key.Escape))
                 * {
                 *  Video.sDrawText = "Load cancelled";
                 *  Video.popup_text_end = Wintime.osd_ticks() + Wintime.ticks_per_second * 2;
                 *  playState = PlayState.PLAY_RUNNING;
                 *  mame_pause(false);
                 *  UI.ui_handler_callback = UI.handler_ingame;
                 *  return;
                 * }*/
                char file;
                //foreach (Key key1 in Inptport.lk)
                //{

                /*if (Keyboard.IsTriggered(key1))
                 * {
                 *  file = Inptport.getcharbykey(key1);
                 *  if (!File.Exists("sta\\" + Machine.sName + "\\" + file + ".sta"))
                 *  {
                 *      Video.sDrawText = "Load fail";
                 *      Video.popup_text_end = Wintime.osd_ticks() + Wintime.ticks_per_second * 2;
                 *      playState = PlayState.PLAY_RUNNING;
                 *      Thread.Sleep(500);
                 *      mame_pause(false);
                 *      UI.ui_handler_callback = UI.handler_ingame;
                 *      return;
                 *  }
                 *  FileStream fs1 = new FileStream("sta\\" + Machine.sName + "\\" + file + ".sta", FileMode.Open);
                 *  BinaryReader br1 = new BinaryReader(fs1);
                 *  State.loadstate_callback(br1);
                 *  br1.Close();
                 *  fs1.Close();
                 *  postload();
                 *  Video.sDrawText = "Load from position " + file;
                 *  Video.popup_text_end = Wintime.osd_ticks() + Wintime.ticks_per_second * 2;
                 *  playState = PlayState.PLAY_RUNNING;
                 *  UI.ui_handler_callback = UI.handler_ingame;
                 *  Thread.Sleep(500);
                 *  mame_pause(false);
                 *  return;
                 * }*/
                // }
            }
        }
Пример #5
0
        private static void handle_save()
        {
            sHandle2 = GetForegroundWindow().ToString();
            if (sHandle1 == sHandle2)
            {
                is_foreground = true;
            }
            else
            {
                is_foreground = false;
            }
            if (is_foreground)
            {
                Video.sDrawText      = "Select position to save to";
                Video.popup_text_end = Wintime.osd_ticks() + Wintime.ticks_per_second * 1000;

                /*if (Keyboard.IsTriggered(Key.Escape))
                 * {
                 *  Video.sDrawText = "Save cancelled";
                 *  Video.popup_text_end = Wintime.osd_ticks() + Wintime.ticks_per_second * 2;
                 *  playState = PlayState.PLAY_RUNNING;
                 *  mame_pause(false);
                 *  UI.ui_handler_callback = UI.handler_ingame;
                 *  return;
                 * }
                 * char file;
                 * foreach(Key key1 in Inptport.lk)
                 * {
                 *  if (Keyboard.IsTriggered(key1))
                 *  {
                 *      file = Inptport.getcharbykey(key1);
                 *      if (!Directory.Exists("sta\\" + Machine.sName))
                 *      {
                 *          Directory.CreateDirectory("sta\\" + Machine.sName);
                 *      }
                 *      FileStream fs1 = new FileStream("sta\\" + Machine.sName + "\\" + file + ".sta", FileMode.Create);
                 *      BinaryWriter bw1 = new BinaryWriter(fs1);
                 *      State.savestate_callback(bw1);
                 *      bw1.Close();
                 *      fs1.Close();
                 *      Video.sDrawText = "Save to position " + file;
                 *      Video.popup_text_end = Wintime.osd_ticks() + Wintime.ticks_per_second * 2;
                 *      playState = PlayState.PLAY_RUNNING;
                 *      UI.ui_handler_callback = UI.handler_ingame;
                 *      Thread.Sleep(500);
                 *      mame_pause(false);
                 *      return;
                 *  }
                 * }*/
            }
        }
Пример #6
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;
        }
Пример #7
0
        private static void handle_replay()
        {
            sHandle2 = GetForegroundWindow().ToString();
            if (sHandle1 == sHandle2)
            {
                is_foreground = true;
            }
            else
            {
                is_foreground = false;
            }
            if (is_foreground)
            {
                if (playState == PlayState.PLAY_REPLAYSTART)
                {
                    Video.sDrawText      = "Select position to replay from";
                    Video.popup_text_end = Wintime.osd_ticks() + Wintime.ticks_per_second * 1000;

                    /*if (Keyboard.IsTriggered(Key.Escape))
                     * {
                     *  Video.sDrawText = "Replay cancelled";
                     *  Video.popup_text_end = Wintime.osd_ticks() + Wintime.ticks_per_second * 2;
                     *  playState = PlayState.PLAY_RUNNING;
                     *  mame_pause(false);
                     *  UI.ui_handler_callback = UI.handler_ingame;
                     *  return;
                     * }*/
                    char file;
                    //foreach (Key key1 in Inptport.lk)
                    //{

                    /*if (Keyboard.IsTriggered(key1))
                     * {
                     *  file = Inptport.getcharbykey(key1);
                     *  if (!File.Exists("inp\\" + Machine.sName + "\\" + file + ".sta") || !File.Exists("inp\\" + Machine.sName + "\\" + file + ".inp"))
                     *  {
                     *      Video.sDrawText = "Replay fail";
                     *      Video.popup_text_end = Wintime.osd_ticks() + Wintime.ticks_per_second * 2;
                     *      playState = PlayState.PLAY_RUNNING;
                     *      Thread.Sleep(500);
                     *      mame_pause(false);
                     *      UI.ui_handler_callback = UI.handler_ingame;
                     *      return;
                     *  }
                     *  if (bwRecord != null)
                     *  {
                     *      bwRecord.Close();
                     *      bwRecord = null;
                     *  }
                     *  if (fsRecord != null)
                     *  {
                     *      fsRecord.Close();
                     *      fsRecord = null;
                     *  }
                     *  if (brRecord != null)
                     *  {
                     *      brRecord.Close();
                     *      brRecord = null;
                     *  }
                     *  FileStream fs1 = new FileStream("inp\\" + Machine.sName + "\\" + file + ".sta", FileMode.Open);
                     *  BinaryReader br1 = new BinaryReader(fs1);
                     *  State.loadstate_callback(br1);
                     *  br1.Close();
                     *  fs1.Close();
                     *  postload();
                     *  fsRecord = new FileStream("inp\\" + Machine.sName + "\\" + file + ".inp", FileMode.Open);
                     *  brRecord = new BinaryReader(fsRecord);
                     *  Memory.memory_reset();
                     *  Inptport.bReplayRead = true;
                     *  Inptport.replay_port_callback();
                     *  Video.sDrawText = "Replay from position " + file;
                     *  Video.popup_text_end = Wintime.osd_ticks() + Wintime.ticks_per_second * 2;
                     *  playState = PlayState.PLAY_REPLAYRUNNING;
                     *  UI.ui_handler_callback = UI.handler_ingame;
                     *  Thread.Sleep(500);
                     *  mame_pause(false);
                     *  return;
                     * }*/
                    // }
                }
            }
            if (playState == PlayState.PLAY_REPLAYEND)
            {
                Video.sDrawText      = "Replay end";
                Video.popup_text_end = Wintime.osd_ticks() + Wintime.ticks_per_second * 2;
                brRecord.Close();
                brRecord  = null;
                playState = PlayState.PLAY_RUNNING;
            }
        }
Пример #8
0
        private static void handle_record()
        {
            sHandle2 = GetForegroundWindow().ToString();
            if (sHandle1 == sHandle2)
            {
                is_foreground = true;
            }
            else
            {
                is_foreground = false;
            }
            if (is_foreground)
            {
                if (playState == PlayState.PLAY_RECORDSTART)
                {
                    Video.sDrawText      = "Select position to record to";
                    Video.popup_text_end = Wintime.osd_ticks() + Wintime.ticks_per_second * 1000;

                    /*if (Keyboard.IsTriggered(Key.Escape))
                     * {
                     *  Video.sDrawText = "Record cancelled";
                     *  Video.popup_text_end = Wintime.osd_ticks() + Wintime.ticks_per_second * 2;
                     *  playState = PlayState.PLAY_RUNNING;
                     *  mame_pause(false);
                     *  UI.ui_handler_callback = UI.handler_ingame;
                     *  return;
                     * } */
                    char file;
                    //foreach (Key key1 in Inptport.lk)
                    // {

                    /*if (Keyboard.IsTriggered(key1))
                     * {
                     *  file = Inptport.getcharbykey(key1);
                     *  if (!Directory.Exists("inp\\" + Machine.sName))
                     *  {
                     *      Directory.CreateDirectory("inp\\" + Machine.sName);
                     *  }
                     *  FileStream fs1 = new FileStream("inp\\" + Machine.sName + "\\" + file + ".sta", FileMode.Create);
                     *  BinaryWriter bw1 = new BinaryWriter(fs1);
                     *  State.savestate_callback(bw1);
                     *  bw1.Close();
                     *  fs1.Close();
                     *  if (bwRecord != null)
                     *  {
                     *      bwRecord.Close();
                     *      bwRecord = null;
                     *  }
                     *  FileStream fs2 = new FileStream("inp\\" + Machine.sName + "\\" + file + ".inp", FileMode.Create);
                     *  bwRecord = new BinaryWriter(fs2);
                     *  Memory.memory_reset2();
                     *  Inptport.record_port_callback();
                     *  Video.sDrawText = "Record to position " + file;
                     *  Video.popup_text_end = Wintime.osd_ticks() + Wintime.ticks_per_second * 2;
                     *  playState = PlayState.PLAY_RECORDRUNNING;
                     *  UI.ui_handler_callback = UI.handler_ingame;
                     *  Thread.Sleep(500);
                     *  mame_pause(false);
                     *  return;
                     * }*/
                    //}
                }
                else if (playState == PlayState.PLAY_RECORDEND)
                {
                    Video.sDrawText      = "Record end";
                    Video.popup_text_end = Wintime.osd_ticks() + Wintime.ticks_per_second * 2;
                    bwRecord.Close();
                    bwRecord  = null;
                    playState = PlayState.PLAY_RUNNING;
                }
            }
        }