Switch.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. using Ryujinx.Audio.Backends.CompatLayer;
  2. using Ryujinx.Audio.Integration;
  3. using Ryujinx.Graphics.Gpu;
  4. using Ryujinx.HLE.FileSystem;
  5. using Ryujinx.HLE.HOS;
  6. using Ryujinx.HLE.HOS.Services.Apm;
  7. using Ryujinx.HLE.HOS.Services.Hid;
  8. using Ryujinx.HLE.Ui;
  9. using Ryujinx.Memory;
  10. using System;
  11. namespace Ryujinx.HLE
  12. {
  13. public class Switch : IDisposable
  14. {
  15. public HLEConfiguration Configuration { get; }
  16. public IHardwareDeviceDriver AudioDeviceDriver { get; }
  17. public MemoryBlock Memory { get; }
  18. public GpuContext Gpu { get; }
  19. public VirtualFileSystem FileSystem { get; }
  20. public Horizon System { get; }
  21. public ApplicationLoader Application { get; }
  22. public PerformanceStatistics Statistics { get; }
  23. public Hid Hid { get; }
  24. public TamperMachine TamperMachine { get; }
  25. public IHostUiHandler UiHandler { get; }
  26. public bool EnableDeviceVsync { get; set; } = true;
  27. public Switch(HLEConfiguration configuration)
  28. {
  29. if (configuration.GpuRenderer == null)
  30. {
  31. throw new ArgumentNullException(nameof(configuration.GpuRenderer));
  32. }
  33. if (configuration.AudioDeviceDriver == null)
  34. {
  35. throw new ArgumentNullException(nameof(configuration.AudioDeviceDriver));
  36. }
  37. if (configuration.UserChannelPersistence == null)
  38. {
  39. throw new ArgumentNullException(nameof(configuration.UserChannelPersistence));
  40. }
  41. Configuration = configuration;
  42. FileSystem = Configuration.VirtualFileSystem;
  43. UiHandler = Configuration.HostUiHandler;
  44. AudioDeviceDriver = new CompatLayerHardwareDeviceDriver(Configuration.AudioDeviceDriver);
  45. Memory = new MemoryBlock(Configuration.MemoryConfiguration.ToDramSize(), MemoryAllocationFlags.Reserve);
  46. Gpu = new GpuContext(Configuration.GpuRenderer);
  47. System = new Horizon(this);
  48. Statistics = new PerformanceStatistics();
  49. Hid = new Hid(this, System.HidStorage);
  50. Application = new ApplicationLoader(this);
  51. TamperMachine = new TamperMachine();
  52. System.State.SetLanguage(Configuration.SystemLanguage);
  53. System.State.SetRegion(Configuration.Region);
  54. EnableDeviceVsync = Configuration.EnableVsync;
  55. System.State.DockedMode = Configuration.EnableDockedMode;
  56. System.PerformanceState.PerformanceMode = System.State.DockedMode ? PerformanceMode.Boost : PerformanceMode.Default;
  57. System.EnablePtc = Configuration.EnablePtc;
  58. System.FsIntegrityCheckLevel = Configuration.FsIntegrityCheckLevel;
  59. System.GlobalAccessLogMode = Configuration.FsGlobalAccessLogMode;
  60. }
  61. public void LoadCart(string exeFsDir, string romFsFile = null)
  62. {
  63. Application.LoadCart(exeFsDir, romFsFile);
  64. }
  65. public void LoadXci(string xciFile)
  66. {
  67. Application.LoadXci(xciFile);
  68. }
  69. public void LoadNca(string ncaFile)
  70. {
  71. Application.LoadNca(ncaFile);
  72. }
  73. public void LoadNsp(string nspFile)
  74. {
  75. Application.LoadNsp(nspFile);
  76. }
  77. public void LoadProgram(string fileName)
  78. {
  79. Application.LoadProgram(fileName);
  80. }
  81. public bool WaitFifo()
  82. {
  83. return Gpu.GPFifo.WaitForCommands();
  84. }
  85. public void ProcessFrame()
  86. {
  87. Gpu.ProcessShaderCacheQueue();
  88. Gpu.Renderer.PreFrame();
  89. Gpu.GPFifo.DispatchCalls();
  90. }
  91. public bool ConsumeFrameAvailable()
  92. {
  93. return Gpu.Window.ConsumeFrameAvailable();
  94. }
  95. public void PresentFrame(Action swapBuffersCallback)
  96. {
  97. Gpu.Window.Present(swapBuffersCallback);
  98. }
  99. public void SetVolume(float volume)
  100. {
  101. System.SetVolume(volume);
  102. }
  103. public float GetVolume()
  104. {
  105. return System.GetVolume();
  106. }
  107. public void EnableCheats()
  108. {
  109. FileSystem.ModLoader.EnableCheats(Application.TitleId, TamperMachine);
  110. }
  111. public bool IsAudioMuted()
  112. {
  113. return System.GetVolume() == 0;
  114. }
  115. public void DisposeGpu()
  116. {
  117. Gpu.Dispose();
  118. }
  119. public void Dispose()
  120. {
  121. Dispose(true);
  122. }
  123. protected virtual void Dispose(bool disposing)
  124. {
  125. if (disposing)
  126. {
  127. System.Dispose();
  128. AudioDeviceDriver.Dispose();
  129. FileSystem.Dispose();
  130. Memory.Dispose();
  131. }
  132. }
  133. }
  134. }