From 807cee02d27434592315de01b31ac3c275b64f20 Mon Sep 17 00:00:00 2001 From: penfold42 Date: Sun, 5 Aug 2018 18:26:33 +1000 Subject: [PATCH 1/8] InputMapping: merge letters and numbers --- src/FileBrowser.cpp | 25 ++++++++----------------- src/InputMappings.cpp | 28 +++++++++++++--------------- src/InputMappings.h | 18 ++++++++---------- 3 files changed, 29 insertions(+), 42 deletions(-) diff --git a/src/FileBrowser.cpp b/src/FileBrowser.cpp index 52402b4..aec7731 100644 --- a/src/FileBrowser.cpp +++ b/src/FileBrowser.cpp @@ -375,11 +375,7 @@ bool FileBrowser::BrowsableList::CheckBrowseNavigation() } // check for keys a-z and 0-9 - char searchChar = 0; - if (inputMappings->BrowseLetter()) - searchChar = inputMappings->getKeyboardLetter(); - if (inputMappings->BrowseNumber()) - searchChar = inputMappings->getKeyboardNumber(); + char searchChar = inputMappings->getKeyboardNumLetter(); if (searchChar) { char temp[8]; @@ -833,12 +829,7 @@ void FileBrowser::Update() dirty = inputMappings->CheckButtonsBrowseMode(); if (dirty) - { - //if (state == State_Folders) - UpdateInputFolders(); - //else - // UpdateInputDiskCaddy(); - } + UpdateInputFolders(); UpdateCurrentHighlight(); } @@ -1049,15 +1040,15 @@ void FileBrowser::UpdateInputFolders() } else { - // check for number keys for ROM and Drive Number changes - if (inputMappings->BrowseFunction() - && inputMappings->getKeyboardFunction() >= 1 - && inputMappings->getKeyboardFunction() <= 11 ) + // check Fkeys for ROM and Drive Number changes + unsigned ROMOrDevice = inputMappings->getROMOrDevice(); + if ( inputMappings->BrowseFunction() + && ROMOrDevice >= 1 + && ROMOrDevice <= 11 ) { - SelectROMOrDevice(inputMappings->getKeyboardFunction()); + SelectROMOrDevice(ROMOrDevice); } - dirty = folder.CheckBrowseNavigation(); } diff --git a/src/InputMappings.cpp b/src/InputMappings.cpp index 3f2a1e0..4cee775 100644 --- a/src/InputMappings.cpp +++ b/src/InputMappings.cpp @@ -44,18 +44,14 @@ InputMappings::InputMappings() bool InputMappings::CheckButtonsBrowseMode() { buttonFlags = 0; - //if (IEC_Bus::GetInputButtonPressed(0)) - // SetButtonFlag(ENTER_FLAG); - //else - if (IEC_Bus::GetInputButtonRepeating(1)) + if (IEC_Bus::GetInputButtonRepeating(1)) SetButtonFlag(UP_FLAG); else if (IEC_Bus::GetInputButtonRepeating(2)) SetButtonFlag(DOWN_FLAG); else if (IEC_Bus::GetInputButtonPressed(3)) SetButtonFlag(BACK_FLAG); - //else if (IEC_Bus::GetInputButtonPressed(4)) - // SetButtonFlag(INSERT_FLAG); +// edge detection insertButtonPressed = !IEC_Bus::GetInputButtonReleased(4); if (insertButtonPressedPrev && !insertButtonPressed) SetButtonFlag(INSERT_FLAG); @@ -152,6 +148,8 @@ bool InputMappings::CheckKeyboardBrowseMode() Keyboard* keyboard = Keyboard::Instance(); keyboardFlags = 0; + inputROMOrDevice = 0; + keyboardNumLetter = 0; if (keyboard->KeyHeld(KEY_DELETE) && keyboard->KeyLCtrlAlt() ) reboot_now(); @@ -206,26 +204,26 @@ bool InputMappings::CheckKeyboardBrowseMode() { if (keyboard->KeyHeld(index)) { - SetKeyboardFlag(NUMBER_FLAG); - keyboardNumber = index-KEY_1+'1'; // key 1 is ascii '1' - if (keyboardNumber > '9') keyboardNumber = '0'; + SetKeyboardFlag(NUMLET_FLAG); + keyboardNumLetter = index-KEY_1+'1'; // key 1 is ascii '1' + if (keyboardNumLetter > '9') keyboardNumLetter = '0'; } } for (index = KEY_KP1; index <= KEY_KP0; ++index) { if (keyboard->KeyHeld(index)) { - SetKeyboardFlag(NUMBER_FLAG); - keyboardNumber = index-KEY_KP1+'1'; // key 1 is ascii '1' - if (keyboardNumber > '9') keyboardNumber = '0'; + SetKeyboardFlag(NUMLET_FLAG); + keyboardNumLetter = index-KEY_KP1+'1'; // key 1 is ascii '1' + if (keyboardNumLetter > '9') keyboardNumLetter = '0'; } } for (index = KEY_A; index <= KEY_Z; ++index) { if (keyboard->KeyHeld(index)) { - SetKeyboardFlag(LETTER_FLAG); - keyboardLetter = index-KEY_A+'A'; // key A is ascii 'A' + SetKeyboardFlag(NUMLET_FLAG); + keyboardNumLetter = index-KEY_A+'A'; // key A is ascii 'A' } } for (index = KEY_F1; index <= KEY_F12; ++index) // F13 isnt contiguous @@ -233,7 +231,7 @@ bool InputMappings::CheckKeyboardBrowseMode() if (keyboard->KeyHeld(index)) { SetKeyboardFlag(FUNCTION_FLAG); - keyboardFunction = index-KEY_F1+1; // key F1 is 1 + inputROMOrDevice = index-KEY_F1+1; // key F1 is 1 } } } diff --git a/src/InputMappings.h b/src/InputMappings.h index 4f873fe..6dd4293 100644 --- a/src/InputMappings.h +++ b/src/InputMappings.h @@ -32,7 +32,8 @@ #define SPACE_FLAG (1 << 8) #define BACK_FLAG (1 << 9) #define INSERT_FLAG (1 << 10) -#define NUMBER_FLAG (1 << 11) + +#define NUMLET_FLAG (1 << 11) #define PAGEDOWN_LCD_FLAG (1 << 12) #define PAGEUP_LCD_FLAG (1 << 13) @@ -41,9 +42,10 @@ #define AUTOLOAD_FLAG (1 << 15) #define FAKERESET_FLAG (1 << 16) #define WRITEPROTECT_FLAG (1 << 17) -#define LETTER_FLAG (1 << 18) +//#define SPARE_FLAG (1 << 18) #define HOME_FLAG (1 << 19) #define END_FLAG (1 << 20) + #define FUNCTION_FLAG (1 << 21) // dont exceed 32!! @@ -78,9 +80,8 @@ protected: bool enterButtonPressedPrev; bool enterButtonPressed; - unsigned keyboardNumber; - unsigned keyboardLetter; - unsigned keyboardFunction; + unsigned keyboardNumLetter; + unsigned inputROMOrDevice; //inline void SetUartFlag(unsigned flag) { uartFlags |= flag; } //inline bool UartFlag(unsigned flag) { return (uartFlags & flag) != 0; } @@ -178,17 +179,14 @@ public: inline bool BrowseWriteProtect() { return KeyboardFlag(WRITEPROTECT_FLAG); } - inline bool BrowseNumber() { return KeyboardFlag(NUMBER_FLAG); } - inline bool BrowseLetter() { return KeyboardFlag(LETTER_FLAG); } inline bool BrowseFunction() { return KeyboardFlag(FUNCTION_FLAG); } inline bool BrowseHome() { return KeyboardFlag(HOME_FLAG); } inline bool BrowseEnd() { return KeyboardFlag(END_FLAG); } - inline char getKeyboardNumber() { return keyboardNumber; } - inline char getKeyboardLetter() { return (char) keyboardLetter; } - inline unsigned getKeyboardFunction() { return (char) keyboardFunction; } + inline char getKeyboardNumLetter() { return keyboardNumLetter; } + inline unsigned getROMOrDevice() { return inputROMOrDevice; } // Used by the 2 cores so need to be volatile //volatile static unsigned directDiskSwapRequest; From c42f4d364335e9b069bdd255dcec7ee663908917 Mon Sep 17 00:00:00 2001 From: penfold42 Date: Sun, 5 Aug 2018 20:20:48 +1000 Subject: [PATCH 2/8] move button rom and device code to inputmappings remove a temp buffer add defines for button numbers --- src/FileBrowser.cpp | 72 ++++++------------------------------------- src/InputMappings.cpp | 64 +++++++++++++++++++++++++++++++++----- src/InputMappings.h | 7 +++-- src/iec_bus.h | 6 ++++ 4 files changed, 77 insertions(+), 72 deletions(-) diff --git a/src/FileBrowser.cpp b/src/FileBrowser.cpp index aec7731..a7ba81f 100644 --- a/src/FileBrowser.cpp +++ b/src/FileBrowser.cpp @@ -378,16 +378,14 @@ bool FileBrowser::BrowsableList::CheckBrowseNavigation() char searchChar = inputMappings->getKeyboardNumLetter(); if (searchChar) { - char temp[8]; unsigned found=0; u32 i=0; - snprintf (temp, sizeof(temp), "%c", searchChar); // first look from next to last for (i=1+currentIndex; i <= numberOfEntriesMinus1 ; i++) { FileBrowser::BrowsableList::Entry* entry = &entries[i]; - if (strncasecmp(temp, entry->filImage.fname, 1) == 0) + if (strncasecmp(&searchChar, entry->filImage.fname, 1) == 0) { found=i; break; @@ -399,7 +397,7 @@ bool FileBrowser::BrowsableList::CheckBrowseNavigation() for (i=0; i< 1+currentIndex ; i++) { FileBrowser::BrowsableList::Entry* entry = &entries[i]; - if (strncasecmp(temp, entry->filImage.fname, 1) == 0) + if (strncasecmp(&searchChar, entry->filImage.fname, 1) == 0) { found=i; break; @@ -450,7 +448,6 @@ FileBrowser::FileBrowser(DiskCaddy* diskCaddy, ROMs* roms, u8* deviceID, bool di , roms(roms) , deviceID(deviceID) , displayPNGIcons(displayPNGIcons) - , buttonChangedROMDevice(false) , screenMain(screenMain) , screenLCD(screenLCD) , scrollHighlightRate(scrollHighlightRate) @@ -883,52 +880,12 @@ void FileBrowser::UpdateInputFolders() Keyboard* keyboard = Keyboard::Instance(); InputMappings* inputMappings = InputMappings::Instance(); - buttonChangedROMDevice = false; - if (IEC_Bus::GetInputButtonHeld(4)) + if (inputMappings->BrowseFunction()) { - if (inputMappings->BrowseSelect()) - { - SelectROMOrDevice(8); // == device 8 - buttonChangedROMDevice = true; - } - else if (inputMappings->BrowseUp()) - { - SelectROMOrDevice(9); // == device 9 - buttonChangedROMDevice = true; - } - else if (inputMappings->BrowseDown()) - { - SelectROMOrDevice(10); // == device 10 - buttonChangedROMDevice = true; - } - else if (inputMappings->BrowseBack()) - { - SelectROMOrDevice(11); // == device 11 - buttonChangedROMDevice = true; - } - } - else if (IEC_Bus::GetInputButtonHeld(0)) - { - if (inputMappings->BrowseUp()) - { - SelectROMOrDevice(1); - buttonChangedROMDevice = true; - } - else if (inputMappings->BrowseDown()) - { - SelectROMOrDevice(2); - buttonChangedROMDevice = true; - } - else if (inputMappings->BrowseBack()) - { - SelectROMOrDevice(3); - buttonChangedROMDevice = true; - } - else if (inputMappings->BrowseInsert()) - { - SelectROMOrDevice(4); - buttonChangedROMDevice = true; - } + // check for ROM and Drive Number changes + unsigned ROMOrDevice = inputMappings->getROMOrDevice(); + if ( ROMOrDevice >= 1 && ROMOrDevice <= 11 ) + SelectROMOrDevice(ROMOrDevice); } else { @@ -937,7 +894,7 @@ void FileBrowser::UpdateInputFolders() //u32 numberOfEntriesMinus1 = folder.entries.size() - 1; bool dirty = false; - if (inputMappings->BrowseSelect() && !buttonChangedROMDevice ) + if (inputMappings->BrowseSelect()) { FileBrowser::BrowsableList::Entry* current = folder.current; if (current) @@ -1004,7 +961,7 @@ void FileBrowser::UpdateInputFolders() ClearSelections(); dirty = true; } - else if (inputMappings->BrowseInsert() && !buttonChangedROMDevice ) + else if (inputMappings->BrowseInsert()) { FileBrowser::BrowsableList::Entry* current = folder.current; if (current) @@ -1040,21 +997,12 @@ void FileBrowser::UpdateInputFolders() } else { - // check Fkeys for ROM and Drive Number changes - unsigned ROMOrDevice = inputMappings->getROMOrDevice(); - if ( inputMappings->BrowseFunction() - && ROMOrDevice >= 1 - && ROMOrDevice <= 11 ) - { - SelectROMOrDevice(ROMOrDevice); - } - dirty = folder.CheckBrowseNavigation(); } if (dirty) RefeshDisplay(); } - else + else // no folder entries, could this ever happen?? ".." is everpresent? { if (inputMappings->BrowseBack()) PopFolder(); diff --git a/src/InputMappings.cpp b/src/InputMappings.cpp index 4cee775..ff15782 100644 --- a/src/InputMappings.cpp +++ b/src/InputMappings.cpp @@ -44,11 +44,58 @@ InputMappings::InputMappings() bool InputMappings::CheckButtonsBrowseMode() { buttonFlags = 0; - if (IEC_Bus::GetInputButtonRepeating(1)) + + if (IEC_Bus::GetInputButtonHeld(INPUT_BUTTON_INSERT)) // Change DeviceID + { + if (IEC_Bus::GetInputButtonRepeating(INPUT_BUTTON_ENTER)) + { + SetButtonFlag(FUNCTION_FLAG); + inputROMOrDevice = 8; + } + else if (IEC_Bus::GetInputButtonRepeating(INPUT_BUTTON_UP)) + { + SetButtonFlag(FUNCTION_FLAG); + inputROMOrDevice = 9; + } + else if (IEC_Bus::GetInputButtonRepeating(INPUT_BUTTON_DOWN)) + { + SetButtonFlag(FUNCTION_FLAG); + inputROMOrDevice = 10; + } + else if (IEC_Bus::GetInputButtonRepeating(INPUT_BUTTON_BACK)) + { + SetButtonFlag(FUNCTION_FLAG); + inputROMOrDevice = 11; + } + } + else if (IEC_Bus::GetInputButtonHeld(INPUT_BUTTON_ENTER)) // Change ROMs + { + if (IEC_Bus::GetInputButtonRepeating(INPUT_BUTTON_UP)) + { + SetButtonFlag(FUNCTION_FLAG); + inputROMOrDevice = 1; + } + else if (IEC_Bus::GetInputButtonRepeating(INPUT_BUTTON_DOWN)) + { + SetButtonFlag(FUNCTION_FLAG); + inputROMOrDevice = 2; + } + else if (IEC_Bus::GetInputButtonRepeating(INPUT_BUTTON_BACK)) + { + SetButtonFlag(FUNCTION_FLAG); + inputROMOrDevice = 3; + } + else if (IEC_Bus::GetInputButtonRepeating(INPUT_BUTTON_INSERT)) + { + SetButtonFlag(FUNCTION_FLAG); + inputROMOrDevice = 4; + } + } + else if (IEC_Bus::GetInputButtonRepeating(INPUT_BUTTON_UP)) SetButtonFlag(UP_FLAG); - else if (IEC_Bus::GetInputButtonRepeating(2)) + else if (IEC_Bus::GetInputButtonRepeating(INPUT_BUTTON_DOWN)) SetButtonFlag(DOWN_FLAG); - else if (IEC_Bus::GetInputButtonPressed(3)) + else if (IEC_Bus::GetInputButtonPressed(INPUT_BUTTON_BACK)) SetButtonFlag(BACK_FLAG); // edge detection @@ -69,14 +116,16 @@ void InputMappings::CheckButtonsEmulationMode() { buttonFlags = 0; - if (IEC_Bus::GetInputButtonPressed(0)) + if (IEC_Bus::GetInputButtonPressed(INPUT_BUTTON_ENTER)) SetButtonFlag(ESC_FLAG); - else if (IEC_Bus::GetInputButtonPressed(1)) + else if (IEC_Bus::GetInputButtonPressed(INPUT_BUTTON_UP)) SetButtonFlag(NEXT_FLAG); - else if (IEC_Bus::GetInputButtonPressed(2)) + else if (IEC_Bus::GetInputButtonPressed(INPUT_BUTTON_DOWN)) SetButtonFlag(PREV_FLAG); - //else if (IEC_Bus::GetInputButtonPressed(3)) + //else if (IEC_Bus::GetInputButtonPressed(INPUT_BUTTON_BACK)) // SetButtonFlag(BACK_FLAG); + //else if (IEC_Bus::GetInputButtonPressed(INPUT_BUTTON_INSERT)) + // SetButtonFlag(INSERT_FLAG); } @@ -148,7 +197,6 @@ bool InputMappings::CheckKeyboardBrowseMode() Keyboard* keyboard = Keyboard::Instance(); keyboardFlags = 0; - inputROMOrDevice = 0; keyboardNumLetter = 0; if (keyboard->KeyHeld(KEY_DELETE) && keyboard->KeyLCtrlAlt() ) diff --git a/src/InputMappings.h b/src/InputMappings.h index 6dd4293..9c5eaad 100644 --- a/src/InputMappings.h +++ b/src/InputMappings.h @@ -171,6 +171,11 @@ public: return KeyboardFlag(INSERT_FLAG)/* | UartFlag(INSERT_FLAG)*/ | ButtonFlag(INSERT_FLAG); } + inline bool BrowseFunction() + { + return KeyboardFlag(FUNCTION_FLAG) | ButtonFlag(FUNCTION_FLAG); + } + inline bool BrowseNewD64() { return KeyboardFlag(NEWD64_FLAG); } inline bool BrowseAutoLoad() { return KeyboardFlag(AUTOLOAD_FLAG); } @@ -179,8 +184,6 @@ public: inline bool BrowseWriteProtect() { return KeyboardFlag(WRITEPROTECT_FLAG); } - inline bool BrowseFunction() { return KeyboardFlag(FUNCTION_FLAG); } - inline bool BrowseHome() { return KeyboardFlag(HOME_FLAG); } inline bool BrowseEnd() { return KeyboardFlag(END_FLAG); } diff --git a/src/iec_bus.h b/src/iec_bus.h index 53aa5af..965075d 100644 --- a/src/iec_bus.h +++ b/src/iec_bus.h @@ -28,6 +28,12 @@ #define INPUT_BUTTON_DEBOUNCE_THRESHOLD 20000 #define INPUT_BUTTON_REPEAT_THRESHOLD 460000 +#define INPUT_BUTTON_ENTER 0 +#define INPUT_BUTTON_UP 1 +#define INPUT_BUTTON_DOWN 2 +#define INPUT_BUTTON_BACK 3 +#define INPUT_BUTTON_INSERT 4 + // DIN ATN is inverted and then connected to pb7 and ca1 // - also input to xor with ATNAout pb4 // - output of xor is inverted and connected to DIN pin 5 DATAout (OC so can only pull low) From a7cf8107d25cd3352fd3e748525f8f9dde17ba30 Mon Sep 17 00:00:00 2001 From: penfold42 Date: Sun, 5 Aug 2018 21:22:21 +1000 Subject: [PATCH 3/8] removed keyboard.h from filebrowser remove len>0 check from FileBrowser::UpdateInputFolders() removed NumberKeys table --- src/FileBrowser.cpp | 214 ++++++++++++++++++------------------------ src/InputMappings.cpp | 51 +++++----- src/InputMappings.h | 14 --- 3 files changed, 119 insertions(+), 160 deletions(-) diff --git a/src/FileBrowser.cpp b/src/FileBrowser.cpp index a7ba81f..709ee48 100644 --- a/src/FileBrowser.cpp +++ b/src/FileBrowser.cpp @@ -22,7 +22,6 @@ #include #include #include "debug.h" -#include "Keyboard.h" #include "options.h" #include "InputMappings.h" #include "stb_image.h" @@ -817,15 +816,8 @@ void FileBrowser::UpdateCurrentHighlight() void FileBrowser::Update() { InputMappings* inputMappings = InputMappings::Instance(); - Keyboard* keyboard = Keyboard::Instance(); - bool dirty = false; - if (keyboard->CheckChanged()) - dirty = inputMappings->CheckKeyboardBrowseMode(); - else - dirty = inputMappings->CheckButtonsBrowseMode(); - - if (dirty) + if ( inputMappings->CheckKeyboardBrowseMode() || inputMappings->CheckButtonsBrowseMode() ) UpdateInputFolders(); UpdateCurrentHighlight(); @@ -877,8 +869,8 @@ bool FileBrowser::AddToCaddy(FileBrowser::BrowsableList::Entry* current) void FileBrowser::UpdateInputFolders() { - Keyboard* keyboard = Keyboard::Instance(); InputMappings* inputMappings = InputMappings::Instance(); + bool dirty = false; if (inputMappings->BrowseFunction()) { @@ -887,131 +879,108 @@ void FileBrowser::UpdateInputFolders() if ( ROMOrDevice >= 1 && ROMOrDevice <= 11 ) SelectROMOrDevice(ROMOrDevice); } - else + else if (inputMappings->BrowseSelect()) { - if (folder.entries.size() > 0) + FileBrowser::BrowsableList::Entry* current = folder.current; + if (current) { - //u32 numberOfEntriesMinus1 = folder.entries.size() - 1; - bool dirty = false; - - if (inputMappings->BrowseSelect()) + if (current->filImage.fattrib & AM_DIR) { - 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 // not a directory + { + 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) - { - PopFolder(); - } - else if (strcmp(current->filImage.fname, ".") != 0) - { - f_chdir(current->filImage.fname); - RefreshFolderEntries(); - } - dirty = true; + selectionsMade = SelectLST(current->filImage.fname); } 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; - } - } - } - } - else if (inputMappings->BrowseDone()) - { - selectionsMade = FillCaddyWithSelections(); - } - //else if (keyboard->KeyPressed(KEY_TAB)) - //{ - // state = State_DiskCaddy; - // dirty = true; - //} - else if (inputMappings->BrowseBack()) - { - PopFolder(); - dirty = true; - } - else if (inputMappings->Exit()) - { - ClearSelections(); - dirty = true; - } - else if (inputMappings->BrowseInsert()) - { - FileBrowser::BrowsableList::Entry* current = folder.current; - if (current) - { - dirty = AddToCaddy(current); - } - } - else if (inputMappings->BrowseNewD64()) - { - char newFileName[64]; - strncpy (newFileName, options.GetAutoBaseName(), 63); - int num = folder.FindNextAutoName( newFileName ); - m_IEC_Commands.CreateD64(newFileName, "42", true); - FolderChanged(); - } - else if (inputMappings->BrowseWriteProtect()) - { - FileBrowser::BrowsableList::Entry* current = folder.current; - if (current) - { - if (current->filImage.fattrib & AM_RDO) - { - current->filImage.fattrib &= ~AM_RDO; - f_chmod(current->filImage.fname, 0, AM_RDO); - } - else - { - current->filImage.fattrib |= AM_RDO; - f_chmod(current->filImage.fname, AM_RDO, AM_RDO); + // Add the current selected + AddToCaddy(current); + selectionsMade = FillCaddyWithSelections(); } + + if (selectionsMade) + lastSelectionName = current->filImage.fname; + dirty = true; } } - else - { - dirty = folder.CheckBrowseNavigation(); - } - - if (dirty) RefeshDisplay(); - } - else // no folder entries, could this ever happen?? ".." is everpresent? - { - if (inputMappings->BrowseBack()) - PopFolder(); - } - if (inputMappings->BrowseAutoLoad()) - { - CheckAutoMountImage(EXIT_RESET, this); } } + else if (inputMappings->BrowseDone()) + { + selectionsMade = FillCaddyWithSelections(); + } + else if (inputMappings->BrowseBack()) + { + PopFolder(); + dirty = true; + } + else if (inputMappings->Exit()) + { + ClearSelections(); + dirty = true; + } + else if (inputMappings->BrowseInsert()) + { + FileBrowser::BrowsableList::Entry* current = folder.current; + if (current) + { + dirty = AddToCaddy(current); + } + } + else if (inputMappings->BrowseNewD64()) + { + char newFileName[64]; + strncpy (newFileName, options.GetAutoBaseName(), 63); + int num = folder.FindNextAutoName( newFileName ); + m_IEC_Commands.CreateD64(newFileName, "42", true); + FolderChanged(); + } + else if (inputMappings->BrowseWriteProtect()) + { + FileBrowser::BrowsableList::Entry* current = folder.current; + if (current) + { + if (current->filImage.fattrib & AM_RDO) + { + current->filImage.fattrib &= ~AM_RDO; + f_chmod(current->filImage.fname, 0, AM_RDO); + } + else + { + current->filImage.fattrib |= AM_RDO; + f_chmod(current->filImage.fname, AM_RDO, AM_RDO); + } + dirty = true; + } + } + else if (inputMappings->BrowseAutoLoad()) + { + CheckAutoMountImage(EXIT_RESET, this); + } + else + { + dirty = folder.CheckBrowseNavigation(); + } + + if (dirty) RefeshDisplay(); } bool FileBrowser::SelectROMOrDevice(u32 index) @@ -1084,11 +1053,11 @@ bool FileBrowser::SelectLST(const char* filenameLST) return validImage; } +/* // Not used void FileBrowser::UpdateInputDiskCaddy() { bool dirty = false; - Keyboard* keyboard = Keyboard::Instance(); if (keyboard->KeyPressed(KEY_DELETE)) { @@ -1110,6 +1079,7 @@ void FileBrowser::UpdateInputDiskCaddy() if (dirty) RefeshDisplay(); } +*/ void FileBrowser::DisplayStatusBar() { diff --git a/src/InputMappings.cpp b/src/InputMappings.cpp index ff15782..fb1abdd 100644 --- a/src/InputMappings.cpp +++ b/src/InputMappings.cpp @@ -198,6 +198,10 @@ bool InputMappings::CheckKeyboardBrowseMode() keyboardFlags = 0; keyboardNumLetter = 0; + if (!keyboard->CheckChanged()) + { + return false; + } if (keyboard->KeyHeld(KEY_DELETE) && keyboard->KeyLCtrlAlt() ) reboot_now(); @@ -293,32 +297,31 @@ void InputMappings::CheckKeyboardEmulationMode(unsigned numberOfImages, unsigned Keyboard* keyboard = Keyboard::Instance(); keyboardFlags = 0; - if (keyboard->CheckChanged()) + if (!keyboard->CheckChanged()) + return; + + if (keyboard->KeyHeld(KEY_DELETE) && keyboard->KeyLCtrlAlt() ) + reboot_now(); + + if (keyboard->KeyHeld(KEY_ESC)) + SetKeyboardFlag(ESC_FLAG); + else if (keyboard->KeyHeld(KEY_PAGEUP)) + SetKeyboardFlag(PREV_FLAG); + else if (keyboard->KeyHeld(KEY_PAGEDOWN)) + SetKeyboardFlag(NEXT_FLAG); + else if (keyboard->KeyHeld(KEY_A) && keyboard->KeyEitherAlt() ) + SetKeyboardFlag(AUTOLOAD_FLAG); + else if (keyboard->KeyHeld(KEY_R) && keyboard->KeyEitherAlt() ) + SetKeyboardFlag(FAKERESET_FLAG); + else if (numberOfImages > 1) { - - if (keyboard->KeyHeld(KEY_DELETE) && keyboard->KeyLCtrlAlt() ) - reboot_now(); - - if (keyboard->KeyHeld(KEY_ESC)) - SetKeyboardFlag(ESC_FLAG); - else if (keyboard->KeyHeld(KEY_PAGEUP)) - SetKeyboardFlag(PREV_FLAG); - else if (keyboard->KeyHeld(KEY_PAGEDOWN)) - SetKeyboardFlag(NEXT_FLAG); - else if (keyboard->KeyHeld(KEY_A) && keyboard->KeyEitherAlt() ) - SetKeyboardFlag(AUTOLOAD_FLAG); - else if (keyboard->KeyHeld(KEY_R) && keyboard->KeyEitherAlt() ) - SetKeyboardFlag(FAKERESET_FLAG); - else if (numberOfImages > 1) + unsigned index; + for (index = 0; index < 10; index++) { - unsigned index; - for (index = 0; index < sizeof(NumberKeys)/sizeof(NumberKeys[0]); index+=3) - { - if (keyboard->KeyHeld(NumberKeys[index]) - || keyboard->KeyHeld(NumberKeys[index + 1]) - || keyboard->KeyHeld(NumberKeys[index + 2]) ) - directDiskSwapRequest |= (1 << index/3); - } + if ( keyboard->KeyHeld(KEY_F1+index) + || keyboard->KeyHeld(KEY_1+index) + || keyboard->KeyHeld(KEY_KP1+index) ) + directDiskSwapRequest |= (1 << index); } } } diff --git a/src/InputMappings.h b/src/InputMappings.h index 9c5eaad..9d6c3f8 100644 --- a/src/InputMappings.h +++ b/src/InputMappings.h @@ -49,20 +49,6 @@ #define FUNCTION_FLAG (1 << 21) // dont exceed 32!! -const unsigned NumberKeys[33] = -{ - KEY_F1, KEY_KP1, KEY_1, - KEY_F2, KEY_KP2, KEY_2, - KEY_F3, KEY_KP3, KEY_3, - KEY_F4, KEY_KP4, KEY_4, - KEY_F5, KEY_KP5, KEY_5, - KEY_F6, KEY_KP6, KEY_6, - KEY_F7, KEY_KP7, KEY_7, - KEY_F8, KEY_KP8, KEY_8, - KEY_F9, KEY_KP9, KEY_9, - KEY_F10, KEY_KP0, KEY_0, - KEY_F11, KEY_KPMINUS, KEY_MINUS -}; class InputMappings : public Singleton { From 93985e46c099a0c684bb84a2b8610bd498e2c143 Mon Sep 17 00:00:00 2001 From: penfold42 Date: Sun, 5 Aug 2018 23:51:24 +1000 Subject: [PATCH 4/8] PopDir now hightlights the folder you were in --- src/FileBrowser.cpp | 48 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 11 deletions(-) diff --git a/src/FileBrowser.cpp b/src/FileBrowser.cpp index 709ee48..ad47611 100644 --- a/src/FileBrowser.cpp +++ b/src/FileBrowser.cpp @@ -756,17 +756,43 @@ void FileBrowser::DisplayPNG() void FileBrowser::PopFolder() { - f_chdir(".."); - //{ - // char buffer[1024]; - // if (f_getcwd(buffer, 1024) == FR_OK) - // { - // DEBUG_LOG("CWD = %s\r\n", buffer); - // } - //} - RefreshFolderEntries(); - caddySelections.Clear(); - RefeshDisplay(); + char buffer[1024]; + if (f_getcwd(buffer, 1024) == FR_OK) + { + // find the last '/' of the current dir + char *last_ptr = 0; + char *ptr = strtok(buffer, "/"); + while (ptr != NULL) + { + last_ptr = ptr; + ptr = strtok(NULL, "/"); + } + + f_chdir(".."); + RefreshFolderEntries(); + caddySelections.Clear(); + + unsigned found=0; + if (last_ptr) + { + u32 numberOfEntriesMinus1 = folder.entries.size() - 1; + for (unsigned i=0; i <= numberOfEntriesMinus1 ; i++) + { + FileBrowser::BrowsableList::Entry* entry = &folder.entries[i]; + if (strcmp(last_ptr, entry->filImage.fname) == 0) + { + found=i; + break; + } + } + } + if (found) + { + folder.currentIndex=found; + folder.SetCurrent(); + } + RefeshDisplay(); + } } void FileBrowser::UpdateCurrentHighlight() From 3152d4efd5bf07dca1dc61bf286da3e5638cd965 Mon Sep 17 00:00:00 2001 From: penfold42 Date: Tue, 7 Aug 2018 18:57:21 +1000 Subject: [PATCH 5/8] Browser: can a directory - all d64 in it are loaded into caddy --- src/FileBrowser.cpp | 25 +++++++++++++++++++++++++ src/FileBrowser.h | 1 + 2 files changed, 26 insertions(+) diff --git a/src/FileBrowser.cpp b/src/FileBrowser.cpp index ad47611..7951537 100644 --- a/src/FileBrowser.cpp +++ b/src/FileBrowser.cpp @@ -868,6 +868,31 @@ bool FileBrowser::FillCaddyWithSelections() } bool FileBrowser::AddToCaddy(FileBrowser::BrowsableList::Entry* current) +{ + if (!current) return false; + + else if (!(current->filImage.fattrib & AM_DIR) && DiskImage::IsDiskImageExtention(current->filImage.fname)) + { + return AddImageToCaddy(current); + } + else if (current->filImage.fattrib & AM_DIR) + { + bool ret = false; + f_chdir(current->filImage.fname); + RefreshFolderEntries(); + RefeshDisplay(); + + for (unsigned i = 0; i < folder.entries.size(); ++i) + ret |= AddImageToCaddy(&folder.entries[i]); + + RefeshDisplay(); + return ret; + } + return false; + +} + +bool FileBrowser::AddImageToCaddy(FileBrowser::BrowsableList::Entry* current) { bool added = false; diff --git a/src/FileBrowser.h b/src/FileBrowser.h index d6de6cc..f7e9c90 100644 --- a/src/FileBrowser.h +++ b/src/FileBrowser.h @@ -211,6 +211,7 @@ private: bool FillCaddyWithSelections(); bool AddToCaddy(FileBrowser::BrowsableList::Entry* current); + bool AddImageToCaddy(FileBrowser::BrowsableList::Entry* current); bool CheckForPNG(const char* filename, FILINFO& filIcon); void DisplayPNG(); From 680a4a5b03552660a33de1cc837ec6d97348cf17 Mon Sep 17 00:00:00 2001 From: penfold42 Date: Tue, 7 Aug 2018 19:46:27 +1000 Subject: [PATCH 6/8] dont try to insert ".." --- src/FileBrowser.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/FileBrowser.cpp b/src/FileBrowser.cpp index 7951537..15a5e96 100644 --- a/src/FileBrowser.cpp +++ b/src/FileBrowser.cpp @@ -875,7 +875,8 @@ bool FileBrowser::AddToCaddy(FileBrowser::BrowsableList::Entry* current) { return AddImageToCaddy(current); } - else if (current->filImage.fattrib & AM_DIR) + + else if ( (current->filImage.fattrib & AM_DIR) && ( strcmp(current->filImage.fname, "..") != 0) ) { bool ret = false; f_chdir(current->filImage.fname); From d08e5e781a7bf249a19895d775527435ad24d52e Mon Sep 17 00:00:00 2001 From: penfold42 Date: Tue, 7 Aug 2018 19:54:57 +1000 Subject: [PATCH 7/8] Move hightlight to last row --- src/FileBrowser.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/FileBrowser.cpp b/src/FileBrowser.cpp index 15a5e96..b8a0937 100644 --- a/src/FileBrowser.cpp +++ b/src/FileBrowser.cpp @@ -886,6 +886,9 @@ bool FileBrowser::AddToCaddy(FileBrowser::BrowsableList::Entry* current) for (unsigned i = 0; i < folder.entries.size(); ++i) ret |= AddImageToCaddy(&folder.entries[i]); + folder.currentIndex = folder.entries.size() - 1; + folder.SetCurrent(); + RefeshDisplay(); return ret; } From 05d89d25053f78ad7ae00380e406bd3f28ebd277 Mon Sep 17 00:00:00 2001 From: penfold42 Date: Wed, 8 Aug 2018 00:38:08 +1000 Subject: [PATCH 8/8] Browser: Alt-L to create LST file in current dir with all images included Also small optimise number scanner in inputmapping --- src/FileBrowser.cpp | 53 +++++++++++++++++++++++++++++++++++++++++++ src/FileBrowser.h | 1 + src/InputMappings.cpp | 18 +++++---------- src/InputMappings.h | 4 +++- 4 files changed, 63 insertions(+), 13 deletions(-) diff --git a/src/FileBrowser.cpp b/src/FileBrowser.cpp index b8a0937..15a992d 100644 --- a/src/FileBrowser.cpp +++ b/src/FileBrowser.cpp @@ -1030,6 +1030,23 @@ void FileBrowser::UpdateInputFolders() { CheckAutoMountImage(EXIT_RESET, this); } + else if (inputMappings->MakeLSTFile()) + { + MakeLST("autoswap.lst"); + FolderChanged(); + FileBrowser::BrowsableList::Entry* current = 0; + for (unsigned index = 0; index < folder.entries.size(); ++index) + { + current = &folder.entries[index]; + if (strcasecmp(current->filImage.fname, "autoswap.lst") == 0) + { + folder.currentIndex = index; + folder.SetCurrent(); + dirty=true; + break; + } + } + } else { dirty = folder.CheckBrowseNavigation(); @@ -1061,6 +1078,42 @@ bool FileBrowser::SelectROMOrDevice(u32 index) } +bool FileBrowser::MakeLST(const char* filenameLST) +{ + bool retcode=true; + FIL fp; + FRESULT res; + res = f_open(&fp, filenameLST, FA_CREATE_ALWAYS | FA_WRITE); + if (res == FR_OK) + { + FileBrowser::BrowsableList::Entry* entry = 0; + u32 bytes; + + for (unsigned index = 0; index < folder.entries.size(); ++index) + { + entry = &folder.entries[index]; + if (entry->filImage.fattrib & AM_DIR) + continue; // skip dirs + + if ( DiskImage::IsDiskImageExtention(entry->filImage.fname) + && !DiskImage::IsLSTExtention(entry->filImage.fname) ) + { + f_write(&fp, + entry->filImage.fname, + strlen(entry->filImage.fname), + &bytes); + f_write(&fp, "\r\n", 2, &bytes); + } + } + + f_close(&fp); + } + else + retcode=false; + + return retcode; +} + bool FileBrowser::SelectLST(const char* filenameLST) { bool validImage = false; diff --git a/src/FileBrowser.h b/src/FileBrowser.h index f7e9c90..c1be6d2 100644 --- a/src/FileBrowser.h +++ b/src/FileBrowser.h @@ -193,6 +193,7 @@ public: static u32 Colour(int index); + bool MakeLST(const char* filenameLST); bool SelectLST(const char* filenameLST); void SetScrollHighlightRate(float value) { scrollHighlightRate = value; } diff --git a/src/InputMappings.cpp b/src/InputMappings.cpp index fb1abdd..89b9e5e 100644 --- a/src/InputMappings.cpp +++ b/src/InputMappings.cpp @@ -246,30 +246,24 @@ bool InputMappings::CheckKeyboardBrowseMode() SetKeyboardFlag(FAKERESET_FLAG); else if (keyboard->KeyHeld(KEY_W) && keyboard->KeyEitherAlt() ) SetKeyboardFlag(WRITEPROTECT_FLAG); + else if (keyboard->KeyHeld(KEY_L) && keyboard->KeyEitherAlt() ) + SetKeyboardFlag(MAKELST_FLAG); else { if (keyboard->KeyNoModifiers()) { unsigned index; - for (index = KEY_1; index <= KEY_0; ++index) + for (index = 0; index <= 9; ++index) { - if (keyboard->KeyHeld(index)) + if (keyboard->KeyHeld(KEY_1+index) || keyboard->KeyHeld(KEY_KP1+index)) { SetKeyboardFlag(NUMLET_FLAG); - keyboardNumLetter = index-KEY_1+'1'; // key 1 is ascii '1' - if (keyboardNumLetter > '9') keyboardNumLetter = '0'; - } - } - for (index = KEY_KP1; index <= KEY_KP0; ++index) - { - if (keyboard->KeyHeld(index)) - { - SetKeyboardFlag(NUMLET_FLAG); - keyboardNumLetter = index-KEY_KP1+'1'; // key 1 is ascii '1' + keyboardNumLetter = index+'1'; // key 1 is ascii '1' if (keyboardNumLetter > '9') keyboardNumLetter = '0'; } } + for (index = KEY_A; index <= KEY_Z; ++index) { if (keyboard->KeyHeld(index)) diff --git a/src/InputMappings.h b/src/InputMappings.h index 9d6c3f8..0cfc119 100644 --- a/src/InputMappings.h +++ b/src/InputMappings.h @@ -42,7 +42,7 @@ #define AUTOLOAD_FLAG (1 << 15) #define FAKERESET_FLAG (1 << 16) #define WRITEPROTECT_FLAG (1 << 17) -//#define SPARE_FLAG (1 << 18) +#define MAKELST_FLAG (1 << 18) #define HOME_FLAG (1 << 19) #define END_FLAG (1 << 20) @@ -170,6 +170,8 @@ public: inline bool BrowseWriteProtect() { return KeyboardFlag(WRITEPROTECT_FLAG); } + inline bool MakeLSTFile() { return KeyboardFlag(MAKELST_FLAG); } + inline bool BrowseHome() { return KeyboardFlag(HOME_FLAG); } inline bool BrowseEnd() { return KeyboardFlag(END_FLAG); }