diff --git a/src/InputMappings.cpp b/src/InputMappings.cpp index a119a83..541045c 100644 --- a/src/InputMappings.cpp +++ b/src/InputMappings.cpp @@ -23,6 +23,7 @@ extern "C" { #include "rpi-aux.h" +extern void usDelay(unsigned nMicroSeconds); } extern void Reboot_Pi(void); @@ -67,6 +68,7 @@ bool InputMappings::CheckButtonsBrowseMode() SetButtonFlag(FUNCTION_FLAG); inputROMOrDevice = 11; } + insertButtonPressedPrev = false; } else if (IEC_Bus::GetInputButtonHeld(INPUT_BUTTON_ENTER)) // Change ROMs { @@ -90,6 +92,7 @@ bool InputMappings::CheckButtonsBrowseMode() SetButtonFlag(FUNCTION_FLAG); inputROMOrDevice = 4; } + enterButtonPressedPrev = false; } else if (IEC_Bus::GetInputButtonRepeating(INPUT_BUTTON_UP)) SetButtonFlag(UP_FLAG); @@ -97,21 +100,41 @@ bool InputMappings::CheckButtonsBrowseMode() SetButtonFlag(DOWN_FLAG); else if (IEC_Bus::GetInputButtonPressed(INPUT_BUTTON_BACK)) SetButtonFlag(BACK_FLAG); + else + { + // edge detection + insertButtonPressed = !IEC_Bus::GetInputButtonReleased(INPUT_BUTTON_INSERT); + if (insertButtonPressedPrev && !insertButtonPressed) + SetButtonFlag(INSERT_FLAG); + insertButtonPressedPrev = insertButtonPressed; -// edge detection - insertButtonPressed = !IEC_Bus::GetInputButtonReleased(INPUT_BUTTON_INSERT); - if (insertButtonPressedPrev && !insertButtonPressed) - SetButtonFlag(INSERT_FLAG); - insertButtonPressedPrev = insertButtonPressed; - - enterButtonPressed = !IEC_Bus::GetInputButtonReleased(INPUT_BUTTON_ENTER); - if (enterButtonPressedPrev && !enterButtonPressed) - SetButtonFlag(ENTER_FLAG); - enterButtonPressedPrev = enterButtonPressed; + enterButtonPressed = !IEC_Bus::GetInputButtonReleased(INPUT_BUTTON_ENTER); + if (enterButtonPressedPrev && !enterButtonPressed) + SetButtonFlag(ENTER_FLAG); + enterButtonPressedPrev = enterButtonPressed; + } return buttonFlags != 0; } +void InputMappings::WaitForClearButtons() +{ + buttonFlags = 0; + + do + { + IEC_Bus::ReadBrowseMode(); + + insertButtonPressed = !IEC_Bus::GetInputButtonReleased(INPUT_BUTTON_INSERT); + insertButtonPressedPrev = insertButtonPressed; + + enterButtonPressed = !IEC_Bus::GetInputButtonReleased(INPUT_BUTTON_ENTER); + enterButtonPressedPrev = enterButtonPressed; + + usDelay(1); + } while (insertButtonPressedPrev || enterButtonPressedPrev); +} + void InputMappings::CheckButtonsEmulationMode() { buttonFlags = 0; diff --git a/src/InputMappings.h b/src/InputMappings.h index cec7a8f..e0dad43 100644 --- a/src/InputMappings.h +++ b/src/InputMappings.h @@ -84,6 +84,8 @@ public: bool CheckButtonsBrowseMode(); void CheckButtonsEmulationMode(); + void WaitForClearButtons(); + u8 INPUT_BUTTON_ENTER = 0; u8 INPUT_BUTTON_UP = 1; u8 INPUT_BUTTON_DOWN = 2; diff --git a/src/main.cpp b/src/main.cpp index 018d963..44e9fe4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -618,6 +618,7 @@ EmulatingMode BeginEmulating(FileBrowser* fileBrowser, const char* filenameForIc return EMULATING_1541; } } + inputMappings->WaitForClearButtons(); return IEC_COMMANDS; } @@ -1251,6 +1252,8 @@ void emulator() if ((exitReason == EXIT_RESET) && (options.GetOnResetChangeToStartingFolder() || selectedViaIECCommands)) fileBrowser->DisplayRoot(); // TO CHECK + + inputMappings->WaitForClearButtons(); } } delete fileBrowser;