コード例 #1
0
ファイル: APU.cs プロジェクト: evgenyvinnik/jvsc-windows-apps
        void InitDirectSound(/*Control parent*/)
        {
            //Create the device
            MyNesDEBUGGER.WriteLine(this, "Initializing direct sound for APU", DebugStatus.None);

            /*_SoundDevice = new DirectSound();
             * _SoundDevice.SetCooperativeLevel(parent.Parent.Handle, CooperativeLevel.Normal);
             * //Create the wav format
             * WaveFormat wav = new WaveFormat();
             * wav.FormatTag = WaveFormatTag.Pcm;
             * wav.SamplesPerSecond = 44100;
             * wav.Channels = (short)(STEREO ? 2 : 1);
             * AD = (STEREO ? 4 : 2);//Stereo / Mono
             * wav.BitsPerSample = 16;
             * wav.AverageBytesPerSecond = wav.SamplesPerSecond * wav.Channels * (wav.BitsPerSample / 8);
             * wav.BlockAlignment = (short)(wav.Channels * wav.BitsPerSample / 8);
             * BufferSize = wav.AverageBytesPerSecond;
             * //Description
             * SoundBufferDescription des = new SoundBufferDescription();
             * des.Format = wav;
             * des.SizeInBytes = BufferSize;
             * //des.Flags = BufferFlags.GlobalFocus | BufferFlags.Software;
             * des.Flags = BufferFlags.ControlVolume | BufferFlags.ControlFrequency | BufferFlags.ControlPan | BufferFlags.ControlEffects;
             * //buffer
             * DATA = new byte[BufferSize];
             * buffer = new SecondarySoundBuffer(_SoundDevice, des);
             * buffer.Play(0, PlayFlags.Looping);
             * //channels
             * InitChannels();
             * MyNesDEBUGGER.WriteLine(this, "APU OK !!", DebugStatus.Cool);*/
        }
コード例 #2
0
 /// <summary>
 /// The main class of the emulator
 /// </summary>
 public NES()
 {
     MyNesDEBUGGER.WriteLine(this, "Initializing the NES engine..", DebugStatus.None);
     _Mem = new CPUMemory(this);
     _Ppu = new PPU(this);
     _Cpu = new CPU(this);
     ON   = true;
     MyNesDEBUGGER.WriteLine(this, "NES engine running.", DebugStatus.Cool);
 }
コード例 #3
0
 public void SetUpMapperDefaults()
 {
     timer_irq_enabled = false;
     Map.Switch16kPrgRom(0, 0);
     Map.Switch16kPrgRom((Map.Cartridge.PRG_PAGES - 1) * 4, 1);
     if (Map.Cartridge.IsVRAM)
     {
         Map.FillCHR(16);
     }
     Map.Switch8kChrRom(0);
     MyNesDEBUGGER.WriteLine(this, "Mapper 16 setup done.", DebugStatus.Cool);
 }
コード例 #4
0
 public void SaveSRAM(string FilePath)
 {
     //If we have save RAM, try to save it
     try
     {
         using (FileStream writer = File.OpenWrite(FilePath))
         {
             writer.Write(_Mem.SRAM, 0, 0x2000);
             writer.Close();
             MyNesDEBUGGER.WriteLine(this, "SRAM saved !!", DebugStatus.Cool);
         }
     }
     catch
     {
         MyNesDEBUGGER.WriteLine(this, "Could not save S-RAM.", DebugStatus.Error);
     }
 }
コード例 #5
0
 /// <summary>
 /// Turn off the nes !!
 /// </summary>
 public void ShutDown()
 {
     //while (_Apu.IsRendering)
     //{ }
     MyNesDEBUGGER.WriteLine(this, "SHUTDOWN", DebugStatus.Error);
     _Apu.Pause();
     _Apu.Shutdown();
     if (_Apu.RECODER.IsRecording)
     {
         _Apu.RECODER.Stop();
     }
     if (_Mem.Cartridge.IsBatteryBacked & AutoSaveSRAM)
     {
         SaveSRAM(_Mem.Cartridge.SRAMFileName);
     }
     ON = false;
     MyNesDEBUGGER.WriteSeparateLine(this, DebugStatus.None);
 }
コード例 #6
0
 /// <summary>
 /// Picture Processing Unit class
 /// </summary>
 /// <param name="nes">The nes</param>
 public PPU(NES nes)
 {
     MEM_PPU        = new PPUMemory(nes);
     nes.Memory.ppu = this;
     MyNesDEBUGGER.WriteLine(this, "PPU Initialized ok.", DebugStatus.Cool);
 }
コード例 #7
0
        /// <summary>
        /// Load a carttidage file
        /// </summary>
        /// <param name="FileName">The complete rom path</param>
        /// <param name="HeaderOnly">True=load header only, false=load the prg, chr and trainer</param>
        /// <returns>The status of the load operation</returns>
        public LoadRomStatus Load(string FileName, bool HeaderOnly)
        {
            try
            {
                Encoding aSCII = Encoding.ASCII;
                //Create our stream
                Stream STR = new FileStream(FileName, FileMode.Open, FileAccess.Read);
                //Read the header
                byte[] header = new byte[16];
                STR.Read(header, 0, 16);
                //Check out
                if (aSCII.GetString(header, 0, 3) != "NES")
                {
                    STR.Close();
                    return(LoadRomStatus.NotINES);
                }
                //Flags
                PRG_PAGES = header[4];
                CHR_PAGES = header[5];
                if ((header[6] & 0x1) != 0x0)
                {
                    this.Mirroring = Nes.Mirroring.Vertical;
                }
                else
                {
                    this.Mirroring = Nes.Mirroring.Horizontal;
                }
                IsBatteryBacked = (header[6] & 0x2) != 0x0;
                IsTrainer       = (header[6] & 0x4) != 0x0;
                if ((header[6] & 0x8) != 0x0)
                {
                    this.Mirroring = Nes.Mirroring.Four_Screen;
                }
                if ((header[7] & 0x0F) == 0)
                {
                    MAPPER = (byte)((header[7] & 0xF0) | (header[6] & 0xF0) >> 4);
                }
                else
                {
                    MAPPER = (byte)((header[6] & 0xF0) >> 4);
                }


                IsPAL = CheckForPal(FileName);

                if (!SupportedMapper())
                {
                    STR.Close();
                    return(LoadRomStatus.UnsupportedMapper);
                }
                //Load the cart pages
                if (!HeaderOnly)
                {
                    //Trainer
                    if (IsTrainer)
                    {
                        STR.Read(MEM.SRAM, 0x1000, 512);
                    }
                    //PRG
                    int prg_roms = PRG_PAGES * 4;
                    PRG = new byte[prg_roms][];
                    for (int i = 0; i < prg_roms; i++)
                    {
                        PRG[i] = new byte[4096];
                        STR.Read(PRG[i], 0, 4096);
                    }
                    //CHR
                    int chr_roms = CHR_PAGES * 8;
                    if (CHR_PAGES != 0)
                    {
                        CHR = new byte[chr_roms][];
                        for (int i = 0; i < (chr_roms); i++)
                        {
                            CHR[i] = new byte[1024];
                            STR.Read(CHR[i], 0, 1024);
                        }
                        IsVRAM = false;
                    }
                    else
                    {
                        IsVRAM = true;//Mapper will fill up the chr
                    }
                    MyNesDEBUGGER.WriteLine(this, "PRG PAGES = " + PRG_PAGES.ToString(), DebugStatus.None);
                    MyNesDEBUGGER.WriteLine(this, "CHR PAGES = " + CHR_PAGES.ToString(), DebugStatus.None);
                    MyNesDEBUGGER.WriteLine(this, "Mapper # " + MAPPER, DebugStatus.Cool);
                    if (IsPAL)
                    {
                        MyNesDEBUGGER.WriteLine(this, "PAL rom", DebugStatus.Warning);
                    }
                    else
                    {
                        MyNesDEBUGGER.WriteLine(this, "NTSC rom", DebugStatus.Warning);
                    }

                    //SRAM
                    if (IsBatteryBacked)
                    {
                        SRAMFileName = FileName.Remove(FileName.Length - 3, 3);
                        SRAMFileName = SRAMFileName.Insert(SRAMFileName.Length, "sav");
                        MyNesDEBUGGER.WriteLine(this, "Trying to read SRAM from file : " + SRAMFileName, DebugStatus.None);
                        try
                        {
                            using (FileStream reader = File.OpenRead(SRAMFileName))
                            {
                                reader.Read(MEM.SRAM, 0, 0x2000);
                                reader.Close();
                                MyNesDEBUGGER.WriteLine(this, "Done read SRAM.", DebugStatus.Cool);
                            }
                        }
                        catch
                        {
                            MyNesDEBUGGER.WriteLine(this, "Faild to read SRAM", DebugStatus.Warning);
                        }
                    }
                    RomPath = FileName;
                    InitializeMapper();
                }
                //Finish
                STR.Close();
                return(LoadRomStatus.LoadSuccessed);
            }
            catch
            {
            }
            return(LoadRomStatus.LoadFaild);
        }
コード例 #8
0
 public void SetUpMapperDefaults()
 {
     Map.Switch32kPrgRom(0);
     Map.Switch8kChrRom(0);
     MyNesDEBUGGER.WriteLine(this, "Mapper 11 setup done.", DebugStatus.Cool);
 }