all repos — mgba @ 46590f98d83da55b3820a35b8cc948d3c0605a86

mGBA Game Boy Advance Emulator

Core: Add category names
Jeffrey Pfau jeffrey@endrift.com
Tue, 02 Feb 2016 20:56:08 -0800
commit

46590f98d83da55b3820a35b8cc948d3c0605a86

parent

92c6b90b03f8c04b53312bf2273d86a9783ee073

5 files changed, 27 insertions(+), 11 deletions(-)

jump to
M src/core/log.csrc/core/log.c

@@ -5,12 +5,26 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this

* 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; }
M src/core/log.hsrc/core/log.h

@@ -24,7 +24,8 @@ void (*log)(struct mLogger*, int category, enum mLogLevel level, const char* format, ...);

}; 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 @@ va_start(args, format);

if (context) { context->log(context, category(), level, format, args); } else { + printf("%s: ", mLogCategoryName(category())); vprintf(format, args); printf("\n"); }

@@ -43,11 +45,11 @@

#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; \ }
M src/gb/gb.csrc/gb/gb.c

@@ -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);
M src/gb/io.csrc/gb/io.c

@@ -7,7 +7,7 @@ #include "io.h"

#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));
M src/gb/memory.csrc/gb/memory.c

@@ -13,8 +13,8 @@ #include "util/memory.h"

#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);