summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--blastem.c37
-rw-r--r--render.h3
-rwxr-xr-xrender_sdl.c12
3 files changed, 40 insertions, 12 deletions
diff --git a/blastem.c b/blastem.c
index 561623a..9e30461 100644
--- a/blastem.c
+++ b/blastem.c
@@ -172,6 +172,15 @@ void setup_saves(char *fname, rom_info *info, system_header *context)
}
}
+static void on_drag_drop(const char *filename)
+{
+ if (current_system->next_rom) {
+ free(current_system->next_rom);
+ }
+ current_system->next_rom = strdup(filename);
+ current_system->request_exit(current_system);
+}
+
int main(int argc, char ** argv)
{
set_exe_str(argv[0]);
@@ -365,6 +374,7 @@ int main(int argc, char ** argv)
}
if (!headless) {
render_init(width, height, "BlastEm", fullscreen);
+ render_set_drag_drop_handler(on_drag_drop);
}
if (stype == SYSTEM_UNKNOWN) {
@@ -394,40 +404,43 @@ int main(int argc, char ** argv)
if (current_system->should_exit) {
break;
}
- if (menu && menu_context->next_rom) {
+ if (current_system->next_rom) {
+ char *next_rom = current_system->next_rom;
+ current_system->next_rom = NULL;
if (game_context) {
game_context->persist_save(game_context);
//swap to game context arena and mark all allocated pages in it free
- current_system->arena = set_current_arena(game_context->arena);
+ if (menu) {
+ current_system->arena = set_current_arena(game_context->arena);
+ }
mark_all_free();
game_context->free_context(game_context);
} else {
//start a new arena and save old one in suspended genesis context
current_system->arena = start_new_arena();
}
- if (!(cart.size = load_rom(menu_context->next_rom, &cart.buffer, &stype))) {
- fatal_error("Failed to open %s for reading\n", menu_context->next_rom);
+ if (!(cart.size = load_rom(next_rom, &cart.buffer, &stype))) {
+ fatal_error("Failed to open %s for reading\n", next_rom);
}
- cart.name = basename_no_extension(menu_context->next_rom);
- cart.extension = path_extension(menu_context->next_rom);
+ cart.name = basename_no_extension(next_rom);
+ cart.extension = path_extension(next_rom);
stype = force_stype;
if (stype == SYSTEM_UNKNOWN) {
stype = detect_system_type(&cart);
}
if (stype == SYSTEM_UNKNOWN) {
- fatal_error("Failed to detect system type for %s\n", menu_context->next_rom);
+ fatal_error("Failed to detect system type for %s\n", next_rom);
}
- //allocate new genesis context
+ //allocate new system context
game_context = alloc_config_system(stype, &cart, opts,force_region, &info);
if (!game_context) {
- fatal_error("Failed to configure emulated machine for %s\n", menu_context->next_rom);
+ fatal_error("Failed to configure emulated machine for %s\n", next_rom);
}
menu_context->next_context = game_context;
game_context->next_context = menu_context;
- setup_saves(menu_context->next_rom, &info, game_context);
+ setup_saves(next_rom, &info, game_context);
update_title(info.name);
- free(menu_context->next_rom);
- menu_context->next_rom = NULL;
+ free(next_rom);
menu = 0;
current_system = game_context;
current_system->debugger_type = dtype;
diff --git a/render.h b/render.h
index 9e55022..873ff72 100644
--- a/render.h
+++ b/render.h
@@ -69,6 +69,8 @@ typedef enum {
#define RENDER_NOT_MAPPED -2
#define RENDER_NOT_PLUGGED_IN -3
+typedef void (*drop_handler)(const char *filename);
+
uint32_t render_map_color(uint8_t r, uint8_t g, uint8_t b);
void render_save_screenshot(char *path);
uint32_t *render_get_framebuffer(uint8_t which, int *pitch);
@@ -88,6 +90,7 @@ void process_events();
int render_width();
int render_height();
int render_fullscreen();
+void render_set_drag_drop_handler(drop_handler handler);
void process_events();
int32_t render_translate_input_name(int32_t controller, char *name, uint8_t is_axis);
int32_t render_dpad_part(int32_t input);
diff --git a/render_sdl.c b/render_sdl.c
index d2fda42..8e1e7f6 100755
--- a/render_sdl.c
+++ b/render_sdl.c
@@ -914,6 +914,12 @@ static uint8_t scancode_map[SDL_NUM_SCANCODES] = {
[SDL_SCANCODE_KP_PERIOD] = 0x71,
};
+static drop_handler drag_drop_handler;
+void render_set_drag_drop_handler(drop_handler handler)
+{
+ drag_drop_handler = handler;
+}
+
static int32_t handle_event(SDL_Event *event)
{
switch (event->type) {
@@ -986,6 +992,12 @@ static int32_t handle_event(SDL_Event *event)
break;
}
break;
+ case SDL_DROPFILE:
+ if (drag_drop_handler) {
+ drag_drop_handler(event->drop.file);
+ }
+ SDL_free(event->drop.file);
+ break;
case SDL_QUIT:
puts("");
exit(0);