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