Switch.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. }
  48. public void LoadCart(string ExeFsDir, string RomFsFile = null)
  49. {
  50. Os.LoadCart(ExeFsDir, RomFsFile);
  51. }
  52. public void LoadProgram(string FileName)
  53. {
  54. Os.LoadProgram(FileName);
  55. }
  56. public bool WaitFifo()
  57. {
  58. return Gpu.Fifo.Event.WaitOne(8);
  59. }
  60. public void ProcessFrame()
  61. {
  62. Gpu.Fifo.DispatchCalls();
  63. }
  64. public virtual void OnFinish(EventArgs e)
  65. {
  66. Os.Dispose();
  67. Finish?.Invoke(this, e);
  68. }
  69. public void Dispose()
  70. {
  71. Dispose(true);
  72. }
  73. protected virtual void Dispose(bool Disposing)
  74. {
  75. if (Disposing)
  76. {
  77. Os.Dispose();
  78. VFs.Dispose();
  79. }
  80. }
  81. }
  82. }