2014-06-21 15:43:41 -04:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "stdafx.h"
|
2017-04-29 08:29:56 -04:00
|
|
|
#include "../Utilities/SimpleLock.h"
|
2014-06-21 15:43:41 -04:00
|
|
|
#include "IMemoryHandler.h"
|
2014-07-06 19:54:47 -04:00
|
|
|
#include "Snapshotable.h"
|
2014-06-21 15:43:41 -04:00
|
|
|
|
2016-02-05 23:14:27 -05:00
|
|
|
class BaseControlDevice;
|
|
|
|
class Zapper;
|
2017-11-19 23:08:23 -05:00
|
|
|
class SystemActionManager;
|
|
|
|
class IInputRecorder;
|
|
|
|
class IInputProvider;
|
|
|
|
struct ControlDeviceState;
|
|
|
|
enum class ControllerType;
|
|
|
|
enum class ExpansionPortDevice;
|
2016-02-14 12:58:35 -05:00
|
|
|
|
2014-07-06 19:54:47 -04:00
|
|
|
class ControlManager : public Snapshotable, public IMemoryHandler
|
2014-06-21 15:43:41 -04:00
|
|
|
{
|
2017-11-19 23:08:23 -05:00
|
|
|
private:
|
|
|
|
static ControlManager* _instance;
|
|
|
|
static vector<IInputRecorder*> _inputRecorders;
|
|
|
|
static vector<IInputProvider*> _inputProviders;
|
|
|
|
static SimpleLock _deviceLock;
|
|
|
|
|
2017-12-23 12:32:44 -05:00
|
|
|
//Static so that power cycle does not reset its value
|
|
|
|
static uint32_t _pollCounter;
|
|
|
|
|
2017-11-19 23:08:23 -05:00
|
|
|
vector<shared_ptr<BaseControlDevice>> _controlDevices;
|
|
|
|
|
|
|
|
shared_ptr<BaseControlDevice> _systemActionManager;
|
|
|
|
shared_ptr<BaseControlDevice> _mapperControlDevice;
|
|
|
|
|
2017-12-23 12:32:44 -05:00
|
|
|
|
2017-11-19 23:08:23 -05:00
|
|
|
uint32_t _lagCounter = 0;
|
|
|
|
bool _isLagging = false;
|
|
|
|
|
|
|
|
uint8_t GetOpenBusMask(uint8_t port);
|
|
|
|
void RegisterControlDevice(shared_ptr<BaseControlDevice> controlDevice);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void StreamState(bool saving) override;
|
|
|
|
virtual ControllerType GetControllerType(uint8_t port);
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
ControlManager(shared_ptr<BaseControlDevice> systemActionManager, shared_ptr<BaseControlDevice> mapperControlDevice);
|
|
|
|
virtual ~ControlManager();
|
|
|
|
|
|
|
|
void UpdateControlDevices();
|
|
|
|
void UpdateInputState();
|
|
|
|
|
|
|
|
uint32_t GetLagCounter();
|
|
|
|
void ResetLagCounter();
|
|
|
|
|
2017-12-23 12:32:44 -05:00
|
|
|
static uint32_t GetPollCounter();
|
|
|
|
static void ResetPollCounter();
|
|
|
|
|
2017-11-19 23:08:23 -05:00
|
|
|
virtual void Reset(bool softReset);
|
|
|
|
|
|
|
|
static void RegisterInputProvider(IInputProvider* provider);
|
|
|
|
static void UnregisterInputProvider(IInputProvider* provider);
|
|
|
|
|
|
|
|
static void RegisterInputRecorder(IInputRecorder* recorder);
|
|
|
|
static void UnregisterInputRecorder(IInputRecorder* recorder);
|
|
|
|
|
|
|
|
static vector<ControlDeviceState> GetPortStates();
|
|
|
|
|
|
|
|
static shared_ptr<BaseControlDevice> GetControlDevice(uint8_t port);
|
|
|
|
static shared_ptr<BaseControlDevice> CreateControllerDevice(ControllerType type, uint8_t port);
|
|
|
|
static shared_ptr<BaseControlDevice> CreateExpansionDevice(ExpansionPortDevice type);
|
2017-12-17 21:11:54 -05:00
|
|
|
static bool HasKeyboard();
|
2017-11-19 23:08:23 -05:00
|
|
|
|
|
|
|
virtual void GetMemoryRanges(MemoryRanges &ranges) override
|
|
|
|
{
|
|
|
|
ranges.AddHandler(MemoryOperation::Read, 0x4016, 0x4017);
|
|
|
|
ranges.AddHandler(MemoryOperation::Write, 0x4016);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual uint8_t ReadRAM(uint16_t addr) override;
|
|
|
|
virtual void WriteRAM(uint16_t addr, uint8_t value) override;
|
|
|
|
};
|