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