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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
|
/* 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.
*
*/
#ifndef GLK_TADS_TADS2_OS
#define GLK_TADS_TADS2_OS
#include "glk/tads/tads.h"
#include "glk/tads/tads2/types.h"
namespace Glk {
namespace TADS {
namespace TADS2 {
/**
* Operating system compatibility layer
*/
class OS : public TADS {
protected:
char status_left[OSS_STATUS_STRING_LEN];
char status_right[OSS_STATUS_STRING_LEN];
int status_mode;
protected:
/**
* Constructor
*/
OS(OSystem *syst, const GlkGameDescription &gameDesc);
/**
* Terminates the game
*/
void os_terminate(int rc);
/**
* \defgroup Type Conversions
* @{
*/
/**
* Change a TADS prompt type (OS_AFP_*) into a Glk prompt type.
*/
uint oss_convert_prompt_type(int type);
/**
* Change a TADS file type (OSFT*) into a Glk file type.
*/
uint oss_convert_file_type(int type);
/**
* Change a fileref ID (frefid_t) to a special string and put it in the
* buffer which is passed to it. The string is given by
* OSS_FILEREF_STRING_PREFIX + 'nnnnn' + OSS_FILEREF_STRING_SUFFIX
* where 'nnnnn' is the frefid_t pointer converted into a string of decimal
* numbers. This is only really practical for 32-bit pointers; if we use
* 64-bit pointers I'll have to start using a hash table or use hex
* numbers.
*/
uint oss_convert_fileref_to_string(frefid_t file_to_convert, char *buffer, int buf_len);
/**
* Turn a filename or a special fileref string into an actual fileref.
* Notice that, since Glk doesn't know paths, we take this opportunity to
* call oss_check_path, which should do the OS-dependent path changing
* in the event that the filename contains path information
*/
frefid_t oss_convert_string_to_fileref(char *buffer, uint usage);
/**
* Tell us if the passed string is a hashed fileref or not
*/
bool oss_is_string_a_fileref(char *buffer);
/**
* Change a Glk key into a TADS one, using the CMD_xxx codes
*/
unsigned char oss_convert_keystroke_to_tads(uint key);
/**@}*/
/**
* \defgroup Directory/File methods
* @{
*/
/**
* If a filename contains path information, change dirs to that path.
* Returns true if the path was fiddled with
*/
bool oss_check_path(char *filename);
/**
* In case we changed directories in oss_check_path, change back to the
* original executable directory
*/
void oss_revert_path();
/**
* Open a stream, given a string, usage, and a filemode. tadsusage is the
* TADS filemode (OSFT*); tbusage is either fileusage_TextMode or
* fileusage_BinaryMode (from Glk).
*/
osfildef *oss_open_stream(char *buffer, uint tadsusage, uint tbusage,
uint fmode, uint rock);
/**
* Get a pointer to the root name portion of a filename. This is the part
* of the filename after any path or directory prefix. For example, on
* Unix, given the string "/home/mjr/deep.gam", this function should return
* a pointer to the 'd' in "deep.gam". If the filename doesn't appear to
* have a path prefix, it should simply return the argument unchanged.
*/
const char *os_get_root_name(const char *buf) const { return buf; }
/**
* Open a file for access
*/
osfildef *osfoprb(const char *fname, uint typ = 0);
/**
* Receive notification that a character mapping file has been loaded. We
* don't need to do anything with this information, since we we're relying
* on the Glk layer and ScummVM backend to handle all that
*/
void os_advise_load_charmap(const char *id, const char *ldesc, const char *sysinfo) {
// No implementation needed
}
/**
* Generate a filename for a character mapping table. On Windows, the
* filename is always simply "win" plus the internal ID plus ".tcp".
*/
void os_gen_charmap_filename(char *filename, const char *internal_id,
const char *argv0);
/**@}*/
/**
* \defgroup The main text area print routines
* @{
*/
/**
* Process hilighting codes while printing a string
*/
void oss_put_string_with_hilite(winid_t win, const char *str, size_t len);
/**
* Status line handling
*/
void oss_draw_status_line();
void oss_change_status_string(char *dest, const char *src, size_t len);
void oss_change_status_left(const char *str, size_t len);
void oss_change_status_right(const char *str);
int os_get_status() const { return status_mode; }
/**
* Flush the output
*/
void os_flush();
/**
* Print a null terminated string
*/
void os_printz(const char *str) { os_print(str, strlen(str)); }
/**
* Print a string
*/
void os_print(const char *str, size_t len);
/**@}*/
/**
* \defgroup Memory routines
* @{
*/
/**
* Compare two strings
*/
int memicmp(const char *s1, const char *s2, int len);
/**@}*/
/**
* \defgroup Input routines
* @{
*/
/**
* Wait for a key to be hit
*/
void os_waitc(void) { os_getc(); }
/**
* Get a character from the keyboard. For extended characters, return 0,
* then return the extended key at the next call to this function
*/
int os_getc() {
return oss_getc_from_window(story_win);
}
/**
* Accept a keystroke in the passed window
*/
int oss_getc_from_window(winid_t win);
/**
* Print a message (with os_print) and wait for a key
*/
void os_expause();
/**@}*/
};
} // End of namespace TADS2
} // End of namespace TADS
} // End of namespace Glk
#endif
|