1 /* ScummVM - Graphic Adventure Engine 2 * 3 * ScummVM is the legal property of its developers, whose names 4 * are too numerous to list here. Please refer to the COPYRIGHT 5 * file distributed with this source distribution. 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 */ 22 23 /* 24 * file i/o interface 25 */ 26 27 #ifndef GLK_TADS_TADS2_FILE_IO 28 #define GLK_TADS_TADS2_FILE_IO 29 30 #include "glk/tads/tads2/lib.h" 31 #include "glk/tads/tads2/memory_cache_loader.h" 32 #include "glk/tads/tads2/object.h" 33 34 namespace Glk { 35 namespace TADS { 36 namespace TADS2 { 37 38 /* forward declarations */ 39 struct voccxdef; 40 struct tokpdef; 41 struct tokthdef; 42 struct tokcxdef; 43 44 /* load-on-demand context (passed in by mcm in load callback) */ 45 struct fiolcxdef { 46 osfildef *fiolcxfp; /* file pointer of load file */ 47 errcxdef *fiolcxerr; /* error handling context */ 48 ulong fiolcxst; /* starting offset in file */ 49 uint fiolcxflg; /* flags from original load file */ 50 uint fiolcxseed; /* fioxor seed */ 51 uint fiolcxinc; /* fioxor increment */ 52 }; 53 54 /* write game to binary file */ 55 void fiowrt(struct mcmcxdef *mctx, voccxdef *vctx, 56 struct tokcxdef *tokctx, struct tokthdef *tab, 57 uchar *fmts, uint fmtl, char *fname, uint flags, objnum preinit, 58 int extc, uint prpcnt, char *filever); 59 60 /* flag values for use with fiowrt */ 61 #define FIOFSYM 0x01 /* include symbol table in output file */ 62 #define FIOFLIN 0x02 /* include source file tracking information */ 63 #define FIOFPRE 0x04 /* preinit needs to be run after reading game */ 64 #define FIOFCRYPT 0x08 /* "encrypt" objects prior to writing them */ 65 #define FIOFBIN 0x10 /* writing precompiled header */ 66 #define FIOFFAST 0x20 /* fast-load records are in file */ 67 #define FIOFCASE 0x40 /* case folding was turned on in original compile */ 68 #define FIOFLIN2 0x80 /* new-style line records */ 69 70 /* read game from binary file; sets up loader callback context */ 71 void fiord(mcmcxdef *mctx, voccxdef *vctx, tokcxdef *tctx, const char *fname, 72 const char *exename, fiolcxdef *setupctx, objnum *preinit, uint *flagp, 73 tokpdef *path, uchar **fmtsp, uint *fmtlp, uint *pcntptr, int flags, 74 appctxdef *appctx, char *argv0); 75 76 /* shut down load-on-demand subsystem, close load file */ 77 void fiorcls(fiolcxdef *ctx); 78 79 /* loader callback - load an object on demand */ 80 void OS_LOADDS fioldobj(void *ctx, mclhd handle, uchar *ptr, ushort siz); 81 82 /* 83 * Save a game - returns TRUE on failure. We'll save the file to 84 * 'fname'. 'game_fname' is the name of the game file; if this is not 85 * null, we'll save it to the saved game file so that the player can 86 * later start the game by specifying only the saved game file to the 87 * run-time. 'game_fname' can be null, in which case we'll omit the 88 * game file information. 89 */ 90 int fiosav(voccxdef *vctx, char *fname, char *game_fname); 91 92 /* 93 * fiorso() result codes 94 */ 95 #define FIORSO_SUCCESS 0 /* success */ 96 #define FIORSO_FILE_NOT_FOUND 1 /* file not found */ 97 #define FIORSO_NOT_SAVE_FILE 2 /* not a saved game file */ 98 #define FIORSO_BAD_FMT_VSN 3 /* incompatible file format version */ 99 #define FIORSO_BAD_GAME_VSN 4 /* file saved by another game or version */ 100 #define FIORSO_READ_ERROR 5 /* error reading from the file */ 101 #define FIORSO_NO_PARAM_FILE 6 /* no parameter file (for restore(nil)) */ 102 103 /* restore a game - returns TRUE on failure */ 104 int fiorso(voccxdef *vctx, char *fname); 105 106 /* 107 * Look in a saved game file to determine if it has information on which 108 * GAM file created it. If the GAM file information is available, this 109 * routine returns true and stores the game file name in the given 110 * buffer; if the information isn't available, we'll return false. 111 */ 112 int fiorso_getgame(char *saved_file, char *buf, size_t buflen); 113 114 /* encrypt/decrypt an object */ 115 void fioxor(uchar *p, uint siz, uint seed, uint inc); 116 117 /* strings stored in binary game file for identification and validation */ 118 119 /* file header string */ 120 #define FIOFILHDR "TADS2 bin\012\015\032" 121 122 /* resource file header string */ 123 #define FIOFILHDRRSC "TADS2 rsc\012\015\032" 124 125 /* CURRENT file format version string */ 126 #define FIOVSNHDR "v2.2.0" 127 128 /* other file format versions that can be READ by this version */ 129 #define FIOVSNHDR2 "v2.0.0" 130 #define FIOVSNHDR3 "v2.0.1" 131 132 } // End of namespace TADS2 133 } // End of namespace TADS 134 } // End of namespace Glk 135 136 #endif 137