Switch.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. using Ryujinx.Audio;
  2. using Ryujinx.Graphics;
  3. using Ryujinx.Graphics.Gal;
  4. using Ryujinx.HLE.FileSystem;
  5. using Ryujinx.HLE.HOS;
  6. using Ryujinx.HLE.Input;
  7. using Ryujinx.HLE.Logging;
  8. using Ryujinx.HLE.Memory;
  9. using System;
  10. using System.Threading;
  11. namespace Ryujinx.HLE
  12. {
  13. public class Switch : IDisposable
  14. {
  15. internal IAalOutput AudioOut { get; private set; }
  16. public Logger Log { get; private set; }
  17. internal DeviceMemory Memory { get; private set; }
  18. internal NvGpu Gpu { get; private set; }
  19. internal VirtualFileSystem FileSystem { get; private set; }
  20. public Horizon System { get; private set; }
  21. public PerformanceStatistics Statistics { get; private set; }
  22. public Hid Hid { get; private set; }
  23. public bool EnableDeviceVsync { get; set; } = true;
  24. public AutoResetEvent VsyncEvent { get; private set; }
  25. public event EventHandler Finish;
  26. public Switch(IGalRenderer Renderer, IAalOutput AudioOut)
  27. {
  28. if (Renderer == null)
  29. {
  30. throw new ArgumentNullException(nameof(Renderer));
  31. }
  32. if (AudioOut == null)
  33. {
  34. throw new ArgumentNullException(nameof(AudioOut));
  35. }
  36. this.AudioOut = AudioOut;
  37. Log = new Logger();
  38. Memory = new DeviceMemory();
  39. Gpu = new NvGpu(Renderer);
  40. FileSystem = new VirtualFileSystem();
  41. System = new Horizon(this);
  42. Statistics = new PerformanceStatistics();
  43. Hid = new Hid(this, System.HidSharedMem.PA);
  44. VsyncEvent = new AutoResetEvent(true);
  45. }
  46. public void LoadCart(string ExeFsDir, string RomFsFile = null)
  47. {
  48. System.LoadCart(ExeFsDir, RomFsFile);
  49. }
  50. public void LoadXci(string XciFile)
  51. {
  52. System.LoadXci(XciFile);
  53. }
  54. public void LoadNca(string NcaFile)
  55. {
  56. System.LoadNca(NcaFile);
  57. }
  58. public void LoadNsp(string NspFile)
  59. {
  60. System.LoadNsp(NspFile);
  61. }
  62. public void LoadProgram(string FileName)
  63. {
  64. System.LoadProgram(FileName);
  65. }
  66. public bool WaitFifo()
  67. {
  68. return Gpu.Fifo.Event.WaitOne(8);
  69. }
  70. public void ProcessFrame()
  71. {
  72. Gpu.Fifo.DispatchCalls();
  73. }
  74. internal void Unload()
  75. {
  76. FileSystem.Dispose();
  77. Memory.Dispose();
  78. }
  79. public void Dispose()
  80. {
  81. Dispose(true);
  82. }
  83. protected virtual void Dispose(bool Disposing)
  84. {
  85. if (Disposing)
  86. {
  87. System.Dispose();
  88. VsyncEvent.Dispose();
  89. }
  90. }
  91. }
  92. }