2014-06-21 15:43:41 -04:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "stdafx.h"
|
2016-02-05 23:14:27 -05:00
|
|
|
#include "BaseControlDevice.h"
|
2014-06-21 15:43:41 -04:00
|
|
|
#include "IMemoryHandler.h"
|
2014-07-01 12:44:01 -04:00
|
|
|
#include "Movie.h"
|
2014-07-06 19:54:47 -04:00
|
|
|
#include "IGameBroadcaster.h"
|
|
|
|
#include "Snapshotable.h"
|
2014-07-06 21:11:52 -04:00
|
|
|
#include "../Utilities/SimpleLock.h"
|
2015-07-10 21:07:24 -04:00
|
|
|
#include "IKeyManager.h"
|
2014-06-21 15:43:41 -04:00
|
|
|
|
2016-02-05 23:14:27 -05:00
|
|
|
class BaseControlDevice;
|
|
|
|
class Zapper;
|
|
|
|
|
2016-02-14 12:58:35 -05:00
|
|
|
struct MousePosition
|
|
|
|
{
|
|
|
|
int32_t X;
|
|
|
|
int32_t Y;
|
|
|
|
};
|
|
|
|
|
2014-07-06 19:54:47 -04:00
|
|
|
class ControlManager : public Snapshotable, public IMemoryHandler
|
2014-06-21 15:43:41 -04:00
|
|
|
{
|
|
|
|
private:
|
2015-07-10 21:07:24 -04:00
|
|
|
static unique_ptr<IKeyManager> _keyManager;
|
2016-02-05 23:14:27 -05:00
|
|
|
static shared_ptr<BaseControlDevice> _controlDevices[2];
|
|
|
|
static IGameBroadcaster* _gameBroadcaster;
|
2016-02-14 12:58:35 -05:00
|
|
|
static MousePosition _mousePosition;
|
2014-07-06 19:54:47 -04:00
|
|
|
|
2016-07-10 18:22:37 -04:00
|
|
|
bool _isLagging = false;
|
2014-06-21 15:43:41 -04:00
|
|
|
bool _refreshState = false;
|
|
|
|
|
2016-07-30 17:27:14 -04:00
|
|
|
template<typename T> shared_ptr<T> GetExpansionDevice();
|
|
|
|
|
2016-06-22 19:23:08 -04:00
|
|
|
virtual shared_ptr<BaseControlDevice> GetZapper(uint8_t port);
|
|
|
|
|
2016-02-05 23:14:27 -05:00
|
|
|
static void RegisterControlDevice(shared_ptr<BaseControlDevice> controlDevice, uint8_t port);
|
|
|
|
void UnregisterControlDevice(uint8_t port);
|
|
|
|
|
2014-07-06 19:54:47 -04:00
|
|
|
protected:
|
2016-04-30 20:08:53 -04:00
|
|
|
uint8_t GetPortValue(uint8_t port);
|
2016-07-10 09:05:41 -04:00
|
|
|
virtual void RefreshAllPorts();
|
|
|
|
|
2016-12-17 23:14:47 -05:00
|
|
|
virtual void StreamState(bool saving) override;
|
2014-07-06 19:54:47 -04:00
|
|
|
|
2014-06-21 15:43:41 -04:00
|
|
|
public:
|
|
|
|
ControlManager();
|
2016-07-10 19:26:08 -04:00
|
|
|
virtual ~ControlManager();
|
2014-06-21 15:43:41 -04:00
|
|
|
|
2016-02-05 23:14:27 -05:00
|
|
|
void UpdateControlDevices();
|
2016-07-10 18:22:37 -04:00
|
|
|
bool GetLagFlag();
|
2016-06-21 22:13:26 -04:00
|
|
|
|
|
|
|
virtual void Reset(bool softReset);
|
2016-02-05 23:14:27 -05:00
|
|
|
|
2014-07-06 19:54:47 -04:00
|
|
|
static void RegisterBroadcaster(IGameBroadcaster* gameBroadcaster);
|
|
|
|
static void UnregisterBroadcaster(IGameBroadcaster* gameBroadcaster);
|
|
|
|
|
2015-07-10 21:07:24 -04:00
|
|
|
static void RegisterKeyManager(IKeyManager* keyManager);
|
2016-09-02 19:36:37 -04:00
|
|
|
static void RefreshKeyState();
|
2015-07-10 21:07:24 -04:00
|
|
|
static bool IsKeyPressed(uint32_t keyCode);
|
2016-02-14 12:58:35 -05:00
|
|
|
static bool IsMouseButtonPressed(MouseButton button);
|
2015-07-10 21:07:24 -04:00
|
|
|
static uint32_t GetPressedKey();
|
2015-07-11 08:27:22 -04:00
|
|
|
static string GetKeyName(uint32_t keyCode);
|
|
|
|
static uint32_t GetKeyCode(string keyName);
|
2016-02-05 23:14:27 -05:00
|
|
|
|
|
|
|
static shared_ptr<BaseControlDevice> GetControlDevice(uint8_t port);
|
|
|
|
|
2016-02-14 12:58:35 -05:00
|
|
|
static void SetMousePosition(double x, double y);
|
|
|
|
static MousePosition GetMousePosition();
|
2015-07-10 21:07:24 -04:00
|
|
|
|
2016-02-05 23:14:27 -05:00
|
|
|
static void BroadcastInput(uint8_t port, uint8_t state);
|
2014-06-21 15:43:41 -04:00
|
|
|
|
2016-12-17 23:14:47 -05:00
|
|
|
virtual void GetMemoryRanges(MemoryRanges &ranges) override
|
2014-06-21 15:43:41 -04:00
|
|
|
{
|
2015-07-29 22:10:34 -04:00
|
|
|
ranges.AddHandler(MemoryOperation::Read, 0x4016, 0x4017);
|
|
|
|
ranges.AddHandler(MemoryOperation::Write, 0x4016);
|
2014-06-21 15:43:41 -04:00
|
|
|
}
|
|
|
|
|
2016-12-17 23:14:47 -05:00
|
|
|
virtual uint8_t ReadRAM(uint16_t addr) override;
|
|
|
|
virtual void WriteRAM(uint16_t addr, uint8_t value) override;
|
2014-06-21 15:43:41 -04:00
|
|
|
};
|