Ejemplo n.º 1
0
        public static Cartridge FromFile(string path)
        {
            var cartridge = new Cartridge();
            var rom       = new ROM();

            if (!File.Exists(path))
            {
                return(null);
            }

            var reader = File.OpenRead(path);

            rom.nesTitle    = reader.Nextbytes(4);
            rom.numPRGPages = (byte)reader.ReadByte();
            rom.numCHRPages = (byte)reader.ReadByte();
            rom.flags6      = (byte)reader.ReadByte();
            rom.flags7      = (byte)reader.ReadByte();
            rom.endOfHeader = reader.Nextbytes(8);

            //Check the third bit to check if the ROM has a trainer
            if (Bit.Test(rom.flags6, 3))
            {
                //if the trainer is there, then it's 512 bytes long. Always.
                rom.trainer = reader.Nextbytes(ROM.TrainerSize);
            }

            rom.prgROM = reader.Nextbytes((int)rom.numPRGPages * ROM.PrgPageSize);
            rom.chrROM = reader.Nextbytes((int)rom.numCHRPages * ROM.ChrPageSize);

            cartridge.Rom    = rom;
            cartridge.mapper = cartridge.GetMapperInstance(rom.mapper);

            return(cartridge);
        }
Ejemplo n.º 2
0
        public bool LoadCartridge(string fileName)
        {
            var c = Cartridge.FromFile(fileName);

            if (c == null)
            {
                return(false);
            }
            Bus.Cartridge = c;
            return(true);
        }