2014-06-20 21:48:55 -04:00
|
|
|
#pragma once
|
|
|
|
|
2014-06-14 11:27:55 -04:00
|
|
|
#include "stdafx.h"
|
2016-12-11 10:56:23 -05:00
|
|
|
#include <atomic>
|
2014-07-06 19:54:47 -04:00
|
|
|
#include "../Utilities/SimpleLock.h"
|
2017-09-30 14:07:07 -04:00
|
|
|
#include "VirtualFile.h"
|
2014-06-14 11:27:55 -04:00
|
|
|
|
2015-07-01 23:17:14 -04:00
|
|
|
class BaseMapper;
|
2017-04-28 19:54:58 -04:00
|
|
|
class RewindManager;
|
2018-07-11 18:07:13 -04:00
|
|
|
class HistoryViewer;
|
2017-04-29 08:29:56 -04:00
|
|
|
class APU;
|
|
|
|
class CPU;
|
|
|
|
class PPU;
|
|
|
|
class MemoryManager;
|
|
|
|
class ControlManager;
|
|
|
|
class AutoSaveManager;
|
2017-06-28 19:00:08 -04:00
|
|
|
class HdPackBuilder;
|
2017-08-19 16:46:57 -04:00
|
|
|
class HdAudioDevice;
|
2017-11-19 23:08:23 -05:00
|
|
|
class SystemActionManager;
|
2018-06-09 14:03:53 -04:00
|
|
|
class Timer;
|
2018-07-01 15:21:05 -04:00
|
|
|
class CheatManager;
|
|
|
|
class SaveStateManager;
|
|
|
|
class VideoDecoder;
|
|
|
|
class VideoRenderer;
|
|
|
|
class DebugHud;
|
|
|
|
class SoundMixer;
|
2018-07-02 14:49:19 -04:00
|
|
|
class NotificationManager;
|
2018-07-06 00:10:10 -04:00
|
|
|
class Debugger;
|
2018-07-13 22:19:26 -04:00
|
|
|
class EmulationSettings;
|
2018-07-22 17:31:50 -04:00
|
|
|
class BatteryManager;
|
2018-07-01 15:21:05 -04:00
|
|
|
|
2017-07-25 19:46:25 -04:00
|
|
|
struct HdPackData;
|
2018-07-06 00:10:10 -04:00
|
|
|
struct HashInfo;
|
2018-07-07 14:52:51 -04:00
|
|
|
struct RomInfo;
|
2018-07-06 00:10:10 -04:00
|
|
|
|
|
|
|
enum class MemoryOperationType;
|
2017-04-29 08:29:56 -04:00
|
|
|
enum class NesModel;
|
2017-06-28 19:00:08 -04:00
|
|
|
enum class ScaleFilterType;
|
2017-11-19 23:08:23 -05:00
|
|
|
enum class ConsoleFeatures;
|
2018-01-07 01:22:28 -05:00
|
|
|
enum class DebugMemoryType;
|
2018-07-01 15:21:05 -04:00
|
|
|
enum class EventType;
|
2019-06-22 16:33:59 -04:00
|
|
|
enum class RamPowerOnState;
|
2015-07-01 23:17:14 -04:00
|
|
|
|
2018-07-01 15:21:05 -04:00
|
|
|
class Console : public std::enable_shared_from_this<Console>
|
2014-06-14 11:27:55 -04:00
|
|
|
{
|
2018-07-01 15:21:05 -04:00
|
|
|
private:
|
|
|
|
SimpleLock _runLock;
|
|
|
|
SimpleLock _stopLock;
|
|
|
|
SimpleLock _debuggerLock;
|
2018-07-22 16:17:15 -04:00
|
|
|
atomic<uint32_t> _pauseCounter;
|
2018-07-01 15:21:05 -04:00
|
|
|
|
|
|
|
shared_ptr<RewindManager> _rewindManager;
|
2018-07-11 18:07:13 -04:00
|
|
|
shared_ptr<HistoryViewer> _historyViewer;
|
|
|
|
|
2018-07-01 15:21:05 -04: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-02 21:32:59 -04:00
|
|
|
|
|
|
|
//Used by VS-DualSystem
|
|
|
|
shared_ptr<Console> _master;
|
|
|
|
shared_ptr<Console> _slave;
|
2018-07-22 17:31:50 -04:00
|
|
|
|
|
|
|
shared_ptr<BatteryManager> _batteryManager;
|
2018-07-01 15:21:05 -04: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 14:49:19 -04:00
|
|
|
shared_ptr<NotificationManager> _notificationManager;
|
2018-07-13 22:19:26 -04:00
|
|
|
shared_ptr<EmulationSettings> _settings;
|
2018-07-01 15:21:05 -04:00
|
|
|
|
|
|
|
shared_ptr<HdPackBuilder> _hdPackBuilder;
|
|
|
|
shared_ptr<HdPackData> _hdData;
|
|
|
|
unique_ptr<HdAudioDevice> _hdAudioDevice;
|
|
|
|
|
|
|
|
NesModel _model;
|
|
|
|
|
|
|
|
string _romFilepath;
|
|
|
|
string _patchFilename;
|
|
|
|
|
2018-07-11 18:07:13 -04:00
|
|
|
bool _paused = false;
|
2018-07-01 15:21:05 -04:00
|
|
|
bool _stop = false;
|
|
|
|
bool _running = false;
|
|
|
|
int32_t _stopCode = 0;
|
|
|
|
|
2019-01-13 14:10:46 -05:00
|
|
|
bool _pauseOnNextFrameRequested = false;
|
2018-08-26 18:53:15 -04:00
|
|
|
bool _resetRunTimers = false;
|
|
|
|
|
2018-07-01 15:21:05 -04:00
|
|
|
bool _disableOcNextFrame = false;
|
|
|
|
|
|
|
|
bool _initialized = false;
|
|
|
|
std::thread::id _emulationThreadId;
|
|
|
|
|
|
|
|
void LoadHdPack(VirtualFile &romFile, VirtualFile &patchFile);
|
|
|
|
|
|
|
|
void UpdateNesModel(bool sendNotification);
|
|
|
|
double GetFrameDelay();
|
2019-02-01 14:15:27 -05:00
|
|
|
void DisplayDebugInformation(double lastFrame, double &lastFrameMin, double &lastFrameMax, double frameDurations[60]);
|
2018-07-01 15:21:05 -04:00
|
|
|
|
2018-12-31 14:59:00 -05:00
|
|
|
void ExportStub();
|
|
|
|
|
2018-07-01 15:21:05 -04:00
|
|
|
public:
|
2018-07-13 22:19:26 -04:00
|
|
|
Console(shared_ptr<Console> master = nullptr, EmulationSettings* initialSettings = nullptr);
|
2018-07-01 15:21:05 -04:00
|
|
|
~Console();
|
|
|
|
|
|
|
|
void Init();
|
|
|
|
void Release(bool forShutdown);
|
|
|
|
|
2018-07-22 17:31:50 -04:00
|
|
|
shared_ptr<BatteryManager> GetBatteryManager();
|
2018-07-01 15:21:05 -04:00
|
|
|
shared_ptr<SaveStateManager> GetSaveStateManager();
|
|
|
|
shared_ptr<VideoDecoder> GetVideoDecoder();
|
|
|
|
shared_ptr<VideoRenderer> GetVideoRenderer();
|
|
|
|
shared_ptr<DebugHud> GetDebugHud();
|
|
|
|
shared_ptr<SoundMixer> GetSoundMixer();
|
2018-07-02 14:49:19 -04:00
|
|
|
shared_ptr<NotificationManager> GetNotificationManager();
|
2018-07-13 22:19:26 -04:00
|
|
|
EmulationSettings* GetSettings();
|
|
|
|
|
2018-07-02 21:32:59 -04:00
|
|
|
bool IsDualSystem();
|
|
|
|
shared_ptr<Console> GetDualConsole();
|
|
|
|
bool IsMaster();
|
|
|
|
|
2018-07-01 15:21:05 -04:00
|
|
|
void ProcessCpuClock();
|
|
|
|
CPU* GetCpu();
|
|
|
|
PPU* GetPpu();
|
|
|
|
APU* GetApu();
|
|
|
|
BaseMapper* GetMapper();
|
|
|
|
ControlManager* GetControlManager();
|
|
|
|
MemoryManager* GetMemoryManager();
|
|
|
|
CheatManager* GetCheatManager();
|
2018-08-06 18:32:22 -04:00
|
|
|
shared_ptr<RewindManager> GetRewindManager();
|
2018-07-11 18:07:13 -04:00
|
|
|
HistoryViewer* GetHistoryViewer();
|
2018-07-01 15:21:05 -04: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();
|
2018-08-26 18:53:15 -04:00
|
|
|
void ResetRunTimers();
|
2018-07-01 15:21:05 -04:00
|
|
|
void Stop(int stopCode = 0);
|
2018-04-14 21:53:52 -04:00
|
|
|
|
2018-07-01 15:21:05 -04:00
|
|
|
int32_t GetStopCode();
|
2018-01-04 19:03:47 -05:00
|
|
|
|
2018-07-01 15:21:05 -04:00
|
|
|
void RunSingleFrame();
|
2018-07-03 23:32:26 -04:00
|
|
|
void RunSlaveCpu();
|
2018-07-01 15:21:05 -04:00
|
|
|
bool UpdateHdPackMode();
|
2017-10-07 13:01:42 -04:00
|
|
|
|
2018-07-01 15:21:05 -04:00
|
|
|
shared_ptr<SystemActionManager> GetSystemActionManager();
|
2017-11-19 23:08:23 -05:00
|
|
|
|
2018-07-01 15:21:05 -04:00
|
|
|
template<typename T>
|
|
|
|
shared_ptr<T> GetSystemActionManager()
|
|
|
|
{
|
|
|
|
return std::dynamic_pointer_cast<T>(_systemActionManager);
|
|
|
|
}
|
2017-11-19 23:08:23 -05:00
|
|
|
|
2019-02-08 19:39:35 -05:00
|
|
|
uint32_t GetDipSwitchCount();
|
2018-07-01 15:21:05 -04:00
|
|
|
ConsoleFeatures GetAvailableFeatures();
|
|
|
|
void InputBarcode(uint64_t barcode, uint32_t digitCount);
|
2017-11-19 23:08:23 -05:00
|
|
|
|
2018-07-01 15:21:05 -04:00
|
|
|
void LoadTapeFile(string filepath);
|
|
|
|
void StartRecordingTapeFile(string filepath);
|
|
|
|
void StopRecordingTapeFile();
|
|
|
|
bool IsRecordingTapeFile();
|
2018-12-26 13:28:17 -05:00
|
|
|
bool IsNsf();
|
2017-11-24 21:38:12 -05:00
|
|
|
|
2018-07-01 15:21:05 -04:00
|
|
|
std::thread::id GetEmulationThreadId();
|
2017-10-07 13:01:42 -04:00
|
|
|
|
2018-07-01 15:21:05 -04:00
|
|
|
void Reset(bool softReset = true);
|
|
|
|
void PowerCycle();
|
|
|
|
void ResetComponents(bool softReset);
|
2014-07-01 12:44:01 -04:00
|
|
|
|
2018-07-01 15:21:05 -04:00
|
|
|
//Used to pause the emu loop to perform thread-safe operations
|
|
|
|
void Pause();
|
2014-07-01 12:44:01 -04:00
|
|
|
|
2018-07-01 15:21:05 -04:00
|
|
|
//Used to resume the emu loop after calling Pause()
|
|
|
|
void Resume();
|
2014-06-21 19:03:13 -04:00
|
|
|
|
2018-07-01 15:21:05 -04:00
|
|
|
void BreakIfDebugging();
|
|
|
|
shared_ptr<Debugger> GetDebugger(bool autoStart = true);
|
|
|
|
void StopDebugger();
|
2015-06-24 19:26:19 -04:00
|
|
|
|
2018-07-01 15:21:05 -04: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-25 21:52:37 -04:00
|
|
|
|
2018-07-01 15:21:05 -04:00
|
|
|
VirtualFile GetRomPath();
|
|
|
|
VirtualFile GetPatchFile();
|
2018-07-07 14:52:51 -04:00
|
|
|
RomInfo GetRomInfo();
|
2018-07-01 15:21:05 -04:00
|
|
|
uint32_t GetFrameCount();
|
|
|
|
NesModel GetModel();
|
2014-07-09 18:29:07 -04:00
|
|
|
|
2018-07-01 15:21:05 -04:00
|
|
|
uint32_t GetLagCounter();
|
|
|
|
void ResetLagCounter();
|
2016-07-10 18:22:37 -04:00
|
|
|
|
2018-07-01 15:21:05 -04:00
|
|
|
bool IsRunning();
|
2018-07-13 22:19:26 -04:00
|
|
|
bool IsExecutionStopped();
|
2016-02-14 12:58:35 -05:00
|
|
|
|
2018-07-13 22:19:26 -04:00
|
|
|
bool IsPaused();
|
2019-01-13 14:10:46 -05:00
|
|
|
void PauseOnNextFrame();
|
2018-07-11 18:07:13 -04:00
|
|
|
|
2018-07-01 15:21:05 -04:00
|
|
|
void SetNextFrameOverclockStatus(bool disabled);
|
2016-12-23 13:56:45 -05:00
|
|
|
|
2018-07-01 15:21:05 -04:00
|
|
|
bool IsDebuggerAttached();
|
2016-11-26 18:04:09 -05:00
|
|
|
|
2019-06-22 16:33:59 -04:00
|
|
|
void InitializeRam(void* data, uint32_t length);
|
|
|
|
static void InitializeRam(RamPowerOnState powerOnState, void* data, uint32_t length);
|
|
|
|
|
2018-07-01 15:21:05 -04:00
|
|
|
shared_ptr<HdPackData> GetHdData();
|
|
|
|
bool IsHdPpu();
|
2017-06-28 19:00:08 -04:00
|
|
|
|
2018-07-01 15:21:05 -04:00
|
|
|
void StartRecordingHdPack(string saveFolder, ScaleFilterType filterType, uint32_t scale, uint32_t flags, uint32_t chrRamBankSize);
|
|
|
|
void StopRecordingHdPack();
|
2018-07-11 18:07:13 -04:00
|
|
|
|
|
|
|
void CopyRewindData(shared_ptr<Console> sourceConsole);
|
2017-06-28 19:00:08 -04:00
|
|
|
|
2018-07-01 15:21:05 -04: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 11:27:55 -04:00
|
|
|
};
|