summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/file_sys/archive.h16
-rw-r--r--src/core/file_sys/archive_romfs.cpp10
-rw-r--r--src/core/file_sys/archive_romfs.h16
-rw-r--r--src/core/file_sys/archive_sdmc.cpp8
-rw-r--r--src/core/file_sys/archive_sdmc.h16
-rw-r--r--src/core/hle/kernel/archive.cpp79
-rw-r--r--src/core/hle/kernel/archive.h28
-rw-r--r--src/core/hle/kernel/kernel.cpp13
-rw-r--r--src/core/hle/kernel/kernel.h4
-rw-r--r--src/core/hle/service/dsp_dsp.cpp69
-rw-r--r--src/core/hle/service/fs_user.cpp94
-rw-r--r--src/core/hle/service/hid_user.cpp4
-rw-r--r--src/core/hle/service/hid_user.h4
-rw-r--r--src/core/hle/service/ptm_u.cpp75
-rw-r--r--src/core/mem_map.h6
15 files changed, 360 insertions, 82 deletions
diff --git a/src/core/file_sys/archive.h b/src/core/file_sys/archive.h
index c2426a153..f3cb11133 100644
--- a/src/core/file_sys/archive.h
+++ b/src/core/file_sys/archive.h
@@ -194,6 +194,14 @@ public:
194 virtual bool DeleteFile(const FileSys::Path& path) const = 0; 194 virtual bool DeleteFile(const FileSys::Path& path) const = 0;
195 195
196 /** 196 /**
197 * Rename a File specified by its path
198 * @param src_path Source path relative to the archive
199 * @param dest_path Destination path relative to the archive
200 * @return Whether rename succeeded
201 */
202 virtual bool RenameFile(const FileSys::Path& src_path, const FileSys::Path& dest_path) const = 0;
203
204 /**
197 * Delete a directory specified by its path 205 * Delete a directory specified by its path
198 * @param path Path relative to the archive 206 * @param path Path relative to the archive
199 * @return Whether the directory could be deleted 207 * @return Whether the directory could be deleted
@@ -208,6 +216,14 @@ public:
208 virtual bool CreateDirectory(const Path& path) const = 0; 216 virtual bool CreateDirectory(const Path& path) const = 0;
209 217
210 /** 218 /**
219 * Rename a Directory specified by its path
220 * @param src_path Source path relative to the archive
221 * @param dest_path Destination path relative to the archive
222 * @return Whether rename succeeded
223 */
224 virtual bool RenameDirectory(const FileSys::Path& src_path, const FileSys::Path& dest_path) const = 0;
225
226 /**
211 * Open a directory specified by its path 227 * Open a directory specified by its path
212 * @param path Path relative to the archive 228 * @param path Path relative to the archive
213 * @return Opened directory, or nullptr 229 * @return Opened directory, or nullptr
diff --git a/src/core/file_sys/archive_romfs.cpp b/src/core/file_sys/archive_romfs.cpp
index 53dc57954..8c2dbeda5 100644
--- a/src/core/file_sys/archive_romfs.cpp
+++ b/src/core/file_sys/archive_romfs.cpp
@@ -43,6 +43,11 @@ bool Archive_RomFS::DeleteFile(const FileSys::Path& path) const {
43 return false; 43 return false;
44} 44}
45 45
46bool Archive_RomFS::RenameFile(const FileSys::Path& src_path, const FileSys::Path& dest_path) const {
47 ERROR_LOG(FILESYS, "Attempted to rename a file within ROMFS.");
48 return false;
49}
50
46/** 51/**
47 * Delete a directory specified by its path 52 * Delete a directory specified by its path
48 * @param path Path relative to the archive 53 * @param path Path relative to the archive
@@ -63,6 +68,11 @@ bool Archive_RomFS::CreateDirectory(const Path& path) const {
63 return false; 68 return false;
64} 69}
65 70
71bool Archive_RomFS::RenameDirectory(const FileSys::Path& src_path, const FileSys::Path& dest_path) const {
72 ERROR_LOG(FILESYS, "Attempted to rename a file within ROMFS.");
73 return false;
74}
75
66/** 76/**
67 * Open a directory specified by its path 77 * Open a directory specified by its path
68 * @param path Path relative to the archive 78 * @param path Path relative to the archive
diff --git a/src/core/file_sys/archive_romfs.h b/src/core/file_sys/archive_romfs.h
index 0649dde99..222bdc356 100644
--- a/src/core/file_sys/archive_romfs.h
+++ b/src/core/file_sys/archive_romfs.h
@@ -44,6 +44,14 @@ public:
44 bool DeleteFile(const FileSys::Path& path) const override; 44 bool DeleteFile(const FileSys::Path& path) const override;
45 45
46 /** 46 /**
47 * Rename a File specified by its path
48 * @param src_path Source path relative to the archive
49 * @param dest_path Destination path relative to the archive
50 * @return Whether rename succeeded
51 */
52 bool RenameFile(const FileSys::Path& src_path, const FileSys::Path& dest_path) const override;
53
54 /**
47 * Delete a directory specified by its path 55 * Delete a directory specified by its path
48 * @param path Path relative to the archive 56 * @param path Path relative to the archive
49 * @return Whether the directory could be deleted 57 * @return Whether the directory could be deleted
@@ -58,6 +66,14 @@ public:
58 bool CreateDirectory(const Path& path) const override; 66 bool CreateDirectory(const Path& path) const override;
59 67
60 /** 68 /**
69 * Rename a Directory specified by its path
70 * @param src_path Source path relative to the archive
71 * @param dest_path Destination path relative to the archive
72 * @return Whether rename succeeded
73 */
74 bool RenameDirectory(const FileSys::Path& src_path, const FileSys::Path& dest_path) const override;
75
76 /**
61 * Open a directory specified by its path 77 * Open a directory specified by its path
62 * @param path Path relative to the archive 78 * @param path Path relative to the archive
63 * @return Opened directory, or nullptr 79 * @return Opened directory, or nullptr
diff --git a/src/core/file_sys/archive_sdmc.cpp b/src/core/file_sys/archive_sdmc.cpp
index 789212b17..169ab0f1c 100644
--- a/src/core/file_sys/archive_sdmc.cpp
+++ b/src/core/file_sys/archive_sdmc.cpp
@@ -66,6 +66,10 @@ bool Archive_SDMC::DeleteFile(const FileSys::Path& path) const {
66 return FileUtil::Delete(GetMountPoint() + path.AsString()); 66 return FileUtil::Delete(GetMountPoint() + path.AsString());
67} 67}
68 68
69bool Archive_SDMC::RenameFile(const FileSys::Path& src_path, const FileSys::Path& dest_path) const {
70 return FileUtil::Rename(GetMountPoint() + src_path.AsString(), GetMountPoint() + dest_path.AsString());
71}
72
69/** 73/**
70 * Delete a directory specified by its path 74 * Delete a directory specified by its path
71 * @param path Path relative to the archive 75 * @param path Path relative to the archive
@@ -84,6 +88,10 @@ bool Archive_SDMC::CreateDirectory(const Path& path) const {
84 return FileUtil::CreateDir(GetMountPoint() + path.AsString()); 88 return FileUtil::CreateDir(GetMountPoint() + path.AsString());
85} 89}
86 90
91bool Archive_SDMC::RenameDirectory(const FileSys::Path& src_path, const FileSys::Path& dest_path) const {
92 return FileUtil::Rename(GetMountPoint() + src_path.AsString(), GetMountPoint() + dest_path.AsString());
93}
94
87/** 95/**
88 * Open a directory specified by its path 96 * Open a directory specified by its path
89 * @param path Path relative to the archive 97 * @param path Path relative to the archive
diff --git a/src/core/file_sys/archive_sdmc.h b/src/core/file_sys/archive_sdmc.h
index 74ce29c0d..19f563a62 100644
--- a/src/core/file_sys/archive_sdmc.h
+++ b/src/core/file_sys/archive_sdmc.h
@@ -48,6 +48,14 @@ public:
48 bool DeleteFile(const FileSys::Path& path) const override; 48 bool DeleteFile(const FileSys::Path& path) const override;
49 49
50 /** 50 /**
51 * Rename a File specified by its path
52 * @param src_path Source path relative to the archive
53 * @param dest_path Destination path relative to the archive
54 * @return Whether rename succeeded
55 */
56 bool RenameFile(const FileSys::Path& src_path, const FileSys::Path& dest_path) const override;
57
58 /**
51 * Delete a directory specified by its path 59 * Delete a directory specified by its path
52 * @param path Path relative to the archive 60 * @param path Path relative to the archive
53 * @return Whether the directory could be deleted 61 * @return Whether the directory could be deleted
@@ -62,6 +70,14 @@ public:
62 bool CreateDirectory(const Path& path) const override; 70 bool CreateDirectory(const Path& path) const override;
63 71
64 /** 72 /**
73 * Rename a Directory specified by its path
74 * @param src_path Source path relative to the archive
75 * @param dest_path Destination path relative to the archive
76 * @return Whether rename succeeded
77 */
78 bool RenameDirectory(const FileSys::Path& src_path, const FileSys::Path& dest_path) const override;
79
80 /**
65 * Open a directory specified by its path 81 * Open a directory specified by its path
66 * @param path Path relative to the archive 82 * @param path Path relative to the archive
67 * @return Opened directory, or nullptr 83 * @return Opened directory, or nullptr
diff --git a/src/core/hle/kernel/archive.cpp b/src/core/hle/kernel/archive.cpp
index e273444c9..647f0dea9 100644
--- a/src/core/hle/kernel/archive.cpp
+++ b/src/core/hle/kernel/archive.cpp
@@ -340,49 +340,68 @@ ResultVal<Handle> OpenFileFromArchive(Handle archive_handle, const FileSys::Path
340 return MakeResult<Handle>(handle); 340 return MakeResult<Handle>(handle);
341} 341}
342 342
343/** 343ResultCode DeleteFileFromArchive(Handle archive_handle, const FileSys::Path& path) {
344 * Delete a File from an Archive
345 * @param archive_handle Handle to an open Archive object
346 * @param path Path to the File inside of the Archive
347 * @return Whether deletion succeeded
348 */
349Result DeleteFileFromArchive(Handle archive_handle, const FileSys::Path& path) {
350 Archive* archive = Kernel::g_object_pool.GetFast<Archive>(archive_handle); 344 Archive* archive = Kernel::g_object_pool.GetFast<Archive>(archive_handle);
351 if (archive == nullptr) 345 if (archive == nullptr)
352 return -1; 346 return InvalidHandle(ErrorModule::FS);
353 if (archive->backend->DeleteFile(path)) 347 if (archive->backend->DeleteFile(path))
354 return 0; 348 return RESULT_SUCCESS;
355 return -1; 349 return ResultCode(ErrorDescription::NoData, ErrorModule::FS, // TODO: verify description
350 ErrorSummary::Canceled, ErrorLevel::Status);
356} 351}
357 352
358/** 353ResultCode RenameFileBetweenArchives(Handle src_archive_handle, const FileSys::Path& src_path,
359 * Delete a Directory from an Archive 354 Handle dest_archive_handle, const FileSys::Path& dest_path) {
360 * @param archive_handle Handle to an open Archive object 355 Archive* src_archive = Kernel::g_object_pool.GetFast<Archive>(src_archive_handle);
361 * @param path Path to the Directory inside of the Archive 356 Archive* dest_archive = Kernel::g_object_pool.GetFast<Archive>(dest_archive_handle);
362 * @return Whether deletion succeeded 357 if (src_archive == nullptr || dest_archive == nullptr)
363 */ 358 return InvalidHandle(ErrorModule::FS);
364Result DeleteDirectoryFromArchive(Handle archive_handle, const FileSys::Path& path) { 359 if (src_archive == dest_archive) {
360 if (src_archive->backend->RenameFile(src_path, dest_path))
361 return RESULT_SUCCESS;
362 } else {
363 // TODO: Implement renaming across archives
364 return UnimplementedFunction(ErrorModule::FS);
365 }
366 return ResultCode(ErrorDescription::NoData, ErrorModule::FS, // TODO: verify description
367 ErrorSummary::NothingHappened, ErrorLevel::Status);
368}
369
370ResultCode DeleteDirectoryFromArchive(Handle archive_handle, const FileSys::Path& path) {
365 Archive* archive = Kernel::g_object_pool.GetFast<Archive>(archive_handle); 371 Archive* archive = Kernel::g_object_pool.GetFast<Archive>(archive_handle);
366 if (archive == nullptr) 372 if (archive == nullptr)
367 return -1; 373 return InvalidHandle(ErrorModule::FS);
368 if (archive->backend->DeleteDirectory(path)) 374 if (archive->backend->DeleteDirectory(path))
369 return 0; 375 return RESULT_SUCCESS;
370 return -1; 376 return ResultCode(ErrorDescription::NoData, ErrorModule::FS, // TODO: verify description
377 ErrorSummary::Canceled, ErrorLevel::Status);
371} 378}
372 379
373/** 380ResultCode CreateDirectoryFromArchive(Handle archive_handle, const FileSys::Path& path) {
374 * Create a Directory from an Archive
375 * @param archive_handle Handle to an open Archive object
376 * @param path Path to the Directory inside of the Archive
377 * @return Whether creation succeeded
378 */
379Result CreateDirectoryFromArchive(Handle archive_handle, const FileSys::Path& path) {
380 Archive* archive = Kernel::g_object_pool.GetFast<Archive>(archive_handle); 381 Archive* archive = Kernel::g_object_pool.GetFast<Archive>(archive_handle);
381 if (archive == nullptr) 382 if (archive == nullptr)
382 return -1; 383 return InvalidHandle(ErrorModule::FS);
383 if (archive->backend->CreateDirectory(path)) 384 if (archive->backend->CreateDirectory(path))
384 return 0; 385 return RESULT_SUCCESS;
385 return -1; 386 return ResultCode(ErrorDescription::NoData, ErrorModule::FS, // TODO: verify description
387 ErrorSummary::Canceled, ErrorLevel::Status);
388}
389
390ResultCode RenameDirectoryBetweenArchives(Handle src_archive_handle, const FileSys::Path& src_path,
391 Handle dest_archive_handle, const FileSys::Path& dest_path) {
392 Archive* src_archive = Kernel::g_object_pool.GetFast<Archive>(src_archive_handle);
393 Archive* dest_archive = Kernel::g_object_pool.GetFast<Archive>(dest_archive_handle);
394 if (src_archive == nullptr || dest_archive == nullptr)
395 return InvalidHandle(ErrorModule::FS);
396 if (src_archive == dest_archive) {
397 if (src_archive->backend->RenameDirectory(src_path, dest_path))
398 return RESULT_SUCCESS;
399 } else {
400 // TODO: Implement renaming across archives
401 return UnimplementedFunction(ErrorModule::FS);
402 }
403 return ResultCode(ErrorDescription::NoData, ErrorModule::FS, // TODO: verify description
404 ErrorSummary::NothingHappened, ErrorLevel::Status);
386} 405}
387 406
388/** 407/**
diff --git a/src/core/hle/kernel/archive.h b/src/core/hle/kernel/archive.h
index 6fc4f0f25..b50833a2b 100644
--- a/src/core/hle/kernel/archive.h
+++ b/src/core/hle/kernel/archive.h
@@ -50,7 +50,18 @@ ResultVal<Handle> OpenFileFromArchive(Handle archive_handle, const FileSys::Path
50 * @param path Path to the File inside of the Archive 50 * @param path Path to the File inside of the Archive
51 * @return Whether deletion succeeded 51 * @return Whether deletion succeeded
52 */ 52 */
53Result DeleteFileFromArchive(Handle archive_handle, const FileSys::Path& path); 53ResultCode DeleteFileFromArchive(Handle archive_handle, const FileSys::Path& path);
54
55/**
56 * Rename a File between two Archives
57 * @param src_archive_handle Handle to the source Archive object
58 * @param src_path Path to the File inside of the source Archive
59 * @param dest_archive_handle Handle to the destination Archive object
60 * @param dest_path Path to the File inside of the destination Archive
61 * @return Whether rename succeeded
62 */
63ResultCode RenameFileBetweenArchives(Handle src_archive_handle, const FileSys::Path& src_path,
64 Handle dest_archive_handle, const FileSys::Path& dest_path);
54 65
55/** 66/**
56 * Delete a Directory from an Archive 67 * Delete a Directory from an Archive
@@ -58,7 +69,7 @@ Result DeleteFileFromArchive(Handle archive_handle, const FileSys::Path& path);
58 * @param path Path to the Directory inside of the Archive 69 * @param path Path to the Directory inside of the Archive
59 * @return Whether deletion succeeded 70 * @return Whether deletion succeeded
60 */ 71 */
61Result DeleteDirectoryFromArchive(Handle archive_handle, const FileSys::Path& path); 72ResultCode DeleteDirectoryFromArchive(Handle archive_handle, const FileSys::Path& path);
62 73
63/** 74/**
64 * Create a Directory from an Archive 75 * Create a Directory from an Archive
@@ -66,7 +77,18 @@ Result DeleteDirectoryFromArchive(Handle archive_handle, const FileSys::Path& pa
66 * @param path Path to the Directory inside of the Archive 77 * @param path Path to the Directory inside of the Archive
67 * @return Whether creation of directory succeeded 78 * @return Whether creation of directory succeeded
68 */ 79 */
69Result CreateDirectoryFromArchive(Handle archive_handle, const FileSys::Path& path); 80ResultCode CreateDirectoryFromArchive(Handle archive_handle, const FileSys::Path& path);
81
82/**
83 * Rename a Directory between two Archives
84 * @param src_archive_handle Handle to the source Archive object
85 * @param src_path Path to the Directory inside of the source Archive
86 * @param dest_archive_handle Handle to the destination Archive object
87 * @param dest_path Path to the Directory inside of the destination Archive
88 * @return Whether rename succeeded
89 */
90ResultCode RenameDirectoryBetweenArchives(Handle src_archive_handle, const FileSys::Path& src_path,
91 Handle dest_archive_handle, const FileSys::Path& dest_path);
70 92
71/** 93/**
72 * Open a Directory from an Archive 94 * Open a Directory from an Archive
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp
index 018000abd..80a34c2d5 100644
--- a/src/core/hle/kernel/kernel.cpp
+++ b/src/core/hle/kernel/kernel.cpp
@@ -2,6 +2,8 @@
2// Licensed under GPLv2 2// Licensed under GPLv2
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include <algorithm>
6
5#include "common/common.h" 7#include "common/common.h"
6 8
7#include "core/core.h" 9#include "core/core.h"
@@ -37,7 +39,7 @@ Handle ObjectPool::Create(Object* obj, int range_bottom, int range_top) {
37 return 0; 39 return 0;
38} 40}
39 41
40bool ObjectPool::IsValid(Handle handle) { 42bool ObjectPool::IsValid(Handle handle) const {
41 int index = handle - HANDLE_OFFSET; 43 int index = handle - HANDLE_OFFSET;
42 if (index < 0) 44 if (index < 0)
43 return false; 45 return false;
@@ -75,13 +77,8 @@ void ObjectPool::List() {
75 } 77 }
76} 78}
77 79
78int ObjectPool::GetCount() { 80int ObjectPool::GetCount() const {
79 int count = 0; 81 return std::count(occupied.begin(), occupied.end(), true);
80 for (int i = 0; i < MAX_COUNT; i++) {
81 if (occupied[i])
82 count++;
83 }
84 return count;
85} 82}
86 83
87Object* ObjectPool::CreateByIDType(int type) { 84Object* ObjectPool::CreateByIDType(int type) {
diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.h
index 8d3937ce8..00a2228bf 100644
--- a/src/core/hle/kernel/kernel.h
+++ b/src/core/hle/kernel/kernel.h
@@ -86,7 +86,7 @@ public:
86 } 86 }
87 } 87 }
88 88
89 bool IsValid(Handle handle); 89 bool IsValid(Handle handle) const;
90 90
91 template <class T> 91 template <class T>
92 T* Get(Handle handle) { 92 T* Get(Handle handle) {
@@ -142,7 +142,7 @@ public:
142 Object* &operator [](Handle handle); 142 Object* &operator [](Handle handle);
143 void List(); 143 void List();
144 void Clear(); 144 void Clear();
145 int GetCount(); 145 int GetCount() const;
146 146
147private: 147private:
148 148
diff --git a/src/core/hle/service/dsp_dsp.cpp b/src/core/hle/service/dsp_dsp.cpp
index a2b68cac8..72be4c817 100644
--- a/src/core/hle/service/dsp_dsp.cpp
+++ b/src/core/hle/service/dsp_dsp.cpp
@@ -16,6 +16,25 @@ static Handle semaphore_event;
16static Handle interrupt_event; 16static Handle interrupt_event;
17 17
18/** 18/**
19 * DSP_DSP::ConvertProcessAddressFromDspDram service function
20 * Inputs:
21 * 1 : Address
22 * Outputs:
23 * 1 : Result of function, 0 on success, otherwise error code
24 * 2 : (inaddr << 1) + 0x1FF40000 (where 0x1FF00000 is the DSP RAM address)
25 */
26void ConvertProcessAddressFromDspDram(Service::Interface* self) {
27 u32* cmd_buff = Service::GetCommandBuffer();
28
29 u32 addr = cmd_buff[1];
30
31 cmd_buff[1] = 0; // No error
32 cmd_buff[2] = (addr << 1) + (Memory::DSP_MEMORY_VADDR + 0x40000);
33
34 DEBUG_LOG(KERNEL, "(STUBBED) called with address %u", addr);
35}
36
37/**
19 * DSP_DSP::LoadComponent service function 38 * DSP_DSP::LoadComponent service function
20 * Inputs: 39 * Inputs:
21 * 1 : Size 40 * 1 : Size
@@ -90,31 +109,31 @@ void WriteReg0x10(Service::Interface* self) {
90} 109}
91 110
92const Interface::FunctionInfo FunctionTable[] = { 111const Interface::FunctionInfo FunctionTable[] = {
93 {0x00010040, nullptr, "RecvData"}, 112 {0x00010040, nullptr, "RecvData"},
94 {0x00020040, nullptr, "RecvDataIsReady"}, 113 {0x00020040, nullptr, "RecvDataIsReady"},
95 {0x00030080, nullptr, "SendData"}, 114 {0x00030080, nullptr, "SendData"},
96 {0x00040040, nullptr, "SendDataIsEmpty"}, 115 {0x00040040, nullptr, "SendDataIsEmpty"},
97 {0x00070040, WriteReg0x10, "WriteReg0x10"}, 116 {0x00070040, WriteReg0x10, "WriteReg0x10"},
98 {0x00080000, nullptr, "GetSemaphore"}, 117 {0x00080000, nullptr, "GetSemaphore"},
99 {0x00090040, nullptr, "ClearSemaphore"}, 118 {0x00090040, nullptr, "ClearSemaphore"},
100 {0x000B0000, nullptr, "CheckSemaphoreRequest"}, 119 {0x000B0000, nullptr, "CheckSemaphoreRequest"},
101 {0x000C0040, nullptr, "ConvertProcessAddressFromDspDram"}, 120 {0x000C0040, ConvertProcessAddressFromDspDram, "ConvertProcessAddressFromDspDram"},
102 {0x000D0082, nullptr, "WriteProcessPipe"}, 121 {0x000D0082, nullptr, "WriteProcessPipe"},
103 {0x001000C0, nullptr, "ReadPipeIfPossible"}, 122 {0x001000C0, nullptr, "ReadPipeIfPossible"},
104 {0x001100C2, LoadComponent, "LoadComponent"}, 123 {0x001100C2, LoadComponent, "LoadComponent"},
105 {0x00120000, nullptr, "UnloadComponent"}, 124 {0x00120000, nullptr, "UnloadComponent"},
106 {0x00130082, nullptr, "FlushDataCache"}, 125 {0x00130082, nullptr, "FlushDataCache"},
107 {0x00140082, nullptr, "InvalidateDCache"}, 126 {0x00140082, nullptr, "InvalidateDCache"},
108 {0x00150082, RegisterInterruptEvents, "RegisterInterruptEvents"}, 127 {0x00150082, RegisterInterruptEvents, "RegisterInterruptEvents"},
109 {0x00160000, GetSemaphoreEventHandle, "GetSemaphoreEventHandle"}, 128 {0x00160000, GetSemaphoreEventHandle, "GetSemaphoreEventHandle"},
110 {0x00170040, nullptr, "SetSemaphoreMask"}, 129 {0x00170040, nullptr, "SetSemaphoreMask"},
111 {0x00180040, nullptr, "GetPhysicalAddress"}, 130 {0x00180040, nullptr, "GetPhysicalAddress"},
112 {0x00190040, nullptr, "GetVirtualAddress"}, 131 {0x00190040, nullptr, "GetVirtualAddress"},
113 {0x001A0042, nullptr, "SetIirFilterI2S1_cmd1"}, 132 {0x001A0042, nullptr, "SetIirFilterI2S1_cmd1"},
114 {0x001B0042, nullptr, "SetIirFilterI2S1_cmd2"}, 133 {0x001B0042, nullptr, "SetIirFilterI2S1_cmd2"},
115 {0x001C0082, nullptr, "SetIirFilterEQ"}, 134 {0x001C0082, nullptr, "SetIirFilterEQ"},
116 {0x001F0000, nullptr, "GetHeadphoneStatus"}, 135 {0x001F0000, nullptr, "GetHeadphoneStatus"},
117 {0x00210000, nullptr, "GetIsDspOccupied"}, 136 {0x00210000, nullptr, "GetIsDspOccupied"},
118}; 137};
119 138
120//////////////////////////////////////////////////////////////////////////////////////////////////// 139////////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/core/hle/service/fs_user.cpp b/src/core/hle/service/fs_user.cpp
index 34af78cb9..51e8b579e 100644
--- a/src/core/hle/service/fs_user.cpp
+++ b/src/core/hle/service/fs_user.cpp
@@ -159,7 +159,49 @@ void DeleteFile(Service::Interface* self) {
159 DEBUG_LOG(KERNEL, "type=%d size=%d data=%s", 159 DEBUG_LOG(KERNEL, "type=%d size=%d data=%s",
160 filename_type, filename_size, file_path.DebugStr().c_str()); 160 filename_type, filename_size, file_path.DebugStr().c_str());
161 161
162 cmd_buff[1] = Kernel::DeleteFileFromArchive(archive_handle, file_path); 162 cmd_buff[1] = Kernel::DeleteFileFromArchive(archive_handle, file_path).raw;
163
164 DEBUG_LOG(KERNEL, "called");
165}
166
167/*
168 * FS_User::RenameFile service function
169 * Inputs:
170 * 2 : Source archive handle lower word
171 * 3 : Source archive handle upper word
172 * 4 : Source file path type
173 * 5 : Source file path size
174 * 6 : Dest archive handle lower word
175 * 7 : Dest archive handle upper word
176 * 8 : Dest file path type
177 * 9 : Dest file path size
178 * 11: Source file path string data
179 * 13: Dest file path string
180 * Outputs:
181 * 1 : Result of function, 0 on success, otherwise error code
182 */
183void RenameFile(Service::Interface* self) {
184 u32* cmd_buff = Service::GetCommandBuffer();
185
186 // TODO(Link Mauve): cmd_buff[2] and cmd_buff[6], aka archive handle lower word, aren't used according to
187 // 3dmoo's or ctrulib's implementations. Triple check if it's really the case.
188 Handle src_archive_handle = static_cast<Handle>(cmd_buff[3]);
189 auto src_filename_type = static_cast<FileSys::LowPathType>(cmd_buff[4]);
190 u32 src_filename_size = cmd_buff[5];
191 Handle dest_archive_handle = static_cast<Handle>(cmd_buff[7]);
192 auto dest_filename_type = static_cast<FileSys::LowPathType>(cmd_buff[8]);
193 u32 dest_filename_size = cmd_buff[9];
194 u32 src_filename_ptr = cmd_buff[11];
195 u32 dest_filename_ptr = cmd_buff[13];
196
197 FileSys::Path src_file_path(src_filename_type, src_filename_size, src_filename_ptr);
198 FileSys::Path dest_file_path(dest_filename_type, dest_filename_size, dest_filename_ptr);
199
200 DEBUG_LOG(KERNEL, "src_type=%d src_size=%d src_data=%s dest_type=%d dest_size=%d dest_data=%s",
201 src_filename_type, src_filename_size, src_file_path.DebugStr().c_str(),
202 dest_filename_type, dest_filename_size, dest_file_path.DebugStr().c_str());
203
204 cmd_buff[1] = Kernel::RenameFileBetweenArchives(src_archive_handle, src_file_path, dest_archive_handle, dest_file_path).raw;
163 205
164 DEBUG_LOG(KERNEL, "called"); 206 DEBUG_LOG(KERNEL, "called");
165} 207}
@@ -190,7 +232,7 @@ void DeleteDirectory(Service::Interface* self) {
190 DEBUG_LOG(KERNEL, "type=%d size=%d data=%s", 232 DEBUG_LOG(KERNEL, "type=%d size=%d data=%s",
191 dirname_type, dirname_size, dir_path.DebugStr().c_str()); 233 dirname_type, dirname_size, dir_path.DebugStr().c_str());
192 234
193 cmd_buff[1] = Kernel::DeleteDirectoryFromArchive(archive_handle, dir_path); 235 cmd_buff[1] = Kernel::DeleteDirectoryFromArchive(archive_handle, dir_path).raw;
194 236
195 DEBUG_LOG(KERNEL, "called"); 237 DEBUG_LOG(KERNEL, "called");
196} 238}
@@ -220,11 +262,53 @@ static void CreateDirectory(Service::Interface* self) {
220 262
221 DEBUG_LOG(KERNEL, "type=%d size=%d data=%s", dirname_type, dirname_size, dir_path.DebugStr().c_str()); 263 DEBUG_LOG(KERNEL, "type=%d size=%d data=%s", dirname_type, dirname_size, dir_path.DebugStr().c_str());
222 264
223 cmd_buff[1] = Kernel::CreateDirectoryFromArchive(archive_handle, dir_path); 265 cmd_buff[1] = Kernel::CreateDirectoryFromArchive(archive_handle, dir_path).raw;
224 266
225 DEBUG_LOG(KERNEL, "called"); 267 DEBUG_LOG(KERNEL, "called");
226} 268}
227 269
270/*
271 * FS_User::RenameDirectory service function
272 * Inputs:
273 * 2 : Source archive handle lower word
274 * 3 : Source archive handle upper word
275 * 4 : Source dir path type
276 * 5 : Source dir path size
277 * 6 : Dest archive handle lower word
278 * 7 : Dest archive handle upper word
279 * 8 : Dest dir path type
280 * 9 : Dest dir path size
281 * 11: Source dir path string data
282 * 13: Dest dir path string
283 * Outputs:
284 * 1 : Result of function, 0 on success, otherwise error code
285 */
286void RenameDirectory(Service::Interface* self) {
287 u32* cmd_buff = Service::GetCommandBuffer();
288
289 // TODO(Link Mauve): cmd_buff[2] and cmd_buff[6], aka archive handle lower word, aren't used according to
290 // 3dmoo's or ctrulib's implementations. Triple check if it's really the case.
291 Handle src_archive_handle = static_cast<Handle>(cmd_buff[3]);
292 auto src_dirname_type = static_cast<FileSys::LowPathType>(cmd_buff[4]);
293 u32 src_dirname_size = cmd_buff[5];
294 Handle dest_archive_handle = static_cast<Handle>(cmd_buff[7]);
295 auto dest_dirname_type = static_cast<FileSys::LowPathType>(cmd_buff[8]);
296 u32 dest_dirname_size = cmd_buff[9];
297 u32 src_dirname_ptr = cmd_buff[11];
298 u32 dest_dirname_ptr = cmd_buff[13];
299
300 FileSys::Path src_dir_path(src_dirname_type, src_dirname_size, src_dirname_ptr);
301 FileSys::Path dest_dir_path(dest_dirname_type, dest_dirname_size, dest_dirname_ptr);
302
303 DEBUG_LOG(KERNEL, "src_type=%d src_size=%d src_data=%s dest_type=%d dest_size=%d dest_data=%s",
304 src_dirname_type, src_dirname_size, src_dir_path.DebugStr().c_str(),
305 dest_dirname_type, dest_dirname_size, dest_dir_path.DebugStr().c_str());
306
307 cmd_buff[1] = Kernel::RenameDirectoryBetweenArchives(src_archive_handle, src_dir_path, dest_archive_handle, dest_dir_path).raw;
308
309 DEBUG_LOG(KERNEL, "called");
310}
311
228static void OpenDirectory(Service::Interface* self) { 312static void OpenDirectory(Service::Interface* self) {
229 u32* cmd_buff = Service::GetCommandBuffer(); 313 u32* cmd_buff = Service::GetCommandBuffer();
230 314
@@ -314,12 +398,12 @@ const Interface::FunctionInfo FunctionTable[] = {
314 {0x080201C2, OpenFile, "OpenFile"}, 398 {0x080201C2, OpenFile, "OpenFile"},
315 {0x08030204, OpenFileDirectly, "OpenFileDirectly"}, 399 {0x08030204, OpenFileDirectly, "OpenFileDirectly"},
316 {0x08040142, DeleteFile, "DeleteFile"}, 400 {0x08040142, DeleteFile, "DeleteFile"},
317 {0x08050244, nullptr, "RenameFile"}, 401 {0x08050244, RenameFile, "RenameFile"},
318 {0x08060142, DeleteDirectory, "DeleteDirectory"}, 402 {0x08060142, DeleteDirectory, "DeleteDirectory"},
319 {0x08070142, nullptr, "DeleteDirectoryRecursively"}, 403 {0x08070142, nullptr, "DeleteDirectoryRecursively"},
320 {0x08080202, nullptr, "CreateFile"}, 404 {0x08080202, nullptr, "CreateFile"},
321 {0x08090182, CreateDirectory, "CreateDirectory"}, 405 {0x08090182, CreateDirectory, "CreateDirectory"},
322 {0x080A0244, nullptr, "RenameDirectory"}, 406 {0x080A0244, RenameDirectory, "RenameDirectory"},
323 {0x080B0102, OpenDirectory, "OpenDirectory"}, 407 {0x080B0102, OpenDirectory, "OpenDirectory"},
324 {0x080C00C2, OpenArchive, "OpenArchive"}, 408 {0x080C00C2, OpenArchive, "OpenArchive"},
325 {0x080D0144, nullptr, "ControlArchive"}, 409 {0x080D0144, nullptr, "ControlArchive"},
diff --git a/src/core/hle/service/hid_user.cpp b/src/core/hle/service/hid_user.cpp
index d29de1a52..2abaf0f2f 100644
--- a/src/core/hle/service/hid_user.cpp
+++ b/src/core/hle/service/hid_user.cpp
@@ -55,7 +55,7 @@ static void UpdateNextCirclePadState() {
55/** 55/**
56 * Sets a Pad state (button or button combo) as pressed 56 * Sets a Pad state (button or button combo) as pressed
57 */ 57 */
58void PadButtonPress(PadState pad_state) { 58void PadButtonPress(const PadState& pad_state) {
59 next_state.hex |= pad_state.hex; 59 next_state.hex |= pad_state.hex;
60 UpdateNextCirclePadState(); 60 UpdateNextCirclePadState();
61} 61}
@@ -63,7 +63,7 @@ void PadButtonPress(PadState pad_state) {
63/** 63/**
64 * Sets a Pad state (button or button combo) as released 64 * Sets a Pad state (button or button combo) as released
65 */ 65 */
66void PadButtonRelease(PadState pad_state) { 66void PadButtonRelease(const PadState& pad_state) {
67 next_state.hex &= ~pad_state.hex; 67 next_state.hex &= ~pad_state.hex;
68 UpdateNextCirclePadState(); 68 UpdateNextCirclePadState();
69} 69}
diff --git a/src/core/hle/service/hid_user.h b/src/core/hle/service/hid_user.h
index 5ed97085d..8f53befdb 100644
--- a/src/core/hle/service/hid_user.h
+++ b/src/core/hle/service/hid_user.h
@@ -93,8 +93,8 @@ const PadState PAD_CIRCLE_UP = {{1u << 30}};
93const PadState PAD_CIRCLE_DOWN = {{1u << 31}}; 93const PadState PAD_CIRCLE_DOWN = {{1u << 31}};
94 94
95// Methods for updating the HID module's state 95// Methods for updating the HID module's state
96void PadButtonPress(PadState pad_state); 96void PadButtonPress(const PadState& pad_state);
97void PadButtonRelease(PadState pad_state); 97void PadButtonRelease(const PadState& pad_state);
98void PadUpdateComplete(); 98void PadUpdateComplete();
99 99
100/** 100/**
diff --git a/src/core/hle/service/ptm_u.cpp b/src/core/hle/service/ptm_u.cpp
index 1ce32ee4a..941df467b 100644
--- a/src/core/hle/service/ptm_u.cpp
+++ b/src/core/hle/service/ptm_u.cpp
@@ -11,8 +11,40 @@
11 11
12namespace PTM_U { 12namespace PTM_U {
13 13
14/// Charge levels used by PTM functions
15enum class ChargeLevels : u32 {
16 CriticalBattery = 1,
17 LowBattery = 2,
18 HalfFull = 3,
19 MostlyFull = 4,
20 CompletelyFull = 5,
21};
22
14static bool shell_open = true; 23static bool shell_open = true;
15 24
25static bool battery_is_charging = true;
26
27/**
28 * It is unknown if GetAdapterState is the same as GetBatteryChargeState,
29 * it is likely to just be a duplicate function of GetBatteryChargeState
30 * that controls another part of the HW.
31 * PTM_U::GetAdapterState service function
32 * Outputs:
33 * 1 : Result of function, 0 on success, otherwise error code
34 * 2 : Output of function, 0 = not charging, 1 = charging.
35 */
36static void GetAdapterState(Service::Interface* self) {
37 u32* cmd_buff = Service::GetCommandBuffer();
38
39 // TODO(purpasmart96): This function is only a stub,
40 // it returns a valid result without implementing full functionality.
41
42 cmd_buff[1] = 0; // No error
43 cmd_buff[2] = battery_is_charging ? 1 : 0;
44
45 WARN_LOG(KERNEL, "(STUBBED) called");
46}
47
16/* 48/*
17 * PTM_User::GetShellState service function. 49 * PTM_User::GetShellState service function.
18 * Outputs: 50 * Outputs:
@@ -28,15 +60,52 @@ static void GetShellState(Service::Interface* self) {
28 DEBUG_LOG(KERNEL, "PTM_U::GetShellState called"); 60 DEBUG_LOG(KERNEL, "PTM_U::GetShellState called");
29} 61}
30 62
63/**
64 * PTM_U::GetBatteryLevel service function
65 * Outputs:
66 * 1 : Result of function, 0 on success, otherwise error code
67 * 2 : Battery level, 5 = completely full battery, 4 = mostly full battery,
68 * 3 = half full battery, 2 = low battery, 1 = critical battery.
69 */
70static void GetBatteryLevel(Service::Interface* self) {
71 u32* cmd_buff = Service::GetCommandBuffer();
72
73 // TODO(purpasmart96): This function is only a stub,
74 // it returns a valid result without implementing full functionality.
75
76 cmd_buff[1] = 0; // No error
77 cmd_buff[2] = static_cast<u32>(ChargeLevels::CompletelyFull); // Set to a completely full battery
78
79 WARN_LOG(KERNEL, "(STUBBED) called");
80}
81
82/**
83 * PTM_U::GetBatteryChargeState service function
84 * Outputs:
85 * 1 : Result of function, 0 on success, otherwise error code
86 * 2 : Output of function, 0 = not charging, 1 = charging.
87 */
88static void GetBatteryChargeState(Service::Interface* self) {
89 u32* cmd_buff = Service::GetCommandBuffer();
90
91 // TODO(purpasmart96): This function is only a stub,
92 // it returns a valid result without implementing full functionality.
93
94 cmd_buff[1] = 0; // No error
95 cmd_buff[2] = battery_is_charging ? 1 : 0;
96
97 WARN_LOG(KERNEL, "(STUBBED) called");
98}
99
31const Interface::FunctionInfo FunctionTable[] = { 100const Interface::FunctionInfo FunctionTable[] = {
32 {0x00010002, nullptr, "RegisterAlarmClient"}, 101 {0x00010002, nullptr, "RegisterAlarmClient"},
33 {0x00020080, nullptr, "SetRtcAlarm"}, 102 {0x00020080, nullptr, "SetRtcAlarm"},
34 {0x00030000, nullptr, "GetRtcAlarm"}, 103 {0x00030000, nullptr, "GetRtcAlarm"},
35 {0x00040000, nullptr, "CancelRtcAlarm"}, 104 {0x00040000, nullptr, "CancelRtcAlarm"},
36 {0x00050000, nullptr, "GetAdapterState"}, 105 {0x00050000, GetAdapterState, "GetAdapterState"},
37 {0x00060000, GetShellState, "GetShellState"}, 106 {0x00060000, GetShellState, "GetShellState"},
38 {0x00070000, nullptr, "GetBatteryLevel"}, 107 {0x00070000, GetBatteryLevel, "GetBatteryLevel"},
39 {0x00080000, nullptr, "GetBatteryChargeState"}, 108 {0x00080000, GetBatteryChargeState, "GetBatteryChargeState"},
40 {0x00090000, nullptr, "GetPedometerState"}, 109 {0x00090000, nullptr, "GetPedometerState"},
41 {0x000A0042, nullptr, "GetStepHistoryEntry"}, 110 {0x000A0042, nullptr, "GetStepHistoryEntry"},
42 {0x000B00C2, nullptr, "GetStepHistory"}, 111 {0x000B00C2, nullptr, "GetStepHistory"},
diff --git a/src/core/mem_map.h b/src/core/mem_map.h
index a58c59244..c9529f84c 100644
--- a/src/core/mem_map.h
+++ b/src/core/mem_map.h
@@ -16,10 +16,9 @@ typedef u32 PAddr; ///< Represents a pointer in the physical address space.
16 16
17//////////////////////////////////////////////////////////////////////////////////////////////////// 17////////////////////////////////////////////////////////////////////////////////////////////////////
18 18
19enum { 19enum : u32 {
20 BOOTROM_SIZE = 0x00010000, ///< Bootrom (super secret code/data @ 0x8000) size 20 BOOTROM_SIZE = 0x00010000, ///< Bootrom (super secret code/data @ 0x8000) size
21 MPCORE_PRIV_SIZE = 0x00002000, ///< MPCore private memory region size 21 MPCORE_PRIV_SIZE = 0x00002000, ///< MPCore private memory region size
22 DSP_SIZE = 0x00080000, ///< DSP memory size
23 AXI_WRAM_SIZE = 0x00080000, ///< AXI WRAM size 22 AXI_WRAM_SIZE = 0x00080000, ///< AXI WRAM size
24 23
25 FCRAM_SIZE = 0x08000000, ///< FCRAM size 24 FCRAM_SIZE = 0x08000000, ///< FCRAM size
@@ -34,6 +33,9 @@ enum {
34 SHARED_MEMORY_VADDR_END = (SHARED_MEMORY_VADDR + SHARED_MEMORY_SIZE), 33 SHARED_MEMORY_VADDR_END = (SHARED_MEMORY_VADDR + SHARED_MEMORY_SIZE),
35 SHARED_MEMORY_MASK = (SHARED_MEMORY_SIZE - 1), 34 SHARED_MEMORY_MASK = (SHARED_MEMORY_SIZE - 1),
36 35
36 DSP_MEMORY_SIZE = 0x00080000, ///< DSP memory size
37 DSP_MEMORY_VADDR = 0x1FF00000, ///< DSP memory virtual address
38
37 CONFIG_MEMORY_SIZE = 0x00001000, ///< Configuration memory size 39 CONFIG_MEMORY_SIZE = 0x00001000, ///< Configuration memory size
38 CONFIG_MEMORY_VADDR = 0x1FF80000, ///< Configuration memory virtual address 40 CONFIG_MEMORY_VADDR = 0x1FF80000, ///< Configuration memory virtual address
39 CONFIG_MEMORY_VADDR_END = (CONFIG_MEMORY_VADDR + CONFIG_MEMORY_SIZE), 41 CONFIG_MEMORY_VADDR_END = (CONFIG_MEMORY_VADDR + CONFIG_MEMORY_SIZE),