diff --git a/main.cpp b/main.cpp index 7cbbba2..d5e6b66 100644 --- a/main.cpp +++ b/main.cpp @@ -119,6 +119,7 @@ int main(int argc, char *argv[]) bool result = true; if (e.type == SDL_QUIT) { should_exit=true; break; } + if (e.type == SDL_MOUSEBUTTONDOWN) result = ui::window::sendEvent(e.button.windowID, &e); if (e.type == SDL_MOUSEBUTTONUP) result = ui::window::sendEvent(e.button.windowID, &e); if (e.type == SDL_MOUSEMOTION) result = ui::window::sendEvent(e.motion.windowID, &e); if (e.type == SDL_WINDOWEVENT) result = ui::window::sendEvent(e.window.windowID, &e); diff --git a/z80debug.cpp b/z80debug.cpp index fd1c675..6f9a7fc 100644 --- a/z80debug.cpp +++ b/z80debug.cpp @@ -9,9 +9,26 @@ #include "zx_screen.h" #include "z80analyze.h" +#define RESIZING_NONE 0 +#define RESIZING_MEMORY 1 +#define RESIZING_CONSOLE 2 +#define RESIZING_SYMBOLS 3 +#define RESIZING_X 4 + namespace z80debug { - #define midy 58 + int midx = 58; + int mem_y = 20; + int con_y = 28; + int sym_y = 20; + int win_h = 44; + int mem_h = 8; + int con_h = 6; + int sym_h = 14; + + int resizing_type = RESIZING_MEMORY; + bool resizing = false; + namespace history { uint16_t buffer[65536]; @@ -27,6 +44,9 @@ namespace z80debug SDL_Window *win = nullptr; SDL_Renderer *ren = nullptr; SDL_Texture *tex = nullptr; + SDL_Cursor *cur_df = nullptr; + SDL_Cursor *cur_ns = nullptr; + SDL_Cursor *cur_we = nullptr; bool is_debugging=false; bool is_paused=false; @@ -51,6 +71,13 @@ namespace z80debug if (z80debug::debugging()) { if (e->type==SDL_WINDOWEVENT) { if ((e->window.event==SDL_WINDOWEVENT_SHOWN) || (e->window.event==SDL_WINDOWEVENT_EXPOSED)) { + int w; int h; + SDL_GetWindowSize(win, &w, &h); + midx = (w/CHR_W) - 25; + win_h = (h/CHR_H); + mem_y = win_h - mem_h - con_h; + con_y = win_h - con_h; + sym_y = win_h - sym_h; z80debug::refresh(); zxscreen::redraw(); } else if (e->window.event == SDL_WINDOWEVENT_CLOSE) { @@ -59,7 +86,7 @@ namespace z80debug } } if (e->type == SDL_MOUSEWHEEL) { - if (e->wheel.mouseXwheel.mouseY<20*CHR_H) { + if (e->wheel.mouseXwheel.mouseYwheel.y>0) { z80debug::cursorback(); z80debug::refresh(); @@ -98,6 +125,61 @@ namespace z80debug z80debug::DeleteCharConsole(); } } + if (e->type == SDL_MOUSEMOTION) { + if (!resizing) { + if ( (e->motion.y > (mem_y*CHR_H)-8) && (e->motion.y < (mem_y*CHR_H)+8) && ( e->motion.x < midx*CHR_W ) ) { + if (resizing_type != RESIZING_MEMORY) SDL_SetCursor(cur_ns); + resizing_type = RESIZING_MEMORY; + } else if ( (e->motion.y > (sym_y*CHR_H)-8) && (e->motion.y < (sym_y*CHR_H)+8) && ( e->motion.x >= midx*CHR_W ) ) { + if (resizing_type != RESIZING_SYMBOLS) SDL_SetCursor(cur_ns); + resizing_type = RESIZING_SYMBOLS; + } else if ( (e->motion.y > (con_y*CHR_H)-8) && (e->motion.y < (con_y*CHR_H)+8) && (e->motion.x < midx*CHR_W) ) { + if (resizing_type != RESIZING_CONSOLE) SDL_SetCursor(cur_ns); + resizing_type = RESIZING_CONSOLE; + } else { + if (resizing_type != RESIZING_NONE) SDL_SetCursor(cur_df); + resizing_type = RESIZING_NONE; + } + } else { + if (resizing_type==RESIZING_MEMORY) { + const int new_mem_y = e->motion.y/CHR_H; + const int new_mem_h = win_h - new_mem_y - con_h; + if (new_mem_y>=5 && new_mem_h>=3) { + mem_y = new_mem_y; + mem_h = new_mem_h; + refresh(); + } + } else if (resizing_type==RESIZING_CONSOLE) { + const int new_con_y = e->motion.y/CHR_H; + const int new_con_h = win_h - new_con_y; + const int new_mem_y = win_h - mem_h - new_con_h; + if (new_mem_y>=5 && new_con_h>=3) { + mem_y = new_mem_y; + con_y = new_con_y; + con_h = new_con_h; + refresh(); + } + } else if (resizing_type==RESIZING_SYMBOLS) { + const int new_sym_y = e->motion.y/CHR_H; + const int new_sym_h = win_h - new_sym_y; + if (new_sym_y>=12 && new_sym_h >=3) { + sym_y = new_sym_y; + sym_h = new_sym_h; + refresh(); + } + } + } + } + if (e->type == SDL_MOUSEBUTTONDOWN) { + if (!resizing && resizing_type != RESIZING_NONE) { + resizing = true; + } + } + if (e->type == SDL_MOUSEBUTTONUP) { + if (resizing) { + resizing = false; + } + } if (e->type == SDL_TEXTINPUT) { z80debug::sendToConsole(e->text.text); } @@ -111,13 +193,17 @@ namespace z80debug { is_debugging = is_paused = false; for (int i=0; i<65536; ++i) breakpoints[i]=0; + if (!cur_df) cur_df = SDL_GetCursor(); + if (!cur_ns) cur_ns = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZENS); + if (!cur_we) cur_we = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZEWE); + //show(); } void show() { if (!win) { - win = SDL_CreateWindow("Z80 Debugger", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 83*CHR_W, 34*CHR_H, SDL_WINDOW_RESIZABLE); + win = SDL_CreateWindow("Z80 Debugger", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 98*CHR_W, 44*CHR_H, SDL_WINDOW_RESIZABLE); ren = SDL_CreateRenderer(win, -1, 0); ui::window::registerWindow(SDL_GetWindowID(win), eventHandler); tex = ui::createtexture(ren); @@ -203,7 +289,7 @@ namespace z80debug if (is_debugging && (address == z80::getPC())) { for (int i=0; i<4;++i) colors[i]=COLOR_YELLOW; - ui::printrect(0,line, midy-2,1, COLOR_BLUE); + ui::printrect(0,line, midx-2,1, COLOR_BLUE); } if (breakpoints[address]&9) ui::printtxt(0,line,"*", colors[0]); @@ -230,7 +316,7 @@ namespace z80debug // ****************************************** ui::setoffset(0, 0); - ui::box(0,0,midy,20,COLOR_WHITE); + ui::box(0,0,midx,mem_y,COLOR_WHITE); ui::printrect(2,0, 12,1, COLOR_DARK); ui::printtxt(3,0, "ASSEMBLER:", COLOR_WHITE); @@ -240,16 +326,16 @@ namespace z80debug uint16_t pc = cursor; //z80::getPC(); uint16_t pos = pc; + int num_lines = mem_y-2; + printDissasemblerLine(pc, (num_lines/2)-1, true); - printDissasemblerLine(pc, 8, true); - - for (int i=9;i<18;++i) { + for (int i=num_lines/2;i=0;--i) { + for (int i=(num_lines/2)-2;i>=0;--i) { pos = find_previous_opcode(pos); printDissasemblerLine(pos, i); } @@ -258,11 +344,11 @@ namespace z80debug // ****************************************** ui::setoffset(0, 0); - ui::box(midy,0,25,8,COLOR_WHITE); - ui::printrect(midy+2,0, 12,1, COLOR_DARK); - ui::printtxt(midy+3,0, "REGISTERS:", COLOR_WHITE); + ui::box(midx,0,25,8,COLOR_WHITE); + ui::printrect(midx+2,0, 12,1, COLOR_DARK); + ui::printtxt(midx+3,0, "REGISTERS:", COLOR_WHITE); - ui::setoffset(midy+1, 1); + ui::setoffset(midx+1, 1); ui::printtxt(0,0, "AF AF' IX ", COLOR_WHITE); ui::printtxt(0,1, "BC BC' IY ", COLOR_WHITE); ui::printtxt(0,2, "DE DE' SP ", COLOR_WHITE); @@ -306,12 +392,12 @@ namespace z80debug // ****************************************** ui::setoffset(0, 0); - ui::box(midy,8,11,12,COLOR_WHITE); - ui::printrect(midy+2,8, 8,1, COLOR_DARK); - ui::printtxt(midy+3,8, "STACK:", COLOR_WHITE); - ui::setoffset(midy+1, 9); - uint16_t sp = z80::getSP()-8; - for (int i=0; i<10; ++i) { + ui::box(midx,8,11,sym_y-8,COLOR_WHITE); + ui::printrect(midx+2,8, 8,1, COLOR_DARK); + ui::printtxt(midx+3,8, "STACK:", COLOR_WHITE); + ui::setoffset(midx+1, 9); + uint16_t sp = z80::getSP()-(((sym_y-12)>>1)<<1); + for (int i=0; i", 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); + + // SYMBOLS + // ***************************************** + + ui::setoffset(0, 0); + ui::box(midx,sym_y,25,sym_h,COLOR_WHITE); + ui::printrect(midx+2,sym_y, 9,1, COLOR_DARK); + ui::printtxt(midx+3,sym_y, "SYMBOLS:", COLOR_WHITE); + + ui::setoffset(midx+1, sym_y+1); + const int num_symbols = z80dis::getNumSymbols(); + for (int i=0;i #include #include "z80.h" +#include +#include namespace z80dis { char buffer[256]; int opcode_size = 0; char symbols[65536][15]; + std::vector used_symbols; // $%04x // $%02x @@ -39,6 +42,7 @@ namespace z80dis void loadSymbols() { + used_symbols.clear(); for (int i=0; i<65536; ++i) symbols[i][0] = 0; FILE *f = fopen("symbols.txt", "r"); while (true) { @@ -47,6 +51,17 @@ namespace z80dis const int result = fscanf(f, "%x %s", &address, tmp); if (result != 2) break; strcpy(symbols[address], tmp); + used_symbols.push_back(address); + } + fclose(f); + } + + void saveSymbols() + { + FILE *f = fopen("symbols.txt", "w"); + for (auto sym_addr : used_symbols) + { + fprintf(f, "0x%x %s\n", sym_addr, symbols[sym_addr]); } fclose(f); } @@ -202,4 +217,27 @@ namespace z80dis return symbols[pos]; } + bool comp(uint16_t a, uint16_t b) { + return a <= b; + } + + void setSymbol(const uint16_t pos, const char *sym) + { + strcpy(symbols[pos], sym); + used_symbols.push_back(pos); + sort(used_symbols.begin(), used_symbols.end(), comp); + saveSymbols(); + } + + const int getNumSymbols() + { + return used_symbols.size(); + } + + const uint16_t getSymbolAddress(const int pos) + { + return used_symbols[pos]; + } + + } diff --git a/z80dis.h b/z80dis.h index 67eb28f..6fc81d3 100644 --- a/z80dis.h +++ b/z80dis.h @@ -5,8 +5,13 @@ namespace z80dis { void loadSymbols(); + void saveSymbols(); const char *getAsm(const uint16_t pos); const char *getOpcode(const uint16_t pos); const int getOpcodeSize(const uint16_t pos); const char *getSymbol(const uint16_t pos); + void setSymbol(const uint16_t pos, const char *sym); + + const int getNumSymbols(); + const uint16_t getSymbolAddress(const int pos); }