summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorGravatar Subv2016-04-19 12:13:00 -0500
committerGravatar Subv2016-05-12 20:01:54 -0500
commitabf8dcd700ce6e8af35aff9b8fa568dfe6acfecb (patch)
treefaba126b2f72850d65ba1102de49d6e6a07e37d4 /src/core
parentKernel/SharedMemory: Log an error when Map fails. (diff)
downloadyuzu-abf8dcd700ce6e8af35aff9b8fa568dfe6acfecb.tar.gz
yuzu-abf8dcd700ce6e8af35aff9b8fa568dfe6acfecb.tar.xz
yuzu-abf8dcd700ce6e8af35aff9b8fa568dfe6acfecb.zip
APT: Move the shared font loading and relocation functions to their own subdirectory services/apt/bcfnt.
Diffstat (limited to 'src/core')
-rw-r--r--src/core/CMakeLists.txt2
-rw-r--r--src/core/hle/service/apt/apt.cpp73
-rw-r--r--src/core/hle/service/apt/bcfnt/bcfnt.cpp71
-rw-r--r--src/core/hle/service/apt/bcfnt/bcfnt.h87
4 files changed, 167 insertions, 66 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt
index a8d891689..f6a7566bf 100644
--- a/src/core/CMakeLists.txt
+++ b/src/core/CMakeLists.txt
@@ -52,6 +52,7 @@ set(SRCS
52 hle/service/apt/apt_a.cpp 52 hle/service/apt/apt_a.cpp
53 hle/service/apt/apt_s.cpp 53 hle/service/apt/apt_s.cpp
54 hle/service/apt/apt_u.cpp 54 hle/service/apt/apt_u.cpp
55 hle/service/apt/bcfnt/bcfnt.cpp
55 hle/service/boss/boss.cpp 56 hle/service/boss/boss.cpp
56 hle/service/boss/boss_p.cpp 57 hle/service/boss/boss_p.cpp
57 hle/service/boss/boss_u.cpp 58 hle/service/boss/boss_u.cpp
@@ -185,6 +186,7 @@ set(HEADERS
185 hle/service/apt/apt_a.h 186 hle/service/apt/apt_a.h
186 hle/service/apt/apt_s.h 187 hle/service/apt/apt_s.h
187 hle/service/apt/apt_u.h 188 hle/service/apt/apt_u.h
189 hle/service/apt/bcfnt/bcfnt.h
188 hle/service/boss/boss.h 190 hle/service/boss/boss.h
189 hle/service/boss/boss_p.h 191 hle/service/boss/boss_p.h
190 hle/service/boss/boss_u.h 192 hle/service/boss/boss_u.h
diff --git a/src/core/hle/service/apt/apt.cpp b/src/core/hle/service/apt/apt.cpp
index ad6ba1fac..73fce6079 100644
--- a/src/core/hle/service/apt/apt.cpp
+++ b/src/core/hle/service/apt/apt.cpp
@@ -12,6 +12,7 @@
12#include "core/hle/service/apt/apt_a.h" 12#include "core/hle/service/apt/apt_a.h"
13#include "core/hle/service/apt/apt_s.h" 13#include "core/hle/service/apt/apt_s.h"
14#include "core/hle/service/apt/apt_u.h" 14#include "core/hle/service/apt/apt_u.h"
15#include "core/hle/service/apt/bcfnt/bcfnt.h"
15#include "core/hle/service/fs/archive.h" 16#include "core/hle/service/fs/archive.h"
16 17
17#include "core/hle/kernel/event.h" 18#include "core/hle/kernel/event.h"
@@ -22,70 +23,6 @@
22namespace Service { 23namespace Service {
23namespace APT { 24namespace APT {
24 25
25/// BCFNT Shared Font file structures
26namespace BCFNT {
27struct CFNT {
28 u8 magic[4];
29 u16_le endianness;
30 u16_le header_size;
31 u32_le version;
32 u32_le file_size;
33 u32_le num_blocks;
34};
35
36struct FINF {
37 u8 magic[4];
38 u32_le section_size;
39 u8 font_type;
40 u8 line_feed;
41 u16_le alter_char_index;
42 u8 default_width[3];
43 u8 encoding;
44 u32_le tglp_offset;
45 u32_le cwdh_offset;
46 u32_le cmap_offset;
47 u8 height;
48 u8 width;
49 u8 ascent;
50 u8 reserved;
51};
52
53struct TGLP {
54 u8 magic[4];
55 u32_le section_size;
56 u8 cell_width;
57 u8 cell_height;
58 u8 baseline_position;
59 u8 max_character_width;
60 u32_le sheet_size;
61 u16_le num_sheets;
62 u16_le sheet_image_format;
63 u16_le num_columns;
64 u16_le num_rows;
65 u16_le sheet_width;
66 u16_le sheet_height;
67 u32_le sheet_data_offset;
68};
69
70struct CMAP {
71 u8 magic[4];
72 u32_le section_size;
73 u16_le code_begin;
74 u16_le code_end;
75 u16_le mapping_method;
76 u16_le reserved;
77 u32_le next_cmap_offset;
78};
79
80struct CWDH {
81 u8 magic[4];
82 u32_le section_size;
83 u16_le start_index;
84 u16_le end_index;
85 u32_le next_cwdh_offset;
86};
87}
88
89/// Handle to shared memory region designated to for shared system font 26/// Handle to shared memory region designated to for shared system font
90static Kernel::SharedPtr<Kernel::SharedMemory> shared_font_mem; 27static Kernel::SharedPtr<Kernel::SharedMemory> shared_font_mem;
91static bool shared_font_relocated = false; 28static bool shared_font_relocated = false;
@@ -133,9 +70,13 @@ void GetSharedFont(Service::Interface* self) {
133 VAddr target_address = Memory::PhysicalToVirtualAddress(shared_font_mem->linear_heap_phys_address); 70 VAddr target_address = Memory::PhysicalToVirtualAddress(shared_font_mem->linear_heap_phys_address);
134 // The shared font dumped by 3dsutils (https://github.com/citra-emu/3dsutils) uses this address as base, 71 // The shared font dumped by 3dsutils (https://github.com/citra-emu/3dsutils) uses this address as base,
135 // so we relocate it from there to our real address. 72 // so we relocate it from there to our real address.
73 // TODO(Subv): This address is wrong if the shared font is dumped from a n3DS,
74 // we need a way to automatically calculate the original address of the font from the file.
136 static const VAddr SHARED_FONT_VADDR = 0x18000000; 75 static const VAddr SHARED_FONT_VADDR = 0x18000000;
137 if (!shared_font_relocated) 76 if (!shared_font_relocated) {
138 RelocateSharedFont(SHARED_FONT_VADDR, target_address); 77 BCFNT::RelocateSharedFont(shared_font_mem, SHARED_FONT_VADDR, target_address);
78 shared_font_relocated = true;
79 }
139 cmd_buff[0] = IPC::MakeHeader(0x44, 2, 2); 80 cmd_buff[0] = IPC::MakeHeader(0x44, 2, 2);
140 cmd_buff[1] = RESULT_SUCCESS.raw; // No error 81 cmd_buff[1] = RESULT_SUCCESS.raw; // No error
141 // Since the SharedMemory interface doesn't provide the address at which the memory was allocated, 82 // Since the SharedMemory interface doesn't provide the address at which the memory was allocated,
diff --git a/src/core/hle/service/apt/bcfnt/bcfnt.cpp b/src/core/hle/service/apt/bcfnt/bcfnt.cpp
new file mode 100644
index 000000000..b0d39d4a5
--- /dev/null
+++ b/src/core/hle/service/apt/bcfnt/bcfnt.cpp
@@ -0,0 +1,71 @@
1// Copyright 2016 Citra Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#include "core/hle/service/apt/bcfnt/bcfnt.h"
6#include "core/hle/service/service.h"
7
8namespace Service {
9namespace APT {
10namespace BCFNT {
11
12void RelocateSharedFont(Kernel::SharedPtr<Kernel::SharedMemory> shared_font, VAddr previous_address, VAddr new_address) {
13 static const u32 SharedFontStartOffset = 0x80;
14 u8* data = shared_font->GetPointer(SharedFontStartOffset);
15
16 CFNT cfnt;
17 memcpy(&cfnt, data, sizeof(cfnt));
18
19 // Advance past the header
20 data = shared_font->GetPointer(SharedFontStartOffset + cfnt.header_size);
21
22 for (unsigned block = 0; block < cfnt.num_blocks; ++block) {
23
24 u32 section_size = 0;
25 if (memcmp(data, "FINF", 4) == 0) {
26 BCFNT::FINF finf;
27 memcpy(&finf, data, sizeof(finf));
28 section_size = finf.section_size;
29
30 // Relocate the offsets in the FINF section
31 finf.cmap_offset += new_address - previous_address;
32 finf.cwdh_offset += new_address - previous_address;
33 finf.tglp_offset += new_address - previous_address;
34
35 memcpy(data, &finf, sizeof(finf));
36 } else if (memcmp(data, "CMAP", 4) == 0) {
37 BCFNT::CMAP cmap;
38 memcpy(&cmap, data, sizeof(cmap));
39 section_size = cmap.section_size;
40
41 // Relocate the offsets in the CMAP section
42 cmap.next_cmap_offset += new_address - previous_address;
43
44 memcpy(data, &cmap, sizeof(cmap));
45 } else if (memcmp(data, "CWDH", 4) == 0) {
46 BCFNT::CWDH cwdh;
47 memcpy(&cwdh, data, sizeof(cwdh));
48 section_size = cwdh.section_size;
49
50 // Relocate the offsets in the CWDH section
51 cwdh.next_cwdh_offset += new_address - previous_address;
52
53 memcpy(data, &cwdh, sizeof(cwdh));
54 } else if (memcmp(data, "TGLP", 4) == 0) {
55 BCFNT::TGLP tglp;
56 memcpy(&tglp, data, sizeof(tglp));
57 section_size = tglp.section_size;
58
59 // Relocate the offsets in the TGLP section
60 tglp.sheet_data_offset += new_address - previous_address;
61
62 memcpy(data, &tglp, sizeof(tglp));
63 }
64
65 data += section_size;
66 }
67}
68
69} // namespace BCFNT
70} // namespace APT
71} // namespace Service \ No newline at end of file
diff --git a/src/core/hle/service/apt/bcfnt/bcfnt.h b/src/core/hle/service/apt/bcfnt/bcfnt.h
new file mode 100644
index 000000000..388c6bea0
--- /dev/null
+++ b/src/core/hle/service/apt/bcfnt/bcfnt.h
@@ -0,0 +1,87 @@
1// Copyright 2016 Citra Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include "common/swap.h"
8
9#include "core/hle/kernel/shared_memory.h"
10#include "core/hle/service/service.h"
11
12namespace Service {
13namespace APT {
14namespace BCFNT { ///< BCFNT Shared Font file structures
15
16struct CFNT {
17 u8 magic[4];
18 u16_le endianness;
19 u16_le header_size;
20 u32_le version;
21 u32_le file_size;
22 u32_le num_blocks;
23};
24
25struct FINF {
26 u8 magic[4];
27 u32_le section_size;
28 u8 font_type;
29 u8 line_feed;
30 u16_le alter_char_index;
31 u8 default_width[3];
32 u8 encoding;
33 u32_le tglp_offset;
34 u32_le cwdh_offset;
35 u32_le cmap_offset;
36 u8 height;
37 u8 width;
38 u8 ascent;
39 u8 reserved;
40};
41
42struct TGLP {
43 u8 magic[4];
44 u32_le section_size;
45 u8 cell_width;
46 u8 cell_height;
47 u8 baseline_position;
48 u8 max_character_width;
49 u32_le sheet_size;
50 u16_le num_sheets;
51 u16_le sheet_image_format;
52 u16_le num_columns;
53 u16_le num_rows;
54 u16_le sheet_width;
55 u16_le sheet_height;
56 u32_le sheet_data_offset;
57};
58
59struct CMAP {
60 u8 magic[4];
61 u32_le section_size;
62 u16_le code_begin;
63 u16_le code_end;
64 u16_le mapping_method;
65 u16_le reserved;
66 u32_le next_cmap_offset;
67};
68
69struct CWDH {
70 u8 magic[4];
71 u32_le section_size;
72 u16_le start_index;
73 u16_le end_index;
74 u32_le next_cwdh_offset;
75};
76
77/**
78 * Relocates the internal addresses of the BCFNT Shared Font to the new base.
79 * @param shared_font SharedMemory object that contains the Shared Font
80 * @param previous_address Previous address at which the offsets in the structure were based.
81 * @param new_address New base for the offsets in the structure.
82 */
83void RelocateSharedFont(Kernel::SharedPtr<Kernel::SharedMemory> shared_font, VAddr previous_address, VAddr new_address);
84
85} // namespace BCFNT
86} // namespace APT
87} // namespace Service