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
This commit is contained in:
Denis Kasak 2009-06-28 16:19:10 +00:00
parent 948bf2cfcc
commit f61b2d289d
5 changed files with 36 additions and 25 deletions

View File

@ -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

View File

@ -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;
}
}

View File

@ -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;

View File

@ -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;
}

View File

@ -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);