Switch.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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 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 Switch(VirtualFileSystem fileSystem, ContentManager contentManager, IRenderer renderer, IAalOutput audioOut)
  27. {
  28. if (renderer == null)
  29. {
  30. throw new ArgumentNullException(nameof(renderer));
  31. }
  32. if (audioOut == null)
  33. {
  34. throw new ArgumentNullException(nameof(audioOut));
  35. }
  36. AudioOut = audioOut;
  37. Memory = new DeviceMemory();
  38. Gpu = new GpuContext(renderer);
  39. FileSystem = fileSystem;
  40. System = new Horizon(this, contentManager);
  41. Statistics = new PerformanceStatistics();
  42. Hid = new Hid(this, System.HidBaseAddress);
  43. Hid.InitDevices();
  44. }
  45. public void Initialize()
  46. {
  47. System.State.SetLanguage((SystemLanguage)ConfigurationState.Instance.System.Language.Value);
  48. System.State.SetRegion((SystemRegion)ConfigurationState.Instance.System.Region.Value);
  49. EnableDeviceVsync = ConfigurationState.Instance.Graphics.EnableVsync;
  50. System.State.DockedMode = ConfigurationState.Instance.System.EnableDockedMode;
  51. if (ConfigurationState.Instance.System.EnableMulticoreScheduling)
  52. {
  53. System.EnableMultiCoreScheduling();
  54. }
  55. System.FsIntegrityCheckLevel = GetIntigrityCheckLevel();
  56. System.GlobalAccessLogMode = ConfigurationState.Instance.System.FsGlobalAccessLogMode;
  57. ServiceConfiguration.IgnoreMissingServices = ConfigurationState.Instance.System.IgnoreMissingServices;
  58. }
  59. public static IntegrityCheckLevel GetIntigrityCheckLevel()
  60. {
  61. return ConfigurationState.Instance.System.EnableFsIntegrityChecks
  62. ? IntegrityCheckLevel.ErrorOnInvalid
  63. : IntegrityCheckLevel.None;
  64. }
  65. public void LoadCart(string exeFsDir, string romFsFile = null)
  66. {
  67. System.LoadCart(exeFsDir, romFsFile);
  68. }
  69. public void LoadXci(string xciFile)
  70. {
  71. System.LoadXci(xciFile);
  72. }
  73. public void LoadNca(string ncaFile)
  74. {
  75. System.LoadNca(ncaFile);
  76. }
  77. public void LoadNsp(string nspFile)
  78. {
  79. System.LoadNsp(nspFile);
  80. }
  81. public void LoadProgram(string fileName)
  82. {
  83. System.LoadProgram(fileName);
  84. }
  85. public bool WaitFifo()
  86. {
  87. return Gpu.DmaPusher.WaitForCommands();
  88. }
  89. public void ProcessFrame()
  90. {
  91. Gpu.DmaPusher.DispatchCalls();
  92. }
  93. public void PresentFrame(Action swapBuffersCallback)
  94. {
  95. Gpu.Window.Present(swapBuffersCallback);
  96. }
  97. internal void Unload()
  98. {
  99. FileSystem.Unload();
  100. Memory.Dispose();
  101. }
  102. public void DisposeGpu()
  103. {
  104. Gpu.Dispose();
  105. }
  106. public void Dispose()
  107. {
  108. Dispose(true);
  109. }
  110. protected virtual void Dispose(bool disposing)
  111. {
  112. if (disposing)
  113. {
  114. System.Dispose();
  115. AudioOut.Dispose();
  116. }
  117. }
  118. }
  119. }