mirror of
https://github.com/AppleWin/AppleWin.git
synced 2025-01-10 13:29:56 +00:00
Refactor: Get rid of HIMAGE handle for disk images
This commit is contained in:
parent
d7937dc58c
commit
31483b33b9
@ -143,8 +143,6 @@ enum AppMode_e
|
|||||||
// TODO-TC: Refactor codebase by renaming /nCyclesLeft/ to /uExecutedCycles/
|
// TODO-TC: Refactor codebase by renaming /nCyclesLeft/ to /uExecutedCycles/
|
||||||
typedef BYTE (__stdcall *iofunction)(WORD nPC, WORD nAddr, BYTE nWriteFlag, BYTE nWriteValue, ULONG nCyclesLeft);
|
typedef BYTE (__stdcall *iofunction)(WORD nPC, WORD nAddr, BYTE nWriteFlag, BYTE nWriteValue, ULONG nCyclesLeft);
|
||||||
|
|
||||||
typedef struct _IMAGE__ { int unused; } *HIMAGE; // DiskImage's /ImageInfo/ is hidden behind HIMAGE
|
|
||||||
|
|
||||||
enum eIRQSRC {IS_6522=0, IS_SPEECH, IS_SSC, IS_MOUSE};
|
enum eIRQSRC {IS_6522=0, IS_SPEECH, IS_SSC, IS_MOUSE};
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -76,7 +76,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|||||||
TCHAR imagename[ MAX_DISK_IMAGE_NAME + 1 ]; // <FILENAME> (ie. no extension)
|
TCHAR imagename[ MAX_DISK_IMAGE_NAME + 1 ]; // <FILENAME> (ie. no extension)
|
||||||
TCHAR fullname [ MAX_DISK_FULL_NAME + 1 ]; // <FILENAME.EXT> or <FILENAME.zip> : This is persisted to the snapshot file
|
TCHAR fullname [ MAX_DISK_FULL_NAME + 1 ]; // <FILENAME.EXT> or <FILENAME.zip> : This is persisted to the snapshot file
|
||||||
std::string strFilenameInZip; // "" or <FILENAME.EXT>
|
std::string strFilenameInZip; // "" or <FILENAME.EXT>
|
||||||
HIMAGE imagehandle; // Init'd by DiskInsert() -> ImageOpen()
|
ImageInfo* imagehandle; // Init'd by DiskInsert() -> ImageOpen()
|
||||||
bool bWriteProtected;
|
bool bWriteProtected;
|
||||||
//
|
//
|
||||||
int track;
|
int track;
|
||||||
@ -327,7 +327,7 @@ static void RemoveDisk(const int iDrive)
|
|||||||
WriteTrack( iDrive);
|
WriteTrack( iDrive);
|
||||||
|
|
||||||
ImageClose(pFloppy->imagehandle);
|
ImageClose(pFloppy->imagehandle);
|
||||||
pFloppy->imagehandle = (HIMAGE)0;
|
pFloppy->imagehandle = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pFloppy->trackimage)
|
if (pFloppy->trackimage)
|
||||||
|
@ -27,7 +27,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "StdAfx.h"
|
#include "StdAfx.h"
|
||||||
#include "Common.h"
|
|
||||||
|
|
||||||
#include "DiskImage.h"
|
#include "DiskImage.h"
|
||||||
#include "DiskImageHelper.h"
|
#include "DiskImageHelper.h"
|
||||||
@ -40,23 +39,23 @@ static CHardDiskImageHelper sg_HardDiskImageHelper;
|
|||||||
|
|
||||||
// Pre: *pWriteProtected_ already set to file's r/w status - see DiskInsert()
|
// Pre: *pWriteProtected_ already set to file's r/w status - see DiskInsert()
|
||||||
ImageError_e ImageOpen( LPCTSTR pszImageFilename,
|
ImageError_e ImageOpen( LPCTSTR pszImageFilename,
|
||||||
HIMAGE* hDiskImage,
|
ImageInfo** ppImageInfo,
|
||||||
bool* pWriteProtected,
|
bool* pWriteProtected,
|
||||||
const bool bCreateIfNecessary,
|
const bool bCreateIfNecessary,
|
||||||
std::string& strFilenameInZip,
|
std::string& strFilenameInZip,
|
||||||
const bool bExpectFloppy /*=true*/,
|
const bool bExpectFloppy /*=true*/,
|
||||||
const bool bIsHarddisk /*=false*/)
|
const bool bIsHarddisk /*=false*/)
|
||||||
{
|
{
|
||||||
if (! (pszImageFilename && hDiskImage && pWriteProtected && sg_DiskImageHelper.GetWorkBuffer()))
|
if (! (pszImageFilename && ppImageInfo && pWriteProtected && sg_DiskImageHelper.GetWorkBuffer()))
|
||||||
return eIMAGE_ERROR_BAD_POINTER;
|
return eIMAGE_ERROR_BAD_POINTER;
|
||||||
|
|
||||||
// CREATE A RECORD FOR THE FILE, AND RETURN AN IMAGE HANDLE
|
// CREATE A RECORD FOR THE FILE
|
||||||
*hDiskImage = (HIMAGE) VirtualAlloc(NULL, sizeof(ImageInfo), MEM_COMMIT, PAGE_READWRITE);
|
*ppImageInfo = (ImageInfo*) VirtualAlloc(NULL, sizeof(ImageInfo), MEM_COMMIT, PAGE_READWRITE);
|
||||||
if (*hDiskImage == NULL)
|
if (*ppImageInfo == NULL)
|
||||||
return eIMAGE_ERROR_BAD_POINTER;
|
return eIMAGE_ERROR_BAD_POINTER;
|
||||||
|
|
||||||
ZeroMemory(*hDiskImage, sizeof(ImageInfo));
|
ZeroMemory(*ppImageInfo, sizeof(ImageInfo));
|
||||||
ImageInfo* pImageInfo = (ImageInfo*) *hDiskImage;
|
ImageInfo* pImageInfo = *ppImageInfo;
|
||||||
pImageInfo->bWriteProtected = *pWriteProtected;
|
pImageInfo->bWriteProtected = *pWriteProtected;
|
||||||
|
|
||||||
ImageError_e Err = (!bIsHarddisk)
|
ImageError_e Err = (!bIsHarddisk)
|
||||||
@ -65,8 +64,8 @@ ImageError_e ImageOpen( LPCTSTR pszImageFilename,
|
|||||||
|
|
||||||
if (Err != eIMAGE_ERROR_NONE)
|
if (Err != eIMAGE_ERROR_NONE)
|
||||||
{
|
{
|
||||||
ImageClose(*hDiskImage, true);
|
ImageClose(*ppImageInfo, true);
|
||||||
*hDiskImage = (HIMAGE)0;
|
*ppImageInfo = NULL;
|
||||||
return Err;
|
return Err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,16 +90,15 @@ ImageError_e ImageOpen( LPCTSTR pszImageFilename,
|
|||||||
|
|
||||||
//===========================================================================
|
//===========================================================================
|
||||||
|
|
||||||
void ImageClose(const HIMAGE hDiskImage, const bool bOpenError /*=false*/)
|
void ImageClose(ImageInfo* const pImageInfo, const bool bOpenError /*=false*/)
|
||||||
{
|
{
|
||||||
ImageInfo* ptr = (ImageInfo*) hDiskImage;
|
|
||||||
bool bDeleteFile = false;
|
bool bDeleteFile = false;
|
||||||
|
|
||||||
if (!bOpenError)
|
if (!bOpenError)
|
||||||
{
|
{
|
||||||
for (UINT uTrack = 0; uTrack < ptr->uNumTracks; uTrack++)
|
for (UINT uTrack = 0; uTrack < pImageInfo->uNumTracks; uTrack++)
|
||||||
{
|
{
|
||||||
if (!ptr->ValidTrack[uTrack])
|
if (!pImageInfo->ValidTrack[uTrack])
|
||||||
{
|
{
|
||||||
// TODO: Comment using info from this URL:
|
// TODO: Comment using info from this URL:
|
||||||
// http://groups.google.de/group/comp.emulators.apple2/msg/7a1b9317e7905152
|
// http://groups.google.de/group/comp.emulators.apple2/msg/7a1b9317e7905152
|
||||||
@ -110,23 +108,22 @@ void ImageClose(const HIMAGE hDiskImage, const bool bOpenError /*=false*/)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sg_DiskImageHelper.Close(ptr, bDeleteFile);
|
sg_DiskImageHelper.Close(pImageInfo, bDeleteFile);
|
||||||
|
|
||||||
VirtualFree(ptr, 0, MEM_RELEASE);
|
VirtualFree(pImageInfo, 0, MEM_RELEASE);
|
||||||
}
|
}
|
||||||
|
|
||||||
//===========================================================================
|
//===========================================================================
|
||||||
|
|
||||||
BOOL ImageBoot(const HIMAGE hDiskImage)
|
BOOL ImageBoot(ImageInfo* const pImageInfo)
|
||||||
{
|
{
|
||||||
ImageInfo* ptr = (ImageInfo*) hDiskImage;
|
|
||||||
BOOL result = 0;
|
BOOL result = 0;
|
||||||
|
|
||||||
if (ptr->pImageType->AllowBoot())
|
if (pImageInfo->pImageType->AllowBoot())
|
||||||
result = ptr->pImageType->Boot(ptr);
|
result = pImageInfo->pImageType->Boot(pImageInfo);
|
||||||
|
|
||||||
if (result)
|
if (result)
|
||||||
ptr->bWriteProtected = 1;
|
pImageInfo->bWriteProtected = 1;
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -149,7 +146,7 @@ void ImageInitialize(void)
|
|||||||
|
|
||||||
//===========================================================================
|
//===========================================================================
|
||||||
|
|
||||||
void ImageReadTrack( const HIMAGE hDiskImage,
|
void ImageReadTrack( ImageInfo* const pImageInfo,
|
||||||
const int nTrack,
|
const int nTrack,
|
||||||
const int nQuarterTrack,
|
const int nQuarterTrack,
|
||||||
LPBYTE pTrackImageBuffer,
|
LPBYTE pTrackImageBuffer,
|
||||||
@ -159,10 +156,9 @@ void ImageReadTrack( const HIMAGE hDiskImage,
|
|||||||
if (nTrack < 0)
|
if (nTrack < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ImageInfo* ptr = (ImageInfo*) hDiskImage;
|
if (pImageInfo->pImageType->AllowRW() && pImageInfo->ValidTrack[nTrack])
|
||||||
if (ptr->pImageType->AllowRW() && ptr->ValidTrack[nTrack])
|
|
||||||
{
|
{
|
||||||
ptr->pImageType->Read(ptr, nTrack, nQuarterTrack, pTrackImageBuffer, pNibbles);
|
pImageInfo->pImageType->Read(pImageInfo, nTrack, nQuarterTrack, pTrackImageBuffer, pNibbles);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -173,7 +169,7 @@ void ImageReadTrack( const HIMAGE hDiskImage,
|
|||||||
|
|
||||||
//===========================================================================
|
//===========================================================================
|
||||||
|
|
||||||
void ImageWriteTrack( const HIMAGE hDiskImage,
|
void ImageWriteTrack( ImageInfo* const pImageInfo,
|
||||||
const int nTrack,
|
const int nTrack,
|
||||||
const int nQuarterTrack,
|
const int nQuarterTrack,
|
||||||
LPBYTE pTrackImage,
|
LPBYTE pTrackImage,
|
||||||
@ -183,75 +179,65 @@ void ImageWriteTrack( const HIMAGE hDiskImage,
|
|||||||
if (nTrack < 0)
|
if (nTrack < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ImageInfo* ptr = (ImageInfo*) hDiskImage;
|
if (pImageInfo->pImageType->AllowRW() && !pImageInfo->bWriteProtected)
|
||||||
if (ptr->pImageType->AllowRW() && !ptr->bWriteProtected)
|
|
||||||
{
|
{
|
||||||
ptr->pImageType->Write(ptr, nTrack, nQuarterTrack, pTrackImage, nNibbles);
|
pImageInfo->pImageType->Write(pImageInfo, nTrack, nQuarterTrack, pTrackImage, nNibbles);
|
||||||
ptr->ValidTrack[nTrack] = 1;
|
pImageInfo->ValidTrack[nTrack] = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//===========================================================================
|
//===========================================================================
|
||||||
|
|
||||||
bool ImageReadBlock( const HIMAGE hDiskImage,
|
bool ImageReadBlock( ImageInfo* const pImageInfo,
|
||||||
UINT nBlock,
|
UINT nBlock,
|
||||||
LPBYTE pBlockBuffer)
|
LPBYTE pBlockBuffer)
|
||||||
{
|
{
|
||||||
ImageInfo* ptr = (ImageInfo*) hDiskImage;
|
|
||||||
|
|
||||||
bool bRes = false;
|
bool bRes = false;
|
||||||
if (ptr->pImageType->AllowRW())
|
if (pImageInfo->pImageType->AllowRW())
|
||||||
bRes = ptr->pImageType->Read(ptr, nBlock, pBlockBuffer);
|
bRes = pImageInfo->pImageType->Read(pImageInfo, nBlock, pBlockBuffer);
|
||||||
|
|
||||||
return bRes;
|
return bRes;
|
||||||
}
|
}
|
||||||
|
|
||||||
//===========================================================================
|
//===========================================================================
|
||||||
|
|
||||||
bool ImageWriteBlock( const HIMAGE hDiskImage,
|
bool ImageWriteBlock( ImageInfo* const pImageInfo,
|
||||||
UINT nBlock,
|
UINT nBlock,
|
||||||
LPBYTE pBlockBuffer)
|
LPBYTE pBlockBuffer)
|
||||||
{
|
{
|
||||||
ImageInfo* ptr = (ImageInfo*) hDiskImage;
|
|
||||||
|
|
||||||
bool bRes = false;
|
bool bRes = false;
|
||||||
if (ptr->pImageType->AllowRW() && !ptr->bWriteProtected)
|
if (pImageInfo->pImageType->AllowRW() && !pImageInfo->bWriteProtected)
|
||||||
bRes = ptr->pImageType->Write(ptr, nBlock, pBlockBuffer);
|
bRes = pImageInfo->pImageType->Write(pImageInfo, nBlock, pBlockBuffer);
|
||||||
|
|
||||||
return bRes;
|
return bRes;
|
||||||
}
|
}
|
||||||
|
|
||||||
//===========================================================================
|
//===========================================================================
|
||||||
|
|
||||||
int ImageGetNumTracks(const HIMAGE hDiskImage)
|
int ImageGetNumTracks(ImageInfo* const pImageInfo)
|
||||||
{
|
{
|
||||||
ImageInfo* ptr = (ImageInfo*) hDiskImage;
|
return pImageInfo ? pImageInfo->uNumTracks : 0;
|
||||||
return ptr ? ptr->uNumTracks : 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ImageIsWriteProtected(const HIMAGE hDiskImage)
|
bool ImageIsWriteProtected(ImageInfo* const pImageInfo)
|
||||||
{
|
{
|
||||||
ImageInfo* ptr = (ImageInfo*) hDiskImage;
|
return pImageInfo ? pImageInfo->bWriteProtected : true;
|
||||||
return ptr ? ptr->bWriteProtected : true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ImageIsMultiFileZip(const HIMAGE hDiskImage)
|
bool ImageIsMultiFileZip(ImageInfo* const pImageInfo)
|
||||||
{
|
{
|
||||||
ImageInfo* ptr = (ImageInfo*) hDiskImage;
|
return pImageInfo ? (pImageInfo->uNumEntriesInZip > 1) : false;
|
||||||
return ptr ? (ptr->uNumEntriesInZip > 1) : false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* ImageGetPathname(const HIMAGE hDiskImage)
|
const char* ImageGetPathname(ImageInfo* const pImageInfo)
|
||||||
{
|
{
|
||||||
static char* szEmpty = "";
|
static char* szEmpty = "";
|
||||||
ImageInfo* ptr = (ImageInfo*) hDiskImage;
|
return pImageInfo ? pImageInfo->szFilename : szEmpty;
|
||||||
return ptr ? ptr->szFilename : szEmpty;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
UINT ImageGetImageSize(const HIMAGE hDiskImage)
|
UINT ImageGetImageSize(ImageInfo* const pImageInfo)
|
||||||
{
|
{
|
||||||
ImageInfo* ptr = (ImageInfo*) hDiskImage;
|
return pImageInfo ? pImageInfo->uImageSize : 0;
|
||||||
return ptr ? ptr->uImageSize : 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GetImageTitle(LPCTSTR pPathname, TCHAR* pImageName, TCHAR* pFullName)
|
void GetImageTitle(LPCTSTR pPathname, TCHAR* pImageName, TCHAR* pFullName)
|
||||||
|
@ -61,22 +61,23 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|||||||
const int MAX_DISK_IMAGE_NAME = 15;
|
const int MAX_DISK_IMAGE_NAME = 15;
|
||||||
const int MAX_DISK_FULL_NAME = 127;
|
const int MAX_DISK_FULL_NAME = 127;
|
||||||
|
|
||||||
|
struct ImageInfo;
|
||||||
|
|
||||||
ImageError_e ImageOpen(LPCTSTR pszImageFilename, HIMAGE* hDiskImage, bool* pWriteProtected, const bool bCreateIfNecessary, std::string& strFilenameInZip, const bool bExpectFloppy=true, const bool bIsHarddisk=false);
|
ImageError_e ImageOpen(LPCTSTR pszImageFilename, ImageInfo** ppImageInfo, bool* pWriteProtected, const bool bCreateIfNecessary, std::string& strFilenameInZip, const bool bExpectFloppy=true, const bool bIsHarddisk=false);
|
||||||
void ImageClose(const HIMAGE hDiskImage, const bool bOpenError=false);
|
void ImageClose(ImageInfo* const pImageInfo, const bool bOpenError=false);
|
||||||
BOOL ImageBoot(const HIMAGE hDiskImage);
|
BOOL ImageBoot(ImageInfo* const pImageInfo);
|
||||||
void ImageDestroy(void);
|
void ImageDestroy(void);
|
||||||
void ImageInitialize(void);
|
void ImageInitialize(void);
|
||||||
|
|
||||||
void ImageReadTrack(const HIMAGE hDiskImage, int nTrack, int nQuarterTrack, LPBYTE pTrackImageBuffer, int* pNibbles);
|
void ImageReadTrack(ImageInfo* const pImageInfo, int nTrack, int nQuarterTrack, LPBYTE pTrackImageBuffer, int* pNibbles);
|
||||||
void ImageWriteTrack(const HIMAGE hDiskImage, int nTrack, int nQuarterTrack, LPBYTE pTrackImage, int nNibbles);
|
void ImageWriteTrack(ImageInfo* const pImageInfo, int nTrack, int nQuarterTrack, LPBYTE pTrackImage, int nNibbles);
|
||||||
bool ImageReadBlock(const HIMAGE hDiskImage, UINT nBlock, LPBYTE pBlockBuffer);
|
bool ImageReadBlock(ImageInfo* const pImageInfo, UINT nBlock, LPBYTE pBlockBuffer);
|
||||||
bool ImageWriteBlock(const HIMAGE hDiskImage, UINT nBlock, LPBYTE pBlockBuffer);
|
bool ImageWriteBlock(ImageInfo* const pImageInfo, UINT nBlock, LPBYTE pBlockBuffer);
|
||||||
|
|
||||||
int ImageGetNumTracks(const HIMAGE hDiskImage);
|
int ImageGetNumTracks(ImageInfo* const pImageInfo);
|
||||||
bool ImageIsWriteProtected(const HIMAGE hDiskImage);
|
bool ImageIsWriteProtected(ImageInfo* const pImageInfo);
|
||||||
bool ImageIsMultiFileZip(const HIMAGE hDiskImage);
|
bool ImageIsMultiFileZip(ImageInfo* const pImageInfo);
|
||||||
const char* ImageGetPathname(const HIMAGE hDiskImage);
|
const char* ImageGetPathname(ImageInfo* const pImageInfo);
|
||||||
UINT ImageGetImageSize(const HIMAGE hDiskImage);
|
UINT ImageGetImageSize(ImageInfo* const pImageInfo);
|
||||||
|
|
||||||
void GetImageTitle(LPCTSTR pPathname, TCHAR* pImageName, TCHAR* pFullName);
|
void GetImageTitle(LPCTSTR pPathname, TCHAR* pImageName, TCHAR* pFullName);
|
||||||
|
@ -118,7 +118,7 @@ struct HDD
|
|||||||
TCHAR imagename[ MAX_DISK_IMAGE_NAME + 1 ]; // <FILENAME> (ie. no extension) [not used]
|
TCHAR imagename[ MAX_DISK_IMAGE_NAME + 1 ]; // <FILENAME> (ie. no extension) [not used]
|
||||||
TCHAR fullname[ MAX_DISK_FULL_NAME + 1 ]; // <FILENAME.EXT> or <FILENAME.zip>
|
TCHAR fullname[ MAX_DISK_FULL_NAME + 1 ]; // <FILENAME.EXT> or <FILENAME.zip>
|
||||||
std::string strFilenameInZip; // "" or <FILENAME.EXT> [not used]
|
std::string strFilenameInZip; // "" or <FILENAME.EXT> [not used]
|
||||||
HIMAGE imagehandle; // Init'd by HD_Insert() -> ImageOpen()
|
ImageInfo* imagehandle; // Init'd by HD_Insert() -> ImageOpen()
|
||||||
bool bWriteProtected; // Needed for ImageOpen() [otherwise not used]
|
bool bWriteProtected; // Needed for ImageOpen() [otherwise not used]
|
||||||
//
|
//
|
||||||
BYTE hd_error;
|
BYTE hd_error;
|
||||||
@ -157,7 +157,7 @@ static void HD_CleanupDrive(const int iDrive)
|
|||||||
if (g_HardDisk[iDrive].imagehandle)
|
if (g_HardDisk[iDrive].imagehandle)
|
||||||
{
|
{
|
||||||
ImageClose(g_HardDisk[iDrive].imagehandle);
|
ImageClose(g_HardDisk[iDrive].imagehandle);
|
||||||
g_HardDisk[iDrive].imagehandle = (HIMAGE)0;
|
g_HardDisk[iDrive].imagehandle = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_HardDisk[iDrive].hd_imageloaded = false;
|
g_HardDisk[iDrive].hd_imageloaded = false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user