1 #pragma once 2 #include "stdafx.h" 3 #include "StandardController.h" 4 #include "KeyManager.h" 5 6 class HoriTrack : public StandardController 7 { 8 protected: HasCoordinates()9 bool HasCoordinates() override { return true; } 10 InternalSetStateFromInput()11 void InternalSetStateFromInput() override 12 { 13 StandardController::InternalSetStateFromInput(); 14 SetPressedState(StandardController::Buttons::A, KeyManager::IsMouseButtonPressed(MouseButton::LeftButton)); 15 SetPressedState(StandardController::Buttons::B, KeyManager::IsMouseButtonPressed(MouseButton::RightButton)); 16 SetMovement(KeyManager::GetMouseMovement(_console->GetSettings()->GetMouseSensitivity(MouseDevice::HoriTrack))); 17 } 18 19 public: HoriTrack(shared_ptr<Console> console,KeyMappingSet keyMappings)20 HoriTrack(shared_ptr<Console> console, KeyMappingSet keyMappings) : StandardController(console, BaseControlDevice::ExpDevicePort, keyMappings) 21 { 22 } 23 ReadRAM(uint16_t addr)24 uint8_t ReadRAM(uint16_t addr) override 25 { 26 uint8_t output = 0; 27 if(addr == 0x4016) { 28 output = (_stateBuffer & 0x01) << 1; 29 _stateBuffer >>= 1; 30 StrobeProcessRead(); 31 } 32 return output; 33 } 34 RefreshStateBuffer()35 void RefreshStateBuffer() override 36 { 37 MouseMovement mov = GetMovement(); 38 39 mov.dx = std::max(-8, std::min((int)mov.dx, 7)); 40 mov.dy = std::max(-8, std::min((int)mov.dy, 7)); 41 42 mov.dx = ((mov.dx & 0x08) >> 3) | ((mov.dx & 0x04) >> 1) | ((mov.dx & 0x02) << 1) | ((mov.dx & 0x01) << 3); 43 mov.dy = ((mov.dy & 0x08) >> 3) | ((mov.dy & 0x04) >> 1) | ((mov.dy & 0x02) << 1) | ((mov.dy & 0x01) << 3); 44 45 uint8_t byte1 = (~mov.dy & 0x0F) | ((~mov.dx & 0x0F) << 4); 46 uint8_t byte2 = 0x09; 47 48 StandardController::RefreshStateBuffer(); 49 _stateBuffer = (_stateBuffer & 0xFF) | (byte1 << 8) | (byte2 << 16); 50 } 51 };