aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugene Sandulenko2004-08-12 21:39:11 +0000
committerEugene Sandulenko2004-08-12 21:39:11 +0000
commitec5d498703309e1bded1126442c361255d7226c8 (patch)
tree2f008149ce232d0646858ed4dae2af2ad8826ae9
parente31aa607306b7b32891d4dd65efe0c06e1c71793 (diff)
downloadscummvm-rg350-ec5d498703309e1bded1126442c361255d7226c8.tar.gz
scummvm-rg350-ec5d498703309e1bded1126442c361255d7226c8.tar.bz2
scummvm-rg350-ec5d498703309e1bded1126442c361255d7226c8.zip
Drop SSTACK_ in favor of common/stack.h implementation.
svn-id: r14566
-rw-r--r--saga/module.mk1
-rw-r--r--saga/script.cpp1
-rw-r--r--saga/script.h1
-rw-r--r--saga/sdebug.cpp1
-rw-r--r--saga/sfuncs.cpp83
-rw-r--r--saga/sstack.cpp155
-rw-r--r--saga/sstack.h68
-rw-r--r--saga/sthread.cpp199
-rw-r--r--saga/sthread.h4
9 files changed, 143 insertions, 370 deletions
diff --git a/saga/module.mk b/saga/module.mk
index 1a3d423c3c..4a907ee54f 100644
--- a/saga/module.mk
+++ b/saga/module.mk
@@ -30,7 +30,6 @@ MODULE_OBJS = \
saga/sfuncs.o \
saga/sndres.o \
saga/sprite.o \
- saga/sstack.o \
saga/sthread.o \
saga/text.o \
saga/transitions.o \
diff --git a/saga/script.cpp b/saga/script.cpp
index 8147408db3..f87fedc72b 100644
--- a/saga/script.cpp
+++ b/saga/script.cpp
@@ -33,7 +33,6 @@
#include "saga/script_mod.h"
#include "saga/script.h"
-#include "saga/sstack.h"
#include "saga/sthread.h"
namespace Saga {
diff --git a/saga/script.h b/saga/script.h
index 38e8e9ba5e..69a2788285 100644
--- a/saga/script.h
+++ b/saga/script.h
@@ -26,7 +26,6 @@
#ifndef SAGA_SCRIPT_H
#define SAGA_SCRIPT_H
-#include "saga/sstack.h"
#include "saga/sdata.h"
#include "saga/text.h"
#include "saga/yslib.h"
diff --git a/saga/sdebug.cpp b/saga/sdebug.cpp
index 3943a31c2a..e68f8cdd82 100644
--- a/saga/sdebug.cpp
+++ b/saga/sdebug.cpp
@@ -29,6 +29,7 @@
#include "saga/scene.h"
#include "saga/font.h"
+#include "saga/script_mod.h"
#include "saga/script.h"
#include "saga/sthread.h"
diff --git a/saga/sfuncs.cpp b/saga/sfuncs.cpp
index 98c7fbabb4..c2a3e02dbf 100644
--- a/saga/sfuncs.cpp
+++ b/saga/sfuncs.cpp
@@ -33,6 +33,7 @@
#include "saga/script.h"
#include "saga/sfuncs.h"
+#include "common/stack.h"
namespace Saga {
@@ -124,7 +125,7 @@ int SF_sleep(R_SCRIPTFUNC_PARAMS) {
SDataWord_T time_param;
int time;
- SSTACK_Pop(thread->stack, &time_param);
+ time_param = thread->stack->pop();
time = _vm->_sdata->readWordU(time_param);
thread->sleep_time = time * 10;
return R_SUCCESS;
@@ -136,8 +137,8 @@ int SF_sleep(R_SCRIPTFUNC_PARAMS) {
int SF_3(R_SCRIPTFUNC_PARAMS) {
// INCOMPLETE
SDataWord_T param1;
- SSTACK_Pop(thread->stack, &param1);
- SSTACK_Push(thread->stack, 0); // push for now to allow intro faire
+ param1 = thread->stack->pop();
+ thread->stack->push(0); // push for now to allow intro faire
// setup to run completely
return R_SUCCESS;
@@ -149,7 +150,7 @@ int SF_3(R_SCRIPTFUNC_PARAMS) {
int SF_setCommandText(R_SCRIPTFUNC_PARAMS) {
SDataWord_T s_idx_parm;
- SSTACK_Pop(thread->stack, &s_idx_parm);
+ s_idx_parm = thread->stack->pop();
// INCOMPLETE
return R_SUCCESS;
@@ -168,9 +169,9 @@ int SF_actorWalkTo(R_SCRIPTFUNC_PARAMS) {
int actor_idx;
R_POINT pt;
- SSTACK_Pop(thread->stack, &actor_parm);
- SSTACK_Pop(thread->stack, &x_parm);
- SSTACK_Pop(thread->stack, &y_parm);
+ actor_parm = thread->stack->pop();
+ x_parm = thread->stack->pop();
+ y_parm = thread->stack->pop();
actor_id = _vm->_sdata->readWordS(actor_parm);
actor_idx = _vm->_actor->getActorIndex(actor_id);
@@ -203,8 +204,8 @@ int SF_setFacing(R_SCRIPTFUNC_PARAMS) {
int actor_idx;
int orientation;
- SSTACK_Pop(thread->stack, &actor_parm);
- SSTACK_Pop(thread->stack, &orient_parm);
+ actor_parm = thread->stack->pop();
+ orient_parm = thread->stack->pop();
actor_id = _vm->_sdata->readWordS(actor_parm);
orientation = _vm->_sdata->readWordS(orient_parm);
@@ -226,7 +227,7 @@ int SF_setFacing(R_SCRIPTFUNC_PARAMS) {
int SF_freezeInterface(R_SCRIPTFUNC_PARAMS) {
SDataWord_T b_param;
- SSTACK_Pop(thread->stack, &b_param);
+ b_param = thread->stack->pop();
if (b_param) {
_vm->_interface->deactivate();
@@ -265,9 +266,9 @@ int SF_startAnim(R_SCRIPTFUNC_PARAMS) {
int frame_count;
int anim_id;
- SSTACK_Pop(thread->stack, &anim_id_parm);
- SSTACK_Pop(thread->stack, &frame_parm);
- SSTACK_Pop(thread->stack, &unk_parm);
+ anim_id_parm = thread->stack->pop();
+ frame_parm = thread->stack->pop();
+ unk_parm = thread->stack->pop();
frame_count = _vm->_sdata->readWordS(frame_parm);
anim_id = _vm->_sdata->readWordS(anim_id_parm);
@@ -293,9 +294,9 @@ int SF_actorWalkToAsync(R_SCRIPTFUNC_PARAMS) {
int actor_idx;
R_POINT pt;
- SSTACK_Pop(thread->stack, &actor_parm);
- SSTACK_Pop(thread->stack, &x_parm);
- SSTACK_Pop(thread->stack, &y_parm);
+ actor_parm = thread->stack->pop();
+ x_parm = thread->stack->pop();
+ y_parm = thread->stack->pop();
actor_id = _vm->_sdata->readWordS(actor_parm);
actor_idx = _vm->_actor->getActorIndex(actor_id);
@@ -332,9 +333,9 @@ int SF_moveTo(R_SCRIPTFUNC_PARAMS) {
int result;
R_POINT pt;
- SSTACK_Pop(thread->stack, &actor_parm);
- SSTACK_Pop(thread->stack, &x_parm);
- SSTACK_Pop(thread->stack, &y_parm);
+ actor_parm = thread->stack->pop();
+ x_parm = thread->stack->pop();
+ y_parm = thread->stack->pop();
actor_id = _vm->_sdata->readWordS(actor_parm);
pt.x = _vm->_sdata->readWordS(x_parm);
@@ -374,10 +375,10 @@ int SF_actorWalk(R_SCRIPTFUNC_PARAMS) {
int actor_idx;
R_POINT pt;
- SSTACK_Pop(thread->stack, &actor_parm);
- SSTACK_Pop(thread->stack, &x_parm);
- SSTACK_Pop(thread->stack, &y_parm);
- SSTACK_Pop(thread->stack, &unk_parm);
+ actor_parm = thread->stack->pop();
+ x_parm = thread->stack->pop();
+ y_parm = thread->stack->pop();
+ unk_parm = thread->stack->pop();
actor_idx = _vm->_actor->getActorIndex(_vm->_sdata->readWordS(actor_parm));
if (actor_idx < 0) {
@@ -414,10 +415,10 @@ int SF_cycleActorFrames(R_SCRIPTFUNC_PARAMS) {
int action;
//uint16 flags;
- SSTACK_Pop(thread->stack, &actor_parm);
- SSTACK_Pop(thread->stack, &unk1_parm);
- SSTACK_Pop(thread->stack, &action_parm);
- SSTACK_Pop(thread->stack, &unk2_parm);
+ actor_parm = thread->stack->pop();
+ unk1_parm = thread->stack->pop();
+ action_parm = thread->stack->pop();
+ unk2_parm = thread->stack->pop();
actor_id = _vm->_sdata->readWordS(actor_parm);
action = _vm->_sdata->readWordS(action_parm);
actor_idx = _vm->_actor->getActorIndex(actor_id);
@@ -447,9 +448,9 @@ int SF_setFrame(R_SCRIPTFUNC_PARAMS) {
int action;
//uint16 flags;
- SSTACK_Pop(thread->stack, &actor_parm);
- SSTACK_Pop(thread->stack, &action_parm);
- SSTACK_Pop(thread->stack, &unk1_parm);
+ actor_parm = thread->stack->pop();
+ action_parm = thread->stack->pop();
+ unk1_parm = thread->stack->pop();
actor_id = _vm->_sdata->readWordS(actor_parm);
action = _vm->_sdata->readWordS(action_parm);
@@ -479,10 +480,10 @@ int SF_linkAnim(R_SCRIPTFUNC_PARAMS) {
uint16 anim_id1;
uint16 anim_id2;
- SSTACK_Pop(thread->stack, &anim1_parm);
- SSTACK_Pop(thread->stack, &anim2_parm);
- SSTACK_Pop(thread->stack, &tframes_parm);
- SSTACK_Pop(thread->stack, &unk_parm);
+ anim1_parm = thread->stack->pop();
+ anim2_parm = thread->stack->pop();
+ tframes_parm = thread->stack->pop();
+ unk_parm = thread->stack->pop();
tframes = _vm->_sdata->readWordS(tframes_parm);
anim_id1 = _vm->_sdata->readWordU(anim1_parm);
anim_id2 = _vm->_sdata->readWordU(anim2_parm);
@@ -522,12 +523,12 @@ int SF_placeActor(R_SCRIPTFUNC_PARAMS) {
int result;
R_POINT pt;
- SSTACK_Pop(thread->stack, &actor_parm);
- SSTACK_Pop(thread->stack, &x_parm);
- SSTACK_Pop(thread->stack, &y_parm);
- SSTACK_Pop(thread->stack, &unknown_parm);
- SSTACK_Pop(thread->stack, &action_parm);
- SSTACK_Pop(thread->stack, &unknown_parm);
+ actor_parm = thread->stack->pop();
+ x_parm = thread->stack->pop();
+ y_parm = thread->stack->pop();
+ unknown_parm = thread->stack->pop();
+ action_parm = thread->stack->pop();
+ unknown_parm = thread->stack->pop();
actor_id = _vm->_sdata->readWordS(actor_parm);
pt.x = _vm->_sdata->readWordS(x_parm);
@@ -557,7 +558,7 @@ int SF_placeActor(R_SCRIPTFUNC_PARAMS) {
// game cinematic. Pushes a zero or positive value if the game
// has not been interrupted.
int SF_checkUserInterrupt(R_SCRIPTFUNC_PARAMS) {
- SSTACK_Push(thread->stack, 0);
+ thread->stack->push(0);
// INCOMPLETE
diff --git a/saga/sstack.cpp b/saga/sstack.cpp
deleted file mode 100644
index fa967839c9..0000000000
--- a/saga/sstack.cpp
+++ /dev/null
@@ -1,155 +0,0 @@
-/* ScummVM - Scumm Interpreter
- * Copyright (C) 2004 The ScummVM project
- *
- * The ReInherit Engine is (C)2000-2003 by Daniel Balsom.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
-
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
-
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *
- * $Header$
- *
- */
-
-// Scripting engine stack component
-
-#include "saga/saga.h"
-
-#include "saga/gfx.h"
-#include "saga/console.h"
-
-#include "saga/script.h"
-#include "saga/sstack.h"
-
-namespace Saga {
-
-int SSTACK_Create(SSTACK *stack, int stack_len, int flags) {
- SSTACK new_stack;
- SDataWord_T *new_stack_data;
-
- *stack = NULL;
-
- new_stack = (SSTACK_tag *)malloc(sizeof(struct SSTACK_tag));
- if (new_stack == NULL) {
- return STACK_MEM;
- }
-
- new_stack_data = (SDataWord_T *)calloc(stack_len, sizeof *new_stack_data);
- if (new_stack_data == NULL) {
- free(new_stack);
- return STACK_MEM;
- }
-
- new_stack->data = new_stack_data;
- new_stack->flags = flags;
- new_stack->len = stack_len;
- new_stack->top = -1;
- *stack = new_stack;
-
- return STACK_SUCCESS;
-}
-
-int SSTACK_Destroy(SSTACK stack) {
- if (stack != NULL) {
- free(stack->data);
- }
-
- free(stack);
-
- return STACK_SUCCESS;
-}
-
-int SSTACK_Clear(SSTACK stack) {
- stack->top = -1;
-
- return STACK_SUCCESS;
-}
-
-int SSTACK_PushNull(SSTACK stack) {
- if (stack->top >= (stack->len - 1)) {
- if (stack->flags & STACK_FIXED) {
- return STACK_OVERFLOW;
- } else if (SSTACK_Grow(stack) != STACK_SUCCESS) {
- return STACK_MEM;
- }
- }
-
- stack->top++;
-
- return STACK_SUCCESS;
-}
-
-int SSTACK_Push(SSTACK stack, SDataWord_T value) {
- if (stack->top >= (stack->len - 1)) {
- if (stack->flags & STACK_FIXED) {
- return STACK_OVERFLOW;
- } else if (SSTACK_Grow(stack) != STACK_SUCCESS) {
- return STACK_MEM;
- }
- }
-
- stack->top++;
- stack->data[stack->top] = value;
-
- return STACK_SUCCESS;
-}
-
-int SSTACK_Pop(SSTACK stack, SDataWord_T *value) {
- if (stack->top <= -1) {
- return STACK_UNDERFLOW;
- }
-
- if (value == NULL) {
- stack->top--;
- return STACK_SUCCESS;
- }
-
- *value = stack->data[stack->top];
- stack->top--;
-
- return STACK_SUCCESS;
-}
-
-int SSTACK_Top(SSTACK stack, SDataWord_T *value) {
- *value = 0;
-
- if (stack->top <= -1) {
- return STACK_UNDERFLOW;
- }
-
- *value = stack->data[stack->top];
-
- return STACK_SUCCESS;
-}
-
-int SSTACK_Grow(SSTACK stack) {
- SDataWord_T *new_data;
-
- if ((stack->len * 2) > R_STACK_SIZE_LIMIT) {
- _vm->_console->print(S_ERROR_PREFIX "Stack fault: growing beyond limit.");
- return STACK_OVERFLOW;
- }
-
- new_data = (SDataWord_T *)realloc(stack->data, (stack->len * 2) * sizeof *new_data);
- if (new_data == NULL) {
- return STACK_MEM;
- }
-
- stack->data = new_data;
- stack->len *= 2;
-
- return STACK_SUCCESS;
-}
-
-} // End of namespace Saga
-
diff --git a/saga/sstack.h b/saga/sstack.h
deleted file mode 100644
index f73888ac01..0000000000
--- a/saga/sstack.h
+++ /dev/null
@@ -1,68 +0,0 @@
-/* ScummVM - Scumm Interpreter
- * Copyright (C) 2004 The ScummVM project
- *
- * The ReInherit Engine is (C)2000-2003 by Daniel Balsom.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
-
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
-
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *
- * $Header$
- *
- */
-
-// Scripting engine stack component header file
-
-#ifndef SAGA_SSTACK_H
-#define SAGA_SSTACK_H
-
-#include "saga/script_mod.h"
-
-namespace Saga {
-
-#define R_STACK_SIZE_LIMIT 16384
-
-struct SSTACK_tag {
- int flags;
- int len;
- int top;
- SDataWord_T *data;
-};
-
-typedef struct SSTACK_tag *SSTACK;
-
-typedef enum SSTACK_ERR_enum {
- STACK_SUCCESS = 0,
- STACK_ERROR,
- STACK_MEM,
- STACK_UNDERFLOW,
- STACK_OVERFLOW
-} SSTACK_ERR_CODE;
-
-typedef enum SSTACK_FLAGS_enum {
- STACK_FIXED = 0x00,
- STACK_GROW = 0x01
-} SSTACK_FLAGS;
-
-int SSTACK_Create(SSTACK *stack, int stack_len, int flags);
-int SSTACK_Destroy(SSTACK stack);
-int SSTACK_Clear(SSTACK stack);
-int SSTACK_Push(SSTACK stack, SDataWord_T value);
-int SSTACK_PushNull(SSTACK stack);
-int SSTACK_Pop(SSTACK stack, SDataWord_T *value);
-int SSTACK_Top(SSTACK stack, SDataWord_T *value);
-int SSTACK_Grow(SSTACK stack);
-
-} // End of namespace Saga
-
-#endif
diff --git a/saga/sthread.cpp b/saga/sthread.cpp
index 3eaeca0113..7423969eaa 100644
--- a/saga/sthread.cpp
+++ b/saga/sthread.cpp
@@ -29,22 +29,21 @@
#include "saga/actor.h"
#include "saga/console.h"
-#include "saga/script.h"
#include "saga/script_mod.h"
+#include "saga/script.h"
#include "saga/sdata.h"
-#include "saga/sstack.h"
#include "saga/sthread.h"
#include "saga/sfuncs.h"
+#include "common/stack.h"
+
namespace Saga {
R_SCRIPT_THREAD *STHREAD_Create() {
YS_DL_NODE *new_node;
R_SCRIPT_THREAD *new_thread;
- int result;
-
if (!_vm->_script->isInitialized()) {
return NULL;
}
@@ -54,11 +53,7 @@ R_SCRIPT_THREAD *STHREAD_Create() {
return NULL;
}
- result = SSTACK_Create(&(new_thread->stack), R_DEF_THREAD_STACKSIZE, STACK_GROW);
-
- if (result != STACK_SUCCESS) {
- return NULL;
- }
+ new_thread->stack = new Common::Stack<SDataWord_T>();
new_node = ys_dll_add_head(_vm->_script->threadList(), new_thread, sizeof *new_thread);
@@ -72,7 +67,7 @@ int STHREAD_Destroy(R_SCRIPT_THREAD *thread) {
return R_FAILURE;
}
- SSTACK_Destroy(thread->stack);
+ delete thread->stack;
return R_SUCCESS;
}
@@ -191,7 +186,6 @@ int STHREAD_Run(R_SCRIPT_THREAD *thread, int instr_limit, int msec) {
int debug_print = 0;
int n_buf;
int bitstate;
- int result;
int in_char;
int i;
int unhandled = 0;
@@ -233,35 +227,35 @@ int STHREAD_Run(R_SCRIPT_THREAD *thread, int instr_limit, int msec) {
switch (in_char) {
// Align (ALGN)
case 0x01:
+ debug(0, "Stub: ALGN");
break;
// STACK INSTRUCTIONS
-
- // Push nothing (PSHN)
+ // Dup top element (DUP)
case 0x02:
- SSTACK_PushNull(thread->stack);
+ thread->stack->push(thread->stack->top());
break;
// Pop nothing (POPN)
case 0x03:
- SSTACK_Pop(thread->stack, NULL);
+ thread->stack->pop();
break;
// Push false (PSHF)
case 0x04:
- SSTACK_Push(thread->stack, 0);
+ thread->stack->push(0);
break;
// Push true (PSHT)
- case 0x05:
- SSTACK_Push(thread->stack, 1);
+ case 0x06:
+ thread->stack->push(1);
break;
// Push word (PUSH)
- case 0x06:
+ case 0x07:
param1 = (SDataWord_T)readS.readUint16LE();
- SSTACK_Push(thread->stack, param1);
+ thread->stack->push(param1);
break;
// Push word (PSHD) (dialogue string index)
case 0x08:
param1 = (SDataWord_T)readS.readUint16LE();
- SSTACK_Push(thread->stack, param1);
+ thread->stack->push(param1);
break;
// DATA INSTRUCTIONS
@@ -271,21 +265,21 @@ int STHREAD_Run(R_SCRIPT_THREAD *thread, int instr_limit, int msec) {
n_buf = readS.readByte();
param1 = (SDataWord_T)readS.readUint16LE();
_vm->_sdata->getBit(n_buf, param1, &bitstate);
- SSTACK_Push(thread->stack, bitstate);
+ thread->stack->push(bitstate);
break;
// Get word (GETW)
case 0x0C:
n_buf = readS.readByte();
param1 = readS.readUint16LE();
_vm->_sdata->getWord(n_buf, param1, &data);
- SSTACK_Push(thread->stack, data);
+ thread->stack->push(data);
break;
// Modify flag (MODF)
case 0x0F:
n_buf = readS.readByte();
param1 = (SDataWord_T)readS.readUint16LE();
bitstate = _vm->_sdata->readWordU(param1);
- SSTACK_Top(thread->stack, &data);
+ data = thread->stack->top();
if (bitstate) {
_vm->_sdata->setBit(n_buf, data, 1);
} else {
@@ -296,14 +290,14 @@ int STHREAD_Run(R_SCRIPT_THREAD *thread, int instr_limit, int msec) {
case 0x10:
n_buf = readS.readByte();
param1 = (SDataWord_T)readS.readUint16LE();
- SSTACK_Top(thread->stack, &data);
+ data = thread->stack->top();
_vm->_sdata->putWord(n_buf, param1, data);
break;
// Modify flag and pop (MDFP)
case 0x13:
n_buf = readS.readByte();
param1 = (SDataWord_T)readS.readUint16LE();
- SSTACK_Pop(thread->stack, &param1);
+ param1 = thread->stack->pop();
bitstate = _vm->_sdata->readWordU(param1);
if (bitstate) {
_vm->_sdata->setBit(n_buf, param1, 1);
@@ -315,7 +309,7 @@ int STHREAD_Run(R_SCRIPT_THREAD *thread, int instr_limit, int msec) {
case 0x14:
n_buf = readS.readByte();
param1 = (SDataWord_T)readS.readUint16LE();
- SSTACK_Top(thread->stack, &data);
+ data = thread->stack->top();
_vm->_sdata->putWord(n_buf, param1, data);
break;
@@ -331,8 +325,8 @@ int STHREAD_Run(R_SCRIPT_THREAD *thread, int instr_limit, int msec) {
temp2 = readS.readByte();
param1 = (SDataWord_T)readS.readUint16LE();
data = readS.pos();
- //SSTACK_Push(thread->stack, (SDataWord_T)temp);
- SSTACK_Push(thread->stack, data);
+ //thread->stack->push((SDataWord_T)temp);
+ thread->stack->push(data);
thread->i_offset = (unsigned long)param1;
}
break;
@@ -359,7 +353,7 @@ int STHREAD_Run(R_SCRIPT_THREAD *thread, int instr_limit, int msec) {
thread->i_offset, func_num);
_vm->_console->print(S_WARN_PREFIX "Removing %d operand(s) from stack.\n", n_args);
for (i = 0; i < n_args; i++) {
- SSTACK_Pop(thread->stack, NULL);
+ thread->stack->pop();
}
} else {
FIXME_SHADOWED_result = sfunc(thread);
@@ -371,6 +365,9 @@ int STHREAD_Run(R_SCRIPT_THREAD *thread, int instr_limit, int msec) {
break;
// (ENTR) Enter the dragon
case 0x1A:
+ //data = readS.pos();
+ //thread->stack->push(data);
+
param1 = readS.readUint16LE();
break;
// (?) Unknown
@@ -379,11 +376,11 @@ int STHREAD_Run(R_SCRIPT_THREAD *thread, int instr_limit, int msec) {
break;
// (EXIT) End subscript
case 0x1C:
- result = SSTACK_Pop(thread->stack, &data);
- if (result != STACK_SUCCESS) {
+ if (thread->stack->size() == 0) {
_vm->_console->print("Script execution complete.");
thread->executing = 0;
} else {
+ data = thread->stack->pop();
thread->i_offset = data;
}
break;
@@ -398,7 +395,7 @@ int STHREAD_Run(R_SCRIPT_THREAD *thread, int instr_limit, int msec) {
// (JNZP): Jump if nonzero + POP
case 0x1E:
param1 = readS.readUint16LE();
- SSTACK_Pop(thread->stack, &data);
+ data = thread->stack->pop();
if (data) {
thread->i_offset = (unsigned long)param1;
}
@@ -406,7 +403,7 @@ int STHREAD_Run(R_SCRIPT_THREAD *thread, int instr_limit, int msec) {
// (JZP): Jump if zero + POP
case 0x1F:
param1 = readS.readUint16LE();
- SSTACK_Pop(thread->stack, &data);
+ data = thread->stack->pop();
if (!data) {
thread->i_offset = (unsigned long)param1;
}
@@ -414,7 +411,7 @@ int STHREAD_Run(R_SCRIPT_THREAD *thread, int instr_limit, int msec) {
// (JNZ): Jump if nonzero
case 0x20:
param1 = readS.readUint16LE();
- SSTACK_Top(thread->stack, &data);
+ data = thread->stack->top();
if (data) {
thread->i_offset = (unsigned long)param1;
}
@@ -422,7 +419,7 @@ int STHREAD_Run(R_SCRIPT_THREAD *thread, int instr_limit, int msec) {
// (JZ): Jump if zero
case 0x21:
param1 = readS.readUint16LE();
- SSTACK_Top(thread->stack, &data);
+ data = thread->stack->top();
if (!data) {
thread->i_offset = (unsigned long)param1;
}
@@ -444,7 +441,7 @@ int STHREAD_Run(R_SCRIPT_THREAD *thread, int instr_limit, int msec) {
unsigned int default_jmp;
int case_found = 0;
- SSTACK_Pop(thread->stack, &data);
+ data = thread->stack->pop();
n_switch = readS.readUint16LE();
for (i = 0; i < n_switch; i++) {
switch_num = readS.readUint16LE();
@@ -495,22 +492,22 @@ int STHREAD_Run(R_SCRIPT_THREAD *thread, int instr_limit, int msec) {
// (NEG) Negate stack by 2's complement
case 0x25:
- SSTACK_Pop(thread->stack, &data);
+ data = thread->stack->pop();
data = ~data;
data++;
- SSTACK_Push(thread->stack, data);
+ thread->stack->push(data);
break;
// (TSTZ) Test for zero
case 0x26:
- SSTACK_Pop(thread->stack, &data);
+ data = thread->stack->pop();
data = data ? 0 : 1;
- SSTACK_Push(thread->stack, data);
+ thread->stack->push(data);
break;
// (NOT) Binary not
case 0x27:
- SSTACK_Pop(thread->stack, &data);
+ data = thread->stack->pop();
data = ~data;
- SSTACK_Push(thread->stack, data);
+ thread->stack->push(data);
break;
// (?)
case 0x28:
@@ -545,110 +542,110 @@ int STHREAD_Run(R_SCRIPT_THREAD *thread, int instr_limit, int msec) {
// (ADD): Addition
case 0x2C:
- SSTACK_Pop(thread->stack, &param2);
- SSTACK_Pop(thread->stack, &param1);
+ param2 = thread->stack->pop();
+ param1 = thread->stack->pop();
iparam2 = (long)param2;
iparam1 = (long)param1;
iresult = iparam1 + iparam2;
- SSTACK_Push(thread->stack, (SDataWord_T) iresult);
+ thread->stack->push((SDataWord_T) iresult);
break;
// (SUB): Subtraction
case 0x2D:
- SSTACK_Pop(thread->stack, &param2);
- SSTACK_Pop(thread->stack, &param1);
+ param2 = thread->stack->pop();
+ param1 = thread->stack->pop();
iparam2 = (long)param2;
iparam1 = (long)param1;
iresult = iparam1 - iparam2;
- SSTACK_Push(thread->stack, (SDataWord_T) iresult);
+ thread->stack->push((SDataWord_T) iresult);
break;
// (MULT): Integer multiplication
case 0x2E:
- SSTACK_Pop(thread->stack, &param2);
- SSTACK_Pop(thread->stack, &param1);
+ param2 = thread->stack->pop();
+ param1 = thread->stack->pop();
iparam2 = (long)param2;
iparam1 = (long)param1;
iresult = iparam1 * iparam2;
- SSTACK_Push(thread->stack, (SDataWord_T) iresult);
+ thread->stack->push((SDataWord_T) iresult);
break;
// (DIV): Integer division
case 0x2F:
- SSTACK_Pop(thread->stack, &param2);
- SSTACK_Pop(thread->stack, &param1);
+ param2 = thread->stack->pop();
+ param1 = thread->stack->pop();
iparam2 = (long)param2;
iparam1 = (long)param1;
iresult = iparam1 / iparam2;
- SSTACK_Push(thread->stack, (SDataWord_T) iresult);
+ thread->stack->push((SDataWord_T) iresult);
break;
// (MOD) Modulus
case 0x30:
- SSTACK_Pop(thread->stack, &param2);
- SSTACK_Pop(thread->stack, &param1);
+ param2 = thread->stack->pop();
+ param1 = thread->stack->pop();
iparam2 = (long)param2;
iparam1 = (long)param1;
iresult = iparam1 % iparam2;
- SSTACK_Push(thread->stack, (SDataWord_T) iresult);
+ thread->stack->push((SDataWord_T) iresult);
break;
// (EQU) Test equality
case 0x33:
- SSTACK_Pop(thread->stack, &param2);
- SSTACK_Pop(thread->stack, &param1);
+ param2 = thread->stack->pop();
+ param1 = thread->stack->pop();
iparam2 = (long)param2;
iparam1 = (long)param1;
data = (iparam1 == iparam2) ? 1 : 0;
- SSTACK_Push(thread->stack, data);
+ thread->stack->push(data);
break;
// (NEQU) Test inequality
case 0x34:
- SSTACK_Pop(thread->stack, &param2);
- SSTACK_Pop(thread->stack, &param1);
+ param2 = thread->stack->pop();
+ param1 = thread->stack->pop();
iparam2 = (long)param2;
iparam1 = (long)param1;
data = (iparam1 != iparam2) ? 1 : 0;
- SSTACK_Push(thread->stack, data);
+ thread->stack->push(data);
break;
// (GRT) Test Greater-than
case 0x35:
- SSTACK_Pop(thread->stack, &param2);
- SSTACK_Pop(thread->stack, &param1);
+ param2 = thread->stack->pop();
+ param1 = thread->stack->pop();
iparam2 = (long)param2;
iparam1 = (long)param1;
data = (iparam1 > iparam2) ? 1 : 0;
- SSTACK_Push(thread->stack, data);
+ thread->stack->push(data);
break;
// (LST) Test Less-than
case 0x36:
- SSTACK_Pop(thread->stack, &param2);
- SSTACK_Pop(thread->stack, &param1);
+ param2 = thread->stack->pop();
+ param1 = thread->stack->pop();
iparam2 = (long)param2;
iparam1 = (long)param1;
data = (iparam1 < iparam2) ? 1 : 0;
- SSTACK_Push(thread->stack, data);
+ thread->stack->push(data);
break;
// (GRTE) Test Greater-than or Equal to
case 0x37:
- SSTACK_Pop(thread->stack, &param2);
- SSTACK_Pop(thread->stack, &param1);
+ param2 = thread->stack->pop();
+ param1 = thread->stack->pop();
iparam2 = (long)param2;
iparam1 = (long)param1;
data = (iparam1 >= iparam2) ? 1 : 0;
- SSTACK_Push(thread->stack, data);
+ thread->stack->push(data);
break;
// (LSTE) Test Less-than or Equal to
case 0x38:
- SSTACK_Pop(thread->stack, &param2);
- SSTACK_Pop(thread->stack, &param1);
+ param2 = thread->stack->pop();
+ param1 = thread->stack->pop();
iparam2 = (long)param2;
iparam1 = (long)param1;
data = (iparam1 <= iparam2) ? 1 : 0;
- SSTACK_Push(thread->stack, data);
+ thread->stack->push(data);
break;
// BITWISE INSTRUCTIONS
// (SHR): Arithmetic binary shift right
case 0x3F:
- SSTACK_Pop(thread->stack, &param2);
- SSTACK_Pop(thread->stack, &param1);
+ param2 = thread->stack->pop();
+ param1 = thread->stack->pop();
iparam2 = (long)param2;
// Preserve most significant bit
data = (0x01 << ((sizeof param1 * CHAR_BIT) - 1)) & param1;
@@ -656,59 +653,59 @@ int STHREAD_Run(R_SCRIPT_THREAD *thread, int instr_limit, int msec) {
param1 >>= 1;
param1 |= data;
}
- SSTACK_Push(thread->stack, param1);
+ thread->stack->push(param1);
break;
// (SHL) Binary shift left
case 0x40:
- SSTACK_Pop(thread->stack, &param2);
- SSTACK_Pop(thread->stack, &param1);
+ param2 = thread->stack->pop();
+ param1 = thread->stack->pop();
param1 <<= param2;
- SSTACK_Push(thread->stack, param1);
+ thread->stack->push(param1);
break;
// (AND) Binary AND
case 0x41:
- SSTACK_Pop(thread->stack, &param2);
- SSTACK_Pop(thread->stack, &param1);
+ param2 = thread->stack->pop();
+ param1 = thread->stack->pop();
param1 &= param2;
- SSTACK_Push(thread->stack, param1);
+ thread->stack->push(param1);
break;
// (OR) Binary OR
case 0x42:
- SSTACK_Pop(thread->stack, &param2);
- SSTACK_Pop(thread->stack, &param1);
+ param2 = thread->stack->pop();
+ param1 = thread->stack->pop();
param1 |= param2;
- SSTACK_Push(thread->stack, param1);
+ thread->stack->push(param1);
break;
// (XOR) Binary XOR
case 0x43:
- SSTACK_Pop(thread->stack, &param2);
- SSTACK_Pop(thread->stack, &param1);
+ param2 = thread->stack->pop();
+ param1 = thread->stack->pop();
param1 ^= param2;
- SSTACK_Push(thread->stack, param1);
+ thread->stack->push(param1);
break;
// BOOLEAN LOGIC INSTRUCTIONS
// (LAND): Logical AND
case 0x44:
- SSTACK_Pop(thread->stack, &param2);
- SSTACK_Pop(thread->stack, &param1);
+ param2 = thread->stack->pop();
+ param1 = thread->stack->pop();
data = (param1 && param2) ? 1 : 0;
- SSTACK_Push(thread->stack, data);
+ thread->stack->push(data);
break;
// (LOR): Logical OR
case 0x45:
- SSTACK_Pop(thread->stack, &param2);
- SSTACK_Pop(thread->stack, &param1);
+ param2 = thread->stack->pop();
+ param1 = thread->stack->pop();
data = (param1 || param2) ? 1 : 0;
- SSTACK_Push(thread->stack, data);
+ thread->stack->push(data);
break;
// (LXOR): Logical XOR
case 0x46:
- SSTACK_Pop(thread->stack, &param2);
- SSTACK_Pop(thread->stack, &param1);
+ param2 = thread->stack->pop();
+ param1 = thread->stack->pop();
data = ((param1) ? !(param2) : !!(param2));
- SSTACK_Push(thread->stack, data);
+ thread->stack->push(data);
break;
// GAME INSTRUCTIONS
@@ -732,7 +729,7 @@ int STHREAD_Run(R_SCRIPT_THREAD *thread, int instr_limit, int msec) {
}
for (i = 0; i < n_voices; i++) {
- SSTACK_Pop(thread->stack, &data);
+ data = thread->stack->pop();
if (a_index < 0)
continue;
if (!_vm->_script->isVoiceLUTPresent()) {
diff --git a/saga/sthread.h b/saga/sthread.h
index 06e201e490..cadd8a3f18 100644
--- a/saga/sthread.h
+++ b/saga/sthread.h
@@ -26,7 +26,7 @@
#ifndef SAGA_STHREAD_H__
#define SAGA_STHREAD_H__
-#include "saga/sstack.h"
+#include "common/stack.h"
namespace Saga {
@@ -45,7 +45,7 @@ struct R_SCRIPT_THREAD_tag {
unsigned long i_offset; // Instruction offset
R_SEMAPHORE sem;
- SSTACK stack;
+ Common::Stack<SDataWord_T> *stack;
};
R_SCRIPT_THREAD *STHREAD_Create();