aboutsummaryrefslogtreecommitdiff
path: root/engines/glk/frotz/frotz.cpp
diff options
context:
space:
mode:
authorPaul Gilbert2018-11-26 22:18:45 -0800
committerPaul Gilbert2018-12-08 19:05:59 -0800
commit2331a0e9fb3dfe335c15c470d3e7da49cc7ac5f7 (patch)
tree3b895569c5b10fff83dcdb0a96e1f5a545f0aa1e /engines/glk/frotz/frotz.cpp
parent33a23bca1c0363340d14ed4c84e558e82a9f245e (diff)
downloadscummvm-rg350-2331a0e9fb3dfe335c15c470d3e7da49cc7ac5f7.tar.gz
scummvm-rg350-2331a0e9fb3dfe335c15c470d3e7da49cc7ac5f7.tar.bz2
scummvm-rg350-2331a0e9fb3dfe335c15c470d3e7da49cc7ac5f7.zip
GLK: FROTZ: Quetzal saving and loading now works
Diffstat (limited to 'engines/glk/frotz/frotz.cpp')
-rw-r--r--engines/glk/frotz/frotz.cpp180
1 files changed, 29 insertions, 151 deletions
diff --git a/engines/glk/frotz/frotz.cpp b/engines/glk/frotz/frotz.cpp
index 993c65e8e2..2ec7585057 100644
--- a/engines/glk/frotz/frotz.cpp
+++ b/engines/glk/frotz/frotz.cpp
@@ -23,6 +23,7 @@
#include "glk/frotz/frotz.h"
#include "glk/frotz/frotz_types.h"
#include "glk/frotz/screen.h"
+#include "glk/frotz/quetzal.h"
#include "common/config-manager.h"
namespace Glk {
@@ -65,167 +66,44 @@ void Frotz::initialize() {
}
Common::Error Frotz::saveGameData(strid_t file, const Common::String &desc) {
-#ifdef TODO
- long pc;
- zword addr;
- zword nsp, nfp;
- int skip;
- int i;
+ Quetzal q(story_fp);
+ bool success = q.save(*file, this, desc);
- // Open game file
-
- if ((gfp = frotzopenprompt(FILE_SAVE)) == nullptr)
- goto finished;
-
- if (_quetzal) {
- success = save_quetzal(gfp, story_fp, blorb_ofs);
- }
- else {
- // Write game file
-
- fputc((int)hi(h_release), gfp);
- fputc((int)lo(h_release), gfp);
- fputc((int)hi(h_checksum), gfp);
- fputc((int)lo(h_checksum), gfp);
-
- GET_PC(pc)
-
- fputc((int)(pc >> 16) & 0xff, gfp);
- fputc((int)(pc >> 8) & 0xff, gfp);
- fputc((int)(pc)& 0xff, gfp);
-
- nsp = (int)(_sp - _stack);
- nfp = (int)(_fp - _stack);
-
- fputc((int)hi(nsp), gfp);
- fputc((int)lo(nsp), gfp);
- fputc((int)hi(nfp), gfp);
- fputc((int)lo(nfp), gfp);
-
- for (i = nsp; i < STACK_SIZE; i++) {
- fputc((int)hi(_stack[i]), gfp);
- fputc((int)lo(_stack[i]), gfp);
- }
-
- fseek(story_fp, blorb_ofs, SEEK_SET);
-
- for (addr = 0, skip = 0; addr < h_dynamic_size; addr++)
- if (zmp[addr] != fgetc(story_fp) || skip == 255 || addr + 1 == h_dynamic_size) {
- fputc(skip, gfp);
- fputc(zmp[addr], gfp);
- skip = 0;
- }
- else skip++;
- }
-
- // Close game file and check for errors
-
- if (fclose(gfp) == EOF || ferror(story_fp)) {
+ if (!success)
print_string("Error writing save file\n");
- goto finished;
- }
- // Success
- success = 1;
-#endif
return Common::kNoError;
}
Common::Error Frotz::loadGameData(strid_t file) {
-#ifdef TODO
- long pc;
- zword release;
- zword addr;
- int i;
-
- // Open game file
- if ((gfp = frotzopenprompt(FILE_RESTORE)) == nullptr)
- goto finished;
-
- if (_quetzal) {
- success = restore_quetzal (gfp, story_fp, blorb_ofs);
-
+ Quetzal q(story_fp);
+ bool success = q.restore(*file, this) == 2;
+
+ if (success) {
+ zbyte old_screen_rows;
+ zbyte old_screen_cols;
+
+ // In V3, reset the upper window.
+ if (h_version == V3)
+ split_window(0);
+
+ LOW_BYTE(H_SCREEN_ROWS, old_screen_rows);
+ LOW_BYTE(H_SCREEN_COLS, old_screen_cols);
+
+ // Reload cached header fields
+ restart_header ();
+
+ /* Since QUETZAL files may be saved on many different machines,
+ * the screen sizes may vary a lot. Erasing the status window
+ * seems to cover up most of the resulting badness.
+ */
+ if (h_version > V3 && h_version != V6 && (h_screen_rows != old_screen_rows
+ || h_screen_cols != old_screen_cols))
+ erase_window (1);
} else {
- // Load game file
-
- release = (unsigned) fgetc (gfp) << 8;
- release |= fgetc (gfp);
-
- () fgetc (gfp);
- () fgetc (gfp);
-
- // Check the release number
- if (release == h_release) {
-
- pc = (long) fgetc (gfp) << 16;
- pc |= (unsigned) fgetc (gfp) << 8;
- pc |= fgetc (gfp);
-
- SET_PC (pc);
-
- _sp = _stack + (fgetc (gfp) << 8);
- _sp += fgetc (gfp);
- _fp = _stack + (fgetc (gfp) << 8);
- _fp += fgetc (gfp);
-
- for (i = (int) (_sp - _stack); i < STACK_SIZE; i++) {
- _stack[i] = (unsigned) fgetc (gfp) << 8;
- _stack[i] |= fgetc (gfp);
- }
-
- fseek (story_fp, blorb_ofs, SEEK_SET);
-
- for (addr = 0; addr < h_dynamic_size; addr++) {
- int skip = fgetc (gfp);
- for (i = 0; i < skip; i++)
- zmp[addr++] = fgetc (story_fp);
- zmp[addr] = fgetc (gfp);
- () fgetc (story_fp);
- }
-
- // Check for errors
- if (ferror (gfp) || ferror (story_fp) || addr != h_dynamic_size)
- success = -1;
- else
-
- // Success
- success = 2;
-
- } else print_string ("Invalid save file\n");
+ error("Error reading save file");
}
- if ((short) success >= 0) {
-
- // Close game file
- fclose (gfp);
-
- if ((short) success > 0) {
- zbyte old_screen_rows;
- zbyte old_screen_cols;
-
- // In V3, reset the upper window.
- if (h_version == V3)
- split_window (0);
-
- LOW_BYTE (H_SCREEN_ROWS, old_screen_rows);
- LOW_BYTE (H_SCREEN_COLS, old_screen_cols);
-
- /* Reload cached header fields. */
- restart_header ();
-
- /*
- * Since QUETZAL files may be saved on many different machines,
- * the screen sizes may vary a lot. Erasing the status window
- * seems to cover up most of the resulting badness.
- */
- if (h_version > V3 && h_version != V6
- && (h_screen_rows != old_screen_rows
- || h_screen_cols != old_screen_cols))
- erase_window (1);
- }
- } else
- os_fatal ("Error reading save file");
-#endif
return Common::kNoError;
}