Exemplo n.º 1
0
        public override bool Configure(NES.EDetectionOrigin origin)
        {
            switch (Cart.board_type)
            {
            case "UNIF_BMC-BS-5":
                break;

            default:
                return(false);
            }

            reg_prg[0] = 0xFF;
            reg_prg[1] = 0xFF;
            reg_prg[2] = 0xFF;
            reg_prg[3] = 0xFF;

            SetMirrorType(EMirrorType.Vertical);

            _prgMask8k = Cart.prg_size / 8 - 1;
            _chrMask2k = Cart.prg_size / 2 - 1;

            AutoMapperProps.Apply(this);

            return(true);
        }
Exemplo n.º 2
0
        public override bool Configure(EDetectionOrigin origin)
        {
            switch (Cart.BoardType)
            {
            case "UNIF_UNL-DRIPGAME":
                break;

            default:
                return(false);
            }
            Cart.WramSize    = 8;
            Cart.WramBattery = false;
            AssertPrg(16, 32, 64, 128, 256);  // 4 bits x 16
            AssertChr(8, 16, 32);             // 4 bits x 2

            AutoMapperProps.Apply(this);

            prgmask = Cart.PrgSize / 16 - 1;
            chrmask = Cart.PrgSize / 2 - 1;

            prg[1] = prgmask;
            SetMirror(0);

            if (NES.apu != null)             // don't start up sound when in configurator
            {
                sound0 = new SoundChannel(NES.apu.ExternalQueue);
                sound1 = new SoundChannel(NES.apu.ExternalQueue);
            }

            return(true);
        }
Exemplo n.º 3
0
        public override bool Configure(NES.EDetectionOrigin origin)
        {
            switch (Cart.board_type)
            {
            case "MAPPER228":
            case "MLT-ACTION52":
                break;

            default:
                return(false);
            }

            AssertPrg(256, 1536);

            chr_bank_mask_8k  = Cart.chr_size / 8 - 1;
            prg_bank_mask_16k = Cart.prg_size / 16 - 1;
            prg_bank_mask_32k = Cart.prg_size / 32 - 1;

            if (Cart.prg_size == 256)
            {
                cheetahmen = true;
            }
            else
            {
                prg_bank_mask_16k = 0x1F;
                prg_bank_mask_32k = 0xF;
            }

            AutoMapperProps.Apply(this);

            return(true);
        }
Exemplo n.º 4
0
        private void InitValues()
        {
            AutoMapperProps.Apply(this);

            irq_enable    = false;
            init_sequence = 0;
            irq_count     = 0;

            Sync();
        }
		public override bool Configure(EDetectionOrigin origin)
		{
			switch (Cart.BoardType)
			{
				case "UNIF_BMC-Ghostbusters63in1":
					break;
				default:
					return false;
			}

			AutoMapperProps.Apply(this);

			return true;
		}
        public override bool Configure(EDetectionOrigin origin)
        {
            switch (Cart.BoardType)
            {
            case "UNIF_BMC-D1038":
                break;

            default:
                return(false);
            }

            AutoMapperProps.Apply(this);

            return(true);
        }
Exemplo n.º 7
0
        public override bool Configure(NES.EDetectionOrigin origin)
        {
            switch (Cart.board_type)
            {
            case "MAPPER060":
                break;

            default:
                return(false);
            }

            AutoMapperProps.Apply(this);

            return(true);
        }
Exemplo n.º 8
0
        public override bool Configure(NES.EDetectionOrigin origin)
        {
            switch (Cart.board_type)
            {
            case "UNIF_UNL-SHERO":
                break;

            default:
                return(false);
            }

            BaseSetup();
            AutoMapperProps.Apply(this);
            return(true);
        }
Exemplo n.º 9
0
        private void InitValues()
        {
            for (int i = 0; i < 4; i++)
            {
                prg_regs[i] = 0xFF;
                nt_regs[i]  = 0;
            }
            for (int i = 0; i < 8; i++)
            {
                chr_regs[i] = 0xFFFF;
            }

            AutoMapperProps.Apply(this);

            Sync();
        }
        public override bool Configure(EDetectionOrigin origin)
        {
            switch (Cart.BoardType)
            {
            case "MAPPER057":
                break;

            default:
                return(false);
            }

            SetMirrorType(EMirrorType.Horizontal);

            AutoMapperProps.Apply(this);

            return(true);
        }
        public override bool Configure(EDetectionOrigin origin)
        {
            switch (Cart.BoardType)
            {
            case "UNIF_BMC-8157":
                break;

            default:
                return(false);
            }

            _prgMask16k = Cart.PrgSize / 16 - 1;

            AutoMapperProps.Apply(this);

            return(true);
        }
Exemplo n.º 12
0
        public override bool Configure(NES.EDetectionOrigin origin)
        {
            switch (Cart.board_type)
            {
            case "MAPPER060":
                // Hack, Reset 4-in-1 is a different board but still assign to mapper 60
                if (Cart.prg_size != 64 || Cart.chr_size != 32)
                {
                    break;
                }

                return(false);

            default:
                return(false);
            }

            AutoMapperProps.Apply(this);

            return(true);
        }
Exemplo n.º 13
0
        public override bool Configure(NES.EDetectionOrigin origin)
        {
            switch (Cart.board_type)
            {
            case "UNIF_BMC-70in1":
                isLargeBanks = false;
                break;

            case "MAPPER236":
            case "UNIF_BMC-70in1B":
                isLargeBanks = true;
                break;

            default:
                return(false);
            }

            AutoMapperProps.Apply(this);

            return(true);
        }
Exemplo n.º 14
0
        public override bool Configure(NES.EDetectionOrigin origin)
        {
            switch (Cart.board_type)
            {
            //case "MAPPER236": // Nestopia classifies both boards as MAPPER236, but I have yet to a see a ROM iwth this iNES header, and how would we determine which one it was?
            case "UNIF_BMC-70in1":
                isLargeBanks = false;
                break;

            case "UNIF_BMC-70in1B":
                isLargeBanks = true;
                break;

            default:
                return(false);
            }

            AutoMapperProps.Apply(this);

            return(true);
        }
Exemplo n.º 15
0
        public void Init(GameInfo gameInfo, byte[] rom, byte[] fdsbios = null)
        {
            LoadReport = new StringWriter();
            LoadWriteLine("------");
            LoadWriteLine("BEGIN NES rom analysis:");
            byte[] file = rom;

            Type          boardType = null;
            CartInfo      choice = null;
            CartInfo      iNesHeaderInfo = null;
            CartInfo      iNesHeaderInfoV2 = null;
            List <string> hash_sha1_several = new List <string>();
            string        hash_sha1 = null, hash_md5 = null;
            Unif          unif = null;

            Dictionary <string, string> InitialMapperRegisterValues = new Dictionary <string, string>(SyncSettings.BoardProperties);

            origin = EDetectionOrigin.None;

            if (file.Length < 16)
            {
                throw new Exception("Alleged NES rom too small to be anything useful");
            }
            if (file.Take(4).SequenceEqual(System.Text.Encoding.ASCII.GetBytes("UNIF")))
            {
                unif = new Unif(new MemoryStream(file));
                LoadWriteLine("Found UNIF header:");
                LoadWriteLine(unif.CartInfo);
                LoadWriteLine("Since this is UNIF we can confidently parse PRG/CHR banks to hash.");
                hash_sha1 = unif.CartInfo.sha1;
                hash_sha1_several.Add(hash_sha1);
                LoadWriteLine("headerless rom hash: {0}", hash_sha1);
            }
            else if (file.Take(5).SequenceEqual(System.Text.Encoding.ASCII.GetBytes("NESM\x1A")))
            {
                origin = EDetectionOrigin.NSF;
                LoadWriteLine("Loading as NSF");
                var nsf = new NSFFormat();
                nsf.WrapByteArray(file);

                cart = new CartInfo();
                var nsfboard = new NSFBoard();
                nsfboard.Create(this);
                nsfboard.ROM = rom;
                nsfboard.InitNSF(nsf);
                nsfboard.InitialRegisterValues = InitialMapperRegisterValues;
                nsfboard.Configure(origin);
                nsfboard.WRAM = new byte[cart.wram_size * 1024];
                Board         = nsfboard;
                Board.PostConfigure();
                AutoMapperProps.Populate(Board, SyncSettings);

                Console.WriteLine("Using NTSC display type for NSF for now");
                _display_type = Common.DisplayType.NTSC;

                HardReset();

                return;
            }
            else if (file.Take(4).SequenceEqual(System.Text.Encoding.ASCII.GetBytes("FDS\x1A")) ||
                     file.Take(4).SequenceEqual(System.Text.Encoding.ASCII.GetBytes("\x01*NI")))
            {
                // danger!  this is a different codepath with an early return.  accordingly, some
                // code is duplicated twice...

                // FDS roms are just fed to the board, we don't do much else with them
                origin = EDetectionOrigin.FDS;
                LoadWriteLine("Found FDS header.");
                if (fdsbios == null)
                {
                    throw new MissingFirmwareException("Missing FDS Bios");
                }
                cart = new CartInfo();
                var fdsboard = new FDS();
                fdsboard.biosrom = fdsbios;
                fdsboard.SetDiskImage(rom);
                fdsboard.Create(this);
                // at the moment, FDS doesn't use the IRVs, but it could at some point in the future
                fdsboard.InitialRegisterValues = InitialMapperRegisterValues;
                fdsboard.Configure(origin);

                Board = fdsboard;

                //create the vram and wram if necessary
                if (cart.wram_size != 0)
                {
                    Board.WRAM = new byte[cart.wram_size * 1024];
                }
                if (cart.vram_size != 0)
                {
                    Board.VRAM = new byte[cart.vram_size * 1024];
                }

                Board.PostConfigure();
                AutoMapperProps.Populate(Board, SyncSettings);

                Console.WriteLine("Using NTSC display type for FDS disk image");
                _display_type = Common.DisplayType.NTSC;

                HardReset();

                return;
            }
            else
            {
                byte[] nesheader = new byte[16];
                Buffer.BlockCopy(file, 0, nesheader, 0, 16);

                bool exists = true;

                if (!DetectFromINES(nesheader, out iNesHeaderInfo, out iNesHeaderInfoV2))
                {
                    // we don't have an ines header, check if the game hash is in the game db
                    exists = false;
                    Console.WriteLine("headerless ROM, using Game DB");
                    hash_md5  = "md5:" + file.HashMD5(0, file.Length);
                    hash_sha1 = "sha1:" + file.HashSHA1(0, file.Length);
                    if (hash_md5 != null)
                    {
                        choice = IdentifyFromGameDB(hash_md5);
                    }
                    if (choice == null)
                    {
                        choice = IdentifyFromGameDB(hash_sha1);
                    }
                    if (choice == null)
                    {
                        hash_sha1_several.Add(hash_sha1);
                        choice = IdentifyFromBootGodDB(hash_sha1_several);
                        if (choice == null)
                        {
                            LoadWriteLine("Could not locate game in nescartdb");
                        }
                        else
                        {
                            LoadWriteLine("Chose board from nescartdb:");
                            LoadWriteLine(choice);
                            origin = EDetectionOrigin.BootGodDB;
                        }
                    }
                    if (choice == null)
                    {
                        throw new InvalidOperationException("iNES header not found and no gamedb entry");
                    }
                }

                if (exists)
                {
                    //now that we know we have an iNES header, we can try to ignore it.

                    hash_sha1 = "sha1:" + file.HashSHA1(16, file.Length - 16);
                    hash_sha1_several.Add(hash_sha1);
                    hash_md5 = "md5:" + file.HashMD5(16, file.Length - 16);

                    LoadWriteLine("Found iNES header:");
                    LoadWriteLine(iNesHeaderInfo.ToString());
                    if (iNesHeaderInfoV2 != null)
                    {
                        LoadWriteLine("Found iNES V2 header:");
                        LoadWriteLine(iNesHeaderInfoV2);
                    }
                    LoadWriteLine("Since this is iNES we can (somewhat) confidently parse PRG/CHR banks to hash.");

                    LoadWriteLine("headerless rom hash: {0}", hash_sha1);
                    LoadWriteLine("headerless rom hash:  {0}", hash_md5);

                    if (iNesHeaderInfo.prg_size == 16)
                    {
                        //8KB prg can't be stored in iNES format, which counts 16KB prg banks.
                        //so a correct hash will include only 8KB.
                        LoadWriteLine("Since this rom has a 16 KB PRG, we'll hash it as 8KB too for bootgod's DB:");
                        var msTemp = new MemoryStream();
                        msTemp.Write(file, 16, 8 * 1024);                         //add prg
                        if (file.Length >= (16 * 1024 + iNesHeaderInfo.chr_size * 1024 + 16))
                        {
                            // This assumes that even though the PRG is only 8k the CHR is still written
                            // 16k into the file, which is not always the case (e.x. Galaxian RevA)
                            msTemp.Write(file, 16 + 16 * 1024, iNesHeaderInfo.chr_size * 1024);                             //add chr
                        }
                        else if (file.Length >= (8 * 1024 + iNesHeaderInfo.chr_size * 1024 + 16))
                        {
                            // maybe the PRG is only 8k
                            msTemp.Write(file, 16 + 8 * 1024, iNesHeaderInfo.chr_size * 1024);                             //add chr
                        }
                        else
                        {
                            // we failed somehow
                            // most likely the header is wrong
                            Console.WriteLine("WARNING: 16kb PRG iNES header but unable to parse");
                        }
                        msTemp.Flush();
                        var bytes = msTemp.ToArray();
                        var hash  = "sha1:" + bytes.HashSHA1(0, bytes.Length);
                        LoadWriteLine("  PRG (8KB) + CHR hash: {0}", hash);
                        hash_sha1_several.Add(hash);
                        hash = "md5:" + bytes.HashMD5(0, bytes.Length);
                        LoadWriteLine("  PRG (8KB) + CHR hash:  {0}", hash);
                    }
                }
            }

            if (USE_DATABASE)
            {
                if (hash_md5 != null)
                {
                    choice = IdentifyFromGameDB(hash_md5);
                }
                if (choice == null)
                {
                    choice = IdentifyFromGameDB(hash_sha1);
                }
                if (choice == null)
                {
                    LoadWriteLine("Could not locate game in bizhawk gamedb");
                }
                else
                {
                    origin = EDetectionOrigin.GameDB;
                    LoadWriteLine("Chose board from bizhawk gamedb: " + choice.board_type);
                    //gamedb entries that dont specify prg/chr sizes can infer it from the ines header
                    if (iNesHeaderInfo != null)
                    {
                        if (choice.prg_size == -1)
                        {
                            choice.prg_size = iNesHeaderInfo.prg_size;
                        }
                        if (choice.chr_size == -1)
                        {
                            choice.chr_size = iNesHeaderInfo.chr_size;
                        }
                        if (choice.vram_size == -1)
                        {
                            choice.vram_size = iNesHeaderInfo.vram_size;
                        }
                        if (choice.wram_size == -1)
                        {
                            choice.wram_size = iNesHeaderInfo.wram_size;
                        }
                    }
                    else if (unif != null)
                    {
                        if (choice.prg_size == -1)
                        {
                            choice.prg_size = unif.CartInfo.prg_size;
                        }
                        if (choice.chr_size == -1)
                        {
                            choice.chr_size = unif.CartInfo.chr_size;
                        }
                        // unif has no wram\vram sizes; hope the board impl can figure it out...
                        if (choice.vram_size == -1)
                        {
                            choice.vram_size = 0;
                        }
                        if (choice.wram_size == -1)
                        {
                            choice.wram_size = 0;
                        }
                    }
                }

                //if this is still null, we have to try it some other way. nescartdb perhaps?
                if (choice == null)
                {
                    choice = IdentifyFromBootGodDB(hash_sha1_several);
                    if (choice == null)
                    {
                        LoadWriteLine("Could not locate game in nescartdb");
                    }
                    else
                    {
                        LoadWriteLine("Chose board from nescartdb:");
                        LoadWriteLine(choice);
                        origin = EDetectionOrigin.BootGodDB;
                    }
                }
            }

            //if choice is still null, try UNIF and iNES
            if (choice == null)
            {
                if (unif != null)
                {
                    LoadWriteLine("Using information from UNIF header");
                    choice = unif.CartInfo;
                    //ok, i have this Q-Boy rom with no VROM and no VRAM.
                    //we also certainly have games with VROM and no VRAM.
                    //looks like FCEUX policy is to allocate 8KB of chr ram no matter what UNLESS certain flags are set. but what's the justification for this? please leave a note if you go debugging in it again.
                    //well, we know we can't have much of a NES game if there's no VROM unless there's VRAM instead.
                    //so if the VRAM isn't set, choose 8 for it.
                    //TODO - unif loading code may need to use VROR flag to transform chr_size=8 to vram_size=8 (need example)
                    if (choice.chr_size == 0 && choice.vram_size == 0)
                    {
                        choice.vram_size = 8;
                    }
                    //(do we need to suppress this in case theres a CHR rom? probably not. nes board base will use ram if no rom is available)
                    origin = EDetectionOrigin.UNIF;
                }
                if (iNesHeaderInfo != null)
                {
                    LoadWriteLine("Attempting inference from iNES header");
                    // try to spin up V2 header first, then V1 header
                    if (iNesHeaderInfoV2 != null)
                    {
                        try
                        {
                            boardType = FindBoard(iNesHeaderInfoV2, origin, InitialMapperRegisterValues);
                        }
                        catch { }
                        if (boardType == null)
                        {
                            LoadWriteLine("Failed to load as iNES V2");
                        }
                        else
                        {
                            choice = iNesHeaderInfoV2;
                        }

                        // V2 might fail but V1 might succeed because we don't have most V2 aliases setup; and there's
                        // no reason to do so except when needed
                    }
                    if (boardType == null)
                    {
                        choice    = iNesHeaderInfo;                      // we're out of options, really
                        boardType = FindBoard(iNesHeaderInfo, origin, InitialMapperRegisterValues);
                        if (boardType == null)
                        {
                            LoadWriteLine("Failed to load as iNES V1");
                        }

                        // do not further meddle in wram sizes.  a board that is being loaded from a "MAPPERxxx"
                        // entry should know and handle the situation better for the individual board
                    }

                    LoadWriteLine("Chose board from iNES heuristics:");
                    LoadWriteLine(choice);
                    origin = EDetectionOrigin.INES;
                }
            }

            game_name = choice.name;

            //find a INESBoard to handle this
            if (choice != null)
            {
                boardType = FindBoard(choice, origin, InitialMapperRegisterValues);
            }
            else
            {
                throw new Exception("Unable to detect ROM");
            }
            if (boardType == null)
            {
                throw new Exception("No class implements the necessary board type: " + choice.board_type);
            }

            if (choice.DB_GameInfo != null)
            {
                choice.bad = choice.DB_GameInfo.IsRomStatusBad();
            }

            LoadWriteLine("Final game detection results:");
            LoadWriteLine(choice);
            LoadWriteLine("\"" + game_name + "\"");
            LoadWriteLine("Implemented by: class " + boardType.Name);
            if (choice.bad)
            {
                LoadWriteLine("~~ ONE WAY OR ANOTHER, THIS DUMP IS KNOWN TO BE *BAD* ~~");
                LoadWriteLine("~~ YOU SHOULD FIND A BETTER FILE ~~");
            }

            LoadWriteLine("END NES rom analysis");
            LoadWriteLine("------");

            Board = CreateBoardInstance(boardType);

            cart = choice;
            Board.Create(this);
            Board.InitialRegisterValues = InitialMapperRegisterValues;
            Board.Configure(origin);

            if (origin == EDetectionOrigin.BootGodDB)
            {
                RomStatus = RomStatus.GoodDump;
                CoreComm.RomStatusAnnotation = "Identified from BootGod's database";
            }
            if (origin == EDetectionOrigin.UNIF)
            {
                RomStatus = RomStatus.NotInDatabase;
                CoreComm.RomStatusAnnotation = "Inferred from UNIF header; somewhat suspicious";
            }
            if (origin == EDetectionOrigin.INES)
            {
                RomStatus = RomStatus.NotInDatabase;
                CoreComm.RomStatusAnnotation = "Inferred from iNES header; potentially wrong";
            }
            if (origin == EDetectionOrigin.GameDB)
            {
                if (choice.bad)
                {
                    RomStatus = RomStatus.BadDump;
                }
                else
                {
                    RomStatus = choice.DB_GameInfo.Status;
                }
            }

            byte[] trainer = null;

            //create the board's rom and vrom
            if (iNesHeaderInfo != null)
            {
                var ms = new MemoryStream(file, false);
                ms.Seek(16, SeekOrigin.Begin);                 // ines header
                //pluck the necessary bytes out of the file
                if (iNesHeaderInfo.trainer_size != 0)
                {
                    trainer = new byte[512];
                    ms.Read(trainer, 0, 512);
                }

                Board.ROM = new byte[choice.prg_size * 1024];
                ms.Read(Board.ROM, 0, Board.ROM.Length);

                if (choice.chr_size > 0)
                {
                    Board.VROM = new byte[choice.chr_size * 1024];
                    int vrom_copy_size = ms.Read(Board.VROM, 0, Board.VROM.Length);

                    if (vrom_copy_size < Board.VROM.Length)
                    {
                        LoadWriteLine("Less than the expected VROM was found in the file: {0} < {1}", vrom_copy_size, Board.VROM.Length);
                    }
                }
                if (choice.prg_size != iNesHeaderInfo.prg_size || choice.chr_size != iNesHeaderInfo.chr_size)
                {
                    LoadWriteLine("Warning: Detected choice has different filesizes than the INES header!");
                }
            }
            else if (unif != null)
            {
                Board.ROM  = unif.PRG;
                Board.VROM = unif.CHR;
            }
            else
            {
                // we should only get here for boards with no header
                var ms = new MemoryStream(file, false);
                ms.Seek(0, SeekOrigin.Begin);

                Board.ROM = new byte[choice.prg_size * 1024];
                ms.Read(Board.ROM, 0, Board.ROM.Length);

                if (choice.chr_size > 0)
                {
                    Board.VROM = new byte[choice.chr_size * 1024];
                    int vrom_copy_size = ms.Read(Board.VROM, 0, Board.VROM.Length);

                    if (vrom_copy_size < Board.VROM.Length)
                    {
                        LoadWriteLine("Less than the expected VROM was found in the file: {0} < {1}", vrom_copy_size, Board.VROM.Length);
                    }
                }
            }

            LoadReport.Flush();
            CoreComm.RomStatusDetails = LoadReport.ToString();

            // IF YOU DO ANYTHING AT ALL BELOW THIS LINE, MAKE SURE THE APPROPRIATE CHANGE IS MADE TO FDS (if applicable)

            //create the vram and wram if necessary
            if (cart.wram_size != 0)
            {
                Board.WRAM = new byte[cart.wram_size * 1024];
            }
            if (cart.vram_size != 0)
            {
                Board.VRAM = new byte[cart.vram_size * 1024];
            }

            Board.PostConfigure();
            AutoMapperProps.Populate(Board, SyncSettings);

            // set up display type

            NESSyncSettings.Region fromrom      = DetectRegion(cart.system);
            NESSyncSettings.Region fromsettings = SyncSettings.RegionOverride;

            if (fromsettings != NESSyncSettings.Region.Default)
            {
                Console.WriteLine("Using system region override");
                fromrom = fromsettings;
            }
            switch (fromrom)
            {
            case NESSyncSettings.Region.Dendy:
                _display_type = Common.DisplayType.Dendy;
                break;

            case NESSyncSettings.Region.NTSC:
                _display_type = Common.DisplayType.NTSC;
                break;

            case NESSyncSettings.Region.PAL:
                _display_type = Common.DisplayType.PAL;
                break;

            default:
                _display_type = Common.DisplayType.NTSC;
                break;
            }
            Console.WriteLine("Using NES system region of {0}", _display_type);

            HardReset();

            if (trainer != null)
            {
                Console.WriteLine("Applying trainer");
                for (int i = 0; i < 512; i++)
                {
                    WriteMemory((ushort)(0x7000 + i), trainer[i]);
                }
            }
        }