diff --git a/engines/director/director.cpp b/engines/director/director.cpp index 1d22edbc7525..8a7cf7e6157f 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 641a617f9d7d..cf48d6668516 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; }