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 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (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, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 */ 22 23 #ifndef TOLTECS_SCRIPT_H 24 #define TOLTECS_SCRIPT_H 25 26 #include "common/func.h" 27 28 namespace Toltecs { 29 30 const int kMaxScriptSlots = 50; 31 const int kScriptStackSize = 4096 + 4; 32 33 enum VarType { 34 vtByte, 35 vtWord 36 }; 37 38 typedef Common::Functor0<void> ScriptFunction; 39 40 class ScriptInterpreter { 41 public: 42 ScriptInterpreter(ToltecsEngine *vm); 43 ~ScriptInterpreter(); 44 45 void loadScript(uint resIndex, uint slotIndex); 46 void setMainScript(uint slotIndex); 47 void runScript(); 48 getSlotData(int slotIndex)49 byte *getSlotData(int slotIndex) const { return _slots[slotIndex].data; } 50 51 int16 getGameVar(uint variable); 52 void setGameVar(uint variable, int16 value); 53 54 void saveState(Common::WriteStream *out); 55 void loadState(Common::ReadStream *in); 56 setSwitchLocalDataNear(bool newValue)57 void setSwitchLocalDataNear(bool newValue) { _switchLocalDataNear = newValue; } 58 59 protected: 60 61 struct ScriptRegs { 62 int16 reg0; 63 int16 reg1; 64 int16 reg2; 65 int16 reg3; 66 int16 reg4; 67 int16 reg5; 68 int16 reg6; 69 int16 sp; 70 int16 reg8; 71 }; 72 73 struct ScriptSlot { 74 byte *data; 75 int32 size; 76 uint resIndex; 77 }; 78 79 ToltecsEngine *_vm; 80 Common::Array<const ScriptFunction *> _scriptFuncs; 81 Common::Array<const char *> _scriptFuncNames; 82 83 byte *_stack; 84 85 byte *_code, *_subCode, *_codeStart; 86 byte *_localData; 87 bool _switchLocalDataNear, _switchLocalDataFar, _switchLocalDataToStack; 88 bool _cmpBitTest; 89 90 ScriptSlot _slots[kMaxScriptSlots]; 91 92 ScriptRegs _regs; 93 int16 _savedSp; 94 95 byte readByte(); 96 int16 readInt16(); 97 98 void execOpcode(byte opcode); 99 100 void setupScriptFunctions(); 101 void execScriptFunction(uint16 index); 102 103 byte arg8(int16 offset); 104 int16 arg16(int16 offset); 105 106 void pushInt16(int16 value); 107 int16 popInt16(); 108 109 void localWrite8(int16 offset, byte value); 110 byte localRead8(int16 offset); 111 void localWrite16(int16 offset, int16 value); 112 int16 localRead16(int16 offset); 113 byte *localPtr(int16 offset); 114 115 void sfNop(); 116 void sfGetGameVar(); 117 void sfSetGameVar(); 118 void sfUpdateScreen(); 119 void sfGetRandomNumber(); 120 void sfDrawGuiTextMulti(); 121 void sfUpdateVerbLine(); 122 void sfSetFontColor(); 123 void sfGetTalkTextDuration(); 124 void sfTalk(); 125 void sfFindPaletteFragment(); 126 void sfClearPaletteFragments(); 127 void sfAddPaletteFragment(); 128 void sfSetDeltaAnimPalette(); 129 void sfSetUnkPaletteEffect(); 130 void sfBuildColorTransTable(); 131 void sfSetDeltaMainPalette(); 132 void sfLoadScript(); 133 void sfRegisterFont(); 134 void sfLoadAddPalette(); 135 void sfLoadScene(); 136 void sfSetGuiHeight(); 137 void sfFindMouseInRectIndex1(); 138 void sfFindMouseInRectIndex2(); 139 void sfDrawGuiImage(); 140 void sfAddAnimatedSpriteNoLoop(); 141 void sfAddAnimatedSprite(); 142 void sfAddStaticSprite(); 143 void sfAddAnimatedSpriteScaled(); 144 void sfFindPath(); 145 void sfWalk(); 146 void sfScrollCameraUp(); 147 void sfScrollCameraDown(); 148 void sfScrollCameraLeft(); 149 void sfScrollCameraRight(); 150 void sfScrollCameraUpEx(); 151 void sfScrollCameraDownEx(); 152 void sfScrollCameraLeftEx(); 153 void sfScrollCameraRightEx(); 154 void sfSetCamera(); 155 void sfGetCameraChanged(); 156 void sfGetRgbModifiertAtPoint(); 157 void sfStartAnim(); 158 void sfAnimNextFrame(); 159 void sfGetAnimFrameNumber(); 160 void sfGetAnimStatus(); 161 void sfStartShakeScreen(); 162 void sfStopShakeScreen(); 163 void sfStartSequence(); 164 void sfEndSequence(); 165 void sfSetSequenceVolume(); 166 void sfPlayPositionalSound(); 167 void sfPlaySound2(); 168 void sfClearScreen(); 169 void sfHandleInput(); 170 void sfRunOptionsScreen(); 171 void sfPrecacheSprites(); 172 void sfPrecacheSounds1(); 173 void sfDeletePrecachedFiles(); 174 void sfPrecacheSounds2(); 175 void sfRestoreStackPtr(); 176 void sfSaveStackPtr(); 177 void sfPlayMovie(); 178 179 }; 180 181 182 } // End of namespace Toltecs 183 184 #endif /* TOLTECS_H */ 185