Switch.cs 2.7 KB

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