Fixed exception with fullscreen. Improved debugger BASIC window.

This commit is contained in:
2017-02-03 20:07:55 +01:00
parent 88c0288931
commit 1391368c4c
4 changed files with 36 additions and 23 deletions

View File

@@ -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_draw_space(1, 2, 70, 35, "CODE:");
debug_set_ink(255, 255, 255); debug_set_ink(255, 255, 255);
if (*pc >= 0x8000) { if (*pc >= 0x8000) {
debug_print(17, 17, "No source code for this memory region"); debug_print(17, 17, "No source code for this memory region");
return; return;
} }
int line = offset; int line = basic_line;
int l = 0; int l = 0;
if (lines[*pc] >= 35) line = lines[*pc] + 30; if (force) {
int row = 0; 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; 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); } 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 debug_set_ink(255, 255, 255);
while (line < 35 && *prog != 0) { while (l < 35 && *prog != 0) {
if (*prog == '\t') { if (*prog == '\t') {
row += 4; row += 4;
} else if (*prog == '\n') { } else if (*prog == '\n') {
@@ -304,6 +311,7 @@ void debug_show_window() {
SDL_SetTextureBlendMode(debug_texture, SDL_BLENDMODE_BLEND); SDL_SetTextureBlendMode(debug_texture, SDL_BLENDMODE_BLEND);
stbi_image_free(buffer); stbi_image_free(buffer);
fclose(f); fclose(f);
visible = true;
} }
void debug_init(unsigned char* mem, const bool window_shown) { 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(); if (window_shown) debug_update();
} }
void debug_update() { void debug_update(const bool force) {
if (!visible) debug_show_window(); if (!visible) debug_show_window();
debug_set_paper(128, 128, 128); debug_set_paper(128, 128, 128);
debug_clear(); debug_clear();
@@ -339,7 +347,7 @@ void debug_update() {
debug_print_datastack(0); debug_print_datastack(0);
debug_print_callstack(0); debug_print_callstack(0);
debug_print_registers(); debug_print_registers();
debug_print_basic(0); debug_print_basic(force);
SDL_RenderPresent(debug_renderer); SDL_RenderPresent(debug_renderer);
} }
@@ -358,11 +366,19 @@ void debug_mouse_event(SDL_Event& event) {
int x, y; int x, y;
Uint32 buttons = SDL_GetMouseState(&x, &y); Uint32 buttons = SDL_GetMouseState(&x, &y);
if (x >= 8 && x <= 568 && y >= 16 && y <= 296) { 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++; } int bm = 0; while (lines[bm] < l) { bm++; }
breakpoints[bm] = !breakpoints[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);
}
} }
} }

View File

@@ -2,7 +2,7 @@
#include <SDL.h> #include <SDL.h>
void debug_init(unsigned char* mem, const bool window_shown = false); 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_hide();
void debug_mouse_event(SDL_Event& event); void debug_mouse_event(SDL_Event& event);
const bool* debug_get_breakpoints(); const bool* debug_get_breakpoints();

View File

@@ -85,6 +85,7 @@ int main(int argc, char** argv) {
case SDL_KEYUP: case SDL_KEYUP:
if (sdlEvent.key.keysym.scancode == SDL_SCANCODE_SPACE) { anykey = false; } if (sdlEvent.key.keysym.scancode == SDL_SCANCODE_SPACE) { anykey = false; }
case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEWHEEL:
debug_mouse_event(sdlEvent); debug_mouse_event(sdlEvent);
break; break;
} }

22
vdp.cpp
View File

@@ -65,25 +65,15 @@ static Uint8 palette[16][4] = {
void vdp_init() { void vdp_init() {
SDL_Init(SDL_INIT_EVERYTHING); 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); sdlRenderer = SDL_CreateRenderer(sdlWindow, -1, SDL_RENDERER_PRESENTVSYNC);
//SDL_SetRenderDrawBlendMode(sdlRenderer, SDL_BLENDMODE_BLEND);
SDL_RenderSetLogicalSize(sdlRenderer, 152, 120); SDL_RenderSetLogicalSize(sdlRenderer, 152, 120);
SDL_SetRenderDrawColor(sdlRenderer, palette[border][0], palette[border][1], palette[border][2], palette[border][3]); 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_map[i] = 32;
for (int i = 0; i < 16 * 12; i++) screen_color[i] = color; 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; src.x = src.y = 0;
dst.x = dst.y = 12; dst.x = dst.y = 12;
@@ -152,6 +142,12 @@ void vdp_flip() {
void vdp_switch_fullscreen() { void vdp_switch_fullscreen() {
SDL_SetWindowFullscreen(sdlWindow, fullscreen ? 0 : SDL_WINDOW_FULLSCREEN_DESKTOP); SDL_SetWindowFullscreen(sdlWindow, fullscreen ? 0 : SDL_WINDOW_FULLSCREEN_DESKTOP);
fullscreen = !fullscreen; 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) { void vdp_data_out(const unsigned char& value) {