InsertDisk and HD_Insert refactored to take an optional ImageInfo*

This commit is contained in:
tomcw 2021-05-05 21:51:36 +01:00
parent f27db49bd9
commit 524a03f071
4 changed files with 41 additions and 20 deletions

View File

@ -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))
{

View File

@ -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);

View File

@ -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);

View File

@ -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);