diff options
author | Eugene Sandulenko | 2016-06-13 00:31:33 +0200 |
---|---|---|
committer | Eugene Sandulenko | 2016-08-03 23:40:36 +0200 |
commit | 75d759c4d8cc05131270c720d9e86692bd5af199 (patch) | |
tree | 5728d354cef554fc0de0627fd5df0ba7b9ac4755 | |
parent | df50e60b1a2f165988f45286f7b0d8e04ddece37 (diff) | |
download | scummvm-rg350-75d759c4d8cc05131270c720d9e86692bd5af199.tar.gz scummvm-rg350-75d759c4d8cc05131270c720d9e86692bd5af199.tar.bz2 scummvm-rg350-75d759c4d8cc05131270c720d9e86692bd5af199.zip |
DIRECTOR: Lingo: Implement MCI command parsing
-rw-r--r-- | engines/director/director.cpp | 3 | ||||
-rw-r--r-- | engines/director/lingo/lingo-funcs.cpp | 97 |
2 files changed, 98 insertions, 2 deletions
diff --git a/engines/director/director.cpp b/engines/director/director.cpp index 1d22edbc75..8a7cf7e615 100644 --- a/engines/director/director.cpp +++ b/engines/director/director.cpp @@ -70,7 +70,8 @@ Common::Error DirectorEngine::run() { _lingo = new Lingo(); - _lingo->parse("mci \"open MM\\T005045a.wav type WaveAudio alias T005045a\""); + _lingo->parse("mci \"open MM\\T005045a.wav type WaveAudio alias T005045a\"\n\ + mci \"play T005045a from 22710 to 32872\""); #if 0 _lingo->parse("set x = 1\n\ diff --git a/engines/director/lingo/lingo-funcs.cpp b/engines/director/lingo/lingo-funcs.cpp index 641a617f9d..cf48d66685 100644 --- a/engines/director/lingo/lingo-funcs.cpp +++ b/engines/director/lingo/lingo-funcs.cpp @@ -24,8 +24,103 @@ namespace Director { +enum MCITokenType { + kMCITokenNone, + + kMCITokenOpen, + kMCITokenWait, + kMCITokenPlay, + + kMCITokenType, + kMCITokenAlias, + kMCITokenBuffer, + kMCITokenFrom, + kMCITokenTo +}; + +struct MCIToken { + MCITokenType command; + MCITokenType flag; + const char *token; + int pos; +} MCITokens[] = { + { kMCITokenNone, kMCITokenOpen, "open", 0 }, + { kMCITokenOpen, kMCITokenType, "type", 1 }, + { kMCITokenOpen, kMCITokenAlias, "alias", 2 }, + { kMCITokenOpen, kMCITokenBuffer, "buffer", 3 }, + + { kMCITokenNone, kMCITokenPlay, "play", 0 }, + { kMCITokenPlay, kMCITokenFrom, "from", 1 }, + { kMCITokenPlay, kMCITokenTo, "to", 2 }, + + { kMCITokenNone, kMCITokenWait, "wait", 0 }, + + { kMCITokenNone, kMCITokenNone, 0, 0 } +}; + int Lingo::func_mci(Common::String *s) { - warning("STUB: mci(\"%s\")", s->c_str()); + Common::String params[5]; + MCITokenType command = kMCITokenNone; + + s->trim(); + s->toLowercase(); + + MCITokenType state = kMCITokenNone; + Common::String token; + const char *ptr = s->c_str(); + int respos = -1; + + while (*ptr) { + while (*ptr && *ptr == ' ') + ptr++; + + token.clear(); + + while (*ptr && *ptr != ' ') + token += *ptr++; + + switch (state) { + case kMCITokenNone: + { + MCIToken *f = MCITokens; + + while (f->token) { + if (command == f->command && token == f->token) + break; + + f++; + } + + if (command == kMCITokenNone) { // We caught command + command = f->flag; // Switching to processing this command parameters + } else if (f->flag == kMCITokenNone) { // Unmatched token, parsing as filename + if (!params[0].empty()) + warning("Duplicate filename in MCI command: %s -> %s", params[0].c_str(), token.c_str()); + params[0] = token; + } else { + state = f->flag; + respos = f->pos; + } + break; + } + default: + params[respos] = token; + state = kMCITokenNone; + break; + } + + } + + switch (command) { + case kMCITokenOpen: + warning("MCI open file: %s, type: %s, alias: %s buffer: %s", params[0].c_str(), params[1].c_str(), params[2].c_str(), params[3].c_str()); + break; + case kMCITokenPlay: + warning("MCI play file: %s, from: %s, to: %s", params[0].c_str(), params[1].c_str(), params[2].c_str()); + break; + default: + warning("Unhandled MCI command: %s", s->c_str()); + } return 0; } |