[ACT/MIC/NFC] Stub function for Captain Toad

This commit is contained in:
wheremyfoodat 2023-04-24 21:33:59 +03:00
parent 269efc3c43
commit 3935820c05
11 changed files with 144 additions and 9 deletions

View file

@ -64,6 +64,7 @@ set(SERVICE_SOURCE_FILES src/core/services/service_manager.cpp src/core/services
src/core/services/ac.cpp src/core/services/am.cpp src/core/services/boss.cpp
src/core/services/frd.cpp src/core/services/nim.cpp src/core/services/shared_font.cpp
src/core/services/y2r.cpp src/core/services/cam.cpp src/core/services/ldr_ro.cpp
src/core/services/act.cpp src/core/services/nfc.cpp
)
set(PICA_SOURCE_FILES src/core/PICA/gpu.cpp src/core/PICA/regs.cpp src/core/PICA/shader_unit.cpp
src/core/PICA/shader_interpreter.cpp
@ -92,7 +93,7 @@ set(HEADER_FILES include/emulator.hpp include/helpers.hpp include/opengl.hpp inc
include/services/am.hpp include/services/boss.hpp include/services/frd.hpp include/services/nim.hpp
include/fs/archive_ext_save_data.hpp include/services/shared_font.hpp include/fs/archive_ncch.hpp
include/renderer_gl/textures.hpp include/colour.hpp include/services/y2r.hpp include/services/cam.hpp
include/services/ldr_ro.hpp include/ipc.hpp
include/services/ldr_ro.hpp include/ipc.hpp include/services/act.hpp include/services/nfc.hpp
)
set(THIRD_PARTY_SOURCE_FILES third_party/imgui/imgui.cpp

View file

@ -11,6 +11,7 @@ namespace KernelHandles {
CurrentThread = 0xFFFF8000, // Used by the original kernel
CurrentProcess = 0xFFFF8001, // Used by the original kernel
AC, // Something network related
ACT, // Handles NNID accounts
AM, // Application manager
APT, // App Title something service?
BOSS, // Streetpass stuff?
@ -25,6 +26,7 @@ namespace KernelHandles {
LCD, // LCD service (Used for configuring the displays)
LDR_RO, // Loader service. Used for loading CROs.
MIC, // MIC service (Controls the microphone)
NFC, // NFC (Duh), used for Amiibo
NIM, // Updates, DLC, etc
NDM, // ?????
PTM, // PTM service (Used for accessing various console info, such as battery, shell and pedometer state)
@ -61,6 +63,7 @@ namespace KernelHandles {
static const char* getServiceName(Handle handle) {
switch (handle) {
case AC: return "AC";
case ACT: return "ACT";
case AM: return "AM";
case APT: return "APT";
case BOSS: return "BOSS";
@ -71,11 +74,12 @@ namespace KernelHandles {
case FRD: return "FRD";
case FS: return "FS";
case DSP: return "DSP";
case GPU: return "GPU";
case LCD: return "LCD";
case GPU: return "GSP::GPU";
case LCD: return "GSP::LCD";
case LDR_RO: return "LDR:RO";
case MIC: return "MIC";
case NDM: return "NDM";
case NFC: return "NFC";
case NIM: return "NIM";
case PTM: return "PTM";
case Y2R: return "Y2R";

View file

@ -30,6 +30,7 @@ namespace Log {
// Service loggers
static Logger<false> acLogger;
static Logger<false> actLogger;
static Logger<false> amLogger;
static Logger<false> aptLogger;
static Logger<false> bossLogger;
@ -44,6 +45,7 @@ namespace Log {
static Logger<false> gspLCDLogger;
static Logger<false> ldrLogger;
static Logger<false> micLogger;
static Logger<false> nfcLogger;
static Logger<false> nimLogger;
static Logger<false> ndmLogger;
static Logger<false> ptmLogger;

19
include/services/act.hpp Normal file
View file

@ -0,0 +1,19 @@
#pragma once
#include "helpers.hpp"
#include "kernel_types.hpp"
#include "logger.hpp"
#include "memory.hpp"
class ACTService {
Handle handle = KernelHandles::ACT;
Memory& mem;
MAKE_LOG_FUNCTION(log, actLogger)
// Service commands
void initialize(u32 messagePointer);
public:
ACTService(Memory& mem) : mem(mem) {}
void reset();
void handleSyncRequest(u32 messagePointer);
};

View file

@ -16,6 +16,7 @@ class MICService {
void setGain(u32 messagePointer);
void setPower(u32 messagePointer);
void startSampling(u32 messagePointer);
void theCaptainToadFunction(u32 messagePointer);
u8 gain = 0; // How loud our microphone input signal is
bool micEnabled = false;

19
include/services/nfc.hpp Normal file
View file

@ -0,0 +1,19 @@
#pragma once
#include "helpers.hpp"
#include "kernel_types.hpp"
#include "logger.hpp"
#include "memory.hpp"
class NFCService {
Handle handle = KernelHandles::NFC;
Memory& mem;
MAKE_LOG_FUNCTION(log, nfcLogger)
// Service commands
void initialize(u32 messagePointer);
public:
NFCService(Memory& mem) : mem(mem) {}
void reset();
void handleSyncRequest(u32 messagePointer);
};

View file

@ -5,6 +5,7 @@
#include "logger.hpp"
#include "memory.hpp"
#include "services/ac.hpp"
#include "services/act.hpp"
#include "services/am.hpp"
#include "services/apt.hpp"
#include "services/boss.hpp"
@ -19,6 +20,7 @@
#include "services/gsp_lcd.hpp"
#include "services/ldr_ro.hpp"
#include "services/mic.hpp"
#include "services/nfc.hpp"
#include "services/nim.hpp"
#include "services/ndm.hpp"
#include "services/ptm.hpp"
@ -37,6 +39,7 @@ class ServiceManager {
MAKE_LOG_FUNCTION(log, srvLogger)
ACService ac;
ACTService act;
AMService am;
APTService apt;
BOSSService boss;
@ -51,6 +54,7 @@ class ServiceManager {
LCDService gsp_lcd;
LDRService ldr;
MICService mic;
NFCService nfc;
NIMService nim;
NDMService ndm;
PTMService ptm;

31
src/core/services/act.cpp Normal file
View file

@ -0,0 +1,31 @@
#include "services/act.hpp"
#include "ipc.hpp"
namespace ACTCommands {
enum : u32 {
Initialize = 0x00010084
};
}
namespace Result {
enum : u32 {
Success = 0,
};
}
void ACTService::reset() {}
void ACTService::handleSyncRequest(u32 messagePointer) {
const u32 command = mem.read32(messagePointer);
switch (command) {
case ACTCommands::Initialize: initialize(messagePointer); break;
default: Helpers::panic("ACT service requested. Command: %08X\n", command);
}
}
void ACTService::initialize(u32 messagePointer) {
log("ACT::Initialize");
mem.write32(messagePointer, IPC::responseHeader(0x1, 1, 0));
mem.write32(messagePointer + 4, Result::Success);
}

View file

@ -8,7 +8,8 @@ namespace MICCommands {
SetGain = 0x00080040,
GetGain = 0x00090000,
SetPower = 0x000A0040,
SetClamp = 0x000D0040
SetClamp = 0x000D0040,
CaptainToadFunction = 0x00100040
};
}
@ -33,6 +34,7 @@ void MICService::handleSyncRequest(u32 messagePointer) {
case MICCommands::SetGain: setGain(messagePointer); break;
case MICCommands::SetPower: setPower(messagePointer); break;
case MICCommands::StartSampling: startSampling(messagePointer); break;
case MICCommands::CaptainToadFunction: theCaptainToadFunction(messagePointer); break;
default: Helpers::panic("MIC service requested. Command: %08X\n", command);
}
}
@ -92,4 +94,16 @@ void MICService::startSampling(u32 messagePointer) {
mem.write32(messagePointer, IPC::responseHeader(0x3, 1, 0));
mem.write32(messagePointer + 4, Result::Success);
}
// Found in Captain Toad: Treasure Tracker
// This is what 3DBrew says:
// When the input value is 0, value 1 is written to an u8 MIC module state field.
// Otherwise, value 0 is written there.Normally the input value is non - zero.
// Citra calls it setClientVersion but no idea how they got that
void MICService::theCaptainToadFunction(u32 messagePointer) {
log("MIC: Unknown function 0x00100040\n");
mem.write32(messagePointer, IPC::responseHeader(0x10, 1, 0));
mem.write32(messagePointer + 4, Result::Success);
}

33
src/core/services/nfc.cpp Normal file
View file

@ -0,0 +1,33 @@
#include "services/nfc.hpp"
#include "ipc.hpp"
namespace NFCCommands {
enum : u32 {
Initialize = 0x00010040
};
}
namespace Result {
enum : u32 {
Success = 0,
};
}
void NFCService::reset() {}
void NFCService::handleSyncRequest(u32 messagePointer) {
const u32 command = mem.read32(messagePointer);
switch (command) {
case NFCCommands::Initialize: initialize(messagePointer); break;
default: Helpers::panic("NFC service requested. Command: %08X\n", command);
}
}
void NFCService::initialize(u32 messagePointer) {
const u8 type = mem.read8(messagePointer + 4);
log("NFC::Initialize (type = %d)\n", type);
// TODO: This should error if already initialized. Also sanitize type.
mem.write32(messagePointer, IPC::responseHeader(0x1, 1, 0));
mem.write32(messagePointer + 4, Result::Success);
}

View file

@ -4,15 +4,16 @@
#include "kernel.hpp"
ServiceManager::ServiceManager(std::array<u32, 16>& regs, Memory& mem, GPU& gpu, u32& currentPID, Kernel& kernel)
: regs(regs), mem(mem), kernel(kernel), ac(mem), am(mem), boss(mem), apt(mem, kernel), cam(mem), cecd(mem), cfg(mem),
dsp(mem, kernel), hid(mem), frd(mem), fs(mem, kernel), gsp_gpu(mem, gpu, kernel, currentPID), gsp_lcd(mem), ldr(mem),
mic(mem), nim(mem), ndm(mem), ptm(mem), y2r(mem, kernel) {}
: regs(regs), mem(mem), kernel(kernel), ac(mem), am(mem), boss(mem), act(mem), apt(mem, kernel), cam(mem), cecd(mem),
cfg(mem), dsp(mem, kernel), hid(mem), frd(mem), fs(mem, kernel), gsp_gpu(mem, gpu, kernel, currentPID), gsp_lcd(mem),
ldr(mem), mic(mem), nfc(mem), nim(mem), ndm(mem), ptm(mem), y2r(mem, kernel) {}
static constexpr int MAX_NOTIFICATION_COUNT = 16;
// Reset every single service
void ServiceManager::reset() {
ac.reset();
act.reset();
am.reset();
apt.reset();
boss.reset();
@ -86,6 +87,7 @@ void ServiceManager::registerClient(u32 messagePointer) {
static std::map<std::string, Handle> serviceMap = {
{ "ac:u", KernelHandles::AC },
{ "act:u", KernelHandles::ACT },
{ "am:app", KernelHandles::AM },
{ "APT:S", KernelHandles::APT }, // TODO: APT:A, APT:S and APT:U are slightly different
{ "APT:A", KernelHandles::APT },
@ -103,6 +105,7 @@ static std::map<std::string, Handle> serviceMap = {
{ "ldr:ro", KernelHandles::LDR_RO },
{ "mic:u", KernelHandles::MIC },
{ "ndm:u", KernelHandles::NDM },
{ "nfc:u", KernelHandles::NFC },
{ "nim:aoc", KernelHandles::NIM },
{ "ptm:u", KernelHandles::PTM }, // TODO: ptm:u and ptm:sysm have very different command sets
{ "ptm:sysm", KernelHandles::PTM },
@ -162,10 +165,14 @@ void ServiceManager::subscribe(u32 messagePointer) {
void ServiceManager::sendCommandToService(u32 messagePointer, Handle handle) {
switch (handle) {
// Breaking alphabetical order a bit to place the ones I think are most common at the top
case KernelHandles::GPU: [[likely]] gsp_gpu.handleSyncRequest(messagePointer); break;
case KernelHandles::FS: [[likely]] fs.handleSyncRequest(messagePointer); break;
case KernelHandles::APT: [[likely]] apt.handleSyncRequest(messagePointer); break;
case KernelHandles::AC: ac.handleSyncRequest(messagePointer); break;
case KernelHandles::ACT: act.handleSyncRequest(messagePointer); break;
case KernelHandles::AM: am.handleSyncRequest(messagePointer); break;
case KernelHandles::APT: apt.handleSyncRequest(messagePointer); break;
case KernelHandles::BOSS: boss.handleSyncRequest(messagePointer); break;
case KernelHandles::CAM: cam.handleSyncRequest(messagePointer); break;
case KernelHandles::CECD: cecd.handleSyncRequest(messagePointer); break;
@ -173,10 +180,10 @@ void ServiceManager::sendCommandToService(u32 messagePointer, Handle handle) {
case KernelHandles::DSP: dsp.handleSyncRequest(messagePointer); break;
case KernelHandles::HID: hid.handleSyncRequest(messagePointer); break;
case KernelHandles::FRD: frd.handleSyncRequest(messagePointer); break;
case KernelHandles::FS: fs.handleSyncRequest(messagePointer); break;
case KernelHandles::LCD: gsp_lcd.handleSyncRequest(messagePointer); break;
case KernelHandles::LDR_RO: ldr.handleSyncRequest(messagePointer); break;
case KernelHandles::MIC: mic.handleSyncRequest(messagePointer); break;
case KernelHandles::NFC: nfc.handleSyncRequest(messagePointer); break;
case KernelHandles::NIM: nim.handleSyncRequest(messagePointer); break;
case KernelHandles::NDM: ndm.handleSyncRequest(messagePointer); break;
case KernelHandles::PTM: ptm.handleSyncRequest(messagePointer); break;