summaryrefslogtreecommitdiff
path: root/src/core/hle/applets/applet.cpp
diff options
context:
space:
mode:
authorGravatar Subv2015-05-26 11:00:26 -0500
committerGravatar Subv2015-07-11 21:47:23 -0500
commit621ee10eae0546d4ec3f9e911e113aa9ee609c22 (patch)
treeadfdc1cf9ae7e9ac9a5cf9950a91bbcfeb6cd552 /src/core/hle/applets/applet.cpp
parentHLE/APT: Initial HLE support for applets. (diff)
downloadyuzu-621ee10eae0546d4ec3f9e911e113aa9ee609c22.tar.gz
yuzu-621ee10eae0546d4ec3f9e911e113aa9ee609c22.tar.xz
yuzu-621ee10eae0546d4ec3f9e911e113aa9ee609c22.zip
Applets: Add infrastructure to allow custom drawing and input handling in Applets.
Diffstat (limited to 'src/core/hle/applets/applet.cpp')
-rw-r--r--src/core/hle/applets/applet.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/core/hle/applets/applet.cpp b/src/core/hle/applets/applet.cpp
index 1f447e5fc..689f5adc8 100644
--- a/src/core/hle/applets/applet.cpp
+++ b/src/core/hle/applets/applet.cpp
@@ -5,15 +5,35 @@
5#include "common/assert.h" 5#include "common/assert.h"
6#include "common/logging/log.h" 6#include "common/logging/log.h"
7 7
8#include "core/core_timing.h"
8#include "core/hle/applets/applet.h" 9#include "core/hle/applets/applet.h"
9#include "core/hle/applets/swkbd.h" 10#include "core/hle/applets/swkbd.h"
10 11
11//////////////////////////////////////////////////////////////////////////////////////////////////// 12////////////////////////////////////////////////////////////////////////////////////////////////////
12 13
14// Specializes std::hash for AppletId, so that we can use it in std::unordered_map.
15// Workaround for libstdc++ bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60970
16namespace std {
17 template <>
18 struct hash<Service::APT::AppletId> {
19 typedef Service::APT::AppletId argument_type;
20 typedef std::size_t result_type;
21
22 result_type operator()(const argument_type& id_code) const {
23 typedef std::underlying_type<argument_type>::type Type;
24 return std::hash<Type>()(static_cast<Type>(id_code));
25 }
26 };
27}
28
13namespace HLE { 29namespace HLE {
14namespace Applets { 30namespace Applets {
15 31
16static std::unordered_map<Service::APT::AppletId, std::shared_ptr<Applet>> applets; 32static std::unordered_map<Service::APT::AppletId, std::shared_ptr<Applet>> applets;
33static 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.
35static const u64 applet_update_interval_microseconds = 16666;
36std::shared_ptr<Applet> g_current_applet = nullptr; ///< The applet that is currently executing
17 37
18ResultCode Applet::Create(Service::APT::AppletId id) { 38ResultCode Applet::Create(Service::APT::AppletId id) {
19 switch (id) { 39 switch (id) {
@@ -36,5 +56,23 @@ std::shared_ptr<Applet> Applet::Get(Service::APT::AppletId id) {
36 return nullptr; 56 return nullptr;
37} 57}
38 58
59/// Handles updating the current Applet every time it's called.
60static void AppletUpdateEvent(u64, int cycles_late) {
61 if (g_current_applet && g_current_applet->IsRunning())
62 g_current_applet->Update();
63
64 CoreTiming::ScheduleEvent(usToCycles(applet_update_interval) - cycles_late,
65 applet_update_event);
66}
67
68void Init() {
69 applet_update_event = CoreTiming::RegisterEvent("HLE Applet Update Event", AppletUpdateEvent);
70 CoreTiming::ScheduleEvent(usToCycles(applet_update_interval), applet_update_event);
71}
72
73void Shutdown() {
74 CoreTiming::UnscheduleEvent(applet_update_event, 0);
75}
76
39} 77}
40} // namespace 78} // namespace