mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-06-03 12:27:21 +12:00
Trongle
This commit is contained in:
parent
75070ca6ef
commit
be4fae5104
33 changed files with 341 additions and 70 deletions
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
#include <array>
|
||||
#include "helpers.hpp"
|
||||
#include "logger.hpp"
|
||||
#include "memory.hpp"
|
||||
#include "opengl.hpp"
|
||||
#include "PICA/float_types.hpp"
|
||||
|
@ -12,11 +13,17 @@ class GPU {
|
|||
Memory& mem;
|
||||
ShaderUnit shaderUnit;
|
||||
u8* vram = nullptr;
|
||||
MAKE_LOG_FUNCTION(log, gpuLogger)
|
||||
|
||||
static constexpr u32 maxAttribCount = 12; // Up to 12 vertex attributes
|
||||
static constexpr u32 regNum = 0x300;
|
||||
static constexpr u32 vramSize = 6_MB;
|
||||
std::array<u32, regNum> regs; // GPU internal registers
|
||||
|
||||
struct Vertex {
|
||||
OpenGL::vec4 position;
|
||||
OpenGL::vec4 colour;
|
||||
};
|
||||
|
||||
// Read a value of type T from physical address paddr
|
||||
// This is necessary because vertex attribute fetching uses physical addresses
|
||||
|
@ -71,8 +78,27 @@ class GPU {
|
|||
u32 fixedAttribCount = 0; // How many attribute components have we written? When we get to 4 the attr will actually get submitted
|
||||
std::array<u32, 3> fixedAttrBuff; // Buffer to hold fixed attributes in until they get submitted
|
||||
|
||||
OpenGL::Framebuffer fbo;
|
||||
OpenGL::Texture fboTexture;
|
||||
OpenGL::Program triangleProgram;
|
||||
OpenGL::Program displayProgram;
|
||||
|
||||
OpenGL::VertexArray vao;
|
||||
OpenGL::VertexBuffer vbo;
|
||||
|
||||
// Dummy VAO/VBO for blitting the final output
|
||||
OpenGL::VertexArray dummyVAO;
|
||||
OpenGL::VertexBuffer dummyVBO;
|
||||
|
||||
static constexpr u32 vertexBufferSize = 0x1000;
|
||||
void drawVertices(OpenGL::Primitives primType, Vertex* vertices, u32 count);
|
||||
|
||||
public:
|
||||
GPU(Memory& mem);
|
||||
void initGraphicsContext(); // Initialize graphics context
|
||||
void getGraphicsContext(); // Set up the graphics context for rendering
|
||||
void display(); // Display the screen contents onto our window
|
||||
|
||||
void clearBuffer(u32 startAddress, u32 endAddress, u32 value, u32 control);
|
||||
void reset();
|
||||
|
||||
|
|
|
@ -47,6 +47,8 @@ namespace PICAInternalRegs {
|
|||
FixedAttribData1 = 0x234,
|
||||
FixedAttribData2 = 0x235,
|
||||
|
||||
PrimitiveConfig = 0x25E,
|
||||
|
||||
// Vertex shader registers
|
||||
VertexShaderTransferEnd = 0x2BF,
|
||||
VertexFloatUniformIndex = 0x2C0,
|
||||
|
|
|
@ -158,6 +158,8 @@ public:
|
|||
void runFrame() {
|
||||
env.ticksLeft = 268111856 / 60;
|
||||
const auto exitReason = jit->Run();
|
||||
Helpers::panic("Exit reason: %d\nPC: %08X", (u32)exitReason, getReg(15));
|
||||
if (static_cast<u32>(exitReason) != 0) [[unlikely]] {
|
||||
Helpers::panic("Exit reason: %d\nPC: %08X", static_cast<u32>(exitReason), getReg(15));
|
||||
}
|
||||
}
|
||||
};
|
|
@ -43,4 +43,5 @@ public:
|
|||
|
||||
bool loadELF(std::filesystem::path& path);
|
||||
bool loadELF(std::ifstream& file);
|
||||
void initGraphicsContext() { gpu.initGraphicsContext(); }
|
||||
};
|
|
@ -5,6 +5,7 @@
|
|||
#include <vector>
|
||||
#include "kernel_types.hpp"
|
||||
#include "helpers.hpp"
|
||||
#include "logger.hpp"
|
||||
#include "memory.hpp"
|
||||
#include "resource_limits.hpp"
|
||||
#include "services/service_manager.hpp"
|
||||
|
@ -58,7 +59,7 @@ class Kernel {
|
|||
}
|
||||
|
||||
objects.push_back(KernelObject(handleCounter, type));
|
||||
printf("Created %s object with handle %d\n", kernelObjectTypeToString(type), handleCounter);
|
||||
log("Created %s object with handle %d\n", kernelObjectTypeToString(type), handleCounter);
|
||||
return handleCounter++;
|
||||
}
|
||||
|
||||
|
@ -83,6 +84,9 @@ class Kernel {
|
|||
std::string getProcessName(u32 pid);
|
||||
const char* resetTypeToString(u32 type);
|
||||
|
||||
MAKE_LOG_FUNCTION(log, kernelLogger)
|
||||
MAKE_LOG_FUNCTION(logSVC, svcLogger)
|
||||
|
||||
// SVC implementations
|
||||
void arbitrateAddress();
|
||||
void clearEvent();
|
||||
|
@ -110,4 +114,6 @@ public:
|
|||
void setVersion(u8 major, u8 minor);
|
||||
void serviceSVC(u32 svc);
|
||||
void reset();
|
||||
|
||||
void sendGPUInterrupt(GPUInterrupt type) { serviceManager.requestGPUInterrupt(type); }
|
||||
};
|
39
include/logger.hpp
Normal file
39
include/logger.hpp
Normal file
|
@ -0,0 +1,39 @@
|
|||
#pragma once
|
||||
#include <cstdarg>
|
||||
#include <fstream>
|
||||
|
||||
namespace Log {
|
||||
// Our logger class
|
||||
template <bool enabled>
|
||||
class Logger {
|
||||
public:
|
||||
void log(const char* fmt, ...) {
|
||||
if constexpr (!enabled) return;
|
||||
|
||||
std::va_list args;
|
||||
va_start(args, fmt);
|
||||
std::vprintf(fmt, args);
|
||||
va_end(args);
|
||||
}
|
||||
};
|
||||
|
||||
// Our loggers here. Enable/disable by toggling the template param
|
||||
static Logger<false> kernelLogger;
|
||||
static Logger<false> svcLogger;
|
||||
static Logger<false> gpuLogger;
|
||||
|
||||
// Service loggers
|
||||
static Logger<false> aptLogger;
|
||||
static Logger<false> fsLogger;
|
||||
static Logger<false> hidLogger;
|
||||
static Logger<false> gspGPULogger;
|
||||
static Logger<false> gspLCDLogger;
|
||||
static Logger<false> ndmLogger;
|
||||
static Logger<false> srvLogger;
|
||||
|
||||
#define MAKE_LOG_FUNCTION(functionName, logger) \
|
||||
template <typename... Args> \
|
||||
void functionName(const char* fmt, Args... args) { \
|
||||
Log::logger.log(fmt, args...); \
|
||||
}
|
||||
}
|
|
@ -57,7 +57,7 @@ namespace OpenGL {
|
|||
void bind() { glBindVertexArray(m_handle); }
|
||||
|
||||
template <typename T>
|
||||
void setAttributeFloat(GLuint index, GLint size, GLsizei stride, const void* offset, bool normalized = false) {
|
||||
void setAttributeFloat(GLuint index, GLint size, GLsizei stride, const void* offset, bool normalized = GL_FALSE) {
|
||||
if constexpr (std::is_same<T, GLfloat>()) {
|
||||
glVertexAttribPointer(index, size, GL_FLOAT, normalized, stride, offset);
|
||||
}
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
#pragma once
|
||||
#include "helpers.hpp"
|
||||
#include "kernel_types.hpp"
|
||||
#include "logger.hpp"
|
||||
#include "memory.hpp"
|
||||
|
||||
class APTService {
|
||||
Handle handle = KernelHandles::APT;
|
||||
Memory& mem;
|
||||
MAKE_LOG_FUNCTION(log, aptLogger)
|
||||
|
||||
// Service commands
|
||||
void getLockHandle(u32 messagePointer);
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
#pragma once
|
||||
#include "helpers.hpp"
|
||||
#include "kernel_types.hpp"
|
||||
#include "logger.hpp"
|
||||
#include "memory.hpp"
|
||||
|
||||
class FSService {
|
||||
Handle handle = KernelHandles::FS;
|
||||
Memory& mem;
|
||||
MAKE_LOG_FUNCTION(log, fsLogger)
|
||||
|
||||
// Service commands
|
||||
void initialize(u32 messagePointer);
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include "PICA/gpu.hpp"
|
||||
#include "helpers.hpp"
|
||||
#include "kernel_types.hpp"
|
||||
#include "logger.hpp"
|
||||
#include "memory.hpp"
|
||||
|
||||
enum class GPUInterrupt : u8 {
|
||||
|
@ -26,6 +27,7 @@ class GPUService {
|
|||
// This is the PID of that process
|
||||
u32 privilegedProcess;
|
||||
|
||||
MAKE_LOG_FUNCTION(log, gspGPULogger)
|
||||
void processCommandBuffer();
|
||||
|
||||
// Service commands
|
||||
|
@ -40,6 +42,7 @@ class GPUService {
|
|||
// GSP commands processed via TriggerCmdReqQueue
|
||||
void processCommandList(u32* cmd);
|
||||
void memoryFill(u32* cmd);
|
||||
void triggerDisplayTransfer(u32* cmd);
|
||||
|
||||
public:
|
||||
GPUService(Memory& mem, GPU& gpu, u32& currentPID) : mem(mem), gpu(gpu), currentPID(currentPID) {}
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
#pragma once
|
||||
#include "helpers.hpp"
|
||||
#include "kernel_types.hpp"
|
||||
#include "logger.hpp"
|
||||
#include "memory.hpp"
|
||||
|
||||
class LCDService {
|
||||
Handle handle = KernelHandles::LCD;
|
||||
Memory& mem;
|
||||
MAKE_LOG_FUNCTION(log, gspLCDLogger)
|
||||
|
||||
// Service commands
|
||||
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
#pragma once
|
||||
#include "helpers.hpp"
|
||||
#include "kernel_types.hpp"
|
||||
#include "logger.hpp"
|
||||
#include "memory.hpp"
|
||||
|
||||
class HIDService {
|
||||
Handle handle = KernelHandles::HID;
|
||||
Memory& mem;
|
||||
MAKE_LOG_FUNCTION(log, hidLogger)
|
||||
|
||||
// Service commands
|
||||
void getIPCHandles(u32 messagePointer);
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
#pragma once
|
||||
#include "helpers.hpp"
|
||||
#include "kernel_types.hpp"
|
||||
#include "logger.hpp"
|
||||
#include "memory.hpp"
|
||||
|
||||
class NDMService {
|
||||
Handle handle = KernelHandles::NDM;
|
||||
Memory& mem;
|
||||
MAKE_LOG_FUNCTION(log, ndmLogger)
|
||||
|
||||
// Service commands
|
||||
void overrideDefaultDaemons(u32 messagePointer);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
#include <array>
|
||||
#include "helpers.hpp"
|
||||
#include "logger.hpp"
|
||||
#include "memory.hpp"
|
||||
#include "services/apt.hpp"
|
||||
#include "services/hid.hpp"
|
||||
|
@ -12,6 +13,7 @@
|
|||
class ServiceManager {
|
||||
std::array<u32, 16>& regs;
|
||||
Memory& mem;
|
||||
MAKE_LOG_FUNCTION(log, srvLogger)
|
||||
|
||||
APTService apt;
|
||||
HIDService hid;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue