Beispiel #1
0
 private void InitSound()
 {
     _blipL = new BlipBuffer(1024);
     _blipL.SetRates(TICKSPERSECOND, 44100);
     _blipR = new BlipBuffer(1024);
     _blipR.SetRates(TICKSPERSECOND, 44100);
 }
Beispiel #2
0
        public GambatteLink(CoreComm comm, GameInfo leftinfo, byte[] leftrom, GameInfo rightinfo, byte[] rightrom, object settings, object syncSettings, bool deterministic)
        {
            ServiceProvider = new BasicServiceProvider(this);
            GambatteLinkSettings     linkSettings     = (GambatteLinkSettings)settings ?? new GambatteLinkSettings();
            GambatteLinkSyncSettings linkSyncSettings = (GambatteLinkSyncSettings)syncSettings ?? new GambatteLinkSyncSettings();

            L = new Gameboy(comm, leftinfo, leftrom, linkSettings.L, linkSyncSettings.L, deterministic);
            R = new Gameboy(comm, rightinfo, rightrom, linkSettings.R, linkSyncSettings.R, deterministic);

            // connect link cable
            LibGambatte.gambatte_linkstatus(L.GambatteState, 259);
            LibGambatte.gambatte_linkstatus(R.GambatteState, 259);

            L.ConnectInputCallbackSystem(_inputCallbacks);
            R.ConnectInputCallbackSystem(_inputCallbacks);
            L.ConnectMemoryCallbackSystem(_memorycallbacks);
            R.ConnectMemoryCallbackSystem(_memorycallbacks);

            RomDetails = "LEFT:\r\n" + L.RomDetails + "RIGHT:\r\n" + R.RomDetails;

            LinkConnected = true;

            Frame      = 0;
            LagCount   = 0;
            IsLagFrame = false;

            _blipLeft  = new BlipBuffer(1024);
            _blipRight = new BlipBuffer(1024);
            _blipLeft.SetRates(2097152 * 2, 44100);
            _blipRight.SetRates(2097152 * 2, 44100);

            SetMemoryDomains();
        }
Beispiel #3
0
        public void AudioReset()
        {
            master_audio_clock = 0;

            sample = 0;

            _blip_C.SetRates(4194304, 44100);
        }
Beispiel #4
0
        public void AudioReset()
        {
            master_audio_clock = 0;

            sample = 0;

            _blip_C.SetRates(1792000, 44100);
        }
Beispiel #5
0
 private void SetupAudio()
 {
     Period          = 1.0 / SampleRate;
     SamplesPerFrame = (int)(SampleRate / refreshRate);
     CyclesPerSample = (double)ClockPerFrame / (double)SamplesPerFrame;
     SampleBuffer    = new short[SamplesPerFrame];
     _blip           = new BlipBuffer(SamplesPerFrame);
     _blip.SetRates(ClockPerFrame * refreshRate, SampleRate);
 }
Beispiel #6
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="blipSampleRate">The sample rate to pass to blipbuffer (this should be 44100 for ISoundProvider)</param>
 /// <param name="clocksPerFrame">The number of (usually CPU) clocked cycles in one frame</param>
 /// <param name="framesPerSecond">The number of frames per second (usually either 60 or 50)</param>
 /// <param name="beeperId">Unique name for this instance (needed for serialization as some cores have more than one active instance of the beeper)</param>
 public OneBitBeeper(int blipSampleRate, int clocksPerFrame, int framesPerSecond, string beeperId)
 {
     _beeperId        = beeperId;
     _sampleRate      = blipSampleRate;
     _clocksPerFrame  = clocksPerFrame;
     _framesPerSecond = framesPerSecond;
     _blip            = new BlipBuffer(blipSampleRate / framesPerSecond);
     _blip.SetRates(clocksPerFrame * 50, blipSampleRate);
 }
        private void SetupResampler(double fps, double sps)
        {
            Console.WriteLine("FPS {0} SPS {1}", fps, sps);

            _outSampBuf = new short[44100];             // big enough

            _blipL = new BlipBuffer(44100);
            _blipL.SetRates(sps, 44100);
            _blipR = new BlipBuffer(44100);
            _blipR.SetRates(sps, 44100);
        }
Beispiel #8
0
        public void Reset()
        {
            Audio_Regs = new byte[21];

            master_audio_clock = 0;

            sample = 0;

            _blip_L.SetRates(4194304, 44100);
            _blip_R.SetRates(4194304, 44100);
        }
Beispiel #9
0
            public MagicSoundProvider(NES nes, uint infreq)
            {
                this.nes = nes;

                blip = new BlipBuffer(blipbuffsize);
                blip.SetRates(infreq, 44100);

                //var actualMetaspu = new Sound.MetaspuSoundProvider(Sound.ESynchMethod.ESynchMethod_V);
                //1.789773mhz NTSC
                //resampler = new Sound.Utilities.SpeexResampler(2, infreq, 44100 * APU.DECIMATIONFACTOR, infreq, 44100, actualMetaspu.buffer.enqueue_samples);
                //output = new Sound.Utilities.DCFilter(actualMetaspu);
            }
Beispiel #10
0
        public void Reset()
        {
            clock_A     = clock_B = clock_C = 0x1000;
            noise_clock = 0x20;
            port_sel    = 0;

            for (int i = 0; i < 16; i++)
            {
                Register[i] = 0x0000;
            }
            sync_psg_state();

            _blip_L.SetRates(4194304, 44100);
            _blip_R.SetRates(4194304, 44100);
        }
Beispiel #11
0
        public void Reset()
        {
            clock_A            = clock_B = clock_C = 0x1000;
            noise_clock        = 0x20;
            port_sel           = 0;
            current_sample     = old_sample = 0;
            master_audio_clock = 0;

            for (int i = 0; i < 16; i++)
            {
                Register[i] = 0x0000;
            }
            sync_psg_state();

            _blip.SetRates(1500000, 44100);
        }
Beispiel #12
0
        public GambatteLink(CoreComm comm, GameInfo leftinfo, byte[] leftrom, GameInfo rightinfo, byte[] rightrom, object Settings, object SyncSettings, bool deterministic)
        {
            ServiceProvider = new BasicServiceProvider(this);
            GambatteLinkSettings     _Settings     = (GambatteLinkSettings)Settings ?? new GambatteLinkSettings();
            GambatteLinkSyncSettings _SyncSettings = (GambatteLinkSyncSettings)SyncSettings ?? new GambatteLinkSyncSettings();

            CoreComm = comm;
            L        = new Gameboy(new CoreComm(comm.ShowMessage, comm.Notify), leftinfo, leftrom, _Settings.L, _SyncSettings.L, deterministic);
            R        = new Gameboy(new CoreComm(comm.ShowMessage, comm.Notify), rightinfo, rightrom, _Settings.R, _SyncSettings.R, deterministic);

            // connect link cable
            LibGambatte.gambatte_linkstatus(L.GambatteState, 259);
            LibGambatte.gambatte_linkstatus(R.GambatteState, 259);

            L.Controller = LCont;
            R.Controller = RCont;
            L.ConnectInputCallbackSystem(_inputCallbacks);
            R.ConnectInputCallbackSystem(_inputCallbacks);
            L.ConnectMemoryCallbackSystem(_memorycallbacks);
            R.ConnectMemoryCallbackSystem(_memorycallbacks);

            comm.VsyncNum            = L.CoreComm.VsyncNum;
            comm.VsyncDen            = L.CoreComm.VsyncDen;
            comm.RomStatusAnnotation = null;
            comm.RomStatusDetails    = "LEFT:\r\n" + L.CoreComm.RomStatusDetails + "RIGHT:\r\n" + R.CoreComm.RomStatusDetails;
            comm.NominalWidth        = L.CoreComm.NominalWidth + R.CoreComm.NominalWidth;
            comm.NominalHeight       = L.CoreComm.NominalHeight;

            LinkConnected = true;

            Frame      = 0;
            LagCount   = 0;
            IsLagFrame = false;

            blip_left  = new BlipBuffer(1024);
            blip_right = new BlipBuffer(1024);
            blip_left.SetRates(2097152 * 2, 44100);
            blip_right.SetRates(2097152 * 2, 44100);

            SetMemoryDomains();
        }
Beispiel #13
0
        public GambatteLink(CoreLoadParameters <GambatteLink.GambatteLinkSettings, GambatteLink.GambatteLinkSyncSettings> lp)
        {
            if (lp.Roms.Count != 2)
            {
                throw new InvalidOperationException("Wrong number of roms");
            }

            ServiceProvider = new BasicServiceProvider(this);
            GambatteLinkSettings     linkSettings     = (GambatteLinkSettings)lp.Settings ?? new GambatteLinkSettings();
            GambatteLinkSyncSettings linkSyncSettings = (GambatteLinkSyncSettings)lp.SyncSettings ?? new GambatteLinkSyncSettings();

            L = new Gameboy(lp.Comm, lp.Roms[0].Game, lp.Roms[0].RomData, linkSettings.L, linkSyncSettings.L, lp.DeterministicEmulationRequested);
            R = new Gameboy(lp.Comm, lp.Roms[1].Game, lp.Roms[1].RomData, linkSettings.R, linkSyncSettings.R, lp.DeterministicEmulationRequested);

            // connect link cable
            LibGambatte.gambatte_linkstatus(L.GambatteState, 259);
            LibGambatte.gambatte_linkstatus(R.GambatteState, 259);

            L.ConnectInputCallbackSystem(_inputCallbacks);
            R.ConnectInputCallbackSystem(_inputCallbacks);
            L.ConnectMemoryCallbackSystem(_memorycallbacks);
            R.ConnectMemoryCallbackSystem(_memorycallbacks);

            RomDetails = "LEFT:\r\n" + L.RomDetails + "RIGHT:\r\n" + R.RomDetails;

            LinkConnected = true;

            Frame      = 0;
            LagCount   = 0;
            IsLagFrame = false;

            _blipLeft  = new BlipBuffer(1024);
            _blipRight = new BlipBuffer(1024);
            _blipLeft.SetRates(2097152 * 2, 44100);
            _blipRight.SetRates(2097152 * 2, 44100);

            SetMemoryDomains();
        }
Beispiel #14
0
        public void HardReset()
        {
            cpu = new MOS6502X <CpuLink>(new CpuLink(this))
            {
                BCD_Enabled = false
            };

            ppu   = new PPU(this);
            ram   = new byte[0x800];
            CIRAM = new byte[0x800];

            // don't replace the magicSoundProvider on reset, as it's not needed
            // if (magicSoundProvider != null) magicSoundProvider.Dispose();

            // set up region
            switch (_display_type)
            {
            case DisplayType.PAL:
                apu           = new APU(this, apu, true);
                ppu.region    = PPU.Region.PAL;
                cpuclockrate  = 1662607;
                VsyncNum      = cpuclockrate * 2;
                VsyncDen      = 66495;
                cpu_sequence  = cpu_sequence_PAL;
                _display_type = DisplayType.PAL;
                ClockRate     = 5320342.5;
                break;

            case DisplayType.NTSC:
                apu          = new APU(this, apu, false);
                ppu.region   = PPU.Region.NTSC;
                cpuclockrate = 1789773;
                VsyncNum     = cpuclockrate * 2;
                VsyncDen     = 59561;
                cpu_sequence = cpu_sequence_NTSC;
                ClockRate    = 5369318.1818181818181818181818182;
                break;

            // this is in bootgod, but not used at all
            case DisplayType.Dendy:
                apu           = new APU(this, apu, false);
                ppu.region    = PPU.Region.Dendy;
                cpuclockrate  = 1773448;
                VsyncNum      = cpuclockrate;
                VsyncDen      = 35464;
                cpu_sequence  = cpu_sequence_NTSC;
                _display_type = DisplayType.Dendy;
                ClockRate     = 5320342.5;
                break;

            default:
                throw new Exception("Unknown displaytype!");
            }

            blip.SetRates((uint)cpuclockrate, 44100);

            BoardSystemHardReset();

            // apu has some specific power up bahaviour that we will emulate here
            apu.NESHardReset();

            if (SyncSettings.InitialWRamStatePattern != null && SyncSettings.InitialWRamStatePattern.Any())
            {
                for (int i = 0; i < 0x800; i++)
                {
                    ram[i] = SyncSettings.InitialWRamStatePattern[i % SyncSettings.InitialWRamStatePattern.Count];
                }
            }
            else
            {
                // check fceux's PowerNES and FCEU_MemoryRand function for more information:
                // relevant games: Cybernoid; Minna no Taabou no Nakayoshi Daisakusen; Huang Di; and maybe mechanized attack
                for (int i = 0; i < 0x800; i++)
                {
                    if ((i & 4) != 0)
                    {
                        ram[i] = 0xFF;
                    }
                    else
                    {
                        ram[i] = 0x00;
                    }
                }
            }

            SetupMemoryDomains();

            // some boards cannot have specific values in RAM upon initialization
            // Let's hard code those cases here
            // these will be defined through the gameDB exclusively for now.
            var hash = cart.GameInfo?.Hash;             // SHA1 or MD5 (see NES.IdentifyFromGameDB)

            if (hash is null)
            {
                // short-circuit
            }
            else if (hash is RomChecksums.CamericaGolden5 or RomChecksums.CamericaGolden5Overdump or RomChecksums.CamericaPegasus4in1)
            {
                ram[0x701] = 0xFF;
            }
Beispiel #15
0
 /// <summary>
 /// Initialises the beeper
 /// </summary>
 public void Init(int sampleRate, int tStatesPerFrame)
 {
     blip.SetRates((tStatesPerFrame * 50), sampleRate);
     _sampleRate      = sampleRate;
     _tStatesPerFrame = tStatesPerFrame;
 }
Beispiel #16
0
 public PSG()
 {
     _blip.SetRates(894866 / 4.0, 44100);
 }
Beispiel #17
0
        public void HardReset()
        {
            cpu = new MOS6502X <CpuLink>(new CpuLink(this))
            {
                BCD_Enabled = false
            };

            ppu   = new PPU(this);
            ram   = new byte[0x800];
            CIRAM = new byte[0x800];

            // wire controllers
            // todo: allow changing this
            ControllerDeck = ControllerSettings.Instantiate(ppu.LightGunCallback);
            // set controller definition first time only
            if (ControllerDefinition == null)
            {
                ControllerDefinition      = new ControllerDefinition(ControllerDeck.GetDefinition());
                ControllerDefinition.Name = "NES Controller";
                // controls other than the deck
                ControllerDefinition.BoolButtons.Add("Power");
                ControllerDefinition.BoolButtons.Add("Reset");
                if (Board is FDS)
                {
                    var b = Board as FDS;
                    ControllerDefinition.BoolButtons.Add("FDS Eject");
                    for (int i = 0; i < b.NumSides; i++)
                    {
                        ControllerDefinition.BoolButtons.Add("FDS Insert " + i);
                    }
                }

                if (_isVS)
                {
                    ControllerDefinition.BoolButtons.Add("Insert Coin P1");
                    ControllerDefinition.BoolButtons.Add("Insert Coin P2");
                    ControllerDefinition.BoolButtons.Add("Service Switch");
                }
            }

            // Add in the reset timing float control for subneshawk
            if (using_reset_timing && (ControllerDefinition.FloatControls.Count() == 0))
            {
                ControllerDefinition.FloatControls.Add("Reset Cycle");
                ControllerDefinition.FloatRanges.Add(new ControllerDefinition.FloatRange(0, 0, 500000));
            }

            // don't replace the magicSoundProvider on reset, as it's not needed
            // if (magicSoundProvider != null) magicSoundProvider.Dispose();

            // set up region
            switch (_display_type)
            {
            case Common.DisplayType.PAL:
                apu           = new APU(this, apu, true);
                ppu.region    = PPU.Region.PAL;
                VsyncNum      = 50;
                VsyncDen      = 1;
                cpuclockrate  = 1662607;
                cpu_sequence  = cpu_sequence_PAL;
                _display_type = DisplayType.PAL;
                ClockRate     = 5320342.5;
                break;

            case Common.DisplayType.NTSC:
                apu          = new APU(this, apu, false);
                ppu.region   = PPU.Region.NTSC;
                VsyncNum     = 39375000;
                VsyncDen     = 655171;
                cpuclockrate = 1789773;
                cpu_sequence = cpu_sequence_NTSC;
                ClockRate    = 5369318.1818181818181818181818182;
                break;

            // this is in bootgod, but not used at all
            case Common.DisplayType.Dendy:
                apu           = new APU(this, apu, false);
                ppu.region    = PPU.Region.Dendy;
                VsyncNum      = 50;
                VsyncDen      = 1;
                cpuclockrate  = 1773448;
                cpu_sequence  = cpu_sequence_NTSC;
                _display_type = DisplayType.Dendy;
                ClockRate     = 5320342.5;
                break;

            default:
                throw new Exception("Unknown displaytype!");
            }

            blip.SetRates((uint)cpuclockrate, 44100);

            BoardSystemHardReset();

            // apu has some specific power up bahaviour that we will emulate here
            apu.NESHardReset();

            if (SyncSettings.InitialWRamStatePattern != null && SyncSettings.InitialWRamStatePattern.Any())
            {
                for (int i = 0; i < 0x800; i++)
                {
                    ram[i] = SyncSettings.InitialWRamStatePattern[i % SyncSettings.InitialWRamStatePattern.Count];
                }
            }
            else
            {
                // check fceux's PowerNES and FCEU_MemoryRand function for more information:
                // relevant games: Cybernoid; Minna no Taabou no Nakayoshi Daisakusen; Huang Di; and maybe mechanized attack
                for (int i = 0; i < 0x800; i++)
                {
                    if ((i & 4) != 0)
                    {
                        ram[i] = 0xFF;
                    }
                    else
                    {
                        ram[i] = 0x00;
                    }
                }
            }

            SetupMemoryDomains();

            // some boards cannot have specific values in RAM upon initialization
            // Let's hard code those cases here
            // these will be defined through the gameDB exclusively for now.

            if (cart.DB_GameInfo != null)
            {
                if (cart.DB_GameInfo.Hash == "60FC5FA5B5ACCAF3AEFEBA73FC8BFFD3C4DAE558" ||              // Camerica Golden 5
                    cart.DB_GameInfo.Hash == "BAD382331C30B22A908DA4BFF2759C25113CC26A" ||                     // Camerica Golden 5
                    cart.DB_GameInfo.Hash == "40409FEC8249EFDB772E6FFB2DCD41860C6CCA23"                        // Camerica Pegasus 4-in-1
                    )
                {
                    ram[0x701] = 0xFF;
                }

                if (cart.DB_GameInfo.Hash == "68ABE1E49C9E9CCEA978A48232432C252E5912C0")                 // Dancing Blocks
                {
                    ram[0xEC] = 0;
                    ram[0xED] = 0;
                }

                if (cart.DB_GameInfo.Hash == "00C50062A2DECE99580063777590F26A253AAB6B")                 // Silva Saga
                {
                    for (int i = 0; i < Board.WRAM.Length; i++)
                    {
                        Board.WRAM[i] = 0xFF;
                    }
                }
            }
        }
        public void HardReset()
        {
            cpu = new MOS6502X <CpuLink>(new CpuLink(this))
            {
                BCD_Enabled = false
            };

            ppu   = new PPU(this);
            ram   = new byte[0x800];
            CIRAM = new byte[0x800];

            // wire controllers
            // todo: allow changing this
            ControllerDeck = ControllerSettings.Instantiate(ppu.LightGunCallback);
            // set controller definition first time only
            if (ControllerDefinition == null)
            {
                ControllerDefinition = new ControllerDefinition(ControllerDeck.GetDefinition())
                {
                    Name = "NES Controller"
                };

                // controls other than the deck
                ControllerDefinition.BoolButtons.Add("Power");
                ControllerDefinition.BoolButtons.Add("Reset");
                if (Board is FDS b)
                {
                    ControllerDefinition.BoolButtons.Add("FDS Eject");
                    for (int i = 0; i < b.NumSides; i++)
                    {
                        ControllerDefinition.BoolButtons.Add("FDS Insert " + i);
                    }
                }

                if (_isVS)
                {
                    ControllerDefinition.BoolButtons.Add("Insert Coin P1");
                    ControllerDefinition.BoolButtons.Add("Insert Coin P2");
                    ControllerDefinition.BoolButtons.Add("Service Switch");
                }
            }

            // Add in the reset timing axis for subneshawk
            if (using_reset_timing && ControllerDefinition.Axes.Count == 0)
            {
                ControllerDefinition.AddAxis("Reset Cycle", 0.RangeTo(500000), 0);
            }

            // don't replace the magicSoundProvider on reset, as it's not needed
            // if (magicSoundProvider != null) magicSoundProvider.Dispose();

            // set up region
            switch (_display_type)
            {
            case DisplayType.PAL:
                apu           = new APU(this, apu, true);
                ppu.region    = PPU.Region.PAL;
                cpuclockrate  = 1662607;
                VsyncNum      = cpuclockrate * 2;
                VsyncDen      = 66495;
                cpu_sequence  = cpu_sequence_PAL;
                _display_type = DisplayType.PAL;
                ClockRate     = 5320342.5;
                break;

            case DisplayType.NTSC:
                apu          = new APU(this, apu, false);
                ppu.region   = PPU.Region.NTSC;
                cpuclockrate = 1789773;
                VsyncNum     = cpuclockrate * 2;
                VsyncDen     = 59561;
                cpu_sequence = cpu_sequence_NTSC;
                ClockRate    = 5369318.1818181818181818181818182;
                break;

            // this is in bootgod, but not used at all
            case DisplayType.Dendy:
                apu           = new APU(this, apu, false);
                ppu.region    = PPU.Region.Dendy;
                cpuclockrate  = 1773448;
                VsyncNum      = cpuclockrate;
                VsyncDen      = 35464;
                cpu_sequence  = cpu_sequence_NTSC;
                _display_type = DisplayType.Dendy;
                ClockRate     = 5320342.5;
                break;

            default:
                throw new Exception("Unknown displaytype!");
            }

            blip.SetRates((uint)cpuclockrate, 44100);

            BoardSystemHardReset();

            // apu has some specific power up bahaviour that we will emulate here
            apu.NESHardReset();

            if (SyncSettings.InitialWRamStatePattern != null && SyncSettings.InitialWRamStatePattern.Any())
            {
                for (int i = 0; i < 0x800; i++)
                {
                    ram[i] = SyncSettings.InitialWRamStatePattern[i % SyncSettings.InitialWRamStatePattern.Count];
                }
            }
            else
            {
                // check fceux's PowerNES and FCEU_MemoryRand function for more information:
                // relevant games: Cybernoid; Minna no Taabou no Nakayoshi Daisakusen; Huang Di; and maybe mechanized attack
                for (int i = 0; i < 0x800; i++)
                {
                    if ((i & 4) != 0)
                    {
                        ram[i] = 0xFF;
                    }
                    else
                    {
                        ram[i] = 0x00;
                    }
                }
            }

            SetupMemoryDomains();

            // some boards cannot have specific values in RAM upon initialization
            // Let's hard code those cases here
            // these will be defined through the gameDB exclusively for now.

            if (cart.GameInfo != null)
            {
                if (cart.GameInfo.Hash is RomChecksums.CamericaGolden5 or RomChecksums.CamericaGolden5Overdump or RomChecksums.CamericaPegasus4in1)
                {
                    ram[0x701] = 0xFF;
                }
                else if (cart.GameInfo.Hash == RomChecksums.DancingBlocks)
                {
                    ram[0xEC] = 0;
                    ram[0xED] = 0;
                }
                else if (cart.GameInfo.Hash == RomChecksums.SilvaSaga)
                {
                    for (int i = 0; i < Board.Wram.Length; i++)
                    {
                        Board.Wram[i] = 0xFF;
                    }
                }
            }