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 SCUMM_SCUMM_H
24 #define SCUMM_SCUMM_H
25 
26 #include "engines/engine.h"
27 
28 #include "common/endian.h"
29 #include "common/events.h"
30 #include "common/file.h"
31 #include "common/savefile.h"
32 #include "common/keyboard.h"
33 #include "common/random.h"
34 #include "common/rect.h"
35 #include "common/rendermode.h"
36 #include "common/serializer.h"
37 #include "common/str.h"
38 #include "common/textconsole.h"
39 #include "graphics/surface.h"
40 #include "graphics/sjis.h"
41 
42 #include "scumm/gfx.h"
43 #include "scumm/detection.h"
44 #include "scumm/script.h"
45 
46 #ifdef __DS__
47 /* This disables the dual layer mode which is used in FM-Towns versions
48  * of SCUMM games and which emulates the behavior of the original code.
49  * The only purpose is code size reduction for certain backends.
50  * SCUMM 3 (FM-Towns) games will run in English in normal (DOS VGA) mode,
51  * which should work just fine in most situations. Some glitches might
52  * occur. Japanese mode and SCUMM 5 FM-Towns games will not work without
53  * dual layer (and 16 bit color) support.
54  */
55 #define DISABLE_TOWNS_DUAL_LAYER_MODE
56 #endif
57 
58 namespace GUI {
59 class Dialog;
60 }
61 using GUI::Dialog;
62 namespace Common {
63 class SeekableReadStream;
64 class WriteStream;
65 }
66 
67 /**
68  * This is the namespace of the SCUMM engine.
69  *
70  * Status of this engine:
71  * Complete support for all SCUMM based LucasArts adventures.
72  * Complete support for many Humongous Entertainment games,
73  * but for some of the newer ones, this is still work in progress.
74  *
75  * Games using this engine:
76  * - Classic 2D LucasArts adventures
77  * - numerous Humongous Entertainment games
78  */
79 namespace Scumm {
80 
81 class Actor;
82 class BaseCostumeLoader;
83 class BaseCostumeRenderer;
84 class BaseScummFile;
85 class CharsetRenderer;
86 class IMuse;
87 class IMuseDigital;
88 class MusicEngine;
89 class Player_Towns;
90 class ScummEngine;
91 class ScummDebugger;
92 class Sound;
93 
94 struct Box;
95 struct BoxCoords;
96 struct FindObjectInRoom;
97 
98 // Use g_scumm from error() ONLY
99 extern ScummEngine *g_scumm;
100 
101 /* System Wide Constants */
102 enum {
103 	NUM_SENTENCE = 6,
104 	NUM_SHADOW_PALETTE = 8
105 };
106 
107 /**
108  * SCUMM feature flags define for every game which specific set of engine
109  * features are used by that game.
110  * Note that some of them could be replaced by checks for the SCUMM version.
111  */
112 enum GameFeatures {
113 	/** A demo, not a full blown game. */
114 	GF_DEMO                = 1 << 0,
115 
116 	/** Games with the AKOS costume system (ScummEngine_v7 and subclasses, HE games). */
117 	GF_NEW_COSTUMES        = 1 << 2,
118 
119 	/** Games using XOR encrypted data files. */
120 	GF_USE_KEY             = 1 << 4,
121 
122 	/** Small header games (ScummEngine_v4 and subclasses). */
123 	GF_SMALL_HEADER        = 1 << 5,
124 
125 	/** Old bundle games (ScummEngine_v3old and subclasses). */
126 	GF_OLD_BUNDLE          = 1 << 6,
127 
128 	/** EGA games. */
129 	GF_16COLOR             = 1 << 7,
130 
131 	/** VGA versions of V3 games.  Equivalent to (version == 3 && not GF_16COLOR) */
132 	GF_OLD256              = 1 << 8,
133 
134 	/** Games which have Audio CD tracks. */
135 	GF_AUDIOTRACKS         = 1 << 9,
136 
137 	/**
138 	 * Games using only very few local variables in scripts.
139 	 * Apparently that is only the case for 256 color version of Indy3.
140 	 */
141 	GF_FEW_LOCALS          = 1 << 11,
142 
143 	/** HE games for which localized versions exist */
144 	GF_HE_LOCALIZED        = 1 << 13,
145 
146 	/**
147 	 *  HE games with more global scripts and different sprite handling
148 	 *  i.e. read it as HE version 9.85. Used for HE98 only.
149 	 */
150 	GF_HE_985             = 1 << 14,
151 
152 	/** HE games with 16 bit color */
153 	GF_16BIT_COLOR         = 1 << 15,
154 
155 	/**
156 	 * SCUMM v5-v7 Mac games stored in a container file
157 	 * Used to differentiate between m68k and PPC versions of Indy4
158 	 */
159 	GF_MAC_CONTAINER       = 1 << 16
160 };
161 
162 /* SCUMM Debug Channels */
163 void debugC(int level, const char *s, ...) GCC_PRINTF(2, 3);
164 
165 enum {
166 	DEBUG_GENERAL	=	1 << 0,		// General debug
167 	DEBUG_SCRIPTS	=	1 << 2,		// Track script execution (start/stop/pause)
168 	DEBUG_OPCODES	=	1 << 3,		// Track opcode invocations
169 	DEBUG_VARS	=	1 << 4,		// Track variable changes
170 	DEBUG_RESOURCE	=	1 << 5,		// Track resource loading / allocation
171 	DEBUG_IMUSE	=	1 << 6,		// Track iMUSE events
172 	DEBUG_SOUND	=	1 << 7,		// General Sound Debug
173 	DEBUG_ACTORS	=	1 << 8,		// General Actor Debug
174 	DEBUG_INSANE	=	1 << 9,		// Track INSANE
175 	DEBUG_SMUSH	=	1 << 10,		// Track SMUSH
176 	DEBUG_MOONBASE_AI = 1 << 11		// Moonbase AI
177 };
178 
179 struct VerbSlot;
180 struct ObjectData;
181 
182 enum {
183 	/**
184 	 * Lighting flag that indicates whether the normal palette, or the 'dark'
185 	 * palette shall be used to draw actors.
186 	 * Apparantly only used in very old games (so far only NESCostumeRenderer
187 	 * checks it).
188 	 */
189 	LIGHTMODE_actor_use_base_palette	= 1 << 0,
190 
191 	/**
192 	 * Lighting flag that indicates whether the room is currently lit. Normally
193 	 * always on. Used for rooms in which the light can be switched "off".
194 	 */
195 	LIGHTMODE_room_lights_on			= 1 << 1,
196 
197 	/**
198 	 * Lighting flag that indicates whether a flashlight like device is active.
199 	 * Used in Loom (flashlight follows the actor) and Indy 3 (flashlight
200 	 * follows the mouse). Only has any effect if the room lights are off.
201 	 */
202 	LIGHTMODE_flashlight_on				= 1 << 2,
203 
204 	/**
205 	 * Lighting flag that indicates whether actors are to be drawn with their
206 	 * own custom palette, or using a fixed 'dark' palette. This is the
207 	 * modern successor of LIGHTMODE_actor_use_base_palette.
208 	 * Note: It is tempting to 'merge' these two flags, but since flags can
209 	 * check their values, this is probably not a good idea.
210 	 */
211 	LIGHTMODE_actor_use_colors	= 1 << 3
212 	//
213 };
214 
215 enum {
216 	MBS_LEFT_CLICK = 0x8000,
217 	MBS_RIGHT_CLICK = 0x4000,
218 	MBS_MOUSE_MASK = (MBS_LEFT_CLICK | MBS_RIGHT_CLICK),
219 	MBS_MAX_KEY	= 0x0200
220 };
221 
222 enum ScummGameId {
223 	GID_CMI,
224 	GID_DIG,
225 	GID_FT,
226 	GID_INDY3,
227 	GID_INDY4,
228 	GID_LOOM,
229 	GID_MANIAC,
230 	GID_MONKEY_EGA,
231 	GID_MONKEY_VGA,
232 	GID_MONKEY,
233 	GID_MONKEY2,
234 	GID_PASS,
235 	GID_SAMNMAX,
236 	GID_TENTACLE,
237 	GID_ZAK,
238 
239 	GID_HEGAME,      // Generic name for all HE games with default behavior
240 	GID_PUTTDEMO,
241 	GID_FBEAR,
242 	GID_PUTTMOON,
243 	GID_FUNPACK,
244 	GID_PUTTZOO,
245 	GID_FREDDI3,
246 	GID_BIRTHDAYRED,
247 	GID_BIRTHDAYYELLOW,
248 	GID_TREASUREHUNT,
249 	GID_PUTTRACE,
250 	GID_FUNSHOP,	// Used for all three funshops
251 	GID_FOOTBALL,
252 	GID_FOOTBALL2002,
253 	GID_SOCCER,
254 	GID_SOCCERMLS,
255 	GID_SOCCER2004,
256 	GID_BASEBALL2001,
257 	GID_BASEBALL2003,
258 	GID_BASKETBALL,
259 	GID_MOONBASE,
260 	GID_PJGAMES,
261 	GID_HECUP		// CUP demos
262 };
263 
264 struct SentenceTab {
265 	byte verb;
266 	byte preposition;
267 	uint16 objectA;
268 	uint16 objectB;
269 	uint8 freezeCount;
270 };
271 
272 struct StringSlot {
273 	int16 xpos;
274 	int16 ypos;
275 	int16 right;
276 	int16 height;
277 	byte color;
278 	byte charset;
279 	bool center;
280 	bool overhead;
281 	bool no_talk_anim;
282 	bool wrapping;
283 };
284 
285 struct StringTab : StringSlot {
286 	// The 'default' values for this string slot. This is used so that the
287 	// string slot can temporarily be set to different values, and then be
288 	// easily reset to a previously set default.
289 	StringSlot _default;
290 
saveDefaultStringTab291 	void saveDefault() {
292 		StringSlot &s = *this;
293 		_default = s;
294 	}
295 
loadDefaultStringTab296 	void loadDefault() {
297 		StringSlot &s = *this;
298 		s = _default;
299 	}
300 };
301 
302 struct ScummEngine_v0_Delays {
303 	bool _screenScroll;
304 	uint _objectRedrawCount;
305 	uint _objectStripRedrawCount;
306 	uint _actorRedrawCount;
307 	uint _actorLimbRedrawDrawCount;
308 
309 };
310 
311 enum WhereIsObject {
312 	WIO_NOT_FOUND = -1,
313 	WIO_INVENTORY = 0,
314 	WIO_ROOM = 1,
315 	WIO_GLOBAL = 2,
316 	WIO_LOCAL = 3,
317 	WIO_FLOBJECT = 4
318 };
319 
320 struct SaveStateMetaInfos {
321 	uint32 date;
322 	uint16 time;
323 	uint32 playtime;
324 };
325 
326 enum UserStates {
327 	USERSTATE_SET_FREEZE      = 0x01,   // freeze scripts if USERSTATE_FREEZE_ON is set, unfreeze otherwise
328 	USERSTATE_SET_CURSOR      = 0x02,   // shows cursor if USERSTATE_CURSOR_ON is set, hides it otherwise
329 	USERSTATE_SET_IFACE       = 0x04,   // change user-interface (sentence-line, inventory, verb-area)
330 	USERSTATE_FREEZE_ON       = 0x08,   // only interpreted if USERSTATE_SET_FREEZE is set
331 	USERSTATE_CURSOR_ON       = 0x10,   // only interpreted if USERSTATE_SET_CURSOR is set
332 	USERSTATE_IFACE_SENTENCE  = 0x20,   // only interpreted if USERSTATE_SET_IFACE is set
333 	USERSTATE_IFACE_INVENTORY = 0x40,   // only interpreted if USERSTATE_SET_IFACE is set
334 	USERSTATE_IFACE_VERBS     = 0x80    // only interpreted if USERSTATE_SET_IFACE is set
335 };
336 
337 #define USERSTATE_IFACE_ALL (USERSTATE_IFACE_SENTENCE | USERSTATE_IFACE_INVENTORY | USERSTATE_IFACE_VERBS)
338 
339 /**
340  * A list of resource types.
341  * WARNING: Do not change the order of these, as the savegame format relies
342  * on it; any change made here will break savegame compatibility!
343  */
344 enum ResType {
345 	rtInvalid = 0,
346 	rtFirst = 1,
347 	rtRoom = 1,
348 	rtScript = 2,
349 	rtCostume = 3,
350 	rtSound = 4,
351 	rtInventory = 5,
352 	rtCharset = 6,
353 	rtString = 7,
354 	rtVerb = 8,
355 	rtActorName = 9,
356 	rtBuffer = 10,
357 	rtScaleTable = 11,
358 	rtTemp = 12,
359 	rtFlObject = 13,
360 	rtMatrix = 14,
361 	rtBox = 15,
362 	rtObjectName = 16,
363 	rtRoomScripts = 17,
364 	rtRoomImage = 18,
365 	rtImage = 19,
366 	rtTalkie = 20,
367 	rtSpoolBuffer = 21,
368 	rtLast = 21
369 };
370 
371 typedef uint16 ResId;
372 
373 class ResourceManager;
374 
375 /**
376  * Base class for all SCUMM engines.
377  */
378 class ScummEngine : public Engine, public Common::Serializable {
379 	friend class ScummDebugger;
380 	friend class CharsetRenderer;
381 	friend class CharsetRendererTownsClassic;
382 	friend class ResourceManager;
383 
384 public:
385 	/* Put often used variables at the top.
386 	 * That results in a shorter form of the opcode
387 	 * on some architectures. */
388 	IMuse *_imuse;
389 	IMuseDigital *_imuseDigital;
390 	MusicEngine *_musicEngine;
391 	Player_Towns *_townsPlayer;
392 	Sound *_sound;
393 
394 	VerbSlot *_verbs;
395 	ObjectData *_objs;
396 	ScummDebugger *_debugger;
397 
398 	// Core variables
399 	GameSettings _game;
400 	uint8 _gameMD5[16];
401 
402 	/** Random number generator */
403 	Common::RandomSource _rnd;
404 
405 	/** Graphics manager */
406 	Gdi *_gdi;
407 
408 	/** Central resource data. */
409 	ResourceManager *_res;
410 
411 protected:
412 	VirtualMachineState vm;
413 
414 	bool _oldSoundsPaused;
415 
416 public:
417 	// Constructor / Destructor
418 	ScummEngine(OSystem *syst, const DetectorResult &dr);
419 	virtual ~ScummEngine();
420 
421 	// Engine APIs
422 	Common::Error init();
423 	Common::Error go();
run()424 	virtual Common::Error run() {
425 		Common::Error err;
426 		err = init();
427 		if (err.getCode() != Common::kNoError)
428 			return err;
429 		return go();
430 	}
431 	virtual void errorString(const char *buf_input, char *buf_output, int buf_output_size);
432 	virtual GUI::Debugger *getDebugger();
433 	virtual bool hasFeature(EngineFeature f) const;
434 	virtual void syncSoundSettings();
435 
436 	virtual Common::Error loadGameState(int slot);
437 	virtual bool canLoadGameStateCurrently();
438 	virtual Common::Error saveGameState(int slot, const Common::String &desc);
439 	virtual bool canSaveGameStateCurrently();
440 
441 	virtual void pauseEngineIntern(bool pause);
442 
443 protected:
444 	virtual void setupScumm();
445 	virtual void resetScumm();
446 
447 	virtual void setupScummVars();
448 	virtual void resetScummVars();
449 
450 	void setupCharsetRenderer();
451 	void setupCostumeRenderer();
452 
loadLanguageBundle()453 	virtual void loadLanguageBundle() {}
454 	void loadCJKFont();
455 	void setupMusic(int midi);
456 	void setTalkSpeed(int talkspeed);
457 	int getTalkSpeed();
458 
459 	// Scumm main loop & helper functions.
460 	virtual void scummLoop(int delta);
461 	virtual void scummLoop_updateScummVars();
462 	virtual void scummLoop_handleSaveLoad();
463 	virtual void scummLoop_handleDrawing();
464 	virtual void scummLoop_handleActors() = 0;
465 	virtual void scummLoop_handleEffects();
466 	virtual void scummLoop_handleSound();
467 
468 	virtual void runBootscript();
469 
470 	// Event handling
471 public:
472 	void parseEvents();	// Used by IMuseDigital::startSound
473 protected:
474 	virtual void parseEvent(Common::Event event);
475 
476 	void waitForTimer(int msec_delay);
477 	virtual void processInput();
478 	virtual void processKeyboard(Common::KeyState lastKeyHit);
479 	virtual void clearClickedStatus();
480 
481 	// Cursor/palette
482 	void updateCursor();
animateCursor()483 	virtual void animateCursor() {}
484 	virtual void updatePalette();
485 
resetCursors()486 	virtual void resetCursors() {}
487 
488 public:
489 	void pauseGame();
490 	void restart();
491 
492 protected:
493 	Dialog *_pauseDialog;
494 	Dialog *_messageDialog;
495 	Dialog *_versionDialog;
496 
497 	virtual int runDialog(Dialog &dialog);
498 	void confirmExitDialog();
499 	void confirmRestartDialog();
500 	void pauseDialog();
501 	void messageDialog(const char *message);
502 	void versionDialog();
503 
504 	char displayMessage(const char *altButton, const char *message, ...) GCC_PRINTF(3, 4);
505 
506 	byte _fastMode;
507 
508 	byte _numActors;
509 	Actor **_actors;	// Has _numActors elements
510 	Actor **_sortedActors;
511 
512 	byte *_arraySlot;
513 	uint16 *_inventory;
514 	uint16 *_newNames;
515 public:
516 	// VAR is a wrapper around scummVar, which attempts to include additional
517 	// useful information should an illegal var access be detected.
518 	#define VAR(x)	scummVar(x, #x, __FILE__, __LINE__)
scummVar(byte var,const char * varName,const char * file,int line)519 	int32& scummVar(byte var, const char *varName, const char *file, int line) {
520 		if (var == 0xFF) {
521 			error("Illegal access to variable %s in file %s, line %d", varName, file, line);
522 		}
523 		return _scummVars[var];
524 	}
scummVar(byte var,const char * varName,const char * file,int line)525 	int32 scummVar(byte var, const char *varName, const char *file, int line) const {
526 		if (var == 0xFF) {
527 			error("Illegal access to variable %s in file %s, line %d", varName, file, line);
528 		}
529 		return _scummVars[var];
530 	}
531 
532 protected:
533 	int16 _varwatch;
534 	int32 *_roomVars;
535 	int32 *_scummVars;
536 	byte *_bitVars;
537 
538 	/* Global resource tables */
539 	int _numVariables, _numBitVariables, _numLocalObjects;
540 	int _numGlobalObjects, _numArray, _numVerbs, _numFlObject;
541 	int _numInventory;
542 	int _numNewNames, _numGlobalScripts;
543 	int _numRoomVariables;
544 	int _numPalettes, _numSprites, _numTalkies, _numUnk;
545 	int _HEHeapSize;
546 public:
547 	int _numLocalScripts, _numImages, _numRooms, _numScripts, _numSounds;	// Used by HE games
548 	int _numCostumes;	// FIXME - should be protected, used by Actor::remapActorPalette
549 	int32 _numCharsets;	// FIXME - should be protected, used by CharsetRenderer
550 
551 	BaseCostumeLoader *_costumeLoader;
552 	BaseCostumeRenderer *_costumeRenderer;
553 
554 	int _NESCostumeSet;
555 	void NES_loadCostumeSet(int n);
556 	byte *_NEScostdesc, *_NEScostlens, *_NEScostoffs, *_NEScostdata;
557 	byte _NESPatTable[2][4096];
558 	byte _NESPalette[2][16];
559 	byte _NESBaseTiles;
560 
561 	int _NESStartStrip;
562 
563 protected:
564 	int _curPalIndex;
565 
566 public:
567 	byte _currentRoom;	// FIXME - should be protected but Actor::isInCurrentRoom uses it
568 	int _roomResource;  // FIXME - should be protected but Sound::pauseSounds uses it
569 	bool _egoPositioned;	// Used by Actor::putActor, hence public
570 
571 	FilenamePattern _filenamePattern;
572 
573 	virtual Common::String generateFilename(const int room) const;
574 
575 protected:
576 	Common::KeyState _keyPressed;
577 	bool _keyDownMap[512]; // FIXME - 512 is a guess. it's max(kbd.ascii)
578 
579 	Common::Point _mouse;
580 	Common::Point _virtualMouse;
581 
582 	uint16 _mouseAndKeyboardStat;
583 	byte _leftBtnPressed, _rightBtnPressed;
584 
585 	/**
586 	 * Last time runInputScript was run (measured in terms of OSystem::getMillis()).
587 	 * This is currently only used for Indy3 mac to detect "double clicks".
588 	 */
589 	uint32 _lastInputScriptTime;
590 
591 	/** The bootparam, to be passed to the script 1, the bootscript. */
592 	int _bootParam;
593 
594 	// Various options useful for debugging
595 	bool _dumpScripts;
596 	bool _hexdumpScripts;
597 	bool _showStack;
598 	bool _debugMode;
599 
600 	// Save/Load class - some of this may be GUI
601 	byte _saveLoadFlag, _saveLoadSlot;
602 	uint32 _lastSaveTime;
603 	bool _saveTemporaryState;
604 	Common::String _saveLoadFileName;
605 	Common::String _saveLoadDescription;
606 
607 	bool saveState(Common::WriteStream *out, bool writeHeader = true);
608 	bool saveState(int slot, bool compat, Common::String &fileName);
609 	bool loadState(int slot, bool compat);
610 	bool loadState(int slot, bool compat, Common::String &fileName);
611 	virtual void saveLoadWithSerializer(Common::Serializer &s);
612 	void saveResource(Common::Serializer &ser, ResType type, ResId idx);
613 	void loadResource(Common::Serializer &ser, ResType type, ResId idx);
614 	void loadResourceOLD(Common::Serializer &ser, ResType type, ResId idx);	// "Obsolete"
615 
616 	virtual Common::SeekableReadStream *openSaveFileForReading(int slot, bool compat, Common::String &fileName);
617 	virtual Common::WriteStream *openSaveFileForWriting(int slot, bool compat, Common::String &fileName);
618 
makeSavegameName(int slot,bool temporary)619 	Common::String makeSavegameName(int slot, bool temporary) const {
620 		return makeSavegameName(_targetName, slot, temporary);
621 	}
622 
623 	int getKeyState(int key);
624 
625 public:
626 	static Common::String makeSavegameName(const Common::String &target, int slot, bool temporary);
627 
628 	bool getSavegameName(int slot, Common::String &desc);
629 	void listSavegames(bool *marks, int num);
630 
631 	void requestSave(int slot, const Common::String &name);
632 	void requestLoad(int slot);
633 
getTargetName()634 	Common::String getTargetName() const { return _targetName; }
635 
636 // thumbnail + info stuff
637 public:
638 	static bool querySaveMetaInfos(const char *target, int slot, int heversion, Common::String &desc, Graphics::Surface *&thumbnail, SaveStateMetaInfos *&timeInfos);
639 
640 protected:
641 	void saveInfos(Common::WriteStream *file);
642 	static bool loadInfos(Common::SeekableReadStream *file, SaveStateMetaInfos *stuff);
643 
644 protected:
645 	/* Script VM - should be in Script class */
646 	uint32 _localScriptOffsets[1024];
647 	const byte *_scriptPointer;
648 	const byte *_scriptOrgPointer;
649 	const byte * const *_lastCodePtr;
650 	byte _opcode;
651 	byte _currentScript;
652 	int _scummStackPos;
653 	int _vmStack[256];
654 
655 	OpcodeEntry _opcodes[256];
656 
657 	virtual void setupOpcodes() = 0;
658 	void executeOpcode(byte i);
659 	const char *getOpcodeDesc(byte i);
660 
661 	void initializeLocals(int slot, int *vars);
662 	int	getScriptSlot();
663 
664 	void startScene(int room, Actor *a, int b);
665 	bool startManiac();
666 
667 public:
668 	void runScript(int script, bool freezeResistant, bool recursive, int *lvarptr, int cycle = 0);
669 	void stopScript(int script);
670 	void nukeArrays(byte scriptSlot);
671 
672 protected:
673 	void runObjectScript(int script, int entry, bool freezeResistant, bool recursive, int *vars, int slot = -1, int cycle = 0);
674 	void runScriptNested(int script);
675 	void executeScript();
676 	void updateScriptPtr();
677 	virtual void runInventoryScript(int i);
678 	void inventoryScriptIndy3Mac();
679 	virtual void checkAndRunSentenceScript();
680 	void runExitScript();
681 	void runEntryScript();
682 	void runQuitScript();
683 	void runAllScripts();
684 	void freezeScripts(int scr);
685 	void unfreezeScripts();
686 
687 	bool isScriptInUse(int script) const;
688 	bool isRoomScriptRunning(int script) const;
689 	bool isScriptRunning(int script) const;
690 
691 	void killAllScriptsExceptCurrent();
692 	void killScriptsAndResources();
693 	void decreaseScriptDelay(int amount);
694 
695 	void stopObjectCode();
696 	void stopObjectScript(int script);
697 
698 	void getScriptBaseAddress();
699 	void resetScriptPointer();
700 	int getVerbEntrypoint(int obj, int entry);
701 
702 	void refreshScriptPointer();
703 	byte fetchScriptByte();
704 	virtual uint fetchScriptWord();
705 	virtual int fetchScriptWordSigned();
706 	uint fetchScriptDWord();
707 	int fetchScriptDWordSigned();
ignoreScriptWord()708 	void ignoreScriptWord() { fetchScriptWord(); }
ignoreScriptByte()709 	void ignoreScriptByte() { fetchScriptByte(); }
710 	void push(int a);
711 	int pop();
712 	virtual int readVar(uint var);
713 	virtual void writeVar(uint var, int value);
714 
715 protected:
716 	void beginCutscene(int *args);
717 	void endCutscene();
718 	void abortCutscene();
719 	void beginOverride();
720 	void endOverride();
721 
722 	void copyScriptString(byte *dst);
723 	int resStrLen(const byte *src);
724 	void doSentence(int c, int b, int a);
725 
726 	/* Should be in Resource class */
727 	BaseScummFile *_fileHandle;
728 	uint32 _fileOffset;
729 public:
730 	/** The name of the (macintosh/rescumm style) container file, if any. */
731 	Common::String _containerFile;
732 
733 	bool openFile(BaseScummFile &file, const Common::String &filename, bool resourceFile = false);
734 
735 	/** Is this game a Mac m68k v5 game with iMuse? */
736 	bool isMacM68kIMuse() const;
737 
738 protected:
739 	int _resourceHeaderSize;
740 	byte _resourceMapper[128];
741 	const byte *_resourceLastSearchBuf; // FIXME: need to put it to savefile?
742 	uint32 _resourceLastSearchSize;    // FIXME: need to put it to savefile?
743 
744 	virtual void allocateArrays();
745 	void openRoom(int room);
746 	void closeRoom();
747 	void deleteRoomOffsets();
748 	virtual void readRoomsOffsets();
749 	void askForDisk(const char *filename, int disknum);	// TODO: Use Common::String
750 	bool openResourceFile(const Common::String &filename, byte encByte);	// TODO: Use Common::String
751 
752 	void loadPtrToResource(ResType type, ResId idx, const byte *ptr);
753 	virtual int readResTypeList(ResType type);
754 //	void allocResTypeData(ResType type, uint32 tag, int num, int mode);
755 //	byte *createResource(int type, int index, uint32 size);
756 	int loadResource(ResType type, ResId idx);
757 //	void nukeResource(ResType type, ResId idx);
758 	int getResourceRoomNr(ResType type, ResId idx);
759 	virtual uint32 getResourceRoomOffset(ResType type, ResId idx);
760 	int getResourceSize(ResType type, ResId idx);
761 
762 public:
763 	byte *getResourceAddress(ResType type, ResId idx);
764 	virtual byte *getStringAddress(ResId idx);
765 	byte *getStringAddressVar(int i);
766 	void ensureResourceLoaded(ResType type, ResId idx);
767 
768 protected:
769 	int readSoundResource(ResId idx);
770 	int readSoundResourceSmallHeader(ResId idx);
771 	bool isResourceInUse(ResType type, ResId idx) const;
772 
773 	virtual void setupRoomSubBlocks();
774 	virtual void resetRoomSubBlocks();
775 
776 	virtual void clearRoomObjects();
777 	virtual void resetRoomObjects();
778 	virtual void resetRoomObject(ObjectData *od, const byte *room, const byte *searchptr = NULL);
779 
780 	virtual void readArrayFromIndexFile();
781 	virtual void readMAXS(int blockSize) = 0;
782 	virtual void readGlobalObjects();
783 	virtual void readIndexFile();
784 	virtual void readIndexBlock(uint32 block, uint32 itemsize);
785 	virtual void loadCharset(int i);
786 	void nukeCharset(int i);
787 
788 	int _lastLoadedRoom;
789 public:
790 	const byte *findResourceData(uint32 tag, const byte *ptr);
791 	const byte *findResource(uint32 tag, const byte *ptr);
792 	int getResourceDataSize(const byte *ptr) const;
793 	void dumpResource(const char *tag, int index, const byte *ptr, int length = -1);
794 
795 public:
796 	/* Should be in Object class */
797 	byte OF_OWNER_ROOM;
798 	int getInventorySlot();
799 	int findInventory(int owner, int index);
800 	int getInventoryCount(int owner);
801 
802 protected:
803 	byte *_objectOwnerTable, *_objectRoomTable, *_objectStateTable;
804 	int _numObjectsInRoom;
805 
806 public:
807 	uint32 *_classData;
808 
809 protected:
810 	void markObjectRectAsDirty(int obj);
811 	virtual void loadFlObject(uint object, uint room);
812 	void nukeFlObjects(int min, int max);
813 	int findFlObjectSlot();
814 	int findLocalObjectSlot();
815 	void addObjectToInventory(uint obj, uint room);
816 	void updateObjectStates();
817 public:
818 	bool getClass(int obj, int cls) const;		// Used in actor.cpp, hence public
819 protected:
820 	void putClass(int obj, int cls, bool set);
821 	int getState(int obj);
822 	void putState(int obj, int state);
823 	void setObjectState(int obj, int state, int x, int y);
824 	int getOwner(int obj) const;
825 	void putOwner(int obj, int owner);
826 	void setOwnerOf(int obj, int owner);
827 	void clearOwnerOf(int obj);
828 	int getObjectRoom(int obj) const;
829 	virtual bool objIsActor(int obj);
830 	virtual int objToActor(int obj);
831 	virtual int actorToObj(int actor);
832 	int getObjX(int obj);
833 	int getObjY(int obj);
getObjectXYPos(int object,int & x,int & y)834 	void getObjectXYPos(int object, int &x, int &y)	{ int dir; getObjectXYPos(object, x, y, dir); }
835 	void getObjectXYPos(int object, int &x, int &y, int &dir);
836 	int getObjOldDir(int obj);
837 	int getObjNewDir(int obj);
838 	int getObjectIndex(int object) const;
839 	int getObjectImageCount(int object);
840 	int whereIsObject(int object) const;
841 	int findObject(int x, int y);
842 	void findObjectInRoom(FindObjectInRoom *fo, byte findWhat, uint object, uint room);
843 public:
844 	int getObjectOrActorXY(int object, int &x, int &y);	// Used in actor.cpp, hence public
845 	int getDist(int x, int y, int x2, int y2);	// Also used in actor.cpp
846 protected:
847 
848 	int getObjActToObjActDist(int a, int b); // Not sure how to handle
849 	const byte *getObjOrActorName(int obj);		 // these three..
850 	void setObjectName(int obj);
851 
852 	void addObjectToDrawQue(int object);
853 	void removeObjectFromDrawQue(int object);
854 	void clearDrawObjectQueue();
855 	void processDrawQue();
856 
857 	virtual void clearDrawQueues();
858 
859 	uint32 getOBCDOffs(int object) const;
860 	byte *getOBCDFromObject(int obj, bool v0CheckInventory = true);
861 	const byte *getOBIMFromObjectData(const ObjectData &od);
862 	const byte *getObjectImage(const byte *ptr, int state);
863 	virtual int getObjectIdFromOBIM(const byte *obim);
864 
865 protected:
866 	/* Should be in Verb class */
867 	uint16 _verbMouseOver;
868 	int8 _userPut;
869 	uint16 _userState;
870 
871 	virtual void handleMouseOver(bool updateInventory);
872 	virtual void redrawVerbs();
873 	virtual void checkExecVerbs();
874 
875 	void verbMouseOver(int verb);
876 	int findVerbAtPos(int x, int y) const;
877 	virtual void drawVerb(int verb, int mode);
878 	virtual void runInputScript(int clickArea, int val, int mode);
879 	void restoreVerbBG(int verb);
880 	void drawVerbBitmap(int verb, int x, int y);
881 	int getVerbSlot(int id, int mode) const;
882 	void killVerb(int slot);
883 	void setVerbObject(uint room, uint object, uint verb);
884 
885 public:
886 	bool isValidActor(int id) const;
887 
888 	/* Should be in Actor class */
889 	Actor *derefActor(int id, const char *errmsg = 0) const;
890 	Actor *derefActorSafe(int id, const char *errmsg) const;
891 
892 protected:
893 	void walkActors();
894 	void playActorSounds();
895 	void redrawAllActors();
896 	void setActorRedrawFlags();
897 	void putActors();
898 	void showActors();
899 	void resetV1ActorTalkColor();
900 	void resetActorBgs();
901 	virtual void processActors();
902 	void processUpperActors();
903 	virtual int getActorFromPos(int x, int y);
904 
905 public:
906 	/* Actor talking stuff */
907 	byte _actorToPrintStrFor, _V1TalkingActor;
908 	int _sentenceNum;
909 	SentenceTab _sentence[NUM_SENTENCE];
910 	StringTab _string[6];
911 	byte _haveMsg;
912 	int16 _talkDelay;
913 	int _NES_lastTalkingActor;
914 	int _NES_talkColor;
915 
916 	virtual void actorTalk(const byte *msg);
917 	void stopTalk();
918 	int getTalkingActor();		// Wrapper around VAR_TALK_ACTOR for V1 Maniac
919 	void setTalkingActor(int variable);
920 
921 	// Generic costume code
922 	bool isCostumeInUse(int i) const;
923 
924 protected:
925 	/* Should be in Graphics class? */
926 	uint16 _screenB, _screenH;
927 public:
928 	int _roomHeight, _roomWidth;
929 	int _screenHeight, _screenWidth;
930 	VirtScreen _virtscr[4];		// Virtual screen areas
931 	CameraData camera;			// 'Camera' - viewport
932 
933 	int _screenStartStrip, _screenEndStrip;
934 	int _screenTop;
935 
936 	Common::RenderMode _renderMode;
937 	uint8 _bytesPerPixel;
938 	Graphics::PixelFormat _outputPixelFormat;
939 
940 protected:
941 	ColorCycle _colorCycle[16];	// Palette cycles
942 	uint8 _colorUsedByCycle[256];
943 
944 	uint32 _ENCD_offs, _EXCD_offs;
945 	uint32 _CLUT_offs, _EPAL_offs;
946 	uint32 _IM00_offs, _PALS_offs;
947 
948 	//ender: fullscreen
949 	bool _fullRedraw, _bgNeedsRedraw;
950 	bool _screenEffectFlag, _completeScreenRedraw;
951 	bool _disableFadeInEffect;
952 
953 	struct {
954 		int hotspotX, hotspotY, width, height;
955 		byte animate, animateIndex;
956 		int8 state;
957 	} _cursor;
958 
959 	// HACK Double the array size to handle 16-bit images.
960 	// this should be dynamically allocated based on game depth instead.
961 	byte _grabbedCursor[16384];
962 	byte _currentCursor;
963 
964 	byte _newEffect, _switchRoomEffect2, _switchRoomEffect;
965 	bool _doEffect;
966 
967 	bool _snapScroll;
968 public:
969 	bool isLightOn() const;
970 
971 	virtual int getCurrentLights() const;
972 
973 protected:
974 	void initScreens(int b, int h);
975 	void initVirtScreen(VirtScreenNumber slot, int top, int width, int height, bool twobufs, bool scrollable);
976 	void initBGBuffers(int height);
977 	void initCycl(const byte *ptr);	// Color cycle
978 
979 	void decodeNESBaseTiles();
980 
981 	void drawObject(int obj, int arg);
982 	void drawRoomObjects(int arg);
983 	void drawRoomObject(int i, int arg);
984 	void drawBox(int x, int y, int x2, int y2, int color);
985 
986 	void moveScreen(int dx, int dy, int height);
987 
988 	void restoreBackground(Common::Rect rect, byte backcolor = 0);
989 	void redrawBGStrip(int start, int num);
990 	virtual void redrawBGAreas();
991 
992 	void cameraMoved();
993 	void setCameraAtEx(int at);
994 	virtual void setCameraAt(int pos_x, int pos_y);
995 	virtual void setCameraFollows(Actor *a, bool setCamera = false);
996 	virtual void moveCamera();
997 	virtual void panCameraTo(int x, int y);
998 	void clampCameraPos(Common::Point *pt);
999 	void actorFollowCamera(int act);
1000 
1001 	const byte *getPalettePtr(int palindex, int room);
1002 
1003 	void setPaletteFromTable(const byte *ptr, int numcolor, int firstIndex = 0);
1004 	void resetPalette();
1005 
1006 	void setCurrentPalette(int pal);
1007 	void setRoomPalette(int pal, int room);
1008 	void setPCEPaletteFromPtr(const byte *ptr);
1009 	void setAmigaPaletteFromPtr(const byte *ptr);
1010 	virtual void setPaletteFromPtr(const byte *ptr, int numcolor = -1);
1011 
1012 	virtual void setPalColor(int index, int r, int g, int b);
1013 	void setDirtyColors(int min, int max);
1014 	const byte *findPalInPals(const byte *pal, int index);
1015 	void swapPalColors(int a, int b);
1016 	virtual void copyPalColor(int dst, int src);
1017 	void cyclePalette();
1018 	void stopCycle(int i);
1019 	virtual void palManipulateInit(int resID, int start, int end, int time);
1020 	void palManipulate();
1021 public:
1022 	uint8 *getHEPaletteSlot(uint16 palSlot);
1023 	uint16 get16BitColor(uint8 r, uint8 g, uint8 b);
1024 	int remapPaletteColor(int r, int g, int b, int threshold);		// Used by Actor::remapActorPalette
1025 	void readPCEPalette(const byte **ptr, byte **dest, int numEntries);
1026 	void colorPCEToRGB(uint16 color, byte *r, byte *g, byte *b);
1027 	void setPCETextPalette(uint8 color);
1028 protected:
1029 	void moveMemInPalRes(int start, int end, byte direction);
1030 	void setShadowPalette(int slot, int redScale, int greenScale, int blueScale, int startColor, int endColor);
1031 	void setShadowPalette(int redScale, int greenScale, int blueScale, int startColor, int endColor, int start, int end);
1032 	virtual void darkenPalette(int redScale, int greenScale, int blueScale, int startColor, int endColor);
1033 
1034 	void setCursorFromBuffer(const byte *ptr, int width, int height, int pitch);
1035 
1036 public:
1037 	void markRectAsDirty(VirtScreenNumber virt, int left, int right, int top, int bottom, int dirtybit = 0);
1038 	void markRectAsDirty(VirtScreenNumber virt, const Common::Rect& rect, int dirtybit = 0) {
1039 		markRectAsDirty(virt, rect.left, rect.right, rect.top, rect.bottom, dirtybit);
1040 	}
1041 protected:
1042 	// Screen rendering
1043 	byte *_compositeBuf;
1044 	byte *_herculesBuf;
1045 
1046 	virtual void drawDirtyScreenParts();
1047 	void updateDirtyScreen(VirtScreenNumber slot);
1048 	void drawStripToScreen(VirtScreen *vs, int x, int w, int t, int b);
1049 	void ditherCGA(byte *dst, int dstPitch, int x, int y, int width, int height) const;
1050 
1051 public:
1052 	VirtScreen *findVirtScreen(int y);
1053 	byte *getMaskBuffer(int x, int y, int z);
1054 
1055 protected:
1056 	void fadeIn(int effect);
1057 	void fadeOut(int effect);
1058 	void setScrollBuffer();
1059 
1060 	void unkScreenEffect6();
1061 	void transitionEffect(int a);
1062 	void dissolveEffect(int width, int height);
1063 	void scrollEffect(int dir);
1064 
1065 protected:
1066 	bool _shakeEnabled;
1067 	uint _shakeFrame;
1068 	void setShake(int mode);
1069 
1070 	int _drawObjectQueNr;
1071 	byte _drawObjectQue[200];
1072 
1073 	/* For each of the 410 screen strips, gfxUsageBits contains a
1074 	 * bitmask. The lower 80 bits each correspond to one actor and
1075 	 * signify if any part of that actor is currently contained in
1076 	 * that strip.
1077 	 *
1078 	 * If the leftmost bit is set, the strip (background) is dirty
1079 	 * needs to be redrawn.
1080 	 *
1081 	 * The second leftmost bit is set by removeBlastObject() and
1082 	 * restoreBackground(), but I'm not yet sure why.
1083 	 */
1084 	uint32 gfxUsageBits[410 * 3];
1085 
1086 	void upgradeGfxUsageBits();
1087 	void setGfxUsageBit(int strip, int bit);
1088 	void clearGfxUsageBit(int strip, int bit);
1089 	bool testGfxUsageBit(int strip, int bit);
1090 	bool testGfxAnyUsageBits(int strip);
1091 	bool testGfxOtherUsageBits(int strip, int bit);
1092 
1093 public:
1094 	byte _roomPalette[256];
1095 	byte *_shadowPalette;
1096 	bool _skipDrawObject;
1097 	int _voiceMode;
1098 
1099 	// HE specific
1100 	byte _HEV7ActorPalette[256];
1101 	uint8 *_hePalettes;
1102 	uint16 _hePaletteSlot;
1103 	uint16 *_16BitPalette;
1104 
1105 	// Indy4 Amiga specific
1106 	byte *_verbPalette;
1107 
1108 	ScummEngine_v0_Delays _V0Delay;
1109 
1110 protected:
1111 	int _shadowPaletteSize;
1112 	byte _currentPalette[3 * 256];
1113 	byte _darkenPalette[3 * 256];
1114 
1115 	int _palDirtyMin, _palDirtyMax;
1116 
1117 	byte _palManipStart, _palManipEnd;
1118 	uint16 _palManipCounter;
1119 	byte *_palManipPalette;
1120 	byte *_palManipIntermediatePal;
1121 
1122 	bool _haveActorSpeechMsg;
1123 	bool _useTalkAnims;
1124 	uint16 _defaultTalkDelay;
1125 	int _saveSound;
1126 	bool _native_mt32;
1127 	bool _enable_gs;
1128 	bool _copyProtection;
1129 
1130 	// Indy4 Amiga specific
1131 	uint16 _amigaFirstUsedColor;
1132 	byte _amigaPalette[3 * 64];
1133 	void amigaPaletteFindFirstUsedColor();
1134 	void mapRoomPalette(int idx);
1135 	int remapRoomPaletteColor(int r, int g, int b);
1136 	void mapVerbPalette(int idx);
1137 	int remapVerbPaletteColor(int r, int g, int b);
1138 
1139 public:
1140 	uint16 _extraBoxFlags[65];
1141 
1142 	byte getNumBoxes();
1143 	byte *getBoxMatrixBaseAddr();
1144 	byte *getBoxConnectionBase(int box);
1145 
1146 	int getNextBox(byte from, byte to);
1147 
1148 	void setBoxFlags(int box, int val);
1149 	void setBoxScale(int box, int b);
1150 
1151 	bool checkXYInBoxBounds(int box, int x, int y);
1152 
1153 	BoxCoords getBoxCoordinates(int boxnum);
1154 
1155 	byte getMaskFromBox(int box);
1156 	Box *getBoxBaseAddr(int box);
1157 	byte getBoxFlags(int box);
1158 	int getBoxScale(int box);
1159 
1160 	int getScale(int box, int x, int y);
1161 	int getScaleFromSlot(int slot, int x, int y);
1162 
1163 protected:
1164 	// Scaling slots/items
1165 	struct ScaleSlot {
1166 		int x1, y1, scale1;
1167 		int x2, y2, scale2;
1168 	};
1169 	friend void syncWithSerializer(Common::Serializer &, ScaleSlot &);
1170 	ScaleSlot _scaleSlots[20];
1171 	void setScaleSlot(int slot, int x1, int y1, int scale1, int x2, int y2, int scale2);
1172 	void setBoxScaleSlot(int box, int slot);
1173 	void convertScaleTableToScaleSlot(int slot);
1174 
1175 	void calcItineraryMatrix(byte *itineraryMatrix, int num);
1176 	void createBoxMatrix();
1177 	virtual bool areBoxesNeighbors(int i, int j);
1178 
1179 	/* String class */
1180 public:
1181 	CharsetRenderer *_charset;
1182 	byte _charsetColorMap[16];
1183 
1184 	/**
1185 	 * All text is normally rendered into this overlay surface. Then later
1186 	 * drawStripToScreen() composits it over the game graphics.
1187 	 */
1188 	Graphics::Surface _textSurface;
1189 	int _textSurfaceMultiplier;
1190 
1191 protected:
1192 	byte _charsetColor;
1193 	byte _charsetData[23][16];
1194 
1195 	int _charsetBufPos;
1196 	byte _charsetBuffer[512];
1197 
1198 	bool _keepText;
1199 	byte _msgCount;
1200 
1201 	int _nextLeft, _nextTop;
1202 
1203 	void restoreCharsetBg();
1204 	void clearCharsetMask();
1205 	void clearTextSurface();
1206 
1207 	virtual void initCharset(int charset);
1208 
1209 	virtual void printString(int m, const byte *msg);
1210 
1211 	virtual bool handleNextCharsetCode(Actor *a, int *c);
1212 	virtual void CHARSET_1();
1213 	bool newLine();
1214 	void drawString(int a, const byte *msg);
1215 	void debugMessage(const byte *msg);
1216 	void showMessageDialog(const byte *msg);
1217 
1218 	virtual int convertMessageToString(const byte *msg, byte *dst, int dstSize);
1219 	int convertIntMessage(byte *dst, int dstSize, int var);
1220 	int convertVerbMessage(byte *dst, int dstSize, int var);
1221 	int convertNameMessage(byte *dst, int dstSize, int var);
1222 	int convertStringMessage(byte *dst, int dstSize, int var);
1223 
1224 public:
1225 	Common::Language _language;	// Accessed by a hack in NutRenderer::loadFont
1226 
1227 	// Used by class ScummDialog:
1228 	virtual void translateText(const byte *text, byte *trans_buff);
1229 
1230 	// Somewhat hackish stuff for 2 byte support (Chinese/Japanese/Korean)
1231 	bool _useCJKMode;
1232 	int _2byteHeight;
1233 	int _2byteWidth;
1234 	byte _newLineCharacter;
1235 	byte *get2byteCharPtr(int idx);
1236 
1237 protected:
1238 	byte *_2byteFontPtr;
1239 
1240 public:
1241 
1242 	/* Scumm Vars */
1243 	byte VAR_KEYPRESS;
1244 	byte VAR_SYNC;
1245 	byte VAR_EGO;
1246 	byte VAR_CAMERA_POS_X;
1247 	byte VAR_HAVE_MSG;
1248 	byte VAR_ROOM;
1249 	byte VAR_OVERRIDE;
1250 	byte VAR_MACHINE_SPEED;
1251 	byte VAR_ME;
1252 	byte VAR_NUM_ACTOR;
1253 	byte VAR_CURRENT_LIGHTS;
1254 	byte VAR_CURRENTDRIVE;
1255 	byte VAR_CURRENTDISK;
1256 	byte VAR_TMR_1;
1257 	byte VAR_TMR_2;
1258 	byte VAR_TMR_3;
1259 	byte VAR_MUSIC_TIMER;
1260 	byte VAR_ACTOR_RANGE_MIN;
1261 	byte VAR_ACTOR_RANGE_MAX;
1262 	byte VAR_CAMERA_MIN_X;
1263 	byte VAR_CAMERA_MAX_X;
1264 	byte VAR_TIMER_NEXT;
1265 	byte VAR_VIRT_MOUSE_X;
1266 	byte VAR_VIRT_MOUSE_Y;
1267 	byte VAR_ROOM_RESOURCE;
1268 	byte VAR_LAST_SOUND;
1269 	byte VAR_CUTSCENEEXIT_KEY;
1270 	byte VAR_OPTIONS_KEY;
1271 	byte VAR_TALK_ACTOR;
1272 	byte VAR_CAMERA_FAST_X;
1273 	byte VAR_SCROLL_SCRIPT;
1274 	byte VAR_ENTRY_SCRIPT;
1275 	byte VAR_ENTRY_SCRIPT2;
1276 	byte VAR_EXIT_SCRIPT;
1277 	byte VAR_EXIT_SCRIPT2;
1278 	byte VAR_VERB_SCRIPT;
1279 	byte VAR_SENTENCE_SCRIPT;
1280 	byte VAR_INVENTORY_SCRIPT;
1281 	byte VAR_CUTSCENE_START_SCRIPT;
1282 	byte VAR_CUTSCENE_END_SCRIPT;
1283 	byte VAR_CHARINC;
1284 	byte VAR_WALKTO_OBJ;
1285 	byte VAR_DEBUGMODE;
1286 	byte VAR_HEAPSPACE;
1287 	byte VAR_RESTART_KEY;
1288 	byte VAR_PAUSE_KEY;
1289 	byte VAR_MOUSE_X;
1290 	byte VAR_MOUSE_Y;
1291 	byte VAR_TIMER;
1292 	byte VAR_TIMER_TOTAL;
1293 	byte VAR_SOUNDCARD;
1294 	byte VAR_VIDEOMODE;
1295 	byte VAR_MAINMENU_KEY;
1296 	byte VAR_FIXEDDISK;
1297 	byte VAR_CURSORSTATE;
1298 	byte VAR_USERPUT;
1299 	byte VAR_SOUNDRESULT;
1300 	byte VAR_TALKSTOP_KEY;
1301 	byte VAR_FADE_DELAY;
1302 	byte VAR_NOSUBTITLES;
1303 
1304 	// V5+
1305 	byte VAR_SOUNDPARAM;
1306 	byte VAR_SOUNDPARAM2;
1307 	byte VAR_SOUNDPARAM3;
1308 	byte VAR_INPUTMODE;
1309 	byte VAR_MEMORY_PERFORMANCE;
1310 	byte VAR_VIDEO_PERFORMANCE;
1311 	byte VAR_ROOM_FLAG;
1312 	byte VAR_GAME_LOADED;
1313 	byte VAR_NEW_ROOM;
1314 
1315 	// V4/V5
1316 	byte VAR_V5_TALK_STRING_Y;
1317 
1318 	// V6+
1319 	byte VAR_ROOM_WIDTH;
1320 	byte VAR_ROOM_HEIGHT;
1321 	byte VAR_SUBTITLES;
1322 	byte VAR_V6_EMSSPACE;
1323 
1324 	// V7/V8 specific variables
1325 	byte VAR_CAMERA_POS_Y;
1326 	byte VAR_CAMERA_MIN_Y;
1327 	byte VAR_CAMERA_MAX_Y;
1328 	byte VAR_CAMERA_THRESHOLD_X;
1329 	byte VAR_CAMERA_THRESHOLD_Y;
1330 	byte VAR_CAMERA_SPEED_X;
1331 	byte VAR_CAMERA_SPEED_Y;
1332 	byte VAR_CAMERA_ACCEL_X;
1333 	byte VAR_CAMERA_ACCEL_Y;
1334 	byte VAR_CAMERA_DEST_X;
1335 	byte VAR_CAMERA_DEST_Y;
1336 	byte VAR_CAMERA_FOLLOWED_ACTOR;
1337 
1338 	// V7/V8 specific variables
1339 	byte VAR_VERSION_KEY;
1340 	byte VAR_DEFAULT_TALK_DELAY;
1341 	byte VAR_CUSTOMSCALETABLE;
1342 	byte VAR_BLAST_ABOVE_TEXT;
1343 	byte VAR_VOICE_MODE;
1344 	byte VAR_MUSIC_BUNDLE_LOADED;
1345 	byte VAR_VOICE_BUNDLE_LOADED;
1346 
1347 	byte VAR_LEFTBTN_DOWN;	// V7/V8
1348 	byte VAR_RIGHTBTN_DOWN;	// V7/V8
1349 	byte VAR_LEFTBTN_HOLD;	// V6/V72HE/V7/V8
1350 	byte VAR_RIGHTBTN_HOLD;	// V6/V72HE/V7/V8
1351 	byte VAR_SAVELOAD_SCRIPT;	// V6/V7 (not HE)
1352 	byte VAR_SAVELOAD_SCRIPT2;	// V6/V7 (not HE)
1353 
1354 	// V6/V7 specific variables (FT & Sam & Max specific)
1355 	byte VAR_CHARSET_MASK;
1356 
1357 	// V6 specific variables
1358 	byte VAR_V6_SOUNDMODE;
1359 
1360 	// V1/V2 specific variables
1361 	byte VAR_CHARCOUNT;
1362 	byte VAR_VERB_ALLOWED;
1363 	byte VAR_ACTIVE_VERB;
1364 	byte VAR_ACTIVE_OBJECT1;
1365 	byte VAR_ACTIVE_OBJECT2;
1366 
1367 	// HE specific variables
1368 	byte VAR_REDRAW_ALL_ACTORS;		// Used in setActorRedrawFlags()
1369 	byte VAR_SKIP_RESET_TALK_ACTOR;		// Used in setActorCostume()
1370 
1371 	byte VAR_SOUND_CHANNEL;			// Used in o_startSound()
1372 	byte VAR_TALK_CHANNEL;			// Used in startHETalkSound()
1373 	byte VAR_SOUNDCODE_TMR;			// Used in processSoundCode()
1374 	byte VAR_RESERVED_SOUND_CHANNELS;	// Used in findFreeSoundChannel()
1375 
1376 	byte VAR_MAIN_SCRIPT;			// Used in scummLoop()
1377 
1378 	byte VAR_SCRIPT_CYCLE;			// Used in runScript()/runObjectScript()
1379 	byte VAR_NUM_SCRIPT_CYCLES;		// Used in runAllScripts()
1380 
1381 	byte VAR_QUIT_SCRIPT;			// Used in confirmExitDialog()
1382 
1383 	// Exists both in V7 and in V72HE:
1384 	byte VAR_NUM_GLOBAL_OBJS;
1385 
1386 #ifdef USE_RGB_COLOR
1387 	// FM-Towns / PC-Engine specific
1388 	Graphics::FontSJIS *_cjkFont;
1389 #endif
1390 
1391 	// FM-Towns specific
1392 #ifndef DISABLE_TOWNS_DUAL_LAYER_MODE
1393 public:
1394 	bool towns_isRectInStringBox(int x1, int y1, int x2, int y2);
1395 	byte _townsPaletteFlags;
1396 	byte _townsCharsetColorMap[16];
1397 
1398 protected:
1399 	void towns_drawStripToScreen(VirtScreen *vs, int dstX, int dstY, int srcX, int srcY, int w, int h);
1400 #ifdef USE_RGB_COLOR
1401 	void towns_setPaletteFromPtr(const byte *ptr, int numcolor = -1);
1402 	void towns_setTextPaletteFromPtr(const byte *ptr);
1403 #endif
1404 	void towns_setupPalCycleField(int x1, int y1, int x2, int y2);
1405 	void towns_processPalCycleField();
1406 	void towns_resetPalCycleFields();
1407 	void towns_restoreCharsetBg();
1408 
1409 	Common::Rect _cyclRects[16];
1410 	int _numCyclRects;
1411 
1412 	Common::Rect _curStringRect;
1413 
1414 	byte _townsOverrideShadowColor;
1415 	byte _textPalette[48];
1416 	byte _townsClearLayerFlag;
1417 	byte _townsActiveLayerFlags;
1418 	static const uint8 _townsLayer2Mask[];
1419 
1420 	TownsScreen *_townsScreen;
1421 #endif // DISABLE_TOWNS_DUAL_LAYER_MODE
1422 };
1423 
1424 } // End of namespace Scumm
1425 
1426 #endif
1427