예제 #1
0
        public void Dispose()
        {
            if (BlipL != null)
            {
                BlipL.Dispose();
                BlipL = null;
            }

            if (BlipR != null)
            {
                BlipR.Dispose();
                BlipR = null;
            }
        }
예제 #2
0
        public SMS(CoreComm comm, GameInfo game, byte[] rom, SmsSettings settings, SmsSyncSettings syncSettings)
        {
            var ser = new BasicServiceProvider(this);

            ServiceProvider = ser;
            Settings        = (SmsSettings)settings ?? new SmsSettings();
            SyncSettings    = (SmsSyncSettings)syncSettings ?? new SmsSyncSettings();

            IsGameGear   = game.System == "GG";
            IsGameGear_C = game.System == "GG";
            IsSG1000     = game.System == "SG";
            RomData      = rom;

            if (RomData.Length % BankSize != 0)
            {
                Array.Resize(ref RomData, ((RomData.Length / BankSize) + 1) * BankSize);
            }

            RomBanks = (byte)(RomData.Length / BankSize);

            Region = DetermineDisplayType(SyncSettings.DisplayType, game.Region);
            if (game["PAL"] && Region != DisplayType.PAL)
            {
                Region = DisplayType.PAL;
                comm.Notify("Display was forced to PAL mode for game compatibility.");
            }

            if (IsGameGear)
            {
                Region = DisplayType.NTSC;                 // all game gears run at 60hz/NTSC mode
            }

            _region = SyncSettings.ConsoleRegion;
            if (_region == SmsSyncSettings.Regions.Auto)
            {
                _region = DetermineRegion(game.Region);
            }

            if (game["Japan"] && _region != SmsSyncSettings.Regions.Japan)
            {
                _region = SmsSyncSettings.Regions.Japan;
                comm.Notify("Region was forced to Japan for game compatibility.");
            }

            if (game["Korea"] && _region != SmsSyncSettings.Regions.Korea)
            {
                _region = SmsSyncSettings.Regions.Korea;
                comm.Notify("Region was forced to Korea for game compatibility.");
            }

            if ((game.NotInDatabase || game["FM"]) && SyncSettings.EnableFm && !IsGameGear)
            {
                HasYM2413 = true;
            }

            Cpu = new Z80A
            {
                ReadHardware    = ReadPort,
                WriteHardware   = WritePort,
                FetchMemory     = FetchMemory,
                ReadMemory      = ReadMemory,
                WriteMemory     = WriteMemory,
                MemoryCallbacks = MemoryCallbacks,
                OnExecFetch     = OnExecMemory
            };

            if (game["GG_in_SMS"])
            {
                // skip setting the BIOS because this is a game gear game that puts the system
                // in SMS compatibility mode (it will fail the check sum if played on an actual SMS though.)
                IsGameGear   = false;
                IsGameGear_C = true;
                game.System  = "GG";
                Console.WriteLine("Using SMS Compatibility mode for Game Gear System");
            }

            Vdp = new VDP(this, Cpu, IsGameGear ? VdpMode.GameGear : VdpMode.SMS, Region);
            ser.Register <IVideoProvider>(Vdp);
            PSG    = new SN76489sms();
            YM2413 = new YM2413();
            //SoundMixer = new SoundMixer(YM2413, PSG);
            if (HasYM2413 && game["WhenFMDisablePSG"])
            {
                disablePSG = true;
            }

            BlipL.SetRates(3579545, 44100);
            BlipR.SetRates(3579545, 44100);

            ser.Register <ISoundProvider>(this);

            SystemRam = new byte[0x2000];

            if (game["CMMapper"])
            {
                InitCodeMastersMapper();
            }
            else if (game["CMMapperWithRam"])
            {
                InitCodeMastersMapperRam();
            }
            else if (game["ExtRam"])
            {
                InitExt2kMapper(int.Parse(game.OptionValue("ExtRam")));
            }
            else if (game["KoreaMapper"])
            {
                InitKoreaMapper();
            }
            else if (game["MSXMapper"])
            {
                InitMSXMapper();
            }
            else if (game["NemesisMapper"])
            {
                InitNemesisMapper();
            }
            else if (game["TerebiOekaki"])
            {
                InitTerebiOekaki();
            }
            else if (game["EEPROM"])
            {
                InitEEPROMMapper();
            }
            else
            {
                InitSegaMapper();
            }

            if (Settings.ForceStereoSeparation && !IsGameGear)
            {
                if (game["StereoByte"])
                {
                    ForceStereoByte = byte.Parse(game.OptionValue("StereoByte"));
                }

                PSG.Set_Panning(ForceStereoByte);
            }

            if (SyncSettings.AllowOverClock && game["OverclockSafe"])
            {
                Vdp.IPeriod = 512;
            }

            if (Settings.SpriteLimit)
            {
                Vdp.SpriteLimit = true;
            }

            if (game["3D"])
            {
                IsGame3D = true;
            }

            if (game["BIOS"])
            {
                Port3E = 0xF7;                 // Disable cartridge, enable BIOS rom
                InitBiosMapper();
            }
            else if (game.System == "SMS" && !game["GG_in_SMS"])
            {
                BiosRom = comm.CoreFileProvider.GetFirmware("SMS", _region.ToString(), false);

                if (BiosRom == null)
                {
                    throw new MissingFirmwareException("No BIOS found");
                }

                if (!game["RequireBios"] && !SyncSettings.UseBios)
                {
                    // we are skipping the BIOS
                    // but only if it won't break the game
                }
                else
                {
                    Port3E = 0xF7;
                }
            }

            if (game["SRAM"])
            {
                SaveRAM = new byte[int.Parse(game.OptionValue("SRAM"))];
                Console.WriteLine(SaveRAM.Length);
            }
            else if (game.NotInDatabase)
            {
                SaveRAM = new byte[0x8000];
            }

            SetupMemoryDomains();

            //this manages the linkage between the cpu and mapper callbacks so it needs running before bootup is complete
            ((ICodeDataLogger)this).SetCDL(null);

            Tracer = new TraceBuffer {
                Header = Cpu.TraceHeader
            };

            ser.Register(Tracer);
            ser.Register <IDisassemblable>(Cpu);
            ser.Register <IStatable>(new StateSerializer(SyncState));
            Vdp.ProcessOverscan();

            Cpu.ReadMemory  = ReadMemory;
            Cpu.WriteMemory = WriteMemory;

            // Z80 SP initialization
            // stops a few SMS and GG games from crashing
            Cpu.Regs[Cpu.SPl] = 0xF0;
            Cpu.Regs[Cpu.SPh] = 0xDF;

            if (!IsSG1000)
            {
                ser.Register <ISmsGpuView>(new SmsGpuView(Vdp));
            }
        }
예제 #3
0
        public bool FrameAdvance(IController controller, bool render, bool renderSound)
        {
            _controller = controller;
            _lagged     = true;
            _frame++;

            if (!IsGameGear)
            {
                PSG.Set_Panning(Settings.ForceStereoSeparation ? ForceStereoByte : (byte)0xFF);
            }

            if (Tracer.Enabled)
            {
                Cpu.TraceCallback = s => Tracer.Put(s);
            }
            else
            {
                Cpu.TraceCallback = null;
            }

            if (IsGameGear_C == false)
            {
                Cpu.NonMaskableInterrupt = controller.IsPressed("Pause");
            }
            else if (!IsGameGear && IsGameGear_C)
            {
                Cpu.NonMaskableInterrupt = controller.IsPressed("P1 Start");
            }

            if (IsGame3D && Settings.Fix3D)
            {
                render = ((Frame & 1) == 0) & render;
            }

            int scanlinesPerFrame = Vdp.DisplayType == DisplayType.NTSC ? 262 : 313;

            Vdp.SpriteLimit = Settings.SpriteLimit;
            for (int i = 0; i < scanlinesPerFrame; i++)
            {
                Vdp.ScanLine = i;

                Vdp.RenderCurrentScanline(render);

                Vdp.ProcessFrameInterrupt();
                Vdp.ProcessLineInterrupt();
                ProcessLineControls();

                for (int j = 0; j < Vdp.IPeriod; j++)
                {
                    Cpu.ExecuteOne();

                    PSG.generate_sound();

                    s_L = PSG.current_sample_L;
                    s_R = PSG.current_sample_R;

                    if (s_L != OldSl)
                    {
                        BlipL.AddDelta(SampleClock, s_L - OldSl);
                        OldSl = s_L;
                    }

                    if (s_R != OldSr)
                    {
                        BlipR.AddDelta(SampleClock, s_R - OldSr);
                        OldSr = s_R;
                    }

                    SampleClock++;
                }

                if (Vdp.ScanLine == scanlinesPerFrame - 1)
                {
                    Vdp.ProcessGGScreen();
                    Vdp.ProcessOverscan();
                }
            }

            if (_lagged)
            {
                _lagCount++;
                _isLag = true;
            }
            else
            {
                _isLag = false;
            }

            return(true);
        }