mirror of
https://github.com/libretro/scummvm.git
synced 2025-01-31 07:53:36 +00:00
create Script class from SCRIPT_* and ScriptModule
svn-id: r14425
This commit is contained in:
parent
48cddda4b9
commit
4aaea2131e
@ -47,6 +47,7 @@
|
|||||||
#include "game.h"
|
#include "game.h"
|
||||||
#include "interface_mod.h"
|
#include "interface_mod.h"
|
||||||
#include "isomap_mod.h"
|
#include "isomap_mod.h"
|
||||||
|
#include "script.h"
|
||||||
#include "script_mod.h"
|
#include "script_mod.h"
|
||||||
#include "scene_mod.h"
|
#include "scene_mod.h"
|
||||||
#include "sdata.h"
|
#include "sdata.h"
|
||||||
@ -117,9 +118,7 @@ void SagaEngine::go() {
|
|||||||
CON_Register(); // Register console cvars first
|
CON_Register(); // Register console cvars first
|
||||||
|
|
||||||
GAME_Register();
|
GAME_Register();
|
||||||
|
|
||||||
OBJECTMAP_Register();
|
OBJECTMAP_Register();
|
||||||
SCRIPT_Register();
|
|
||||||
ACTOR_Register();
|
ACTOR_Register();
|
||||||
SCENE_Register();
|
SCENE_Register();
|
||||||
|
|
||||||
@ -159,7 +158,7 @@ void SagaEngine::go() {
|
|||||||
_actionMap = new ActionMap(this);
|
_actionMap = new ActionMap(this);
|
||||||
OBJECTMAP_Init();
|
OBJECTMAP_Init();
|
||||||
ISOMAP_Init();
|
ISOMAP_Init();
|
||||||
SCRIPT_Init();
|
_script = new Script();
|
||||||
_sdata = new SData();
|
_sdata = new SData();
|
||||||
INTERFACE_Init(); // requires script module
|
INTERFACE_Init(); // requires script module
|
||||||
ACTOR_Init();
|
ACTOR_Init();
|
||||||
@ -208,6 +207,7 @@ void SagaEngine::go() {
|
|||||||
debug(0, "Sound disabled.");
|
debug(0, "Sound disabled.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_script->reg();
|
||||||
_render->reg();
|
_render->reg();
|
||||||
_anim->reg();
|
_anim->reg();
|
||||||
_actionMap->reg();
|
_actionMap->reg();
|
||||||
@ -240,7 +240,7 @@ void SagaEngine::go() {
|
|||||||
void SagaEngine::shutdown() {
|
void SagaEngine::shutdown() {
|
||||||
SCENE_Shutdown();
|
SCENE_Shutdown();
|
||||||
ACTOR_Shutdown();
|
ACTOR_Shutdown();
|
||||||
SCRIPT_Shutdown();
|
delete _script;
|
||||||
SPRITE_Shutdown();
|
SPRITE_Shutdown();
|
||||||
OBJECTMAP_Shutdown();
|
OBJECTMAP_Shutdown();
|
||||||
FONT_Shutdown();
|
FONT_Shutdown();
|
||||||
|
@ -45,6 +45,7 @@ class Render;
|
|||||||
class ActionMap;
|
class ActionMap;
|
||||||
class Gfx;
|
class Gfx;
|
||||||
class SData;
|
class SData;
|
||||||
|
class Script;
|
||||||
|
|
||||||
using Common::MemoryReadStream;
|
using Common::MemoryReadStream;
|
||||||
|
|
||||||
@ -95,6 +96,7 @@ public:
|
|||||||
ActionMap *_actionMap;
|
ActionMap *_actionMap;
|
||||||
Gfx *_gfx;
|
Gfx *_gfx;
|
||||||
SData *_sdata;
|
SData *_sdata;
|
||||||
|
Script *_script;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int decodeBGImageRLE(const byte *inbuf, size_t inbuf_len, byte *outbuf, size_t outbuf_len);
|
int decodeBGImageRLE(const byte *inbuf, size_t inbuf_len, byte *outbuf, size_t outbuf_len);
|
||||||
|
@ -38,6 +38,7 @@
|
|||||||
#include "palanim_mod.h"
|
#include "palanim_mod.h"
|
||||||
#include "render.h"
|
#include "render.h"
|
||||||
#include "rscfile_mod.h"
|
#include "rscfile_mod.h"
|
||||||
|
#include "script.h"
|
||||||
#include "text_mod.h"
|
#include "text_mod.h"
|
||||||
#include "sound.h"
|
#include "sound.h"
|
||||||
#include "music.h"
|
#include "music.h"
|
||||||
@ -469,7 +470,7 @@ int SCENE_Load(int scene_num, int load_flag, R_SCENE_PROC scene_proc, R_SCENE_DE
|
|||||||
|
|
||||||
// Load scene script data
|
// Load scene script data
|
||||||
if (SceneModule.desc.script_num > 0) {
|
if (SceneModule.desc.script_num > 0) {
|
||||||
if (SCRIPT_Load(SceneModule.desc.script_num) != R_SUCCESS) {
|
if (_vm->_script->loadScript(SceneModule.desc.script_num) != R_SUCCESS) {
|
||||||
warning("Error loading scene script");
|
warning("Error loading scene script");
|
||||||
return R_FAILURE;
|
return R_FAILURE;
|
||||||
}
|
}
|
||||||
@ -763,7 +764,7 @@ int SCENE_End() {
|
|||||||
SceneModule.scene_proc(SCENE_END, &scene_info);
|
SceneModule.scene_proc(SCENE_END, &scene_info);
|
||||||
|
|
||||||
if (SceneModule.desc.script_num > 0) {
|
if (SceneModule.desc.script_num > 0) {
|
||||||
SCRIPT_Free();
|
_vm->_script->freeScript();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Free scene background
|
// Free scene background
|
||||||
|
179
saga/script.cpp
179
saga/script.cpp
@ -39,19 +39,21 @@
|
|||||||
|
|
||||||
namespace Saga {
|
namespace Saga {
|
||||||
|
|
||||||
R_SCRIPT_MODULE ScriptModule;
|
static void CF_script_info(int argc, char *argv[], void *refCon);
|
||||||
|
static void CF_script_exec(int argc, char *argv[], void *refCon);
|
||||||
|
static void CF_script_togglestep(int argc, char *argv[], void *refCon);
|
||||||
|
|
||||||
int SCRIPT_Register() {
|
int Script::reg() {
|
||||||
CVAR_RegisterFunc(CF_script_info, "script_info", NULL, R_CVAR_NONE, 0, 0, NULL);
|
CVAR_RegisterFunc(CF_script_info, "script_info", NULL, R_CVAR_NONE, 0, 0, this);
|
||||||
CVAR_RegisterFunc(CF_script_exec, "script_exec", "<Script number>", R_CVAR_NONE, 1, 1, NULL);
|
CVAR_RegisterFunc(CF_script_exec, "script_exec", "<Script number>", R_CVAR_NONE, 1, 1, this);
|
||||||
CVAR_RegisterFunc(CF_script_togglestep, "script_togglestep", NULL, R_CVAR_NONE, 0, 0, NULL);
|
CVAR_RegisterFunc(CF_script_togglestep, "script_togglestep", NULL, R_CVAR_NONE, 0, 0, this);
|
||||||
|
|
||||||
return R_SUCCESS;
|
return R_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initializes the scripting module.
|
// Initializes the scripting module.
|
||||||
// Loads script resource look-up table, initializes script data system
|
// Loads script resource look-up table, initializes script data system
|
||||||
int SCRIPT_Init() {
|
Script::Script() {
|
||||||
R_RSCFILE_CONTEXT *s_lut_ctxt;
|
R_RSCFILE_CONTEXT *s_lut_ctxt;
|
||||||
byte *rsc_ptr;
|
byte *rsc_ptr;
|
||||||
size_t rsc_len;
|
size_t rsc_len;
|
||||||
@ -59,105 +61,108 @@ int SCRIPT_Init() {
|
|||||||
int result;
|
int result;
|
||||||
int i, j;
|
int i, j;
|
||||||
|
|
||||||
debug(0, "Initializing scripting subsystem.");
|
//initialize member variables
|
||||||
|
_initialized = 0;
|
||||||
|
_script_ctxt = 0;
|
||||||
|
_voice_lut_present = 0;
|
||||||
|
_script_lut = 0;
|
||||||
|
_script_lut_max = 0;
|
||||||
|
_script_lut_entrylen = 0;
|
||||||
|
_current_script = 0;
|
||||||
|
_thread_list = 0;
|
||||||
|
memset(_data_buf, 0, sizeof(_data_buf));
|
||||||
|
|
||||||
|
debug(0, "Initializing scripting subsystem");
|
||||||
// Load script resource file context
|
// Load script resource file context
|
||||||
result = GAME_GetFileContext(&ScriptModule.script_ctxt, R_GAME_SCRIPTFILE, 0);
|
result = GAME_GetFileContext(&_script_ctxt, R_GAME_SCRIPTFILE, 0);
|
||||||
if (result != R_SUCCESS) {
|
if (result != R_SUCCESS) {
|
||||||
warning("Couldn't get script file context");
|
error("Couldn't get script file context");
|
||||||
return R_FAILURE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load script LUT resource
|
// Load script LUT resource
|
||||||
result = GAME_GetFileContext(&s_lut_ctxt, R_GAME_RESOURCEFILE, 0);
|
result = GAME_GetFileContext(&s_lut_ctxt, R_GAME_RESOURCEFILE, 0);
|
||||||
if (result != R_SUCCESS) {
|
if (result != R_SUCCESS) {
|
||||||
warning("Couldn't get resource file context");
|
error("Couldn't get resource file context");
|
||||||
return R_FAILURE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
result = RSC_LoadResource(s_lut_ctxt, ITE_SCRIPT_LUT, &rsc_ptr, &rsc_len);
|
result = RSC_LoadResource(s_lut_ctxt, ITE_SCRIPT_LUT, &rsc_ptr, &rsc_len);
|
||||||
if (result != R_SUCCESS) {
|
if (result != R_SUCCESS) {
|
||||||
warning("Error: Couldn't load script resource look-up table");
|
error("Error: Couldn't load script resource look-up table");
|
||||||
return R_FAILURE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create logical script LUT from resource
|
// Create logical script LUT from resource
|
||||||
if (rsc_len % R_S_LUT_ENTRYLEN_ITECD == 0) {
|
if (rsc_len % R_S_LUT_ENTRYLEN_ITECD == 0) {
|
||||||
ScriptModule.script_lut_entrylen = R_S_LUT_ENTRYLEN_ITECD;
|
_script_lut_entrylen = R_S_LUT_ENTRYLEN_ITECD;
|
||||||
} else if (rsc_len % R_S_LUT_ENTRYLEN_ITEDISK == 0) {
|
} else if (rsc_len % R_S_LUT_ENTRYLEN_ITEDISK == 0) {
|
||||||
ScriptModule.script_lut_entrylen = R_S_LUT_ENTRYLEN_ITEDISK;
|
_script_lut_entrylen = R_S_LUT_ENTRYLEN_ITEDISK;
|
||||||
} else {
|
} else {
|
||||||
warning("Error: Invalid script lookup table length");
|
error("Error: Invalid script lookup table length");
|
||||||
return R_FAILURE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate number of entries
|
// Calculate number of entries
|
||||||
ScriptModule.script_lut_max = rsc_len / ScriptModule.script_lut_entrylen;
|
_script_lut_max = rsc_len / _script_lut_entrylen;
|
||||||
|
|
||||||
// Allocate space for logical LUT
|
// Allocate space for logical LUT
|
||||||
ScriptModule.script_lut = (R_SCRIPT_LUT_ENTRY *)malloc(ScriptModule.script_lut_max * sizeof(R_SCRIPT_LUT_ENTRY));
|
_script_lut = (R_SCRIPT_LUT_ENTRY *)malloc(_script_lut_max * sizeof(R_SCRIPT_LUT_ENTRY));
|
||||||
if (ScriptModule.script_lut == NULL) {
|
if (_script_lut == NULL) {
|
||||||
warning("Error: Couldn't allocate memory for script resource look-up table");
|
error("Error: Couldn't allocate memory for script resource look-up table");
|
||||||
return R_MEM;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert LUT resource to logical LUT
|
// Convert LUT resource to logical LUT
|
||||||
MemoryReadStream *readS = new MemoryReadStream(rsc_ptr, rsc_len);
|
MemoryReadStream *readS = new MemoryReadStream(rsc_ptr, rsc_len);
|
||||||
for (i = 0; i < ScriptModule.script_lut_max; i++) {
|
for (i = 0; i < _script_lut_max; i++) {
|
||||||
prevTell = readS->pos();
|
prevTell = readS->pos();
|
||||||
ScriptModule.script_lut[i].script_rn = readS->readUint16LE();
|
_script_lut[i].script_rn = readS->readUint16LE();
|
||||||
ScriptModule.script_lut[i].diag_list_rn = readS->readUint16LE();
|
_script_lut[i].diag_list_rn = readS->readUint16LE();
|
||||||
ScriptModule.script_lut[i].voice_lut_rn = readS->readUint16LE();
|
_script_lut[i].voice_lut_rn = readS->readUint16LE();
|
||||||
// Skip the unused portion of the structure
|
// Skip the unused portion of the structure
|
||||||
for (j = readS->pos(); j < prevTell + ScriptModule.script_lut_entrylen; j++)
|
for (j = readS->pos(); j < prevTell + _script_lut_entrylen; j++)
|
||||||
readS->readByte();
|
readS->readByte();
|
||||||
}
|
}
|
||||||
|
|
||||||
RSC_FreeResource(rsc_ptr);
|
RSC_FreeResource(rsc_ptr);
|
||||||
|
|
||||||
// Any voice lookup table resources present?
|
// Any voice lookup table resources present?
|
||||||
for (i = 0; i < ScriptModule.script_lut_max; i++) {
|
for (i = 0; i < _script_lut_max; i++) {
|
||||||
if (ScriptModule.script_lut[i].voice_lut_rn) {
|
if (_script_lut[i].voice_lut_rn) {
|
||||||
ScriptModule.voice_lut_present = 1;
|
_voice_lut_present = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize script submodules
|
// Initialize script submodules
|
||||||
ScriptModule.thread_list = ys_dll_create();
|
_thread_list = ys_dll_create();
|
||||||
|
|
||||||
ScriptModule.initialized = 1;
|
_initialized = 1;
|
||||||
return R_SUCCESS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shut down script module gracefully; free all allocated module resources
|
// Shut down script module gracefully; free all allocated module resources
|
||||||
int SCRIPT_Shutdown() {
|
Script::~Script() {
|
||||||
YS_DL_NODE *thread_node;
|
YS_DL_NODE *thread_node;
|
||||||
R_SCRIPT_THREAD *thread;
|
R_SCRIPT_THREAD *thread;
|
||||||
|
|
||||||
if (!ScriptModule.initialized) {
|
if (!_initialized) {
|
||||||
return R_FAILURE;
|
error("Script not initialized");
|
||||||
}
|
}
|
||||||
|
|
||||||
debug(0, "Shutting down scripting subsystem.");
|
debug(0, "Shutting down scripting subsystem.");
|
||||||
|
|
||||||
// Free script lookup table
|
// Free script lookup table
|
||||||
free(ScriptModule.script_lut);
|
free(_script_lut);
|
||||||
|
|
||||||
// Stop all threads and destroy them
|
// Stop all threads and destroy them
|
||||||
|
|
||||||
for (thread_node = ys_dll_head(ScriptModule.thread_list); thread_node != NULL;
|
for (thread_node = ys_dll_head(_thread_list); thread_node != NULL;
|
||||||
thread_node = ys_dll_next(thread_node)) {
|
thread_node = ys_dll_next(thread_node)) {
|
||||||
thread = (R_SCRIPT_THREAD *)ys_dll_get_data(thread_node);
|
thread = (R_SCRIPT_THREAD *)ys_dll_get_data(thread_node);
|
||||||
STHREAD_Destroy(thread);
|
STHREAD_Destroy(thread);
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptModule.initialized = 0;
|
_initialized = 0;
|
||||||
|
|
||||||
return R_SUCCESS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Loads a script; including script bytecode and dialogue list
|
// Loads a script; including script bytecode and dialogue list
|
||||||
int SCRIPT_Load(int script_num) {
|
int Script::loadScript(int script_num) {
|
||||||
R_SCRIPTDATA *script_data;
|
R_SCRIPTDATA *script_data;
|
||||||
byte *bytecode_p;
|
byte *bytecode_p;
|
||||||
size_t bytecode_len;
|
size_t bytecode_len;
|
||||||
@ -175,13 +180,13 @@ int SCRIPT_Load(int script_num) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Validate script number
|
// Validate script number
|
||||||
if ((script_num < 0) || (script_num > ScriptModule.script_lut_max)) {
|
if ((script_num < 0) || (script_num > _script_lut_max)) {
|
||||||
warning("SCRIPT_Load(): Invalid script number");
|
warning("Script::loadScript(): Invalid script number");
|
||||||
return R_FAILURE;
|
return R_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Release old script data if present
|
// Release old script data if present
|
||||||
SCRIPT_Free();
|
freeScript();
|
||||||
|
|
||||||
// Initialize script data structure
|
// Initialize script data structure
|
||||||
debug(0, "Loading script data for script #%d", script_num);
|
debug(0, "Loading script data for script #%d", script_num);
|
||||||
@ -200,16 +205,16 @@ int SCRIPT_Load(int script_num) {
|
|||||||
script_data->voice = NULL;
|
script_data->voice = NULL;
|
||||||
|
|
||||||
// Load script bytecode
|
// Load script bytecode
|
||||||
scriptl_rn = ScriptModule.script_lut[script_num].script_rn;
|
scriptl_rn = _script_lut[script_num].script_rn;
|
||||||
|
|
||||||
result = RSC_LoadResource(ScriptModule.script_ctxt, scriptl_rn, &bytecode_p, &bytecode_len);
|
result = RSC_LoadResource(_script_ctxt, scriptl_rn, &bytecode_p, &bytecode_len);
|
||||||
if (result != R_SUCCESS) {
|
if (result != R_SUCCESS) {
|
||||||
warning("Error loading script bytecode resource");
|
warning("Error loading script bytecode resource");
|
||||||
free(script_data);
|
free(script_data);
|
||||||
return R_FAILURE;
|
return R_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
script_data->bytecode = SCRIPT_LoadBytecode(bytecode_p, bytecode_len);
|
script_data->bytecode = loadBytecode(bytecode_p, bytecode_len);
|
||||||
|
|
||||||
if (script_data->bytecode == NULL) {
|
if (script_data->bytecode == NULL) {
|
||||||
warning("Error interpreting script bytecode resource");
|
warning("Error interpreting script bytecode resource");
|
||||||
@ -219,10 +224,10 @@ int SCRIPT_Load(int script_num) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Load script dialogue list
|
// Load script dialogue list
|
||||||
diagl_rn = ScriptModule.script_lut[script_num].diag_list_rn;
|
diagl_rn = _script_lut[script_num].diag_list_rn;
|
||||||
|
|
||||||
// Load dialogue list resource
|
// Load dialogue list resource
|
||||||
result = RSC_LoadResource(ScriptModule.script_ctxt, diagl_rn, &diagl_p, &diagl_len);
|
result = RSC_LoadResource(_script_ctxt, diagl_rn, &diagl_p, &diagl_len);
|
||||||
if (result != R_SUCCESS) {
|
if (result != R_SUCCESS) {
|
||||||
warning("Error loading dialogue list resource");
|
warning("Error loading dialogue list resource");
|
||||||
free(script_data);
|
free(script_data);
|
||||||
@ -231,7 +236,7 @@ int SCRIPT_Load(int script_num) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Convert dialogue list resource to logical dialogue list
|
// Convert dialogue list resource to logical dialogue list
|
||||||
script_data->diag = SCRIPT_LoadDialogue(diagl_p, diagl_len);
|
script_data->diag = loadDialogue(diagl_p, diagl_len);
|
||||||
if (script_data->diag == NULL) {
|
if (script_data->diag == NULL) {
|
||||||
warning("Error interpreting dialogue list resource");
|
warning("Error interpreting dialogue list resource");
|
||||||
free(script_data);
|
free(script_data);
|
||||||
@ -241,11 +246,11 @@ int SCRIPT_Load(int script_num) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Load voice resource lookup table
|
// Load voice resource lookup table
|
||||||
if (ScriptModule.voice_lut_present) {
|
if (_voice_lut_present) {
|
||||||
voicelut_rn = ScriptModule.script_lut[script_num].voice_lut_rn;
|
voicelut_rn = _script_lut[script_num].voice_lut_rn;
|
||||||
|
|
||||||
// Load voice LUT resource
|
// Load voice LUT resource
|
||||||
result = RSC_LoadResource(ScriptModule.script_ctxt, voicelut_rn, &voicelut_p, &voicelut_len);
|
result = RSC_LoadResource(_script_ctxt, voicelut_rn, &voicelut_p, &voicelut_len);
|
||||||
if (result != R_SUCCESS) {
|
if (result != R_SUCCESS) {
|
||||||
warning("Error loading voice LUT resource");
|
warning("Error loading voice LUT resource");
|
||||||
free(script_data);
|
free(script_data);
|
||||||
@ -255,7 +260,7 @@ int SCRIPT_Load(int script_num) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Convert voice LUT resource to logical voice LUT
|
// Convert voice LUT resource to logical voice LUT
|
||||||
script_data->voice = SCRIPT_LoadVoiceLUT(voicelut_p, voicelut_len, script_data);
|
script_data->voice = loadVoiceLUT(voicelut_p, voicelut_len, script_data);
|
||||||
if (script_data->voice == NULL) {
|
if (script_data->voice == NULL) {
|
||||||
warning("Error interpreting voice LUT resource");
|
warning("Error interpreting voice LUT resource");
|
||||||
free(script_data);
|
free(script_data);
|
||||||
@ -268,52 +273,52 @@ int SCRIPT_Load(int script_num) {
|
|||||||
|
|
||||||
// Finish initialization
|
// Finish initialization
|
||||||
script_data->loaded = 1;
|
script_data->loaded = 1;
|
||||||
ScriptModule.current_script = script_data;
|
_current_script = script_data;
|
||||||
|
|
||||||
return R_SUCCESS;
|
return R_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Frees all resources associated with current script.
|
// Frees all resources associated with current script.
|
||||||
int SCRIPT_Free() {
|
int Script::freeScript() {
|
||||||
if (ScriptModule.current_script == NULL) {
|
if (_current_script == NULL) {
|
||||||
return R_FAILURE;
|
return R_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ScriptModule.current_script->loaded) {
|
if (!_current_script->loaded) {
|
||||||
return R_FAILURE;
|
return R_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
debug(0, "Releasing script data.");
|
debug(0, "Releasing script data.");
|
||||||
|
|
||||||
// Finish initialization
|
// Finish initialization
|
||||||
if (ScriptModule.current_script->diag != NULL) {
|
if (_current_script->diag != NULL) {
|
||||||
free(ScriptModule.current_script->diag->str);
|
free(_current_script->diag->str);
|
||||||
free(ScriptModule.current_script->diag->str_off);
|
free(_current_script->diag->str_off);
|
||||||
}
|
}
|
||||||
free(ScriptModule.current_script->diag);
|
free(_current_script->diag);
|
||||||
|
|
||||||
if (ScriptModule.current_script->bytecode != NULL) {
|
if (_current_script->bytecode != NULL) {
|
||||||
free(ScriptModule.current_script->bytecode->entrypoints);
|
free(_current_script->bytecode->entrypoints);
|
||||||
RSC_FreeResource(ScriptModule.current_script->bytecode->bytecode_p);
|
RSC_FreeResource(_current_script->bytecode->bytecode_p);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(ScriptModule.current_script->bytecode);
|
free(_current_script->bytecode);
|
||||||
|
|
||||||
if (ScriptModule.voice_lut_present) {
|
if (_voice_lut_present) {
|
||||||
free(ScriptModule.current_script->voice->voices);
|
free(_current_script->voice->voices);
|
||||||
free(ScriptModule.current_script->voice);
|
free(_current_script->voice);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(ScriptModule.current_script);
|
free(_current_script);
|
||||||
|
|
||||||
ScriptModule.current_script = NULL;
|
_current_script = NULL;
|
||||||
|
|
||||||
return R_SUCCESS;
|
return R_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reads the entrypoint table from a script bytecode resource in memory.
|
// Reads the entrypoint table from a script bytecode resource in memory.
|
||||||
// Returns NULL on failure.
|
// Returns NULL on failure.
|
||||||
R_SCRIPT_BYTECODE *SCRIPT_LoadBytecode(byte *bytecode_p, size_t bytecode_len) {
|
R_SCRIPT_BYTECODE *Script::loadBytecode(byte *bytecode_p, size_t bytecode_len) {
|
||||||
R_PROC_TBLENTRY *bc_ep_tbl = NULL;
|
R_PROC_TBLENTRY *bc_ep_tbl = NULL;
|
||||||
R_SCRIPT_BYTECODE *bc_new_data = NULL;
|
R_SCRIPT_BYTECODE *bc_new_data = NULL;
|
||||||
|
|
||||||
@ -390,7 +395,7 @@ R_SCRIPT_BYTECODE *SCRIPT_LoadBytecode(byte *bytecode_p, size_t bytecode_len) {
|
|||||||
|
|
||||||
// Reads a logical dialogue list from a dialogue list resource in memory.
|
// Reads a logical dialogue list from a dialogue list resource in memory.
|
||||||
// Returns NULL on failure.
|
// Returns NULL on failure.
|
||||||
R_DIALOGUE_LIST *SCRIPT_LoadDialogue(const byte *dialogue_p, size_t dialogue_len) {
|
R_DIALOGUE_LIST *Script::loadDialogue(const byte *dialogue_p, size_t dialogue_len) {
|
||||||
R_DIALOGUE_LIST *dialogue_list;
|
R_DIALOGUE_LIST *dialogue_list;
|
||||||
uint16 n_dialogue;
|
uint16 n_dialogue;
|
||||||
uint16 i;
|
uint16 i;
|
||||||
@ -452,7 +457,7 @@ R_DIALOGUE_LIST *SCRIPT_LoadDialogue(const byte *dialogue_p, size_t dialogue_len
|
|||||||
|
|
||||||
// Reads a logical voice LUT from a voice LUT resource in memory.
|
// Reads a logical voice LUT from a voice LUT resource in memory.
|
||||||
// Returns NULL on failure.
|
// Returns NULL on failure.
|
||||||
R_VOICE_LUT *SCRIPT_LoadVoiceLUT(const byte *voicelut_p, size_t voicelut_len, R_SCRIPTDATA *script) {
|
R_VOICE_LUT *Script::loadVoiceLUT(const byte *voicelut_p, size_t voicelut_len, R_SCRIPTDATA *script) {
|
||||||
R_VOICE_LUT *voice_lut;
|
R_VOICE_LUT *voice_lut;
|
||||||
|
|
||||||
uint16 n_voices;
|
uint16 n_voices;
|
||||||
@ -489,21 +494,21 @@ void CF_script_info(int argc, char *argv[], void *refCon) {
|
|||||||
uint32 i;
|
uint32 i;
|
||||||
char *name_ptr;
|
char *name_ptr;
|
||||||
|
|
||||||
if (ScriptModule.current_script == NULL) {
|
if (((Script *)refCon)->_current_script == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ScriptModule.current_script->loaded) {
|
if (!((Script *)refCon)->_current_script->loaded) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
n_entrypoints = ScriptModule.current_script->bytecode->n_entrypoints;
|
n_entrypoints = ((Script *)refCon)->_current_script->bytecode->n_entrypoints;
|
||||||
|
|
||||||
CON_Print("Current script contains %d entrypoints:", n_entrypoints);
|
CON_Print("Current script contains %d entrypoints:", n_entrypoints);
|
||||||
|
|
||||||
for (i = 0; i < n_entrypoints; i++) {
|
for (i = 0; i < n_entrypoints; i++) {
|
||||||
name_ptr = (char *)ScriptModule.current_script->bytecode->bytecode_p +
|
name_ptr = (char *)((Script *)refCon)->_current_script->bytecode->bytecode_p +
|
||||||
ScriptModule.current_script->bytecode->entrypoints[i].name_offset;
|
((Script *)refCon)->_current_script->bytecode->entrypoints[i].name_offset;
|
||||||
CON_Print("%lu: %s", i, name_ptr);
|
CON_Print("%lu: %s", i, name_ptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -517,25 +522,25 @@ void CF_script_exec(int argc, char *argv[], void *refCon) {
|
|||||||
|
|
||||||
ep_num = atoi(argv[0]);
|
ep_num = atoi(argv[0]);
|
||||||
|
|
||||||
if (ScriptModule.dbg_thread == NULL) {
|
if (((Script *)refCon)->_dbg_thread == NULL) {
|
||||||
CON_Print("Creating debug thread...");
|
CON_Print("Creating debug thread...");
|
||||||
ScriptModule.dbg_thread = STHREAD_Create();
|
((Script *)refCon)->_dbg_thread = STHREAD_Create();
|
||||||
if (ScriptModule.dbg_thread == NULL) {
|
if (((Script *)refCon)->_dbg_thread == NULL) {
|
||||||
CON_Print("Thread creation failed.");
|
CON_Print("Thread creation failed.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ep_num >= ScriptModule.current_script->bytecode->n_entrypoints) {
|
if (ep_num >= ((Script *)refCon)->_current_script->bytecode->n_entrypoints) {
|
||||||
CON_Print("Invalid entrypoint.");
|
CON_Print("Invalid entrypoint.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
STHREAD_Execute(ScriptModule.dbg_thread, ep_num);
|
STHREAD_Execute(((Script *)refCon)->_dbg_thread, ep_num);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CF_script_togglestep(int argc, char *argv[], void *refCon) {
|
void CF_script_togglestep(int argc, char *argv[], void *refCon) {
|
||||||
ScriptModule.dbg_singlestep = !ScriptModule.dbg_singlestep;
|
((Script *)refCon)->_dbg_singlestep = !((Script *)refCon)->_dbg_singlestep;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // End of namespace Saga
|
} // End of namespace Saga
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
|
|
||||||
#include "sstack.h"
|
#include "sstack.h"
|
||||||
#include "sdata.h"
|
#include "sdata.h"
|
||||||
|
#include "text_mod.h"
|
||||||
#include "yslib.h"
|
#include "yslib.h"
|
||||||
|
|
||||||
namespace Saga {
|
namespace Saga {
|
||||||
@ -89,32 +90,38 @@ struct R_SCRIPT_DATABUF {
|
|||||||
int len;
|
int len;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct R_SCRIPT_MODULE {
|
|
||||||
int initialized;
|
class Script {
|
||||||
R_RSCFILE_CONTEXT *script_ctxt;
|
public:
|
||||||
int voice_lut_present;
|
Script();
|
||||||
R_SCRIPT_LUT_ENTRY *script_lut;
|
~Script();
|
||||||
int script_lut_max;
|
|
||||||
uint16 script_lut_entrylen;
|
int reg(void);
|
||||||
R_SCRIPTDATA *current_script;
|
int loadScript(int scriptNum);
|
||||||
YS_DL_LIST *thread_list;
|
int freeScript();
|
||||||
R_SCRIPT_DATABUF *data_buf[R_SCRIPT_DATABUF_NUM];
|
R_SCRIPT_BYTECODE *loadBytecode(byte *bytecode_p, size_t bytecode_len);
|
||||||
int dbg_singlestep;
|
R_DIALOGUE_LIST *loadDialogue(const byte *dialogue_p, size_t dialogue_len);
|
||||||
int dbg_dostep;
|
R_VOICE_LUT *loadVoiceLUT(const byte *voicelut_p, size_t voicelut_len, R_SCRIPTDATA *script);
|
||||||
R_SCRIPT_THREAD *dbg_thread;
|
int disassemble(R_SCRIPT_BYTECODE *script_list, R_DIALOGUE_LIST *diag_list);
|
||||||
R_TEXTLIST_ENTRY *dbg_txtentry;
|
|
||||||
|
|
||||||
|
//protected:
|
||||||
|
//these are temporarily public, eventually get/set methods should be created for them
|
||||||
|
int _initialized;
|
||||||
|
R_RSCFILE_CONTEXT *_script_ctxt;
|
||||||
|
int _voice_lut_present;
|
||||||
|
R_SCRIPT_LUT_ENTRY *_script_lut;
|
||||||
|
int _script_lut_max;
|
||||||
|
uint16 _script_lut_entrylen;
|
||||||
|
R_SCRIPTDATA *_current_script;
|
||||||
|
YS_DL_LIST *_thread_list;
|
||||||
|
R_SCRIPT_DATABUF *_data_buf[R_SCRIPT_DATABUF_NUM];
|
||||||
|
int _dbg_singlestep;
|
||||||
|
int _dbg_dostep;
|
||||||
|
R_SCRIPT_THREAD *_dbg_thread;
|
||||||
|
R_TEXTLIST_ENTRY *_dbg_txtentry;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern R_SCRIPT_MODULE ScriptModule;
|
|
||||||
|
|
||||||
R_SCRIPT_BYTECODE *SCRIPT_LoadBytecode(byte *bytecode_p, size_t bytecode_len);
|
|
||||||
R_DIALOGUE_LIST *SCRIPT_LoadDialogue(const byte *dialogue_p, size_t dialogue_len);
|
|
||||||
R_VOICE_LUT *SCRIPT_LoadVoiceLUT(const byte *voicelut_p, size_t voicelut_len, R_SCRIPTDATA *script);
|
|
||||||
int SCRIPT_Disassemble(R_SCRIPT_BYTECODE *script_list, R_DIALOGUE_LIST *diag_list);
|
|
||||||
void CF_script_info(int argc, char *argv[], void *refCon);
|
|
||||||
void CF_script_exec(int argc, char *argv[], void *refCon);
|
|
||||||
void CF_script_togglestep(int argc, char *argv[], void *refCon);
|
|
||||||
|
|
||||||
} // End of namespace Saga
|
} // End of namespace Saga
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -43,11 +43,6 @@ enum R_SCRIPT_VERBS {
|
|||||||
S_VERB_GIVE
|
S_VERB_GIVE
|
||||||
};
|
};
|
||||||
|
|
||||||
int SCRIPT_Register();
|
|
||||||
int SCRIPT_Init();
|
|
||||||
int SCRIPT_Shutdown();
|
|
||||||
int SCRIPT_Load(int script_num);
|
|
||||||
int SCRIPT_Free();
|
|
||||||
R_SCRIPT_THREAD *STHREAD_Create();
|
R_SCRIPT_THREAD *STHREAD_Create();
|
||||||
int STHREAD_Execute(R_SCRIPT_THREAD *thread, int ep_num);
|
int STHREAD_Execute(R_SCRIPT_THREAD *thread, int ep_num);
|
||||||
int STHREAD_ExecThreads(int msec);
|
int STHREAD_ExecThreads(int msec);
|
||||||
|
@ -37,20 +37,20 @@ SData::SData() {
|
|||||||
|
|
||||||
debug(0, "Initializing script data buffers");
|
debug(0, "Initializing script data buffers");
|
||||||
for (i = 0; i < R_SCRIPT_DATABUF_NUM; i++) {
|
for (i = 0; i < R_SCRIPT_DATABUF_NUM; i++) {
|
||||||
alloc_ptr = malloc(sizeof *ScriptModule.data_buf[0]);
|
alloc_ptr = malloc(sizeof *_vm->_script->_data_buf[0]);
|
||||||
if (alloc_ptr == NULL) {
|
if (alloc_ptr == NULL) {
|
||||||
error("Couldn't allocate memory for script data buffer %d", i);
|
error("Couldn't allocate memory for script data buffer %d", i);
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptModule.data_buf[i] = (R_SCRIPT_DATABUF *)alloc_ptr;
|
_vm->_script->_data_buf[i] = (R_SCRIPT_DATABUF *)alloc_ptr;
|
||||||
alloc_ptr = calloc(R_SCRIPT_DATABUF_LEN, sizeof(SDataWord_T));
|
alloc_ptr = calloc(R_SCRIPT_DATABUF_LEN, sizeof(SDataWord_T));
|
||||||
|
|
||||||
if (alloc_ptr == NULL) {
|
if (alloc_ptr == NULL) {
|
||||||
error("Couldn't allocate memory for script data buffer %d", i);
|
error("Couldn't allocate memory for script data buffer %d", i);
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptModule.data_buf[i]->len = R_SCRIPT_DATABUF_LEN;
|
_vm->_script->_data_buf[i]->len = R_SCRIPT_DATABUF_LEN;
|
||||||
ScriptModule.data_buf[i]->data = (SDataWord_T *)alloc_ptr;
|
_vm->_script->_data_buf[i]->data = (SDataWord_T *)alloc_ptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,7 +62,7 @@ int SData::getWord(int n_buf, int n_word, SDataWord_T *data) {
|
|||||||
return R_FAILURE;
|
return R_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((n_word < 0) || (n_word >= ScriptModule.data_buf[n_buf]->len)) {
|
if ((n_word < 0) || (n_word >= _vm->_script->_data_buf[n_buf]->len)) {
|
||||||
return R_FAILURE;
|
return R_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,7 +70,7 @@ int SData::getWord(int n_buf, int n_word, SDataWord_T *data) {
|
|||||||
return R_FAILURE;
|
return R_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
*data = ScriptModule.data_buf[n_buf]->data[n_word];
|
*data = _vm->_script->_data_buf[n_buf]->data[n_word];
|
||||||
|
|
||||||
return R_SUCCESS;
|
return R_SUCCESS;
|
||||||
}
|
}
|
||||||
@ -80,11 +80,11 @@ int SData::putWord(int n_buf, int n_word, SDataWord_T data) {
|
|||||||
return R_FAILURE;
|
return R_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((n_word < 0) || (n_word >= ScriptModule.data_buf[n_buf]->len)) {
|
if ((n_word < 0) || (n_word >= _vm->_script->_data_buf[n_buf]->len)) {
|
||||||
return R_FAILURE;
|
return R_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptModule.data_buf[n_buf]->data[n_word] = data;
|
_vm->_script->_data_buf[n_buf]->data[n_word] = data;
|
||||||
|
|
||||||
return R_SUCCESS;
|
return R_SUCCESS;
|
||||||
}
|
}
|
||||||
@ -99,7 +99,7 @@ int SData::setBit(int n_buf, SDataWord_T n_bit, int bitstate) {
|
|||||||
return R_FAILURE;
|
return R_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (n_bit >= (unsigned long)ScriptModule.data_buf[n_buf]->len * (sizeof(SDataWord_T) * CHAR_BIT)) {
|
if (n_bit >= (unsigned long)_vm->_script->_data_buf[n_buf]->len * (sizeof(SDataWord_T) * CHAR_BIT)) {
|
||||||
return R_FAILURE;
|
return R_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,9 +109,9 @@ int SData::setBit(int n_buf, SDataWord_T n_bit, int bitstate) {
|
|||||||
bit_pattern <<= ((sizeof(SDataWord_T) * CHAR_BIT) - (n_bitpos + 1));
|
bit_pattern <<= ((sizeof(SDataWord_T) * CHAR_BIT) - (n_bitpos + 1));
|
||||||
|
|
||||||
if (bitstate) {
|
if (bitstate) {
|
||||||
ScriptModule.data_buf[n_buf]->data[n_word] |= bit_pattern;
|
_vm->_script->_data_buf[n_buf]->data[n_word] |= bit_pattern;
|
||||||
} else {
|
} else {
|
||||||
ScriptModule.data_buf[n_buf]->data[n_word] &= ~bit_pattern;
|
_vm->_script->_data_buf[n_buf]->data[n_word] &= ~bit_pattern;
|
||||||
}
|
}
|
||||||
|
|
||||||
return R_SUCCESS;
|
return R_SUCCESS;
|
||||||
@ -127,7 +127,7 @@ int SData::getBit(int n_buf, SDataWord_T n_bit, int *bitstate) {
|
|||||||
return R_FAILURE;
|
return R_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (n_bit >= (SDataWord_T) ScriptModule.data_buf[n_buf]->len * (sizeof(SDataWord_T) * CHAR_BIT)) {
|
if (n_bit >= (SDataWord_T) _vm->_script->_data_buf[n_buf]->len * (sizeof(SDataWord_T) * CHAR_BIT)) {
|
||||||
return R_FAILURE;
|
return R_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,7 +136,7 @@ int SData::getBit(int n_buf, SDataWord_T n_bit, int *bitstate) {
|
|||||||
|
|
||||||
bit_pattern <<= ((sizeof(SDataWord_T) * CHAR_BIT) - (n_bitpos + 1));
|
bit_pattern <<= ((sizeof(SDataWord_T) * CHAR_BIT) - (n_bitpos + 1));
|
||||||
|
|
||||||
*bitstate = (ScriptModule.data_buf[n_buf]->data[n_word] & bit_pattern) ? 1 : 0;
|
*bitstate = (_vm->_script->_data_buf[n_buf]->data[n_word] & bit_pattern) ? 1 : 0;
|
||||||
|
|
||||||
return R_SUCCESS;
|
return R_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -53,9 +53,9 @@ int SDEBUG_PrintInstr(R_SCRIPT_THREAD *thread) {
|
|||||||
|
|
||||||
disp_buf[0] = 0;
|
disp_buf[0] = 0;
|
||||||
|
|
||||||
if (ScriptModule.dbg_txtentry != NULL) {
|
if (_vm->_script->_dbg_txtentry != NULL) {
|
||||||
TEXT_DeleteEntry(si.text_list, ScriptModule.dbg_txtentry);
|
TEXT_DeleteEntry(si.text_list, _vm->_script->_dbg_txtentry);
|
||||||
ScriptModule.dbg_txtentry = NULL;
|
_vm->_script->_dbg_txtentry = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
tl_e.color = 1;
|
tl_e.color = 1;
|
||||||
@ -69,9 +69,9 @@ int SDEBUG_PrintInstr(R_SCRIPT_THREAD *thread) {
|
|||||||
|
|
||||||
// XXX
|
// XXX
|
||||||
MemoryReadStream *readS =
|
MemoryReadStream *readS =
|
||||||
new MemoryReadStream(ScriptModule.current_script->bytecode->bytecode_p
|
new MemoryReadStream(_vm->_script->_current_script->bytecode->bytecode_p
|
||||||
+ thread->i_offset,
|
+ thread->i_offset,
|
||||||
ScriptModule.current_script->bytecode->bytecode_len
|
_vm->_script->_current_script->bytecode->bytecode_len
|
||||||
- thread->i_offset);
|
- thread->i_offset);
|
||||||
in_char = readS->readByte();
|
in_char = readS->readByte();
|
||||||
sprintf(tmp_buf, "%04lX | %02X | ", thread->i_offset, in_char);
|
sprintf(tmp_buf, "%04lX | %02X | ", thread->i_offset, in_char);
|
||||||
@ -517,8 +517,8 @@ int SDEBUG_PrintInstr(R_SCRIPT_THREAD *thread) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptModule.dbg_txtentry = TEXT_AddEntry(si.text_list, &tl_e);
|
_vm->_script->_dbg_txtentry = TEXT_AddEntry(si.text_list, &tl_e);
|
||||||
TEXT_SetDisplay(ScriptModule.dbg_txtentry, 1);
|
TEXT_SetDisplay(_vm->_script->_dbg_txtentry, 1);
|
||||||
|
|
||||||
return R_SUCCESS;
|
return R_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ R_SCRIPT_THREAD *STHREAD_Create() {
|
|||||||
|
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
if (!ScriptModule.initialized) {
|
if (!_vm->_script->_initialized) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,7 +62,7 @@ R_SCRIPT_THREAD *STHREAD_Create() {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
new_node = ys_dll_add_head(ScriptModule.thread_list, new_thread, sizeof *new_thread);
|
new_node = ys_dll_add_head(_vm->_script->_thread_list, new_thread, sizeof *new_thread);
|
||||||
|
|
||||||
free(new_thread);
|
free(new_thread);
|
||||||
|
|
||||||
@ -83,11 +83,11 @@ int STHREAD_ExecThreads(int msec) {
|
|||||||
YS_DL_NODE *walk_p;
|
YS_DL_NODE *walk_p;
|
||||||
R_SCRIPT_THREAD *thread;
|
R_SCRIPT_THREAD *thread;
|
||||||
|
|
||||||
if (!ScriptModule.initialized) {
|
if (!_vm->_script->_initialized) {
|
||||||
return R_FAILURE;
|
return R_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (walk_p = ys_dll_head(ScriptModule.thread_list); walk_p != NULL; walk_p = ys_dll_next(walk_p)) {
|
for (walk_p = ys_dll_head(_vm->_script->_thread_list); walk_p != NULL; walk_p = ys_dll_next(walk_p)) {
|
||||||
thread = (R_SCRIPT_THREAD *)ys_dll_get_data(walk_p);
|
thread = (R_SCRIPT_THREAD *)ys_dll_get_data(walk_p);
|
||||||
if (thread->executing) {
|
if (thread->executing) {
|
||||||
STHREAD_Run(thread, STHREAD_DEF_INSTR_COUNT, msec);
|
STHREAD_Run(thread, STHREAD_DEF_INSTR_COUNT, msec);
|
||||||
@ -101,9 +101,9 @@ int STHREAD_SetEntrypoint(R_SCRIPT_THREAD *thread, int ep_num) {
|
|||||||
R_SCRIPT_BYTECODE *bytecode;
|
R_SCRIPT_BYTECODE *bytecode;
|
||||||
int max_entrypoint;
|
int max_entrypoint;
|
||||||
|
|
||||||
assert(ScriptModule.initialized);
|
assert(_vm->_script->_initialized);
|
||||||
|
|
||||||
bytecode = ScriptModule.current_script->bytecode;
|
bytecode = _vm->_script->_current_script->bytecode;
|
||||||
max_entrypoint = bytecode->n_entrypoints;
|
max_entrypoint = bytecode->n_entrypoints;
|
||||||
|
|
||||||
if ((ep_num < 0) || (ep_num >= max_entrypoint)) {
|
if ((ep_num < 0) || (ep_num >= max_entrypoint)) {
|
||||||
@ -117,9 +117,9 @@ int STHREAD_SetEntrypoint(R_SCRIPT_THREAD *thread, int ep_num) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int STHREAD_Execute(R_SCRIPT_THREAD *thread, int ep_num) {
|
int STHREAD_Execute(R_SCRIPT_THREAD *thread, int ep_num) {
|
||||||
assert(ScriptModule.initialized);
|
assert(_vm->_script->_initialized);
|
||||||
|
|
||||||
if ((ScriptModule.current_script == NULL) || (!ScriptModule.current_script->loaded)) {
|
if ((_vm->_script->_current_script == NULL) || (!_vm->_script->_current_script->loaded)) {
|
||||||
return R_FAILURE;
|
return R_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,15 +132,15 @@ int STHREAD_Execute(R_SCRIPT_THREAD *thread, int ep_num) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
unsigned char *GetReadPtr(R_SCRIPT_THREAD *thread) {
|
unsigned char *GetReadPtr(R_SCRIPT_THREAD *thread) {
|
||||||
return ScriptModule.current_script->bytecode->bytecode_p + thread->i_offset;
|
return _vm->_script->_current_script->bytecode->bytecode_p + thread->i_offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long GetReadOffset(const byte *read_p) {
|
unsigned long GetReadOffset(const byte *read_p) {
|
||||||
return (unsigned long)(read_p - (unsigned char *)ScriptModule.current_script->bytecode->bytecode_p);
|
return (unsigned long)(read_p - (unsigned char *)_vm->_script->_current_script->bytecode->bytecode_p);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t GetReadLen(R_SCRIPT_THREAD *thread) {
|
size_t GetReadLen(R_SCRIPT_THREAD *thread) {
|
||||||
return ScriptModule.current_script->bytecode->bytecode_len - thread->i_offset;
|
return _vm->_script->_current_script->bytecode->bytecode_len - thread->i_offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -168,8 +168,8 @@ int STHREAD_ReleaseSem(R_SEMAPHORE *sem) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int STHREAD_DebugStep() {
|
int STHREAD_DebugStep() {
|
||||||
if (ScriptModule.dbg_singlestep) {
|
if (_vm->_script->_dbg_singlestep) {
|
||||||
ScriptModule.dbg_dostep = 1;
|
_vm->_script->_dbg_dostep = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return R_SUCCESS;
|
return R_SUCCESS;
|
||||||
@ -194,12 +194,12 @@ int STHREAD_Run(R_SCRIPT_THREAD *thread, int instr_limit, int msec) {
|
|||||||
int unhandled = 0;
|
int unhandled = 0;
|
||||||
|
|
||||||
// Handle debug single-stepping
|
// Handle debug single-stepping
|
||||||
if ((thread == ScriptModule.dbg_thread) && ScriptModule.dbg_singlestep) {
|
if ((thread == _vm->_script->_dbg_thread) && _vm->_script->_dbg_singlestep) {
|
||||||
if (ScriptModule.dbg_dostep) {
|
if (_vm->_script->_dbg_dostep) {
|
||||||
debug_print = 1;
|
debug_print = 1;
|
||||||
thread->sleep_time = 0;
|
thread->sleep_time = 0;
|
||||||
instr_limit = 1;
|
instr_limit = 1;
|
||||||
ScriptModule.dbg_dostep = 0;
|
_vm->_script->_dbg_dostep = 0;
|
||||||
} else {
|
} else {
|
||||||
return R_SUCCESS;
|
return R_SUCCESS;
|
||||||
}
|
}
|
||||||
@ -730,12 +730,12 @@ int STHREAD_Run(R_SCRIPT_THREAD *thread, int instr_limit, int msec) {
|
|||||||
SSTACK_Pop(thread->stack, &data);
|
SSTACK_Pop(thread->stack, &data);
|
||||||
if (a_index < 0)
|
if (a_index < 0)
|
||||||
continue;
|
continue;
|
||||||
if (!ScriptModule.voice_lut_present) {
|
if (!_vm->_script->_voice_lut_present) {
|
||||||
voice_rn = -1;
|
voice_rn = -1;
|
||||||
} else {
|
} else {
|
||||||
voice_rn = ScriptModule.current_script->voice->voices[data];
|
voice_rn = _vm->_script->_current_script->voice->voices[data];
|
||||||
}
|
}
|
||||||
ACTOR_Speak(a_index, ScriptModule.current_script->diag-> str[data], voice_rn, &thread->sem);
|
ACTOR_Speak(a_index, _vm->_script->_current_script->diag-> str[data], voice_rn, &thread->sem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user