diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/hle/applets/applet.cpp | 36 | ||||
| -rw-r--r-- | src/core/hle/applets/applet.h | 21 | ||||
| -rw-r--r-- | src/core/hle/applets/swkbd.cpp | 13 | ||||
| -rw-r--r-- | src/core/hle/applets/swkbd.h | 18 | ||||
| -rw-r--r-- | src/core/hle/service/apt/apt.cpp | 4 | ||||
| -rw-r--r-- | src/core/hle/service/apt/apt.h | 2 | ||||
| -rw-r--r-- | src/core/hle/service/gsp_gpu.h | 2 |
7 files changed, 61 insertions, 35 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 | } |
diff --git a/src/core/hle/applets/applet.h b/src/core/hle/applets/applet.h index f50f7d604..fe537e70d 100644 --- a/src/core/hle/applets/applet.h +++ b/src/core/hle/applets/applet.h | |||
| @@ -12,10 +12,10 @@ | |||
| 12 | namespace HLE { | 12 | namespace HLE { |
| 13 | namespace Applets { | 13 | namespace Applets { |
| 14 | 14 | ||
| 15 | class Applet : public std::enable_shared_from_this<Applet> { | 15 | class Applet { |
| 16 | public: | 16 | public: |
| 17 | virtual ~Applet() {}; | 17 | virtual ~Applet() { } |
| 18 | Applet(Service::APT::AppletId id) : id(id) {}; | 18 | Applet(Service::APT::AppletId id) : id(id) { } |
| 19 | 19 | ||
| 20 | /** | 20 | /** |
| 21 | * Creates an instance of the Applet subclass identified by the parameter. | 21 | * Creates an instance of the Applet subclass identified by the parameter. |
| @@ -37,25 +37,33 @@ public: | |||
| 37 | * @param parameter Parameter data to handle. | 37 | * @param parameter Parameter data to handle. |
| 38 | * @returns ResultCode Whether the operation was successful or not. | 38 | * @returns ResultCode Whether the operation was successful or not. |
| 39 | */ | 39 | */ |
| 40 | virtual ResultCode ReceiveParameter(Service::APT::MessageParameter const& parameter) = 0; | 40 | virtual ResultCode ReceiveParameter(const Service::APT::MessageParameter& parameter) = 0; |
| 41 | 41 | ||
| 42 | /** | 42 | /** |
| 43 | * Handles the Applet start event, triggered from the application. | 43 | * Handles the Applet start event, triggered from the application. |
| 44 | * @param parameter Parameter data to handle. | 44 | * @param parameter Parameter data to handle. |
| 45 | * @returns ResultCode Whether the operation was successful or not. | 45 | * @returns ResultCode Whether the operation was successful or not. |
| 46 | */ | 46 | */ |
| 47 | virtual ResultCode Start(Service::APT::AppletStartupParameter const& parameter) = 0; | 47 | ResultCode Start(const Service::APT::AppletStartupParameter& parameter); |
| 48 | 48 | ||
| 49 | /** | 49 | /** |
| 50 | * Whether the applet is currently executing instead of the host application or not. | 50 | * Whether the applet is currently executing instead of the host application or not. |
| 51 | */ | 51 | */ |
| 52 | virtual bool IsRunning() = 0; | 52 | virtual bool IsRunning() const = 0; |
| 53 | 53 | ||
| 54 | /** | 54 | /** |
| 55 | * Handles an update tick for the Applet, lets it update the screen, send commands, etc. | 55 | * Handles an update tick for the Applet, lets it update the screen, send commands, etc. |
| 56 | */ | 56 | */ |
| 57 | virtual void Update() = 0; | 57 | virtual void Update() = 0; |
| 58 | 58 | ||
| 59 | protected: | ||
| 60 | /** | ||
| 61 | * Handles the Applet start event, triggered from the application. | ||
| 62 | * @param parameter Parameter data to handle. | ||
| 63 | * @returns ResultCode Whether the operation was successful or not. | ||
| 64 | */ | ||
| 65 | virtual ResultCode StartImpl(const Service::APT::AppletStartupParameter& parameter) = 0; | ||
| 66 | |||
| 59 | Service::APT::AppletId id; ///< Id of this Applet | 67 | Service::APT::AppletId id; ///< Id of this Applet |
| 60 | }; | 68 | }; |
| 61 | 69 | ||
| @@ -65,6 +73,5 @@ void Init(); | |||
| 65 | /// Shuts down the HLE applets | 73 | /// Shuts down the HLE applets |
| 66 | void Shutdown(); | 74 | void Shutdown(); |
| 67 | 75 | ||
| 68 | extern std::shared_ptr<Applet> g_current_applet; ///< Applet that is currently executing | ||
| 69 | } | 76 | } |
| 70 | } // namespace | 77 | } // namespace |
diff --git a/src/core/hle/applets/swkbd.cpp b/src/core/hle/applets/swkbd.cpp index b800e0eb4..7431ebcf8 100644 --- a/src/core/hle/applets/swkbd.cpp +++ b/src/core/hle/applets/swkbd.cpp | |||
| @@ -4,6 +4,7 @@ | |||
| 4 | 4 | ||
| 5 | #include "common/assert.h" | 5 | #include "common/assert.h" |
| 6 | #include "common/logging/log.h" | 6 | #include "common/logging/log.h" |
| 7 | #include "common/string_util.h" | ||
| 7 | 8 | ||
| 8 | #include "core/hle/applets/swkbd.h" | 9 | #include "core/hle/applets/swkbd.h" |
| 9 | #include "core/hle/service/hid/hid.h" | 10 | #include "core/hle/service/hid/hid.h" |
| @@ -33,7 +34,7 @@ ResultCode SoftwareKeyboard::ReceiveParameter(Service::APT::MessageParameter con | |||
| 33 | Service::APT::MessageParameter result; | 34 | Service::APT::MessageParameter result; |
| 34 | // The buffer passed in parameter contains the data returned by GSPGPU::ImportDisplayCaptureInfo | 35 | // The buffer passed in parameter contains the data returned by GSPGPU::ImportDisplayCaptureInfo |
| 35 | result.signal = static_cast<u32>(Service::APT::SignalType::LibAppFinished); | 36 | result.signal = static_cast<u32>(Service::APT::SignalType::LibAppFinished); |
| 36 | result.data = nullptr; | 37 | result.data = nullptr; |
| 37 | result.buffer_size = 0; | 38 | result.buffer_size = 0; |
| 38 | result.destination_id = static_cast<u32>(Service::APT::AppletId::Application); | 39 | result.destination_id = static_cast<u32>(Service::APT::AppletId::Application); |
| 39 | result.sender_id = static_cast<u32>(id); | 40 | result.sender_id = static_cast<u32>(id); |
| @@ -43,7 +44,9 @@ ResultCode SoftwareKeyboard::ReceiveParameter(Service::APT::MessageParameter con | |||
| 43 | return RESULT_SUCCESS; | 44 | return RESULT_SUCCESS; |
| 44 | } | 45 | } |
| 45 | 46 | ||
| 46 | ResultCode SoftwareKeyboard::Start(Service::APT::AppletStartupParameter const& parameter) { | 47 | ResultCode SoftwareKeyboard::StartImpl(Service::APT::AppletStartupParameter const& parameter) { |
| 48 | ASSERT_MSG(parameter.buffer_size == sizeof(config), "The size of the parameter (SoftwareKeyboardConfig) is wrong"); | ||
| 49 | |||
| 47 | memcpy(&config, parameter.data, parameter.buffer_size); | 50 | memcpy(&config, parameter.data, parameter.buffer_size); |
| 48 | text_memory = boost::static_pointer_cast<Kernel::SharedMemory, Kernel::Object>(parameter.object); | 51 | text_memory = boost::static_pointer_cast<Kernel::SharedMemory, Kernel::Object>(parameter.object); |
| 49 | 52 | ||
| @@ -52,9 +55,7 @@ ResultCode SoftwareKeyboard::Start(Service::APT::AppletStartupParameter const& p | |||
| 52 | 55 | ||
| 53 | DrawScreenKeyboard(); | 56 | DrawScreenKeyboard(); |
| 54 | 57 | ||
| 55 | // Update the current applet so we can get update events | ||
| 56 | started = true; | 58 | started = true; |
| 57 | g_current_applet = shared_from_this(); | ||
| 58 | return RESULT_SUCCESS; | 59 | return RESULT_SUCCESS; |
| 59 | } | 60 | } |
| 60 | 61 | ||
| @@ -72,7 +73,7 @@ void SoftwareKeyboard::Update() { | |||
| 72 | config.text_length = 6; | 73 | config.text_length = 6; |
| 73 | config.text_offset = 0; | 74 | config.text_offset = 0; |
| 74 | 75 | ||
| 75 | // TODO(Subv): We're finalizing the applet immediately after it's started, | 76 | // TODO(Subv): We're finalizing the applet immediately after it's started, |
| 76 | // but we should defer this call until after all the input has been collected. | 77 | // but we should defer this call until after all the input has been collected. |
| 77 | Finalize(); | 78 | Finalize(); |
| 78 | } | 79 | } |
| @@ -98,8 +99,6 @@ void SoftwareKeyboard::Finalize() { | |||
| 98 | Service::APT::SendParameter(message); | 99 | Service::APT::SendParameter(message); |
| 99 | 100 | ||
| 100 | started = false; | 101 | started = false; |
| 101 | // Unset the current applet, we are not running anymore | ||
| 102 | g_current_applet = nullptr; | ||
| 103 | } | 102 | } |
| 104 | 103 | ||
| 105 | } | 104 | } |
diff --git a/src/core/hle/applets/swkbd.h b/src/core/hle/applets/swkbd.h index 5970390c6..98e81c48a 100644 --- a/src/core/hle/applets/swkbd.h +++ b/src/core/hle/applets/swkbd.h | |||
| @@ -42,17 +42,21 @@ struct SoftwareKeyboardConfig { | |||
| 42 | INSERT_PADDING_BYTES(0x2B6); | 42 | INSERT_PADDING_BYTES(0x2B6); |
| 43 | }; | 43 | }; |
| 44 | 44 | ||
| 45 | /** | ||
| 46 | * The size of this structure (0x400) has been verified via reverse engineering of multiple games | ||
| 47 | * that use the software keyboard. | ||
| 48 | */ | ||
| 45 | static_assert(sizeof(SoftwareKeyboardConfig) == 0x400, "Software Keyboard Config size is wrong"); | 49 | static_assert(sizeof(SoftwareKeyboardConfig) == 0x400, "Software Keyboard Config size is wrong"); |
| 46 | 50 | ||
| 47 | class SoftwareKeyboard : public Applet { | 51 | class SoftwareKeyboard final : public Applet { |
| 48 | public: | 52 | public: |
| 49 | SoftwareKeyboard(Service::APT::AppletId id); | 53 | SoftwareKeyboard(Service::APT::AppletId id); |
| 50 | ~SoftwareKeyboard() {} | 54 | ~SoftwareKeyboard() {} |
| 51 | 55 | ||
| 52 | ResultCode ReceiveParameter(Service::APT::MessageParameter const& parameter) override; | 56 | ResultCode ReceiveParameter(const Service::APT::MessageParameter& parameter) override; |
| 53 | ResultCode Start(Service::APT::AppletStartupParameter const& parameter) override; | 57 | ResultCode StartImpl(const Service::APT::AppletStartupParameter& parameter) override; |
| 54 | void Update() override; | 58 | void Update() override; |
| 55 | bool IsRunning() override { return started; } | 59 | bool IsRunning() const override { return started; } |
| 56 | 60 | ||
| 57 | /** | 61 | /** |
| 58 | * Draws a keyboard to the current bottom screen framebuffer. | 62 | * Draws a keyboard to the current bottom screen framebuffer. |
| @@ -65,13 +69,13 @@ public: | |||
| 65 | */ | 69 | */ |
| 66 | void Finalize(); | 70 | void Finalize(); |
| 67 | 71 | ||
| 68 | /// TODO(Subv): Find out what this is actually used for. | 72 | /// TODO(Subv): Find out what this is actually used for. |
| 69 | // It is believed that the application stores the current screen image here. | 73 | /// It is believed that the application stores the current screen image here. |
| 70 | Kernel::SharedPtr<Kernel::SharedMemory> framebuffer_memory; | 74 | Kernel::SharedPtr<Kernel::SharedMemory> framebuffer_memory; |
| 71 | 75 | ||
| 72 | /// SharedMemory where the output text will be stored | 76 | /// SharedMemory where the output text will be stored |
| 73 | Kernel::SharedPtr<Kernel::SharedMemory> text_memory; | 77 | Kernel::SharedPtr<Kernel::SharedMemory> text_memory; |
| 74 | 78 | ||
| 75 | /// Configuration of this instance of the SoftwareKeyboard, as received from the application | 79 | /// Configuration of this instance of the SoftwareKeyboard, as received from the application |
| 76 | SoftwareKeyboardConfig config; | 80 | SoftwareKeyboardConfig config; |
| 77 | 81 | ||
diff --git a/src/core/hle/service/apt/apt.cpp b/src/core/hle/service/apt/apt.cpp index 783fad7ca..b364beed9 100644 --- a/src/core/hle/service/apt/apt.cpp +++ b/src/core/hle/service/apt/apt.cpp | |||
| @@ -44,7 +44,7 @@ static u32 cpu_percent; ///< CPU time available to the running application | |||
| 44 | /// Parameter data to be returned in the next call to Glance/ReceiveParameter | 44 | /// Parameter data to be returned in the next call to Glance/ReceiveParameter |
| 45 | static MessageParameter next_parameter; | 45 | static MessageParameter next_parameter; |
| 46 | 46 | ||
| 47 | void SendParameter(MessageParameter const& parameter) { | 47 | void SendParameter(const MessageParameter& parameter) { |
| 48 | next_parameter = parameter; | 48 | next_parameter = parameter; |
| 49 | // Signal the event to let the application know that a new parameter is ready to be read | 49 | // Signal the event to let the application know that a new parameter is ready to be read |
| 50 | parameter_event->Signal(); | 50 | parameter_event->Signal(); |
| @@ -338,7 +338,7 @@ void StartLibraryApplet(Service::Interface* self) { | |||
| 338 | u32* cmd_buff = Kernel::GetCommandBuffer(); | 338 | u32* cmd_buff = Kernel::GetCommandBuffer(); |
| 339 | AppletId applet_id = static_cast<AppletId>(cmd_buff[1]); | 339 | AppletId applet_id = static_cast<AppletId>(cmd_buff[1]); |
| 340 | std::shared_ptr<HLE::Applets::Applet> applet = HLE::Applets::Applet::Get(applet_id); | 340 | std::shared_ptr<HLE::Applets::Applet> applet = HLE::Applets::Applet::Get(applet_id); |
| 341 | 341 | ||
| 342 | LOG_DEBUG(Service_APT, "called applet_id=%08X", applet_id); | 342 | LOG_DEBUG(Service_APT, "called applet_id=%08X", applet_id); |
| 343 | 343 | ||
| 344 | if (applet == nullptr) { | 344 | if (applet == nullptr) { |
diff --git a/src/core/hle/service/apt/apt.h b/src/core/hle/service/apt/apt.h index 510193cc8..9f0802508 100644 --- a/src/core/hle/service/apt/apt.h +++ b/src/core/hle/service/apt/apt.h | |||
| @@ -63,7 +63,7 @@ enum class AppletId : u32 { | |||
| 63 | }; | 63 | }; |
| 64 | 64 | ||
| 65 | /// Send a parameter to the currently-running application, which will read it via ReceiveParameter | 65 | /// Send a parameter to the currently-running application, which will read it via ReceiveParameter |
| 66 | void SendParameter(MessageParameter const& parameter); | 66 | void SendParameter(const MessageParameter& parameter); |
| 67 | 67 | ||
| 68 | /** | 68 | /** |
| 69 | * APT::Initialize service function | 69 | * APT::Initialize service function |
diff --git a/src/core/hle/service/gsp_gpu.h b/src/core/hle/service/gsp_gpu.h index 9fcf6f06f..268089fdd 100644 --- a/src/core/hle/service/gsp_gpu.h +++ b/src/core/hle/service/gsp_gpu.h | |||
| @@ -176,7 +176,7 @@ void SignalInterrupt(InterruptId interrupt_id); | |||
| 176 | void SetBufferSwap(u32 screen_id, const FrameBufferInfo& info); | 176 | void SetBufferSwap(u32 screen_id, const FrameBufferInfo& info); |
| 177 | 177 | ||
| 178 | /** | 178 | /** |
| 179 | * Retrieves the framebuffer info stored in the GSP shared memory for the | 179 | * Retrieves the framebuffer info stored in the GSP shared memory for the |
| 180 | * specified screen index and thread id. | 180 | * specified screen index and thread id. |
| 181 | * @param thread_id GSP thread id of the process that accesses the structure that we are requesting. | 181 | * @param thread_id GSP thread id of the process that accesses the structure that we are requesting. |
| 182 | * @param screen_index Index of the screen we are requesting (Top = 0, Bottom = 1). | 182 | * @param screen_index Index of the screen we are requesting (Top = 0, Bottom = 1). |