Ejemplo n.º 1
0
        public NesFile(byte[] data)
        {
            if (data[0] != 0x4E ||
                data[1] != 0x45 ||
                data[2] != 0x53 ||
                data[3] != 0x1A)
            {
                throw new Exception("Invalid NES file " + fileName);
            }

            if (!(data[12] == 0 && data[13] == 0 && data[14] == 0 && data[15] == 0))
            {
                // archaic iNES
                data[7] = data[8] = data[9] = data[10] = data[11] = data[12] = data[13] = data[14] = data[15] = 0;
            }

            var prgSize = data[4] * 16384;
            var chrSize = data[5] * 8192;

            Mirroring = (MirroringType)(data[6] & 1);
            Battery   = (data[6] & (1 << 1)) != 0;
            if ((data[6] & (1 << 2)) != 0)
            {
                Trainer = new byte[512];
            }
            else
            {
                Trainer = null;
            }
            if ((data[6] & (1 << 3)) != 0)
            {
                Mirroring = MirroringType.FourScreenVram;
            }

            Mapper = (byte)((data[6] >> 4) | (data[7] & 0xF0));

            VSunisystem  = (data[7] & 1) != 0;
            PlayChoice10 = (data[7] & (1 << 1)) != 0;

            /*
             * header[8] = 0; // PRG RAM size in 8 KB
             * header[9] = 0;
             */
            TvSystem = (TvSystemType)(data[9] & 1);

            int offset = 16;

            if (Trainer != null)
            {
                Array.Copy(data, offset, Trainer, 0, 512);
                offset += 512;
            }

            PRG = new byte[prgSize];
            Array.Copy(data, offset, PRG, 0, Math.Max(0, Math.Min(prgSize, data.Length - offset))); // Ignore end of for some bad ROMs
            offset += prgSize;

            CHR = new byte[chrSize];
            Array.Copy(data, offset, CHR, 0, Math.Max(0, Math.Min(chrSize, data.Length - offset)));
        }
Ejemplo n.º 2
0
 public void Reset()
 {
     INesMapper    = 0;
     CHRSize       = 0;
     PRGSize       = 0;
     Battery       = false;
     FrameTiming   = FrameTiming.NTSC;
     MirroringType = MirroringType.Vertical;
 }
Ejemplo n.º 3
0
        void SetMirroring(MirroringType mirroringType)
        {
            mnuMirrorHorizontal.Checked  = mirroringType == MirroringType.Horizontal;
            mnuMirrorVertical.Checked    = mirroringType == MirroringType.Vertical;
            mnuMirrorScreenA.Checked     = mirroringType == MirroringType.ScreenAOnly;
            mnuMirrorScreenB.Checked     = mirroringType == MirroringType.ScreenBOnly;
            mnuMirrorFourScreens.Checked = mirroringType == MirroringType.FourScreens;

            CoreWrapper.setMirroringType(mirroringType);
        }
Ejemplo n.º 4
0
 public NameTableRam(Cartridge cartridge)
 {
     if ((cartridge.NesHeader.Flags6 & 0x0F) == 0x0F)
     {
         _mirroring = MirroringType.NONE;
     }
     else
     {
         _mirroring = (cartridge.NesHeader.Flags6 & 0x01) == 0x01 ? MirroringType.VERTICAL : MirroringType.HORIZANTAL;
     }
 }
Ejemplo n.º 5
0
        public NesFixType CorrectRom()
        {
            int result = 0;
            var crc32  = CRC32;

            for (int i = 0; i < correct.Length; i += 3)
            {
                if (crc32 == correct[i])
                {
                    var mapper    = correct[i + 1];
                    var mirroring = correct[i + 2];
                    if (mapper >= 0)
                    {
                        // no CHR
                        if ((mapper & 0x800) != 0 && CHR.Length > 0)
                        {
                            CHR     = new byte[0];
                            result |= 8;
                        }
                        // invalid mapper
                        if (Mapper != (mapper & 0xFF))
                        {
                            Mapper  = (byte)(mapper & 0xFF);
                            result |= 1;
                        }
                    }
                    if (mirroring >= 0)
                    {
                        // Anything but hard-wired(four screen)
                        if (mirroring == 8 && Mirroring == MirroringType.FourScreenVram)
                        {
                            Mirroring = MirroringType.Horizontal;
                            result   |= 2;
                        }
                        MirroringType needMirroring = MirroringType.Unknown_none;
                        switch (mirroring)
                        {
                        case 0:
                            needMirroring = MirroringType.Horizontal;
                            break;

                        case 1:
                            needMirroring = MirroringType.Vertical;
                            break;

                        case 2:
                            needMirroring = MirroringType.FourScreenVram;
                            break;
                        }
                        if (needMirroring != MirroringType.Unknown_none && needMirroring != Mirroring)
                        {
                            Mirroring = needMirroring;
                            result   |= 2;
                        }
                    }
                }
            }

            var   md5        = MD5;
            ulong partialmd5 = 0;

            for (int x = 0; x < 8; x++)
            {
                partialmd5 |= (ulong)md5[15 - x] << (x * 8);
            }
            // maybe this games uses battery saves?
            foreach (var sav in savie)
            {
                if (!Battery && sav == partialmd5)
                {
                    Battery = true;
                    result |= 4;
                }
            }

            return((NesFixType)result);
        }
Ejemplo n.º 6
0
 [DllImport(dllName)] public extern static void setMirroringType(MirroringType mirroring);