Switch.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. 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. }