|
|
1.1 root 1: /*
2: Hatari
3:
4: Memory Snapshot
5:
6: This handles the saving/restoring of the emulator's state so any game/application can be saved
7: and restored at any time. This is quite complicated as we need to store all STRam, all chip states,
8: all emulation variables and then things get really complicated as we need to restore file handles
9: and such like.
10: To help keep things simple each file has one function which is used to save/restore all variables
11: that are local to it. We use one function to reduce redundancy and the function 'MemorySnapShot_Store'
12: decides if it should save or restore the data.
13: */
14:
15: #include "main.h"
16: /*#include "compress.h"*/
17: #include "debug.h"
18: #include "dialog.h"
19: #include "fdc.h"
20: #include "file.h"
21: #include "floppy.h"
22: #include "gemdos.h"
23: #include "ikbd.h"
24: #include "int.h"
25: #include "m68000.h"
26: #include "memorySnapShot.h"
27: #include "mfp.h"
28: #include "psg.h"
29: #include "reset.h"
30: #include "sound.h"
31: #include "tos.h"
32: #include "video.h"
1.1.1.2 root 33:
1.1 root 34:
35: //#define COMPRESS_MEMORYSNAPSHOT // Compress snapshots to reduce disc space used
36:
37: //HFILE CaptureFile;
38: //OFSTRUCT CaptureFileInfo;
39: BOOL bCaptureSave, bCaptureError;
40: BOOL bSaveMemoryState=FALSE, bRestoreMemoryState=FALSE;
41: char szSnapShotFileName[MAX_FILENAME_LENGTH];
42:
43: //-----------------------------------------------------------------------
44: /*
45: Check if need to save/restore emulation memory state, via flag 'bSaveMemoryState', and 'bRestoreMemoryState'
46: */
47: void MemorySnapShot_CheckSaveRestore(void)
48: {
49: // Is chose to save memory state, one of these two flags will be set
50: /*FIXME*/
51: /*
52: if (bSaveMemoryState || bRestoreMemoryState) {
53: Main_PauseEmulation(); // Hold things...
54: View_ToggleWindowsMouse(MOUSE_WINDOWS); // Put mouse into ST mode
55: View_LimitCursorToScreen(); // Free mouse from Window constraints
56:
57: // Do we need user to enter a filename?
58: if (strlen(ConfigureParams.Memory.szMemoryCaptureFileName)<=0) {
59: if (!File_OpenSelectDlg(hWnd,ConfigureParams.Memory.szMemoryCaptureFileName,FILEFILTER_MEMORYFILE,FALSE,bSaveMemoryState))
60: bSaveMemoryState = bRestoreMemoryState = FALSE;
61: }
62:
63: // Do save/load
64: if (bSaveMemoryState)
65: MemorySnapShot_Capture(ConfigureParams.Memory.szMemoryCaptureFileName);
66: else if (bRestoreMemoryState)
67: MemorySnapShot_Restore(ConfigureParams.Memory.szMemoryCaptureFileName);
68: bSaveMemoryState = bRestoreMemoryState = FALSE;
69:
70: View_LimitCursorToClient(); // And limit mouse in Window
71: View_ToggleWindowsMouse(MOUSE_ST); // Put mouse into ST mode
72: Main_UnPauseEmulation(); // And off we go...
73: }
74: */
75: }
76:
77: //-----------------------------------------------------------------------
78: /*
79: Get filename to save/restore to, so can compress
80: */
81: char *MemorySnapShot_CompressBegin(char *pszFileName)
82: {
83: #ifdef COMPRESS_MEMORYSNAPSHOT
84: // Create temporary filename
85: sprintf(szSnapShotFileName,"%s/%s",szWorkingDir,"snapshot.mem");
86: return(szSnapShotFileName);
87: #else //COMPRESS_MEMORYSNAPSHOT
88: return(pszFileName);
89: #endif //COMPRESS_MEMORYSNAPSHOT
90: }
91:
92: //-----------------------------------------------------------------------
93: /*
94: Compress memory snap shot
95: */
96: void MemorySnapShot_CompressEnd(char *pszFileName)
97: {
98: #ifdef COMPRESS_MEMORYSNAPSHOT
99: // Compress file from temporary to final destination
100: Compress_Pack_File(szSnapShotFileName,pszFileName);
101: // And delete temporary
102: File_Delete(szSnapShotFileName);
103: #endif //COMPRESS_MEMORYSNAPSHOT
104: }
105:
106: //-----------------------------------------------------------------------
107: /*
108: Uncompress memory snap shot to temporary file
109: */
110: char *MemorySnapShot_UnCompressBegin(char *pszFileName)
111: {
112: #ifdef COMPRESS_MEMORYSNAPSHOT
113: // Uncompress to temporary file
114: sprintf(szSnapShotFileName,"%s/%s",szWorkingDir,"snapshot.mem");
115: Compress_UnPack_File(pszFileName,szSnapShotFileName);
116: return(szSnapShotFileName);
117: #else //COMPRESS_MEMORYSNAPSHOT
118: return(pszFileName);
119: #endif //COMPRESS_MEMORYSNAPSHOT
120: }
121:
122: //-----------------------------------------------------------------------
123: /*
124: Clean up after uncompression
125: */
126: void MemorySnapShot_UnCompressEnd(void)
127: {
128: // And delete temporary
129: File_Delete(szSnapShotFileName);
130: }
131:
132: //-----------------------------------------------------------------------
133: /*
134: Open/Create snapshot file, and set flag so 'MemorySnapShot_Store' knows how to handle data
135: */
136: BOOL MemorySnapShot_OpenFile(char *pszFileName,BOOL bSave)
137: {
138: /* FIXME */
139: /*
1.1.1.3 ! root 140: char szString[256];
! 141: char VersionString[VERSION_STRING_SIZE];
! 142:
1.1 root 143: // Set error
144: bCaptureError = FALSE;
145:
146: // Open file, set flag so 'MemorySnapShot_Store' can load to/save from file
147: if (bSave) {
148: // Save
149: CaptureFile = OpenFile(pszFileName,&CaptureFileInfo,OF_CREATE | OF_WRITE);
150: if (CaptureFile==HFILE_ERROR) {
151: bCaptureError = TRUE;
152: return(FALSE);
153: }
154: bCaptureSave = TRUE;
155: // Store version string
156: MemorySnapShot_Store(VERSION_STRING,VERSION_STRING_SIZE);
157: }
158: else {
159: // Restore
160: CaptureFile = OpenFile(pszFileName,&CaptureFileInfo,OF_READ);
161: if (CaptureFile==HFILE_ERROR) {
162: bCaptureError = TRUE;
163: return(FALSE);
164: }
165: bCaptureSave = FALSE;
166: // Restore version string
167: MemorySnapShot_Store(VersionString,VERSION_STRING_SIZE);
168: // Does match current version?
169: if (stricmp(VersionString,VERSION_STRING)) {
170: // No, inform user and error
171: sprintf(szString,"Unable to Restore Memory State.\nFile is only compatible with Hatari v%s",VersionString);
172: Main_Message(szString,PROG_NAME,MB_OK | MB_ICONSTOP);
173: bCaptureError = TRUE;
174: return(FALSE);
175: }
176: }
177:
178: // All OK
179: return(TRUE);
180: */
181: return FALSE;
182: }
183:
184: //-----------------------------------------------------------------------
185: /*
186: Close snapshot file
187: */
188: void MemorySnapShot_CloseFile(void)
189: {
190: //FIXME _lclose(CaptureFile);
191: }
192:
193: //-----------------------------------------------------------------------
194: /*
195: Save/Restore data to/from file
196: */
197: void MemorySnapShot_Store(void *pData, int Size)
198: {
199: /*FIXME*/
200: /*
1.1.1.3 ! root 201: long nBytes;
! 202:
1.1 root 203: // Check no file errors
204: if (CaptureFile!=HFILE_ERROR) {
205: // Saving or Restoring?
206: if (bCaptureSave)
207: nBytes = _hwrite(CaptureFile,(char *)pData,Size);
208: else
209: nBytes = _hread(CaptureFile,(char *)pData,Size);
210:
211: // Did save OK?
212: if (nBytes==HFILE_ERROR)
213: bCaptureError = TRUE;
214: else if (nBytes!=Size)
215: bCaptureError = TRUE;
216: }
217: */
218: }
219:
220: //-----------------------------------------------------------------------
221: /*
222: Save 'snapshot' of memory/chips/emulation variables
223: */
224: void MemorySnapShot_Capture(char *pszFileName)
225: {
226: /*FIXME*/
227: /*
1.1.1.3 ! root 228: char *pszSnapShotFileName;
! 229:
1.1 root 230: // Wait...
231: SetCursor(Cursors[CURSOR_HOURGLASS]);
232:
233: // If to be compressed, return temporary filename
234: pszSnapShotFileName = MemorySnapShot_CompressBegin(pszFileName);
235:
236: // Set to 'saving'
237: if (MemorySnapShot_OpenFile(pszSnapShotFileName,TRUE)) {
238: // Capture each files details
239: Main_MemorySnapShot_Capture(TRUE);
240: FDC_MemorySnapShot_Capture(TRUE);
241: Floppy_MemorySnapShot_Capture(TRUE);
242: GemDOS_MemorySnapShot_Capture(TRUE);
243: IKBD_MemorySnapShot_Capture(TRUE);
244: Int_MemorySnapShot_Capture(TRUE);
245: M68000_MemorySnapShot_Capture(TRUE);
246: M68000_Decode_MemorySnapShot_Capture(TRUE);
247: MFP_MemorySnapShot_Capture(TRUE);
248: PSG_MemorySnapShot_Capture(TRUE);
249: Sound_MemorySnapShot_Capture(TRUE);
250: TOS_MemorySnapShot_Capture(TRUE);
251: Video_MemorySnapShot_Capture(TRUE);
252:
253: // And close
254: MemorySnapShot_CloseFile();
255: }
256:
257: // And compress, if need to
258: MemorySnapShot_CompressEnd(pszFileName);
259:
260: // We're back
261: SetCursor(Cursors[CURSOR_ARROW]);
262:
263: // Did error
264: if (bCaptureError)
265: Main_Message("Unable to Save Memory State to file.",PROG_NAME,MB_OK | MB_ICONSTOP);
266: else
267: Main_Message("Memory State file saved.",PROG_NAME,MB_OK | MB_ICONINFORMATION);
268: */
269: }
270:
271: //-----------------------------------------------------------------------
272: /*
273: Restore 'snapshot' of memory/chips/emulation variables
274: */
275: void MemorySnapShot_Restore(char *pszFileName)
276: {
277: /*FIXME*/
278: /*
1.1.1.3 ! root 279: char *pszSnapShotFileName;
! 280:
1.1 root 281: // Wait...
282: SetCursor(Cursors[CURSOR_HOURGLASS]);
283:
284: // If to be uncompressed, return temporary filename
285: pszSnapShotFileName = MemorySnapShot_UnCompressBegin(pszFileName);
286:
287: // Set to 'restore'
288: if (MemorySnapShot_OpenFile(pszSnapShotFileName,FALSE)) {
289: // Reset emulator to get things running
290: Reset_Cold();
291:
292: // Capture each files details
293: Main_MemorySnapShot_Capture(FALSE);
294: FDC_MemorySnapShot_Capture(FALSE);
295: Floppy_MemorySnapShot_Capture(FALSE);
296: GemDOS_MemorySnapShot_Capture(FALSE);
297: IKBD_MemorySnapShot_Capture(FALSE);
298: Int_MemorySnapShot_Capture(FALSE);
299: M68000_MemorySnapShot_Capture(FALSE);
300: M68000_Decode_MemorySnapShot_Capture(FALSE);
301: MFP_MemorySnapShot_Capture(FALSE);
302: PSG_MemorySnapShot_Capture(FALSE);
303: Sound_MemorySnapShot_Capture(FALSE);
304: TOS_MemorySnapShot_Capture(FALSE);
305: Video_MemorySnapShot_Capture(FALSE);
306:
307: // And close
308: MemorySnapShot_CloseFile();
309: }
310:
311: // And clean up
312: MemorySnapShot_UnCompressEnd();
313:
314: // We're back
315: SetCursor(Cursors[CURSOR_ARROW]);
316:
317: // Did error
318: if (bCaptureError)
319: Main_Message("Unable to Restore Memory State from file.",PROG_NAME,MB_OK | MB_ICONSTOP);
320: else
321: Main_Message("Memory State file restored.",PROG_NAME,MB_OK | MB_ICONINFORMATION);
322: */
323: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.