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