mirror of
https://github.com/AppleWin/AppleWin.git
synced 2026-04-20 00:17:16 +00:00
Manual merge from master @ c798157
This commit is contained in:
+427
-129
@@ -4,7 +4,7 @@ AppleWin : An Apple //e emulator for Windows
|
||||
Copyright (C) 1994-1996, Michael O'Brien
|
||||
Copyright (C) 1999-2001, Oliver Schmidt
|
||||
Copyright (C) 2002-2005, Tom Charlesworth
|
||||
Copyright (C) 2006-2007, Tom Charlesworth, Michael Pohoreski
|
||||
Copyright (C) 2006-2015, Tom Charlesworth, Michael Pohoreski
|
||||
|
||||
AppleWin is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -23,11 +23,14 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
/* Description: Save-state (snapshot) module
|
||||
*
|
||||
* Author: Copyright (c) 2004-2006 Tom Charlesworth
|
||||
* Author: Copyright (c) 2004-2015 Tom Charlesworth
|
||||
*/
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "SaveState_Structs_v1.h"
|
||||
#include "YamlHelper.h"
|
||||
|
||||
#include "AppleWin.h"
|
||||
#include "CPU.h"
|
||||
#include "Disk.h"
|
||||
@@ -36,17 +39,20 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#include "Keyboard.h"
|
||||
#include "Memory.h"
|
||||
#include "Mockingboard.h"
|
||||
#include "MouseInterface.h"
|
||||
#include "ParallelPrinter.h"
|
||||
#include "Pravets.h"
|
||||
#include "SerialComms.h"
|
||||
#include "Speaker.h"
|
||||
#include "Speech.h"
|
||||
#include "Video.h"
|
||||
#include "z80emu.h"
|
||||
|
||||
// Prototypes (Public)
|
||||
// Note: This is here and not in Video.h to prevent header include bloat.
|
||||
// i.e. so we don't need to incude "Structs.h" for NTSC.cpp
|
||||
DWORD VideoGetSnapshot(SS_IO_Video* pSS);
|
||||
DWORD VideoSetSnapshot(SS_IO_Video* pSS);
|
||||
#include "Configuration\Config.h"
|
||||
#include "Configuration\IPropertySheet.h"
|
||||
|
||||
#define DEFAULT_SNAPSHOT_NAME "SaveState.aws"
|
||||
|
||||
#define DEFAULT_SNAPSHOT_NAME "SaveState.aws.yaml"
|
||||
|
||||
bool g_bSaveStateOnExit = false;
|
||||
|
||||
@@ -54,6 +60,13 @@ static std::string g_strSaveStateFilename;
|
||||
static std::string g_strSaveStatePathname;
|
||||
static std::string g_strSaveStatePath;
|
||||
|
||||
static YamlHelper yamlHelper;
|
||||
|
||||
#define SS_FILE_VER 2
|
||||
|
||||
#define UNIT_APPLE2_VER 1
|
||||
#define UNIT_SLOTS_VER 1
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void Snapshot_SetFilename(std::string strPathname)
|
||||
@@ -98,22 +111,27 @@ const char* Snapshot_GetPath()
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void Snapshot_LoadState()
|
||||
static void Snapshot_LoadState_v1() // .aws v1.0.0.1, up to (and including) AppleWin v1.25.0
|
||||
{
|
||||
char szMessage[32 + MAX_PATH];
|
||||
std::string strOldImageDir;
|
||||
std::string strOldImageDir(g_sCurrentDir);
|
||||
|
||||
APPLEWIN_SNAPSHOT* pSS = (APPLEWIN_SNAPSHOT*) new char[sizeof(APPLEWIN_SNAPSHOT)];
|
||||
APPLEWIN_SNAPSHOT_v1* pSS = (APPLEWIN_SNAPSHOT_v1*) new char[sizeof(APPLEWIN_SNAPSHOT_v1)]; // throw's bad_alloc
|
||||
|
||||
try
|
||||
{
|
||||
strOldImageDir = g_sCurrentDir;
|
||||
#if _MSC_VER >= 1600 // static_assert supported from VS2010 (cl.exe v16.00)
|
||||
static_assert(kSnapshotSize_v1 == sizeof(APPLEWIN_SNAPSHOT_v1), "Save-state v1 struct size mismatch");
|
||||
#else
|
||||
// A compile error here means sizeof(APPLEWIN_SNAPSHOT_v1) is wrong, eg. one of the constituent structs has been modified
|
||||
typedef char VerifySizesAreEqual[kSnapshotSize_v1 == sizeof(APPLEWIN_SNAPSHOT_v1) ? 1 : -1];
|
||||
#endif
|
||||
|
||||
if (kSnapshotSize_v1 != sizeof(APPLEWIN_SNAPSHOT_v1))
|
||||
throw std::string("Save-state v1 struct size mismatch");
|
||||
|
||||
SetCurrentImageDir(g_strSaveStatePath.c_str()); // Allow .dsk's load without prompting
|
||||
|
||||
if(pSS == NULL)
|
||||
throw(0);
|
||||
|
||||
memset(pSS, 0, sizeof(APPLEWIN_SNAPSHOT));
|
||||
memset(pSS, 0, sizeof(APPLEWIN_SNAPSHOT_v1));
|
||||
|
||||
//
|
||||
|
||||
@@ -126,49 +144,32 @@ void Snapshot_LoadState()
|
||||
NULL);
|
||||
|
||||
if(hFile == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
strcpy(szMessage, "File not found: ");
|
||||
strcpy(szMessage + strlen(szMessage), g_strSaveStatePathname.c_str());
|
||||
throw(0);
|
||||
}
|
||||
throw std::string("File not found: ") + g_strSaveStatePathname;
|
||||
|
||||
DWORD dwBytesRead;
|
||||
BOOL bRes = ReadFile( hFile,
|
||||
pSS,
|
||||
sizeof(APPLEWIN_SNAPSHOT),
|
||||
sizeof(APPLEWIN_SNAPSHOT_v1),
|
||||
&dwBytesRead,
|
||||
NULL);
|
||||
|
||||
CloseHandle(hFile);
|
||||
|
||||
if(!bRes || (dwBytesRead != sizeof(APPLEWIN_SNAPSHOT)))
|
||||
{
|
||||
if(!bRes || (dwBytesRead != sizeof(APPLEWIN_SNAPSHOT_v1)))
|
||||
// File size wrong: probably because of version mismatch or corrupt file
|
||||
strcpy(szMessage, "File size mismatch");
|
||||
throw(0);
|
||||
}
|
||||
throw std::string("File size mismatch");
|
||||
|
||||
if(pSS->Hdr.dwTag != AW_SS_TAG)
|
||||
{
|
||||
strcpy(szMessage, "File corrupt");
|
||||
throw(0);
|
||||
}
|
||||
throw std::string("File corrupt");
|
||||
|
||||
if(pSS->Hdr.dwVersion != MAKE_VERSION(1,0,0,1))
|
||||
{
|
||||
strcpy(szMessage, "Version mismatch");
|
||||
throw(0);
|
||||
}
|
||||
throw std::string("Version mismatch");
|
||||
|
||||
// TO DO: Verify checksum
|
||||
|
||||
//
|
||||
// Reset all sub-systems
|
||||
MemReset();
|
||||
|
||||
if (!IS_APPLE2)
|
||||
MemResetPaging();
|
||||
|
||||
DiskReset();
|
||||
KeybReset();
|
||||
VideoResetState();
|
||||
@@ -178,38 +179,46 @@ void Snapshot_LoadState()
|
||||
// Apple2 unit
|
||||
//
|
||||
|
||||
CpuSetSnapshot(&pSS->Apple2Unit.CPU6502);
|
||||
sg_SSC.CommSetSnapshot(&pSS->Apple2Unit.Comms);
|
||||
JoySetSnapshot(&pSS->Apple2Unit.Joystick);
|
||||
KeybSetSnapshot(&pSS->Apple2Unit.Keyboard);
|
||||
SpkrSetSnapshot(&pSS->Apple2Unit.Speaker);
|
||||
VideoSetSnapshot(&pSS->Apple2Unit.Video);
|
||||
MemSetSnapshot(&pSS->Apple2Unit.Memory);
|
||||
SS_CPU6502& CPU = pSS->Apple2Unit.CPU6502;
|
||||
CpuSetSnapshot_v1(CPU.A, CPU.X, CPU.Y, CPU.P, CPU.S, CPU.PC, CPU.nCumulativeCycles);
|
||||
|
||||
SS_IO_Comms& SSC = pSS->Apple2Unit.Comms;
|
||||
sg_SSC.SetSnapshot_v1(SSC.baudrate, SSC.bytesize, SSC.commandbyte, SSC.comminactivity, SSC.controlbyte, SSC.parity, SSC.stopbits);
|
||||
|
||||
JoySetSnapshot_v1(pSS->Apple2Unit.Joystick.nJoyCntrResetCycle);
|
||||
KeybSetSnapshot_v1(pSS->Apple2Unit.Keyboard.nLastKey);
|
||||
SpkrSetSnapshot_v1(pSS->Apple2Unit.Speaker.nSpkrLastCycle);
|
||||
VideoSetSnapshot_v1(pSS->Apple2Unit.Video.bAltCharSet, pSS->Apple2Unit.Video.dwVidMode);
|
||||
MemSetSnapshot_v1(pSS->Apple2Unit.Memory.dwMemMode, pSS->Apple2Unit.Memory.bLastWriteRam, pSS->Apple2Unit.Memory.nMemMain, pSS->Apple2Unit.Memory.nMemAux);
|
||||
|
||||
//
|
||||
|
||||
//
|
||||
// Slot4: Mockingboard
|
||||
MB_SetSnapshot(&pSS->Mockingboard1, 4);
|
||||
MB_SetSnapshot_v1(&pSS->Mockingboard1, 4);
|
||||
|
||||
//
|
||||
// Slot5: Mockingboard
|
||||
MB_SetSnapshot(&pSS->Mockingboard2, 5);
|
||||
MB_SetSnapshot_v1(&pSS->Mockingboard2, 5);
|
||||
|
||||
//
|
||||
// Slot6: Disk][
|
||||
DiskSetSnapshot(&pSS->Disk2, 6);
|
||||
DiskSetSnapshot_v1(&pSS->Disk2);
|
||||
|
||||
SetLoadedSaveStateFlag(true);
|
||||
|
||||
MemUpdatePaging(TRUE);
|
||||
}
|
||||
catch(int)
|
||||
catch(std::string szMessage)
|
||||
{
|
||||
MessageBox( g_hFrameWindow,
|
||||
szMessage,
|
||||
szMessage.c_str(),
|
||||
TEXT("Load State"),
|
||||
MB_ICONEXCLAMATION | MB_SETFOREGROUND);
|
||||
|
||||
SetCurrentImageDir(strOldImageDir.c_str());
|
||||
|
||||
PostMessage(g_hFrameWindow, WM_USER_RESTART, 0, 0); // Power-cycle VM (undoing all the new state just loaded)
|
||||
}
|
||||
|
||||
delete [] pSS;
|
||||
@@ -217,104 +226,393 @@ void Snapshot_LoadState()
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void Snapshot_SaveState()
|
||||
static HANDLE m_hFile = INVALID_HANDLE_VALUE;
|
||||
static CConfigNeedingRestart m_ConfigNew;
|
||||
|
||||
static std::string GetSnapshotUnitApple2Name(void)
|
||||
{
|
||||
APPLEWIN_SNAPSHOT* pSS = (APPLEWIN_SNAPSHOT*) new char[sizeof(APPLEWIN_SNAPSHOT)];
|
||||
if(pSS == NULL)
|
||||
static const std::string name("Apple2");
|
||||
return name;
|
||||
}
|
||||
|
||||
static std::string GetSnapshotUnitSlotsName(void)
|
||||
{
|
||||
static const std::string name("Slots");
|
||||
return name;
|
||||
}
|
||||
|
||||
#define SS_YAML_KEY_MODEL "Model"
|
||||
|
||||
#define SS_YAML_VALUE_APPLE2 "Apple]["
|
||||
#define SS_YAML_VALUE_APPLE2PLUS "Apple][+"
|
||||
#define SS_YAML_VALUE_APPLE2E "Apple//e"
|
||||
#define SS_YAML_VALUE_APPLE2EENHANCED "Enhanced Apple//e"
|
||||
#define SS_YAML_VALUE_APPLE2C "Apple2c"
|
||||
#define SS_YAML_VALUE_PRAVETS82 "Pravets82"
|
||||
#define SS_YAML_VALUE_PRAVETS8M "Pravets8M"
|
||||
#define SS_YAML_VALUE_PRAVETS8A "Pravets8A"
|
||||
|
||||
static eApple2Type ParseApple2Type(std::string type)
|
||||
{
|
||||
if (type == SS_YAML_VALUE_APPLE2) return A2TYPE_APPLE2;
|
||||
else if (type == SS_YAML_VALUE_APPLE2PLUS) return A2TYPE_APPLE2PLUS;
|
||||
else if (type == SS_YAML_VALUE_APPLE2E) return A2TYPE_APPLE2E;
|
||||
else if (type == SS_YAML_VALUE_APPLE2EENHANCED) return A2TYPE_APPLE2EENHANCED;
|
||||
else if (type == SS_YAML_VALUE_APPLE2C) return A2TYPE_APPLE2C;
|
||||
else if (type == SS_YAML_VALUE_PRAVETS82) return A2TYPE_PRAVETS82;
|
||||
else if (type == SS_YAML_VALUE_PRAVETS8M) return A2TYPE_PRAVETS8M;
|
||||
else if (type == SS_YAML_VALUE_PRAVETS8A) return A2TYPE_PRAVETS8A;
|
||||
|
||||
throw std::string("Load: Unknown Apple2 type");
|
||||
}
|
||||
|
||||
static std::string GetApple2TypeAsString(void)
|
||||
{
|
||||
switch ( GetApple2Type() )
|
||||
{
|
||||
// To do
|
||||
return;
|
||||
case A2TYPE_APPLE2: return SS_YAML_VALUE_APPLE2;
|
||||
case A2TYPE_APPLE2PLUS: return SS_YAML_VALUE_APPLE2PLUS;
|
||||
case A2TYPE_APPLE2E: return SS_YAML_VALUE_APPLE2E;
|
||||
case A2TYPE_APPLE2EENHANCED:return SS_YAML_VALUE_APPLE2EENHANCED;
|
||||
case A2TYPE_APPLE2C: return SS_YAML_VALUE_APPLE2C;
|
||||
case A2TYPE_PRAVETS82: return SS_YAML_VALUE_PRAVETS82;
|
||||
case A2TYPE_PRAVETS8M: return SS_YAML_VALUE_PRAVETS8M;
|
||||
case A2TYPE_PRAVETS8A: return SS_YAML_VALUE_PRAVETS8A;
|
||||
default:
|
||||
throw std::string("Save: Unknown Apple2 type");
|
||||
}
|
||||
}
|
||||
|
||||
//---
|
||||
|
||||
static UINT ParseFileHdr(void)
|
||||
{
|
||||
std::string scalar;
|
||||
if (!yamlHelper.GetScalar(scalar))
|
||||
throw std::string(SS_YAML_KEY_FILEHDR ": Failed to find scalar");
|
||||
|
||||
if (scalar != SS_YAML_KEY_FILEHDR)
|
||||
throw std::string("Failed to find file header");
|
||||
|
||||
yamlHelper.GetMapStartEvent();
|
||||
|
||||
YamlLoadHelper yamlLoadHelper(yamlHelper);
|
||||
|
||||
//
|
||||
|
||||
std::string value = yamlLoadHelper.LoadString(SS_YAML_KEY_TAG);
|
||||
if (value != SS_YAML_VALUE_AWSS)
|
||||
{
|
||||
//printf("%s: Bad tag (%s) - expected %s\n", SS_YAML_KEY_FILEHDR, value.c_str(), SS_YAML_VALUE_AWSS);
|
||||
throw std::string(SS_YAML_KEY_FILEHDR ": Bad tag");
|
||||
}
|
||||
|
||||
memset(pSS, 0, sizeof(APPLEWIN_SNAPSHOT));
|
||||
return yamlLoadHelper.LoadUint(SS_YAML_KEY_VERSION);
|
||||
}
|
||||
|
||||
pSS->Hdr.dwTag = AW_SS_TAG;
|
||||
pSS->Hdr.dwVersion = MAKE_VERSION(1,0,0,1);
|
||||
pSS->Hdr.dwChecksum = 0; // TO DO
|
||||
//---
|
||||
|
||||
//
|
||||
// Apple2 unit
|
||||
//
|
||||
static void ParseUnitApple2(YamlLoadHelper& yamlLoadHelper, UINT version)
|
||||
{
|
||||
if (version != UNIT_APPLE2_VER)
|
||||
throw std::string(SS_YAML_KEY_UNIT ": Apple2: Version mismatch");
|
||||
|
||||
pSS->Apple2Unit.UnitHdr.dwLength = sizeof(SS_APPLE2_Unit);
|
||||
pSS->Apple2Unit.UnitHdr.dwVersion = MAKE_VERSION(1,0,0,0);
|
||||
std::string model = yamlLoadHelper.LoadString(SS_YAML_KEY_MODEL);
|
||||
SetApple2Type( ParseApple2Type(model) ); // NB. Sets default main CPU type
|
||||
m_ConfigNew.m_Apple2Type = GetApple2Type();
|
||||
|
||||
CpuGetSnapshot(&pSS->Apple2Unit.CPU6502);
|
||||
sg_SSC.CommGetSnapshot(&pSS->Apple2Unit.Comms);
|
||||
JoyGetSnapshot(&pSS->Apple2Unit.Joystick);
|
||||
KeybGetSnapshot(&pSS->Apple2Unit.Keyboard);
|
||||
SpkrGetSnapshot(&pSS->Apple2Unit.Speaker);
|
||||
VideoGetSnapshot(&pSS->Apple2Unit.Video);
|
||||
MemGetSnapshot(&pSS->Apple2Unit.Memory);
|
||||
CpuLoadSnapshot(yamlLoadHelper); // NB. Overrides default main CPU type
|
||||
m_ConfigNew.m_CpuType = GetMainCpu();
|
||||
|
||||
//
|
||||
// Slot1: Empty
|
||||
pSS->Empty1.Hdr.UnitHdr.dwLength = sizeof(SS_CARD_EMPTY);
|
||||
pSS->Empty1.Hdr.UnitHdr.dwVersion = MAKE_VERSION(1,0,0,0);
|
||||
pSS->Empty1.Hdr.dwSlot = 1;
|
||||
pSS->Empty1.Hdr.dwType = CT_Empty;
|
||||
JoyLoadSnapshot(yamlLoadHelper);
|
||||
KeybLoadSnapshot(yamlLoadHelper);
|
||||
SpkrLoadSnapshot(yamlLoadHelper);
|
||||
VideoLoadSnapshot(yamlLoadHelper);
|
||||
MemLoadSnapshot(yamlLoadHelper);
|
||||
}
|
||||
|
||||
//
|
||||
// Slot2: Empty
|
||||
pSS->Empty2.Hdr.UnitHdr.dwLength = sizeof(SS_CARD_EMPTY);
|
||||
pSS->Empty2.Hdr.UnitHdr.dwVersion = MAKE_VERSION(1,0,0,0);
|
||||
pSS->Empty2.Hdr.dwSlot = 2;
|
||||
pSS->Empty2.Hdr.dwType = CT_Empty;
|
||||
//---
|
||||
|
||||
//
|
||||
// Slot3: Empty
|
||||
pSS->Empty3.Hdr.UnitHdr.dwLength = sizeof(SS_CARD_EMPTY);
|
||||
pSS->Empty3.Hdr.UnitHdr.dwVersion = MAKE_VERSION(1,0,0,0);
|
||||
pSS->Empty3.Hdr.dwSlot = 3;
|
||||
pSS->Empty3.Hdr.dwType = CT_Empty;
|
||||
static void ParseSlots(YamlLoadHelper& yamlLoadHelper, UINT version)
|
||||
{
|
||||
if (version != UNIT_SLOTS_VER)
|
||||
throw std::string(SS_YAML_KEY_UNIT ": Slots: Version mismatch");
|
||||
|
||||
//
|
||||
// Slot4: Mockingboard
|
||||
MB_GetSnapshot(&pSS->Mockingboard1, 4);
|
||||
|
||||
//
|
||||
// Slot5: Mockingboard
|
||||
MB_GetSnapshot(&pSS->Mockingboard2, 5);
|
||||
|
||||
//
|
||||
// Slot6: Disk][
|
||||
DiskGetSnapshot(&pSS->Disk2, 6);
|
||||
|
||||
//
|
||||
|
||||
HANDLE hFile = CreateFile( g_strSaveStatePathname.c_str(),
|
||||
GENERIC_WRITE,
|
||||
0,
|
||||
NULL,
|
||||
CREATE_ALWAYS,
|
||||
FILE_ATTRIBUTE_NORMAL,
|
||||
NULL);
|
||||
|
||||
DWORD dwError = GetLastError();
|
||||
_ASSERT((dwError == 0) || (dwError == ERROR_ALREADY_EXISTS));
|
||||
|
||||
if(hFile != INVALID_HANDLE_VALUE)
|
||||
while (1)
|
||||
{
|
||||
DWORD dwBytesWritten;
|
||||
BOOL bRes = WriteFile( hFile,
|
||||
pSS,
|
||||
sizeof(APPLEWIN_SNAPSHOT),
|
||||
&dwBytesWritten,
|
||||
NULL);
|
||||
std::string scalar = yamlLoadHelper.GetMapNextSlotNumber();
|
||||
if (scalar.empty())
|
||||
break; // done all slots
|
||||
|
||||
if(!bRes || (dwBytesWritten != sizeof(APPLEWIN_SNAPSHOT)))
|
||||
dwError = GetLastError();
|
||||
const int slot = strtoul(scalar.c_str(), NULL, 10); // NB. aux slot supported as a different "unit"
|
||||
if (slot < 1 || slot > 7)
|
||||
throw std::string("Slots: Invalid slot #: ") + scalar;
|
||||
|
||||
CloseHandle(hFile);
|
||||
yamlLoadHelper.GetSubMap(scalar);
|
||||
|
||||
std::string card = yamlLoadHelper.LoadString(SS_YAML_KEY_CARD);
|
||||
UINT version = yamlLoadHelper.LoadUint(SS_YAML_KEY_VERSION);
|
||||
|
||||
if (!yamlLoadHelper.GetSubMap(std::string(SS_YAML_KEY_STATE)))
|
||||
throw std::string(SS_YAML_KEY_UNIT ": Expected sub-map name: " SS_YAML_KEY_STATE);
|
||||
|
||||
bool bIsCardSupported = true;
|
||||
SS_CARDTYPE type = CT_Empty;
|
||||
bool bRes = false;
|
||||
|
||||
if (card == Printer_GetSnapshotCardName())
|
||||
{
|
||||
bRes = Printer_LoadSnapshot(yamlLoadHelper, slot, version);
|
||||
type = CT_GenericPrinter;
|
||||
}
|
||||
else if (card == sg_SSC.GetSnapshotCardName())
|
||||
{
|
||||
bRes = sg_SSC.LoadSnapshot(yamlLoadHelper, slot, version);
|
||||
type = CT_SSC;
|
||||
}
|
||||
else if (card == sg_Mouse.GetSnapshotCardName())
|
||||
{
|
||||
bRes = sg_Mouse.LoadSnapshot(yamlLoadHelper, slot, version);
|
||||
type = CT_MouseInterface;
|
||||
}
|
||||
else if (card == Z80_GetSnapshotCardName())
|
||||
{
|
||||
bRes = Z80_LoadSnapshot(yamlLoadHelper, slot, version);
|
||||
type = CT_Z80;
|
||||
}
|
||||
else if (card == MB_GetSnapshotCardName())
|
||||
{
|
||||
bRes = MB_LoadSnapshot(yamlLoadHelper, slot, version);
|
||||
type = CT_MockingboardC;
|
||||
}
|
||||
else if (card == Phasor_GetSnapshotCardName())
|
||||
{
|
||||
bRes = Phasor_LoadSnapshot(yamlLoadHelper, slot, version);
|
||||
type = CT_Phasor;
|
||||
}
|
||||
else if (card == DiskGetSnapshotCardName())
|
||||
{
|
||||
bRes = DiskLoadSnapshot(yamlLoadHelper, slot, version);
|
||||
type = CT_Disk2;
|
||||
}
|
||||
else if (card == HD_GetSnapshotCardName())
|
||||
{
|
||||
bRes = HD_LoadSnapshot(yamlLoadHelper, slot, version, g_strSaveStatePath);
|
||||
m_ConfigNew.m_bEnableHDD = true;
|
||||
type = CT_GenericHDD;
|
||||
}
|
||||
else
|
||||
{
|
||||
bIsCardSupported = false;
|
||||
throw std::string("Slots: Unknown card: " + card); // todo: don't throw - just ignore & continue
|
||||
}
|
||||
|
||||
if (bRes && bIsCardSupported)
|
||||
{
|
||||
m_ConfigNew.m_Slot[slot] = type;
|
||||
}
|
||||
|
||||
yamlLoadHelper.PopMap();
|
||||
yamlLoadHelper.PopMap();
|
||||
}
|
||||
}
|
||||
|
||||
//---
|
||||
|
||||
static void ParseUnit(void)
|
||||
{
|
||||
yamlHelper.GetMapStartEvent();
|
||||
|
||||
YamlLoadHelper yamlLoadHelper(yamlHelper);
|
||||
|
||||
std::string unit = yamlLoadHelper.LoadString(SS_YAML_KEY_TYPE);
|
||||
UINT version = yamlLoadHelper.LoadUint(SS_YAML_KEY_VERSION);
|
||||
|
||||
if (!yamlLoadHelper.GetSubMap(std::string(SS_YAML_KEY_STATE)))
|
||||
throw std::string(SS_YAML_KEY_UNIT ": Expected sub-map name: " SS_YAML_KEY_STATE);
|
||||
|
||||
if (unit == GetSnapshotUnitApple2Name())
|
||||
{
|
||||
ParseUnitApple2(yamlLoadHelper, version);
|
||||
}
|
||||
else if (unit == MemGetSnapshotUnitAuxSlotName())
|
||||
{
|
||||
MemLoadSnapshotAux(yamlLoadHelper, version);
|
||||
}
|
||||
else if (unit == GetSnapshotUnitSlotsName())
|
||||
{
|
||||
ParseSlots(yamlLoadHelper, version);
|
||||
}
|
||||
else
|
||||
{
|
||||
dwError = GetLastError();
|
||||
throw std::string(SS_YAML_KEY_UNIT ": Unknown type: " ) + unit;
|
||||
}
|
||||
}
|
||||
|
||||
static void Snapshot_LoadState_v2(void)
|
||||
{
|
||||
try
|
||||
{
|
||||
int res = yamlHelper.InitParser( g_strSaveStatePathname.c_str() );
|
||||
if (!res)
|
||||
throw std::string("Failed to initialize parser or open file"); // TODO: disambiguate
|
||||
|
||||
UINT version = ParseFileHdr();
|
||||
if (version != SS_FILE_VER)
|
||||
throw std::string("Version mismatch");
|
||||
|
||||
//
|
||||
|
||||
CConfigNeedingRestart ConfigOld;
|
||||
ConfigOld.m_Slot[1] = CT_GenericPrinter; // fixme
|
||||
ConfigOld.m_Slot[2] = CT_SSC; // fixme
|
||||
//ConfigOld.m_Slot[3] = CT_Uthernet; // todo
|
||||
ConfigOld.m_Slot[6] = CT_Disk2; // fixme
|
||||
ConfigOld.m_Slot[7] = ConfigOld.m_bEnableHDD ? CT_GenericHDD : CT_Empty; // fixme
|
||||
//ConfigOld.m_SlotAux = ?; // fixme
|
||||
|
||||
for (UINT i=0; i<NUM_SLOTS; i++)
|
||||
m_ConfigNew.m_Slot[i] = CT_Empty;
|
||||
m_ConfigNew.m_SlotAux = CT_Empty;
|
||||
m_ConfigNew.m_bEnableHDD = false;
|
||||
//m_ConfigNew.m_bEnableTheFreezesF8Rom = ?; // todo: when support saving config
|
||||
//m_ConfigNew.m_bEnhanceDisk = ?; // todo: when support saving config
|
||||
|
||||
MemReset();
|
||||
PravetsReset();
|
||||
DiskReset();
|
||||
KeybReset();
|
||||
VideoResetState();
|
||||
MB_Reset();
|
||||
#ifdef USE_SPEECH_API
|
||||
g_Speech.Reset();
|
||||
#endif
|
||||
sg_Mouse.Uninitialize();
|
||||
sg_Mouse.Reset();
|
||||
HD_SetEnabled(false);
|
||||
|
||||
std::string scalar;
|
||||
while(yamlHelper.GetScalar(scalar))
|
||||
{
|
||||
if (scalar == SS_YAML_KEY_UNIT)
|
||||
ParseUnit();
|
||||
else
|
||||
throw std::string("Unknown top-level scalar: " + scalar);
|
||||
}
|
||||
|
||||
SetLoadedSaveStateFlag(true);
|
||||
|
||||
// NB. The following disparity should be resolved:
|
||||
// . A change in h/w via the Configuration property sheets results in a the VM completely restarting (via WM_USER_RESTART)
|
||||
// . A change in h/w via loading a save-state avoids this VM restart
|
||||
// The latter is the desired approach (as the former needs a "power-on" / F2 to start things again)
|
||||
|
||||
sg_PropertySheet.ApplyNewConfig(m_ConfigNew, ConfigOld);
|
||||
|
||||
MemInitializeROM();
|
||||
MemInitializeCustomF8ROM();
|
||||
MemInitializeIO();
|
||||
|
||||
MemUpdatePaging(TRUE);
|
||||
|
||||
// g_Apple2Type may've changed: so redraw frame (title, buttons, leds, etc)
|
||||
SetCharsetType();
|
||||
VideoReinitialize(); // g_CharsetType changed
|
||||
FrameUpdateApple2Type();
|
||||
}
|
||||
catch(std::string szMessage)
|
||||
{
|
||||
MessageBox( g_hFrameWindow,
|
||||
szMessage.c_str(),
|
||||
TEXT("Load State"),
|
||||
MB_ICONEXCLAMATION | MB_SETFOREGROUND);
|
||||
|
||||
PostMessage(g_hFrameWindow, WM_USER_RESTART, 0, 0); // Power-cycle VM (undoing all the new state just loaded)
|
||||
}
|
||||
|
||||
_ASSERT((dwError == 0) || (dwError == ERROR_ALREADY_EXISTS));
|
||||
yamlHelper.FinaliseParser();
|
||||
}
|
||||
|
||||
delete [] pSS;
|
||||
void Snapshot_LoadState()
|
||||
{
|
||||
const std::string ext_aws = (".aws");
|
||||
const size_t pos = g_strSaveStatePathname.size() - ext_aws.size();
|
||||
if (g_strSaveStatePathname.find(ext_aws, pos) != std::string::npos) // find ".aws" at end of pathname
|
||||
{
|
||||
Snapshot_LoadState_v1();
|
||||
return;
|
||||
}
|
||||
|
||||
Snapshot_LoadState_v2();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// todo:
|
||||
// . Uthernet card
|
||||
|
||||
void Snapshot_SaveState(void)
|
||||
{
|
||||
try
|
||||
{
|
||||
YamlSaveHelper yamlSaveHelper(g_strSaveStatePathname);
|
||||
yamlSaveHelper.FileHdr(SS_FILE_VER);
|
||||
|
||||
// Unit: Apple2
|
||||
{
|
||||
yamlSaveHelper.UnitHdr(GetSnapshotUnitApple2Name(), UNIT_APPLE2_VER);
|
||||
YamlSaveHelper::Label state(yamlSaveHelper, "%s:\n", SS_YAML_KEY_STATE);
|
||||
|
||||
yamlSaveHelper.Save("%s: %s\n", SS_YAML_KEY_MODEL, GetApple2TypeAsString().c_str());
|
||||
CpuSaveSnapshot(yamlSaveHelper);
|
||||
JoySaveSnapshot(yamlSaveHelper);
|
||||
KeybSaveSnapshot(yamlSaveHelper);
|
||||
SpkrSaveSnapshot(yamlSaveHelper);
|
||||
VideoSaveSnapshot(yamlSaveHelper);
|
||||
MemSaveSnapshot(yamlSaveHelper);
|
||||
}
|
||||
|
||||
// Unit: Aux slot
|
||||
MemSaveSnapshotAux(yamlSaveHelper);
|
||||
|
||||
// Unit: Slots
|
||||
{
|
||||
yamlSaveHelper.UnitHdr(GetSnapshotUnitSlotsName(), UNIT_SLOTS_VER);
|
||||
YamlSaveHelper::Label state(yamlSaveHelper, "%s:\n", SS_YAML_KEY_STATE);
|
||||
|
||||
Printer_SaveSnapshot(yamlSaveHelper);
|
||||
|
||||
sg_SSC.SaveSnapshot(yamlSaveHelper);
|
||||
|
||||
sg_Mouse.SaveSnapshot(yamlSaveHelper);
|
||||
|
||||
if (g_Slot4 == CT_Z80)
|
||||
Z80_SaveSnapshot(yamlSaveHelper, 4);
|
||||
|
||||
if (g_Slot5 == CT_Z80)
|
||||
Z80_SaveSnapshot(yamlSaveHelper, 5);
|
||||
|
||||
if (g_Slot4 == CT_MockingboardC)
|
||||
MB_SaveSnapshot(yamlSaveHelper, 4);
|
||||
|
||||
if (g_Slot5 == CT_MockingboardC)
|
||||
MB_SaveSnapshot(yamlSaveHelper, 5);
|
||||
|
||||
if (g_Slot4 == CT_Phasor)
|
||||
Phasor_SaveSnapshot(yamlSaveHelper, 4);
|
||||
|
||||
DiskSaveSnapshot(yamlSaveHelper);
|
||||
|
||||
HD_SaveSnapshot(yamlSaveHelper);
|
||||
}
|
||||
}
|
||||
catch(std::string szMessage)
|
||||
{
|
||||
MessageBox( g_hFrameWindow,
|
||||
szMessage.c_str(),
|
||||
TEXT("Save State"),
|
||||
MB_ICONEXCLAMATION | MB_SETFOREGROUND);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user