diff options
Diffstat (limited to 'sword2/interpreter.h')
-rw-r--r-- | sword2/interpreter.h | 123 |
1 files changed, 60 insertions, 63 deletions
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 |