Switch.cs 2.7 KB

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