diff --git a/source/Disk.cpp b/source/Disk.cpp index df476444..f6dba56b 100644 --- a/source/Disk.cpp +++ b/source/Disk.cpp @@ -38,6 +38,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include "Core.h" #include "CPU.h" #include "DiskImage.h" +#include "DiskImageHelper.h" #include "Log.h" #include "Memory.h" #include "Registry.h" @@ -655,7 +656,7 @@ void Disk2InterfaceCard::GetLightStatus(Disk_Status_e *pDisk1Status, Disk_Status //=========================================================================== // Pre: pszImageFilename is *not* qualified with path -ImageError_e Disk2InterfaceCard::InsertDisk(const int drive, LPCTSTR pszImageFilename, const bool bForceWriteProtected, const bool bCreateIfNecessary) +ImageError_e Disk2InterfaceCard::InsertDisk(const int drive, LPCTSTR pszImageFilename, const bool bForceWriteProtected, const bool bCreateIfNecessary, ImageInfo* pImageInfo /* = NULL */) { FloppyDrive* pDrive = &m_floppyDrive[drive]; FloppyDisk* pFloppy = &pDrive->m_disk; @@ -689,11 +690,22 @@ ImageError_e Disk2InterfaceCard::InsertDisk(const int drive, LPCTSTR pszImageFil } } - ImageError_e Error = ImageOpen(pszImageFilename, - &pFloppy->m_imagehandle, - &pFloppy->m_bWriteProtected, - bCreateIfNecessary, - pFloppy->m_strFilenameInZip); + ImageError_e Error = eIMAGE_ERROR_NONE; + if (pImageInfo) + { + // Use already opened image + pFloppy->m_imagehandle = pImageInfo; + pFloppy->m_bWriteProtected = pImageInfo->bWriteProtected; + } + else + { + // Open new image + ImageError_e Error = ImageOpen(pszImageFilename, + &pFloppy->m_imagehandle, + &pFloppy->m_bWriteProtected, + bCreateIfNecessary, + pFloppy->m_strFilenameInZip); + } if (Error == eIMAGE_ERROR_NONE && ImageIsMultiFileZip(pFloppy->m_imagehandle)) { diff --git a/source/Disk.h b/source/Disk.h index 24612c19..f80e4bf8 100644 --- a/source/Disk.h +++ b/source/Disk.h @@ -142,7 +142,7 @@ public: void GetFilenameAndPathForSaveState(std::string& filename, std::string& path); void GetLightStatus (Disk_Status_e* pDisk1Status, Disk_Status_e* pDisk2Status); - ImageError_e InsertDisk(const int drive, LPCTSTR pszImageFilename, const bool bForceWriteProtected, const bool bCreateIfNecessary); + ImageError_e InsertDisk(const int drive, LPCTSTR pszImageFilename, const bool bForceWriteProtected, const bool bCreateIfNecessary, ImageInfo* pImageInfo = NULL); void EjectDisk(const int drive); void UnplugDrive(const int drive); diff --git a/source/Harddisk.cpp b/source/Harddisk.cpp index 7a70b0ed..f270415d 100644 --- a/source/Harddisk.cpp +++ b/source/Harddisk.cpp @@ -207,8 +207,6 @@ static void NotifyInvalidImage(TCHAR* pszImageFilename) //=========================================================================== -BOOL HD_Insert(const int iDrive, const std::string & pszImageFilename); - void HD_LoadLastDiskImage(const int iDrive) { _ASSERT(iDrive == HARDDISK_1 || iDrive == HARDDISK_2); @@ -385,7 +383,7 @@ void HD_Destroy(void) } // Pre: pszImageFilename is qualified with path -BOOL HD_Insert(const int iDrive, const std::string & pszImageFilename) +BOOL HD_Insert(const int iDrive, const std::string & pszImageFilename, ImageInfo* pImageInfo /* = NULL */) { if (pszImageFilename.empty()) return FALSE; @@ -409,15 +407,26 @@ BOOL HD_Insert(const int iDrive, const std::string & pszImageFilename) } } - const bool bCreateIfNecessary = false; // NB. Don't allow creation of HDV files - const bool bExpectFloppy = false; - const bool bIsHarddisk = true; - ImageError_e Error = ImageOpen(pszImageFilename, - &g_HardDisk[iDrive].imagehandle, - &g_HardDisk[iDrive].bWriteProtected, - bCreateIfNecessary, - g_HardDisk[iDrive].strFilenameInZip, // TODO: Use this - bExpectFloppy); + ImageError_e Error = eIMAGE_ERROR_NONE; + if (pImageInfo) + { + // Use already opened image + g_HardDisk[iDrive].imagehandle = pImageInfo; + g_HardDisk[iDrive].bWriteProtected = pImageInfo->bWriteProtected; + } + else + { + // Open new image + const bool bCreateIfNecessary = false; // NB. Don't allow creation of HDV files + const bool bExpectFloppy = false; + const bool bIsHarddisk = true; + Error = ImageOpen(pszImageFilename, + &g_HardDisk[iDrive].imagehandle, + &g_HardDisk[iDrive].bWriteProtected, + bCreateIfNecessary, + g_HardDisk[iDrive].strFilenameInZip, // TODO: Use this + bExpectFloppy); + } g_HardDisk[iDrive].hd_imageloaded = (Error == eIMAGE_ERROR_NONE); diff --git a/source/Harddisk.h b/source/Harddisk.h index 0faa768e..317b76b6 100644 --- a/source/Harddisk.h +++ b/source/Harddisk.h @@ -44,7 +44,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA void HD_Reset(void); void HD_Load_Rom(const LPBYTE pCxRomPeripheral, const UINT uSlot); bool HD_Select(const int iDrive); - BOOL HD_Insert(const int iDrive, const std::string & pszImageFilename); + BOOL HD_Insert(const int iDrive, const std::string & pszImageFilename, ImageInfo* pImageInfo = NULL); void HD_Unplug(const int iDrive); bool HD_IsDriveUnplugged(const int iDrive); void HD_LoadLastDiskImage(const int iDrive);