mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-07 14:45:41 +12:00
Implement NFC::CommunicationGetStatus
This commit is contained in:
parent
7bbf37bb63
commit
59649b27a0
2 changed files with 27 additions and 1 deletions
|
@ -14,10 +14,19 @@ class NFCService {
|
|||
Kernel& kernel;
|
||||
MAKE_LOG_FUNCTION(log, nfcLogger)
|
||||
|
||||
enum class Old3DSAdapterStatus : s32 {
|
||||
AttemptingToInitialize = 1,
|
||||
InitializationComplete = 2,
|
||||
// Other values are errors according to 3DBrew, set the not initialized error to -1 until we find out what it should be
|
||||
NotInitialized = -1,
|
||||
};
|
||||
|
||||
// Kernel events signaled when an NFC tag goes in and out of range respectively
|
||||
std::optional<Handle> tagInRangeEvent, tagOutOfRangeEvent;
|
||||
Old3DSAdapterStatus adapterStatus;
|
||||
|
||||
// Service commands
|
||||
void communicationGetStatus(u32 messagePointer);
|
||||
void initialize(u32 messagePointer);
|
||||
void getTagInRangeEvent(u32 messagePointer);
|
||||
void getTagOutOfRangeEvent(u32 messagePointer);
|
||||
|
|
|
@ -6,18 +6,22 @@ namespace NFCCommands {
|
|||
enum : u32 {
|
||||
Initialize = 0x00010040,
|
||||
GetTagInRangeEvent = 0x000B0000,
|
||||
GetTagOutOfRangeEvent = 0x000C0000
|
||||
GetTagOutOfRangeEvent = 0x000C0000,
|
||||
CommunicationGetStatus = 0x000F0000,
|
||||
};
|
||||
}
|
||||
|
||||
void NFCService::reset() {
|
||||
tagInRangeEvent = std::nullopt;
|
||||
tagOutOfRangeEvent = std::nullopt;
|
||||
|
||||
adapterStatus = Old3DSAdapterStatus::NotInitialized;
|
||||
}
|
||||
|
||||
void NFCService::handleSyncRequest(u32 messagePointer) {
|
||||
const u32 command = mem.read32(messagePointer);
|
||||
switch (command) {
|
||||
case NFCCommands::CommunicationGetStatus: communicationGetStatus(messagePointer); break;
|
||||
case NFCCommands::Initialize: initialize(messagePointer); break;
|
||||
case NFCCommands::GetTagInRangeEvent: getTagInRangeEvent(messagePointer); break;
|
||||
case NFCCommands::GetTagOutOfRangeEvent: getTagOutOfRangeEvent(messagePointer); break;
|
||||
|
@ -29,6 +33,7 @@ void NFCService::initialize(u32 messagePointer) {
|
|||
const u8 type = mem.read8(messagePointer + 4);
|
||||
log("NFC::Initialize (type = %d)\n", type);
|
||||
|
||||
adapterStatus = Old3DSAdapterStatus::InitializationComplete;
|
||||
// TODO: This should error if already initialized. Also sanitize type.
|
||||
mem.write32(messagePointer, IPC::responseHeader(0x1, 1, 0));
|
||||
mem.write32(messagePointer + 4, Result::Success);
|
||||
|
@ -67,4 +72,16 @@ void NFCService::getTagOutOfRangeEvent(u32 messagePointer) {
|
|||
mem.write32(messagePointer + 4, Result::Success);
|
||||
// TODO: Translation descriptor here
|
||||
mem.write32(messagePointer + 12, tagOutOfRangeEvent.value());
|
||||
}
|
||||
|
||||
void NFCService::communicationGetStatus(u32 messagePointer) {
|
||||
log("NFC::CommunicationGetStatus");
|
||||
|
||||
if (adapterStatus != Old3DSAdapterStatus::InitializationComplete) {
|
||||
Helpers::warn("NFC::CommunicationGetStatus: Old 3DS NFC Adapter not initialized\n");
|
||||
}
|
||||
|
||||
mem.write32(messagePointer, IPC::responseHeader(0xF, 2, 0));
|
||||
mem.write32(messagePointer + 4, Result::Success);
|
||||
mem.write8(messagePointer + 8, static_cast<u32>(adapterStatus));
|
||||
}
|
Loading…
Add table
Reference in a new issue