Ejemplo n.º 1
0
 public void ReadSector(IntPtr destinationBuffer, int sectorNumber)
 {
     FreeDOCore.SetAnvilFix(2);
     // Set fix for anvil bios
 }
Ejemplo n.º 2
0
        public void Start(string biosRom1FileName, string biosRom2FileName, IGameSource gameSource, string nvramFileName)
        {
            int fixMode = 0;

            ///////////
            // If they haven't initialized us properly, complain!

            if (!this.maxLagTicks.HasValue)
            {
                throw new InvalidOperationException("Audio buffer not set!");
            }

            if (!this.cpuClockHertz.HasValue)
            {
                throw new InvalidOperationException("CPU Clock speed not set!");
            }

            if (!this.renderHighResolution.HasValue)
            {
                throw new InvalidOperationException("High resolution setting not set!");
            }

            // Are we already started?
            if (this.workerThread != null)
            {
                return;
            }

            this.GameSource = gameSource;

            //////////////
            // Attempt to load Bios #1.
            try
            {
                this.biosRom1Copy = System.IO.File.ReadAllBytes(biosRom1FileName);
            }
            catch
            {
                throw new BadBiosRom1Exception();
            }

            // Also get outta here if it's not the right length.
            if (this.biosRom1Copy.Length != ROM1_SIZE)
            {
                throw new BadBiosRom1Exception();
            }
            if (this.biosRom1Copy[28] == 234)
            {
                FreeDOCore.SetAnvilFix(30);
            }                                                                 //bios anvil
            //////////////
            // Attempt to load Bios #2.

            // If we don't load Bios #2, we'll just use all zeroes.
            this.biosRom2Copy = new byte[ROM2_SIZE];             // Allocate full size to get all 0's

            // Load from file, if a file was chosen
            byte[] biosRom2Bytes = null;
            if (!string.IsNullOrWhiteSpace(biosRom2FileName))
            {
                try
                {
                    biosRom2Bytes = System.IO.File.ReadAllBytes(biosRom2FileName);
                }
                catch
                {
                    throw new BadBiosRom2Exception();
                }

                // Bios #2 is allowed to be less than or equal to the right size.
                // The only example file I know of is less than (912KB) the actual size on the hardware (1MB).
                if (biosRom2Bytes.Length > ROM2_SIZE || biosRom2Bytes.Length == 0)
                {
                    throw new BadBiosRom2Exception();
                }



                // Copy to the member variable.
                biosRom2Bytes.CopyTo(this.biosRom2Copy, 0);
            }

            //////////////
            // Load a copy of the nvram.
            try
            {
                // If we previously had a game open, and they have now loaded
                // a new game, we want to make sure the game that was previously
                // open does not accidentally save.
                lock (nvramCopySemaphore)
                {
                    // Note that we copy to the OLD nvram file name, just in case.
                    if (this.nvramTimer.Enabled == true)
                    {
                        Memory.WriteMemoryDump(this.nvramFileName, this.nvramCopyPtr, NVRAM_SIZE);
                    }

                    this.nvramTimer.Enabled = false;

                    // Read the new NVRAM into memory.
                    Memory.ReadMemoryDump(this.nvramCopy, nvramFileName, NVRAM_SIZE);
                }
            }
            catch
            {
                throw new BadNvramFileException();
            }

            // Freak out if the nvram isn't the right size.
            if (this.nvramCopy.Length != NVRAM_SIZE)
            {
                throw new BadNvramFileException();
            }

            // Remember the file name.
            this.nvramFileName = nvramFileName;

            //////////////
            // Attempt to start up the game source (it is allowed to throw errors).
            try
            {
                this.GameSource.Open();
            }
            catch
            {
                throw new BadGameRomException();
            }

            FreeDOCore.SetFixMode(fixMode);

            /////////////////
            // Initialize the core
            FreeDOCore.Initialize();

            ////////////////
            // Set fix mode
            GameRecord record = GameRegistrar.GetGameRecordById(this.GameSource.GetGameId());

            if (record != null)
            {
                if (
                    record.Id == "F3AF1B13" || // Crash 'n Burn (JP)
                    record.Id == "217344B0"    // Crash 'n Burn (US)

                    )
                {
                    fixMode = fixMode | (int)FixMode.FIX_BIT_TIMING_1;
                }

                if (record.Id == "DBB419FA" || // Street Figthter 2, for intro sync
                    record.Id == "07C32F10" ||// Street Figthter 2, for intro sync
                    record.Id == "5282889F" ||// Street Figthter 2, for intro sync
                    record.Id == "7340307E"   // Street Figthter 2, for intro sync
                    )
                {
                    fixMode = fixMode | (int)FixMode.FIX_BIT_TIMING_2;
                }

                if (record.Id == "CB8EE795" // Dinopark Tycoon
                    )
                {
                    fixMode = fixMode | (int)FixMode.FIX_BIT_TIMING_3;
                }

                if (record.Id == "1A370EBA" || // Microcosm
                    record.Id == "B35C911D"// Microcosm
                    )
                {
                    fixMode = fixMode | (int)FixMode.FIX_BIT_TIMING_5;
                }

                if (record.Id == "0511D3D2" || // Alone in the Dark
                    record.Id == "9F7D72BC" ||// Alone in the Dark
                    record.Id == "E843C635"// Alone in the Dark
                    )
                {
                    fixMode = fixMode | (int)FixMode.FIX_BIT_TIMING_6;
                }

                if (record.Id == "2AABA5B9" || // Samurai Shodown (EU-US)
                    record.Id == "BF61BB32"    // Samurai Shodown (JP)
                    )
                {
                    fixMode = fixMode | (int)FixMode.FIX_BIT_GRAPHICS_STEP_Y;
                }
            }
            FreeDOCore.SetFixMode(fixMode);
            /////////////////
            // Start the core thread
            this.InternalResume(false);
        }