summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--genesis.h1
-rw-r--r--render.h3
-rwxr-xr-xrender_sdl.c20
-rw-r--r--vdp.c17
-rw-r--r--vdp.h2
5 files changed, 38 insertions, 5 deletions
diff --git a/genesis.h b/genesis.h
index 2b3163e..04c9069 100644
--- a/genesis.h
+++ b/genesis.h
@@ -60,7 +60,6 @@ struct genesis_context {
#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 --git a/render.h b/render.h
index fd05811..a5f585e 100644
--- a/render.h
+++ b/render.h
@@ -86,10 +86,11 @@ typedef enum {
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 --git a/render_sdl.c b/render_sdl.c
index a13eb91..d50ac6c 100755
--- a/render_sdl.c
+++ b/render_sdl.c
@@ -29,6 +29,7 @@ static SDL_Window **extra_windows;
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 @@ static int32_t handle_event(SDL_Event *event)
}
#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 @@ void render_save_screenshot(char *path)
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 @@ uint8_t render_create_window(char *caption, uint32_t width, uint32_t height)
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 @@ uint8_t render_create_window(char *caption, uint32_t width, uint32_t height)
if (!sdl_textures[texture_idx]) {
goto fail_texture;
}
+ close_handlers[win_idx] = close_handler;
return texture_idx;
fail_texture:
diff --git a/vdp.c b/vdp.c
index e1eef7b..9c1cf0e 100644
--- a/vdp.c
+++ b/vdp.c
@@ -5,7 +5,6 @@
*/
#include "vdp.h"
#include "blastem.h"
-#include "genesis.h"
#include <stdlib.h>
#include <string.h>
#include "render.h"
@@ -3875,6 +3874,19 @@ void vdp_deserialize(deserialize_buffer *buf, void *vcontext)
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 @@ void vdp_toggle_debug_view(vdp_context *context, uint8_t debug_type)
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 --git a/vdp.h b/vdp.h
index fec1c35..22a5c2f 100644
--- a/vdp.h
+++ b/vdp.h
@@ -271,5 +271,7 @@ void vdp_deserialize(deserialize_buffer *buf, void *vcontext);
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_