This repository was archived by the owner on Sep 11, 2023. It is now read-only.
forked from SourMesen/Mesen
-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathConsole.h
More file actions
246 lines (191 loc) · 6.51 KB
/
Console.h
File metadata and controls
246 lines (191 loc) · 6.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
#pragma once
#include "stdafx.h"
#include <atomic>
#include "../Utilities/SimpleLock.h"
#include "VirtualFile.h"
class BaseMapper;
class RewindManager;
class HistoryViewer;
class APU;
class CPU;
class PPU;
class MemoryManager;
class ControlManager;
class AutoSaveManager;
class HdPackBuilder;
class HdAudioDevice;
class SystemActionManager;
class Timer;
class CheatManager;
class SaveStateManager;
class VideoDecoder;
class VideoRenderer;
class DebugHud;
class SoundMixer;
class NotificationManager;
class Debugger;
class EmulationSettings;
class BatteryManager;
struct HdPackData;
struct HashInfo;
struct RomInfo;
enum class MemoryOperationType;
enum class NesModel;
enum class ScaleFilterType;
enum class ConsoleFeatures;
enum class DebugMemoryType;
enum class EventType;
enum class DebugEventType : uint8_t;
enum class RamPowerOnState;
class Console : public std::enable_shared_from_this<Console>
{
private:
SimpleLock _runLock;
SimpleLock _stopLock;
SimpleLock _debuggerLock;
atomic<uint32_t> _pauseCounter;
shared_ptr<RewindManager> _rewindManager;
shared_ptr<HistoryViewer> _historyViewer;
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;
//Used by VS-DualSystem
shared_ptr<Console> _master;
shared_ptr<Console> _slave;
shared_ptr<BatteryManager> _batteryManager;
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;
shared_ptr<NotificationManager> _notificationManager;
shared_ptr<EmulationSettings> _settings;
shared_ptr<HdPackBuilder> _hdPackBuilder;
shared_ptr<HdPackData> _hdData;
unique_ptr<HdAudioDevice> _hdAudioDevice;
NesModel _model;
string _romFilepath;
string _patchFilename;
bool _paused = false;
bool _stop = false;
bool _running = false;
int32_t _stopCode = 0;
bool _pauseOnNextFrameRequested = false;
bool _resetRunTimers = false;
bool _disableOcNextFrame = false;
bool _initialized = false;
std::thread::id _emulationThreadId;
void RunFrameWithRunAhead(std::stringstream& runAheadState);
void LoadHdPack(VirtualFile &romFile, VirtualFile &patchFile);
void UpdateNesModel(bool sendNotification);
double GetFrameDelay();
void DisplayDebugInformation(double lastFrame, double &lastFrameMin, double &lastFrameMax, double frameDurations[60]);
void ExportStub();
public:
Console(shared_ptr<Console> master = nullptr, EmulationSettings* initialSettings = nullptr);
~Console();
void Init();
void Release(bool forShutdown);
shared_ptr<BatteryManager> GetBatteryManager();
shared_ptr<SaveStateManager> GetSaveStateManager();
shared_ptr<VideoDecoder> GetVideoDecoder();
shared_ptr<VideoRenderer> GetVideoRenderer();
shared_ptr<DebugHud> GetDebugHud();
shared_ptr<SoundMixer> GetSoundMixer();
shared_ptr<NotificationManager> GetNotificationManager();
EmulationSettings* GetSettings();
bool IsDualSystem();
shared_ptr<Console> GetDualConsole();
bool IsMaster();
void ProcessCpuClock();
CPU* GetCpu();
PPU* GetPpu();
APU* GetApu();
BaseMapper* GetMapper();
ControlManager* GetControlManager();
MemoryManager* GetMemoryManager();
CheatManager* GetCheatManager();
shared_ptr<RewindManager> GetRewindManager();
HistoryViewer* GetHistoryViewer();
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, bool forPowerCycle = false);
void SaveBatteries();
void Run();
void ResetRunTimers();
void Stop(int stopCode = 0);
int32_t GetStopCode();
void RunSingleFrame();
void RunSlaveCpu();
void RunFrame();
bool UpdateHdPackMode();
shared_ptr<SystemActionManager> GetSystemActionManager();
template<typename T>
shared_ptr<T> GetSystemActionManager()
{
return std::dynamic_pointer_cast<T>(_systemActionManager);
}
uint32_t GetDipSwitchCount();
ConsoleFeatures GetAvailableFeatures();
void InputBarcode(uint64_t barcode, uint32_t digitCount);
void LoadTapeFile(string filepath);
void StartRecordingTapeFile(string filepath);
void StopRecordingTapeFile();
bool IsRecordingTapeFile();
bool IsNsf();
std::thread::id GetEmulationThreadId();
void Reset(bool softReset = true);
void PowerCycle();
void ReloadRom(bool forPowerCycle = false);
void ResetComponents(bool softReset);
//Used to pause the emu loop to perform thread-safe operations
void Pause();
//Used to resume the emu loop after calling Pause()
void Resume();
shared_ptr<Debugger> GetDebugger(bool autoStart = true);
void StopDebugger();
void SaveState(ostream &saveStream);
void LoadState(istream &loadStream);
void LoadState(istream &loadStream, uint32_t stateVersion);
void LoadState(uint8_t *buffer, uint32_t bufferSize);
VirtualFile GetRomPath();
VirtualFile GetPatchFile();
RomInfo GetRomInfo();
uint32_t GetFrameCount();
NesModel GetModel();
uint32_t GetLagCounter();
void ResetLagCounter();
bool IsRunning();
bool IsExecutionStopped();
bool IsPaused();
void PauseOnNextFrame();
void SetNextFrameOverclockStatus(bool disabled);
bool IsDebuggerAttached();
double GetFps();
void InitializeRam(void* data, uint32_t length);
static void InitializeRam(RamPowerOnState powerOnState, void* data, uint32_t length);
shared_ptr<HdPackData> GetHdData();
bool IsHdPpu();
void StartRecordingHdPack(string saveFolder, ScaleFilterType filterType, uint32_t scale, uint32_t flags, uint32_t chrRamBankSize, uint32_t outTileType);
void StopRecordingHdPack();
void CopyRewindData(shared_ptr<Console> sourceConsole);
uint8_t* GetRamBuffer(uint16_t address);
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);
void DebugAddDebugEvent(DebugEventType type);
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);
};