Skip to content

Commit

Permalink
WAGE: Change Script Object to use Common::SeekableReadStream.
Browse files Browse the repository at this point in the history
This replaces the use of (byte* data, int dataSize) type buffer.
Also, some replacements of code in world object to incorporate.
Still not compilable.

Signed-off-by: Eugene Sandulenko <sev@scummvm.org>
  • Loading branch information
digitall authored and sev- committed Dec 27, 2015
1 parent 57b464b commit 624c401
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 47 deletions.
50 changes: 24 additions & 26 deletions engines/wage/script.cpp
Expand Up @@ -53,6 +53,8 @@
#include "wage/script.h"
#include "wage/world.h"

#include "common/stream.h"

namespace Wage {

bool Script::execute(World *world, int loopCount, String *inputText, Designed *inputClick, WageEngine *callbacks) {
Expand All @@ -63,20 +65,18 @@ bool Script::execute(World *world, int loopCount, String *inputText, Designed *i
_callbacks = callbacks;
_handled = false;

_index = 12;
while (_index < _dataSize) {
switch(_data[_index]) {
_data->skip(12);
while (_data->pos() < _data->size()) {
switch(_data->readByte()) {
case 0x80: // IF
_index++;
processIf();
break;
case 0x87: // EXIT
debug(0, "exit at offset %d", _index - 1);
debug(0, "exit at offset %d", _data->pos() - 1);

return true;
case 0x89: // MOVE
{
_index++;
Scene *currentScene = _world->_player->_currentScene;
processMove();
if (_world->_player->_currentScene != currentScene)
Expand All @@ -85,43 +85,41 @@ bool Script::execute(World *world, int loopCount, String *inputText, Designed *i
}
case 0x8B: // PRINT
{
_index++;
Operand *op = readOperand();
// TODO check op type is string or number, or something good...
appendText(op->_str);
// TODO check data[_index] == 0xFD
_index++;
byte d = _data->readByte();
if (d != 0xFD)
warning("Operand 0x8B (PRINT) End Byte != 0xFD");
break;
}
case 0x8C: // SOUND
{
_index++;
Operand *op = readOperand();
// TODO check op type is string.
_handled = true;
callbacks->playSound(op->_str);
// TODO check data[_index] == 0xFD
_index++;
byte d = _data->readByte();
if (d != 0xFD)
warning("Operand 0x8B (PRINT) End Byte != 0xFD");
break;
}
case 0x8E: // LET
_index++;
processLet();
break;
case 0x95: // MENU
{
_index++;
Operand *op = readStringOperand(); // allows empty menu
// TODO check op type is string.
_callbacks->setMenu(op->_str);
// TODO check data[_index] == 0xFD
_index++;
byte d = _data->readByte();
if (d != 0xFD)
warning("Operand 0x8B (PRINT) End Byte != 0xFD");
}
case 0x88: // END
_index++;
break;
default:
debug(0, "Unknown opcode: %d", _index);
debug(0, "Unknown opcode: %d", _data->pos());
}
}

Expand Down Expand Up @@ -194,7 +192,8 @@ bool Script::execute(World *world, int loopCount, String *inputText, Designed *i
}

Script::Operand *Script::readOperand() {
switch (_data[_index++]) {
byte operandType = _data->readByte();
switch (operandType) {
case 0xA0: // TEXT$
return new Operand(_inputText, Operand::TEXT_INPUT);
case 0xA1:
Expand Down Expand Up @@ -228,7 +227,7 @@ Script::Operand *Script::readOperand() {
case 0xFF:
{
// user variable
int value = _data[_index++];
int value = _data->readByte();
if (value < 0)
value += 256;

Expand Down Expand Up @@ -272,13 +271,11 @@ Script::Operand *Script::readOperand() {
case 0xE8:
return new Operand(_world->_player->_context._statVariables[Context::PHYS_SPE_CUR], Operand::NUMBER);
default:
_index--;
if (_data[_index] >= 0x20 && _data[_index] < 0x80) {
if (operandType >= 0x20 && operandType < 0x80) {
return readStringOperand();
} else {
debug("Dunno what %x is (index=%d)!\n", _data[_index], _index);
debug("Dunno what %x is (index=%d)!\n", operandType, _data->pos()-1);
}
_index++;
return NULL;
}
}
Expand All @@ -289,8 +286,9 @@ Script::Operand *Script::readStringOperand() {

sb = new String();

while (_data[_index] >= 0x20 && _data[_index] < 0x80) {
char c = _data[_index++];
byte c = 0x20;
while (c >= 0x20 && c < 0x80) {
c = _data->readByte();
if (c < '0' || c > '9')
allDigits = false;
*sb += c;
Expand Down
6 changes: 2 additions & 4 deletions engines/wage/script.h
Expand Up @@ -55,19 +55,17 @@ namespace Wage {

class Script {
public:
Script(byte *data, int dataSize) : _data(data), _dataSize(dataSize) {}
Script(Common::SeekableReadStream *data) : _data(data) {}
~Script();

private:
byte *_data;
int _dataSize;
Common::SeekableReadStream *_data;

WageEngine *_callbacks;
World *_world;
int _loopCount;
String *_inputText;
Designed *_inputClick;
int _index;
bool _evalResult;
bool _handled;

Expand Down
31 changes: 14 additions & 17 deletions engines/wage/world.cpp
Expand Up @@ -75,7 +75,7 @@ bool World::loadWorld(Common::MacResManager *resMan) {

// Load global script
res = resMan->getResource(MKTAG('G','C','O','D'), resArray[0]);
_globalScript = new Script(res, res->size());
_globalScript = new Script(res);

// Load main configuration
if ((resArray = resMan->getResIDArray(MKTAG('V','E','R','S'))).size() == 0)
Expand All @@ -86,23 +86,22 @@ bool World::loadWorld(Common::MacResManager *resMan) {

res = resMan->getResource(MKTAG('V','E','R','S'), resArray[0]);

Common::MemoryReadStream readS(res, res->size());
readS.skip(10);
byte b = readS.readByte();
res->skip(10);
byte b = res->readByte();
_weaponMenuDisabled = (b != 0);
if (b != 0 && b != 1)
error("Unexpected value for weapons menu");

readS.skip(3);
_aboutMessage = readPascalString(readS);
res->skip(3);
_aboutMessage = readPascalString(res);

if (!scumm_stricmp(resMan->getFileName().c_str(), "Scepters"))
readS.skip(1); // ????
res->skip(1); // ????

_soundLibrary1 = readPascalString(readS);
_soundLibrary2 = readPascalString(readS);
_soundLibrary1 = readPascalString(res);
_soundLibrary2 = readPascalString(res);

free(res);
delete res;

// Load scenes
resArray = resMan->getResIDArray(MKTAG('A','S','C','N'));
Expand All @@ -116,10 +115,9 @@ bool World::loadWorld(Common::MacResManager *resMan) {

res = resMan->getResource(MKTAG('A','T','X','T'), *iter);
if (res != NULL) {
Common::MemoryReadStream readT(res, res->size());
scene->_textBounds = readRect(readT);
scene->_fontType = readT.readUint16BE();
scene->_fontSize = readT.readUint16BE();
scene->_textBounds = readRect(res);
scene->_fontType = res->readUint16BE();
scene->_fontSize = res->readUint16BE();

for (int i = 12; i < res->size(); i++)
if (res[i] == 0x0d)
Expand Down Expand Up @@ -168,12 +166,11 @@ bool World::loadWorld(Common::MacResManager *resMan) {
// Load Patterns
res = resMan->getResource(MKTAG('P','A','T','#'), 900);
if (res != NULL) {
Common::MemoryReadStream readP(res, res->size());
int count = readP.readUint16BE();
int count = res->readUint16BE();
for (int i = 0; i < count; i++) {
byte *pattern = (byte *)malloc(8);
for (int j = 0; j < 8; j++) {
pattern[j] = readP.readByte();
pattern[j] = res->readByte();
_patterns.push_back(pattern);
}
}
Expand Down

0 comments on commit 624c401

Please sign in to comment.