aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.HLE/HOS/Font
diff options
context:
space:
mode:
authorgdkchan <gab.dark.100@gmail.com>2018-08-16 20:47:36 -0300
committerGitHub <noreply@github.com>2018-08-16 20:47:36 -0300
commit521751795a1c97c0d97f6f8904a3be69b13d3a9d (patch)
tree942a05899c40e2de6d92a38b93a494bd96ee64b8 /Ryujinx.HLE/HOS/Font
parent182d716867ae477c2b15a5332430dc2641fa1cc3 (diff)
Code style fixes and nits on the HLE project (#355)
* Some style fixes and nits on ITimeZoneService * Remove some unneeded usings * Remove the Ryujinx.HLE.OsHle.Handles namespace * Remove hbmenu automatic load on process exit * Rename Ns to Device, rename Os to System, rename SystemState to State * Move Exceptions and Utilities out of OsHle * Rename OsHle to HOS * Rename OsHle folder to HOS * IManagerDisplayService and ISystemDisplayService style fixes * BsdError shouldn't be public * Add a empty new line before using static * Remove unused file * Some style fixes on NPDM * Exit gracefully when the application is closed * Code style fixes on IGeneralService * Add 0x prefix on values printed as hex * Small improvements on finalization code * Move ProcessId and ThreadId out of AThreadState * Rename VFs to FileSystem * FsAccessHeader shouldn't be public. Also fix file names casing * More case changes on NPDM * Remove unused files * Move using to the correct place on NPDM * Use properties on KernelAccessControlMmio * Address PR feedback
Diffstat (limited to 'Ryujinx.HLE/HOS/Font')
-rw-r--r--Ryujinx.HLE/HOS/Font/SharedFontManager.cs122
-rw-r--r--Ryujinx.HLE/HOS/Font/SharedFontType.cs13
2 files changed, 135 insertions, 0 deletions
diff --git a/Ryujinx.HLE/HOS/Font/SharedFontManager.cs b/Ryujinx.HLE/HOS/Font/SharedFontManager.cs
new file mode 100644
index 00000000..0be5e896
--- /dev/null
+++ b/Ryujinx.HLE/HOS/Font/SharedFontManager.cs
@@ -0,0 +1,122 @@
+using Ryujinx.HLE.Memory;
+using Ryujinx.HLE.Resource;
+using Ryujinx.HLE.Utilities;
+using System.Collections.Generic;
+using System.IO;
+
+namespace Ryujinx.HLE.HOS.Font
+{
+ class SharedFontManager
+ {
+ private DeviceMemory Memory;
+
+ private long PhysicalAddress;
+
+ private string FontsPath;
+
+ private struct FontInfo
+ {
+ public int Offset;
+ public int Size;
+
+ public FontInfo(int Offset, int Size)
+ {
+ this.Offset = Offset;
+ this.Size = Size;
+ }
+ }
+
+ private Dictionary<SharedFontType, FontInfo> FontData;
+
+ public SharedFontManager(Switch Device, long PhysicalAddress)
+ {
+ this.PhysicalAddress = PhysicalAddress;
+
+ Memory = Device.Memory;
+
+ FontsPath = Path.Combine(Device.FileSystem.GetSystemPath(), "fonts");
+ }
+
+ public void EnsureInitialized()
+ {
+ if (FontData == null)
+ {
+ Memory.FillWithZeros(PhysicalAddress, Horizon.FontSize);
+
+ uint FontOffset = 0;
+
+ FontInfo CreateFont(string Name)
+ {
+ string FontFilePath = Path.Combine(FontsPath, Name + ".ttf");
+
+ if (File.Exists(FontFilePath))
+ {
+ byte[] Data = File.ReadAllBytes(FontFilePath);
+
+ FontInfo Info = new FontInfo((int)FontOffset, Data.Length);
+
+ WriteMagicAndSize(PhysicalAddress + FontOffset, Data.Length);
+
+ FontOffset += 8;
+
+ uint Start = FontOffset;
+
+ for (; FontOffset - Start < Data.Length; FontOffset++)
+ {
+ Memory.WriteByte(PhysicalAddress + FontOffset, Data[FontOffset - Start]);
+ }
+
+ return Info;
+ }
+ else
+ {
+ throw new InvalidSystemResourceException($"Font \"{Name}.ttf\" not found. Please provide it in \"{FontsPath}\".");
+ }
+ }
+
+ FontData = new Dictionary<SharedFontType, FontInfo>()
+ {
+ { SharedFontType.JapanUsEurope, CreateFont("FontStandard") },
+ { SharedFontType.SimplifiedChinese, CreateFont("FontChineseSimplified") },
+ { SharedFontType.SimplifiedChineseEx, CreateFont("FontExtendedChineseSimplified") },
+ { SharedFontType.TraditionalChinese, CreateFont("FontChineseTraditional") },
+ { SharedFontType.Korean, CreateFont("FontKorean") },
+ { SharedFontType.NintendoEx, CreateFont("FontNintendoExtended") }
+ };
+
+ if (FontOffset > Horizon.FontSize)
+ {
+ throw new InvalidSystemResourceException(
+ $"The sum of all fonts size exceed the shared memory size. " +
+ $"Please make sure that the fonts don't exceed {Horizon.FontSize} bytes in total. " +
+ $"(actual size: {FontOffset} bytes).");
+ }
+ }
+ }
+
+ private void WriteMagicAndSize(long Position, int Size)
+ {
+ const int DecMagic = 0x18029a7f;
+ const int Key = 0x49621806;
+
+ int EncryptedSize = EndianSwap.Swap32(Size ^ Key);
+
+ Memory.WriteInt32(Position + 0, DecMagic);
+ Memory.WriteInt32(Position + 4, EncryptedSize);
+ }
+
+ public int GetFontSize(SharedFontType FontType)
+ {
+ EnsureInitialized();
+
+ return FontData[FontType].Size;
+ }
+
+ public int GetSharedMemoryAddressOffset(SharedFontType FontType)
+ {
+ EnsureInitialized();
+
+ return FontData[FontType].Offset + 8;
+ }
+ }
+}
diff --git a/Ryujinx.HLE/HOS/Font/SharedFontType.cs b/Ryujinx.HLE/HOS/Font/SharedFontType.cs
new file mode 100644
index 00000000..53dca626
--- /dev/null
+++ b/Ryujinx.HLE/HOS/Font/SharedFontType.cs
@@ -0,0 +1,13 @@
+namespace Ryujinx.HLE.HOS.Font
+{
+ public enum SharedFontType
+ {
+ JapanUsEurope = 0,
+ SimplifiedChinese = 1,
+ SimplifiedChineseEx = 2,
+ TraditionalChinese = 3,
+ Korean = 4,
+ NintendoEx = 5,
+ Count
+ }
+} \ No newline at end of file