aboutsummaryrefslogtreecommitdiff
path: root/engines/glk/magnetic/magnetic.h
blob: 6cf05c942e1a080c5d693c65c7aa445e7793cf17 (plain)
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
/* 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_MAGNETIC_MAGNETIC
#define GLK_MAGNETIC_MAGNETIC

#include "common/scummsys.h"
#include "glk/glk_api.h"
#include "glk/magnetic/magnetic_types.h"

namespace Glk {
namespace Magnetic {

/**
 * Magnetic game interpreter
 */
class Magnetic : public GlkAPI {
public:
	Common::File _hintFile;
	Common::File _gfxFile;
	Common::File _sndFile;
	bool vm_exited_cleanly;
	uint dlimit, slimit;
	int log_on;

	// Emu fields
	uint32 dreg[8], areg[8], i_count, string_size, rseed, pc, arg1i, mem_size;
	uint16 properties, fl_sub, fl_tab, fl_size, fp_tab, fp_size;
	byte zflag, nflag, cflag, vflag, byte1, byte2, regnr, admode, opsize;
	byte *arg1, *arg2, is_reversible, running, tmparg[4];
	byte lastchar, version, sd;
	byte *decode_table, *restart, *code, *string, *string2;
	byte *string3, *dict;
	byte quick_flag, gfx_ver, *gfx_buf, *gfx_data;
	byte *gfx2_hdr, *gfx2_buf;
	Common::String gfx2_name;
	uint16 gfx2_hsize;
	byte *snd_buf, *snd_hdr;
	uint16 snd_hsize;
	Common::File gfx_fp;
	uint32 undo_regs[2][18], undo_pc, undo_size;
	byte *undo[2], undo_stat[2];
	uint16 gfxtable, table_dist;
	uint16 v4_id, next_table;

	ms_hint *hints;
	byte *hint_contents;
	picture anim_frame_table[MAX_ANIMS];
	uint16 pos_table_size;
	uint16 pos_table_count[MAX_POSITIONS];
	ms_position pos_table[MAX_POSITIONS][MAX_ANIMS];
	byte *command_table;
	int command_index;
	lookup anim_table[MAX_POSITIONS];
	int pos_table_index;
	int pos_table_max;
	ms_position pos_array[MAX_FRAMES];
	byte anim_repeat;


private:
	/**
	 * Validates the game file, and if it's invalid, displays an error dialog
	 */
	bool is_gamefile_valid();

	/**
	 * \defgroup Emu
	 * @{
	 */

	/**
	 * Loads the interpreter with a game
	 * @return	0 = failure, 1 = success(without graphics or graphics failed),
	 *		2 = success(with graphics)
	 */
	int ms_init(bool restarting = false);

	/**
	 * Stops further processing of opcodes
	 */
	void ms_stop() { running = false; }

	/**
	 * Detects if game is running
	 */
	bool ms_is_running() const { return running; }

	/**
	 * Returns true if running a Magnetic Windows game
	 */
	bool ms_is_magwin() const { return version == 4; }

	/**
	 * Frees all allocated ressources
	 */
	void ms_freemem();

	/**@}*/

	/**
	 * \defgroup Graphics support methods
	 * @{
	 */

	byte init_gfx1(size_t size);

	byte init_gfx2(size_t size);

	/**
	 * Displays or hides a picture
	 * @param c			number of image to be displayed
	 * @param mode		0 = means gfx off, 1 gfx on thumbnails, 2 gfx on normal
	 *
	 * @remarks		For retrieving the raw data of a picture call ms_extract
	 */
	void ms_showpic(int c, byte mode);

	/**
	 * Returns true if a given line is blank
	 */
	bool is_blank(uint16 line, uint16 width) const;

	byte *ms_extract1(byte pic, uint16 *w, uint16 *h, uint16 *pal);

	int16 find_name_in_header(const Common::String &name, bool upper);

	void extract_frame(const picture *pic);

	byte *ms_extract2(const char *name, uint16 *w, uint16 *h, uint16 *pal, byte *is_anim);

	byte *ms_extract(uint32 pic, uint16 *w, uint16 *h, uint16 *pal, byte *is_anim);

	byte ms_animate(ms_position **positions, uint16 *count);

	byte *ms_get_anim_frame(int16 number, uint16 *width, uint16 *height, byte **mask);

	bool ms_anim_is_repeating() const { return anim_repeat;	}

	void write_reg(int i, int s, uint32 val) {
		// TODO
	}

	/**@}*/

	/**
	 * \defgroup Sound support methods
	 * @{
	 */

	byte init_snd(size_t size);

	int16 find_name_in_sndheader(const Common::String &name);

	byte *sound_extract(const Common::String &name, uint32 *length, uint16 *tempo);

	/**@}*/
public:
	/**
	 * Constructor
	 */
	Magnetic(OSystem *syst, const GlkGameDescription &gameDesc);

	/**
	 * Run the game
	 */
	void runGame();

	/**
	 * Returns the running interpreter type
	 */
	virtual InterpreterType getInterpreterType() const override { return INTERPRETER_GLULXE; }

	/**
	 * Load a savegame from the passed stream
	 */
	virtual Common::Error loadGameData(strid_t file) override;

	/**
	 * Save the game to the passed stream
	 */
	virtual Common::Error saveGameData(strid_t file, const Common::String &desc) override;
};

} // End of namespace Magnetic
} // End of namespace Glk

#endif