comparison blastem.c @ 1438:e2bd03ed3190

Allow reloading current ROM with a hotkey (default F5) and allow locking on a cartridge via menu
author Michael Pavone <pavone@retrodev.com>
date Wed, 23 Aug 2017 21:18:17 -0700
parents 2540c05520f2
children 3d48cb0c28be
comparison
equal deleted inserted replaced
1437:da72344af3ff 1438:e2bd03ed3190
205 } else { 205 } else {
206 puts("no menu"); 206 puts("no menu");
207 } 207 }
208 } 208 }
209 209
210 static system_media cart, lock_on;
211 void reload_media(void)
212 {
213 if (current_system->next_rom) {
214 free(current_system->next_rom);
215 }
216 char const *parts[] = {
217 cart.dir, PATH_SEP, cart.name, ".", cart.extension
218 };
219 char const **start = parts[0] ? parts : parts + 2;
220 int num_parts = parts[0] ? 5 : 3;
221 if (!parts[4]) {
222 num_parts--;
223 }
224 current_system->next_rom = alloc_concat_m(num_parts, start);
225 current_system->request_exit(current_system);
226 }
227
228 void lockon_media(char *lock_on_path)
229 {
230 reload_media();
231 cart.chain = &lock_on;
232 free(lock_on.dir);
233 free(lock_on.name);
234 free(lock_on.extension);
235 lock_on.dir = path_dirname(lock_on_path);
236 lock_on.name = basename_no_extension(lock_on_path);
237 lock_on.extension = path_extension(lock_on_path);
238 lock_on.size = load_rom(lock_on_path, &lock_on.buffer, NULL);
239 }
240
210 int main(int argc, char ** argv) 241 int main(int argc, char ** argv)
211 { 242 {
212 set_exe_str(argv[0]); 243 set_exe_str(argv[0]);
213 config = load_config(); 244 config = load_config();
214 int width = -1; 245 int width = -1;
218 int loaded = 0; 249 int loaded = 0;
219 system_type stype = SYSTEM_UNKNOWN, force_stype = SYSTEM_UNKNOWN; 250 system_type stype = SYSTEM_UNKNOWN, force_stype = SYSTEM_UNKNOWN;
220 uint8_t force_region = 0; 251 uint8_t force_region = 0;
221 char * romfname = NULL; 252 char * romfname = NULL;
222 char * statefile = NULL; 253 char * statefile = NULL;
223 system_media cart = {.chain = NULL}, lock_on;
224 debugger_type dtype = DEBUGGER_NATIVE; 254 debugger_type dtype = DEBUGGER_NATIVE;
225 uint8_t start_in_debugger = 0; 255 uint8_t start_in_debugger = 0;
226 uint8_t fullscreen = FULLSCREEN_DEFAULT, use_gl = 1; 256 uint8_t fullscreen = FULLSCREEN_DEFAULT, use_gl = 1;
227 uint8_t debug_target = 0; 257 uint8_t debug_target = 0;
228 for (int i = 1; i < argc; i++) { 258 for (int i = 1; i < argc; i++) {
342 } 372 }
343 } else if (!loaded) { 373 } else if (!loaded) {
344 if (!(cart.size = load_rom(argv[i], &cart.buffer, stype == SYSTEM_UNKNOWN ? &stype : NULL))) { 374 if (!(cart.size = load_rom(argv[i], &cart.buffer, stype == SYSTEM_UNKNOWN ? &stype : NULL))) {
345 fatal_error("Failed to open %s for reading\n", argv[i]); 375 fatal_error("Failed to open %s for reading\n", argv[i]);
346 } 376 }
377 cart.dir = path_dirname(argv[i]);
347 cart.name = basename_no_extension(argv[i]); 378 cart.name = basename_no_extension(argv[i]);
348 cart.extension = path_extension(argv[i]); 379 cart.extension = path_extension(argv[i]);
349 romfname = argv[i]; 380 romfname = argv[i];
350 loaded = 1; 381 loaded = 1;
351 } else if (width < 0) { 382 } else if (width < 0) {
376 cart.size = rom_size; 407 cart.size = rom_size;
377 } 408 }
378 } 409 }
379 //force system detection, value on command line is only for games not the menu 410 //force system detection, value on command line is only for games not the menu
380 stype = detect_system_type(&cart); 411 stype = detect_system_type(&cart);
412 cart.dir = path_dirname(romfname);
381 cart.name = basename_no_extension(romfname); 413 cart.name = basename_no_extension(romfname);
382 cart.extension = path_extension(romfname); 414 cart.extension = path_extension(romfname);
383 loaded = 1; 415 loaded = 1;
384 } 416 }
385 417
459 current_system->arena = start_new_arena(); 491 current_system->arena = start_new_arena();
460 } 492 }
461 if (!(cart.size = load_rom(next_rom, &cart.buffer, &stype))) { 493 if (!(cart.size = load_rom(next_rom, &cart.buffer, &stype))) {
462 fatal_error("Failed to open %s for reading\n", next_rom); 494 fatal_error("Failed to open %s for reading\n", next_rom);
463 } 495 }
496 free(cart.dir);
497 free(cart.name);
498 free(cart.extension);
499 cart.dir = path_dirname(next_rom);
464 cart.name = basename_no_extension(next_rom); 500 cart.name = basename_no_extension(next_rom);
465 cart.extension = path_extension(next_rom); 501 cart.extension = path_extension(next_rom);
466 stype = force_stype; 502 stype = force_stype;
467 if (stype == SYSTEM_UNKNOWN) { 503 if (stype == SYSTEM_UNKNOWN) {
468 stype = detect_system_type(&cart); 504 stype = detect_system_type(&cart);
473 //allocate new system context 509 //allocate new system context
474 game_system = alloc_config_system(stype, &cart, opts,force_region, &info); 510 game_system = alloc_config_system(stype, &cart, opts,force_region, &info);
475 if (!game_system) { 511 if (!game_system) {
476 fatal_error("Failed to configure emulated machine for %s\n", next_rom); 512 fatal_error("Failed to configure emulated machine for %s\n", next_rom);
477 } 513 }
478 menu_system->next_context = game_system; 514 if (menu_system) {
515 menu_system->next_context = game_system;
516 }
479 game_system->next_context = menu_system; 517 game_system->next_context = menu_system;
480 setup_saves(&cart, &info, game_system); 518 setup_saves(&cart, &info, game_system);
481 update_title(info.name); 519 update_title(info.name);
482 free(next_rom); 520 free(next_rom);
483 menu = 0; 521 menu = 0;