Switch.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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.Services.Hid;
  11. using Ryujinx.HLE.HOS.SystemState;
  12. using Ryujinx.Memory;
  13. using System;
  14. using System.Threading;
  15. namespace Ryujinx.HLE
  16. {
  17. public class Switch : IDisposable
  18. {
  19. public IAalOutput AudioOut { get; private set; }
  20. internal MemoryBlock Memory { get; private set; }
  21. public GpuContext Gpu { get; private set; }
  22. public VirtualFileSystem FileSystem { get; private set; }
  23. public Horizon System { get; private set; }
  24. public ApplicationLoader Application { get; }
  25. public PerformanceStatistics Statistics { get; private set; }
  26. public Hid Hid { get; private set; }
  27. public bool EnableDeviceVsync { get; set; } = true;
  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 MemoryBlock(1UL << 32);
  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. Hid.InitDevices();
  46. Application = new ApplicationLoader(this, fileSystem, contentManager);
  47. }
  48. public void Initialize()
  49. {
  50. System.State.SetLanguage((SystemLanguage)ConfigurationState.Instance.System.Language.Value);
  51. System.State.SetRegion((RegionCode)ConfigurationState.Instance.System.Region.Value);
  52. EnableDeviceVsync = ConfigurationState.Instance.Graphics.EnableVsync;
  53. System.State.DockedMode = ConfigurationState.Instance.System.EnableDockedMode;
  54. if (ConfigurationState.Instance.System.EnableMulticoreScheduling)
  55. {
  56. System.EnableMultiCoreScheduling();
  57. }
  58. System.EnablePtc = ConfigurationState.Instance.System.EnablePtc;
  59. System.FsIntegrityCheckLevel = GetIntegrityCheckLevel();
  60. System.GlobalAccessLogMode = ConfigurationState.Instance.System.FsGlobalAccessLogMode;
  61. ServiceConfiguration.IgnoreMissingServices = ConfigurationState.Instance.System.IgnoreMissingServices;
  62. }
  63. public static IntegrityCheckLevel GetIntegrityCheckLevel()
  64. {
  65. return ConfigurationState.Instance.System.EnableFsIntegrityChecks
  66. ? IntegrityCheckLevel.ErrorOnInvalid
  67. : IntegrityCheckLevel.None;
  68. }
  69. public void LoadCart(string exeFsDir, string romFsFile = null)
  70. {
  71. Application.LoadCart(exeFsDir, romFsFile);
  72. }
  73. public void LoadXci(string xciFile)
  74. {
  75. Application.LoadXci(xciFile);
  76. }
  77. public void LoadNca(string ncaFile)
  78. {
  79. Application.LoadNca(ncaFile);
  80. }
  81. public void LoadNsp(string nspFile)
  82. {
  83. Application.LoadNsp(nspFile);
  84. }
  85. public void LoadProgram(string fileName)
  86. {
  87. Application.LoadProgram(fileName);
  88. }
  89. public bool WaitFifo()
  90. {
  91. return Gpu.DmaPusher.WaitForCommands();
  92. }
  93. public void ProcessFrame()
  94. {
  95. Gpu.DmaPusher.DispatchCalls();
  96. }
  97. public void PresentFrame(Action swapBuffersCallback)
  98. {
  99. Gpu.Window.Present(swapBuffersCallback);
  100. }
  101. internal void Unload()
  102. {
  103. FileSystem.Unload();
  104. Memory.Dispose();
  105. }
  106. public void DisposeGpu()
  107. {
  108. Gpu.Dispose();
  109. }
  110. public void Dispose()
  111. {
  112. Dispose(true);
  113. }
  114. protected virtual void Dispose(bool disposing)
  115. {
  116. if (disposing)
  117. {
  118. System.Dispose();
  119. AudioOut.Dispose();
  120. }
  121. }
  122. }
  123. }