MCPcopy Create free account
hub / github.com/dborth/fceugx / BrowserLoadFile

Function BrowserLoadFile

source/filebrowser.cpp:520–611  ·  view source on GitHub ↗

* BrowserLoadFile * * Loads the selected ROM ***************************************************************************/

Source from the content-addressed store, hash-verified

518 * Loads the selected ROM
519 ***************************************************************************/
520int BrowserLoadFile()
521{
522 char filepath[1024];
523 size_t filesize = 0;
524 romLoaded = false;
525
526 int device;
527
528 if(!FindDevice(browser.dir, &device))
529 return 0;
530
531 // check that this is a valid ROM
532 if(!IsValidROM())
533 goto done;
534
535 loadingFile = true;
536
537 if(!inSz)
538 {
539 if(!MakeFilePath(filepath, FILE_ROM))
540 goto done;
541
542 filesize = LoadFile ((char *)nesrom, filepath, 0, (1024*1024*4), NOTSILENT);
543
544 if(filesize > 0) {
545 // check nesrom for PocketNES embedded roms
546 const char *ext = strrchr(filepath, '.');
547 if (ext != NULL && strcmp(ext, ".gba") == 0)
548 {
549 const pocketnes_romheader* rom1 = pocketnes_first_rom(nesrom, filesize);
550 const pocketnes_romheader* rom2 = NULL;
551 if (rom1 != NULL) {
552 rom2 = pocketnes_next_rom(nesrom, filesize, rom1);
553 }
554
555 if (rom1 == NULL)
556 ErrorPrompt("No NES ROMs found in this file.");
557 else if (rom2 != NULL)
558 ErrorPrompt("More than one NES ROM found in this file. Only files with one ROM are supported.");
559 else
560 {
561 const void* rom = rom1 + 1;
562 filesize = little_endian_conv_32(rom1->filesize);
563 memcpy(nesrom, rom, filesize);
564 }
565 }
566 }
567 }
568 else
569 {
570 filesize = LoadSzFile(szpath, nesrom);
571
572 if(filesize <= 0)
573 {
574 browser.selIndex = 0;
575 BrowserChangeFolder();
576 }
577 }

Callers 2

MenuGameSelectionFunction · 0.85
AutoloadGameFunction · 0.85

Calls 15

FindDeviceFunction · 0.85
IsValidROMFunction · 0.85
MakeFilePathFunction · 0.85
LoadFileFunction · 0.85
pocketnes_first_romFunction · 0.85
pocketnes_next_romFunction · 0.85
ErrorPromptFunction · 0.85
little_endian_conv_32Function · 0.85
LoadSzFileFunction · 0.85
BrowserChangeFolderFunction · 0.85
StripExtFunction · 0.85
LoadPatchFunction · 0.85

Tested by

no test coverage detected