25 #include "common/scummsys.h" 26 #include "common/error.h" 27 #include "common/util.h" 28 #include "common/file.h" 29 #include "common/keyboard.h" 30 #include "common/rect.h" 31 #include "common/rendermode.h" 32 #include "common/stack.h" 33 #include "common/str.h" 34 #include "common/system.h" 36 #include "engines/engine.h" 38 #include "gui/debugger.h" 41 #include "agi/console.h" 43 #include "agi/picture.h" 44 #include "agi/logic.h" 45 #include "agi/sound.h" 65 #define TITLE "AGI engine" 68 #define LOGDIR "logdir" 69 #define PICDIR "picdir" 70 #define VIEWDIR "viewdir" 71 #define SNDDIR "snddir" 72 #define OBJECTS "object" 73 #define WORDS "words.tok" 75 #define MAX_DIRECTORY_ENTRIES 256 76 #define MAX_CONTROLLERS 256 78 #define MAX_FLAGS (256 >> 3) 79 #define SCREENOBJECTS_MAX 255 // KQ3 uses o255! 80 #define SCREENOBJECTS_EGO_ENTRY 0 // first entry is ego 82 #define MAX_STRINGS 24 // MAX_STRINGS + 1 used for get.num 83 #define MAX_STRINGLEN 40 84 #define MAX_CONTROLLER_KEYMAPPINGS 39 86 #define SAVEDGAME_DESCRIPTION_LEN 30 88 #define _EMPTY 0xfffff 89 #define EGO_OWNED 0xff 90 #define EGO_OWNED_V1 0xf9 92 #define CRYPT_KEY_SIERRA "Avis Durgan" 93 #define CRYPT_KEY_AGDS "Alex Simkin" 108 enum AgiGameFeatures {
109 GF_AGIMOUSE = (1 << 0),
111 GF_AGI256 = (1 << 2),
112 GF_FANMADE = (1 << 3),
113 GF_2GSOLDSOUND = (1 << 5),
114 GF_EXTCHAR = (1 << 6)
153 kDebugLevelMain = 1 << 0,
154 kDebugLevelResources = 1 << 1,
155 kDebugLevelSprites = 1 << 2,
156 kDebugLevelInventory = 1 << 3,
157 kDebugLevelInput = 1 << 4,
158 kDebugLevelMenu = 1 << 5,
159 kDebugLevelScripts = 1 << 6,
160 kDebugLevelSound = 1 << 7,
161 kDebugLevelText = 1 << 8,
162 kDebugLevelSavegame = 1 << 9
169 RESOURCETYPE_LOGIC = 1,
177 RES_COMPRESSED = 0x40,
178 RES_PICTURE_V3_NIBBLE_PARM = 0x80
199 Mouse() : button(0) {}
203 enum AgiMouseButton {
206 kAgiMouseButtonRight,
207 kAgiMouseButtonMiddle
214 VM_VAR_CURRENT_ROOM = 0,
215 VM_VAR_PREVIOUS_ROOM,
216 VM_VAR_BORDER_TOUCH_EGO,
219 VM_VAR_BORDER_TOUCH_OBJECT,
220 VM_VAR_EGO_DIRECTION,
223 VM_VAR_WORD_NOT_FOUND,
229 VM_VAR_JOYSTICK_SENSITIVITY,
230 VM_VAR_EGO_VIEW_RESOURCE,
231 VM_VAR_AGI_ERROR_CODE,
232 VM_VAR_AGI_ERROR_INFO,
235 VM_VAR_WINDOW_AUTO_CLOSE_TIMER,
236 VM_VAR_SOUNDGENERATOR,
238 VM_VAR_MAX_INPUT_CHARACTERS,
239 VM_VAR_SELECTED_INVENTORY_ITEM,
241 VM_VAR_MOUSE_BUTTONSTATE = 27,
253 kAgiMonitorHercules = 2,
264 kAgiComputerApple2 = 3,
265 kAgiComputerAtariST = 4,
266 kAgiComputerAmiga = 5,
267 kAgiComputerApple2GS = 7
280 VM_FLAG_EGO_WATER = 0,
281 VM_FLAG_EGO_INVISIBLE,
283 VM_FLAG_EGO_TOUCHED_P2,
284 VM_FLAG_SAID_ACCEPTED_INPUT,
285 VM_FLAG_NEW_ROOM_EXEC,
286 VM_FLAG_RESTART_GAME,
287 VM_FLAG_SCRIPT_BLOCKED,
288 VM_FLAG_JOY_SENSITIVITY,
291 VM_FLAG_LOGIC_ZERO_FIRST_TIME,
292 VM_FLAG_RESTORE_JUST_RAN,
293 VM_FLAG_STATUS_SELECTS_ITEMS,
294 VM_FLAG_MENUS_ACCESSIBLE,
340 AgiBlock() : active(
false), x1(0), y1(0), x2(0), y2(0) {}
348 enum CycleInnerLoopType {
349 CYCLE_INNERLOOP_GETSTRING = 0,
350 CYCLE_INNERLOOP_GETNUMBER,
351 CYCLE_INNERLOOP_INVENTORY,
352 CYCLE_INNERLOOP_MENU_VIA_KEYBOARD,
353 CYCLE_INNERLOOP_MENU_VIA_MOUSE,
354 CYCLE_INNERLOOP_SYSTEMUI_SELECTSAVEDGAMESLOT,
355 CYCLE_INNERLOOP_SYSTEMUI_VERIFICATION,
356 CYCLE_INNERLOOP_MESSAGEBOX,
357 CYCLE_INNERLOOP_HAVEKEY
381 uint8 flags[MAX_FLAGS];
382 uint8 vars[MAX_VARS];
387 bool cycleInnerLoopActive;
388 int16 cycleInnerLoopType;
404 unsigned int numObjects;
406 bool controllerOccurred[MAX_CONTROLLERS];
409 char strings[MAX_STRINGS + 1][MAX_STRINGLEN];
412 AgiDir dirLogic[MAX_DIRECTORY_ENTRIES];
413 AgiDir dirPic[MAX_DIRECTORY_ENTRIES];
414 AgiDir dirView[MAX_DIRECTORY_ENTRIES];
415 AgiDir dirSound[MAX_DIRECTORY_ENTRIES];
431 char automaticSaveDescription[SAVEDGAME_DESCRIPTION_LEN + 1];
451 bool nonBlockingTextShown;
452 int16 nonBlockingTextCyclesLeft;
454 bool automaticRestoreGame;
458 uint16 appleIIgsSpeedControllerSlot;
460 const char *getString(
int number);
461 void setString(
int number,
const char *str);
465 void setSpeedLevel(byte s);
473 memset(
id, 0,
sizeof(
id));
475 memset(flags, 0,
sizeof(flags));
476 memset(vars, 0,
sizeof(vars));
480 cycleInnerLoopActive =
false;
481 cycleInnerLoopType = 0;
487 playerControl =
false;
488 exitAllLogics =
false;
489 pictureShown =
false;
497 memset(controllerOccurred, 0,
sizeof(controllerOccurred));
501 memset(strings, 0,
sizeof(strings));
511 memset(sounds, 0,
sizeof(sounds));
519 automaticSave =
false;
520 memset(automaticSaveDescription, 0,
sizeof(automaticSaveDescription));
523 mouseEnabled =
false;
525 predictiveDlgOnMouseClick =
false;
530 memset(logic_list, 0,
sizeof(logic_list));
532 nonBlockingTextShown =
false;
533 nonBlockingTextCyclesLeft = 0;
535 automaticRestoreGame =
false;
539 appleIIgsSpeedControllerSlot = 0xffff;
575 virtual int loadDirs() = 0;
580 virtual uint8 *loadVolumeResource(
AgiDir *agid) = 0;
585 virtual int loadObjects() = 0;
590 virtual int loadWords() = 0;
601 void init()
override;
602 int loadDirs()
override;
603 uint8 *loadVolumeResource(
AgiDir *agid)
override;
604 int loadObjects()
override;
605 int loadWords()
override;
630 void init()
override;
631 int loadDirs()
override;
632 uint8 *loadVolumeResource(
AgiDir *agid)
override;
633 int loadObjects()
override;
634 int loadWords()
override;
656 bool _hasV3VolumeFormat;
658 int loadDir(
AgiDir *agid,
const char *fname);
659 bool detectV3VolumeFormat();
664 int loadDirs()
override;
665 uint8 *loadVolumeResource(
AgiDir *agid)
override;
666 int loadObjects()
override;
667 int loadWords()
override;
679 void init()
override;
680 int loadDirs()
override;
681 uint8 *loadVolumeResource(
AgiDir *agid)
override;
682 int loadObjects()
override;
683 int loadWords()
override;
709 #define TICK_SECONDS 20 711 #define KEY_QUEUE_SIZE 16 727 virtual void initialize() = 0;
729 void initRenderMode();
746 bool _noSaveLoadAllowed;
748 virtual bool promptIsEnabled() {
752 virtual int getKeypress() = 0;
753 virtual bool isKeypress() = 0;
754 virtual void clearKeyQueue() = 0;
759 virtual void clearImageStack() = 0;
760 virtual void recordImageStackCall(uint8 type, int16 p1, int16 p2, int16 p3,
761 int16 p4, int16 p5, int16 p6, int16 p7) = 0;
762 virtual void replayImageStackCall(uint8 type, int16 p1, int16 p2, int16 p3,
763 int16 p4, int16 p5, int16 p6, int16 p7) = 0;
764 virtual void releaseImageStack() = 0;
768 bool getFlag(int16 flagNr);
769 void setFlag(int16 flagNr,
bool newState);
770 void flipFlag(int16 flagNr);
772 void setFlagOrVar(int16 flagNr,
bool newState);
776 uint32 _gameFeatures;
779 uint32 getGameID()
const;
780 uint32 getFeatures()
const;
781 uint16 getVersion()
const;
782 uint16 getGameType()
const;
784 bool isLanguageRTL()
const;
786 const char *getGameMD5()
const;
790 const char *getDiskName(uint16
id);
795 const byte *getFontData();
797 void cycleInnerLoopActive(int16 loopType) {
798 _game.cycleInnerLoopActive =
true;
799 _game.cycleInnerLoopType = loopType;
801 void cycleInnerLoopInactive() {
802 _game.cycleInnerLoopActive =
false;
804 bool cycleInnerLoopIsActive() {
805 return _game.cycleInnerLoopActive;
809 enum AgiArtificialDelayTriggerType {
810 ARTIFICIALDELAYTYPE_NEWROOM = 0,
811 ARTIFICIALDELAYTYPE_NEWPICTURE = 1,
812 ARTIFICIALDELAYTYPE_END = -1
818 AgiArtificialDelayTriggerType triggerType;
821 uint16 millisecondsDelay;
828 const char *parameters;
829 AgiOpCodeFunction functionPtr;
830 uint16 parameterSize;
835 const char *parameters;
836 AgiOpCodeFunction functionPtr;
844 void initialize()
override;
850 bool promptIsEnabled()
override;
856 int _keyQueue[KEY_QUEUE_SIZE];
860 bool _allowSynthetic;
871 SavedGameSlotIdArray getSavegameSlotIds();
872 bool getSavegameInformation(int16 slotId,
Common::String &saveDescription, uint32 &saveDate, uint32 &saveTime,
bool &saveIsValid);
875 int loadGame(
const Common::String &fileName,
bool checkId =
true);
876 bool saveGameDialog();
877 bool saveGameAutomatic();
878 bool loadGameDialog();
879 bool loadGameAutomatic();
881 int doLoad(
int slot,
bool showMessages);
882 int scummVMSaveLoadDialog(
bool isSave);
898 void clearImageStack()
override;
899 void recordImageStackCall(uint8 type, int16 p1, int16 p2, int16 p3,
900 int16 p4, int16 p5, int16 p6, int16 p7)
override;
901 void replayImageStackCall(uint8 type, int16 p1, int16 p2, int16 p3,
902 int16 p4, int16 p5, int16 p6, int16 p7)
override;
903 void releaseImageStack()
override;
905 void wait(uint32 msec,
bool busy =
false);
909 int loadResource(int16 resourceType, int16 resourceNr);
910 void unloadResource(int16 resourceType, int16 resourceNr);
914 void unloadResources();
916 int getKeypress()
override;
917 bool isKeypress()
override;
918 void clearKeyQueue()
override;
920 byte getVar(int16 varNr);
921 void setVar(int16 varNr, byte newValue);
924 void applyVolumeToMixer();
927 void syncSoundSettings()
override;
930 void decrypt(uint8 *mem,
int len);
931 uint16 processAGIEvents();
934 void newRoom(int16 newRoomNr);
935 void resetControllers();
936 void interpretCycle();
939 void allowSynthetic(
bool);
940 void processScummVMEvents();
941 void checkQuickLoad();
943 const Common::String getTargetName()
const {
return _targetName; }
950 int loadObjects(
const char *fname);
952 const char *objectName(uint16 objectNr);
953 int objectGetLocation(uint16 objectNr);
954 void objectSetLocation(uint16 objectNr,
int location);
956 int decodeObjects(uint8 *mem, uint32 flen);
960 int decodeLogic(int16 logicNr);
961 void unloadLogic(int16 logicNr);
962 int runLogic(int16 logicNr);
963 void debugConsole(
int lognum,
int mode,
const char *str);
964 bool testIfCode(int16 logicNr);
965 void executeAgiCommand(uint8 op, uint8 *p);
968 bool _veryFirstInitialCycle;
969 uint32 _instructionCounter;
971 bool _setVolumeBrokenFangame;
973 void resetGetVarSecondsHeuristic();
974 void getVarSecondsHeuristicTrigger();
975 uint32 _getVarSecondsHeuristicLastInstructionCounter;
976 uint16 _getVarSecondsHeuristicCounter;
978 uint32 _playTimeInSecondsAdjust;
980 void setVarSecondsTrigger(byte newSeconds);
984 void skipInstruction(byte op);
985 void skipInstructionsUntil(byte v);
986 bool testObjRight(uint8 n, uint8 x1, uint8 y1, uint8 x2, uint8 y2);
987 bool testObjCenter(uint8 n, uint8 x1, uint8 y1, uint8 x2, uint8 y2);
988 bool testObjInBox(uint8 n, uint8 x1, uint8 y1, uint8 x2, uint8 y2);
989 bool testPosn(uint8 n, uint8 x1, uint8 y1, uint8 x2, uint8 y2);
990 bool testSaid(uint8 nwords, uint8 *cc);
991 bool testController(uint8 cont);
992 bool testCompareStrings(uint8 s1, uint8 s2);
1007 void updateScreenObjTable();
1008 void unloadView(int16 viewNr);
1009 int decodeView(byte *resourceData, uint16 resourceSize, int16 viewNr);
1012 void unpackViewCelData(
AgiViewCel *celData, byte *compressedData, uint16 compressedSize, int16 viewNr);
1013 void unpackViewCelDataAGI256(
AgiViewCel *celData, byte *compressedData, uint16 compressedSize, int16 viewNr);
1020 int checkStep(
int delta,
int step);
1021 bool checkBlock(int16 x, int16 y);
1032 void checkAllMotions();
1035 void fixPosition(int16 screenObjNr);
1037 void updatePosition();
1038 int getDirection(int16 objX, int16 objY, int16 destX, int16 destY, int16 stepSize);
1041 Common::KeyCode _keyHoldModeLastKey;
1044 int doPollKeyboard();
1046 bool handleMouseClicks(uint16 &key);
1047 bool handleController(uint16 key);
1049 bool showPredictiveDialog();
1053 void waitAnyKeyOrFinishedSound();
1055 void nonBlockingText_IsShown();
1056 void nonBlockingText_Forget();
1058 void artificialDelay_Reset();
1059 void artificialDelay_CycleDone();
1061 uint16 artificialDelay_SearchTable(AgiArtificialDelayTriggerType triggerType, int16 orgNr, int16 newNr);
1063 void artificialDelayTrigger_NewRoom(int16 newRoomNr);
1064 void artificialDelayTrigger_DrawPicture(int16 newPictureNr);
1067 int16 _artificialDelayCurrentRoom;
1068 int16 _artificialDelayCurrentPicture;
1071 void redrawScreen();
1073 void inGameTimerReset(uint32 newPlayTime = 0);
1074 void inGameTimerResetPassedCycles();
1075 uint32 inGameTimerGet();
1076 uint32 inGameTimerGetPassedCycles();
1078 void inGameTimerUpdate();
1081 uint32 _lastUsedPlayTimeInCycles;
1082 uint32 _lastUsedPlayTimeInSeconds;
1083 uint32 _passedPlayTimeCycles;
1089 void setupOpCodes(uint16 version);
1095 void goldRushClockTimeWorkaround_OnReadVar();
1096 void goldRushClockTimeWorkaround_OnWriteVar(byte oldValue);
bool pictureShown
Definition: agi.h:396
int adjMouseX
Definition: agi.h:374
EngineFeature
Definition: engine.h:253
ErrorCode getCode() const
Definition: error.h:115
bool playerControl
Definition: agi.h:394
RenderMode
Definition: rendermode.h:48
No error occurred.
Definition: error.h:48
bool predictiveDlgOnMouseClick
Definition: agi.h:436
Definition: systemui.h:51
virtual void init()
Definition: agi.h:569
AgiMonitorType
Definition: agi.h:250
int adjMouseY
Definition: agi.h:375
byte speedLevel
Definition: agi.h:456
bool mouseEnabled
Definition: agi.h:434
Definition: graphics.h:58
int16 curLogicNr
Definition: agi.h:390
uint32 crc
Definition: agi.h:378
Definition: algorithm.h:29
bool automaticSave
Definition: agi.h:430
A2DirVersion
Definition: agi.h:555
bool mouseHidden
Definition: agi.h:435
bool exitAllLogics
Definition: agi.h:395
Common::Error run() override
Definition: agi.h:718
AgiComputerType
Definition: agi.h:262
Definition: appleIIgs_timedelay_overwrite.h:36
int16 horizon
Definition: agi.h:385
Common::Rect mouseFence
Definition: agi.h:433
Definition: detection.h:29
Language
Definition: language.h:45