2019-02-12 22:13:09 -05:00
|
|
|
#pragma once
|
|
|
|
#include "stdafx.h"
|
2019-03-12 09:15:57 -04:00
|
|
|
#include "CartTypes.h"
|
2019-07-25 22:22:09 -04:00
|
|
|
#include "DebugTypes.h"
|
2019-03-12 09:15:57 -04:00
|
|
|
#include "ConsoleLock.h"
|
2019-02-12 22:13:09 -05:00
|
|
|
#include "../Utilities/VirtualFile.h"
|
|
|
|
#include "../Utilities/SimpleLock.h"
|
|
|
|
|
|
|
|
class Cpu;
|
2019-02-13 13:32:21 -05:00
|
|
|
class Ppu;
|
2019-02-16 11:23:01 -05:00
|
|
|
class Spc;
|
2019-02-15 21:33:13 -05:00
|
|
|
class BaseCartridge;
|
2019-02-12 22:13:09 -05:00
|
|
|
class MemoryManager;
|
2019-02-17 15:37:31 -05:00
|
|
|
class InternalRegisters;
|
2019-02-17 19:54:29 -05:00
|
|
|
class ControlManager;
|
2019-02-19 21:09:12 -05:00
|
|
|
class DmaController;
|
2019-02-12 22:13:09 -05:00
|
|
|
class Debugger;
|
2019-02-13 23:02:43 -05:00
|
|
|
class DebugHud;
|
2019-02-16 11:23:01 -05:00
|
|
|
class SoundMixer;
|
2019-02-13 23:02:43 -05:00
|
|
|
class VideoRenderer;
|
|
|
|
class VideoDecoder;
|
2019-02-15 21:33:13 -05:00
|
|
|
class NotificationManager;
|
2019-03-10 11:12:50 -04:00
|
|
|
class EmuSettings;
|
2019-03-12 09:15:57 -04:00
|
|
|
class SaveStateManager;
|
2019-03-12 12:06:42 -04:00
|
|
|
class RewindManager;
|
2019-02-12 22:13:09 -05:00
|
|
|
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;
|
2019-02-12 22:13:09 -05:00
|
|
|
|
|
|
|
class Console : public std::enable_shared_from_this<Console>
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
shared_ptr<Cpu> _cpu;
|
2019-02-13 13:32:21 -05:00
|
|
|
shared_ptr<Ppu> _ppu;
|
2019-02-16 11:23:01 -05:00
|
|
|
shared_ptr<Spc> _spc;
|
2019-02-12 22:13:09 -05:00
|
|
|
shared_ptr<MemoryManager> _memoryManager;
|
2019-02-15 21:33:13 -05:00
|
|
|
shared_ptr<BaseCartridge> _cart;
|
2019-02-17 15:37:31 -05:00
|
|
|
shared_ptr<InternalRegisters> _internalRegisters;
|
2019-02-17 19:54:29 -05:00
|
|
|
shared_ptr<ControlManager> _controlManager;
|
2019-02-19 21:09:12 -05:00
|
|
|
shared_ptr<DmaController> _dmaController;
|
2019-02-17 15:37:31 -05:00
|
|
|
|
2019-02-12 22:13:09 -05:00
|
|
|
shared_ptr<Debugger> _debugger;
|
2019-02-13 23:02:43 -05:00
|
|
|
|
2019-02-15 21:33:13 -05:00
|
|
|
shared_ptr<NotificationManager> _notificationManager;
|
2019-02-16 11:23:01 -05:00
|
|
|
shared_ptr<SoundMixer> _soundMixer;
|
2019-02-13 23:02:43 -05:00
|
|
|
shared_ptr<VideoRenderer> _videoRenderer;
|
|
|
|
shared_ptr<VideoDecoder> _videoDecoder;
|
|
|
|
shared_ptr<DebugHud> _debugHud;
|
2019-03-10 11:12:50 -04:00
|
|
|
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;
|
2019-02-12 22:13:09 -05:00
|
|
|
|
2019-03-07 20:12:32 -05:00
|
|
|
thread::id _emulationThreadId;
|
2019-03-12 09:15:57 -04:00
|
|
|
|
|
|
|
atomic<uint32_t> _lockCounter;
|
2019-02-12 22:13:09 -05:00
|
|
|
SimpleLock _runLock;
|
2019-07-13 13:43:56 -04:00
|
|
|
SimpleLock _emulationLock;
|
2019-03-12 09:15:57 -04:00
|
|
|
|
2019-02-16 00:47:53 -05:00
|
|
|
SimpleLock _debuggerLock;
|
2019-02-12 22:13:09 -05:00
|
|
|
atomic<bool> _stopFlag;
|
2019-03-12 13:13:32 -04:00
|
|
|
atomic<bool> _paused;
|
2019-07-16 21:02:56 -04:00
|
|
|
atomic<bool> _pauseOnNextFrame;
|
2019-02-12 22:13:09 -05:00
|
|
|
|
2019-03-14 15:25:35 -04:00
|
|
|
ConsoleRegion _region;
|
|
|
|
uint32_t _masterClockRate;
|
|
|
|
|
2019-03-11 17:56:54 -04:00
|
|
|
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();
|
2019-03-11 17:56:54 -04:00
|
|
|
|
2019-02-12 22:13:09 -05:00
|
|
|
public:
|
2019-07-16 19:08:16 -04:00
|
|
|
Console();
|
2019-02-26 22:27:09 -05:00
|
|
|
~Console();
|
|
|
|
|
2019-02-13 23:02:43 -05:00
|
|
|
void Initialize();
|
2019-02-16 01:22:31 -05:00
|
|
|
void Release();
|
2019-02-13 23:02:43 -05:00
|
|
|
|
2019-02-12 22:13:09 -05:00
|
|
|
void Run();
|
2019-07-02 19:56:00 -04:00
|
|
|
void RunSingleFrame();
|
2019-03-14 18:07:25 -04:00
|
|
|
void Stop(bool sendNotification);
|
2019-02-12 22:13:09 -05:00
|
|
|
|
2019-03-16 12:20:18 -04:00
|
|
|
void Reset();
|
|
|
|
void PowerCycle();
|
|
|
|
|
2019-07-16 21:02:56 -04:00
|
|
|
void PauseOnNextFrame();
|
|
|
|
|
2019-03-12 13:13:32 -04:00
|
|
|
void Pause();
|
|
|
|
void Resume();
|
|
|
|
bool IsPaused();
|
|
|
|
|
2019-03-16 12:20:18 -04:00
|
|
|
bool LoadRom(VirtualFile romFile, VirtualFile patchFile, bool stopRom = true);
|
2019-03-12 09:15:57 -04:00
|
|
|
RomInfo GetRomInfo();
|
2019-03-14 15:25:35 -04:00
|
|
|
uint32_t GetMasterClockRate();
|
|
|
|
ConsoleRegion GetRegion();
|
2019-03-12 09:15:57 -04:00
|
|
|
|
|
|
|
ConsoleLock AcquireLock();
|
|
|
|
void Lock();
|
|
|
|
void Unlock();
|
|
|
|
|
|
|
|
void Serialize(ostream &out);
|
|
|
|
void Deserialize(istream &in, uint32_t fileFormatVersion);
|
2019-02-12 22:13:09 -05:00
|
|
|
|
2019-02-16 11:23:01 -05:00
|
|
|
shared_ptr<SoundMixer> GetSoundMixer();
|
2019-02-13 23:02:43 -05:00
|
|
|
shared_ptr<VideoRenderer> GetVideoRenderer();
|
|
|
|
shared_ptr<VideoDecoder> GetVideoDecoder();
|
2019-02-15 21:33:13 -05:00
|
|
|
shared_ptr<NotificationManager> GetNotificationManager();
|
2019-03-10 11:12:50 -04:00
|
|
|
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();
|
2019-02-13 23:02:43 -05:00
|
|
|
shared_ptr<DebugHud> GetDebugHud();
|
|
|
|
|
2019-02-13 18:44:39 -05:00
|
|
|
shared_ptr<Cpu> GetCpu();
|
2019-02-13 13:32:21 -05:00
|
|
|
shared_ptr<Ppu> GetPpu();
|
2019-02-16 11:23:01 -05:00
|
|
|
shared_ptr<Spc> GetSpc();
|
2019-02-15 21:33:13 -05:00
|
|
|
shared_ptr<BaseCartridge> GetCartridge();
|
2019-02-13 23:02:43 -05:00
|
|
|
shared_ptr<MemoryManager> GetMemoryManager();
|
2019-02-17 15:37:31 -05:00
|
|
|
shared_ptr<InternalRegisters> GetInternalRegisters();
|
2019-02-17 19:54:29 -05:00
|
|
|
shared_ptr<ControlManager> GetControlManager();
|
2019-02-19 21:09:12 -05:00
|
|
|
shared_ptr<DmaController> GetDmaController();
|
2019-03-16 12:20:18 -04:00
|
|
|
|
2019-02-16 00:47:53 -05:00
|
|
|
shared_ptr<Debugger> GetDebugger(bool autoStart = true);
|
2019-03-16 12:20:18 -04:00
|
|
|
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();
|
2019-02-12 22:13:09 -05:00
|
|
|
|
2019-07-25 22:22:09 -04:00
|
|
|
template<CpuType type> void ProcessMemoryRead(uint32_t addr, uint8_t value, MemoryOperationType opType);
|
|
|
|
template<CpuType type> void ProcessMemoryWrite(uint32_t addr, uint8_t value, MemoryOperationType opType);
|
2019-03-01 20:27:49 -05:00
|
|
|
void ProcessPpuRead(uint32_t addr, uint8_t value, SnesMemoryType memoryType);
|
|
|
|
void ProcessPpuWrite(uint32_t addr, uint8_t value, SnesMemoryType memoryType);
|
|
|
|
void ProcessWorkRamRead(uint32_t addr, uint8_t value);
|
|
|
|
void ProcessWorkRamWrite(uint32_t addr, uint8_t value);
|
2019-07-14 21:45:12 -04:00
|
|
|
void ProcessNecDspExec(uint32_t addr, uint32_t value);
|
2019-08-03 23:43:51 -04:00
|
|
|
void ProcessCx4Exec();
|
2019-03-03 16:34:23 -05:00
|
|
|
void ProcessPpuCycle();
|
2019-07-25 22:22:09 -04:00
|
|
|
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);
|
2019-07-25 22:22:09 -04:00
|
|
|
};
|