diff --git a/include/PSX/Periphery/periphery.hpp b/include/PSX/Periphery/periphery.hpp index 0bad0d42..ccbe6b65 100644 --- a/include/PSX/Periphery/periphery.hpp +++ b/include/PSX/Periphery/periphery.hpp @@ -4,8 +4,8 @@ namespace JabyEngine { namespace Periphery { - static constexpr uint32_t PortCount = Configuration::Periphery::UsePortB ? 2 : 1; - static constexpr uint32_t DeviceCount = Configuration::Periphery::UseMultiTap ? 4 : 1; + static constexpr uint32_t PortCount = Configuration::Periphery::IncludePortB ? 2 : 1; + static constexpr uint32_t DeviceCount = Configuration::Periphery::UseMultiTap ? 4 : 1; extern RawController controller[PortCount][DeviceCount]; diff --git a/include/PSX/jabyegine_config.hpp b/include/PSX/jabyegine_config.hpp index 47a99d4c..db8360d0 100644 --- a/include/PSX/jabyegine_config.hpp +++ b/include/PSX/jabyegine_config.hpp @@ -9,8 +9,8 @@ namespace JabyEngine { }; struct Periphery { - static constexpr bool UsePortB = false; - static constexpr bool UseMultiTap = false; + static constexpr bool IncludePortB = false; + static constexpr bool UseMultiTap = false; }; }; } \ No newline at end of file diff --git a/src/Library/src/Periphery/periphery.cpp b/src/Library/src/Periphery/periphery.cpp index 42611922..cbf3e0d5 100644 --- a/src/Library/src/Periphery/periphery.cpp +++ b/src/Library/src/Periphery/periphery.cpp @@ -4,7 +4,9 @@ namespace JabyEngine { namespace Periphery { - RawController controller[PortCount][DeviceCount]; + // Controllers are checked every alternating frame + static uint8_t cur_controller_port = 0; + RawController controller[PortCount][DeviceCount]; struct ControllerHelper { static bool is_config(const RawController &cont) { @@ -86,48 +88,47 @@ namespace JabyEngine { void query_controller() { static constexpr auto TypeIDX = 1; - for(uint32_t port = 0; port < Periphery::PortCount; port++) { - Periphery::connect_to(port); - for(uint32_t id = 0; id < Periphery::DeviceCount; id++) { - auto &cur_controller = controller[port][id]; + Periphery::connect_to(cur_controller_port); + for(uint32_t id = 0; id < Periphery::DeviceCount; id++) { + auto &cur_controller = controller[cur_controller_port][id]; - uint8_t header[] = {static_cast((id + 1)), 0x42, 0x0}; - uint8_t data[] = {cur_controller.header.rumble0, cur_controller.header.rumble1, 0x0, 0x0, 0x0, 0x0}; + uint8_t header[] = {static_cast((id + 1)), 0x42, 0x0}; + uint8_t data[] = {cur_controller.header.rumble0, cur_controller.header.rumble1, 0x0, 0x0, 0x0, 0x0}; - // Can this move to the if?? - set_config_command(cur_controller.header.state, header, data); - if(ControllerHelper::is_config(cur_controller)) { - send_data(header, header, data, data); - ControllerHelper::advance_config(cur_controller); - } + // Can this move to the if?? + set_config_command(cur_controller.header.state, header, data); + if(ControllerHelper::is_config(cur_controller)) { + send_data(header, header, data, data); + ControllerHelper::advance_config(cur_controller); + } - else { - cur_controller.button.exchange_state(); + else { + cur_controller.button.exchange_state(); - send_data(header, header, data, ControllerHelper::raw_device_data(cur_controller)); - const bool isValidController = (header[TypeIDX] != 0xFF); + send_data(header, header, data, ControllerHelper::raw_device_data(cur_controller)); + const bool isValidController = (header[TypeIDX] != 0xFF); - if(header[TypeIDX] != cur_controller.header.type) { - cur_controller.header.type = header[TypeIDX]; - cur_controller.header.state = isValidController ? RawController::State::EnterConfigMode : RawController::State::Disconnected; + if(header[TypeIDX] != cur_controller.header.type) { + cur_controller.header.type = header[TypeIDX]; + cur_controller.header.state = isValidController ? RawController::State::EnterConfigMode : RawController::State::Disconnected; - /*if(!isValidController) - { - printf("Disconnected!\n"); - } - - else - { - printf("ID: 0x%02X 0x%04X\n", header[TypeIDX], contData.button); - }*/ + /*if(!isValidController) + { + printf("Disconnected!\n"); } + + else + { + printf("ID: 0x%02X 0x%04X\n", header[TypeIDX], contData.button); + }*/ } } - Periphery::close_connection(); + } + Periphery::close_connection(); + + if(Configuration::Periphery::IncludePortB) { + cur_controller_port ^= 0x1; } } - - static_assert(!Configuration::Periphery::UsePortB, "Port B not supported yet"); - static_assert(!Configuration::Periphery::UseMultiTap, "MultiTap not supported yet"); } } \ No newline at end of file