ULTIMA8: Shifting UCMachine console methods to Debugger

This commit is contained in:
Paul Gilbert 2020-02-22 10:32:55 -08:00
parent 142a65d1ae
commit 67a5d0d7e3
4 changed files with 143 additions and 141 deletions

View File

@ -42,6 +42,7 @@
#include "ultima/ultima8/kernel/object_manager.h"
#include "ultima/ultima8/misc/id_man.h"
#include "ultima/ultima8/usecode/uc_machine.h"
#include "ultima/ultima8/usecode/bit_set.h"
#include "ultima/ultima8/world/world.h"
#include "ultima/ultima8/world/get_object.h"
#include "ultima/ultima8/world/item_factory.h"
@ -130,6 +131,17 @@ Debugger::Debugger() : Shared::Debugger() {
registerCmd("QuickAvatarMoverProcess::toggleQuarterSpeed", WRAP_METHOD(Debugger, cmdToggleQuarterSpeed));
registerCmd("QuickAvatarMoverProcess::toggleClipping", WRAP_METHOD(Debugger, cmdToggleClipping));
registerCmd("UCMachine::getGlobal", WRAP_METHOD(Debugger, cmdGetGlobal));
registerCmd("UCMachine::setGlobal", WRAP_METHOD(Debugger, cmdSetGlobal));
#ifdef DEBUG
registerCmd("UCMachine::traceObjID", WRAP_METHOD(Debugger, cmdTraceObjID));
registerCmd("UCMachine::tracePID", WRAP_METHOD(Debugger, cmdTracePID));
registerCmd("UCMachine::traceClass", WRAP_METHOD(Debugger, cmdTraceClass));
registerCmd("UCMachine::traceEvents", WRAP_METHOD(Debugger, cmdTraceEvents));
registerCmd("UCMachine::traceAll", WRAP_METHOD(Debugger, cmdTraceAll));
registerCmd("UCMachine::stopTrace", WRAP_METHOD(Debugger, cmdStopTrace));
#endif
registerCmd("FastAreaVisGump::toggle", WRAP_METHOD(Debugger, cmdToggleFastArea));
registerCmd("InverterProcess::invertScreen", WRAP_METHOD(Debugger, cmdInvertScreen));
registerCmd("MenuGump::showMenu", WRAP_METHOD(Debugger, cmdShowMenu));
@ -1278,6 +1290,123 @@ bool Debugger::cmdToggleClipping(int argc, const char **argv) {
}
bool Debugger::cmdGetGlobal(int argc, const char **argv) {
UCMachine *uc = UCMachine::get_instance();
if (argc != 3) {
debugPrintf("usage: UCMachine::getGlobal offset size\n");
return true;
}
unsigned int offset = strtol(argv[1], 0, 0);
unsigned int size = strtol(argv[2], 0, 0);
pout.Print("[%04X %02X] = %d\n", offset, size,
uc->_globals->getBits(offset, size));
return true;
}
bool Debugger::cmdSetGlobal(int argc, const char **argv) {
UCMachine *uc = UCMachine::get_instance();
if (argc != 4) {
debugPrintf("usage: UCMachine::setGlobal offset size value\n");
return true;
}
unsigned int offset = strtol(argv[1], 0, 0);
unsigned int size = strtol(argv[2], 0, 0);
unsigned int value = strtol(argv[3], 0, 0);
uc->_globals->setBits(offset, size, value);
debugPrintf("[%04X %02X] = %d\n", offset, size, uc->_globals->getBits(offset, size));
return true;
}
#ifdef DEBUG
bool Debugger::cmdTracePID(int argc, const char **argv) {
if (argc != 2) {
debugPrintf("Usage: UCMachine::tracePID _pid\n");
return true;
}
uint16 _pid = static_cast<uint16>(strtol(argv[1].c_str(), 0, 0));
UCMachine *uc = UCMachine::get_instance();
uc->tracing_enabled = true;
uc->trace_PIDs.insert(_pid);
debugPrintf("UCMachine: tracing process %d\n", pid);
return true;
}
bool Debugger::cmdTraceObjID(int argc, const char **argv) {
if (argc != 2) {
debugPrintf("Usage: UCMachine::traceObjID objid\n");
return true;
}
uint16 objid = static_cast<uint16>(strtol(argv[1].c_str(), 0, 0));
UCMachine *uc = UCMachine::get_instance();
uc->tracing_enabled = true;
uc->trace_ObjIDs.insert(objid);
debugPrintf("UCMachine: tracing object %d\n", objid);
return true;
}
bool Debugger::cmdTraceClass(int argc, const char **argv) {
if (argc != 2) {
debugPrintf("Usage: UCMachine::traceClass class\n");
return true;
}
uint16 ucclass = static_cast<uint16>(strtol(argv[1].c_str(), 0, 0));
UCMachine *uc = UCMachine::get_instance();
uc->tracing_enabled = true;
uc->trace_classes.insert(ucclass);
debugPrintf("UCMachine: tracing class %d\n", ucclass);
return true;
}
bool Debugger::cmdTraceAll(int argc, const char **argv) {
UCMachine *uc = UCMachine::get_instance();
uc->tracing_enabled = true;
uc->trace_all = true;
debugPrintf("UCMachine: tracing all usecode\n");
return true;
}
bool Debugger::cmdTraceEvents(int argc, const char **argv) {
UCMachine *uc = UCMachine::get_instance();
uc->tracing_enabled = true;
uc->trace_events = true;
debugPrintf("UCMachine: tracing usecode events\n");
return true;
}
bool Debugger::cmdStopTrace(const Console::ArgvType &/*argv*/) {
UCMachine *uc = UCMachine::get_instance();
uc->trace_ObjIDs.clear();
uc->trace_PIDs.clear();
uc->trace_classes.clear();
uc->tracing_enabled = false;
uc->trace_all = false;
uc->trace_events = false;
debugPrintf("Trace stopped\n");
return true;
}
#endif
bool Debugger::cmdVerifyQuit(int argc, const char **argv) {
QuitGump::verifyQuit();
return false;

View File

@ -126,6 +126,18 @@ private:
bool cmdToggleQuarterSpeed(int argc, const char **argv);
bool cmdToggleClipping(int argc, const char **argv);
// UCMachine
bool cmdGetGlobal(int argc, const char **argv);
bool cmdSetGlobal(int argc, const char **argv);
#ifdef DEBUG
bool cmdTracePID(int argc, const char **argv);
bool cmdTraceObjID(int argc, const char **argv);
bool cmdTraceClass(int argc, const char **argv);
bool cmdTraceAll(int argc, const char **argv);
bool cmdTraceEvents(int argc, const char **argv);
bool cmdStopTrace(int argc, const char **argv);
#endif
// Miscellaneous
bool cmdToggleFastArea(int argc, const char **argv);
bool cmdVerifyQuit(int argc, const char **argv);

View File

@ -96,16 +96,7 @@ UCMachine::UCMachine(Intrinsic *iset, unsigned int icount) {
_listIDs = new idMan(1, 65534, 128);
_stringIDs = new idMan(1, 65534, 256);
con->AddConsoleCommand("UCMachine::getGlobal", ConCmd_getGlobal);
con->AddConsoleCommand("UCMachine::setGlobal", ConCmd_setGlobal);
#ifdef DEBUG
con->AddConsoleCommand("UCMachine::traceObjID", ConCmd_traceObjID);
con->AddConsoleCommand("UCMachine::tracePID", ConCmd_tracePID);
con->AddConsoleCommand("UCMachine::traceClass", ConCmd_traceClass);
con->AddConsoleCommand("UCMachine::traceEvents", ConCmd_traceEvents);
con->AddConsoleCommand("UCMachine::traceAll", ConCmd_traceAll);
con->AddConsoleCommand("UCMachine::stopTrace", ConCmd_stopTrace);
tracing_enabled = false;
trace_all = false;
#endif
@ -114,17 +105,6 @@ UCMachine::UCMachine(Intrinsic *iset, unsigned int icount) {
UCMachine::~UCMachine() {
con->Print(MM_INFO, "Destroying UCMachine...\n");
con->RemoveConsoleCommand(UCMachine::ConCmd_getGlobal);
con->RemoveConsoleCommand(UCMachine::ConCmd_setGlobal);
#ifdef DEBUG
con->RemoveConsoleCommand(UCMachine::ConCmd_traceObjID);
con->RemoveConsoleCommand(UCMachine::ConCmd_tracePID);
con->RemoveConsoleCommand(UCMachine::ConCmd_traceClass);
con->RemoveConsoleCommand(UCMachine::ConCmd_traceAll);
con->RemoveConsoleCommand(UCMachine::ConCmd_stopTrace);
#endif
_ucMachine = 0;
delete _globals;
@ -2359,114 +2339,5 @@ uint32 UCMachine::I_rndRange(const uint8 *args, unsigned int /*argsize*/) {
return (lo + (getRandom() % (hi - lo + 1)));
}
void UCMachine::ConCmd_getGlobal(const Console::ArgvType &argv) {
UCMachine *uc = UCMachine::get_instance();
if (argv.size() != 3) {
pout << "usage: UCMachine::getGlobal offset size" << Std::endl;
return;
}
unsigned int offset = strtol(argv[1].c_str(), 0, 0);
unsigned int size = strtol(argv[2].c_str(), 0, 0);
pout.Print("[%04X %02X] = %d\n", offset, size,
uc->_globals->getBits(offset, size));
}
void UCMachine::ConCmd_setGlobal(const Console::ArgvType &argv) {
UCMachine *uc = UCMachine::get_instance();
if (argv.size() != 4) {
pout << "usage: UCMachine::setGlobal offset size value" << Std::endl;
return;
}
unsigned int offset = strtol(argv[1].c_str(), 0, 0);
unsigned int size = strtol(argv[2].c_str(), 0, 0);
unsigned int value = strtol(argv[3].c_str(), 0, 0);
uc->_globals->setBits(offset, size, value);
pout.Print("[%04X %02X] = %d\n", offset, size,
uc->_globals->getBits(offset, size));
}
#ifdef DEBUG
void UCMachine::ConCmd_tracePID(const Console::ArgvType &argv) {
if (argv.size() != 2) {
pout << "Usage: UCMachine::tracePID _pid" << Std::endl;
return;
}
uint16 _pid = static_cast<uint16>(strtol(argv[1].c_str(), 0, 0));
UCMachine *uc = UCMachine::get_instance();
uc->tracing_enabled = true;
uc->trace_PIDs.insert(_pid);
pout << "UCMachine: tracing process " << _pid << Std::endl;
}
void UCMachine::ConCmd_traceObjID(const Console::ArgvType &argv) {
if (argv.size() != 2) {
pout << "Usage: UCMachine::traceObjID objid" << Std::endl;
return;
}
uint16 objid = static_cast<uint16>(strtol(argv[1].c_str(), 0, 0));
UCMachine *uc = UCMachine::get_instance();
uc->tracing_enabled = true;
uc->trace_ObjIDs.insert(objid);
pout << "UCMachine: tracing object " << objid << Std::endl;
}
void UCMachine::ConCmd_traceClass(const Console::ArgvType &argv) {
if (argv.size() != 2) {
pout << "Usage: UCMachine::traceClass class" << Std::endl;
return;
}
uint16 ucclass = static_cast<uint16>(strtol(argv[1].c_str(), 0, 0));
UCMachine *uc = UCMachine::get_instance();
uc->tracing_enabled = true;
uc->trace_classes.insert(ucclass);
pout << "UCMachine: tracing class " << ucclass << Std::endl;
}
void UCMachine::ConCmd_traceAll(const Console::ArgvType &argv) {
UCMachine *uc = UCMachine::get_instance();
uc->tracing_enabled = true;
uc->trace_all = true;
pout << "UCMachine: tracing all usecode" << Std::endl;
}
void UCMachine::ConCmd_traceEvents(const Console::ArgvType &argv) {
UCMachine *uc = UCMachine::get_instance();
uc->tracing_enabled = true;
uc->trace_events = true;
pout << "UCMachine: tracing usecode events" << Std::endl;
}
void UCMachine::ConCmd_stopTrace(const Console::ArgvType &/*argv*/) {
UCMachine *uc = UCMachine::get_instance();
uc->trace_ObjIDs.clear();
uc->trace_PIDs.clear();
uc->trace_classes.clear();
uc->tracing_enabled = false;
uc->trace_all = false;
uc->trace_events = false;
}
#endif
} // End of namespace Ultima8
} // End of namespace Ultima

View File

@ -29,6 +29,7 @@
namespace Ultima {
namespace Ultima8 {
class Debugger;
class Process;
class UCProcess;
class ConvertUsecode;
@ -39,6 +40,7 @@ class UCList;
class idMan;
class UCMachine {
friend class Debugger;
public:
UCMachine(Intrinsic *iset, unsigned int icount);
~UCMachine();
@ -110,10 +112,6 @@ private:
static UCMachine *_ucMachine;
static void ConCmd_getGlobal(const Console::ArgvType &argv);
static void ConCmd_setGlobal(const Console::ArgvType &argv);
#ifdef DEBUG
// tracing
bool tracing_enabled;
@ -136,14 +134,6 @@ public:
bool trace_event() {
return (tracing_enabled && (trace_all || trace_events));
}
private:
static void ConCmd_tracePID(const Console::ArgvType &argv);
static void ConCmd_traceObjID(const Console::ArgvType &argv);
static void ConCmd_traceClass(const Console::ArgvType &argv);
static void ConCmd_traceAll(const Console::ArgvType &argv);
static void ConCmd_traceEvents(const Console::ArgvType &argv);
static void ConCmd_stopTrace(const Console::ArgvType &argv);
#endif
};