Skip to content

Commit

Permalink
DIRECTOR: Lingo: Implement more built-in math functions
Browse files Browse the repository at this point in the history
  • Loading branch information
sev- committed Aug 3, 2016
1 parent e08f8bb commit 7327f0b
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 2 deletions.
2 changes: 2 additions & 0 deletions engines/director/director.cpp
Expand Up @@ -155,6 +155,8 @@ set z2 = z / z1\n\
put z\n\
put z1\n\
put z2\n\
put integer(z2)\n\
put cos(z2)\n\
", kMovieScript, 2);

_lingo->executeScript(kMovieScript, 2);
Expand Down
55 changes: 53 additions & 2 deletions engines/director/lingo/lingo-builtins.cpp
Expand Up @@ -29,6 +29,12 @@ static struct BuiltinProto {
void (*func)(void);
int nparams;
} builtins[] = {
{ "abs", Lingo::b_abs, 1},
{ "atan", Lingo::b_atan, 1},
{ "cos", Lingo::b_cos, 1},
{ "exp", Lingo::b_exp, 1},
{ "integer",Lingo::b_integer, 1},
{ "log", Lingo::b_log, 1},
{ "random", Lingo::b_random, 1},
{ 0, 0, 0 }
};
Expand All @@ -39,12 +45,57 @@ void Lingo::initBuiltIns() {
}
}

void Lingo::b_abs() {
Datum d = g_lingo->pop();

if (d.type == INT)
d.u.i = ABS(d.u.i);
else if (d.type == FLOAT)
d.u.f = ABS(d.u.f);

g_lingo->push(d);
}

void Lingo::b_atan() {
Datum d = g_lingo->pop();
d.toFloat();
d.u.f = atanf(d.u.f);
g_lingo->push(d);
}

void Lingo::b_cos() {
Datum d = g_lingo->pop();
d.toFloat();
d.u.f = cos(d.u.f);
g_lingo->push(d);
}

void Lingo::b_exp() {
Datum d = g_lingo->pop();
d.toInt(); // Lingo uses int, so we're enforcing it
d.toFloat();
d.u.f = expf(d.u.f);
g_lingo->push(d);
}

void Lingo::b_integer() {
Datum d = g_lingo->pop();
d.toInt();
g_lingo->push(d);
}

void Lingo::b_log() {
Datum d = g_lingo->pop();
d.toFloat();
d.u.f = logf(d.u.f);
g_lingo->push(d);
}

void Lingo::b_random() {
Datum max = g_lingo->pop();
Datum res;

if (max.type != INT)
warning("Non-int type for rand: %d", max.type);
max.toInt();

res.u.i = g_lingo->_vm->_rnd.getRandomNumber(max.u.i);
res.type = INT;
Expand Down
6 changes: 6 additions & 0 deletions engines/director/lingo/lingo.h
Expand Up @@ -199,6 +199,12 @@ class Lingo {
static void c_gotoprevious();
static void c_global();

static void b_abs();
static void b_atan();
static void b_cos();
static void b_exp();
static void b_integer();
static void b_log();
static void b_random();

void func_mci(Common::String &s);
Expand Down

0 comments on commit 7327f0b

Please sign in to comment.