diff options
| author | Johannes Schickel | 2005-10-13 18:05:04 +0000 | 
|---|---|---|
| committer | Johannes Schickel | 2005-10-13 18:05:04 +0000 | 
| commit | ce2e9ab9d8a814f2356371b941ddb7e83d387427 (patch) | |
| tree | 16516e73d26edb16fde1ce44384829b74f3fd4ff /kyra/script.h | |
| parent | e9b7a88e77de0043aa1eacf1e80b90d9d257c5c9 (diff) | |
| download | scummvm-rg350-ce2e9ab9d8a814f2356371b941ddb7e83d387427.tar.gz scummvm-rg350-ce2e9ab9d8a814f2356371b941ddb7e83d387427.tar.bz2 scummvm-rg350-ce2e9ab9d8a814f2356371b941ddb7e83d387427.zip  | |
Rewrite of the script interpretation class:
	- Now only one instance is needed for many scripts
	- Fixed a few command procs, but lacks opcode caller
	  implementation
svn-id: r19064
Diffstat (limited to 'kyra/script.h')
| -rw-r--r-- | kyra/script.h | 183 | 
1 files changed, 65 insertions, 118 deletions
diff --git a/kyra/script.h b/kyra/script.h index 3acaf6bb9c..b9cc31d562 100644 --- a/kyra/script.h +++ b/kyra/script.h @@ -22,136 +22,83 @@  #ifndef KYRASCRIPT_H  #define KYRASCRIPT_H +#include "kyra/kyra.h" +  namespace Kyra { -// TODO: -// find out more script functions -enum ScriptFunc { -	kSetupScene = 0, -	kClickEvent = 1, // _registers[1] and _registers[2] are mouse x, y _registers[4] is action -	kActorEvent = 2, -	kEnterEvent = 4, -	kExitEvent = 5, -	kLoadResources = 7 +struct ScriptData { +	byte *text; +	byte *data; +	byte *ordr; +	uint16 dataSize; +	/*command table ptr (uint32)*/ +	uint16 mustBeFreed;  }; -enum ScriptState { -	kScriptStopped = 0, -	kScriptRunning = 1, -	kScriptWaiting = 2, -	kScriptError = 3 +struct ScriptState { +	byte *ip; +	ScriptData *dataPtr; +	int16 retValue; +	uint16 bp; +	uint16 sp; +	int16 variables[30]; +	int16 stack[61];  }; +enum { +	SCRIPT_INIT = 0 +}; -class VMContext { - +class ScriptHelper {  public: - -	VMContext(KyraEngine* engine); -	~VMContext() { delete [] _scriptFile; } - -	void loadScript(const char* file); - -	const char* stringAtIndex(int32 index); - -	// TODO: check for 'over'flow -	void pushStack(int32 value) { _stack[_stackPos++] = value; } -	void registerValue(int32 reg, int32 value) { _registers[reg] = value; } -	int32 checkReg(int32 reg) { return _registers[reg]; } - -	uint32 state(void) { return _scriptState; } - -	bool startScript(int32 func); -	uint32 contScript(void); - +	ScriptHelper(KyraEngine *vm); +	virtual ~ScriptHelper(); +	 +	bool loadScript(const char *filename, ScriptData *data, byte *specialPtr = 0); +	void unloadScript(ScriptData *data); +	 +	void initScript(ScriptState *scriptStat, ScriptData *data); +	bool startScript(ScriptState *script, int function); +	 +	bool validScript(ScriptState *script); +	 +	bool runScript(ScriptState *script);  protected: -	KyraEngine* _engine; -	uint8* _scriptFile; -	uint32 _scriptFileSize; - -	uint32 _scriptState; -	uint32 _delay; - -	int32 _registers[32]; // registers of the interpreter -	int32 _stack[64]; // our stack - -	// TODO: check for 'under'flow -	int32 popStack(void) { return _stack[--_stackPos]; } -	int32& topStack(void) { return _stack[_stackPos]; } - -	uint32 _returnValue; - -	int32 _nextScriptPos; -	int32 _instructionPos; -	int32 _stackPos; -	int32 _tempPos; - -	// used by command & opcode procs -	uint16 _argument; -	uint8 _currentCommand; -	uint32 _currentOpcode; - -	int32 param(int32 index); -	const char* paramString(int32 index) { return stringAtIndex(param(index)); } - -	bool _error;	// used by all command- and opcodefuncs - -	enum ScriptChunkTypes { -		kForm = 0, -		kEmc2Ordr = 1, -		kText = 2, -		kData = 3, -		kCountChunkTypes -	}; - -	struct ScriptChunk { -		uint32 _size; -		uint8* _data; // by TEXT used for count of texts, by EMC2ODRD it is used for a count of somewhat -		uint8* _additional; // currently only used for TEXT -	}; - -	ScriptChunk _chunks[kCountChunkTypes]; - -	typedef void (VMContext::*CommandProc)(); +	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; +	ScriptState *_curScript; +	uint32 _parameter; +	bool _continue; + +	typedef void (ScriptHelper::*CommandProc)();  	struct CommandEntry {  		CommandProc proc;  		const char* desc;  	}; - -	typedef void (VMContext::*OpcodeProc)(); -	struct OpcodeEntry { -		OpcodeProc proc; -		const char* desc; -	}; - -	uint16 _numCommands; -	const CommandEntry* _commands; -	uint16 _numOpcodes; -	const OpcodeEntry* _opcodes; - -protected: -	// the command procs -	void c1_goToLine(void);			// 0x00 -	void c1_setReturn(void);		// 0x01 -	void c1_pushRetRec(void);		// 0x02 -	void c1_push(void);			// 0x03 & 0x04 -	void c1_pushVar(void);			// 0x05 -	void c1_pushFrameNeg(void);		// 0x06 -	void c1_pushFramePos(void);		// 0x07 -	void c1_popRetRec(void);		// 0x08 -	void c1_popVar(void);			// 0x09 -	void c1_popFrameNeg(void);		// 0x0A -	void c1_popFramePos(void);		// 0x0B -	void c1_addToSP(void);			// 0x0C -	void c1_subFromSP(void);		// 0x0D -	void c1_execOpcode(void);		// 0x0E -	void c1_ifNotGoTo(void);		// 0x0F -	void c1_negate(void);			// 0x10 -	void c1_evaluate(void);			// 0x11 -	void c1_unknownCommand(void); - -	// the opcode procs -	void o1_0x68(void);			// 0x68 -	void o1_unknownOpcode(void); +	 +	const CommandEntry *_commands; +private: +	void c1_jmpTo(); +	void c1_setRetValue(); +	void c1_pushRetOrPos(); +	void c1_push(); +	//void c1_push(); same as 03 +	void c1_pushVar(); +	void c1_pushBPNeg(); +	void c1_pushBPAdd(); +	void c1_popRetOrPos(); +	void c1_popVar(); +	void c1_popBPNeg(); +	void c1_popBPAdd(); +	void c1_addSP(); +	void c1_subSP(); +	void c1_execOpcode(); +	void c1_ifNotJmp(); +	void c1_negate(); +	void c1_eval(); +	void c1_setRetAndJmp();  };  } // end of namespace Kyra  | 
