Switch.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. using Ryujinx.Audio;
  2. using Ryujinx.Graphics.Gal;
  3. using Ryujinx.HLE.Gpu;
  4. using Ryujinx.HLE.Input;
  5. using Ryujinx.HLE.Logging;
  6. using Ryujinx.HLE.OsHle;
  7. using Ryujinx.HLE.Settings;
  8. using System;
  9. namespace Ryujinx.HLE
  10. {
  11. public class Switch : IDisposable
  12. {
  13. internal IAalOutput AudioOut { get; private set; }
  14. public Logger Log { get; private set; }
  15. internal NvGpu Gpu { get; private set; }
  16. internal VirtualFileSystem VFs { get; private set; }
  17. public Horizon Os { get; private set; }
  18. public SystemSettings Settings { get; private set; }
  19. public PerformanceStatistics Statistics { get; private set; }
  20. public Hid Hid { get; private set; }
  21. public event EventHandler Finish;
  22. public Switch(IGalRenderer Renderer, IAalOutput AudioOut)
  23. {
  24. if (Renderer == null)
  25. {
  26. throw new ArgumentNullException(nameof(Renderer));
  27. }
  28. if (AudioOut == null)
  29. {
  30. throw new ArgumentNullException(nameof(AudioOut));
  31. }
  32. this.AudioOut = AudioOut;
  33. Log = new Logger();
  34. Gpu = new NvGpu(Renderer);
  35. VFs = new VirtualFileSystem();
  36. Os = new Horizon(this);
  37. Settings = new SystemSettings();
  38. Statistics = new PerformanceStatistics();
  39. Hid = new Hid(Log);
  40. Os.HidSharedMem.MemoryMapped += Hid.ShMemMap;
  41. Os.HidSharedMem.MemoryUnmapped += Hid.ShMemUnmap;
  42. }
  43. public void LoadCart(string ExeFsDir, string RomFsFile = null)
  44. {
  45. Os.LoadCart(ExeFsDir, RomFsFile);
  46. }
  47. public void LoadProgram(string FileName)
  48. {
  49. Os.LoadProgram(FileName);
  50. }
  51. public bool WaitFifo()
  52. {
  53. return Gpu.Fifo.Event.WaitOne(8);
  54. }
  55. public void ProcessFrame()
  56. {
  57. Gpu.Fifo.DispatchCalls();
  58. }
  59. internal virtual void OnFinish(EventArgs e)
  60. {
  61. Finish?.Invoke(this, e);
  62. }
  63. public void Dispose()
  64. {
  65. Dispose(true);
  66. }
  67. protected virtual void Dispose(bool Disposing)
  68. {
  69. if (Disposing)
  70. {
  71. Os.Dispose();
  72. VFs.Dispose();
  73. }
  74. }
  75. }
  76. }