Mercurial > repos > blastem
comparison blastem.c @ 1397:89eb967fed72
Initial support for drag and drop. Some work needed for proper menu integration.
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Wed, 14 Jun 2017 09:48:46 -0700 |
parents | efa7225e0f07 |
children | 458df351af06 |
comparison
equal
deleted
inserted
replaced
1396:aca496957999 | 1397:89eb967fed72 |
---|---|
168 if (!persist_save_registered) { | 168 if (!persist_save_registered) { |
169 atexit(persist_save); | 169 atexit(persist_save); |
170 persist_save_registered = 1; | 170 persist_save_registered = 1; |
171 } | 171 } |
172 } | 172 } |
173 } | |
174 | |
175 static void on_drag_drop(const char *filename) | |
176 { | |
177 if (current_system->next_rom) { | |
178 free(current_system->next_rom); | |
179 } | |
180 current_system->next_rom = strdup(filename); | |
181 current_system->request_exit(current_system); | |
173 } | 182 } |
174 | 183 |
175 int main(int argc, char ** argv) | 184 int main(int argc, char ** argv) |
176 { | 185 { |
177 set_exe_str(argv[0]); | 186 set_exe_str(argv[0]); |
363 if (config_fullscreen && !strcmp("on", config_fullscreen)) { | 372 if (config_fullscreen && !strcmp("on", config_fullscreen)) { |
364 fullscreen = !fullscreen; | 373 fullscreen = !fullscreen; |
365 } | 374 } |
366 if (!headless) { | 375 if (!headless) { |
367 render_init(width, height, "BlastEm", fullscreen); | 376 render_init(width, height, "BlastEm", fullscreen); |
377 render_set_drag_drop_handler(on_drag_drop); | |
368 } | 378 } |
369 | 379 |
370 if (stype == SYSTEM_UNKNOWN) { | 380 if (stype == SYSTEM_UNKNOWN) { |
371 stype = detect_system_type(&cart); | 381 stype = detect_system_type(&cart); |
372 } | 382 } |
392 for(;;) | 402 for(;;) |
393 { | 403 { |
394 if (current_system->should_exit) { | 404 if (current_system->should_exit) { |
395 break; | 405 break; |
396 } | 406 } |
397 if (menu && menu_context->next_rom) { | 407 if (current_system->next_rom) { |
408 char *next_rom = current_system->next_rom; | |
409 current_system->next_rom = NULL; | |
398 if (game_context) { | 410 if (game_context) { |
399 game_context->persist_save(game_context); | 411 game_context->persist_save(game_context); |
400 //swap to game context arena and mark all allocated pages in it free | 412 //swap to game context arena and mark all allocated pages in it free |
401 current_system->arena = set_current_arena(game_context->arena); | 413 if (menu) { |
414 current_system->arena = set_current_arena(game_context->arena); | |
415 } | |
402 mark_all_free(); | 416 mark_all_free(); |
403 game_context->free_context(game_context); | 417 game_context->free_context(game_context); |
404 } else { | 418 } else { |
405 //start a new arena and save old one in suspended genesis context | 419 //start a new arena and save old one in suspended genesis context |
406 current_system->arena = start_new_arena(); | 420 current_system->arena = start_new_arena(); |
407 } | 421 } |
408 if (!(cart.size = load_rom(menu_context->next_rom, &cart.buffer, &stype))) { | 422 if (!(cart.size = load_rom(next_rom, &cart.buffer, &stype))) { |
409 fatal_error("Failed to open %s for reading\n", menu_context->next_rom); | 423 fatal_error("Failed to open %s for reading\n", next_rom); |
410 } | 424 } |
411 cart.name = basename_no_extension(menu_context->next_rom); | 425 cart.name = basename_no_extension(next_rom); |
412 cart.extension = path_extension(menu_context->next_rom); | 426 cart.extension = path_extension(next_rom); |
413 stype = force_stype; | 427 stype = force_stype; |
414 if (stype == SYSTEM_UNKNOWN) { | 428 if (stype == SYSTEM_UNKNOWN) { |
415 stype = detect_system_type(&cart); | 429 stype = detect_system_type(&cart); |
416 } | 430 } |
417 if (stype == SYSTEM_UNKNOWN) { | 431 if (stype == SYSTEM_UNKNOWN) { |
418 fatal_error("Failed to detect system type for %s\n", menu_context->next_rom); | 432 fatal_error("Failed to detect system type for %s\n", next_rom); |
419 } | 433 } |
420 //allocate new genesis context | 434 //allocate new system context |
421 game_context = alloc_config_system(stype, &cart, opts,force_region, &info); | 435 game_context = alloc_config_system(stype, &cart, opts,force_region, &info); |
422 if (!game_context) { | 436 if (!game_context) { |
423 fatal_error("Failed to configure emulated machine for %s\n", menu_context->next_rom); | 437 fatal_error("Failed to configure emulated machine for %s\n", next_rom); |
424 } | 438 } |
425 menu_context->next_context = game_context; | 439 menu_context->next_context = game_context; |
426 game_context->next_context = menu_context; | 440 game_context->next_context = menu_context; |
427 setup_saves(menu_context->next_rom, &info, game_context); | 441 setup_saves(next_rom, &info, game_context); |
428 update_title(info.name); | 442 update_title(info.name); |
429 free(menu_context->next_rom); | 443 free(next_rom); |
430 menu_context->next_rom = NULL; | |
431 menu = 0; | 444 menu = 0; |
432 current_system = game_context; | 445 current_system = game_context; |
433 current_system->debugger_type = dtype; | 446 current_system->debugger_type = dtype; |
434 current_system->enter_debugger = start_in_debugger && menu == debug_target; | 447 current_system->enter_debugger = start_in_debugger && menu == debug_target; |
435 current_system->start_context(current_system, statefile); | 448 current_system->start_context(current_system, statefile); |