mirror of https://github.com/mgba-emu/mgba.git
Core: Add category names
This commit is contained in:
parent
92c6b90b03
commit
46590f98d8
|
@ -5,12 +5,26 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
#include "log.h"
|
||||
|
||||
#define MAX_CATEGORY 64
|
||||
|
||||
struct mLogger* mLogGetContext(void) {
|
||||
return NULL; // TODO
|
||||
}
|
||||
|
||||
int mLogGenerateCategory(void) {
|
||||
static int category = 0;
|
||||
++category;
|
||||
return category;
|
||||
static int _category = 0;
|
||||
static const char* _categoryNames[MAX_CATEGORY];
|
||||
|
||||
int mLogGenerateCategory(const char* name) {
|
||||
++_category;
|
||||
if (_category < MAX_CATEGORY) {
|
||||
_categoryNames[_category] = name;
|
||||
}
|
||||
return _category;
|
||||
}
|
||||
|
||||
const char* mLogCategoryName(int category) {
|
||||
if (category < MAX_CATEGORY) {
|
||||
return _categoryNames[category];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -24,7 +24,8 @@ struct mLogger {
|
|||
};
|
||||
|
||||
struct mLogger* mLogGetContext(void);
|
||||
int mLogGenerateCategory(void);
|
||||
int mLogGenerateCategory(const char*);
|
||||
const char* mLogCategoryName(int);
|
||||
|
||||
ATTRIBUTE_FORMAT(printf, 3, 4)
|
||||
static inline void _mLog(int (*category)(void), enum mLogLevel level, const char* format, ...) {
|
||||
|
@ -34,6 +35,7 @@ static inline void _mLog(int (*category)(void), enum mLogLevel level, const char
|
|||
if (context) {
|
||||
context->log(context, category(), level, format, args);
|
||||
} else {
|
||||
printf("%s: ", mLogCategoryName(category()));
|
||||
vprintf(format, args);
|
||||
printf("\n");
|
||||
}
|
||||
|
@ -43,11 +45,11 @@ static inline void _mLog(int (*category)(void), enum mLogLevel level, const char
|
|||
#define mLOG(CATEGORY, LEVEL, ...) _mLog(_mLOG_CAT_ ## CATEGORY, mLOG_ ## LEVEL, __VA_ARGS__)
|
||||
|
||||
#define mLOG_DECLARE_CATEGORY(CATEGORY) int _mLOG_CAT_ ## CATEGORY (void);
|
||||
#define mLOG_DEFINE_CATEGORY(CATEGORY) \
|
||||
#define mLOG_DEFINE_CATEGORY(CATEGORY, NAME) \
|
||||
int _mLOG_CAT_ ## CATEGORY (void) { \
|
||||
static int category = 0; \
|
||||
if (!category) { \
|
||||
category = mLogGenerateCategory(); \
|
||||
category = mLogGenerateCategory(NAME); \
|
||||
} \
|
||||
return category; \
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ const uint32_t SGB_LR35902_FREQUENCY = 0x418B1E;
|
|||
|
||||
const uint32_t GB_COMPONENT_MAGIC = 0x400000;
|
||||
|
||||
mLOG_DEFINE_CATEGORY(GB);
|
||||
mLOG_DEFINE_CATEGORY(GB, "GB");
|
||||
|
||||
static void GBInit(struct LR35902Core* cpu, struct LR35902Component* component);
|
||||
static void GBInterruptHandlerInit(struct LR35902InterruptHandler* irqh);
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
#include "gb/gb.h"
|
||||
|
||||
mLOG_DEFINE_CATEGORY(GB_IO);
|
||||
mLOG_DEFINE_CATEGORY(GB_IO, "GB I/O");
|
||||
|
||||
void GBIOInit(struct GB* gb) {
|
||||
memset(gb->memory.io, 0, sizeof(gb->memory.io));
|
||||
|
|
|
@ -13,8 +13,8 @@
|
|||
|
||||
#include <time.h>
|
||||
|
||||
mLOG_DEFINE_CATEGORY(GB_MBC);
|
||||
mLOG_DEFINE_CATEGORY(GB_MEM);
|
||||
mLOG_DEFINE_CATEGORY(GB_MBC, "GB MBC");
|
||||
mLOG_DEFINE_CATEGORY(GB_MEM, "GB Memory");
|
||||
|
||||
static void _GBMBCNone(struct GBMemory* memory, uint16_t address, uint8_t value) {
|
||||
UNUSED(memory);
|
||||
|
|
Loading…
Reference in New Issue