diff options
-rw-r--r-- | engines/parallaction/debug.cpp | 10 | ||||
-rw-r--r-- | engines/parallaction/exec_ns.cpp | 3 | ||||
-rw-r--r-- | engines/parallaction/parallaction.h | 53 | ||||
-rw-r--r-- | engines/parallaction/parallaction_br.cpp | 3 | ||||
-rw-r--r-- | engines/parallaction/parallaction_ns.cpp | 5 | ||||
-rw-r--r-- | engines/parallaction/parser.cpp | 1 | ||||
-rw-r--r-- | engines/parallaction/parser.h | 92 | ||||
-rw-r--r-- | engines/parallaction/parser_br.cpp | 61 | ||||
-rw-r--r-- | engines/parallaction/parser_ns.cpp | 108 | ||||
-rw-r--r-- | engines/parallaction/staticres.cpp | 62 |
10 files changed, 239 insertions, 159 deletions
diff --git a/engines/parallaction/debug.cpp b/engines/parallaction/debug.cpp index 4f281998e2..3c90a76f61 100644 --- a/engines/parallaction/debug.cpp +++ b/engines/parallaction/debug.cpp @@ -226,14 +226,14 @@ bool Debugger::Cmd_Programs(int argc, const char** argv) { int i = 1; - DebugPrintf("+---+--------------------+----------+\n" - "| # | bound animation | status |\n" - "+---+--------------------+----------+\n"); + DebugPrintf("+---+--------------------+--------+----------+\n" + "| # | bound animation | size | status |\n" + "+---+--------------------+--------+----------+\n"); for ( ; b != e; b++, i++) { ProgramPtr p = *b; - DebugPrintf("|%3i|%-20s|%-10s|\n", i, p->_anim->_name, status[p->_status] ); + DebugPrintf("|%3i|%-20s|%8i|%-10s|\n", i, p->_anim->_name, p->_instructions.size(), status[p->_status] ); } - DebugPrintf("+---+--------------------+---------+\n"); + DebugPrintf("+---+--------------------+--------+----------+\n"); return true; } diff --git a/engines/parallaction/exec_ns.cpp b/engines/parallaction/exec_ns.cpp index 06969fd01d..9ed56827b5 100644 --- a/engines/parallaction/exec_ns.cpp +++ b/engines/parallaction/exec_ns.cpp @@ -361,7 +361,6 @@ void Parallaction_ns::runScripts() { debugC(9, kDebugExec, "runScripts"); - static uint16 modCounter = 0; for (ProgramList::iterator it = _location._programs.begin(); it != _location._programs.end(); it++) { @@ -379,7 +378,7 @@ void Parallaction_ns::runScripts() { (*it)->_status = kProgramRunning; - debugC(9, kDebugExec, "Animation: %s, instruction: %s", a->_name, _instructionNamesRes[(*inst)->_index - 1]); + debugC(9, kDebugExec, "Animation: %s, instruction: %i", a->_name, (*inst)->_index); //_instructionNamesRes[(*inst)->_index - 1]); _instRunCtxt.inst = inst; _instRunCtxt.anim = AnimationPtr(a); diff --git a/engines/parallaction/parallaction.h b/engines/parallaction/parallaction.h index b3e93ee83f..367ee93f80 100644 --- a/engines/parallaction/parallaction.h +++ b/engines/parallaction/parallaction.h @@ -247,8 +247,6 @@ public: -#define DECLARE_UNQUALIFIED_INSTRUCTION_PARSER(sig) void instParse_##sig() - #define DECLARE_UNQUALIFIED_COMMAND_OPCODE(op) void cmdOp_##op() #define DECLARE_UNQUALIFIED_INSTRUCTION_OPCODE(op) void instOp_##op() @@ -554,6 +552,7 @@ public: private: LocationParser_ns *_locationParser; + ProgramParser_ns *_programParser; void initFonts(); void freeFonts(); @@ -645,44 +644,9 @@ protected: void drawAnimations(); void parseLocation(const char *filename); - void initOpcodes(); - - - // program parser - OpcodeSet _instructionParsers; - Table *_instructionNames; - - struct { - bool end; - AnimationPtr a; - InstructionPtr inst; - LocalVariable *locals; - ProgramPtr program; - - // BRA specific - InstructionPtr openIf; - } _instParseCtxt; - - DECLARE_UNQUALIFIED_INSTRUCTION_PARSER(defLocal); - DECLARE_UNQUALIFIED_INSTRUCTION_PARSER(animation); - DECLARE_UNQUALIFIED_INSTRUCTION_PARSER(loop); - DECLARE_UNQUALIFIED_INSTRUCTION_PARSER(x); - DECLARE_UNQUALIFIED_INSTRUCTION_PARSER(y); - DECLARE_UNQUALIFIED_INSTRUCTION_PARSER(z); - DECLARE_UNQUALIFIED_INSTRUCTION_PARSER(f); - DECLARE_UNQUALIFIED_INSTRUCTION_PARSER(inc); - DECLARE_UNQUALIFIED_INSTRUCTION_PARSER(set); - DECLARE_UNQUALIFIED_INSTRUCTION_PARSER(move); - DECLARE_UNQUALIFIED_INSTRUCTION_PARSER(put); - DECLARE_UNQUALIFIED_INSTRUCTION_PARSER(call); - DECLARE_UNQUALIFIED_INSTRUCTION_PARSER(sound); - DECLARE_UNQUALIFIED_INSTRUCTION_PARSER(null); - DECLARE_UNQUALIFIED_INSTRUCTION_PARSER(endscript); - - void parseInstruction(ProgramPtr program); void loadProgram(AnimationPtr a, const char *filename); - void parseLValue(ScriptVar &var, const char *str); - virtual void parseRValue(ScriptVar &var, const char *str); + + void initOpcodes(); DECLARE_UNQUALIFIED_COMMAND_OPCODE(invalid); DECLARE_UNQUALIFIED_COMMAND_OPCODE(set); @@ -771,6 +735,7 @@ public: private: LocationParser_br *_locationParser; + ProgramParser_br *_programParser; void initResources(); void initFonts(); @@ -818,16 +783,6 @@ private: void parseLocation(const char* name); - DECLARE_UNQUALIFIED_INSTRUCTION_PARSER(zone); - DECLARE_UNQUALIFIED_INSTRUCTION_PARSER(color); - DECLARE_UNQUALIFIED_INSTRUCTION_PARSER(mask); - DECLARE_UNQUALIFIED_INSTRUCTION_PARSER(print); - DECLARE_UNQUALIFIED_INSTRUCTION_PARSER(text); - DECLARE_UNQUALIFIED_INSTRUCTION_PARSER(if_op); - DECLARE_UNQUALIFIED_INSTRUCTION_PARSER(endif); - - virtual void parseRValue(ScriptVar &var, const char *str); - DECLARE_UNQUALIFIED_COMMAND_OPCODE(location); DECLARE_UNQUALIFIED_COMMAND_OPCODE(open); DECLARE_UNQUALIFIED_COMMAND_OPCODE(close); diff --git a/engines/parallaction/parallaction_br.cpp b/engines/parallaction/parallaction_br.cpp index 118fe195d0..779a7f72b1 100644 --- a/engines/parallaction/parallaction_br.cpp +++ b/engines/parallaction/parallaction_br.cpp @@ -72,7 +72,8 @@ int Parallaction_br::init() { initFonts(); initCursors(); initOpcodes(); - initParsers(); + _locationParser = new LocationParser_br(this); + _programParser = new ProgramParser_br(this); _part = -1; diff --git a/engines/parallaction/parallaction_ns.cpp b/engines/parallaction/parallaction_ns.cpp index 071fa262a8..197f99d723 100644 --- a/engines/parallaction/parallaction_ns.cpp +++ b/engines/parallaction/parallaction_ns.cpp @@ -135,7 +135,8 @@ int Parallaction_ns::init() { initFonts(); initCursors(); initOpcodes(); - initParsers(); + _locationParser = new LocationParser_ns(this); + _programParser = new ProgramParser_ns(this); _introSarcData1 = 0; _introSarcData2 = 1; @@ -155,8 +156,6 @@ Parallaction_ns::~Parallaction_ns() { delete _mouseComposedArrow; - delete _instructionNames; - _location._animations.remove(_char._ani); } diff --git a/engines/parallaction/parser.cpp b/engines/parallaction/parser.cpp index 665da16636..542a35b7f8 100644 --- a/engines/parallaction/parser.cpp +++ b/engines/parallaction/parser.cpp @@ -234,7 +234,6 @@ void Parser::popTables() { void Parser::parseStatement() { assert(_currentOpcodes != 0); - _script->readLineToken(true); _lookup = _currentStatements->lookup(_tokens[0]); debugC(9, kDebugParser, "parseStatement: %s (lookup = %i)", _tokens[0], _lookup); diff --git a/engines/parallaction/parser.h b/engines/parallaction/parser.h index a62d883ccc..de0a56ddfc 100644 --- a/engines/parallaction/parser.h +++ b/engines/parallaction/parser.h @@ -117,6 +117,7 @@ protected: #define DECLARE_UNQUALIFIED_ANIM_PARSER(sig) void locAnimParse_##sig() #define DECLARE_UNQUALIFIED_COMMAND_PARSER(sig) void cmdParse_##sig() #define DECLARE_UNQUALIFIED_LOCATION_PARSER(sig) void locParse_##sig() +#define DECLARE_UNQUALIFIED_INSTRUCTION_PARSER(sig) void instParse_##sig() #define MAX_FORWARDS 50 @@ -228,7 +229,6 @@ protected: void resolveCommandForwards(); void createCommand(uint id); void addCommand(); - void initParsers(); struct CommandForwardReference { char name[20]; @@ -316,6 +316,95 @@ public: }; + +class ProgramParser_ns { + +protected: + Parser *parser; + Parallaction_ns *_vm; + + Script *script; + ProgramPtr program; + + // program parser + OpcodeSet _instructionParsers; + Table *_instructionNames; + + struct { + bool end; + AnimationPtr a; + InstructionPtr inst; + LocalVariable *locals; + ProgramPtr program; + + // BRA specific + InstructionPtr openIf; + } _instParseCtxt; + + DECLARE_UNQUALIFIED_INSTRUCTION_PARSER(defLocal); + DECLARE_UNQUALIFIED_INSTRUCTION_PARSER(animation); + DECLARE_UNQUALIFIED_INSTRUCTION_PARSER(loop); + DECLARE_UNQUALIFIED_INSTRUCTION_PARSER(x); + DECLARE_UNQUALIFIED_INSTRUCTION_PARSER(y); + DECLARE_UNQUALIFIED_INSTRUCTION_PARSER(z); + DECLARE_UNQUALIFIED_INSTRUCTION_PARSER(f); + DECLARE_UNQUALIFIED_INSTRUCTION_PARSER(inc); + DECLARE_UNQUALIFIED_INSTRUCTION_PARSER(set); + DECLARE_UNQUALIFIED_INSTRUCTION_PARSER(move); + DECLARE_UNQUALIFIED_INSTRUCTION_PARSER(put); + DECLARE_UNQUALIFIED_INSTRUCTION_PARSER(call); + DECLARE_UNQUALIFIED_INSTRUCTION_PARSER(sound); + DECLARE_UNQUALIFIED_INSTRUCTION_PARSER(null); + DECLARE_UNQUALIFIED_INSTRUCTION_PARSER(endscript); + + void parseInstruction(); + void parseLValue(ScriptVar &var, const char *str); + virtual void parseRValue(ScriptVar &var, const char *str); + + void init(); + +public: + ProgramParser_ns(Parallaction_ns *vm) : _vm(vm) { + init(); + } + + virtual ~ProgramParser_ns() { + delete _instructionNames; + } + + void parse(Script *script, ProgramPtr program); + +}; + + +class ProgramParser_br : public ProgramParser_ns { + +protected: + Parallaction_br *_vm; + + DECLARE_UNQUALIFIED_INSTRUCTION_PARSER(zone); + DECLARE_UNQUALIFIED_INSTRUCTION_PARSER(color); + DECLARE_UNQUALIFIED_INSTRUCTION_PARSER(mask); + DECLARE_UNQUALIFIED_INSTRUCTION_PARSER(print); + DECLARE_UNQUALIFIED_INSTRUCTION_PARSER(text); + DECLARE_UNQUALIFIED_INSTRUCTION_PARSER(if_op); + DECLARE_UNQUALIFIED_INSTRUCTION_PARSER(endif); + + virtual void parseRValue(ScriptVar &var, const char *str); + + void init(); + +public: + ProgramParser_br(Parallaction_br *vm) : ProgramParser_ns((Parallaction_ns*)vm), _vm(vm) { + init(); + } + + virtual ~ProgramParser_br() { + delete _instructionNames; + } + +}; + } // namespace Parallaction #endif @@ -324,3 +413,4 @@ public: + diff --git a/engines/parallaction/parser_br.cpp b/engines/parallaction/parser_br.cpp index 612a53759b..3d5cdc795a 100644 --- a/engines/parallaction/parser_br.cpp +++ b/engines/parallaction/parser_br.cpp @@ -253,13 +253,48 @@ const char *_locationAnimStmtRes_br[] = { "moveto" }; +const char *_instructionNamesRes_br[] = { + "on", + "off", + "x", + "y", + "z", + "f", + "loop", + "endloop", + "show", + "inc", + "dec", + "set", + "put", + "call", + "wait", + "start", + "process", + "move", + "color", + "sound", + "mask", + "print", + "text", + "mul", + "div", + "if", + "dummy", + "dummy", + "endif", + "stop", + "endscript" +}; + #define DECLARE_ZONE_PARSER(sig) void LocationParser_br::locZoneParse_##sig() #define DECLARE_ANIM_PARSER(sig) void LocationParser_br::locAnimParse_##sig() #define DECLARE_COMMAND_PARSER(sig) void LocationParser_br::cmdParse_##sig() -#define DECLARE_INSTRUCTION_PARSER(sig) void Parallaction_br::instParse_##sig() #define DECLARE_LOCATION_PARSER(sig) void LocationParser_br::locParse_##sig() +#define DECLARE_INSTRUCTION_PARSER(sig) void ProgramParser_br::instParse_##sig() + DECLARE_LOCATION_PARSER(location) { debugC(7, kDebugParser, "LOCATION_PARSER(location) "); @@ -757,7 +792,8 @@ DECLARE_ANIM_PARSER(endanimation) { DECLARE_INSTRUCTION_PARSER(zone) { debugC(7, kDebugParser, "INSTRUCTION_PARSER(zone) "); - _instParseCtxt.inst->_z = findZone(_tokens[1]); + _instParseCtxt.inst->_z = _vm->findZone(_tokens[1]); + _instParseCtxt.inst->_index = parser->_lookup; } @@ -771,6 +807,7 @@ DECLARE_INSTRUCTION_PARSER(color) { _instParseCtxt.inst->_colors[0] = atoi(_tokens[2]); _instParseCtxt.inst->_colors[1] = atoi(_tokens[3]); _instParseCtxt.inst->_colors[2] = atoi(_tokens[4]); + _instParseCtxt.inst->_index = parser->_lookup; } @@ -782,6 +819,7 @@ DECLARE_INSTRUCTION_PARSER(mask) { parseRValue(_instParseCtxt.inst->_opA, _tokens[1]); parseRValue(_instParseCtxt.inst->_opB, _tokens[2]); parseRValue(_instParseCtxt.inst->_opC, _tokens[3]); + _instParseCtxt.inst->_index = parser->_lookup; } @@ -790,6 +828,7 @@ DECLARE_INSTRUCTION_PARSER(print) { debugC(7, kDebugParser, "INSTRUCTION_PARSER(print) "); parseRValue(_instParseCtxt.inst->_opB, _tokens[1]); + _instParseCtxt.inst->_index = parser->_lookup; } @@ -812,6 +851,7 @@ DECLARE_INSTRUCTION_PARSER(text) { if (_tokens[_si][0] != '\0' && scumm_stricmp("flags", _tokens[_si])) { _instParseCtxt.inst->_text2 = strdup(_tokens[_si]); } + _instParseCtxt.inst->_index = parser->_lookup; } @@ -850,10 +890,11 @@ DECLARE_INSTRUCTION_PARSER(endif) { // _instParseCtxt.openIf->_endif = _instParseCtxt.inst; _instParseCtxt.openIf = nullInstructionPtr; + _instParseCtxt.inst->_index = parser->_lookup; } -void Parallaction_br::parseRValue(ScriptVar &v, const char *str) { +void ProgramParser_br::parseRValue(ScriptVar &v, const char *str) { if (isdigit(str[0]) || str[0] == '-') { v.setImmediate(atoi(str)); @@ -868,7 +909,7 @@ void Parallaction_br::parseRValue(ScriptVar &v, const char *str) { AnimationPtr a; if (str[1] == '.') { - a = findAnimation(&str[2]); + a = _vm->findAnimation(&str[2]); if (!a) { error("unknown animation '%s' in script", &str[2]); } @@ -894,7 +935,7 @@ void Parallaction_br::parseRValue(ScriptVar &v, const char *str) { v.setRandom(atoi(&str[1])); } else if (str[0] == 'L') { - v.setField(&_lipSyncVal); + v.setField(&_vm->_lipSyncVal); } } @@ -906,8 +947,8 @@ typedef OpcodeImpl<LocationParser_br> OpcodeV2; #define COMMAND_PARSER(sig) OpcodeV2(this, &LocationParser_br::cmdParse_##sig) #define WARNING_PARSER(sig) OpcodeV2(this, &LocationParser_br::warning_##sig) -typedef OpcodeImpl<Parallaction_br> OpcodeV3; -#define INSTRUCTION_PARSER(sig) OpcodeV3(this, &Parallaction_br::instParse_##sig) +typedef OpcodeImpl<ProgramParser_br> OpcodeV3; +#define INSTRUCTION_PARSER(sig) OpcodeV3(this, &ProgramParser_br::instParse_##sig) void LocationParser_br::init() { @@ -1036,9 +1077,11 @@ void LocationParser_br::init() { } -void Parallaction_br::initParsers() { +void ProgramParser_br::init() { + + parser = new Parser; - _locationParser = new LocationParser_br(this); + _instructionNames = new Table(ARRAYSIZE(_instructionNamesRes_br), _instructionNamesRes_br); static const OpcodeV3 op0[] = { INSTRUCTION_PARSER(defLocal), // invalid opcode -> local definition diff --git a/engines/parallaction/parser_ns.cpp b/engines/parallaction/parser_ns.cpp index 29c356b8af..492d605a38 100644 --- a/engines/parallaction/parser_ns.cpp +++ b/engines/parallaction/parser_ns.cpp @@ -157,13 +157,35 @@ const char *_locationAnimStmtRes_ns[] = { "endanimation" }; +const char *_instructionNamesRes_ns[] = { + "on", + "off", + "x", + "y", + "z", + "f", + "loop", + "endloop", + "show", + "inc", + "dec", + "set", + "put", + "call", + "wait", + "start", + "sound", + "move", + "endscript" +}; + #define DECLARE_ZONE_PARSER(sig) void LocationParser_ns::locZoneParse_##sig() #define DECLARE_ANIM_PARSER(sig) void LocationParser_ns::locAnimParse_##sig() #define DECLARE_COMMAND_PARSER(sig) void LocationParser_ns::cmdParse_##sig() #define DECLARE_LOCATION_PARSER(sig) void LocationParser_ns::locParse_##sig() -#define DECLARE_INSTRUCTION_PARSER(sig) void Parallaction_ns::instParse_##sig() +#define DECLARE_INSTRUCTION_PARSER(sig) void ProgramParser_ns::instParse_##sig() void LocationParser_ns::warning_unexpected() { @@ -286,49 +308,62 @@ void LocationParser_ns::parseAnimation(Script& script, AnimationList &list, char parser->pushTables(&_locationAnimParsers, _locationAnimStmt); } -void Parallaction_ns::parseInstruction(ProgramPtr program) { +void ProgramParser_ns::parseInstruction() { InstructionPtr inst(new Instruction); + script->readLineToken(true); + if (_tokens[0][1] == '.') { _tokens[0][1] = '\0'; - _instParseCtxt.a = findAnimation(&_tokens[0][2]); + _instParseCtxt.a = _vm->findAnimation(&_tokens[0][2]); } else if (_tokens[1][1] == '.') { _tokens[1][1] = '\0'; - _instParseCtxt.a = findAnimation(&_tokens[1][2]); + _instParseCtxt.a = _vm->findAnimation(&_tokens[1][2]); } else _instParseCtxt.a = program->_anim; - inst->_index = _instructionNames->lookup(_tokens[0]); _instParseCtxt.inst = inst; - _instParseCtxt.locals = program->_locals; - (*(_instructionParsers[inst->_index]))(); + parser->parseStatement(); program->_instructions.push_back(inst); return; } -void Parallaction_ns::loadProgram(AnimationPtr a, const char *filename) { - debugC(1, kDebugParser, "loadProgram(Animation: %s, script: %s)", a->_name, filename); +void ProgramParser_ns::parse(Script *script, ProgramPtr program) { - Script *script = _disk->loadScript(filename); - ProgramPtr program(new Program); - program->_anim = a; + this->script = script; + this->program = program; _instParseCtxt.openIf = nullInstructionPtr; _instParseCtxt.end = false; _instParseCtxt.program = program; + _instParseCtxt.locals = program->_locals; + parser->bind(script); + parser->pushTables(&_instructionParsers, _instructionNames); do { - script->readLineToken(); - parseInstruction(program); + parseInstruction(); } while (!_instParseCtxt.end); + parser->popTables(); + parser->unbind(); program->_ip = program->_instructions.begin(); +} + +void Parallaction_ns::loadProgram(AnimationPtr a, const char *filename) { + debugC(1, kDebugParser, "loadProgram(Animation: %s, script: %s)", a->_name, filename); + + Script *script = _disk->loadScript(filename); + ProgramPtr program(new Program); + program->_anim = a; + + _programParser->parse(script, program); + delete script; _vm->_location._programs.push_back(program); @@ -344,8 +379,10 @@ DECLARE_INSTRUCTION_PARSER(animation) { if (!scumm_stricmp(_tokens[1], _instParseCtxt.a->_name)) { _instParseCtxt.inst->_a = _instParseCtxt.a; } else { - _instParseCtxt.inst->_a = findAnimation(_tokens[1]); + _instParseCtxt.inst->_a = _vm->findAnimation(_tokens[1]); } + + _instParseCtxt.inst->_index = parser->_lookup; } @@ -353,6 +390,7 @@ DECLARE_INSTRUCTION_PARSER(loop) { debugC(7, kDebugParser, "INSTRUCTION_PARSER(loop) "); parseRValue(_instParseCtxt.inst->_opB, _tokens[1]); + _instParseCtxt.inst->_index = parser->_lookup; } @@ -361,6 +399,7 @@ DECLARE_INSTRUCTION_PARSER(x) { parseLValue(_instParseCtxt.inst->_opA, "X"); parseRValue(_instParseCtxt.inst->_opB, _tokens[1]); + _instParseCtxt.inst->_index = parser->_lookup; } @@ -369,6 +408,7 @@ DECLARE_INSTRUCTION_PARSER(y) { parseLValue(_instParseCtxt.inst->_opA, "Y"); parseRValue(_instParseCtxt.inst->_opB, _tokens[1]); + _instParseCtxt.inst->_index = parser->_lookup; } @@ -377,6 +417,7 @@ DECLARE_INSTRUCTION_PARSER(z) { parseLValue(_instParseCtxt.inst->_opA, "Z"); parseRValue(_instParseCtxt.inst->_opB, _tokens[1]); + _instParseCtxt.inst->_index = parser->_lookup; } @@ -385,6 +426,7 @@ DECLARE_INSTRUCTION_PARSER(f) { parseLValue(_instParseCtxt.inst->_opA, "F"); parseRValue(_instParseCtxt.inst->_opB, _tokens[1]); + _instParseCtxt.inst->_index = parser->_lookup; } @@ -397,6 +439,7 @@ DECLARE_INSTRUCTION_PARSER(inc) { if (!scumm_stricmp(_tokens[3], "mod")) { _instParseCtxt.inst->_flags |= kInstMod; } + _instParseCtxt.inst->_index = parser->_lookup; } @@ -414,6 +457,7 @@ DECLARE_INSTRUCTION_PARSER(set) { parseLValue(_instParseCtxt.inst->_opA, _tokens[1]); parseRValue(_instParseCtxt.inst->_opB, _tokens[2]); + _instParseCtxt.inst->_index = parser->_lookup; } @@ -422,6 +466,7 @@ DECLARE_INSTRUCTION_PARSER(move) { parseRValue(_instParseCtxt.inst->_opA, _tokens[1]); parseRValue(_instParseCtxt.inst->_opB, _tokens[2]); + _instParseCtxt.inst->_index = parser->_lookup; } @@ -431,7 +476,7 @@ DECLARE_INSTRUCTION_PARSER(put) { if (!scumm_stricmp(_tokens[1], _instParseCtxt.a->_name)) { _instParseCtxt.inst->_a = _instParseCtxt.a; } else { - _instParseCtxt.inst->_a = findAnimation(_tokens[1]); + _instParseCtxt.inst->_a = _vm->findAnimation(_tokens[1]); } parseRValue(_instParseCtxt.inst->_opA, _tokens[2]); @@ -439,30 +484,32 @@ DECLARE_INSTRUCTION_PARSER(put) { if (!scumm_stricmp(_tokens[4], "masked")) { _instParseCtxt.inst->_flags |= kInstMaskedPut; } + _instParseCtxt.inst->_index = parser->_lookup; } DECLARE_INSTRUCTION_PARSER(call) { debugC(7, kDebugParser, "INSTRUCTION_PARSER(call) "); - int index = _callableNames->lookup(_tokens[1]); + int index = _vm->_callableNames->lookup(_tokens[1]); if (index == Table::notFound) error("unknown callable '%s'", _tokens[1]); _instParseCtxt.inst->_immediate = index - 1; + _instParseCtxt.inst->_index = parser->_lookup; } DECLARE_INSTRUCTION_PARSER(sound) { debugC(7, kDebugParser, "INSTRUCTION_PARSER(sound) "); - _instParseCtxt.inst->_z = findZone(_tokens[1]); + _instParseCtxt.inst->_z = _vm->findZone(_tokens[1]); + _instParseCtxt.inst->_index = parser->_lookup; } DECLARE_INSTRUCTION_PARSER(null) { debugC(7, kDebugParser, "INSTRUCTION_PARSER(null) "); - - + _instParseCtxt.inst->_index = parser->_lookup; } @@ -488,11 +535,12 @@ DECLARE_INSTRUCTION_PARSER(endscript) { debugC(7, kDebugParser, "INSTRUCTION_PARSER(endscript) "); _instParseCtxt.end = true; + _instParseCtxt.inst->_index = parser->_lookup; } -void Parallaction_ns::parseRValue(ScriptVar &v, const char *str) { +void ProgramParser_ns::parseRValue(ScriptVar &v, const char *str) { if (isdigit(str[0]) || str[0] == '-') { v.setImmediate(atoi(str)); @@ -507,7 +555,7 @@ void Parallaction_ns::parseRValue(ScriptVar &v, const char *str) { AnimationPtr a; if (str[1] == '.') { - a = findAnimation(&str[2]); + a = _vm->findAnimation(&str[2]); } else { a = _instParseCtxt.a; } @@ -527,7 +575,7 @@ void Parallaction_ns::parseRValue(ScriptVar &v, const char *str) { } -void Parallaction_ns::parseLValue(ScriptVar &v, const char *str) { +void ProgramParser_ns::parseLValue(ScriptVar &v, const char *str) { int index = _instParseCtxt.program->findLocal(str); if (index != -1) { @@ -537,7 +585,7 @@ void Parallaction_ns::parseLValue(ScriptVar &v, const char *str) { AnimationPtr a; if (str[1] == '.') { - a = findAnimation(&str[2]); + a = _vm->findAnimation(&str[2]); } else { a = _instParseCtxt.a; } @@ -871,6 +919,7 @@ Answer *LocationParser_ns::parseAnswer(Script &script) { parseCommands(script, answer->_commands); _locParseCtxt.endcommands = false; do { + script.readLineToken(true); parser->parseStatement(); } while (!_locParseCtxt.endcommands); @@ -1072,6 +1121,7 @@ void LocationParser_ns::parse(Script *script) { parser->bind(script); parser->pushTables(&_locationParsers, _locationStmt); do { + script->readLineToken(true); parser->parseStatement(); } while (!_locParseCtxt.end); parser->popTables(); @@ -1104,8 +1154,8 @@ void LocationParser_ns::parseWalkNodes(Script& script, WalkNodeList &list) { return; } -typedef OpcodeImpl<Parallaction_ns> OpcodeV1; -#define INSTRUCTION_PARSER(sig) OpcodeV1(this, &Parallaction_ns::instParse_##sig) +typedef OpcodeImpl<ProgramParser_ns> OpcodeV1; +#define INSTRUCTION_PARSER(sig) OpcodeV1(this, &ProgramParser_ns::instParse_##sig) typedef OpcodeImpl<LocationParser_ns> OpcodeV2; #define ZONE_PARSER(sig) OpcodeV2(this, &LocationParser_ns::locZoneParse_##sig) @@ -1208,9 +1258,11 @@ void LocationParser_ns::init() { } -void Parallaction_ns::initParsers() { +void ProgramParser_ns::init() { + + parser = new Parser; - _locationParser = new LocationParser_ns(this); + _instructionNames = new Table(ARRAYSIZE(_instructionNamesRes_ns), _instructionNamesRes_ns); static const OpcodeV1 op0[] = { INSTRUCTION_PARSER(defLocal), // invalid opcode -> local definition diff --git a/engines/parallaction/staticres.cpp b/engines/parallaction/staticres.cpp index 3c2051795d..18021db9a1 100644 --- a/engines/parallaction/staticres.cpp +++ b/engines/parallaction/staticres.cpp @@ -216,28 +216,6 @@ byte _amigaTopazFont[2600] = { }; -const char *_instructionNamesRes_ns[] = { - "on", - "off", - "x", - "y", - "z", - "f", - "loop", - "endloop", - "show", - "inc", - "dec", - "set", - "put", - "call", - "wait", - "start", - "sound", - "move", - "endscript" -}; - const char *_callableNamesRes_ns[] = { "Projector", "HBOff", @@ -266,40 +244,6 @@ const char *_callableNamesRes_ns[] = { "TestResult" }; -const char *_instructionNamesRes_br[] = { - "on", - "off", - "x", - "y", - "z", - "f", - "loop", - "endloop", - "show", - "inc", - "dec", - "set", - "put", - "call", - "wait", - "start", - "process", - "move", - "color", - "sound", - "mask", - "print", - "text", - "mul", - "div", - "if", - "dummy", - "dummy", - "endif", - "stop", - "endscript" -}; - const char *_callableNamesRes_br[] = { "blufade", @@ -395,10 +339,9 @@ void Parallaction_ns::initResources() { // _zoneTypeNamesRes = _zoneTypeNamesRes_ns; // _commandsNamesRes = _commandsNamesRes_ns; _callableNamesRes = _callableNamesRes_ns; - _instructionNamesRes = _instructionNamesRes_ns; +// _instructionNamesRes = _instructionNamesRes_ns; _callableNames = new Table(ARRAYSIZE(_callableNamesRes_ns), _callableNamesRes_ns); - _instructionNames = new Table(ARRAYSIZE(_instructionNamesRes_ns), _instructionNamesRes_ns); _localFlagNames = new FixedTable(NUM_LOCATIONS, 1); _localFlagNames->addData("visited"); @@ -417,11 +360,10 @@ void Parallaction_br::initResources() { // _zoneTypeNamesRes = _zoneTypeNamesRes_br; // _commandsNamesRes = _commandsNamesRes_br; _callableNamesRes = _callableNamesRes_br; - _instructionNamesRes = _instructionNamesRes_br; +// _instructionNamesRes = _instructionNamesRes_br; // _audioCommandsNamesRes = _audioCommandsNamesRes_br; _callableNames = new Table(ARRAYSIZE(_callableNamesRes_br), _callableNamesRes_br); - _instructionNames = new Table(ARRAYSIZE(_instructionNamesRes_br), _instructionNamesRes_br); _localFlagNames = new FixedTable(NUM_LOCATIONS, 2); _localFlagNames->addData("visited"); |