mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-06-03 12:27:21 +12:00
Add DSP emulation interface
Co-Authored-By: PSISP <12768103+psi-rockin@users.noreply.github.com>
This commit is contained in:
parent
3c25be4c63
commit
0a51a80d91
14 changed files with 426 additions and 6 deletions
35
include/audio/dsp_core.hpp
Normal file
35
include/audio/dsp_core.hpp
Normal file
|
@ -0,0 +1,35 @@
|
|||
#pragma once
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "helpers.hpp"
|
||||
#include "logger.hpp"
|
||||
#include "memory.hpp"
|
||||
|
||||
namespace Audio {
|
||||
class DSPCore {
|
||||
protected:
|
||||
Memory& mem;
|
||||
MAKE_LOG_FUNCTION(log, dspLogger)
|
||||
|
||||
public:
|
||||
enum class Type { Null, Teakra };
|
||||
DSPCore(Memory& mem) : mem(mem) {}
|
||||
|
||||
virtual void reset() = 0;
|
||||
virtual void runAudioFrame() = 0;
|
||||
virtual u8* getDspMemory() = 0;
|
||||
|
||||
virtual u16 recvData(u32 regId) = 0;
|
||||
virtual bool recvDataIsReady(u32 regId) = 0;
|
||||
virtual void setSemaphore(u16 value) = 0;
|
||||
virtual void writeProcessPipe(u32 channel, u32 size, u32 buffer) = 0;
|
||||
virtual std::vector<u8> readPipe(u32 channel, u32 peer, u32 size, u32 buffer) = 0;
|
||||
virtual void loadComponent(std::vector<u8>& data, u32 programMask, u32 dataMask) = 0;
|
||||
virtual void unloadComponent() = 0;
|
||||
virtual void setSemaphoreMask(u16 value) = 0;
|
||||
};
|
||||
|
||||
std::unique_ptr<DSPCore> makeDSPCore(DSPCore::Type type, Memory& mem);
|
||||
} // namespace Audio
|
41
include/audio/null_core.hpp
Normal file
41
include/audio/null_core.hpp
Normal file
|
@ -0,0 +1,41 @@
|
|||
#pragma once
|
||||
#include <array>
|
||||
#include "audio/dsp_core.hpp"
|
||||
|
||||
namespace Audio {
|
||||
class NullDSP : public DSPCore {
|
||||
enum class DSPState : u32 {
|
||||
Off,
|
||||
On,
|
||||
Slep,
|
||||
};
|
||||
|
||||
// Number of DSP pipes
|
||||
static constexpr size_t pipeCount = 8;
|
||||
DSPState dspState;
|
||||
|
||||
std::array<std::vector<u8>, pipeCount> pipeData; // The data of each pipe
|
||||
std::array<u8, Memory::DSP_RAM_SIZE> dspRam;
|
||||
|
||||
void resetAudioPipe();
|
||||
|
||||
public:
|
||||
NullDSP(Memory& mem) : DSPCore(mem) {}
|
||||
|
||||
void reset() override;
|
||||
void runAudioFrame() override {}
|
||||
u8* getDspMemory() override { return dspRam.data(); }
|
||||
|
||||
u16 recvData(u32 regId) override;
|
||||
bool recvDataIsReady(u32 regId) override { return true; } // Treat data as always ready
|
||||
void writeProcessPipe(u32 channel, u32 size, u32 buffer) override;
|
||||
std::vector<u8> readPipe(u32 channel, u32 peer, u32 size, u32 buffer) override;
|
||||
|
||||
// NOPs for null DSP core
|
||||
void loadComponent(std::vector<u8>& data, u32 programMask, u32 dataMask) override {}
|
||||
void unloadComponent() override {}
|
||||
void setSemaphore(u16 value) override {}
|
||||
void setSemaphoreMask(u16 value) override {}
|
||||
};
|
||||
|
||||
} // namespace Audio
|
28
include/audio/teakra_core.hpp
Normal file
28
include/audio/teakra_core.hpp
Normal file
|
@ -0,0 +1,28 @@
|
|||
#pragma once
|
||||
#include "audio/dsp_core.hpp"
|
||||
#include "teakra/teakra.h"
|
||||
|
||||
namespace Audio {
|
||||
class TeakraDSP : public DSPCore {
|
||||
Teakra::Teakra teakra;
|
||||
u32 pipeBaseAddr;
|
||||
bool running;
|
||||
|
||||
public:
|
||||
TeakraDSP(Memory& mem);
|
||||
|
||||
void reset() override;
|
||||
void runAudioFrame() override;
|
||||
u8* getDspMemory() override { return teakra.GetDspMemory().data(); }
|
||||
|
||||
u16 recvData(u32 regId) override { return teakra.RecvData(regId); }
|
||||
bool recvDataIsReady(u32 regId) override { return teakra.RecvDataIsReady(regId); }
|
||||
void setSemaphore(u16 value) override { return teakra.SetSemaphore(value); }
|
||||
void setSemaphoreMask(u16 value) override { teakra.MaskSemaphore(value); }
|
||||
|
||||
void writeProcessPipe(u32 channel, u32 size, u32 buffer) override;
|
||||
std::vector<u8> readPipe(u32 channel, u32 peer, u32 size, u32 buffer) override;
|
||||
void loadComponent(std::vector<u8>& data, u32 programMask, u32 dataMask) override;
|
||||
void unloadComponent() override;
|
||||
};
|
||||
} // namespace Audio
|
|
@ -2,10 +2,12 @@
|
|||
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <span>
|
||||
|
||||
#include "PICA/gpu.hpp"
|
||||
#include "audio/dsp_core.hpp"
|
||||
#include "cheats.hpp"
|
||||
#include "config.hpp"
|
||||
#include "cpu.hpp"
|
||||
|
@ -41,9 +43,11 @@ class Emulator {
|
|||
GPU gpu;
|
||||
Memory memory;
|
||||
Kernel kernel;
|
||||
std::unique_ptr<Audio::DSPCore> dsp;
|
||||
Scheduler scheduler;
|
||||
|
||||
Crypto::AESEngine aesEngine;
|
||||
Cheats cheats;
|
||||
Scheduler scheduler;
|
||||
|
||||
// Variables to keep track of whether the user is controlling the 3DS analog stick with their keyboard
|
||||
// This is done so when a gamepad is connected, we won't automatically override the 3DS analog stick settings with the gamepad's state
|
||||
|
|
|
@ -36,6 +36,7 @@ namespace Log {
|
|||
static Logger<false> gpuLogger;
|
||||
static Logger<false> rendererLogger;
|
||||
static Logger<false> shaderJITLogger;
|
||||
static Logger<false> dspLogger;
|
||||
|
||||
// Service loggers
|
||||
static Logger<false> acLogger;
|
||||
|
|
|
@ -100,8 +100,8 @@ namespace KernelMemoryTypes {
|
|||
|
||||
class Memory {
|
||||
u8* fcram;
|
||||
u8* dspRam;
|
||||
u8* vram; // Provided to the memory class by the GPU class
|
||||
u8* dspRam; // Provided to us by Audio
|
||||
u8* vram; // Provided to the memory class by the GPU class
|
||||
|
||||
u64& cpuTicks; // Reference to the CPU tick counter
|
||||
using SharedMemoryBlock = KernelMemoryTypes::SharedMemoryBlock;
|
||||
|
@ -281,6 +281,8 @@ private:
|
|||
u32 getUsedUserMem() { return usedUserMemory; }
|
||||
|
||||
void setVRAM(u8* pointer) { vram = pointer; }
|
||||
void setDSPMem(u8* pointer) { dspRam = pointer; }
|
||||
|
||||
bool allocateMainThreadStack(u32 size);
|
||||
Regions getConsoleRegion();
|
||||
void copySharedFont(u8* ptr);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue