From 7c919f70d441961d8335cdadb10fc4f0e14ee915 Mon Sep 17 00:00:00 2001 From: Scott Percival Date: Wed, 18 Dec 2019 01:46:45 +0800 Subject: DIRECTOR: Fix calling convention for b_go --- engines/director/lingo/lingo-builtins.cpp | 62 +++++++++++++++++++++---------- 1 file changed, 43 insertions(+), 19 deletions(-) (limited to 'engines/director') diff --git a/engines/director/lingo/lingo-builtins.cpp b/engines/director/lingo/lingo-builtins.cpp index f0e384d92c..8a465c585e 100644 --- a/engines/director/lingo/lingo-builtins.cpp +++ b/engines/director/lingo/lingo-builtins.cpp @@ -893,36 +893,60 @@ void Lingo::b_do(int nargs) { } void Lingo::b_go(int nargs) { + // Builtin function for go as used by the Director bytecode engine. + // + // Accepted arguments: + // "loop" + // "next" + // "previous" + // (STRING|INT) frame + // STRING movie, (STRING|INT) frame + if (nargs >= 1 && nargs <= 2) { - Datum frame = g_lingo->pop(); + Datum firstArg = g_lingo->pop(); nargs -= 1; - if (frame.type == STRING) { - if (*frame.u.s == "loop") { + bool callSpecial = false; + + if (firstArg.type == STRING) { + if (*firstArg.u.s == "loop") { g_lingo->func_gotoloop(); - } else if (*frame.u.s == "next") { + callSpecial = true; + } else if (*firstArg.u.s == "next") { g_lingo->func_gotonext(); - } else if (*frame.u.s == "previous") { + callSpecial = true; + } else if (*firstArg.u.s == "previous") { g_lingo->func_gotoprevious(); - } else { - Datum movie; - if (nargs > 0) { - movie = g_lingo->pop(); - nargs -= 1; - if (movie.type != STRING) { - warning("b_go: movie arg should be of type STRING, not %s", movie.type2str()); - } - } - g_lingo->func_goto(frame, movie); + callSpecial = true; } + } + + if (!callSpecial) { + Datum movie; + Datum frame; + if (nargs > 0) { - warning("b_go: ignoring %d extra args", nargs); - g_lingo->dropStack(nargs); + movie = firstArg; + if (movie.type != STRING) { + warning("b_go: movie arg should be of type STRING, not %s", movie.type2str()); + } + frame = g_lingo->pop(); + nargs -= 1; + } else { + frame = firstArg; } - } else { - warning("b_go: frame arg should be of type STRING, not %s", frame.type2str()); + if (frame.type != STRING && frame.type != INT) { + warning("b_go: frame arg should be of type STRING or INT, not %s", frame.type2str()); + } + + g_lingo->func_goto(frame, movie); + } + + if (nargs > 0) { + warning("b_go: ignoring %d extra args", nargs); g_lingo->dropStack(nargs); } + } else { warning("b_go: expected 1 or 2 args, not %d", nargs); g_lingo->dropStack(nargs); -- cgit v1.2.3