[APT] Properly forward parameters in SendParameter

This commit is contained in:
wheremyfoodat 2023-11-12 21:07:44 +02:00
parent 5df44e0c4f
commit bd1d7b7a81
7 changed files with 30 additions and 11 deletions

View file

@ -67,7 +67,7 @@ namespace Applets {
struct Parameter {
u32 senderID;
u32 destID;
APTSignal signal;
u32 signal;
std::vector<u8> data;
};
@ -82,7 +82,7 @@ namespace Applets {
// Called by APT::StartLibraryApplet and similar
virtual Result::HorizonResult start() = 0;
// Transfer parameters from application -> applet
virtual Result::HorizonResult receiveParameter() = 0;
virtual Result::HorizonResult receiveParameter(const Parameter& parameter) = 0;
virtual void reset() = 0;
AppletBase(Memory& mem, std::optional<Parameter>& nextParam) : mem(mem), nextParameter(nextParam) {}

View file

@ -5,7 +5,7 @@ namespace Applets {
public:
virtual const char* name() override { return "Mii Selector"; }
virtual Result::HorizonResult start() override;
virtual Result::HorizonResult receiveParameter() override;
virtual Result::HorizonResult receiveParameter(const Applets::Parameter& parameter) override;
virtual void reset() override;
MiiSelectorApplet(Memory& memory, std::optional<Parameter>& nextParam) : AppletBase(memory, nextParam) {}

View file

@ -5,7 +5,7 @@ namespace Applets {
public:
virtual const char* name() override { return "Software Keyboard"; }
virtual Result::HorizonResult start() override;
virtual Result::HorizonResult receiveParameter() override;
virtual Result::HorizonResult receiveParameter(const Applets::Parameter& parameter) override;
virtual void reset() override;
SoftwareKeyboardApplet(Memory& memory, std::optional<Parameter>& nextParam) : AppletBase(memory, nextParam) {}

View file

@ -28,7 +28,7 @@ Applets::Parameter AppletManager::glanceParameter() {
// Copy parameter
Applets::Parameter param = nextParameter.value();
// APT module clears next parameter even for GlanceParameter for these 2 signals
if (param.signal == APTSignal::DspWakeup || param.signal == APTSignal::DspSleep) {
if (param.signal == static_cast<u32>(APTSignal::DspWakeup) || param.signal == static_cast<u32>(APTSignal::DspSleep)) {
nextParameter = std::nullopt;
}
@ -37,7 +37,12 @@ Applets::Parameter AppletManager::glanceParameter() {
// Default return value. This is legacy code from before applets were implemented. TODO: Update it
else {
return Applets::Parameter{.senderID = 0, .destID = Applets::AppletIDs::Application, .signal = APTSignal::Wakeup, .data = {}};
return Applets::Parameter{
.senderID = 0,
.destID = Applets::AppletIDs::Application,
.signal = static_cast<u32>(APTSignal::Wakeup),
.data = {},
};
}
}

View file

@ -5,7 +5,7 @@ using namespace Applets;
void MiiSelectorApplet::reset() {}
Result::HorizonResult MiiSelectorApplet::start() { return Result::Success; }
Result::HorizonResult MiiSelectorApplet::receiveParameter() {
Result::HorizonResult MiiSelectorApplet::receiveParameter(const Applets::Parameter& parameter) {
Helpers::warn("Mii Selector: Unimplemented ReceiveParameter");
return Result::Success;
}

View file

@ -5,13 +5,13 @@ using namespace Applets;
void SoftwareKeyboardApplet::reset() {}
Result::HorizonResult SoftwareKeyboardApplet::start() { return Result::Success; }
Result::HorizonResult SoftwareKeyboardApplet::receiveParameter() {
Result::HorizonResult SoftwareKeyboardApplet::receiveParameter(const Applets::Parameter& parameter) {
Helpers::warn("Software keyboard: Unimplemented ReceiveParameter");
Applets::Parameter param = Applets::Parameter{
.senderID = AppletIDs::SoftwareKeyboard,
.senderID = parameter.destID,
.destID = AppletIDs::Application,
.signal = APTSignal::Response,
.signal = static_cast<u32>(APTSignal::Response),
.data = {},
};

View file

@ -234,7 +234,21 @@ void APTService::sendParameter(u32 messagePointer) {
if (destApplet == nullptr) {
Helpers::warn("APT::SendParameter: Unimplemented dest applet ID");
} else {
auto result = destApplet->receiveParameter();
// Construct parameter, send it to applet
Applets::Parameter param;
param.senderID = sourceAppID;
param.destID = destAppID;
param.signal = cmd;
// Fetch parameter data buffer
param.data.reserve(paramSize);
u32 pointer = parameterPointer;
for (u32 i = 0; i < paramSize; i++) {
param.data.push_back(mem.read8(pointer++));
}
auto result = destApplet->receiveParameter(param);
}
if (resumeEvent.has_value()) {