aboutsummaryrefslogtreecommitdiff
path: root/engines/sci
diff options
context:
space:
mode:
Diffstat (limited to 'engines/sci')
-rw-r--r--engines/sci/console.cpp25
-rw-r--r--engines/sci/debug.h1
-rw-r--r--engines/sci/engine/scriptdebug.cpp29
-rw-r--r--engines/sci/engine/seg_manager.cpp13
-rw-r--r--engines/sci/engine/seg_manager.h7
-rw-r--r--engines/sci/engine/vm.cpp14
-rw-r--r--engines/sci/engine/vm.h5
-rw-r--r--engines/sci/gfx/operations.cpp1
-rw-r--r--engines/sci/resource.cpp8
-rw-r--r--engines/sci/sci.cpp4
10 files changed, 59 insertions, 48 deletions
diff --git a/engines/sci/console.cpp b/engines/sci/console.cpp
index 7c1a165ec1..2ddc6979c9 100644
--- a/engines/sci/console.cpp
+++ b/engines/sci/console.cpp
@@ -194,6 +194,7 @@ Console::Console(SciEngine *vm) : GUI::Debugger() {
scriptState.seekLevel = 0;
scriptState.runningStep = 0;
scriptState.stopOnEvent = false;
+ scriptState.debugging = false;
}
Console::~Console() {
@@ -2091,28 +2092,30 @@ bool Console::cmdBacktrace(int argc, const char **argv) {
printf("\n");
}
- return 0;
return true;
}
bool Console::cmdStep(int argc, const char **argv) {
if (argc == 2 && atoi(argv[1]) > 0)
scriptState.runningStep = atoi(argv[1]) - 1;
+ scriptState.debugging = true;
- return true;
+ return false;
}
bool Console::cmdStepEvent(int argc, const char **argv) {
scriptState.stopOnEvent = true;
+ scriptState.debugging = true;
- return true;
+ return false;
}
bool Console::cmdStepRet(int argc, const char **argv) {
scriptState.seeking = kDebugSeekLevelRet;
scriptState.seekLevel = _vm->_gamestate->_executionStack.size() - 1;
+ scriptState.debugging = true;
- return true;
+ return false;
}
bool Console::cmdStepGlobal(int argc, const char **argv) {
@@ -2124,8 +2127,9 @@ bool Console::cmdStepGlobal(int argc, const char **argv) {
scriptState.seeking = kDebugSeekGlobal;
scriptState.seekSpecial = atoi(argv[1]);
+ scriptState.debugging = true;
- return true;
+ return false;
}
bool Console::cmdStepCallk(int argc, const char **argv) {
@@ -2156,8 +2160,9 @@ bool Console::cmdStepCallk(int argc, const char **argv) {
} else {
scriptState.seeking = kDebugSeekCallk;
}
+ scriptState.debugging = true;
- return true;
+ return false;
}
bool Console::cmdDissassemble(int argc, const char **argv) {
@@ -2227,7 +2232,7 @@ bool Console::cmdDissassembleAddress(int argc, const char **argv) {
_vm->_gamestate->seg_manager->dereference(vpc, &size);
size += vpc.offset; // total segment size
- for (int i = 1; i < argc; i++) {
+ for (int i = 2; i < argc; i++) {
if (!scumm_stricmp(argv[i], "bwt"))
do_bwc = 1;
else if (!scumm_stricmp(argv[i], "bc"))
@@ -2322,14 +2327,16 @@ bool Console::cmdSend(int argc, const char **argv) {
xstack->fp += argc;
_vm->_gamestate->_executionStackPosChanged = true;
+ scriptState.debugging = true;
- return true;
+ return false;
}
bool Console::cmdGo(int argc, const char **argv) {
+ // CHECKME: is this necessary?
scriptState.seeking = kDebugSeekNothing;
- return true;
+ return Cmd_Exit(argc, argv);
}
bool Console::cmdBreakpointList(int argc, const char **argv) {
diff --git a/engines/sci/debug.h b/engines/sci/debug.h
index cd2de2b3a9..a3c4fab372 100644
--- a/engines/sci/debug.h
+++ b/engines/sci/debug.h
@@ -38,6 +38,7 @@ enum DebugSeeking {
};
struct ScriptState {
+ bool debugging;
bool stopOnEvent;
DebugSeeking seeking; // Stepping forward until some special condition is met
int runningStep; // Set to > 0 to allow multiple stepping
diff --git a/engines/sci/engine/scriptdebug.cpp b/engines/sci/engine/scriptdebug.cpp
index 92cfe9daf3..11dd56f2aa 100644
--- a/engines/sci/engine/scriptdebug.cpp
+++ b/engines/sci/engine/scriptdebug.cpp
@@ -311,11 +311,18 @@ reg_t disassemble(EngineState *s, reg_t pos, int print_bw_tag, int print_bytecod
void script_debug(EngineState *s, bool bp) {
// Do we support a separate console?
- printf("%d: acc=%04x:%04x ", script_step_counter, PRINT_REG(s->r_acc));
- disassemble(s, scriptState.xs->addr.pc, 0, 1);
- if (scriptState.seeking == kDebugSeekGlobal)
- printf("Global %d (0x%x) = %04x:%04x\n", scriptState.seekSpecial,
- scriptState.seekSpecial, PRINT_REG(s->script_000->locals_block->_locals[scriptState.seekSpecial]));
+ /* if (sci_debug_flags & _DEBUG_FLAG_LOGGING) { */
+ printf("%d: acc=%04x:%04x ", script_step_counter, PRINT_REG(s->r_acc));
+ disassemble(s, scriptState.xs->addr.pc, 0, 1);
+ if (scriptState.seeking == kDebugSeekGlobal)
+ printf("Global %d (0x%x) = %04x:%04x\n", scriptState.seekSpecial,
+ scriptState.seekSpecial, PRINT_REG(s->script_000->locals_block->_locals[scriptState.seekSpecial]));
+ /* } */
+
+#if 0
+ if (!scriptState.debugging)
+ return;
+#endif
if (scriptState.seeking && !bp) { // Are we looking for something special?
MemObject *mobj = GET_SEGMENT(*s->seg_manager, scriptState.xs->addr.pc.segment, MEM_OBJ_SCRIPT);
@@ -370,9 +377,19 @@ void script_debug(EngineState *s, bool bp) {
// OK, found whatever we were looking for
}
}
-
+
printf("Step #%d\n", script_step_counter);
disassemble(s, scriptState.xs->addr.pc, 0, 1);
+
+ if (scriptState.runningStep) {
+ scriptState.runningStep--;
+ return;
+ }
+
+ scriptState.debugging = false;
+
+ Console *con = ((Sci::SciEngine*)g_engine)->getSciDebugger();
+ con->attach();
}
} // End of namespace Sci
diff --git a/engines/sci/engine/seg_manager.cpp b/engines/sci/engine/seg_manager.cpp
index 6752ba3e56..905cba9d94 100644
--- a/engines/sci/engine/seg_manager.cpp
+++ b/engines/sci/engine/seg_manager.cpp
@@ -169,7 +169,9 @@ int SegManager::initialiseScript(Script &scr, EngineState *s, int script_nr) {
setScriptSize(scr, s, script_nr);
scr.buf = (byte *)malloc(scr.buf_size);
- dbgPrint("scr.buf ", scr.buf);
+#ifdef DEBUG_SEG_MANAGER
+ printf("scr.buf = %p ", scr.buf);
+#endif
if (!scr.buf) {
scr.freeScript();
warning("SegManager: Not enough memory space for script size");
@@ -864,14 +866,5 @@ int SegManager::freeDynmem(reg_t addr) {
return 0; // OK
}
-void SegManager::dbgPrint(const char* msg, void *i) {
-#ifdef DEBUG_SEG_MANAGER
- char buf[1000];
- sprintf(buf, "%s = [0x%x], dec:[%d]", msg, i, i);
- perror(buf);
-#endif
-}
-
-
} // End of namespace Sci
diff --git a/engines/sci/engine/seg_manager.h b/engines/sci/engine/seg_manager.h
index a41d820014..9d406f559f 100644
--- a/engines/sci/engine/seg_manager.h
+++ b/engines/sci/engine/seg_manager.h
@@ -362,13 +362,6 @@ private:
* 'seg' is a valid segment
*/
bool check(SegmentId seg);
-
- void dbgPrint(const char* msg, void *i); // for debug only
-
- // Perform garbage collection
- // Parameters: (EngineState *) s: The state to operate on
- // Effects : Unreachable objects in 's' are deallocated
- //void sm_gc(EngineState *s);
};
} // End of namespace Sci
diff --git a/engines/sci/engine/vm.cpp b/engines/sci/engine/vm.cpp
index 99b5a86e53..0f8fee0876 100644
--- a/engines/sci/engine/vm.cpp
+++ b/engines/sci/engine/vm.cpp
@@ -258,6 +258,7 @@ ExecStack *execute_method(EngineState *s, uint16 script, uint16 pubfunct, StackP
if (bp->type == BREAK_EXPORT && bp->data.address == bpaddress) {
Console *con = ((SciEngine *)g_engine)->getSciDebugger();
con->DebugPrintf("Break on script %d, export %d\n", script, pubfunct);
+ scriptState.debugging = true;
breakpointFlag = true;
break;
}
@@ -325,6 +326,7 @@ ExecStack *send_selector(EngineState *s, reg_t send_obj, reg_t work_obj, StackPt
con->DebugPrintf("Break on %s (in [%04x:%04x])\n", method_name, PRINT_REG(send_obj));
print_send_action = 1;
breakpointFlag = true;
+ scriptState.debugging = true;
break;
}
bp = bp->next;
@@ -652,17 +654,19 @@ void run_vm(EngineState *s, int restoring) {
}
- if (script_abort_flag)
+ if (script_abort_flag || g_engine->shouldQuit())
return; // Emergency
-// TODO: re-enable this
-#if 0
// Debug if this has been requested:
- if (script_debug_flag || sci_debug_flags) {
+ // TODO: re-implement sci_debug_flags
+ if (scriptState.debugging /* sci_debug_flags*/) {
script_debug(s, breakpointFlag);
breakpointFlag = false;
}
-#endif
+ Console *con = ((Sci::SciEngine*)g_engine)->getSciDebugger();
+ if (con->isAttached()) {
+ con->onFrame();
+ }
#ifndef DISABLE_VALIDATIONS
if (scriptState.xs->sp < scriptState.xs->fp)
diff --git a/engines/sci/engine/vm.h b/engines/sci/engine/vm.h
index f711570d11..ba225a9c00 100644
--- a/engines/sci/engine/vm.h
+++ b/engines/sci/engine/vm.h
@@ -266,18 +266,19 @@ struct ExecStack {
};
+// These types are used both as identifiers and as elements of bitfields
enum BreakpointType {
/**
* Break when selector is executed. data contains (char *) selector name
* (in the format Object::Method)
*/
- BREAK_SELECTOR,
+ BREAK_SELECTOR = 1,
/**
* Break when an exported function is called. data contains
* script_no << 16 | export_no.
*/
- BREAK_EXPORT
+ BREAK_EXPORT = 2
};
struct Breakpoint {
diff --git a/engines/sci/gfx/operations.cpp b/engines/sci/gfx/operations.cpp
index 5604166794..b3a1be68d1 100644
--- a/engines/sci/gfx/operations.cpp
+++ b/engines/sci/gfx/operations.cpp
@@ -1383,7 +1383,6 @@ static sci_event_t scummvm_get_event(GfxDriver *drv) {
// Open debug console
Console *con = ((Sci::SciEngine*)g_engine)->getSciDebugger();
con->attach();
- con->onFrame();
// Clear keyboard event
input.type = SCI_EVT_NONE;
diff --git a/engines/sci/resource.cpp b/engines/sci/resource.cpp
index d99f9f0771..943361332f 100644
--- a/engines/sci/resource.cpp
+++ b/engines/sci/resource.cpp
@@ -882,7 +882,7 @@ void ResourceManager::processPatch(ResourceSource *source, ResourceType restype,
if (resnumber == -1)
return;
if (!file.open(source->location_name)) {
- perror("""__FILE__"": (""__LINE__""): failed to open");
+ warning("ResourceManager::processPatch(): failed to open %s", source->location_name.c_str());
return;
}
fsize = file.size();
@@ -1007,8 +1007,7 @@ int ResourceManager::readResourceMapSCI0(ResourceSource *map) {
offset = file.readUint32LE();
if (file.ioFailed()) {
- warning("Error while reading %s: ", map->location_name.c_str());
- perror("");
+ warning("Error while reading %s", map->location_name.c_str());
return SCI_ERROR_RESMAP_NOT_FOUND;
}
if (offset == 0xFFFFFFFF)
@@ -1079,8 +1078,7 @@ int ResourceManager::readResourceMapSCI1(ResourceSource *map) {
}
}
if (file.ioFailed()) {
- warning("Error while reading %s: ", map->location_name.c_str());
- perror("");
+ warning("Error while reading %s", map->location_name.c_str());
return SCI_ERROR_RESMAP_NOT_FOUND;
}
resId = ResourceId((ResourceType)type, number);
diff --git a/engines/sci/sci.cpp b/engines/sci/sci.cpp
index af8aac3147..3e434e4f02 100644
--- a/engines/sci/sci.cpp
+++ b/engines/sci/sci.cpp
@@ -289,9 +289,7 @@ uint32 SciEngine::getFlags() const {
}
Common::String SciEngine::getSavegameName(int nr) const {
- char extension[6];
- snprintf(extension, sizeof(extension), ".%03d", nr);
- return _targetName + extension;
+ return _targetName + Common::String::printf(".%03d", nr);
}
Common::String SciEngine::getSavegamePattern() const {