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,6 +554,53 @@ struct greater
} }
}; };
void FileBrowser::RefreshDevicesEntries(std::vector<FileBrowser::BrowsableList::Entry>& entries, bool toLower)
{
FileBrowser::BrowsableList::Entry entry;
char label[1024];
DWORD vsn;
f_getlabel("SD:", label, &vsn);
if (strlen(label) > 0)
sprintf(entry.filImage.fname, "SD: %s", label);
else
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.filIcon.fname[0] = 0;
entries.push_back(entry);
for (int USBDriveIndex = 0; USBDriveIndex < numberOfUSBMassStorageDevices; ++USBDriveIndex)
{
char USBDriveId[16];
sprintf(USBDriveId, "USB%02d:", USBDriveIndex + 1);
f_getlabel(USBDriveId, label, &vsn);
if (strlen(label) > 0)
sprintf(entry.filImage.fname, "%s %s", USBDriveId, label);
else
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.filIcon.fname[0] = 0;
entries.push_back(entry);
}
}
void FileBrowser::RefreshFolderEntries() void FileBrowser::RefreshFolderEntries()
{ {
DIR dir; DIR dir;
@ -563,34 +611,7 @@ void FileBrowser::RefreshFolderEntries()
folder.Clear(); folder.Clear();
if (displayingDevices) if (displayingDevices)
{ {
char label[1024]; FileBrowser::RefreshDevicesEntries(folder.entries, false);
DWORD vsn;
f_getlabel("SD:", label, &vsn);
if (strlen(label) > 0)
sprintf(entry.filImage.fname, "SD: %s", label);
else
sprintf(entry.filImage.fname, "SD:");
entry.filImage.fattrib |= AM_DIR;
entry.filIcon.fname[0] = 0;
folder.entries.push_back(entry);
for (int USBDriveIndex = 0; USBDriveIndex < numberOfUSBMassStorageDevices; ++USBDriveIndex)
{
char USBDriveId[16];
sprintf(USBDriveId, "USB%02d:", USBDriveIndex + 1);
f_getlabel(USBDriveId, label, &vsn);
if (strlen(label) > 0)
sprintf(entry.filImage.fname, "%s %s", USBDriveId, label);
else
strcpy(entry.filImage.fname, USBDriveId);
entry.filImage.fattrib |= AM_DIR;
entry.filIcon.fname[0] = 0;
folder.entries.push_back(entry);
}
} }
else else
{ {
@ -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

@ -770,102 +770,129 @@ void IEC_Commands::CD(int partition, char* filename)
} }
else else
{ {
DIR dir; if (displayingDevices)
FILINFO filInfo;
char path[256] = { 0 };
char* pattern = strrchr(filenameEdited, '\\');
if (pattern)
{ {
// Now we look for a folder if (strncmp(filename, "SD", 2) == 0)
int len = pattern - filenameEdited;
strncpy(path, filenameEdited, len);
pattern++;
if ((f_stat(path, &filInfo) != FR_OK) || !IsDirectory(filInfo))
{ {
Error(ERROR_62_FILE_NOT_FOUND); SwitchDrive("SD:");
displayingDevices = false;
updateAction = DECIVE_SWITCHED;
} }
else else
{ {
char cwd[1024]; for (int USBDriveIndex = 0; USBDriveIndex < numberOfUSBMassStorageDevices; ++USBDriveIndex)
if (f_getcwd(cwd, 1024) == FR_OK)
{ {
f_chdir(path); char USBDriveId[16];
sprintf(USBDriveId, "USB%02d:", USBDriveIndex + 1);
char cwd2[1024]; if (strncmp(filename, USBDriveId, 5) == 0)
f_getcwd(cwd2, 1024);
bool found = f_findfirst(&dir, &filInfo, ".", pattern) == FR_OK && filInfo.fname[0] != 0;
//DEBUG_LOG("%s pattern = %s\r\n", filInfo.fname, pattern);
if (found)
{ {
if (DiskImage::IsDiskImageExtention(filInfo.fname)) SwitchDrive(USBDriveId);
{ displayingDevices = false;
if (f_stat(filInfo.fname, &filInfoSelectedImage) == FR_OK) updateAction = DECIVE_SWITCHED;
{
strcpy((char*)selectedImageName, filInfo.fname);
}
else
{
f_chdir(cwd);
Error(ERROR_62_FILE_NOT_FOUND);
}
}
else
{
//DEBUG_LOG("attemting changing dir %s\r\n", filInfo.fname);
if (f_chdir(filInfo.fname) != FR_OK)
{
Error(ERROR_62_FILE_NOT_FOUND);
f_chdir(cwd);
}
else
{
updateAction = DIR_PUSHED;
}
}
} }
else
{
Error(ERROR_62_FILE_NOT_FOUND);
f_chdir(cwd);
}
} }
//if (f_getcwd(cwd, 1024) == FR_OK)
// DEBUG_LOG("CWD on exit = %s\r\n", cwd);
} }
} }
else else
{ {
bool found = FindFirst(dir, filenameEdited, filInfo); DIR dir;
FILINFO filInfo;
if (found) char path[256] = { 0 };
char* pattern = strrchr(filenameEdited, '\\');
if (pattern)
{ {
if (DiskImage::IsDiskImageExtention(filInfo.fname)) // Now we look for a folder
int len = pattern - filenameEdited;
strncpy(path, filenameEdited, len);
pattern++;
if ((f_stat(path, &filInfo) != FR_OK) || !IsDirectory(filInfo))
{ {
if (f_stat(filInfo.fname, &filInfoSelectedImage) == FR_OK) Error(ERROR_62_FILE_NOT_FOUND);
strcpy((char*)selectedImageName, filInfo.fname);
else
Error(ERROR_62_FILE_NOT_FOUND);
} }
else else
{ {
//DEBUG_LOG("attemting changing dir %s\r\n", filInfo.fname); char cwd[1024];
if (f_chdir(filInfo.fname) != FR_OK) if (f_getcwd(cwd, 1024) == FR_OK)
Error(ERROR_62_FILE_NOT_FOUND); {
else f_chdir(path);
updateAction = DIR_PUSHED;
char cwd2[1024];
f_getcwd(cwd2, 1024);
bool found = f_findfirst(&dir, &filInfo, ".", pattern) == FR_OK && filInfo.fname[0] != 0;
//DEBUG_LOG("%s pattern = %s\r\n", filInfo.fname, pattern);
if (found)
{
if (DiskImage::IsDiskImageExtention(filInfo.fname))
{
if (f_stat(filInfo.fname, &filInfoSelectedImage) == FR_OK)
{
strcpy((char*)selectedImageName, filInfo.fname);
}
else
{
f_chdir(cwd);
Error(ERROR_62_FILE_NOT_FOUND);
}
}
else
{
//DEBUG_LOG("attemting changing dir %s\r\n", filInfo.fname);
if (f_chdir(filInfo.fname) != FR_OK)
{
Error(ERROR_62_FILE_NOT_FOUND);
f_chdir(cwd);
}
else
{
updateAction = DIR_PUSHED;
}
}
}
else
{
Error(ERROR_62_FILE_NOT_FOUND);
f_chdir(cwd);
}
}
//if (f_getcwd(cwd, 1024) == FR_OK)
// DEBUG_LOG("CWD on exit = %s\r\n", cwd);
} }
} }
else else
{ {
Error(ERROR_62_FILE_NOT_FOUND); bool found = FindFirst(dir, filenameEdited, filInfo);
if (found)
{
if (DiskImage::IsDiskImageExtention(filInfo.fname))
{
if (f_stat(filInfo.fname, &filInfoSelectedImage) == FR_OK)
strcpy((char*)selectedImageName, filInfo.fname);
else
Error(ERROR_62_FILE_NOT_FOUND);
}
else
{
//DEBUG_LOG("attemting changing dir %s\r\n", filInfo.fname);
if (f_chdir(filInfo.fname) != FR_OK)
Error(ERROR_62_FILE_NOT_FOUND);
else
updateAction = DIR_PUSHED;
}
}
else
{
Error(ERROR_62_FILE_NOT_FOUND);
}
} }
} }
} }
@ -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,19 +1690,26 @@ void IEC_Commands::LoadDirectory()
FileBrowser::BrowsableList::Entry entry; FileBrowser::BrowsableList::Entry entry;
std::vector<FileBrowser::BrowsableList::Entry> entries; std::vector<FileBrowser::BrowsableList::Entry> entries;
res = f_opendir(&dir, "."); if (displayingDevices)
if (res == FR_OK)
{ {
do FileBrowser::RefreshDevicesEntries(entries, true);
}
else
{
res = f_opendir(&dir, ".");
if (res == FR_OK)
{ {
res = f_readdir(&dir, &entry.filImage); do
ext = strrchr(entry.filImage.fname, '.'); {
if (res == FR_OK && entry.filImage.fname[0] != 0 && !(ext && strcasecmp(ext, ".png") == 0)) res = f_readdir(&dir, &entry.filImage);
entries.push_back(entry); ext = strrchr(entry.filImage.fname, '.');
} while (res == FR_OK && entry.filImage.fname[0] != 0); if (res == FR_OK && entry.filImage.fname[0] != 0 && !(ext && strcasecmp(ext, ".png") == 0))
f_closedir(&dir); entries.push_back(entry);
} while (res == FR_OK && entry.filImage.fname[0] != 0);
f_closedir(&dir);
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;
} }