Merge pull request #62 from penfold42/inputcleanup

PopDir highlight previous selection, Insert directory, Alt-L to create LST + Code cleanup
This commit is contained in:
Stephen White 2018-08-08 20:03:01 +10:00 committed by GitHub
commit 9b902f19bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 342 additions and 285 deletions

View File

@ -22,7 +22,6 @@
#include <strings.h> #include <strings.h>
#include <algorithm> #include <algorithm>
#include "debug.h" #include "debug.h"
#include "Keyboard.h"
#include "options.h" #include "options.h"
#include "InputMappings.h" #include "InputMappings.h"
#include "stb_image.h" #include "stb_image.h"
@ -375,23 +374,17 @@ bool FileBrowser::BrowsableList::CheckBrowseNavigation()
} }
// check for keys a-z and 0-9 // check for keys a-z and 0-9
char searchChar = 0; char searchChar = inputMappings->getKeyboardNumLetter();
if (inputMappings->BrowseLetter())
searchChar = inputMappings->getKeyboardLetter();
if (inputMappings->BrowseNumber())
searchChar = inputMappings->getKeyboardNumber();
if (searchChar) if (searchChar)
{ {
char temp[8];
unsigned found=0; unsigned found=0;
u32 i=0; u32 i=0;
snprintf (temp, sizeof(temp), "%c", searchChar);
// first look from next to last // first look from next to last
for (i=1+currentIndex; i <= numberOfEntriesMinus1 ; i++) for (i=1+currentIndex; i <= numberOfEntriesMinus1 ; i++)
{ {
FileBrowser::BrowsableList::Entry* entry = &entries[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; found=i;
break; break;
@ -403,7 +396,7 @@ bool FileBrowser::BrowsableList::CheckBrowseNavigation()
for (i=0; i< 1+currentIndex ; i++) for (i=0; i< 1+currentIndex ; i++)
{ {
FileBrowser::BrowsableList::Entry* entry = &entries[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; found=i;
break; break;
@ -454,7 +447,6 @@ FileBrowser::FileBrowser(DiskCaddy* diskCaddy, ROMs* roms, u8* deviceID, bool di
, roms(roms) , roms(roms)
, deviceID(deviceID) , deviceID(deviceID)
, displayPNGIcons(displayPNGIcons) , displayPNGIcons(displayPNGIcons)
, buttonChangedROMDevice(false)
, screenMain(screenMain) , screenMain(screenMain)
, screenLCD(screenLCD) , screenLCD(screenLCD)
, scrollHighlightRate(scrollHighlightRate) , scrollHighlightRate(scrollHighlightRate)
@ -764,17 +756,43 @@ void FileBrowser::DisplayPNG()
void FileBrowser::PopFolder() void FileBrowser::PopFolder()
{ {
f_chdir(".."); char buffer[1024];
//{ if (f_getcwd(buffer, 1024) == FR_OK)
// char buffer[1024]; {
// if (f_getcwd(buffer, 1024) == FR_OK) // find the last '/' of the current dir
// { char *last_ptr = 0;
// DEBUG_LOG("CWD = %s\r\n", buffer); char *ptr = strtok(buffer, "/");
// } while (ptr != NULL)
//} {
RefreshFolderEntries(); last_ptr = ptr;
caddySelections.Clear(); ptr = strtok(NULL, "/");
RefeshDisplay(); }
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() void FileBrowser::UpdateCurrentHighlight()
@ -824,21 +842,9 @@ void FileBrowser::UpdateCurrentHighlight()
void FileBrowser::Update() void FileBrowser::Update()
{ {
InputMappings* inputMappings = InputMappings::Instance(); InputMappings* inputMappings = InputMappings::Instance();
Keyboard* keyboard = Keyboard::Instance();
bool dirty = false;
if (keyboard->CheckChanged()) if ( inputMappings->CheckKeyboardBrowseMode() || inputMappings->CheckButtonsBrowseMode() )
dirty = inputMappings->CheckKeyboardBrowseMode(); UpdateInputFolders();
else
dirty = inputMappings->CheckButtonsBrowseMode();
if (dirty)
{
//if (state == State_Folders)
UpdateInputFolders();
//else
// UpdateInputDiskCaddy();
}
UpdateCurrentHighlight(); UpdateCurrentHighlight();
} }
@ -862,6 +868,35 @@ bool FileBrowser::FillCaddyWithSelections()
} }
bool FileBrowser::AddToCaddy(FileBrowser::BrowsableList::Entry* current) 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) && ( strcmp(current->filImage.fname, "..") != 0) )
{
bool ret = false;
f_chdir(current->filImage.fname);
RefreshFolderEntries();
RefeshDisplay();
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;
}
return false;
}
bool FileBrowser::AddImageToCaddy(FileBrowser::BrowsableList::Entry* current)
{ {
bool added = false; bool added = false;
@ -889,190 +924,135 @@ bool FileBrowser::AddToCaddy(FileBrowser::BrowsableList::Entry* current)
void FileBrowser::UpdateInputFolders() void FileBrowser::UpdateInputFolders()
{ {
Keyboard* keyboard = Keyboard::Instance();
InputMappings* inputMappings = InputMappings::Instance(); InputMappings* inputMappings = InputMappings::Instance();
bool dirty = false;
buttonChangedROMDevice = false; if (inputMappings->BrowseFunction())
if (IEC_Bus::GetInputButtonHeld(4))
{ {
if (inputMappings->BrowseSelect()) // check for ROM and Drive Number changes
unsigned ROMOrDevice = inputMappings->getROMOrDevice();
if ( ROMOrDevice >= 1 && ROMOrDevice <= 11 )
SelectROMOrDevice(ROMOrDevice);
}
else if (inputMappings->BrowseSelect())
{
FileBrowser::BrowsableList::Entry* current = folder.current;
if (current)
{ {
SelectROMOrDevice(8); // == device 8 if (current->filImage.fattrib & AM_DIR)
buttonChangedROMDevice = true; {
} if (strcmp(current->filImage.fname, "..") == 0)
else if (inputMappings->BrowseUp()) {
{ PopFolder();
SelectROMOrDevice(9); // == device 9 }
buttonChangedROMDevice = true; else if (strcmp(current->filImage.fname, ".") != 0)
} {
else if (inputMappings->BrowseDown()) f_chdir(current->filImage.fname);
{ RefreshFolderEntries();
SelectROMOrDevice(10); // == device 10 }
buttonChangedROMDevice = true; dirty = true;
} }
else if (inputMappings->BrowseBack()) else // not a directory
{ {
SelectROMOrDevice(11); // == device 11 if (DiskImage::IsDiskImageExtention(current->filImage.fname))
buttonChangedROMDevice = true; {
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 (IEC_Bus::GetInputButtonHeld(0)) else if (inputMappings->BrowseDone())
{ {
if (inputMappings->BrowseUp()) 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)
{ {
SelectROMOrDevice(1); dirty = AddToCaddy(current);
buttonChangedROMDevice = true;
} }
else if (inputMappings->BrowseDown()) }
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)
{ {
SelectROMOrDevice(2); if (current->filImage.fattrib & AM_RDO)
buttonChangedROMDevice = true; {
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->BrowseBack()) }
else if (inputMappings->BrowseAutoLoad())
{
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)
{ {
SelectROMOrDevice(3); current = &folder.entries[index];
buttonChangedROMDevice = true; if (strcasecmp(current->filImage.fname, "autoswap.lst") == 0)
} {
else if (inputMappings->BrowseInsert()) folder.currentIndex = index;
{ folder.SetCurrent();
SelectROMOrDevice(4); dirty=true;
buttonChangedROMDevice = true; break;
}
} }
} }
else else
{ {
if (folder.entries.size() > 0) dirty = folder.CheckBrowseNavigation();
{
//u32 numberOfEntriesMinus1 = folder.entries.size() - 1;
bool dirty = false;
if (inputMappings->BrowseSelect() && !buttonChangedROMDevice )
{
FileBrowser::BrowsableList::Entry* current = folder.current;
if (current)
{
if (current->filImage.fattrib & AM_DIR)
{
if (strcmp(current->filImage.fname, "..") == 0)
{
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)
{
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() && !buttonChangedROMDevice )
{
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
{
// check for number keys for ROM and Drive Number changes
if (inputMappings->BrowseFunction()
&& inputMappings->getKeyboardFunction() >= 1
&& inputMappings->getKeyboardFunction() <= 11 )
{
SelectROMOrDevice(inputMappings->getKeyboardFunction());
}
dirty = folder.CheckBrowseNavigation();
}
if (dirty) RefeshDisplay();
}
else
{
if (inputMappings->BrowseBack())
PopFolder();
}
if (inputMappings->BrowseAutoLoad())
{
CheckAutoMountImage(EXIT_RESET, this);
}
} }
if (dirty) RefeshDisplay();
} }
bool FileBrowser::SelectROMOrDevice(u32 index) bool FileBrowser::SelectROMOrDevice(u32 index)
@ -1098,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 FileBrowser::SelectLST(const char* filenameLST)
{ {
bool validImage = false; bool validImage = false;
@ -1145,11 +1161,11 @@ bool FileBrowser::SelectLST(const char* filenameLST)
return validImage; return validImage;
} }
/*
// Not used // Not used
void FileBrowser::UpdateInputDiskCaddy() void FileBrowser::UpdateInputDiskCaddy()
{ {
bool dirty = false; bool dirty = false;
Keyboard* keyboard = Keyboard::Instance();
if (keyboard->KeyPressed(KEY_DELETE)) if (keyboard->KeyPressed(KEY_DELETE))
{ {
@ -1171,6 +1187,7 @@ void FileBrowser::UpdateInputDiskCaddy()
if (dirty) RefeshDisplay(); if (dirty) RefeshDisplay();
} }
*/
void FileBrowser::DisplayStatusBar() void FileBrowser::DisplayStatusBar()
{ {

View File

@ -193,6 +193,7 @@ public:
static u32 Colour(int index); static u32 Colour(int index);
bool MakeLST(const char* filenameLST);
bool SelectLST(const char* filenameLST); bool SelectLST(const char* filenameLST);
void SetScrollHighlightRate(float value) { scrollHighlightRate = value; } void SetScrollHighlightRate(float value) { scrollHighlightRate = value; }
@ -211,6 +212,7 @@ private:
bool FillCaddyWithSelections(); bool FillCaddyWithSelections();
bool AddToCaddy(FileBrowser::BrowsableList::Entry* current); bool AddToCaddy(FileBrowser::BrowsableList::Entry* current);
bool AddImageToCaddy(FileBrowser::BrowsableList::Entry* current);
bool CheckForPNG(const char* filename, FILINFO& filIcon); bool CheckForPNG(const char* filename, FILINFO& filIcon);
void DisplayPNG(); void DisplayPNG();

View File

@ -44,18 +44,61 @@ InputMappings::InputMappings()
bool InputMappings::CheckButtonsBrowseMode() bool InputMappings::CheckButtonsBrowseMode()
{ {
buttonFlags = 0; buttonFlags = 0;
//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);
else if (IEC_Bus::GetInputButtonPressed(3))
SetButtonFlag(BACK_FLAG);
//else if (IEC_Bus::GetInputButtonPressed(4))
// SetButtonFlag(INSERT_FLAG);
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(INPUT_BUTTON_DOWN))
SetButtonFlag(DOWN_FLAG);
else if (IEC_Bus::GetInputButtonPressed(INPUT_BUTTON_BACK))
SetButtonFlag(BACK_FLAG);
// edge detection
insertButtonPressed = !IEC_Bus::GetInputButtonReleased(4); insertButtonPressed = !IEC_Bus::GetInputButtonReleased(4);
if (insertButtonPressedPrev && !insertButtonPressed) if (insertButtonPressedPrev && !insertButtonPressed)
SetButtonFlag(INSERT_FLAG); SetButtonFlag(INSERT_FLAG);
@ -73,14 +116,16 @@ void InputMappings::CheckButtonsEmulationMode()
{ {
buttonFlags = 0; buttonFlags = 0;
if (IEC_Bus::GetInputButtonPressed(0)) if (IEC_Bus::GetInputButtonPressed(INPUT_BUTTON_ENTER))
SetButtonFlag(ESC_FLAG); SetButtonFlag(ESC_FLAG);
else if (IEC_Bus::GetInputButtonPressed(1)) else if (IEC_Bus::GetInputButtonPressed(INPUT_BUTTON_UP))
SetButtonFlag(NEXT_FLAG); SetButtonFlag(NEXT_FLAG);
else if (IEC_Bus::GetInputButtonPressed(2)) else if (IEC_Bus::GetInputButtonPressed(INPUT_BUTTON_DOWN))
SetButtonFlag(PREV_FLAG); SetButtonFlag(PREV_FLAG);
//else if (IEC_Bus::GetInputButtonPressed(3)) //else if (IEC_Bus::GetInputButtonPressed(INPUT_BUTTON_BACK))
// SetButtonFlag(BACK_FLAG); // SetButtonFlag(BACK_FLAG);
//else if (IEC_Bus::GetInputButtonPressed(INPUT_BUTTON_INSERT))
// SetButtonFlag(INSERT_FLAG);
} }
@ -152,6 +197,11 @@ bool InputMappings::CheckKeyboardBrowseMode()
Keyboard* keyboard = Keyboard::Instance(); Keyboard* keyboard = Keyboard::Instance();
keyboardFlags = 0; keyboardFlags = 0;
keyboardNumLetter = 0;
if (!keyboard->CheckChanged())
{
return false;
}
if (keyboard->KeyHeld(KEY_DELETE) && keyboard->KeyLCtrlAlt() ) if (keyboard->KeyHeld(KEY_DELETE) && keyboard->KeyLCtrlAlt() )
reboot_now(); reboot_now();
@ -196,36 +246,30 @@ bool InputMappings::CheckKeyboardBrowseMode()
SetKeyboardFlag(FAKERESET_FLAG); SetKeyboardFlag(FAKERESET_FLAG);
else if (keyboard->KeyHeld(KEY_W) && keyboard->KeyEitherAlt() ) else if (keyboard->KeyHeld(KEY_W) && keyboard->KeyEitherAlt() )
SetKeyboardFlag(WRITEPROTECT_FLAG); SetKeyboardFlag(WRITEPROTECT_FLAG);
else if (keyboard->KeyHeld(KEY_L) && keyboard->KeyEitherAlt() )
SetKeyboardFlag(MAKELST_FLAG);
else else
{ {
if (keyboard->KeyNoModifiers()) if (keyboard->KeyNoModifiers())
{ {
unsigned index; 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(NUMBER_FLAG); SetKeyboardFlag(NUMLET_FLAG);
keyboardNumber = index-KEY_1+'1'; // key 1 is ascii '1' keyboardNumLetter = index+'1'; // key 1 is ascii '1'
if (keyboardNumber > '9') keyboardNumber = '0'; 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';
} }
} }
for (index = KEY_A; index <= KEY_Z; ++index) for (index = KEY_A; index <= KEY_Z; ++index)
{ {
if (keyboard->KeyHeld(index)) if (keyboard->KeyHeld(index))
{ {
SetKeyboardFlag(LETTER_FLAG); SetKeyboardFlag(NUMLET_FLAG);
keyboardLetter = index-KEY_A+'A'; // key A is ascii 'A' keyboardNumLetter = index-KEY_A+'A'; // key A is ascii 'A'
} }
} }
for (index = KEY_F1; index <= KEY_F12; ++index) // F13 isnt contiguous for (index = KEY_F1; index <= KEY_F12; ++index) // F13 isnt contiguous
@ -233,7 +277,7 @@ bool InputMappings::CheckKeyboardBrowseMode()
if (keyboard->KeyHeld(index)) if (keyboard->KeyHeld(index))
{ {
SetKeyboardFlag(FUNCTION_FLAG); SetKeyboardFlag(FUNCTION_FLAG);
keyboardFunction = index-KEY_F1+1; // key F1 is 1 inputROMOrDevice = index-KEY_F1+1; // key F1 is 1
} }
} }
} }
@ -247,32 +291,31 @@ void InputMappings::CheckKeyboardEmulationMode(unsigned numberOfImages, unsigned
Keyboard* keyboard = Keyboard::Instance(); Keyboard* keyboard = Keyboard::Instance();
keyboardFlags = 0; 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)
{ {
unsigned index;
if (keyboard->KeyHeld(KEY_DELETE) && keyboard->KeyLCtrlAlt() ) for (index = 0; index < 10; index++)
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; if ( keyboard->KeyHeld(KEY_F1+index)
for (index = 0; index < sizeof(NumberKeys)/sizeof(NumberKeys[0]); index+=3) || keyboard->KeyHeld(KEY_1+index)
{ || keyboard->KeyHeld(KEY_KP1+index) )
if (keyboard->KeyHeld(NumberKeys[index]) directDiskSwapRequest |= (1 << index);
|| keyboard->KeyHeld(NumberKeys[index + 1])
|| keyboard->KeyHeld(NumberKeys[index + 2]) )
directDiskSwapRequest |= (1 << index/3);
}
} }
} }
} }

View File

@ -32,7 +32,8 @@
#define SPACE_FLAG (1 << 8) #define SPACE_FLAG (1 << 8)
#define BACK_FLAG (1 << 9) #define BACK_FLAG (1 << 9)
#define INSERT_FLAG (1 << 10) #define INSERT_FLAG (1 << 10)
#define NUMBER_FLAG (1 << 11)
#define NUMLET_FLAG (1 << 11)
#define PAGEDOWN_LCD_FLAG (1 << 12) #define PAGEDOWN_LCD_FLAG (1 << 12)
#define PAGEUP_LCD_FLAG (1 << 13) #define PAGEUP_LCD_FLAG (1 << 13)
@ -41,26 +42,13 @@
#define AUTOLOAD_FLAG (1 << 15) #define AUTOLOAD_FLAG (1 << 15)
#define FAKERESET_FLAG (1 << 16) #define FAKERESET_FLAG (1 << 16)
#define WRITEPROTECT_FLAG (1 << 17) #define WRITEPROTECT_FLAG (1 << 17)
#define LETTER_FLAG (1 << 18) #define MAKELST_FLAG (1 << 18)
#define HOME_FLAG (1 << 19) #define HOME_FLAG (1 << 19)
#define END_FLAG (1 << 20) #define END_FLAG (1 << 20)
#define FUNCTION_FLAG (1 << 21) #define FUNCTION_FLAG (1 << 21)
// dont exceed 32!! // 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<InputMappings> class InputMappings : public Singleton<InputMappings>
{ {
@ -78,9 +66,8 @@ protected:
bool enterButtonPressedPrev; bool enterButtonPressedPrev;
bool enterButtonPressed; bool enterButtonPressed;
unsigned keyboardNumber; unsigned keyboardNumLetter;
unsigned keyboardLetter; unsigned inputROMOrDevice;
unsigned keyboardFunction;
//inline void SetUartFlag(unsigned flag) { uartFlags |= flag; } //inline void SetUartFlag(unsigned flag) { uartFlags |= flag; }
//inline bool UartFlag(unsigned flag) { return (uartFlags & flag) != 0; } //inline bool UartFlag(unsigned flag) { return (uartFlags & flag) != 0; }
@ -170,6 +157,11 @@ public:
return KeyboardFlag(INSERT_FLAG)/* | UartFlag(INSERT_FLAG)*/ | ButtonFlag(INSERT_FLAG); 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 BrowseNewD64() { return KeyboardFlag(NEWD64_FLAG); }
inline bool BrowseAutoLoad() { return KeyboardFlag(AUTOLOAD_FLAG); } inline bool BrowseAutoLoad() { return KeyboardFlag(AUTOLOAD_FLAG); }
@ -178,17 +170,14 @@ public:
inline bool BrowseWriteProtect() { return KeyboardFlag(WRITEPROTECT_FLAG); } inline bool BrowseWriteProtect() { return KeyboardFlag(WRITEPROTECT_FLAG); }
inline bool BrowseNumber() { return KeyboardFlag(NUMBER_FLAG); } inline bool MakeLSTFile() { return KeyboardFlag(MAKELST_FLAG); }
inline bool BrowseLetter() { return KeyboardFlag(LETTER_FLAG); }
inline bool BrowseFunction() { return KeyboardFlag(FUNCTION_FLAG); }
inline bool BrowseHome() { return KeyboardFlag(HOME_FLAG); } inline bool BrowseHome() { return KeyboardFlag(HOME_FLAG); }
inline bool BrowseEnd() { return KeyboardFlag(END_FLAG); } inline bool BrowseEnd() { return KeyboardFlag(END_FLAG); }
inline char getKeyboardNumber() { return keyboardNumber; } inline char getKeyboardNumLetter() { return keyboardNumLetter; }
inline char getKeyboardLetter() { return (char) keyboardLetter; } inline unsigned getROMOrDevice() { return inputROMOrDevice; }
inline unsigned getKeyboardFunction() { return (char) keyboardFunction; }
// Used by the 2 cores so need to be volatile // Used by the 2 cores so need to be volatile
//volatile static unsigned directDiskSwapRequest; //volatile static unsigned directDiskSwapRequest;

View File

@ -28,6 +28,12 @@
#define INPUT_BUTTON_DEBOUNCE_THRESHOLD 20000 #define INPUT_BUTTON_DEBOUNCE_THRESHOLD 20000
#define INPUT_BUTTON_REPEAT_THRESHOLD 460000 #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 // DIN ATN is inverted and then connected to pb7 and ca1
// - also input to xor with ATNAout pb4 // - 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) // - output of xor is inverted and connected to DIN pin 5 DATAout (OC so can only pull low)