mirror of
https://github.com/LNH-team/pico-loader.git
synced 2026-06-02 09:16:49 +02:00
Initial commit
This commit is contained in:
43
arm7/source/logger/NitroEmulatorOutputStream.cpp
Normal file
43
arm7/source/logger/NitroEmulatorOutputStream.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
#include <nds.h>
|
||||
#include "NitroEmulatorOutputStream.h"
|
||||
|
||||
#define ISND_DBGINFO_ADDRESS 0x027FFF60
|
||||
#define ISND_DBGINFO_AGB_ADDR_OFFSET 0x1C
|
||||
#define ISND_DBGINFO_AGB_ADDR (*(u32*)(ISND_DBGINFO_ADDRESS + ISND_DBGINFO_AGB_ADDR_OFFSET))
|
||||
|
||||
#define ISND_AGB_PRINT_ARM9_WRITE_PTR_OFFSET 0x90
|
||||
#define ISND_AGB_PRINT_ARM7_WRITE_PTR_OFFSET 0x92
|
||||
#define ISND_AGB_PRINT_ARM9_READ_PTR_OFFSET 0x94
|
||||
#define ISND_AGB_PRINT_ARM7_READ_PTR_OFFSET 0x96
|
||||
#define ISND_AGB_SOMETHING_OFFSET 0xFE
|
||||
#define ISND_AGB_PRINT_ARM9_RING_OFFSET 0x8000
|
||||
#define ISND_AGB_PRINT_ARM7_RING_OFFSET 0xC000
|
||||
#define ISND_AGB_PRINT_RING_LENGTH 0x4000
|
||||
|
||||
NitroEmulatorOutputStream::NitroEmulatorOutputStream()
|
||||
{
|
||||
*(vu16*)(ISND_DBGINFO_AGB_ADDR + ISND_AGB_SOMETHING_OFFSET) = 0x202;
|
||||
}
|
||||
|
||||
void NitroEmulatorOutputStream::Write(const char* str)
|
||||
{
|
||||
char c;
|
||||
vu16* ring = (vu16*)(ISND_DBGINFO_AGB_ADDR + ISND_AGB_PRINT_ARM9_RING_OFFSET);
|
||||
u32 writePtr = *(vu16*)(ISND_DBGINFO_AGB_ADDR + ISND_AGB_PRINT_ARM9_WRITE_PTR_OFFSET);
|
||||
u32 readPtr = *(vu16*)(ISND_DBGINFO_AGB_ADDR + ISND_AGB_PRINT_ARM9_READ_PTR_OFFSET);
|
||||
while ((c = *str++) != 0)
|
||||
{
|
||||
u32 newWritePtr = (writePtr + 1) & (ISND_AGB_PRINT_RING_LENGTH - 1);
|
||||
while (newWritePtr == readPtr)
|
||||
{
|
||||
*(vu16*)(ISND_DBGINFO_AGB_ADDR + ISND_AGB_PRINT_ARM9_WRITE_PTR_OFFSET) = writePtr;
|
||||
readPtr = *(vu16*)(ISND_DBGINFO_AGB_ADDR + ISND_AGB_PRINT_ARM9_READ_PTR_OFFSET);
|
||||
}
|
||||
if (writePtr & 1)
|
||||
ring[writePtr >> 1] = (ring[writePtr >> 1] & 0xFF) | (c << 8);
|
||||
else
|
||||
ring[writePtr >> 1] = (ring[writePtr >> 1] & 0xFF00) | c;
|
||||
writePtr = newWritePtr;
|
||||
}
|
||||
*(vu16*)(ISND_DBGINFO_AGB_ADDR + ISND_AGB_PRINT_ARM9_WRITE_PTR_OFFSET) = writePtr;
|
||||
}
|
||||
11
arm7/source/logger/NitroEmulatorOutputStream.h
Normal file
11
arm7/source/logger/NitroEmulatorOutputStream.h
Normal file
@@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
#include "logger/IOutputStream.h"
|
||||
|
||||
class NitroEmulatorOutputStream : public IOutputStream
|
||||
{
|
||||
public:
|
||||
NitroEmulatorOutputStream();
|
||||
|
||||
void Write(const char* str) override;
|
||||
void Flush() override { }
|
||||
};
|
||||
16
arm7/source/logger/NocashOutputStream.h
Normal file
16
arm7/source/logger/NocashOutputStream.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
#include "logger/IOutputStream.h"
|
||||
|
||||
#define REG_NOCASH_STRING_OUT (*(vu32*)0x04FFFA10)
|
||||
#define REG_NOCASH_CHAR_OUT (*(vu32*)0x04FFFA1C)
|
||||
|
||||
class NocashOutputStream : public IOutputStream
|
||||
{
|
||||
public:
|
||||
void Write(const char* str) override
|
||||
{
|
||||
REG_NOCASH_STRING_OUT = (u32)str;
|
||||
}
|
||||
|
||||
void Flush() override { }
|
||||
};
|
||||
26
arm7/source/logger/PlainLogger.h
Normal file
26
arm7/source/logger/PlainLogger.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
#include "core/mini-printf.h"
|
||||
#include <memory>
|
||||
#include "logger/ILogger.h"
|
||||
#include "logger/IOutputStream.h"
|
||||
|
||||
class PlainLogger : public ILogger
|
||||
{
|
||||
LogLevel _maxLogLevel;
|
||||
std::unique_ptr<IOutputStream> _outputStream;
|
||||
|
||||
char _logBuffer[512];
|
||||
|
||||
public:
|
||||
PlainLogger(LogLevel maxLogLevel, std::unique_ptr<IOutputStream> outputStream)
|
||||
: _maxLogLevel(maxLogLevel), _outputStream(std::move(outputStream))
|
||||
{ }
|
||||
|
||||
void LogV(LogLevel level, const char* fmt, va_list vlist) override
|
||||
{
|
||||
if (level > _maxLogLevel)
|
||||
return;
|
||||
mini_vsnprintf(_logBuffer, sizeof(_logBuffer), fmt, vlist);
|
||||
_outputStream->Write(_logBuffer);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user