# HG changeset patch # User Michael Pavone # Date 1545191880 28800 # Node ID b500e971da7502e7ae6f7566162f22e2e7276935 # Parent 5a662692c215fafb0c6cf5e5a916a4ef0a67b604 Allow closing VDP debug windows with the close button in the window title bar diff -r 5a662692c215 -r b500e971da75 genesis.h --- a/genesis.h Sat Dec 15 13:06:47 2018 -0800 +++ b/genesis.h Tue Dec 18 19:58:00 2018 -0800 @@ -60,7 +60,6 @@ #define RAM_WORDS 32 * 1024 #define Z80_RAM_BYTES 8 * 1024 -uint16_t read_dma_value(uint32_t address); m68k_context * sync_components(m68k_context *context, uint32_t address); genesis_context *alloc_config_genesis(void *rom, uint32_t rom_size, void *lock_on, uint32_t lock_on_size, uint32_t system_opts, uint8_t force_region); void genesis_serialize(genesis_context *gen, serialize_buffer *buf, uint32_t m68k_pc); diff -r 5a662692c215 -r b500e971da75 render.h --- a/render.h Sat Dec 15 13:06:47 2018 -0800 +++ b/render.h Tue Dec 18 19:58:00 2018 -0800 @@ -86,10 +86,11 @@ typedef struct audio_source audio_source; typedef void (*drop_handler)(const char *filename); +typedef void (*window_close_handler)(uint8_t which); uint32_t render_map_color(uint8_t r, uint8_t g, uint8_t b); void render_save_screenshot(char *path); -uint8_t render_create_window(char *caption, uint32_t width, uint32_t height); +uint8_t render_create_window(char *caption, uint32_t width, uint32_t height, window_close_handler close_handler); void render_destroy_window(uint8_t which); uint32_t *render_get_framebuffer(uint8_t which, int *pitch); void render_framebuffer_updated(uint8_t which, int width); diff -r 5a662692c215 -r b500e971da75 render_sdl.c --- a/render_sdl.c Sat Dec 15 13:06:47 2018 -0800 +++ b/render_sdl.c Tue Dec 18 19:58:00 2018 -0800 @@ -29,6 +29,7 @@ static SDL_Renderer *main_renderer; static SDL_Renderer **extra_renderers; static SDL_Texture **sdl_textures; +static window_close_handler *close_handlers; static uint8_t num_textures; static SDL_Rect main_clip; static SDL_GLContext *main_context; @@ -921,6 +922,21 @@ } #endif break; + case SDL_WINDOWEVENT_CLOSE: + if (SDL_GetWindowID(main_window) == event->window.windowID) { + exit(0); + } else { + for (int i = 0; i < num_textures - FRAMEBUFFER_USER_START; i++) + { + if (SDL_GetWindowID(extra_windows[i]) == event->window.windowID) { + if (close_handlers[i]) { + close_handlers[i](i + FRAMEBUFFER_USER_START); + } + break; + } + } + } + break; } break; case SDL_DROPFILE: @@ -1326,7 +1342,7 @@ screenshot_path = path; } -uint8_t render_create_window(char *caption, uint32_t width, uint32_t height) +uint8_t render_create_window(char *caption, uint32_t width, uint32_t height, window_close_handler close_handler) { uint8_t win_idx = 0xFF; for (int i = 0; i < num_textures - FRAMEBUFFER_USER_START; i++) @@ -1342,6 +1358,7 @@ sdl_textures = realloc(sdl_textures, num_textures * sizeof(*sdl_textures)); extra_windows = realloc(extra_windows, (num_textures - FRAMEBUFFER_USER_START) * sizeof(*extra_windows)); extra_renderers = realloc(extra_renderers, (num_textures - FRAMEBUFFER_USER_START) * sizeof(*extra_renderers)); + close_handlers = realloc(close_handlers, (num_textures - FRAMEBUFFER_USER_START) * sizeof(*close_handlers)); win_idx = num_textures - FRAMEBUFFER_USER_START - 1; } extra_windows[win_idx] = SDL_CreateWindow(caption, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, 0); @@ -1357,6 +1374,7 @@ if (!sdl_textures[texture_idx]) { goto fail_texture; } + close_handlers[win_idx] = close_handler; return texture_idx; fail_texture: diff -r 5a662692c215 -r b500e971da75 vdp.c --- a/vdp.c Sat Dec 15 13:06:47 2018 -0800 +++ b/vdp.c Tue Dec 18 19:58:00 2018 -0800 @@ -5,7 +5,6 @@ */ #include "vdp.h" #include "blastem.h" -#include "genesis.h" #include #include #include "render.h" @@ -3875,6 +3874,19 @@ update_video_params(context); } +static vdp_context *current_vdp; +static void vdp_debug_window_close(uint8_t which) +{ + //TODO: remove need for current_vdp global, and find the VDP via current_system instead + for (int i = 0; i < VDP_NUM_DEBUG_TYPES; i++) + { + if (current_vdp->enabled_debuggers & (1 << i) && which == current_vdp->debug_fb_indices[i]) { + vdp_toggle_debug_view(current_vdp, i); + break; + } + } +} + void vdp_toggle_debug_view(vdp_context *context, uint8_t debug_type) { if (context->enabled_debuggers & 1 << debug_type) { @@ -3910,7 +3922,8 @@ default: return; } - context->debug_fb_indices[debug_type] = render_create_window(caption, width, height); + current_vdp = context; + context->debug_fb_indices[debug_type] = render_create_window(caption, width, height, vdp_debug_window_close); if (context->debug_fb_indices[debug_type]) { context->enabled_debuggers |= 1 << debug_type; } diff -r 5a662692c215 -r b500e971da75 vdp.h --- a/vdp.h Sat Dec 15 13:06:47 2018 -0800 +++ b/vdp.h Tue Dec 18 19:58:00 2018 -0800 @@ -271,5 +271,7 @@ void vdp_force_update_framebuffer(vdp_context *context); void vdp_toggle_debug_view(vdp_context *context, uint8_t debug_type); void vdp_inc_debug_mode(vdp_context *context); +//to be implemented by the host system +uint16_t read_dma_value(uint32_t address); #endif //VDP_H_