2014-06-21 01:48:55 +00:00
|
|
|
#pragma once
|
|
|
|
|
2014-06-14 15:27:55 +00:00
|
|
|
#include "stdafx.h"
|
2016-12-11 15:56:23 +00:00
|
|
|
#include <atomic>
|
2014-07-06 23:54:47 +00:00
|
|
|
#include "../Utilities/SimpleLock.h"
|
2017-09-30 18:07:07 +00:00
|
|
|
#include "VirtualFile.h"
|
2014-06-14 15:27:55 +00:00
|
|
|
|
2015-07-02 03:17:14 +00:00
|
|
|
class BaseMapper;
|
2017-04-28 23:54:58 +00:00
|
|
|
class RewindManager;
|
2018-07-11 22:07:13 +00:00
|
|
|
class HistoryViewer;
|
2017-04-29 12:29:56 +00:00
|
|
|
class APU;
|
|
|
|
class CPU;
|
|
|
|
class PPU;
|
|
|
|
class MemoryManager;
|
|
|
|
class ControlManager;
|
|
|
|
class AutoSaveManager;
|
2017-06-28 23:00:08 +00:00
|
|
|
class HdPackBuilder;
|
2017-08-19 20:46:57 +00:00
|
|
|
class HdAudioDevice;
|
2017-11-20 04:08:23 +00:00
|
|
|
class SystemActionManager;
|
2018-06-09 18:03:53 +00:00
|
|
|
class Timer;
|
2018-07-01 19:21:05 +00:00
|
|
|
class CheatManager;
|
|
|
|
class SaveStateManager;
|
|
|
|
class VideoDecoder;
|
|
|
|
class VideoRenderer;
|
|
|
|
class DebugHud;
|
|
|
|
class SoundMixer;
|
2018-07-02 18:49:19 +00:00
|
|
|
class NotificationManager;
|
2018-07-06 04:10:10 +00:00
|
|
|
class Debugger;
|
2018-07-14 02:19:26 +00:00
|
|
|
class EmulationSettings;
|
2018-07-22 21:31:50 +00:00
|
|
|
class BatteryManager;
|
2018-07-01 19:21:05 +00:00
|
|
|
|
2017-07-25 23:46:25 +00:00
|
|
|
struct HdPackData;
|
2018-07-06 04:10:10 +00:00
|
|
|
struct HashInfo;
|
2018-07-07 18:52:51 +00:00
|
|
|
struct RomInfo;
|
2018-07-06 04:10:10 +00:00
|
|
|
|
|
|
|
enum class MemoryOperationType;
|
2017-04-29 12:29:56 +00:00
|
|
|
enum class NesModel;
|
2017-06-28 23:00:08 +00:00
|
|
|
enum class ScaleFilterType;
|
2017-11-20 04:08:23 +00:00
|
|
|
enum class ConsoleFeatures;
|
2018-01-07 06:22:28 +00:00
|
|
|
enum class DebugMemoryType;
|
2018-07-01 19:21:05 +00:00
|
|
|
enum class EventType;
|
2015-07-02 03:17:14 +00:00
|
|
|
|
2018-07-01 19:21:05 +00:00
|
|
|
class Console : public std::enable_shared_from_this<Console>
|
2014-06-14 15:27:55 +00:00
|
|
|
{
|
2018-07-01 19:21:05 +00:00
|
|
|
private:
|
|
|
|
SimpleLock _runLock;
|
|
|
|
SimpleLock _stopLock;
|
|
|
|
SimpleLock _debuggerLock;
|
2018-07-22 20:17:15 +00:00
|
|
|
atomic<uint32_t> _pauseCounter;
|
2018-07-01 19:21:05 +00:00
|
|
|
|
|
|
|
shared_ptr<RewindManager> _rewindManager;
|
2018-07-11 22:07:13 +00:00
|
|
|
shared_ptr<HistoryViewer> _historyViewer;
|
|
|
|
|
2018-07-01 19:21:05 +00:00
|
|
|
shared_ptr<CPU> _cpu;
|
|
|
|
shared_ptr<PPU> _ppu;
|
|
|
|
shared_ptr<APU> _apu;
|
|
|
|
shared_ptr<Debugger> _debugger;
|
|
|
|
shared_ptr<BaseMapper> _mapper;
|
|
|
|
shared_ptr<ControlManager> _controlManager;
|
|
|
|
shared_ptr<MemoryManager> _memoryManager;
|
2018-07-03 01:32:59 +00:00
|
|
|
|
|
|
|
//Used by VS-DualSystem
|
|
|
|
shared_ptr<Console> _master;
|
|
|
|
shared_ptr<Console> _slave;
|
2018-07-22 21:31:50 +00:00
|
|
|
|
|
|
|
shared_ptr<BatteryManager> _batteryManager;
|
2018-07-01 19:21:05 +00:00
|
|
|
shared_ptr<SystemActionManager> _systemActionManager;
|
|
|
|
|
|
|
|
shared_ptr<VideoDecoder> _videoDecoder;
|
|
|
|
shared_ptr<VideoRenderer> _videoRenderer;
|
|
|
|
unique_ptr<AutoSaveManager> _autoSaveManager;
|
|
|
|
shared_ptr<SaveStateManager> _saveStateManager;
|
|
|
|
shared_ptr<CheatManager> _cheatManager;
|
|
|
|
shared_ptr<DebugHud> _debugHud;
|
|
|
|
shared_ptr<SoundMixer> _soundMixer;
|
2018-07-02 18:49:19 +00:00
|
|
|
shared_ptr<NotificationManager> _notificationManager;
|
2018-07-14 02:19:26 +00:00
|
|
|
shared_ptr<EmulationSettings> _settings;
|
2018-07-01 19:21:05 +00:00
|
|
|
|
|
|
|
shared_ptr<HdPackBuilder> _hdPackBuilder;
|
|
|
|
shared_ptr<HdPackData> _hdData;
|
|
|
|
unique_ptr<HdAudioDevice> _hdAudioDevice;
|
|
|
|
|
|
|
|
NesModel _model;
|
|
|
|
|
|
|
|
string _romFilepath;
|
|
|
|
string _patchFilename;
|
|
|
|
|
2018-07-11 22:07:13 +00:00
|
|
|
bool _paused = false;
|
2018-07-01 19:21:05 +00:00
|
|
|
bool _stop = false;
|
|
|
|
bool _running = false;
|
|
|
|
int32_t _stopCode = 0;
|
|
|
|
|
|
|
|
bool _disableOcNextFrame = false;
|
|
|
|
|
|
|
|
bool _initialized = false;
|
|
|
|
std::thread::id _emulationThreadId;
|
|
|
|
|
|
|
|
void LoadHdPack(VirtualFile &romFile, VirtualFile &patchFile);
|
|
|
|
|
|
|
|
void UpdateNesModel(bool sendNotification);
|
|
|
|
double GetFrameDelay();
|
|
|
|
void DisplayDebugInformation(Timer &clockTimer, Timer &lastFrameTimer, double &lastFrameMin, double &lastFrameMax, double *timeLagData);
|
|
|
|
|
|
|
|
public:
|
2018-07-14 02:19:26 +00:00
|
|
|
Console(shared_ptr<Console> master = nullptr, EmulationSettings* initialSettings = nullptr);
|
2018-07-01 19:21:05 +00:00
|
|
|
~Console();
|
|
|
|
|
|
|
|
void Init();
|
|
|
|
void Release(bool forShutdown);
|
|
|
|
|
2018-07-22 21:31:50 +00:00
|
|
|
shared_ptr<BatteryManager> GetBatteryManager();
|
2018-07-01 19:21:05 +00:00
|
|
|
shared_ptr<SaveStateManager> GetSaveStateManager();
|
|
|
|
shared_ptr<VideoDecoder> GetVideoDecoder();
|
|
|
|
shared_ptr<VideoRenderer> GetVideoRenderer();
|
|
|
|
shared_ptr<DebugHud> GetDebugHud();
|
|
|
|
shared_ptr<SoundMixer> GetSoundMixer();
|
2018-07-02 18:49:19 +00:00
|
|
|
shared_ptr<NotificationManager> GetNotificationManager();
|
2018-07-14 02:19:26 +00:00
|
|
|
EmulationSettings* GetSettings();
|
|
|
|
|
2018-07-03 01:32:59 +00:00
|
|
|
bool IsDualSystem();
|
|
|
|
shared_ptr<Console> GetDualConsole();
|
|
|
|
bool IsMaster();
|
|
|
|
|
2018-07-01 19:21:05 +00:00
|
|
|
void ProcessCpuClock();
|
|
|
|
CPU* GetCpu();
|
|
|
|
PPU* GetPpu();
|
|
|
|
APU* GetApu();
|
|
|
|
BaseMapper* GetMapper();
|
|
|
|
ControlManager* GetControlManager();
|
|
|
|
MemoryManager* GetMemoryManager();
|
|
|
|
CheatManager* GetCheatManager();
|
2018-08-06 22:32:22 +00:00
|
|
|
shared_ptr<RewindManager> GetRewindManager();
|
2018-07-11 22:07:13 +00:00
|
|
|
HistoryViewer* GetHistoryViewer();
|
2018-07-01 19:21:05 +00:00
|
|
|
|
|
|
|
bool LoadMatchingRom(string romName, HashInfo hashInfo);
|
|
|
|
string FindMatchingRom(string romName, HashInfo hashInfo);
|
|
|
|
|
|
|
|
bool Initialize(string romFile, string patchFile = "");
|
|
|
|
bool Initialize(VirtualFile &romFile);
|
|
|
|
bool Initialize(VirtualFile &romFile, VirtualFile &patchFile);
|
|
|
|
|
|
|
|
void SaveBatteries();
|
|
|
|
|
|
|
|
void Run();
|
|
|
|
void Stop(int stopCode = 0);
|
2018-04-15 01:53:52 +00:00
|
|
|
|
2018-07-01 19:21:05 +00:00
|
|
|
int32_t GetStopCode();
|
2018-01-05 00:03:47 +00:00
|
|
|
|
2018-07-01 19:21:05 +00:00
|
|
|
void RunSingleFrame();
|
2018-07-04 03:32:26 +00:00
|
|
|
void RunSlaveCpu();
|
2018-07-01 19:21:05 +00:00
|
|
|
bool UpdateHdPackMode();
|
2017-10-07 17:01:42 +00:00
|
|
|
|
2018-07-01 19:21:05 +00:00
|
|
|
shared_ptr<SystemActionManager> GetSystemActionManager();
|
2017-11-20 04:08:23 +00:00
|
|
|
|
2018-07-01 19:21:05 +00:00
|
|
|
template<typename T>
|
|
|
|
shared_ptr<T> GetSystemActionManager()
|
|
|
|
{
|
|
|
|
return std::dynamic_pointer_cast<T>(_systemActionManager);
|
|
|
|
}
|
2017-11-20 04:08:23 +00:00
|
|
|
|
2018-07-01 19:21:05 +00:00
|
|
|
ConsoleFeatures GetAvailableFeatures();
|
|
|
|
void InputBarcode(uint64_t barcode, uint32_t digitCount);
|
2017-11-20 04:08:23 +00:00
|
|
|
|
2018-07-01 19:21:05 +00:00
|
|
|
void LoadTapeFile(string filepath);
|
|
|
|
void StartRecordingTapeFile(string filepath);
|
|
|
|
void StopRecordingTapeFile();
|
|
|
|
bool IsRecordingTapeFile();
|
2017-11-25 02:38:12 +00:00
|
|
|
|
2018-07-01 19:21:05 +00:00
|
|
|
std::thread::id GetEmulationThreadId();
|
2017-10-07 17:01:42 +00:00
|
|
|
|
2018-07-01 19:21:05 +00:00
|
|
|
void Reset(bool softReset = true);
|
|
|
|
void PowerCycle();
|
|
|
|
void ResetComponents(bool softReset);
|
2014-07-01 16:44:01 +00:00
|
|
|
|
2018-07-01 19:21:05 +00:00
|
|
|
//Used to pause the emu loop to perform thread-safe operations
|
|
|
|
void Pause();
|
2014-07-01 16:44:01 +00:00
|
|
|
|
2018-07-01 19:21:05 +00:00
|
|
|
//Used to resume the emu loop after calling Pause()
|
|
|
|
void Resume();
|
2014-06-21 23:03:13 +00:00
|
|
|
|
2018-07-01 19:21:05 +00:00
|
|
|
void BreakIfDebugging();
|
|
|
|
shared_ptr<Debugger> GetDebugger(bool autoStart = true);
|
|
|
|
void StopDebugger();
|
2015-06-24 23:26:19 +00:00
|
|
|
|
2018-07-01 19:21:05 +00:00
|
|
|
void SaveState(ostream &saveStream);
|
|
|
|
void LoadState(istream &loadStream);
|
|
|
|
void LoadState(istream &loadStream, uint32_t stateVersion);
|
|
|
|
void LoadState(uint8_t *buffer, uint32_t bufferSize);
|
2014-06-26 01:52:37 +00:00
|
|
|
|
2018-07-01 19:21:05 +00:00
|
|
|
VirtualFile GetRomPath();
|
|
|
|
VirtualFile GetPatchFile();
|
2018-07-07 18:52:51 +00:00
|
|
|
RomInfo GetRomInfo();
|
2018-07-01 19:21:05 +00:00
|
|
|
uint32_t GetFrameCount();
|
|
|
|
NesModel GetModel();
|
2014-07-09 22:29:07 +00:00
|
|
|
|
2018-07-01 19:21:05 +00:00
|
|
|
uint32_t GetLagCounter();
|
|
|
|
void ResetLagCounter();
|
2016-07-10 22:22:37 +00:00
|
|
|
|
2018-07-01 19:21:05 +00:00
|
|
|
bool IsRunning();
|
2018-07-14 02:19:26 +00:00
|
|
|
bool IsExecutionStopped();
|
2016-02-14 17:58:35 +00:00
|
|
|
|
2018-07-14 02:19:26 +00:00
|
|
|
bool IsPaused();
|
2018-07-11 22:07:13 +00:00
|
|
|
|
2018-07-01 19:21:05 +00:00
|
|
|
void SetNextFrameOverclockStatus(bool disabled);
|
2016-12-23 18:56:45 +00:00
|
|
|
|
2018-07-01 19:21:05 +00:00
|
|
|
bool IsDebuggerAttached();
|
2016-11-26 23:04:09 +00:00
|
|
|
|
2018-07-01 19:21:05 +00:00
|
|
|
shared_ptr<HdPackData> GetHdData();
|
|
|
|
bool IsHdPpu();
|
2017-06-28 23:00:08 +00:00
|
|
|
|
2018-07-01 19:21:05 +00:00
|
|
|
void StartRecordingHdPack(string saveFolder, ScaleFilterType filterType, uint32_t scale, uint32_t flags, uint32_t chrRamBankSize);
|
|
|
|
void StopRecordingHdPack();
|
2018-07-11 22:07:13 +00:00
|
|
|
|
|
|
|
void CopyRewindData(shared_ptr<Console> sourceConsole);
|
2017-06-28 23:00:08 +00:00
|
|
|
|
2018-07-01 19:21:05 +00:00
|
|
|
uint8_t* GetRamBuffer(DebugMemoryType memoryType, uint32_t &size, int32_t &startAddr);
|
|
|
|
|
|
|
|
void DebugAddTrace(const char *log);
|
|
|
|
void DebugProcessPpuCycle();
|
|
|
|
void DebugProcessEvent(EventType type);
|
|
|
|
void DebugProcessInterrupt(uint16_t cpuAddr, uint16_t destCpuAddr, bool forNmi);
|
|
|
|
void DebugSetLastFramePpuScroll(uint16_t addr, uint8_t xScroll, bool updateHorizontalScrollOnly);
|
|
|
|
bool DebugProcessRamOperation(MemoryOperationType type, uint16_t &addr, uint8_t &value);
|
|
|
|
void DebugProcessVramReadOperation(MemoryOperationType type, uint16_t addr, uint8_t &value);
|
|
|
|
void DebugProcessVramWriteOperation(uint16_t addr, uint8_t &value);
|
2014-06-14 15:27:55 +00:00
|
|
|
};
|