Merge branch 'master' into cleanup

This commit is contained in:
penfold42 2018-07-29 17:26:08 +10:00
commit 209d73469c
9 changed files with 277 additions and 143 deletions

View File

@ -60,6 +60,8 @@ GraphIEC = 1
// If you are using a LCD screen then specify it here
//LCDName = ssd1306_128x64
//LCDName = ssd1306_128x32
//LCDName = sh1106_128x64
// If you are using a LCD screen and you would like PageUp and PageDown keys to work with it then specify this option
//KeyboardBrowseLCDScreen = 1

View File

@ -32,6 +32,8 @@ static char buffer[256] = { 0 };
static u32 white = RGBA(0xff, 0xff, 0xff, 0xff);
static u32 red = RGBA(0xff, 0, 0, 0xff);
#define LCDFONTHEIGHT 16
bool DiskCaddy::Empty()
{
int x;
@ -62,7 +64,7 @@ bool DiskCaddy::Empty()
snprintf(buffer, 256, "Saving");
screenLCD->PrintText(false, x, y, buffer, RGBA(0xff, 0xff, 0xff, 0xff), BkColour);
y += 16;
y += LCDFONTHEIGHT;
snprintf(buffer, 256, "%s ", disks[index].GetName());
screenLCD->PrintText(false, x, y, buffer, RGBA(0xff, 0xff, 0xff, 0xff), red);
screenLCD->SwapBuffers();
@ -91,7 +93,7 @@ bool DiskCaddy::Empty()
snprintf(buffer, 256, "Saving");
screenLCD->PrintText(false, x, y, buffer, RGBA(0xff, 0xff, 0xff, 0xff), BkColour);
y += 16;
y += LCDFONTHEIGHT;
snprintf(buffer, 256, "Complete ");
screenLCD->PrintText(false, x, y, buffer, RGBA(0xff, 0xff, 0xff, 0xff), red);
screenLCD->SwapBuffers();
@ -130,7 +132,7 @@ bool DiskCaddy::Insert(const FILINFO* fileInfo, bool readOnly)
snprintf(buffer, 256, "Loading");
screenLCD->PrintText(false, x, y, buffer, RGBA(0xff, 0xff, 0xff, 0xff), BkColour);
y += 16;
y += LCDFONTHEIGHT;
snprintf(buffer, 256, "%s ", fileInfo->fname);
screenLCD->PrintText(false, x, y, buffer, RGBA(0xff, 0xff, 0xff, 0xff), red);
screenLCD->SwapBuffers();
@ -282,47 +284,44 @@ void DiskCaddy::ShowSelectedImage(u32 index)
if (screenLCD)
{
unsigned numberOfImages = GetNumberOfImages();
unsigned numberOfDisplayedImages = screenLCD->Height()/LCDFONTHEIGHT-1;
unsigned caddyIndex;
if (screenLCD)
RGBA BkColour = RGBA(0, 0, 0, 0xFF);
//screenLCD->Clear(BkColour);
x = 0;
y = 0;
snprintf(buffer, 256, " D %d/%d ", index + 1, numberOfImages);
screenLCD->PrintText(false, x, y, buffer, RGBA(0xff, 0xff, 0xff, 0xff), RGBA(0xff, 0xff, 0xff, 0xff));
y += LCDFONTHEIGHT;
if (numberOfImages > numberOfDisplayedImages && index > numberOfDisplayedImages-1)
{
RGBA BkColour = RGBA(0, 0, 0, 0xFF);
//screenLCD->Clear(BkColour);
x = 0;
y = 0;
//snprintf(buffer, 256, "Emulating %d/%d ", index + 1, numberOfImages);
snprintf(buffer, 256, " D %d/%d ", index + 1, numberOfImages);
screenLCD->PrintText(false, x, y, buffer, RGBA(0xff, 0xff, 0xff, 0xff), RGBA(0xff, 0xff, 0xff, 0xff));
y += 16;
if (numberOfImages > 3 && index > 2)
{
if (numberOfImages - index < 3)
caddyIndex = numberOfImages - 3;
else
caddyIndex = index;
}
if (numberOfImages - index < numberOfDisplayedImages)
caddyIndex = numberOfImages - numberOfDisplayedImages;
else
{
caddyIndex = 0;
}
for (; caddyIndex < numberOfImages; ++caddyIndex)
{
DiskImage* image = GetImage(caddyIndex);
const char* name = image->GetName();
if (name)
{
snprintf(buffer, 256, "%d %s ", caddyIndex + 1, name);
screenLCD->PrintText(false, x, y, buffer, RGBA(0xff, 0xff, 0xff, 0xff), caddyIndex == index ? RGBA(0xff, 0xff, 0xff, 0xff) : BkColour);
y += 16;
}
if (y >= screenLCD->Height())
break;
}
screenLCD->SwapBuffers();
caddyIndex = index;
}
else
{
caddyIndex = 0;
}
for (; caddyIndex < numberOfImages; ++caddyIndex)
{
DiskImage* image = GetImage(caddyIndex);
const char* name = image->GetName();
if (name)
{
snprintf(buffer, 256, "%d %s ", caddyIndex + 1, name);
screenLCD->PrintText(false, x, y, buffer, RGBA(0xff, 0xff, 0xff, 0xff), caddyIndex == index ? RGBA(0xff, 0xff, 0xff, 0xff) : BkColour);
y += LCDFONTHEIGHT;
}
if (y >= screenLCD->Height())
break;
}
screenLCD->SwapBuffers();
}
}

View File

@ -41,6 +41,7 @@ extern Options options;
#define PNG_HEIGHT 200
extern void GlobalSetDeviceID(u8 id);
extern void CheckAutoMountImage(EXIT_TYPE reset_reason , FileBrowser* fileBrowser);
unsigned char FileBrowser::LSTBuffer[FileBrowser::LSTBuffer_size];
@ -386,6 +387,7 @@ FileBrowser::FileBrowser(DiskCaddy* diskCaddy, ROMs* roms, u8* deviceID, bool di
, deviceID(deviceID)
, displayPNGIcons(displayPNGIcons)
, buttonChangedDevice(false)
, buttonSelectROM(false)
, screenMain(screenMain)
, screenLCD(screenLCD)
, scrollHighlightRate(scrollHighlightRate)
@ -825,14 +827,12 @@ void FileBrowser::UpdateInputFolders()
{
if (inputMappings->BrowseSelect())
{
DEBUG_LOG("DEv8\r\n");
GlobalSetDeviceID(8);
ShowDeviceAndROM();
buttonChangedDevice = true;
}
else if (inputMappings->BrowseUp())
{
DEBUG_LOG("DEv9\r\n");
GlobalSetDeviceID(9);
ShowDeviceAndROM();
buttonChangedDevice = true;
@ -850,6 +850,29 @@ void FileBrowser::UpdateInputFolders()
buttonChangedDevice = true;
}
}
else if (IEC_Bus::GetInputButtonHeld(0))
{
if (inputMappings->BrowseUp())
{
SelectROM(0);
buttonSelectROM = true;
}
else if (inputMappings->BrowseDown())
{
SelectROM(1);
buttonSelectROM = true;
}
else if (inputMappings->BrowseBack())
{
SelectROM(2);
buttonSelectROM = true;
}
else if (inputMappings->BrowseInsert())
{
SelectROM(3);
buttonSelectROM = true;
}
}
else
{
if (folder.entries.size() > 0)
@ -859,49 +882,56 @@ void FileBrowser::UpdateInputFolders()
if (inputMappings->BrowseSelect())
{
FileBrowser::BrowsableList::Entry* current = folder.current;
if (current)
if (buttonSelectROM)
{
if (current->filImage.fattrib & AM_DIR)
buttonSelectROM = false;
}
else
{
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
{
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)
if (strcmp(current->filImage.fname, "..") == 0)
{
selectionsMade = SelectLST(current->filImage.fname);
PopFolder();
}
else
else if (strcmp(current->filImage.fname, ".") != 0)
{
// Add the current selected
AddToCaddy(current);
selectionsMade = FillCaddyWithSelections();
f_chdir(current->filImage.fname);
RefreshFolderEntries();
}
if (selectionsMade)
lastSelectionName = current->filImage.fname;
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;
}
}
}
}
}
@ -947,6 +977,24 @@ void FileBrowser::UpdateInputFolders()
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
{
unsigned keySetIndex;
@ -957,12 +1005,8 @@ void FileBrowser::UpdateInputFolders()
|| keyboard->KeyPressed(FileBrowser::SwapKeys[keySetIndexBase + 1])
|| keyboard->KeyPressed(FileBrowser::SwapKeys[keySetIndexBase + 2]))
{
if ( (keySetIndex < ROMs::MAX_ROMS) && (roms->ROMValid[keySetIndex]) )
if (SelectROM(keySetIndex))
{
roms->currentROMIndex = keySetIndex;
roms->lastManualSelectedROMIndex = keySetIndex;
DEBUG_LOG("Swap ROM %d %s\r\n", keySetIndex, roms->ROMNames[keySetIndex]);
ShowDeviceAndROM();
}
else if ( (keySetIndex >= 7) && (keySetIndex <= 10 ) )
{
@ -982,9 +1026,27 @@ void FileBrowser::UpdateInputFolders()
if (inputMappings->BrowseBack())
PopFolder();
}
if (inputMappings->BrowseAutoLoad())
{
CheckAutoMountImage(EXIT_RESET, this);
}
}
}
bool FileBrowser::SelectROM(u32 index)
{
if ((index < ROMs::MAX_ROMS) && (roms->ROMValid[index]))
{
roms->currentROMIndex = index;
roms->lastManualSelectedROMIndex = index;
DEBUG_LOG("Swap ROM %d %s\r\n", index, roms->ROMNames[index]);
ShowDeviceAndROM();
return true;
}
return false;
}
bool FileBrowser::SelectLST(const char* filenameLST)
{
bool validImage = false;
@ -1282,26 +1344,36 @@ void FileBrowser::DisplayDiskInfo(DiskImage* diskImage, const char* filenameForI
}
}
void FileBrowser::AutoSelectImage(const char* image)
void FileBrowser::SelectAutoMountImage(const char* image)
{
FileBrowser::BrowsableList::Entry* current = 0;
int index;
int maxEntries = folder.entries.size();
f_chdir("/1541");
RefreshFolderEntries();
for (index = 0; index < maxEntries; ++index)
if (SelectLST(image))
{
current = &folder.entries[index];
if (strcasecmp(current->filImage.fname, image) == 0)
{
break;
}
selectionsMade = true;
}
if (index != maxEntries)
else
{
ClearSelections();
caddySelections.entries.push_back(*current);
selectionsMade = FillCaddyWithSelections();
FileBrowser::BrowsableList::Entry* current = 0;
int index;
int maxEntries = folder.entries.size();
for (index = 0; index < maxEntries; ++index)
{
current = &folder.entries[index];
if (strcasecmp(current->filImage.fname, image) == 0)
{
break;
}
}
if (index != maxEntries)
{
ClearSelections();
caddySelections.entries.push_back(*current);
selectionsMade = FillCaddyWithSelections();
}
}
}

View File

@ -168,7 +168,7 @@ public:
FileBrowser(DiskCaddy* diskCaddy, ROMs* roms, u8* deviceID, bool displayPNGIcons, ScreenBase* screenMain, ScreenBase* screenLCD, float scrollHighlightRate);
void AutoSelectImage(const char* image);
void SelectAutoMountImage(const char* image);
void DisplayRoot();
void Update();
@ -217,6 +217,8 @@ private:
bool CheckForPNG(const char* filename, FILINFO& filIcon);
void DisplayPNG();
bool SelectROM(u32 index);
enum State
{
State_Folders,
@ -231,6 +233,7 @@ private:
u8* deviceID;
bool displayPNGIcons;
bool buttonChangedDevice;
bool buttonSelectROM;
BrowsableList caddySelections;

View File

@ -35,15 +35,18 @@ InputMappings::InputMappings()
: keyboardBrowseLCDScreen(false)
, insertButtonPressedPrev(false)
, insertButtonPressed(false)
, enterButtonPressedPrev(false)
, enterButtonPressed(false)
{
}
bool InputMappings::CheckButtonsBrowseMode()
{
buttonFlags = 0;
if (IEC_Bus::GetInputButtonPressed(0))
SetButtonFlag(ENTER_FLAG);
else if (IEC_Bus::GetInputButtonRepeating(1))
//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);
@ -57,6 +60,11 @@ bool InputMappings::CheckButtonsBrowseMode()
SetButtonFlag(INSERT_FLAG);
insertButtonPressedPrev = insertButtonPressed;
enterButtonPressed = !IEC_Bus::GetInputButtonReleased(0);
if (enterButtonPressedPrev && !enterButtonPressed)
SetButtonFlag(ENTER_FLAG);
enterButtonPressedPrev = enterButtonPressed;
return buttonFlags != 0;
}
@ -179,6 +187,12 @@ bool InputMappings::CheckKeyboardBrowseMode()
// SetKeyboardFlag(PAGEDOWN_LCD_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())
SetKeyboardFlag(WRITEPROTECT_FLAG);
else
{
unsigned index;
@ -206,6 +220,10 @@ void InputMappings::CheckKeyboardEmulationMode(unsigned numberOfImages, unsigned
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;

View File

@ -38,6 +38,9 @@
#define PAGEUP_LCD_FLAG (1 << 13)
#define NEWD64_FLAG (1 << 14)
#define AUTOLOAD_FLAG (1 << 15)
#define FAKERESET_FLAG (1 << 16)
#define WRITEPROTECT_FLAG (1 << 17)
// dont exceed 32!!
class InputMappings : public Singleton<InputMappings>
@ -53,6 +56,9 @@ protected:
bool insertButtonPressedPrev;
bool insertButtonPressed;
bool enterButtonPressedPrev;
bool enterButtonPressed;
//inline void SetUartFlag(unsigned flag) { uartFlags |= flag; }
//inline bool UartFlag(unsigned flag) { return (uartFlags & flag) != 0; }
inline void SetKeyboardFlag(unsigned flag) { keyboardFlags |= flag; }
@ -95,6 +101,16 @@ public:
return KeyboardFlag(PREV_FLAG)/* | UartFlag(PREV_FLAG)*/ | ButtonFlag(PREV_FLAG);
}
inline bool AutoLoad()
{
return KeyboardFlag(AUTOLOAD_FLAG);
}
inline bool FakeReset()
{
return KeyboardFlag(FAKERESET_FLAG);
}
inline bool BrowseSelect()
{
return KeyboardFlag(ENTER_FLAG)/* | UartFlag(ENTER_FLAG)*/ | ButtonFlag(ENTER_FLAG);
@ -148,6 +164,21 @@ public:
return KeyboardFlag(NEWD64_FLAG);
}
inline bool BrowseAutoLoad()
{
return KeyboardFlag(AUTOLOAD_FLAG);
}
inline bool BrowseFakeReset()
{
return KeyboardFlag(FAKERESET_FLAG);
}
inline bool BrowseWriteProtect()
{
return KeyboardFlag(WRITEPROTECT_FLAG);
}
// Used by the 2 cores so need to be volatile
//volatile static unsigned directDiskSwapRequest;
static unsigned directDiskSwapRequest;

View File

@ -51,12 +51,12 @@ bool IEC_Bus::ignoreReset = false;
u32 IEC_Bus::myOutsGPFSEL1 = 0;
u32 IEC_Bus::myOutsGPFSEL0 = 0;
bool IEC_Bus::InputButton[5];
bool IEC_Bus::InputButtonPrev[5];
u32 IEC_Bus::validInputCount[5];
bool IEC_Bus::InputButton[5] = { 0 };
bool IEC_Bus::InputButtonPrev[5] = { 0 };
u32 IEC_Bus::validInputCount[5] = { 0 };
u32 IEC_Bus::inputRepeatThreshold[5];
u32 IEC_Bus::inputRepeat[5];
u32 IEC_Bus::inputRepeatPrev[5];
u32 IEC_Bus::inputRepeat[5] = { 0 };
u32 IEC_Bus::inputRepeatPrev[5] = { 0 };
m6522* IEC_Bus::VIA = 0;

View File

@ -102,12 +102,6 @@ unsigned int screenHeight = 768;
const char* termainalTextRed = "\E[31m";
const char* termainalTextNormal = "\E[0m";
typedef enum {
EXIT_UNKNOWN,
EXIT_RESET,
EXIT_CD,
EXIT_KEYBOARD
} EXIT_TYPE;
EXIT_TYPE exitReason = EXIT_UNKNOWN;
// Hooks required for USPi library
@ -654,7 +648,7 @@ void GlobalSetDeviceID(u8 id)
SetVIAsDeviceID(id);
}
static void CheckAutoMountImage(EXIT_TYPE reset_reason , FileBrowser* fileBrowser)
void CheckAutoMountImage(EXIT_TYPE reset_reason , FileBrowser* fileBrowser)
{
const char* autoMountImageName = options.GetAutoMountImageName();
if (autoMountImageName[0] != 0)
@ -662,8 +656,9 @@ static void CheckAutoMountImage(EXIT_TYPE reset_reason , FileBrowser* fileBrowse
switch (reset_reason)
{
case EXIT_UNKNOWN:
case EXIT_AUTOLOAD:
case EXIT_RESET:
fileBrowser->AutoSelectImage(autoMountImageName);
fileBrowser->SelectAutoMountImage(autoMountImageName);
break;
case EXIT_CD:
case EXIT_KEYBOARD:
@ -933,41 +928,16 @@ void emulator()
IEC_Bus::RefreshOuts(); // Now output all outputs.
}
// We have now output so HERE is where the next phi2 cycle starts.
pi1541.Update();
// Other core will check the uart (as it is slow) (could enable uart irqs - will they execute on this core?)
inputMappings->CheckKeyboardEmulationMode(numberOfImages, numberOfImagesMax);
inputMappings->CheckButtonsEmulationMode();
bool exitEmulation = inputMappings->Exit();
bool nextDisk = inputMappings->NextDisk();
bool prevDisk = inputMappings->PrevDisk();
bool exitDoAutoLoad = inputMappings->AutoLoad();
// We have now output so HERE is where the next phi2 cycle starts.
pi1541.Update();
if (nextDisk)
{
pi1541.drive.Insert(diskCaddy.PrevDisk());
}
else if (prevDisk)
{
pi1541.drive.Insert(diskCaddy.NextDisk());
}
else if (numberOfImages > 1 && inputMappings->directDiskSwapRequest != 0)
{
for (caddyIndex = 0; caddyIndex < numberOfImagesMax; ++caddyIndex)
{
if (inputMappings->directDiskSwapRequest & (1 << caddyIndex))
{
DiskImage* diskImage = diskCaddy.SelectImage(caddyIndex);
if (diskImage && diskImage != pi1541.drive.GetDiskImage())
{
pi1541.drive.Insert(diskImage);
break;
}
}
}
inputMappings->directDiskSwapRequest = 0;
}
bool reset = IEC_Bus::IsReset();
if (reset)
@ -975,7 +945,7 @@ void emulator()
else
resetCount = 0;
if (!emulating || (resetCount > 10) || exitEmulation)
if (!emulating || (resetCount > 10) || exitEmulation || exitDoAutoLoad)
{
// Clearing the caddy now
// - will write back all changed/dirty/written to disk images now
@ -999,8 +969,9 @@ void emulator()
}
if (exitEmulation)
exitReason = EXIT_KEYBOARD;
if (exitDoAutoLoad)
exitReason = EXIT_AUTOLOAD;
break;
}
if (cycleCount < FAST_BOOT_CYCLES) // cycleCount is used so we can quickly get through 1541's self test code. This will make the emulated 1541 responsive to commands asap.
@ -1024,6 +995,36 @@ void emulator()
while (ctAfter == ctBefore);
}
ctBefore = ctAfter;
if (numberOfImages > 1)
{
bool nextDisk = inputMappings->NextDisk();
bool prevDisk = inputMappings->PrevDisk();
if (nextDisk)
{
pi1541.drive.Insert(diskCaddy.PrevDisk());
}
else if (prevDisk)
{
pi1541.drive.Insert(diskCaddy.NextDisk());
}
else if (inputMappings->directDiskSwapRequest != 0)
{
for (caddyIndex = 0; caddyIndex < numberOfImagesMax; ++caddyIndex)
{
if (inputMappings->directDiskSwapRequest & (1 << caddyIndex))
{
DiskImage* diskImage = diskCaddy.SelectImage(caddyIndex);
if (diskImage && diskImage != pi1541.drive.GetDiskImage())
{
pi1541.drive.Insert(diskImage);
break;
}
}
}
inputMappings->directDiskSwapRequest = 0;
}
}
}
}
}

View File

@ -16,4 +16,12 @@ typedef enum {
LCD_1106_128x64,
} LCD_MODEL;
typedef enum {
EXIT_UNKNOWN,
EXIT_RESET,
EXIT_CD,
EXIT_KEYBOARD,
EXIT_AUTOLOAD
} EXIT_TYPE;
#endif