MCPcopy Create free account
hub / github.com/TASEmulators/fceux / FCEUXLoad

Function FCEUXLoad

src/fceu.cpp:1490–1539  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1488}
1489
1490bool FCEUXLoad(const char *name, FCEUFILE *fp) {
1491 //read ines header
1492 iNES_HEADER head;
1493 if (FCEU_fread(&head, 1, 16, fp) != 16)
1494 return false;
1495
1496 //validate header
1497 if (memcmp(&head, "NES\x1a", 4))
1498 return 0;
1499
1500 int mapper = (head.ROM_type >> 4);
1501 mapper |= (head.ROM_type2 & 0xF0);
1502
1503 //choose what kind of cart to use.
1504 cart = (FCEUXCart*)new NROM();
1505
1506 //fceu ines loading code uses 256 here when the romsize is 0.
1507 cart->prgPages = head.ROM_size;
1508 if (cart->prgPages == 0) {
1509 printf("FCEUX: received zero prgpages\n");
1510 cart->prgPages = 256;
1511 }
1512
1513 cart->chrPages = head.VROM_size;
1514
1515 cart->mirroring = (head.ROM_type & 1);
1516 if (head.ROM_type & 8) cart->mirroring = 2;
1517
1518 //skip trainer
1519 bool hasTrainer = (head.ROM_type & 4) != 0;
1520 if (hasTrainer) {
1521 FCEU_fseek(fp, 512, SEEK_CUR);
1522 }
1523
1524 //load data
1525 cart->prgSize = cart->prgPages * 16 * 1024;
1526 cart->chrSize = cart->chrPages * 8 * 1024;
1527 cart->PRG = new char[cart->prgSize];
1528 cart->CHR = new char[cart->chrSize];
1529 FCEU_fread(cart->PRG, 1, cart->prgSize, fp);
1530 FCEU_fread(cart->CHR, 1, cart->chrSize, fp);
1531
1532 //setup the emulator
1533 GameInterface = FCEUXGameInterface;
1534 ResetCartMapping();
1535 SetupCartPRGMapping(0, (uint8*)cart->PRG, cart->prgSize, 0);
1536 SetupCartCHRMapping(0, (uint8*)cart->CHR, cart->chrSize, 0);
1537
1538 return true;
1539}
1540
1541uint8 FCEU_ReadRomByte(uint32 i) {
1542 extern iNES_HEADER head;

Callers

nothing calls this directly

Calls 5

FCEU_freadFunction · 0.85
FCEU_fseekFunction · 0.85
ResetCartMappingFunction · 0.85
SetupCartPRGMappingFunction · 0.85
SetupCartCHRMappingFunction · 0.85

Tested by

no test coverage detected