Switch.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. using Ryujinx.Audio;
  2. using Ryujinx.Graphics.Gal;
  3. using Ryujinx.HLE.Font;
  4. using Ryujinx.HLE.Gpu;
  5. using Ryujinx.HLE.Input;
  6. using Ryujinx.HLE.Logging;
  7. using Ryujinx.HLE.OsHle;
  8. using Ryujinx.HLE.Settings;
  9. using System;
  10. namespace Ryujinx.HLE
  11. {
  12. public class Switch : IDisposable
  13. {
  14. internal IAalOutput AudioOut { get; private set; }
  15. public Logger Log { get; private set; }
  16. internal NvGpu Gpu { get; private set; }
  17. internal VirtualFileSystem VFs { get; private set; }
  18. public Horizon Os { get; private set; }
  19. public SystemSettings Settings { get; private set; }
  20. public PerformanceStatistics Statistics { get; private set; }
  21. public Hid Hid { get; private set; }
  22. public SharedFontManager Font { get; private set; }
  23. public event EventHandler Finish;
  24. public Switch(IGalRenderer Renderer, IAalOutput AudioOut)
  25. {
  26. if (Renderer == null)
  27. {
  28. throw new ArgumentNullException(nameof(Renderer));
  29. }
  30. if (AudioOut == null)
  31. {
  32. throw new ArgumentNullException(nameof(AudioOut));
  33. }
  34. this.AudioOut = AudioOut;
  35. Log = new Logger();
  36. Gpu = new NvGpu(Renderer);
  37. VFs = new VirtualFileSystem();
  38. Os = new Horizon(this);
  39. Settings = new SystemSettings();
  40. Statistics = new PerformanceStatistics();
  41. Hid = new Hid(Log);
  42. Font = new SharedFontManager(Log, VFs.GetSystemPath());
  43. Os.HidSharedMem.MemoryMapped += Hid.ShMemMap;
  44. Os.HidSharedMem.MemoryUnmapped += Hid.ShMemUnmap;
  45. Os.FontSharedMem.MemoryMapped += Font.ShMemMap;
  46. Os.FontSharedMem.MemoryUnmapped += Font.ShMemUnmap;
  47. Settings.User = new Profile()
  48. {
  49. Username = "Ryujinx",
  50. UserId = "000123456789abcdef09876543210000"
  51. };
  52. }
  53. public void LoadCart(string ExeFsDir, string RomFsFile = null)
  54. {
  55. Os.LoadCart(ExeFsDir, RomFsFile);
  56. }
  57. public void LoadProgram(string FileName)
  58. {
  59. Os.LoadProgram(FileName);
  60. }
  61. public bool WaitFifo()
  62. {
  63. return Gpu.Fifo.Event.WaitOne(8);
  64. }
  65. public void ProcessFrame()
  66. {
  67. Gpu.Fifo.DispatchCalls();
  68. }
  69. public virtual void OnFinish(EventArgs e)
  70. {
  71. Os.Dispose();
  72. Finish?.Invoke(this, e);
  73. }
  74. public void Dispose()
  75. {
  76. Dispose(true);
  77. }
  78. protected virtual void Dispose(bool Disposing)
  79. {
  80. if (Disposing)
  81. {
  82. Os.Dispose();
  83. VFs.Dispose();
  84. }
  85. }
  86. }
  87. }