Skip to content
This repository was archived by the owner on Aug 19, 2023. It is now read-only.

mGBA printf

Felix Jones edited this page May 22, 2021 · 1 revision

mGBA contains logging utilities available from within a GBA ROM.
The official mGBA C implementation is available in the mGBA GitHub.

gba-plusplus provides a light wrapper around this.

Definition

#include <gba/ext/mgba.hpp>

namespace gba::mgba {
    enum class log_level {
        fatal,
        error,
        warn,
        info,
        debug
    };
}

bool gba::mgba::open() noexcept;

void gba::mgba::close() noexcept;

template <typename... Args>
void gba::mgba::printf( const gba::mgba::log_level lvl, const char * fmt, Args... args ) noexcept;

Example 1

Hello world.

#include <gba/gba.hpp>
#include <gba/ext/mgba.hpp>

using namespace gba;

int main() {
    if ( mgba::open() ) {
        mgba::printf( mgba::log_level::info, "Hello, world!" );
        mgba::close();
    }
}

Example 2

Print reg::vcount.

#include <gba/gba.hpp>
#include <gba/ext/mgba.hpp>

using namespace gba;

int main() {
    mgba::open(); // Assume success

    while ( true ) {
        mgba::printf( mgba::log_level::info, "Line = %d", reg::vcount::read() );
    }
}

posprintf

If the macro __posprintf is defined, mgba::printf will switch from std::vsnprintf to using posprintf if it is available to your project. Website for posprintf.

Log Levels

Under namespace gba::mgba:

  • ::log_level::fatal
  • ::log_level::error
  • ::log_level::warn
  • ::log_level::info
  • ::log_level::debug

Clone this wiki locally