aboutsummaryrefslogtreecommitdiff
path: root/sword2
diff options
context:
space:
mode:
Diffstat (limited to 'sword2')
-rw-r--r--sword2/build_display.cpp1
-rw-r--r--sword2/controls.cpp2
-rw-r--r--sword2/icons.cpp2
-rw-r--r--sword2/interpreter.cpp6
-rw-r--r--sword2/interpreter.h123
-rw-r--r--sword2/logic.cpp6
-rw-r--r--sword2/logic.h3
-rw-r--r--sword2/save_rest.cpp8
-rw-r--r--sword2/speech.cpp10
-rw-r--r--sword2/startup.cpp6
-rw-r--r--sword2/sword2.cpp4
-rw-r--r--sword2/walker.cpp4
12 files changed, 88 insertions, 87 deletions
diff --git a/sword2/build_display.cpp b/sword2/build_display.cpp
index 65dec308ab..18dca60264 100644
--- a/sword2/build_display.cpp
+++ b/sword2/build_display.cpp
@@ -23,6 +23,7 @@
#include "stdafx.h"
#include "bs2/sword2.h"
+#include "bs2/debug.h"
#include "bs2/build_display.h"
#include "bs2/console.h"
#include "bs2/defs.h"
diff --git a/sword2/controls.cpp b/sword2/controls.cpp
index d504c05406..7f48ad8b4d 100644
--- a/sword2/controls.cpp
+++ b/sword2/controls.cpp
@@ -1427,7 +1427,7 @@ void Gui::restartControl(void) {
// reopen global variables resource & send address to interpreter -
// it won't be moving
- SetGlobalInterpreterVariables((int32 *) (res_man.open(1) + sizeof(_standardHeader)));
+ g_logic.setGlobalInterpreterVariables((int32 *) (res_man.open(1) + sizeof(_standardHeader)));
res_man.close(1);
DEMO = temp_demo_flag;
diff --git a/sword2/icons.cpp b/sword2/icons.cpp
index 06a80e585d..a8e049354d 100644
--- a/sword2/icons.cpp
+++ b/sword2/icons.cpp
@@ -98,7 +98,7 @@ void Build_menu(void) {
// objects. Run the 'build_menu' script in the 'menu_master' object
head = res_man.open(MENU_MASTER_OBJECT);
- RunScript((char*) head, (char*) head, &null_pc);
+ g_logic.runScript((char*) head, (char*) head, &null_pc);
res_man.close(MENU_MASTER_OBJECT);
// Compare new with old. Anything in master thats not in new gets
diff --git a/sword2/interpreter.cpp b/sword2/interpreter.cpp
index 4b16528db9..bf1161180d 100644
--- a/sword2/interpreter.cpp
+++ b/sword2/interpreter.cpp
@@ -215,11 +215,11 @@ int32 Logic::executeOpcode(int i, int32 *params) {
#define POPOFFSTACK(x) { x = stack2[stackPointer2 - 1]; stackPointer2--; CHECKSTACKPOINTER2 }
#define DOOPERATION(x) { stack2[stackPointer2 - 2] = (x); stackPointer2--; CHECKSTACKPOINTER2 }
-void SetGlobalInterpreterVariables(int32 *vars) {
+void Logic::setGlobalInterpreterVariables(int32 *vars) {
globalInterpreterVariables2 = vars;
}
-int RunScript(char *scriptData, char *objectData, uint32 *offset) {
+int Logic::runScript(char *scriptData, char *objectData, uint32 *offset) {
#define STACK_SIZE 10
_standardHeader *header = (_standardHeader *) scriptData;
@@ -329,7 +329,7 @@ int RunScript(char *scriptData, char *objectData, uint32 *offset) {
Read8ip(value);
debug(5, "Call mcode %d with stack = %x", parameter, stack2 + stackPointer2 - value);
- retVal = g_logic.executeOpcode(parameter, stack2 + stackPointer2 - value);
+ retVal = executeOpcode(parameter, stack2 + stackPointer2 - value);
stackPointer2 -= value;
CHECKSTACKPOINTER2
diff --git a/sword2/interpreter.h b/sword2/interpreter.h
index 0a9a1c3bb4..4b0d4a1329 100644
--- a/sword2/interpreter.h
+++ b/sword2/interpreter.h
@@ -20,77 +20,74 @@
#ifndef _INTERPRETER
#define _INTERPRETER
-#include "bs2/debug.h"
-#include "bs2/header.h"
-
namespace Sword2 {
// Interpreter return codes
-#define IR_STOP 0
-#define IR_CONT 1
-#define IR_TERMINATE 2
-#define IR_REPEAT 3
-#define IR_GOSUB 4
+enum {
+ IR_STOP = 0,
+ IR_CONT = 1,
+ IR_TERMINATE = 2,
+ IR_REPEAT = 3,
+ IR_GOSUB = 4
+};
// Get parameter fix so that the playstation version can handle words not on
// word boundaries
-#define Read8ip(var) { var = *((const int8 *) (code + ip)); ip++; }
-#define Read16ip(var) { var = (int16) READ_LE_UINT16(code + ip); ip += sizeof(int16); }
-#define Read32ip(var) { var = (int32) READ_LE_UINT32(code + ip); ip += sizeof(int32); }
-#define Read32ipLeaveip(var) { var = (int32) READ_LE_UINT32(code + ip); }
-
-void SetGlobalInterpreterVariables(int32 *vars);
-int RunScript (char *scriptData, char *objectData, uint32 *offset);
-
-// Compiled tokens
-
-#define CP_END_SCRIPT 0
-#define CP_PUSH_LOCAL_VAR32 1 // Push a local variable on to the stack
-#define CP_PUSH_GLOBAL_VAR32 2 // Push a global variable
-#define CP_POP_LOCAL_VAR32 3 // Pop a local variable from the stack
-#define CP_CALL_MCODE 4 // Call a machine code function
-#define CP_PUSH_LOCAL_ADDR 5 // Push the address of a local variable
-#define CP_PUSH_INT32 6 // Adjust the stack after calling an fn function
-#define CP_SKIPONFALSE 7 // Skip if the bottom value on the stack is false
-#define CP_SKIPALWAYS 8 // Skip a block of code
-#define CP_SWITCH 9 // Switch on last stack value
-#define CP_ADDNPOP_LOCAL_VAR32 10 // Add to a local varible
-#define CP_SUBNPOP_LOCAL_VAR32 11 // Subtract to a local variable
-#define CP_SKIPONTRUE 12 // Skip if the bottom value on the stack is true
-#define CP_POP_GLOBAL_VAR32 13 // Pop a global variable
-#define CP_ADDNPOP_GLOBAL_VAR32 14
-#define CP_SUBNPOP_GLOBAL_VAR32 15
-#define CP_DEBUGON 16 // Turn debugging on
-#define CP_DEBUGOFF 17 // Turn debugging off
-#define CP_QUIT 18 // Quit for a cycle
-#define CP_TERMINATE 19 // Quit script completely
-
-// Operators
-
-#define OP_ISEQUAL 20 // '=='
-#define OP_PLUS 21 // '+'
-#define OP_MINUS 22 // '-'
-#define OP_TIMES 23 // '*'
-#define OP_DIVIDE 24 // '/'
-#define OP_NOTEQUAL 25 // '=='
-#define OP_ANDAND 26 // '&&'
-#define OP_GTTHAN 27 // '>'
-#define OP_LSTHAN 28 // '<'
-
-// More tokens, mixed types
-
-#define CP_JUMP_ON_RETURNED 29 // Use table of jumps with value returned from fn_mcode
-#define CP_TEMP_TEXT_PROCESS 30 // A dummy text process command for me
-#define CP_SAVE_MCODE_START 31 // Save the mcode code start for restarting when necessary
-#define CP_RESTART_SCRIPT 32 // Start the script from the beginning
-#define CP_PUSH_STRING 33 // Push a pointer to a string on the stack
-#define CP_PUSH_DEREFERENCED_STRUCTURE 34 // Push the address of a structure thing
-
-#define OP_GTTHANE 35 // >=
-#define OP_LSTHANE 36 // <=
-#define OP_OROR 37 // || or OR
+#define Read8ip(var) { var = *((const int8 *) (code + ip)); ip++; }
+#define Read16ip(var) { var = (int16) READ_LE_UINT16(code + ip); ip += sizeof(int16); }
+#define Read32ip(var) { var = (int32) READ_LE_UINT32(code + ip); ip += sizeof(int32); }
+#define Read32ipLeaveip(var) { var = (int32) READ_LE_UINT32(code + ip); }
+
+enum {
+ // Compiled tokens
+
+ CP_END_SCRIPT = 0,
+ CP_PUSH_LOCAL_VAR32 = 1, // Push a local variable on to the stack
+ CP_PUSH_GLOBAL_VAR32 = 2, // Push a global variable
+ CP_POP_LOCAL_VAR32 = 3, // Pop a local variable from the stack
+ CP_CALL_MCODE = 4, // Call a machine code function
+ CP_PUSH_LOCAL_ADDR = 5, // Push the address of a local variable
+ CP_PUSH_INT32 = 6, // Adjust the stack after calling an fn function
+ CP_SKIPONFALSE = 7, // Skip if the bottom value on the stack is false
+ CP_SKIPALWAYS = 8, // Skip a block of code
+ CP_SWITCH = 9, // Switch on last stack value
+ CP_ADDNPOP_LOCAL_VAR32 = 10, // Add to a local varible
+ CP_SUBNPOP_LOCAL_VAR32 = 11, // Subtract to a local variable
+ CP_SKIPONTRUE = 12, // Skip if the bottom value on the stack is true
+ CP_POP_GLOBAL_VAR32 = 13, // Pop a global variable
+ CP_ADDNPOP_GLOBAL_VAR32 = 14,
+ CP_SUBNPOP_GLOBAL_VAR32 = 15,
+ CP_DEBUGON = 16, // Turn debugging on
+ CP_DEBUGOFF = 17, // Turn debugging off
+ CP_QUIT = 18, // Quit for a cycle
+ CP_TERMINATE = 19, // Quit script completely
+
+ // Operators
+
+ OP_ISEQUAL = 20, // '=='
+ OP_PLUS = 21, // '+'
+ OP_MINUS = 22, // '-'
+ OP_TIMES = 23, // '*'
+ OP_DIVIDE = 24, // '/'
+ OP_NOTEQUAL = 25, // '=='
+ OP_ANDAND = 26, // '&&'
+ OP_GTTHAN = 27, // '>'
+ OP_LSTHAN = 28, // '<'
+
+ // More tokens, mixed types
+
+ CP_JUMP_ON_RETURNED = 29, // Use table of jumps with value returned from fn_mcode
+ CP_TEMP_TEXT_PROCESS = 30, // A dummy text process command for me
+ CP_SAVE_MCODE_START = 31, // Save the mcode code start for restarting when necessary
+ CP_RESTART_SCRIPT = 32, // Start the script from the beginning
+ CP_PUSH_STRING = 33, // Push a pointer to a string on the stack
+ CP_PUSH_DEREFERENCED_STRUCTURE = 34, // Push the address of a structure thing
+ OP_GTTHANE = 35, // >=
+ OP_LSTHANE = 36, // <=
+ OP_OROR = 37 // || or OR
+};
} // End of namespace Sword2
diff --git a/sword2/logic.cpp b/sword2/logic.cpp
index c3654ba042..1a7c0e79de 100644
--- a/sword2/logic.cpp
+++ b/sword2/logic.cpp
@@ -126,7 +126,7 @@ int Logic::processSession(void) {
raw_script_ad = (char*) head;
// script and data object are us/same
- ret = RunScript(raw_script_ad, raw_script_ad, &_curObjectHub->script_pc[LEVEL]);
+ ret = runScript(raw_script_ad, raw_script_ad, &_curObjectHub->script_pc[LEVEL]);
} else {
// we're running the script of another game
// object - get our data object address
@@ -147,7 +147,7 @@ int Logic::processSession(void) {
raw_script_ad = (char*) far_head;
- ret = RunScript(raw_script_ad, raw_data_ad, &_curObjectHub->script_pc[LEVEL]);
+ ret = runScript(raw_script_ad, raw_data_ad, &_curObjectHub->script_pc[LEVEL]);
// close foreign object again
res_man.close(script / SIZE);
@@ -199,7 +199,7 @@ int Logic::processSession(void) {
// call the base script - this is the graphic/mouse
// service call
- RunScript(raw_script_ad, raw_script_ad, &null_pc);
+ runScript(raw_script_ad, raw_script_ad, &null_pc);
}
// made for all live objects
diff --git a/sword2/logic.h b/sword2/logic.h
index 0bf985b4e8..a1c2e4d718 100644
--- a/sword2/logic.h
+++ b/sword2/logic.h
@@ -61,6 +61,9 @@ public:
setupOpcodes();
}
+ void setGlobalInterpreterVariables(int32 *vars);
+ int runScript(char *scriptData, char *objectData, uint32 *offset);
+
int32 executeOpcode(int op, int32 *params);
int32 fnTestFunction(int32 *params);
diff --git a/sword2/save_rest.cpp b/sword2/save_rest.cpp
index e062ed0c93..d5e8dca505 100644
--- a/sword2/save_rest.cpp
+++ b/sword2/save_rest.cpp
@@ -520,7 +520,7 @@ void GetPlayerStructures(void) {
Con_fatal_error("incorrect CUR_PLAYER_ID=%d", CUR_PLAYER_ID);
raw_script_ad = (char *) head;
- RunScript(raw_script_ad, raw_script_ad, &null_pc);
+ g_logic.runScript(raw_script_ad, raw_script_ad, &null_pc);
res_man.close(CUR_PLAYER_ID);
}
@@ -543,12 +543,12 @@ void PutPlayerStructures(void) {
// script no. 8 - 'george_savedata_return' calls fnGetPlayerSaveData
null_pc = 8;
- RunScript(raw_script_ad, raw_script_ad, &null_pc);
+ g_logic.runScript(raw_script_ad, raw_script_ad, &null_pc);
// script no. 14 - 'set_up_nico_anim_tables'
null_pc = 14;
- RunScript(raw_script_ad, raw_script_ad, &null_pc);
+ g_logic.runScript(raw_script_ad, raw_script_ad, &null_pc);
// which megaset was the player at the time of saving?
@@ -570,7 +570,7 @@ void PutPlayerStructures(void) {
break;
}
- RunScript(raw_script_ad, raw_script_ad, &null_pc);
+ g_logic.runScript(raw_script_ad, raw_script_ad, &null_pc);
res_man.close(CUR_PLAYER_ID);
}
diff --git a/sword2/speech.cpp b/sword2/speech.cpp
index e3df918b68..f72bbddb8d 100644
--- a/sword2/speech.cpp
+++ b/sword2/speech.cpp
@@ -365,8 +365,8 @@ int32 Logic::fnTheyDo(int32 *params) {
raw_script_ad = (char *) head;
- //call the base script - this is the graphic/mouse service call
- RunScript(raw_script_ad, raw_script_ad, &null_pc);
+ // call the base script - this is the graphic/mouse service call
+ runScript(raw_script_ad, raw_script_ad, &null_pc);
res_man.close(target);
@@ -428,7 +428,7 @@ int32 Logic::fnTheyDoWeWait(int32 *params) {
raw_script_ad = (char *) head;
// call the base script - this is the graphic/mouse service call
- RunScript(raw_script_ad, raw_script_ad, &null_pc);
+ runScript(raw_script_ad, raw_script_ad, &null_pc);
res_man.close(target);
@@ -508,7 +508,7 @@ int32 Logic::fnWeWait(int32 *params) {
raw_script_ad = (char *) head;
// call the base script - this is the graphic/mouse service call
- RunScript(raw_script_ad, raw_script_ad, &null_pc);
+ runScript(raw_script_ad, raw_script_ad, &null_pc);
res_man.close(target);
@@ -556,7 +556,7 @@ int32 Logic::fnTimedWait(int32 *params) {
raw_script_ad = (char *) head;
// call the base script - this is the graphic/mouse service call
- RunScript(raw_script_ad, raw_script_ad, &null_pc);
+ runScript(raw_script_ad, raw_script_ad, &null_pc);
res_man.close(target);
diff --git a/sword2/startup.cpp b/sword2/startup.cpp
index a50d627672..75e39c6a7f 100644
--- a/sword2/startup.cpp
+++ b/sword2/startup.cpp
@@ -129,7 +129,7 @@ uint32 Init_start_menu(void) {
debug(5, "- resource %d ok", res);
raw_script = (char*) res_man.open(res);
null_pc = 0;
- RunScript(raw_script, raw_script, &null_pc);
+ g_logic.runScript(raw_script, raw_script, &null_pc);
res_man.close(res);
} else
debug(5, "- resource %d invalid", res);
@@ -267,7 +267,7 @@ uint32 Con_start(uint8 *input) {
// reopen global variables resource & send address to
// interpreter - it won't be moving
- SetGlobalInterpreterVariables((int32 *) (res_man.open(1) + sizeof(_standardHeader)));
+ g_logic.setGlobalInterpreterVariables((int32 *) (res_man.open(1) + sizeof(_standardHeader)));
res_man.close(1);
// free all the route memory blocks from previous game
@@ -289,7 +289,7 @@ uint32 Con_start(uint8 *input) {
null_pc = start_list[start].key & 0xffff;
Print_to_console("running start %d", start);
- RunScript(raw_script, raw_data_ad, &null_pc);
+ g_logic.runScript(raw_script, raw_data_ad, &null_pc);
res_man.close(start_list[start].start_res_id);
diff --git a/sword2/sword2.cpp b/sword2/sword2.cpp
index 6fcacd540f..f6925d39c6 100644
--- a/sword2/sword2.cpp
+++ b/sword2/sword2.cpp
@@ -184,7 +184,7 @@ int32 Sword2Engine::InitialiseGame(void) {
// res 1 is the globals list
file = res_man.open(1);
debug(5, "CALLING: SetGlobalInterpreterVariables");
- SetGlobalInterpreterVariables((int32 * ) (file + sizeof(_standardHeader)));
+ g_logic.setGlobalInterpreterVariables((int32 * ) (file + sizeof(_standardHeader)));
// DON'T CLOSE VARIABLES RESOURCE - KEEP IT OPEN AT VERY START OF
// MEMORY SO IT CAN'T MOVE!
@@ -466,7 +466,7 @@ void Sword2Engine::Start_game(void) {
raw_script = (char *) res_man.open(screen_manager_id);
// run the start script now (because no console)
- RunScript(raw_script, raw_data_ad, &null_pc);
+ g_logic.runScript(raw_script, raw_data_ad, &null_pc);
// close the ScreenManager object
res_man.close(screen_manager_id);
diff --git a/sword2/walker.cpp b/sword2/walker.cpp
index ebf198bbe2..11e0d6a3cf 100644
--- a/sword2/walker.cpp
+++ b/sword2/walker.cpp
@@ -611,7 +611,7 @@ int32 Logic::fnFaceMega(int32 *params) {
raw_script_ad = (char *) head;
//call the base script - this is the graphic/mouse service call
- RunScript(raw_script_ad, raw_script_ad, &null_pc);
+ runScript(raw_script_ad, raw_script_ad, &null_pc);
res_man.close(params[4]);
@@ -674,7 +674,7 @@ int32 Logic::fnWalkToTalkToMega(int32 *params) {
// call the base script - this is the graphic/mouse service
// call
- RunScript(raw_script_ad, raw_script_ad, &null_pc);
+ runScript(raw_script_ad, raw_script_ad, &null_pc);
res_man.close(params[4]);