From 970aaa518f47b77f25601b7167857d8c9731c4a5 Mon Sep 17 00:00:00 2001 From: Raimon Zamora Date: Fri, 6 Dec 2024 11:53:31 +0100 Subject: [PATCH] - [FIX] ui module should only update renderer when it actually changes - [NEW] Disassembly window now can scroll with cursors or mouse wheel - [NEW] Added valgrind script and supporting file --- main.cpp | 23 +++++++++++++-- ui.cpp | 1 + valgrind-sup.txt | 12 ++++++++ valgrind.sh | 2 ++ z80.cpp | 1 + z80debug.cpp | 75 ++++++++++++++++++++++++++++-------------------- z80debug.h | 4 +++ 7 files changed, 85 insertions(+), 33 deletions(-) create mode 100644 valgrind-sup.txt create mode 100755 valgrind.sh diff --git a/main.cpp b/main.cpp index fdadab7..8c391d0 100644 --- a/main.cpp +++ b/main.cpp @@ -107,15 +107,28 @@ int main(int argc, char *argv[]) z80debug::refresh(); zxscreen::redraw(); } + if (e.type == SDL_MOUSEWHEEL) { + if (e.wheel.mouseX<46 && e.wheel.mouseY<20) { + if (e.wheel.y>0) { + z80debug::cursorback(); + z80debug::refresh(); + } else if (e.wheel.y<0) { + z80debug::cursorfwd(); + z80debug::refresh(); + } + } + } if (e.type == SDL_KEYDOWN) { if (e.key.keysym.scancode==SDL_SCANCODE_ESCAPE) { should_exit=true; break; } else if (e.key.keysym.scancode==SDL_SCANCODE_F10) { + z80debug::history::gototop(); const uint8_t dt = z80::step(); z80debug::refresh(); zxscreen::refresh(dt); zxscreen::redraw(); } else if (e.key.keysym.scancode==SDL_SCANCODE_F11) { + z80debug::history::gototop(); const uint8_t dt = z80debug::next(); zxscreen::refresh(dt); zxscreen::redraw(); @@ -133,11 +146,17 @@ int main(int argc, char *argv[]) const uint8_t dt = z80::step(); z80debug::cont(); zxscreen::refresh(dt); - } else if (e.key.keysym.scancode==SDL_SCANCODE_F6) { + /*} else if (e.key.keysym.scancode==SDL_SCANCODE_F6) { z80debug::history::gototop(); const uint8_t dt = z80::step(); z80debug::refresh(); - zxscreen::refresh(dt); + zxscreen::refresh(dt);*/ + } else if (e.key.keysym.scancode==SDL_SCANCODE_UP) { + z80debug::cursorback(); + z80debug::refresh(); + } else if (e.key.keysym.scancode==SDL_SCANCODE_DOWN) { + z80debug::cursorfwd(); + z80debug::refresh(); } else if (e.key.keysym.scancode==SDL_SCANCODE_RETURN) { z80debug::executeConsole(); } else if (e.key.keysym.scancode==SDL_SCANCODE_BACKSPACE) { diff --git a/ui.cpp b/ui.cpp index f459e74..087c400 100644 --- a/ui.cpp +++ b/ui.cpp @@ -39,6 +39,7 @@ namespace ui void setrenderer(SDL_Renderer *renderer) { if (!surf) init(); + if (ren==renderer) return; ren = renderer; if (tex) SDL_DestroyTexture(tex); tex = SDL_CreateTextureFromSurface(ren, surf); diff --git a/valgrind-sup.txt b/valgrind-sup.txt new file mode 100644 index 0000000..bd6fa5b --- /dev/null +++ b/valgrind-sup.txt @@ -0,0 +1,12 @@ +{ + ignore_unversioned_libs + Memcheck:Leak + ... + obj:*/lib*/lib*.so +} +{ + ignore_versioned_libs + Memcheck:Leak + ... + obj:*/lib*/lib*.so.* +} diff --git a/valgrind.sh b/valgrind.sh new file mode 100755 index 0000000..f6f4c9a --- /dev/null +++ b/valgrind.sh @@ -0,0 +1,2 @@ +#!/bin/bash +valgrind --tool=memcheck --leak-check=full --leak-resolution=high --suppressions=valgrind-sup.txt ./z80 \ No newline at end of file diff --git a/z80.cpp b/z80.cpp index 5374891..02ac5f0 100644 --- a/z80.cpp +++ b/z80.cpp @@ -1066,6 +1066,7 @@ namespace z80 uint32_t step() { + z80debug::setcursor(rPC); current_opcode_address = rPC; t = 0; const uint8_t opcode = READ_M1(); diff --git a/z80debug.cpp b/z80debug.cpp index 4910f11..2a67b21 100644 --- a/z80debug.cpp +++ b/z80debug.cpp @@ -30,6 +30,8 @@ namespace z80debug uint8_t breakpoints[65536]; + uint16_t cursor = 0; + char temp[256]; const char *tohex(int value, int numdigits) { @@ -112,6 +114,26 @@ namespace z80debug */ } + void printDissasemblerLine(const uint16_t address, const int line) + { + uint8_t colors[4] = { COLOR_RED, COLOR_CYAN, COLOR_GRAY, COLOR_WHITE}; + if (is_debugging && (address == z80::getPC())) { + for (int i=0; i<4;++i) colors[i]=COLOR_YELLOW; + ui::printrect(0,line, 44,1, COLOR_BLUE); + } + + if (breakpoints[address]&9) ui::printtxt(0,line,"*", colors[0]); + ui::printtxt(1,line,tohex(address,4), colors[1]); + + if (z80::getMemTag(address)==MEMTAG_INST) { + ui::printtxt(7,line, z80dis::getOpcode(address), colors[2]); + ui::printtxt(19,line, z80dis::getAsm(address), colors[3]); + } else { + ui::printtxt(7,line, tohex(z80::getMem()[address],2), COLOR_GRAY); + ui::printtxt(19,line, "?????????", COLOR_GRAY); + } + } + void refresh() { ui::setrenderer(ren); @@ -125,49 +147,24 @@ namespace z80debug ui::printtxt(3,0, "ASSEMBLER:", COLOR_WHITE); ui::setoffset(1, 1); - /*printtxt(1,0, "19C4:", COLOR_CYAN); - printtxt(7,0, "10 EE", COLOR_GRAY); - printtxt(19,0, "DJNZ 0x19B4", COLOR_WHITE); - printrect(0,1, 44,1, COLOR_BLUE); - printtxt(1,1, "19C6:", COLOR_YELLOW); - printtxt(7,1, "01 3C 00", COLOR_YELLOW); - printtxt(19,1, "LD BC,0x003C", COLOR_YELLOW);*/ - uint8_t colors[4] = { COLOR_RED, COLOR_CYAN, COLOR_GRAY, COLOR_WHITE}; - uint16_t pc = z80::getPC(); uint8_t *memory = z80::getMem(); - if (is_debugging) { - for (int i=0; i<4;++i) colors[i]=COLOR_YELLOW; - ui::printrect(0,8, 44,1, COLOR_BLUE); - } - if (breakpoints[pc]&9) ui::printtxt(0,8,"*", colors[0]); - ui::printtxt(1,8,tohex(pc,4), colors[1]); - ui::printtxt(7,8, z80dis::getOpcode(pc), colors[2]); - ui::printtxt(19,8, z80dis::getAsm(pc), colors[3]); + uint16_t pc = cursor; //z80::getPC(); uint16_t pos = pc; + + printDissasemblerLine(pc, 8); + for (int i=9;i<18;++i) { pos += z80dis::getOpcodeSize(pos); - if (breakpoints[pos]&9) ui::printtxt(0,i,"*", COLOR_RED); - ui::printtxt(1,i,tohex(pos,4), COLOR_CYAN); - ui::printtxt(7,i, z80dis::getOpcode(pos), COLOR_GRAY); - ui::printtxt(19,i, z80dis::getAsm(pos), COLOR_WHITE); + printDissasemblerLine(pos, i); } pos = pc; for (int i=7;i>=0;--i) { pos = find_previous_opcode(pos); - if (breakpoints[pos]&9) ui::printtxt(0,i,"*", COLOR_RED); - ui::printtxt(1,i,tohex(pos,4), COLOR_CYAN); - if (z80::getMemTag(pos)==MEMTAG_INST) { - ui::printtxt(7,i, z80dis::getOpcode(pos), COLOR_GRAY); - ui::printtxt(19,i, z80dis::getAsm(pos), COLOR_WHITE); - } else { - ui::printtxt(7,i, tohex(z80::getMem()[pos],2), COLOR_GRAY); - ui::printtxt(19,i, "?????????", COLOR_GRAY); - } + printDissasemblerLine(pos, i); } - //for (int i=0;i<20;++i) printtxt(1,i,tohex(pc,4), COLOR_CYAN); ui::setoffset(0, 0); ui::box(46,0,25,8,COLOR_WHITE); @@ -513,6 +510,22 @@ namespace z80debug fclose(f); } + void setcursor(const uint16_t address) + { + cursor = address; + } + + void cursorfwd() + { + cursor += z80dis::getOpcodeSize(cursor); + } + + void cursorback() + { + cursor = find_previous_opcode(cursor); + } + + namespace history { void store() diff --git a/z80debug.h b/z80debug.h index c70296f..04bf50f 100644 --- a/z80debug.h +++ b/z80debug.h @@ -27,6 +27,10 @@ namespace z80debug void loadngo(const char* filename, const char* addr); + void setcursor(const uint16_t address); + void cursorfwd(); + void cursorback(); + namespace history { void store();