From f61b2d289d0e6ec960e20ac5b59a0fe7dfe8740e Mon Sep 17 00:00:00 2001 From: Denis Kasak Date: Sun, 28 Jun 2009 16:19:10 +0000 Subject: Changed Script::run() to accept a GPL2Program struct instead of a byte pointer and a length. Also, Script::run() now executes the GPL program until a gplend instruction rather than to the end of the whole program. Modified GameObject according to the new changes. svn-id: r41927 --- engines/draci/draci.cpp | 2 +- engines/draci/game.cpp | 18 ++++++++---------- engines/draci/game.h | 12 ++++++++---- engines/draci/script.cpp | 15 ++++++--------- engines/draci/script.h | 14 +++++++++++++- 5 files changed, 36 insertions(+), 25 deletions(-) (limited to 'engines') diff --git a/engines/draci/draci.cpp b/engines/draci/draci.cpp index 7e73e3d4b2..5ace58c8bc 100644 --- a/engines/draci/draci.cpp +++ b/engines/draci/draci.cpp @@ -69,7 +69,7 @@ int DraciEngine::init() { _screen = new Screen(this); _font = new Font(); _mouse = new Mouse(this); - _game = new Game(); + _game = new Game(this); _script = new Script(); // Load default font diff --git a/engines/draci/game.cpp b/engines/draci/game.cpp index 7cceb0e854..9b8a2855ef 100644 --- a/engines/draci/game.cpp +++ b/engines/draci/game.cpp @@ -28,10 +28,11 @@ #include "draci/draci.h" #include "draci/game.h" #include "draci/barchive.h" +#include "draci/script.h" namespace Draci { -Game::Game() { +Game::Game(DraciEngine *vm) : _vm(vm) { unsigned int i; Common::String path("INIT.DFW"); @@ -161,9 +162,9 @@ void Game::loadObject(uint16 objNum, GameObject *obj) { memcpy(obj->_title, file->_data, file->_length); file = objArchive[objNum * 3 + 2]; - obj->_program = new byte[file->_length]; - memcpy(obj->_program, file->_data, file->_length); - obj->_progLen = file->_length; + obj->_program._bytecode = new byte[file->_length]; + obj->_program._length = file->_length; + memcpy(obj->_program._bytecode, file->_data, file->_length); } Game::~Game() { @@ -176,12 +177,9 @@ Game::~Game() { } GameObject::~GameObject() { - if (_seqTab) - delete[] _seqTab; - if (_title) - delete[] _title; - if (_program) - delete[] _program; + delete[] _seqTab; + delete[] _title; + delete[] _program._bytecode; } } diff --git a/engines/draci/game.h b/engines/draci/game.h index 5bd2074489..bdbb402795 100644 --- a/engines/draci/game.h +++ b/engines/draci/game.h @@ -27,16 +27,19 @@ #define DRACI_GAME_H #include "common/str.h" +#include "draci/script.h" namespace Draci { +class DraciEngine; + enum StructSizes { personSize = sizeof(uint16) * 2 + sizeof(byte) }; struct GameObject { - GameObject() : _seqTab(NULL), _title(NULL), _program(NULL) {} + GameObject() : _seqTab(NULL), _title(NULL) {} ~GameObject(); uint16 _init, _look, _use, _canUse; @@ -49,9 +52,8 @@ struct GameObject { uint16 _absNum; byte _animObj; uint16 *_seqTab; - byte *_program; + GPL2Program _program; byte *_title; - uint32 _progLen; }; struct GameInfo { @@ -76,10 +78,12 @@ struct Person { class Game { public: - Game(); + Game(DraciEngine *vm); ~Game(); private: + DraciEngine *_vm; + GameInfo *_info; Person *_persons; uint16 *_dialogOffsets; diff --git a/engines/draci/script.cpp b/engines/draci/script.cpp index c04100af78..751aadc3f3 100644 --- a/engines/draci/script.cpp +++ b/engines/draci/script.cpp @@ -246,8 +246,7 @@ GPL2Command *Script::findCommand(byte num, byte subnum) { /** * @brief GPL2 bytecode disassembler - * @param gplcode A pointer to the bytecode - * @param len Length of the bytecode + * @param program GPL program in the form of a GPL2Program struct * * GPL2 is short for Game Programming Language 2 which is the script language * used by Draci Historie. This is a simple disassembler for the language. @@ -275,10 +274,11 @@ GPL2Command *Script::findCommand(byte num, byte subnum) { * value comes from. */ -int Script::run(byte *gplcode, uint16 len) { - Common::MemoryReadStream reader(gplcode, len); +int Script::run(GPL2Program program) { + Common::MemoryReadStream reader(program._bytecode, program._length); - while (!reader.eos()) { + GPL2Command *cmd; + do { // read in command pair uint16 cmdpair = reader.readUint16BE(); @@ -288,7 +288,6 @@ int Script::run(byte *gplcode, uint16 len) { // extract low byte, i.e. the command subnumber byte subnum = cmdpair & 0xFF; - GPL2Command *cmd; if ((cmd = findCommand(num, subnum))) { // Print command name @@ -308,9 +307,7 @@ int Script::run(byte *gplcode, uint16 len) { debugC(2, kDraciBytecodeDebugLevel, "Unknown opcode %hu, %hu", num, subnum); } - - - } + } while (cmd->_name != "gplend"); return 0; } diff --git a/engines/draci/script.h b/engines/draci/script.h index 4ad305c209..55712e99f2 100644 --- a/engines/draci/script.h +++ b/engines/draci/script.h @@ -50,10 +50,22 @@ struct GPL2Command { int _paramTypes[kMaxParams]; }; +/** + * A convenience data type that holds both the actual bytecode and the + * length of the bytecode. Passed to Script::run(). + */ + +struct GPL2Program { + GPL2Program() : _bytecode(NULL), _length(0) {} + + byte *_bytecode; + uint16 _length; +}; + class Script { public: - int run(byte *gplcode, uint16 len); + int run(GPL2Program program); private: GPL2Command *findCommand(byte num, byte subnum); -- cgit v1.2.3