CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/Core/CoreTiming.h
Views: 1401
// Copyright (c) 2012- PPSSPP Project / Dolphin Project.12// This program is free software: you can redistribute it and/or modify3// it under the terms of the GNU General Public License as published by4// the Free Software Foundation, version 2.0 or later versions.56// This program is distributed in the hope that it will be useful,7// but WITHOUT ANY WARRANTY; without even the implied warranty of8// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the9// GNU General Public License 2.0 for more details.1011// A copy of the GPL 2.0 should have been included with the program.12// If not, see http://www.gnu.org/licenses/1314// Official git repository and contact information can be found at15// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.1617#pragma once1819#include <string>20#include "Common/CommonTypes.h"2122// This is a system to schedule events into the emulated machine's future. Time is measured23// in main CPU clock cycles.2425// To schedule an event, you first have to register its type. This is where you pass in the26// callback. You then schedule events using the type id you get back.2728// See HW/SystemTimers.cpp for the main part of Dolphin's usage of this scheduler.2930// The int cyclesLate that the callbacks get is how many cycles late it was.31// So to schedule a new event on a regular basis:32// inside callback:33// ScheduleEvent(periodInCycles - cyclesLate, callback, "whatever")3435class PointerWrap;3637//const int CPU_HZ = 222000000;38extern int CPU_HZ;3940inline s64 msToCycles(int ms) {41return CPU_HZ / 1000 * ms;42}4344inline s64 msToCycles(float ms) {45return (s64)(CPU_HZ * ms * (0.001f));46}4748inline s64 msToCycles(double ms) {49return (s64)(CPU_HZ * ms * (0.001));50}5152inline s64 usToCycles(float us) {53return (s64)(CPU_HZ * us * (0.000001f));54}5556inline s64 usToCycles(int us) {57return (CPU_HZ / 1000000 * (s64)us);58}5960inline s64 usToCycles(s64 us) {61return (CPU_HZ / 1000000 * us);62}6364inline s64 usToCycles(u64 us) {65return (s64)(CPU_HZ / 1000000 * us);66}6768inline s64 cyclesToUs(s64 cycles) {69return (cycles * 1000000) / CPU_HZ;70}7172namespace CoreTiming73{74void Init();75void Shutdown();7677typedef void (*MHzChangeCallback)();78typedef void (*TimedCallback)(u64 userdata, int cyclesLate);7980u64 GetTicks();81u64 GetIdleTicks();82u64 GetGlobalTimeUs();83u64 GetGlobalTimeUsScaled();8485// Returns the event_type identifier.86int RegisterEvent(const char *name, TimedCallback callback);87// For save states.88void RestoreRegisterEvent(int &event_type, const char *name, TimedCallback callback);89void UnregisterAllEvents();9091// userdata MAY NOT CONTAIN POINTERS. userdata might get written and reloaded from disk,92// when we implement state saves.93void ScheduleEvent(s64 cyclesIntoFuture, int event_type, u64 userdata=0);94s64 UnscheduleEvent(int event_type, u64 userdata);9596void RemoveEvent(int event_type);97bool IsScheduled(int event_type);98void Advance();99void ForceCheck();100101// Pretend that the main CPU has executed enough cycles to reach the next event.102void Idle(int maxIdle = 0);103104// Clear all pending events. This should ONLY be done on exit or state load.105void ClearPendingEvents();106107void LogPendingEvents();108109// Warning: not included in save states.110void RegisterMHzChangeCallback(MHzChangeCallback callback);111112std::string GetScheduledEventsSummary();113114void DoState(PointerWrap &p);115116void SetClockFrequencyHz(int cpuHz);117int GetClockFrequencyHz();118extern int slicelength;119120}; // end of namespace121122123