From 1700d8d10453ffe046438de0e6fbd496def915a1 Mon Sep 17 00:00:00 2001 From: mrb0nk500 Date: Wed, 9 Dec 2020 21:13:40 -0500 Subject: - Made the emulator's debugger use individual windows. I mainly did this to be able to display all 16 main registers, but also to simplify the debugger. --- sux.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 70 insertions(+), 15 deletions(-) (limited to 'sux.c') diff --git a/sux.c b/sux.c index 25bd8c5..de88b92 100644 --- a/sux.c +++ b/sux.c @@ -37,6 +37,9 @@ uint8_t kbd_rdy; uint8_t end = 0; WINDOW *scr; +WINDOW *regs; +WINDOW *inst_win; +WINDOW *dbg_win; struct suxthr { struct sux sx; @@ -173,15 +176,16 @@ void *run(void *args) { #if keypoll pthread_mutex_lock(&mutex); #endif - print_regs(cpu, lines, thread); + print_info(cpu, inst_win, lines, thread); + print_regs(cpu, regs); #if keypoll pthread_mutex_unlock(&mutex); #endif #endif - uint32_t instr = read_value(cpu, 0, cpu->pc, 4, 1, 0); - uint8_t *tmp_inst = (uint8_t *)&instr; + uint32_t inst = read_value(cpu, 0, cpu->pc, 4, 1, 0); + uint8_t *tmp_inst = (uint8_t *)&inst; uint8_t inst_len = 0; - prefix = ((instr & 3) == 3) ? tmp_inst[inst_len++] : 0; + prefix = ((inst & 3) == 3) ? tmp_inst[inst_len++] : 0; ext_prefix = ((tmp_inst[inst_len] & 0xF) == 0xD) ? tmp_inst[inst_len++] : 0; opcode = tmp_inst[inst_len++]; op_id = (ext_prefix == 0x1D) ? tmp_inst[inst_len++] : 0; @@ -253,7 +257,7 @@ void *run(void *args) { #if keypoll pthread_mutex_lock(&mutex); #endif - disasm(cpu, lines, opcode, prefix, ext_prefix, prefix2, operand_type, ortho_id, thread); + disasm(cpu, inst_win, lines, opcode, prefix, ext_prefix, prefix2, operand_type, ortho_id, thread); lines+=1; #if keypoll pthread_mutex_unlock(&mutex); @@ -290,10 +294,14 @@ void *run(void *args) { int c = 0; #if debug wrefresh(scr); + wrefresh(regs); + wrefresh(inst_win); #endif for (; step && c != 19 && !end; c = get_key(scr)); #if debug wrefresh(scr); + wrefresh(regs); + wrefresh(inst_win); #endif } #endif @@ -301,13 +309,16 @@ void *run(void *args) { #if keypoll pthread_mutex_lock(&mutex); #endif - wmove(scr, (6*thread)+1, 0); - wprintw(scr, "Instructions executed: %"PRIu64, ins); + wmove(inst_win, (6*thread)+1, 0); + wprintw(inst_win, "Instructions executed: %"PRIu64, ins); #if getclk - wprintw(scr, ", Clock cycles: %"PRIu64, cpu->clk); + wprintw(inst_win, ", Clock cycles: %"PRIu64, cpu->clk); #endif if (step || !subdbg) { wrefresh(scr); + wrefresh(regs); + wrefresh(inst_win); + wrefresh(dbg_win); } #if keypoll pthread_mutex_unlock(&mutex); @@ -343,7 +354,34 @@ void init_scr() { start_color(); use_default_colors(); init_pair(1, COLOR_WHITE, -1); - attron(COLOR_PAIR(1) | A_BOLD); + wattron(scr, COLOR_PAIR(1) | A_BOLD); + + #if debug + int x; + int y; + getmaxyx(scr, y, x); + if (!regs) { + regs = newwin(24, 80, 1, (x/2)); + } + nodelay(regs, 0); + keypad(regs, 1); + scrollok(regs, 1); + wattron(regs, COLOR_PAIR(1) | A_BOLD); + if (!inst_win) { + inst_win = newwin(28, (x/2)-20, 0, 0); + } + nodelay(inst_win, 0); + keypad(inst_win, 1); + scrollok(inst_win, 1); + wattron(inst_win, COLOR_PAIR(1) | A_BOLD); + if (!dbg_win) { + dbg_win = newwin(33, x, y-33, 0); + } + nodelay(dbg_win, 0); + keypad(dbg_win, 1); + scrollok(dbg_win, 1); + wattron(dbg_win, COLOR_PAIR(1) | A_BOLD); + #endif } int main(int argc, char **argv) { @@ -368,13 +406,26 @@ int main(int argc, char **argv) { return 0; } } - sprintf(tmp, "\033[2J\033[H"); + /*sprintf(tmp, "\033[2J\033[H"); fwrite(tmp, sizeof(char), strlen(tmp), stdout); - fflush(stdout); + fflush(stdout);*/ init_scr(); werase(scr); wmove(scr, 0, 0); wrefresh(scr); + #if debug + werase(regs); + wmove(regs, 0, 0); + wrefresh(regs); + + werase(inst_win); + wmove(inst_win, 0, 0); + wrefresh(inst_win); + + werase(dbg_win); + wmove(dbg_win, 0, 0); + wrefresh(dbg_win); + #endif pthread_t therads[THREADS]; int result; uint16_t vec = 0xFFC0; @@ -412,10 +463,14 @@ int main(int argc, char **argv) { thr[i].sx.sp = (i << 16) | 0xFFFF; offset = (i) ? ((i-1) << 3) : 0; vec = (i) ? 0xFF50 : 0xFFC0; - thr[i].sx.a = 0; - thr[i].sx.b = 0; - thr[i].sx.x = 0; - thr[i].sx.y = 0; + thr[i].sx.a = 0, thr[i].sx.b = 0; + thr[i].sx.x = 0, thr[i].sx.y = 0; + thr[i].sx.e = 0, thr[i].sx.c = 0; + thr[i].sx.d = 0, thr[i].sx.s = 0; + thr[i].sx.f = 0, thr[i].sx.bp = 0; + thr[i].sx.r11 = 0, thr[i].sx.r12 = 0; + thr[i].sx.r12 = 0, thr[i].sx.r13 = 0; + thr[i].sx.r14 = 0, thr[i].sx.r15 = 0; thr[i].sx.pc = read_value(&thr[i].sx, 0, vec+offset, 7, 0, 0); thr[i].th = i; #if !IO -- cgit v1.2.3-13-gbd6f