From 2f4ee9466f15f3522123d9016f32d716401741b4 Mon Sep 17 00:00:00 2001 From: tomcw Date: Fri, 21 Aug 2015 21:45:21 +0100 Subject: [PATCH] Save-state: . add ConfirmReboot . Restore saved configuration . Moved some config to Joystick & SerialCard . save config --- source/Applewin.cpp | 28 +++++-- source/Applewin.h | 2 +- source/Configuration/PageInput.cpp | 10 +-- source/Joystick.cpp | 36 +++++++- source/Joystick.h | 8 +- source/SaveState.cpp | 128 +++++++++++++++++++++++++---- source/SaveState_Structs_common.h | 1 + source/SaveState_Structs_v2.h | 18 ++-- source/SerialComms.cpp | 6 ++ 9 files changed, 192 insertions(+), 45 deletions(-) diff --git a/source/Applewin.cpp b/source/Applewin.cpp index e35f8b0d..7ff05ccf 100644 --- a/source/Applewin.cpp +++ b/source/Applewin.cpp @@ -56,6 +56,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include "Configuration\PropertySheet.h" #include "Tfe\Tfe.h" +static UINT16 g_AppleWinVersion[4] = {0}; char VERSIONSTRING[16] = "xx.yy.zz.ww"; TCHAR *g_pAppTitle = TITLE_APPLE_2E_ENHANCED; @@ -110,6 +111,11 @@ CSpeech g_Speech; //=========================================================================== +const UINT16* GetAppleWinVersion(void) +{ + return &g_AppleWinVersion[0]; +} + bool GetLoadedSaveStateFlag(void) { return g_bLoadedSaveState; @@ -366,7 +372,7 @@ static void LoadConfigOldJoystick(const UINT uJoyNum) break; } - joytype[uJoyNum] = uNewJoyType; + JoySetJoyType(uJoyNum, uNewJoyType); } //Reads configuration from the registry entries @@ -407,9 +413,15 @@ void LoadConfiguration(void) // - if (!REGLOAD(TEXT(REGVALUE_JOYSTICK0_EMU_TYPE), &joytype[JN_JOYSTICK0])) + DWORD dwJoyType; + if (REGLOAD(TEXT(REGVALUE_JOYSTICK0_EMU_TYPE), &dwJoyType)) + JoySetJoyType(JN_JOYSTICK0, dwJoyType); + else LoadConfigOldJoystick(JN_JOYSTICK0); - if (!REGLOAD(TEXT(REGVALUE_JOYSTICK1_EMU_TYPE), &joytype[JN_JOYSTICK1])) + + if (REGLOAD(TEXT(REGVALUE_JOYSTICK1_EMU_TYPE), &dwJoyType)) + JoySetJoyType(JN_JOYSTICK1, dwJoyType); + else LoadConfigOldJoystick(JN_JOYSTICK1); REGLOAD(TEXT("Sound Emulation") ,&soundtype); @@ -898,11 +910,11 @@ int APIENTRY WinMain(HINSTANCE passinstance, HINSTANCE, LPSTR lpCmdLine, int) // Construct version string from fixed file info block - unsigned long major = pFixedFileInfo->dwFileVersionMS >> 16; - unsigned long minor = pFixedFileInfo->dwFileVersionMS & 0xffff; - unsigned long fix = pFixedFileInfo->dwFileVersionLS >> 16; - unsigned long fix_minor = pFixedFileInfo->dwFileVersionLS & 0xffff; - sprintf(VERSIONSTRING, "%d.%d.%d.%d", major, minor, fix, fix_minor); // potential buffer overflow + unsigned long major = g_AppleWinVersion[0] = pFixedFileInfo->dwFileVersionMS >> 16; + unsigned long minor = g_AppleWinVersion[1] = pFixedFileInfo->dwFileVersionMS & 0xffff; + unsigned long fix = g_AppleWinVersion[2] = pFixedFileInfo->dwFileVersionLS >> 16; + unsigned long fix_minor = g_AppleWinVersion[3] = pFixedFileInfo->dwFileVersionLS & 0xffff; + sprintf(VERSIONSTRING, "%d.%d.%d.%d", major, minor, fix, fix_minor); // potential buffer overflow } } diff --git a/source/Applewin.h b/source/Applewin.h index 933a1752..a8313335 100644 --- a/source/Applewin.h +++ b/source/Applewin.h @@ -6,7 +6,7 @@ void SetCurrentCLK6502(); void SetCurrentImageDir(const char* pszImageDir); - +extern const UINT16* GetAppleWinVersion(void); extern char VERSIONSTRING[]; // Constructed in WinMain() extern TCHAR *g_pAppTitle; diff --git a/source/Configuration/PageInput.cpp b/source/Configuration/PageInput.cpp index 940b9978..7bd0a20b 100644 --- a/source/Configuration/PageInput.cpp +++ b/source/Configuration/PageInput.cpp @@ -214,12 +214,12 @@ void CPageInput::DlgOK(HWND hWnd) if (JoySetEmulationType(hWnd, m_nJoy0ChoiceTranlationTbl[uNewJoyType0], JN_JOYSTICK0, bIsSlot4Mouse)) { - REGSAVE(TEXT(REGVALUE_JOYSTICK0_EMU_TYPE), joytype[0]); + REGSAVE(TEXT(REGVALUE_JOYSTICK0_EMU_TYPE), JoyGetJoyType(0)); } if (JoySetEmulationType(hWnd, m_nJoy1ChoiceTranlationTbl[uNewJoyType1], JN_JOYSTICK1, bIsSlot4Mouse)) { - REGSAVE(TEXT(REGVALUE_JOYSTICK1_EMU_TYPE), joytype[1]); + REGSAVE(TEXT(REGVALUE_JOYSTICK1_EMU_TYPE), JoyGetJoyType(1)); } JoySetTrim((short)SendDlgItemMessage(hWnd, IDC_SPIN_XTRIM, UDM_GETPOS, 0, 0), true); @@ -305,7 +305,7 @@ void CPageInput::InitJoystickChoices(HWND hWnd, int nJoyNum, int nIdcValue) for(UINT i=nJC_KEYBD_CURSORS; i JN_JOYSTICK1) + return; + + joytype[num] = type; + + // Refresh centre positions whenever 'joytype' changes + JoySetTrim(JoyGetTrim(true) , true); + JoySetTrim(JoyGetTrim(false), false); +} + +DWORD JoyGetJoyType(UINT num) +{ + _ASSERT(num <= JN_JOYSTICK1); + if (num > JN_JOYSTICK1) + return J0C_DISABLED; + + return joytype[num]; +} + +//=========================================================================== + void JoySetTrim(short nValue, bool bAxisX) { if(bAxisX) @@ -831,12 +855,18 @@ void JoySetSnapshot_v1(const unsigned __int64 JoyCntrResetCycle) // -void JoyGetSnapshot(unsigned __int64& rJoyCntrResetCycle) +void JoyGetSnapshot(unsigned __int64& rJoyCntrResetCycle, short* pJoystick0Trim, short* pJoystick1Trim) { rJoyCntrResetCycle = g_nJoyCntrResetCycle; + pJoystick0Trim[0] = JoyGetTrim(true); + pJoystick0Trim[1] = JoyGetTrim(false); + pJoystick1Trim[0] = 0; // TBD: not implemented yet + pJoystick1Trim[1] = 0; // TBD: not implemented yet } -void JoySetSnapshot(const unsigned __int64 JoyCntrResetCycle) +void JoySetSnapshot(const unsigned __int64 JoyCntrResetCycle, const short* pJoystick0Trim, const short* pJoystick1Trim) { g_nJoyCntrResetCycle = JoyCntrResetCycle; + JoySetTrim(pJoystick0Trim[0], true); + JoySetTrim(pJoystick0Trim[1], false); } diff --git a/source/Joystick.h b/source/Joystick.h index f4dfba56..6c718088 100644 --- a/source/Joystick.h +++ b/source/Joystick.h @@ -5,8 +5,6 @@ enum JOYNUM {JN_JOYSTICK0=0, JN_JOYSTICK1}; enum JOY0CHOICE {J0C_DISABLED=0, J0C_JOYSTICK1, J0C_KEYBD_CURSORS, J0C_KEYBD_NUMPAD, J0C_MOUSE, J0C_MAX}; enum JOY1CHOICE {J1C_DISABLED=0, J1C_JOYSTICK2, J1C_KEYBD_CURSORS, J1C_KEYBD_NUMPAD, J1C_MOUSE, J1C_MAX}; -extern DWORD joytype[2]; - enum {JOYSTICK_MODE_FLOATING=0, JOYSTICK_MODE_CENTERING}; // Joystick centering control void JoyInitialize(); @@ -21,12 +19,14 @@ BOOL JoyUsingKeyboard(); BOOL JoyUsingKeyboardCursors(); BOOL JoyUsingKeyboardNumpad(); void JoyDisableUsingMouse(); +void JoySetJoyType(UINT num, DWORD type); +DWORD JoyGetJoyType(UINT num); void JoySetTrim(short nValue, bool bAxisX); short JoyGetTrim(bool bAxisX); void JoyportControl(const UINT uControl); void JoySetSnapshot_v1(const unsigned __int64 JoyCntrResetCycle); -void JoyGetSnapshot(unsigned __int64& rJoyCntrResetCycle); -void JoySetSnapshot(const unsigned __int64 JoyCntrResetCycle); +void JoyGetSnapshot(unsigned __int64& rJoyCntrResetCycle, short* pJoystick0Trim, short* pJoystick1Trim); +void JoySetSnapshot(const unsigned __int64 JoyCntrResetCycle, const short* pJoystick0Trim, const short* pJoystick1Trim); BYTE __stdcall JoyReadButton(WORD pc, WORD addr, BYTE bWrite, BYTE d, ULONG nCyclesLeft); BYTE __stdcall JoyReadPosition(WORD pc, WORD addr, BYTE bWrite, BYTE d, ULONG nCyclesLeft); diff --git a/source/SaveState.cpp b/source/SaveState.cpp index fdc0b7c7..e14d0eb3 100644 --- a/source/SaveState.cpp +++ b/source/SaveState.cpp @@ -291,7 +291,7 @@ static void LoadUnitApple2(DWORD Length, DWORD Version) m_ConfigNew.m_Apple2Type = g_Apple2Type; CpuSetSnapshot(Apple2Unit.CPU6502); - JoySetSnapshot(Apple2Unit.Joystick.JoyCntrResetCycle); + JoySetSnapshot(Apple2Unit.Joystick.JoyCntrResetCycle, &Apple2Unit.Joystick.Joystick0Trim[0], &Apple2Unit.Joystick.Joystick1Trim[0]); KeybSetSnapshot(Apple2Unit.Keyboard.LastKey); SpkrSetSnapshot(Apple2Unit.Speaker.SpkrLastCycle); VideoSetSnapshot(Apple2Unit.Video); @@ -428,23 +428,22 @@ static void LoadUnitCard(DWORD Length, DWORD Version) } } -#if 0 static void LoadUnitConfig(DWORD Length, DWORD Version) { - SS_APPLEWIN_CONFIG Cfg; + SS_APPLEWIN_CONFIG Config; if (Version != UNIT_CONFIG_VER) throw std::string("Config: Version mismatch"); - if (Length != sizeof(Cfg)) + if (Length != sizeof(Config)) throw std::string("Config: Length mismatch"); - if (SetFilePointer(m_hFile, -(LONG)sizeof(Cfg.UnitHdr), NULL, FILE_CURRENT) == INVALID_SET_FILE_POINTER) + if (SetFilePointer(m_hFile, -(LONG)sizeof(Config.UnitHdr), NULL, FILE_CURRENT) == INVALID_SET_FILE_POINTER) throw std::string("Config: file corrupt"); DWORD dwBytesRead; BOOL bRes = ReadFile( m_hFile, - &Cfg, + &Config, Length, &dwBytesRead, NULL); @@ -452,10 +451,38 @@ static void LoadUnitConfig(DWORD Length, DWORD Version) if (dwBytesRead != Length) throw std::string("Config: file corrupt"); - // todo: - //m_ConfigNew.m_bEnhanceDisk; + // Restore all config state + + //Config.Cfg.AppleWinVersion // Nothing to do + g_eVideoType = Config.Cfg.VideoMode; + g_uHalfScanLines = Config.Cfg.IsHalfScanLines; + g_bConfirmReboot = Config.Cfg.IsConfirmReboot; + monochrome = Config.Cfg.MonochromeColor; + SetViewportScale(Config.Cfg.WindowScale); + + g_dwSpeed = Config.Cfg.CpuSpeed; + SetCurrentCLK6502(); + + JoySetJoyType(JN_JOYSTICK0, Config.Cfg.JoystickType[0]); + JoySetJoyType(JN_JOYSTICK1, Config.Cfg.JoystickType[1]); + sg_PropertySheet.SetJoystickCursorControl(Config.Cfg.IsAllowCursorsToBeRead); + sg_PropertySheet.SetAutofire(Config.Cfg.IsAutofire); + sg_PropertySheet.SetJoystickCenteringControl(Config.Cfg.IsKeyboardAutocentering); + //Config.Cfg.IsSwapButton0and1; // TBD: not implemented yet + sg_PropertySheet.SetScrollLockToggle(Config.Cfg.IsScrollLockToggle); + sg_PropertySheet.SetMouseShowCrosshair(Config.Cfg.IsMouseShowCrosshair); + sg_PropertySheet.SetMouseRestrictToWindow(Config.Cfg.IsMouseRestrictToWindow); + + soundtype = Config.Cfg.SoundType; + SpkrSetVolume(Config.Cfg.SpeakerVolume, sg_PropertySheet.GetVolumeMax()); + MB_SetVolume(Config.Cfg.MockingboardVolume, sg_PropertySheet.GetVolumeMax()); + + enhancedisk = Config.Cfg.IsEnhancedDiskSpeed; + g_bSaveStateOnExit = Config.Cfg.IsSaveStateOnExit ? true : false; + + g_bPrinterAppend = Config.Cfg.IsAppendToFile ? true : false; + sg_PropertySheet.SetTheFreezesF8Rom(Config.Cfg.IsUsingFreezesF8Rom); } -#endif static void Snapshot_LoadState_v2(DWORD dwVersion) { @@ -467,6 +494,7 @@ static void Snapshot_LoadState_v2(DWORD dwVersion) 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 @@ -515,11 +543,9 @@ static void Snapshot_LoadState_v2(DWORD dwVersion) case UT_Card: LoadUnitCard(UnitHdr.hdr.v2.Length, UnitHdr.hdr.v2.Version); break; -#if 0 case UT_Config: LoadUnitConfig(UnitHdr.hdr.v2.Length, UnitHdr.hdr.v2.Version); break; -#endif default: // Log then skip unsupported unit type break; @@ -577,22 +603,84 @@ void Snapshot_LoadState() //----------------------------------------------------------------------------- +// todo: +// . "Uthernet Active" + +static void SaveUnitConfig() +{ + SS_APPLEWIN_CONFIG Config; + memset(&Config, 0, sizeof(Config)); + + Config.UnitHdr.hdr.v2.Length = sizeof(Config); + Config.UnitHdr.hdr.v2.Type = UT_Config; + Config.UnitHdr.hdr.v2.Version = UNIT_CONFIG_VER; + + // + + memcpy(Config.Cfg.AppleWinVersion, GetAppleWinVersion(), sizeof(Config.Cfg.AppleWinVersion)); + Config.Cfg.VideoMode = g_eVideoType; + Config.Cfg.IsHalfScanLines = g_uHalfScanLines; + Config.Cfg.IsConfirmReboot = g_bConfirmReboot; + Config.Cfg.MonochromeColor = monochrome; + Config.Cfg.WindowScale = GetViewportScale(); + Config.Cfg.CpuSpeed = g_dwSpeed; + + Config.Cfg.JoystickType[0] = JoyGetJoyType(JN_JOYSTICK0); + Config.Cfg.JoystickType[1] = JoyGetJoyType(JN_JOYSTICK1); + Config.Cfg.IsAllowCursorsToBeRead = sg_PropertySheet.GetJoystickCursorControl(); + Config.Cfg.IsAutofire = (sg_PropertySheet.GetAutofire(1)<<1) | sg_PropertySheet.GetAutofire(0); + Config.Cfg.IsKeyboardAutocentering = sg_PropertySheet.GetJoystickCenteringControl(); + Config.Cfg.IsSwapButton0and1 = 0; // TBD: not implemented yet + Config.Cfg.IsScrollLockToggle = sg_PropertySheet.GetScrollLockToggle(); + Config.Cfg.IsMouseShowCrosshair = sg_PropertySheet.GetMouseShowCrosshair(); + Config.Cfg.IsMouseRestrictToWindow = sg_PropertySheet.GetMouseRestrictToWindow(); + + Config.Cfg.SoundType = soundtype; + Config.Cfg.SpeakerVolume = SpkrGetVolume(); + Config.Cfg.MockingboardVolume = MB_GetVolume(); + + Config.Cfg.IsEnhancedDiskSpeed = enhancedisk; + Config.Cfg.IsSaveStateOnExit = g_bSaveStateOnExit; + + Config.Cfg.IsAppendToFile = g_bPrinterAppend; + Config.Cfg.IsUsingFreezesF8Rom = sg_PropertySheet.GetTheFreezesF8Rom(); + + // + + DWORD dwBytesWritten; + BOOL bRes = WriteFile( m_hFile, + &Config, + Config.UnitHdr.hdr.v2.Length, + &dwBytesWritten, + NULL); + + if(!bRes || (dwBytesWritten != Config.UnitHdr.hdr.v2.Length)) + { + //dwError = GetLastError(); + throw std::string("Save error: Config"); + } +} + +// todo: +// . Uthernet card + void Snapshot_SaveState() { try { m_hFile = CreateFile( g_strSaveStatePathname.c_str(), - GENERIC_WRITE, - 0, - NULL, - CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); + GENERIC_WRITE, + 0, + NULL, + CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); DWORD dwError = GetLastError(); _ASSERT((dwError == 0) || (dwError == ERROR_ALREADY_EXISTS)); // todo: handle ERROR_ALREADY_EXISTS - ask if user wants to replace existing file + // - at this point any old file will have been truncated to zero if(m_hFile == INVALID_HANDLE_VALUE) { @@ -621,7 +709,7 @@ void Snapshot_SaveState() Apple2Unit.Apple2Type = g_Apple2Type; CpuGetSnapshot(Apple2Unit.CPU6502); - JoyGetSnapshot(Apple2Unit.Joystick.JoyCntrResetCycle); + JoyGetSnapshot(Apple2Unit.Joystick.JoyCntrResetCycle, &Apple2Unit.Joystick.Joystick0Trim[0], &Apple2Unit.Joystick.Joystick1Trim[0]); KeybGetSnapshot(Apple2Unit.Keyboard.LastKey); SpkrGetSnapshot(Apple2Unit.Speaker.SpkrLastCycle); VideoGetSnapshot(Apple2Unit.Video); @@ -668,6 +756,10 @@ void Snapshot_SaveState() DiskGetSnapshot(m_hFile); HD_GetSnapshot(m_hFile); + + // + + SaveUnitConfig(); } catch(std::string szMessage) { diff --git a/source/SaveState_Structs_common.h b/source/SaveState_Structs_common.h index 61922d98..93ba181a 100644 --- a/source/SaveState_Structs_common.h +++ b/source/SaveState_Structs_common.h @@ -73,6 +73,7 @@ enum SS_CARDTYPE CT_80Col, // 80 column card (no memory) CT_Extended80Col, // Extended 80-col card (64K) CT_RamWorksIII, // RamWorksIII (up to 8MB) + CT_Uthernet, }; ///////////////////////////////////////////////////////////////////////////////// diff --git a/source/SaveState_Structs_v2.h b/source/SaveState_Structs_v2.h index 22a0eb2c..ed14b1b8 100644 --- a/source/SaveState_Structs_v2.h +++ b/source/SaveState_Structs_v2.h @@ -27,6 +27,8 @@ struct SS_CPU6502_v2 struct SS_IO_Joystick_v2 { unsigned __int64 JoyCntrResetCycle; + short Joystick0Trim[2]; // [x,y] + short Joystick1Trim[2]; // [x,y] }; struct SS_IO_Keyboard_v2 @@ -90,27 +92,31 @@ struct APPLEWIN_SNAPSHOT_v2 struct SS_AW_CFG { - UINT32 AppleWinVersion; + UINT16 AppleWinVersion[4]; // major,minor,fix,fix_minor UINT32 VideoMode; + UINT32 IsHalfScanLines; + UINT32 IsConfirmReboot; UINT32 MonochromeColor; - float ClockFreqMHz; + UINT32 WindowScale; + UINT32 CpuSpeed; // UINT32 JoystickType[2]; - UINT32 JoystickTrim[2]; UINT32 IsAllowCursorsToBeRead; UINT32 IsAutofire; UINT32 IsKeyboardAutocentering; UINT32 IsSwapButton0and1; + UINT32 IsScrollLockToggle; + UINT32 IsMouseShowCrosshair; + UINT32 IsMouseRestrictToWindow; // + UINT32 SoundType; UINT32 SpeakerVolume; UINT32 MockingboardVolume; // UINT32 IsEnhancedDiskSpeed; + UINT32 IsSaveStateOnExit; // - UINT32 IsEncodingConversionForClones; - UINT32 IsFilterUnprintableChars; UINT32 IsAppendToFile; - UINT32 TerminatePrintingAfterIdleSecs; UINT32 IsUsingFreezesF8Rom; }; diff --git a/source/SerialComms.cpp b/source/SerialComms.cpp index 041a9fca..167c37d4 100644 --- a/source/SerialComms.cpp +++ b/source/SerialComms.cpp @@ -1340,6 +1340,8 @@ struct SSC_Unit bool vbRxIrqPending; bool bWrittenTx; + + char SerialPortName[8]; }; struct SS_CARD_SSC @@ -1376,6 +1378,8 @@ void CSuperSerialCard::GetSnapshot(const HANDLE hFile) Unit.vbRxIrqPending = m_vbRxIrqPending; Unit.bWrittenTx = m_bWrittenTx; + strncpy_s(Unit.SerialPortName, sizeof(Unit.SerialPortName), GetSerialPortName(), _TRUNCATE); + // DWORD dwBytesWritten; @@ -1428,4 +1432,6 @@ void CSuperSerialCard::SetSnapshot(const HANDLE hFile) m_vbTxIrqPending = Unit.vbTxIrqPending; m_vbRxIrqPending = Unit.vbRxIrqPending; m_bWrittenTx = Unit.bWrittenTx; + + SetSerialPortName(Unit.SerialPortName); }