From 3110da1fd6c27d9ffcd6677d7efde1d58acb12ec Mon Sep 17 00:00:00 2001 From: wheremyfoodat <44909372+wheremyfoodat@users.noreply.github.com> Date: Fri, 8 Sep 2023 19:01:44 +0300 Subject: [PATCH] Add amiibo loading interface --- include/emulator.hpp | 1 + include/services/nfc.hpp | 6 +++++- include/services/service_manager.hpp | 1 + src/core/services/nfc.cpp | 2 ++ src/emulator.cpp | 14 +++++++++++++- 5 files changed, 22 insertions(+), 2 deletions(-) diff --git a/include/emulator.hpp b/include/emulator.hpp index 770d78df..47358a95 100644 --- a/include/emulator.hpp +++ b/include/emulator.hpp @@ -98,6 +98,7 @@ class Emulator { void pause(); // Pause the emulator void togglePause(); + bool loadAmiibo(const std::filesystem::path& path); bool loadROM(const std::filesystem::path& path); bool loadNCSD(const std::filesystem::path& path, ROMType type); bool load3DSX(const std::filesystem::path& path); diff --git a/include/services/nfc.hpp b/include/services/nfc.hpp index e65c42c1..94667f21 100644 --- a/include/services/nfc.hpp +++ b/include/services/nfc.hpp @@ -1,4 +1,6 @@ #pragma once +#include + #include "helpers.hpp" #include "kernel_types.hpp" #include "logger.hpp" @@ -49,8 +51,10 @@ class NFCService { void startTagScanning(u32 messagePointer); void stopCommunication(u32 messagePointer); -public: + public: NFCService(Memory& mem, Kernel& kernel) : mem(mem), kernel(kernel) {} void reset(); void handleSyncRequest(u32 messagePointer); + + bool loadAmiibo(const std::filesystem::path& path); }; \ No newline at end of file diff --git a/include/services/service_manager.hpp b/include/services/service_manager.hpp index 42025a3e..aa559ee8 100644 --- a/include/services/service_manager.hpp +++ b/include/services/service_manager.hpp @@ -104,4 +104,5 @@ class ServiceManager { // Input function wrappers HIDService& getHID() { return hid; } + NFCService& getNFC() { return nfc; } }; diff --git a/src/core/services/nfc.cpp b/src/core/services/nfc.cpp index 4f71556c..0cb3e699 100644 --- a/src/core/services/nfc.cpp +++ b/src/core/services/nfc.cpp @@ -43,6 +43,8 @@ void NFCService::handleSyncRequest(u32 messagePointer) { } } +bool NFCService::loadAmiibo(const std::filesystem::path& path) { return true; } + void NFCService::initialize(u32 messagePointer) { const u8 type = mem.read8(messagePointer + 4); log("NFC::Initialize (type = %d)\n", type); diff --git a/src/emulator.cpp b/src/emulator.cpp index 2f8c81cc..ec99b0fe 100644 --- a/src/emulator.cpp +++ b/src/emulator.cpp @@ -353,7 +353,14 @@ void Emulator::run() { char* droppedDir = event.drop.file; if (droppedDir) { - loadROM(droppedDir); + const std::filesystem::path path(droppedDir); + + if (path.extension() == ".amiibo") { + loadAmiibo(path); + } else { + loadROM(path); + } + SDL_free(droppedDir); } break; @@ -478,6 +485,11 @@ bool Emulator::loadROM(const std::filesystem::path& path) { return success; } +bool Emulator::loadAmiibo(const std::filesystem::path& path) { + NFCService& nfc = kernel.getServiceManager().getNFC(); + return nfc.loadAmiibo(path); +} + // Used for loading both CXI and NCSD files since they are both so similar and use the same interface // (We promote CXI files to NCSD internally for ease) bool Emulator::loadNCSD(const std::filesystem::path& path, ROMType type) {