Skip to content

Commit

Permalink
Add preliminary official MiSTer support
Browse files Browse the repository at this point in the history
With this, the old "MiSTer mode" hotkey has been removed: now, when used with a compatible OF-enabled MiSTer_Main, the MiSTer input subsystem will automatically send signals to all OpenFIRE guns to so that they will respond as gamepad devices without user input or pre-setup.

Because MiSTer doesn't like certain buttons (mainly triggers), MiSTer mode uses a predefined gamepad layout tailored to the system so that all buttons will be mapped the same (even after the inevitable Button Function Remap mode is introduced).
  • Loading branch information
SeongGino authored Sep 26, 2024
1 parent 8d2728f commit 2f22ba7
Showing 1 changed file with 36 additions and 20 deletions.
56 changes: 36 additions & 20 deletions SamcoEnhanced/SamcoEnhanced.ino
Original file line number Diff line number Diff line change
Expand Up @@ -199,20 +199,20 @@ enum ButtonMask_e {
// see LightgunButtons::Desc_t, format is:
// {pin, report type, report code (ignored for internal), offscreen report type, offscreen report code, gamepad output report type, gamepad output report code, debounce time, debounce mask, label}
LightgunButtons::Desc_t LightgunButtons::ButtonDesc[] = {
{SamcoPreferences::pins.bTrigger, LightgunButtons::ReportType_Internal, MOUSE_LEFT, LightgunButtons::ReportType_Internal, MOUSE_LEFT, LightgunButtons::ReportType_Internal, PAD_RT, 15, BTN_AG_MASK}, // Barry says: "I'll handle this."
{SamcoPreferences::pins.bGunA, LightgunButtons::ReportType_Mouse, MOUSE_RIGHT, LightgunButtons::ReportType_Mouse, MOUSE_RIGHT, LightgunButtons::ReportType_Gamepad, PAD_LT, 15, BTN_AG_MASK2},
{SamcoPreferences::pins.bGunB, LightgunButtons::ReportType_Mouse, MOUSE_MIDDLE, LightgunButtons::ReportType_Mouse, MOUSE_MIDDLE, LightgunButtons::ReportType_Gamepad, PAD_Y, 15, BTN_AG_MASK2},
{SamcoPreferences::pins.bStart, LightgunButtons::ReportType_Keyboard, playerStartBtn, LightgunButtons::ReportType_Keyboard, playerStartBtn, LightgunButtons::ReportType_Gamepad, PAD_START, 20, BTN_AG_MASK2},
{SamcoPreferences::pins.bSelect, LightgunButtons::ReportType_Keyboard, playerSelectBtn, LightgunButtons::ReportType_Keyboard, playerSelectBtn, LightgunButtons::ReportType_Gamepad, PAD_SELECT, 20, BTN_AG_MASK2},
{SamcoPreferences::pins.bGunUp, LightgunButtons::ReportType_Gamepad, PAD_UP, LightgunButtons::ReportType_Gamepad, PAD_UP, LightgunButtons::ReportType_Gamepad, PAD_UP, 20, BTN_AG_MASK2},
{SamcoPreferences::pins.bGunDown, LightgunButtons::ReportType_Gamepad, PAD_DOWN, LightgunButtons::ReportType_Gamepad, PAD_DOWN, LightgunButtons::ReportType_Gamepad, PAD_DOWN, 20, BTN_AG_MASK2},
{SamcoPreferences::pins.bGunLeft, LightgunButtons::ReportType_Gamepad, PAD_LEFT, LightgunButtons::ReportType_Gamepad, PAD_LEFT, LightgunButtons::ReportType_Gamepad, PAD_LEFT, 20, BTN_AG_MASK2},
{SamcoPreferences::pins.bGunRight, LightgunButtons::ReportType_Gamepad, PAD_RIGHT, LightgunButtons::ReportType_Gamepad, PAD_RIGHT, LightgunButtons::ReportType_Gamepad, PAD_RIGHT, 20, BTN_AG_MASK2},
{SamcoPreferences::pins.bGunC, LightgunButtons::ReportType_Mouse, MOUSE_BUTTON4, LightgunButtons::ReportType_Mouse, MOUSE_BUTTON4, LightgunButtons::ReportType_Gamepad, PAD_A, 15, BTN_AG_MASK2},
{SamcoPreferences::pins.bPedal, LightgunButtons::ReportType_Mouse, MOUSE_BUTTON4, LightgunButtons::ReportType_Mouse, MOUSE_BUTTON4, LightgunButtons::ReportType_Gamepad, PAD_X, 15, BTN_AG_MASK2},
{SamcoPreferences::pins.bPedal2, LightgunButtons::ReportType_Mouse, MOUSE_BUTTON5, LightgunButtons::ReportType_Mouse, MOUSE_BUTTON5, LightgunButtons::ReportType_Gamepad, PAD_B, 15, BTN_AG_MASK2},
{SamcoPreferences::pins.bPump, LightgunButtons::ReportType_Mouse, MOUSE_RIGHT, LightgunButtons::ReportType_Mouse, MOUSE_RIGHT, LightgunButtons::ReportType_Gamepad, PAD_LT, 15, BTN_AG_MASK2},
{SamcoPreferences::pins.bHome, LightgunButtons::ReportType_Internal, 0, LightgunButtons::ReportType_Internal, 0, LightgunButtons::ReportType_Internal, 0, 15, BTN_AG_MASK2}
{SamcoPreferences::pins.bTrigger, LightgunButtons::ReportType_Internal, MOUSE_LEFT, LightgunButtons::ReportType_Internal, MOUSE_LEFT, LightgunButtons::ReportType_Internal, PAD_RT, 15, BTN_AG_MASK}, // Barry says: "I'll handle this."
{SamcoPreferences::pins.bGunA, LightgunButtons::ReportType_Mouse, MOUSE_RIGHT, LightgunButtons::ReportType_Mouse, MOUSE_RIGHT, LightgunButtons::ReportType_Gamepad, PAD_LT, 15, BTN_AG_MASK2},
{SamcoPreferences::pins.bGunB, LightgunButtons::ReportType_Mouse, MOUSE_MIDDLE, LightgunButtons::ReportType_Mouse, MOUSE_MIDDLE, LightgunButtons::ReportType_Gamepad, PAD_Y, 15, BTN_AG_MASK2},
{SamcoPreferences::pins.bStart, LightgunButtons::ReportType_Keyboard, playerStartBtn, LightgunButtons::ReportType_Keyboard, playerStartBtn, LightgunButtons::ReportType_Gamepad, PAD_START, 20, BTN_AG_MASK2},
{SamcoPreferences::pins.bSelect, LightgunButtons::ReportType_Keyboard, playerSelectBtn, LightgunButtons::ReportType_Keyboard, playerSelectBtn, LightgunButtons::ReportType_Gamepad, PAD_SELECT, 20, BTN_AG_MASK2},
{SamcoPreferences::pins.bGunUp, LightgunButtons::ReportType_Gamepad, PAD_UP, LightgunButtons::ReportType_Gamepad, PAD_UP, LightgunButtons::ReportType_Gamepad, PAD_UP, 20, BTN_AG_MASK2},
{SamcoPreferences::pins.bGunDown, LightgunButtons::ReportType_Gamepad, PAD_DOWN, LightgunButtons::ReportType_Gamepad, PAD_DOWN, LightgunButtons::ReportType_Gamepad, PAD_DOWN, 20, BTN_AG_MASK2},
{SamcoPreferences::pins.bGunLeft, LightgunButtons::ReportType_Gamepad, PAD_LEFT, LightgunButtons::ReportType_Gamepad, PAD_LEFT, LightgunButtons::ReportType_Gamepad, PAD_LEFT, 20, BTN_AG_MASK2},
{SamcoPreferences::pins.bGunRight, LightgunButtons::ReportType_Gamepad, PAD_RIGHT, LightgunButtons::ReportType_Gamepad, PAD_RIGHT, LightgunButtons::ReportType_Gamepad, PAD_RIGHT, 20, BTN_AG_MASK2},
{SamcoPreferences::pins.bGunC, LightgunButtons::ReportType_Mouse, MOUSE_BUTTON4, LightgunButtons::ReportType_Mouse, MOUSE_BUTTON4, LightgunButtons::ReportType_Gamepad, PAD_A, 15, BTN_AG_MASK2},
{SamcoPreferences::pins.bPedal, LightgunButtons::ReportType_Mouse, MOUSE_BUTTON4, LightgunButtons::ReportType_Mouse, MOUSE_BUTTON4, LightgunButtons::ReportType_Gamepad, PAD_X, 15, BTN_AG_MASK2},
{SamcoPreferences::pins.bPedal2, LightgunButtons::ReportType_Mouse, MOUSE_BUTTON5, LightgunButtons::ReportType_Mouse, MOUSE_BUTTON5, LightgunButtons::ReportType_Gamepad, PAD_B, 15, BTN_AG_MASK2},
{SamcoPreferences::pins.bPump, LightgunButtons::ReportType_Mouse, MOUSE_RIGHT, LightgunButtons::ReportType_Mouse, MOUSE_RIGHT, LightgunButtons::ReportType_Gamepad, PAD_LT, 15, BTN_AG_MASK2},
{SamcoPreferences::pins.bHome, LightgunButtons::ReportType_Internal, 0, LightgunButtons::ReportType_Internal, 0, LightgunButtons::ReportType_Internal, 0, 15, BTN_AG_MASK2}
};

// button count constant
Expand Down Expand Up @@ -698,13 +698,10 @@ void setup() {
profileData[selectedProfile].rightOffset == 0)) { SetMode(GunMode_Calibration); }
else { SetMode(GunMode_Run); }
} else {
// unofficial official "MiSTer mode" - default to camera -> left stick if trigger's held.
// For some reason, doing this through buttons.Poll doesn't work, so just directly read the pin.
// (pullup resistors make this normally closed/1 when unpressed, open/0 when pressed.)
/* In case someone wants to implement functionality when user holds trigger on boot, here's the former "mister mode" template c:
if(SamcoPreferences::pins.bTrigger >= 0 && !digitalRead(SamcoPreferences::pins.bTrigger)) {
buttons.analogOutput = true;
Gamepad16.stickRight = true;
}
}*/
// this will turn off the DotStar/RGB LED and ensure proper transition to Run
SetMode(GunMode_Run);
}
Expand Down Expand Up @@ -3103,6 +3100,25 @@ void SerialProcessing()
buttons.analogOutput = true;
Gamepad16.stickRight = (Serial.peek() == 'L') ? true: false;
break;
// official "MiSTer optimized" mode
case '9':
buttons.analogOutput = true;
Gamepad16.stickRight = true;
// HACK SHACK - testing MiSTer-friendly default gamepad maps
LightgunButtons::ButtonDesc[BtnIdx_Trigger].reportCode3 = PAD_A,
LightgunButtons::ButtonDesc[BtnIdx_A].reportCode3 = PAD_B,
LightgunButtons::ButtonDesc[BtnIdx_B].reportCode3 = PAD_X,
LightgunButtons::ButtonDesc[BtnIdx_Reload].reportCode3 = PAD_Y,
LightgunButtons::ButtonDesc[BtnIdx_Start].reportCode3 = PAD_START,
LightgunButtons::ButtonDesc[BtnIdx_Select].reportCode3 = PAD_SELECT,
LightgunButtons::ButtonDesc[BtnIdx_Up].reportCode3 = PAD_UP,
LightgunButtons::ButtonDesc[BtnIdx_Down].reportCode3 = PAD_DOWN,
LightgunButtons::ButtonDesc[BtnIdx_Left].reportCode3 = PAD_LEFT,
LightgunButtons::ButtonDesc[BtnIdx_Right].reportCode3 = PAD_RIGHT,
LightgunButtons::ButtonDesc[BtnIdx_Pedal].reportCode3 = PAD_LB,
LightgunButtons::ButtonDesc[BtnIdx_Pedal2].reportCode3 = PAD_RB,
LightgunButtons::ButtonDesc[BtnIdx_Pump].reportCode3 = PAD_C;
break;
}
AbsMouse5.releaseAll();
Keyboard.releaseAll();
Expand Down

0 comments on commit 2f22ba7

Please sign in to comment.