all repos — mgba @ 61e7cc9556eaa118efa209c2b9cef2a550539bb7

mGBA Game Boy Advance Emulator

GB: Add basic logging support
Jeffrey Pfau jeffrey@endrift.com
Mon, 25 Jan 2016 22:17:01 -0800
commit

61e7cc9556eaa118efa209c2b9cef2a550539bb7

parent

487c54f0accad7f4bc8c16ad2e13928c3bfb2762

7 files changed, 34 insertions(+), 7 deletions(-)

jump to
M CMakeLists.txtCMakeLists.txt

@@ -40,7 +40,7 @@ file(GLOB GBA_CHEATS_SRC ${CMAKE_SOURCE_DIR}/src/gba/cheats/*.c)

file(GLOB GBA_RR_SRC ${CMAKE_SOURCE_DIR}/src/gba/rr/*.c) file(GLOB GBA_SV_SRC ${CMAKE_SOURCE_DIR}/src/gba/supervisor/*.c) file(GLOB GBA_CTX_SRC ${CMAKE_SOURCE_DIR}/src/gba/context/*.c) -file(GLOB UTIL_SRC ${CMAKE_SOURCE_DIR}/src/util/*.[cSs]) +file(GLOB UTIL_SRC ${CMAKE_SOURCE_DIR}/src/util/*.[cSs] ${CMAKE_SOURCE_DIR}/src/core/*.c) file(GLOB GUI_SRC ${CMAKE_SOURCE_DIR}/src/util/gui/*.c ${CMAKE_SOURCE_DIR}/src/gba/gui/*.c) file(GLOB GBA_RENDERER_SRC ${CMAKE_SOURCE_DIR}/src/gba/renderers/*.c) file(GLOB SIO_SRC ${CMAKE_SOURCE_DIR}/src/gba/sio/lockstep.c)
M src/gb/gb.csrc/gb/gb.c

@@ -19,6 +19,8 @@ const uint32_t SGB_LR35902_FREQUENCY = 0x418B1E;

const uint32_t GB_COMPONENT_MAGIC = 0x400000; +mLOG_DEFINE_CATEGORY(GB); + static void GBInit(struct LR35902Core* cpu, struct LR35902Component* component); static void GBInterruptHandlerInit(struct LR35902InterruptHandler* irqh); static void GBProcessEvents(struct LR35902Core* cpu);

@@ -229,7 +231,7 @@ }

void GBHitStub(struct LR35902Core* cpu) { // TODO - //printf("Hit stub at address %04X\n", cpu->pc); + mLOG(GB, STUB, "Hit stub at address %04X:%02X\n", cpu->pc, cpu->bus); } bool GBIsROM(struct VFile* vf) {
M src/gb/gb.hsrc/gb/gb.h

@@ -8,6 +8,8 @@ #define GB_H

#include "util/common.h" +#include "core/log.h" + #include "lr35902/lr35902.h" #include "gb/memory.h"

@@ -17,6 +19,8 @@

extern const uint32_t DMG_LR35902_FREQUENCY; extern const uint32_t CGB_LR35902_FREQUENCY; extern const uint32_t SGB_LR35902_FREQUENCY; + +mLOG_DECLARE_CATEGORY(GB); // TODO: Prefix GBAIRQ enum GBIRQ {
M src/gb/io.csrc/gb/io.c

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

#include "gb/gb.h" +mLOG_DEFINE_CATEGORY(GB_IO); + void GBIOInit(struct GB* gb) { memset(gb->memory.io, 0, sizeof(gb->memory.io)); }
M src/gb/io.hsrc/gb/io.h

@@ -8,6 +8,10 @@ #define GB_IO_H

#include "util/common.h" +#include "core/log.h" + +mLOG_DECLARE_CATEGORY(GB_IO); + enum GBIORegisters { REG_JOYP = 0x00, REG_SB = 0x01,
M src/gb/memory.csrc/gb/memory.c

@@ -10,11 +10,15 @@ #include "gb/io.h"

#include "util/memory.h" +mLOG_DEFINE_CATEGORY(GB_MBC); +mLOG_DEFINE_CATEGORY(GB_MEM); + static void _GBMBCNone(struct GBMemory* memory, uint16_t address, uint8_t value) { - // TODO: Log game error UNUSED(memory); UNUSED(address); UNUSED(value); + + mLOG(GB_MBC, GAME_ERROR, "Wrote to invalid MBC"); } static void _GBMBC1(struct GBMemory*, uint16_t address, uint8_t value);

@@ -106,7 +110,7 @@ gb->memory.mbc = _GBMBC4;

gb->memory.mbcType = GB_MBC4; break; default: - // TODO: Log + mLOG(GB_MBC, WARN, "Unknown MBC type: %02X", cart->type); case 0x19: case 0x1A: case 0x1B:

@@ -166,6 +170,7 @@ }

return 0xFF; } if (address < GB_BASE_IO) { + mLOG(GB_MEM, GAME_ERROR, "Attempt to read from unusable memory: %04X", address); return 0xFF; } if (address < GB_BASE_HRAM) {

@@ -220,7 +225,7 @@ gb->video.oam.raw[address & 0xFF] = value;

gb->video.renderer->writeOAM(gb->video.renderer, address & 0xFF); } } else if (address < GB_BASE_IO) { - // TODO: Log + mLOG(GB_MEM, GAME_ERROR, "Attempt to write to unusable memory: %04X:%02X", address, value); } else if (address < GB_BASE_HRAM) { GBIOWrite(gb, address & (GB_SIZE_IO - 1), value); } else if (address < GB_BASE_IE) {

@@ -297,7 +302,7 @@

static void _switchBank(struct GBMemory* memory, int bank) { size_t bankStart = bank * GB_SIZE_CART_BANK0; if (bankStart + GB_SIZE_CART_BANK0 > memory->romSize) { - // TODO: Log + mLOG(GB_MBC, GAME_ERROR, "Attempting to switch to an invalid ROM bank: %0X", bank); return; } memory->romBank = &memory->rom[bankStart];

@@ -324,6 +329,7 @@ _switchSramBank(memory, memory->sramCurrentBank);

break; default: // TODO + mLOG(GB_MBC, STUB, "MBC1 unknown value %02X", value); break; } break;

@@ -338,7 +344,7 @@ }

} void _GBMBC2(struct GBMemory* memory, uint16_t address, uint8_t value) { - // TODO + mLOG(GB_MBC, STUB, "MBC2 unimplemented"); } void _GBMBC3(struct GBMemory* memory, uint16_t address, uint8_t value) {

@@ -355,6 +361,7 @@ _switchSramBank(memory, memory->sramCurrentBank);

break; default: // TODO + mLOG(GB_MBC, STUB, "MBC3 unknown value %02X", value); break; } break;

@@ -374,6 +381,7 @@ }

void _GBMBC4(struct GBMemory* memory, uint16_t address, uint8_t value) { // TODO + mLOG(GB_MBC, STUB, "MBC4 unimplemented"); } void _GBMBC5(struct GBMemory* memory, uint16_t address, uint8_t value) {

@@ -390,6 +398,7 @@ _switchSramBank(memory, memory->sramCurrentBank);

break; default: // TODO + mLOG(GB_MBC, STUB, "MBC5 unknown value %02X", value); break; } break;

@@ -402,4 +411,5 @@ }

void _GBMBC7(struct GBMemory* memory, uint16_t address, uint8_t value) { // TODO + mLOG(GB_MBC, STUB, "MBC7 unimplemented"); }
M src/gb/memory.hsrc/gb/memory.h

@@ -8,7 +8,12 @@ #define GB_MEMORY_H

#include "util/common.h" +#include "core/log.h" + #include "lr35902/lr35902.h" + +mLOG_DECLARE_CATEGORY(GB_MBC); +mLOG_DECLARE_CATEGORY(GB_MEM); struct GB;