Last active
February 8, 2023 02:00
-
-
Save ITotalJustice/7491efcd51f0c73cd0ee0bcf024ae0f1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #ifndef MGBA_LOG_H | |
| #define MGBA_LOG_H | |
| #include <stdio.h> /* needed for snprintf */ | |
| #define MGBA_LOG_ON 0xC0DE | |
| #define MGBA_LOG_OFF 0x0000 | |
| #define MGBA_LOG_ON_RESULT 0x1DEA | |
| #define MGBA_LOG_STDOUT ((char*)0x4FFF600) | |
| #define MGBA_LOG_FLAGS (*(volatile unsigned short*)0x4FFF700) | |
| #define MGBA_LOG_CONTROL (*(volatile unsigned short*)0x4FFF780) | |
| #define MGBA_LOG_LEVEL_FATAL 0 | |
| #define MGBA_LOG_LEVEL_ERROR 1 | |
| #define MGBA_LOG_LEVEL_WARN 2 | |
| #define MGBA_LOG_LEVEL_INFO 3 | |
| #define MGBA_LOG_LEVEL_DEBUG 4 | |
| #define mgba_enable_log() MGBA_LOG_CONTROL = MGBA_LOG_ON | |
| #define mgba_is_log_enabled() MGBA_LOG_CONTROL == MGBA_LOG_ON_RESULT | |
| #define mgba_disable_log() MGBA_LOG_CONTROL = MGBA_LOG_OFF | |
| // NOTE: string output is truncated to 0x100 chars | |
| // this is due to the address range overlapping with | |
| // MGBA_LOG_FLAGS and mgba log buffer size is 0x100 | |
| #define mgba_log(level, args...) do { \ | |
| snprintf(MGBA_LOG_STDOUT, 0x100, args); \ | |
| MGBA_LOG_FLAGS = 0x100 | level; \ | |
| } while (0) | |
| #define mgba_log_fatal(args...) mgba_log(MGBA_LOG_LEVEL_FATAL, args) | |
| #define mgba_log_error(args...) mgba_log(MGBA_LOG_LEVEL_ERROR, args) | |
| #define mgba_log_warn(args...) mgba_log(MGBA_LOG_LEVEL_WARN, args) | |
| #define mgba_log_info(args...) mgba_log(MGBA_LOG_LEVEL_INFO, args) | |
| #define mgba_log_debug(args...) mgba_log(MGBA_LOG_LEVEL_DEBUG, args) | |
| #endif /* MGBA_LOG_H */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment