Add MGBA debug logging w/ puts
MGBA debugging must be enabled using debug::open and disabled using debug::close. This commit adds logging through debug::puts. TODO: add logging using debug::printf and debug::write.
This commit is contained in:
parent
f75e734c8b
commit
489e942bd2
16
include/debug.hpp
Normal file
16
include/debug.hpp
Normal file
@ -0,0 +1,16 @@
|
||||
#include <cstdint>
|
||||
|
||||
namespace debug {
|
||||
enum level {
|
||||
fatal = 0,
|
||||
error = 1,
|
||||
warn = 2,
|
||||
info = 3,
|
||||
debug = 4,
|
||||
};
|
||||
|
||||
void puts(const char* msg, level lvl = level::info );
|
||||
|
||||
bool open();
|
||||
void close();
|
||||
};
|
||||
49
src/debug.cpp
Normal file
49
src/debug.cpp
Normal file
@ -0,0 +1,49 @@
|
||||
#include "debug.hpp"
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
|
||||
#include <tonc.h>
|
||||
|
||||
namespace debug {
|
||||
/**
|
||||
* \brief MGBA debug registers and constants
|
||||
*/
|
||||
namespace reg {
|
||||
/**
|
||||
* \brief MGBA debug enable register.
|
||||
*
|
||||
* When 0xC0DE is written to the register, debug output is enabled.
|
||||
* When 0 is written to the register, debug output is disabled.
|
||||
* Will be set to 0x1DEA when successfully enabled.
|
||||
*/
|
||||
static volatile uint16_t* enable = reinterpret_cast<uint16_t*>(0x4FFF780);
|
||||
/**
|
||||
* \brief MGBA debug flags register.
|
||||
*/
|
||||
static volatile uint16_t* flags = reinterpret_cast<uint16_t*>(0x4FFF700);
|
||||
/**
|
||||
* \brief MGBA debug string register.
|
||||
*
|
||||
* Max length of 0x100 (256)
|
||||
*/
|
||||
static char* string = reinterpret_cast<char*>(0x4FFF600);
|
||||
constexpr size_t string_len = 0x100;
|
||||
}; // namespace reg
|
||||
|
||||
|
||||
void puts(const char* msg, level lvl) {
|
||||
std::strncpy(reg::string, msg, reg::string_len);
|
||||
*reg::flags = (lvl) | 0x100;
|
||||
}
|
||||
|
||||
bool open() {
|
||||
*reg::enable = 0xC0DE;
|
||||
return *reg::enable ==0x1DEA;
|
||||
}
|
||||
|
||||
void close() {
|
||||
*reg::enable = 0;
|
||||
}
|
||||
}; // namespace debug
|
||||
Loading…
x
Reference in New Issue
Block a user