diff options
Diffstat (limited to 'src/core/hle/applets/applet.cpp')
| -rw-r--r-- | src/core/hle/applets/applet.cpp | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/src/core/hle/applets/applet.cpp b/src/core/hle/applets/applet.cpp index 689f5adc8..4dcce729a 100644 --- a/src/core/hle/applets/applet.cpp +++ b/src/core/hle/applets/applet.cpp | |||
| @@ -31,9 +31,8 @@ namespace Applets { | |||
| 31 | 31 | ||
| 32 | static std::unordered_map<Service::APT::AppletId, std::shared_ptr<Applet>> applets; | 32 | static std::unordered_map<Service::APT::AppletId, std::shared_ptr<Applet>> applets; |
| 33 | static u32 applet_update_event = -1; ///< The CoreTiming event identifier for the Applet update callback. | 33 | static u32 applet_update_event = -1; ///< The CoreTiming event identifier for the Applet update callback. |
| 34 | /// The interval at which the Applet update callback will be called. | 34 | /// The interval at which the Applet update callback will be called, 16.6ms |
| 35 | static const u64 applet_update_interval_microseconds = 16666; | 35 | static const u64 applet_update_interval_us = 16666; |
| 36 | std::shared_ptr<Applet> g_current_applet = nullptr; ///< The applet that is currently executing | ||
| 37 | 36 | ||
| 38 | ResultCode Applet::Create(Service::APT::AppletId id) { | 37 | ResultCode Applet::Create(Service::APT::AppletId id) { |
| 39 | switch (id) { | 38 | switch (id) { |
| @@ -57,21 +56,38 @@ std::shared_ptr<Applet> Applet::Get(Service::APT::AppletId id) { | |||
| 57 | } | 56 | } |
| 58 | 57 | ||
| 59 | /// Handles updating the current Applet every time it's called. | 58 | /// Handles updating the current Applet every time it's called. |
| 60 | static void AppletUpdateEvent(u64, int cycles_late) { | 59 | static void AppletUpdateEvent(u64 applet_id, int cycles_late) { |
| 61 | if (g_current_applet && g_current_applet->IsRunning()) | 60 | Service::APT::AppletId id = static_cast<Service::APT::AppletId>(applet_id); |
| 62 | g_current_applet->Update(); | 61 | std::shared_ptr<Applet> applet = Applet::Get(id); |
| 62 | ASSERT_MSG(applet != nullptr, "Applet doesn't exist! applet_id=%08X", id); | ||
| 63 | 63 | ||
| 64 | CoreTiming::ScheduleEvent(usToCycles(applet_update_interval) - cycles_late, | 64 | applet->Update(); |
| 65 | applet_update_event); | 65 | |
| 66 | // If the applet is still running after the last update, reschedule the event | ||
| 67 | if (applet->IsRunning()) { | ||
| 68 | CoreTiming::ScheduleEvent(usToCycles(applet_update_interval_us) - cycles_late, | ||
| 69 | applet_update_event, applet_id); | ||
| 70 | } else { | ||
| 71 | // Otherwise the applet has terminated, in which case we should clean it up | ||
| 72 | applets[id] = nullptr; | ||
| 73 | } | ||
| 74 | } | ||
| 75 | |||
| 76 | ResultCode Applet::Start(const Service::APT::AppletStartupParameter& parameter) { | ||
| 77 | ResultCode result = StartImpl(parameter); | ||
| 78 | if (result.IsError()) | ||
| 79 | return result; | ||
| 80 | // Schedule the update event | ||
| 81 | CoreTiming::ScheduleEvent(usToCycles(applet_update_interval_us), applet_update_event, static_cast<u64>(id)); | ||
| 82 | return result; | ||
| 66 | } | 83 | } |
| 67 | 84 | ||
| 68 | void Init() { | 85 | void Init() { |
| 86 | // Register the applet update callback | ||
| 69 | applet_update_event = CoreTiming::RegisterEvent("HLE Applet Update Event", AppletUpdateEvent); | 87 | applet_update_event = CoreTiming::RegisterEvent("HLE Applet Update Event", AppletUpdateEvent); |
| 70 | CoreTiming::ScheduleEvent(usToCycles(applet_update_interval), applet_update_event); | ||
| 71 | } | 88 | } |
| 72 | 89 | ||
| 73 | void Shutdown() { | 90 | void Shutdown() { |
| 74 | CoreTiming::UnscheduleEvent(applet_update_event, 0); | ||
| 75 | } | 91 | } |
| 76 | 92 | ||
| 77 | } | 93 | } |