Mesen-X/Core/ControlManager.h

64 lines
No EOL
1.8 KiB
C++

#pragma once
#include "stdafx.h"
#include "BaseControlDevice.h"
#include "IMemoryHandler.h"
#include "Movie.h"
#include "IGameBroadcaster.h"
#include "Snapshotable.h"
#include "../Utilities/SimpleLock.h"
#include "IKeyManager.h"
class BaseControlDevice;
class Zapper;
class ControlManager : public Snapshotable, public IMemoryHandler
{
private:
static unique_ptr<IKeyManager> _keyManager;
static shared_ptr<BaseControlDevice> _controlDevices[2];
static IGameBroadcaster* _gameBroadcaster;
bool _refreshState = false;
void RefreshAllPorts();
uint8_t GetPortValue(uint8_t port);
static shared_ptr<Zapper> GetZapper(uint8_t port);
static void RegisterControlDevice(shared_ptr<BaseControlDevice> controlDevice, uint8_t port);
void UnregisterControlDevice(uint8_t port);
protected:
virtual void StreamState(bool saving);
public:
ControlManager();
void UpdateControlDevices();
static void RegisterBroadcaster(IGameBroadcaster* gameBroadcaster);
static void UnregisterBroadcaster(IGameBroadcaster* gameBroadcaster);
static void RegisterKeyManager(IKeyManager* keyManager);
static bool IsKeyPressed(uint32_t keyCode);
static uint32_t GetPressedKey();
static string GetKeyName(uint32_t keyCode);
static uint32_t GetKeyCode(string keyName);
static shared_ptr<BaseControlDevice> GetControlDevice(uint8_t port);
static bool HasZapper();
static void ZapperSetPosition(uint8_t port, double x, double y);
static void ZapperSetTriggerState(uint8_t port, bool pulled);
static void BroadcastInput(uint8_t port, uint8_t state);
void GetMemoryRanges(MemoryRanges &ranges)
{
ranges.AddHandler(MemoryOperation::Read, 0x4016, 0x4017);
ranges.AddHandler(MemoryOperation::Write, 0x4016);
}
uint8_t ReadRAM(uint16_t addr);
void WriteRAM(uint16_t addr, uint8_t value);
};