diff --git a/src/FileBrowser.cpp b/src/FileBrowser.cpp index 9dcb9b9..650e8b6 100644 --- a/src/FileBrowser.cpp +++ b/src/FileBrowser.cpp @@ -45,21 +45,6 @@ extern void CheckAutoMountImage(EXIT_TYPE reset_reason , FileBrowser* fileBrowse unsigned char FileBrowser::LSTBuffer[FileBrowser::LSTBuffer_size]; -const unsigned FileBrowser::SwapKeys[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 -}; - static const u32 palette[] = { RGBA(0x00, 0x00, 0x00, 0xFF), @@ -370,12 +355,72 @@ void FileBrowser::BrowsableList::RefreshViewsHighlightScroll() bool FileBrowser::BrowsableList::CheckBrowseNavigation() { + InputMappings* inputMappings = InputMappings::Instance(); + u32 numberOfEntriesMinus1 = entries.size() - 1; + bool dirty = false; u32 index; for (index = 0; index < views.size(); ++index) { dirty |= views[index].CheckBrowseNavigation(index != 0); } + + // check for keys a-z and 0-9 + char searchChar = 0; + if (inputMappings->BrowseLetter()) + searchChar = inputMappings->getKeyboardLetter(); + if (inputMappings->BrowseNumber()) + searchChar = inputMappings->getKeyboardNumber(); + 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) + { + found=i; + break; + } + } + if (!found) + { + // look from first to previous + for (i=0; i< 1+currentIndex ; i++) + { + FileBrowser::BrowsableList::Entry* entry = &entries[i]; + if (strncasecmp(temp, entry->filImage.fname, 1) == 0) + { + found=i; + break; + } + } + } + + if (found) + { + currentIndex=found; + SetCurrent(); + dirty |= 1; + } + } + else if (inputMappings->BrowseHome()) + { + currentIndex = 0; + SetCurrent(); + dirty |= 1; + } + else if (inputMappings->BrowseEnd()) + { + currentIndex = numberOfEntriesMinus1; + SetCurrent(); + dirty |= 1; + } return dirty; } @@ -400,8 +445,7 @@ FileBrowser::FileBrowser(DiskCaddy* diskCaddy, ROMs* roms, u8* deviceID, bool di , roms(roms) , deviceID(deviceID) , displayPNGIcons(displayPNGIcons) - , buttonChangedDevice(false) - , buttonSelectROM(false) + , buttonChangedROMDevice(false) , screenMain(screenMain) , screenLCD(screenLCD) , scrollHighlightRate(scrollHighlightRate) @@ -418,7 +462,8 @@ FileBrowser::FileBrowser(DiskCaddy* diskCaddy, ROMs* roms, u8* deviceID, bool di folder.AddView(screenMain, columns, rows, positionX, positionY, false); positionX = screenMain->ScaleX(1024 - 320); - caddySelections.AddView(screenMain, 6, rows, positionX, positionY, false); + columns = screenMain->ScaleX(40); + caddySelections.AddView(screenMain, columns, rows, positionX, positionY, false); @@ -837,54 +882,51 @@ void FileBrowser::UpdateInputFolders() Keyboard* keyboard = Keyboard::Instance(); InputMappings* inputMappings = InputMappings::Instance(); + buttonChangedROMDevice = false; if (IEC_Bus::GetInputButtonHeld(4)) { if (inputMappings->BrowseSelect()) { - GlobalSetDeviceID(8); - ShowDeviceAndROM(); - buttonChangedDevice = true; + SelectROMOrDevice(7); // == device 8 + buttonChangedROMDevice = true; } else if (inputMappings->BrowseUp()) { - GlobalSetDeviceID(9); - ShowDeviceAndROM(); - buttonChangedDevice = true; + SelectROMOrDevice(8); // == device 9 + buttonChangedROMDevice = true; } else if (inputMappings->BrowseDown()) { - GlobalSetDeviceID(10); - ShowDeviceAndROM(); - buttonChangedDevice = true; + SelectROMOrDevice(9); // == device 10 + buttonChangedROMDevice = true; } else if (inputMappings->BrowseBack()) { - GlobalSetDeviceID(11); - ShowDeviceAndROM(); - buttonChangedDevice = true; + SelectROMOrDevice(10); // == device 11 + buttonChangedROMDevice = true; } } else if (IEC_Bus::GetInputButtonHeld(0)) { if (inputMappings->BrowseUp()) { - SelectROM(0); - buttonSelectROM = true; + SelectROMOrDevice(0); + buttonChangedROMDevice = true; } else if (inputMappings->BrowseDown()) { - SelectROM(1); - buttonSelectROM = true; + SelectROMOrDevice(1); + buttonChangedROMDevice = true; } else if (inputMappings->BrowseBack()) { - SelectROM(2); - buttonSelectROM = true; + SelectROMOrDevice(2); + buttonChangedROMDevice = true; } else if (inputMappings->BrowseInsert()) { - SelectROM(3); - buttonSelectROM = true; + SelectROMOrDevice(3); + buttonChangedROMDevice = true; } } else @@ -894,57 +936,50 @@ void FileBrowser::UpdateInputFolders() //u32 numberOfEntriesMinus1 = folder.entries.size() - 1; bool dirty = false; - if (inputMappings->BrowseSelect()) + if (inputMappings->BrowseSelect() && !buttonChangedROMDevice ) { - if (buttonSelectROM) + FileBrowser::BrowsableList::Entry* current = folder.current; + if (current) { - buttonSelectROM = false; - } - else - { - FileBrowser::BrowsableList::Entry* current = folder.current; - if (current) + if (current->filImage.fattrib & AM_DIR) { - if (current->filImage.fattrib & AM_DIR) + if (strcmp(current->filImage.fname, "..") == 0) { - if (strcmp(current->filImage.fname, "..") == 0) - { - PopFolder(); - } - else if (strcmp(current->filImage.fname, ".") != 0) - { - f_chdir(current->filImage.fname); - RefreshFolderEntries(); - } - dirty = true; + PopFolder(); } - else + else if (strcmp(current->filImage.fname, ".") != 0) { - 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) { - PopFolder(); + selectionsMade = SelectLST(current->filImage.fname); } - else if (DiskImage::IsDiskImageExtention(current->filImage.fname)) + else { - 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; + // Add the current selected + AddToCaddy(current); + selectionsMade = FillCaddyWithSelections(); } + + if (selectionsMade) + lastSelectionName = current->filImage.fname; + + dirty = true; } } } @@ -968,19 +1003,12 @@ void FileBrowser::UpdateInputFolders() ClearSelections(); dirty = true; } - else if (inputMappings->BrowseInsert()) + else if (inputMappings->BrowseInsert() && !buttonChangedROMDevice ) { - if (buttonChangedDevice) + FileBrowser::BrowsableList::Entry* current = folder.current; + if (current) { - buttonChangedDevice = false; - } - else - { - FileBrowser::BrowsableList::Entry* current = folder.current; - if (current) - { - dirty = AddToCaddy(current); - } + dirty = AddToCaddy(current); } } else if (inputMappings->BrowseNewD64()) @@ -1011,25 +1039,15 @@ void FileBrowser::UpdateInputFolders() } else { - unsigned keySetIndex; - for (keySetIndex = 0; keySetIndex < 11; ++keySetIndex) + // check for number keys for ROM and Drive Number changes + if (inputMappings->BrowseFunction() + && inputMappings->getKeyboardFunction() >= 1 + && inputMappings->getKeyboardFunction() <= 11 ) { - unsigned keySetIndexBase = keySetIndex * 3; - if (keyboard->KeyPressed(FileBrowser::SwapKeys[keySetIndexBase]) - || keyboard->KeyPressed(FileBrowser::SwapKeys[keySetIndexBase + 1]) - || keyboard->KeyPressed(FileBrowser::SwapKeys[keySetIndexBase + 2])) - { - if (SelectROM(keySetIndex)) - { - } - else if ( (keySetIndex >= 7) && (keySetIndex <= 10 ) ) - { - GlobalSetDeviceID( keySetIndex+1 ); - ShowDeviceAndROM(); - } - } + SelectROMOrDevice(inputMappings->getKeyboardFunction()); } + dirty = folder.CheckBrowseNavigation(); } @@ -1047,8 +1065,17 @@ void FileBrowser::UpdateInputFolders() } } -bool FileBrowser::SelectROM(u32 index) +bool FileBrowser::SelectROMOrDevice(u32 index) +// 1-7 select ROM image +// 8-11 change deviceID to 8-11 { + if ( (index >= 8) && (index <= 11 ) ) + { + GlobalSetDeviceID( index ); + ShowDeviceAndROM(); + return true; + } + index--; if ((index < ROMs::MAX_ROMS) && (roms->ROMValid[index])) { roms->currentROMIndex = index; diff --git a/src/FileBrowser.h b/src/FileBrowser.h index 84f5a97..d6de6cc 100644 --- a/src/FileBrowser.h +++ b/src/FileBrowser.h @@ -191,8 +191,6 @@ public: static const long int LSTBuffer_size = 1024 * 8; static unsigned char LSTBuffer[]; - static const unsigned SwapKeys[]; - static u32 Colour(int index); bool SelectLST(const char* filenameLST); @@ -217,7 +215,7 @@ private: bool CheckForPNG(const char* filename, FILINFO& filIcon); void DisplayPNG(); - bool SelectROM(u32 index); + bool SelectROMOrDevice(u32 index); enum State { @@ -232,8 +230,7 @@ private: ROMs* roms; u8* deviceID; bool displayPNGIcons; - bool buttonChangedDevice; - bool buttonSelectROM; + bool buttonChangedROMDevice; BrowsableList caddySelections; diff --git a/src/InputMappings.cpp b/src/InputMappings.cpp index 9cb5140..a300ede 100644 --- a/src/InputMappings.cpp +++ b/src/InputMappings.cpp @@ -152,7 +152,6 @@ bool InputMappings::CheckKeyboardBrowseMode() keyboardFlags = 0; - // TODO: add KEY_HOME and KEY_END if (keyboard->KeyHeld(KEY_ESC)) SetKeyboardFlag(ESC_FLAG); else if (keyboard->KeyHeld(KEY_ENTER)) @@ -181,26 +180,58 @@ bool InputMappings::CheckKeyboardBrowseMode() else SetKeyboardFlag(PAGEDOWN_FLAG); } - //else if (keyboard->KeyHeld(KEY_HOME)) - // SetKeyboardFlag(PAGEUP_LCD_FLAG); - //else if (keyboard->KeyHeld(KEY_END)) - // SetKeyboardFlag(PAGEDOWN_LCD_FLAG); + else if (keyboard->KeyHeld(KEY_HOME)) + SetKeyboardFlag(HOME_FLAG); + else if (keyboard->KeyHeld(KEY_END)) + SetKeyboardFlag(END_FLAG); else if (keyboard->KeyHeld(KEY_N) && keyboard->KeyEitherAlt() ) SetKeyboardFlag(NEWD64_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 (keyboard->KeyHeld(KEY_W) && keyboard->KeyEitherAlt()) + else if (keyboard->KeyHeld(KEY_W) && keyboard->KeyEitherAlt() ) SetKeyboardFlag(WRITEPROTECT_FLAG); else { - unsigned index; - for (index = 0; index < 11; ++index) + if (keyboard->KeyNoModifiers()) { - unsigned keySetIndexBase = index * 3; - if (keyboard->KeyHeld(FileBrowser::SwapKeys[keySetIndexBase]) || keyboard->KeyHeld(FileBrowser::SwapKeys[keySetIndexBase + 1]) || keyboard->KeyHeld(FileBrowser::SwapKeys[keySetIndexBase + 2])) - keyboardFlags |= NUMBER_FLAG; + unsigned index; + + for (index = KEY_1; index <= KEY_0; ++index) + { + if (keyboard->KeyHeld(index)) + { + SetKeyboardFlag(NUMBER_FLAG); + keyboardNumber = index-KEY_1+'1'; // key 1 is ascii '1' + if (keyboardNumber > '9') keyboardNumber = '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'; + } + } + 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' + } + } + for (index = KEY_F1; index <= KEY_F12; ++index) // F13 isnt contiguous + { + if (keyboard->KeyHeld(index)) + { + SetKeyboardFlag(FUNCTION_FLAG); + keyboardFunction = index-KEY_F1+1; // key F1 is 1 + } + } } } @@ -227,12 +258,14 @@ void InputMappings::CheckKeyboardEmulationMode(unsigned numberOfImages, unsigned else if (numberOfImages > 1) { unsigned index; - for (index = 0; index < numberOfImagesMax; ++index) + for (index = 0; index < sizeof(NumberKeys)/sizeof(NumberKeys[0]); index+=3) { - unsigned keySetIndexBase = index * 3; - if (keyboard->KeyHeld(FileBrowser::SwapKeys[keySetIndexBase]) || keyboard->KeyHeld(FileBrowser::SwapKeys[keySetIndexBase + 1]) || keyboard->KeyHeld(FileBrowser::SwapKeys[keySetIndexBase + 2])) - directDiskSwapRequest |= (1 << index); + if (keyboard->KeyHeld(NumberKeys[index]) + || keyboard->KeyHeld(NumberKeys[index + 1]) + || keyboard->KeyHeld(NumberKeys[index + 2]) ) + directDiskSwapRequest |= (1 << index/3); } } } } + diff --git a/src/InputMappings.h b/src/InputMappings.h index ffce76e..4f873fe 100644 --- a/src/InputMappings.h +++ b/src/InputMappings.h @@ -41,8 +41,27 @@ #define AUTOLOAD_FLAG (1 << 15) #define FAKERESET_FLAG (1 << 16) #define WRITEPROTECT_FLAG (1 << 17) +#define LETTER_FLAG (1 << 18) +#define HOME_FLAG (1 << 19) +#define END_FLAG (1 << 20) +#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 { protected: @@ -59,6 +78,10 @@ protected: bool enterButtonPressedPrev; bool enterButtonPressed; + unsigned keyboardNumber; + unsigned keyboardLetter; + unsigned keyboardFunction; + //inline void SetUartFlag(unsigned flag) { uartFlags |= flag; } //inline bool UartFlag(unsigned flag) { return (uartFlags & flag) != 0; } inline void SetKeyboardFlag(unsigned flag) { keyboardFlags |= flag; } @@ -101,15 +124,9 @@ public: return KeyboardFlag(PREV_FLAG)/* | UartFlag(PREV_FLAG)*/ | ButtonFlag(PREV_FLAG); } - inline bool AutoLoad() - { - return KeyboardFlag(AUTOLOAD_FLAG); - } + inline bool AutoLoad() { return KeyboardFlag(AUTOLOAD_FLAG); } - inline bool FakeReset() - { - return KeyboardFlag(FAKERESET_FLAG); - } + inline bool FakeReset() { return KeyboardFlag(FAKERESET_FLAG); } inline bool BrowseSelect() { @@ -135,10 +152,7 @@ public: { return KeyboardFlag(PAGEUP_FLAG)/* | UartFlag(PAGEUP_FLAG)*/; } - inline bool BrowsePageUpLCD() - { - return KeyboardFlag(PAGEUP_LCD_FLAG); - } + inline bool BrowsePageUpLCD() { return KeyboardFlag(PAGEUP_LCD_FLAG); } inline bool BrowseDown() { @@ -149,35 +163,32 @@ public: { return KeyboardFlag(PAGEDOWN_FLAG)/* | UartFlag(PAGEDOWN_FLAG)*/; } - inline bool BrowsePageDownLCD() - { - return KeyboardFlag(PAGEDOWN_LCD_FLAG); - } + inline bool BrowsePageDownLCD() { return KeyboardFlag(PAGEDOWN_LCD_FLAG); } inline bool BrowseInsert() { return KeyboardFlag(INSERT_FLAG)/* | UartFlag(INSERT_FLAG)*/ | ButtonFlag(INSERT_FLAG); } - inline bool BrowseNewD64() - { - return KeyboardFlag(NEWD64_FLAG); - } + inline bool BrowseNewD64() { return KeyboardFlag(NEWD64_FLAG); } - inline bool BrowseAutoLoad() - { - return KeyboardFlag(AUTOLOAD_FLAG); - } + inline bool BrowseAutoLoad() { return KeyboardFlag(AUTOLOAD_FLAG); } - inline bool BrowseFakeReset() - { - return KeyboardFlag(FAKERESET_FLAG); - } + inline bool BrowseFakeReset() { return KeyboardFlag(FAKERESET_FLAG); } - inline bool BrowseWriteProtect() - { - return KeyboardFlag(WRITEPROTECT_FLAG); - } + 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; } // Used by the 2 cores so need to be volatile //volatile static unsigned directDiskSwapRequest; @@ -187,3 +198,4 @@ public: // static unsigned escapeSequenceIndex; }; #endif + diff --git a/src/Keyboard.h b/src/Keyboard.h index ad0e631..774ef6c 100644 --- a/src/Keyboard.h +++ b/src/Keyboard.h @@ -348,5 +348,9 @@ public: { return (modifier & (KEY_MOD_LALT | KEY_MOD_RALT) ); } + inline bool KeyNoModifiers() + { + return (!modifier ); + } }; #endif