ScummVM API documentation
scumm.h
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 modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (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, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef SCUMM_SCUMM_H
23 #define SCUMM_SCUMM_H
24 
25 #include "engines/engine.h"
26 
27 #include "common/endian.h"
28 #include "common/events.h"
29 #include "common/file.h"
30 #include "common/savefile.h"
31 #include "common/keyboard.h"
32 #include "common/mutex.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 #include "graphics/palette.h"
42 
43 #include "scumm/gfx.h"
44 #include "scumm/detection.h"
45 #include "scumm/script.h"
46 
47 #ifdef __DS__
48 /* This disables the dual layer mode which is used in FM-Towns versions
49  * of SCUMM games and which emulates the behavior of the original code.
50  * The only purpose is code size reduction for certain backends.
51  * SCUMM 3 (FM-Towns) games will run in English in normal (DOS VGA) mode,
52  * which should work just fine in most situations. Some glitches might
53  * occur. Japanese mode and SCUMM 5 FM-Towns games will not work without
54  * dual layer (and 16 bit color) support.
55  */
56 #define DISABLE_TOWNS_DUAL_LAYER_MODE
57 #endif
58 
59 namespace GUI {
60 class Dialog;
61 }
62 using GUI::Dialog;
63 namespace Common {
64 class SeekableReadStream;
65 class WriteStream;
66 class SeekableWriteStream;
67 }
68 namespace Graphics {
69 class FontSJIS;
70 }
71 
84 namespace Scumm {
85 
86 class Actor;
87 class BaseCostumeLoader;
88 class BaseCostumeRenderer;
89 class BaseScummFile;
90 class CharsetRenderer;
91 class IMuse;
92 class IMuseDigital;
93 class MacGui;
94 class MusicEngine;
95 class Player_Towns;
96 class ScummEngine;
97 class ScummDebugger;
98 class Sound;
99 class Localizer;
100 class GlyphRenderer_v7;
101 
102 struct Box;
103 struct BoxCoords;
104 struct FindObjectInRoom;
105 
106 // Use g_scumm from error() ONLY
107 extern ScummEngine *g_scumm;
108 
109 /* System Wide Constants */
110 enum {
111  NUM_SENTENCE = 6,
112  NUM_SHADOW_PALETTE = 8
113 };
114 
115 /* SCUMM Debug Channels */
116 void debugC(int level, MSVC_PRINTF const char *s, ...) GCC_PRINTF(2, 3);
117 
118 enum {
119  DEBUG_GENERAL = 1 << 0, // General debug
120  DEBUG_SCRIPTS = 1 << 2, // Track script execution (start/stop/pause)
121  DEBUG_OPCODES = 1 << 3, // Track opcode invocations
122  DEBUG_VARS = 1 << 4, // Track variable changes
123  DEBUG_RESOURCE = 1 << 5, // Track resource loading / allocation
124  DEBUG_IMUSE = 1 << 6, // Track iMUSE events
125  DEBUG_SOUND = 1 << 7, // General Sound Debug
126  DEBUG_ACTORS = 1 << 8, // General Actor Debug
127  DEBUG_INSANE = 1 << 9, // Track INSANE
128  DEBUG_SMUSH = 1 << 10, // Track SMUSH
129  DEBUG_MOONBASE_AI = 1 << 11, // Moonbase AI
130  DEBUG_NETWORK = 1 << 12 // Track Networking
131 };
132 
133 struct VerbSlot;
134 struct ObjectData;
135 
136 enum {
144 
150 
157 
166  //
167 };
168 
169 enum {
170  MBS_LEFT_CLICK = 0x8000,
171  MBS_RIGHT_CLICK = 0x4000,
172  MBS_MOUSE_MASK = (MBS_LEFT_CLICK | MBS_RIGHT_CLICK),
173  MBS_MAX_KEY = 0x0200
174 };
175 
176 struct SentenceTab {
177  byte verb;
178  byte preposition;
179  uint16 objectA;
180  uint16 objectB;
181  uint8 freezeCount;
182 };
183 
184 struct StringSlot {
185  int16 xpos;
186  int16 ypos;
187  int16 right;
188  int16 height;
189  byte color;
190  byte charset;
191  bool center;
192  bool overhead;
193  bool no_talk_anim;
194  bool wrapping;
195 };
196 
198  // The 'default' values for this string slot. This is used so that the
199  // string slot can temporarily be set to different values, and then be
200  // easily reset to a previously set default.
201  StringSlot _default;
202 
203  void saveDefault() {
204  StringSlot &s = *this;
205  _default = s;
206  }
207 
208  void loadDefault() {
209  StringSlot &s = *this;
210  s = _default;
211  }
212 };
213 
215  bool _screenScroll;
216  uint _objectRedrawCount;
217  uint _objectStripRedrawCount;
218  uint _actorRedrawCount;
219  uint _actorLimbRedrawDrawCount;
220 
221 };
222 
223 enum WhereIsObject {
224  WIO_NOT_FOUND = -1,
225  WIO_INVENTORY = 0,
226  WIO_ROOM = 1,
227  WIO_GLOBAL = 2,
228  WIO_LOCAL = 3,
229  WIO_FLOBJECT = 4
230 };
231 
233  uint32 date;
234  uint16 time;
235  uint32 playtime;
236 };
237 
238 enum UserStates {
239  USERSTATE_SET_FREEZE = 0x01, // freeze scripts if USERSTATE_FREEZE_ON is set, unfreeze otherwise
240  USERSTATE_SET_CURSOR = 0x02, // shows cursor if USERSTATE_CURSOR_ON is set, hides it otherwise
241  USERSTATE_SET_IFACE = 0x04, // change user-interface (sentence-line, inventory, verb-area)
242  USERSTATE_FREEZE_ON = 0x08, // only interpreted if USERSTATE_SET_FREEZE is set
243  USERSTATE_CURSOR_ON = 0x10, // only interpreted if USERSTATE_SET_CURSOR is set
244  USERSTATE_IFACE_SENTENCE = 0x20, // only interpreted if USERSTATE_SET_IFACE is set
245  USERSTATE_IFACE_INVENTORY = 0x40, // only interpreted if USERSTATE_SET_IFACE is set
246  USERSTATE_IFACE_VERBS = 0x80 // only interpreted if USERSTATE_SET_IFACE is set
247 };
248 
249 #define USERSTATE_IFACE_ALL (USERSTATE_IFACE_SENTENCE | USERSTATE_IFACE_INVENTORY | USERSTATE_IFACE_VERBS)
250 
256 enum ResType {
257  rtInvalid = 0,
258  rtFirst = 1,
259  rtRoom = 1,
260  rtScript = 2,
261  rtCostume = 3,
262  rtSound = 4,
263  rtInventory = 5,
264  rtCharset = 6,
265  rtString = 7,
266  rtVerb = 8,
267  rtActorName = 9,
268  rtBuffer = 10,
269  rtScaleTable = 11,
270  rtTemp = 12,
271  rtFlObject = 13,
272  rtMatrix = 14,
273  rtBox = 15,
274  rtObjectName = 16,
275  rtRoomScripts = 17,
276  rtRoomImage = 18,
277  rtImage = 19,
278  rtTalkie = 20,
279  rtSpoolBuffer = 21,
280  rtLast = 21
281 };
282 
283 typedef uint16 ResId;
284 
285 class ResourceManager;
286 
327 #define PIT_BASE_FREQUENCY 1193182.0 // In Hz
328 #define PIT_V1_DIVISOR 65536.0
329 #define PIT_V2_4_DIVISOR 5041.0
330 #define PIT_V5_6_ORCHESTRATOR_DIVISOR 4096.0
331 #define PIT_V5_6_SUBTIMER_INC 3433.0
332 #define PIT_V5_SUBTIMER_THRESH 4167.0
333 #define PIT_V6_SAMNMAX_SUBTIMER_THRESH 4167.0
334 #define PIT_V6_DOTT_SUBTIMER_THRESH 4237.0
335 #define PIT_V7_ORCHESTRATOR_DIVISOR 3977.0
336 #define PIT_V7_SUBTIMER_INC 3977.0
337 #define PIT_V7_SUBTIMER_THRESH 4971.0
338 
339 #define LOOM_STEAM_CDDA_RATE 240.0
340 
354 #define AMIGA_NTSC_VBLANK_RATE 240.0
355 #define AMIGA_PAL_VBLANK_RATE 200.0
356 
361 #define GAME_PROPER_SAVE 201
362 #define GAME_FAILED_SAVE 202
363 #define GAME_PROPER_LOAD 203
364 #define GAME_FAILED_LOAD 204
365 
370 #define GUI_PAGE_MAIN 0
371 #define GUI_PAGE_SAVE 1
372 #define GUI_PAGE_LOAD 2
373 #define GUI_PAGE_RESTART 3 // Sega CD
374 #define GUI_PAGE_CODE_CONFIRM 4 // Sega CD
375 #define GUI_PAGE_INVALID_CODE 5 // Sega CD
376 
377 #define GUI_CTRL_FIRST_SG 1
378 #define GUI_CTRL_LAST_SG 9
379 #define GUI_CTRL_SAVE_BUTTON 10
380 #define GUI_CTRL_LOAD_BUTTON 11
381 #define GUI_CTRL_PLAY_BUTTON 12
382 #define GUI_CTRL_QUIT_BUTTON 13
383 #define GUI_CTRL_OK_BUTTON 14
384 #define GUI_CTRL_CANCEL_BUTTON 15
385 #define GUI_CTRL_ARROW_UP_BUTTON 16
386 #define GUI_CTRL_ARROW_DOWN_BUTTON 17
387 #define GUI_CTRL_PATH_BUTTON 18
388 #define GUI_CTRL_MUSIC_SLIDER 19
389 #define GUI_CTRL_SPEECH_SLIDER 20
390 #define GUI_CTRL_SFX_SLIDER 21
391 #define GUI_CTRL_TEXT_SPEED_SLIDER 22
392 #define GUI_CTRL_DISPLAY_TEXT_CHECKBOX 23
393 #define GUI_CTRL_SPOOLED_MUSIC_CHECKBOX 24
394 #define GUI_CTRL_OUTER_BOX 26
395 #define GUI_CTRL_INNER_BOX 27
396 
397 // Sega CD
398 #define GUI_CTRL_NUMPAD_1 1
399 #define GUI_CTRL_NUMPAD_2 2
400 #define GUI_CTRL_NUMPAD_3 3
401 #define GUI_CTRL_NUMPAD_4 4
402 #define GUI_CTRL_NUMPAD_5 5
403 #define GUI_CTRL_NUMPAD_6 6
404 #define GUI_CTRL_NUMPAD_7 7
405 #define GUI_CTRL_NUMPAD_8 8
406 #define GUI_CTRL_NUMPAD_9 9
407 #define GUI_CTRL_NUMPAD_0 10
408 #define GUI_CTRL_RESTART_BUTTON 13
409 #define GUI_CTRL_ARROW_LEFT_BUTTON 16
410 #define GUI_CTRL_ARROW_RIGHT_BUTTON 17
411 #define GUI_CTRL_NUMPAD_BACK 23
412 
413 enum GUIString {
414  gsPause = 0,
415  gsVersion = 1,
416  gsTextSpeedSlider = 2,
417  gsRestart = 3,
418  gsQuitPrompt = 4,
419  gsSave = 5,
420  gsLoad = 6,
421  gsPlay = 7,
422  gsCancel = 8,
423  gsQuit = 9,
424  gsOK = 10,
425  gsMustName = 11,
426  gsGameNotSaved = 12,
427  gsGameNotLoaded = 13,
428  gsSaving = 14,
429  gsLoading = 15,
430  gsNamePrompt = 16,
431  gsSelectLoadPrompt = 17,
432  gsReplacePrompt = 18,
433  gsYes = 20,
434  gsNo = 21,
435  gsIMuseBuffer = 22,
436  gsVoiceAndText = 23,
437  gsTextDisplayOnly = 24,
438  gsVoiceOnly = 25,
439  gsYesKey = 26,
440  gsMusicVolumeSlider = 27,
441  gsVoiceVolumeSlider = 28,
442  gsSfxVolumeSlider = 29,
443  gsHeap = 30,
444  gsSavePath = 31,
445  gsTitle = 32,
446  gsDisabled = 33,
447  gsMusic = 34,
448  gsVoice = 35,
449  gsSfx = 36,
450  gsTextSpeed = 37,
451  gsDisplayText = 38,
452  gsSpooledMusic = 39,
453  gsInsertSaveDisk = 40,
454  gsSnapOn = 41,
455  gsSnapOff = 42,
456  gsRecalJoystick = 43,
457  gsMouseMode = 44,
458  gsMouseOn = 45,
459  gsMouseOff = 46,
460  gsJoystickOn = 47,
461  gsJoystickOff = 48,
462  gsSoundsOn = 49,
463  gsSoundsOff = 50,
464  gsVGAMode = 51,
465  gsEGAMode = 52,
466  gsCGAMode = 53,
467  gsHerculesMode = 54,
468  gsTandyMode = 55,
469  gsCurrentPasscode = 56,
470  gsEnterPasscode = 57,
471  gsConfirmPasscode = 58,
472  gsInvalidPasscode = 59,
473  gsSlowFast = 60,
474  gsRestartGame = 61,
475  gsHeapExt = 62,
476 };
477 
479  int relativeCenterX;
480  int relativeCenterY;
481  int xPos;
482  int yPos;
483  int normalFillColor;
484  int topLineColor;
485  int bottomLineColor;
486  int leftLineColor;
487  int rightLineColor;
488  int normalTextColor;
489  int highlightedTextColor;
490  int highlightedFillColor;
491  bool centerText;
492  Common::String label;
493  bool doubleLinesFlag;
494 };
495 
496 enum ScummAction {
497  kScummActionNone,
498  kScummActionInsaneDownLeft,
499  kScummActionInsaneDown,
500  kScummActionInsaneDownRight,
501  kScummActionInsaneLeft,
502  kScummActionInsaneRight,
503  kScummActionInsaneUpLeft,
504  kScummActionInsaneUp,
505  kScummActionInsaneUpRight,
506  kScummActionInsaneAttack,
507  kScummActionInsaneSwitch,
508  kScummActionInsaneCheat,
509 
510  kScummActionCount
511 };
512 
513 extern const char *const insaneKeymapId;
514 
518 class ScummEngine : public Engine, public Common::Serializable {
519  friend class ScummDebugger;
520  friend class CharsetRenderer;
521  friend class CharsetRendererClassic;
522  friend class CharsetRendererTownsClassic;
523  friend class ResourceManager;
524  friend class MacGuiImpl;
525  friend class MacIndy3Gui;
526  friend class MacLoomGui;
527  friend class MacV5Gui;
528  friend class LogicHEBasketball;
529 
530 public:
531  /* Put often used variables at the top.
532  * That results in a shorter form of the opcode
533  * on some architectures. */
534  IMuse *_imuse = nullptr;
535  IMuseDigital *_imuseDigital = nullptr;
536  MusicEngine *_musicEngine = nullptr;
537  Player_Towns *_townsPlayer = nullptr;
538  Sound *_sound = nullptr;
539 
540  VerbSlot *_verbs = nullptr;
541  ObjectData *_objs = nullptr;
542 
543  // Core variables
544  GameSettings _game;
545  uint8 _gameMD5[16];
546 
549 
551  Gdi *_gdi = nullptr;
552 
554  ResourceManager *_res = nullptr;
555  int _insideCreateResource = 0; // Counter for HE sound
556 
557  bool _useOriginalGUI = true;
558  bool _enableAudioOverride = false;
559  bool _enableCOMISong = false;
560  bool _isAmigaPALSystem = false;
561  bool _quitFromScriptCmd = false;
562  bool _isHE995 = false;
563  bool _enableHECompetitiveOnlineMods = false;
564 
565  Common::Keymap *_insaneKeymap;
566 
567 protected:
569 
570  bool _needsSoundUnpause = false;
571 
572 public:
573  // Constructor / Destructor
574  ScummEngine(OSystem *syst, const DetectorResult &dr);
575  ~ScummEngine() override;
576 
577  // Engine APIs
578  Common::Error init();
579  Common::Error go();
580  Common::Error run() override {
581  Common::Error err;
582  err = init();
583  if (err.getCode() != Common::kNoError)
584  return err;
585  return go();
586  }
587 
588  void errorString(const char *buf_input, char *buf_output, int buf_output_size) override;
589  bool hasFeature(EngineFeature f) const override;
590  bool gameSupportsQuitDialogOverride() const;
591  void syncSoundSettings() override;
592 
593  Common::Error loadGameState(int slot) override;
594  bool canLoadGameStateCurrently(Common::U32String *msg = nullptr) override;
595  Common::Error saveGameState(int slot, const Common::String &desc, bool isAutosave = false) override;
596  bool canSaveGameStateCurrently(Common::U32String *msg = nullptr) override;
597 
598  void pauseEngineIntern(bool pause) override;
599 
600 protected:
601  virtual void setupScumm(const Common::Path &macResourceFile);
602  virtual void resetScumm();
603 
604  virtual void setupScummVars();
605  virtual void resetScummVars();
606  void setVideoModeVarToCurrentConfig();
607  void setSoundCardVarToCurrentConfig();
608 
609  void setupCharsetRenderer(const Common::Path &macFontFile);
610  void setupCostumeRenderer();
611 
612  virtual void loadLanguageBundle();
613  void loadCJKFont();
614  void loadKorFont();
615  void setupMusic(int midi);
616  void setTalkSpeed(int talkspeed);
617  int getTalkSpeed();
618 
619  // Scumm main loop & helper functions.
620  virtual void scummLoop(int delta);
621  virtual void scummLoop_updateScummVars();
622  virtual void scummLoop_handleSaveLoad();
623  virtual void scummLoop_handleDrawing();
624  virtual void scummLoop_handleActors() = 0;
625  virtual void scummLoop_handleEffects();
626  virtual void scummLoop_handleSound();
627 
628  virtual void runBootscript();
629 
630  virtual void terminateSaveMenuScript() {};
631 
632  // Event handling
633 public:
634  void beginTextInput();
635  void endTextInput();
636 
637  void parseEvents(); // Used by IMuseDigital::startSound
638 protected:
639  virtual void parseEvent(Common::Event event);
640 
641  void waitForTimer(int quarterFrames, bool freezeMacGui = false);
642  uint32 _lastWaitTime;
643 
644  void setTimerAndShakeFrequency();
645 
651  uint32 getIntegralTime(double fMsecs);
652  double _msecFractParts = 0.0;
653 
654  virtual void processInput();
655  virtual void processKeyboard(Common::KeyState lastKeyHit);
656  virtual void clearClickedStatus();
657 
658  // Cursor/palette
659  virtual void updateCursor();
660  virtual void animateCursor() {}
661  virtual void updatePalette();
662  virtual void setDefaultCursor() {};
663  virtual void setCursorTransparency(int a) {};
664  virtual void resetCursors() {}
665  virtual void setCursorHotspot(int x, int y) {}
666  virtual void setCursorFromBuffer(const byte *ptr, int width, int height, int pitch, bool preventScale = false) {}
667 
668  // Gamma curve lookup, from the Macintosh Quadra/Performa monitor driver
669  byte _macGammaCorrectionLookUp[256] = {
670  0x00, 0x05, 0x09, 0x0B, 0x0E, 0x10, 0x13, 0x15, 0x17, 0x19, 0x1B, 0x1D, 0x1E, 0x20, 0x22, 0x24,
671  0x25, 0x27, 0x28, 0x2A, 0x2C, 0x2D, 0x2F, 0x30, 0x31, 0x33, 0x34, 0x36, 0x37, 0x38, 0x3A, 0x3B,
672  0x3C, 0x3E, 0x3F, 0x40, 0x42, 0x43, 0x44, 0x45, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4D, 0x4E, 0x4F,
673  0x50, 0x51, 0x52, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5E, 0x5F, 0x60, 0x61,
674  0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71,
675  0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F, 0x80, 0x81,
676  0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8C, 0x8D, 0x8E, 0x8F,
677  0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0x9B, 0x9B, 0x9C, 0x9D,
678  0x9E, 0x9F, 0xA0, 0xA1, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xAB,
679  0xAB, 0xAC, 0xAD, 0xAE, 0xAF, 0xB0, 0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8,
680  0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBC, 0xBD, 0xBE, 0xBF, 0xC0, 0xC0, 0xC1, 0xC2, 0xC3, 0xC3, 0xC4,
681  0xC5, 0xC6, 0xC7, 0xC7, 0xC8, 0xC9, 0xCA, 0xCA, 0xCB, 0xCC, 0xCD, 0xCD, 0xCE, 0xCF, 0xD0, 0xD0,
682  0xD1, 0xD2, 0xD3, 0xD3, 0xD4, 0xD5, 0xD6, 0xD6, 0xD7, 0xD8, 0xD9, 0xD9, 0xDA, 0xDB, 0xDC, 0xDC,
683  0xDD, 0xDE, 0xDF, 0xDF, 0xE0, 0xE1, 0xE1, 0xE2, 0xE3, 0xE4, 0xE4, 0xE5, 0xE6, 0xE7, 0xE7, 0xE8,
684  0xE9, 0xE9, 0xEA, 0xEB, 0xEC, 0xEC, 0xED, 0xEE, 0xEE, 0xEF, 0xF0, 0xF1, 0xF1, 0xF2, 0xF3, 0xF3,
685  0xF4, 0xF5, 0xF5, 0xF6, 0xF7, 0xF8, 0xF8, 0xF9, 0xFA, 0xFA, 0xFB, 0xFC, 0xFC, 0xFD, 0xFE, 0xFF
686  };
687 
688 public:
689  void pauseGame();
690  void restart();
691  bool isUsingOriginalGUI() const;
692  bool isMessageBannerActive(); // For Indy4 Jap character shadows
693 
694  bool _isIndy4Jap = false;
695 
696 protected:
697  Dialog *_pauseDialog = nullptr;
698  Dialog *_messageDialog = nullptr;
699  Dialog *_versionDialog = nullptr;
700 
701  void confirmExitDialog();
702  void confirmRestartDialog();
703  void pauseDialog();
704  void messageDialog(const Common::U32String &message);
705  void versionDialog();
706 
707  // Original GUI
708  int32 _bannerColors[50]; // Colors for the original GUI
709  byte *_bannerMem = nullptr;
710  uint32 _bannerMemSize = 0;
711  int _bannerSaveYStart = 0;
712 
713  bool _messageBannerActive = false;
714  bool _comiQuitMenuIsOpen = false;
715  bool _closeBannerAndQueryQuitFlag = false;
716 
717  // The followings are needed for MI1 FM-Towns
718  byte *_textSurfBannerMem = nullptr;
719  uint32 _textSurfBannerMemSize = 0;
720 
721  InternalGUIControl _internalGUIControls[30];
722 
723  // Special GUI strings
724  const char _emptyMsg[1] = {'\0'};
725  const char _uncheckedBox[2] = {' ', '\0'};
726  const char _checkedBox[2] = {'x', '\0'};
727  const char _arrowUp[2] = {'\x18', '\0'};
728  const char _arrowDown[2] = {'\x19', '\0'};
729  const char _arrowLeft[2] = {'\x3c', '\0'};
730  const char _arrowRight[2] = {'\x3d', '\0'};
731 
732  Common::StringArray _savegameNames;
733  int _menuPage = 0;
734  int _mainMenuSavegameLabel = 1;
735  int _curDisplayedSaveSlotPage = 0;
736  int _firstSaveStateOfList = 0; // For LOOM VGA
737  bool _mainMenuIsActive = false;
738  bool _quitByGUIPrompt = false;
739  char _mainMenuMusicSlider[17];
740  char _mainMenuSpeechSlider[17];
741  char _mainMenuSfxSlider[17];
742  char _mainMenuTextSpeedSlider[17];
743  char _mainMenuSegaCDPasscode[5];
744  int _spooledMusicIsToBeEnabled = 1;
745  int _saveScriptParam = 0;
746  int _guiCursorAnimCounter = 0;
747  int _v5VoiceMode = 0;
748 
749  // Fake flags just for sub v5 GUIs
750  int _internalSpeakerSoundsAreOn = 1;
751  int _guiMouseFlag = 1;
752  int _guiJoystickFlag = 1;
753 
754  bool _mixerMutedByGUI = false;
755 
756  Graphics::Surface _savegameThumbnail;
757  byte *_tempTextSurface = nullptr;
758  byte *_tempMainSurface = nullptr;
759  byte *_tempVerbSurface = nullptr;
760  bool _postGUICharMask = false;
761 
762  // Saved cursor pre and post GUI
763  byte *_curGrabbedCursor = nullptr;
764  int8 _oldCursorState = 0;
765  int _curCursorState = 0;
766  int _curCursorWidth = 0;
767  int _curCursorHeight = 0;
768  int _curCursorHotspotX = 0;
769  int _curCursorHotspotY = 0;
770 
771  virtual void setSnailCursor() {}
772 
773  void initBanners();
774  Common::KeyState showBannerAndPause(int bannerId, int32 waitTime, const char *msg, ...);
775  Common::KeyState showOldStyleBannerAndPause(const char *msg, int color, int32 waitTime);
776  Common::KeyState printMessageAndPause(const char *msg, int color, int32 waitTime, bool drawOnSentenceLine);
777 
778  void clearBanner();
779  void setBannerColors(int bannerId, byte r, byte g, byte b);
780  virtual int getBannerColor(int bannerId);
781  void setUpInternalGUIControl(int id, int normalFillColor, int normalTextColor,
782  int topLineColor, int bottomLineColor, int leftLineColor, int rightLineColor,
783  int highlightedTextColor, int highlightedFillColor,
784  int anchorPointX, int anchorPointY, int x, int y, const char *label, bool centerFlag, bool unknownFlag);
785  void drawInternalGUIControl(int id, bool highlightColor);
786  int getInternalGUIControlFromCoordinates(int x, int y);
787  virtual bool isSmushActive() { return false; }
788  virtual bool isInsaneActive() { return false; }
789 
790  virtual void queryQuit(bool returnToLauncher);
791  virtual void queryRestart();
792  virtual const char *getGUIString(int stringId);
793  void waitForBannerInput(int32 waitTime, Common::KeyState &ks, bool &leftBtnClicked, bool &rightBtnClicked, bool handleMouseWheel = false);
794  virtual int getGUIStringHeight(const char *str);
795  virtual int getGUIStringWidth(const char *str);
796  virtual void drawGUIText(const char *buttonString, Common::Rect *clipRect, int textXPos, int textYPos, int textColor, bool centerFlag);
797  void getSliderString(int stringId, int value, char *sliderString, int size);
798  virtual int getMusicVolume();
799  virtual int getSpeechVolume();
800  virtual int getSFXVolume();
801  virtual void setMusicVolume(int volume);
802  virtual void setSpeechVolume(int volume);
803  virtual void setSFXVolume(int volume);
804  virtual void toggleVoiceMode();
805  virtual void handleLoadDuringSmush() {}
806  virtual void setSkipVideo(int value) {}
807 
808  void showMainMenu();
809  virtual void setUpMainMenuControls();
810  void setUpMainMenuControlsSegaCD();
811  void setUpMainMenuControlsIndy4Jap();
812  void drawMainMenuControls();
813  void drawMainMenuControlsSegaCD();
814  void updateMainMenuControls();
815  void updateMainMenuControlsSegaCD();
816  void drawMainMenuTitle(const char *title);
817  bool executeMainMenuOperation(int op, int mouseX, int mouseY, bool &hasLoadedState);
818  bool executeMainMenuOperationSegaCD(int op, int mouseX, int mouseY, bool &hasLoadedState);
819  bool shouldHighlightLabelAndWait(int clickedControl);
820  void fillSavegameLabels();
821  bool canWriteGame(int slotId);
822  bool userWriteLabelRoutine(Common::KeyState &ks, bool &leftMsClicked, bool &rightMsClicked);
823  void saveCursorPreMenu();
824  void restoreCursorPostMenu();
825  void saveSurfacesPreGUI();
826  void restoreSurfacesPostGUI();
827  void showDraftsInventory();
828  void setUpDraftsInventory();
829  void drawDraftsInventory();
830 
831 public:
832  char displayMessage(const char *altButton, MSVC_PRINTF const char *message, ...) GCC_PRINTF(3, 4);
833  bool displayMessageYesNo(MSVC_PRINTF const char *message, ...) GCC_PRINTF(2, 3);
834 
835 protected:
836  byte _fastMode = 0;
837 
838  byte _numActors = 0;
839  Actor **_actors = nullptr; // Has _numActors elements
840  Actor **_sortedActors = nullptr;
841 
842  byte *_arraySlot = nullptr;
843  uint16 *_inventory = nullptr;
844  uint16 *_newNames = nullptr;
845 public:
846  // VAR is a wrapper around scummVar, which attempts to include additional
847  // useful information should an illegal var access be detected.
848  #define VAR(x) scummVar(x, #x, __FILE__, __LINE__)
849  int32& scummVar(byte var, const char *varName, const char *file, int line) {
850  if (var == 0xFF) {
851  error("Illegal access to variable %s in file %s, line %d", varName, file, line);
852  }
853  return _scummVars[var];
854  }
855  int32 scummVar(byte var, const char *varName, const char *file, int line) const {
856  if (var == 0xFF) {
857  error("Illegal access to variable %s in file %s, line %d", varName, file, line);
858  }
859  return _scummVars[var];
860  }
861 
862 protected:
863  int16 _varwatch = 0;
864  int32 *_roomVars = nullptr;
865  int32 *_scummVars = nullptr;
866  byte *_bitVars = nullptr;
867 
868  /* Global resource tables */
869  int _numVariables = 0;
870  int _numBitVariables = 0;
871  int _numLocalObjects = 0;
872  int _numGlobalObjects = 0;
873  int _numArray = 0;
874  int _numVerbs = 0;
875  int _numFlObject = 0;
876  int _numInventory = 0;
877  int _numNewNames = 0;
878  int _numGlobalScripts = 0;
879  int _numRoomVariables = 0;
880  int _numPalettes = 0;
881  int _numSprites = 0;
882  int _numTalkies = 0;
883  int _numUnk = 0;
884  int _HEHeapSize = 0;
885 public:
886  int _numLocalScripts = 60, _numImages = 0, _numRooms = 0, _numScripts = 0, _numSounds = 0; // Used by HE games
887  int _numCostumes = 0; // FIXME - should be protected, used by Actor::remapActorPalette
888  int32 _numCharsets = 0; // FIXME - should be protected, used by CharsetRenderer
889 
890  BaseCostumeLoader *_costumeLoader = nullptr;
891  BaseCostumeRenderer *_costumeRenderer = nullptr;
892 
893  int _NESCostumeSet = 0;
894  void NES_loadCostumeSet(int n);
895  byte *_NEScostdesc = nullptr, *_NEScostlens = nullptr, *_NEScostoffs = nullptr, *_NEScostdata = nullptr;
896  byte _NESPatTable[2][4096];
897  byte _NESPalette[2][16];
898  byte _NESBaseTiles = 0;
899 
900  int _NESStartStrip = 0;
901 
902 protected:
903  int _curPalIndex = 0;
904 
905 public:
906  byte _currentRoom = 0; // FIXME - should be protected but Actor::isInCurrentRoom uses it
907  int _roomResource = 0; // FIXME - should be protected but Sound::pauseSounds uses it
908  bool _egoPositioned = false; // Used by Actor::putActor, hence public
909 
910  FilenamePattern _filenamePattern;
911 
912  virtual Common::Path generateFilename(const int room) const;
913 
914 protected:
915  Common::KeyState _keyPressed;
916  bool _keyDownMap[512]; // FIXME - 512 is a guess. it's max(kbd.ascii)
917  bool _actionMap[kScummActionCount];
918 
919  Common::Point _mouse;
920  Common::Point _virtualMouse;
921 
922  uint16 _mouseAndKeyboardStat = 0;
923  byte _leftBtnPressed = 0, _rightBtnPressed = 0;
924 
925  int _mouseWheelFlag = 0; // For original save/load dialog only
926 
927  bool _setupIsComplete = false;
928 
933  uint32 _lastInputScriptTime = 0;
934 
936  int _bootParam = 0;
937 
938  // Various options useful for debugging
939  bool _dumpScripts = false;
940  bool _hexdumpScripts = false;
941  bool _showStack = false;
942  bool _debugMode = false;
943 
944  // Save/Load class - some of this may be GUI
945  byte _saveLoadFlag = 0, _saveLoadSlot = 0;
946  uint32 _lastSaveTime = 0;
947  bool _saveTemporaryState = false;
948  bool _pauseSoundsDuringSave = true;
949  bool _loadFromLauncher = false;
950  bool _videoModeChanged = false;
951  Common::String _saveLoadFileName;
952  Common::String _saveLoadDescription;
953 
954  bool saveState(Common::WriteStream *out, bool writeHeader = true);
955  bool saveState(int slot, bool compat, Common::String &fileName);
956  bool loadState(int slot, bool compat);
957  bool loadState(int slot, bool compat, Common::String &fileName);
958  void saveLoadWithSerializer(Common::Serializer &s) override;
959  void saveResource(Common::Serializer &ser, ResType type, ResId idx);
960  void loadResource(Common::Serializer &ser, ResType type, ResId idx);
961  void loadResourceOLD(Common::Serializer &ser, ResType type, ResId idx); // "Obsolete"
962 
963  void copyHeapSaveGameToFile(int slot, const char *saveName);
964  bool changeSavegameName(int slot, char *newName);
965  virtual Common::SeekableReadStream *openSaveFileForReading(int slot, bool compat, Common::String &fileName);
966  virtual Common::SeekableWriteStream *openSaveFileForWriting(int slot, bool compat, Common::String &fileName);
967 
968  Common::String makeSavegameName(int slot, bool temporary) const {
969  return makeSavegameName(_targetName, slot, temporary);
970  }
971 
972  int getKeyState(int key);
973  int getActionState(ScummAction action);
974 
975 public:
976  static Common::String makeSavegameName(const Common::String &target, int slot, bool temporary);
977 
978  bool getSavegameName(int slot, Common::String &desc);
979  void listSavegames(bool *marks, int num);
980 
981  void requestSave(int slot, const Common::String &name);
982  void requestLoad(int slot);
983 
984  Common::String getTargetName() const { return _targetName; }
985  bool canPauseSoundsDuringSave() const { return _pauseSoundsDuringSave; }
986 
987 // thumbnail + info stuff
988 public:
989  static bool querySaveMetaInfos(const char *target, int slot, int heversion, Common::String &desc, Graphics::Surface *&thumbnail, SaveStateMetaInfos *&timeInfos);
990 
991 protected:
992  void saveInfos(Common::WriteStream *file);
993  static bool loadInfos(Common::SeekableReadStream *file, SaveStateMetaInfos *stuff);
994 
995 protected:
996  /* Script VM - should be in Script class */
997  uint32 _localScriptOffsets[1024];
998  const byte *_scriptPointer = nullptr;
999  const byte *_scriptOrgPointer = nullptr;
1000  const byte * const *_lastCodePtr = nullptr;
1001  byte _opcode = 0;
1002  bool _debug = false;
1003  byte _currentScript = 0xFF; // Let debug() work on init stage
1004  int _scummStackPos = 0;
1005  int _vmStack[256];
1006 
1007  char _engineVersionString[50];
1008  char _dataFileVersionString[50];
1009 
1010  OpcodeEntry _opcodes[256];
1011 
1012  virtual void setupOpcodes() = 0;
1013  void executeOpcode(byte i);
1014  const char *getOpcodeDesc(byte i);
1015 
1016  void initializeLocals(int slot, int *vars);
1017  int getScriptSlot();
1018 
1019  void startScene(int room, Actor *a, int b);
1020  bool startManiac();
1021 
1022 public:
1023  void runScript(int script, bool freezeResistant, bool recursive, int *lvarptr, int cycle = 0);
1024  void stopScript(int script);
1025  void nukeArrays(byte scriptSlot);
1026 
1027 protected:
1028  void runObjectScript(int script, int entry, bool freezeResistant, bool recursive, int *vars, int slot = -1, int cycle = 0);
1029  void runScriptNested(int script);
1030  void executeScript();
1031  void updateScriptPtr();
1032  virtual void runInventoryScript(int i);
1033  virtual void runInventoryScriptEx(int i);
1034  virtual void checkAndRunSentenceScript();
1035  void runExitScript();
1036  void runEntryScript();
1037  void runQuitScript();
1038  void runAllScripts();
1039  void freezeScripts(int scr);
1040  void unfreezeScripts();
1041 
1042  bool isScriptInUse(int script) const;
1043  bool isRoomScriptRunning(int script) const;
1044  bool isScriptRunning(int script) const;
1045 
1046  void killAllScriptsExceptCurrent();
1047  void killScriptsAndResources();
1048  void decreaseScriptDelay(int amount);
1049 
1050  void stopObjectCode();
1051  void stopObjectScript(int script);
1052 
1053  void getScriptBaseAddress();
1054  void resetScriptPointer();
1055  int getVerbEntrypoint(int obj, int entry);
1056 
1057  void refreshScriptPointer();
1058  byte fetchScriptByte();
1059  virtual uint fetchScriptWord();
1060  virtual int fetchScriptWordSigned();
1061  uint fetchScriptDWord();
1062  int fetchScriptDWordSigned();
1063  void ignoreScriptWord() { fetchScriptWord(); }
1064  void ignoreScriptByte() { fetchScriptByte(); }
1065  void push(int a);
1066  int pop();
1067  virtual int readVar(uint var);
1068  virtual void writeVar(uint var, int value);
1069  // SCUMM 1/2
1070  virtual void resetSentence() {}
1071 
1072 protected:
1073  virtual void beginCutscene(int *args);
1074  virtual void endCutscene();
1075  void abortCutscene();
1076  void beginOverride();
1077  void endOverride();
1078 
1079  void copyScriptString(byte *dst);
1080  int resStrLen(const byte *src);
1081  void doSentence(int c, int b, int a);
1082 
1083  /* Should be in Resource class */
1084  BaseScummFile *_fileHandle = nullptr;
1085  uint32 _fileOffset = 0;
1086 public:
1089  Common::Path _macCursorFile;
1090 
1091  bool openFile(BaseScummFile &file, const Common::Path &filename, bool resourceFile = false);
1092 
1094  bool isMacM68kIMuse() const;
1095 
1096 protected:
1097  int _resourceHeaderSize = 8;
1098  byte _resourceMapper[128];
1099  const byte *_resourceLastSearchBuf; // FIXME: need to put it to savefile?
1100  uint32 _resourceLastSearchSize; // FIXME: need to put it to savefile?
1101 
1102  virtual void allocateArrays();
1103  void openRoom(int room);
1104  void closeRoom();
1105  void deleteRoomOffsets();
1106  virtual void readRoomsOffsets();
1107  void askForDisk(const Common::Path &filename, int disknum);
1108  bool openResourceFile(const Common::Path &filename, byte encByte);
1109 
1110  void loadPtrToResource(ResType type, ResId idx, const byte *ptr);
1111  virtual int readResTypeList(ResType type);
1112 // void allocResTypeData(ResType type, uint32 tag, int num, int mode);
1113 // byte *createResource(int type, int index, uint32 size);
1114  int loadResource(ResType type, ResId idx);
1115 // void nukeResource(ResType type, ResId idx);
1116  int getResourceRoomNr(ResType type, ResId idx);
1117  virtual uint32 getResourceRoomOffset(ResType type, ResId idx);
1118 
1119 public:
1120  int getResourceSize(ResType type, ResId idx);
1121  byte *getResourceAddress(ResType type, ResId idx);
1122  virtual byte *getStringAddress(ResId idx);
1123  byte *getStringAddressVar(int i);
1124  void ensureResourceLoaded(ResType type, ResId idx);
1125 
1126 protected:
1127  Common::Mutex _resourceAccessMutex; // Used in getResourceSize(), getResourceAddress() and findResource()
1128  // to avoid race conditions between the audio thread of Digital iMUSE
1129  // and the main SCUMM thread
1130 
1131  int readSoundResource(ResId idx);
1132  int readSoundResourceSmallHeader(ResId idx);
1133  bool isResourceInUse(ResType type, ResId idx) const;
1134 
1135  virtual void setupRoomSubBlocks();
1136  virtual void resetRoomSubBlocks();
1137 
1138  virtual void clearRoomObjects();
1139  virtual void resetRoomObjects();
1140  virtual void resetRoomObject(ObjectData *od, const byte *room, const byte *searchptr = NULL);
1141 
1142  virtual void readArrayFromIndexFile();
1143  virtual void readMAXS(int blockSize) = 0;
1144  virtual void readGlobalObjects();
1145  virtual void readIndexFile();
1146  virtual void readIndexBlock(uint32 block, uint32 itemsize);
1147  virtual void loadCharset(int i);
1148  void nukeCharset(int i);
1149 
1150  int _lastLoadedRoom = 0;
1151 public:
1152  const byte *findResourceData(uint32 tag, const byte *ptr);
1153  const byte *findResource(uint32 tag, const byte *ptr);
1154  void applyWorkaroundIfNeeded(ResType type, int idx);
1155  bool verifyMI2MacBootScript();
1156  bool verifyMI2MacBootScript(byte *buf, int size);
1157  bool tryPatchMI1CannibalScript(byte *buf, int size);
1158 
1159  int getResourceDataSize(const byte *ptr) const;
1160  void dumpResource(const char *tag, int index, const byte *ptr, int length = -1);
1161 
1162 public:
1163  /* Should be in Object class */
1164  byte OF_OWNER_ROOM = 0;
1165  int getInventorySlot();
1166  int findInventory(int owner, int index);
1167  int getInventoryCount(int owner);
1168 
1169 protected:
1170  byte *_objectOwnerTable = nullptr, *_objectRoomTable = nullptr, *_objectStateTable = nullptr;
1171  int _numObjectsInRoom = 0;
1172 
1173 public:
1174  uint32 *_classData = nullptr;
1175 
1176 protected:
1177  void markObjectRectAsDirty(int obj);
1178  virtual void loadFlObject(uint object, uint room);
1179  void nukeFlObjects(int min, int max);
1180  int findFlObjectSlot();
1181  int findLocalObjectSlot();
1182  void addObjectToInventory(uint obj, uint room);
1183  void updateObjectStates();
1184 public:
1185  bool getClass(int obj, int cls) const; // Used in actor.cpp, hence public
1186 protected:
1187  void putClass(int obj, int cls, bool set);
1188  int getState(int obj);
1189  void putState(int obj, int state);
1190  void setObjectState(int obj, int state, int x, int y);
1191  int getOwner(int obj) const;
1192  void putOwner(int obj, int owner);
1193  void setOwnerOf(int obj, int owner);
1194  void clearOwnerOf(int obj);
1195  int getObjectRoom(int obj) const;
1196  virtual bool objIsActor(int obj);
1197  virtual int objToActor(int obj);
1198  virtual int actorToObj(int actor);
1199  int getObjX(int obj);
1200  int getObjY(int obj);
1201  void getObjectWidth(int object, int &width) { int x, y, dir; getObjectXYPos(object, x, y, dir, width); }
1202  void getObjectXYPos(int object, int &x, int &y) { int dir, width; getObjectXYPos(object, x, y, dir, width); }
1203  void getObjectXYPos(int object, int &x, int &y, int &dir) { int width; getObjectXYPos(object, x, y, dir, width); }
1204  void getObjectXYPos(int object, int &x, int &y, int &dir, int &width);
1205  int getObjOldDir(int obj);
1206  int getObjNewDir(int obj);
1207  int getObjectIndex(int object) const;
1208  int getObjectImageCount(int object);
1209  int whereIsObject(int object) const;
1210  int findObject(int x, int y);
1211  void findObjectInRoom(FindObjectInRoom *fo, byte findWhat, uint object, uint room);
1212 public:
1213  int getObjectOrActorWidth(int object, int &width); // Used in v4 and below
1214  int getObjectOrActorXY(int object, int &x, int &y); // Used in actor.cpp, hence public
1215  int getDist(int x, int y, int x2, int y2); // Also used in actor.cpp
1216 protected:
1217 
1218  int getObjActToObjActDist(int a, int b); // Not sure how to handle
1219  const byte *getObjOrActorName(int obj); // these three..
1220  void setObjectName(int obj);
1221 
1222  void addObjectToDrawQue(int object);
1223  void removeObjectFromDrawQue(int object);
1224  void clearDrawObjectQueue();
1225  void processDrawQue();
1226 
1227  virtual void clearDrawQueues();
1228 
1229  uint32 getOBCDOffs(int object) const;
1230  byte *getOBCDFromObject(int obj, bool v0CheckInventory = true);
1231  const byte *getOBIMFromObjectData(const ObjectData &od);
1232  const byte *getObjectImage(const byte *ptr, int state);
1233  virtual int getObjectIdFromOBIM(const byte *obim);
1234 
1235 protected:
1236  /* Should be in Verb class */
1237  uint16 _verbMouseOver = 0;
1238  int8 _userPut = 0;
1239  uint16 _userState = 0;
1240 
1241  virtual void handleMouseOver(bool updateInventory);
1242  virtual void redrawVerbs();
1243  virtual void checkExecVerbs();
1244 
1245  void verbMouseOver(int verb);
1246  int findVerbAtPos(int x, int y) const;
1247  virtual void drawVerb(int verb, int mode);
1248  virtual void runInputScript(int clickArea, int val, int mode);
1249  void restoreVerbBG(int verb);
1250  void drawVerbBitmap(int verb, int x, int y);
1251  int getVerbSlot(int id, int mode) const;
1252  void killVerb(int slot);
1253  void setVerbObject(uint room, uint object, uint verb);
1254 
1255 public:
1256  bool isValidActor(int id) const;
1257 
1258  /* Should be in Actor class */
1259  Actor *derefActor(int id, const char *errmsg = 0) const;
1260  Actor *derefActorSafe(int id, const char *errmsg) const;
1261 
1262 protected:
1263  void walkActors();
1264  void playActorSounds();
1265  void redrawAllActors();
1266  virtual void setActorRedrawFlags();
1267  void putActors();
1268  void showActors();
1269  void resetV1ActorTalkColor();
1270  virtual void resetActorBgs();
1271  virtual void processActors();
1272  void processUpperActors();
1273  virtual int getActorFromPos(int x, int y);
1274 
1275 public:
1276  /* Actor talking stuff */
1277  byte _actorToPrintStrFor = 0, _V1TalkingActor = 0;
1278  int _sentenceNum = 0;
1279  SentenceTab _sentence[NUM_SENTENCE];
1280  StringTab _string[6];
1281  byte _haveMsg = 0;
1282  int16 _talkDelay = 0;
1283  int _NES_lastTalkingActor = 0;
1284  int _NES_talkColor = 0;
1285 
1286  virtual void actorTalk(const byte *msg);
1287  void stopTalk();
1288  int getTalkingActor(); // Wrapper around VAR_TALK_ACTOR for V1 Maniac
1289  void setTalkingActor(int variable);
1290 
1291  // Generic costume code
1292  bool isCostumeInUse(int i) const;
1293 
1294 protected:
1295  /* Should be in Graphics class? */
1296  uint16 _screenB = 0, _screenH = 0;
1297 public:
1298  int _roomHeight = 0, _roomWidth = 0;
1299  int _screenHeight = 0, _screenWidth = 0;
1300  VirtScreen _virtscr[4]; // Virtual screen areas
1301  CameraData camera; // 'Camera' - viewport
1302  bool _cameraIsFrozen = false;
1303 
1304  int _screenStartStrip = 0, _screenEndStrip = 0;
1305  int _screenTop = 0;
1306  bool _forceBannerVirtScreen = false;
1307 
1308  // For Mac versions of 320x200 games:
1309  // these versions rendered at 640x480 without any aspect ratio correction;
1310  // in order to correctly display the games as they should be, we perform some
1311  // offset corrections within the various rendering pipelines.
1312  //
1313  // The only reason I've made _useMacScreenCorrectHeight toggleable is because
1314  // maybe someday the screen correction can be activated or deactivated from the
1315  // ScummVM GUI; but currently I'm not taking that responsibility, after all the
1316  // work done on ensuring that old savegames translate correctly to the new setting... :-P
1317  bool _useMacScreenCorrectHeight = true;
1318  int _macScreenDrawOffset = 20;
1319 
1320  Common::RenderMode _renderMode;
1321  uint8 _bytesPerPixel = 1;
1322  Graphics::PixelFormat _outputPixelFormat;
1323 
1324 protected:
1325  ColorCycle _colorCycle[16]; // Palette cycles
1326  uint8 _colorUsedByCycle[256];
1327  Graphics::PaletteLookup _pl; // Used by the internal GUI
1328 
1329  uint32 _ENCD_offs = 0, _EXCD_offs = 0;
1330  uint32 _CLUT_offs = 0, _EPAL_offs = 0;
1331  uint32 _IM00_offs = 0, _PALS_offs = 0;
1332 
1333  //ender: fullscreen
1334  bool _fullRedraw = false, _bgNeedsRedraw = false;
1335  bool _screenEffectFlag = false, _completeScreenRedraw = false;
1336  bool _disableFadeInEffect = false;
1337 
1338  struct {
1339  int hotspotX, hotspotY, width, height;
1340  byte animate, animateIndex;
1341  int8 state;
1342  } _cursor;
1343 
1344  // HACK Double the array size to handle 16-bit images.
1345  // this should be dynamically allocated based on game depth instead.
1346  byte _grabbedCursor[16384];
1347  byte _macGrabbedCursor[16384 * 4]; // Double resolution cursor
1348  byte _currentCursor = 0;
1349 
1350  byte _newEffect = 0, _switchRoomEffect2 = 0, _switchRoomEffect = 0;
1351  bool _doEffect = false;
1352 
1353  bool _snapScroll = false;
1354 
1355  virtual void setBuiltinCursor(int index) {}
1356 public:
1357  bool isLightOn() const;
1358 
1359  virtual int getCurrentLights() const;
1360 
1361 protected:
1362  void initScreens(int b, int h);
1363  void initVirtScreen(VirtScreenNumber slot, int top, int width, int height, bool twobufs, bool scrollable);
1364  void initBGBuffers(int height);
1365  void initCycl(const byte *ptr); // Color cycle
1366 
1367  void decodeNESBaseTiles();
1368 
1369  void drawObject(int obj, int scrollType);
1370  void drawRoomObjects(int arg);
1371  void drawRoomObject(int i, int arg);
1372  void drawBox(int x, int y, int x2, int y2, int color);
1373  void drawLine(int x1, int y1, int x2, int y2, int color);
1374  void drawPixel(VirtScreen *vs, int x, int y, int16 color, bool useBackbuffer = false);
1375 
1376  void moveScreen(int dx, int dy, int height);
1377 
1378  void restoreBackground(Common::Rect rect, byte backcolor = 0);
1379  void redrawBGStrip(int start, int num);
1380  virtual void redrawBGAreas();
1381 
1382  void cameraMoved();
1383  void setCameraAtEx(int at);
1384  virtual void setCameraAt(int pos_x, int pos_y);
1385  virtual void setCameraFollows(Actor *a, bool setCamera = false);
1386  virtual void moveCamera();
1387  virtual void panCameraTo(int x, int y);
1388  void clampCameraPos(Common::Point *pt);
1389  void actorFollowCamera(int act);
1390 
1391  const byte *getPalettePtr(int palindex, int room);
1392 
1393  void setPaletteFromTable(const byte *ptr, int numcolor, int firstIndex = 0);
1394  void resetPalette();
1395 
1396  void setCurrentPalette(int pal);
1397  void setRoomPalette(int pal, int room);
1398  void setPCEPaletteFromPtr(const byte *ptr);
1399  void setAmigaPaletteFromPtr(const byte *ptr);
1400  virtual void setPaletteFromPtr(const byte *ptr, int numcolor = -1);
1401  void setV1ColorTable(int renderMode);
1402 
1403  virtual void setPalColor(int index, int r, int g, int b);
1404  void setDirtyColors(int min, int max);
1405  const byte *findPalInPals(const byte *pal, int index);
1406  void swapPalColors(int a, int b);
1407  virtual void copyPalColor(int dst, int src);
1408  void cyclePalette();
1409  void stopCycle(int i);
1410  virtual void palManipulateInit(int resID, int start, int end, int time);
1411  void palManipulate();
1412  uint32 findClosestPaletteColor(byte *palette, int paletteLength, byte r, byte g, byte b);
1413  void applyGrayscaleToPaletteRange(int min, int max); // For Sam&Max original noir mode
1414  bool haveToApplyMonkey1PaletteFix();
1415 
1416 public:
1417  uint8 *getHEPaletteSlot(uint16 palSlot);
1418  uint16 get16BitColor(uint8 r, uint8 g, uint8 b);
1419  uint32 getPaletteColorFromRGB(byte *palette, byte r, byte g, byte b);
1420  uint32 getPackedRGBColorFromPalette(byte *palette, uint32 color);
1421  void fetchBlackAndWhite(uint32 &black, uint32 &white, byte *palette, int paletteEntries);
1422  int remapPaletteColor(int r, int g, int b, int threshold); // Used by Actor::remapActorPalette
1423  void readPCEPalette(const byte **ptr, byte **dest, int numEntries);
1424  void colorPCEToRGB(uint16 color, byte *r, byte *g, byte *b);
1425  void setPCETextPalette(uint8 color);
1426 protected:
1427  void moveMemInPalRes(int start, int end, byte direction);
1428  void setShadowPalette(int slot, int redScale, int greenScale, int blueScale, int startColor, int endColor);
1429  void setShadowPalette(int redScale, int greenScale, int blueScale, int startColor, int endColor, int start, int end);
1430  virtual void darkenPalette(int redScale, int greenScale, int blueScale, int startColor, int endColor);
1431 
1432 public:
1433  void markRectAsDirty(VirtScreenNumber virt, int left, int right, int top, int bottom, int dirtybit = 0);
1434  void markRectAsDirty(VirtScreenNumber virt, const Common::Rect& rect, int dirtybit = 0) {
1435  markRectAsDirty(virt, rect.left, rect.right, rect.top, rect.bottom, dirtybit);
1436  }
1437 protected:
1438  // Screen rendering
1439  byte *_compositeBuf;
1440  byte *_hercCGAScaleBuf = nullptr;
1441  bool _enableEGADithering = false;
1442  bool _supportsEGADithering = false;
1443 
1444  virtual void drawDirtyScreenParts();
1445  void updateDirtyScreen(VirtScreenNumber slot);
1446  void drawStripToScreen(VirtScreen *vs, int x, int width, int top, int bottom);
1447 
1448  void mac_markScreenAsDirty(int x, int y, int w, int h);
1449  void mac_drawStripToScreen(VirtScreen *vs, int top, int x, int y, int width, int height);
1450  void mac_drawIndy3TextBox();
1451  void mac_undrawIndy3TextBox();
1452  void mac_undrawIndy3CreditsText();
1453  void mac_drawBufferToScreen(const byte *buffer, int pitch, int x, int y, int width, int height, bool epxRectangleExpansion = true);
1454  void mac_updateCompositeBuffer(const byte *buffer, int pitch, int x, int y, int width, int height);
1455  void mac_blitDoubleResImage(const byte *buffer, int pitch, int x, int y, int width, int height);
1456  void mac_applyDoubleResToBuffer(const byte *inputBuffer, byte *outputBuffer, int width, int height, int inputPitch, int outputPitch);
1457  void mac_blitEPXImage(const byte *buffer, int pitch, int x, int y, int width, int height, bool epxRectangleExpansion = true);
1458  void mac_applyEPXToBuffer(const byte *inputBuffer, byte *outputBuffer, int width, int height, int inputPitch, int outputPitch, int xOffset, int yOffset, int bufferWidth, int bufferHeight);
1459  void mac_scaleCursor(byte *&outCursor, int &outHotspotX, int &outHotspotY, int &outWidth, int &outHeight);
1460  void mac_toggleSmoothing();
1461 
1462  Common::KeyState mac_showOldStyleBannerAndPause(const char *msg, int32 waitTime);
1463 
1464  const byte *postProcessDOSGraphics(VirtScreen *vs, int &pitch, int &x, int &y, int &width, int &height) const;
1465  const byte *ditherVGAtoEGA(int &pitch, int &x, int &y, int &width, int &height) const;
1466 
1467 public:
1468  VirtScreen *findVirtScreen(int y);
1469  byte *getMaskBuffer(int x, int y, int z);
1470 
1471 protected:
1472  void fadeIn(int effect);
1473  void fadeOut(int effect);
1474 
1475  void dissolveEffectSelector();
1476  void transitionEffect(int a);
1477  void dissolveEffect(int width, int height);
1478  void scrollEffect(int dir);
1479 
1480  void updateScreenShakeEffect();
1481 
1482 public:
1483  double getTimerFrequency();
1484  double getAmigaMusicTimerFrequency(); // For setting up Players v2 and v3
1485 
1486 protected:
1487  bool _shakeEnabled = false;
1488  bool _shakeTempSavedState = false; // For saving and restoring before and after GUI calls
1489  uint _shakeFrame = 0;
1490  uint32 _shakeNextTick = 0;
1491  uint32 _shakeTickCounter = 0;
1492  double _shakeTimerRate;
1493  double _timerFrequency;
1494 
1495  void setShake(int mode);
1496 
1497  int _drawObjectQueNr = 0;
1498  byte _drawObjectQue[200];
1499 
1500  /* For each of the 410 screen strips, gfxUsageBits contains a
1501  * bitmask. The lower 80 bits each correspond to one actor and
1502  * signify if any part of that actor is currently contained in
1503  * that strip.
1504  *
1505  * If the leftmost bit is set, the strip (background) is dirty
1506  * needs to be redrawn.
1507  *
1508  * The second leftmost bit is set by restoreBlastObjectsRect() and
1509  * restoreBackground(), but I'm not yet sure why.
1510  */
1511  uint32 gfxUsageBits[410 * 3];
1512 
1513  void upgradeGfxUsageBits();
1514  void setGfxUsageBit(int strip, int bit);
1515  void clearGfxUsageBit(int strip, int bit);
1516 
1517  // speed optimization: inline due to frequent calling
1518  bool testGfxUsageBit(int strip, int bit) {
1519  assert(strip >= 0 && strip < ARRAYSIZE(gfxUsageBits) / 3);
1520  assert(1 <= bit && bit <= 96);
1521  bit--;
1522  return (gfxUsageBits[3 * strip + bit / 32] & (1 << (bit % 32))) != 0;
1523  }
1524 
1525  bool testGfxAnyUsageBits(int strip);
1526  bool testGfxObjectUsageBits(int strip); // Used for HE actors overlap calculations
1527  bool testGfxOtherUsageBits(int strip, int bit);
1528 
1529 public:
1530  byte _roomPalette[256];
1531  byte *_shadowPalette = nullptr;
1532  bool _skipDrawObject = 0;
1533  int _voiceMode = 0;
1534 
1535  // HE specific
1536  byte _HEV7ActorPalette[256];
1537  uint8 *_hePalettes = nullptr;
1538  uint16 _hePaletteSlot = 0;
1539  uint16 *_16BitPalette = nullptr;
1540 
1541  // Indy4 Amiga specific
1542  byte *_verbPalette = nullptr;
1543 
1544  ScummEngine_v0_Delays _V0Delay;
1545 
1546 protected:
1547  int _shadowPaletteSize = 0;
1548  byte _currentPalette[3 * 256];
1549  byte _darkenPalette[3 * 256];
1550  int _paletteChangedCounter = 1;
1551 
1552  int _palDirtyMin = 0, _palDirtyMax = 0;
1553 
1554  byte _palManipStart = 0, _palManipEnd = 0;
1555  uint16 _palManipCounter = 0;
1556  byte *_palManipPalette = nullptr;
1557  byte *_palManipIntermediatePal = nullptr;
1558 
1559  bool _haveActorSpeechMsg = false;
1560  bool _useTalkAnims = false;
1561  uint16 _defaultTextSpeed = 0;
1562  int _saveSound = 0;
1563  bool _native_mt32 = false;
1564  bool _copyProtection = false;
1565  bool _shadowPalRemap = false;
1566 
1567  // Indy4 Amiga specific
1568  uint16 _amigaFirstUsedColor = 0;
1569  byte _amigaPalette[3 * 64];
1570  void amigaPaletteFindFirstUsedColor();
1571  void mapRoomPalette(int idx);
1572  int remapRoomPaletteColor(int r, int g, int b);
1573  void mapVerbPalette(int idx);
1574  int remapVerbPaletteColor(int r, int g, int b);
1575 
1576  // EGA dithering mode color tables for certain VGA games like MI2, LOOM Talkie...
1577  byte *_egaColorMap[2];
1578 
1579 public:
1580  uint16 _extraBoxFlags[65];
1581 
1582  byte getNumBoxes();
1583  byte *getBoxMatrixBaseAddr();
1584  byte *getBoxConnectionBase(int box);
1585 
1586  int getNextBox(byte from, byte to);
1587 
1588  void setBoxFlags(int box, int val);
1589  void setBoxScale(int box, int b);
1590 
1591  bool checkXYInBoxBounds(int box, int x, int y);
1592 
1593  BoxCoords getBoxCoordinates(int boxnum);
1594 
1595  byte getMaskFromBox(int box);
1596  Box *getBoxBaseAddr(int box);
1597  byte getBoxFlags(int box);
1598  int getBoxScale(int box);
1599 
1600  int getScale(int box, int x, int y);
1601  int getScaleFromSlot(int slot, int x, int y);
1602 
1603 protected:
1604  // Scaling slots/items
1605  struct ScaleSlot {
1606  int x1, y1, scale1;
1607  int x2, y2, scale2;
1608  };
1609  friend void syncWithSerializer(Common::Serializer &, ScaleSlot &);
1610  ScaleSlot _scaleSlots[20];
1611  void setScaleSlot(int slot, int x1, int y1, int scale1, int x2, int y2, int scale2);
1612  void setBoxScaleSlot(int box, int slot);
1613  void convertScaleTableToScaleSlot(int slot);
1614 
1615  void calcItineraryMatrix(byte *itineraryMatrix, int num);
1616  void createBoxMatrix();
1617  virtual bool areBoxesNeighbors(int i, int j);
1618 
1619  /* String class */
1620 public:
1621  CharsetRenderer *_charset = nullptr;
1622  byte _charsetColorMap[16];
1623 
1629  int _textSurfaceMultiplier = 0;
1630 
1631  Graphics::Surface *_macScreen = nullptr;
1632  MacGui *_macGui = nullptr;
1633  bool _useMacGraphicsSmoothing = true;
1634  byte _completeScreenBuffer[320 * 200];
1635 
1636 protected:
1637  byte _charsetColor = 0;
1638  byte _charsetData[23][16];
1639 
1640  int _charsetBufPos = 0;
1641  byte _charsetBuffer[512];
1642 
1643  bool _keepText = false;
1644  byte _msgCount = 0;
1645 
1646  int _nextLeft = 0, _nextTop = 0;
1647 
1648  Localizer *_localizer = nullptr;
1649 
1650  void restoreCharsetBg();
1651  void clearCharsetMask();
1652  void clearTextSurface();
1653 
1654  virtual void initCharset(int charset);
1655 
1656  virtual void printString(int m, const byte *msg);
1657 
1658  virtual bool handleNextCharsetCode(Actor *a, int *c);
1659  virtual void drawSentence() {}
1660  virtual void displayDialog();
1661  bool newLine();
1662  void drawString(int a, const byte *msg);
1663  virtual void fakeBidiString(byte *ltext, bool ignoreVerb, int ltextSize) const;
1664  void wrapSegaCDText();
1665  void debugMessage(const byte *msg);
1666  virtual void showMessageDialog(const byte *msg);
1667 
1668  virtual int convertMessageToString(const byte *msg, byte *dst, int dstSize);
1669  int convertIntMessage(byte *dst, int dstSize, int var);
1670  int convertVerbMessage(byte *dst, int dstSize, int var);
1671  int convertNameMessage(byte *dst, int dstSize, int var);
1672  int convertStringMessage(byte *dst, int dstSize, int var);
1673 
1674 public:
1675  Common::Language _language; // Accessed by a hack in NutRenderer::loadFont
1676 
1677  // Used by class ScummDialog:
1678  virtual void translateText(const byte *text, byte *trans_buff, int transBufferSize);
1679  // Old Hebrew games require reversing the dialog text.
1680  bool reverseIfNeeded(const byte *text, byte *reverseBuf, int reverseBufSize) const;
1681  // Returns codepage that matches the game for languages that require it.
1682  Common::CodePage getDialogCodePage() const;
1683 
1684  // Somewhat hackish stuff for 2 byte support (Chinese/Japanese/Korean)
1685  bool _useCJKMode = false;
1686  bool _useMultiFont = false;
1687  int _numLoadedFont = 0;
1688  int _2byteShadow = 0;
1689  bool _force2ByteCharHeight = false;
1690 
1691  int _2byteHeight = 0;
1692  int _2byteWidth = 0;
1693  int _krStrPost = 0;
1694  byte _newLineCharacter = 0;
1695  byte *get2byteCharPtr(int idx);
1696 
1697  bool isScummvmKorTarget();
1698  bool hasLocalizer();
1699 
1700 //protected:
1701  byte *_2byteFontPtr = nullptr;
1702  byte *_2byteMultiFontPtr[20];
1703  int _2byteMultiHeight[20];
1704  int _2byteMultiWidth[20];
1705  int _2byteMultiShadow[20];
1706 
1707 private:
1708  struct TranslatedLine {
1709  uint32 originalTextOffset;
1710  uint32 translatedTextOffset;
1711  };
1712 
1713  struct TranslationRange {
1714  uint32 left;
1715  uint32 right;
1716 
1717  TranslationRange(uint32 left_, uint32 right_) : left(left_), right(right_) {}
1718  TranslationRange() : left(0), right(0) {}
1719  };
1720 
1721  struct TranslationRoom {
1723  };
1724 
1725  bool _existLanguageFile = false;
1726  bool _isRTL = false;
1727  byte *_languageBuffer = nullptr;
1728  int _numTranslatedLines = 0;
1729  TranslatedLine *_translatedLines = nullptr;
1730  uint16 *_languageLineIndex = nullptr;
1732 
1733  const byte *searchTranslatedLine(const byte *text, const TranslationRange &range, bool useIndex);
1734 
1735  virtual void createTextRenderer(GlyphRenderer_v7 *gr) {}
1736 
1737 public:
1738 
1739  /* Scumm Vars */
1740  byte VAR_KEYPRESS = 0xFF;
1741  byte VAR_SYNC = 0xFF;
1742  byte VAR_EGO = 0xFF;
1743  byte VAR_CAMERA_POS_X = 0xFF;
1744  byte VAR_HAVE_MSG = 0xFF;
1745  byte VAR_ROOM = 0xFF;
1746  byte VAR_OVERRIDE = 0xFF;
1747  byte VAR_MACHINE_SPEED = 0xFF;
1748  byte VAR_ME = 0xFF;
1749  byte VAR_NUM_ACTOR = 0xFF;
1750  byte VAR_CURRENT_LIGHTS = 0xFF;
1751  byte VAR_CURRENTDRIVE = 0xFF; // How about merging this with VAR_CURRENTDISK?
1752  byte VAR_CURRENTDISK = 0xFF;
1753  byte VAR_TMR_1 = 0xFF;
1754  byte VAR_TMR_2 = 0xFF;
1755  byte VAR_TMR_3 = 0xFF;
1756  byte VAR_MUSIC_TIMER = 0xFF;
1757  byte VAR_ACTOR_RANGE_MIN = 0xFF;
1758  byte VAR_ACTOR_RANGE_MAX = 0xFF;
1759  byte VAR_CAMERA_MIN_X = 0xFF;
1760  byte VAR_CAMERA_MAX_X = 0xFF;
1761  byte VAR_TIMER_NEXT = 0xFF;
1762  byte VAR_VIRT_MOUSE_X = 0xFF;
1763  byte VAR_VIRT_MOUSE_Y = 0xFF;
1764  byte VAR_ROOM_RESOURCE = 0xFF;
1765  byte VAR_LAST_SOUND = 0xFF;
1766  byte VAR_CUTSCENEEXIT_KEY = 0xFF;
1767  byte VAR_OPTIONS_KEY = 0xFF;
1768  byte VAR_TALK_ACTOR = 0xFF;
1769  byte VAR_CAMERA_FAST_X = 0xFF;
1770  byte VAR_SCROLL_SCRIPT = 0xFF;
1771  byte VAR_ENTRY_SCRIPT = 0xFF;
1772  byte VAR_ENTRY_SCRIPT2 = 0xFF;
1773  byte VAR_EXIT_SCRIPT = 0xFF;
1774  byte VAR_EXIT_SCRIPT2 = 0xFF;
1775  byte VAR_VERB_SCRIPT = 0xFF;
1776  byte VAR_SENTENCE_SCRIPT = 0xFF;
1777  byte VAR_INVENTORY_SCRIPT = 0xFF;
1778  byte VAR_CUTSCENE_START_SCRIPT = 0xFF;
1779  byte VAR_CUTSCENE_END_SCRIPT = 0xFF;
1780  byte VAR_CHARINC = 0xFF;
1781  byte VAR_WALKTO_OBJ = 0xFF;
1782  byte VAR_DEBUGMODE = 0xFF;
1783  byte VAR_HEAPSPACE = 0xFF;
1784  byte VAR_RESTART_KEY = 0xFF;
1785  byte VAR_PAUSE_KEY = 0xFF;
1786  byte VAR_MOUSE_X = 0xFF;
1787  byte VAR_MOUSE_Y = 0xFF;
1788  byte VAR_TIMER = 0xFF;
1789  byte VAR_TIMER_TOTAL = 0xFF;
1790  byte VAR_SOUNDCARD = 0xFF;
1791  byte VAR_VIDEOMODE = 0xFF;
1792  byte VAR_MAINMENU_KEY = 0xFF;
1793  byte VAR_FIXEDDISK = 0xFF;
1794  byte VAR_CURSORSTATE = 0xFF;
1795  byte VAR_USERPUT = 0xFF;
1796  byte VAR_SOUNDRESULT = 0xFF;
1797  byte VAR_TALKSTOP_KEY = 0xFF;
1798  byte VAR_FADE_DELAY = 0xFF;
1799  byte VAR_NOSUBTITLES = 0xFF;
1800 
1801  // V5+
1802  byte VAR_SOUNDPARAM = 0xFF;
1803  byte VAR_SOUNDPARAM2 = 0xFF;
1804  byte VAR_SOUNDPARAM3 = 0xFF;
1805  byte VAR_INPUTMODE = 0xFF;
1806  byte VAR_MEMORY_PERFORMANCE = 0xFF;
1807  byte VAR_VIDEO_PERFORMANCE = 0xFF;
1808  byte VAR_ROOM_FLAG = 0xFF;
1809  byte VAR_GAME_LOADED = 0xFF;
1810  byte VAR_NEW_ROOM = 0xFF;
1811 
1812  // V4/V5
1813  byte VAR_V5_TALK_STRING_Y = 0xFF;
1814 
1815  // V6+
1816  byte VAR_ROOM_WIDTH = 0xFF;
1817  byte VAR_ROOM_HEIGHT = 0xFF;
1818  byte VAR_SUBTITLES = 0xFF;
1819  byte VAR_V6_EMSSPACE = 0xFF;
1820 
1821  // V7/V8 specific variables
1822  byte VAR_CAMERA_POS_Y = 0xFF;
1823  byte VAR_CAMERA_MIN_Y = 0xFF;
1824  byte VAR_CAMERA_MAX_Y = 0xFF;
1825  byte VAR_CAMERA_THRESHOLD_X = 0xFF;
1826  byte VAR_CAMERA_THRESHOLD_Y = 0xFF;
1827  byte VAR_CAMERA_SPEED_X = 0xFF;
1828  byte VAR_CAMERA_SPEED_Y = 0xFF;
1829  byte VAR_CAMERA_ACCEL_X = 0xFF;
1830  byte VAR_CAMERA_ACCEL_Y = 0xFF;
1831  byte VAR_CAMERA_DEST_X = 0xFF;
1832  byte VAR_CAMERA_DEST_Y = 0xFF;
1833  byte VAR_CAMERA_FOLLOWED_ACTOR = 0xFF;
1834 
1835  // V7/V8 specific variables
1836  byte VAR_VERSION_KEY = 0xFF;
1837  byte VAR_DEFAULT_TALK_DELAY = 0xFF;
1838  byte VAR_CUSTOMSCALETABLE = 0xFF;
1839  byte VAR_BLAST_ABOVE_TEXT = 0xFF;
1840  byte VAR_VOICE_MODE = 0xFF;
1841  byte VAR_MUSIC_BUNDLE_LOADED = 0xFF;
1842  byte VAR_VOICE_BUNDLE_LOADED = 0xFF;
1843 
1844  byte VAR_LEFTBTN_DOWN = 0xFF; // V7/V8
1845  byte VAR_RIGHTBTN_DOWN = 0xFF; // V7/V8
1846  byte VAR_LEFTBTN_HOLD = 0xFF; // V6/V72HE/V7/V8
1847  byte VAR_RIGHTBTN_HOLD = 0xFF; // V6/V72HE/V7/V8
1848  byte VAR_PRE_SAVELOAD_SCRIPT = 0xFF; // V6/V7 (not HE)
1849  byte VAR_POST_SAVELOAD_SCRIPT = 0xFF; // V6/V7 (not HE)
1850  byte VAR_SAVELOAD_PAGE = 0xFF; // V8
1851  byte VAR_OBJECT_LABEL_FLAG = 0xFF; // V8
1852 
1853  // V6/V7 specific variables (FT & Sam & Max specific)
1854  byte VAR_CHARSET_MASK = 0xFF;
1855 
1856  // V6 specific variables
1857  byte VAR_V6_SOUNDMODE = 0xFF;
1858 
1859  // V1/V2 specific variables
1860  byte VAR_CHARCOUNT = 0xFF;
1861  byte VAR_VERB_ALLOWED = 0xFF;
1862  byte VAR_ACTIVE_VERB = 0xFF;
1863  byte VAR_ACTIVE_OBJECT1 = 0xFF;
1864  byte VAR_ACTIVE_OBJECT2 = 0xFF;
1865 
1866  // HE specific variables
1867  byte VAR_ALWAYS_REDRAW_ACTORS = 0xFF; // Used in setActorRedrawFlags()
1868  byte VAR_SKIP_RESET_TALK_ACTOR = 0xFF; // Used in setActorCostume()
1869 
1870  byte VAR_SOUND_CHANNEL = 0xFF; // Used in o_startSound()
1871  byte VAR_TALK_CHANNEL = 0xFF; // Used in playVoice()
1872  byte VAR_SOUND_TOKEN_OFFSET = 0xFF; // Used in handleSoundFrame()
1873  byte VAR_START_DYN_SOUND_CHANNELS = 0xFF; // Used in getNextDynamicChannel()
1874  byte VAR_SOUND_CALLBACK_SCRIPT = 0xFF;
1875 
1876  byte VAR_EARLY_TALKIE_CALLBACK = 0xFF;
1877  byte VAR_EARLY_CHAN_0_CALLBACK = 0xFF;
1878  byte VAR_EARLY_CHAN_1_CALLBACK = 0xFF;
1879  byte VAR_EARLY_CHAN_2_CALLBACK = 0xFF;
1880  byte VAR_EARLY_CHAN_3_CALLBACK = 0xFF;
1881 
1882  byte VAR_MAIN_SCRIPT = 0xFF; // Used in scummLoop()
1883 
1884  byte VAR_DEFAULT_SCRIPT_PRIORITY = 0xFF; // Used in runScript()/runObjectScript()
1885  byte VAR_LAST_SCRIPT_PRIORITY = 0xFF; // Used in runAllScripts()
1886 
1887  byte VAR_QUIT_SCRIPT = 0xFF; // Used in confirmExitDialog()
1888  byte VAR_ERROR_FLAG = 0xFF; // HE70-90
1889  byte VAR_OPERATION_FAILURE = 0xFF; // HE99+
1890 
1891  byte VAR_COLOR_BLACK = 0xFF;
1892 
1893  // Exists both in V7 and in V72HE:
1894  byte VAR_NUM_GLOBAL_OBJS = 0xFF;
1895 
1896 #ifdef USE_RGB_COLOR
1897  // FM-Towns / PC-Engine specific
1898  Graphics::FontSJIS *_cjkFont = nullptr;
1899 #endif
1900 
1901  // FM-Towns specific
1902 #ifndef DISABLE_TOWNS_DUAL_LAYER_MODE
1903 public:
1904  bool towns_isRectInStringBox(int x1, int y1, int x2, int y2);
1905  byte _townsPaletteFlags = 0;
1906  byte _townsCharsetColorMap[16];
1907 
1908 protected:
1909  void towns_drawStripToScreen(VirtScreen *vs, int dstX, int dstY, int srcX, int srcY, int w, int h);
1910  void towns_fillTopLayerRect(int x1, int y1, int x2, int y2, int col);
1911  void towns_swapVirtScreenArea(VirtScreen *vs, int x, int y, int w, int h);
1912  void towns_clearStrip(int strip);
1913 #ifdef USE_RGB_COLOR
1914  void towns_setPaletteFromPtr(const byte *ptr, int numcolor = -1);
1915  void towns_setTextPaletteFromPtr(const byte *ptr);
1916 #endif
1917  void towns_setupPalCycleField(int x1, int y1, int x2, int y2);
1918  void towns_processPalCycleField();
1919  void towns_resetPalCycleFields();
1920  void towns_restoreCharsetBg();
1921  void towns_scriptScrollEffect(int dir);
1922 
1923  void requestScroll(int dir);
1924  void scrollLeft() { requestScroll(-1); }
1925  void scrollRight() { requestScroll(1); }
1926  void towns_waitForScroll(int waitForDirection, int threshold = 0);
1927  void towns_updateGfx();
1928 
1929  Common::Rect _cyclRects[10];
1930  int _numCyclRects = 0;
1931  int _scrollRequest = 0;
1932  int _scrollDeltaAdjust = 0;
1933  bool _scrollNeedDeltaAdjust = 0;
1934  int _refreshDuration[20];
1935  int _refreshArrayPos = 0;
1936  bool _refreshNeedCatchUp = false;
1937  bool _enableSmoothScrolling = false;
1938  bool _forceFMTownsHiResMode = false;
1939  uint32 _scrollTimer = 0;
1940  uint32 _scrollDestOffset = 0;
1941  uint16 _scrollFeedStrips[3];
1942 
1943  Common::Rect _curStringRect;
1944 
1945  byte _townsOverrideShadowColor = 0;
1946  byte _textPalette[48];
1947  byte _townsClearLayerFlag = 1;
1948  byte _townsActiveLayerFlags = 3;
1949  static const uint8 _townsLayer2Mask[];
1950 
1951  TownsScreen *_townsScreen = nullptr;
1952 #else
1953  void scrollLeft() { redrawBGStrip(_gdi->_numStrips - 1, 1); }
1954  void scrollRight() { redrawBGStrip(0, 1); }
1955  void towns_updateGfx() {}
1956  void towns_waitForScroll(int waitForDirection, int threshold = 0) {}
1957  void towns_fillTopLayerRect(int x1, int y1, int x2, int y2, int col) {}
1958  void towns_swapVirtScreenArea(VirtScreen *vs, int x, int y, int w, int h) {}
1959 #endif // DISABLE_TOWNS_DUAL_LAYER_MODE
1960 };
1961 
1962 } // End of namespace Scumm
1963 
1964 #endif
#define ARRAYSIZE(x)
Definition: util.h:91
Definition: charset.h:70
Definition: macgui_impl.h:55
Definition: keymap.h:66
VirtScreenNumber
Definition: gfx.h:161
Definition: gfx.h:563
Definition: str.h:59
Definition: boxes.h:44
Definition: surface.h:67
EngineFeature
Definition: engine.h:253
Definition: stream.h:77
Definition: error.h:84
ErrorCode getCode() const
Definition: error.h:115
Definition: detection.h:117
Definition: script.h:31
Definition: scumm.h:149
Definition: gfx.h:138
Definition: pixelformat.h:138
Definition: script.h:120
Definition: scumm.h:165
Definition: random.h:44
int16 right
Definition: rect.h:146
Definition: palette.h:153
RenderMode
Definition: rendermode.h:48
No error occurred.
Definition: error.h:48
Definition: rect.h:144
Common::Path _containerFile
Definition: scumm.h:1088
Definition: path.h:52
Definition: scumm.h:184
Definition: resource.h:75
Definition: music.h:40
ResType
Definition: scumm.h:256
Definition: stream.h:745
Definition: macgui_indy3.h:37
Definition: sound.h:59
Definition: system.h:46
Definition: serializer.h:79
Definition: scumm.h:176
Definition: scumm.h:518
Definition: gfx.h:185
Graphics::Surface _textSurface
Definition: scumm.h:1628
Definition: scumm.h:197
int FORCEINLINE GCC_PRINTF(2, 0) int vsprintf_s(T(&dst)[N]
Definition: scumm.h:156
Definition: detection.h:44
Definition: ustr.h:57
Definition: scumm.h:232
Definition: player_towns.h:32
Definition: scumm.h:214
Definition: debugger.h:33
Definition: object.h:189
Definition: object.h:64
Definition: imuse.h:50
Definition: events.h:199
Definition: algorithm.h:29
Definition: formatinfo.h:28
Definition: mutex.h:67
Definition: rect.h:45
Definition: macgui_v5.h:33
int16 left
Definition: rect.h:145
Definition: serializer.h:308
Definition: charset.h:155
Definition: scumm.h:478
void NORETURN_PRE error(MSVC_PRINTF const char *s,...) GCC_PRINTF(1
Definition: actor.h:97
Definition: localizer.h:31
Definition: dialog.h:49
Definition: gfx.h:292
Definition: stream.h:351
Definition: base-costume.h:68
Definition: scumm.h:1605
Definition: macgui.h:39
Definition: keyboard.h:294
Common::Error run() override
Definition: scumm.h:580
Common::RandomSource _rnd
Definition: scumm.h:548
Definition: macgui_loom.h:33
Definition: system.h:161
void void void void void debugC(int level, uint32 debugChannels, MSVC_PRINTF const char *s,...) GCC_PRINTF(3
Definition: base-costume.h:49
Definition: engine.h:144
Definition: actor.h:30
Definition: gfx.h:279
Definition: verbs.h:47
Definition: detection.h:131
Definition: file.h:34
Language
Definition: language.h:45