Skip to content

Commit

Permalink
NFC stuffs
Browse files Browse the repository at this point in the history
  • Loading branch information
wheremyfoodat committed Aug 21, 2023
1 parent 3c7b9bb commit 3f2a546
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions include/services/nfc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ class NFCService {

Old3DSAdapterStatus adapterStatus;
TagStatus tagStatus;
bool initialized = false;

// Service commands
void communicationGetResult(u32 messagePointer);
void communicationGetStatus(u32 messagePointer);
void initialize(u32 messagePointer);
void getTagInRangeEvent(u32 messagePointer);
Expand Down
7 changes: 6 additions & 1 deletion src/core/services/nfc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace NFCCommands {
GetTagOutOfRangeEvent = 0x000C0000,
GetTagState = 0x000D0000,
CommunicationGetStatus = 0x000F0000,
CommunicationGetResult = 0x00120000,
};
}

Expand All @@ -20,6 +21,7 @@ void NFCService::reset() {

adapterStatus = Old3DSAdapterStatus::Idle;
tagStatus = TagStatus::NotInitialized;
initialized = false;
}

void NFCService::handleSyncRequest(u32 messagePointer) {
Expand All @@ -42,6 +44,7 @@ void NFCService::initialize(u32 messagePointer) {

adapterStatus = Old3DSAdapterStatus::InitializationComplete;
tagStatus = TagStatus::Initialized;
initialized = true;
// TODO: This should error if already initialized. Also sanitize type.
mem.write32(messagePointer, IPC::responseHeader(0x1, 1, 0));
mem.write32(messagePointer + 4, Result::Success);
Expand Down Expand Up @@ -93,7 +96,7 @@ void NFCService::getTagState(u32 messagePointer) {
void NFCService::communicationGetStatus(u32 messagePointer) {
log("NFC::CommunicationGetStatus");

if (adapterStatus != Old3DSAdapterStatus::InitializationComplete) {
if (!initialized) {
Helpers::warn("NFC::CommunicationGetStatus: Old 3DS NFC Adapter not initialized\n");
}

Expand All @@ -104,6 +107,7 @@ void NFCService::communicationGetStatus(u32 messagePointer) {

void NFCService::startCommunication(u32 messagePointer) {
log("NFC::StartCommunication\n");
// adapterStatus = Old3DSAdapterStatus::Active;
// TODO: Actually start communication when we emulate amiibo

mem.write32(messagePointer, IPC::responseHeader(0x3, 1, 0));
Expand All @@ -112,6 +116,7 @@ void NFCService::startCommunication(u32 messagePointer) {

void NFCService::stopCommunication(u32 messagePointer) {
log("NFC::StopCommunication\n");
adapterStatus = Old3DSAdapterStatus::InitializationComplete;
// TODO: Actually stop communication when we emulate amiibo

mem.write32(messagePointer, IPC::responseHeader(0x4, 1, 0));
Expand Down

0 comments on commit 3f2a546

Please sign in to comment.