2017-11-20 04:08:23 +00:00
|
|
|
#pragma once
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "StandardController.h"
|
|
|
|
#include "KeyManager.h"
|
|
|
|
|
|
|
|
class HoriTrack : public StandardController
|
|
|
|
{
|
2023-05-18 13:18:55 +00:00
|
|
|
private:
|
|
|
|
uint32_t _horiTrackState = 0;
|
|
|
|
|
2017-11-20 04:08:23 +00:00
|
|
|
protected:
|
|
|
|
bool HasCoordinates() override { return true; }
|
|
|
|
|
|
|
|
void InternalSetStateFromInput() override
|
|
|
|
{
|
|
|
|
StandardController::InternalSetStateFromInput();
|
|
|
|
SetPressedState(StandardController::Buttons::A, KeyManager::IsMouseButtonPressed(MouseButton::LeftButton));
|
|
|
|
SetPressedState(StandardController::Buttons::B, KeyManager::IsMouseButtonPressed(MouseButton::RightButton));
|
2018-07-14 02:19:26 +00:00
|
|
|
SetMovement(KeyManager::GetMouseMovement(_console->GetSettings()->GetMouseSensitivity(MouseDevice::HoriTrack)));
|
2017-11-20 04:08:23 +00:00
|
|
|
}
|
|
|
|
|
2023-05-18 13:18:55 +00:00
|
|
|
void StreamState(bool saving) override
|
|
|
|
{
|
|
|
|
BaseControlDevice::StreamState(saving);
|
|
|
|
Stream(_horiTrackState);
|
|
|
|
}
|
|
|
|
|
2017-11-20 04:08:23 +00:00
|
|
|
public:
|
2018-07-01 19:21:05 +00:00
|
|
|
HoriTrack(shared_ptr<Console> console, KeyMappingSet keyMappings) : StandardController(console, BaseControlDevice::ExpDevicePort, keyMappings)
|
2017-11-20 04:08:23 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-11-21 00:15:17 +00:00
|
|
|
uint8_t ReadRAM(uint16_t addr) override
|
2017-11-20 04:08:23 +00:00
|
|
|
{
|
|
|
|
uint8_t output = 0;
|
|
|
|
if(addr == 0x4016) {
|
2019-12-24 01:47:10 +00:00
|
|
|
StrobeProcessRead();
|
2023-05-18 13:18:55 +00:00
|
|
|
output = (_horiTrackState & 0x01) << 1;
|
|
|
|
_horiTrackState >>= 1;
|
2017-11-20 04:08:23 +00:00
|
|
|
}
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RefreshStateBuffer() override
|
|
|
|
{
|
|
|
|
MouseMovement mov = GetMovement();
|
|
|
|
|
|
|
|
mov.dx = std::max(-8, std::min((int)mov.dx, 7));
|
|
|
|
mov.dy = std::max(-8, std::min((int)mov.dy, 7));
|
|
|
|
|
|
|
|
mov.dx = ((mov.dx & 0x08) >> 3) | ((mov.dx & 0x04) >> 1) | ((mov.dx & 0x02) << 1) | ((mov.dx & 0x01) << 3);
|
|
|
|
mov.dy = ((mov.dy & 0x08) >> 3) | ((mov.dy & 0x04) >> 1) | ((mov.dy & 0x02) << 1) | ((mov.dy & 0x01) << 3);
|
|
|
|
|
|
|
|
uint8_t byte1 = (~mov.dy & 0x0F) | ((~mov.dx & 0x0F) << 4);
|
|
|
|
uint8_t byte2 = 0x09;
|
|
|
|
|
|
|
|
StandardController::RefreshStateBuffer();
|
2023-05-18 13:18:55 +00:00
|
|
|
_horiTrackState = (_horiTrackState & 0xFF) | (byte1 << 8) | (byte2 << 16);
|
2017-11-20 04:08:23 +00:00
|
|
|
}
|
|
|
|
};
|