aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Core/Switch.cs
blob: 2b6a9045735f1c3a9321414714bc563248603690 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using ChocolArm64.Memory;
using Ryujinx.Core.OsHle;
using Ryujinx.Graphics.Gal;
using Ryujinx.Graphics.Gpu;
using System;
using System.Runtime.InteropServices;

namespace Ryujinx.Core
{
    public class Switch : IDisposable
    {
        public IntPtr Ram {get; private set; }

        internal NsGpu     Gpu { get; private set; }
        internal Horizon   Os  { get; private set; }
        internal VirtualFs VFs { get; private set; }
        internal Hid       Hid { get; private set; }

        public event EventHandler Finish;

        public Switch(IGalRenderer Renderer)
        {
            Ram = Marshal.AllocHGlobal((IntPtr)AMemoryMgr.RamSize);

            Gpu = new NsGpu(Renderer);
            Os  = new Horizon(this);
            VFs = new VirtualFs();
            Hid = new Hid(this);
        }

        public void FinalizeAllProcesses()
        {
            Os.FinalizeAllProcesses();
        }

        public void LoadCart(string ExeFsDir, string RomFsFile = null)
        {
            Os.LoadCart(ExeFsDir, RomFsFile);
        }

        public void LoadProgram(string FileName)
        {
            Os.LoadProgram(FileName);
        }

        public void SendControllerButtons(HidControllerID ControllerId,
                                          HidControllerLayouts Layout,
                                          HidControllerKeys Buttons,
                                          JoystickPosition LeftJoystick,
                                          JoystickPosition RightJoystick)
        {
            Hid.SendControllerButtons(ControllerId, Layout, Buttons, LeftJoystick, RightJoystick);
        }

        internal virtual void OnFinish(EventArgs e)
        {
            Finish?.Invoke(this, e);
        }

        public void Dispose()
        {
            Dispose(true);
        }

        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                VFs.Dispose();
            }

            Marshal.FreeHGlobal(Ram);
        }
    }
}