aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Core
diff options
context:
space:
mode:
Diffstat (limited to 'Ryujinx.Core')
-rw-r--r--Ryujinx.Core/Hid/Hid.cs186
-rw-r--r--Ryujinx.Core/OsHle/MemoryRegions.cs5
-rw-r--r--Ryujinx.Core/OsHle/Process.cs2
-rw-r--r--Ryujinx.Core/OsHle/Services/Vi/NvFlinger.cs6
-rw-r--r--Ryujinx.Core/OsHle/Svc/SvcSystem.cs2
-rw-r--r--Ryujinx.Core/PerformanceStatistics.cs5
-rw-r--r--Ryujinx.Core/Switch.cs11
7 files changed, 108 insertions, 109 deletions
diff --git a/Ryujinx.Core/Hid/Hid.cs b/Ryujinx.Core/Hid/Hid.cs
index 249747c1..16976889 100644
--- a/Ryujinx.Core/Hid/Hid.cs
+++ b/Ryujinx.Core/Hid/Hid.cs
@@ -1,7 +1,5 @@
-using ChocolArm64.Memory;
-using Ryujinx.Core.OsHle.Handles;
+using Ryujinx.Core.OsHle.Handles;
using System;
-using System.Diagnostics;
namespace Ryujinx.Core.Input
{
@@ -66,11 +64,15 @@ namespace Ryujinx.Core.Input
private long[] ShMemPositions;
- private IntPtr Ram;
+ private long CurrControllerEntry;
+ private long CurrTouchEntry;
+ private long CurrTouchSampleCounter;
- public Hid(IntPtr Ram)
+ private Switch Ns;
+
+ public Hid(Switch Ns)
{
- this.Ram = Ram;
+ this.Ns = Ns;
ShMemLock = new object();
@@ -136,20 +138,20 @@ namespace Ryujinx.Core.Input
HidControllerColorDesc SplitColorDesc = 0;
- WriteInt32(BaseControllerOffset + 0x0, (int)Type);
+ Ns.Memory.WriteInt32(BaseControllerOffset + 0x0, (int)Type);
- WriteInt32(BaseControllerOffset + 0x4, IsHalf ? 1 : 0);
+ Ns.Memory.WriteInt32(BaseControllerOffset + 0x4, IsHalf ? 1 : 0);
- WriteInt32(BaseControllerOffset + 0x8, (int)SingleColorDesc);
- WriteInt32(BaseControllerOffset + 0xc, (int)SingleColorBody);
- WriteInt32(BaseControllerOffset + 0x10, (int)SingleColorButtons);
- WriteInt32(BaseControllerOffset + 0x14, (int)SplitColorDesc);
+ Ns.Memory.WriteInt32(BaseControllerOffset + 0x8, (int)SingleColorDesc);
+ Ns.Memory.WriteInt32(BaseControllerOffset + 0xc, (int)SingleColorBody);
+ Ns.Memory.WriteInt32(BaseControllerOffset + 0x10, (int)SingleColorButtons);
+ Ns.Memory.WriteInt32(BaseControllerOffset + 0x14, (int)SplitColorDesc);
- WriteInt32(BaseControllerOffset + 0x18, (int)LeftColorBody);
- WriteInt32(BaseControllerOffset + 0x1c, (int)LeftColorButtons);
+ Ns.Memory.WriteInt32(BaseControllerOffset + 0x18, (int)LeftColorBody);
+ Ns.Memory.WriteInt32(BaseControllerOffset + 0x1c, (int)LeftColorButtons);
- WriteInt32(BaseControllerOffset + 0x20, (int)RightColorBody);
- WriteInt32(BaseControllerOffset + 0x24, (int)RightColorButtons);
+ Ns.Memory.WriteInt32(BaseControllerOffset + 0x20, (int)RightColorBody);
+ Ns.Memory.WriteInt32(BaseControllerOffset + 0x24, (int)RightColorButtons);
}
public void SetJoyconButton(
@@ -163,45 +165,60 @@ namespace Ryujinx.Core.Input
{
foreach (long Position in ShMemPositions)
{
- long ControllerOffset = Position + HidControllersOffset;
+ WriteJoyconButtons(
+ Position,
+ ControllerId,
+ ControllerLayout,
+ Buttons,
+ LeftStick,
+ RightStick);
+ }
+ }
+ }
- ControllerOffset += (int)ControllerId * HidControllerSize;
+ private void WriteJoyconButtons(
+ long BasePosition,
+ HidControllerId ControllerId,
+ HidControllerLayouts ControllerLayout,
+ HidControllerButtons Buttons,
+ HidJoystickPosition LeftStick,
+ HidJoystickPosition RightStick)
+ {
+ long ControllerOffset = BasePosition + HidControllersOffset;
- ControllerOffset += HidControllerHeaderSize;
+ ControllerOffset += (int)ControllerId * HidControllerSize;
- ControllerOffset += (int)ControllerLayout * HidControllerLayoutsSize;
+ ControllerOffset += HidControllerHeaderSize;
- long LastEntry = ReadInt64(ControllerOffset + 0x10);
+ ControllerOffset += (int)ControllerLayout * HidControllerLayoutsSize;
- long CurrEntry = (LastEntry + 1) % HidEntryCount;
+ CurrControllerEntry = (CurrControllerEntry + 1) % HidEntryCount;
- long Timestamp = Stopwatch.GetTimestamp();
+ long Timestamp = GetTimestamp();
- WriteInt64(ControllerOffset + 0x0, Timestamp);
- WriteInt64(ControllerOffset + 0x8, HidEntryCount);
- WriteInt64(ControllerOffset + 0x10, CurrEntry);
- WriteInt64(ControllerOffset + 0x18, HidEntryCount - 1);
+ Ns.Memory.WriteInt64(ControllerOffset + 0x0, Timestamp);
+ Ns.Memory.WriteInt64(ControllerOffset + 0x8, HidEntryCount);
+ Ns.Memory.WriteInt64(ControllerOffset + 0x10, CurrControllerEntry);
+ Ns.Memory.WriteInt64(ControllerOffset + 0x18, HidEntryCount - 1);
- ControllerOffset += HidControllersLayoutHeaderSize;
+ ControllerOffset += HidControllersLayoutHeaderSize;
- ControllerOffset += CurrEntry * HidControllersInputEntrySize;
+ ControllerOffset += CurrControllerEntry * HidControllersInputEntrySize;
- WriteInt64(ControllerOffset + 0x0, Timestamp);
- WriteInt64(ControllerOffset + 0x8, Timestamp);
+ Ns.Memory.WriteInt64(ControllerOffset + 0x0, Timestamp);
+ Ns.Memory.WriteInt64(ControllerOffset + 0x8, Timestamp);
- WriteInt64(ControllerOffset + 0x10, (uint)Buttons);
+ Ns.Memory.WriteInt64(ControllerOffset + 0x10, (uint)Buttons);
- WriteInt32(ControllerOffset + 0x18, LeftStick.DX);
- WriteInt32(ControllerOffset + 0x1c, LeftStick.DY);
+ Ns.Memory.WriteInt32(ControllerOffset + 0x18, LeftStick.DX);
+ Ns.Memory.WriteInt32(ControllerOffset + 0x1c, LeftStick.DY);
- WriteInt64(ControllerOffset + 0x20, RightStick.DX);
- WriteInt64(ControllerOffset + 0x24, RightStick.DY);
+ Ns.Memory.WriteInt32(ControllerOffset + 0x20, RightStick.DX);
+ Ns.Memory.WriteInt32(ControllerOffset + 0x24, RightStick.DY);
- WriteInt64(ControllerOffset + 0x28,
- (uint)HidControllerConnState.Controller_State_Connected |
- (uint)HidControllerConnState.Controller_State_Wired);
- }
- }
+ Ns.Memory.WriteInt64(ControllerOffset + 0x28,
+ (uint)HidControllerConnState.Controller_State_Connected |
+ (uint)HidControllerConnState.Controller_State_Wired);
}
public void SetTouchPoints(params HidTouchPoint[] Points)
@@ -210,72 +227,57 @@ namespace Ryujinx.Core.Input
{
foreach (long Position in ShMemPositions)
{
- long TouchScreenOffset = Position + HidTouchScreenOffset;
-
- long LastEntry = ReadInt64(TouchScreenOffset + 0x10);
-
- long CurrEntry = (LastEntry + 1) % HidEntryCount;
+ WriteTouchPoints(Position, Points);
+ }
+ }
+ }
- long Timestamp = ReadInt64(TouchScreenOffset) + 1;
+ private void WriteTouchPoints(long BasePosition, params HidTouchPoint[] Points)
+ {
+ long TouchScreenOffset = BasePosition + HidTouchScreenOffset;
- WriteInt64(TouchScreenOffset + 0x0, Timestamp);
- WriteInt64(TouchScreenOffset + 0x8, HidEntryCount);
- WriteInt64(TouchScreenOffset + 0x10, CurrEntry);
- WriteInt64(TouchScreenOffset + 0x18, HidEntryCount - 1);
- WriteInt64(TouchScreenOffset + 0x20, Timestamp);
+ long Timestamp = GetTimestamp();
- long TouchEntryOffset = TouchScreenOffset + HidTouchHeaderSize;
+ CurrTouchEntry = (CurrTouchEntry + 1) % HidEntryCount;
- long LastEntryOffset = TouchEntryOffset + LastEntry * HidTouchEntrySize;
+ Ns.Memory.WriteInt64(TouchScreenOffset + 0x0, Timestamp);
+ Ns.Memory.WriteInt64(TouchScreenOffset + 0x8, HidEntryCount);
+ Ns.Memory.WriteInt64(TouchScreenOffset + 0x10, CurrTouchEntry);
+ Ns.Memory.WriteInt64(TouchScreenOffset + 0x18, HidEntryCount - 1);
+ Ns.Memory.WriteInt64(TouchScreenOffset + 0x20, Timestamp);
- TouchEntryOffset += CurrEntry * HidTouchEntrySize;
+ long TouchEntryOffset = TouchScreenOffset + HidTouchHeaderSize;
- WriteInt64(TouchEntryOffset + 0x0, Timestamp);
- WriteInt64(TouchEntryOffset + 0x8, Points.Length);
+ TouchEntryOffset += CurrTouchEntry * HidTouchEntrySize;
- TouchEntryOffset += HidTouchEntryHeaderSize;
+ Ns.Memory.WriteInt64(TouchEntryOffset + 0x0, CurrTouchSampleCounter++);
+ Ns.Memory.WriteInt64(TouchEntryOffset + 0x8, Points.Length);
- const int Padding = 0;
+ TouchEntryOffset += HidTouchEntryHeaderSize;
- int Index = 0;
+ const int Padding = 0;
- foreach (HidTouchPoint Point in Points)
- {
- WriteInt64(TouchEntryOffset + 0x0, Timestamp);
- WriteInt32(TouchEntryOffset + 0x8, Padding);
- WriteInt32(TouchEntryOffset + 0xc, Index++);
- WriteInt32(TouchEntryOffset + 0x10, Point.X);
- WriteInt32(TouchEntryOffset + 0x14, Point.Y);
- WriteInt32(TouchEntryOffset + 0x18, Point.DiameterX);
- WriteInt32(TouchEntryOffset + 0x1c, Point.DiameterY);
- WriteInt32(TouchEntryOffset + 0x20, Point.Angle);
- WriteInt32(TouchEntryOffset + 0x24, Padding);
+ int Index = 0;
- TouchEntryOffset += HidTouchEntryTouchSize;
- }
- }
+ foreach (HidTouchPoint Point in Points)
+ {
+ Ns.Memory.WriteInt64(TouchEntryOffset + 0x0, Timestamp);
+ Ns.Memory.WriteInt32(TouchEntryOffset + 0x8, Padding);
+ Ns.Memory.WriteInt32(TouchEntryOffset + 0xc, Index++);
+ Ns.Memory.WriteInt32(TouchEntryOffset + 0x10, Point.X);
+ Ns.Memory.WriteInt32(TouchEntryOffset + 0x14, Point.Y);
+ Ns.Memory.WriteInt32(TouchEntryOffset + 0x18, Point.DiameterX);
+ Ns.Memory.WriteInt32(TouchEntryOffset + 0x1c, Point.DiameterY);
+ Ns.Memory.WriteInt32(TouchEntryOffset + 0x20, Point.Angle);
+ Ns.Memory.WriteInt32(TouchEntryOffset + 0x24, Padding);
+
+ TouchEntryOffset += HidTouchEntryTouchSize;
}
}
- private unsafe long ReadInt64(long Position)
- {
- if ((ulong)Position + 8 > AMemoryMgr.AddrSize) return 0;
-
- return *((long*)((byte*)Ram + Position));
- }
-
- private unsafe void WriteInt32(long Position, int Value)
+ private long GetTimestamp()
{
- if ((ulong)Position + 4 > AMemoryMgr.AddrSize) return;
-
- *((int*)((byte*)Ram + Position)) = Value;
- }
-
- private unsafe void WriteInt64(long Position, long Value)
- {
- if ((ulong)Position + 8 > AMemoryMgr.AddrSize) return;
-
- *((long*)((byte*)Ram + Position)) = Value;
+ return Environment.TickCount * 19_200;
}
}
} \ No newline at end of file
diff --git a/Ryujinx.Core/OsHle/MemoryRegions.cs b/Ryujinx.Core/OsHle/MemoryRegions.cs
index 7f5ab0ed..75b97b1f 100644
--- a/Ryujinx.Core/OsHle/MemoryRegions.cs
+++ b/Ryujinx.Core/OsHle/MemoryRegions.cs
@@ -9,6 +9,9 @@ namespace Ryujinx.Core.OsHle
public const long MapRegionAddress = 0x10000000;
public const long MapRegionSize = 0x20000000;
+ public const long HeapRegionAddress = MapRegionAddress + MapRegionSize;
+ public const long HeapRegionSize = TlsPagesAddress - HeapRegionAddress;
+
public const long MainStackSize = 0x100000;
public const long MainStackAddress = AMemoryMgr.AddrSize - MainStackSize;
@@ -17,8 +20,6 @@ namespace Ryujinx.Core.OsHle
public const long TlsPagesAddress = MainStackAddress - TlsPagesSize;
- public const long HeapRegionAddress = MapRegionAddress + MapRegionSize;
-
public const long TotalMemoryUsed = HeapRegionAddress + TlsPagesSize + MainStackSize;
public const long TotalMemoryAvailable = AMemoryMgr.RamSize - AddrSpaceStart;
diff --git a/Ryujinx.Core/OsHle/Process.cs b/Ryujinx.Core/OsHle/Process.cs
index f549b027..a919f1af 100644
--- a/Ryujinx.Core/OsHle/Process.cs
+++ b/Ryujinx.Core/OsHle/Process.cs
@@ -45,7 +45,7 @@ namespace Ryujinx.Core.OsHle
this.Ns = Ns;
this.ProcessId = ProcessId;
- Memory = new AMemory(Ns.Ram);
+ Memory = Ns.Memory;
Scheduler = new KProcessScheduler();
diff --git a/Ryujinx.Core/OsHle/Services/Vi/NvFlinger.cs b/Ryujinx.Core/OsHle/Services/Vi/NvFlinger.cs
index 740a35f9..1d394fb4 100644
--- a/Ryujinx.Core/OsHle/Services/Vi/NvFlinger.cs
+++ b/Ryujinx.Core/OsHle/Services/Vi/NvFlinger.cs
@@ -264,11 +264,11 @@ namespace Ryujinx.Core.OsHle.IpcServices.Android
int FbWidth = BufferQueue[Slot].Data.Width;
int FbHeight = BufferQueue[Slot].Data.Height;
- int FbSize = FbWidth * FbHeight * 4;
+ long FbSize = (uint)FbWidth * FbHeight * 4;
HNvMap NvMap = GetNvMap(Context, Slot);
- if (FbSize < 0 || NvMap.Address < 0 || NvMap.Address + FbSize > AMemoryMgr.AddrSize)
+ if ((ulong)(NvMap.Address + FbSize) > AMemoryMgr.AddrSize)
{
Logging.Error($"Frame buffer address {NvMap.Address:x16} is invalid!");
@@ -330,7 +330,7 @@ namespace Ryujinx.Core.OsHle.IpcServices.Android
Rotate = -MathF.PI * 0.5f;
}
- byte* Fb = (byte*)Context.Ns.Ram + NvMap.Address;
+ byte* Fb = (byte*)Context.Ns.Memory.Ram + NvMap.Address;
Context.Ns.Gpu.Renderer.QueueAction(delegate()
{
diff --git a/Ryujinx.Core/OsHle/Svc/SvcSystem.cs b/Ryujinx.Core/OsHle/Svc/SvcSystem.cs
index 8a0a3917..a276fe3c 100644
--- a/Ryujinx.Core/OsHle/Svc/SvcSystem.cs
+++ b/Ryujinx.Core/OsHle/Svc/SvcSystem.cs
@@ -197,7 +197,7 @@ namespace Ryujinx.Core.OsHle.Svc
break;
case 5:
- ThreadState.X1 = CurrentHeapSize;
+ ThreadState.X1 = MemoryRegions.HeapRegionSize;
break;
case 6:
diff --git a/Ryujinx.Core/PerformanceStatistics.cs b/Ryujinx.Core/PerformanceStatistics.cs
index 3740daa5..e5d930f9 100644
--- a/Ryujinx.Core/PerformanceStatistics.cs
+++ b/Ryujinx.Core/PerformanceStatistics.cs
@@ -1,7 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Text;
+using System.Diagnostics;
using System.Timers;
namespace Ryujinx.Core
diff --git a/Ryujinx.Core/Switch.cs b/Ryujinx.Core/Switch.cs
index 1acd87f0..dff7802b 100644
--- a/Ryujinx.Core/Switch.cs
+++ b/Ryujinx.Core/Switch.cs
@@ -5,13 +5,12 @@ using Ryujinx.Core.Settings;
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 AMemory Memory { get; private set; }
internal NsGpu Gpu { get; private set; }
internal Horizon Os { get; private set; }
@@ -25,13 +24,13 @@ namespace Ryujinx.Core
public Switch(IGalRenderer Renderer)
{
- Ram = Marshal.AllocHGlobal((IntPtr)AMemoryMgr.RamSize);
+ Memory = new AMemory();
Gpu = new NsGpu(Renderer);
VFs = new VirtualFs();
- Hid = new Hid(Ram);
+ Hid = new Hid(this);
Statistics = new PerformanceStatistics();
@@ -72,10 +71,10 @@ namespace Ryujinx.Core
{
if (disposing)
{
+ Memory.Dispose();
+
VFs.Dispose();
}
-
- Marshal.FreeHGlobal(Ram);
}
}
} \ No newline at end of file