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-06-14 15:27:55 +00:00
|
|
|
#include "CPU.h"
|
|
|
|
#include "PPU.h"
|
2014-06-23 02:15:35 +00:00
|
|
|
#include "APU.h"
|
2014-06-14 15:27:55 +00:00
|
|
|
#include "MemoryManager.h"
|
2014-06-21 19:43:41 +00:00
|
|
|
#include "ControlManager.h"
|
2014-07-06 23:54:47 +00:00
|
|
|
#include "../Utilities/SimpleLock.h"
|
2016-09-01 00:54:38 +00:00
|
|
|
#include "AutoSaveManager.h"
|
2014-06-14 15:27:55 +00:00
|
|
|
|
2015-07-02 03:17:14 +00:00
|
|
|
class Debugger;
|
|
|
|
class BaseMapper;
|
|
|
|
|
2014-06-14 15:27:55 +00:00
|
|
|
class Console
|
|
|
|
{
|
|
|
|
private:
|
2015-07-02 03:17:14 +00:00
|
|
|
static shared_ptr<Console> Instance;
|
2015-07-05 23:05:33 +00:00
|
|
|
SimpleLock _pauseLock;
|
|
|
|
SimpleLock _runLock;
|
|
|
|
SimpleLock _stopLock;
|
2014-06-21 23:03:13 +00:00
|
|
|
|
2015-06-24 23:26:19 +00:00
|
|
|
shared_ptr<CPU> _cpu;
|
2015-07-02 03:17:14 +00:00
|
|
|
shared_ptr<PPU> _ppu;
|
2014-06-23 02:15:35 +00:00
|
|
|
unique_ptr<APU> _apu;
|
2015-08-22 02:42:44 +00:00
|
|
|
shared_ptr<Debugger> _debugger;
|
2016-07-31 18:31:44 +00:00
|
|
|
SimpleLock _debuggerLock;
|
2014-06-24 06:47:32 +00:00
|
|
|
shared_ptr<BaseMapper> _mapper;
|
2014-06-21 19:43:41 +00:00
|
|
|
unique_ptr<ControlManager> _controlManager;
|
2015-06-24 23:26:19 +00:00
|
|
|
shared_ptr<MemoryManager> _memoryManager;
|
2014-06-14 15:27:55 +00:00
|
|
|
|
2016-09-01 00:54:38 +00:00
|
|
|
unique_ptr<AutoSaveManager> _autoSaveManager;
|
|
|
|
|
2016-02-06 04:14:27 +00:00
|
|
|
NesModel _model;
|
|
|
|
|
2015-07-11 12:27:22 +00:00
|
|
|
string _romFilepath;
|
2014-06-22 12:38:42 +00:00
|
|
|
|
2014-06-21 01:48:55 +00:00
|
|
|
bool _stop = false;
|
2014-06-23 17:52:53 +00:00
|
|
|
bool _reset = false;
|
2016-06-26 00:46:54 +00:00
|
|
|
|
2016-12-11 15:56:23 +00:00
|
|
|
atomic<bool> _resetRequested;
|
2016-07-10 22:22:37 +00:00
|
|
|
atomic<uint32_t> _lagCounter;
|
2015-07-06 02:23:44 +00:00
|
|
|
|
|
|
|
bool _initialized = false;
|
2014-06-21 01:48:55 +00:00
|
|
|
|
2014-06-25 17:30:02 +00:00
|
|
|
void ResetComponents(bool softReset);
|
2016-06-18 00:53:05 +00:00
|
|
|
void Initialize(string filename, stringstream *filestream = nullptr, string ipsFilename = "", int32_t archiveFileIndex = -1);
|
2016-07-10 23:15:00 +00:00
|
|
|
void UpdateNesModel(bool sendNotification);
|
|
|
|
double GetFrameDelay();
|
2014-06-24 06:47:32 +00:00
|
|
|
|
2014-06-14 15:27:55 +00:00
|
|
|
public:
|
2015-07-06 02:23:44 +00:00
|
|
|
Console();
|
2014-06-14 15:27:55 +00:00
|
|
|
~Console();
|
|
|
|
void Run();
|
2014-06-21 01:48:55 +00:00
|
|
|
void Stop();
|
2016-06-26 00:46:54 +00:00
|
|
|
static void RequestReset();
|
2015-07-05 23:35:38 +00:00
|
|
|
static void Reset(bool softReset = true);
|
2014-07-01 16:44:01 +00:00
|
|
|
|
|
|
|
//Used to pause the emu loop to perform thread-safe operations
|
|
|
|
static void Pause();
|
|
|
|
|
|
|
|
//Used to resume the emu loop after calling Pause()
|
|
|
|
static void Resume();
|
2014-06-21 23:03:13 +00:00
|
|
|
|
2016-08-25 23:02:33 +00:00
|
|
|
std::shared_ptr<Debugger> GetDebugger(bool autoStart = true);
|
2015-08-22 02:42:44 +00:00
|
|
|
void StopDebugger();
|
2015-06-24 23:26:19 +00:00
|
|
|
|
2016-02-06 04:14:27 +00:00
|
|
|
static NesModel GetNesModel();
|
2014-07-01 16:44:01 +00:00
|
|
|
static void SaveState(ostream &saveStream);
|
|
|
|
static void LoadState(istream &loadStream);
|
2014-07-06 23:54:47 +00:00
|
|
|
static void LoadState(uint8_t *buffer, uint32_t bufferSize);
|
2014-06-26 01:52:37 +00:00
|
|
|
|
2016-08-21 02:07:56 +00:00
|
|
|
static void LoadROM(string filepath, stringstream *filestream = nullptr, int32_t archiveFileIndex = -1, string ipsFile = "");
|
2015-07-11 12:27:22 +00:00
|
|
|
static bool LoadROM(string romName, uint32_t crc32Hash);
|
|
|
|
static string GetROMPath();
|
2016-06-18 00:53:05 +00:00
|
|
|
static string GetRomName();
|
2016-01-29 01:47:16 +00:00
|
|
|
static uint32_t GetCrc32();
|
2016-07-10 13:05:41 +00:00
|
|
|
static uint32_t GetPrgCrc32();
|
2016-07-02 03:54:31 +00:00
|
|
|
static NesModel GetModel();
|
2014-07-09 22:29:07 +00:00
|
|
|
|
2016-07-10 22:22:37 +00:00
|
|
|
static uint32_t GetLagCounter();
|
|
|
|
static void ResetLagCounter();
|
|
|
|
|
2016-02-14 17:58:35 +00:00
|
|
|
static bool IsRunning();
|
|
|
|
|
2016-11-26 23:04:09 +00:00
|
|
|
static bool IsDebuggerAttached();
|
|
|
|
|
2015-07-02 03:17:14 +00:00
|
|
|
static shared_ptr<Console> GetInstance();
|
2015-07-21 03:20:41 +00:00
|
|
|
static void Release();
|
2014-06-14 15:27:55 +00:00
|
|
|
};
|