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