Switch.cs 4.1 KB

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