Switch.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. using LibHac.FsSystem;
  2. using Ryujinx.Audio;
  3. using Ryujinx.Configuration;
  4. using Ryujinx.Graphics.GAL;
  5. using Ryujinx.Graphics.Gpu;
  6. using Ryujinx.HLE.FileSystem;
  7. using Ryujinx.HLE.FileSystem.Content;
  8. using Ryujinx.HLE.HOS;
  9. using Ryujinx.HLE.HOS.Services;
  10. using Ryujinx.HLE.HOS.SystemState;
  11. using Ryujinx.HLE.Input;
  12. using System;
  13. using System.Threading;
  14. namespace Ryujinx.HLE
  15. {
  16. public class Switch : IDisposable
  17. {
  18. public IAalOutput AudioOut { get; private set; }
  19. internal DeviceMemory Memory { get; private set; }
  20. public GpuContext Gpu { get; private set; }
  21. public VirtualFileSystem FileSystem { get; private set; }
  22. public Horizon System { get; private set; }
  23. public PerformanceStatistics Statistics { get; private set; }
  24. public Hid Hid { get; private set; }
  25. public bool EnableDeviceVsync { get; set; } = true;
  26. public AutoResetEvent VsyncEvent { get; private set; }
  27. public event EventHandler Finish;
  28. public Switch(VirtualFileSystem fileSystem, ContentManager contentManager, IRenderer renderer, IAalOutput audioOut)
  29. {
  30. if (renderer == null)
  31. {
  32. throw new ArgumentNullException(nameof(renderer));
  33. }
  34. if (audioOut == null)
  35. {
  36. throw new ArgumentNullException(nameof(audioOut));
  37. }
  38. AudioOut = audioOut;
  39. Memory = new DeviceMemory();
  40. Gpu = new GpuContext(renderer);
  41. FileSystem = fileSystem;
  42. System = new Horizon(this, contentManager);
  43. Statistics = new PerformanceStatistics();
  44. Hid = new Hid(this, System.HidBaseAddress);
  45. VsyncEvent = new AutoResetEvent(true);
  46. }
  47. public void Initialize()
  48. {
  49. System.State.SetLanguage((SystemLanguage)ConfigurationState.Instance.System.Language.Value);
  50. EnableDeviceVsync = ConfigurationState.Instance.Graphics.EnableVsync;
  51. // TODO: Make this reloadable and implement Docking/Undocking logic.
  52. System.State.DockedMode = ConfigurationState.Instance.System.EnableDockedMode;
  53. if (ConfigurationState.Instance.System.EnableMulticoreScheduling)
  54. {
  55. System.EnableMultiCoreScheduling();
  56. }
  57. System.FsIntegrityCheckLevel = GetIntigrityCheckLevel();
  58. System.GlobalAccessLogMode = ConfigurationState.Instance.System.FsGlobalAccessLogMode;
  59. ServiceConfiguration.IgnoreMissingServices = ConfigurationState.Instance.System.IgnoreMissingServices;
  60. }
  61. public static IntegrityCheckLevel GetIntigrityCheckLevel()
  62. {
  63. return ConfigurationState.Instance.System.EnableFsIntegrityChecks
  64. ? IntegrityCheckLevel.ErrorOnInvalid
  65. : IntegrityCheckLevel.None;
  66. }
  67. public void LoadCart(string exeFsDir, string romFsFile = null)
  68. {
  69. System.LoadCart(exeFsDir, romFsFile);
  70. }
  71. public void LoadXci(string xciFile)
  72. {
  73. System.LoadXci(xciFile);
  74. }
  75. public void LoadNca(string ncaFile)
  76. {
  77. System.LoadNca(ncaFile);
  78. }
  79. public void LoadNsp(string nspFile)
  80. {
  81. System.LoadNsp(nspFile);
  82. }
  83. public void LoadProgram(string fileName)
  84. {
  85. System.LoadProgram(fileName);
  86. }
  87. public bool WaitFifo()
  88. {
  89. return Gpu.DmaPusher.WaitForCommands();
  90. }
  91. public void ProcessFrame()
  92. {
  93. Gpu.DmaPusher.DispatchCalls();
  94. }
  95. public void PresentFrame(Action swapBuffersCallback)
  96. {
  97. Gpu.Window.Present(swapBuffersCallback);
  98. }
  99. internal void Unload()
  100. {
  101. FileSystem.Unload();
  102. Memory.Dispose();
  103. }
  104. public void DisposeGpu()
  105. {
  106. Gpu.Dispose();
  107. }
  108. public void Dispose()
  109. {
  110. Dispose(true);
  111. }
  112. protected virtual void Dispose(bool disposing)
  113. {
  114. if (disposing)
  115. {
  116. System.Dispose();
  117. VsyncEvent.Dispose();
  118. AudioOut.Dispose();
  119. }
  120. }
  121. }
  122. }