mirror of
https://github.com/AppleWin/AppleWin.git
synced 2026-04-21 23:16:39 +00:00
Removed redundant binary v2 save-state code
Also: . support new CpuType independently of Apple2Type . save-state: don't save disk track image if no disk . save-state: re-init AppleWin internals & UI to reflect changed Apple2Type
This commit is contained in:
@@ -804,159 +804,3 @@ bool HD_LoadSnapshot(YamlLoadHelper& yamlLoadHelper, UINT slot, UINT version, co
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//---
|
||||
|
||||
struct HDD_Unit
|
||||
{
|
||||
char szFilename[MAX_PATH];
|
||||
BYTE error;
|
||||
WORD memblock;
|
||||
UINT diskblock;
|
||||
WORD buf_ptr;
|
||||
BOOL imageloaded;
|
||||
BYTE buf[HD_BLOCK_SIZE];
|
||||
UINT status_next;
|
||||
UINT status_prev;
|
||||
};
|
||||
|
||||
struct SS_CARD_HDD
|
||||
{
|
||||
SS_CARD_HDR Hdr;
|
||||
HDD_Unit Unit[NUM_HARDDISKS];
|
||||
BYTE CurrUnit;
|
||||
BYTE Command;
|
||||
};
|
||||
|
||||
void HD_GetSnapshot(const HANDLE hFile)
|
||||
{
|
||||
if (!HD_CardIsEnabled())
|
||||
return;
|
||||
|
||||
SS_CARD_HDD CardHDD;
|
||||
|
||||
CardHDD.Hdr.UnitHdr.hdr.v2.Length = sizeof(SS_CARD_HDD);
|
||||
CardHDD.Hdr.UnitHdr.hdr.v2.Type = UT_Card;
|
||||
CardHDD.Hdr.UnitHdr.hdr.v2.Version = 1;
|
||||
|
||||
CardHDD.Hdr.Slot = g_uSlot;
|
||||
CardHDD.Hdr.Type = CT_GenericHDD;
|
||||
|
||||
CardHDD.CurrUnit = g_nHD_UnitNum;
|
||||
CardHDD.Command = g_nHD_Command;
|
||||
|
||||
for (UINT i=0; i<NUM_HARDDISKS; i++)
|
||||
{
|
||||
strcpy(CardHDD.Unit[i].szFilename, g_HardDisk[i].fullname);
|
||||
CardHDD.Unit[i].error = g_HardDisk[i].hd_error;
|
||||
CardHDD.Unit[i].memblock = g_HardDisk[i].hd_memblock;
|
||||
CardHDD.Unit[i].diskblock = g_HardDisk[i].hd_diskblock;
|
||||
CardHDD.Unit[i].buf_ptr = g_HardDisk[i].hd_buf_ptr;
|
||||
CardHDD.Unit[i].imageloaded = g_HardDisk[i].hd_imageloaded;
|
||||
memcpy(CardHDD.Unit[i].buf, g_HardDisk[i].hd_buf, sizeof(CardHDD.Unit[i].buf));
|
||||
CardHDD.Unit[i].status_next = g_HardDisk[i].hd_status_next;
|
||||
CardHDD.Unit[i].status_prev = g_HardDisk[i].hd_status_prev;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
DWORD dwBytesWritten;
|
||||
BOOL bRes = WriteFile( hFile,
|
||||
&CardHDD,
|
||||
CardHDD.Hdr.UnitHdr.hdr.v2.Length,
|
||||
&dwBytesWritten,
|
||||
NULL);
|
||||
|
||||
if(!bRes || (dwBytesWritten != CardHDD.Hdr.UnitHdr.hdr.v2.Length))
|
||||
{
|
||||
//dwError = GetLastError();
|
||||
throw std::string("Save error: HDD");
|
||||
}
|
||||
}
|
||||
|
||||
void HD_SetSnapshot(const HANDLE hFile, const std::string strSaveStatePath)
|
||||
{
|
||||
SS_CARD_HDD CardHDD;
|
||||
|
||||
DWORD dwBytesRead;
|
||||
BOOL bRes = ReadFile( hFile,
|
||||
&CardHDD,
|
||||
sizeof(CardHDD),
|
||||
&dwBytesRead,
|
||||
NULL);
|
||||
|
||||
if (dwBytesRead != sizeof(CardHDD))
|
||||
throw std::string("Card: file corrupt");
|
||||
|
||||
if (CardHDD.Hdr.Slot != 7) // fixme
|
||||
throw std::string("Card: wrong slot");
|
||||
|
||||
if (CardHDD.Hdr.UnitHdr.hdr.v2.Version > 1)
|
||||
throw std::string("Card: wrong version");
|
||||
|
||||
if (CardHDD.Hdr.UnitHdr.hdr.v2.Length != sizeof(SS_CARD_HDD))
|
||||
throw std::string("Card: unit size mismatch");
|
||||
|
||||
g_nHD_UnitNum = CardHDD.CurrUnit;
|
||||
g_nHD_Command = CardHDD.Command;
|
||||
|
||||
// Unplug all HDDs first in case HDD-2 is to be plugged in as HDD-1
|
||||
for (UINT i=0; i<NUM_HARDDISKS; i++)
|
||||
{
|
||||
HD_Unplug(i);
|
||||
ZeroMemory(&g_HardDisk[i], sizeof(HDD));
|
||||
}
|
||||
|
||||
bool bResSelectImage = false;
|
||||
|
||||
for (UINT i=0; i<NUM_HARDDISKS; i++)
|
||||
{
|
||||
if (CardHDD.Unit[i].szFilename[0] == 0x00)
|
||||
continue;
|
||||
|
||||
DWORD dwAttributes = GetFileAttributes(CardHDD.Unit[i].szFilename);
|
||||
if (dwAttributes == INVALID_FILE_ATTRIBUTES)
|
||||
{
|
||||
// Get user to browse for file
|
||||
bResSelectImage = HD_SelectImage(i, CardHDD.Unit[i].szFilename);
|
||||
|
||||
dwAttributes = GetFileAttributes(CardHDD.Unit[i].szFilename);
|
||||
}
|
||||
|
||||
bool bImageError = (dwAttributes == INVALID_FILE_ATTRIBUTES);
|
||||
if (!bImageError)
|
||||
{
|
||||
if (!HD_Insert(i, CardHDD.Unit[i].szFilename))
|
||||
bImageError = true;
|
||||
|
||||
// HD_Insert() sets up:
|
||||
// . imagename
|
||||
// . fullname
|
||||
// . hd_imageloaded
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
// strcpy(g_HardDisk[i].fullname, CardHDD.Unit[i].szFilename);
|
||||
g_HardDisk[i].hd_error = CardHDD.Unit[i].error;
|
||||
g_HardDisk[i].hd_memblock = CardHDD.Unit[i].memblock;
|
||||
g_HardDisk[i].hd_diskblock = CardHDD.Unit[i].diskblock;
|
||||
g_HardDisk[i].hd_buf_ptr = CardHDD.Unit[i].buf_ptr;
|
||||
// g_HardDisk[i].hd_imageloaded = CardHDD.Unit[i].imageloaded;
|
||||
memcpy(g_HardDisk[i].hd_buf, CardHDD.Unit[i].buf, sizeof(CardHDD.Unit[i].buf));
|
||||
g_HardDisk[i].hd_status_next = (Disk_Status_e) CardHDD.Unit[i].status_next;
|
||||
g_HardDisk[i].hd_status_prev = (Disk_Status_e) CardHDD.Unit[i].status_prev;
|
||||
|
||||
if (bImageError)
|
||||
{
|
||||
g_HardDisk[i].hd_imageloaded = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
if (!bResSelectImage)
|
||||
RegSaveString(TEXT(REG_PREFS), TEXT(REGVALUE_PREF_HDV_START_DIR), 1, strSaveStatePath.c_str());
|
||||
|
||||
HD_SetEnabled(true);
|
||||
|
||||
FrameRefreshStatus(DRAW_LEDS);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user