all repos — mgba @ 000f232c582b0981b66d48d7af799e97faffad8e

mGBA Game Boy Advance Emulator

Core: Begin log revamp
Vicki Pfau vi@endrift.com
Sun, 05 Mar 2017 15:58:00 -0800
commit

000f232c582b0981b66d48d7af799e97faffad8e

parent

e0c2b3d68272e6c059f0f62f66f15756a27ce590

M include/mgba/core/log.hinclude/mgba/core/log.h

@@ -28,23 +28,26 @@ };

struct mLogger* mLogGetContext(void); void mLogSetDefaultLogger(struct mLogger*); -int mLogGenerateCategory(const char*); +int mLogGenerateCategory(const char*, const char*); const char* mLogCategoryName(int); +const char* mLogCategoryId(int); +int mLogCategoryById(const char*); ATTRIBUTE_FORMAT(printf, 3, 4) void mLog(int category, enum mLogLevel level, const char* format, ...); #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, NAME) \ +#define mLOG_DECLARE_CATEGORY(CATEGORY) int _mLOG_CAT_ ## CATEGORY (void); extern const char* _mLOG_CAT_ ## CATEGORY ## _ID; +#define mLOG_DEFINE_CATEGORY(CATEGORY, NAME, ID) \ int _mLOG_CAT_ ## CATEGORY (void) { \ static int category = 0; \ if (!category) { \ - category = mLogGenerateCategory(NAME); \ + category = mLogGenerateCategory(NAME, ID); \ } \ return category; \ - } + } \ + const char* _mLOG_CAT_ ## CATEGORY ## _ID = ID; mLOG_DECLARE_CATEGORY(STATUS)
M src/core/cheats.csrc/core/cheats.c

@@ -13,7 +13,7 @@ #define MAX_LINE_LENGTH 128

const uint32_t M_CHEAT_DEVICE_ID = 0xABADC0DE; -mLOG_DEFINE_CATEGORY(CHEATS, "Cheats"); +mLOG_DEFINE_CATEGORY(CHEATS, "Cheats", "core.cheats"); DEFINE_VECTOR(mCheatList, struct mCheat); DEFINE_VECTOR(mCheatSets, struct mCheatSet*);
M src/core/log.csrc/core/log.c

@@ -28,12 +28,14 @@ }

static int _category = 0; static const char* _categoryNames[MAX_CATEGORY]; +static const char* _categoryIds[MAX_CATEGORY]; -int mLogGenerateCategory(const char* name) { - ++_category; +int mLogGenerateCategory(const char* name, const char* id) { if (_category < MAX_CATEGORY) { _categoryNames[_category] = name; + _categoryIds[_category] = id; } + ++_category; return _category; }

@@ -41,7 +43,24 @@ const char* mLogCategoryName(int category) {

if (category < MAX_CATEGORY) { return _categoryNames[category]; } - return 0; + return NULL; +} + +const char* mLogCategoryId(int category) { + if (category < MAX_CATEGORY) { + return _categoryIds[category]; + } + return NULL; +} + +int mLogCategoryById(const char* id) { + int i; + for (i = 0; i < _category; ++i) { + if (strcmp(_categoryIds[i], id) == 0) { + return i; + } + } + return -1; } void mLog(int category, enum mLogLevel level, const char* format, ...) {

@@ -58,4 +77,4 @@ }

va_end(args); } -mLOG_DEFINE_CATEGORY(STATUS, "Status") +mLOG_DEFINE_CATEGORY(STATUS, "Status", "core.status")
M src/core/serialize.csrc/core/serialize.c

@@ -17,7 +17,7 @@ #include <png.h>

#include <zlib.h> #endif -mLOG_DEFINE_CATEGORY(SAVESTATE, "Savestate"); +mLOG_DEFINE_CATEGORY(SAVESTATE, "Savestate", "core.serialize"); struct mBundledState { size_t stateSize;
M src/debugger/debugger.csrc/debugger/debugger.c

@@ -15,7 +15,7 @@ #endif

const uint32_t DEBUGGER_ID = 0xDEADBEEF; -mLOG_DEFINE_CATEGORY(DEBUGGER, "Debugger"); +mLOG_DEFINE_CATEGORY(DEBUGGER, "Debugger", "core.debugger"); static void mDebuggerInit(void* cpu, struct mCPUComponent* component); static void mDebuggerDeinit(struct mCPUComponent* component);
M src/feature/gui/gui-runner.csrc/feature/gui/gui-runner.c

@@ -25,7 +25,7 @@

#include <sys/time.h> mLOG_DECLARE_CATEGORY(GUI_RUNNER); -mLOG_DEFINE_CATEGORY(GUI_RUNNER, "GUI Runner"); +mLOG_DEFINE_CATEGORY(GUI_RUNNER, "GUI Runner", "gui.runner"); #define FPS_GRANULARITY 120 #define FPS_BUFFER_SIZE 3
M src/gb/gb.csrc/gb/gb.c

@@ -30,7 +30,7 @@ #define DMG_BIOS_CHECKSUM 0xC2F5CC97

#define DMG_2_BIOS_CHECKSUM 0x59C8598E #define CGB_BIOS_CHECKSUM 0x41884E46 -mLOG_DEFINE_CATEGORY(GB, "GB"); +mLOG_DEFINE_CATEGORY(GB, "GB", "gb"); static void GBInit(void* cpu, struct mCPUComponent* component); static void GBDeinit(struct mCPUComponent* component);
M src/gb/io.csrc/gb/io.c

@@ -9,7 +9,7 @@ #include <mgba/internal/gb/gb.h>

#include <mgba/internal/gb/sio.h> #include <mgba/internal/gb/serialize.h> -mLOG_DEFINE_CATEGORY(GB_IO, "GB I/O"); +mLOG_DEFINE_CATEGORY(GB_IO, "GB I/O", "gb.io"); const char* const GBIORegisterNames[] = { [REG_JOYP] = "JOYP",
M src/gb/mbc.csrc/gb/mbc.c

@@ -11,7 +11,7 @@ #include <mgba/internal/gb/gb.h>

#include <mgba/internal/gb/memory.h> #include <mgba-util/vfs.h> -mLOG_DEFINE_CATEGORY(GB_MBC, "GB MBC"); +mLOG_DEFINE_CATEGORY(GB_MBC, "GB MBC", "gb.mbc"); static void _GBMBCNone(struct GB* gb, uint16_t address, uint8_t value) { UNUSED(gb);
M src/gb/memory.csrc/gb/memory.c

@@ -14,7 +14,7 @@ #include <mgba/internal/lr35902/lr35902.h>

#include <mgba-util/memory.h> -mLOG_DEFINE_CATEGORY(GB_MEM, "GB Memory"); +mLOG_DEFINE_CATEGORY(GB_MEM, "GB Memory", "gb.memory"); static void _pristineCow(struct GB* gba);
M src/gb/serialize.csrc/gb/serialize.c

@@ -9,7 +9,7 @@ #include <mgba/internal/gb/io.h>

#include <mgba/internal/gb/timer.h> #include <mgba/internal/lr35902/lr35902.h> -mLOG_DEFINE_CATEGORY(GB_STATE, "GB Savestate"); +mLOG_DEFINE_CATEGORY(GB_STATE, "GB Savestate", "gb.serialize"); const uint32_t GB_SAVESTATE_MAGIC = 0x00400000; const uint32_t GB_SAVESTATE_VERSION = 0x00000001;
M src/gb/sio.csrc/gb/sio.c

@@ -9,7 +9,7 @@ #include <mgba/internal/gb/gb.h>

#include <mgba/internal/gb/io.h> #include <mgba/internal/gb/serialize.h> -mLOG_DEFINE_CATEGORY(GB_SIO, "GB Serial I/O"); +mLOG_DEFINE_CATEGORY(GB_SIO, "GB Serial I/O", "gb.sio"); const int GBSIOCyclesPerTransfer[2] = { 512,
M src/gba/audio.csrc/gba/audio.c

@@ -18,7 +18,7 @@ #ifdef _3DS

#define blip_add_delta blip_add_delta_fast #endif -mLOG_DEFINE_CATEGORY(GBA_AUDIO, "GBA Audio"); +mLOG_DEFINE_CATEGORY(GBA_AUDIO, "GBA Audio", "gba.audio"); const unsigned GBA_AUDIO_SAMPLES = 2048; const unsigned GBA_AUDIO_FIFO_SIZE = 8 * sizeof(int32_t);
M src/gba/bios.csrc/gba/bios.c

@@ -14,7 +14,7 @@

const uint32_t GBA_BIOS_CHECKSUM = 0xBAAE187F; const uint32_t GBA_DS_BIOS_CHECKSUM = 0xBAAE1880; -mLOG_DEFINE_CATEGORY(GBA_BIOS, "GBA BIOS"); +mLOG_DEFINE_CATEGORY(GBA_BIOS, "GBA BIOS", "gba.bios"); static void _unLz77(struct GBA* gba, int width); static void _unHuffman(struct GBA* gba);
M src/gba/gba.csrc/gba/gba.c

@@ -21,8 +21,8 @@ #include <mgba-util/math.h>

#include <mgba-util/memory.h> #include <mgba-util/vfs.h> -mLOG_DEFINE_CATEGORY(GBA, "GBA"); -mLOG_DEFINE_CATEGORY(GBA_DEBUG, "GBA Debug"); +mLOG_DEFINE_CATEGORY(GBA, "GBA", "gba"); +mLOG_DEFINE_CATEGORY(GBA_DEBUG, "GBA Debug", "gba.debug"); const uint32_t GBA_COMPONENT_MAGIC = 0x1000000;
M src/gba/hardware.csrc/gba/hardware.c

@@ -11,7 +11,7 @@ #include <mgba/internal/gba/serialize.h>

#include <mgba-util/formatting.h> #include <mgba-util/hash.h> -mLOG_DEFINE_CATEGORY(GBA_HW, "GBA Pak Hardware"); +mLOG_DEFINE_CATEGORY(GBA_HW, "GBA Pak Hardware", "gba.hardware"); const int GBA_LUX_LEVELS[10] = { 5, 11, 18, 27, 42, 62, 84, 109, 139, 183 };
M src/gba/io.csrc/gba/io.c

@@ -11,7 +11,7 @@ #include <mgba/internal/gba/gba.h>

#include <mgba/internal/gba/rr/rr.h> #include <mgba/internal/gba/serialize.h> -mLOG_DEFINE_CATEGORY(GBA_IO, "GBA I/O"); +mLOG_DEFINE_CATEGORY(GBA_IO, "GBA I/O", "gba.io"); const char* const GBAIORegisterNames[] = { // Video
M src/gba/memory.csrc/gba/memory.c

@@ -19,7 +19,7 @@ #include <mgba-util/vfs.h>

#define IDLE_LOOP_THRESHOLD 10000 -mLOG_DEFINE_CATEGORY(GBA_MEM, "GBA Memory"); +mLOG_DEFINE_CATEGORY(GBA_MEM, "GBA Memory", "gba.memory"); static void _pristineCow(struct GBA* gba); static uint32_t _deadbeef[1] = { 0xE710B710 }; // Illegal instruction on both ARM and Thumb
M src/gba/rr/rr.csrc/gba/rr/rr.c

@@ -9,7 +9,7 @@ #include <mgba/core/log.h>

#include <mgba/core/serialize.h> #include <mgba-util/vfs.h> -mLOG_DEFINE_CATEGORY(GBA_RR, "GBA RR"); +mLOG_DEFINE_CATEGORY(GBA_RR, "GBA RR", "gba.rr"); void GBARRInitRecord(struct GBA* gba) { if (!gba || !gba->rr) {
M src/gba/savedata.csrc/gba/savedata.c

@@ -26,7 +26,7 @@ // This needs real testing, and is only an estimation currently

#define EEPROM_SETTLE_CYCLES 115000 #define CLEANUP_THRESHOLD 15 -mLOG_DEFINE_CATEGORY(GBA_SAVE, "GBA Savedata"); +mLOG_DEFINE_CATEGORY(GBA_SAVE, "GBA Savedata", "gba.savedata"); static void _flashSwitchBank(struct GBASavedata* savedata, int bank); static void _flashErase(struct GBASavedata* savedata);
M src/gba/serialize.csrc/gba/serialize.c

@@ -17,7 +17,7 @@

const uint32_t GBA_SAVESTATE_MAGIC = 0x01000000; const uint32_t GBA_SAVESTATE_VERSION = 0x00000002; -mLOG_DEFINE_CATEGORY(GBA_STATE, "GBA Savestate"); +mLOG_DEFINE_CATEGORY(GBA_STATE, "GBA Savestate", "gba.serialize"); struct GBABundledState { struct GBASerializedState* state;
M src/gba/sio.csrc/gba/sio.c

@@ -8,7 +8,7 @@

#include <mgba/internal/gba/gba.h> #include <mgba/internal/gba/io.h> -mLOG_DEFINE_CATEGORY(GBA_SIO, "GBA Serial I/O"); +mLOG_DEFINE_CATEGORY(GBA_SIO, "GBA Serial I/O", "gba.sio"); const int GBASIOCyclesPerTransfer[4][MAX_GBAS] = { { 38326, 73003, 107680, 142356 },
M src/gba/video.csrc/gba/video.c

@@ -15,7 +15,7 @@ #include <mgba/internal/gba/serialize.h>

#include <mgba-util/memory.h> -mLOG_DEFINE_CATEGORY(GBA_VIDEO, "GBA Video"); +mLOG_DEFINE_CATEGORY(GBA_VIDEO, "GBA Video", "gba.video"); static void GBAVideoDummyRendererInit(struct GBAVideoRenderer* renderer); static void GBAVideoDummyRendererReset(struct GBAVideoRenderer* renderer);
M src/platform/opengl/gles2.csrc/platform/opengl/gles2.c

@@ -12,7 +12,7 @@ #include <mgba-util/vector.h>

#include <mgba-util/vfs.h> mLOG_DECLARE_CATEGORY(OPENGL); -mLOG_DEFINE_CATEGORY(OPENGL, "OpenGL"); +mLOG_DEFINE_CATEGORY(OPENGL, "OpenGL", "video.ogl"); #define MAX_PASSES 8
M src/platform/qt/GBAApp.cppsrc/platform/qt/GBAApp.cpp

@@ -29,7 +29,7 @@ using namespace QGBA;

static GBAApp* g_app = nullptr; -mLOG_DEFINE_CATEGORY(QT, "Qt"); +mLOG_DEFINE_CATEGORY(QT, "Qt", "platform.qt"); GBAApp::GBAApp(int& argc, char* argv[]) : QApplication(argc, argv)
M src/platform/qt/GameController.cppsrc/platform/qt/GameController.cpp

@@ -23,7 +23,6 @@ #include <mgba/core/serialize.h>

#include <mgba/core/tile-cache.h> #ifdef M_CORE_GBA #include <mgba/gba/interface.h> -#include <mgba/internal/gba/bios.h> #include <mgba/internal/gba/gba.h> #include <mgba/gba/core.h> #include <mgba/internal/gba/renderers/tile-cache.h>

@@ -239,13 +238,21 @@ mCoreThread* context = logContext->p;

static const char* savestateMessage = "State %i loaded"; static const char* savestateFailedMessage = "State %i failed to load"; + static int biosCat = -1; + static int statusCat = -1; if (!context) { return; } GameController* controller = static_cast<GameController*>(context->userData); QString message; + if (biosCat < 0) { + biosCat = mLogCategoryById("gba.bios"); + } + if (statusCat < 0) { + statusCat = mLogCategoryById("core.status"); + } #ifdef M_CORE_GBA - if (level == mLOG_STUB && category == _mLOG_CAT_GBA_BIOS()) { + if (level == mLOG_STUB && category == biosCat) { va_list argc; va_copy(argc, args); int immediate = va_arg(argc, int);

@@ -253,7 +260,7 @@ va_end(argc);

QMetaObject::invokeMethod(controller, "unimplementedBiosCall", Q_ARG(int, immediate)); } else #endif - if (category == _mLOG_CAT_STATUS()) { + if (category == statusCat) { // Slot 0 is reserved for suspend points if (strncmp(savestateMessage, format, strlen(savestateMessage)) == 0) { va_list argc;
M src/platform/sdl/sdl-audio.csrc/platform/sdl/sdl-audio.c

@@ -14,7 +14,7 @@ #include <mgba/core/blip_buf.h>

#define BUFFER_SIZE (GBA_AUDIO_SAMPLES >> 2) -mLOG_DEFINE_CATEGORY(SDL_AUDIO, "SDL Audio"); +mLOG_DEFINE_CATEGORY(SDL_AUDIO, "SDL Audio", "platform.sdl.audio"); static void _mSDLAudioCallback(void* context, Uint8* data, int len);
M src/platform/sdl/sdl-events.csrc/platform/sdl/sdl-events.c

@@ -25,7 +25,7 @@ #define GYRO_STEPS 100

#define RUMBLE_PWM 16 #define RUMBLE_STEPS 2 -mLOG_DEFINE_CATEGORY(SDL_EVENTS, "SDL Events"); +mLOG_DEFINE_CATEGORY(SDL_EVENTS, "SDL Events", "platform.sdl.events"); DEFINE_VECTOR(SDL_JoystickList, struct SDL_JoystickCombo);