2005-01-09 16:06:29 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
2006-01-18 17:39:49 +00:00
|
|
|
* Copyright (C) 2004-2006 The ScummVM project
|
2004-10-15 06:06:47 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2004-10-15 06:06:47 +00:00
|
|
|
*
|
2006-02-09 12:19:53 +00:00
|
|
|
* $URL$
|
|
|
|
* $Id$
|
2004-10-15 06:06:47 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2005-10-03 20:21:18 +00:00
|
|
|
#ifndef KYRASCRIPT_H
|
|
|
|
#define KYRASCRIPT_H
|
2004-10-15 06:06:47 +00:00
|
|
|
|
2005-10-13 18:05:04 +00:00
|
|
|
#include "kyra/kyra.h"
|
|
|
|
|
2004-10-15 06:06:47 +00:00
|
|
|
namespace Kyra {
|
2005-10-13 18:05:04 +00:00
|
|
|
struct ScriptData {
|
|
|
|
byte *text;
|
|
|
|
byte *data;
|
|
|
|
byte *ordr;
|
|
|
|
uint16 dataSize;
|
2005-10-29 18:37:40 +00:00
|
|
|
KyraEngine::OpcodeProc *opcodes;
|
|
|
|
int opcodeSize;
|
2005-10-13 18:05:04 +00:00
|
|
|
uint16 mustBeFreed;
|
2004-11-14 20:11:22 +00:00
|
|
|
};
|
|
|
|
|
2005-10-13 18:05:04 +00:00
|
|
|
struct ScriptState {
|
|
|
|
byte *ip;
|
|
|
|
ScriptData *dataPtr;
|
|
|
|
int16 retValue;
|
|
|
|
uint16 bp;
|
|
|
|
uint16 sp;
|
|
|
|
int16 variables[30];
|
|
|
|
int16 stack[61];
|
2004-11-14 20:11:22 +00:00
|
|
|
};
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2005-10-13 18:05:04 +00:00
|
|
|
enum {
|
|
|
|
SCRIPT_INIT = 0
|
|
|
|
};
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2005-10-13 18:05:04 +00:00
|
|
|
class ScriptHelper {
|
2004-11-14 20:11:22 +00:00
|
|
|
public:
|
2005-10-13 18:05:04 +00:00
|
|
|
ScriptHelper(KyraEngine *vm);
|
|
|
|
virtual ~ScriptHelper();
|
|
|
|
|
2005-10-29 18:37:40 +00:00
|
|
|
bool loadScript(const char *filename, ScriptData *data, KyraEngine::OpcodeProc *opcodes, int opcodeSize, byte *specialPtr = 0);
|
2005-10-13 18:05:04 +00:00
|
|
|
void unloadScript(ScriptData *data);
|
|
|
|
|
2005-10-29 18:37:40 +00:00
|
|
|
void initScript(ScriptState *scriptState, ScriptData *data);
|
2005-10-13 18:05:04 +00:00
|
|
|
bool startScript(ScriptState *script, int function);
|
|
|
|
|
|
|
|
bool validScript(ScriptState *script);
|
|
|
|
|
|
|
|
bool runScript(ScriptState *script);
|
2004-11-14 20:11:22 +00:00
|
|
|
protected:
|
2005-10-13 18:05:04 +00:00
|
|
|
uint32 getFORMBlockSize(byte *&data) const;
|
|
|
|
uint32 getIFFBlockSize(byte *start, byte *&data, uint32 maxSize, const uint32 chunk) const;
|
|
|
|
bool loadIFFBlock(byte *start, byte *&data, uint32 maxSize, const uint32 chunk, byte *loadTo, uint32 ptrSize) const;
|
|
|
|
|
|
|
|
KyraEngine *_vm;
|
2005-11-13 19:35:01 +00:00
|
|
|
int16 _parameter;
|
2005-10-13 18:05:04 +00:00
|
|
|
bool _continue;
|
|
|
|
|
2006-01-08 16:15:34 +00:00
|
|
|
typedef void (ScriptHelper::*CommandProc)(ScriptState*);
|
2004-11-14 20:11:22 +00:00
|
|
|
struct CommandEntry {
|
|
|
|
CommandProc proc;
|
|
|
|
const char* desc;
|
|
|
|
};
|
2005-10-13 18:05:04 +00:00
|
|
|
|
|
|
|
const CommandEntry *_commands;
|
|
|
|
private:
|
2006-01-08 16:15:34 +00:00
|
|
|
void c1_jmpTo(ScriptState*);
|
|
|
|
void c1_setRetValue(ScriptState*);
|
|
|
|
void c1_pushRetOrPos(ScriptState*);
|
|
|
|
void c1_push(ScriptState*);
|
2005-10-13 18:05:04 +00:00
|
|
|
//void c1_push(); same as 03
|
2006-01-08 16:15:34 +00:00
|
|
|
void c1_pushVar(ScriptState*);
|
|
|
|
void c1_pushBPNeg(ScriptState*);
|
|
|
|
void c1_pushBPAdd(ScriptState*);
|
|
|
|
void c1_popRetOrPos(ScriptState*);
|
|
|
|
void c1_popVar(ScriptState*);
|
|
|
|
void c1_popBPNeg(ScriptState*);
|
|
|
|
void c1_popBPAdd(ScriptState*);
|
|
|
|
void c1_addSP(ScriptState*);
|
|
|
|
void c1_subSP(ScriptState*);
|
|
|
|
void c1_execOpcode(ScriptState*);
|
|
|
|
void c1_ifNotJmp(ScriptState*);
|
|
|
|
void c1_negate(ScriptState*);
|
|
|
|
void c1_eval(ScriptState*);
|
|
|
|
void c1_setRetAndJmp(ScriptState*);
|
2004-11-14 20:11:22 +00:00
|
|
|
};
|
2004-10-15 06:06:47 +00:00
|
|
|
} // end of namespace Kyra
|
|
|
|
|
|
|
|
#endif
|