mirror of
https://github.com/LNH-team/pico-loader.git
synced 2026-06-02 17:26:48 +02:00
Initial commit
This commit is contained in:
32
common/logger/ILogger.h
Normal file
32
common/logger/ILogger.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
#include <stdarg.h>
|
||||
|
||||
enum class LogLevel
|
||||
{
|
||||
Off,
|
||||
|
||||
Fatal,
|
||||
Error,
|
||||
Warning,
|
||||
Info,
|
||||
Debug,
|
||||
Trace,
|
||||
|
||||
All
|
||||
};
|
||||
|
||||
class ILogger
|
||||
{
|
||||
public:
|
||||
virtual ~ILogger() { }
|
||||
|
||||
void Log(LogLevel level, const char* fmt, ...)
|
||||
{
|
||||
va_list vlist;
|
||||
va_start(vlist, fmt);
|
||||
LogV(level, fmt, vlist);
|
||||
va_end(vlist);
|
||||
}
|
||||
|
||||
virtual void LogV(LogLevel level, const char* fmt, va_list vlist) = 0;
|
||||
};
|
||||
10
common/logger/IOutputStream.h
Normal file
10
common/logger/IOutputStream.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
class IOutputStream
|
||||
{
|
||||
public:
|
||||
virtual ~IOutputStream() { }
|
||||
|
||||
virtual void Write(const char* str) = 0;
|
||||
virtual void Flush() = 0;
|
||||
};
|
||||
8
common/logger/NullLogger.h
Normal file
8
common/logger/NullLogger.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
#include "ILogger.h"
|
||||
|
||||
class NullLogger : public ILogger
|
||||
{
|
||||
public:
|
||||
void LogV(LogLevel level, const char* fmt, va_list vlist) override { }
|
||||
};
|
||||
9
common/logger/NullOutputStream.h
Normal file
9
common/logger/NullOutputStream.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
#include "IOutputStream.h"
|
||||
|
||||
class NullOutputStream : public IOutputStream
|
||||
{
|
||||
public:
|
||||
void Write(const char* str) { }
|
||||
void Flush() { }
|
||||
};
|
||||
26
common/logger/PicoAgbAdapterOutputStream.cpp
Normal file
26
common/logger/PicoAgbAdapterOutputStream.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#include <nds.h>
|
||||
#include "picoAgbAdapter.h"
|
||||
#include "PicoAgbAdapterOutputStream.h"
|
||||
|
||||
void PicoAgbAdapterOutputStream::Write(const char* str)
|
||||
{
|
||||
char c;
|
||||
vu16* ring = PICO_AGB_PRINT_ARM9_RING;
|
||||
u32 writePtr = PICO_AGB_PRINT_ARM9_WRITE_PTR;
|
||||
u32 readPtr = PICO_AGB_PRINT_ARM9_READ_PTR;
|
||||
while ((c = *str++) != 0)
|
||||
{
|
||||
u32 newWritePtr = (writePtr + 1) & (PICO_AGB_PRINT_RING_LENGTH - 1);
|
||||
while (newWritePtr == readPtr)
|
||||
{
|
||||
PICO_AGB_PRINT_ARM9_WRITE_PTR = writePtr;
|
||||
readPtr = PICO_AGB_PRINT_ARM9_READ_PTR;
|
||||
}
|
||||
if (writePtr & 1)
|
||||
ring[writePtr >> 1] = (ring[writePtr >> 1] & 0xFF) | (c << 8);
|
||||
else
|
||||
ring[writePtr >> 1] = (ring[writePtr >> 1] & 0xFF00) | c;
|
||||
writePtr = newWritePtr;
|
||||
}
|
||||
PICO_AGB_PRINT_ARM9_WRITE_PTR = writePtr;
|
||||
}
|
||||
11
common/logger/PicoAgbAdapterOutputStream.h
Normal file
11
common/logger/PicoAgbAdapterOutputStream.h
Normal file
@@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
#include "IOutputStream.h"
|
||||
|
||||
class PicoAgbAdapterOutputStream : public IOutputStream
|
||||
{
|
||||
public:
|
||||
PicoAgbAdapterOutputStream() { }
|
||||
|
||||
void Write(const char* str) override;
|
||||
void Flush() override { }
|
||||
};
|
||||
Reference in New Issue
Block a user