1 #pragma once 2 #include "stdafx.h" 3 #include "StandardController.h" 4 5 class PachinkoController : public StandardController 6 { 7 private: 8 uint8_t _analogData = 0; 9 10 protected: 11 enum PachinkoButtons { Press = 8, Release = 9 }; 12 InternalSetStateFromInput()13 void InternalSetStateFromInput() override 14 { 15 StandardController::InternalSetStateFromInput(); 16 17 for(KeyMapping keyMapping : _keyMappings) { 18 SetPressedState(PachinkoButtons::Press, keyMapping.PachinkoButtons[0]); 19 SetPressedState(PachinkoButtons::Release, keyMapping.PachinkoButtons[1]); 20 } 21 } 22 23 public: PachinkoController(shared_ptr<Console> console,KeyMappingSet keyMappings)24 PachinkoController(shared_ptr<Console> console, KeyMappingSet keyMappings) : StandardController(console, BaseControlDevice::ExpDevicePort, keyMappings) 25 { 26 } 27 ReadRAM(uint16_t addr)28 uint8_t ReadRAM(uint16_t addr) override 29 { 30 uint8_t output = 0; 31 if(addr == 0x4016) { 32 output = (_stateBuffer & 0x01) << 1; 33 _stateBuffer >>= 1; 34 StrobeProcessRead(); 35 } 36 return output; 37 } 38 RefreshStateBuffer()39 void RefreshStateBuffer() override 40 { 41 if(_analogData < 63 && IsPressed(PachinkoController::PachinkoButtons::Press)) { 42 _analogData++; 43 } else if(_analogData > 0 && IsPressed(PachinkoController::PachinkoButtons::Release)) { 44 _analogData--; 45 } 46 47 uint8_t analogData = 48 ((_analogData & 0x01) << 7) | 49 ((_analogData & 0x02) << 5) | 50 ((_analogData & 0x04) << 3) | 51 ((_analogData & 0x08) << 1) | 52 ((_analogData & 0x10) >> 1) | 53 ((_analogData & 0x20) >> 3) | 54 ((_analogData & 0x40) >> 5) | 55 ((_analogData & 0x80) >> 7); 56 57 StandardController::RefreshStateBuffer(); 58 _stateBuffer = (_stateBuffer & 0xFF) | (~analogData << 8); 59 } 60 };