FB and @CP can now be used to switch between SD and USB devices.

This commit is contained in:
Stephen White 2018-11-06 19:23:48 +11:00
parent d9528f0f26
commit 9051abec6d
4 changed files with 221 additions and 112 deletions

View file

@ -21,6 +21,7 @@
#include <string.h> #include <string.h>
#include <strings.h> #include <strings.h>
#include <algorithm> #include <algorithm>
#include <ctype.h>
#include "debug.h" #include "debug.h"
#include "options.h" #include "options.h"
#include "InputMappings.h" #include "InputMappings.h"
@ -553,16 +554,9 @@ struct greater
} }
}; };
void FileBrowser::RefreshFolderEntries() void FileBrowser::RefreshDevicesEntries(std::vector<FileBrowser::BrowsableList::Entry>& entries, bool toLower)
{ {
DIR dir;
FileBrowser::BrowsableList::Entry entry; FileBrowser::BrowsableList::Entry entry;
FRESULT res;
char* ext;
folder.Clear();
if (displayingDevices)
{
char label[1024]; char label[1024];
DWORD vsn; DWORD vsn;
f_getlabel("SD:", label, &vsn); f_getlabel("SD:", label, &vsn);
@ -571,9 +565,16 @@ void FileBrowser::RefreshFolderEntries()
sprintf(entry.filImage.fname, "SD: %s", label); sprintf(entry.filImage.fname, "SD: %s", label);
else else
sprintf(entry.filImage.fname, "SD:"); sprintf(entry.filImage.fname, "SD:");
if (toLower)
{
for (int i = 0; entry.filImage.fname[i]; i++)
{
entry.filImage.fname[i] = tolower(entry.filImage.fname[i]);
}
}
entry.filImage.fattrib |= AM_DIR; entry.filImage.fattrib |= AM_DIR;
entry.filIcon.fname[0] = 0; entry.filIcon.fname[0] = 0;
folder.entries.push_back(entry); entries.push_back(entry);
for (int USBDriveIndex = 0; USBDriveIndex < numberOfUSBMassStorageDevices; ++USBDriveIndex) for (int USBDriveIndex = 0; USBDriveIndex < numberOfUSBMassStorageDevices; ++USBDriveIndex)
{ {
@ -587,11 +588,31 @@ void FileBrowser::RefreshFolderEntries()
else else
strcpy(entry.filImage.fname, USBDriveId); strcpy(entry.filImage.fname, USBDriveId);
if (toLower)
{
for (int i = 0; entry.filImage.fname[i]; i++)
{
entry.filImage.fname[i] = tolower(entry.filImage.fname[i]);
}
}
entry.filImage.fattrib |= AM_DIR; entry.filImage.fattrib |= AM_DIR;
entry.filIcon.fname[0] = 0; entry.filIcon.fname[0] = 0;
folder.entries.push_back(entry); entries.push_back(entry);
} }
} }
void FileBrowser::RefreshFolderEntries()
{
DIR dir;
FileBrowser::BrowsableList::Entry entry;
FRESULT res;
char* ext;
folder.Clear();
if (displayingDevices)
{
FileBrowser::RefreshDevicesEntries(folder.entries, false);
}
else else
{ {
res = f_opendir(&dir, "."); res = f_opendir(&dir, ".");
@ -663,6 +684,13 @@ void FileBrowser::DisplayRoot()
FolderChanged(); FolderChanged();
} }
void FileBrowser::DeviceSwitched()
{
displayingDevices = false;
m_IEC_Commands.SetDisplayingDevices(displayingDevices);
FolderChanged();
}
/* /*
void FileBrowser::RefeshDisplayForBrowsableList(FileBrowser::BrowsableList* browsableList, int xOffset, bool showSelected) void FileBrowser::RefeshDisplayForBrowsableList(FileBrowser::BrowsableList* browsableList, int xOffset, bool showSelected)
{ {
@ -867,9 +895,11 @@ void FileBrowser::PopFolder()
if (f_getcwd(buffer, 1024) == FR_OK) if (f_getcwd(buffer, 1024) == FR_OK)
{ {
int deviceRoot = IsAtRootOfDevice(); int deviceRoot = IsAtRootOfDevice();
DEBUG_LOG("deviceRoot = %d\r\n", deviceRoot);
if (deviceRoot >= 0) if (deviceRoot >= 0)
{ {
displayingDevices = true; displayingDevices = true;
m_IEC_Commands.SetDisplayingDevices(displayingDevices);
RefreshFolderEntries(); RefreshFolderEntries();
folder.currentIndex = deviceRoot; folder.currentIndex = deviceRoot;
folder.SetCurrent(); folder.SetCurrent();
@ -1058,6 +1088,7 @@ void FileBrowser::UpdateInputFolders()
{ {
SwitchDrive("SD:"); SwitchDrive("SD:");
displayingDevices = false; displayingDevices = false;
m_IEC_Commands.SetDisplayingDevices(displayingDevices);
RefreshFolderEntries(); RefreshFolderEntries();
} }
else else
@ -1071,6 +1102,7 @@ void FileBrowser::UpdateInputFolders()
{ {
SwitchDrive(USBDriveId); SwitchDrive(USBDriveId);
displayingDevices = false; displayingDevices = false;
m_IEC_Commands.SetDisplayingDevices(displayingDevices);
RefreshFolderEntries(); RefreshFolderEntries();
} }
} }

View file

@ -198,11 +198,15 @@ public:
static u32 Colour(int index); static u32 Colour(int index);
static void RefreshDevicesEntries(std::vector<FileBrowser::BrowsableList::Entry>& entries, bool toLower);
bool MakeLST(const char* filenameLST); 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; }
void DeviceSwitched();
private: private:
void DisplayPNG(FILINFO& filIcon, int x, int y); void DisplayPNG(FILINFO& filIcon, int x, int y);
void RefreshFolderEntries(); void RefreshFolderEntries();

View file

@ -769,6 +769,32 @@ void IEC_Commands::CD(int partition, char* filename)
updateAction = POP_DIR; updateAction = POP_DIR;
} }
else else
{
if (displayingDevices)
{
if (strncmp(filename, "SD", 2) == 0)
{
SwitchDrive("SD:");
displayingDevices = false;
updateAction = DECIVE_SWITCHED;
}
else
{
for (int USBDriveIndex = 0; USBDriveIndex < numberOfUSBMassStorageDevices; ++USBDriveIndex)
{
char USBDriveId[16];
sprintf(USBDriveId, "USB%02d:", USBDriveIndex + 1);
if (strncmp(filename, USBDriveId, 5) == 0)
{
SwitchDrive(USBDriveId);
displayingDevices = false;
updateAction = DECIVE_SWITCHED;
}
}
}
}
else
{ {
DIR dir; DIR dir;
FILINFO filInfo; FILINFO filInfo;
@ -870,6 +896,7 @@ void IEC_Commands::CD(int partition, char* filename)
} }
} }
} }
}
void IEC_Commands::MKDir(int partition, char* filename) void IEC_Commands::MKDir(int partition, char* filename)
{ {
@ -1040,6 +1067,41 @@ void IEC_Commands::Copy(void)
Error(ERROR_34_SYNTAX_ERROR); Error(ERROR_34_SYNTAX_ERROR);
} }
} }
void IEC_Commands::ChangeDevice(void)
{
Channel& channel = channels[15];
const char* text = (char*)channel.buffer;
if (strlen(text) > 2)
{
int deviceIndex = atoi(text + 2);
if (deviceIndex == 0)
{
SwitchDrive("SD:");
displayingDevices = false;
updateAction = DECIVE_SWITCHED;
}
else if ((deviceIndex - 1) < numberOfUSBMassStorageDevices)
{
char USBDriveId[16];
sprintf(USBDriveId, "USB%02d:", deviceIndex);
SwitchDrive(USBDriveId);
displayingDevices = false;
updateAction = DECIVE_SWITCHED;
}
else
{
Error(ERROR_74_DRlVE_NOT_READY);
}
}
else
{
Error(ERROR_31_SYNTAX_ERROR);
}
}
void IEC_Commands::Memory(void) void IEC_Commands::Memory(void)
{ {
Channel& channel = channels[15]; Channel& channel = channels[15];
@ -1286,7 +1348,7 @@ void IEC_Commands::ProcessCommand(void)
break; break;
case 'C': case 'C':
if (channel.buffer[1] == 'P') if (channel.buffer[1] == 'P')
Error(ERROR_31_SYNTAX_ERROR); // Change Partition not implemented yet ChangeDevice();
else else
Copy(); Copy();
break; break;
@ -1628,6 +1690,12 @@ void IEC_Commands::LoadDirectory()
FileBrowser::BrowsableList::Entry entry; FileBrowser::BrowsableList::Entry entry;
std::vector<FileBrowser::BrowsableList::Entry> entries; std::vector<FileBrowser::BrowsableList::Entry> entries;
if (displayingDevices)
{
FileBrowser::RefreshDevicesEntries(entries, true);
}
else
{
res = f_opendir(&dir, "."); res = f_opendir(&dir, ".");
if (res == FR_OK) if (res == FR_OK)
{ {
@ -1642,6 +1710,7 @@ void IEC_Commands::LoadDirectory()
std::sort(entries.begin(), entries.end(), greater()); std::sort(entries.begin(), entries.end(), greater());
} }
}
for (u32 i = 0; i < entries.size(); ++i) for (u32 i = 0; i < entries.size(); ++i)
{ {

View file

@ -47,7 +47,7 @@ extern "C"
#include "ssd_logo.h" #include "ssd_logo.h"
unsigned versionMajor = 1; unsigned versionMajor = 1;
unsigned versionMinor = 16; unsigned versionMinor = 17;
// When the emulated CPU starts we execute the first million odd cycles in non-real-time (ie as fast as possible so the emulated 1541 becomes responsive to CBM-Browser asap) // When the emulated CPU starts we execute the first million odd cycles in non-real-time (ie as fast as possible so the emulated 1541 becomes responsive to CBM-Browser asap)
// During these cycles the CPU is executing the ROM self test routines (these do not need to be cycle accurate) // During these cycles the CPU is executing the ROM self test routines (these do not need to be cycle accurate)
@ -1114,6 +1114,10 @@ void emulator()
GlobalSetDeviceID( m_IEC_Commands.GetDeviceId() ); GlobalSetDeviceID( m_IEC_Commands.GetDeviceId() );
fileBrowser->ShowDeviceAndROM(); fileBrowser->ShowDeviceAndROM();
break; break;
case IEC_Commands::DECIVE_SWITCHED:
DEBUG_LOG("DECIVE_SWITCHED\r\n");
fileBrowser->DeviceSwitched();
break;
default: default:
break; break;
} }