From 5ac2fe8c4595b3e51dfe230b60370503e8ae0b6b Mon Sep 17 00:00:00 2001 From: Stephen White Date: Sun, 29 Jul 2018 14:22:14 +1000 Subject: [PATCH] Buttons in browse mode can change the selected ROM Holding down the first button and pressing one of the other buttons will select different ROMs (if they have been specified in the options.txt file) --- src/FileBrowser.cpp | 121 ++++++++++++++++++++++++++++-------------- src/FileBrowser.h | 3 ++ src/InputMappings.cpp | 14 +++-- src/InputMappings.h | 3 ++ src/iec_bus.cpp | 10 ++-- 5 files changed, 102 insertions(+), 49 deletions(-) diff --git a/src/FileBrowser.cpp b/src/FileBrowser.cpp index 3e92ce5..b814393 100644 --- a/src/FileBrowser.cpp +++ b/src/FileBrowser.cpp @@ -386,6 +386,7 @@ FileBrowser::FileBrowser(DiskCaddy* diskCaddy, ROMs* roms, u8* deviceID, bool di , deviceID(deviceID) , displayPNGIcons(displayPNGIcons) , buttonChangedDevice(false) + , buttonSelectROM(false) , screenMain(screenMain) , screenLCD(screenLCD) , scrollHighlightRate(scrollHighlightRate) @@ -825,14 +826,12 @@ void FileBrowser::UpdateInputFolders() { if (inputMappings->BrowseSelect()) { - DEBUG_LOG("DEv8\r\n"); GlobalSetDeviceID(8); ShowDeviceAndROM(); buttonChangedDevice = true; } else if (inputMappings->BrowseUp()) { - DEBUG_LOG("DEv9\r\n"); GlobalSetDeviceID(9); ShowDeviceAndROM(); buttonChangedDevice = true; @@ -850,6 +849,29 @@ void FileBrowser::UpdateInputFolders() buttonChangedDevice = true; } } + else if (IEC_Bus::GetInputButtonHeld(0)) + { + if (inputMappings->BrowseUp()) + { + SelectROM(0); + buttonSelectROM = true; + } + else if (inputMappings->BrowseDown()) + { + SelectROM(1); + buttonSelectROM = true; + } + else if (inputMappings->BrowseBack()) + { + SelectROM(2); + buttonSelectROM = true; + } + else if (inputMappings->BrowseInsert()) + { + SelectROM(3); + buttonSelectROM = true; + } + } else { if (folder.entries.size() > 0) @@ -859,49 +881,56 @@ void FileBrowser::UpdateInputFolders() if (inputMappings->BrowseSelect()) { - FileBrowser::BrowsableList::Entry* current = folder.current; - if (current) + if (buttonSelectROM) { - if (current->filImage.fattrib & AM_DIR) + buttonSelectROM = false; + } + else + { + FileBrowser::BrowsableList::Entry* current = folder.current; + if (current) { - if (strcmp(current->filImage.fname, "..") == 0) + if (current->filImage.fattrib & AM_DIR) { - PopFolder(); - } - else if (strcmp(current->filImage.fname, ".") != 0) - { - f_chdir(current->filImage.fname); - RefreshFolderEntries(); - } - dirty = true; - } - else - { - if (strcmp(current->filImage.fname, "..") == 0) - { - PopFolder(); - } - else if (DiskImage::IsDiskImageExtention(current->filImage.fname)) - { - DiskImage::DiskType diskType = DiskImage::GetDiskImageTypeViaExtention(current->filImage.fname); - - // Should also be able to create a LST file from all the images currently selected in the caddy - if (diskType == DiskImage::LST) + if (strcmp(current->filImage.fname, "..") == 0) { - selectionsMade = SelectLST(current->filImage.fname); + PopFolder(); } - else + else if (strcmp(current->filImage.fname, ".") != 0) { - // Add the current selected - AddToCaddy(current); - selectionsMade = FillCaddyWithSelections(); + f_chdir(current->filImage.fname); + RefreshFolderEntries(); } - - if (selectionsMade) - lastSelectionName = current->filImage.fname; - dirty = true; } + else + { + if (strcmp(current->filImage.fname, "..") == 0) + { + PopFolder(); + } + else if (DiskImage::IsDiskImageExtention(current->filImage.fname)) + { + DiskImage::DiskType diskType = DiskImage::GetDiskImageTypeViaExtention(current->filImage.fname); + + // Should also be able to create a LST file from all the images currently selected in the caddy + if (diskType == DiskImage::LST) + { + selectionsMade = SelectLST(current->filImage.fname); + } + else + { + // Add the current selected + AddToCaddy(current); + selectionsMade = FillCaddyWithSelections(); + } + + if (selectionsMade) + lastSelectionName = current->filImage.fname; + + dirty = true; + } + } } } } @@ -957,12 +986,8 @@ void FileBrowser::UpdateInputFolders() || keyboard->KeyPressed(FileBrowser::SwapKeys[keySetIndexBase + 1]) || keyboard->KeyPressed(FileBrowser::SwapKeys[keySetIndexBase + 2])) { - if ( (keySetIndex < ROMs::MAX_ROMS) && (roms->ROMValid[keySetIndex]) ) + if (SelectROM(keySetIndex)) { - roms->currentROMIndex = keySetIndex; - roms->lastManualSelectedROMIndex = keySetIndex; - DEBUG_LOG("Swap ROM %d %s\r\n", keySetIndex, roms->ROMNames[keySetIndex]); - ShowDeviceAndROM(); } else if ( (keySetIndex >= 7) && (keySetIndex <= 10 ) ) { @@ -985,6 +1010,20 @@ void FileBrowser::UpdateInputFolders() } } +bool FileBrowser::SelectROM(u32 index) +{ + if ((index < ROMs::MAX_ROMS) && (roms->ROMValid[index])) + { + roms->currentROMIndex = index; + roms->lastManualSelectedROMIndex = index; + DEBUG_LOG("Swap ROM %d %s\r\n", index, roms->ROMNames[index]); + ShowDeviceAndROM(); + return true; + } + return false; +} + + bool FileBrowser::SelectLST(const char* filenameLST) { bool validImage = false; diff --git a/src/FileBrowser.h b/src/FileBrowser.h index 68da5e1..a2212a6 100644 --- a/src/FileBrowser.h +++ b/src/FileBrowser.h @@ -217,6 +217,8 @@ private: bool CheckForPNG(const char* filename, FILINFO& filIcon); void DisplayPNG(); + bool SelectROM(u32 index); + enum State { State_Folders, @@ -231,6 +233,7 @@ private: u8* deviceID; bool displayPNGIcons; bool buttonChangedDevice; + bool buttonSelectROM; BrowsableList caddySelections; diff --git a/src/InputMappings.cpp b/src/InputMappings.cpp index 17c0d1a..2a4ccc6 100644 --- a/src/InputMappings.cpp +++ b/src/InputMappings.cpp @@ -35,15 +35,18 @@ InputMappings::InputMappings() : keyboardBrowseLCDScreen(false) , insertButtonPressedPrev(false) , insertButtonPressed(false) + , enterButtonPressedPrev(false) + , enterButtonPressed(false) { } bool InputMappings::CheckButtonsBrowseMode() { buttonFlags = 0; - if (IEC_Bus::GetInputButtonPressed(0)) - SetButtonFlag(ENTER_FLAG); - else if (IEC_Bus::GetInputButtonRepeating(1)) + //if (IEC_Bus::GetInputButtonPressed(0)) + // SetButtonFlag(ENTER_FLAG); + //else + if (IEC_Bus::GetInputButtonRepeating(1)) SetButtonFlag(UP_FLAG); else if (IEC_Bus::GetInputButtonRepeating(2)) SetButtonFlag(DOWN_FLAG); @@ -57,6 +60,11 @@ bool InputMappings::CheckButtonsBrowseMode() SetButtonFlag(INSERT_FLAG); insertButtonPressedPrev = insertButtonPressed; + enterButtonPressed = !IEC_Bus::GetInputButtonReleased(0); + if (enterButtonPressedPrev && !enterButtonPressed) + SetButtonFlag(ENTER_FLAG); + enterButtonPressedPrev = enterButtonPressed; + return buttonFlags != 0; } diff --git a/src/InputMappings.h b/src/InputMappings.h index e884681..780ce77 100644 --- a/src/InputMappings.h +++ b/src/InputMappings.h @@ -53,6 +53,9 @@ protected: bool insertButtonPressedPrev; bool insertButtonPressed; + bool enterButtonPressedPrev; + bool enterButtonPressed; + //inline void SetUartFlag(unsigned flag) { uartFlags |= flag; } //inline bool UartFlag(unsigned flag) { return (uartFlags & flag) != 0; } inline void SetKeyboardFlag(unsigned flag) { keyboardFlags |= flag; } diff --git a/src/iec_bus.cpp b/src/iec_bus.cpp index 1d70734..f669716 100644 --- a/src/iec_bus.cpp +++ b/src/iec_bus.cpp @@ -51,12 +51,12 @@ bool IEC_Bus::ignoreReset = false; u32 IEC_Bus::myOutsGPFSEL1 = 0; u32 IEC_Bus::myOutsGPFSEL0 = 0; -bool IEC_Bus::InputButton[5]; -bool IEC_Bus::InputButtonPrev[5]; -u32 IEC_Bus::validInputCount[5]; +bool IEC_Bus::InputButton[5] = { 0 }; +bool IEC_Bus::InputButtonPrev[5] = { 0 }; +u32 IEC_Bus::validInputCount[5] = { 0 }; u32 IEC_Bus::inputRepeatThreshold[5]; -u32 IEC_Bus::inputRepeat[5]; -u32 IEC_Bus::inputRepeatPrev[5]; +u32 IEC_Bus::inputRepeat[5] = { 0 }; +u32 IEC_Bus::inputRepeatPrev[5] = { 0 }; m6522* IEC_Bus::VIA = 0;