Mercurial > vba-clojure
comparison src/gb/GB.cpp @ 76:d7c38ce83421
working on disk-backup for save-states
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Thu, 08 Mar 2012 19:48:54 -0600 |
parents | 4699c7bab77d |
children | 1ff2c546f5ad |
comparison
equal
deleted
inserted
replaced
75:eb7d4efe0f34 | 76:d7c38ce83421 |
---|---|
2461 { NULL, 0 } | 2461 { NULL, 0 } |
2462 }; | 2462 }; |
2463 | 2463 |
2464 bool gbWriteSaveStateToStream(gzFile gzFile) | 2464 bool gbWriteSaveStateToStream(gzFile gzFile) |
2465 { | 2465 { |
2466 | |
2466 utilWriteInt(gzFile, GBSAVE_GAME_VERSION); | 2467 utilWriteInt(gzFile, GBSAVE_GAME_VERSION); |
2467 | 2468 |
2469 | |
2468 utilGzWrite(gzFile, &gbRom[0x134], 15); | 2470 utilGzWrite(gzFile, &gbRom[0x134], 15); |
2469 | 2471 |
2470 utilWriteData(gzFile, gbSaveGameStruct); | 2472 utilWriteData(gzFile, gbSaveGameStruct); |
2471 | 2473 |
2472 utilGzWrite(gzFile, &IFF, 2); | 2474 utilGzWrite(gzFile, &IFF, 2); |
2473 | 2475 |
2474 if (gbSgbMode) | 2476 if (gbSgbMode) |
2475 { | 2477 { |
2476 gbSgbSaveGame(gzFile); | 2478 gbSgbSaveGame(gzFile); |
2477 } | 2479 } |
2478 | 2480 |
2547 utilGzWrite(gzFile, &GBSystemCounters.lagCount, sizeof(GBSystemCounters.lagCount)); | 2549 utilGzWrite(gzFile, &GBSystemCounters.lagCount, sizeof(GBSystemCounters.lagCount)); |
2548 utilGzWrite(gzFile, &GBSystemCounters.lagged, sizeof(GBSystemCounters.lagged)); | 2550 utilGzWrite(gzFile, &GBSystemCounters.lagged, sizeof(GBSystemCounters.lagged)); |
2549 utilGzWrite(gzFile, &GBSystemCounters.laggedLast, sizeof(GBSystemCounters.laggedLast)); | 2551 utilGzWrite(gzFile, &GBSystemCounters.laggedLast, sizeof(GBSystemCounters.laggedLast)); |
2550 } | 2552 } |
2551 | 2553 |
2554 utilWriteInt(gzFile, 0x07); // RLM this is the end of file marker. | |
2552 return true; | 2555 return true; |
2553 } | 2556 } |
2554 | 2557 |
2558 | |
2559 long gbWriteMemSaveStatePos(char *memory, int available){ | |
2560 gzFile gzFile = utilMemGzOpen(memory, available, "w"); | |
2561 | |
2562 if (gzFile == NULL) | |
2563 { | |
2564 return false; | |
2565 } | |
2566 | |
2567 bool res = gbWriteSaveStateToStream(gzFile); | |
2568 | |
2569 long pos = utilGzTell(gzFile) + 8; | |
2570 | |
2571 if (pos >= available){ | |
2572 pos = 0; | |
2573 } | |
2574 | |
2575 utilGzClose(gzFile); | |
2576 | |
2577 return pos; | |
2578 | |
2579 } | |
2580 | |
2555 bool gbWriteMemSaveState(char *memory, int available) | 2581 bool gbWriteMemSaveState(char *memory, int available) |
2556 { | 2582 { |
2557 gzFile gzFile = utilMemGzOpen(memory, available, "w"); | 2583 long pos = gbWriteMemSaveStatePos(memory, available); |
2558 | 2584 if (pos > 0) { return true; } |
2559 if (gzFile == NULL) | 2585 else{ return false; } |
2560 { | |
2561 return false; | |
2562 } | |
2563 | |
2564 bool res = gbWriteSaveStateToStream(gzFile); | |
2565 | |
2566 long pos = utilGzTell(gzFile) + 8; | |
2567 | |
2568 if (pos >= (available)) | |
2569 res = false; | |
2570 | |
2571 utilGzClose(gzFile); | |
2572 | |
2573 return res; | |
2574 } | 2586 } |
2575 | 2587 |
2576 bool gbWriteSaveState(const char *name) | 2588 bool gbWriteSaveState(const char *name) |
2577 { | 2589 { |
2578 gzFile gzFile = utilGzOpen(name, "wb"); | 2590 gzFile gzFile = utilGzOpen(name, "wb"); |