ScummVM API documentation
script.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 GROOVIE_SCRIPT_H
23 #define GROOVIE_SCRIPT_H
24 
25 #include "groovie/groovie.h"
26 #ifdef ENABLE_GROOVIE2
27 #include "groovie/logic/beehive.h"
28 #include "groovie/logic/cake.h"
29 #include "groovie/logic/gallery.h"
30 #include "groovie/logic/mousetrap.h"
31 #include "groovie/logic/othello.h"
32 #include "groovie/logic/pente.h"
33 #include "groovie/logic/triangle.h"
34 #include "groovie/logic/winerack.h"
35 #endif
36 
37 #include "common/random.h"
38 #include "common/rect.h"
39 
40 namespace Common {
41 class SeekableReadStream;
42 }
43 
44 namespace Graphics {
45 struct Surface;
46 }
47 
48 namespace Groovie {
49 
50 class CellGame;
51 class Debugger;
52 class GroovieEngine;
53 class TlcGame;
54 
55 class Script {
56  friend class Debugger;
57 
58 public:
59  Script(GroovieEngine *vm, EngineVersion version);
60  ~Script();
61 
62  void setDebugger(Debugger *debugger);
63  void setVariable(uint16 varnum, byte value);
64 
65  void timerTick();
66 
67  bool loadScript(Common::String scriptfile);
68  void directGameLoad(int slot);
69  void directGameSave(int slot, const Common::String &desc);
70  bool canDirectSave() const;
71  void step();
72 
73  void setMouseClick(uint8 button);
74  void setKbdChar(uint8 c);
75 
76  void setBitFlag(int bitnum, bool value);
77  bool getBitFlag(int bitnum);
78 
79  Common::String &getContext();
80 
81 private:
82  GroovieEngine *_vm;
83 
84  Common::RandomSource _random;
85 
86  bool _firstbit;
87  uint8 _lastCursor;
88 
89  EngineVersion _version;
90 
91  // Script filename (for debugging purposes)
92  Common::String _scriptFile;
93  Common::String _savedScriptFile;
94 
95  // Save names
96  Common::String _saveNames[MAX_SAVES];
97  bool _wantAutosave;
98 
99  // Code
100  byte *_code;
101  uint16 _codeSize;
102  uint16 _currentInstruction;
103  byte *_savedCode;
104  uint16 _savedCodeSize;
105  uint16 _savedInstruction;
106 
107  // Variables
108  byte _variables[0x400];
109  byte _savedVariables[0x180];
110 
111  // Stack
112  uint16 _stack[0x20];
113  uint8 _stacktop;
114  uint8 _savedStacktop;
115 
116  // Input
117  bool _mouseClicked;
118  uint8 _eventMouseClicked;
119  uint8 _kbdChar;
120  uint8 _eventKbdChar;
121  uint16 _inputLoopAddress;
122  uint8 _newCursorStyle;
123  uint16 _hotspotTopAction;
124  uint16 _hotspotTopCursor;
125  uint16 _hotspotBottomAction;
126  uint16 _hotspotBottomCursor;
127  uint16 _hotspotRightAction;
128  uint16 _hotspotLeftAction;
129  uint16 _hotspotSlot;
130  bool _fastForwarding;
131  void resetFastForward();
132 
133  // Video
134  Common::SeekableReadStream *_videoFile;
135  uint32 _videoRef;
136  uint16 _bitflags;
137  uint16 _videoSkipAddress;
138 
139  // Debugging
140  Debugger *_debugger;
141  Common::String _debugString;
142  uint16 _oldInstruction;
143 
144  // Special classes depending on played game
145  CellGame *_cellGame;
146  TlcGame *_tlcGame;
147 
148  // Helper functions
149  uint8 getCodeByte(uint16 address);
150  uint8 readScript8bits();
151  uint16 readScript16bits();
152  uint32 readScript32bits();
153  uint16 readScript8or16bits();
154  uint8 readScriptChar(bool allow7C, bool limitVal, bool limitVar);
155  void readScriptString(Common::String &str);
156  uint8 readScriptVar();
157  uint32 getVideoRefString(Common::String &resName);
158 
159  void executeInputAction(uint16 address);
160  bool hotspot(Common::Rect rect, uint16 addr, uint8 cursor);
161 
162  void loadgame(uint slot);
163  bool preview_loadgame(uint slot);
164  void savegame(uint slot, const char name[27]);
165  bool playvideofromref(uint32 fileref, bool loopUntilAudioDone = false);
166  bool playBackgroundSound(uint32 fileref, uint32 loops);
167  void printString(Graphics::Surface *surface, const char *str);
168 
169  // Opcodes
170  typedef void (Script::*OpcodeFunc)();
171  OpcodeFunc *_opcodes;
172  static OpcodeFunc _opcodesT7G[];
173  static OpcodeFunc _opcodesV2[];
174 
175  void o_invalid();
176 
177  void o_nop();
178  void o_nop8();
179  void o_nop16();
180  void o_nop32();
181  void o_nop8or16();
182 
183  void o_playsong();
184  void o_bf9on();
185  void o_palfadeout();
186  void o_bf8on();
187  void o_bf6on();
188  void o_bf7on();
189  void o_setbackgroundsong();
190  void o_videofromref();
191  void o_bf5on();
192  void o_inputloopstart();
193  void o_keyboardaction();
194  void o_hotspot_rect();
195  void o_hotspot_left();
196  void o_hotspot_right();
197  void o_hotspot_center();
198  void o_hotspot_current();
199  void o_inputloopend();
200  void o_random();
201  void o_jmp();
202  void o_loadstring();
203  void o_ret();
204  void o_call();
205  void o_sleep();
206  void o_strcmpnejmp_var();
207  void o_copybgtofg();
208  void o_strcmpnejmp();
209  void o_xor_obfuscate();
210  void o_vdxtransition();
211  void o_swap();
212  void o_inc();
213  void o_dec();
214  void o_strcmpeqjmp();
215  void o_mov();
216  void o_add();
217  void o_videofromstring1();
218  void o_videofromstring2();
219  void o_stopmidi();
220  void o_endscript();
221  void o_sethotspottop();
222  void o_sethotspotbottom();
223  void o_loadgame();
224  void o_savegame();
225  void o_hotspotbottom_4();
226  void o_midivolume();
227  void o_jne();
228  void o_loadstringvar();
229  void o_chargreatjmp();
230  void o_bf7off();
231  void o_charlessjmp();
232  void o_copyrecttobg();
233  void o_restorestkpnt();
234  void o_obscureswap();
235  void o_printstring();
236  void o_hotspot_slot();
237  void o_checkvalidsaves();
238  void o_resetvars();
239  void o_mod();
240  void o_loadscript();
241  void o_setvideoorigin();
242  void o_sub();
243  void o_returnscript();
244  void o_sethotspotright();
245  void o_sethotspotleft();
246  void o_getcd();
247  void o_playcd();
248  void o_musicdelay();
249  void o_hotspot_outrect();
250  void o_stub56();
251  void o_wipemaskfromstring58();
252  void o_stub59();
253 
254  void o2_bf0on();
255  void o2_copybgtofg();
256  void o2_printstring();
257  void o2_playsong();
258  void o2_midicontrol();
259  void o2_setbackgroundsong();
260  void o2_videofromref();
261  void o2_vdxtransition();
262  void o2_setvideoskip();
263  void o2_savescreen();
264  void o2_restorescreen();
265  void o_gamelogic();
266  void o2_copyfgtobg();
267  void o2_setscriptend();
268  void o2_playsound();
269  void o2_check_sounds_overlays();
270  void o2_preview_loadgame();
271 
272 #ifdef ENABLE_GROOVIE2
273  BeehiveGame _beehive;
274  CakeGame _cake;
275  GalleryGame _gallery;
276  MouseTrapGame _mouseTrap;
277  OthelloGame _othello;
278  PenteGame _pente;
279  TriangleGame _triangle;
280  WineRackGame _wineRack;
281 #endif
282 };
283 
284 } // End of Groovie namespace
285 
286 #endif // GROOVIE_SCRIPT_H
Definition: cake.h:39
Definition: str.h:59
Definition: othello.h:49
Definition: surface.h:66
Definition: groovie.h:113
Definition: mousetrap.h:54
Definition: cell.h:40
Definition: random.h:44
Definition: rect.h:144
Definition: stream.h:745
Definition: winerack.h:41
Definition: triangle.h:36
Definition: algorithm.h:29
Definition: debug.h:32
Definition: script.h:55
Definition: formatinfo.h:28
Definition: beehive.h:44
Definition: pente.h:43
Definition: tlcgame.h:76
Definition: cursor.h:32