Skip to content

Commit

Permalink
refactor(zscript): remove ZASM debugger
Browse files Browse the repository at this point in the history
This was already made inaccessible from the GUI in 1da2d02, but now
it is removed entirely. Work on a real debugger will begin soon.
  • Loading branch information
connorjclark committed May 3, 2024
1 parent d44b13f commit bb5404c
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 298 deletions.
1 change: 0 additions & 1 deletion resources/base_config/zc.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ jit_threads = -2 #? web = 0

[CONSOLE]
enabled = 0
print_ZASM = 0
console_on_top = 0
monochrome_debuggers = 0
clear_console_on_load = 1
Expand Down
23 changes: 1 addition & 22 deletions resources/include/bindings/debug.zh
Original file line number Diff line number Diff line change
Expand Up @@ -135,28 +135,7 @@ class Debug {
// TRIGGERSECRETR D2
internal void TriggerSecret(int arg1);

// If the ZASM debugger is open, this will break execution, and print the
// given string.
//
// Break controls:
//
// - 'Insert' - break, or step forward if broken
// - 'Shift+Insert' - Step forward until next breakpoint, or start of next
// script, whichever comes first
// - 'Ctrl+Shift+Insert' - Same as above, but, doesn't print any ZASM until
// it breaks.
// - 'Alt+Insert' - Step forward until next breakpoint
// - 'Ctrl+Alt+Insert' - Same as above, but, doesn't print any ZASM until it
// breaks.
// - 'Ctrl+Insert' - Exit the ZASM debugger entirely
//
// If the ZASM debugger is not open, this instruction does NOTHING.
//
// Passing NULL to this function will not produce an error, instead printing
// no label
//
// In ZASM scripts, passing the 'NUL' register to this instruction will not
// produce an error, instead printing no label
// @deprecated ZASM debugger no longer exists.
//
// @zasm
// POP D3
Expand Down
213 changes: 7 additions & 206 deletions src/zc/ffscript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,6 @@ std::pair<SubscrWidget*,byte> load_subwidg(dword ref)
#include "zconsole/ConsoleLogger.h"

//no ifdef here
CConsoleLoggerEx coloured_console;
extern CConsoleLoggerEx zscript_coloured_console;

int32_t FFScript::UpperToLower(std::string *s)
Expand Down Expand Up @@ -16292,7 +16291,6 @@ int32_t get_register(int32_t arg)
}
}

if ( zasm_debugger ) FFCore.ZASMPrintVarGet(arg, ret);
return ret;
}

Expand All @@ -16301,7 +16299,6 @@ int32_t get_register(int32_t arg)

void set_register(int32_t arg, int32_t value)
{
if ( zasm_debugger ) FFCore.ZASMPrintVarSet(arg, value);
//Macros

#define SET_SPRITEDATA_VAR_INT(member, str) \
Expand Down Expand Up @@ -36159,41 +36156,6 @@ void do_freeclass()
ri->d[rEXP1] = 0;
}

bool zasm_advance()
{
if( key[KEY_INSERT] )
{
if(key[KEY_LSHIFT] || key[KEY_RSHIFT])
{
if(CHECK_CTRL_CMD)
{
FFCore.zasm_break_mode = ZASM_BREAK_SKIP_SCRIPT;
}
else FFCore.zasm_break_mode = ZASM_BREAK_ADVANCE_SCRIPT;
}
else if(key[KEY_ALT] || key[KEY_ALTGR])
{
if(CHECK_CTRL_CMD)
{
FFCore.zasm_break_mode = ZASM_BREAK_SKIP;
}
else FFCore.zasm_break_mode = ZASM_BREAK_NONE;
}
else if(CHECK_CTRL_CMD)
{
FFCore.ZASMPrint(false); //Close debugger
FFCore.zasm_break_mode = ZASM_BREAK_NONE;
}
return true;
}
if(!zasm_debugger)
{
FFCore.zasm_break_mode = ZASM_BREAK_NONE;
return true;
}
return false;
}

int32_t get_own_i(ScriptType type)
{
switch(type)
Expand Down Expand Up @@ -36489,26 +36451,6 @@ int32_t run_script_int(bool is_jitted)
}

#endif

if( FFCore.zasm_break_mode == ZASM_BREAK_ADVANCE_SCRIPT || FFCore.zasm_break_mode == ZASM_BREAK_SKIP_SCRIPT )
{
if( zasm_debugger )
{
//Halt on new script if set to advance to next script
FFCore.zasm_break_mode = ZASM_BREAK_HALT;
FFCore.TraceScriptIDs(true);
coloured_console.safeprint((CConsoleLoggerEx::COLOR_RED |
CConsoleLoggerEx::COLOR_BACKGROUND_BLACK),"Breaking for script start\n");
}
else FFCore.zasm_break_mode = ZASM_BREAK_NONE;
}
else if( zasm_debugger && !(SKIPZASMPRINT()))
{
//Print new script metadata when starting script
FFCore.TraceScriptIDs(true);
coloured_console.safeprint((CConsoleLoggerEx::COLOR_RED |
CConsoleLoggerEx::COLOR_BACKGROUND_BLACK),"Start of script\n");
}
}
//j_command
bool is_debugging = script_debug_is_runtime_debugging() == 2;
Expand Down Expand Up @@ -36673,23 +36615,6 @@ int32_t run_script_int(bool is_jitted)
scommand=0xFFFF;
}

//Handle manual breaking
if( zasm_debugger && zc_readrawkey(KEY_INSERT, true))
FFCore.zasm_break_mode = ZASM_BREAK_HALT;
//Break
while( FFCore.zasm_break_mode == ZASM_BREAK_HALT )
{
poll_keyboard();
if(zasm_advance()) break;
checkQuitKeys();
if(Quit)
{
scommand=0xFFFF;
break;
}
}

if ( zasm_debugger ) FFCore.ZASMPrintCommand(scommand);
switch(scommand)
{
//always first
Expand Down Expand Up @@ -37732,10 +37657,7 @@ int32_t run_script_int(bool is_jitted)
}

case BREAKPOINT:
if( zasm_debugger )
{
FFCore.do_breakpoint();
}
FFCore.do_breakpoint();
break;

case WARP:
Expand Down Expand Up @@ -43538,12 +43460,6 @@ void FFScript::init()
eventData.clear();
countGenScripts();
for ( int32_t q = 0; q < wexLast; q++ ) warpex[q] = 0;
print_ZASM = zasm_debugger;
if ( zasm_debugger )
{
ZASMPrint(true);
zasm_break_mode = ZASM_BREAK_HALT;
}

temp_no_stepforward = 0;
nostepforward = 0;
Expand All @@ -43561,7 +43477,6 @@ void FFScript::init()
for ( int32_t q = 0; q < susptLAST; q++ ) { system_suspend[q] = 0; }
for ( int32_t q = 0; q < UID_TYPES; ++q ) { script_UIDs[q] = 0; }
//for ( int32_t q = 0; q < 512; q++ ) FF_rules[q] = 0;
FFCore.zasm_break_mode = ZASM_BREAK_NONE;

usr_midi_volume = midi_volume;
usr_digi_volume = digi_volume;
Expand Down Expand Up @@ -46104,97 +46019,6 @@ void FFScript::ZScriptConsole(bool open)
zc_set_config("CONSOLE","enabled",console_enabled);
}

void FFScript::ZASMPrint(bool open)
{
if(SKIPZASMPRINT()) return;
zprint("%s ZASM Console\n", open ? "Opening" : "Closing");
if ( open )
{
coloured_console.Create("ZASM Debugger", 600, 200, NULL, NULL);
coloured_console.cls(CConsoleLoggerEx::COLOR_BACKGROUND_BLACK);
coloured_console.gotoxy(0,0);
coloured_console.safeprint( CConsoleLoggerEx::COLOR_GREEN | CConsoleLoggerEx::COLOR_INTENSITY |
CConsoleLoggerEx::COLOR_BACKGROUND_BLACK,"ZASM Stack Trace:\n");
//coloured_console.SetAsDefaultOutput();
zasm_debugger = 1;
zasm_break_mode = ZASM_BREAK_HALT;
}
else
{
//close
coloured_console.Close();
zasm_debugger = 0;
}
zc_set_config("CONSOLE","print_ZASM",zasm_debugger);
}

void FFScript::ZASMPrintCommand(const word scommand)
{
if(SKIPZASMPRINT()) return;
//if ( !zasm_debugger ) return;

auto& s_c = get_script_command(scommand);

static const auto color_blue = CConsoleLoggerEx::COLOR_BLUE|CConsoleLoggerEx::COLOR_INTENSITY|
CConsoleLoggerEx::COLOR_BACKGROUND_BLACK;
static const auto color_red = CConsoleLoggerEx::COLOR_RED|CConsoleLoggerEx::COLOR_INTENSITY|
CConsoleLoggerEx::COLOR_BACKGROUND_BLACK;
static const auto color_white = CConsoleLoggerEx::COLOR_WHITE|CConsoleLoggerEx::COLOR_BACKGROUND_BLACK;
if(s_c.args)
{
coloured_console.cprintf(color_blue,"%14s: ", s_c.name);
int sargs[] = {sarg1,sarg2,sarg3};
for(int q = 0; q < s_c.args; ++q)
{
bool end = q == (s_c.args-1);
if(s_c.arg_type[q] == ARGTY::LITERAL)
{
coloured_console.cprintf(color_red,"%10s (val = %2d)%s", "immediate", sargs[q], end ? "\n" : ", ");
}
else if(s_c.arg_type[q] == ARGTY::COMPARE_OP)
{
coloured_console.cprintf(color_red,"%10s (%s)", "compare", CMP_STR(sargs[q]).c_str(), end ? "\n" : ", ");
}
else //ARGTY::UNUSED_REG, ARGTY::READ_REG, ARGTY::WRITE_REG, ARGTY::READWRITE_REG
{
coloured_console.cprintf(color_white,"\t %s (val = %2d)%s", zasm_var_to_string(sargs[q]).c_str(), get_register(sargs[q]), end ? "\n" : ", ");
}
}
}
else coloured_console.cprintf(color_blue,"%14s\n",s_c.name);
}


void FFScript::ZASMPrintVarSet(const int32_t arg, int32_t argval)
{
if(SKIPZASMPRINT()) return;

//if ( !zasm_debugger ) return;
// script_variable s_v = variable_list[arg];
//s_v.name is the string with the instruction
coloured_console.cprintf( CConsoleLoggerEx::COLOR_WHITE |
CConsoleLoggerEx::COLOR_BACKGROUND_BLACK,"Set: %s\t",zasm_var_to_string(arg).c_str());
coloured_console.cprintf( CConsoleLoggerEx::COLOR_GREEN | CConsoleLoggerEx::COLOR_INTENSITY |
CConsoleLoggerEx::COLOR_BACKGROUND_BLACK,"%d\n",argval);
//coloured_console.print();
}

void FFScript::ZASMPrintVarGet(const int32_t arg, int32_t argval)
{
if(SKIPZASMPRINT()) return;

//if ( !zasm_debugger ) return;
// script_variable s_v = variable_list[arg];
//s_v.name is the string with the instruction
coloured_console.cprintf( CConsoleLoggerEx::COLOR_WHITE |
CConsoleLoggerEx::COLOR_BACKGROUND_BLACK,"Get: %s\t",zasm_var_to_string(arg).c_str());
coloured_console.cprintf( CConsoleLoggerEx::COLOR_GREEN | CConsoleLoggerEx::COLOR_INTENSITY |
CConsoleLoggerEx::COLOR_BACKGROUND_BLACK,"%d\n",argval);
//coloured_console.print();
}



///----------------------------------------------------------------------------------------------------//
//Tracing

Expand Down Expand Up @@ -46780,28 +46604,7 @@ void FFScript::do_varg_makearray(ScriptType type, const uint32_t UID)

void FFScript::do_breakpoint()
{
int32_t arrayptr = get_register(sarg1) / 10000;
string str;
if(arrayptr && sarg1 != NUL)
{
ArrayH::getString(arrayptr, str, 512);
str = "Breakpoint: " + str + "\n";
}
else str = "Breakpoint\n";
TraceScriptIDs();
al_trace("%s", str.c_str());

if ( console_enabled )
{
zscript_coloured_console.safeprint((CConsoleLoggerEx::COLOR_RED |
CConsoleLoggerEx::COLOR_BACKGROUND_BLACK),str.c_str());
}
if( zasm_debugger )
{
FFCore.zasm_break_mode = ZASM_BREAK_HALT; //Halt ZASM debugger; break execution
coloured_console.safeprint((CConsoleLoggerEx::COLOR_RED |
CConsoleLoggerEx::COLOR_BACKGROUND_BLACK),str.c_str());
}
// TODO: implement as `debugger;` statement when VS Code extension exists.
}

void FFScript::do_tracenl()
Expand All @@ -46816,13 +46619,12 @@ void FFScript::do_tracenl()
}


void FFScript::TraceScriptIDs(bool zasm_console)
void FFScript::TraceScriptIDs()
{
if(DEVTIMESTAMP)
{
if(!zasm_debugger && zasm_console) return;
CConsoleLoggerEx console = (zasm_console ? coloured_console : zscript_coloured_console);
bool cond = (zasm_console ? zasm_debugger : console_enabled);
CConsoleLoggerEx console = zscript_coloured_console;
bool cond = console_enabled;

char buf[256] = {0};
//Calculate timestamp
Expand All @@ -46840,9 +46642,8 @@ void FFScript::TraceScriptIDs(bool zasm_console)
}
if(get_qr(qr_TRACESCRIPTIDS) || DEVLOGGING )
{
if(!zasm_debugger && zasm_console) return;
CConsoleLoggerEx console = (zasm_console ? coloured_console : zscript_coloured_console);
bool cond = (zasm_console ? zasm_debugger : console_enabled);
CConsoleLoggerEx console = zscript_coloured_console;
bool cond = console_enabled;
char buf[256] = {0};
if(script_funcrun)
{
Expand Down
19 changes: 1 addition & 18 deletions src/zc/ffscript.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,6 @@ enum herospritetype
LSprholdsprSw2, LSprsideswimcastingspr, LSprsidedrownspr, LSprrevslashspr, LSprlast
};

enum zasmBreak
{
ZASM_BREAK_NONE,
ZASM_BREAK_HALT,
ZASM_BREAK_ADVANCE_SCRIPT,
ZASM_BREAK_SKIP_SCRIPT,
ZASM_BREAK_SKIP
};
#define SKIPZASMPRINT() (FFCore.zasm_break_mode == ZASM_BREAK_SKIP_SCRIPT || FFCore.zasm_break_mode == ZASM_BREAK_SKIP)

//suspend types
enum {
//Typical processes that we want to pause, similar to ALLOFF()
Expand Down Expand Up @@ -916,16 +906,11 @@ void do_trace(bool v);
void do_tracel(bool v);
void do_tracenl();
void do_cleartrace();
bool print_ZASM;
void do_tracetobase();
void ZScriptConsole(bool open);
template <typename ...Params>
void ZScriptConsole(int32_t attributes,const char *format, Params&&... params);
void TraceScriptIDs(bool zasm_console = false);
void ZASMPrint(bool open);
void ZASMPrintCommand(const word scommand);
void ZASMPrintVarSet(const int32_t arg, int32_t argval);
void ZASMPrintVarGet(const int32_t arg, int32_t argval);
void TraceScriptIDs();
/*
int32_t getQuestHeaderInfo(int32_t type)
{
Expand Down Expand Up @@ -1080,8 +1065,6 @@ byte ScriptDrawingRules[SCRIPT_DRAWING_RULES];
#define NUM_USER_MIDI_OVERRIDES 6
int32_t FF_UserMidis[NUM_USER_MIDI_OVERRIDES]; //MIDIs to use for Game Over, and similar to override system defaults.

byte zasm_break_mode;

//Enemy removal bounds
int32_t enemy_removal_point[6];

Expand Down

0 comments on commit bb5404c

Please sign in to comment.