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 #ifndef ADRIFT_ADRIFT_H
24 #define ADRIFT_ADRIFT_H
25 
26 #include "common/scummsys.h"
27 #include "common/stream.h"
28 #include "glk/jumps.h"
29 
30 namespace Glk {
31 namespace Adrift {
32 
33 /*
34  * Base type definitions.  SCARE integer types need to be at least 32 bits,
35  * so using long here is a good bet for almost all ANSI C implementations for
36  * 32 and 64 bit platforms; maybe also for any 16 bit ones.  For 64 bit
37  * platforms configured for LP64, SCARE integer types will consume more space
38  * in data structures.  Values won't wrap identically to 32 bit ones, but
39  * games shouldn't be relying on wrapping anyway.  One final note -- in several
40  * places, SCARE allocates 32 bytes into which it will sprintf() a long; this
41  * is fine for both standard 32 bit and LP64 64 bit platforms, but is unsafe
42  * should SCARE ever be configured for 128 bit definitions of sc_[u]int.
43  */
44 typedef char sc_char;
45 typedef unsigned char sc_byte;
46 typedef long sc_int;
47 typedef unsigned long sc_uint;
48 typedef int sc_bool;
49 
50 enum { BYTE_MAX = 0xff };
51 enum { INTEGER_MAX = 0x7fff };
52 
53 /* Enumerated confirmation types, passed to os_confirm(). */
54 enum {
55 	SC_CONF_QUIT = 0,
56 	SC_CONF_RESTART, SC_CONF_SAVE, SC_CONF_RESTORE, SC_CONF_VIEW_HINTS
57 };
58 
59 /* HTML-like tag enumerated values, passed to os_print_tag(). */
60 enum {
61 	SC_TAG_UNKNOWN = 0, SC_TAG_ITALICS, SC_TAG_ENDITALICS, SC_TAG_BOLD,
62 	SC_TAG_ENDBOLD, SC_TAG_UNDERLINE, SC_TAG_ENDUNDERLINE, SC_TAG_COLOR,
63 	SC_TAG_ENDCOLOR, SC_TAG_FONT, SC_TAG_ENDFONT, SC_TAG_BGCOLOR, SC_TAG_CENTER,
64 	SC_TAG_ENDCENTER, SC_TAG_RIGHT, SC_TAG_ENDRIGHT, SC_TAG_WAIT, SC_TAG_WAITKEY,
65 	SC_TAG_CLS,
66 
67 	/* British spelling equivalents. */
68 	SC_TAG_COLOUR = SC_TAG_COLOR,
69 	SC_TAG_ENDCOLOUR = SC_TAG_ENDCOLOR,
70 	SC_TAG_BGCOLOUR = SC_TAG_BGCOLOR,
71 	SC_TAG_CENTRE = SC_TAG_CENTER,
72 	SC_TAG_ENDCENTRE = SC_TAG_ENDCENTER
73 };
74 
75 /* OS interface function prototypes; interpreters must define these. */
76 typedef void *sc_game;
77 extern void os_print_string(const sc_char *string);
78 extern void os_print_tag(sc_int tag, const sc_char *argument);
79 extern void os_play_sound(const sc_char *filepath,
80 						  sc_int offset, sc_int length, sc_bool is_looping);
81 extern void os_stop_sound();
82 extern void os_show_graphic(const sc_char *filepath,
83 							sc_int offset, sc_int length);
84 extern sc_bool os_read_line(sc_char *buffer, sc_int length);
85 extern sc_bool os_confirm(sc_int type);
86 extern void *os_open_file(sc_bool is_save);
87 extern void os_write_file(void *opaque, const sc_byte *buffer, sc_int length);
88 extern sc_int os_read_file(void *opaque, sc_byte *buffer, sc_int length);
89 extern void os_close_file(void *opaque);
90 extern void os_display_hints(sc_game game);
91 
92 extern void os_print_string_debug(const sc_char *string);
93 extern sc_bool os_read_line_debug(sc_char *buffer, sc_int length);
94 
95 /* Interpreter trace flag bits, passed to sc_set_trace_flags(). */
96 enum {
97 	SC_TRACE_PARSE = 1, SC_TRACE_PROPERTIES = 2, SC_TRACE_VARIABLES = 4,
98 	SC_TRACE_PARSER = 8, SC_TRACE_LIBRARY = 16, SC_TRACE_EVENTS = 32,
99 	SC_TRACE_NPCS = 64, SC_TRACE_OBJECTS = 128, SC_TRACE_TASKS = 256,
100 	SC_TRACE_PRINTFILTER = 512,
101 
102 	SC_DUMP_TAF = 1024, SC_DUMP_PROPERTIES = 2048, SC_DUMP_VARIABLES = 4096,
103 	SC_DUMP_PARSER_TREES = 8192, SC_DUMP_LOCALE_TABLES = 16384
104 };
105 
106 /* Module-wide trace control function prototype. */
107 extern void sc_set_trace_flags(sc_uint trace_flags);
108 
109 /* Interpreter interface function prototypes. */
110 extern sc_game sc_game_from_filename(const sc_char *filename);
111 extern sc_game sc_game_from_stream(Common::SeekableReadStream *stream);
112 extern sc_game sc_game_from_callback(sc_int(*callback)
113 									 (void *, sc_byte *, sc_int),
114 									 void *opaque);
115 extern void sc_interpret_game(CONTEXT, sc_game game);
116 extern void sc_restart_game(CONTEXT, sc_game game);
117 extern sc_bool sc_save_game(sc_game game);
118 extern sc_bool sc_load_game(sc_game game);
119 extern sc_bool sc_undo_game_turn(CONTEXT, sc_game game);
120 extern void sc_quit_game(sc_game game);
121 extern sc_bool sc_save_game_to_filename(sc_game game, const sc_char *filename);
122 extern void sc_save_game_to_stream(sc_game game, Common::SeekableReadStream *stream);
123 extern void sc_save_game_to_callback(sc_game game,
124 									 void (*callback)
125 									 (void *, const sc_byte *, sc_int),
126 									 void *opaque);
127 extern sc_bool sc_load_game_from_filename(sc_game game,
128 		const sc_char *filename);
129 extern sc_bool sc_load_game_from_stream(sc_game game, Common::SeekableReadStream *stream);
130 extern sc_bool sc_load_game_from_callback(sc_game game,
131 		sc_int(*callback)
132 		(void *, sc_byte *, sc_int),
133 		void *opaque);
134 extern void sc_free_game(sc_game game);
135 extern sc_bool sc_is_game_running(sc_game game);
136 extern const sc_char *sc_get_game_name(sc_game game);
137 extern const sc_char *sc_get_game_author(sc_game game);
138 extern const sc_char *sc_get_game_compile_date(sc_game game);
139 extern sc_int sc_get_game_turns(sc_game game);
140 extern sc_int sc_get_game_score(sc_game game);
141 extern sc_int sc_get_game_max_score(sc_game game);
142 extern const sc_char *sc_get_game_room(sc_game game);
143 extern const sc_char *sc_get_game_status_line(sc_game game);
144 extern const sc_char *sc_get_game_preferred_font(sc_game game);
145 extern sc_bool sc_get_game_bold_room_names(sc_game game);
146 extern sc_bool sc_get_game_verbose(sc_game game);
147 extern sc_bool sc_get_game_notify_score_change(sc_game game);
148 extern sc_bool sc_has_game_completed(sc_game game);
149 extern sc_bool sc_is_game_undo_available(sc_game game);
150 extern void sc_set_game_bold_room_names(sc_game game, sc_bool flag);
151 extern void sc_set_game_verbose(sc_game game, sc_bool flag);
152 extern void sc_set_game_notify_score_change(sc_game game, sc_bool flag);
153 
154 extern sc_bool sc_does_game_use_sounds(sc_game);
155 extern sc_bool sc_does_game_use_graphics(sc_game);
156 
157 typedef void *sc_game_hint;
158 extern sc_game_hint sc_get_first_game_hint(sc_game game);
159 extern sc_game_hint sc_get_next_game_hint(sc_game game, sc_game_hint hint);
160 extern const sc_char *sc_get_game_hint_question(sc_game game,
161 		sc_game_hint hint);
162 extern const sc_char *sc_get_game_subtle_hint(sc_game game,
163 		sc_game_hint hint);
164 extern const sc_char *sc_get_game_unsubtle_hint(sc_game game,
165 		sc_game_hint hint);
166 
167 extern void sc_set_game_debugger_enabled(sc_game game, sc_bool flag);
168 extern sc_bool sc_get_game_debugger_enabled(sc_game game);
169 extern sc_bool sc_run_game_debugger_command(sc_game game,
170 		const sc_char *debug_command);
171 extern void sc_set_portable_random(sc_bool flag);
172 extern void sc_reseed_random_sequence(sc_uint new_seed);
173 
174 /* Locale control and query functions. */
175 extern sc_bool sc_set_locale(const sc_char *name);
176 extern const sc_char *sc_get_locale();
177 
178 /* A few possibly useful utilities. */
179 extern sc_int sc_strncasecmp(const sc_char *s1, const sc_char *s2, sc_int n);
180 extern sc_int sc_strcasecmp(const sc_char *s1, const sc_char *s2);
181 extern const sc_char *sc_scare_version();
182 extern sc_int sc_scare_emulation();
183 
184 extern char *adrift_fgets(char *buf, int max, Common::SeekableReadStream *s);
185 
186 } // End of namespace Adrift
187 } // End of namespace Glk
188 
189 #endif
190