comparison blastem.c @ 1423:9a3e003bdcb3

Make drag and drop play nice with the menu
author Michael Pavone <pavone@retrodev.com>
date Fri, 30 Jun 2017 18:42:52 -0700
parents 909c72c4e5a1
children 2540c05520f2
comparison
equal deleted inserted replaced
1422:2b34469e3f81 1423:9a3e003bdcb3
21 #include "util.h" 21 #include "util.h"
22 #include "romdb.h" 22 #include "romdb.h"
23 #include "terminal.h" 23 #include "terminal.h"
24 #include "arena.h" 24 #include "arena.h"
25 #include "config.h" 25 #include "config.h"
26 #include "menu.h"
26 27
27 #define BLASTEM_VERSION "0.5.1-pre" 28 #define BLASTEM_VERSION "0.5.1-pre"
28 29
29 #ifdef __ANDROID__ 30 #ifdef __ANDROID__
30 #define FULLSCREEN_DEFAULT 1 31 #define FULLSCREEN_DEFAULT 1
114 115
115 116
116 117
117 char * save_filename; 118 char * save_filename;
118 system_header *current_system; 119 system_header *current_system;
119 system_header *menu_context; 120 system_header *menu_system;
120 system_header *game_context; 121 system_header *game_system;
121 void persist_save() 122 void persist_save()
122 { 123 {
123 if (!game_context) { 124 if (!game_system) {
124 return; 125 return;
125 } 126 }
126 game_context->persist_save(game_context); 127 game_system->persist_save(game_system);
127 } 128 }
128 129
129 char *title; 130 char *title;
130 void update_title(char *rom_name) 131 void update_title(char *rom_name)
131 { 132 {
187 if (current_system->next_rom) { 188 if (current_system->next_rom) {
188 free(current_system->next_rom); 189 free(current_system->next_rom);
189 } 190 }
190 current_system->next_rom = strdup(filename); 191 current_system->next_rom = strdup(filename);
191 current_system->request_exit(current_system); 192 current_system->request_exit(current_system);
193 if (menu_system && menu_system->type == SYSTEM_GENESIS) {
194 genesis_context *gen = (genesis_context *)menu_system;
195 if (gen->extra) {
196 menu_context *menu = gen->extra;
197 menu->external_game_load = 1;
198 } else {
199 puts("No extra");
200 }
201 } else {
202 puts("no menu");
203 }
192 } 204 }
193 205
194 int main(int argc, char ** argv) 206 int main(int argc, char ** argv)
195 { 207 {
196 set_exe_str(argv[0]); 208 set_exe_str(argv[0]);
406 fatal_error("Failed to configure emulated machine for %s\n", romfname); 418 fatal_error("Failed to configure emulated machine for %s\n", romfname);
407 } 419 }
408 setup_saves(&cart, &info, current_system); 420 setup_saves(&cart, &info, current_system);
409 update_title(info.name); 421 update_title(info.name);
410 if (menu) { 422 if (menu) {
411 menu_context = current_system; 423 menu_system = current_system;
412 } else { 424 } else {
413 game_context = current_system; 425 game_system = current_system;
414 } 426 }
415 427
416 current_system->debugger_type = dtype; 428 current_system->debugger_type = dtype;
417 current_system->enter_debugger = start_in_debugger && menu == debug_target; 429 current_system->enter_debugger = start_in_debugger && menu == debug_target;
418 current_system->start_context(current_system, menu ? NULL : statefile); 430 current_system->start_context(current_system, menu ? NULL : statefile);
422 break; 434 break;
423 } 435 }
424 if (current_system->next_rom) { 436 if (current_system->next_rom) {
425 char *next_rom = current_system->next_rom; 437 char *next_rom = current_system->next_rom;
426 current_system->next_rom = NULL; 438 current_system->next_rom = NULL;
427 if (game_context) { 439 if (game_system) {
428 game_context->persist_save(game_context); 440 game_system->persist_save(game_system);
429 //swap to game context arena and mark all allocated pages in it free 441 //swap to game context arena and mark all allocated pages in it free
430 if (menu) { 442 if (menu) {
431 current_system->arena = set_current_arena(game_context->arena); 443 current_system->arena = set_current_arena(game_system->arena);
432 } 444 }
433 mark_all_free(); 445 mark_all_free();
434 game_context->free_context(game_context); 446 game_system->free_context(game_system);
435 } else { 447 } else {
436 //start a new arena and save old one in suspended genesis context 448 //start a new arena and save old one in suspended genesis context
437 current_system->arena = start_new_arena(); 449 current_system->arena = start_new_arena();
438 } 450 }
439 if (!(cart.size = load_rom(next_rom, &cart.buffer, &stype))) { 451 if (!(cart.size = load_rom(next_rom, &cart.buffer, &stype))) {
447 } 459 }
448 if (stype == SYSTEM_UNKNOWN) { 460 if (stype == SYSTEM_UNKNOWN) {
449 fatal_error("Failed to detect system type for %s\n", next_rom); 461 fatal_error("Failed to detect system type for %s\n", next_rom);
450 } 462 }
451 //allocate new system context 463 //allocate new system context
452 game_context = alloc_config_system(stype, &cart, opts,force_region, &info); 464 game_system = alloc_config_system(stype, &cart, opts,force_region, &info);
453 if (!game_context) { 465 if (!game_system) {
454 fatal_error("Failed to configure emulated machine for %s\n", next_rom); 466 fatal_error("Failed to configure emulated machine for %s\n", next_rom);
455 } 467 }
456 menu_context->next_context = game_context; 468 menu_system->next_context = game_system;
457 game_context->next_context = menu_context; 469 game_system->next_context = menu_system;
458 setup_saves(&cart, &info, game_context); 470 setup_saves(&cart, &info, game_system);
459 update_title(info.name); 471 update_title(info.name);
460 free(next_rom); 472 free(next_rom);
461 menu = 0; 473 menu = 0;
462 current_system = game_context; 474 current_system = game_system;
463 current_system->debugger_type = dtype; 475 current_system->debugger_type = dtype;
464 current_system->enter_debugger = start_in_debugger && menu == debug_target; 476 current_system->enter_debugger = start_in_debugger && menu == debug_target;
465 current_system->start_context(current_system, statefile); 477 current_system->start_context(current_system, statefile);
466 } else if (menu && game_context) { 478 } else if (menu && game_system) {
467 current_system->arena = set_current_arena(game_context->arena); 479 current_system->arena = set_current_arena(game_system->arena);
468 current_system = game_context; 480 current_system = game_system;
469 menu = 0; 481 menu = 0;
470 current_system->resume_context(current_system); 482 current_system->resume_context(current_system);
471 } else if (!menu && menu_context) { 483 } else if (!menu && menu_system) {
472 current_system->arena = set_current_arena(menu_context->arena); 484 current_system->arena = set_current_arena(menu_system->arena);
473 current_system = menu_context; 485 current_system = menu_system;
474 menu = 1; 486 menu = 1;
475 current_system->resume_context(current_system); 487 current_system->resume_context(current_system);
476 } else { 488 } else {
477 break; 489 break;
478 } 490 }