From 1391368c4c50828c8998de6add2b5a0b2a5d93bd Mon Sep 17 00:00:00 2001 From: Raimon Zamora Date: Fri, 3 Feb 2017 20:07:55 +0100 Subject: [PATCH] Fixed exception with fullscreen. Improved debugger BASIC window. --- debug.cpp | 34 +++++++++++++++++++++++++--------- debug.h | 2 +- main.cpp | 1 + vdp.cpp | 22 +++++++++------------- 4 files changed, 36 insertions(+), 23 deletions(-) diff --git a/debug.cpp b/debug.cpp index 1f2eff1..30489b3 100644 --- a/debug.cpp +++ b/debug.cpp @@ -140,21 +140,28 @@ static void debug_print_callstack(byte offset) { } } -static void debug_print_basic(byte offset) { +static int basic_line = 0; + +static void debug_print_basic(const bool force) { debug_draw_space(1, 2, 70, 35, "CODE:"); debug_set_ink(255, 255, 255); if (*pc >= 0x8000) { debug_print(17, 17, "No source code for this memory region"); return; } - int line = offset; + int line = basic_line; int l = 0; - if (lines[*pc] >= 35) line = lines[*pc] + 30; - int row = 0; + if (force) { + if (lines[*pc] >= basic_line + 35) line = basic_line = lines[*pc] - 30; + if (lines[*pc] < basic_line) line = basic_line = lines[*pc] - 5; + if (line < 0) line = basic_line = 0; + } + int row = 0; int cline = 0; char* prog = program; + while (cline < line) { if (*prog == '\n') cline++; prog++; } 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) { + while (l < 35 && *prog != 0) { if (*prog == '\t') { row += 4; } else if (*prog == '\n') { @@ -304,6 +311,7 @@ void debug_show_window() { SDL_SetTextureBlendMode(debug_texture, SDL_BLENDMODE_BLEND); stbi_image_free(buffer); fclose(f); + visible = true; } void debug_init(unsigned char* mem, const bool window_shown) { @@ -329,7 +337,7 @@ void debug_init(unsigned char* mem, const bool window_shown) { if (window_shown) debug_update(); } -void debug_update() { +void debug_update(const bool force) { if (!visible) debug_show_window(); debug_set_paper(128, 128, 128); debug_clear(); @@ -339,7 +347,7 @@ void debug_update() { debug_print_datastack(0); debug_print_callstack(0); debug_print_registers(); - debug_print_basic(0); + debug_print_basic(force); SDL_RenderPresent(debug_renderer); } @@ -358,11 +366,19 @@ void debug_mouse_event(SDL_Event& event) { int x, y; Uint32 buttons = SDL_GetMouseState(&x, &y); if (x >= 8 && x <= 568 && y >= 16 && y <= 296) { - int l = (y - 16) >> 3; + int l = basic_line + ((y - 16) >> 3); int bm = 0; while (lines[bm] < l) { bm++; } breakpoints[bm] = !breakpoints[bm]; } - debug_update(); + debug_update(false); + } + if (event.type == SDL_MOUSEWHEEL) { + int x, y; + Uint32 buttons = SDL_GetMouseState(&x, &y); + if (x >= 8 && x <= 568 && y >= 16 && y <= 296) { + basic_line -= event.wheel.y*3; if (basic_line < 0) basic_line = 0; + debug_update(false); + } } } diff --git a/debug.h b/debug.h index d383a13..5b61377 100644 --- a/debug.h +++ b/debug.h @@ -2,7 +2,7 @@ #include void debug_init(unsigned char* mem, const bool window_shown = false); -void debug_update(); +void debug_update(const bool force = true); void debug_hide(); void debug_mouse_event(SDL_Event& event); const bool* debug_get_breakpoints(); diff --git a/main.cpp b/main.cpp index e7872d4..b6af441 100644 --- a/main.cpp +++ b/main.cpp @@ -85,6 +85,7 @@ int main(int argc, char** argv) { case SDL_KEYUP: if (sdlEvent.key.keysym.scancode == SDL_SCANCODE_SPACE) { anykey = false; } case SDL_MOUSEBUTTONDOWN: + case SDL_MOUSEWHEEL: debug_mouse_event(sdlEvent); break; } diff --git a/vdp.cpp b/vdp.cpp index 440e44f..bc3fae9 100644 --- a/vdp.cpp +++ b/vdp.cpp @@ -65,25 +65,15 @@ static Uint8 palette[16][4] = { void vdp_init() { SDL_Init(SDL_INIT_EVERYTHING); - sdlWindow = SDL_CreateWindow("PaCo", 160, SDL_WINDOWPOS_UNDEFINED, 608, 480, SDL_WINDOW_SHOWN); + sdlWindow = SDL_CreateWindow("PaCo", 160, SDL_WINDOWPOS_UNDEFINED, 608, 480, fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : SDL_WINDOW_SHOWN); sdlRenderer = SDL_CreateRenderer(sdlWindow, -1, SDL_RENDERER_PRESENTVSYNC); - //SDL_SetRenderDrawBlendMode(sdlRenderer, SDL_BLENDMODE_BLEND); SDL_RenderSetLogicalSize(sdlRenderer, 152, 120); SDL_SetRenderDrawColor(sdlRenderer, palette[border][0], palette[border][1], palette[border][2], palette[border][3]); + sdlTexture = SDL_CreateTexture(sdlRenderer, SDL_PIXELFORMAT_ABGR8888, SDL_TEXTUREACCESS_STATIC, 128, 128); + SDL_ShowCursor(fullscreen ? 0 : 1); for (int i = 0; i < 16 * 12; i++) screen_map[i] = 32; for (int i = 0; i < 16 * 12; i++) screen_color[i] = color; - //jtexture texture = (jtexture)malloc(sizeof(jtexture_t)); - //FILE* f = fopen("font.png", "rb"); - //if (!f) { error = 2; return; } - //int c; - //int size = 128; - //Uint8* buffer = stbi_load_from_file(f, &size, &size, &c, 4); - sdlTexture = SDL_CreateTexture(sdlRenderer, SDL_PIXELFORMAT_ABGR8888, SDL_TEXTUREACCESS_STATIC, 128, 128); - //SDL_UpdateTexture(sdlTexture, NULL, buffer, 128 * sizeof(Uint32)); - //SDL_SetTextureBlendMode(sdlTexture, SDL_BLENDMODE_BLEND); - //stbi_image_free(buffer); - //fclose(f); src.x = src.y = 0; dst.x = dst.y = 12; @@ -152,6 +142,12 @@ void vdp_flip() { void vdp_switch_fullscreen() { SDL_SetWindowFullscreen(sdlWindow, fullscreen ? 0 : SDL_WINDOW_FULLSCREEN_DESKTOP); fullscreen = !fullscreen; + SDL_DestroyRenderer(sdlRenderer); + sdlRenderer = SDL_CreateRenderer(sdlWindow, -1, SDL_RENDERER_PRESENTVSYNC); + SDL_RenderSetLogicalSize(sdlRenderer, 152, 120); + SDL_ShowCursor(fullscreen ? 0 : 1); + SDL_DestroyTexture(sdlTexture); + sdlTexture = SDL_CreateTexture(sdlRenderer, SDL_PIXELFORMAT_ABGR8888, SDL_TEXTUREACCESS_STATIC, 128, 128); } void vdp_data_out(const unsigned char& value) {