Make GBALog actually use its log levels

This commit is contained in:
Jeffrey Pfau 2013-09-22 15:01:23 -07:00
parent 7978a57128
commit 2a6e7db693
7 changed files with 31 additions and 22 deletions

View File

@ -13,7 +13,7 @@ static void _unRl(struct GBAMemory* memory, uint32_t source, uint8_t* dest);
static void _RegisterRamReset(struct GBA* gba) { static void _RegisterRamReset(struct GBA* gba) {
uint32_t registers = gba->cpu.gprs[0]; uint32_t registers = gba->cpu.gprs[0];
(void)(registers); (void)(registers);
GBALog(GBA_LOG_STUB, "RegisterRamReset unimplemented"); GBALog(gba, GBA_LOG_STUB, "RegisterRamReset unimplemented");
} }
static void _CpuSet(struct GBA* gba) { 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)]); _unLz77(&gba->memory, gba->cpu.gprs[0], &((uint8_t*) gba->video.renderer->vram)[(gba->cpu.gprs[1] & 0x0001FFFF)]);
break; break;
default: default:
GBALog(GBA_LOG_WARN, "Bad LZ77 destination"); GBALog(gba, GBA_LOG_WARN, "Bad LZ77 destination");
break; break;
} }
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)]); _unRl(&gba->memory, gba->cpu.gprs[0], &((uint8_t*) gba->video.renderer->vram)[(gba->cpu.gprs[1] & 0x0001FFFF)]);
break; break;
default: default:
GBALog(GBA_LOG_WARN, "Bad RL destination"); GBALog(gba, GBA_LOG_WARN, "Bad RL destination");
break; break;
} }
break; break;
@ -255,7 +255,7 @@ void GBASwi16(struct ARMBoard* board, int immediate) {
_MidiKey2Freq(gba); _MidiKey2Freq(gba);
break; break;
default: default:
GBALog(GBA_LOG_STUB, "Stub software interrupt: %02x", immediate); GBALog(gba, GBA_LOG_STUB, "Stub software interrupt: %02x", immediate);
} }
} }

View File

@ -113,7 +113,7 @@ void GBAIOWrite(struct GBA* gba, uint32_t address, uint16_t value) {
// Some bad interrupt libraries will write to this // Some bad interrupt libraries will write to this
break; break;
default: 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; break;
} }
} }
@ -126,7 +126,7 @@ void GBAIOWrite8(struct GBA* gba, uint32_t address, uint8_t value) {
if (!value) { if (!value) {
GBAHalt(gba); GBAHalt(gba);
} else { } else {
GBALog(GBA_LOG_STUB, "Stop unimplemented"); GBALog(gba, GBA_LOG_STUB, "Stop unimplemented");
} }
return; return;
} }
@ -216,7 +216,7 @@ uint16_t GBAIORead(struct GBA* gba, uint32_t address) {
// Some bad interrupt libraries will read from this // Some bad interrupt libraries will read from this
break; break;
default: 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; break;
} }
return gba->memory.io[address >> 1]; return gba->memory.io[address >> 1];

View File

@ -554,7 +554,7 @@ uint16_t GBAMemoryWriteDMACNT_HI(struct GBAMemory* memory, int dma, uint16_t con
currentDma->nextIRQ = 0; currentDma->nextIRQ = 0;
if (currentDma->drq) { if (currentDma->drq) {
GBALog(GBA_LOG_STUB, "DRQ not implemented"); GBALog(memory->p, GBA_LOG_STUB, "DRQ not implemented");
} }
if (!wasEnabled && currentDma->enable) { if (!wasEnabled && currentDma->enable) {
@ -581,7 +581,7 @@ void GBAMemoryScheduleDMA(struct GBAMemory* memory, int number, struct GBADMA* i
case DMA_TIMING_CUSTOM: case DMA_TIMING_CUSTOM:
switch (number) { switch (number) {
case 0: case 0:
GBALog(GBA_LOG_WARN, "Discarding invalid DMA0 scheduling"); GBALog(memory->p, GBA_LOG_WARN, "Discarding invalid DMA0 scheduling");
break; break;
case 1: case 1:
case 2: case 2:

View File

@ -42,7 +42,7 @@ void GBASavedataInitFlash(struct GBASavedata* savedata) {
off_t end; off_t end;
int flags = MAP_SHARED; int flags = MAP_SHARED;
if (savedata->fd < 0) { 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; end = 0;
flags |= MAP_ANON; flags |= MAP_ANON;
} else { } else {
@ -64,7 +64,7 @@ void GBASavedataInitEEPROM(struct GBASavedata* savedata) {
off_t end; off_t end;
int flags = MAP_SHARED; int flags = MAP_SHARED;
if (savedata->fd < 0) { 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; end = 0;
flags |= MAP_ANON; flags |= MAP_ANON;
} else { } else {
@ -85,7 +85,7 @@ void GBASavedataInitSRAM(struct GBASavedata* savedata) {
off_t end; off_t end;
int flags = MAP_SHARED; int flags = MAP_SHARED;
if (savedata->fd < 0) { 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; end = 0;
flags |= MAP_ANON; flags |= MAP_ANON;
} else { } else {
@ -104,7 +104,7 @@ void GBASavedataInitSRAM(struct GBASavedata* savedata) {
void GBASavedataWriteFlash(struct GBASavedata* savedata, uint8_t value) { void GBASavedataWriteFlash(struct GBASavedata* savedata, uint8_t value) {
(void)(savedata); (void)(savedata);
(void)(value); (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) { void GBASavedataWriteEEPROM(struct GBASavedata* savedata, uint16_t value, uint32_t writeSize) {

View File

@ -47,6 +47,8 @@ void GBAInit(struct GBA* gba) {
gba->springIRQ = 0; gba->springIRQ = 0;
gba->keySource = 0; gba->keySource = 0;
gba->logLevel = GBA_LOG_INFO;
ARMReset(&gba->cpu); 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) { void GBAWriteIE(struct GBA* gba, uint16_t value) {
if (value & (1 << IRQ_SIO)) { 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)) { 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)) { 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]) { 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); return GBAWaitForIRQ(gba);
} }
void GBALog(int level, const char* format, ...) { void GBALog(struct GBA* gba, enum GBALogLevel level, const char* format, ...) {
(void)(level); if (gba && level < gba->logLevel) {
return;
}
va_list args; va_list args;
va_start(args, format); va_start(args, format);
vprintf(format, args); vprintf(format, args);
@ -371,8 +375,8 @@ void GBALog(int level, const char* format, ...) {
} }
void GBAHitStub(struct ARMBoard* board, uint32_t opcode) { void GBAHitStub(struct ARMBoard* board, uint32_t opcode) {
GBALog(GBA_LOG_STUB, "Stub opcode: %08x", opcode);
struct GBABoard* gbaBoard = (struct GBABoard*) board; struct GBABoard* gbaBoard = (struct GBABoard*) board;
GBALog(gbaBoard->p, GBA_LOG_STUB, "Stub opcode: %08x", opcode);
if (!gbaBoard->p->debugger) { if (!gbaBoard->p->debugger) {
abort(); abort();
} else { } else {

View File

@ -30,7 +30,10 @@ enum GBAError {
enum GBALogLevel { enum GBALogLevel {
GBA_LOG_STUB, GBA_LOG_STUB,
GBA_LOG_WARN GBA_LOG_DEBUG,
GBA_LOG_INFO,
GBA_LOG_WARN,
GBA_LOG_ERROR
}; };
enum GBAKey { enum GBAKey {
@ -77,6 +80,7 @@ struct GBA {
enum GBAError errno; enum GBAError errno;
const char* errstr; const char* errstr;
enum GBALogLevel logLevel;
}; };
void GBAInit(struct GBA* gba); 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 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 #endif

View File

@ -291,7 +291,7 @@ static uint16_t GBAVideoSoftwareRendererWriteVideoRegister(struct GBAVideoRender
softwareRenderer->objwin.packed = value >> 8; softwareRenderer->objwin.packed = value >> 8;
break; break;
default: default:
GBALog(GBA_LOG_STUB, "Stub video register write: %03x", address); GBALog(0, GBA_LOG_STUB, "Stub video register write: %03x", address);
} }
return value; return value;
} }