Add option to print DSP fw

This commit is contained in:
wheremyfoodat 2024-11-30 21:51:46 +02:00
parent e1f830c7f7
commit 18f3865f8b
5 changed files with 39 additions and 4 deletions

View file

@ -58,6 +58,7 @@ struct EmulatorConfig {
bool enableRenderdoc = false;
bool printAppVersion = true;
bool printDSPFirmware = false;
bool chargerPlugged = true;
// Default to 3% battery to make users suffer

View file

@ -10,6 +10,7 @@
#include "memory.hpp"
#include "result/result.hpp"
struct EmulatorConfig;
// Circular dependencies!
class Kernel;
@ -19,7 +20,9 @@ class DSPService {
Handle handle = KernelHandles::DSP;
Memory& mem;
Kernel& kernel;
const EmulatorConfig& config;
Audio::DSPCore* dsp = nullptr;
MAKE_LOG_FUNCTION(log, dspServiceLogger)
// Number of DSP pipes
@ -58,7 +61,7 @@ class DSPService {
void writeProcessPipe(u32 messagePointer);
public:
DSPService(Memory& mem, Kernel& kernel) : mem(mem), kernel(kernel) {}
DSPService(Memory& mem, Kernel& kernel, const EmulatorConfig& config) : mem(mem), kernel(kernel), config(config) {}
void reset();
void handleSyncRequest(u32 messagePointer);
void setDSPCore(Audio::DSPCore* pointer) { dsp = pointer; }
@ -84,4 +87,5 @@ class DSPService {
void triggerInterrupt1();
ComponentDumpResult dumpComponent(const std::filesystem::path& path);
void printFirmwareInfo();
};

View file

@ -99,6 +99,7 @@ void EmulatorConfig::load() {
audioEnabled = toml::find_or<toml::boolean>(audio, "EnableAudio", false);
aacEnabled = toml::find_or<toml::boolean>(audio, "EnableAACAudio", true);
printDSPFirmware = toml::find_or<toml::boolean>(audio, "PrintDSPFirmware", false);
audioDeviceConfig.muteAudio = toml::find_or<toml::boolean>(audio, "MuteAudio", false);
// Our volume ranges from 0.0 (muted) to 2.0 (boosted, using a logarithmic scale). 1.0 is the "default" volume, ie we don't adjust the PCM
@ -177,6 +178,7 @@ void EmulatorConfig::save() {
data["Audio"]["EnableAACAudio"] = aacEnabled;
data["Audio"]["MuteAudio"] = audioDeviceConfig.muteAudio;
data["Audio"]["AudioVolume"] = double(audioDeviceConfig.volumeRaw);
data["Audio"]["PrintDSPFirmware"] = printDSPFirmware;
data["Battery"]["ChargerPlugged"] = chargerPlugged;
data["Battery"]["BatteryPercentage"] = batteryPercentage;

View file

@ -1,10 +1,17 @@
#include "services/dsp.hpp"
#include "ipc.hpp"
#include "kernel.hpp"
#include <cryptopp/sha.h>
#include <fmt/format.h>
#include <fmt/ranges.h>
#include <algorithm>
#include <array>
#include <fstream>
#include "config.hpp"
#include "ipc.hpp"
#include "kernel.hpp"
namespace DSPCommands {
enum : u32 {
RecvData = 0x00010040,
@ -92,6 +99,10 @@ void DSPService::loadComponent(u32 messagePointer) {
log("DSP::LoadComponent (size = %08X, program mask = %X, data mask = %X\n", size, programMask, dataMask);
dsp->loadComponent(loadedComponent, programMask, dataMask);
if (config.printDSPFirmware) {
printFirmwareInfo();
}
mem.write32(messagePointer, IPC::responseHeader(0x11, 2, 2));
mem.write32(messagePointer + 4, Result::Success);
mem.write32(messagePointer + 8, 1); // Component loaded
@ -303,4 +314,21 @@ void DSPService::triggerInterrupt1() {
if (interrupt1.has_value()) {
kernel.signalEvent(*interrupt1);
}
}
void DSPService::printFirmwareInfo() {
// No component has been loaded, do nothing.
if (!loadedComponent.size()) {
return;
}
const usize firmwareSize = loadedComponent.size();
std::array<u8, CryptoPP::SHA256::DIGESTSIZE> hash;
CryptoPP::SHA256 sha;
sha.CalculateDigest(hash.data(), loadedComponent.data(), firmwareSize);
fmt::print("\nLoaded DSP firmware\n");
fmt::print("DSP firmware hash: {:X}\n", fmt::join(hash, ""));
fmt::print("Size: {} bytes ({} KB)\n", firmwareSize, firmwareSize / 1024);
fmt::print("\n");
}

View file

@ -7,7 +7,7 @@
ServiceManager::ServiceManager(std::span<u32, 16> regs, Memory& mem, GPU& gpu, u32& currentPID, Kernel& kernel, const EmulatorConfig& config)
: regs(regs), mem(mem), kernel(kernel), ac(mem), am(mem), boss(mem), act(mem), apt(mem, kernel), cam(mem, kernel), cecd(mem, kernel), cfg(mem),
csnd(mem, kernel), dlp_srvr(mem), dsp(mem, kernel), hid(mem, kernel), http(mem), ir_user(mem, kernel), frd(mem), fs(mem, kernel, config),
csnd(mem, kernel), dlp_srvr(mem), dsp(mem, kernel, config), hid(mem, kernel), http(mem), ir_user(mem, kernel), frd(mem), fs(mem, kernel, config),
gsp_gpu(mem, gpu, kernel, currentPID), gsp_lcd(mem), ldr(mem, kernel), mcu_hwc(mem, config), mic(mem, kernel), nfc(mem, kernel), nim(mem), ndm(mem),
news_u(mem), nwm_uds(mem, kernel), ptm(mem, config), soc(mem), ssl(mem), y2r(mem, kernel) {}