apt.h 10 KB

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