From 1ca78e3383fbad2880d218fcee14b5936b1959c0 Mon Sep 17 00:00:00 2001 From: Stephen White Date: Sat, 28 Dec 2019 15:27:28 +1100 Subject: [PATCH] If you select a PRG file using the Pi's browser then it will mount it into a virtual D64 so fast loaders can be used. Note: FB64 will still use SD2IEC style loading directlyfrom the Pi's file system. --- src/DiskCaddy.cpp | 17 +++++++++++++++++ src/DiskCaddy.h | 1 + src/DiskImage.cpp | 37 +++++++++++++++++++++++++++++++++++++ src/DiskImage.h | 2 ++ 4 files changed, 57 insertions(+) diff --git a/src/DiskCaddy.cpp b/src/DiskCaddy.cpp index ffa29ae..821d8fd 100644 --- a/src/DiskCaddy.cpp +++ b/src/DiskCaddy.cpp @@ -182,6 +182,9 @@ bool DiskCaddy::Insert(const FILINFO* fileInfo, bool readOnly) case DiskImage::T64: success = InsertT64(fileInfo, (unsigned char*)DiskImage::readBuffer, bytesRead, readOnly); break; + case DiskImage::PRG: + success = InsertPRG(fileInfo, (unsigned char*)DiskImage::readBuffer, bytesRead, readOnly); + break; default: success = false; break; @@ -289,6 +292,20 @@ bool DiskCaddy::InsertT64(const FILINFO* fileInfo, unsigned char* diskImageData, return false; } +bool DiskCaddy::InsertPRG(const FILINFO* fileInfo, unsigned char* diskImageData, unsigned size, bool readOnly) +{ + DiskImage* diskImage = new DiskImage(); + if (diskImage->OpenPRG(fileInfo, diskImageData, size)) + { + diskImage->SetReadOnly(readOnly); + disks.push_back(diskImage); + selectedIndex = disks.size() - 1; + return true; + } + delete diskImage; + return false; +} + void DiskCaddy::Display() { unsigned numberOfImages = GetNumberOfImages(); diff --git a/src/DiskCaddy.h b/src/DiskCaddy.h index a08a43b..e588e02 100644 --- a/src/DiskCaddy.h +++ b/src/DiskCaddy.h @@ -107,6 +107,7 @@ private: bool InsertNBZ(const FILINFO* fileInfo, unsigned char* diskImageData, unsigned size, bool readOnly); bool InsertD81(const FILINFO* fileInfo, unsigned char* diskImageData, unsigned size, bool readOnly); bool InsertT64(const FILINFO* fileInfo, unsigned char* diskImageData, unsigned size, bool readOnly); + bool InsertPRG(const FILINFO* fileInfo, unsigned char* diskImageData, unsigned size, bool readOnly); void ShowSelectedImage(u32 index); diff --git a/src/DiskImage.cpp b/src/DiskImage.cpp index 68cc449..7f13dfb 100644 --- a/src/DiskImage.cpp +++ b/src/DiskImage.cpp @@ -176,6 +176,7 @@ void DiskImage::Close() memset(tracks, 0x55, sizeof(tracks)); break; default: + memset(tracks, 0x55, sizeof(tracks)); break; } memset(trackLengths, 0, sizeof(trackLengths)); @@ -1295,6 +1296,40 @@ void DiskImage::CloseT64() attachedImageSize = 0; } +bool DiskImage::OpenPRG(const FILINFO* fileInfo, unsigned char* diskImage, unsigned size) +{ + bool success = false; + + Close(); + + this->fileInfo = fileInfo; + + attachedImageSize = size; + + unsigned char* newDiskImage = (unsigned char*)malloc(READBUFFER_SIZE); + + if (newDiskImage) + { + unsigned length = DiskImage::CreateNewDiskInRAM(fileInfo->fname, "00", newDiskImage); + + if (length) + { + bool addFileSuccess = AddFileToRAMD64(newDiskImage, fileInfo->fname, diskImage, size); + + if (addFileSuccess && OpenD64(fileInfo, newDiskImage, length)) + { + success = true; + DEBUG_LOG("Success\r\n"); + diskType = PRG; + } + } + + free(newDiskImage); + } + + return success; +} + bool DiskImage::GetDecodedSector(u32 track, u32 sector, u8* buffer) { if (track > 0) @@ -1327,6 +1362,8 @@ DiskImage::DiskType DiskImage::GetDiskImageTypeViaExtention(const char* diskImag return LST; else if (toupper((char)ext[1]) == 'D' && ext[2] == '8' && ext[3] == '1') return D81; + else if (toupper((char)ext[1]) == 'P' && toupper((char)ext[2]) == 'R' && toupper((char)ext[3]) == 'G') + return PRG; } return NONE; } diff --git a/src/DiskImage.h b/src/DiskImage.h index bcc810d..e9f3409 100644 --- a/src/DiskImage.h +++ b/src/DiskImage.h @@ -63,6 +63,7 @@ public: D71, D81, T64, + PRG, RAW }; @@ -77,6 +78,7 @@ public: bool OpenD71(const FILINFO* fileInfo, unsigned char* diskImage, unsigned size); bool OpenD81(const FILINFO* fileInfo, unsigned char* diskImage, unsigned size); bool OpenT64(const FILINFO* fileInfo, unsigned char* diskImage, unsigned size); + bool OpenPRG(const FILINFO* fileInfo, unsigned char* diskImage, unsigned size); void Close();