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 * This file is dual-licensed.
22 * In addition to the GPLv3 license mentioned above, this code is also
23 * licensed under LGPL 2.1. See LICENSES/COPYING.LGPL file for the
24 * full text of the license.
25 *
26 */
27
28#ifndef GOB_SCRIPT_H
29#define GOB_SCRIPT_H
30
31#include "common/str.h"
32#include "common/stack.h"
33
34#include "gob/totfile.h"
35
36namespace Gob {
37
38class GobEngine;
39class Expression;
40
41class Script {
42public:
43 Script(GobEngine *vm);
44 ~Script();
45
47 uint32 read(byte *data, int32 size);
49 uint32 peek(byte *data, int32 size, int32 offset = 0) const;
50
51 // Stream properties
52 int32 pos() const;
53 int32 getSize() const;
54
55 // Stream seeking
56 bool seek(int32 offset, int whence = SEEK_SET);
57 bool skip(int32 offset);
58 bool skipBlock();
59
60 // Reading data
61 byte readByte ();
62 char readChar ();
63 uint8 readUint8 ();
64 uint16 readUint16();
65 uint32 readUint32();
66 int8 readInt8 ();
67 int16 readInt16 ();
68 int32 readInt32 ();
69 char *readString(int32 length = -1);
70
71 // Peeking data
72 byte peekByte (int32 offset = 0);
73 char peekChar (int32 offset = 0);
74 uint8 peekUint8 (int32 offset = 0);
75 uint16 peekUint16(int32 offset = 0);
76 uint32 peekUint32(int32 offset = 0);
77 int8 peekInt8 (int32 offset = 0);
78 int16 peekInt16 (int32 offset = 0);
79 int32 peekInt32 (int32 offset = 0);
80 char *peekString(int32 offset = 0);
81
82 // Expression parsing functions
83 uint16 readVarIndex(uint16 *size = 0, uint16 *type = 0);
84 int16 readValExpr(byte stopToken = 99);
85 int16 readExpr(byte stopToken, byte *type);
86 void skipExpr(char stopToken);
87
88 // Higher-level expression parsing functions
89 char evalExpr(int32 *pRes);
90 bool evalBool();
91 int32 evalInt();
92
93 const char *evalString();
94
95 // Accessing the result of expressions
96 int32 getResultInt() const;
97 char *getResultStr() const;
98
100 int32 getOffset(byte *ptr) const;
102 byte *getData(int32 offset) const;
103
105 byte *getData();
106
108 bool load(const Common::String &fileName);
110 void unload();
112 bool isLoaded() const;
113
115 void setFinished(bool finished);
117 bool isFinished() const;
118
119 // Call stack operations
121 void push();
123 void pop(bool ret = true);
125 void call(uint32 offset);
126
128 void writeByte(int32 offset, byte v);
129
130 // Fixed properties
131 uint8 getVersionMajor () const;
132 uint8 getVersionMinor () const;
133 uint32 getVariablesCount () const;
134 uint32 getTextsOffset () const;
135 uint32 getResourcesOffset() const;
136 uint16 getAnimDataSize () const;
137 uint8 getImFileNumber () const;
138 uint8 getExFileNumber () const;
139 uint8 getCommunHandling () const;
140
141 uint16 getFunctionOffset (uint8 function) const;
142
143 static uint32 getVariablesCount(const char *fileName, GobEngine *vm);
144
145 int32 _currentOpcodePos = 0; // for debugging purposes only
146
147private:
148 struct CallEntry {
149 byte *totPtr;
150 bool finished;
151 };
152
153 GobEngine *_vm;
154 Expression *_expression;
155
156 bool _finished;
157
158 Common::String _totFile;
159 byte *_totData;
160 byte *_totPtr;
161 uint32 _totSize;
162
164
165 TOTFile::Properties _totProperties;
166
167 Common::Stack<CallEntry> _callStack;
168
170 bool loadTOT(const Common::String &fileName);
172 bool loadLOM(const Common::String &fileName);
173
175 void unloadTOT();
176};
177
178} // End of namespace Gob
179
180#endif // GOB_SCRIPT_H
Definition: stream.h:745
Definition: str.h:59
Definition: expression.h:114
Definition: gob.h:166
Definition: script.h:41
bool isLoaded() const
uint32 read(byte *data, int32 size)
void unload()
void call(uint32 offset)
void setFinished(bool finished)
bool isFinished() const
byte * getData(int32 offset) const
void pop(bool ret=true)
uint32 peek(byte *data, int32 size, int32 offset=0) const
void writeByte(int32 offset, byte v)
bool load(const Common::String &fileName)
int32 getOffset(byte *ptr) const
byte * getData()
Definition: totfile.h:46