|
| 1 | +/** |
| 2 | + * @file ptmplays.h |
| 3 | + * @brief PTMPLAYS service. Has access to ptm:u commands, but this is not exposed here. |
| 4 | + */ |
| 5 | +#pragma once |
| 6 | + |
| 7 | +#include <3ds/types.h> |
| 8 | + |
| 9 | +/// Maximum number of play events that can be stored. |
| 10 | +#define PTM_MAX_PLAY_EVENTS 0x11D28u |
| 11 | + |
| 12 | +/// Invalid title ID constant for PTM. |
| 13 | +#define PTM_INVALID_TITLE_ID 0xFFFFFFFFFFFFFFFFull |
| 14 | + |
| 15 | +/// Play event types. "Applet" includes "HOME Menu". |
| 16 | +typedef enum PtmPlayEventType { |
| 17 | + PTMPLAYEVENT_APPLICATION_LAUNCH = 0, ///< Application launch (special meaning for invalid TitleId upon launching DSi title) |
| 18 | + PTMPLAYEVENT_APPLICATION_EXIT = 1, ///< Application exit (likewise) |
| 19 | + PTMPLAYEVENT_APPLET_LAUNCH = 2, ///< Applet launch |
| 20 | + PTMPLAYEVENT_APPLET_EXIT = 3, ///< Applet exit |
| 21 | + PTMPLAYEVENT_JUMP_TO_APPLICATION = 4, ///< Jump to application |
| 22 | + PTMPLAYEVENT_LEAVE_APPLICATION = 5, ///< Leave application |
| 23 | + PTMPLAYEVENT_JUMP_TO_APPLET = 6, ///< Jump to applet |
| 24 | + PTMPLAYEVENT_LEAVE_APPLET = 7, ///< Leave applet |
| 25 | + PTMPLAYEVENT_SHELL_CLOSE = 8, ///< Shell close (no TitleId) |
| 26 | + PTMPLAYEVENT_SHELL_OPEN = 9, ///< Shell open (no TitleId) |
| 27 | + PTMPLAYEVENT_SYSTEM_SHUTDOWN = 10, ///< System shutdown (no TitleId) |
| 28 | + PTMPLAYEVENT_USER_TIME_CHANGE_OLD_TIME = 11, ///< User time change - old time (no TitleId, old user time stored in \ref minutesSince2000) |
| 29 | + PTMPLAYEVENT_USER_TIME_CHANGE_NEW_TIME = 12, ///< User time change - new time (no TitleId, new user time stored in \ref minutesSince2000) |
| 30 | +} PtmPlayEventType; |
| 31 | + |
| 32 | +/// Play event entry. |
| 33 | +typedef struct PtmPlayEvent { |
| 34 | + u32 tidHigh; ///< Upper 32 bits of title ID |
| 35 | + u32 tidLow; ///< Lower 32 bits of title ID |
| 36 | + PtmPlayEventType type : 4; ///< Event type |
| 37 | + u32 minutesSince2000 : 28; ///< Number of minutes elapsed since 2000-01-01 00:00 |
| 38 | +} PtmPlayEvent; |
| 39 | + |
| 40 | +/// Get TitleID from PtmPlayEvent. |
| 41 | +static inline u64 ptmGetPlayEventTitleId(PtmPlayEvent event) { |
| 42 | + return ((u64)(event.tidHigh) << 32) | event.tidLow; |
| 43 | +} |
| 44 | + |
| 45 | +/// Initializes PTMPLAYS. |
| 46 | +Result ptmPlaysInit(void); |
| 47 | + |
| 48 | +/// Exits PTMPLAYS. |
| 49 | +void ptmPlaysExit(void); |
| 50 | + |
| 51 | +/** |
| 52 | + * @brief Gets a pointer to the current ptm:plays session handle. |
| 53 | + * @return A pointer to the current ptm:plays session handle. |
| 54 | + */ |
| 55 | +Handle *ptmPlaysGetSessionHandle(void); |
| 56 | + |
| 57 | +/** |
| 58 | + * @brief Gets the PlayEvent history (ring buffer). |
| 59 | + * @param[out] outEndIndex The pointer to write the end index to (ring buffer). |
| 60 | + * @param[out] outEvents The pointer to write the event entries to. |
| 61 | + * @param[in] startIndex The start index (offset) to read from (ring buffer). |
| 62 | + * @param[in] maxEvents The maximum number of events to write to outEvents. |
| 63 | + */ |
| 64 | +Result PTMPLAYS_GetPlayHistory(s32 *outEndIndex, PtmPlayEvent *outEvents, s32 startIndex, s32 maxEvents); |
| 65 | + |
| 66 | +/** |
| 67 | + * @brief Gets the start index of the PlayEvent history (ring buffer). |
| 68 | + * @param[out] outStartIndex The pointer to write the start index to (ring buffer). |
| 69 | + */ |
| 70 | +Result PTMPLAYS_GetPlayHistoryStart(s32 *outStartIndex); |
| 71 | + |
| 72 | +/** |
| 73 | + * @brief Gets the number of entries of the PlayEvent history (ring buffer). |
| 74 | + * @param[out] outNumEvents The pointer to write the start index to (ring buffer). |
| 75 | + */ |
| 76 | +Result PTMPLAYS_GetPlayHistorySize(s32 *outNumEvents); |
| 77 | + |
| 78 | +/** |
| 79 | + * @brief Computes (start + numEvents) % PTM_MAX_PLAY_EVENTS with positive remainder. |
| 80 | + * @param[out] outIndex Result of the index computation. |
| 81 | + */ |
| 82 | +Result PTMPLAYS_CalcPlayHistoryStart(s32 *outIndex, s32 start, s32 numEvents); |
0 commit comments