Make GBALog actually use its log levels
@@ -13,7 +13,7 @@
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 @@ case REGION_VRAM:
_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 @@ case REGION_VRAM:
_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 @@ case 0x1F:
_MidiKey2Freq(gba); break; default: - GBALog(GBA_LOG_STUB, "Stub software interrupt: %02x", immediate); + GBALog(gba, GBA_LOG_STUB, "Stub software interrupt: %02x", immediate); } }
@@ -113,7 +113,7 @@ case 0x20A:
// 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 @@ value &= 0x80;
if (!value) { GBAHalt(gba); } else { - GBALog(GBA_LOG_STUB, "Stop unimplemented"); + GBALog(gba, GBA_LOG_STUB, "Stop unimplemented"); } return; }@@ -216,7 +216,7 @@ case 0x20A:
// 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];
@@ -554,7 +554,7 @@ currentDma->packed = control;
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 @@ break;
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:
@@ -42,7 +42,7 @@ savedata->fd = open(savedata->filename, O_RDWR | O_CREAT, 0666);
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 @@ savedata->fd = open(savedata->filename, O_RDWR | O_CREAT, 0666);
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 @@ savedata->fd = open(savedata->filename, O_RDWR | O_CREAT, 0666);
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 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) {
@@ -47,6 +47,8 @@
gba->springIRQ = 0; gba->keySource = 0; + gba->logLevel = GBA_LOG_INFO; + ARMReset(&gba->cpu); }@@ -298,15 +300,15 @@ };
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 @@ printf("\n");
} 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 {
@@ -30,7 +30,10 @@ };
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 @@ int* keySource;
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
@@ -291,7 +291,7 @@ softwareRenderer->winout.packed = value;
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; }