GBA: Kill GBALog

This commit is contained in:
Jeffrey Pfau 2016-02-11 23:50:58 -08:00
parent 74fc29fc68
commit ff637c84d1
39 changed files with 224 additions and 216 deletions

View File

@ -15,6 +15,8 @@ const uint32_t DEBUGGER_ID = 0xDEADBEEF;
DEFINE_VECTOR(DebugBreakpointList, struct DebugBreakpoint); DEFINE_VECTOR(DebugBreakpointList, struct DebugBreakpoint);
DEFINE_VECTOR(DebugWatchpointList, struct DebugWatchpoint); DEFINE_VECTOR(DebugWatchpointList, struct DebugWatchpoint);
mLOG_DEFINE_CATEGORY(DEBUGGER, "Debugger");
static struct DebugBreakpoint* _lookupBreakpoint(struct DebugBreakpointList* breakpoints, uint32_t address) { static struct DebugBreakpoint* _lookupBreakpoint(struct DebugBreakpointList* breakpoints, uint32_t address) {
size_t i; size_t i;
for (i = 0; i < DebugBreakpointListSize(breakpoints); ++i) { for (i = 0; i < DebugBreakpointListSize(breakpoints); ++i) {

View File

@ -9,8 +9,11 @@
#include "util/common.h" #include "util/common.h"
#include "arm/arm.h" #include "arm/arm.h"
#include "core/log.h"
#include "util/vector.h" #include "util/vector.h"
mLOG_DECLARE_CATEGORY(DEBUGGER);
extern const uint32_t DEBUGGER_ID; extern const uint32_t DEBUGGER_ID;
enum DebuggerType { enum DebuggerType {
@ -105,9 +108,6 @@ struct Debugger {
bool (*setSoftwareBreakpoint)(struct Debugger*, uint32_t address, enum ExecutionMode mode, uint32_t* opcode); bool (*setSoftwareBreakpoint)(struct Debugger*, uint32_t address, enum ExecutionMode mode, uint32_t* opcode);
bool (*clearSoftwareBreakpoint)(struct Debugger*, uint32_t address, enum ExecutionMode mode, uint32_t opcode); bool (*clearSoftwareBreakpoint)(struct Debugger*, uint32_t address, enum ExecutionMode mode, uint32_t opcode);
ATTRIBUTE_FORMAT(printf, 3, 4)
void (*log)(struct Debugger*, enum DebuggerLogLevel, const char* format, ...);
}; };
void DebuggerCreate(struct Debugger*); void DebuggerCreate(struct Debugger*);

View File

@ -100,9 +100,7 @@ static void _ack(struct GDBStub* stub) {
static void _nak(struct GDBStub* stub) { static void _nak(struct GDBStub* stub) {
char nak = '-'; char nak = '-';
if (stub->d.log) { mLOG(DEBUGGER, WARN, "Packet error");
stub->d.log(&stub->d, DEBUGGER_LOG_WARN, "Packet error");
}
SocketSend(stub->connection, &nak, 1); SocketSend(stub->connection, &nak, 1);
} }
@ -181,9 +179,7 @@ static void _sendMessage(struct GDBStub* stub) {
stub->outgoing[i] = '#'; stub->outgoing[i] = '#';
_int2hex8(checksum, &stub->outgoing[i + 1]); _int2hex8(checksum, &stub->outgoing[i + 1]);
stub->outgoing[i + 3] = 0; stub->outgoing[i + 3] = 0;
if (stub->d.log) { mLOG(DEBUGGER, DEBUG, "> %s", stub->outgoing);
stub->d.log(&stub->d, DEBUGGER_LOG_DEBUG, "> %s", stub->outgoing);
}
SocketSend(stub->connection, stub->outgoing, i + 3); SocketSend(stub->connection, stub->outgoing, i + 3);
} }
@ -408,9 +404,7 @@ size_t _parseGDBMessage(struct GDBStub* stub, const char* message) {
parsed += 2; parsed += 2;
int networkChecksum = _hex2int(&message[i], 2); int networkChecksum = _hex2int(&message[i], 2);
if (networkChecksum != checksum) { if (networkChecksum != checksum) {
if (stub->d.log) { mLOG(DEBUGGER, WARN, "Checksum error: expected %02x, got %02x", checksum, networkChecksum);
stub->d.log(&stub->d, DEBUGGER_LOG_WARN, "Checksum error: expected %02x, got %02x", checksum, networkChecksum);
}
_nak(stub); _nak(stub);
return parsed; return parsed;
} }
@ -476,7 +470,6 @@ void GDBStubCreate(struct GDBStub* stub) {
stub->d.paused = _gdbStubWait; stub->d.paused = _gdbStubWait;
stub->d.entered = _gdbStubEntered; stub->d.entered = _gdbStubEntered;
stub->d.custom = _gdbStubPoll; stub->d.custom = _gdbStubPoll;
stub->d.log = 0;
stub->untilPoll = GDB_STUB_INTERVAL; stub->untilPoll = GDB_STUB_INTERVAL;
stub->lineAck = GDB_ACK_PENDING; stub->lineAck = GDB_ACK_PENDING;
stub->shouldBlock = false; stub->shouldBlock = false;
@ -488,9 +481,7 @@ bool GDBStubListen(struct GDBStub* stub, int port, const struct Address* bindAdd
} }
stub->socket = SocketOpenTCP(port, bindAddress); stub->socket = SocketOpenTCP(port, bindAddress);
if (SOCKET_FAILED(stub->socket)) { if (SOCKET_FAILED(stub->socket)) {
if (stub->d.log) { mLOG(DEBUGGER, ERROR, "Couldn't open socket");
stub->d.log(&stub->d, DEBUGGER_LOG_ERROR, "Couldn't open socket");
}
return false; return false;
} }
if (!SocketSetBlocking(stub->socket, false)) { if (!SocketSetBlocking(stub->socket, false)) {
@ -504,9 +495,7 @@ bool GDBStubListen(struct GDBStub* stub, int port, const struct Address* bindAdd
return true; return true;
cleanup: cleanup:
if (stub->d.log) { mLOG(DEBUGGER, ERROR, "Couldn't listen on port");
stub->d.log(&stub->d, DEBUGGER_LOG_ERROR, "Couldn't listen on port");
}
SocketClose(stub->socket); SocketClose(stub->socket);
stub->socket = INVALID_SOCKET; stub->socket = INVALID_SOCKET;
return false; return false;
@ -570,9 +559,7 @@ void GDBStubUpdate(struct GDBStub* stub) {
goto connectionLost; goto connectionLost;
} }
stub->line[messageLen] = '\0'; stub->line[messageLen] = '\0';
if (stub->d.log) { mLOG(DEBUGGER, DEBUG, "< %s", stub->line);
stub->d.log(&stub->d, DEBUGGER_LOG_DEBUG, "< %s", stub->line);
}
ssize_t position = 0; ssize_t position = 0;
while (position < messageLen) { while (position < messageLen) {
position += _parseGDBMessage(stub, &stub->line[position]); position += _parseGDBMessage(stub, &stub->line[position]);
@ -580,8 +567,6 @@ void GDBStubUpdate(struct GDBStub* stub) {
} }
connectionLost: connectionLost:
if (stub->d.log) { mLOG(DEBUGGER, WARN, "Connection lost");
stub->d.log(&stub->d, DEBUGGER_LOG_INFO, "Connection lost");
}
GDBStubHangup(stub); GDBStubHangup(stub);
} }

View File

@ -11,6 +11,8 @@
#include "gba/serialize.h" #include "gba/serialize.h"
#include "gba/video.h" #include "gba/video.h"
mLOG_DEFINE_CATEGORY(GBA_AUDIO, "GBA Audio");
const unsigned GBA_AUDIO_SAMPLES = 2048; const unsigned GBA_AUDIO_SAMPLES = 2048;
const unsigned GBA_AUDIO_FIFO_SIZE = 8 * sizeof(int32_t); const unsigned GBA_AUDIO_FIFO_SIZE = 8 * sizeof(int32_t);
const int GBA_AUDIO_VOLUME_MAX = 0x100; const int GBA_AUDIO_VOLUME_MAX = 0x100;
@ -118,7 +120,7 @@ void GBAAudioScheduleFifoDma(struct GBAAudio* audio, int number, struct GBADMA*
audio->chB.dmaSource = number; audio->chB.dmaSource = number;
break; break;
default: default:
GBALog(audio->p, GBA_LOG_GAME_ERROR, "Invalid FIFO destination: 0x%08X", info->dest); mLOG(GBA_AUDIO, GAME_ERROR, "Invalid FIFO destination: 0x%08X", info->dest);
return; return;
} }
info->reg = GBADMARegisterSetDestControl(info->reg, DMA_FIXED); info->reg = GBADMARegisterSetDestControl(info->reg, DMA_FIXED);
@ -220,7 +222,7 @@ void GBAAudioWriteFIFO(struct GBAAudio* audio, int address, uint32_t value) {
fifo = &audio->chB.fifo; fifo = &audio->chB.fifo;
break; break;
default: default:
GBALog(audio->p, GBA_LOG_ERROR, "Bad FIFO write to address 0x%03x", address); mLOG(GBA_AUDIO, ERROR, "Bad FIFO write to address 0x%03x", address);
return; return;
} }
int i; int i;
@ -239,7 +241,7 @@ void GBAAudioSampleFIFO(struct GBAAudio* audio, int fifoId, int32_t cycles) {
} else if (fifoId == 1) { } else if (fifoId == 1) {
channel = &audio->chB; channel = &audio->chB;
} else { } else {
GBALog(audio->p, GBA_LOG_ERROR, "Bad FIFO write to address 0x%03x", fifoId); mLOG(GBA_AUDIO, ERROR, "Bad FIFO write to address 0x%03x", fifoId);
return; return;
} }
if (CircleBufferSize(&channel->fifo) <= 4 * sizeof(int32_t) && channel->dmaSource > 0) { if (CircleBufferSize(&channel->fifo) <= 4 * sizeof(int32_t) && channel->dmaSource > 0) {

View File

@ -9,9 +9,12 @@
#include "util/common.h" #include "util/common.h"
#include "macros.h" #include "macros.h"
#include "core/log.h"
#include "gb/audio.h" #include "gb/audio.h"
#include "util/circle-buffer.h" #include "util/circle-buffer.h"
mLOG_DECLARE_CATEGORY(GBA_AUDIO);
struct GBADMA; struct GBADMA;
extern const unsigned GBA_AUDIO_SAMPLES; extern const unsigned GBA_AUDIO_SAMPLES;

View File

@ -508,11 +508,11 @@ static void _unHuffman(struct GBA* gba) {
int remaining = header >> 8; int remaining = header >> 8;
int bits = header & 0xF; int bits = header & 0xF;
if (bits == 0) { if (bits == 0) {
GBALog(gba, GBA_LOG_GAME_ERROR, "Invalid Huffman bits"); mLOG(GBA_BIOS, GAME_ERROR, "Invalid Huffman bits");
bits = 8; bits = 8;
} }
if (32 % bits || bits == 1) { if (32 % bits || bits == 1) {
GBALog(gba, GBA_LOG_STUB, "Unimplemented unaligned Huffman"); mLOG(GBA_BIOS, STUB, "Unimplemented unaligned Huffman");
return; return;
} }
// We assume the signature byte (0x20) is correct // We assume the signature byte (0x20) is correct

View File

@ -15,6 +15,8 @@
const uint32_t GBA_CHEAT_DEVICE_ID = 0xABADC0DE; const uint32_t GBA_CHEAT_DEVICE_ID = 0xABADC0DE;
mLOG_DEFINE_CATEGORY(CHEATS, "Cheats");
DEFINE_VECTOR(GBACheatList, struct GBACheat); DEFINE_VECTOR(GBACheatList, struct GBACheat);
DEFINE_VECTOR(GBACheatSets, struct GBACheatSet*); DEFINE_VECTOR(GBACheatSets, struct GBACheatSet*);
DEFINE_VECTOR(StringList, char*); DEFINE_VECTOR(StringList, char*);

View File

@ -8,7 +8,8 @@
#include "util/common.h" #include "util/common.h"
#include "arm.h" #include "arm/arm.h"
#include "core/log.h"
#include "util/vector.h" #include "util/vector.h"
#define MAX_ROM_PATCHES 4 #define MAX_ROM_PATCHES 4
@ -151,6 +152,8 @@ struct GBACheatHook {
size_t reentries; size_t reentries;
}; };
mLOG_DECLARE_CATEGORY(CHEATS);
DECLARE_VECTOR(GBACheatList, struct GBACheat); DECLARE_VECTOR(GBACheatList, struct GBACheat);
DECLARE_VECTOR(StringList, char*); DECLARE_VECTOR(StringList, char*);

View File

@ -57,7 +57,7 @@ bool GBACheatAddCodeBreaker(struct GBACheatSet* cheats, uint32_t op1, uint16_t o
cheats->incompleteCheat = cheat; cheats->incompleteCheat = cheat;
break; break;
case CB_FILL_8: case CB_FILL_8:
GBALog(0, GBA_LOG_STUB, "[Cheat] CodeBreaker code %08X %04X not supported", op1, op2); mLOG(CHEATS, STUB, "CodeBreaker code %08X %04X not supported", op1, op2);
return false; return false;
case CB_AND_2: case CB_AND_2:
cheat = GBACheatListAppend(&cheats->list); cheat = GBACheatListAppend(&cheats->list);
@ -75,7 +75,7 @@ bool GBACheatAddCodeBreaker(struct GBACheatSet* cheats, uint32_t op1, uint16_t o
cheat->width = 2; cheat->width = 2;
break; break;
case CB_ENCRYPT: case CB_ENCRYPT:
GBALog(0, GBA_LOG_STUB, "[Cheat] CodeBreaker encryption not supported"); mLOG(CHEATS, STUB, "CodeBreaker encryption not supported");
return false; return false;
case CB_IF_NE: case CB_IF_NE:
cheat = GBACheatListAppend(&cheats->list); cheat = GBACheatListAppend(&cheats->list);
@ -103,7 +103,7 @@ bool GBACheatAddCodeBreaker(struct GBACheatSet* cheats, uint32_t op1, uint16_t o
cheat->repeat = 1; cheat->repeat = 1;
return true; return true;
default: default:
GBALog(0, GBA_LOG_STUB, "[Cheat] CodeBreaker code %08X %04X not supported", op1, op2); mLOG(CHEATS, STUB, "CodeBreaker code %08X %04X not supported", op1, op2);
return false; return false;
} }
case CB_ADD_2: case CB_ADD_2:

View File

@ -152,7 +152,7 @@ bool GBACheatAddGameSharkRaw(struct GBACheatSet* cheats, uint32_t op1, uint32_t
return true; return true;
case GSA_BUTTON: case GSA_BUTTON:
// TODO: Implement button // TODO: Implement button
GBALog(0, GBA_LOG_STUB, "GameShark button unimplemented"); mLOG(CHEATS, STUB, "GameShark button unimplemented");
return false; return false;
case GSA_IF_EQ: case GSA_IF_EQ:
if (op1 == 0xDEADFACE) { if (op1 == 0xDEADFACE) {

View File

@ -109,7 +109,7 @@ static bool _addPAR3Cond(struct GBACheatSet* cheats, uint32_t op1, uint32_t op2)
switch (condition) { switch (condition) {
case PAR3_COND_OTHER: case PAR3_COND_OTHER:
// We shouldn't be able to get here // We shouldn't be able to get here
GBALog(0, GBA_LOG_ERROR, "Unexpectedly created 'other' PARv3 code"); mLOG(CHEATS, ERROR, "Unexpectedly created 'other' PARv3 code");
cheat->type = CHEAT_IF_LAND; cheat->type = CHEAT_IF_LAND;
cheat->operand = 0; cheat->operand = 0;
break; break;
@ -148,7 +148,7 @@ static bool _addPAR3Special(struct GBACheatSet* cheats, uint32_t op2) {
case PAR3_OTHER_BUTTON_2: case PAR3_OTHER_BUTTON_2:
case PAR3_OTHER_BUTTON_4: case PAR3_OTHER_BUTTON_4:
// TODO: Button // TODO: Button
GBALog(0, GBA_LOG_STUB, "GameShark button unimplemented"); mLOG(CHEATS, STUB, "GameShark button unimplemented");
return false; return false;
// TODO: Fix overriding existing patches // TODO: Fix overriding existing patches
case PAR3_OTHER_PATCH_1: case PAR3_OTHER_PATCH_1:

View File

@ -225,7 +225,7 @@ static void GBAProcessEvents(struct ARMCore* cpu) {
int32_t testEvent; int32_t testEvent;
#ifndef NDEBUG #ifndef NDEBUG
if (cycles < 0) { if (cycles < 0) {
GBALog(gba, GBA_LOG_FATAL, "Negative cycles passed: %i", cycles); mLOG(GBA, FATAL, "Negative cycles passed: %i", cycles);
} }
#endif #endif
@ -434,7 +434,7 @@ bool GBALoadMB(struct GBA* gba, struct VFile* vf, const char* fname) {
gba->pristineRom = vf->map(vf, gba->pristineRomSize, MAP_READ); gba->pristineRom = vf->map(vf, gba->pristineRomSize, MAP_READ);
#endif #endif
if (!gba->pristineRom) { if (!gba->pristineRom) {
GBALog(gba, GBA_LOG_WARN, "Couldn't map ROM"); mLOG(GBA, WARN, "Couldn't map ROM");
return false; return false;
} }
gba->yankedRomSize = 0; gba->yankedRomSize = 0;
@ -463,7 +463,7 @@ bool GBALoadROM2(struct GBA* gba, struct VFile* vf) {
gba->pristineRom = vf->map(vf, gba->pristineRomSize, MAP_READ); gba->pristineRom = vf->map(vf, gba->pristineRomSize, MAP_READ);
#endif #endif
if (!gba->pristineRom) { if (!gba->pristineRom) {
GBALog(gba, GBA_LOG_WARN, "Couldn't map ROM"); mLOG(GBA, WARN, "Couldn't map ROM");
return false; return false;
} }
gba->yankedRomSize = 0; gba->yankedRomSize = 0;
@ -476,15 +476,6 @@ bool GBALoadROM2(struct GBA* gba, struct VFile* vf) {
return true; return true;
} }
bool GBALoadROM(struct GBA* gba, struct VFile* vf, struct VFile* sav, const char* fname) {
if (!GBALoadROM2(gba, vf)) {
return false;
}
gba->activeFile = fname;
GBALoadSave(gba, sav);
return true;
}
bool GBALoadSave(struct GBA* gba, struct VFile* sav) { bool GBALoadSave(struct GBA* gba, struct VFile* sav) {
GBASavedataInit(&gba->memory.savedata, sav); GBASavedataInit(&gba->memory.savedata, sav);
return true; return true;
@ -501,19 +492,19 @@ void GBALoadBIOS(struct GBA* gba, struct VFile* vf) {
gba->biosVf = vf; gba->biosVf = vf;
uint32_t* bios = vf->map(vf, SIZE_BIOS, MAP_READ); uint32_t* bios = vf->map(vf, SIZE_BIOS, MAP_READ);
if (!bios) { if (!bios) {
GBALog(gba, GBA_LOG_WARN, "Couldn't map BIOS"); mLOG(GBA, WARN, "Couldn't map BIOS");
return; return;
} }
gba->memory.bios = bios; gba->memory.bios = bios;
gba->memory.fullBios = 1; gba->memory.fullBios = 1;
uint32_t checksum = GBAChecksum(gba->memory.bios, SIZE_BIOS); uint32_t checksum = GBAChecksum(gba->memory.bios, SIZE_BIOS);
GBALog(gba, GBA_LOG_DEBUG, "BIOS Checksum: 0x%X", checksum); mLOG(GBA, DEBUG, "BIOS Checksum: 0x%X", checksum);
if (checksum == GBA_BIOS_CHECKSUM) { if (checksum == GBA_BIOS_CHECKSUM) {
GBALog(gba, GBA_LOG_INFO, "Official GBA BIOS detected"); mLOG(GBA, INFO, "Official GBA BIOS detected");
} else if (checksum == GBA_DS_BIOS_CHECKSUM) { } else if (checksum == GBA_DS_BIOS_CHECKSUM) {
GBALog(gba, GBA_LOG_INFO, "Official GBA (DS) BIOS detected"); mLOG(GBA, INFO, "Official GBA (DS) BIOS detected");
} else { } else {
GBALog(gba, GBA_LOG_WARN, "BIOS checksum incorrect"); mLOG(GBA, WARN, "BIOS checksum incorrect");
} }
gba->biosChecksum = checksum; gba->biosChecksum = checksum;
if (gba->memory.activeRegion == REGION_BIOS) { if (gba->memory.activeRegion == REGION_BIOS) {
@ -606,7 +597,7 @@ 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_KEYPAD)) { if (value & (1 << IRQ_KEYPAD)) {
GBALog(gba, GBA_LOG_STUB, "Keypad interrupts not implemented"); mLOG(GBA, STUB, "Keypad 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]) {
@ -650,14 +641,6 @@ void GBAStop(struct GBA* gba) {
gba->stopCallback->stop(gba->stopCallback); gba->stopCallback->stop(gba->stopCallback);
} }
void GBALog(struct GBA* gba, enum GBALogLevel level, const char* format, ...) {
// TODO: Kill GBALog
}
void GBADebuggerLogShim(struct Debugger* debugger, enum DebuggerLogLevel level, const char* format, ...) {
// TODO: Kill GBADebuggerLogShim
}
bool GBAIsROM(struct VFile* vf) { bool GBAIsROM(struct VFile* vf) {
if (vf->seek(vf, GBA_ROM_MAGIC_OFFSET, SEEK_SET) < 0) { if (vf->seek(vf, GBA_ROM_MAGIC_OFFSET, SEEK_SET) < 0) {
return false; return false;
@ -744,22 +727,22 @@ void GBAGetGameTitle(struct GBA* gba, char* out) {
void GBAHitStub(struct ARMCore* cpu, uint32_t opcode) { void GBAHitStub(struct ARMCore* cpu, uint32_t opcode) {
struct GBA* gba = (struct GBA*) cpu->master; struct GBA* gba = (struct GBA*) cpu->master;
enum GBALogLevel level = GBA_LOG_ERROR;
if (gba->debugger) { if (gba->debugger) {
level = GBA_LOG_STUB;
struct DebuggerEntryInfo info = { struct DebuggerEntryInfo info = {
.address = _ARMPCAddress(cpu), .address = _ARMPCAddress(cpu),
.opcode = opcode .opcode = opcode
}; };
DebuggerEnter(gba->debugger, DEBUGGER_ENTER_ILLEGAL_OP, &info); DebuggerEnter(gba->debugger, DEBUGGER_ENTER_ILLEGAL_OP, &info);
} }
GBALog(gba, level, "Stub opcode: %08x", opcode); // TODO: More sensible category?
mLOG(GBA, ERROR, "Stub opcode: %08x", opcode);
} }
void GBAIllegal(struct ARMCore* cpu, uint32_t opcode) { void GBAIllegal(struct ARMCore* cpu, uint32_t opcode) {
struct GBA* gba = (struct GBA*) cpu->master; struct GBA* gba = (struct GBA*) cpu->master;
if (!gba->yankedRomSize) { if (!gba->yankedRomSize) {
GBALog(gba, GBA_LOG_WARN, "Illegal opcode: %08x", opcode); // TODO: More sensible category?
mLOG(GBA, WARN, "Illegal opcode: %08x", opcode);
} }
if (gba->debugger) { if (gba->debugger) {
struct DebuggerEntryInfo info = { struct DebuggerEntryInfo info = {

View File

@ -170,7 +170,6 @@ void GBASetBreakpoint(struct GBA* gba, struct mCPUComponent* component, uint32_t
uint32_t* opcode); uint32_t* opcode);
void GBAClearBreakpoint(struct GBA* gba, uint32_t address, enum ExecutionMode mode, uint32_t opcode); void GBAClearBreakpoint(struct GBA* gba, uint32_t address, enum ExecutionMode mode, uint32_t opcode);
bool GBALoadROM(struct GBA* gba, struct VFile* vf, struct VFile* sav, const char* fname);
bool GBALoadROM2(struct GBA* gba, struct VFile* vf); bool GBALoadROM2(struct GBA* gba, struct VFile* vf);
bool GBALoadSave(struct GBA* gba, struct VFile* sav); bool GBALoadSave(struct GBA* gba, struct VFile* sav);
void GBAYankROM(struct GBA* gba); void GBAYankROM(struct GBA* gba);
@ -189,10 +188,4 @@ void GBAGetGameTitle(struct GBA* gba, char* out);
void GBAFrameStarted(struct GBA* gba); void GBAFrameStarted(struct GBA* gba);
void GBAFrameEnded(struct GBA* gba); void GBAFrameEnded(struct GBA* gba);
ATTRIBUTE_FORMAT(printf, 3, 4)
void GBALog(struct GBA* gba, enum GBALogLevel level, const char* format, ...);
ATTRIBUTE_FORMAT(printf, 3, 4)
void GBADebuggerLogShim(struct Debugger* debugger, enum DebuggerLogLevel level, const char* format, ...);
#endif #endif

View File

@ -10,6 +10,8 @@
#include "util/formatting.h" #include "util/formatting.h"
#include "util/hash.h" #include "util/hash.h"
mLOG_DEFINE_CATEGORY(GBA_HW, "GBA Pak Hardware");
const int GBA_LUX_LEVELS[10] = { 5, 11, 18, 27, 42, 62, 84, 109, 139, 183 }; const int GBA_LUX_LEVELS[10] = { 5, 11, 18, 27, 42, 62, 84, 109, 139, 183 };
static void _readPins(struct GBACartridgeHardware* hw); static void _readPins(struct GBACartridgeHardware* hw);
@ -84,7 +86,7 @@ void GBAHardwareGPIOWrite(struct GBACartridgeHardware* hw, uint32_t address, uin
hw->readWrite = value; hw->readWrite = value;
break; break;
default: default:
GBALog(hw->p, GBA_LOG_WARN, "Invalid GPIO address"); mLOG(GBA_HW, WARN, "Invalid GPIO address");
} }
if (hw->readWrite) { if (hw->readWrite) {
uint16_t old; uint16_t old;
@ -173,7 +175,7 @@ void _rtcReadPins(struct GBACartridgeHardware* hw) {
// GPIO direction should always != reading // GPIO direction should always != reading
if (hw->direction & 2) { if (hw->direction & 2) {
if (RTCCommandDataIsReading(hw->rtc.command)) { if (RTCCommandDataIsReading(hw->rtc.command)) {
GBALog(hw->p, GBA_LOG_GAME_ERROR, "Attempting to write to RTC while in read mode"); mLOG(GBA_HW, GAME_ERROR, "Attempting to write to RTC while in read mode");
} }
++hw->rtc.bitsRead; ++hw->rtc.bitsRead;
if (hw->rtc.bitsRead == 8) { if (hw->rtc.bitsRead == 8) {
@ -226,7 +228,7 @@ void _rtcProcessByte(struct GBACartridgeHardware* hw) {
break; break;
} }
} else { } else {
GBALog(hw->p, GBA_LOG_WARN, "Invalid RTC command byte: %02X", hw->rtc.bits); mLOG(GBA_HW, WARN, "Invalid RTC command byte: %02X", hw->rtc.bits);
} }
} else { } else {
switch (RTCCommandDataGetCommand(hw->rtc.command)) { switch (RTCCommandDataGetCommand(hw->rtc.command)) {
@ -234,7 +236,7 @@ void _rtcProcessByte(struct GBACartridgeHardware* hw) {
hw->rtc.control = hw->rtc.bits; hw->rtc.control = hw->rtc.bits;
break; break;
case RTC_FORCE_IRQ: case RTC_FORCE_IRQ:
GBALog(hw->p, GBA_LOG_STUB, "Unimplemented RTC command %u", RTCCommandDataGetCommand(hw->rtc.command)); mLOG(GBA_HW, STUB, "Unimplemented RTC command %u", RTCCommandDataGetCommand(hw->rtc.command));
break; break;
case RTC_RESET: case RTC_RESET:
case RTC_DATETIME: case RTC_DATETIME:
@ -388,7 +390,7 @@ void _lightReadPins(struct GBACartridgeHardware* hw) {
} }
if (hw->pinState & 2) { if (hw->pinState & 2) {
struct GBALuminanceSource* lux = hw->p->luminanceSource; struct GBALuminanceSource* lux = hw->p->luminanceSource;
GBALog(hw->p, GBA_LOG_DEBUG, "[SOLAR] Got reset"); mLOG(GBA_HW, DEBUG, "[SOLAR] Got reset");
hw->lightCounter = 0; hw->lightCounter = 0;
if (lux) { if (lux) {
lux->sample(lux); lux->sample(lux);
@ -404,7 +406,7 @@ void _lightReadPins(struct GBACartridgeHardware* hw) {
bool sendBit = hw->lightCounter >= hw->lightSample; bool sendBit = hw->lightCounter >= hw->lightSample;
_outputPins(hw, sendBit << 3); _outputPins(hw, sendBit << 3);
GBALog(hw->p, GBA_LOG_DEBUG, "[SOLAR] Output %u with pins %u", hw->lightCounter, hw->pinState); mLOG(GBA_HW, DEBUG, "[SOLAR] Output %u with pins %u", hw->lightCounter, hw->pinState);
} }
// == Tilt // == Tilt
@ -422,7 +424,7 @@ void GBAHardwareTiltWrite(struct GBACartridgeHardware* hw, uint32_t address, uin
if (value == 0x55) { if (value == 0x55) {
hw->tiltState = 1; hw->tiltState = 1;
} else { } else {
GBALog(hw->p, GBA_LOG_GAME_ERROR, "Tilt sensor wrote wrong byte to %04x: %02x", address, value); mLOG(GBA_HW, GAME_ERROR, "Tilt sensor wrote wrong byte to %04x: %02x", address, value);
} }
break; break;
case 0x8100: case 0x8100:
@ -441,11 +443,11 @@ void GBAHardwareTiltWrite(struct GBACartridgeHardware* hw, uint32_t address, uin
hw->tiltX = (x >> 21) + 0x3A0; // Crop off an extra bit so that we can't go negative hw->tiltX = (x >> 21) + 0x3A0; // Crop off an extra bit so that we can't go negative
hw->tiltY = (y >> 21) + 0x3A0; hw->tiltY = (y >> 21) + 0x3A0;
} else { } else {
GBALog(hw->p, GBA_LOG_GAME_ERROR, "Tilt sensor wrote wrong byte to %04x: %02x", address, value); mLOG(GBA_HW, GAME_ERROR, "Tilt sensor wrote wrong byte to %04x: %02x", address, value);
} }
break; break;
default: default:
GBALog(hw->p, GBA_LOG_GAME_ERROR, "Invalid tilt sensor write to %04x: %02x", address, value); mLOG(GBA_HW, GAME_ERROR, "Invalid tilt sensor write to %04x: %02x", address, value);
break; break;
} }
} }
@ -461,7 +463,7 @@ uint8_t GBAHardwareTiltRead(struct GBACartridgeHardware* hw, uint32_t address) {
case 0x8500: case 0x8500:
return (hw->tiltY >> 8) & 0xF; return (hw->tiltY >> 8) & 0xF;
default: default:
GBALog(hw->p, GBA_LOG_GAME_ERROR, "Invalid tilt sensor read from %04x", address); mLOG(GBA_HW, GAME_ERROR, "Invalid tilt sensor read from %04x", address);
break; break;
} }
return 0xFF; return 0xFF;

View File

@ -7,12 +7,16 @@
#define GBA_HARDWARE_H #define GBA_HARDWARE_H
#include "util/common.h" #include "util/common.h"
#include "core/log.h"
#include "gba/interface.h" #include "gba/interface.h"
#include "macros.h" #include "macros.h"
#include <time.h> #include <time.h>
mLOG_DECLARE_CATEGORY(GBA_HW);
#define IS_GPIO_REGISTER(reg) ((reg) == GPIO_REG_DATA || (reg) == GPIO_REG_DIRECTION || (reg) == GPIO_REG_CONTROL) #define IS_GPIO_REGISTER(reg) ((reg) == GPIO_REG_DATA || (reg) == GPIO_REG_DIRECTION || (reg) == GPIO_REG_CONTROL)
struct GBARTCGenericSource { struct GBARTCGenericSource {

View File

@ -10,21 +10,6 @@
#include "core/interface.h" #include "core/interface.h"
enum GBALogLevel {
GBA_LOG_FATAL = 0x01,
GBA_LOG_ERROR = 0x02,
GBA_LOG_WARN = 0x04,
GBA_LOG_INFO = 0x08,
GBA_LOG_DEBUG = 0x10,
GBA_LOG_STUB = 0x20,
GBA_LOG_GAME_ERROR = 0x100,
GBA_LOG_STATUS = 0x400,
GBA_LOG_SIO = 0x800,
GBA_LOG_ALL = 0xF3F,
};
enum GBASIOMode { enum GBASIOMode {
SIO_NORMAL_8 = 0, SIO_NORMAL_8 = 0,
SIO_NORMAL_32 = 1, SIO_NORMAL_32 = 1,

View File

@ -10,6 +10,8 @@
#include "gba/sio.h" #include "gba/sio.h"
#include "gba/video.h" #include "gba/video.h"
mLOG_DEFINE_CATEGORY(GBA_IO, "GBA I/O");
const char* GBAIORegisterNames[] = { const char* GBAIORegisterNames[] = {
// Video // Video
"DISPCNT", "DISPCNT",
@ -533,9 +535,9 @@ 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, GBA_LOG_STUB, "Stub I/O register write: %03X", address); mLOG(GBA_IO, STUB, "Stub I/O register write: %03X", address);
if (address >= REG_MAX) { if (address >= REG_MAX) {
GBALog(gba, GBA_LOG_GAME_ERROR, "Write to unused I/O register: %03X", address); mLOG(GBA_IO, GAME_ERROR, "Write to unused I/O register: %03X", address);
return; return;
} }
break; break;
@ -751,7 +753,7 @@ uint16_t GBAIORead(struct GBA* gba, uint32_t address) {
case REG_DMA3DAD_HI: case REG_DMA3DAD_HI:
case REG_DMA3CNT_LO: case REG_DMA3CNT_LO:
// Write-only register // Write-only register
GBALog(gba, GBA_LOG_GAME_ERROR, "Read from write-only I/O register: %03X", address); mLOG(GBA_IO, GAME_ERROR, "Read from write-only I/O register: %03X", address);
return GBALoadBad(gba->cpu); return GBALoadBad(gba->cpu);
case REG_SOUNDBIAS: case REG_SOUNDBIAS:
@ -760,7 +762,7 @@ uint16_t GBAIORead(struct GBA* gba, uint32_t address) {
case REG_JOY_TRANS: case REG_JOY_TRANS:
case REG_KEYCNT: case REG_KEYCNT:
case REG_POSTFLG: case REG_POSTFLG:
GBALog(gba, GBA_LOG_STUB, "Stub I/O register read: %03x", address); mLOG(GBA_IO, STUB, "Stub I/O register read: %03x", address);
break; break;
case REG_SOUND1CNT_LO: case REG_SOUND1CNT_LO:
case REG_SOUND1CNT_HI: case REG_SOUND1CNT_HI:
@ -822,7 +824,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, GBA_LOG_GAME_ERROR, "Read from unused I/O register: %03X", address); mLOG(GBA_IO, GAME_ERROR, "Read from unused I/O register: %03X", address);
return GBALoadBad(gba->cpu); return GBALoadBad(gba->cpu);
} }
return gba->memory.io[address >> 1]; return gba->memory.io[address >> 1];

View File

@ -151,6 +151,8 @@ enum GBAIORegisters {
REG_HALTCNT = 0x301 REG_HALTCNT = 0x301
}; };
mLOG_DECLARE_CATEGORY(GBA_IO);
extern const char* GBAIORegisterNames[]; extern const char* GBAIORegisterNames[];
void GBAIOInit(struct GBA* gba); void GBAIOInit(struct GBA* gba);

View File

@ -17,6 +17,8 @@
#define IDLE_LOOP_THRESHOLD 10000 #define IDLE_LOOP_THRESHOLD 10000
mLOG_DEFINE_CATEGORY(GBA_MEM, "GBA Memory");
static void _pristineCow(struct GBA* gba); static void _pristineCow(struct GBA* gba);
static uint32_t _deadbeef[1] = { 0xE710B710 }; // Illegal instruction on both ARM and Thumb static uint32_t _deadbeef[1] = { 0xE710B710 }; // Illegal instruction on both ARM and Thumb
@ -123,7 +125,7 @@ void GBAMemoryReset(struct GBA* gba) {
if (!gba->memory.wram || !gba->memory.iwram) { if (!gba->memory.wram || !gba->memory.iwram) {
GBAMemoryDeinit(gba); GBAMemoryDeinit(gba);
GBALog(gba, GBA_LOG_FATAL, "Could not map memory"); mLOG(GBA_MEM, FATAL, "Could not map memory");
} }
} }
@ -291,11 +293,11 @@ static void GBASetActiveRegion(struct ARMCore* cpu, uint32_t address) {
memory->activeRegion = -1; memory->activeRegion = -1;
cpu->memory.activeRegion = _deadbeef; cpu->memory.activeRegion = _deadbeef;
cpu->memory.activeMask = 0; cpu->memory.activeMask = 0;
enum GBALogLevel errorLevel = GBA_LOG_FATAL;
if (gba->yankedRomSize || !gba->hardCrash) { if (gba->yankedRomSize || !gba->hardCrash) {
errorLevel = GBA_LOG_GAME_ERROR; mLOG(GBA_MEM, GAME_ERROR, "Jumped to invalid address: %08X", address);
} else {
mLOG(GBA_MEM, FATAL, "Jumped to invalid address: %08X", address);
} }
GBALog(gba, errorLevel, "Jumped to invalid address: %08X", address);
return; return;
} }
cpu->memory.activeSeqCycles32 = memory->waitstatesSeq32[memory->activeRegion]; cpu->memory.activeSeqCycles32 = memory->waitstatesSeq32[memory->activeRegion];
@ -337,11 +339,11 @@ static void GBASetActiveRegion(struct ARMCore* cpu, uint32_t address) {
if (memory->activeRegion == REGION_BIOS) { \ if (memory->activeRegion == REGION_BIOS) { \
LOAD_32(value, address, memory->bios); \ LOAD_32(value, address, memory->bios); \
} else { \ } else { \
GBALog(gba, GBA_LOG_GAME_ERROR, "Bad BIOS Load32: 0x%08X", address); \ mLOG(GBA_MEM, GAME_ERROR, "Bad BIOS Load32: 0x%08X", address); \
value = memory->biosPrefetch; \ value = memory->biosPrefetch; \
} \ } \
} else { \ } else { \
GBALog(gba, GBA_LOG_GAME_ERROR, "Bad memory Load32: 0x%08X", address); \ mLOG(GBA_MEM, GAME_ERROR, "Bad memory Load32: 0x%08X", address); \
LOAD_BAD; \ LOAD_BAD; \
} }
@ -371,7 +373,7 @@ static void GBASetActiveRegion(struct ARMCore* cpu, uint32_t address) {
if ((address & (SIZE_CART0 - 1)) < memory->romSize) { \ if ((address & (SIZE_CART0 - 1)) < memory->romSize) { \
LOAD_32(value, address & (SIZE_CART0 - 4), memory->rom); \ LOAD_32(value, address & (SIZE_CART0 - 4), memory->rom); \
} else { \ } else { \
GBALog(gba, GBA_LOG_GAME_ERROR, "Out of bounds ROM Load32: 0x%08X", address); \ mLOG(GBA_MEM, GAME_ERROR, "Out of bounds ROM Load32: 0x%08X", address); \
value = ((address & ~3) >> 1) & 0xFFFF; \ value = ((address & ~3) >> 1) & 0xFFFF; \
value |= (((address & ~3) + 2) >> 1) << 16; \ value |= (((address & ~3) + 2) >> 1) << 16; \
} }
@ -431,7 +433,7 @@ uint32_t GBALoad32(struct ARMCore* cpu, uint32_t address, int* cycleCounter) {
LOAD_SRAM; LOAD_SRAM;
break; break;
default: default:
GBALog(gba, GBA_LOG_GAME_ERROR, "Bad memory Load32: 0x%08X", address); mLOG(GBA_MEM, GAME_ERROR, "Bad memory Load32: 0x%08X", address);
LOAD_BAD; LOAD_BAD;
break; break;
} }
@ -460,11 +462,11 @@ uint32_t GBALoad16(struct ARMCore* cpu, uint32_t address, int* cycleCounter) {
if (memory->activeRegion == REGION_BIOS) { if (memory->activeRegion == REGION_BIOS) {
LOAD_16(value, address, memory->bios); LOAD_16(value, address, memory->bios);
} else { } else {
GBALog(gba, GBA_LOG_GAME_ERROR, "Bad BIOS Load16: 0x%08X", address); mLOG(GBA_MEM, GAME_ERROR, "Bad BIOS Load16: 0x%08X", address);
value = (memory->biosPrefetch >> ((address & 2) * 8)) & 0xFFFF; value = (memory->biosPrefetch >> ((address & 2) * 8)) & 0xFFFF;
} }
} else { } else {
GBALog(gba, GBA_LOG_GAME_ERROR, "Bad memory Load16: 0x%08X", address); mLOG(GBA_MEM, GAME_ERROR, "Bad memory Load16: 0x%08X", address);
LOAD_BAD; LOAD_BAD;
value = (value >> ((address & 2) * 8)) & 0xFFFF; value = (value >> ((address & 2) * 8)) & 0xFFFF;
} }
@ -501,7 +503,7 @@ uint32_t GBALoad16(struct ARMCore* cpu, uint32_t address, int* cycleCounter) {
if ((address & (SIZE_CART0 - 1)) < memory->romSize) { if ((address & (SIZE_CART0 - 1)) < memory->romSize) {
LOAD_16(value, address & (SIZE_CART0 - 2), memory->rom); LOAD_16(value, address & (SIZE_CART0 - 2), memory->rom);
} else { } else {
GBALog(gba, GBA_LOG_GAME_ERROR, "Out of bounds ROM Load16: 0x%08X", address); mLOG(GBA_MEM, GAME_ERROR, "Out of bounds ROM Load16: 0x%08X", address);
value = (address >> 1) & 0xFFFF; value = (address >> 1) & 0xFFFF;
} }
break; break;
@ -512,7 +514,7 @@ uint32_t GBALoad16(struct ARMCore* cpu, uint32_t address, int* cycleCounter) {
} else if ((address & (SIZE_CART0 - 1)) < memory->romSize) { } else if ((address & (SIZE_CART0 - 1)) < memory->romSize) {
LOAD_16(value, address & (SIZE_CART0 - 2), memory->rom); LOAD_16(value, address & (SIZE_CART0 - 2), memory->rom);
} else { } else {
GBALog(gba, GBA_LOG_GAME_ERROR, "Out of bounds ROM Load16: 0x%08X", address); mLOG(GBA_MEM, GAME_ERROR, "Out of bounds ROM Load16: 0x%08X", address);
value = (address >> 1) & 0xFFFF; value = (address >> 1) & 0xFFFF;
} }
break; break;
@ -523,7 +525,7 @@ uint32_t GBALoad16(struct ARMCore* cpu, uint32_t address, int* cycleCounter) {
value |= value << 8; value |= value << 8;
break; break;
default: default:
GBALog(gba, GBA_LOG_GAME_ERROR, "Bad memory Load16: 0x%08X", address); mLOG(GBA_MEM, GAME_ERROR, "Bad memory Load16: 0x%08X", address);
LOAD_BAD; LOAD_BAD;
value = (value >> ((address & 2) * 8)) & 0xFFFF; value = (value >> ((address & 2) * 8)) & 0xFFFF;
break; break;
@ -553,11 +555,11 @@ uint32_t GBALoad8(struct ARMCore* cpu, uint32_t address, int* cycleCounter) {
if (memory->activeRegion == REGION_BIOS) { if (memory->activeRegion == REGION_BIOS) {
value = ((uint8_t*) memory->bios)[address]; value = ((uint8_t*) memory->bios)[address];
} else { } else {
GBALog(gba, GBA_LOG_GAME_ERROR, "Bad BIOS Load8: 0x%08X", address); mLOG(GBA_MEM, GAME_ERROR, "Bad BIOS Load8: 0x%08X", address);
value = (memory->biosPrefetch >> ((address & 3) * 8)) & 0xFF; value = (memory->biosPrefetch >> ((address & 3) * 8)) & 0xFF;
} }
} else { } else {
GBALog(gba, GBA_LOG_GAME_ERROR, "Bad memory Load8: 0x%08x", address); mLOG(GBA_MEM, GAME_ERROR, "Bad memory Load8: 0x%08x", address);
LOAD_BAD; LOAD_BAD;
value = (value >> ((address & 3) * 8)) & 0xFF; value = (value >> ((address & 3) * 8)) & 0xFF;
} }
@ -595,7 +597,7 @@ uint32_t GBALoad8(struct ARMCore* cpu, uint32_t address, int* cycleCounter) {
if ((address & (SIZE_CART0 - 1)) < memory->romSize) { if ((address & (SIZE_CART0 - 1)) < memory->romSize) {
value = ((uint8_t*) memory->rom)[address & (SIZE_CART0 - 1)]; value = ((uint8_t*) memory->rom)[address & (SIZE_CART0 - 1)];
} else { } else {
GBALog(gba, GBA_LOG_GAME_ERROR, "Out of bounds ROM Load8: 0x%08X", address); mLOG(GBA_MEM, GAME_ERROR, "Out of bounds ROM Load8: 0x%08X", address);
value = (address >> 1) & 0xFF; value = (address >> 1) & 0xFF;
} }
break; break;
@ -603,7 +605,7 @@ uint32_t GBALoad8(struct ARMCore* cpu, uint32_t address, int* cycleCounter) {
case REGION_CART_SRAM_MIRROR: case REGION_CART_SRAM_MIRROR:
wait = memory->waitstatesNonseq16[address >> BASE_OFFSET]; wait = memory->waitstatesNonseq16[address >> BASE_OFFSET];
if (memory->savedata.type == SAVEDATA_AUTODETECT) { if (memory->savedata.type == SAVEDATA_AUTODETECT) {
GBALog(gba, GBA_LOG_INFO, "Detected SRAM savegame"); mLOG(GBA_MEM, INFO, "Detected SRAM savegame");
GBASavedataInitSRAM(&memory->savedata); GBASavedataInitSRAM(&memory->savedata);
} }
if (gba->performingDMA == 1) { if (gba->performingDMA == 1) {
@ -616,13 +618,13 @@ uint32_t GBALoad8(struct ARMCore* cpu, uint32_t address, int* cycleCounter) {
} else if (memory->hw.devices & HW_TILT) { } else if (memory->hw.devices & HW_TILT) {
value = GBAHardwareTiltRead(&memory->hw, address & OFFSET_MASK); value = GBAHardwareTiltRead(&memory->hw, address & OFFSET_MASK);
} else { } else {
GBALog(gba, GBA_LOG_GAME_ERROR, "Reading from non-existent SRAM: 0x%08X", address); mLOG(GBA_MEM, GAME_ERROR, "Reading from non-existent SRAM: 0x%08X", address);
value = 0xFF; value = 0xFF;
} }
value &= 0xFF; value &= 0xFF;
break; break;
default: default:
GBALog(gba, GBA_LOG_GAME_ERROR, "Bad memory Load8: 0x%08x", address); mLOG(GBA_MEM, GAME_ERROR, "Bad memory Load8: 0x%08x", address);
LOAD_BAD; LOAD_BAD;
value = (value >> ((address & 3) * 8)) & 0xFF; value = (value >> ((address & 3) * 8)) & 0xFF;
break; break;
@ -673,11 +675,11 @@ uint32_t GBALoad8(struct ARMCore* cpu, uint32_t address, int* cycleCounter) {
#define STORE_CART \ #define STORE_CART \
wait += waitstatesRegion[address >> BASE_OFFSET]; \ wait += waitstatesRegion[address >> BASE_OFFSET]; \
GBALog(gba, GBA_LOG_STUB, "Unimplemented memory Store32: 0x%08X", address); mLOG(GBA_MEM, STUB, "Unimplemented memory Store32: 0x%08X", address);
#define STORE_SRAM \ #define STORE_SRAM \
if (address & 0x3) { \ if (address & 0x3) { \
GBALog(gba, GBA_LOG_GAME_ERROR, "Unaligned SRAM Store32: 0x%08X", address); \ mLOG(GBA_MEM, GAME_ERROR, "Unaligned SRAM Store32: 0x%08X", address); \
value = 0; \ value = 0; \
} \ } \
GBAStore8(cpu, address & ~0x3, value, cycleCounter); \ GBAStore8(cpu, address & ~0x3, value, cycleCounter); \
@ -686,7 +688,7 @@ uint32_t GBALoad8(struct ARMCore* cpu, uint32_t address, int* cycleCounter) {
GBAStore8(cpu, (address & ~0x3) | 3, value, cycleCounter); GBAStore8(cpu, (address & ~0x3) | 3, value, cycleCounter);
#define STORE_BAD \ #define STORE_BAD \
GBALog(gba, GBA_LOG_GAME_ERROR, "Bad memory Store32: 0x%08X", address); mLOG(GBA_MEM, GAME_ERROR, "Bad memory Store32: 0x%08X", address);
void GBAStore32(struct ARMCore* cpu, uint32_t address, int32_t value, int* cycleCounter) { void GBAStore32(struct ARMCore* cpu, uint32_t address, int32_t value, int* cycleCounter) {
struct GBA* gba = (struct GBA*) cpu->master; struct GBA* gba = (struct GBA*) cpu->master;
@ -777,12 +779,12 @@ void GBAStore16(struct ARMCore* cpu, uint32_t address, int16_t value, int* cycle
uint32_t reg = address & 0xFFFFFE; uint32_t reg = address & 0xFFFFFE;
GBAHardwareGPIOWrite(&memory->hw, reg, value); GBAHardwareGPIOWrite(&memory->hw, reg, value);
} else { } else {
GBALog(gba, GBA_LOG_GAME_ERROR, "Bad cartridge Store16: 0x%08X", address); mLOG(GBA_MEM, GAME_ERROR, "Bad cartridge Store16: 0x%08X", address);
} }
break; break;
case REGION_CART2_EX: case REGION_CART2_EX:
if (memory->savedata.type == SAVEDATA_AUTODETECT) { if (memory->savedata.type == SAVEDATA_AUTODETECT) {
GBALog(gba, GBA_LOG_INFO, "Detected EEPROM savegame"); mLOG(GBA_MEM, INFO, "Detected EEPROM savegame");
GBASavedataInitEEPROM(&memory->savedata); GBASavedataInitEEPROM(&memory->savedata);
} }
GBASavedataWriteEEPROM(&memory->savedata, value, 1); GBASavedataWriteEEPROM(&memory->savedata, value, 1);
@ -793,7 +795,7 @@ void GBAStore16(struct ARMCore* cpu, uint32_t address, int16_t value, int* cycle
GBAStore8(cpu, (address & ~0x1) | 1, value, cycleCounter); GBAStore8(cpu, (address & ~0x1) | 1, value, cycleCounter);
break; break;
default: default:
GBALog(gba, GBA_LOG_GAME_ERROR, "Bad memory Store16: 0x%08X", address); mLOG(GBA_MEM, GAME_ERROR, "Bad memory Store16: 0x%08X", address);
break; break;
} }
@ -828,26 +830,26 @@ void GBAStore8(struct ARMCore* cpu, uint32_t address, int8_t value, int* cycleCo
case REGION_VRAM: case REGION_VRAM:
if ((address & 0x0001FFFF) >= ((GBARegisterDISPCNTGetMode(gba->memory.io[REG_DISPCNT >> 1]) == 4) ? 0x00014000 : 0x00010000)) { if ((address & 0x0001FFFF) >= ((GBARegisterDISPCNTGetMode(gba->memory.io[REG_DISPCNT >> 1]) == 4) ? 0x00014000 : 0x00010000)) {
// TODO: check BG mode // TODO: check BG mode
GBALog(gba, GBA_LOG_GAME_ERROR, "Cannot Store8 to OBJ: 0x%08X", address); mLOG(GBA_MEM, GAME_ERROR, "Cannot Store8 to OBJ: 0x%08X", address);
break; break;
} }
gba->video.renderer->vram[(address & 0x1FFFE) >> 1] = ((uint8_t) value) | (value << 8); gba->video.renderer->vram[(address & 0x1FFFE) >> 1] = ((uint8_t) value) | (value << 8);
gba->video.renderer->writeVRAM(gba->video.renderer, address & 0x0001FFFE); gba->video.renderer->writeVRAM(gba->video.renderer, address & 0x0001FFFE);
break; break;
case REGION_OAM: case REGION_OAM:
GBALog(gba, GBA_LOG_GAME_ERROR, "Cannot Store8 to OAM: 0x%08X", address); mLOG(GBA_MEM, GAME_ERROR, "Cannot Store8 to OAM: 0x%08X", address);
break; break;
case REGION_CART0: case REGION_CART0:
GBALog(gba, GBA_LOG_STUB, "Unimplemented memory Store8: 0x%08X", address); mLOG(GBA_MEM, STUB, "Unimplemented memory Store8: 0x%08X", address);
break; break;
case REGION_CART_SRAM: case REGION_CART_SRAM:
case REGION_CART_SRAM_MIRROR: case REGION_CART_SRAM_MIRROR:
if (memory->savedata.type == SAVEDATA_AUTODETECT) { if (memory->savedata.type == SAVEDATA_AUTODETECT) {
if (address == SAVEDATA_FLASH_BASE) { if (address == SAVEDATA_FLASH_BASE) {
GBALog(gba, GBA_LOG_INFO, "Detected Flash savegame"); mLOG(GBA_MEM, INFO, "Detected Flash savegame");
GBASavedataInitFlash(&memory->savedata, gba->realisticTiming); GBASavedataInitFlash(&memory->savedata, gba->realisticTiming);
} else { } else {
GBALog(gba, GBA_LOG_INFO, "Detected SRAM savegame"); mLOG(GBA_MEM, INFO, "Detected SRAM savegame");
GBASavedataInitSRAM(&memory->savedata); GBASavedataInitSRAM(&memory->savedata);
} }
} }
@ -859,12 +861,12 @@ void GBAStore8(struct ARMCore* cpu, uint32_t address, int8_t value, int* cycleCo
} else if (memory->hw.devices & HW_TILT) { } else if (memory->hw.devices & HW_TILT) {
GBAHardwareTiltWrite(&memory->hw, address & OFFSET_MASK, value); GBAHardwareTiltWrite(&memory->hw, address & OFFSET_MASK, value);
} else { } else {
GBALog(gba, GBA_LOG_GAME_ERROR, "Writing to non-existent SRAM: 0x%08X", address); mLOG(GBA_MEM, GAME_ERROR, "Writing to non-existent SRAM: 0x%08X", address);
} }
wait = memory->waitstatesNonseq16[REGION_CART_SRAM]; wait = memory->waitstatesNonseq16[REGION_CART_SRAM];
break; break;
default: default:
GBALog(gba, GBA_LOG_GAME_ERROR, "Bad memory Store8: 0x%08X", address); mLOG(GBA_MEM, GAME_ERROR, "Bad memory Store8: 0x%08X", address);
break; break;
} }
@ -1003,7 +1005,7 @@ void GBAPatch32(struct ARMCore* cpu, uint32_t address, int32_t value, int32_t* o
STORE_32(value, address & (SIZE_WORKING_IRAM - 4), memory->iwram); STORE_32(value, address & (SIZE_WORKING_IRAM - 4), memory->iwram);
break; break;
case REGION_IO: case REGION_IO:
GBALog(gba, GBA_LOG_STUB, "Unimplemented memory Patch32: 0x%08X", address); mLOG(GBA_MEM, STUB, "Unimplemented memory Patch32: 0x%08X", address);
break; break;
case REGION_PALETTE_RAM: case REGION_PALETTE_RAM:
LOAD_32(oldValue, address & (SIZE_PALETTE_RAM - 1), gba->video.palette); LOAD_32(oldValue, address & (SIZE_PALETTE_RAM - 1), gba->video.palette);
@ -1046,11 +1048,11 @@ void GBAPatch32(struct ARMCore* cpu, uint32_t address, int32_t value, int32_t* o
LOAD_32(oldValue, address & (SIZE_CART_SRAM - 4), memory->savedata.data); LOAD_32(oldValue, address & (SIZE_CART_SRAM - 4), memory->savedata.data);
STORE_32(value, address & (SIZE_CART_SRAM - 4), memory->savedata.data); STORE_32(value, address & (SIZE_CART_SRAM - 4), memory->savedata.data);
} else { } else {
GBALog(gba, GBA_LOG_GAME_ERROR, "Writing to non-existent SRAM: 0x%08X", address); mLOG(GBA_MEM, GAME_ERROR, "Writing to non-existent SRAM: 0x%08X", address);
} }
break; break;
default: default:
GBALog(gba, GBA_LOG_WARN, "Bad memory Patch16: 0x%08X", address); mLOG(GBA_MEM, WARN, "Bad memory Patch16: 0x%08X", address);
break; break;
} }
if (old) { if (old) {
@ -1073,7 +1075,7 @@ void GBAPatch16(struct ARMCore* cpu, uint32_t address, int16_t value, int16_t* o
STORE_16(value, address & (SIZE_WORKING_IRAM - 2), memory->iwram); STORE_16(value, address & (SIZE_WORKING_IRAM - 2), memory->iwram);
break; break;
case REGION_IO: case REGION_IO:
GBALog(gba, GBA_LOG_STUB, "Unimplemented memory Patch16: 0x%08X", address); mLOG(GBA_MEM, STUB, "Unimplemented memory Patch16: 0x%08X", address);
break; break;
case REGION_PALETTE_RAM: case REGION_PALETTE_RAM:
LOAD_16(oldValue, address & (SIZE_PALETTE_RAM - 2), gba->video.palette); LOAD_16(oldValue, address & (SIZE_PALETTE_RAM - 2), gba->video.palette);
@ -1114,11 +1116,11 @@ void GBAPatch16(struct ARMCore* cpu, uint32_t address, int16_t value, int16_t* o
LOAD_16(oldValue, address & (SIZE_CART_SRAM - 2), memory->savedata.data); LOAD_16(oldValue, address & (SIZE_CART_SRAM - 2), memory->savedata.data);
STORE_16(value, address & (SIZE_CART_SRAM - 2), memory->savedata.data); STORE_16(value, address & (SIZE_CART_SRAM - 2), memory->savedata.data);
} else { } else {
GBALog(gba, GBA_LOG_GAME_ERROR, "Writing to non-existent SRAM: 0x%08X", address); mLOG(GBA_MEM, GAME_ERROR, "Writing to non-existent SRAM: 0x%08X", address);
} }
break; break;
default: default:
GBALog(gba, GBA_LOG_WARN, "Bad memory Patch16: 0x%08X", address); mLOG(GBA_MEM, WARN, "Bad memory Patch16: 0x%08X", address);
break; break;
} }
if (old) { if (old) {
@ -1141,16 +1143,16 @@ void GBAPatch8(struct ARMCore* cpu, uint32_t address, int8_t value, int8_t* old)
((int8_t*) memory->iwram)[address & (SIZE_WORKING_IRAM - 1)] = value; ((int8_t*) memory->iwram)[address & (SIZE_WORKING_IRAM - 1)] = value;
break; break;
case REGION_IO: case REGION_IO:
GBALog(gba, GBA_LOG_STUB, "Unimplemented memory Patch8: 0x%08X", address); mLOG(GBA_MEM, STUB, "Unimplemented memory Patch8: 0x%08X", address);
break; break;
case REGION_PALETTE_RAM: case REGION_PALETTE_RAM:
GBALog(gba, GBA_LOG_STUB, "Unimplemented memory Patch8: 0x%08X", address); mLOG(GBA_MEM, STUB, "Unimplemented memory Patch8: 0x%08X", address);
break; break;
case REGION_VRAM: case REGION_VRAM:
GBALog(gba, GBA_LOG_STUB, "Unimplemented memory Patch8: 0x%08X", address); mLOG(GBA_MEM, STUB, "Unimplemented memory Patch8: 0x%08X", address);
break; break;
case REGION_OAM: case REGION_OAM:
GBALog(gba, GBA_LOG_STUB, "Unimplemented memory Patch8: 0x%08X", address); mLOG(GBA_MEM, STUB, "Unimplemented memory Patch8: 0x%08X", address);
break; break;
case REGION_CART0: case REGION_CART0:
case REGION_CART0_EX: case REGION_CART0_EX:
@ -1172,11 +1174,11 @@ void GBAPatch8(struct ARMCore* cpu, uint32_t address, int8_t value, int8_t* old)
oldValue = ((int8_t*) memory->savedata.data)[address & (SIZE_CART_SRAM - 1)]; oldValue = ((int8_t*) memory->savedata.data)[address & (SIZE_CART_SRAM - 1)];
((int8_t*) memory->savedata.data)[address & (SIZE_CART_SRAM - 1)] = value; ((int8_t*) memory->savedata.data)[address & (SIZE_CART_SRAM - 1)] = value;
} else { } else {
GBALog(gba, GBA_LOG_GAME_ERROR, "Writing to non-existent SRAM: 0x%08X", address); mLOG(GBA_MEM, GAME_ERROR, "Writing to non-existent SRAM: 0x%08X", address);
} }
break; break;
default: default:
GBALog(gba, GBA_LOG_WARN, "Bad memory Patch8: 0x%08X", address); mLOG(GBA_MEM, WARN, "Bad memory Patch8: 0x%08X", address);
break; break;
} }
if (old) { if (old) {
@ -1498,7 +1500,7 @@ uint16_t GBAMemoryWriteDMACNT_HI(struct GBA* gba, int dma, uint16_t control) {
currentDma->reg = control; currentDma->reg = control;
if (GBADMARegisterIsDRQ(currentDma->reg)) { if (GBADMARegisterIsDRQ(currentDma->reg)) {
GBALog(gba, GBA_LOG_STUB, "DRQ not implemented"); mLOG(GBA_MEM, STUB, "DRQ not implemented");
} }
if (!wasEnabled && GBADMARegisterIsEnable(currentDma->reg)) { if (!wasEnabled && GBADMARegisterIsEnable(currentDma->reg)) {
@ -1530,7 +1532,7 @@ void GBAMemoryScheduleDMA(struct GBA* gba, int number, struct GBADMA* info) {
info->nextEvent = INT_MAX; info->nextEvent = INT_MAX;
switch (number) { switch (number) {
case 0: case 0:
GBALog(gba, GBA_LOG_WARN, "Discarding invalid DMA0 scheduling"); mLOG(GBA_MEM, WARN, "Discarding invalid DMA0 scheduling");
break; break;
case 1: case 1:
case 2: case 2:
@ -1657,7 +1659,7 @@ void GBAMemoryServiceDMA(struct GBA* gba, int number, struct GBADMA* info) {
--wordsRemaining; --wordsRemaining;
} else if (destRegion == REGION_CART2_EX) { } else if (destRegion == REGION_CART2_EX) {
if (memory->savedata.type == SAVEDATA_AUTODETECT) { if (memory->savedata.type == SAVEDATA_AUTODETECT) {
GBALog(gba, GBA_LOG_INFO, "Detected EEPROM savegame"); mLOG(GBA_MEM, INFO, "Detected EEPROM savegame");
GBASavedataInitEEPROM(&memory->savedata); GBASavedataInitEEPROM(&memory->savedata);
} }
word = cpu->memory.load16(cpu, source, 0); word = cpu->memory.load16(cpu, source, 0);

View File

@ -86,6 +86,8 @@ enum DMATiming {
DMA_TIMING_CUSTOM = 3 DMA_TIMING_CUSTOM = 3
}; };
mLOG_DECLARE_CATEGORY(GBA_MEM);
DECL_BITFIELD(GBADMARegister, uint16_t); DECL_BITFIELD(GBADMARegister, uint16_t);
DECL_BITS(GBADMARegister, DestControl, 5, 2); DECL_BITS(GBADMARegister, DestControl, 5, 2);
DECL_BITS(GBADMARegister, SrcControl, 7, 2); DECL_BITS(GBADMARegister, SrcControl, 7, 2);

View File

@ -406,7 +406,7 @@
return; \ return; \
} \ } \
if (UNLIKELY(end < outX)) { \ if (UNLIKELY(end < outX)) { \
GBALog(0, GBA_LOG_FATAL, "Out of bounds background draw!"); \ mLOG(GBA_VIDEO, FATAL, "Out of bounds background draw!"); \
return; \ return; \
} \ } \
DRAW_BACKGROUND_MODE_0_TILE_SUFFIX_ ## BPP (BLEND, OBJWIN) \ DRAW_BACKGROUND_MODE_0_TILE_SUFFIX_ ## BPP (BLEND, OBJWIN) \
@ -414,7 +414,7 @@
if (tileX < tileEnd) { \ if (tileX < tileEnd) { \
++tileX; \ ++tileX; \
} else if (VIDEO_CHECKS && UNLIKELY(tileX > tileEnd)) { \ } else if (VIDEO_CHECKS && UNLIKELY(tileX > tileEnd)) { \
GBALog(0, GBA_LOG_FATAL, "Invariant doesn't hold in background draw! tileX (%u) > tileEnd (%u)", tileX, tileEnd); \ mLOG(GBA_VIDEO, FATAL, "Invariant doesn't hold in background draw! tileX (%u) > tileEnd (%u)", tileX, tileEnd); \
return; \ return; \
} \ } \
length -= end - renderer->start; \ length -= end - renderer->start; \
@ -423,7 +423,7 @@
/*!*/ pixel = &renderer->row[outX]; \ /*!*/ pixel = &renderer->row[outX]; \
outX += (tileEnd - tileX) * 8; \ outX += (tileEnd - tileX) * 8; \
/*!*/ if (VIDEO_CHECKS && UNLIKELY(outX > VIDEO_HORIZONTAL_PIXELS)) { \ /*!*/ if (VIDEO_CHECKS && UNLIKELY(outX > VIDEO_HORIZONTAL_PIXELS)) { \
/*!*/ GBALog(0, GBA_LOG_FATAL, "Out of bounds background draw would occur!"); \ /*!*/ mLOG(GBA_VIDEO, FATAL, "Out of bounds background draw would occur!"); \
/*!*/ return; \ /*!*/ return; \
/*!*/ } \ /*!*/ } \
DRAW_BACKGROUND_MODE_0_TILES_ ## BPP (BLEND, OBJWIN) \ DRAW_BACKGROUND_MODE_0_TILES_ ## BPP (BLEND, OBJWIN) \
@ -432,16 +432,16 @@
\ \
int mod8 = length & 0x7; \ int mod8 = length & 0x7; \
if (VIDEO_CHECKS && UNLIKELY(outX + mod8 != renderer->end)) { \ if (VIDEO_CHECKS && UNLIKELY(outX + mod8 != renderer->end)) { \
GBALog(0, GBA_LOG_FATAL, "Invariant doesn't hold in background draw!"); \ mLOG(GBA_VIDEO, FATAL, "Invariant doesn't hold in background draw!"); \
return; \ return; \
} \ } \
DRAW_BACKGROUND_MODE_0_TILE_PREFIX_ ## BPP (BLEND, OBJWIN) \ DRAW_BACKGROUND_MODE_0_TILE_PREFIX_ ## BPP (BLEND, OBJWIN) \
} \ } \
if (VIDEO_CHECKS && UNLIKELY(&renderer->row[outX] != pixel)) { \ if (VIDEO_CHECKS && UNLIKELY(&renderer->row[outX] != pixel)) { \
GBALog(0, GBA_LOG_FATAL, "Background draw ended in the wrong place! Diff: %" PRIXPTR, &renderer->row[outX] - pixel); \ mLOG(GBA_VIDEO, FATAL, "Background draw ended in the wrong place! Diff: %" PRIXPTR, &renderer->row[outX] - pixel); \
} \ } \
if (VIDEO_CHECKS && UNLIKELY(outX > VIDEO_HORIZONTAL_PIXELS)) { \ if (VIDEO_CHECKS && UNLIKELY(outX > VIDEO_HORIZONTAL_PIXELS)) { \
GBALog(0, GBA_LOG_FATAL, "Out of bounds background draw occurred!"); \ mLOG(GBA_VIDEO, FATAL, "Out of bounds background draw occurred!"); \
return; \ return; \
} }

View File

@ -328,10 +328,10 @@ static uint16_t GBAVideoSoftwareRendererWriteVideoRegister(struct GBAVideoRender
softwareRenderer->mosaic = value; softwareRenderer->mosaic = value;
break; break;
case REG_GREENSWP: case REG_GREENSWP:
GBALog(0, GBA_LOG_STUB, "Stub video register write: 0x%03X", address); mLOG(GBA_VIDEO, STUB, "Stub video register write: 0x%03X", address);
break; break;
default: default:
GBALog(0, GBA_LOG_GAME_ERROR, "Invalid video register: 0x%03X", address); mLOG(GBA_VIDEO, GAME_ERROR, "Invalid video register: 0x%03X", address);
} }
return value; return value;
} }
@ -418,7 +418,7 @@ static void _breakWindowInner(struct GBAVideoSoftwareRenderer* softwareRenderer,
// Trim off extra windows we've overwritten // Trim off extra windows we've overwritten
for (++activeWindow; softwareRenderer->nWindows > activeWindow + 1 && win->h.end >= softwareRenderer->windows[activeWindow].endX; ++activeWindow) { for (++activeWindow; softwareRenderer->nWindows > activeWindow + 1 && win->h.end >= softwareRenderer->windows[activeWindow].endX; ++activeWindow) {
if (VIDEO_CHECKS && activeWindow >= MAX_WINDOW) { if (VIDEO_CHECKS && activeWindow >= MAX_WINDOW) {
GBALog(0, GBA_LOG_FATAL, "Out of bounds window write will occur"); mLOG(GBA_VIDEO, FATAL, "Out of bounds window write will occur");
return; return;
} }
softwareRenderer->windows[activeWindow] = softwareRenderer->windows[activeWindow + 1]; softwareRenderer->windows[activeWindow] = softwareRenderer->windows[activeWindow + 1];
@ -440,7 +440,7 @@ static void _breakWindowInner(struct GBAVideoSoftwareRenderer* softwareRenderer,
} }
#ifdef DEBUG #ifdef DEBUG
if (softwareRenderer->nWindows > MAX_WINDOW) { if (softwareRenderer->nWindows > MAX_WINDOW) {
GBALog(0, GBA_LOG_FATAL, "Out of bounds window write occurred!"); mLOG(GBA_VIDEO, FATAL, "Out of bounds window write occurred!");
} }
#endif #endif
} }

View File

@ -157,7 +157,7 @@ bool _loadStream(struct GBAMGMContext* mgm, uint32_t streamId) {
mgm->d.stopPlaying(&mgm->d); mgm->d.stopPlaying(&mgm->d);
} }
} }
GBALog(0, GBA_LOG_DEBUG, "[RR] Loading segment: %u", streamId); mLOG(GBA_RR, DEBUG, "Loading segment: %u", streamId);
mgm->d.frames = 0; mgm->d.frames = 0;
mgm->d.lagFrames = 0; mgm->d.lagFrames = 0;
return true; return true;
@ -174,7 +174,7 @@ bool _incrementStream(struct GBAMGMContext* mgm, bool recursive) {
if (!_loadStream(mgm, newStreamId)) { if (!_loadStream(mgm, newStreamId)) {
return false; return false;
} }
GBALog(0, GBA_LOG_DEBUG, "[RR] New segment: %u", newStreamId); mLOG(GBA_RR, DEBUG, "New segment: %u", newStreamId);
_emitMagic(mgm, mgm->movieStream); _emitMagic(mgm, mgm->movieStream);
mgm->maxStreamId = newStreamId; mgm->maxStreamId = newStreamId;
_emitTag(mgm, mgm->movieStream, TAG_PREVIOUSLY); _emitTag(mgm, mgm->movieStream, TAG_PREVIOUSLY);
@ -264,21 +264,21 @@ void GBAMGMNextFrame(struct GBARRContext* rr) {
if (rr->isPlaying(rr)) { if (rr->isPlaying(rr)) {
while (mgm->peekedTag == TAG_INPUT) { while (mgm->peekedTag == TAG_INPUT) {
_readTag(mgm, mgm->movieStream); _readTag(mgm, mgm->movieStream);
GBALog(0, GBA_LOG_WARN, "[RR] Desync detected!"); mLOG(GBA_RR, WARN, "Desync detected!");
} }
if (mgm->peekedTag == TAG_LAG) { if (mgm->peekedTag == TAG_LAG) {
GBALog(0, GBA_LOG_DEBUG, "[RR] Lag frame marked in stream"); mLOG(GBA_RR, DEBUG, "Lag frame marked in stream");
if (mgm->inputThisFrame) { if (mgm->inputThisFrame) {
GBALog(0, GBA_LOG_WARN, "[RR] Lag frame in stream does not match movie"); mLOG(GBA_RR, WARN, "Lag frame in stream does not match movie");
} }
} }
} }
++mgm->d.frames; ++mgm->d.frames;
GBALog(0, GBA_LOG_DEBUG, "[RR] Frame: %u", mgm->d.frames); mLOG(GBA_RR, DEBUG, "Frame: %u", mgm->d.frames);
if (!mgm->inputThisFrame) { if (!mgm->inputThisFrame) {
++mgm->d.lagFrames; ++mgm->d.lagFrames;
GBALog(0, GBA_LOG_DEBUG, "[RR] Lag frame: %u", mgm->d.lagFrames); mLOG(GBA_RR, DEBUG, "Lag frame: %u", mgm->d.lagFrames);
} }
if (rr->isRecording(rr)) { if (rr->isRecording(rr)) {
@ -305,7 +305,7 @@ void GBAMGMLogInput(struct GBARRContext* rr, uint16_t keys) {
mgm->movieStream->write(mgm->movieStream, &keys, sizeof(keys)); mgm->movieStream->write(mgm->movieStream, &keys, sizeof(keys));
mgm->currentInput = keys; mgm->currentInput = keys;
} }
GBALog(0, GBA_LOG_DEBUG, "[RR] Input log: %03X", mgm->currentInput); mLOG(GBA_RR, DEBUG, "Input log: %03X", mgm->currentInput);
mgm->inputThisFrame = true; mgm->inputThisFrame = true;
} }
@ -320,9 +320,9 @@ uint16_t GBAMGMQueryInput(struct GBARRContext* rr) {
} }
mgm->inputThisFrame = true; mgm->inputThisFrame = true;
if (mgm->currentInput == INVALID_INPUT) { if (mgm->currentInput == INVALID_INPUT) {
GBALog(0, GBA_LOG_WARN, "[RR] Stream did not specify input"); mLOG(GBA_RR, WARN, "Stream did not specify input");
} }
GBALog(0, GBA_LOG_DEBUG, "[RR] Input replay: %03X", mgm->currentInput); mLOG(GBA_RR, DEBUG, "Input replay: %03X", mgm->currentInput);
return mgm->currentInput; return mgm->currentInput;
} }

View File

@ -7,6 +7,8 @@
#include "util/vfs.h" #include "util/vfs.h"
mLOG_DEFINE_CATEGORY(GBA_RR, "GBA RR");
void GBARRInitRecord(struct GBA* gba) { void GBARRInitRecord(struct GBA* gba) {
if (!gba || !gba->rr) { if (!gba || !gba->rr) {
return; return;

View File

@ -8,10 +8,13 @@
#include "util/common.h" #include "util/common.h"
#include "core/log.h"
#include "gba/serialize.h" #include "gba/serialize.h"
struct VFile; struct VFile;
mLOG_DECLARE_CATEGORY(GBA_RR);
enum GBARRInitFrom { enum GBARRInitFrom {
INIT_EX_NIHILO = 0, INIT_EX_NIHILO = 0,
INIT_FROM_SAVEGAME = 1, INIT_FROM_SAVEGAME = 1,

View File

@ -22,6 +22,8 @@
#define FLASH_SETTLE_CYCLES 18000 #define FLASH_SETTLE_CYCLES 18000
#define CLEANUP_THRESHOLD 15 #define CLEANUP_THRESHOLD 15
mLOG_DEFINE_CATEGORY(GBA_SAVE, "GBA Savedata");
static void _flashSwitchBank(struct GBASavedata* savedata, int bank); static void _flashSwitchBank(struct GBASavedata* savedata, int bank);
static void _flashErase(struct GBASavedata* savedata); static void _flashErase(struct GBASavedata* savedata);
static void _flashEraseSector(struct GBASavedata* savedata, uint16_t sectorStart); static void _flashEraseSector(struct GBASavedata* savedata, uint16_t sectorStart);
@ -181,7 +183,7 @@ void GBASavedataInitFlash(struct GBASavedata* savedata, bool realisticTiming) {
savedata->type = SAVEDATA_FLASH512; savedata->type = SAVEDATA_FLASH512;
} }
if (savedata->type != SAVEDATA_FLASH512 && savedata->type != SAVEDATA_FLASH1M) { if (savedata->type != SAVEDATA_FLASH512 && savedata->type != SAVEDATA_FLASH1M) {
GBALog(0, GBA_LOG_WARN, "Can't re-initialize savedata"); mLOG(GBA_SAVE, WARN, "Can't re-initialize savedata");
return; return;
} }
int32_t flashSize = SIZE_CART_FLASH512; int32_t flashSize = SIZE_CART_FLASH512;
@ -213,7 +215,7 @@ void GBASavedataInitEEPROM(struct GBASavedata* savedata) {
if (savedata->type == SAVEDATA_AUTODETECT) { if (savedata->type == SAVEDATA_AUTODETECT) {
savedata->type = SAVEDATA_EEPROM; savedata->type = SAVEDATA_EEPROM;
} else { } else {
GBALog(0, GBA_LOG_WARN, "Can't re-initialize savedata"); mLOG(GBA_SAVE, WARN, "Can't re-initialize savedata");
return; return;
} }
off_t end; off_t end;
@ -236,7 +238,7 @@ void GBASavedataInitSRAM(struct GBASavedata* savedata) {
if (savedata->type == SAVEDATA_AUTODETECT) { if (savedata->type == SAVEDATA_AUTODETECT) {
savedata->type = SAVEDATA_SRAM; savedata->type = SAVEDATA_SRAM;
} else { } else {
GBALog(0, GBA_LOG_WARN, "Can't re-initialize savedata"); mLOG(GBA_SAVE, WARN, "Can't re-initialize savedata");
return; return;
} }
off_t end; off_t end;
@ -290,7 +292,7 @@ void GBASavedataWriteFlash(struct GBASavedata* savedata, uint16_t address, uint8
if (address == 0 && value < 2) { if (address == 0 && value < 2) {
_flashSwitchBank(savedata, value); _flashSwitchBank(savedata, value);
} else { } else {
GBALog(0, GBA_LOG_GAME_ERROR, "Bad flash bank switch"); mLOG(GBA_SAVE, GAME_ERROR, "Bad flash bank switch");
savedata->command = FLASH_COMMAND_NONE; savedata->command = FLASH_COMMAND_NONE;
} }
savedata->command = FLASH_COMMAND_NONE; savedata->command = FLASH_COMMAND_NONE;
@ -299,7 +301,7 @@ void GBASavedataWriteFlash(struct GBASavedata* savedata, uint16_t address, uint8
if (address == FLASH_BASE_HI && value == FLASH_COMMAND_START) { if (address == FLASH_BASE_HI && value == FLASH_COMMAND_START) {
savedata->flashState = FLASH_STATE_START; savedata->flashState = FLASH_STATE_START;
} else { } else {
GBALog(0, GBA_LOG_GAME_ERROR, "Bad flash write: %#04x = %#02x", address, value); mLOG(GBA_SAVE, GAME_ERROR, "Bad flash write: %#04x = %#02x", address, value);
} }
break; break;
} }
@ -308,7 +310,7 @@ void GBASavedataWriteFlash(struct GBASavedata* savedata, uint16_t address, uint8
if (address == FLASH_BASE_LO && value == FLASH_COMMAND_CONTINUE) { if (address == FLASH_BASE_LO && value == FLASH_COMMAND_CONTINUE) {
savedata->flashState = FLASH_STATE_CONTINUE; savedata->flashState = FLASH_STATE_CONTINUE;
} else { } else {
GBALog(0, GBA_LOG_GAME_ERROR, "Bad flash write: %#04x = %#02x", address, value); mLOG(GBA_SAVE, GAME_ERROR, "Bad flash write: %#04x = %#02x", address, value);
savedata->flashState = FLASH_STATE_RAW; savedata->flashState = FLASH_STATE_RAW;
} }
break; break;
@ -325,7 +327,7 @@ void GBASavedataWriteFlash(struct GBASavedata* savedata, uint16_t address, uint8
savedata->command = value; savedata->command = value;
break; break;
default: default:
GBALog(0, GBA_LOG_GAME_ERROR, "Unsupported flash operation: %#02x", value); mLOG(GBA_SAVE, GAME_ERROR, "Unsupported flash operation: %#02x", value);
break; break;
} }
break; break;
@ -335,7 +337,7 @@ void GBASavedataWriteFlash(struct GBASavedata* savedata, uint16_t address, uint8
_flashErase(savedata); _flashErase(savedata);
break; break;
default: default:
GBALog(0, GBA_LOG_GAME_ERROR, "Unsupported flash erase operation: %#02x", value); mLOG(GBA_SAVE, GAME_ERROR, "Unsupported flash erase operation: %#02x", value);
break; break;
} }
savedata->command = FLASH_COMMAND_NONE; savedata->command = FLASH_COMMAND_NONE;
@ -346,7 +348,7 @@ void GBASavedataWriteFlash(struct GBASavedata* savedata, uint16_t address, uint8
} }
break; break;
default: default:
GBALog(0, GBA_LOG_ERROR, "Flash entered bad state: %#02x", savedata->command); mLOG(GBA_SAVE, ERROR, "Flash entered bad state: %#02x", savedata->command);
savedata->command = FLASH_COMMAND_NONE; savedata->command = FLASH_COMMAND_NONE;
break; break;
} }
@ -355,7 +357,7 @@ void GBASavedataWriteFlash(struct GBASavedata* savedata, uint16_t address, uint8
_flashEraseSector(savedata, address); _flashEraseSector(savedata, address);
savedata->command = FLASH_COMMAND_NONE; savedata->command = FLASH_COMMAND_NONE;
} else { } else {
GBALog(0, GBA_LOG_GAME_ERROR, "Unsupported flash erase operation: %#02x", value); mLOG(GBA_SAVE, GAME_ERROR, "Unsupported flash erase operation: %#02x", value);
} }
} }
break; break;
@ -394,7 +396,7 @@ void GBASavedataWriteEEPROM(struct GBASavedata* savedata, uint16_t value, uint32
savedata->data[savedata->writeAddress >> 3] = current; savedata->data[savedata->writeAddress >> 3] = current;
++savedata->writeAddress; ++savedata->writeAddress;
} else { } else {
GBALog(0, GBA_LOG_GAME_ERROR, "Writing beyond end of EEPROM: %08X", (savedata->writeAddress >> 3)); mLOG(GBA_SAVE, GAME_ERROR, "Writing beyond end of EEPROM: %08X", (savedata->writeAddress >> 3));
} }
break; break;
case EEPROM_COMMAND_READ_PENDING: case EEPROM_COMMAND_READ_PENDING:
@ -421,7 +423,7 @@ uint16_t GBASavedataReadEEPROM(struct GBASavedata* savedata) {
int step = 63 - savedata->readBitsRemaining; int step = 63 - savedata->readBitsRemaining;
uint32_t address = (savedata->readAddress + step) >> 3; uint32_t address = (savedata->readAddress + step) >> 3;
if (address >= SIZE_CART_EEPROM) { if (address >= SIZE_CART_EEPROM) {
GBALog(0, GBA_LOG_GAME_ERROR, "Reading beyond end of EEPROM: %08X", address); mLOG(GBA_SAVE, GAME_ERROR, "Reading beyond end of EEPROM: %08X", address);
return 0xFF; return 0xFF;
} }
uint8_t data = savedata->data[address] >> (0x7 - (step & 0x7)); uint8_t data = savedata->data[address] >> (0x7 - (step & 0x7));
@ -464,7 +466,7 @@ void GBASavedataClean(struct GBASavedata* savedata, uint32_t frameCount) {
} }
savedata->vf->sync(savedata->vf, savedata->data, size); savedata->vf->sync(savedata->vf, savedata->data, size);
savedata->dirty = 0; savedata->dirty = 0;
GBALog(0, GBA_LOG_INFO, "Savedata synced"); mLOG(GBA_SAVE, INFO, "Savedata synced");
} }
} }
@ -504,7 +506,7 @@ void GBASavedataDeserialize(struct GBASavedata* savedata, const struct GBASerial
} }
void _flashSwitchBank(struct GBASavedata* savedata, int bank) { void _flashSwitchBank(struct GBASavedata* savedata, int bank) {
GBALog(0, GBA_LOG_DEBUG, "Performing flash bank switch to bank %i", bank); mLOG(GBA_SAVE, DEBUG, "Performing flash bank switch to bank %i", bank);
savedata->currentBank = &savedata->data[bank << 16]; savedata->currentBank = &savedata->data[bank << 16];
if (bank > 0 && savedata->type == SAVEDATA_FLASH512) { if (bank > 0 && savedata->type == SAVEDATA_FLASH512) {
savedata->type = SAVEDATA_FLASH1M; savedata->type = SAVEDATA_FLASH1M;
@ -516,7 +518,7 @@ void _flashSwitchBank(struct GBASavedata* savedata, int bank) {
} }
void _flashErase(struct GBASavedata* savedata) { void _flashErase(struct GBASavedata* savedata) {
GBALog(0, GBA_LOG_DEBUG, "Performing flash chip erase"); mLOG(GBA_SAVE, DEBUG, "Performing flash chip erase");
savedata->dirty |= SAVEDATA_DIRT_NEW; savedata->dirty |= SAVEDATA_DIRT_NEW;
size_t size = SIZE_CART_FLASH512; size_t size = SIZE_CART_FLASH512;
if (savedata->type == SAVEDATA_FLASH1M) { if (savedata->type == SAVEDATA_FLASH1M) {
@ -526,11 +528,11 @@ void _flashErase(struct GBASavedata* savedata) {
} }
void _flashEraseSector(struct GBASavedata* savedata, uint16_t sectorStart) { void _flashEraseSector(struct GBASavedata* savedata, uint16_t sectorStart) {
GBALog(0, GBA_LOG_DEBUG, "Performing flash sector erase at 0x%04x", sectorStart); mLOG(GBA_SAVE, DEBUG, "Performing flash sector erase at 0x%04x", sectorStart);
savedata->dirty |= SAVEDATA_DIRT_NEW; savedata->dirty |= SAVEDATA_DIRT_NEW;
size_t size = 0x1000; size_t size = 0x1000;
if (savedata->type == SAVEDATA_FLASH1M) { if (savedata->type == SAVEDATA_FLASH1M) {
GBALog(0, GBA_LOG_DEBUG, "Performing unknown sector-size erase at 0x%04x", sectorStart); mLOG(GBA_SAVE, DEBUG, "Performing unknown sector-size erase at 0x%04x", sectorStart);
} }
savedata->settling = sectorStart >> 12; savedata->settling = sectorStart >> 12;
if (savedata->realisticTiming) { if (savedata->realisticTiming) {

View File

@ -8,6 +8,10 @@
#include "util/common.h" #include "util/common.h"
#include "core/log.h"
mLOG_DECLARE_CATEGORY(GBA_SAVE);
struct VFile; struct VFile;
enum SavedataType { enum SavedataType {

View File

@ -26,6 +26,8 @@
const uint32_t GBA_SAVESTATE_MAGIC = 0x01000000; const uint32_t GBA_SAVESTATE_MAGIC = 0x01000000;
mLOG_DEFINE_CATEGORY(GBA_STATE, "GBA Savestate");
struct GBABundledState { struct GBABundledState {
struct GBASerializedState* state; struct GBASerializedState* state;
struct GBAExtdata* extdata; struct GBAExtdata* extdata;
@ -96,12 +98,12 @@ bool GBADeserialize(struct GBA* gba, const struct GBASerializedState* state) {
uint32_t ucheck; uint32_t ucheck;
LOAD_32(ucheck, 0, &state->versionMagic); LOAD_32(ucheck, 0, &state->versionMagic);
if (ucheck != GBA_SAVESTATE_MAGIC) { if (ucheck != GBA_SAVESTATE_MAGIC) {
GBALog(gba, GBA_LOG_WARN, "Invalid or too new savestate: expected %08X, got %08X", GBA_SAVESTATE_MAGIC, ucheck); mLOG(GBA_STATE, WARN, "Invalid or too new savestate: expected %08X, got %08X", GBA_SAVESTATE_MAGIC, ucheck);
error = true; error = true;
} }
LOAD_32(ucheck, 0, &state->biosChecksum); LOAD_32(ucheck, 0, &state->biosChecksum);
if (ucheck != gba->biosChecksum) { if (ucheck != gba->biosChecksum) {
GBALog(gba, GBA_LOG_WARN, "Savestate created using a different version of the BIOS: expected %08X, got %08X", gba->biosChecksum, ucheck); mLOG(GBA_STATE, WARN, "Savestate created using a different version of the BIOS: expected %08X, got %08X", gba->biosChecksum, ucheck);
uint32_t pc; uint32_t pc;
LOAD_32(pc, ARM_PC * sizeof(state->cpu.gprs[0]), state->cpu.gprs); LOAD_32(pc, ARM_PC * sizeof(state->cpu.gprs[0]), state->cpu.gprs);
if (pc < SIZE_BIOS && pc >= 0x20) { if (pc < SIZE_BIOS && pc >= 0x20) {
@ -109,34 +111,34 @@ bool GBADeserialize(struct GBA* gba, const struct GBASerializedState* state) {
} }
} }
if (gba->memory.rom && (state->id != ((struct GBACartridge*) gba->memory.rom)->id || memcmp(state->title, ((struct GBACartridge*) gba->memory.rom)->title, sizeof(state->title)))) { if (gba->memory.rom && (state->id != ((struct GBACartridge*) gba->memory.rom)->id || memcmp(state->title, ((struct GBACartridge*) gba->memory.rom)->title, sizeof(state->title)))) {
GBALog(gba, GBA_LOG_WARN, "Savestate is for a different game"); mLOG(GBA_STATE, WARN, "Savestate is for a different game");
error = true; error = true;
} else if (!gba->memory.rom && state->id != 0) { } else if (!gba->memory.rom && state->id != 0) {
GBALog(gba, GBA_LOG_WARN, "Savestate is for a game, but no game loaded"); mLOG(GBA_STATE, WARN, "Savestate is for a game, but no game loaded");
error = true; error = true;
} }
LOAD_32(ucheck, 0, &state->romCrc32); LOAD_32(ucheck, 0, &state->romCrc32);
if (ucheck != gba->romCrc32) { if (ucheck != gba->romCrc32) {
GBALog(gba, GBA_LOG_WARN, "Savestate is for a different version of the game"); mLOG(GBA_STATE, WARN, "Savestate is for a different version of the game");
} }
LOAD_32(check, 0, &state->cpu.cycles); LOAD_32(check, 0, &state->cpu.cycles);
if (check < 0) { if (check < 0) {
GBALog(gba, GBA_LOG_WARN, "Savestate is corrupted: CPU cycles are negative"); mLOG(GBA_STATE, WARN, "Savestate is corrupted: CPU cycles are negative");
error = true; error = true;
} }
if (check >= (int32_t) GBA_ARM7TDMI_FREQUENCY) { if (check >= (int32_t) GBA_ARM7TDMI_FREQUENCY) {
GBALog(gba, GBA_LOG_WARN, "Savestate is corrupted: CPU cycles are too high"); mLOG(GBA_STATE, WARN, "Savestate is corrupted: CPU cycles are too high");
error = true; error = true;
} }
LOAD_32(check, 0, &state->video.eventDiff); LOAD_32(check, 0, &state->video.eventDiff);
if (check < 0) { if (check < 0) {
GBALog(gba, GBA_LOG_WARN, "Savestate is corrupted: video eventDiff is negative"); mLOG(GBA_STATE, WARN, "Savestate is corrupted: video eventDiff is negative");
error = true; error = true;
} }
LOAD_32(check, ARM_PC * sizeof(state->cpu.gprs[0]), state->cpu.gprs); LOAD_32(check, ARM_PC * sizeof(state->cpu.gprs[0]), state->cpu.gprs);
int region = (check >> BASE_OFFSET); int region = (check >> BASE_OFFSET);
if ((region == REGION_CART0 || region == REGION_CART1 || region == REGION_CART2) && ((check - WORD_SIZE_ARM) & SIZE_CART0) >= gba->memory.romSize - WORD_SIZE_ARM) { if ((region == REGION_CART0 || region == REGION_CART1 || region == REGION_CART2) && ((check - WORD_SIZE_ARM) & SIZE_CART0) >= gba->memory.romSize - WORD_SIZE_ARM) {
GBALog(gba, GBA_LOG_WARN, "Savestate created using a differently sized version of the ROM"); mLOG(GBA_STATE, WARN, "Savestate created using a differently sized version of the ROM");
error = true; error = true;
} }
if (error) { if (error) {
@ -461,7 +463,7 @@ bool GBALoadStateNamed(struct GBA* gba, struct VFile* vf, int flags) {
gba->video.renderer->putPixels(gba->video.renderer, VIDEO_HORIZONTAL_PIXELS, item.data); gba->video.renderer->putPixels(gba->video.renderer, VIDEO_HORIZONTAL_PIXELS, item.data);
mCoreSyncForceFrame(gba->sync); mCoreSyncForceFrame(gba->sync);
} else { } else {
GBALog(gba, GBA_LOG_WARN, "Savestate includes invalid screenshot"); mLOG(GBA_STATE, WARN, "Savestate includes invalid screenshot");
} }
} }
if (flags & SAVESTATE_SAVEDATA && GBAExtdataGet(&extdata, EXTDATA_SAVEDATA, &item)) { if (flags & SAVESTATE_SAVEDATA && GBAExtdataGet(&extdata, EXTDATA_SAVEDATA, &item)) {
@ -630,11 +632,11 @@ void GBATakeScreenshot(struct GBA* gba, struct VDir* dir) {
vf->close(vf); vf->close(vf);
} }
if (success) { if (success) {
GBALog(gba, GBA_LOG_STATUS, "Screenshot saved"); mLOG(STATUS, INFO, "Screenshot saved");
return; return;
} }
#else #else
UNUSED(dir); UNUSED(dir);
#endif #endif
GBALog(gba, GBA_LOG_STATUS, "Failed to take screenshot"); mLOG(STATUS, WARN, "Failed to take screenshot");
} }

View File

@ -8,10 +8,13 @@
#include "util/common.h" #include "util/common.h"
#include "core/core.h"
#include "gba/gba.h" #include "gba/gba.h"
extern const uint32_t GBA_SAVESTATE_MAGIC; extern const uint32_t GBA_SAVESTATE_MAGIC;
mLOG_DECLARE_CATEGORY(GBA_STATE);
/* Savestate format: /* Savestate format:
* 0x00000 - 0x00003: Version Magic (0x01000000) * 0x00000 - 0x00003: Version Magic (0x01000000)
* 0x00004 - 0x00007: BIOS checksum (e.g. 0xBAAE187F for official BIOS) * 0x00004 - 0x00007: BIOS checksum (e.g. 0xBAAE187F for official BIOS)

View File

@ -7,6 +7,8 @@
#include "gba/io.h" #include "gba/io.h"
mLOG_DEFINE_CATEGORY(GBA_SIO, "GBA Serial I/O");
const int GBASIOCyclesPerTransfer[4][MAX_GBAS] = { const int GBASIOCyclesPerTransfer[4][MAX_GBAS] = {
{ 38326, 73003, 107680, 142356 }, { 38326, 73003, 107680, 142356 },
{ 9582, 18251, 26920, 35589 }, { 9582, 18251, 26920, 35589 },
@ -98,7 +100,7 @@ void GBASIOSetDriver(struct GBASIO* sio, struct GBASIODriver* driver, enum GBASI
driverLoc = &sio->drivers.joybus; driverLoc = &sio->drivers.joybus;
break; break;
default: default:
GBALog(sio->p, GBA_LOG_ERROR, "Setting an unsupported SIO driver: %x", mode); mLOG(GBA_SIO, ERROR, "Setting an unsupported SIO driver: %x", mode);
return; return;
} }
if (*driverLoc) { if (*driverLoc) {
@ -115,7 +117,7 @@ void GBASIOSetDriver(struct GBASIO* sio, struct GBASIODriver* driver, enum GBASI
if (driver->init) { if (driver->init) {
if (!driver->init(driver)) { if (!driver->init(driver)) {
driver->deinit(driver); driver->deinit(driver);
GBALog(sio->p, GBA_LOG_ERROR, "Could not initialize SIO driver"); mLOG(GBA_SIO, ERROR, "Could not initialize SIO driver");
return; return;
} }
} }

View File

@ -8,12 +8,15 @@
#include "util/common.h" #include "util/common.h"
#include "core/log.h"
#include "gba/interface.h" #include "gba/interface.h"
#define MAX_GBAS 4 #define MAX_GBAS 4
extern const int GBASIOCyclesPerTransfer[4][MAX_GBAS]; extern const int GBASIOCyclesPerTransfer[4][MAX_GBAS];
mLOG_DECLARE_CATEGORY(GBA_SIO);
enum { enum {
RCNT_INITIAL = 0x8000 RCNT_INITIAL = 0x8000
}; };

View File

@ -85,7 +85,7 @@ bool GBASIOLockstepNodeInit(struct GBASIODriver* driver) {
struct GBASIOLockstepNode* node = (struct GBASIOLockstepNode*) driver; struct GBASIOLockstepNode* node = (struct GBASIOLockstepNode*) driver;
node->nextEvent = LOCKSTEP_INCREMENT; node->nextEvent = LOCKSTEP_INCREMENT;
node->d.p->multiplayerControl.slave = node->id > 0; node->d.p->multiplayerControl.slave = node->id > 0;
GBALog(node->d.p->p, GBA_LOG_SIO, "Lockstep %i: Node init", node->id); mLOG(GBA_SIO, DEBUG, "Lockstep %i: Node init", node->id);
return true; return true;
} }
@ -142,10 +142,10 @@ bool GBASIOLockstepNodeUnload(struct GBASIODriver* driver) {
static uint16_t GBASIOLockstepNodeMultiWriteRegister(struct GBASIODriver* driver, uint32_t address, uint16_t value) { static uint16_t GBASIOLockstepNodeMultiWriteRegister(struct GBASIODriver* driver, uint32_t address, uint16_t value) {
struct GBASIOLockstepNode* node = (struct GBASIOLockstepNode*) driver; struct GBASIOLockstepNode* node = (struct GBASIOLockstepNode*) driver;
if (address == REG_SIOCNT) { if (address == REG_SIOCNT) {
GBALog(node->d.p->p, GBA_LOG_SIO, "Lockstep %i: SIOCNT <- %04x", node->id, value); mLOG(GBA_SIO, DEBUG, "Lockstep %i: SIOCNT <- %04x", node->id, value);
if (value & 0x0080) { if (value & 0x0080) {
if (!node->id) { if (!node->id) {
GBALog(node->d.p->p, GBA_LOG_SIO, "Lockstep %i: Transfer initiated", node->id); mLOG(GBA_SIO, DEBUG, "Lockstep %i: Transfer initiated", node->id);
MutexLock(&node->p->mutex); MutexLock(&node->p->mutex);
node->p->transferActive = true; node->p->transferActive = true;
node->p->transferCycles = GBASIOCyclesPerTransfer[node->d.p->multiplayerControl.baud][node->p->attached - 1]; node->p->transferCycles = GBASIOCyclesPerTransfer[node->d.p->multiplayerControl.baud][node->p->attached - 1];
@ -158,7 +158,7 @@ static uint16_t GBASIOLockstepNodeMultiWriteRegister(struct GBASIODriver* driver
value &= 0xFF83; value &= 0xFF83;
value |= driver->p->siocnt & 0x00FC; value |= driver->p->siocnt & 0x00FC;
} else if (address == REG_SIOMLT_SEND) { } else if (address == REG_SIOMLT_SEND) {
GBALog(node->d.p->p, GBA_LOG_SIO, "Lockstep %i: SIOMLT_SEND <- %04x", node->id, value); mLOG(GBA_SIO, DEBUG, "Lockstep %i: SIOMLT_SEND <- %04x", node->id, value);
} }
return value; return value;
} }
@ -195,7 +195,7 @@ static int32_t GBASIOLockstepNodeMultiProcessEvents(struct GBASIODriver* driver,
ConditionWake(&node->p->barrier); ConditionWake(&node->p->barrier);
} }
if (node->state == LOCKSTEP_FINISHED) { if (node->state == LOCKSTEP_FINISHED) {
GBALog(node->d.p->p, GBA_LOG_SIO, "Lockstep %i: Finishing transfer: %04x %04x %04x %04x", node->id, node->p->multiRecv[0], node->p->multiRecv[1], node->p->multiRecv[2], node->p->multiRecv[3]); mLOG(GBA_SIO, DEBUG, "Lockstep %i: Finishing transfer: %04x %04x %04x %04x", node->id, node->p->multiRecv[0], node->p->multiRecv[1], node->p->multiRecv[2], node->p->multiRecv[3]);
node->d.p->p->memory.io[REG_SIOMULTI0 >> 1] = node->p->multiRecv[0]; node->d.p->p->memory.io[REG_SIOMULTI0 >> 1] = node->p->multiRecv[0];
node->d.p->p->memory.io[REG_SIOMULTI1 >> 1] = node->p->multiRecv[1]; node->d.p->p->memory.io[REG_SIOMULTI1 >> 1] = node->p->multiRecv[1];
node->d.p->p->memory.io[REG_SIOMULTI2 >> 1] = node->p->multiRecv[2]; node->d.p->p->memory.io[REG_SIOMULTI2 >> 1] = node->p->multiRecv[2];
@ -229,7 +229,7 @@ static int32_t GBASIOLockstepNodeMultiProcessEvents(struct GBASIODriver* driver,
static uint16_t GBASIOLockstepNodeNormalWriteRegister(struct GBASIODriver* driver, uint32_t address, uint16_t value) { static uint16_t GBASIOLockstepNodeNormalWriteRegister(struct GBASIODriver* driver, uint32_t address, uint16_t value) {
struct GBASIOLockstepNode* node = (struct GBASIOLockstepNode*) driver; struct GBASIOLockstepNode* node = (struct GBASIOLockstepNode*) driver;
if (address == REG_SIOCNT) { if (address == REG_SIOCNT) {
GBALog(node->d.p->p, GBA_LOG_SIO, "Lockstep %i: SIOCNT <- %04x", node->id, value); mLOG(GBA_SIO, DEBUG, "Lockstep %i: SIOCNT <- %04x", node->id, value);
value &= 0xFF8B; value &= 0xFF8B;
MutexLock(&node->p->mutex); MutexLock(&node->p->mutex);
if (value & 0x0080) { if (value & 0x0080) {
@ -251,9 +251,9 @@ static uint16_t GBASIOLockstepNodeNormalWriteRegister(struct GBASIODriver* drive
} }
MutexUnlock(&node->p->mutex); MutexUnlock(&node->p->mutex);
} else if (address == REG_SIODATA32_LO) { } else if (address == REG_SIODATA32_LO) {
GBALog(node->d.p->p, GBA_LOG_SIO, "Lockstep %i: SIODATA32_LO <- %04x", node->id, value); mLOG(GBA_SIO, DEBUG, "Lockstep %i: SIODATA32_LO <- %04x", node->id, value);
} else if (address == REG_SIODATA32_HI) { } else if (address == REG_SIODATA32_HI) {
GBALog(node->d.p->p, GBA_LOG_SIO, "Lockstep %i: SIODATA32_HI <- %04x", node->id, value); mLOG(GBA_SIO, DEBUG, "Lockstep %i: SIODATA32_HI <- %04x", node->id, value);
} }
return value; return value;
} }

View File

@ -13,6 +13,8 @@
#include "util/memory.h" #include "util/memory.h"
mLOG_DEFINE_CATEGORY(GBA_VIDEO, "GBA Video");
static void GBAVideoDummyRendererInit(struct GBAVideoRenderer* renderer); static void GBAVideoDummyRendererInit(struct GBAVideoRenderer* renderer);
static void GBAVideoDummyRendererReset(struct GBAVideoRenderer* renderer); static void GBAVideoDummyRendererReset(struct GBAVideoRenderer* renderer);
static void GBAVideoDummyRendererDeinit(struct GBAVideoRenderer* renderer); static void GBAVideoDummyRendererDeinit(struct GBAVideoRenderer* renderer);

View File

@ -20,6 +20,8 @@
#define GBA_G8(X) (((X) >> 2) & 0xF8) #define GBA_G8(X) (((X) >> 2) & 0xF8)
#define GBA_B8(X) (((X) >> 7) & 0xF8) #define GBA_B8(X) (((X) >> 7) & 0xF8)
mLOG_DECLARE_CATEGORY(GBA_VIDEO);
enum { enum {
VIDEO_HORIZONTAL_PIXELS = 240, VIDEO_HORIZONTAL_PIXELS = 240,
VIDEO_HBLANK_PIXELS = 68, VIDEO_HBLANK_PIXELS = 68,

View File

@ -110,7 +110,7 @@ ConfigController::ConfigController(QObject* parent)
m_opts.audioBuffers = 1536; m_opts.audioBuffers = 1536;
m_opts.sampleRate = 44100; m_opts.sampleRate = 44100;
m_opts.volume = 0x100; m_opts.volume = 0x100;
m_opts.logLevel = GBA_LOG_WARN | GBA_LOG_ERROR | GBA_LOG_FATAL | GBA_LOG_STATUS; m_opts.logLevel = mLOG_WARN | mLOG_ERROR | mLOG_FATAL;
m_opts.rewindEnable = false; m_opts.rewindEnable = false;
m_opts.rewindBufferInterval = 0; m_opts.rewindBufferInterval = 0;
m_opts.rewindBufferCapacity = 0; m_opts.rewindBufferCapacity = 0;

View File

@ -12,11 +12,13 @@
#define BUFFER_SIZE (GBA_AUDIO_SAMPLES >> 2) #define BUFFER_SIZE (GBA_AUDIO_SAMPLES >> 2)
mLOG_DEFINE_CATEGORY(SDL_AUDIO, "SDL Audio");
static void _mSDLAudioCallback(void* context, Uint8* data, int len); static void _mSDLAudioCallback(void* context, Uint8* data, int len);
bool mSDLInitAudio(struct mSDLAudio* context, struct mCoreThread* threadContext) { bool mSDLInitAudio(struct mSDLAudio* context, struct mCoreThread* threadContext) {
if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) { if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) {
GBALog(0, GBA_LOG_ERROR, "Could not initialize SDL sound system: %s", SDL_GetError()); mLOG(SDL_AUDIO, ERROR, "Could not initialize SDL sound system: %s", SDL_GetError());
return false; return false;
} }
@ -33,7 +35,7 @@ bool mSDLInitAudio(struct mSDLAudio* context, struct mCoreThread* threadContext)
#else #else
if (SDL_OpenAudio(&context->desiredSpec, &context->obtainedSpec) < 0) { if (SDL_OpenAudio(&context->desiredSpec, &context->obtainedSpec) < 0) {
#endif #endif
GBALog(0, GBA_LOG_ERROR, "Could not open SDL sound system"); mLOG(SDL_AUDIO, ERROR, "Could not open SDL sound system");
return false; return false;
} }
context->samples = context->obtainedSpec.samples; context->samples = context->obtainedSpec.samples;

View File

@ -8,8 +8,12 @@
#include "util/common.h" #include "util/common.h"
#include "core/log.h"
#include <SDL.h> #include <SDL.h>
mLOG_DECLARE_CATEGORY(SDL_AUDIO);
struct mSDLAudio { struct mSDLAudio {
// Input // Input
size_t samples; size_t samples;

View File

@ -27,6 +27,8 @@
#define GYRO_STEPS 100 #define GYRO_STEPS 100
#define RUMBLE_PWM 20 #define RUMBLE_PWM 20
mLOG_DEFINE_CATEGORY(SDL_EVENTS, "SDL Events");
DEFINE_VECTOR(SDL_JoystickList, struct SDL_JoystickCombo); DEFINE_VECTOR(SDL_JoystickList, struct SDL_JoystickCombo);
#if SDL_VERSION_ATLEAST(2, 0, 0) #if SDL_VERSION_ATLEAST(2, 0, 0)
@ -42,16 +44,16 @@ bool mSDLInitEvents(struct mSDLEvents* context) {
SDL_SetHint(SDL_HINT_NO_SIGNAL_HANDLERS, "1"); SDL_SetHint(SDL_HINT_NO_SIGNAL_HANDLERS, "1");
#endif #endif
if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) < 0) { if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) < 0) {
GBALog(0, GBA_LOG_ERROR, "SDL joystick initialization failed: %s", SDL_GetError()); mLOG(SDL_EVENTS, ERROR, "SDL joystick initialization failed: %s", SDL_GetError());
} }
#if SDL_VERSION_ATLEAST(2, 0, 0) #if SDL_VERSION_ATLEAST(2, 0, 0)
SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1"); SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1");
if (SDL_InitSubSystem(SDL_INIT_HAPTIC) < 0) { if (SDL_InitSubSystem(SDL_INIT_HAPTIC) < 0) {
GBALog(0, GBA_LOG_ERROR, "SDL haptic initialization failed: %s", SDL_GetError()); mLOG(SDL_EVENTS, ERROR, "SDL haptic initialization failed: %s", SDL_GetError());
} }
if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) { if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) {
GBALog(0, GBA_LOG_ERROR, "SDL video initialization failed: %s", SDL_GetError()); mLOG(SDL_EVENTS, ERROR, "SDL video initialization failed: %s", SDL_GetError());
} }
#endif #endif

View File

@ -9,11 +9,14 @@
#include "util/common.h" #include "util/common.h"
#include "core/interface.h" #include "core/interface.h"
#include "core/log.h"
#include "util/circle-buffer.h" #include "util/circle-buffer.h"
#include "util/vector.h" #include "util/vector.h"
#include <SDL.h> #include <SDL.h>
mLOG_DECLARE_CATEGORY(SDL_EVENTS);
#define SDL_BINDING_KEY 0x53444C4BU #define SDL_BINDING_KEY 0x53444C4BU
#define SDL_BINDING_BUTTON 0x53444C42U #define SDL_BINDING_BUTTON 0x53444C42U