aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Horn2009-06-07 23:04:34 +0000
committerMax Horn2009-06-07 23:04:34 +0000
commit0dcb1fa84f095753013e01c80b9b80e7c7dd5a0d (patch)
tree786f0463fea84e290d951ef2ac8f5183601ff9a4
parent77bcc94f80b04ad9f4cade885a7f548335530bed (diff)
downloadscummvm-rg350-0dcb1fa84f095753013e01c80b9b80e7c7dd5a0d.tar.gz
scummvm-rg350-0dcb1fa84f095753013e01c80b9b80e7c7dd5a0d.tar.bz2
scummvm-rg350-0dcb1fa84f095753013e01c80b9b80e7c7dd5a0d.zip
SCI: Got rid of g_EngineState
svn-id: r41359
-rw-r--r--engines/sci/console.cpp380
-rw-r--r--engines/sci/engine/vm.cpp4
-rw-r--r--engines/sci/sci.h1
3 files changed, 190 insertions, 195 deletions
diff --git a/engines/sci/console.cpp b/engines/sci/console.cpp
index b7cf44a739..e98c0e0f95 100644
--- a/engines/sci/console.cpp
+++ b/engines/sci/console.cpp
@@ -46,8 +46,6 @@
namespace Sci {
-extern EngineState *g_EngineState;
-
int g_debug_sleeptime_factor = 1;
int g_debug_simulated_key = 0;
bool g_debug_track_mouse_clicks = false;
@@ -197,12 +195,12 @@ Console::~Console() {
}
void Console::preEnter() {
- g_EngineState->_sound.sfx_suspend(true);
+ _vm->_gamestate->_sound.sfx_suspend(true);
_vm->_mixer->pauseAll(true);
}
void Console::postEnter() {
- g_EngineState->_sound.sfx_suspend(false);
+ _vm->_gamestate->_sound.sfx_suspend(false);
_vm->_mixer->pauseAll(false);
}
@@ -369,8 +367,8 @@ bool Console::cmdGetVersion(int argc, const char **argv) {
bool Console::cmdOpcodes(int argc, const char **argv) {
DebugPrintf("Opcode names in numeric order [index: type name]:\n");
- for (uint seeker = 0; seeker < g_EngineState->_kernel->getOpcodesSize(); seeker++) {
- opcode op = g_EngineState->_kernel->getOpcode(seeker);
+ for (uint seeker = 0; seeker < _vm->_gamestate->_kernel->getOpcodesSize(); seeker++) {
+ opcode op = _vm->_gamestate->_kernel->getOpcode(seeker);
DebugPrintf("%03x: %03x %20s | ", seeker, op.type, op.name.c_str());
if ((seeker % 3) == 2)
DebugPrintf("\n");
@@ -383,8 +381,8 @@ bool Console::cmdOpcodes(int argc, const char **argv) {
bool Console::cmdSelectors(int argc, const char **argv) {
DebugPrintf("Selector names in numeric order:\n");
- for (uint seeker = 0; seeker < g_EngineState->_kernel->getSelectorNamesSize(); seeker++) {
- DebugPrintf("%03x: %20s | ", seeker, g_EngineState->_kernel->getSelectorName(seeker).c_str());
+ for (uint seeker = 0; seeker < _vm->_gamestate->_kernel->getSelectorNamesSize(); seeker++) {
+ DebugPrintf("%03x: %20s | ", seeker, _vm->_gamestate->_kernel->getSelectorName(seeker).c_str());
if ((seeker % 3) == 2)
DebugPrintf("\n");
}
@@ -396,8 +394,8 @@ bool Console::cmdSelectors(int argc, const char **argv) {
bool Console::cmdKernelFunctions(int argc, const char **argv) {
DebugPrintf("Kernel function names in numeric order:\n");
- for (uint seeker = 0; seeker < g_EngineState->_kernel->getKernelNamesSize(); seeker++) {
- DebugPrintf("%03x: %20s | ", seeker, g_EngineState->_kernel->getKernelName(seeker).c_str());
+ for (uint seeker = 0; seeker < _vm->_gamestate->_kernel->getKernelNamesSize(); seeker++) {
+ DebugPrintf("%03x: %20s | ", seeker, _vm->_gamestate->_kernel->getKernelName(seeker).c_str());
if ((seeker % 3) == 2)
DebugPrintf("\n");
}
@@ -408,13 +406,13 @@ bool Console::cmdKernelFunctions(int argc, const char **argv) {
}
bool Console::cmdSuffixes(int argc, const char **argv) {
- g_EngineState->_vocabulary->printSuffixes();
+ _vm->_gamestate->_vocabulary->printSuffixes();
return true;
}
bool Console::cmdParserWords(int argc, const char **argv) {
- g_EngineState->_vocabulary->printParserWords();
+ _vm->_gamestate->_vocabulary->printParserWords();
return true;
}
@@ -503,10 +501,10 @@ bool Console::cmdSetParseNodes(int argc, const char **argv) {
nextToken = kParseNumber;
}
- if (parseNodes(g_EngineState, &i, &pos, nextToken, nextValue, argc, argv) == -1)
+ if (parseNodes(_vm->_gamestate, &i, &pos, nextToken, nextValue, argc, argv) == -1)
return 1;
- vocab_dump_parse_tree("debug-parse-tree", g_EngineState->parser_nodes);
+ vocab_dump_parse_tree("debug-parse-tree", _vm->_gamestate->parser_nodes);
return true;
}
@@ -515,10 +513,10 @@ bool Console::cmdRegisters(int argc, const char **argv) {
DebugPrintf("Current register values:\n");
#if 0
// TODO: p_restadjust
- DebugPrintf("acc=%04x:%04x prev=%04x:%04x &rest=%x\n", PRINT_REG(g_EngineState->r_acc), PRINT_REG(g_EngineState->r_prev), *p_restadjust);
+ DebugPrintf("acc=%04x:%04x prev=%04x:%04x &rest=%x\n", PRINT_REG(_vm->_gamestate->r_acc), PRINT_REG(_vm->_gamestate->r_prev), *p_restadjust);
#endif
- if (!g_EngineState->_executionStack.empty()) {
+ if (!_vm->_gamestate->_executionStack.empty()) {
#if 0
// TODO: p_pc, p_objp, p_pp, p_sp
DebugPrintf("pc=%04x:%04x obj=%04x:%04x fp=ST:%04x sp=ST:%04x\n", PRINT_REG(*p_pc), PRINT_REG(*p_objp), PRINT_STK(*p_pp), PRINT_STK(*p_sp));
@@ -580,13 +578,13 @@ bool Console::cmdDissectScript(int argc, const char **argv) {
return true;
}
- g_EngineState->_kernel->dissectScript(atoi(argv[1]), g_EngineState->_vocabulary);
+ _vm->_gamestate->_kernel->dissectScript(atoi(argv[1]), _vm->_gamestate->_vocabulary);
return true;
}
bool Console::cmdRoomNumber(int argc, const char **argv) {
- DebugPrintf("Current room number is %d\n", g_EngineState->currentRoomNumber());
+ DebugPrintf("Current room number is %d\n", _vm->_gamestate->currentRoomNumber());
return true;
}
@@ -762,16 +760,16 @@ bool Console::cmdList(int argc, const char **argv) {
}
bool Console::cmdClearScreen(int argc, const char **argv) {
- gfxop_clear_box(g_EngineState->gfx_state, gfx_rect(0, 0, 320, 200));
- gfxop_update_box(g_EngineState->gfx_state, gfx_rect(0, 0, 320, 200));
+ gfxop_clear_box(_vm->_gamestate->gfx_state, gfx_rect(0, 0, 320, 200));
+ gfxop_update_box(_vm->_gamestate->gfx_state, gfx_rect(0, 0, 320, 200));
return false;
}
bool Console::cmdRedrawScreen(int argc, const char **argv) {
- g_EngineState->visual->draw(Common::Point(0, 0));
- gfxop_update_box(g_EngineState->gfx_state, gfx_rect(0, 0, 320, 200));
- gfxop_update(g_EngineState->gfx_state);
- gfxop_sleep(g_EngineState->gfx_state, 0);
+ _vm->_gamestate->visual->draw(Common::Point(0, 0));
+ gfxop_update_box(_vm->_gamestate->gfx_state, gfx_rect(0, 0, 320, 200));
+ gfxop_update(_vm->_gamestate->gfx_state);
+ gfxop_sleep(_vm->_gamestate->gfx_state, 0);
return false;
}
@@ -783,8 +781,8 @@ bool Console::cmdSaveGame(int argc, const char **argv) {
}
int result = 0;
- for (uint i = 0; i < g_EngineState->_fileHandles.size(); i++)
- if (g_EngineState->_fileHandles[i].isOpen())
+ for (uint i = 0; i < _vm->_gamestate->_fileHandles.size(); i++)
+ if (_vm->_gamestate->_fileHandles[i].isOpen())
result++;
if (result)
@@ -798,7 +796,7 @@ bool Console::cmdSaveGame(int argc, const char **argv) {
}
// TODO: enable custom descriptions? force filename into a specific format?
- if (gamestate_save(g_EngineState, out, "debugging")) {
+ if (gamestate_save(_vm->_gamestate, out, "debugging")) {
DebugPrintf("Saving the game state to '%s' failed\n", argv[1]);
}
@@ -818,17 +816,17 @@ bool Console::cmdRestoreGame(int argc, const char **argv) {
Common::SeekableReadStream *in;
if (!(in = saveFileMan->openForLoading(argv[1]))) {
// found a savegame file
- newstate = gamestate_restore(g_EngineState, in);
+ newstate = gamestate_restore(_vm->_gamestate, in);
delete in;
}
if (newstate) {
- g_EngineState->successor = newstate; // Set successor
+ _vm->_gamestate->successor = newstate; // Set successor
script_abort_flag = 2; // Abort current game with replay
g_debugstate_valid = 0;
- shrink_execution_stack(g_EngineState, g_EngineState->execution_stack_base + 1);
+ shrink_execution_stack(_vm->_gamestate, _vm->_gamestate->execution_stack_base + 1);
return 0;
} else {
DebugPrintf("Restoring gamestate '%s' failed.\n", argv[1]);
@@ -847,15 +845,15 @@ bool Console::cmdRestartGame(int argc, const char **argv) {
}
if (!scumm_stricmp(argv[1], "play")) {
- g_EngineState->restarting_flags |= SCI_GAME_WAS_RESTARTED_AT_LEAST_ONCE;
+ _vm->_gamestate->restarting_flags |= SCI_GAME_WAS_RESTARTED_AT_LEAST_ONCE;
} else if (!scumm_stricmp(argv[1], "replay")) {
- g_EngineState->restarting_flags &= ~SCI_GAME_WAS_RESTARTED_AT_LEAST_ONCE;
+ _vm->_gamestate->restarting_flags &= ~SCI_GAME_WAS_RESTARTED_AT_LEAST_ONCE;
} else {
DebugPrintf("Invalid usage of %s\n", argv[0]);
return true;
}
- g_EngineState->restarting_flags |= SCI_GAME_IS_RESTARTING_NOW;
+ _vm->_gamestate->restarting_flags |= SCI_GAME_IS_RESTARTING_NOW;
script_abort_flag = 1;
g_debugstate_valid = 0;
@@ -864,10 +862,10 @@ bool Console::cmdRestartGame(int argc, const char **argv) {
bool Console::cmdClassTable(int argc, const char **argv) {
DebugPrintf("Available classes:\n");
- for (uint i = 0; i < g_EngineState->_classtable.size(); i++) {
- if (g_EngineState->_classtable[i].reg.segment) {
+ for (uint i = 0; i < _vm->_gamestate->_classtable.size(); i++) {
+ if (_vm->_gamestate->_classtable[i].reg.segment) {
DebugPrintf(" Class 0x%x at %04x:%04x (script 0x%x)\n", i,
- PRINT_REG(g_EngineState->_classtable[i].reg), g_EngineState->_classtable[i].script);
+ PRINT_REG(_vm->_gamestate->_classtable[i].reg), _vm->_gamestate->_classtable[i].script);
}
}
@@ -877,10 +875,10 @@ bool Console::cmdClassTable(int argc, const char **argv) {
bool Console::cmdSentenceFragments(int argc, const char **argv) {
DebugPrintf("Sentence fragments (used to build Parse trees)\n");
- for (uint i = 0; i < g_EngineState->_vocabulary->getParserBranchesSize(); i++) {
+ for (uint i = 0; i < _vm->_gamestate->_vocabulary->getParserBranchesSize(); i++) {
int j = 0;
- const parse_tree_branch_t &branch = g_EngineState->_vocabulary->getParseTreeBranch(i);
+ const parse_tree_branch_t &branch = _vm->_gamestate->_vocabulary->getParseTreeBranch(i);
DebugPrintf("R%02d: [%x] ->", i, branch.id);
while ((j < 10) && branch.data[j]) {
int dat = branch.data[j++];
@@ -912,7 +910,7 @@ bool Console::cmdSentenceFragments(int argc, const char **argv) {
DebugPrintf("\n");
}
- DebugPrintf("%d rules.\n", g_EngineState->_vocabulary->getParserBranchesSize());
+ DebugPrintf("%d rules.\n", _vm->_gamestate->_vocabulary->getParserBranchesSize());
return true;
}
@@ -935,24 +933,24 @@ bool Console::cmdParse(int argc, const char **argv) {
}
DebugPrintf("Parsing '%s'\n", string);
- bool res = g_EngineState->_vocabulary->tokenizeString(words, string, &error);
+ bool res = _vm->_gamestate->_vocabulary->tokenizeString(words, string, &error);
if (res && !words.empty()) {
int syntax_fail = 0;
- vocab_synonymize_tokens(words, g_EngineState->_synonyms);
+ vocab_synonymize_tokens(words, _vm->_gamestate->_synonyms);
DebugPrintf("Parsed to the following blocks:\n");
for (ResultWordList::const_iterator i = words.begin(); i != words.end(); ++i)
DebugPrintf(" Type[%04x] Group[%04x]\n", i->_class, i->_group);
- if (g_EngineState->_vocabulary->parseGNF(g_EngineState->parser_nodes, words, true))
+ if (_vm->_gamestate->_vocabulary->parseGNF(_vm->_gamestate->parser_nodes, words, true))
syntax_fail = 1; // Building a tree failed
if (syntax_fail)
DebugPrintf("Building a tree failed.\n");
else
- vocab_dump_parse_tree("debug-parse-tree", g_EngineState->parser_nodes);
+ vocab_dump_parse_tree("debug-parse-tree", _vm->_gamestate->parser_nodes);
} else {
DebugPrintf("Unknown word: '%s'\n", error);
@@ -974,11 +972,11 @@ bool Console::cmdParserNodes(int argc, const char **argv) {
for (int i = 0; i < end; i++) {
DebugPrintf(" Node %03x: ", i);
- if (g_EngineState->parser_nodes[i].type == kParseTreeLeafNode)
- DebugPrintf("Leaf: %04x\n", g_EngineState->parser_nodes[i].content.value);
+ if (_vm->_gamestate->parser_nodes[i].type == kParseTreeLeafNode)
+ DebugPrintf("Leaf: %04x\n", _vm->_gamestate->parser_nodes[i].content.value);
else
- DebugPrintf("Branch: ->%04x, ->%04x\n", g_EngineState->parser_nodes[i].content.branches[0],
- g_EngineState->parser_nodes[i].content.branches[1]);
+ DebugPrintf("Branch: ->%04x, ->%04x\n", _vm->_gamestate->parser_nodes[i].content.branches[0],
+ _vm->_gamestate->parser_nodes[i].content.branches[1]);
}
return true;
@@ -1002,10 +1000,10 @@ bool Console::cmdDrawPic(int argc, const char **argv) {
if (argc == 4)
flags = atoi(argv[3]);
- gfxop_new_pic(g_EngineState->gfx_state, atoi(argv[1]), flags, default_palette);
- gfxop_clear_box(g_EngineState->gfx_state, gfx_rect(0, 0, 320, 200));
- gfxop_update(g_EngineState->gfx_state);
- gfxop_sleep(g_EngineState->gfx_state, 0);
+ gfxop_new_pic(_vm->_gamestate->gfx_state, atoi(argv[1]), flags, default_palette);
+ gfxop_clear_box(_vm->_gamestate->gfx_state, gfx_rect(0, 0, 320, 200));
+ gfxop_update(_vm->_gamestate->gfx_state);
+ gfxop_sleep(_vm->_gamestate->gfx_state, 0);
return false;
}
@@ -1020,10 +1018,10 @@ bool Console::cmdDrawRect(int argc, const char **argv) {
int col = CLIP<int>(atoi(argv[5]), 0, 15);
- gfxop_set_clip_zone(g_EngineState->gfx_state, gfx_rect_fullscreen);
- gfxop_fill_box(g_EngineState->gfx_state, gfx_rect(atoi(argv[1]), atoi(argv[2]),
- atoi(argv[3]), atoi(argv[4])), g_EngineState->ega_colors[col]);
- gfxop_update(g_EngineState->gfx_state);
+ gfxop_set_clip_zone(_vm->_gamestate->gfx_state, gfx_rect_fullscreen);
+ gfxop_fill_box(_vm->_gamestate->gfx_state, gfx_rect(atoi(argv[1]), atoi(argv[2]),
+ atoi(argv[3]), atoi(argv[4])), _vm->_gamestate->ega_colors[col]);
+ gfxop_update(_vm->_gamestate->gfx_state);
return false;
}
@@ -1040,9 +1038,9 @@ bool Console::cmdDrawCel(int argc, const char **argv) {
int cel = atoi(argv[3]);
int palette = atoi(argv[4]);
- gfxop_set_clip_zone(g_EngineState->gfx_state, gfx_rect_fullscreen);
- gfxop_draw_cel(g_EngineState->gfx_state, view, loop, cel, Common::Point(160, 100), g_EngineState->ega_colors[0], palette);
- gfxop_update(g_EngineState->gfx_state);
+ gfxop_set_clip_zone(_vm->_gamestate->gfx_state, gfx_rect_fullscreen);
+ gfxop_draw_cel(_vm->_gamestate->gfx_state, view, loop, cel, Common::Point(160, 100), _vm->_gamestate->ega_colors[0], palette);
+ gfxop_update(_vm->_gamestate->gfx_state);
return false;
}
@@ -1063,7 +1061,7 @@ bool Console::cmdViewInfo(int argc, const char **argv) {
DebugPrintf("Resource view.%d ", view);
- loops = gfxop_lookup_view_get_loops(g_EngineState->gfx_state, view);
+ loops = gfxop_lookup_view_get_loops(_vm->_gamestate->gfx_state, view);
if (loops < 0)
DebugPrintf("does not exist.\n");
@@ -1073,17 +1071,17 @@ bool Console::cmdViewInfo(int argc, const char **argv) {
for (i = 0; i < loops; i++) {
int j, cels;
- DebugPrintf("Loop %d: %d cels.\n", i, cels = gfxop_lookup_view_get_cels(g_EngineState->gfx_state, view, i));
+ DebugPrintf("Loop %d: %d cels.\n", i, cels = gfxop_lookup_view_get_cels(_vm->_gamestate->gfx_state, view, i));
for (j = 0; j < cels; j++) {
int width;
int height;
Common::Point mod;
// Show pixmap on screen
- view_pixmaps = g_EngineState->gfx_state->gfxResMan->getView(view, &i, &j, palette);
- gfxop_draw_cel(g_EngineState->gfx_state, view, i, j, Common::Point(0,0), transparent, palette);
+ view_pixmaps = _vm->_gamestate->gfx_state->gfxResMan->getView(view, &i, &j, palette);
+ gfxop_draw_cel(_vm->_gamestate->gfx_state, view, i, j, Common::Point(0,0), transparent, palette);
- gfxop_get_cel_parameters(g_EngineState->gfx_state, view, i, j, &width, &height, &mod);
+ gfxop_get_cel_parameters(_vm->_gamestate->gfx_state, view, i, j, &width, &height, &mod);
DebugPrintf(" cel %d: size %dx%d, adj+(%d,%d)\n", j, width, height, mod.x, mod.y);
}
@@ -1105,7 +1103,7 @@ bool Console::cmdUpdateZone(int argc, const char **argv) {
int width = atoi(argv[3]);
int height = atoi(argv[4]);
- g_EngineState->gfx_state->driver->update(gfx_rect(x, y, width, height), Common::Point(x, y), GFX_BUFFER_FRONT);
+ _vm->_gamestate->gfx_state->driver->update(gfx_rect(x, y, width, height), Common::Point(x, y), GFX_BUFFER_FRONT);
return false;
}
@@ -1125,14 +1123,14 @@ bool Console::cmdPropagateZone(int argc, const char **argv) {
int map = CLIP<int>(atoi(argv[5]), 0, 1);
rect_t rect = gfx_rect(x, y, width, height);
- gfxop_set_clip_zone(g_EngineState->gfx_state, gfx_rect_fullscreen);
+ gfxop_set_clip_zone(_vm->_gamestate->gfx_state, gfx_rect_fullscreen);
if (map == 1)
- gfxop_clear_box(g_EngineState->gfx_state, rect);
+ gfxop_clear_box(_vm->_gamestate->gfx_state, rect);
else
- gfxop_update_box(g_EngineState->gfx_state, rect);
- gfxop_update(g_EngineState->gfx_state);
- gfxop_sleep(g_EngineState->gfx_state, 0);
+ gfxop_update_box(_vm->_gamestate->gfx_state, rect);
+ gfxop_update(_vm->_gamestate->gfx_state);
+ gfxop_sleep(_vm->_gamestate->gfx_state, 0);
return false;
}
@@ -1147,18 +1145,18 @@ bool Console::cmdFillScreen(int argc, const char **argv) {
int col = CLIP<int>(atoi(argv[1]), 0, 15);
- gfxop_set_clip_zone(g_EngineState->gfx_state, gfx_rect_fullscreen);
- gfxop_fill_box(g_EngineState->gfx_state, gfx_rect_fullscreen, g_EngineState->ega_colors[col]);
- gfxop_update(g_EngineState->gfx_state);
+ gfxop_set_clip_zone(_vm->_gamestate->gfx_state, gfx_rect_fullscreen);
+ gfxop_fill_box(_vm->_gamestate->gfx_state, gfx_rect_fullscreen, _vm->_gamestate->ega_colors[col]);
+ gfxop_update(_vm->_gamestate->gfx_state);
return false;
}
bool Console::cmdCurrentPort(int argc, const char **argv) {
- if (!g_EngineState->port)
+ if (!_vm->_gamestate->port)
DebugPrintf("There is no port active currently.\n");
else
- DebugPrintf("Current port ID: %d\n", g_EngineState->port->_ID);
+ DebugPrintf("Current port ID: %d\n", _vm->_gamestate->port->_ID);
return true;
}
@@ -1174,16 +1172,16 @@ bool Console::cmdPrintPort(int argc, const char **argv) {
GfxPort *port;
if (!scumm_stricmp(argv[1], "current")) {
- port = g_EngineState->port;
+ port = _vm->_gamestate->port;
if (!port)
DebugPrintf("There is no active port currently\n");
else
port->print(0);
} else {
- if (!g_EngineState->visual) {
+ if (!_vm->_gamestate->visual) {
DebugPrintf("Visual is uninitialized\n");
} else {
- port = g_EngineState->visual->getPort(atoi(argv[1]));
+ port = _vm->_gamestate->visual->getPort(atoi(argv[1]));
if (!port)
DebugPrintf("No such port\n");
else
@@ -1197,7 +1195,7 @@ bool Console::cmdPrintPort(int argc, const char **argv) {
bool Console::cmdParseGrammar(int argc, const char **argv) {
DebugPrintf("Parse grammar, in strict GNF:\n");
- g_EngineState->_vocabulary->buildGNF(true);
+ _vm->_gamestate->_vocabulary->buildGNF(true);
return true;
}
@@ -1205,8 +1203,8 @@ bool Console::cmdParseGrammar(int argc, const char **argv) {
bool Console::cmdVisualState(int argc, const char **argv) {
DebugPrintf("State of the current visual widget:\n");
- if (g_EngineState->visual)
- g_EngineState->visual->print(0);
+ if (_vm->_gamestate->visual)
+ _vm->_gamestate->visual->print(0);
else
DebugPrintf("The visual widget is uninitialized.\n");
@@ -1214,11 +1212,11 @@ bool Console::cmdVisualState(int argc, const char **argv) {
}
bool Console::cmdFlushPorts(int argc, const char **argv) {
- gfxop_set_pointer_cursor(g_EngineState->gfx_state, GFXOP_NO_POINTER);
+ gfxop_set_pointer_cursor(_vm->_gamestate->gfx_state, GFXOP_NO_POINTER);
DebugPrintf("Flushing dynamically allocated ports (for memory profiling)...\n");
- delete g_EngineState->visual;
- g_EngineState->gfx_state->gfxResMan->freeAllResources();
- g_EngineState->visual = NULL;
+ delete _vm->_gamestate->visual;
+ _vm->_gamestate->gfx_state->gfxResMan->freeAllResources();
+ _vm->_gamestate->visual = NULL;
return true;
}
@@ -1226,8 +1224,8 @@ bool Console::cmdFlushPorts(int argc, const char **argv) {
bool Console::cmdDynamicViews(int argc, const char **argv) {
DebugPrintf("List of active dynamic views:\n");
- if (g_EngineState->dyn_views)
- g_EngineState->dyn_views->print(0);
+ if (_vm->_gamestate->dyn_views)
+ _vm->_gamestate->dyn_views->print(0);
else
DebugPrintf("The list is empty.\n");
@@ -1237,8 +1235,8 @@ bool Console::cmdDynamicViews(int argc, const char **argv) {
bool Console::cmdDroppedViews(int argc, const char **argv) {
DebugPrintf("List of dropped dynamic views:\n");
- if (g_EngineState->drop_views)
- g_EngineState->drop_views->print(0);
+ if (_vm->_gamestate->drop_views)
+ _vm->_gamestate->drop_views->print(0);
else
DebugPrintf("The list is empty.\n");
@@ -1247,13 +1245,13 @@ bool Console::cmdDroppedViews(int argc, const char **argv) {
bool Console::cmdPriorityBands(int argc, const char **argv) {
if (argc != 2) {
- DebugPrintf("Priority bands start at y=%d. They end at y=%d\n", g_EngineState->priority_first, g_EngineState->priority_last);
+ DebugPrintf("Priority bands start at y=%d. They end at y=%d\n", _vm->_gamestate->priority_first, _vm->_gamestate->priority_last);
DebugPrintf("Use %s <priority band> to print the start of priority for the specified priority band (0 - 15)\n", argv[0]);
return true;
}
int zone = CLIP<int>(atoi(argv[1]), 0, 15);
- DebugPrintf("Zone %x starts at y=%d\n", zone, _find_priority_band(g_EngineState, zone));
+ DebugPrintf("Zone %x starts at y=%d\n", zone, _find_priority_band(_vm->_gamestate, zone));
return true;
}
@@ -1265,15 +1263,15 @@ bool Console::cmdStatusBarColors(int argc, const char **argv) {
return true;
}
- g_EngineState->titlebar_port->_color = g_EngineState->ega_colors[atoi(argv[1])];
- g_EngineState->titlebar_port->_bgcolor = g_EngineState->ega_colors[atoi(argv[2])];
+ _vm->_gamestate->titlebar_port->_color = _vm->_gamestate->ega_colors[atoi(argv[1])];
+ _vm->_gamestate->titlebar_port->_bgcolor = _vm->_gamestate->ega_colors[atoi(argv[2])];
- g_EngineState->status_bar_foreground = atoi(argv[1]);
- g_EngineState->status_bar_background = atoi(argv[2]);
+ _vm->_gamestate->status_bar_foreground = atoi(argv[1]);
+ _vm->_gamestate->status_bar_background = atoi(argv[2]);
- sciw_set_status_bar(g_EngineState, g_EngineState->titlebar_port, g_EngineState->_statusBarText,
- g_EngineState->status_bar_foreground, g_EngineState->status_bar_background);
- gfxop_update(g_EngineState->gfx_state);
+ sciw_set_status_bar(_vm->_gamestate, _vm->_gamestate->titlebar_port, _vm->_gamestate->_statusBarText,
+ _vm->_gamestate->status_bar_foreground, _vm->_gamestate->status_bar_background);
+ gfxop_update(_vm->_gamestate->gfx_state);
return false;
}
@@ -1281,8 +1279,8 @@ bool Console::cmdStatusBarColors(int argc, const char **argv) {
bool Console::cmdPrintSegmentTable(int argc, const char **argv) {
DebugPrintf("Segment table:\n");
- for (uint i = 0; i < g_EngineState->seg_manager->_heap.size(); i++) {
- MemObject *mobj = g_EngineState->seg_manager->_heap[i];
+ for (uint i = 0; i < _vm->_gamestate->seg_manager->_heap.size(); i++) {
+ MemObject *mobj = _vm->_gamestate->seg_manager->_heap[i];
if (mobj && mobj->getType()) {
DebugPrintf(" [%04x] ", i);
@@ -1343,10 +1341,10 @@ bool Console::cmdPrintSegmentTable(int argc, const char **argv) {
bool Console::segmentInfo(int nr) {
DebugPrintf("[%04x] ", nr);
- if ((nr < 0) || ((uint)nr >= g_EngineState->seg_manager->_heap.size()) || !g_EngineState->seg_manager->_heap[nr])
+ if ((nr < 0) || ((uint)nr >= _vm->_gamestate->seg_manager->_heap.size()) || !_vm->_gamestate->seg_manager->_heap[nr])
return false;
- MemObject *mobj = g_EngineState->seg_manager->_heap[nr];
+ MemObject *mobj = _vm->_gamestate->seg_manager->_heap[nr];
switch (mobj->getType()) {
@@ -1369,10 +1367,10 @@ bool Console::segmentInfo(int nr) {
for (uint i = 0; i < scr->_objects.size(); i++) {
DebugPrintf(" ");
// Object header
- Object *obj = obj_get(g_EngineState, scr->_objects[i].pos);
+ Object *obj = obj_get(_vm->_gamestate, scr->_objects[i].pos);
if (obj)
DebugPrintf("[%04x:%04x] %s : %3d vars, %3d methods\n", PRINT_REG(scr->_objects[i].pos),
- obj_get_name(g_EngineState, scr->_objects[i].pos), obj->_variables.size(), obj->methods_nr);
+ obj_get_name(_vm->_gamestate, scr->_objects[i].pos), obj->_variables.size(), obj->methods_nr);
}
}
break;
@@ -1413,12 +1411,12 @@ bool Console::segmentInfo(int nr) {
reg_t objpos;
objpos.offset = i;
objpos.segment = nr;
- DebugPrintf(" [%04x] %s; copy of ", i, obj_get_name(g_EngineState, objpos));
+ DebugPrintf(" [%04x] %s; copy of ", i, obj_get_name(_vm->_gamestate, objpos));
// Object header
- Object *obj = obj_get(g_EngineState, ct->_table[i].pos);
+ Object *obj = obj_get(_vm->_gamestate, ct->_table[i].pos);
if (obj)
DebugPrintf("[%04x:%04x] %s : %3d vars, %3d methods\n", PRINT_REG(ct->_table[i].pos),
- obj_get_name(g_EngineState, ct->_table[i].pos), obj->_variables.size(), obj->methods_nr);
+ obj_get_name(_vm->_gamestate, ct->_table[i].pos), obj->_variables.size(), obj->methods_nr);
}
}
break;
@@ -1484,7 +1482,7 @@ bool Console::cmdSegmentInfo(int argc, const char **argv) {
}
if (!scumm_stricmp(argv[1], "all")) {
- for (uint i = 0; i < g_EngineState->seg_manager->_heap.size(); i++)
+ for (uint i = 0; i < _vm->_gamestate->seg_manager->_heap.size(); i++)
segmentInfo(i);
} else {
int nr = atoi(argv[1]);
@@ -1503,7 +1501,7 @@ bool Console::cmdKillSegment(int argc, const char **argv) {
return true;
}
- g_EngineState->seg_manager->getScript(atoi(argv[1]))->setLockers(0);
+ _vm->_gamestate->seg_manager->getScript(atoi(argv[1]))->setLockers(0);
return true;
}
@@ -1519,24 +1517,24 @@ bool Console::cmdShowMap(int argc, const char **argv) {
return true;
}
- gfxop_set_clip_zone(g_EngineState->gfx_state, gfx_rect_fullscreen);
+ gfxop_set_clip_zone(_vm->_gamestate->gfx_state, gfx_rect_fullscreen);
int map = atoi(argv[1]);
switch (map) {
case 0:
- g_EngineState->visual->add_dirty_abs((GfxContainer *)g_EngineState->visual, gfx_rect(0, 0, 320, 200), 0);
- g_EngineState->visual->draw(Common::Point(0, 0));
+ _vm->_gamestate->visual->add_dirty_abs((GfxContainer *)_vm->_gamestate->visual, gfx_rect(0, 0, 320, 200), 0);
+ _vm->_gamestate->visual->draw(Common::Point(0, 0));
break;
case 1:
- gfx_xlate_pixmap(g_EngineState->gfx_state->pic->priority_map, g_EngineState->gfx_state->driver->getMode(), GFX_XLATE_FILTER_NONE);
- gfxop_draw_pixmap(g_EngineState->gfx_state, g_EngineState->gfx_state->pic->priority_map, gfx_rect(0, 0, 320, 200), Common::Point(0, 0));
+ gfx_xlate_pixmap(_vm->_gamestate->gfx_state->pic->priority_map, _vm->_gamestate->gfx_state->driver->getMode(), GFX_XLATE_FILTER_NONE);
+ gfxop_draw_pixmap(_vm->_gamestate->gfx_state, _vm->_gamestate->gfx_state->pic->priority_map, gfx_rect(0, 0, 320, 200), Common::Point(0, 0));
break;
case 2:
- gfx_xlate_pixmap(g_EngineState->gfx_state->control_map, g_EngineState->gfx_state->driver->getMode(), GFX_XLATE_FILTER_NONE);
- gfxop_draw_pixmap(g_EngineState->gfx_state, g_EngineState->gfx_state->control_map, gfx_rect(0, 0, 320, 200), Common::Point(0, 0));
+ gfx_xlate_pixmap(_vm->_gamestate->gfx_state->control_map, _vm->_gamestate->gfx_state->driver->getMode(), GFX_XLATE_FILTER_NONE);
+ gfxop_draw_pixmap(_vm->_gamestate->gfx_state, _vm->_gamestate->gfx_state->control_map, gfx_rect(0, 0, 320, 200), Common::Point(0, 0));
break;
default:
@@ -1544,7 +1542,7 @@ bool Console::cmdShowMap(int argc, const char **argv) {
return true;
}
- gfxop_update(g_EngineState->gfx_state);
+ gfxop_update(_vm->_gamestate->gfx_state);
return false;
}
@@ -1552,7 +1550,7 @@ bool Console::cmdShowMap(int argc, const char **argv) {
bool Console::cmdSongLib(int argc, const char **argv) {
DebugPrintf("Song library:\n");
- Song *seeker = g_EngineState->_sound._songlib._lib;
+ Song *seeker = _vm->_gamestate->_sound._songlib._lib;
do {
DebugPrintf(" %p", (void *)seeker);
@@ -1570,12 +1568,12 @@ bool Console::cmdSongLib(int argc, const char **argv) {
bool Console::cmdGCInvoke(int argc, const char **argv) {
DebugPrintf("Performing garbage collection...\n");
- run_gc(g_EngineState);
+ run_gc(_vm->_gamestate);
return true;
}
bool Console::cmdGCObjects(int argc, const char **argv) {
- reg_t_hash_map *use_map = find_all_used_references(g_EngineState);
+ reg_t_hash_map *use_map = find_all_used_references(_vm->_gamestate);
DebugPrintf("Reachable object references (normalised):\n");
for (reg_t_hash_map::iterator i = use_map->begin(); i != use_map->end(); ++i) {
@@ -1602,20 +1600,20 @@ bool Console::cmdGCShowReachable(int argc, const char **argv) {
reg_t addr;
- if (parse_reg_t(g_EngineState, argv[1], &addr)) {
+ if (parse_reg_t(_vm->_gamestate, argv[1], &addr)) {
DebugPrintf("Invalid address passed.\n");
DebugPrintf("Check the \"addresses\" command on how to use addresses\n");
return true;
}
- MemObject *mobj = GET_SEGMENT_ANY(*g_EngineState->seg_manager, addr.segment);
+ MemObject *mobj = GET_SEGMENT_ANY(*_vm->_gamestate->seg_manager, addr.segment);
if (!mobj) {
DebugPrintf("Unknown segment : %x\n", addr.segment);
return 1;
}
DebugPrintf("Reachable from %04x:%04x:\n", PRINT_REG(addr));
- mobj->listAllOutgoingReferences(g_EngineState, addr, NULL, _print_address);
+ mobj->listAllOutgoingReferences(_vm->_gamestate, addr, NULL, _print_address);
return true;
}
@@ -1631,13 +1629,13 @@ bool Console::cmdGCShowFreeable(int argc, const char **argv) {
reg_t addr;
- if (parse_reg_t(g_EngineState, argv[1], &addr)) {
+ if (parse_reg_t(_vm->_gamestate, argv[1], &addr)) {
DebugPrintf("Invalid address passed.\n");
DebugPrintf("Check the \"addresses\" command on how to use addresses\n");
return true;
}
- MemObject *mobj = GET_SEGMENT_ANY(*g_EngineState->seg_manager, addr.segment);
+ MemObject *mobj = GET_SEGMENT_ANY(*_vm->_gamestate->seg_manager, addr.segment);
if (!mobj) {
DebugPrintf("Unknown segment : %x\n", addr.segment);
return true;
@@ -1661,19 +1659,19 @@ bool Console::cmdGCNormalize(int argc, const char **argv) {
reg_t addr;
- if (parse_reg_t(g_EngineState, argv[1], &addr)) {
+ if (parse_reg_t(_vm->_gamestate, argv[1], &addr)) {
DebugPrintf("Invalid address passed.\n");
DebugPrintf("Check the \"addresses\" command on how to use addresses\n");
return true;
}
- MemObject *mobj = GET_SEGMENT_ANY(*g_EngineState->seg_manager, addr.segment);
+ MemObject *mobj = GET_SEGMENT_ANY(*_vm->_gamestate->seg_manager, addr.segment);
if (!mobj) {
DebugPrintf("Unknown segment : %x\n", addr.segment);
return true;
}
- addr = mobj->findCanonicAddress(g_EngineState->seg_manager, addr);
+ addr = mobj->findCanonicAddress(_vm->_gamestate->seg_manager, addr);
DebugPrintf(" %04x:%04x\n", PRINT_REG(addr));
return true;
@@ -1746,7 +1744,7 @@ bool Console::cmdVMVars(int argc, const char **argv) {
#if 0
// TODO: p_vars
- if (parse_reg_t(g_EngineState, argv[3], &p_vars[vartype][idx])) {
+ if (parse_reg_t(_vm->_gamestate, argv[3], &p_vars[vartype][idx])) {
DebugPrintf("Invalid address passed.\n");
DebugPrintf("Check the \"addresses\" command on how to use addresses\n");
return true;
@@ -1767,19 +1765,19 @@ bool Console::cmdStack(int argc, const char **argv) {
return true;
}
- if (g_EngineState->_executionStack.empty()) {
+ if (_vm->_gamestate->_executionStack.empty()) {
DebugPrintf("No exec stack!");
return true;
}
- ExecStack &xs = g_EngineState->_executionStack.back();
+ ExecStack &xs = _vm->_gamestate->_executionStack.back();
int nr = atoi(argv[1]);
for (int i = nr; i > 0; i--) {
if ((xs.sp - xs.fp - i) == 0)
DebugPrintf("-- temp variables --\n");
- if (xs.sp - i >= g_EngineState->stack_base)
- DebugPrintf("ST:%04x = %04x:%04x\n", (unsigned)(xs.sp - i - g_EngineState->stack_base), PRINT_REG(xs.sp[-i]));
+ if (xs.sp - i >= _vm->_gamestate->stack_base)
+ DebugPrintf("ST:%04x = %04x:%04x\n", (unsigned)(xs.sp - i - _vm->_gamestate->stack_base), PRINT_REG(xs.sp[-i]));
}
return true;
@@ -1797,13 +1795,13 @@ bool Console::cmdValueType(int argc, const char **argv) {
reg_t val;
- if (parse_reg_t(g_EngineState, argv[1], &val)) {
+ if (parse_reg_t(_vm->_gamestate, argv[1], &val)) {
DebugPrintf("Invalid address passed.\n");
DebugPrintf("Check the \"addresses\" command on how to use addresses\n");
return true;
}
- int t = determine_reg_type(g_EngineState, val, true);
+ int t = determine_reg_type(_vm->_gamestate, val, true);
int invalid = t & KSIG_INVALID;
switch (t & ~KSIG_INVALID) {
@@ -1841,7 +1839,7 @@ bool Console::cmdViewListNode(int argc, const char **argv) {
reg_t addr;
- if (parse_reg_t(g_EngineState, argv[1], &addr)) {
+ if (parse_reg_t(_vm->_gamestate, argv[1], &addr)) {
DebugPrintf("Invalid address passed.\n");
DebugPrintf("Check the \"addresses\" command on how to use addresses\n");
return true;
@@ -1864,21 +1862,21 @@ bool Console::cmdViewReference(int argc, const char **argv) {
reg_t reg = NULL_REG;
reg_t reg_end = NULL_REG;
- if (parse_reg_t(g_EngineState, argv[1], &reg)) {
+ if (parse_reg_t(_vm->_gamestate, argv[1], &reg)) {
DebugPrintf("Invalid address passed.\n");
DebugPrintf("Check the \"addresses\" command on how to use addresses\n");
return true;
}
if (argc > 2) {
- if (parse_reg_t(g_EngineState, argv[2], &reg_end)) {
+ if (parse_reg_t(_vm->_gamestate, argv[2], &reg_end)) {
DebugPrintf("Invalid address passed.\n");
DebugPrintf("Check the \"addresses\" command on how to use addresses\n");
return true;
}
}
- int type_mask = determine_reg_type(g_EngineState, reg, 1);
+ int type_mask = determine_reg_type(_vm->_gamestate, reg, 1);
int filter;
int found = 0;
@@ -1908,7 +1906,7 @@ bool Console::cmdViewReference(int argc, const char **argv) {
case 0:
break;
case KSIG_LIST: {
- List *l = lookup_list(g_EngineState, reg);
+ List *l = lookup_list(_vm->_gamestate, reg);
DebugPrintf("list\n");
@@ -1924,11 +1922,11 @@ bool Console::cmdViewReference(int argc, const char **argv) {
break;
case KSIG_OBJECT:
DebugPrintf("object\n");
- printObject(g_EngineState, reg);
+ printObject(_vm->_gamestate, reg);
break;
case KSIG_REF: {
int size;
- unsigned char *block = g_EngineState->seg_manager->dereference(reg, &size);
+ unsigned char *block = _vm->_gamestate->seg_manager->dereference(reg, &size);
DebugPrintf("raw data\n");
@@ -1972,14 +1970,14 @@ bool Console::cmdViewObject(int argc, const char **argv) {
reg_t addr;
- if (parse_reg_t(g_EngineState, argv[1], &addr)) {
+ if (parse_reg_t(_vm->_gamestate, argv[1], &addr)) {
DebugPrintf("Invalid address passed.\n");
DebugPrintf("Check the \"addresses\" command on how to use addresses\n");
return true;
}
DebugPrintf("Information on the object at the given address:\n");
- printObject(g_EngineState, addr);
+ printObject(_vm->_gamestate, addr);
return true;
}
@@ -1989,7 +1987,7 @@ bool Console::cmdViewActiveObject(int argc, const char **argv) {
#if 0
// TODO: p_objp
- printObject(g_EngineState, *p_objp);
+ printObject(_vm->_gamestate, *p_objp);
#endif
return true;
@@ -1997,7 +1995,7 @@ bool Console::cmdViewActiveObject(int argc, const char **argv) {
bool Console::cmdViewAccumulatorObject(int argc, const char **argv) {
DebugPrintf("Information on the currently active object or class at the address indexed by the accumulator:\n");
- printObject(g_EngineState, g_EngineState->r_acc);
+ printObject(_vm->_gamestate, _vm->_gamestate->r_acc);
return true;
}
@@ -2017,13 +2015,13 @@ bool Console::cmdSetAccumulator(int argc, const char **argv) {
reg_t val;
- if (parse_reg_t(g_EngineState, argv[1], &val)) {
+ if (parse_reg_t(_vm->_gamestate, argv[1], &val)) {
DebugPrintf("Invalid address passed.\n");
DebugPrintf("Check the \"addresses\" command on how to use addresses\n");
return true;
}
- g_EngineState->r_acc = val;
+ _vm->_gamestate->r_acc = val;
return true;
}
@@ -2031,31 +2029,31 @@ bool Console::cmdSetAccumulator(int argc, const char **argv) {
bool Console::cmdBacktrace(int argc, const char **argv) {
DebugPrintf("Dumping the send/self/super/call/calle/callb stack:\n");
- DebugPrintf("Call stack (current base: 0x%x):\n", g_EngineState->execution_stack_base);
+ DebugPrintf("Call stack (current base: 0x%x):\n", _vm->_gamestate->execution_stack_base);
Common::List<ExecStack>::iterator iter;
uint i = 0;
- for (iter = g_EngineState->_executionStack.begin();
- iter != g_EngineState->_executionStack.end(); ++iter, ++i) {
+ for (iter = _vm->_gamestate->_executionStack.begin();
+ iter != _vm->_gamestate->_executionStack.end(); ++iter, ++i) {
ExecStack &call = *iter;
- const char *objname = obj_get_name(g_EngineState, call.sendp);
+ const char *objname = obj_get_name(_vm->_gamestate, call.sendp);
int paramc, totalparamc;
switch (call.type) {
case EXEC_STACK_TYPE_CALL: {// Normal function
sciprintf(" %x:[%x] %s::%s(", i, call.origin, objname, (call.selector == -1) ? "<call[be]?>" :
- selector_name(g_EngineState, call.selector));
+ selector_name(_vm->_gamestate, call.selector));
}
break;
case EXEC_STACK_TYPE_KERNEL: // Kernel function
- sciprintf(" %x:[%x] k%s(", i, call.origin, g_EngineState->_kernel->getKernelName(-(call.selector) - 42).c_str());
+ sciprintf(" %x:[%x] k%s(", i, call.origin, _vm->_gamestate->_kernel->getKernelName(-(call.selector) - 42).c_str());
break;
case EXEC_STACK_TYPE_VARSELECTOR:
sciprintf(" %x:[%x] vs%s %s::%s (", i, call.origin, (call.argc) ? "write" : "read",
- objname, g_EngineState->_kernel->getSelectorName(call.selector).c_str());
+ objname, _vm->_gamestate->_kernel->getSelectorName(call.selector).c_str());
break;
}
@@ -2080,15 +2078,15 @@ bool Console::cmdBacktrace(int argc, const char **argv) {
if (call.sp == CALL_SP_CARRY)
sciprintf(" sp,fp:carry");
else {
- sciprintf(" sp=ST:%04x", (unsigned)(call.sp - g_EngineState->stack_base));
- sciprintf(" fp=ST:%04x", (unsigned)(call.fp - g_EngineState->stack_base));
+ sciprintf(" sp=ST:%04x", (unsigned)(call.sp - _vm->_gamestate->stack_base));
+ sciprintf(" fp=ST:%04x", (unsigned)(call.fp - _vm->_gamestate->stack_base));
}
} else
sciprintf(" pc:none");
- sciprintf(" argp:ST:%04x", (unsigned)(call.variables_argp - g_EngineState->stack_base));
+ sciprintf(" argp:ST:%04x", (unsigned)(call.variables_argp - _vm->_gamestate->stack_base));
if (call.type == EXEC_STACK_TYPE_CALL)
- sciprintf(" script: %d", (*(Script *)g_EngineState->seg_manager->_heap[call.addr.pc.segment]).nr);
+ sciprintf(" script: %d", (*(Script *)_vm->_gamestate->seg_manager->_heap[call.addr.pc.segment]).nr);
sciprintf("\n");
}
@@ -2113,7 +2111,7 @@ bool Console::cmdStepEvent(int argc, const char **argv) {
bool Console::cmdStepRet(int argc, const char **argv) {
g_debug_seeking = kDebugSeekLevelRet;
- g_debug_seek_level = g_EngineState->_executionStack.size() - 1;
+ g_debug_seek_level = _vm->_gamestate->_executionStack.size() - 1;
g_debugstate_valid = 0;
return true;
@@ -2144,8 +2142,8 @@ bool Console::cmdStepCallk(int argc, const char **argv) {
callk_index = strtoul(argv[1], &endptr, 0);
if (*endptr != '\0') {
callk_index = -1;
- for (uint i = 0; i < g_EngineState->_kernel->getKernelNamesSize(); i++)
- if (argv[1] == g_EngineState->_kernel->getKernelName(i)) {
+ for (uint i = 0; i < _vm->_gamestate->_kernel->getKernelNamesSize(); i++)
+ if (argv[1] == _vm->_gamestate->_kernel->getKernelName(i)) {
callk_index = i;
break;
}
@@ -2176,14 +2174,14 @@ bool Console::cmdDissassemble(int argc, const char **argv) {
reg_t objAddr = NULL_REG;
- if (parse_reg_t(g_EngineState, argv[1], &objAddr)) {
+ if (parse_reg_t(_vm->_gamestate, argv[1], &objAddr)) {
DebugPrintf("Invalid address passed.\n");
DebugPrintf("Check the \"addresses\" command on how to use addresses\n");
return true;
}
- Object *obj = obj_get(g_EngineState, objAddr);
- int selector_id = g_EngineState->_kernel->findSelector(argv[2]);
+ Object *obj = obj_get(_vm->_gamestate, objAddr);
+ int selector_id = _vm->_gamestate->_kernel->findSelector(argv[2]);
reg_t addr;
if (!obj) {
@@ -2196,14 +2194,14 @@ bool Console::cmdDissassemble(int argc, const char **argv) {
return true;
}
- if (lookup_selector(g_EngineState, objAddr, selector_id, NULL, &addr) != kSelectorMethod) {
+ if (lookup_selector(_vm->_gamestate, objAddr, selector_id, NULL, &addr) != kSelectorMethod) {
DebugPrintf("Not a method.");
return true;
}
do {
// TODO
- //addr = disassemble(g_EngineState, addr, 0, 0);
+ //addr = disassemble(_vm->_gamestate, addr, 0, 0);
} while (addr.offset > 0);
return true;
@@ -2226,13 +2224,13 @@ bool Console::cmdDissassembleAddress(int argc, const char **argv) {
int do_bytes = 0;
int size;
- if (parse_reg_t(g_EngineState, argv[1], &vpc)) {
+ if (parse_reg_t(_vm->_gamestate, argv[1], &vpc)) {
DebugPrintf("Invalid address passed.\n");
DebugPrintf("Check the \"addresses\" command on how to use addresses\n");
return true;
}
- g_EngineState->seg_manager->dereference(vpc, &size);
+ _vm->_gamestate->seg_manager->dereference(vpc, &size);
size += vpc.offset; // total segment size
for (int i = 1; i < argc; i++) {
@@ -2255,7 +2253,7 @@ bool Console::cmdDissassembleAddress(int argc, const char **argv) {
do {
// TODO
- //vpc = disassemble(g_EngineState, vpc, do_bwc, do_bytes);
+ //vpc = disassemble(_vm->_gamestate, vpc, do_bwc, do_bytes);
} while ((vpc.offset > 0) && (vpc.offset + 6 < size) && (--op_count));
@@ -2263,7 +2261,7 @@ bool Console::cmdDissassembleAddress(int argc, const char **argv) {
}
bool Console::cmdBreakpointList(int argc, const char **argv) {
- Breakpoint *bp = g_EngineState->bp_list;
+ Breakpoint *bp = _vm->_gamestate->bp_list;
int i = 0;
int bpdata;
@@ -2302,7 +2300,7 @@ bool Console::cmdBreakpointDelete(int argc, const char **argv) {
// Find breakpoint with given index
bp_prev = NULL;
- bp = g_EngineState->bp_list;
+ bp = _vm->_gamestate->bp_list;
while (bp && i < idx) {
bp_prev = bp;
bp = bp->next;
@@ -2321,11 +2319,11 @@ bool Console::cmdBreakpointDelete(int argc, const char **argv) {
if (bp_prev)
bp_prev->next = bp_next;
else
- g_EngineState->bp_list = bp_next;
+ _vm->_gamestate->bp_list = bp_next;
// Check if there are more breakpoints of the same type. If not, clear
// the respective bit in s->have_bp.
- for (bp = g_EngineState->bp_list; bp; bp = bp->next) {
+ for (bp = _vm->_gamestate->bp_list; bp; bp = bp->next) {
if (bp->type == type) {
found = 1;
break;
@@ -2333,7 +2331,7 @@ bool Console::cmdBreakpointDelete(int argc, const char **argv) {
}
if (!found)
- g_EngineState->have_bp &= ~type;
+ _vm->_gamestate->have_bp &= ~type;
return true;
}
@@ -2352,23 +2350,23 @@ bool Console::cmdBreakpointExecMethod(int argc, const char **argv) {
Thus, we can't check whether the command argument is a valid method name.
A breakpoint set on an invalid method name will just never trigger. */
Breakpoint *bp;
- if (g_EngineState->bp_list) {
+ if (_vm->_gamestate->bp_list) {
// List exists, append the breakpoint to the end
- bp = g_EngineState->bp_list;
+ bp = _vm->_gamestate->bp_list;
while (bp->next)
bp = bp->next;
bp->next = (Breakpoint *)malloc(sizeof(Breakpoint));
bp = bp->next;
} else {
// No list, so create the list head
- g_EngineState->bp_list = (Breakpoint *)malloc(sizeof(Breakpoint));
- bp = g_EngineState->bp_list;
+ _vm->_gamestate->bp_list = (Breakpoint *)malloc(sizeof(Breakpoint));
+ bp = _vm->_gamestate->bp_list;
}
bp->next = NULL;
bp->type = BREAK_SELECTOR;
bp->data.name = (char *)malloc(strlen(argv[1]) + 1);
strcpy(bp->data.name, argv[1]);
- g_EngineState->have_bp |= BREAK_SELECTOR;
+ _vm->_gamestate->have_bp |= BREAK_SELECTOR;
return true;
}
@@ -2385,22 +2383,22 @@ bool Console::cmdBreakpointExecFunction(int argc, const char **argv) {
Thus, we can't check whether the command argument is a valid method name.
A breakpoint set on an invalid method name will just never trigger. */
Breakpoint *bp;
- if (g_EngineState->bp_list) {
+ if (_vm->_gamestate->bp_list) {
// List exists, append the breakpoint to the end
- bp = g_EngineState->bp_list;
+ bp = _vm->_gamestate->bp_list;
while (bp->next)
bp = bp->next;
bp->next = (Breakpoint *)malloc(sizeof(Breakpoint));
bp = bp->next;
} else {
// No list, so create the list head
- g_EngineState->bp_list = (Breakpoint *)malloc(sizeof(Breakpoint));
- bp = g_EngineState->bp_list;
+ _vm->_gamestate->bp_list = (Breakpoint *)malloc(sizeof(Breakpoint));
+ bp = _vm->_gamestate->bp_list;
}
bp->next = NULL;
bp->type = BREAK_EXPORT;
bp->data.address = (atoi(argv[1]) << 16 | atoi(argv[2]));
- g_EngineState->have_bp |= BREAK_EXPORT;
+ _vm->_gamestate->have_bp |= BREAK_EXPORT;
return true;
}
@@ -2641,18 +2639,18 @@ bool Console::cmdStopSfx(int argc, const char **argv) {
reg_t id;
- if (parse_reg_t(g_EngineState, argv[1], &id)) {
+ if (parse_reg_t(_vm->_gamestate, argv[1], &id)) {
DebugPrintf("Invalid address passed.\n");
DebugPrintf("Check the \"addresses\" command on how to use addresses\n");
return true;
}
int handle = id.segment << 16 | id.offset; // frobnicate handle
- EngineState* s = g_EngineState; // for PUT_SEL32V
+ EngineState* s = _vm->_gamestate; // for PUT_SEL32V
if (id.segment) {
- g_EngineState->_sound.sfx_song_set_status(handle, SOUND_STATUS_STOPPED);
- g_EngineState->_sound.sfx_remove_song(handle);
+ _vm->_gamestate->_sound.sfx_song_set_status(handle, SOUND_STATUS_STOPPED);
+ _vm->_gamestate->_sound.sfx_remove_song(handle);
PUT_SEL32V(id, signal, -1);
PUT_SEL32V(id, nodePtr, 0);
PUT_SEL32V(id, handle, 0);
@@ -2891,7 +2889,7 @@ void Console::printList(List *l) {
while (!pos.isNull()) {
Node *node;
- NodeTable *nt = (NodeTable *)GET_SEGMENT(*g_EngineState->seg_manager, pos.segment, MEM_OBJ_NODES);
+ NodeTable *nt = (NodeTable *)GET_SEGMENT(*_vm->_gamestate->seg_manager, pos.segment, MEM_OBJ_NODES);
if (!nt || !nt->isValidEntry(pos.offset)) {
DebugPrintf(" WARNING: %04x:%04x: Doesn't contain list node!\n",
@@ -2918,7 +2916,7 @@ void Console::printList(List *l) {
}
int Console::printNode(reg_t addr) {
- MemObject *mobj = GET_SEGMENT(*g_EngineState->seg_manager, addr.segment, MEM_OBJ_LISTS);
+ MemObject *mobj = GET_SEGMENT(*_vm->_gamestate->seg_manager, addr.segment, MEM_OBJ_LISTS);
if (mobj) {
ListTable *lt = (ListTable *)mobj;
@@ -2935,7 +2933,7 @@ int Console::printNode(reg_t addr) {
} else {
NodeTable *nt;
Node *node;
- mobj = GET_SEGMENT(*g_EngineState->seg_manager, addr.segment, MEM_OBJ_NODES);
+ mobj = GET_SEGMENT(*_vm->_gamestate->seg_manager, addr.segment, MEM_OBJ_NODES);
if (!mobj) {
DebugPrintf("Segment #%04x is not a list or node segment\n", addr.segment);
diff --git a/engines/sci/engine/vm.cpp b/engines/sci/engine/vm.cpp
index f788629892..0b84c0ef3c 100644
--- a/engines/sci/engine/vm.cpp
+++ b/engines/sci/engine/vm.cpp
@@ -1945,12 +1945,9 @@ static void _init_stack_base_with_selector(EngineState *s, Selector selector) {
s->stack_base[1] = NULL_REG;
}
-EngineState *g_EngineState = 0;
-
static EngineState *_game_run(EngineState *&s, int restoring) {
EngineState *successor = NULL;
int game_is_finished = 0;
- g_EngineState = s;
do {
s->_executionStackPosChanged = false;
run_vm(s, (successor || restoring) ? 1 : 0);
@@ -1978,7 +1975,6 @@ static EngineState *_game_run(EngineState *&s, int restoring) {
script_free_vm_memory(s);
delete s;
s = successor;
- g_EngineState = s;
if (script_abort_flag == 2) {
sciprintf("Restarting with replay()\n");
diff --git a/engines/sci/sci.h b/engines/sci/sci.h
index 7cadfd0d7b..91f491fe71 100644
--- a/engines/sci/sci.h
+++ b/engines/sci/sci.h
@@ -133,6 +133,7 @@ enum SciGameFlags {
};
class SciEngine : public Engine {
+ friend class Console;
public:
SciEngine(OSystem *syst, const SciGameDescription *desc);
~SciEngine();