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