Mesen-SX/Core/Console.h

244 lines
5.9 KiB
C
Raw Normal View History

#pragma once
#include "stdafx.h"
2019-03-12 09:15:57 -04:00
#include "CartTypes.h"
#include "DebugTypes.h"
#include "Debugger.h"
2019-03-12 09:15:57 -04:00
#include "ConsoleLock.h"
#include "HistoryViewer.h"
#include "../Utilities/Timer.h"
#include "../Utilities/VirtualFile.h"
#include "../Utilities/SimpleLock.h"
class Cpu;
class Ppu;
class Spc;
2019-02-15 21:33:13 -05:00
class BaseCartridge;
class MemoryManager;
class InternalRegisters;
2019-02-17 19:54:29 -05:00
class ControlManager;
class DmaController;
class Debugger;
class DebugHud;
class SoundMixer;
class VideoRenderer;
class VideoDecoder;
2019-02-15 21:33:13 -05:00
class NotificationManager;
class EmuSettings;
2019-03-12 09:15:57 -04:00
class SaveStateManager;
2019-03-12 12:06:42 -04:00
class RewindManager;
class BatteryManager;
2019-10-12 22:40:25 -04:00
class CheatManager;
2019-10-16 20:22:45 -04:00
class MovieManager;
class SpcHud;
class FrameLimiter;
class DebugStats;
2019-11-01 21:15:11 -04:00
class Msu1;
enum class MemoryOperationType;
2019-03-01 20:27:49 -05:00
enum class SnesMemoryType;
2019-03-07 20:12:32 -05:00
enum class EventType;
2019-03-14 15:25:35 -04:00
enum class ConsoleRegion;
enum class ConsoleType;
class Console : public std::enable_shared_from_this<Console>
{
private:
unique_ptr<thread> _emuThread;
shared_ptr<Cpu> _cpu;
shared_ptr<Ppu> _ppu;
shared_ptr<Spc> _spc;
shared_ptr<MemoryManager> _memoryManager;
2019-02-15 21:33:13 -05:00
shared_ptr<BaseCartridge> _cart;
shared_ptr<InternalRegisters> _internalRegisters;
2019-02-17 19:54:29 -05:00
shared_ptr<ControlManager> _controlManager;
shared_ptr<DmaController> _dmaController;
2019-11-01 21:15:11 -04:00
shared_ptr<Msu1> _msu1;
shared_ptr<Debugger> _debugger;
2019-02-15 21:33:13 -05:00
shared_ptr<NotificationManager> _notificationManager;
shared_ptr<BatteryManager> _batteryManager;
shared_ptr<SoundMixer> _soundMixer;
shared_ptr<VideoRenderer> _videoRenderer;
shared_ptr<VideoDecoder> _videoDecoder;
shared_ptr<DebugHud> _debugHud;
shared_ptr<EmuSettings> _settings;
2019-03-12 09:15:57 -04:00
shared_ptr<SaveStateManager> _saveStateManager;
2019-03-12 12:06:42 -04:00
shared_ptr<RewindManager> _rewindManager;
shared_ptr<HistoryViewer> _historyViewer;
2019-10-12 22:40:25 -04:00
shared_ptr<CheatManager> _cheatManager;
2019-10-16 20:22:45 -04:00
shared_ptr<MovieManager> _movieManager;
shared_ptr<SpcHud> _spcHud;
2019-10-16 20:22:45 -04:00
2019-03-07 20:12:32 -05:00
thread::id _emulationThreadId;
2019-03-12 09:15:57 -04:00
atomic<uint32_t> _lockCounter;
SimpleLock _runLock;
SimpleLock _emulationLock;
2019-03-12 09:15:57 -04:00
SimpleLock _debuggerLock;
atomic<bool> _stopFlag;
2019-03-12 13:13:32 -04:00
atomic<bool> _paused;
atomic<bool> _pauseOnNextFrame;
atomic<bool> _threadPaused;
2019-03-14 15:25:35 -04:00
ConsoleRegion _region;
ConsoleType _consoleType;
2019-03-14 15:25:35 -04:00
uint32_t _masterClockRate;
atomic<bool> _isRunAheadFrame;
bool _frameRunning = false;
unique_ptr<DebugStats> _stats;
unique_ptr<FrameLimiter> _frameLimiter;
Timer _lastFrameTimer;
double _frameDelay = 0;
double GetFrameDelay();
2019-03-14 15:25:35 -04:00
void UpdateRegion();
2019-03-12 09:15:57 -04:00
void WaitForLock();
2019-03-12 13:13:32 -04:00
void WaitForPauseEnd();
void RunFrame();
bool ProcessSystemActions();
void RunFrameWithRunAhead();
public:
Console();
2019-02-26 22:27:09 -05:00
~Console();
void Initialize();
void Release();
void Run();
2019-07-02 19:56:00 -04:00
void RunSingleFrame();
2019-03-14 18:07:25 -04:00
void Stop(bool sendNotification);
void ProcessEndOfFrame();
void Reset();
void ReloadRom(bool forPowerCycle);
void PowerCycle();
void PauseOnNextFrame();
2019-03-12 13:13:32 -04:00
void Pause();
void Resume();
bool IsPaused();
bool LoadRom(VirtualFile romFile, VirtualFile patchFile, bool stopRom = true, bool forPowerCycle = false);
2019-03-12 09:15:57 -04:00
RomInfo GetRomInfo();
uint64_t GetMasterClock();
2019-03-14 15:25:35 -04:00
uint32_t GetMasterClockRate();
ConsoleRegion GetRegion();
ConsoleType GetConsoleType();
2019-03-12 09:15:57 -04:00
ConsoleLock AcquireLock();
void Lock();
void Unlock();
bool IsThreadPaused();
2019-03-12 09:15:57 -04:00
void Serialize(ostream &out, int compressionLevel = 1);
void Deserialize(istream &in, uint32_t fileFormatVersion, bool compressed = true);
shared_ptr<SoundMixer> GetSoundMixer();
shared_ptr<VideoRenderer> GetVideoRenderer();
shared_ptr<VideoDecoder> GetVideoDecoder();
2019-02-15 21:33:13 -05:00
shared_ptr<NotificationManager> GetNotificationManager();
shared_ptr<EmuSettings> GetSettings();
2019-03-12 09:15:57 -04:00
shared_ptr<SaveStateManager> GetSaveStateManager();
2019-03-12 12:06:42 -04:00
shared_ptr<RewindManager> GetRewindManager();
shared_ptr<DebugHud> GetDebugHud();
shared_ptr<BatteryManager> GetBatteryManager();
2019-10-12 22:40:25 -04:00
shared_ptr<CheatManager> GetCheatManager();
2019-10-16 20:22:45 -04:00
shared_ptr<MovieManager> GetMovieManager();
2019-02-13 18:44:39 -05:00
shared_ptr<Cpu> GetCpu();
shared_ptr<Ppu> GetPpu();
shared_ptr<Spc> GetSpc();
2019-02-15 21:33:13 -05:00
shared_ptr<BaseCartridge> GetCartridge();
shared_ptr<MemoryManager> GetMemoryManager();
shared_ptr<InternalRegisters> GetInternalRegisters();
2019-02-17 19:54:29 -05:00
shared_ptr<ControlManager> GetControlManager();
shared_ptr<DmaController> GetDmaController();
2019-11-01 21:15:11 -04:00
shared_ptr<Msu1> GetMsu1();
2020-10-08 20:50:36 -04:00
HistoryViewer* GetHistoryViewer();
shared_ptr<Debugger> GetDebugger(bool autoStart = true);
void StopDebugger();
2019-04-06 17:38:14 -04:00
bool IsDebugging();
2019-03-07 20:12:32 -05:00
thread::id GetEmulationThreadId();
2019-02-17 15:02:33 -05:00
bool IsRunning();
bool IsRunAheadFrame();
uint32_t GetFrameCount();
double GetFps();
void CopyRewindData(shared_ptr<Console> sourceConsole);
template<CpuType type> __forceinline void ProcessMemoryRead(uint32_t addr, uint8_t value, MemoryOperationType opType)
{
if(_debugger) {
_debugger->ProcessMemoryRead<type>(addr, value, opType);
}
}
template<CpuType type> __forceinline void ProcessMemoryWrite(uint32_t addr, uint8_t value, MemoryOperationType opType)
{
if(_debugger) {
_debugger->ProcessMemoryWrite<type>(addr, value, opType);
}
}
__forceinline void ProcessPpuRead(uint32_t addr, uint8_t value, SnesMemoryType memoryType)
{
if(_debugger) {
_debugger->ProcessPpuRead(addr, value, memoryType);
}
}
__forceinline void ProcessPpuWrite(uint32_t addr, uint8_t value, SnesMemoryType memoryType)
{
if(_debugger) {
_debugger->ProcessPpuWrite(addr, value, memoryType);
}
}
__forceinline void ProcessWorkRamRead(uint32_t addr, uint8_t value)
{
if(_debugger) {
_debugger->ProcessWorkRamRead(addr, value);
}
}
__forceinline void ProcessWorkRamWrite(uint32_t addr, uint8_t value)
{
if(_debugger) {
_debugger->ProcessWorkRamWrite(addr, value);
}
}
template<CpuType cpuType> __forceinline void ProcessPpuCycle()
{
if(_debugger) {
_debugger->ProcessPpuCycle<cpuType>();
}
}
__forceinline void DebugLog(string log)
{
if(_debugger) {
_debugger->Log(log);
}
}
template<CpuType type> void ProcessInterrupt(uint32_t originalPc, uint32_t currentPc, bool forNmi);
2019-03-07 20:12:32 -05:00
void ProcessEvent(EventType type);
void BreakImmediately(BreakSource source);
};