- [NEW] La consola mostra un log dels ultims comandos i resultats, com un terminal
- [NEW] La consola te un històric de comandos executats, com un terminal (navegar abm cursors amunt i avall)
This commit is contained in:
85
z80debug.cpp
85
z80debug.cpp
@@ -51,8 +51,12 @@ namespace z80debug
|
||||
bool is_debugging=false;
|
||||
bool is_paused=false;
|
||||
uint16_t mem_viewer_pos = 0;
|
||||
char console[256];
|
||||
char console_error[256];
|
||||
|
||||
char console_log[256][256];
|
||||
char console_history[256][256];
|
||||
uint8_t console_log_pos = 255;
|
||||
uint8_t console_history_pos = 0;
|
||||
uint8_t console_history_nav = 0;
|
||||
|
||||
uint8_t breakpoints[65536];
|
||||
|
||||
@@ -114,12 +118,14 @@ namespace z80debug
|
||||
z80debug::refresh();
|
||||
zxscreen::refresh(dt);*/
|
||||
} else if (e->key.keysym.scancode==SDL_SCANCODE_UP) {
|
||||
z80debug::cursorback();
|
||||
if (console_history_nav != console_history_pos+1 && console_history[console_history_nav-1][0]!=0) console_history_nav--;
|
||||
//z80debug::cursorback();
|
||||
z80debug::refresh();
|
||||
} else if (e->key.keysym.scancode==SDL_SCANCODE_DOWN) {
|
||||
z80debug::cursorfwd();
|
||||
if (console_history_nav != console_history_pos) console_history_nav++;
|
||||
//z80debug::cursorfwd();
|
||||
z80debug::refresh();
|
||||
} else if (e->key.keysym.scancode==SDL_SCANCODE_RETURN) {
|
||||
} else if ( (e->key.keysym.scancode==SDL_SCANCODE_RETURN) || (e->key.keysym.scancode==SDL_SCANCODE_KP_ENTER)) {
|
||||
z80debug::executeConsole();
|
||||
} else if (e->key.keysym.scancode==SDL_SCANCODE_BACKSPACE) {
|
||||
z80debug::DeleteCharConsole();
|
||||
@@ -197,6 +203,8 @@ namespace z80debug
|
||||
if (!cur_ns) cur_ns = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZENS);
|
||||
if (!cur_we) cur_we = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZEWE);
|
||||
|
||||
memchr(console_log, 0, 65536);
|
||||
memchr(console_history, 0, 65536);
|
||||
//show();
|
||||
}
|
||||
|
||||
@@ -463,10 +471,16 @@ namespace z80debug
|
||||
ui::printtxt(3,con_y, "CONSOLE:", COLOR_WHITE);
|
||||
|
||||
ui::setoffset(1, con_y+1);
|
||||
ui::printtxt(0,0, ">", COLOR_WHITE);
|
||||
ui::printtxt(1,0, console, COLOR_WHITE);
|
||||
ui::printtxt(strlen(console)+1,0, "\x7F", COLOR_WHITE);
|
||||
ui::printtxt(1,1, console_error, COLOR_RED);
|
||||
line = con_h-3;
|
||||
|
||||
ui::printtxt(0,line, ">", COLOR_WHITE);
|
||||
ui::printtxt(1,line, console_history[console_history_nav], COLOR_WHITE);
|
||||
ui::printtxt(strlen(console_history[console_history_nav])+1,line, "\x7F", COLOR_WHITE);
|
||||
uint8_t i = console_log_pos;
|
||||
while (line>0) {
|
||||
line--;
|
||||
ui::printtxt(1,line, console_log[i--], COLOR_GRAY);
|
||||
}
|
||||
|
||||
|
||||
// SYMBOLS
|
||||
@@ -505,21 +519,44 @@ namespace z80debug
|
||||
|
||||
void sendToConsole(const char* text)
|
||||
{
|
||||
if (strlen(console)+strlen(text)<256) strcat(console, text);
|
||||
if (console_history_nav != console_history_pos) {
|
||||
strcpy(console_history[console_history_pos], console_history[console_history_nav]);
|
||||
console_history_nav=console_history_pos;
|
||||
}
|
||||
|
||||
if (strlen(console_history[console_history_pos])+strlen(text)<256) strcat(console_history[console_history_pos], text);
|
||||
refresh();
|
||||
}
|
||||
|
||||
void sendToConsoleLog(const char *text)
|
||||
{
|
||||
strcpy(console_log[++console_log_pos], text);
|
||||
}
|
||||
|
||||
void DeleteCharConsole()
|
||||
{
|
||||
const int len = strlen(console);
|
||||
console[len-1] = 0;
|
||||
if (console_history_nav != console_history_pos) {
|
||||
strcpy(console_history[console_history_pos], console_history[console_history_nav]);
|
||||
console_history_nav=console_history_pos;
|
||||
}
|
||||
|
||||
const int len = strlen(console_history[console_history_pos]);
|
||||
console_history[console_history_pos][len-1] = 0;
|
||||
refresh();
|
||||
}
|
||||
|
||||
void executeConsole()
|
||||
{
|
||||
if (console_history_nav != console_history_pos) {
|
||||
strcpy(console_history[console_history_pos], console_history[console_history_nav]);
|
||||
console_history_nav=console_history_pos;
|
||||
}
|
||||
strcpy(console_log[++console_log_pos], ">");
|
||||
strcat(console_log[console_log_pos], console_history[console_history_pos]);
|
||||
processCommand();
|
||||
console[0]=0;
|
||||
console_history_pos++;
|
||||
console_history_nav=console_history_pos;
|
||||
console_history[console_history_pos][0] = 0;
|
||||
refresh();
|
||||
}
|
||||
|
||||
@@ -560,10 +597,9 @@ namespace z80debug
|
||||
|
||||
void processCommand()
|
||||
{
|
||||
console_error[0]=0;
|
||||
char cmd[256];
|
||||
int i=0;
|
||||
char *console_ptr = console;
|
||||
char *console_ptr = console_history[console_history_pos];
|
||||
|
||||
getcmd();
|
||||
|
||||
@@ -583,7 +619,7 @@ namespace z80debug
|
||||
getcmd();
|
||||
if (cmd[0] == 0) { breakpoints[z80::getPC()]=1; return; }
|
||||
int address = getnum(cmd);
|
||||
if (address<0 || address>65536) { strcpy(console_error, "Illegal break address"); return; }
|
||||
if (address<0 || address>65536) { sendToConsoleLog("Illegal break address"); return; }
|
||||
getcmd();
|
||||
uint8_t break_type = 1;
|
||||
if (cmd[0]!=0) {
|
||||
@@ -594,7 +630,7 @@ namespace z80debug
|
||||
} else if (strcmp(cmd, "w")==0 || strcmp(cmd, "write")==0) {
|
||||
break_type = 4;
|
||||
} else {
|
||||
strcpy(console_error, "Illegal break type");
|
||||
sendToConsoleLog("Illegal break type");
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -604,7 +640,7 @@ namespace z80debug
|
||||
if (strcmp(cmd, "all")==0) { for (int i=0;i<65536;++i) breakpoints[i]=0; return; }
|
||||
if (cmd[0] == 0) { breakpoints[z80::getPC()]=0; return; }
|
||||
int address = getnum(cmd);
|
||||
if (address<0 || address>65536) { strcpy(console_error, "Illegal address"); return; }
|
||||
if (address<0 || address>65536) { sendToConsoleLog("Illegal address"); return; }
|
||||
getcmd();
|
||||
uint8_t break_type = 7;
|
||||
if (cmd[0]!=0) {
|
||||
@@ -615,7 +651,7 @@ namespace z80debug
|
||||
} else if (strcmp(cmd, "w")==0 || strcmp(cmd, "write")==0) {
|
||||
break_type = 4;
|
||||
} else {
|
||||
strcpy(console_error, "Illegal break type");
|
||||
sendToConsoleLog("Illegal break type");
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -623,7 +659,7 @@ namespace z80debug
|
||||
} else if (strcmp(cmd, "m")==0 || strcmp(cmd, "mem")==0) {
|
||||
getcmd();
|
||||
int address = getnum(cmd);
|
||||
if (address<0 || address>65536) { strcpy(console_error, "Illegal memory address"); return; }
|
||||
if (address<0 || address>65536) { sendToConsoleLog("Illegal memory address"); return; }
|
||||
mem_viewer_pos = address;
|
||||
} else if (strcmp(cmd, "st")==0 || strcmp(cmd, "save")==0) {
|
||||
getcmd();
|
||||
@@ -661,7 +697,8 @@ namespace z80debug
|
||||
int address = getnum(cmd);
|
||||
uint8_t *mem = z80::getMem();
|
||||
int value = mem[address];
|
||||
SDL_itoa(value, console_error, 10);
|
||||
char tmp[10];
|
||||
sendToConsoleLog(SDL_itoa(value, tmp, 10));
|
||||
} else if (strcmp(cmd, "reg")==0) {
|
||||
getcmd();
|
||||
if (strcmp(cmd, "f")==0) { getcmd(); int value = getnum(cmd); z80::getRegs()[0] = value; }
|
||||
@@ -672,11 +709,11 @@ namespace z80debug
|
||||
else if (strcmp(cmd, "d")==0) { getcmd(); int value = getnum(cmd); z80::getRegs()[5] = value; }
|
||||
else if (strcmp(cmd, "l")==0) { getcmd(); int value = getnum(cmd); z80::getRegs()[6] = value; }
|
||||
else if (strcmp(cmd, "h")==0) { getcmd(); int value = getnum(cmd); z80::getRegs()[7] = value; }
|
||||
else { strcpy(console_error, "Syntax error: invalid register"); return; }
|
||||
else { sendToConsoleLog("Syntax error: invalid register"); return; }
|
||||
} else if (strcmp(cmd, "g")==0 || strcmp(cmd, "goto")==0) {
|
||||
getcmd();
|
||||
int address = getnum(cmd);
|
||||
if (address<0 || address>=65536) { strcpy(console_error, "Illegal address"); return; }
|
||||
if (address<0 || address>=65536) { sendToConsoleLog("Illegal address"); return; }
|
||||
if (z80::getMemTag(address)!=MEMTAG_INST) address = find_previous_opcode(address);
|
||||
z80debug::setcursor(address);
|
||||
}
|
||||
@@ -703,7 +740,7 @@ namespace z80debug
|
||||
void loadngo(const char* filename, const char* addr)
|
||||
{
|
||||
int address = getnum(addr);
|
||||
if (address<0 || address>65536) { strcpy(console_error, "Illegal offset"); return; }
|
||||
if (address<0 || address>65536) { sendToConsoleLog("Illegal offset"); return; }
|
||||
|
||||
FILE *f = fopen(filename, "rb");
|
||||
fseek(f, 0, SEEK_END);
|
||||
|
||||
@@ -17,6 +17,7 @@ namespace z80debug
|
||||
|
||||
void refresh();
|
||||
void sendToConsole(const char* text);
|
||||
void sendToConsoleLog(const char *text);
|
||||
void DeleteCharConsole();
|
||||
void executeConsole();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user