diff --git a/src/gba/gba-bios.c b/src/gba/gba-bios.c index 51b186e82..9cfadc480 100644 --- a/src/gba/gba-bios.c +++ b/src/gba/gba-bios.c @@ -13,7 +13,7 @@ static void _unRl(struct GBAMemory* memory, uint32_t source, uint8_t* dest); static void _RegisterRamReset(struct GBA* gba) { uint32_t registers = gba->cpu.gprs[0]; (void)(registers); - GBALog(GBA_LOG_STUB, "RegisterRamReset unimplemented"); + GBALog(gba, GBA_LOG_STUB, "RegisterRamReset unimplemented"); } static void _CpuSet(struct GBA* gba) { @@ -230,7 +230,7 @@ void GBASwi16(struct ARMBoard* board, int immediate) { _unLz77(&gba->memory, gba->cpu.gprs[0], &((uint8_t*) gba->video.renderer->vram)[(gba->cpu.gprs[1] & 0x0001FFFF)]); break; default: - GBALog(GBA_LOG_WARN, "Bad LZ77 destination"); + GBALog(gba, GBA_LOG_WARN, "Bad LZ77 destination"); break; } break; @@ -247,7 +247,7 @@ void GBASwi16(struct ARMBoard* board, int immediate) { _unRl(&gba->memory, gba->cpu.gprs[0], &((uint8_t*) gba->video.renderer->vram)[(gba->cpu.gprs[1] & 0x0001FFFF)]); break; default: - GBALog(GBA_LOG_WARN, "Bad RL destination"); + GBALog(gba, GBA_LOG_WARN, "Bad RL destination"); break; } break; @@ -255,7 +255,7 @@ void GBASwi16(struct ARMBoard* board, int immediate) { _MidiKey2Freq(gba); break; default: - GBALog(GBA_LOG_STUB, "Stub software interrupt: %02x", immediate); + GBALog(gba, GBA_LOG_STUB, "Stub software interrupt: %02x", immediate); } } diff --git a/src/gba/gba-io.c b/src/gba/gba-io.c index 59fdbfd90..34275718a 100644 --- a/src/gba/gba-io.c +++ b/src/gba/gba-io.c @@ -113,7 +113,7 @@ void GBAIOWrite(struct GBA* gba, uint32_t address, uint16_t value) { // Some bad interrupt libraries will write to this break; default: - GBALog(GBA_LOG_STUB, "Stub I/O register write: %03x", address); + GBALog(gba, GBA_LOG_STUB, "Stub I/O register write: %03x", address); break; } } @@ -126,7 +126,7 @@ void GBAIOWrite8(struct GBA* gba, uint32_t address, uint8_t value) { if (!value) { GBAHalt(gba); } else { - GBALog(GBA_LOG_STUB, "Stop unimplemented"); + GBALog(gba, GBA_LOG_STUB, "Stop unimplemented"); } return; } @@ -216,7 +216,7 @@ uint16_t GBAIORead(struct GBA* gba, uint32_t address) { // Some bad interrupt libraries will read from this break; default: - GBALog(GBA_LOG_STUB, "Stub I/O register read: %03x", address); + GBALog(gba, GBA_LOG_STUB, "Stub I/O register read: %03x", address); break; } return gba->memory.io[address >> 1]; diff --git a/src/gba/gba-memory.c b/src/gba/gba-memory.c index fca8dc54e..66c16e377 100644 --- a/src/gba/gba-memory.c +++ b/src/gba/gba-memory.c @@ -554,7 +554,7 @@ uint16_t GBAMemoryWriteDMACNT_HI(struct GBAMemory* memory, int dma, uint16_t con currentDma->nextIRQ = 0; if (currentDma->drq) { - GBALog(GBA_LOG_STUB, "DRQ not implemented"); + GBALog(memory->p, GBA_LOG_STUB, "DRQ not implemented"); } if (!wasEnabled && currentDma->enable) { @@ -581,7 +581,7 @@ void GBAMemoryScheduleDMA(struct GBAMemory* memory, int number, struct GBADMA* i case DMA_TIMING_CUSTOM: switch (number) { case 0: - GBALog(GBA_LOG_WARN, "Discarding invalid DMA0 scheduling"); + GBALog(memory->p, GBA_LOG_WARN, "Discarding invalid DMA0 scheduling"); break; case 1: case 2: diff --git a/src/gba/gba-savedata.c b/src/gba/gba-savedata.c index edb1db35c..2d8a2a0b3 100644 --- a/src/gba/gba-savedata.c +++ b/src/gba/gba-savedata.c @@ -42,7 +42,7 @@ void GBASavedataInitFlash(struct GBASavedata* savedata) { off_t end; int flags = MAP_SHARED; if (savedata->fd < 0) { - GBALog(GBA_LOG_WARN, "Cannot open savedata file %s (errno: %d)", savedata->filename, errno); + GBALog(0, GBA_LOG_ERROR, "Cannot open savedata file %s (errno: %d)", savedata->filename, errno); end = 0; flags |= MAP_ANON; } else { @@ -64,7 +64,7 @@ void GBASavedataInitEEPROM(struct GBASavedata* savedata) { off_t end; int flags = MAP_SHARED; if (savedata->fd < 0) { - GBALog(GBA_LOG_WARN, "Cannot open savedata file %s (errno: %d)", savedata->filename, errno); + GBALog(0, GBA_LOG_ERROR, "Cannot open savedata file %s (errno: %d)", savedata->filename, errno); end = 0; flags |= MAP_ANON; } else { @@ -85,7 +85,7 @@ void GBASavedataInitSRAM(struct GBASavedata* savedata) { off_t end; int flags = MAP_SHARED; if (savedata->fd < 0) { - GBALog(GBA_LOG_WARN, "Cannot open savedata file %s (errno: %d)", savedata->filename, errno); + GBALog(0, GBA_LOG_ERROR, "Cannot open savedata file %s (errno: %d)", savedata->filename, errno); end = 0; flags |= MAP_ANON; } else { @@ -104,7 +104,7 @@ void GBASavedataInitSRAM(struct GBASavedata* savedata) { void GBASavedataWriteFlash(struct GBASavedata* savedata, uint8_t value) { (void)(savedata); (void)(value); - GBALog(GBA_LOG_STUB, "Flash memory unimplemented"); + GBALog(0, GBA_LOG_STUB, "Flash memory unimplemented"); } void GBASavedataWriteEEPROM(struct GBASavedata* savedata, uint16_t value, uint32_t writeSize) { diff --git a/src/gba/gba.c b/src/gba/gba.c index b40745002..39fd4beeb 100644 --- a/src/gba/gba.c +++ b/src/gba/gba.c @@ -47,6 +47,8 @@ void GBAInit(struct GBA* gba) { gba->springIRQ = 0; gba->keySource = 0; + gba->logLevel = GBA_LOG_INFO; + ARMReset(&gba->cpu); } @@ -298,15 +300,15 @@ void GBATimerWriteTMCNT_HI(struct GBA* gba, int timer, uint16_t control) { void GBAWriteIE(struct GBA* gba, uint16_t value) { if (value & (1 << IRQ_SIO)) { - GBALog(GBA_LOG_STUB, "SIO interrupts not implemented"); + GBALog(gba, GBA_LOG_STUB, "SIO interrupts not implemented"); } if (value & (1 << IRQ_KEYPAD)) { - GBALog(GBA_LOG_STUB, "Keypad interrupts not implemented"); + GBALog(gba, GBA_LOG_STUB, "Keypad interrupts not implemented"); } if (value & (1 << IRQ_GAMEPAK)) { - GBALog(GBA_LOG_STUB, "Gamepak interrupts not implemented"); + GBALog(gba, GBA_LOG_STUB, "Gamepak interrupts not implemented"); } if (gba->memory.io[REG_IME >> 1] && value & gba->memory.io[REG_IF >> 1]) { @@ -361,8 +363,10 @@ int GBAHalt(struct GBA* gba) { return GBAWaitForIRQ(gba); } -void GBALog(int level, const char* format, ...) { - (void)(level); +void GBALog(struct GBA* gba, enum GBALogLevel level, const char* format, ...) { + if (gba && level < gba->logLevel) { + return; + } va_list args; va_start(args, format); vprintf(format, args); @@ -371,8 +375,8 @@ void GBALog(int level, const char* format, ...) { } void GBAHitStub(struct ARMBoard* board, uint32_t opcode) { - GBALog(GBA_LOG_STUB, "Stub opcode: %08x", opcode); struct GBABoard* gbaBoard = (struct GBABoard*) board; + GBALog(gbaBoard->p, GBA_LOG_STUB, "Stub opcode: %08x", opcode); if (!gbaBoard->p->debugger) { abort(); } else { diff --git a/src/gba/gba.h b/src/gba/gba.h index 3628ad56b..8c854881e 100644 --- a/src/gba/gba.h +++ b/src/gba/gba.h @@ -30,7 +30,10 @@ enum GBAError { enum GBALogLevel { GBA_LOG_STUB, - GBA_LOG_WARN + GBA_LOG_DEBUG, + GBA_LOG_INFO, + GBA_LOG_WARN, + GBA_LOG_ERROR }; enum GBAKey { @@ -77,6 +80,7 @@ struct GBA { enum GBAError errno; const char* errstr; + enum GBALogLevel logLevel; }; void GBAInit(struct GBA* gba); @@ -103,6 +107,7 @@ void GBAAttachDebugger(struct GBA* gba, struct ARMDebugger* debugger); void GBALoadROM(struct GBA* gba, int fd); -void GBALog(int level, const char* format, ...); +__attribute__((format (printf, 3, 4))) +void GBALog(struct GBA* gba, enum GBALogLevel level, const char* format, ...); #endif diff --git a/src/gba/renderers/video-software.c b/src/gba/renderers/video-software.c index 682bcd28a..159dfe9d6 100644 --- a/src/gba/renderers/video-software.c +++ b/src/gba/renderers/video-software.c @@ -291,7 +291,7 @@ static uint16_t GBAVideoSoftwareRendererWriteVideoRegister(struct GBAVideoRender softwareRenderer->objwin.packed = value >> 8; break; default: - GBALog(GBA_LOG_STUB, "Stub video register write: %03x", address); + GBALog(0, GBA_LOG_STUB, "Stub video register write: %03x", address); } return value; }