From 6768c01c814d88337344cc843c9de2bf22648fb4 Mon Sep 17 00:00:00 2001 From: Raimon Zamora Date: Sat, 14 Dec 2024 09:31:52 +0100 Subject: [PATCH] =?UTF-8?q?-=20[NEW]=20La=20posici=C3=B3=20del=20cursor=20?= =?UTF-8?q?se=20marca=20amb=20un=20requadre=20blau=20(no=20relleno)=20en?= =?UTF-8?q?=20el=20desensamblador=20-=20[NEW]=20setcursor=20corregeix=20l'?= =?UTF-8?q?adre=C3=A7a=20si=20no=20coincideix=20amb=20una=20instrucci?= =?UTF-8?q?=C3=B3=20-=20[FIX]=20Corregits=20els=20opcodes=20FD34=20i=20FD3?= =?UTF-8?q?5=20-=20[NEW]=20Ara=20en=20el=20analitzador=20es=20borra=20o=20?= =?UTF-8?q?es=20fixa=20la=20mem=C3=B2ria=20amb=20DELETE=20i=20RETURN=20-?= =?UTF-8?q?=20[NEW]=20Fent=20click=20en=20un=20pixel=20del=20analitzador?= =?UTF-8?q?=20du=20a=20la=20posici=C3=B3=20de=20mem=C3=B2ria=20que=20toca?= =?UTF-8?q?=20en=20el=20desensamblador=20-=20[NEW]=20ui::printvoidrect()?= =?UTF-8?q?=20-=20[NEW]=20la=20finestra=20del=20analitzador=20pilla=20el?= =?UTF-8?q?=20foco=20nomes=20amb=20pasar=20per=20damunt=20-=20[NEW]=20Fent?= =?UTF-8?q?=20click=20en=20una=20linea=20del=20desensamblador=20fica=20o?= =?UTF-8?q?=20lleva=20un=20breakpoint=20en=20eixa=20adre=C3=A7a=20-=20[FIX?= =?UTF-8?q?]=20les=20accions=20en=20el=20analitzador=20actualitzen=20la=20?= =?UTF-8?q?finestra=20del=20debugger=20-=20[FIX]=20El=20cursor=20del=20ana?= =?UTF-8?q?litzador=20nomes=20es=20deu=20moure=20al=20estar=20damunt=20de?= =?UTF-8?q?=20al=20finestra=20del=20analitzador=20-=20[FIX]=20El=20desensa?= =?UTF-8?q?mblador,=20quan=20el=20tag=20de=20memoria=20era=20MIXED=20no=20?= =?UTF-8?q?reconixia=20part=20de=20la=20instrucci=C3=B3=20-=20[FIX]=20El?= =?UTF-8?q?=20desensamblador=20usava=20el=20color=20incorrecte=20per=20a?= =?UTF-8?q?=20codi=20amb=20el=20tag=20REPEAT?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ui.cpp | 7 +++++++ ui.h | 1 + z80.cpp | 16 +++++++-------- z80analyze.cpp | 54 +++++++++++++++++++++++++++++++++++++++----------- z80analyze.h | 1 + z80debug.cpp | 29 ++++++++++++++++++++++----- 6 files changed, 83 insertions(+), 25 deletions(-) diff --git a/ui.cpp b/ui.cpp index 97ba194..abbda53 100644 --- a/ui.cpp +++ b/ui.cpp @@ -65,6 +65,13 @@ namespace ui SDL_RenderFillRect(ren, &rect); } + void printvoidrect(int x, int y, int w, int h, uint8_t color) + { + SDL_Rect rect {(offset_x+x)*CHR_W, (offset_y+y)*CHR_H, w*CHR_W, h*CHR_H}; + SDL_SetRenderDrawColor(ren, colors[color][0], colors[color][1], colors[color][2], 255); + SDL_RenderDrawRect(ren, &rect); + } + void printchar(int x, int y, char chr, uint8_t color) { if (color != 255) SDL_SetRenderDrawColor(ren, colors[color][0], colors[color][1], colors[color][2], 255); diff --git a/ui.h b/ui.h index 985dc40..5cc4673 100644 --- a/ui.h +++ b/ui.h @@ -29,6 +29,7 @@ namespace ui void box(int x, int y, int w, int h, uint8_t color); void printrect(int x, int y, int w, int h, uint8_t color); + void printvoidrect(int x, int y, int w, int h, uint8_t color); void printchar(int x, int y, char chr, uint8_t color=255); void printtxt(int x, int y, const char *text, uint8_t color); diff --git a/z80.cpp b/z80.cpp index 6dfdef7..ae26118 100644 --- a/z80.cpp +++ b/z80.cpp @@ -153,15 +153,15 @@ namespace z80 if (memtag[addr] != MEMTAG_IGNORE) { if (!code) { if ( memtag[addr] == MEMTAG_INST ) { - printf("WARNING! READING DATA FROM CODE!!! $%4X\n", addr); - z80debug::stop(); + //printf("WARNING! READING DATA FROM CODE!!! $%4X\n", addr); + //z80debug::stop(); } else { memtag[addr] = MEMTAG_DATA; } } else { if ( (reading_m1) && (memtag[addr] == MEMTAG_DATA) ) { - printf("WARNING! EXECUTING DATA AS CODE!!! $%4X\n", addr); - z80debug::stop(); + //printf("WARNING! EXECUTING DATA AS CODE!!! $%4X\n", addr); + //z80debug::stop(); } } } @@ -210,8 +210,8 @@ namespace z80 z80debug::setmemmodified(addr); if ( (memtag[addr] != MEMTAG_IGNORE) && (memtag[addr] != MEMTAG_MIXED) ) { if (memtag[addr]==MEMTAG_INST) { - printf("WARNING! WRITING DATA OVER CODE!!! $%4X\n", addr); - z80debug::stop(); + //printf("WARNING! WRITING DATA OVER CODE!!! $%4X\n", addr); + //z80debug::stop(); } else if (memtag[addr] == MEMTAG_CODE) { memtag[addr] = MEMTAG_MIXED; } else { @@ -2339,8 +2339,8 @@ namespace z80 case 0x31: INVALID(opcode); break; case 0x32: INVALID(opcode); break; case 0x33: INVALID(opcode); break; - case 0x34: INCMEM8(rIY+READ_MEM_8());t+=2; break; - case 0x35: DECMEM8(rIY+READ_MEM_8());t+=2; break; + case 0x34: d=READ_MEM_8(); INCMEM8(rIY+d);t+=2; break; + case 0x35: d=READ_MEM_8(); DECMEM8(rIY+d);t+=2; break; case 0x36: d=READ_MEM_8(); WRITE_MEM_8(rIY+d, READ_MEM_8()); t+=2; break; case 0x37: INVALID(opcode); break; case 0x38: INVALID(opcode); break; diff --git a/z80analyze.cpp b/z80analyze.cpp index 2e977b1..2121f8a 100644 --- a/z80analyze.cpp +++ b/z80analyze.cpp @@ -1,5 +1,6 @@ #include "z80analyze.h" #include "z80.h" +#include "z80debug.h" #include #include "ui_window.h" #include "ui.h" @@ -10,6 +11,7 @@ namespace z80analyze SDL_Renderer *ren = nullptr; SDL_Texture *tex = nullptr; SDL_Texture *uitex = nullptr; + uint16_t address = 0; void refreshTitle(); @@ -17,18 +19,36 @@ namespace z80analyze { if (e->type == SDL_MOUSEBUTTONUP) { - if (e->button.button == 1) - //z80::clearMemTouched(); - z80::clearMemTag(); + //if (z80::getMemTag(address)!=MEMTAG_INST) address = find_previous_opcode(address); + z80debug::setcursor(address); + z80debug::refresh(); + + /*if (e->button.button == 1) + z80::clearMemTouched(); + //z80::clearMemTag(); else - z80::fixMemTouched(); + z80::fixMemTouched();*/ refresh(); } if (e->type == SDL_MOUSEMOTION) { - SDL_ShowCursor(SDL_DISABLE); - refreshTitle(); - refresh(); + if (e->motion.windowID == SDL_GetWindowID(win)) { + SDL_ShowCursor(SDL_DISABLE); + refreshTitle(); + refresh(); + focus(); + } + } + if (e->type == SDL_KEYDOWN) { + if (e->key.keysym.scancode == SDL_SCANCODE_RETURN) { + z80::fixMemTouched(); + refresh(); + z80debug::refresh(); + } else if (e->key.keysym.scancode == SDL_SCANCODE_BACKSPACE) { + z80::clearMemTouched(); + refresh(); + z80debug::refresh(); + } } return true; } @@ -53,7 +73,8 @@ namespace z80analyze int mx, my; SDL_GetMouseState(&mx, &my); mx/=2; my/=2; - SDL_SetWindowTitle(win, SDL_itoa(mx+my*256, tmp, 16)); + address = mx+my*256; + SDL_SetWindowTitle(win, SDL_itoa(address, tmp, 16)); } void refresh() { @@ -65,11 +86,11 @@ namespace z80analyze SDL_LockTexture(tex, NULL, (void**)&pixels, &pitch); for (int i=0; i<65536; ++i) { - uint8_t tag = z80::getMemTag(i); - pixels[i] = tag==MEMTAG_NONE ? 0x808080 : tag==MEMTAG_DATA ? 0x0000FF : tag==MEMTAG_MIXED ? 0xFF00FF : 0x00FF00; + //uint8_t tag = z80::getMemTag(i); + //pixels[i] = tag==MEMTAG_NONE ? 0x808080 : tag==MEMTAG_DATA ? 0x0000FF : tag==MEMTAG_MIXED ? 0xFF00FF : 0x00FF00; - //uint8_t tag = z80::getMemTouched(i); - //pixels[i] = tag==MEMTAG_NONE ? 0x808080 : tag==MEMTAG_DATA ? 0x0000FF : tag==MEMTAG_REPEAT ? 0xFF0000 : 0x00FF00; + uint8_t tag = z80::getMemTouched(i); + pixels[i] = tag==MEMTAG_NONE ? 0x808080 : tag==MEMTAG_DATA ? 0x0000FF : tag==MEMTAG_REPEAT ? 0xFF0000 : 0x00FF00; } pixels[z80::getPC()] = 0xFFFFFF; @@ -99,4 +120,13 @@ namespace z80analyze SDL_DestroyRenderer(ren); ren = nullptr; SDL_DestroyWindow(win); win = nullptr; } + + void focus() + { + if (win) { + SDL_RaiseWindow(win); + refresh(); + } + } + } diff --git a/z80analyze.h b/z80analyze.h index b5a93b6..301798f 100644 --- a/z80analyze.h +++ b/z80analyze.h @@ -5,4 +5,5 @@ namespace z80analyze void show(); void refresh(); void hide(); + void focus(); } diff --git a/z80debug.cpp b/z80debug.cpp index 17b9127..602e90d 100644 --- a/z80debug.cpp +++ b/z80debug.cpp @@ -64,6 +64,8 @@ namespace z80debug uint8_t use[7][256]; + uint16_t line_address[256]; + char temp[256]; const char *tohex(int value, int numdigits) { @@ -183,6 +185,15 @@ namespace z80debug } } if (e->type == SDL_MOUSEBUTTONDOWN) { + if ( (e->button.xbutton.y<(mem_y-1)*CHR_H) && (e->button.y>CHR_H) ) { + const uint16_t address = ((e->button.y)/CHR_H)-1; + if (breakpoints[line_address[address]]==0) + breakpoints[line_address[address]]=1; + else + breakpoints[line_address[address]]=0; + refresh(); + } + if (!resizing && resizing_type != RESIZING_NONE) { resizing = true; } @@ -278,7 +289,7 @@ namespace z80debug uint16_t find_previous_opcode(uint16_t pc) { pc--; - if (z80::getMemTag(pc)!=MEMTAG_CODE && z80::getMemTag(pc)!=MEMTAG_INST) return pc; + if (z80::getMemTag(pc)!=MEMTAG_CODE && z80::getMemTag(pc)!=MEMTAG_MIXED && z80::getMemTag(pc)!=MEMTAG_INST) return pc; while (z80::getMemTag(pc)!=MEMTAG_INST) pc--; @@ -299,8 +310,8 @@ namespace z80debug void printDissasemblerLine(const uint16_t address, const int line, const bool heuristics=false) { - uint8_t colors[4] = { COLOR_RED, COLOR_CYAN, COLOR_GRAY, COLOR_WHITE}; - if (z80::getMemTouched(address)!=MEMTAG_INST) colors[3]=COLOR_GRAY; + uint8_t colors[4] = { COLOR_RED, COLOR_CYAN, COLOR_WHITE, COLOR_WHITE}; + if (z80::getMemTouched(address)!=MEMTAG_INST && z80::getMemTouched(address)!=MEMTAG_REPEAT) colors[3]=COLOR_GRAY; if (z80::getMemTouched(address)==MEMTAG_NONE) colors[1]=COLOR_GRAY; if (is_debugging && (address == z80::getPC())) { @@ -325,7 +336,8 @@ namespace z80debug ui::printtxt(19,line, z80dis::getOpcode(address), colors[2]); ui::printtxt(31,line, z80dis::getAsm(address), colors[3]); } else { - ui::printtxt(19,line, tohex(z80::getMem()[address],2), COLOR_GRAY); + ui::printrect(19,line,2,1,COLOR_GRAY); + ui::printtxt(19,line, tohex(z80::getMem()[address],2), COLOR_WHITE); ui::printtxt(31,line, "?????????", COLOR_GRAY); } } @@ -351,16 +363,20 @@ namespace z80debug uint16_t pc = cursor; //z80::getPC(); uint16_t pos = pc; int num_lines = mem_y-2; + line_address[(num_lines/2)-1] = pos; + ui::printvoidrect(0,(num_lines/2)-1, midx-2,1, COLOR_BLUE); printDissasemblerLine(pc, (num_lines/2)-1, true); for (int i=num_lines/2;i=0;--i) { pos = find_previous_opcode(pos); + line_address[i] = pos; printDissasemblerLine(pos, i); } @@ -852,7 +868,10 @@ namespace z80debug void setcursor(const uint16_t address) { - cursor = address; + if (z80::getMemTag(address)!=MEMTAG_INST) + cursor = find_previous_opcode(address); + else + cursor = address; } void cursorfwd()