Fixes. Debugger improved.
This commit is contained in:
49
debug.cpp
49
debug.cpp
@@ -8,6 +8,7 @@ typedef unsigned char byte;
|
||||
typedef unsigned short word;
|
||||
|
||||
static SDL_Window* debug_window = nullptr;
|
||||
static Uint32 debug_window_id;
|
||||
static SDL_Renderer* debug_renderer = nullptr;
|
||||
static SDL_Texture* debug_texture = nullptr;
|
||||
static SDL_Rect src, dst;
|
||||
@@ -15,6 +16,8 @@ static Uint8 ink[4];
|
||||
static Uint8 paper[4];
|
||||
static unsigned char* debug_mem = nullptr;
|
||||
|
||||
static bool breakpoints[65536] {false};
|
||||
|
||||
static unsigned short* rX;
|
||||
static unsigned char* rY;
|
||||
static unsigned char* rZ;
|
||||
@@ -144,21 +147,25 @@ static void debug_print_basic(byte offset) {
|
||||
return;
|
||||
}
|
||||
int line = offset;
|
||||
int l = 0;
|
||||
if (lines[*pc] >= 35) line = lines[*pc] + 30;
|
||||
int row = 0;
|
||||
char* prog = program;
|
||||
if (lines[*pc] == line) { debug_set_ink(0, 0, 0); debug_fill_rect(1, 2 + line, 70, 1); debug_set_ink(255, 255, 0); }
|
||||
if (lines[*pc] == line) { debug_set_ink(0, 0, 0); debug_fill_rect(1, 2 + l, 70, 1); debug_set_ink(255, 255, 0); }
|
||||
else debug_set_ink(255, 255, 255);
|
||||
while (line < 35 && *prog != 0) {
|
||||
if (*prog == '\t') {
|
||||
row += 4;
|
||||
} else if (*prog == '\n') {
|
||||
row = 0; line++;
|
||||
if (lines[*pc] == line) { debug_set_ink(0, 0, 0); debug_fill_rect(1, 2 + line, 70, 1); debug_set_ink(255, 255, 0); }
|
||||
row = 0; line++; l++;
|
||||
int bm = 0; while (lines[bm] < line) { bm++; }
|
||||
if (breakpoints[bm]) { debug_set_ink(64, 0, 0); debug_fill_rect(1, 2 + l, 70, 1); }
|
||||
if (lines[*pc] == line) { debug_set_ink(0, 0, 0); debug_fill_rect(1, 2 + l, 70, 1); debug_set_ink(255, 255, 0); }
|
||||
else debug_set_ink(255, 255, 255);
|
||||
} else if (*prog == 13) {
|
||||
// row++;
|
||||
} else {
|
||||
if (row < 70) debug_draw_char(1 + row, 2 + line, *prog);
|
||||
if (row < 70) debug_draw_char(1 + row, 2 + l, *prog);
|
||||
row++;
|
||||
}
|
||||
prog++;
|
||||
@@ -293,7 +300,7 @@ void debug_init(unsigned char* mem) {
|
||||
|
||||
debug_window = SDL_CreateWindow("Definitely PaCo Debugger", 1120, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_SHOWN);
|
||||
debug_renderer = SDL_CreateRenderer(debug_window, -1, SDL_RENDERER_PRESENTVSYNC);
|
||||
//SDL_RenderSetLogicalSize(debug_renderer, 152, 120);
|
||||
debug_window_id = SDL_GetWindowID(debug_window);
|
||||
SDL_SetRenderDrawColor(debug_renderer, 128, 128, 128, 255);
|
||||
|
||||
FILE* f = fopen("font.png", "rb");
|
||||
@@ -321,13 +328,6 @@ void debug_update() {
|
||||
debug_set_paper(128, 128, 128);
|
||||
debug_clear();
|
||||
|
||||
/* debug_set_ink(64, 64, 64);
|
||||
debug_fill_rect(39, 39, 40, 20);
|
||||
debug_draw_inset(39, 39, 40, 20);
|
||||
|
||||
debug_set_ink(0, 0, 0);
|
||||
debug_print(39, 38, "DISASSEMBLY:");*/
|
||||
|
||||
debug_print_memory(0);
|
||||
debug_print_asm(0);
|
||||
debug_print_datastack(0);
|
||||
@@ -337,3 +337,28 @@ void debug_update() {
|
||||
|
||||
SDL_RenderPresent(debug_renderer);
|
||||
}
|
||||
|
||||
void debug_hide() {
|
||||
debug_set_paper(128, 128, 128);
|
||||
debug_clear();
|
||||
SDL_RenderPresent(debug_renderer);
|
||||
}
|
||||
|
||||
void debug_mouse_event(SDL_Event& event) {
|
||||
if (event.window.windowID != debug_window_id) return;
|
||||
if (event.type == SDL_MOUSEBUTTONDOWN) {
|
||||
int x, y;
|
||||
Uint32 buttons = SDL_GetMouseState(&x, &y);
|
||||
if (x >= 8 && x <= 568 && y >= 16 && y <= 296) {
|
||||
int l = (y - 16) >> 3;
|
||||
int bm = 0; while (lines[bm] < l) { bm++; }
|
||||
breakpoints[bm] = !breakpoints[bm];
|
||||
}
|
||||
debug_update();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const bool* debug_get_breakpoints() {
|
||||
return breakpoints;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user