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