apt.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. // Copyright 2015 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include "common/common_types.h"
  6. #include "common/swap.h"
  7. #include "core/hle/kernel/kernel.h"
  8. namespace Service {
  9. class Interface;
  10. namespace APT {
  11. /// Holds information about the parameters used in Send/Glance/ReceiveParameter
  12. struct MessageParameter {
  13. u32 sender_id = 0;
  14. u32 destination_id = 0;
  15. u32 signal = 0;
  16. u32 buffer_size = 0;
  17. Kernel::SharedPtr<Kernel::Object> object = nullptr;
  18. u8* data = nullptr;
  19. };
  20. /// Holds information about the parameters used in StartLibraryApplet
  21. struct AppletStartupParameter {
  22. u32 buffer_size = 0;
  23. Kernel::SharedPtr<Kernel::Object> object = nullptr;
  24. u8* data = nullptr;
  25. };
  26. /// Used by the application to pass information about the current framebuffer to applets.
  27. struct CaptureBufferInfo {
  28. u32_le size;
  29. u8 is_3d;
  30. INSERT_PADDING_BYTES(0x3); // Padding for alignment
  31. u32_le top_screen_left_offset;
  32. u32_le top_screen_right_offset;
  33. u32_le top_screen_format;
  34. u32_le bottom_screen_left_offset;
  35. u32_le bottom_screen_right_offset;
  36. u32_le bottom_screen_format;
  37. };
  38. static_assert(sizeof(CaptureBufferInfo) == 0x20, "CaptureBufferInfo struct has incorrect size");
  39. /// Signals used by APT functions
  40. enum class SignalType : u32 {
  41. None = 0x0,
  42. AppJustStarted = 0x1,
  43. LibAppJustStarted = 0x2,
  44. LibAppFinished = 0x3,
  45. LibAppClosed = 0xA,
  46. ReturningToApp = 0xB,
  47. ExitingApp = 0xC,
  48. };
  49. /// App Id's used by APT functions
  50. enum class AppletId : u32 {
  51. HomeMenu = 0x101,
  52. AlternateMenu = 0x103,
  53. Camera = 0x110,
  54. FriendsList = 0x112,
  55. GameNotes = 0x113,
  56. InternetBrowser = 0x114,
  57. InstructionManual = 0x115,
  58. Notifications = 0x116,
  59. Miiverse = 0x117,
  60. SoftwareKeyboard1 = 0x201,
  61. Ed1 = 0x202,
  62. PnoteApp = 0x204,
  63. SnoteApp = 0x205,
  64. Error = 0x206,
  65. Mint = 0x207,
  66. Extrapad = 0x208,
  67. Memolib = 0x209,
  68. Application = 0x300,
  69. AnyLibraryApplet = 0x400,
  70. SoftwareKeyboard2 = 0x401,
  71. Ed2 = 0x402,
  72. };
  73. enum class StartupArgumentType : u32 {
  74. OtherApp = 0,
  75. Restart = 1,
  76. OtherMedia = 2,
  77. };
  78. /// Send a parameter to the currently-running application, which will read it via ReceiveParameter
  79. void SendParameter(const MessageParameter& parameter);
  80. /**
  81. * APT::Initialize service function
  82. * Service function that initializes the APT process for the running application
  83. * Outputs:
  84. * 1 : Result of the function, 0 on success, otherwise error code
  85. * 3 : Handle to the notification event
  86. * 4 : Handle to the pause event
  87. */
  88. void Initialize(Service::Interface* self);
  89. /**
  90. * APT::GetSharedFont service function
  91. * Outputs:
  92. * 1 : Result of function, 0 on success, otherwise error code
  93. * 2 : Virtual address of where shared font will be loaded in memory
  94. * 4 : Handle to shared font memory
  95. */
  96. void GetSharedFont(Service::Interface* self);
  97. /**
  98. * APT::NotifyToWait service function
  99. * Inputs:
  100. * 1 : AppID
  101. * Outputs:
  102. * 1 : Result of function, 0 on success, otherwise error code
  103. */
  104. void NotifyToWait(Service::Interface* self);
  105. /**
  106. * APT::GetLockHandle service function
  107. * Inputs:
  108. * 1 : Applet attributes
  109. * Outputs:
  110. * 1 : Result of function, 0 on success, otherwise error code
  111. * 2 : Applet attributes
  112. * 3 : Power button state
  113. * 4 : IPC handle descriptor
  114. * 5 : APT mutex handle
  115. */
  116. void GetLockHandle(Service::Interface* self);
  117. /**
  118. * APT::Enable service function
  119. * Inputs:
  120. * 1 : Applet attributes
  121. * Outputs:
  122. * 1 : Result of function, 0 on success, otherwise error code
  123. */
  124. void Enable(Service::Interface* self);
  125. /**
  126. * APT::GetAppletManInfo service function.
  127. * Inputs:
  128. * 1 : Unknown
  129. * Outputs:
  130. * 1 : Result of function, 0 on success, otherwise error code
  131. * 2 : Unknown u32 value
  132. * 3 : Unknown u8 value
  133. * 4 : Home Menu AppId
  134. * 5 : AppID of currently active app
  135. */
  136. void GetAppletManInfo(Service::Interface* self);
  137. /**
  138. * APT::GetAppletInfo service function.
  139. * Inputs:
  140. * 1 : AppId
  141. * Outputs:
  142. * 1 : Result of function, 0 on success, otherwise error code
  143. * 2-3 : Title ID
  144. * 4 : Media Type
  145. * 5 : Registered
  146. * 6 : Loaded
  147. * 7 : Attributes
  148. */
  149. void GetAppletInfo(Service::Interface* self);
  150. /**
  151. * APT::IsRegistered service function. This returns whether the specified AppID is registered with NS yet.
  152. * An AppID is "registered" once the process associated with the AppID uses APT:Enable. Home Menu uses this
  153. * command to determine when the launched process is running and to determine when to stop using GSP etc,
  154. * while displaying the "Nintendo 3DS" loading screen.
  155. * Inputs:
  156. * 1 : AppID
  157. * Outputs:
  158. * 0 : Return header
  159. * 1 : Result of function, 0 on success, otherwise error code
  160. * 2 : Output, 0 = not registered, 1 = registered.
  161. */
  162. void IsRegistered(Service::Interface* self);
  163. void InquireNotification(Service::Interface* self);
  164. /**
  165. * APT::SendParameter service function. This sets the parameter data state.
  166. * Inputs:
  167. * 1 : Source AppID
  168. * 2 : Destination AppID
  169. * 3 : Signal type
  170. * 4 : Parameter buffer size, max size is 0x1000 (this can be zero)
  171. * 5 : Value
  172. * 6 : Handle to the destination process, likely used for shared memory (this can be zero)
  173. * 7 : (Size<<14) | 2
  174. * 8 : Input parameter buffer ptr
  175. * Outputs:
  176. * 0 : Return Header
  177. * 1 : Result of function, 0 on success, otherwise error code
  178. */
  179. void SendParameter(Service::Interface* self);
  180. /**
  181. * APT::ReceiveParameter service function. This returns the current parameter data from NS state,
  182. * from the source process which set the parameters. Once finished, NS will clear a flag in the NS
  183. * state so that this command will return an error if this command is used again if parameters were
  184. * not set again. This is called when the second Initialize event is triggered. It returns a signal
  185. * type indicating why it was triggered.
  186. * Inputs:
  187. * 1 : AppID
  188. * 2 : Parameter buffer size, max size is 0x1000
  189. * Outputs:
  190. * 1 : Result of function, 0 on success, otherwise error code
  191. * 2 : AppID of the process which sent these parameters
  192. * 3 : Signal type
  193. * 4 : Actual parameter buffer size, this is <= to the the input size
  194. * 5 : Value
  195. * 6 : Handle from the source process which set the parameters, likely used for shared memory
  196. * 7 : Size
  197. * 8 : Output parameter buffer ptr
  198. */
  199. void ReceiveParameter(Service::Interface* self);
  200. /**
  201. * APT::GlanceParameter service function. This is exactly the same as APT_U::ReceiveParameter
  202. * (except for the word value prior to the output handle), except this will not clear the flag
  203. * (except when responseword[3]==8 || responseword[3]==9) in NS state.
  204. * Inputs:
  205. * 1 : AppID
  206. * 2 : Parameter buffer size, max size is 0x1000
  207. * Outputs:
  208. * 1 : Result of function, 0 on success, otherwise error code
  209. * 2 : Unknown, for now assume AppID of the process which sent these parameters
  210. * 3 : Unknown, for now assume Signal type
  211. * 4 : Actual parameter buffer size, this is <= to the the input size
  212. * 5 : Value
  213. * 6 : Handle from the source process which set the parameters, likely used for shared memory
  214. * 7 : Size
  215. * 8 : Output parameter buffer ptr
  216. */
  217. void GlanceParameter(Service::Interface* self);
  218. /**
  219. * APT::CancelParameter service function. When the parameter data is available, and when the above
  220. * specified fields match the ones in NS state(for the ones where the checks are enabled), this
  221. * clears the flag which indicates that parameter data is available
  222. * (same flag cleared by APT:ReceiveParameter).
  223. * Inputs:
  224. * 1 : Flag, when non-zero NS will compare the word after this one with a field in the NS state.
  225. * 2 : Unknown, this is the same as the first unknown field returned by APT:ReceiveParameter.
  226. * 3 : Flag, when non-zero NS will compare the word after this one with a field in the NS state.
  227. * 4 : AppID
  228. * Outputs:
  229. * 0 : Return header
  230. * 1 : Result of function, 0 on success, otherwise error code
  231. * 2 : Status flag, 0 = failure due to no parameter data being available, or the above enabled
  232. * fields don't match the fields in NS state. 1 = success.
  233. */
  234. void CancelParameter(Service::Interface* self);
  235. /**
  236. * APT::PrepareToStartApplication service function. When the input title-info programID is zero,
  237. * NS will load the actual program ID via AMNet:GetTitleIDList. After doing some checks with the
  238. * programID, NS will then set a NS state flag to value 1, then set the programID for AppID
  239. * 0x300(application) to the input program ID(or the one from GetTitleIDList). A media-type field
  240. * in the NS state is also set to the input media-type value
  241. * (other state fields are set at this point as well). With 8.0.0-18, NS will set an u8 NS state
  242. * field to value 1 when input flags bit8 is set
  243. * Inputs:
  244. * 1-4 : 0x10-byte title-info struct
  245. * 4 : Flags
  246. * Outputs:
  247. * 0 : Return header
  248. * 1 : Result of function, 0 on success, otherwise error code
  249. */
  250. void PrepareToStartApplication(Service::Interface* self);
  251. /**
  252. * APT::StartApplication service function. Buf0 is copied to NS FIRMparams+0x0, then Buf1 is copied
  253. * to the NS FIRMparams+0x480. Then the application is launched.
  254. * Inputs:
  255. * 1 : Buffer 0 size, max size is 0x300
  256. * 2 : Buffer 1 size, max size is 0x20 (this can be zero)
  257. * 3 : u8 flag
  258. * 4 : (Size0<<14) | 2
  259. * 5 : Buffer 0 pointer
  260. * 6 : (Size1<<14) | 0x802
  261. * 7 : Buffer 1 pointer
  262. * Outputs:
  263. * 0 : Return Header
  264. * 1 : Result of function, 0 on success, otherwise error code
  265. */
  266. void StartApplication(Service::Interface* self);
  267. /**
  268. * APT::AppletUtility service function
  269. * Inputs:
  270. * 1 : Unknown, but clearly used for something
  271. * 2 : Buffer 1 size (purpose is unknown)
  272. * 3 : Buffer 2 size (purpose is unknown)
  273. * 5 : Buffer 1 address (purpose is unknown)
  274. * 65 : Buffer 2 address (purpose is unknown)
  275. * Outputs:
  276. * 1 : Result of function, 0 on success, otherwise error code
  277. */
  278. void AppletUtility(Service::Interface* self);
  279. /**
  280. * APT::SetAppCpuTimeLimit service function
  281. * Inputs:
  282. * 1 : Value, must be one
  283. * 2 : Percentage of CPU time from 5 to 80
  284. * Outputs:
  285. * 1 : Result of function, 0 on success, otherwise error code
  286. */
  287. void SetAppCpuTimeLimit(Service::Interface* self);
  288. /**
  289. * APT::GetAppCpuTimeLimit service function
  290. * Inputs:
  291. * 1 : Value, must be one
  292. * Outputs:
  293. * 0 : Return header
  294. * 1 : Result of function, 0 on success, otherwise error code
  295. * 2 : System core CPU time percentage
  296. */
  297. void GetAppCpuTimeLimit(Service::Interface* self);
  298. /**
  299. * APT::PrepareToStartLibraryApplet service function
  300. * Inputs:
  301. * 0 : Command header [0x00180040]
  302. * 1 : Id of the applet to start
  303. * Outputs:
  304. * 0 : Return header
  305. * 1 : Result of function, 0 on success, otherwise error code
  306. */
  307. void PrepareToStartLibraryApplet(Service::Interface* self);
  308. /**
  309. * APT::PreloadLibraryApplet service function
  310. * Inputs:
  311. * 0 : Command header [0x00160040]
  312. * 1 : Id of the applet to start
  313. * Outputs:
  314. * 0 : Return header
  315. * 1 : Result of function, 0 on success, otherwise error code
  316. */
  317. void PreloadLibraryApplet(Service::Interface* self);
  318. /**
  319. * APT::StartLibraryApplet service function
  320. * Inputs:
  321. * 0 : Command header [0x001E0084]
  322. * 1 : Id of the applet to start
  323. * 2 : Buffer size
  324. * 3 : Always 0?
  325. * 4 : Handle passed to the applet
  326. * 5 : (Size << 14) | 2
  327. * 6 : Input buffer virtual address
  328. * Outputs:
  329. * 0 : Return header
  330. * 1 : Result of function, 0 on success, otherwise error code
  331. */
  332. void StartLibraryApplet(Service::Interface* self);
  333. /**
  334. * APT::GetStartupArgument service function
  335. * Inputs:
  336. * 1 : Parameter Size (capped to 0x300)
  337. * 2 : StartupArgumentType
  338. * Outputs:
  339. * 0 : Return header
  340. * 1 : u8, Exists (0 = does not exist, 1 = exists)
  341. */
  342. void GetStartupArgument(Service::Interface* self);
  343. /// Initialize the APT service
  344. void Init();
  345. /// Shutdown the APT service
  346. void Shutdown();
  347. } // namespace APT
  348. } // namespace Service