From 1b10b74c6e7863e8ddb78269be396e9a577a37f6 Mon Sep 17 00:00:00 2001 From: GAsinPrieto Date: Tue, 18 Jan 2022 09:28:17 +0100 Subject: [PATCH] PCE mode B enabled I have added support for mode B (e.g. AvePad 6) for games like Street Fighter II --- PCEngineControllerUSB/Gamepad.h | 2 +- .../PCEngineControllerUSB.ino | 31 +++++++++++++++++-- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/PCEngineControllerUSB/Gamepad.h b/PCEngineControllerUSB/Gamepad.h index 6e6513a..0185a33 100644 --- a/PCEngineControllerUSB/Gamepad.h +++ b/PCEngineControllerUSB/Gamepad.h @@ -34,7 +34,7 @@ extern const char* gp_serial; // The numbers after colon are bit fields, meaning how many bits the field uses. // Remove those if there are problems typedef struct { - uint8_t buttons : 4; + uint8_t buttons : 8; int8_t X; int8_t Y; } GamepadReport; diff --git a/PCEngineControllerUSB/PCEngineControllerUSB.ino b/PCEngineControllerUSB/PCEngineControllerUSB.ino index 70495e2..3580010 100644 --- a/PCEngineControllerUSB/PCEngineControllerUSB.ino +++ b/PCEngineControllerUSB/PCEngineControllerUSB.ino @@ -73,13 +73,17 @@ Gamepad_ Gamepad[GAMEPAD_COUNT]; // Controllers uint8_t buttons[2][2] = {{0,0},{0,0}}; -uint8_t buttonsPrev[2][2] = {{0,0},{0,0}}; +uint8_t buttonsPrevDPad[2] = {0,0}; +uint8_t buttonsPrevA[2] = {0,0}; +uint8_t buttonsPrevB[2] = {0,0}; uint8_t gp = 0; // Turbo timing uint32_t microsNow = 0; uint32_t microsEnable = 0; +int suma[2]={5,5}; + void setup() { // Set D0-D3 as inputs and enable pull-up resistors (port1 data pins) @@ -133,8 +137,11 @@ void loop() { while(1) // Send data to USB if values have changed for(gp=0; gp> DOWN_SH) + ((buttons[gp][0] & UP) >> UP_SH) + ((buttons[gp][0] & RIGHT) >> RIGHT_SH) + ((buttons[gp][0] & LEFT) >> LEFT_SH); + // Has any buttons changed state? - if (buttons[gp][0] != buttonsPrev[gp][0] || buttons[gp][1] != buttonsPrev[gp][1] ) +/* if (buttons[gp][0] != buttonsPrev[gp][0] || buttons[gp][1] != buttonsPrev[gp][1] ) { Gamepad[gp]._GamepadReport.buttons = buttons[gp][1]; Gamepad[gp]._GamepadReport.Y = ((buttons[gp][0] & DOWN) >> DOWN_SH) - ((buttons[gp][0] & UP) >> UP_SH); @@ -143,6 +150,24 @@ void loop() { while(1) buttonsPrev[gp][1] = buttons[gp][1]; Gamepad[gp].send(); } +*/ + + if ((suma[gp] == 4) && (buttons[gp][1]!=buttonsPrevB[gp])){ + Gamepad[gp]._GamepadReport.buttons = (buttons[gp][1] & B00001111) << 4; + buttonsPrevB[gp] = buttons[gp][1]; + Gamepad[gp].send(); + } + else if ((suma[gp] < 4) && ((buttons[gp][0]!=buttonsPrevDPad[gp]) || (buttons[gp][1]!=buttonsPrevA[gp]))){ + Gamepad[gp]._GamepadReport.buttons = (buttons[gp][1] & B00001111); + Gamepad[gp]._GamepadReport.Y = ((buttons[gp][0] & DOWN) >> DOWN_SH) - ((buttons[gp][0] & UP) >> UP_SH); + Gamepad[gp]._GamepadReport.X = ((buttons[gp][0] & RIGHT) >> RIGHT_SH) - ((buttons[gp][0] & LEFT) >> LEFT_SH); + buttonsPrevDPad[gp] = buttons[gp][0]; + buttonsPrevA[gp] = buttons[gp][1]; + Gamepad[gp].send(); + } + + + } -}} \ No newline at end of file +}}