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

Function iNESLoad

src/ines.cpp:804–1091  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

802};
803
804int iNESLoad(const char *name, FCEUFILE *fp, int OverwriteVidMode) {
805 int result;
806 struct md5_context md5;
807 uint64 partialmd5 = 0;
808 const char* mappername = "Not Listed";
809
810 if (FCEU_fread(&head, 1, 16, fp) != 16 || memcmp(&head, "NES\x1A", 4))
811 return LOADER_INVALID_FORMAT;
812
813 head.cleanup();
814
815 iNESCart.clear();
816
817 iNES2 = ((head.ROM_type2 & 0x0C) == 0x08);
818 if(iNES2)
819 {
820 iNESCart.ines2 = true;
821 iNESCart.wram_size = (head.RAM_size & 0x0F)?(64 << (head.RAM_size & 0x0F)):0;
822 iNESCart.battery_wram_size = (head.RAM_size & 0xF0)?(64 << ((head.RAM_size & 0xF0)>>4)):0;
823 iNESCart.vram_size = (head.VRAM_size & 0x0F)?(64 << (head.VRAM_size & 0x0F)):0;
824 iNESCart.battery_vram_size = (head.VRAM_size & 0xF0)?(64 << ((head.VRAM_size & 0xF0)>>4)):0;
825 iNESCart.submapper = head.ROM_type3 >> 4;
826 }
827
828 MapperNo = (head.ROM_type >> 4);
829 MapperNo |= (head.ROM_type2 & 0xF0);
830 if(iNES2) MapperNo |= ((head.ROM_type3 & 0x0F) << 8);
831
832 if (head.ROM_type & 8) {
833 Mirroring = 2;
834 } else
835 Mirroring = (head.ROM_type & 1);
836
837 MirroringAs2bits = head.ROM_type & 1;
838 if (head.ROM_type & 8) MirroringAs2bits |= 2;
839
840 int not_round_size;
841 if (!iNES2) {
842 not_round_size = head.ROM_size;
843 }
844 else {
845 if ((head.Upper_ROM_VROM_size & 0x0F) != 0x0F)
846 // simple notation
847 not_round_size = head.ROM_size | ((head.Upper_ROM_VROM_size & 0x0F) << 8);
848 else
849 // exponent-multiplier notation
850 not_round_size = ((1 << (head.ROM_size >> 2)) * ((head.ROM_size & 0b11) * 2 + 1)) >> 14;
851 }
852
853 if (!head.ROM_size && !iNES2)
854 ROM_size = 256;
855 else
856 ROM_size = uppow2(not_round_size);
857
858 VROM_size = uppow2(head.VROM_size | (iNES2?((head.Upper_ROM_VROM_size & 0xF0)<<4):0));
859 if (!iNES2) {
860 VROM_size = uppow2(head.VROM_size);
861 }

Callers 1

FCEUI_LoadGameVirtualFunction · 0.85

Calls 15

FCEU_freadFunction · 0.85
uppow2Function · 0.85
FCEU_mallocFunction · 0.85
FCEU_PrintErrorFunction · 0.85
FCEU_gmallocFunction · 0.85
ResetCartMappingFunction · 0.85
ResetExStateFunction · 0.85
SetupCartPRGMappingFunction · 0.85
CalcCRC32Function · 0.85
FCEU_printfFunction · 0.85
SetInputFunction · 0.85
SetInputNes20Function · 0.85

Tested by

no test coverage detected