aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ARCodeFile.cpp14
-rw-r--r--src/AREngine.cpp7
-rw-r--r--src/ARM.cpp16
-rw-r--r--src/ARMInterpreter.cpp15
-rw-r--r--src/ARMInterpreter_Branch.cpp6
-rw-r--r--src/ARMJIT.cpp11
-rw-r--r--src/ARMJIT_A64/ARMJIT_Branch.cpp2
-rw-r--r--src/ARMJIT_A64/ARMJIT_Compiler.cpp6
-rw-r--r--src/ARMJIT_A64/ARMJIT_LoadStore.cpp4
-rw-r--r--src/ARMJIT_Memory.cpp17
-rw-r--r--src/ARMJIT_RegisterCache.h6
-rw-r--r--src/ARMJIT_x64/ARMJIT_ALU.cpp2
-rw-r--r--src/ARMJIT_x64/ARMJIT_Branch.cpp2
-rw-r--r--src/ARMJIT_x64/ARMJIT_Compiler.cpp4
-rw-r--r--src/ARMJIT_x64/ARMJIT_LoadStore.cpp4
-rw-r--r--src/CP15.cpp47
-rw-r--r--src/DMA.cpp6
-rw-r--r--src/DSi.cpp50
-rw-r--r--src/DSi_AES.cpp8
-rw-r--r--src/DSi_Camera.cpp24
-rw-r--r--src/DSi_DSP.cpp5
-rw-r--r--src/DSi_I2C.cpp11
-rw-r--r--src/DSi_NAND.cpp32
-rw-r--r--src/DSi_NDMA.cpp7
-rw-r--r--src/DSi_NWifi.cpp105
-rw-r--r--src/DSi_SD.cpp32
-rw-r--r--src/DSi_SPI_TSC.cpp7
-rw-r--r--src/GBACart.cpp20
-rw-r--r--src/GPU.cpp6
-rw-r--r--src/GPU2D.cpp8
-rw-r--r--src/GPU3D.cpp13
-rw-r--r--src/NDS.cpp92
-rw-r--r--src/NDSCart.cpp62
-rw-r--r--src/OpenGLSupport.cpp10
-rw-r--r--src/Platform.h10
-rw-r--r--src/RTC.cpp6
-rw-r--r--src/SPI.cpp32
-rw-r--r--src/SPU.cpp21
-rw-r--r--src/Savestate.cpp17
-rw-r--r--src/Wifi.cpp38
-rw-r--r--src/WifiAP.cpp21
-rw-r--r--src/frontend/qt_sdl/ArchiveUtil.cpp5
-rw-r--r--src/frontend/qt_sdl/CLI.cpp8
-rw-r--r--src/frontend/qt_sdl/CheatsDialog.cpp4
-rw-r--r--src/frontend/qt_sdl/InputConfig/MapButton.h3
-rw-r--r--src/frontend/qt_sdl/LAN_PCap.cpp27
-rw-r--r--src/frontend/qt_sdl/LocalMP.cpp13
-rw-r--r--src/frontend/qt_sdl/Platform.cpp17
-rw-r--r--src/frontend/qt_sdl/SaveManager.cpp6
-rw-r--r--src/frontend/qt_sdl/TitleManagerDialog.cpp10
50 files changed, 521 insertions, 378 deletions
diff --git a/src/ARCodeFile.cpp b/src/ARCodeFile.cpp
index a95ebbd..53a2386 100644
--- a/src/ARCodeFile.cpp
+++ b/src/ARCodeFile.cpp
@@ -21,6 +21,8 @@
#include "ARCodeFile.h"
#include "Platform.h"
+using Platform::Log;
+using Platform::LogLevel;
// TODO: import codes from other sources (usrcheat.dat, ...)
// TODO: more user-friendly error reporting
@@ -79,7 +81,7 @@ bool ARCodeFile::Load()
if (ret < 1)
{
- printf("AR: malformed CAT line: %s\n", start);
+ Log(LogLevel::Error, "AR: malformed CAT line: %s\n", start);
fclose(f);
return false;
}
@@ -102,14 +104,14 @@ bool ARCodeFile::Load()
if (ret < 2)
{
- printf("AR: malformed CODE line: %s\n", start);
+ Log(LogLevel::Error, "AR: malformed CODE line: %s\n", start);
fclose(f);
return false;
}
if (!isincat)
{
- printf("AR: encountered CODE line with no category started\n");
+ Log(LogLevel::Error, "AR: encountered CODE line with no category started\n");
fclose(f);
return false;
}
@@ -128,21 +130,21 @@ bool ARCodeFile::Load()
if (ret < 2)
{
- printf("AR: malformed data line: %s\n", start);
+ Log(LogLevel::Error, "AR: malformed data line: %s\n", start);
fclose(f);
return false;
}
if (!isincode)
{
- printf("AR: encountered data line with no code started\n");
+ Log(LogLevel::Error, "AR: encountered data line with no code started\n");
fclose(f);
return false;
}
if (curcode.CodeLen >= 2*64)
{
- printf("AR: code too long!\n");
+ Log(LogLevel::Error, "AR: code too long!\n");
fclose(f);
return false;
}
diff --git a/src/AREngine.cpp b/src/AREngine.cpp
index 0605d28..06fbc6b 100644
--- a/src/AREngine.cpp
+++ b/src/AREngine.cpp
@@ -21,7 +21,10 @@
#include "NDS.h"
#include "DSi.h"
#include "AREngine.h"
+#include "Platform.h"
+using Platform::Log;
+using Platform::LogLevel;
namespace AREngine
{
@@ -271,7 +274,7 @@ void RunCheat(ARCode& arcode)
// in practice could be used for a self-modifying AR code
// could be implemented with some hackery, but, does anything even
// use it??
- printf("AR: !! THE FUCKING C4000000 OPCODE. TELL ARISOTURA.\n");
+ Log(LogLevel::Error, "AR: !! THE FUCKING C4000000 OPCODE. TELL ARISOTURA.\n");
return;
case 0xC5: // count++ / IF (count & b.l) == b.h
@@ -428,7 +431,7 @@ void RunCheat(ARCode& arcode)
break;
default:
- printf("!! bad AR opcode %08X %08X\n", a, b);
+ Log(LogLevel::Warn, "!! bad AR opcode %08X %08X\n", a, b);
return;
}
}
diff --git a/src/ARM.cpp b/src/ARM.cpp
index d87dc1d..6063bca 100644
--- a/src/ARM.cpp
+++ b/src/ARM.cpp
@@ -24,12 +24,16 @@
#include "ARMInterpreter.h"
#include "AREngine.h"
#include "ARMJIT.h"
+#include "Platform.h"
#ifdef JIT_ENABLED
#include "ARMJIT.h"
#include "ARMJIT_Memory.h"
#endif
+using Platform::Log;
+using Platform::LogLevel;
+
// instruction timing notes
//
// * simple instruction: 1S (code)
@@ -419,7 +423,7 @@ void ARM::RestoreCPSR()
break;
default:
- printf("!! attempt to restore CPSR under bad mode %02X, %08X\n", CPSR&0x1F, R[15]);
+ Log(LogLevel::Warn, "!! attempt to restore CPSR under bad mode %02X, %08X\n", CPSR&0x1F, R[15]);
break;
}
@@ -532,7 +536,7 @@ void ARM::TriggerIRQ()
void ARMv5::PrefetchAbort()
{
- printf("ARM9: prefetch abort (%08X)\n", R[15]);
+ Log(LogLevel::Warn, "ARM9: prefetch abort (%08X)\n", R[15]);
u32 oldcpsr = CPSR;
CPSR &= ~0xBF;
@@ -543,7 +547,7 @@ void ARMv5::PrefetchAbort()
// so better take care of it
if (!(PU_Map[ExceptionBase>>12] & 0x04))
{
- printf("!!!!! EXCEPTION REGION NOT EXECUTABLE. THIS IS VERY BAD!!\n");
+ Log(LogLevel::Error, "!!!!! EXCEPTION REGION NOT EXECUTABLE. THIS IS VERY BAD!!\n");
NDS::Stop();
return;
}
@@ -555,7 +559,7 @@ void ARMv5::PrefetchAbort()
void ARMv5::DataAbort()
{
- printf("ARM9: data abort (%08X)\n", R[15]);
+ Log(LogLevel::Warn, "ARM9: data abort (%08X)\n", R[15]);
u32 oldcpsr = CPSR;
CPSR &= ~0xBF;
@@ -679,7 +683,7 @@ void ARMv5::ExecuteJIT()
&& !ARMJIT::SetupExecutableRegion(0, instrAddr, FastBlockLookup, FastBlockLookupStart, FastBlockLookupSize))
{
NDS::ARM9Timestamp = NDS::ARM9Target;
- printf("ARMv5 PC in non executable region %08X\n", R[15]);
+ Log(LogLevel::Error, "ARMv5 PC in non executable region %08X\n", R[15]);
return;
}
@@ -830,7 +834,7 @@ void ARMv4::ExecuteJIT()
&& !ARMJIT::SetupExecutableRegion(1, instrAddr, FastBlockLookup, FastBlockLookupStart, FastBlockLookupSize))
{
NDS::ARM7Timestamp = NDS::ARM7Target;
- printf("ARMv4 PC in non executable region %08X\n", R[15]);
+ Log(LogLevel::Error, "ARMv4 PC in non executable region %08X\n", R[15]);
return;
}
diff --git a/src/ARMInterpreter.cpp b/src/ARMInterpreter.cpp
index aaa1e7b..35854d1 100644
--- a/src/ARMInterpreter.cpp
+++ b/src/ARMInterpreter.cpp
@@ -22,7 +22,10 @@
#include "ARMInterpreter_ALU.h"
#include "ARMInterpreter_Branch.h"
#include "ARMInterpreter_LoadStore.h"
+#include "Platform.h"
+using Platform::Log;
+using Platform::LogLevel;
namespace ARMInterpreter
{
@@ -30,7 +33,7 @@ namespace ARMInterpreter
void A_UNK(ARM* cpu)
{
- printf("undefined ARM%d instruction %08X @ %08X\n", cpu->Num?7:9, cpu->CurInstr, cpu->R[15]-8);
+ Log(LogLevel::Warn, "undefined ARM%d instruction %08X @ %08X\n", cpu->Num?7:9, cpu->CurInstr, cpu->R[15]-8);
//for (int i = 0; i < 16; i++) printf("R%d: %08X\n", i, cpu->R[i]);
//NDS::Halt();
u32 oldcpsr = cpu->CPSR;
@@ -45,7 +48,7 @@ void A_UNK(ARM* cpu)
void T_UNK(ARM* cpu)
{
- printf("undefined THUMB%d instruction %04X @ %08X\n", cpu->Num?7:9, cpu->CurInstr, cpu->R[15]-4);
+ Log(LogLevel::Warn, "undefined THUMB%d instruction %04X @ %08X\n", cpu->Num?7:9, cpu->CurInstr, cpu->R[15]-4);
//NDS::Halt();
u32 oldcpsr = cpu->CPSR;
cpu->CPSR &= ~0xBF;
@@ -211,11 +214,11 @@ void A_MCR(ARM* cpu)
}
else if (cpu->Num==1 && cp==14)
{
- printf("MCR p14,%d,%d,%d on ARM7\n", cn, cm, cpinfo);
+ Log(LogLevel::Debug, "MCR p14,%d,%d,%d on ARM7\n", cn, cm, cpinfo);
}
else
{
- printf("bad MCR opcode p%d,%d,%d,%d on ARM%d\n", cp, cn, cm, cpinfo, cpu->Num?7:9);
+ Log(LogLevel::Warn, "bad MCR opcode p%d,%d,%d,%d on ARM%d\n", cp, cn, cm, cpinfo, cpu->Num?7:9);
return A_UNK(cpu); // TODO: check what kind of exception it really is
}
@@ -239,11 +242,11 @@ void A_MRC(ARM* cpu)
}
else if (cpu->Num==1 && cp==14)
{
- printf("MRC p14,%d,%d,%d on ARM7\n", cn, cm, cpinfo);
+ Log(LogLevel::Debug, "MRC p14,%d,%d,%d on ARM7\n", cn, cm, cpinfo);
}
else
{
- printf("bad MRC opcode p%d,%d,%d,%d on ARM%d\n", cp, cn, cm, cpinfo, cpu->Num?7:9);
+ Log(LogLevel::Warn, "bad MRC opcode p%d,%d,%d,%d on ARM%d\n", cp, cn, cm, cpinfo, cpu->Num?7:9);
return A_UNK(cpu); // TODO: check what kind of exception it really is
}
diff --git a/src/ARMInterpreter_Branch.cpp b/src/ARMInterpreter_Branch.cpp
index 848c03b..ab66395 100644
--- a/src/ARMInterpreter_Branch.cpp
+++ b/src/ARMInterpreter_Branch.cpp
@@ -16,9 +16,11 @@
with melonDS. If not, see http://www.gnu.org/licenses/.
*/
-#include <stdio.h>
#include "ARM.h"
+#include "Platform.h"
+using Platform::Log;
+using Platform::LogLevel;
namespace ARMInterpreter
{
@@ -79,7 +81,7 @@ void T_BLX_REG(ARM* cpu)
{
if (cpu->Num==1)
{
- printf("!! THUMB BLX_REG ON ARM7\n");
+ Log(LogLevel::Warn, "!! THUMB BLX_REG ON ARM7\n");
return;
}
diff --git a/src/ARMJIT.cpp b/src/ARMJIT.cpp
index 32f20d5..77d8602 100644
--- a/src/ARMJIT.cpp
+++ b/src/ARMJIT.cpp
@@ -42,7 +42,10 @@
#include "SPU.h"
#include "Wifi.h"
#include "NDSCart.h"
+#include "Platform.h"
+using Platform::Log;
+using Platform::LogLevel;
#include "ARMJIT_x64/ARMJIT_Offsets.h"
static_assert(offsetof(ARM, CPSR) == ARM_CPSR_offset, "");
@@ -52,7 +55,7 @@ static_assert(offsetof(ARM, StopExecution) == ARM_StopExecution_offset, "");
namespace ARMJIT
{
-#define JIT_DEBUGPRINT(msg, ...)
+#define JIT_DEBUGPRINT(msg, ...) Platform::Log(Platform::LogLevel::Debug, msg, ## __VA_ARGS__)
//#define JIT_DEBUGPRINT(msg, ...) printf(msg, ## __VA_ARGS__)
Compiler* JITCompiler;
@@ -594,7 +597,7 @@ void CompileBlock(ARM* cpu)
u32 localAddr = LocaliseCodeAddress(cpu->Num, blockAddr);
if (!localAddr)
{
- printf("trying to compile non executable code? %x\n", blockAddr);
+ Log(LogLevel::Warn, "trying to compile non executable code? %x\n", blockAddr);
}
auto& map = cpu->Num == 0 ? JitBlocks9 : JitBlocks7;
@@ -764,7 +767,7 @@ void CompileBlock(ARM* cpu)
u32 translatedAddr = LocaliseCodeAddress(cpu->Num, literalAddr);
if (!translatedAddr)
{
- printf("literal in non executable memory?\n");
+ Log(LogLevel::Warn,"literal in non executable memory?\n");
}
if (InvalidLiterals.Find(translatedAddr) == -1)
{
@@ -1175,7 +1178,7 @@ template void CheckAndInvalidate<1, ARMJIT_Memory::memregion_NewSharedWRAM_C>(u3
void ResetBlockCache()
{
- printf("Resetting JIT block cache...\n");
+ Log(LogLevel::Debug, "Resetting JIT block cache...\n");
// could be replace through a function which only resets
// the permissions but we're too lazy
diff --git a/src/ARMJIT_A64/ARMJIT_Branch.cpp b/src/ARMJIT_A64/ARMJIT_Branch.cpp
index 1cdefea..c7b6e98 100644
--- a/src/ARMJIT_A64/ARMJIT_Branch.cpp
+++ b/src/ARMJIT_A64/ARMJIT_Branch.cpp
@@ -388,7 +388,7 @@ void Compiler::T_Comp_BranchXchangeReg()
{
if (Num == 1)
{
- printf("BLX unsupported on ARM7!!!\n");
+ Log(LogLevel::Warn, "BLX unsupported on ARM7!!!\n");
return;
}
MOV(W0, MapReg(CurInstr.A_Reg(3)));
diff --git a/src/ARMJIT_A64/ARMJIT_Compiler.cpp b/src/ARMJIT_A64/ARMJIT_Compiler.cpp
index bb7a693..55bca84 100644
--- a/src/ARMJIT_A64/ARMJIT_Compiler.cpp
+++ b/src/ARMJIT_A64/ARMJIT_Compiler.cpp
@@ -239,7 +239,7 @@ Compiler::Compiler()
break;
if (i++ > 8)
{
- printf("couldn't find unmapped place for jit memory\n");
+ Log(LogLevel::Error, "couldn't find unmapped place for jit memory\n");
JitRXStart = NULL;
}
}
@@ -703,12 +703,12 @@ JitBlockEntry Compiler::CompileBlock(ARM* cpu, bool thumb, FetchedInstr instrs[]
{
if (JitMemMainSize - GetCodeOffset() < 1024 * 16)
{
- printf("JIT near memory full, resetting...\n");
+ Log(LogLevel::Debug, "JIT near memory full, resetting...\n");
ResetBlockCache();
}
if ((JitMemMainSize + JitMemSecondarySize) - OtherCodeRegion < 1024 * 8)
{
- printf("JIT far memory full, resetting...\n");
+ Log(LogLevel::Debug, "JIT far memory full, resetting...\n");
ResetBlockCache();
}
diff --git a/src/ARMJIT_A64/ARMJIT_LoadStore.cpp b/src/ARMJIT_A64/ARMJIT_LoadStore.cpp
index f159d88..ee8aabe 100644
--- a/src/ARMJIT_A64/ARMJIT_LoadStore.cpp
+++ b/src/ARMJIT_A64/ARMJIT_LoadStore.cpp
@@ -56,7 +56,7 @@ u8* Compiler::RewriteMemAccess(u8* pc)
return pc + (ptrdiff_t)patch.PatchOffset;
}
- printf("this is a JIT bug! %08x\n", __builtin_bswap32(*(u32*)pc));
+ Log(LogLevel::Error, "this is a JIT bug! %08x\n", __builtin_bswap32(*(u32*)pc));
abort();
}
@@ -332,7 +332,7 @@ void Compiler::Comp_MemAccess(int rd, int rn, Op2 offset, int size, int flags)
if (CurInstr.Info.Branches())
{
if (size < 32)
- printf("LDR size < 32 branching?\n");
+ Log(LogLevel::Debug, "LDR size < 32 branching?\n");
Comp_JumpTo(rdMapped, Num == 0, false);
}
}
diff --git a/src/ARMJIT_Memory.cpp b/src/ARMJIT_Memory.cpp
index 4a47f4c..0901248 100644
--- a/src/ARMJIT_Memory.cpp
+++ b/src/ARMJIT_Memory.cpp
@@ -48,6 +48,9 @@
#include <stdlib.h>
+using Platform::Log;
+using Platform::LogLevel;
+
/*
We're handling fastmem here.
@@ -399,7 +402,7 @@ struct Mapping
if (status == memstate_MappedRW)
{
u32 segmentSize = offset - segmentOffset;
- printf("unmapping %x %x %x %x\n", Addr + segmentOffset, Num, segmentOffset + LocalOffset + OffsetsPerRegion[region], segmentSize);
+ Log(LogLevel::Debug, "unmapping %x %x %x %x\n", Addr + segmentOffset, Num, segmentOffset + LocalOffset + OffsetsPerRegion[region], segmentSize);
bool success = UnmapFromRange(Addr + segmentOffset, Num, segmentOffset + LocalOffset + OffsetsPerRegion[region], segmentSize);
assert(success);
}
@@ -485,7 +488,7 @@ void RemapDTCM(u32 newBase, u32 newSize)
u32 newEnd = newBase + newSize;
- printf("remapping DTCM %x %x %x %x\n", newBase, newEnd, oldDTCMBase, oldDTCMEnd);
+ Log(LogLevel::Debug, "remapping DTCM %x %x %x %x\n", newBase, newEnd, oldDTCMBase, oldDTCMEnd);
// unmap all regions containing the old or the current DTCM mapping
for (int region = 0; region < memregions_Count; region++)
{
@@ -499,7 +502,7 @@ void RemapDTCM(u32 newBase, u32 newSize)
u32 start = mapping.Addr;
u32 end = mapping.Addr + mapping.Size;
- printf("unmapping %d %x %x %x %x\n", region, mapping.Addr, mapping.Size, mapping.Num, mapping.LocalOffset);
+ Log(LogLevel::Debug, "unmapping %d %x %x %x %x\n", region, mapping.Addr, mapping.Size, mapping.Num, mapping.LocalOffset);
bool overlap = (oldDTCMSize > 0 && oldDTCMBase < end && oldDTCMEnd > start)
|| (newSize > 0 && newBase < end && newEnd > start);
@@ -548,7 +551,7 @@ void RemapNWRAM(int num)
void RemapSWRAM()
{
- printf("remapping SWRAM\n");
+ Log(LogLevel::Debug, "remapping SWRAM\n");
for (int i = 0; i < Mappings[memregion_WRAM7].Length;)
{
Mapping& mapping = Mappings[memregion_WRAM7][i];
@@ -772,13 +775,13 @@ void Init()
MemoryFile = shm_open(fastmemPidName, O_RDWR | O_CREAT | O_EXCL, 0600);
if (MemoryFile == -1)
{
- printf("Failed to open memory using shm_open!");
+ Log(LogLevel::Error, "Failed to open memory using shm_open!");
}
shm_unlink(fastmemPidName);
#endif
if (ftruncate(MemoryFile, MemoryTotalSize) < 0)
{
- printf("Failed to allocate memory using ftruncate!");
+ Log(LogLevel::Error, "Failed to allocate memory using ftruncate!");
}
struct sigaction sa;
@@ -845,7 +848,7 @@ void Reset()
assert(MappingStatus7[i] == memstate_Unmapped);
}
- printf("done resetting jit mem\n");
+ Log(LogLevel::Debug, "done resetting jit mem\n");
}
bool IsFastmemCompatible(int region)
diff --git a/src/ARMJIT_RegisterCache.h b/src/ARMJIT_RegisterCache.h
index e0c4a15..7ea44ed 100644
--- a/src/ARMJIT_RegisterCache.h
+++ b/src/ARMJIT_RegisterCache.h
@@ -21,6 +21,7 @@
#include "ARMJIT.h"
#include "ARMJIT_Internal.h"
+#include "Platform.h"
// TODO: replace this in the future
#include "dolphin/BitSet.h"
@@ -29,6 +30,9 @@
namespace ARMJIT
{
+ using Platform::Log;
+ using Platform::LogLevel;
+ // Imported inside the namespace so that other headers aren't polluted
template <typename T, typename Reg>
class RegisterCache
@@ -80,7 +84,7 @@ public:
}
}
- printf("this is a JIT bug! LoadRegister failed\n");
+ Log(LogLevel::Error, "this is a JIT bug! LoadRegister failed\n");
abort();
}
diff --git a/src/ARMJIT_x64/ARMJIT_ALU.cpp b/src/ARMJIT_x64/ARMJIT_ALU.cpp
index 0a364ea..ff30787 100644
--- a/src/ARMJIT_x64/ARMJIT_ALU.cpp
+++ b/src/ARMJIT_x64/ARMJIT_ALU.cpp
@@ -227,7 +227,7 @@ void Compiler::A_Comp_Arith()
Comp_ArithTriOp(&Compiler::AND, rd, rn, op2, carryUsed, sFlag|opSymmetric|opInvertOp2);
break;
default:
- printf("this is a JIT bug! %04x\n", op);
+ Log(LogLevel::Error, "this is a JIT bug! %04x\n", op);
abort();
}
diff --git a/src/ARMJIT_x64/ARMJIT_Branch.cpp b/src/ARMJIT_x64/ARMJIT_Branch.cpp
index 8451665..281b24a 100644
--- a/src/ARMJIT_x64/ARMJIT_Branch.cpp
+++ b/src/ARMJIT_x64/ARMJIT_Branch.cpp
@@ -247,7 +247,7 @@ void Compiler::T_Comp_BranchXchangeReg()
{
if (Num == 1)
{
- printf("BLX unsupported on ARM7!!!\n");
+ Log(LogLevel::Warn, "BLX unsupported on ARM7!!!\n");
return;
}
MOV(32, R(RSCRATCH), MapReg(CurInstr.A_Reg(3)));
diff --git a/src/ARMJIT_x64/ARMJIT_Compiler.cpp b/src/ARMJIT_x64/ARMJIT_Compiler.cpp
index fa015f4..ce09871 100644
--- a/src/ARMJIT_x64/ARMJIT_Compiler.cpp
+++ b/src/ARMJIT_x64/ARMJIT_Compiler.cpp
@@ -711,12 +711,12 @@ JitBlockEntry Compiler::CompileBlock(ARM* cpu, bool thumb, FetchedInstr instrs[]
{
if (NearSize - (GetCodePtr() - NearStart) < 1024 * 32) // guess...
{
- printf("near reset\n");
+ Log(LogLevel::Debug, "near reset\n");
ResetBlockCache();
}
if (FarSize - (FarCode - FarStart) < 1024 * 32) // guess...
{
- printf("far reset\n");
+ Log(LogLevel::Debug, "far reset\n");
ResetBlockCache();
}
diff --git a/src/ARMJIT_x64/ARMJIT_LoadStore.cpp b/src/ARMJIT_x64/ARMJIT_LoadStore.cpp
index 7b28e68..99555ff 100644
--- a/src/ARMJIT_x64/ARMJIT_LoadStore.cpp
+++ b/src/ARMJIT_x64/ARMJIT_LoadStore.cpp
@@ -51,7 +51,7 @@ u8* Compiler::RewriteMemAccess(u8* pc)
return pc + (ptrdiff_t)patch.Offset;
}
- printf("this is a JIT bug %sx\n", pc);
+ Log(LogLevel::Error, "this is a JIT bug %sx\n", pc);
abort();
}
@@ -382,7 +382,7 @@ void Compiler::Comp_MemAccess(int rd, int rn, const Op2& op2, int size, int flag
if (!(flags & memop_Store) && rd == 15)
{
if (size < 32)
- printf("!!! LDR <32 bit PC %08X %x\n", R15, CurInstr.Instr);
+ Log(LogLevel::Debug, "!!! LDR <32 bit PC %08X %x\n", R15, CurInstr.Instr);
{
if (Num == 1)
{
diff --git a/src/CP15.cpp b/src/CP15.cpp
index 4fe91cf..7db7b60 100644
--- a/src/CP15.cpp
+++ b/src/CP15.cpp
@@ -21,12 +21,16 @@
#include "NDS.h"
#include "DSi.h"
#include "ARM.h"
+#include "Platform.h"
#ifdef JIT_ENABLED
#include "ARMJIT.h"
#include "ARMJIT_Memory.h"
#endif
+using Platform::Log;
+using Platform::LogLevel;
+
// access timing for cached regions
// this would be an average between cache hits and cache misses
// this was measured to be close to hardware average
@@ -201,7 +205,7 @@ void ARMv5::UpdatePURegion(u32 n)
case 3: privmask |= 0x03; usermask |= 0x03; break;
case 5: privmask |= 0x01; break;
case 6: privmask |= 0x01; usermask |= 0x01; break;
- default: printf("!! BAD DATARW VALUE %d\n", datarw&0xF);
+ default: Log(LogLevel::Warn, "!! BAD DATARW VALUE %d\n", datarw&0xF);
}
switch (coderw)
@@ -212,7 +216,7 @@ void ARMv5::UpdatePURegion(u32 n)
case 3: privmask |= 0x04; usermask |= 0x04; break;
case 5: privmask |= 0x04; break;
case 6: privmask |= 0x04; usermask |= 0x04; break;
- default: printf("!! BAD CODERW VALUE %d\n", datarw&0xF);
+ default: Log(LogLevel::Warn, "!! BAD CODERW VALUE %d\n", datarw&0xF);
}
if (datacache & 0x1)
@@ -233,8 +237,17 @@ void ARMv5::UpdatePURegion(u32 n)
usermask |= 0x40;
}
- printf("PU region %d: %08X-%08X, user=%02X priv=%02X\n", n, start<<12, end<<12, usermask, privmask);
- printf("%08X/%08X\n", PU_DataRW, PU_CodeRW);
+ Log(
+ LogLevel::Debug,
+ "PU region %d: %08X-%08X, user=%02X priv=%02X, %08X/%08X\n",
+ n,
+ start << 12,
+ end << 12,
+ usermask,
+ privmask,
+ PU_DataRW,
+ PU_CodeRW
+ );
for (u32 i = start; i < end; i++)
{
@@ -443,7 +456,7 @@ void ARMv5::CP15Write(u32 id, u32 val)
{
UpdatePURegions((old & 0x1) != (val & 0x1));
}
- if (val & (1<<7)) printf("!!!! ARM9 BIG ENDIAN MODE. VERY BAD. SHIT GONNA ASPLODE NOW\n");
+ if (val & (1<<7)) Log(LogLevel::Warn, "!!!! ARM9 BIG ENDIAN MODE. VERY BAD. SHIT GONNA ASPLODE NOW\n");
if (val & (1<<13)) ExceptionBase = 0xFFFF0000;
else ExceptionBase = 0x00000000;
}
@@ -564,11 +577,21 @@ void ARMv5::CP15Write(u32 id, u32 val)
case 0x661:
case 0x670:
case 0x671:
+ char log_output[1024];
PU_Region[(id >> 4) & 0xF] = val;
- printf("PU: region %d = %08X : ", (id>>4)&0xF, val);
- printf("%s, ", val&1 ? "enabled":"disabled");
- printf("%08X-", val&0xFFFFF000);
- printf("%08X\n", (val&0xFFFFF000)+(2<<((val&0x3E)>>1)));
+
+ std::snprintf(log_output,
+ sizeof(log_output),
+ "PU: region %d = %08X : %s, %08X-%08X\n",
+ (id >> 4) & 0xF,
+ val,
+ val & 1 ? "enabled" : "disabled",
+ val & 0xFFFFF000,
+ (val & 0xFFFFF000) + (2 << ((val & 0x3E) >> 1))
+ );
+ Log(LogLevel::Debug, "%s", log_output);
+ // Some implementations of Log imply a newline, so we build up the line before printing it
+
// TODO: smarter region update for this?
UpdatePURegions(true);
return;
@@ -589,7 +612,7 @@ void ARMv5::CP15Write(u32 id, u32 val)
//Halt(255);
return;
case 0x752:
- printf("CP15: ICACHE INVALIDATE WEIRD. %08X\n", val);
+ Log(LogLevel::Warn, "CP15: ICACHE INVALIDATE WEIRD. %08X\n", val);
//Halt(255);
return;
@@ -645,7 +668,7 @@ void ARMv5::CP15Write(u32 id, u32 val)
return;
if ((id & 0xF00) != 0x700)
- printf("unknown CP15 write op %03X %08X\n", id, val);
+ Log(LogLevel::Warn, "unknown CP15 write op %03X %08X\n", id, val);
}
u32 ARMv5::CP15Read(u32 id)
@@ -741,7 +764,7 @@ u32 ARMv5::CP15Read(u32 id)
if ((id & 0xF00) == 0xF00) // test/debug shit?
return 0;
- printf("unknown CP15 read op %03X\n", id);
+ Log(LogLevel::Warn, "unknown CP15 read op %03X\n", id);
return 0;
}
diff --git a/src/DMA.cpp b/src/DMA.cpp
index f45efc5..6877914 100644
--- a/src/DMA.cpp
+++ b/src/DMA.cpp
@@ -22,8 +22,10 @@
#include "DMA.h"
#include "GPU.h"
#include "DMA_Timings.h"
+#include "Platform.h"
-
+using Platform::Log;
+using Platform::LogLevel;
// DMA TIMINGS
//
@@ -142,7 +144,7 @@ void DMA::WriteCnt(u32 val)
GPU3D::CheckFIFODMA();
if (StartMode==0x06 || StartMode==0x13)
- printf("UNIMPLEMENTED ARM%d DMA%d START MODE %02X, %08X->%08X\n", CPU?7:9, Num, StartMode, SrcAddr, DstAddr);
+ Log(LogLevel::Warn, "UNIMPLEMENTED ARM%d DMA%d START MODE %02X, %08X->%08X\n", CPU?7:9, Num, StartMode, SrcAddr, DstAddr);
}
}
diff --git a/src/DSi.cpp b/src/DSi.cpp
index e069c85..b35eda6 100644
--- a/src/DSi.cpp
+++ b/src/DSi.cpp
@@ -43,6 +43,8 @@
#include "tiny-AES-c/aes.hpp"
+using Platform::Log;
+using Platform::LogLevel;
namespace DSi
{
@@ -692,7 +694,7 @@ bool LoadBIOS()
f = Platform::OpenLocalFile(Platform::GetConfigString(Platform::DSi_BIOS9Path), "rb");
if (!f)
{
- printf("ARM9i BIOS not found\n");
+ Log(LogLevel::Warn, "ARM9i BIOS not found\n");
for (i = 0; i < 16; i++)
((u32*)ARM9iBIOS)[i] = 0xE7FFDEFF;
@@ -702,14 +704,14 @@ bool LoadBIOS()
fseek(f, 0, SEEK_SET);
fread(ARM9iBIOS, 0x10000, 1, f);
- printf("ARM9i BIOS loaded\n");
+ Log(LogLevel::Info, "ARM9i BIOS loaded\n");
fclose(f);
}
f = Platform::OpenLocalFile(Platform::GetConfigString(Platform::DSi_BIOS7Path), "rb");
if (!f)
{
- printf("ARM7i BIOS not found\n");
+ Log(LogLevel::Warn, "ARM7i BIOS not found\n");
for (i = 0; i < 16; i++)
((u32*)ARM7iBIOS)[i] = 0xE7FFDEFF;
@@ -721,7 +723,7 @@ bool LoadBIOS()
fseek(f, 0, SEEK_SET);
fread(ARM7iBIOS, 0x10000, 1, f);
- printf("ARM7i BIOS loaded\n");
+ Log(LogLevel::Info, "ARM7i BIOS loaded\n");
fclose(f);
}
@@ -737,11 +739,11 @@ bool LoadBIOS()
bool LoadNAND()
{
- printf("Loading DSi NAND\n");
+ Log(LogLevel::Info, "Loading DSi NAND\n");
if (!DSi_NAND::Init(&DSi::ARM7iBIOS[0x8308]))
{
- printf("Failed to load DSi NAND\n");
+ Log(LogLevel::Error, "Failed to load DSi NAND\n");
return false;
}
@@ -770,9 +772,9 @@ bool LoadNAND()
fseek(nand, 0x220, SEEK_SET);
fread(bootparams, 4, 8, nand);
- printf("ARM9: offset=%08X size=%08X RAM=%08X size_aligned=%08X\n",
+ Log(LogLevel::Debug, "ARM9: offset=%08X size=%08X RAM=%08X size_aligned=%08X\n",
bootparams[0], bootparams[1], bootparams[2], bootparams[3]);
- printf("ARM7: offset=%08X size=%08X RAM=%08X size_aligned=%08X\n",
+ Log(LogLevel::Debug, "ARM7: offset=%08X size=%08X RAM=%08X size_aligned=%08X\n",
bootparams[4], bootparams[5], bootparams[6], bootparams[7]);
// read and apply new-WRAM settings
@@ -883,8 +885,8 @@ bool LoadNAND()
DSi_NAND::GetIDs(eMMC_CID, ConsoleID);
- printf("eMMC CID: "); printhex(eMMC_CID, 16);
- printf("Console ID: %" PRIx64 "\n", ConsoleID);
+ Log(LogLevel::Debug, "eMMC CID: "); printhex(eMMC_CID, 16);
+ Log(LogLevel::Debug, "Console ID: %" PRIx64 "\n", ConsoleID);
u32 eaddr = 0x03FFE6E4;
ARM7Write32(eaddr+0x00, *(u32*)&eMMC_CID[0]);
@@ -1003,7 +1005,7 @@ void MapNWRAM_A(u32 num, u8 val)
if (MBK[0][8] & (1 << num))
{
- printf("trying to map NWRAM_A %d to %02X, but it is write-protected (%08X)\n", num, val, MBK[0][8]);
+ Log(LogLevel::Warn, "trying to map NWRAM_A %d to %02X, but it is write-protected (%08X)\n", num, val, MBK[0][8]);
return;
}
@@ -1050,7 +1052,7 @@ void MapNWRAM_B(u32 num, u8 val)
if (MBK[0][8] & (1 << (8+num)))
{
- printf("trying to map NWRAM_B %d to %02X, but it is write-protected (%08X)\n", num, val, MBK[0][8]);
+ Log(LogLevel::Warn, "trying to map NWRAM_B %d to %02X, but it is write-protected (%08X)\n", num, val, MBK[0][8]);
return;
}
@@ -1099,7 +1101,7 @@ void MapNWRAM_C(u32 num, u8 val)
if (MBK[0][8] & (1 << (16+num)))
{
- printf("trying to map NWRAM_C %d to %02X, but it is write-protected (%08X)\n", num, val, MBK[0][8]);
+ Log(LogLevel::Warn, "trying to map NWRAM_C %d to %02X, but it is write-protected (%08X)\n", num, val, MBK[0][8]);
return;
}
@@ -1179,7 +1181,7 @@ void MapNWRAMRange(u32 cpu, u32 num, u32 val)
u32 end = 0x03000000 + (((val >> 20) & 0x1FF) << 16);
u32 size = (val >> 12) & 0x3;
- printf("NWRAM-A: ARM%d range %08X-%08X, size %d\n", cpu?7:9, start, end, size);
+ Log(LogLevel::Debug, "NWRAM-A: ARM%d range %08X-%08X, size %d\n", cpu?7:9, start, end, size);
NWRAMStart[cpu][num] = start;
NWRAMEnd[cpu][num] = end;
@@ -1198,7 +1200,7 @@ void MapNWRAMRange(u32 cpu, u32 num, u32 val)
u32 end = 0x03000000 + (((val >> 19) & 0x3FF) << 15);
u32 size = (val >> 12) & 0x3;
- printf("NWRAM-%c: ARM%d range %08X-%08X, size %d\n", 'A'+num, cpu?7:9, start, end, size);
+ Log(LogLevel::Debug, "NWRAM-%c: ARM%d range %08X-%08X, size %d\n", 'A'+num, cpu?7:9, start, end, size);
NWRAMStart[cpu][num] = start;
NWRAMEnd[cpu][num] = end;
@@ -1220,12 +1222,12 @@ void ApplyNewRAMSize(u32 size)
case 0:
case 1:
NDS::MainRAMMask = 0x3FFFFF;
- printf("RAM: 4MB\n");
+ Log(LogLevel::Debug, "RAM: 4MB\n");
break;
case 2:
case 3: // TODO: debug console w/ 32MB?
NDS::MainRAMMask = 0xFFFFFF;
- printf("RAM: 16MB\n");
+ Log(LogLevel::Debug, "RAM: 16MB\n");
break;
}
}
@@ -1236,7 +1238,7 @@ void Set_SCFG_Clock9(u16 val)
NDS::ARM9Timestamp >>= NDS::ARM9ClockShift;
NDS::ARM9Target >>= NDS::ARM9ClockShift;
- printf("CLOCK9=%04X\n", val);
+ Log(LogLevel::Debug, "CLOCK9=%04X\n", val);
SCFG_Clock9 = val & 0x0187;
if (SCFG_Clock9 & (1<<0)) NDS::ARM9ClockShift = 2;
@@ -1253,7 +1255,7 @@ void Set_SCFG_MC(u32 val)
val &= 0xFFFF800C;
if ((val & 0xC) == 0xC) val &= ~0xC; // hax
- if (val & 0x8000) printf("SCFG_MC: weird NDS slot swap\n");
+ if (val & 0x8000) Log(LogLevel::Warn, "SCFG_MC: weird NDS slot swap\n");
SCFG_MC = (SCFG_MC & ~0xFFFF800C) | val;
if ((oldslotstatus == 0x0) && ((SCFG_MC & 0xC) == 0x4))
@@ -2537,7 +2539,7 @@ void ARM9IOWrite32(u32 addr, u32 val)
SCFG_EXT[0] |= (val & 0x8007F19F);
SCFG_EXT[1] &= ~0x0000F080;
SCFG_EXT[1] |= (val & 0x0000F080);
- printf("SCFG_EXT = %08X / %08X (val9 %08X)\n", SCFG_EXT[0], SCFG_EXT[1], val);
+ Log(LogLevel::Debug, "SCFG_EXT = %08X / %08X (val9 %08X)\n", SCFG_EXT[0], SCFG_EXT[1], val);
/*switch ((SCFG_EXT[0] >> 14) & 0x3)
{
case 0:
@@ -2558,7 +2560,7 @@ void ARM9IOWrite32(u32 addr, u32 val)
// is still busy clearing/relocating shit
//if (newram != oldram)
// NDS::ScheduleEvent(NDS::Event_DSi_RAMSizeChange, false, 512*512*512, ApplyNewRAMSize, newram);
- printf("from %08X, ARM7 %08X, %08X\n", NDS::GetPC(0), NDS::GetPC(1), NDS::ARM7->R[1]);
+ Log(LogLevel::Debug, "from %08X, ARM7 %08X, %08X\n", NDS::GetPC(0), NDS::GetPC(1), NDS::ARM7->R[1]);
}
return;
@@ -2805,7 +2807,7 @@ u32 ARM7IORead32(u32 addr)
case 0x04004D08: return 0;
case 0x4004700:
- printf("32-Bit SNDExCnt read? %08X\n", NDS::ARM7->R[15]);
+ Log(LogLevel::Debug, "32-Bit SNDExCnt read? %08X\n", NDS::ARM7->R[15]);
return DSi_DSP::SNDExCnt;
}
@@ -3005,7 +3007,7 @@ void ARM7IOWrite32(u32 addr, u32 val)
SCFG_EXT[0] |= (val & 0x03000000);
SCFG_EXT[1] &= ~0x93FF0F07;
SCFG_EXT[1] |= (val & 0x93FF0F07);
- printf("SCFG_EXT = %08X / %08X (val7 %08X)\n", SCFG_EXT[0], SCFG_EXT[1], val);
+ Log(LogLevel::Debug, "SCFG_EXT = %08X / %08X (val7 %08X)\n", SCFG_EXT[0], SCFG_EXT[1], val);
return;
case 0x04004010:
if (!(SCFG_EXT[1] & (1 << 31))) /* no access to SCFG Registers if disabled*/
@@ -3071,7 +3073,7 @@ void ARM7IOWrite32(u32 addr, u32 val)
case 0x04004408: DSi_AES::WriteInputFIFO(val); return;
case 0x4004700:
- printf("32-Bit SNDExCnt write? %08X %08X\n", val, NDS::ARM7->R[15]);
+ Log(LogLevel::Debug, "32-Bit SNDExCnt write? %08X %08X\n", val, NDS::ARM7->R[15]);
DSi_DSP::WriteSNDExCnt(val);
return;
}
diff --git a/src/DSi_AES.cpp b/src/DSi_AES.cpp
index f84db11..eca778a 100644
--- a/src/DSi_AES.cpp
+++ b/src/DSi_AES.cpp
@@ -24,6 +24,8 @@
#include "tiny-AES-c/aes.hpp"
#include "Platform.h"
+using Platform::Log;
+using Platform::LogLevel;
namespace DSi_AES
{
@@ -332,7 +334,7 @@ void WriteCnt(u32 val)
OutputMACDue = false;
- if (AESMode == 0 && (!(val & (1<<20)))) printf("AES: CCM-DECRYPT MAC FROM WRFIFO, TODO\n");
+ if (AESMode == 0 && (!(val & (1<<20)))) Log(LogLevel::Debug, "AES: CCM-DECRYPT MAC FROM WRFIFO, TODO\n");
if ((RemBlocks > 0) || (RemExtra > 0))
{
@@ -390,7 +392,7 @@ void WriteBlkCnt(u32 val)
u32 ReadOutputFIFO()
{
- if (OutputFIFO.IsEmpty()) printf("!!! AES OUTPUT FIFO EMPTY\n");
+ if (OutputFIFO.IsEmpty()) Log(LogLevel::Warn, "!!! AES OUTPUT FIFO EMPTY\n");
u32 ret = OutputFIFO.Read();
@@ -423,7 +425,7 @@ void WriteInputFIFO(u32 val)
{
// TODO: add some delay to processing
- if (InputFIFO.IsFull()) printf("!!! AES INPUT FIFO FULL\n");
+ if (InputFIFO.IsFull()) Log(LogLevel::Warn, "!!! AES INPUT FIFO FULL\n");
InputFIFO.Write(val);
diff --git a/src/DSi_Camera.cpp b/src/DSi_Camera.cpp
index 20f15cf..19e6c5e 100644
--- a/src/DSi_Camera.cpp
+++ b/src/DSi_Camera.cpp
@@ -22,6 +22,8 @@
#include "DSi_Camera.h"
#include "Platform.h"
+using Platform::Log;
+using Platform::LogLevel;
namespace DSi_CamModule
{
@@ -245,7 +247,7 @@ u8 Read8(u32 addr)
{
//
- printf("unknown DSi cam read8 %08X\n", addr);
+ Log(LogLevel::Warn, "unknown DSi cam read8 %08X\n", addr);
return 0;
}
@@ -257,7 +259,7 @@ u16 Read16(u32 addr)
case 0x04004202: return Cnt;
}
- printf("unknown DSi cam read16 %08X\n", addr);
+ Log(LogLevel::Warn, "unknown DSi cam read16 %08X\n", addr);
return 0;
}
@@ -283,7 +285,7 @@ u32 Read32(u32 addr)
case 0x04004214: return CropEnd;
}
- printf("unknown DSi cam read32 %08X\n", addr);
+ Log(LogLevel::Warn, "unknown DSi cam read32 %08X\n", addr);
return 0;
}
@@ -291,7 +293,7 @@ void Write8(u32 addr, u8 val)
{
//
- printf("unknown DSi cam write8 %08X %02X\n", addr, val);
+ Log(LogLevel::Warn, "unknown DSi cam write8 %08X %02X\n", addr, val);
}
void Write16(u32 addr, u16 val)
@@ -370,7 +372,7 @@ void Write16(u32 addr, u16 val)
return;
}
- printf("unknown DSi cam write16 %08X %04X\n", addr, val);
+ Log(LogLevel::Warn, "unknown DSi cam write16 %08X %04X\n", addr, val);
}
void Write32(u32 addr, u32 val)
@@ -387,7 +389,7 @@ void Write32(u32 addr, u32 val)
return;
}
- printf("unknown DSi cam write32 %08X %08X\n", addr, val);
+ Log(LogLevel::Warn, "unknown DSi cam write32 %08X %08X\n", addr, val);
}
@@ -506,7 +508,7 @@ int Camera::TransferScanline(u32* buffer, int maxlen)
(FrameWidth & 1))
{
// TODO work out something for these cases?
- printf("CAM%d: invalid resolution %dx%d\n", Num, FrameWidth, FrameHeight);
+ Log(LogLevel::Warn, "CAM%d: invalid resolution %dx%d\n", Num, FrameWidth, FrameHeight);
//memset(buffer, 0, width*height*sizeof(u16));
return 0;
}
@@ -584,7 +586,7 @@ void Camera::I2C_Write(u8 val, bool last)
else
RegAddr |= val;
- if (RegAddr & 0x1) printf("DSi_Camera: !! UNALIGNED REG ADDRESS %04X\n", RegAddr);
+ if (RegAddr & 0x1) Log(LogLevel::Warn, "DSi_Camera: !! UNALIGNED REG ADDRESS %04X\n", RegAddr);
}
else
{
@@ -636,7 +638,7 @@ u16 Camera::I2C_ReadReg(u16 addr)
case 0x301A: return ((~StandbyCnt) & 0x4000) >> 12;
}
- if(Num==1)printf("DSi_Camera%d: unknown read %04X\n", Num, addr);
+ if(Num==1) Log(LogLevel::Warn, "DSi_Camera%d: unknown read %04X\n", Num, addr);
return 0;
}
@@ -702,7 +704,7 @@ void Camera::I2C_WriteReg(u16 addr, u16 val)
return;
}
- if(Num==1)printf("DSi_Camera%d: unknown write %04X %04X\n", Num, addr, val);
+ if(Num==1) Log(LogLevel::Warn, "DSi_Camera%d: unknown write %04X %04X\n", Num, addr, val);
}
@@ -727,7 +729,7 @@ void Camera::MCU_Write(u16 addr, u8 val)
if (val == 2) MCURegs[0x2104] = 7; // capture mode
else if (val == 1) MCURegs[0x2104] = 3; // preview mode
else if (val != 5 && val != 6)
- printf("CAM%d: atypical SEQ_CMD %04X\n", Num, val);
+ Log(LogLevel::Debug, "CAM%d: atypical SEQ_CMD %04X\n", Num, val);
return;
case 0x2104: // SEQ_STATE, read-only
diff --git a/src/DSi_DSP.cpp b/src/DSi_DSP.cpp
index b89fca3..eaa80f9 100644
--- a/src/DSi_DSP.cpp
+++ b/src/DSi_DSP.cpp
@@ -22,7 +22,10 @@
#include "DSi_DSP.h"
#include "FIFO.h"
#include "NDS.h"
+#include "Platform.h"
+using Platform::Log;
+using Platform::LogLevel;
namespace DSi_DSP
{
@@ -488,7 +491,7 @@ void Write8(u32 addr, u8 val)
}
void Write16(u32 addr, u16 val)
{
- printf("DSP WRITE16 %d %08X %08X %08X\n", IsDSPCoreEnabled(), addr, val, NDS::GetPC(0));
+ Log(LogLevel::Debug,"DSP WRITE16 %d %08X %08X %08X\n", IsDSPCoreEnabled(), addr, val, NDS::GetPC(0));
//if (!IsDSPIOEnabled()) return;
DSPCatchUp();
diff --git a/src/DSi_I2C.cpp b/src/DSi_I2C.cpp
index 5889bef..b4cfa89 100644
--- a/src/DSi_I2C.cpp
+++ b/src/DSi_I2C.cpp
@@ -23,7 +23,10 @@
#include "DSi_Camera.h"
#include "ARM.h"
#include "SPI.h"
+#include "Platform.h"
+using Platform::Log;
+using Platform::LogLevel;
namespace DSi_BPTWL
{
@@ -131,7 +134,7 @@ void Write(u8 val, bool last)
if (CurPos == 0x11 && val == 0x01)
{
- printf("BPTWL: soft-reset\n");
+ Log(LogLevel::Debug, "BPTWL: soft-reset\n");
val = 0; // checkme
// TODO: soft-reset might need to be scheduled later!
// TODO: this has been moved for the JIT to work, nothing is confirmed here
@@ -225,7 +228,7 @@ void WriteCnt(u8 val)
case 0xA0:
case 0xE0: Data = 0xFF; break;
default:
- printf("I2C: read on unknown device %02X, cnt=%02X, data=%02X, last=%d\n", Device, val, 0, islast);
+ Log(LogLevel::Warn, "I2C: read on unknown device %02X, cnt=%02X, data=%02X, last=%d\n", Device, val, 0, islast);
Data = 0xFF;
break;
}
@@ -251,7 +254,7 @@ void WriteCnt(u8 val)
case 0xA0:
case 0xE0: ack = false; break;
default:
- printf("I2C: %s start on unknown device %02X\n", (Data&0x01)?"read":"write", Device);
+ Log(LogLevel::Warn, "I2C: %s start on unknown device %02X\n", (Data&0x01)?"read":"write", Device);
ack = false;
break;
}
@@ -268,7 +271,7 @@ void WriteCnt(u8 val)
case 0xA0:
case 0xE0: ack = false; break;
default:
- printf("I2C: write on unknown device %02X, cnt=%02X, data=%02X, last=%d\n", Device, val, Data, islast);
+ Log(LogLevel::Warn, "I2C: write on unknown device %02X, cnt=%02X, data=%02X, last=%d\n", Device, val, Data, islast);
ack = false;
break;
}
diff --git a/src/DSi_NAND.cpp b/src/DSi_NAND.cpp
index 912fee4..6af2dd2 100644
--- a/src/DSi_NAND.cpp
+++ b/src/DSi_NAND.cpp
@@ -29,6 +29,8 @@
#include "fatfs/ff.h"
+using Platform::Log;
+using Platform::LogLevel;
namespace DSi_NAND
{
@@ -62,7 +64,7 @@ bool Init(u8* es_keyY)
FILE* orig = Platform::OpenLocalFile(nandpath, "rb");
if (!orig)
{
- printf("Failed to open DSi NAND\n");
+ Log(LogLevel::Error, "Failed to open DSi NAND\n");
return false;
}
@@ -103,7 +105,7 @@ bool Init(u8* es_keyY)
res = f_mount(&CurFS, "0:", 0);
if (res != FR_OK)
{
- printf("NAND mounting failed: %d\n", res);
+ Log(LogLevel::Error, "NAND mounting failed: %d\n", res);
f_unmount("0:");
ff_disk_close();
return false;
@@ -125,7 +127,7 @@ bool Init(u8* es_keyY)
fread(nand_footer, 1, 16, nandfile);
if (memcmp(nand_footer, nand_footer_ref, 16))
{
- printf("ERROR: NAND missing nocash footer\n");
+ Log(LogLevel::Error, "ERROR: NAND missing nocash footer\n");
return false;
}
}
@@ -471,7 +473,7 @@ bool ESDecrypt(u8* data, u32 len)
u32 footerlen = footer[0] | (footer[1] << 8) | (footer[2] << 16);
if (footerlen != len)
{
- printf("ESDecrypt: bad length %d (expected %d)\n", len, footerlen);
+ Log(LogLevel::Error, "ESDecrypt: bad length %d (expected %d)\n", len, footerlen);
return false;
}
@@ -479,7 +481,7 @@ bool ESDecrypt(u8* data, u32 len)
{
if (data[len+i] != mac[15-i])
{
- printf("ESDecrypt: bad MAC\n");
+ Log(LogLevel::Warn, "ESDecrypt: bad MAC\n");
return false;
}
}
@@ -572,7 +574,7 @@ void PatchUserData()
res = f_open(&file, filename, FA_OPEN_EXISTING | FA_READ | FA_WRITE);
if (res != FR_OK)
{
- printf("NAND: editing file %s failed: %d\n", filename, res);
+ Log(LogLevel::Error, "NAND: editing file %s failed: %d\n", filename, res);
continue;
}
@@ -651,7 +653,7 @@ void debug_listfiles(const char* path)
char fullname[512];
sprintf(fullname, "%s/%s", path, info.fname);
- printf("[%c] %s\n", (info.fattrib&AM_DIR)?'D':'F', fullname);
+ Log(LogLevel::Debug, "[%c] %s\n", (info.fattrib&AM_DIR)?'D':'F', fullname);
if (info.fattrib & AM_DIR)
{
@@ -838,7 +840,7 @@ void ListTitles(u32 category, std::vector<u32>& titlelist)
res = f_opendir(&titledir, path);
if (res != FR_OK)
{
- printf("NAND: !! no title dir (%s)\n", path);
+ Log(LogLevel::Warn, "NAND: !! no title dir (%s)\n", path);
return;
}
@@ -931,7 +933,7 @@ bool CreateTicket(const char* path, u32 titleid0, u32 titleid1, u8 version)
res = f_open(&file, path, FA_CREATE_ALWAYS | FA_WRITE);
if (res != FR_OK)
{
- printf("CreateTicket: failed to create file (%d)\n", res);
+ Log(LogLevel::Error, "CreateTicket: failed to create file (%d)\n", res);
return false;
}
@@ -1012,7 +1014,7 @@ bool CreateSaveFile(const char* path, u32 len)
res = f_open(&file, path, FA_CREATE_ALWAYS | FA_WRITE);
if (res != FR_OK)
{
- printf("CreateSaveFile: failed to create file (%d)\n", res);
+ Log(LogLevel::Error, "CreateSaveFile: failed to create file (%d)\n", res);
return false;
}
@@ -1058,11 +1060,11 @@ bool ImportTitle(const char* appfile, u8* tmd, bool readonly)
}
u32 version = (tmd[0x1E4] << 24) | (tmd[0x1E5] << 16) | (tmd[0x1E6] << 8) | tmd[0x1E7];
- printf(".app version: %08x\n", version);
+ Log(LogLevel::Info, ".app version: %08x\n", version);
u32 titleid0 = (tmd[0x18C] << 24) | (tmd[0x18D] << 16) | (tmd[0x18E] << 8) | tmd[0x18F];
u32 titleid1 = (tmd[0x190] << 24) | (tmd[0x191] << 16) | (tmd[0x192] << 8) | tmd[0x193];
- printf("Title ID: %08x/%08x\n", titleid0, titleid1);
+ Log(LogLevel::Info, "Title ID: %08x/%08x\n", titleid0, titleid1);
FRESULT res;
FF_DIR ticketdir;
@@ -1110,7 +1112,7 @@ bool ImportTitle(const char* appfile, u8* tmd, bool readonly)
res = f_open(&file, fname, FA_CREATE_ALWAYS | FA_WRITE);
if (res != FR_OK)
{
- printf("ImportTitle: failed to create banner.sav (%d)\n", res);
+ Log(LogLevel::Error, "ImportTitle: failed to create banner.sav (%d)\n", res);
return false;
}
@@ -1127,7 +1129,7 @@ bool ImportTitle(const char* appfile, u8* tmd, bool readonly)
res = f_open(&file, fname, FA_CREATE_ALWAYS | FA_WRITE);
if (res != FR_OK)
{
- printf("ImportTitle: failed to create TMD (%d)\n", res);
+ Log(LogLevel::Error, "ImportTitle: failed to create TMD (%d)\n", res);
return false;
}
@@ -1142,7 +1144,7 @@ bool ImportTitle(const char* appfile, u8* tmd, bool readonly)
sprintf(fname, "0:/title/%08x/%08x/content/%08x.app", titleid0, titleid1, version);
if (!ImportFile(fname, appfile))
{
- printf("ImportTitle: failed to create executable (%d)\n", res);
+ Log(LogLevel::Error, "ImportTitle: failed to create executable (%d)\n", res);
return false;
}
diff --git a/src/DSi_NDMA.cpp b/src/DSi_NDMA.cpp
index fef755a..dba920c 100644
--- a/src/DSi_NDMA.cpp
+++ b/src/DSi_NDMA.cpp
@@ -23,7 +23,8 @@
#include "GPU.h"
#include "DSi_AES.h"
-
+using Platform::Log;
+using Platform::LogLevel;
DSi_NDMA::DSi_NDMA(u32 cpu, u32 num)
{
@@ -106,7 +107,7 @@ void DSi_NDMA::WriteCnt(u32 val)
case 0: DstAddrInc = 1; break;
case 1: DstAddrInc = -1; break;
case 2: DstAddrInc = 0; break;
- case 3: DstAddrInc = 1; printf("BAD NDMA DST INC MODE 3\n"); break;
+ case 3: DstAddrInc = 1; Log(LogLevel::Warn, "BAD NDMA DST INC MODE 3\n"); break;
}
switch ((Cnt >> 13) & 0x3)
@@ -134,7 +135,7 @@ void DSi_NDMA::WriteCnt(u32 val)
if (StartMode <= 0x03 || StartMode == 0x05 || (StartMode >= 0x0C && StartMode <= 0x0F) ||
(StartMode >= 0x20 && StartMode <= 0x23) || StartMode == 0x25 || StartMode == 0x27 || (StartMode >= 0x2C && StartMode <= 0x2F))
- printf("UNIMPLEMENTED ARM%d NDMA%d START MODE %02X, %08X->%08X LEN=%d BLK=%d CNT=%08X\n",
+ Log(LogLevel::Warn, "UNIMPLEMENTED ARM%d NDMA%d START MODE %02X, %08X->%08X LEN=%d BLK=%d CNT=%08X\n",
CPU?7:9, Num, StartMode, SrcAddr, DstAddr, TotalLength, BlockLength, Cnt);
}
}
diff --git a/src/DSi_NWifi.cpp b/src/DSi_NWifi.cpp
index 7f8be83..b07d7a7 100644
--- a/src/DSi_NWifi.cpp
+++ b/src/DSi_NWifi.cpp
@@ -24,6 +24,9 @@
#include "WifiAP.h"
#include "Platform.h"
+using Platform::Log;
+using Platform::LogLevel;
+
const u8 CIS0[256] =
{
@@ -161,7 +164,7 @@ void DSi_NWifi::Reset()
Mailbox[i].Clear();
u8* mac = SPI_Firmware::GetWifiMAC();
- printf("NWifi MAC: %02X:%02X:%02X:%02X:%02X:%02X\n",
+ Log(LogLevel::Info, "NWifi MAC: %02X:%02X:%02X:%02X:%02X:%02X\n",
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
u8 type = SPI_Firmware::GetNWifiVersion();
@@ -183,11 +186,11 @@ void DSi_NWifi::Reset()
ROMID = 0x2300006F;
ChipID = 0x0D000001;
HostIntAddr = 0x00520000;
- printf("NWifi: hardware is 3DS type, unchecked\n");
+ Log(LogLevel::Info, "NWifi: hardware is 3DS type, unchecked\n");
break;
default:
- printf("NWifi: unknown hardware type, assuming AR6002\n");
+ Log(LogLevel::Warn, "NWifi: unknown hardware type, assuming AR6002\n");
ROMID = 0x20000188;
ChipID = 0x02000001;
HostIntAddr = 0x00500400;
@@ -353,7 +356,7 @@ u8 DSi_NWifi::F0_Read(u32 addr)
return CIS1[addr & 0xFF];
}
- printf("NWIFI: unknown func0 read %05X\n", addr);
+ Log(LogLevel::Warn, "NWIFI: unknown func0 read %05X\n", addr);
return 0;
}
@@ -367,7 +370,7 @@ void DSi_NWifi::F0_Write(u32 addr, u8 val)
return;
}
- printf("NWIFI: unknown func0 write %05X %02X\n", addr, val);
+ Log(LogLevel::Warn, "NWIFI: unknown func0 write %05X %02X\n", addr, val);
}
@@ -480,7 +483,7 @@ void DSi_NWifi::F1_Write(u32 addr, u8 val)
{
if (addr < 0x100)
{
- if (Mailbox[0].IsFull()) printf("!!! NWIFI: MBOX0 FULL\n");
+ if (Mailbox[0].IsFull()) Log(LogLevel::Debug, "!!! NWIFI: MBOX0 FULL\n");
Mailbox[0].Write(val);
if (addr == 0xFF) HandleCommand();
UpdateIRQ_F1();
@@ -488,21 +491,21 @@ void DSi_NWifi::F1_Write(u32 addr, u8 val)
}
else if (addr < 0x200)
{
- if (Mailbox[1].IsFull()) printf("!!! NWIFI: MBOX1 FULL\n");
+ if (Mailbox[1].IsFull()) Log(LogLevel::Debug, "!!! NWIFI: MBOX1 FULL\n");
Mailbox[1].Write(val);
UpdateIRQ_F1();
return;
}
else if (addr < 0x300)
{
- if (Mailbox[2].IsFull()) printf("!!! NWIFI: MBOX2 FULL\n");
+ if (Mailbox[2].IsFull()) Log(LogLevel::Debug, "!!! NWIFI: MBOX2 FULL\n");
Mailbox[2].Write(val);
UpdateIRQ_F1();
return;
}
else if (addr < 0x400)
{
- if (Mailbox[3].IsFull()) printf("!!! NWIFI: MBOX3 FULL\n");
+ if (Mailbox[3].IsFull()) Log(LogLevel::Debug, "!!! NWIFI: MBOX3 FULL\n");
Mailbox[3].Write(val);
UpdateIRQ_F1();
return;
@@ -543,7 +546,7 @@ void DSi_NWifi::F1_Write(u32 addr, u8 val)
}
else if (addr < 0x1000)
{
- if (Mailbox[0].IsFull()) printf("!!! NWIFI: MBOX0 FULL\n");
+ if (Mailbox[0].IsFull()) Log(LogLevel::Debug, "!!! NWIFI: MBOX0 FULL\n");
Mailbox[0].Write(val);
if (addr == 0xFFF) HandleCommand();
UpdateIRQ_F1();
@@ -551,35 +554,35 @@ void DSi_NWifi::F1_Write(u32 addr, u8 val)
}
else if (addr < 0x1800)
{
- if (Mailbox[1].IsFull()) printf("!!! NWIFI: MBOX1 FULL\n");
+ if (Mailbox[1].IsFull()) Log(LogLevel::Debug, "!!! NWIFI: MBOX1 FULL\n");
Mailbox[1].Write(val);
UpdateIRQ_F1();
return;
}
else if (addr < 0x2000)
{
- if (Mailbox[2].IsFull()) printf("!!! NWIFI: MBOX2 FULL\n");
+ if (Mailbox[2].IsFull()) Log(LogLevel::Debug, "!!! NWIFI: MBOX2 FULL\n");
Mailbox[2].Write(val);
UpdateIRQ_F1();
return;
}
else if (addr < 0x2800)
{
- if (Mailbox[3].IsFull()) printf("!!! NWIFI: MBOX3 FULL\n");
+ if (Mailbox[3].IsFull()) Log(LogLevel::Debug, "!!! NWIFI: MBOX3 FULL\n");
Mailbox[3].Write(val);
UpdateIRQ_F1();
return;
}
else
{
- if (Mailbox[0].IsFull()) printf("!!! NWIFI: MBOX0 FULL\n");
+ if (Mailbox[0].IsFull()) Log(LogLevel::Debug, "!!! NWIFI: MBOX0 FULL\n");
Mailbox[0].Write(val);
if (addr == 0x3FFF) HandleCommand(); // CHECKME
UpdateIRQ_F1();
return;
}
- printf("NWIFI: unknown func1 write %05X %02X\n", addr, val);
+ Log(LogLevel::Warn, "NWIFI: unknown func1 write %05X %02X\n", addr, val);
}
@@ -591,7 +594,7 @@ u8 DSi_NWifi::SDIO_Read(u32 func, u32 addr)
case 1: return F1_Read(addr);
}
- printf("NWIFI: unknown SDIO read %d %05X\n", func, addr);
+ Log(LogLevel::Warn, "NWIFI: unknown SDIO read %d %05X\n", func, addr);
return 0;
}
@@ -603,7 +606,7 @@ void DSi_NWifi::SDIO_Write(u32 func, u32 addr, u8 val)
case 1: return F1_Write(addr, val);
}
- printf("NWIFI: unknown SDIO write %d %05X %02X\n", func, addr, val);
+ Log(LogLevel::Warn, "NWIFI: unknown SDIO write %d %05X %02X\n", func, addr, val);
}
@@ -676,12 +679,12 @@ void DSi_NWifi::SendCMD(u8 cmd, u32 param)
return;
}
- printf("NWIFI: unknown CMD %d %08X\n", cmd, param);
+ Log(LogLevel::Warn, "NWIFI: unknown CMD %d %08X\n", cmd, param);
}
void DSi_NWifi::SendACMD(u8 cmd, u32 param)
{
- printf("NWIFI: unknown ACMD %d %08X\n", cmd, param);
+ Log(LogLevel::Warn, "NWIFI: unknown ACMD %d %08X\n", cmd, param);
}
void DSi_NWifi::ContinueTransfer()
@@ -772,7 +775,7 @@ void DSi_NWifi::BMI_Command()
{
case 0x01: // BMI_DONE
{
- printf("BMI_DONE\n");
+ Log(LogLevel::Debug, "BMI_DONE\n");
EEPROMReady = 1; // GROSS FUCKING HACK
u8 ready_msg[6] = {0x0A, 0x00, 0x08, 0x06, 0x16, 0x00};
SendWMIEvent(0, 0x0001, ready_msg, 6);
@@ -784,7 +787,7 @@ void DSi_NWifi::BMI_Command()
{
u32 addr = MB_Read32(0);
u32 len = MB_Read32(0);
- printf("BMI mem write %08X %08X\n", addr, len);
+ Log(LogLevel::Debug, "BMI mem write %08X %08X\n", addr, len);
for (u32 i = 0; i < len; i++)
{
@@ -800,7 +803,7 @@ void DSi_NWifi::BMI_Command()
u32 entry = MB_Read32(0);
u32 arg = MB_Read32(0);
- printf("BMI_EXECUTE %08X %08X\n", entry, arg);
+ Log(LogLevel::Debug, "BMI_EXECUTE %08X %08X\n", entry, arg);
}
return;
@@ -830,14 +833,14 @@ void DSi_NWifi::BMI_Command()
case 0x0D: // BMI_LZ_STREAM_START
{
u32 addr = MB_Read32(0);
- printf("BMI_LZ_STREAM_START %08X\n", addr);
+ Log(LogLevel::Debug, "BMI_LZ_STREAM_START %08X\n", addr);
}
return;
case 0x0E: // BMI_LZ_DATA
{
u32 len = MB_Read32(0);
- printf("BMI LZ write %08X\n", len);
+ Log(LogLevel::Debug, "BMI LZ write %08X\n", len);
//FILE* f = fopen("debug/wififirm.bin", "ab");
for (u32 i = 0; i < len; i++)
@@ -852,7 +855,7 @@ void DSi_NWifi::BMI_Command()
return;
default:
- printf("unknown BMI command %08X\n", cmd);
+ Log(LogLevel::Warn, "unknown BMI command %08X\n", cmd);
return;
}
}
@@ -871,7 +874,7 @@ void DSi_NWifi::HTC_Command()
{
u16 svc_id = MB_Read16(0);
u16 conn_flags = MB_Read16(0);
- printf("service connect %04X %04X %04X\n", svc_id, conn_flags, MB_Read16(0));
+ Log(LogLevel::Info, "service connect %04X %04X %04X\n", svc_id, conn_flags, MB_Read16(0));
u8 svc_resp[8];
// responses from hardware:
@@ -908,7 +911,7 @@ void DSi_NWifi::HTC_Command()
break;
default:
- printf("unknown HTC command %04X\n", cmd);
+ Log(LogLevel::Warn, "unknown HTC command %04X\n", cmd);
for (int i = 0; i < len; i++)
{
printf("%02X ", Mailbox[0].Read());
@@ -947,9 +950,9 @@ void DSi_NWifi::WMI_Command()
case 0x0003: // disconnect
{
if (ConnectionStatus != 1)
- printf("WMI: ?? trying to disconnect while not connected\n");
+ Log(LogLevel::Warn, "WMI: ?? trying to disconnect while not connected\n");
- printf("WMI: disconnect\n");
+ Log(LogLevel::Info, "WMI: disconnect\n");
ConnectionStatus = 0;
u8 reply[11];
@@ -985,12 +988,12 @@ void DSi_NWifi::WMI_Command()
u8 scantype = Mailbox[0].Read();
u8 nchannels = Mailbox[0].Read();
- printf("WMI: start scan, forceFG=%d, legacy=%d, scanTime=%d, interval=%d, scanType=%d, chan=%d\n",
+ Log(LogLevel::Debug, "WMI: start scan, forceFG=%d, legacy=%d, scanTime=%d, interval=%d, scanType=%d, chan=%d\n",
forcefg, legacy, scantime, forceinterval, scantype, nchannels);
if (ScanTimer > 0)
{
- printf("!! CHECKME: START SCAN BUT WAS ALREADY SCANNING (%d)\n", ScanTimer);
+ Log(LogLevel::Debug, "!! CHECKME: START SCAN BUT WAS ALREADY SCANNING (%d)\n", ScanTimer);
}
// checkme
@@ -1013,7 +1016,7 @@ void DSi_NWifi::WMI_Command()
Mailbox[0].Read();
u32 iemask = MB_Read32(0);
- printf("WMI: set BSS filter, filter=%02X, iemask=%08X\n", bssfilter, iemask);
+ Log(LogLevel::Debug, "WMI: set BSS filter, filter=%02X, iemask=%08X\n", bssfilter, iemask);
}
break;
@@ -1028,7 +1031,7 @@ void DSi_NWifi::WMI_Command()
ssid[i] = Mailbox[0].Read();
// TODO: store it somewhere
- printf("WMI: set probed SSID: id=%d, flags=%02X, len=%d, SSID=%s\n", id, flags, len, ssid);
+ Log(LogLevel::Debug, "WMI: set probed SSID: id=%d, flags=%02X, len=%d, SSID=%s\n", id, flags, len, ssid);
}
break;
@@ -1066,7 +1069,7 @@ void DSi_NWifi::WMI_Command()
channels[i] = MB_Read16(0);
// TODO: store it somewhere
- printf("WMI: set channel params: scan=%d, phymode=%d, len=%d, channels=", scan, phymode, len);
+ Log(LogLevel::Debug, "WMI: set channel params: scan=%d, phymode=%d, len=%d, channels=", scan, phymode, len);
for (int i = 0; i < len && i < 32; i++)
printf("%d,", channels[i]);
printf("\n");
@@ -1110,7 +1113,7 @@ void DSi_NWifi::WMI_Command()
break;
default:
- printf("WMI: unknown ext cmd 002E:%04X\n", extcmd);
+ Log(LogLevel::Warn, "WMI: unknown ext cmd 002E:%04X\n", extcmd);
break;
}
}
@@ -1161,7 +1164,7 @@ void DSi_NWifi::WMI_Command()
break;
default:
- printf("unknown WMI command %04X (header: %04X:%04X:%04X)\n", cmd, h0, len, h2);
+ Log(LogLevel::Warn, "unknown WMI command %04X (header: %04X:%04X:%04X)\n", cmd, h0, len, h2);
for (int i = 0; i < len-2; i++)
{
printf("%02X ", Mailbox[0].Read());
@@ -1210,12 +1213,12 @@ void DSi_NWifi::WMI_ConnectToNetwork()
(gCryptoType != 0x01) ||
(memcmp(bssid, WifiAP::APMac, 6)))
{
- printf("WMI_Connect: bad parameters\n");
+ Log(LogLevel::Error, "WMI_Connect: bad parameters\n");
// TODO: send disconnect??
return;
}
- printf("WMI: connecting to network %s\n", ssid);
+ Log(LogLevel::Info, "WMI: connecting to network %s\n", ssid);
u8 reply[20];
@@ -1240,7 +1243,7 @@ void DSi_NWifi::WMI_SendPacket(u16 len)
{
if (ConnectionStatus != 1)
{
- printf("WMI: !! trying to send shit while not connected\n");
+ Log(LogLevel::Warn, "WMI: !! trying to send shit while not connected\n");
// TODO: report error??
return;
}
@@ -1255,7 +1258,7 @@ void DSi_NWifi::WMI_SendPacket(u16 len)
if (type == 2) // data sync
{
- printf("WMI: data sync\n");
+ Log(LogLevel::Debug, "WMI: data sync\n");
/*Mailbox[8].Write(2); // eid
Mailbox[8].Write(0x00); // flags
@@ -1270,7 +1273,7 @@ void DSi_NWifi::WMI_SendPacket(u16 len)
if (type)
{
- printf("WMI: special frame %04X len=%d\n", hdr, len);
+ Log(LogLevel::Debug, "WMI: special frame %04X len=%d\n", hdr, len);
for (int i = 0; i < len-2; i++)
{
printf("%02X ", Mailbox[0].Read());
@@ -1280,7 +1283,7 @@ void DSi_NWifi::WMI_SendPacket(u16 len)
return;
}
- printf("WMI: send packet, hdr=%04X, len=%d\n", hdr, len);
+ Log(LogLevel::Debug, "WMI: send packet, hdr=%04X, len=%d\n", hdr, len);
u8 dstmac[6];
u8 srcmac[6];
@@ -1295,7 +1298,7 @@ void DSi_NWifi::WMI_SendPacket(u16 len)
if (plen > len-16)
{
- printf("WMI: bad packet length %d > %d\n", plen, len-16);
+ Log(LogLevel::Error, "WMI: bad packet length %d > %d\n", plen, len-16);
return;
}
@@ -1304,7 +1307,7 @@ void DSi_NWifi::WMI_SendPacket(u16 len)
if (h0 != 0x0003AAAA || h1 != 0x0000)
{
- printf("WMI: bad LLC/SLIP header\n");
+ Log(LogLevel::Error, "WMI: bad LLC/SLIP header\n");
return;
}
@@ -1334,7 +1337,7 @@ void DSi_NWifi::SendWMIEvent(u8 ep, u16 id, u8* data, u32 len)
{
if (!Mailbox[8].CanFit(6+len+2+8))
{
- printf("NWifi: !! not enough space in RX buffer for WMI event %04X\n", id);
+ Log(LogLevel::Error, "NWifi: !! not enough space in RX buffer for WMI event %04X\n", id);
return;
}
@@ -1367,7 +1370,7 @@ void DSi_NWifi::SendWMIAck(u8 ep)
{
if (!Mailbox[8].CanFit(6+12))
{
- printf("NWifi: !! not enough space in RX buffer for WMI ack (ep #%d)\n", ep);
+ Log(LogLevel::Error, "NWifi: !! not enough space in RX buffer for WMI ack (ep #%d)\n", ep);
return;
}
@@ -1400,7 +1403,7 @@ void DSi_NWifi::SendWMIBSSInfo(u8 type, u8* data, u32 len)
{
if (!Mailbox[8].CanFit(6+len+2+16))
{
- printf("NWifi: !! not enough space in RX buffer for WMI BSSINFO event\n");
+ Log(LogLevel::Error, "NWifi: !! not enough space in RX buffer for WMI BSSINFO event\n");
return;
}
@@ -1452,7 +1455,7 @@ void DSi_NWifi::CheckRX()
// packet is good
- printf("WMI: receive packet %04X, len=%d\n", *(u16*)&LANBuffer[12], rxlen);
+ Log(LogLevel::Debug, "WMI: receive packet %04X, len=%d\n", *(u16*)&LANBuffer[12], rxlen);
/*for (int i = 0; i < rxlen; i++)
{
@@ -1501,7 +1504,7 @@ void DSi_NWifi::CheckRX()
u32 DSi_NWifi::WindowRead(u32 addr)
{
- printf("NWifi: window read %08X\n", addr);
+ Log(LogLevel::Debug, "NWifi: window read %08X\n", addr);
if ((addr & 0xFFFF00) == HostIntAddr)
{
@@ -1540,7 +1543,7 @@ u32 DSi_NWifi::WindowRead(u32 addr)
void DSi_NWifi::WindowWrite(u32 addr, u32 val)
{
- printf("NWifi: window write %08X %08X\n", addr, val);
+ Log(LogLevel::Debug, "NWifi: window write %08X %08X\n", addr, val);
}
@@ -1567,7 +1570,7 @@ void DSi_NWifi::_MSTimer()
};
SendWMIBSSInfo(0x01, beacon, sizeof(beacon));
- printf("send beacon\n");
+ Log(LogLevel::Debug, "send beacon\n");
}
if (ScanTimer == 0)
diff --git a/src/DSi_SD.cpp b/src/DSi_SD.cpp
index e603347..f329437 100644
--- a/src/DSi_SD.cpp
+++ b/src/DSi_SD.cpp
@@ -23,6 +23,8 @@
#include "DSi_NWifi.h"
#include "Platform.h"
+using Platform::Log;
+using Platform::LogLevel;
// observed IRQ behavior during transfers
//
@@ -294,7 +296,7 @@ void DSi_SDHost::FinishRX(u32 param)
u32 DSi_SDHost::DataRX(u8* data, u32 len)
{
- if (len != BlockLen16) { printf("!! BAD BLOCKLEN\n"); len = BlockLen16; }
+ if (len != BlockLen16) { Log(LogLevel::Warn, "!! BAD BLOCKLEN\n"); len = BlockLen16; }
bool last = (BlockCountInternal == 0);
@@ -360,7 +362,7 @@ u32 DSi_SDHost::DataTX(u8* data, u32 len)
// drain FIFO32 into FIFO16
- if (!DataFIFO[f].IsEmpty()) printf("VERY BAD!! TRYING TO DRAIN FIFO32 INTO FIFO16 BUT IT CONTAINS SHIT ALREADY\n");
+ if (!DataFIFO[f].IsEmpty()) Log(LogLevel::Warn, "VERY BAD!! TRYING TO DRAIN FIFO32 INTO FIFO16 BUT IT CONTAINS SHIT ALREADY\n");
for (;;)
{
u32 f = CurFIFO;
@@ -523,7 +525,7 @@ u16 DSi_SDHost::Read(u32 addr)
case 0x10A: return 0;
}
- printf("unknown %s read %08X @ %08X\n", SD_DESC, addr, NDS::GetPC(1));
+ Log(LogLevel::Warn, "unknown %s read %08X @ %08X\n", SD_DESC, addr, NDS::GetPC(1));
return 0;
}
@@ -591,11 +593,11 @@ void DSi_SDHost::Write(u32 addr, u16 val)
case 0: dev->SendCMD(cmd, Param); break;
case 1: /*dev->SendCMD(55, 0);*/ dev->SendCMD(cmd, Param); break;
default:
- printf("%s: unknown command type %d, %02X %08X\n", SD_DESC, (Command>>6)&0x3, cmd, Param);
+ Log(LogLevel::Warn, "%s: unknown command type %d, %02X %08X\n", SD_DESC, (Command>>6)&0x3, cmd, Param);
break;
}
}
- else printf("%s: SENDING CMD %04X TO NULL DEVICE\n", SD_DESC, val);
+ else Log(LogLevel::Debug, "%s: SENDING CMD %04X TO NULL DEVICE\n", SD_DESC, val);
}
return;
@@ -659,7 +661,7 @@ void DSi_SDHost::Write(u32 addr, u16 val)
case 0x0E0:
if ((SoftReset & 0x0001) && !(val & 0x0001))
{
- printf("%s: RESET\n", SD_DESC);
+ Log(LogLevel::Debug, "%s: RESET\n", SD_DESC);
StopAction = 0;
memset(ResponseBuffer, 0, sizeof(ResponseBuffer));
IRQStatus = 0;
@@ -689,7 +691,7 @@ void DSi_SDHost::Write(u32 addr, u16 val)
case 0x10A: return;
}
- printf("unknown %s write %08X %04X\n", SD_DESC, addr, val);
+ Log(LogLevel::Warn, "unknown %s write %08X %04X\n", SD_DESC, addr, val);
}
void DSi_SDHost::WriteFIFO16(u16 val)
@@ -699,7 +701,7 @@ void DSi_SDHost::WriteFIFO16(u16 val)
if (DataFIFO[f].IsFull())
{
// TODO
- printf("!!!! %s FIFO (16) FULL\n", SD_DESC);
+ Log(LogLevel::Error, "!!!! %s FIFO (16) FULL\n", SD_DESC);
return;
}
@@ -715,7 +717,7 @@ void DSi_SDHost::WriteFIFO32(u32 val)
if (DataFIFO32.IsFull())
{
// TODO
- printf("!!!! %s FIFO (32) FULL\n", SD_DESC);
+ Log(LogLevel::Error, "!!!! %s FIFO (32) FULL\n", SD_DESC);
return;
}
@@ -732,7 +734,7 @@ void DSi_SDHost::UpdateFIFO32()
if (DataMode != 1) return;
- if (!DataFIFO32.IsEmpty()) printf("VERY BAD!! TRYING TO DRAIN FIFO16 INTO FIFO32 BUT IT CONTAINS SHIT ALREADY\n");
+ if (!DataFIFO32.IsEmpty()) Log(LogLevel::Warn, "VERY BAD!! TRYING TO DRAIN FIFO16 INTO FIFO32 BUT IT CONTAINS SHIT ALREADY\n");
for (;;)
{
u32 f = CurFIFO;
@@ -875,7 +877,7 @@ void DSi_MMCStorage::SendCMD(u8 cmd, u32 param)
}
else
{
- printf("CMD1 on SD card!!\n");
+ Log(LogLevel::Debug, "CMD1 on SD card!!\n");
}
return;
@@ -897,7 +899,7 @@ void DSi_MMCStorage::SendCMD(u8 cmd, u32 param)
else
{
// TODO
- printf("CMD3 on SD card: TODO\n");
+ Log(LogLevel::Debug, "CMD3 on SD card: TODO\n");
Host->SendResponse((CSR & 0x1FFF) | ((CSR >> 6) & 0x2000) | ((CSR >> 8) & 0xC000) | (1 << 16), true);
}
return;
@@ -938,7 +940,7 @@ void DSi_MMCStorage::SendCMD(u8 cmd, u32 param)
if (BlockSize > 0x200)
{
// TODO! raise error
- printf("!! SD/MMC: BAD BLOCK LEN %d\n", BlockSize);
+ Log(LogLevel::Warn, "!! SD/MMC: BAD BLOCK LEN %d\n", BlockSize);
BlockSize = 0x200;
}
SetState(0x04); // CHECKME
@@ -979,7 +981,7 @@ void DSi_MMCStorage::SendCMD(u8 cmd, u32 param)
return;
}
- printf("MMC: unknown CMD %d %08X\n", cmd, param);
+ Log(LogLevel::Warn, "MMC: unknown CMD %d %08X\n", cmd, param);
}
void DSi_MMCStorage::SendACMD(u8 cmd, u32 param)
@@ -1018,7 +1020,7 @@ void DSi_MMCStorage::SendACMD(u8 cmd, u32 param)
return;
}
- printf("MMC: unknown ACMD %d %08X\n", cmd, param);
+ Log(LogLevel::Warn, "MMC: unknown ACMD %d %08X\n", cmd, param);
}
void DSi_MMCStorage::ContinueTransfer()
diff --git a/src/DSi_SPI_TSC.cpp b/src/DSi_SPI_TSC.cpp
index 73d792b..c690f9c 100644
--- a/src/DSi_SPI_TSC.cpp
+++ b/src/DSi_SPI_TSC.cpp
@@ -21,7 +21,10 @@
#include "DSi.h"
#include "SPI.h"
#include "DSi_SPI_TSC.h"
+#include "Platform.h"
+using Platform::Log;
+using Platform::LogLevel;
namespace DSi_SPI_TSC
{
@@ -214,7 +217,7 @@ void Write(u8 val, u32 hold)
TSCMode = val;
if (TSCMode == 0x00)
{
- printf("DSi_SPI_TSC: DS-compatibility mode\n");
+ Log(LogLevel::Debug, "DSi_SPI_TSC: DS-compatibility mode\n");
DataPos = 0;
NDS::KeyInput |= (1 << (16+6));
return;
@@ -224,7 +227,7 @@ void Write(u8 val, u32 hold)
}
else
{
- printf("DSi_SPI_TSC: unknown IO, bank=%02X, index=%02X (%02X %s)\n", Bank, Index, Index>>1, (Index&1)?"read":"write");
+ Log(LogLevel::Debug, "DSi_SPI_TSC: unknown IO, bank=%02X, index=%02X (%02X %s)\n", Bank, Index, Index>>1, (Index&1)?"read":"write");
}
Index += (1<<1); // increment index
diff --git a/src/GBACart.cpp b/src/GBACart.cpp
index 68507bc..3f42326 100644
--- a/src/GBACart.cpp
+++ b/src/GBACart.cpp
@@ -23,6 +23,8 @@
#include "CRC32.h"
#include "Platform.h"
+using Platform::Log;
+using Platform::LogLevel;
namespace GBACart
{
@@ -210,7 +212,7 @@ void CartGame::SetupSave(u32 type)
SRAMType = S_NULL;
break;
default:
- printf("!! BAD GBA SAVE LENGTH %d\n", SRAMLength);
+ Log(LogLevel::Warn, "!! BAD GBA SAVE LENGTH %d\n", SRAMLength);
}
if (SRAMType == S_FLASH512K)
@@ -283,7 +285,7 @@ void CartGame::ROMWrite(u32 addr, u16 val)
break;
default:
- printf("Unknown GBA GPIO write 0x%02X @ 0x%04X\n", val, addr);
+ Log(LogLevel::Warn, "Unknown GBA GPIO write 0x%02X @ 0x%04X\n", val, addr);
break;
}
}
@@ -369,7 +371,7 @@ u8 CartGame::SRAMRead_FLASH(u32 addr)
case 0xB0: // bank switching (128K only)
break; // ignore here, handled in Write_Flash()
default:
- printf("GBACart_SRAM::Read_Flash: unknown command 0x%02X @ 0x%04X\n", SRAMFlashState.cmd, addr);
+ Log(LogLevel::Warn, "GBACart_SRAM::Read_Flash: unknown command 0x%02X @ 0x%04X\n", SRAMFlashState.cmd, addr);
break;
}
@@ -502,7 +504,7 @@ void CartGame::SRAMWrite_FLASH(u32 addr, u8 val)
return;
}
- printf("GBACart_SRAM::Write_Flash: unknown write 0x%02X @ 0x%04X (state: 0x%02X)\n",
+ Log(LogLevel::Warn, "GBACart_SRAM::Write_Flash: unknown write 0x%02X @ 0x%04X (state: 0x%02X)\n",
val, addr, SRAMFlashState.state);
}
@@ -586,7 +588,7 @@ void CartGameSolarSensor::ProcessGPIO()
u8 prev = LightSample;
LightCounter = 0;
LightSample = (0xFF - (0x16 + kLuxLevels[LightLevel]));
- printf("Solar sensor reset (sample: 0x%02X -> 0x%02X)\n", prev, LightSample);
+ Log(LogLevel::Debug, "Solar sensor reset (sample: 0x%02X -> 0x%02X)\n", prev, LightSample);
}
if (GPIO.data & 1 && LightEdge) LightCounter++;
@@ -750,7 +752,7 @@ bool LoadROM(const u8* romdata, u32 romlen)
}
catch (const std::bad_alloc& e)
{
- printf("GBACart: failed to allocate memory for ROM (%d bytes)\n", CartROMSize);
+ Log(LogLevel::Error, "GBACart: failed to allocate memory for ROM (%d bytes)\n", CartROMSize);
return false;
}
@@ -759,7 +761,7 @@ bool LoadROM(const u8* romdata, u32 romlen)
char gamecode[5] = { '\0' };
memcpy(&gamecode, CartROM + 0xAC, 4);
- printf("GBA game code: %s\n", gamecode);
+ Log(LogLevel::Info, "GBA game code: %s\n", gamecode);
bool solarsensor = false;
for (size_t i = 0; i < sizeof(SOLAR_SENSOR_GAMECODES)/sizeof(SOLAR_SENSOR_GAMECODES[0]); i++)
@@ -770,7 +772,7 @@ bool LoadROM(const u8* romdata, u32 romlen)
if (solarsensor)
{
- printf("GBA solar sensor support detected!\n");
+ Log(LogLevel::Info, "GBA solar sensor support detected!\n");
}
CartInserted = true;
@@ -817,7 +819,7 @@ void LoadAddon(int type)
break;
default:
- printf("GBACart: !! invalid addon type %d\n", type);
+ Log(LogLevel::Warn, "GBACart: !! invalid addon type %d\n", type);
return;
}
diff --git a/src/GPU.cpp b/src/GPU.cpp
index f54d771..f51748b 100644
--- a/src/GPU.cpp
+++ b/src/GPU.cpp
@@ -16,7 +16,6 @@
with melonDS. If not, see http://www.gnu.org/licenses/.
*/
-#include <stdio.h>
#include <string.h>
#include "NDS.h"
#include "GPU.h"
@@ -27,6 +26,9 @@
#include "GPU2D_Soft.h"
+using Platform::Log;
+using Platform::LogLevel;
+
namespace GPU
{
@@ -987,7 +989,7 @@ void SetPowerCnt(u32 val)
// * bit9: disables engine B palette, OAM and rendering (screen turns white)
// * bit15: screen swap
- if (!(val & (1<<0))) printf("!!! CLEARING POWCNT BIT0. DANGER\n");
+ if (!(val & (1<<0))) Log(LogLevel::Warn, "!!! CLEARING POWCNT BIT0. DANGER\n");
GPU2D_A.SetEnabled(val & (1<<1));
GPU2D_B.SetEnabled(val & (1<<9));
diff --git a/src/GPU2D.cpp b/src/GPU2D.cpp
index eda3e32..9d616d3 100644
--- a/src/GPU2D.cpp
+++ b/src/GPU2D.cpp
@@ -21,6 +21,8 @@
#include "NDS.h"
#include "GPU.h"
+using Platform::Log;
+using Platform::LogLevel;
// notes on color conversion
//
@@ -218,7 +220,7 @@ u8 Unit::Read8(u32 addr)
case 0x04D: return 0;
}
- printf("unknown GPU read8 %08X\n", addr);
+ Log(LogLevel::Warn, "unknown GPU read8 %08X\n", addr);
return 0;
}
@@ -247,7 +249,7 @@ u16 Unit::Read16(u32 addr)
case 0x06C: return MasterBrightness;
}
- printf("unknown GPU read16 %08X\n", addr);
+ Log(LogLevel::Warn, "unknown GPU read16 %08X\n", addr);
return 0;
}
@@ -364,7 +366,7 @@ void Unit::Write8(u32 addr, u8 val)
return;
}
- printf("unknown GPU write8 %08X %02X\n", addr, val);
+ Log(LogLevel::Warn, "unknown GPU write8 %08X %02X\n", addr, val);
}
void Unit::Write16(u32 addr, u16 val)
diff --git a/src/GPU3D.cpp b/src/GPU3D.cpp
index b4b9eb2..5c48575 100644
--- a/src/GPU3D.cpp
+++ b/src/GPU3D.cpp
@@ -22,7 +22,10 @@
#include "NDS.h"
#include "GPU.h"
#include "FIFO.h"
+#include "Platform.h"
+using Platform::Log;
+using Platform::LogLevel;
// 3D engine notes
//
@@ -2724,7 +2727,7 @@ u8 Read8(u32 addr)
}
}
- printf("unknown GPU3D read8 %08X\n", addr);
+ Log(LogLevel::Warn, "unknown GPU3D read8 %08X\n", addr);
return 0;
}
@@ -2768,7 +2771,7 @@ u16 Read16(u32 addr)
case 0x04000634: return VecTestResult[2];
}
- printf("unknown GPU3D read16 %08X\n", addr);
+ Log(LogLevel::Warn, "unknown GPU3D read16 %08X\n", addr);
return 0;
}
@@ -2872,7 +2875,7 @@ void Write8(u32 addr, u8 val)
return;
}
- printf("unknown GPU3D write8 %08X %02X\n", addr, val);
+ Log(LogLevel::Warn, "unknown GPU3D write8 %08X %02X\n", addr, val);
}
void Write16(u32 addr, u16 val)
@@ -2959,7 +2962,7 @@ void Write16(u32 addr, u16 val)
return;
}
- printf("unknown GPU3D write16 %08X %04X\n", addr, val);
+ Log(LogLevel::Warn, "unknown GPU3D write16 %08X %04X\n", addr, val);
}
void Write32(u32 addr, u32 val)
@@ -3056,7 +3059,7 @@ void Write32(u32 addr, u32 val)
return;
}
- printf("unknown GPU3D write32 %08X %08X\n", addr, val);
+ Log(LogLevel::Warn, "unknown GPU3D write32 %08X %08X\n", addr, val);
}
Renderer3D::Renderer3D(bool Accelerated)
diff --git a/src/NDS.cpp b/src/NDS.cpp
index 50827ef..215750f 100644
--- a/src/NDS.cpp
+++ b/src/NDS.cpp
@@ -45,6 +45,8 @@
#include "DSi_Camera.h"
#include "DSi_DSP.h"
+using Platform::Log;
+using Platform::LogLevel;
namespace NDS
{
@@ -524,7 +526,7 @@ void Reset()
f = Platform::OpenLocalFile(Platform::GetConfigString(Platform::BIOS9Path), "rb");
if (!f)
{
- printf("ARM9 BIOS not found\n");
+ Log(LogLevel::Warn, "ARM9 BIOS not found\n");
for (i = 0; i < 16; i++)
((u32*)ARM9BIOS)[i] = 0xE7FFDEFF;
@@ -534,14 +536,14 @@ void Reset()
fseek(f, 0, SEEK_SET);
fread(ARM9BIOS, 0x1000, 1, f);
- printf("ARM9 BIOS loaded\n");
+ Log(LogLevel::Info, "ARM9 BIOS loaded\n");
fclose(f);
}
f = Platform::OpenLocalFile(Platform::GetConfigString(Platform::BIOS7Path), "rb");
if (!f)
{
- printf("ARM7 BIOS not found\n");
+ Log(LogLevel::Warn, "ARM7 BIOS not found\n");
for (i = 0; i < 16; i++)
((u32*)ARM7BIOS)[i] = 0xE7FFDEFF;
@@ -551,7 +553,7 @@ void Reset()
fseek(f, 0, SEEK_SET);
fread(ARM7BIOS, 0x4000, 1, f);
- printf("ARM7 BIOS loaded\n");
+ Log(LogLevel::Info, "ARM7 BIOS loaded\n");
fclose(f);
}
}
@@ -690,7 +692,7 @@ void Start()
void Stop()
{
- printf("Stopping: shutdown\n");
+ Log(LogLevel::Info, "Stopping: shutdown\n");
Running = false;
Platform::StopEmu();
GPU::Stop();
@@ -755,7 +757,7 @@ bool DoSavestate_Scheduler(Savestate* file)
}
if (funcid == 0xFFFFFFFF)
{
- printf("savestate: VERY BAD!!!!! FUNCTION POINTER FOR EVENT %d NOT IN HACKY LIST. CANNOT SAVE. SMACK ARISOTURA.\n", i);
+ Log(LogLevel::Error, "savestate: VERY BAD!!!!! FUNCTION POINTER FOR EVENT %d NOT IN HACKY LIST. CANNOT SAVE. SMACK ARISOTURA.\n", i);
return false;
}
}
@@ -780,7 +782,7 @@ bool DoSavestate_Scheduler(Savestate* file)
{
if (!eventfuncs[j])
{
- printf("savestate: VERY BAD!!!!!! EVENT FUNCTION POINTER ID %d IS OUT OF RANGE. HAX?????\n", j);
+ Log(LogLevel::Error, "savestate: VERY BAD!!!!!! EVENT FUNCTION POINTER ID %d IS OUT OF RANGE. HAX?????\n", j);
return false;
}
if (j == funcid) break;
@@ -1128,7 +1130,7 @@ u32 RunFrame()
}
#ifdef DEBUG_CHECK_DESYNC
- printf("[%08X%08X] ARM9=%ld, ARM7=%ld, GPU=%ld\n",
+ Log(LogLevel::Debug, "[%08X%08X] ARM9=%ld, ARM7=%ld, GPU=%ld\n",
(u32)(SysTimestamp>>32), (u32)SysTimestamp,
(ARM9Timestamp>>1)-SysTimestamp,
ARM7Timestamp-SysTimestamp,
@@ -1181,7 +1183,7 @@ void ScheduleEvent(u32 id, bool periodic, s32 delay, void (*func)(u32), u32 para
{
if (SchedListMask & (1<<id))
{
- printf("!! EVENT %d ALREADY SCHEDULED\n", id);
+ Log(LogLevel::Debug, "!! EVENT %d ALREADY SCHEDULED\n", id);
return;
}
@@ -1209,7 +1211,7 @@ void ScheduleEvent(u32 id, u64 timestamp, void (*func)(u32), u32 param)
{
if (SchedListMask & (1<<id))
{
- printf("!! EVENT %d ALREADY SCHEDULED\n", id);
+ Log(LogLevel::Debug, "!! EVENT %d ALREADY SCHEDULED\n", id);
return;
}
@@ -1315,7 +1317,7 @@ void MicInputFrame(s16* data, int samples)
void Halt()
{
- printf("Halt()\n");
+ Log(LogLevel::Info, "Halt()\n");
Running = false;
}
@@ -1645,7 +1647,7 @@ void NocashPrint(u32 ncpu, u32 addr)
}
output[ptr] = '\0';
- printf("%s", output);
+ Log(LogLevel::Debug, "%s", output);
}
@@ -1659,7 +1661,7 @@ void MonitorARM9Jump(u32 addr)
{
if (addr == *(u32*)&NDSCart::CartROM[0x24])
{
- printf("Game is now booting\n");
+ Log(LogLevel::Info, "Game is now booting\n");
RunningGame = true;
}
}
@@ -1987,11 +1989,11 @@ void StartSqrt()
void debug(u32 param)
{
- printf("ARM9 PC=%08X LR=%08X %08X\n", ARM9->R[15], ARM9->R[14], ARM9->R_IRQ[1]);
- printf("ARM7 PC=%08X LR=%08X %08X\n", ARM7->R[15], ARM7->R[14], ARM7->R_IRQ[1]);
+ Log(LogLevel::Debug, "ARM9 PC=%08X LR=%08X %08X\n", ARM9->R[15], ARM9->R[14], ARM9->R_IRQ[1]);
+ Log(LogLevel::Debug, "ARM7 PC=%08X LR=%08X %08X\n", ARM7->R[15], ARM7->R[14], ARM7->R_IRQ[1]);
- printf("ARM9 IME=%08X IE=%08X IF=%08X\n", IME[0], IE[0], IF[0]);
- printf("ARM7 IME=%08X IE=%08X IF=%08X IE2=%04X IF2=%04X\n", IME[1], IE[1], IF[1], IE2, IF2);
+ Log(LogLevel::Debug, "ARM9 IME=%08X IE=%08X IF=%08X\n", IME[0], IE[0], IF[0]);
+ Log(LogLevel::Debug, "ARM7 IME=%08X IE=%08X IF=%08X IE2=%04X IF2=%04X\n", IME[1], IE[1], IF[1], IE2, IF2);
//for (int i = 0; i < 9; i++)
// printf("VRAM %c: %02X\n", 'A'+i, GPU::VRAMCNT[i]);
@@ -2089,7 +2091,7 @@ u8 ARM9Read8(u32 addr)
return GBACart::SRAMRead(addr);
}
- printf("unknown arm9 read8 %08X\n", addr);
+ Log(LogLevel::Warn, "unknown arm9 read8 %08X\n", addr);
return 0;
}
@@ -2149,7 +2151,7 @@ u16 ARM9Read16(u32 addr)
(GBACart::SRAMRead(addr+1) << 8);
}
- //if (addr) printf("unknown arm9 read16 %08X %08X\n", addr, ARM9->R[15]);
+ //if (addr) Log(LogLevel::Warn, "unknown arm9 read16 %08X %08X\n", addr, ARM9->R[15]);
return 0;
}
@@ -2212,7 +2214,7 @@ u32 ARM9Read32(u32 addr)
(GBACart::SRAMRead(addr+3) << 24);
}
- //printf("unknown arm9 read32 %08X | %08X %08X\n", addr, ARM9->R[15], ARM9->R[12]);
+ //Log(LogLevel::Warn, "unknown arm9 read32 %08X | %08X %08X\n", addr, ARM9->R[15], ARM9->R[12]);
return 0;
}
@@ -2256,7 +2258,7 @@ void ARM9Write8(u32 addr, u8 val)
return;
}
- printf("unknown arm9 write8 %08X %02X\n", addr, val);
+ Log(LogLevel::Warn, "unknown arm9 write8 %08X %02X\n", addr, val);
}
void ARM9Write16(u32 addr, u16 val)
@@ -2322,7 +2324,7 @@ void ARM9Write16(u32 addr, u16 val)
return;
}
- //if (addr) printf("unknown arm9 write16 %08X %04X\n", addr, val);
+ //if (addr) Log(LogLevel::Warn, "unknown arm9 write16 %08X %04X\n", addr, val);
}
void ARM9Write32(u32 addr, u32 val)
@@ -2391,7 +2393,7 @@ void ARM9Write32(u32 addr, u32 val)
return;
}
- //printf("unknown arm9 write32 %08X %08X | %08X\n", addr, val, ARM9->R[15]);
+ //Log(LogLevel::Warn, "unknown arm9 write32 %08X %08X | %08X\n", addr, val, ARM9->R[15]);
}
bool ARM9GetMemRegion(u32 addr, bool write, MemRegion* region)
@@ -2488,7 +2490,7 @@ u8 ARM7Read8(u32 addr)
return GBACart::SRAMRead(addr);
}
- printf("unknown arm7 read8 %08X %08X %08X/%08X\n", addr, ARM7->R[15], ARM7->R[0], ARM7->R[1]);
+ Log(LogLevel::Warn, "unknown arm7 read8 %08X %08X %08X/%08X\n", addr, ARM7->R[15], ARM7->R[0], ARM7->R[1]);
return 0;
}
@@ -2554,7 +2556,7 @@ u16 ARM7Read16(u32 addr)
(GBACart::SRAMRead(addr+1) << 8);
}
- printf("unknown arm7 read16 %08X %08X\n", addr, ARM7->R[15]);
+ Log(LogLevel::Warn, "unknown arm7 read16 %08X %08X\n", addr, ARM7->R[15]);
return 0;
}
@@ -2623,7 +2625,7 @@ u32 ARM7Read32(u32 addr)
(GBACart::SRAMRead(addr+3) << 24);
}
- //printf("unknown arm7 read32 %08X | %08X\n", addr, ARM7->R[15]);
+ //Log(LogLevel::Warn, "unknown arm7 read32 %08X | %08X\n", addr, ARM7->R[15]);
return 0;
}
@@ -2691,7 +2693,7 @@ void ARM7Write8(u32 addr, u8 val)
//if (ARM7->R[15] > 0x00002F30) // ARM7 BIOS bug
if (addr >= 0x01000000)
- printf("unknown arm7 write8 %08X %02X @ %08X\n", addr, val, ARM7->R[15]);
+ Log(LogLevel::Warn, "unknown arm7 write8 %08X %02X @ %08X\n", addr, val, ARM7->R[15]);
}
void ARM7Write16(u32 addr, u16 val)
@@ -2771,7 +2773,7 @@ void ARM7Write16(u32 addr, u16 val)
}
if (addr >= 0x01000000)
- printf("unknown arm7 write16 %08X %04X @ %08X\n", addr, val, ARM7->R[15]);
+ Log(LogLevel::Warn, "unknown arm7 write16 %08X %04X @ %08X\n", addr, val, ARM7->R[15]);
}
void ARM7Write32(u32 addr, u32 val)
@@ -2855,7 +2857,7 @@ void ARM7Write32(u32 addr, u32 val)
}
if (addr >= 0x01000000)
- printf("unknown arm7 write32 %08X %08X @ %08X\n", addr, val, ARM7->R[15]);
+ Log(LogLevel::Warn, "unknown arm7 write32 %08X %08X @ %08X\n", addr, val, ARM7->R[15]);
}
bool ARM7GetMemRegion(u32 addr, bool write, MemRegion* region)
@@ -3016,7 +3018,7 @@ u8 ARM9IORead8(u32 addr)
}
if ((addr & 0xFFFFF000) != 0x04004000)
- printf("unknown ARM9 IO read8 %08X %08X\n", addr, ARM9->R[15]);
+ Log(LogLevel::Warn, "unknown ARM9 IO read8 %08X %08X\n", addr, ARM9->R[15]);
return 0;
}
@@ -3163,7 +3165,7 @@ u16 ARM9IORead16(u32 addr)
}
if ((addr & 0xFFFFF000) != 0x04004000)
- printf("unknown ARM9 IO read16 %08X %08X\n", addr, ARM9->R[15]);
+ Log(LogLevel::Warn, "unknown ARM9 IO read16 %08X %08X\n", addr, ARM9->R[15]);
return 0;
}
@@ -3307,7 +3309,7 @@ u32 ARM9IORead32(u32 addr)
}
if ((addr & 0xFFFFF000) != 0x04004000)
- printf("unknown ARM9 IO read32 %08X %08X\n", addr, ARM9->R[15]);
+ Log(LogLevel::Warn, "unknown ARM9 IO read32 %08X %08X\n", addr, ARM9->R[15]);
return 0;
}
@@ -3388,7 +3390,7 @@ void ARM9IOWrite8(u32 addr, u8 val)
return;
}
- printf("unknown ARM9 IO write8 %08X %02X %08X\n", addr, val, ARM9->R[15]);
+ Log(LogLevel::Warn, "unknown ARM9 IO write8 %08X %02X %08X\n", addr, val, ARM9->R[15]);
}
void ARM9IOWrite16(u32 addr, u16 val)
@@ -3572,7 +3574,7 @@ void ARM9IOWrite16(u32 addr, u16 val)
return;
}
- printf("unknown ARM9 IO write16 %08X %04X %08X\n", addr, val, ARM9->R[15]);
+ Log(LogLevel::Warn, "unknown ARM9 IO write16 %08X %04X %08X\n", addr, val, ARM9->R[15]);
}
void ARM9IOWrite32(u32 addr, u32 val)
@@ -3735,7 +3737,7 @@ void ARM9IOWrite32(u32 addr, u32 val)
ch = NDS::ARM9Read8(val + i);
output[i] = ch;
}
- printf("%s", output);
+ Log(LogLevel::Debug, "%s", output);
return;
}
@@ -3746,12 +3748,12 @@ void ARM9IOWrite32(u32 addr, u32 val)
bool appendLF = 0x04FFFA18 == addr;
NocashPrint(0, val);
if(appendLF)
- printf("\n");
+ Log(LogLevel::Debug, "\n");
return;
}
// NO$GBA debug register "Char Out"
- case 0x04FFFA1C: printf("%c", val & 0xFF); return;
+ case 0x04FFFA1C: Log(LogLevel::Debug, "%c", val & 0xFF); return;
}
if (addr >= 0x04000000 && addr < 0x04000060)
@@ -3770,7 +3772,7 @@ void ARM9IOWrite32(u32 addr, u32 val)
return;
}
- printf("unknown ARM9 IO write32 %08X %08X %08X\n", addr, val, ARM9->R[15]);
+ Log(LogLevel::Warn, "unknown ARM9 IO write32 %08X %08X %08X\n", addr, val, ARM9->R[15]);
}
@@ -3844,7 +3846,7 @@ u8 ARM7IORead8(u32 addr)
}
if ((addr & 0xFFFFF000) != 0x04004000)
- printf("unknown ARM7 IO read8 %08X %08X\n", addr, ARM7->R[15]);
+ Log(LogLevel::Warn, "unknown ARM7 IO read8 %08X %08X\n", addr, ARM7->R[15]);
return 0;
}
@@ -3938,7 +3940,7 @@ u16 ARM7IORead16(u32 addr)
}
if ((addr & 0xFFFFF000) != 0x04004000)
- printf("unknown ARM7 IO read16 %08X %08X\n", addr, ARM7->R[15]);
+ Log(LogLevel::Warn, "unknown ARM7 IO read16 %08X %08X\n", addr, ARM7->R[15]);
return 0;
}
@@ -4039,7 +4041,7 @@ u32 ARM7IORead32(u32 addr)
}
if ((addr & 0xFFFFF000) != 0x04004000)
- printf("unknown ARM7 IO read32 %08X %08X\n", addr, ARM7->R[15]);
+ Log(LogLevel::Warn, "unknown ARM7 IO read32 %08X %08X\n", addr, ARM7->R[15]);
return 0;
}
@@ -4105,7 +4107,7 @@ void ARM7IOWrite8(u32 addr, u8 val)
case 0x04000301:
val &= 0xC0;
- if (val == 0x40) printf("!! GBA MODE NOT SUPPORTED\n");
+ if (val == 0x40) Log(LogLevel::Warn, "!! GBA MODE NOT SUPPORTED\n");
else if (val == 0x80) ARM7->Halt(1);
else if (val == 0xC0) EnterSleepMode();
return;
@@ -4117,7 +4119,7 @@ void ARM7IOWrite8(u32 addr, u8 val)
return;
}
- printf("unknown ARM7 IO write8 %08X %02X %08X\n", addr, val, ARM7->R[15]);
+ Log(LogLevel::Warn, "unknown ARM7 IO write8 %08X %02X %08X\n", addr, val, ARM7->R[15]);
}
void ARM7IOWrite16(u32 addr, u16 val)
@@ -4272,7 +4274,7 @@ void ARM7IOWrite16(u32 addr, u16 val)
return;
}
- printf("unknown ARM7 IO write16 %08X %04X %08X\n", addr, val, ARM7->R[15]);
+ Log(LogLevel::Warn, "unknown ARM7 IO write16 %08X %04X %08X\n", addr, val, ARM7->R[15]);
}
void ARM7IOWrite32(u32 addr, u32 val)
@@ -4406,7 +4408,7 @@ void ARM7IOWrite32(u32 addr, u32 val)
return;
}
- printf("unknown ARM7 IO write32 %08X %08X %08X\n", addr, val, ARM7->R[15]);
+ Log(LogLevel::Warn, "unknown ARM7 IO write32 %08X %08X %08X\n", addr, val, ARM7->R[15]);
}
}
diff --git a/src/NDSCart.cpp b/src/NDSCart.cpp
index cdc26ef..eaa6487 100644
--- a/src/NDSCart.cpp
+++ b/src/NDSCart.cpp
@@ -28,6 +28,8 @@
#include "ROMList.h"
#include "melonDLDI.h"
+using Platform::Log;
+using Platform::LogLevel;
namespace NDSCart
{
@@ -422,8 +424,8 @@ void CartRetail::DoSavestate(Savestate* file)
file->Var32(&SRAMLength);
if (SRAMLength != oldlen)
{
- printf("savestate: VERY BAD!!!! SRAM LENGTH DIFFERENT. %d -> %d\n", oldlen, SRAMLength);
- printf("oh well. loading it anyway. adsfgdsf\n");
+ Log(LogLevel::Warn, "savestate: VERY BAD!!!! SRAM LENGTH DIFFERENT. %d -> %d\n", oldlen, SRAMLength);
+ Log(LogLevel::Warn, "oh well. loading it anyway. adsfgdsf\n");
if (oldlen) delete[] SRAM;
SRAM = nullptr;
@@ -627,7 +629,7 @@ u8 CartRetail::SRAMWrite_EEPROMTiny(u8 val, u32 pos, bool last)
default:
if (pos == 1)
- printf("unknown tiny EEPROM save command %02X\n", SRAMCmd);
+ Log(LogLevel::Warn, "unknown tiny EEPROM save command %02X\n", SRAMCmd);
return 0xFF;
}
}
@@ -693,7 +695,7 @@ u8 CartRetail::SRAMWrite_EEPROM(u8 val, u32 pos, bool last)
default:
if (pos == 1)
- printf("unknown EEPROM save command %02X\n", SRAMCmd);
+ Log(LogLevel::Warn, "unknown EEPROM save command %02X\n", SRAMCmd);
return 0xFF;
}
}
@@ -837,7 +839,7 @@ u8 CartRetail::SRAMWrite_FLASH(u8 val, u32 pos, bool last)
default:
if (pos == 1)
- printf("unknown FLASH save command %02X\n", SRAMCmd);
+ Log(LogLevel::Warn, "unknown FLASH save command %02X\n", SRAMCmd);
return 0xFF;
}
}
@@ -966,8 +968,8 @@ int CartRetailNAND::ROMCommandStart(u8* cmd, u8* data, u32 len)
// window is 0x20000 bytes, address is aligned to that boundary
// NAND remains stuck 'busy' forever if this is less than the starting SRAM address
// TODO.
- if (addr < SRAMBase) printf("NAND: !! BAD ADDR %08X < %08X\n", addr, SRAMBase);
- if (addr >= (SRAMBase+SRAMLength)) printf("NAND: !! BAD ADDR %08X > %08X\n", addr, SRAMBase+SRAMLength);
+ if (addr < SRAMBase) Log(LogLevel::Warn,"NAND: !! BAD ADDR %08X < %08X\n", addr, SRAMBase);
+ if (addr >= (SRAMBase+SRAMLength)) Log(LogLevel::Warn,"NAND: !! BAD ADDR %08X > %08X\n", addr, SRAMBase+SRAMLength);
SRAMWindow = addr;
}
@@ -1118,7 +1120,7 @@ u8 CartRetailIR::SPIWrite(u8 val, u32 pos, bool last)
CartRetailBT::CartRetailBT(u8* rom, u32 len, u32 chipid) : CartRetail(rom, len, chipid)
{
- printf("POKETYPE CART\n");
+ Log(LogLevel::Info,"POKETYPE CART\n");
}
CartRetailBT::~CartRetailBT()
@@ -1137,7 +1139,7 @@ void CartRetailBT::DoSavestate(Savestate* file)
u8 CartRetailBT::SPIWrite(u8 val, u32 pos, bool last)
{
- printf("POKETYPE SPI: %02X %d %d - %08X\n", val, pos, last, NDS::GetPC(0));
+ Log(LogLevel::Debug,"POKETYPE SPI: %02X %d %d - %08X\n", val, pos, last, NDS::GetPC(0));
/*if (pos == 0)
{
@@ -1295,12 +1297,12 @@ void CartHomebrew::ApplyDLDIPatchAt(u8* binary, u32 dldioffset, const u8* patch,
{
if (patch[0x0D] > binary[dldioffset+0x0F])
{
- printf("DLDI driver ain't gonna fit, sorry\n");
+ Log(LogLevel::Error, "DLDI driver ain't gonna fit, sorry\n");
return;
}
- printf("existing driver is: %s\n", &binary[dldioffset+0x10]);
- printf("new driver is: %s\n", &patch[0x10]);
+ Log(LogLevel::Info, "existing driver is: %s\n", &binary[dldioffset+0x10]);
+ Log(LogLevel::Info, "new driver is: %s\n", &patch[0x10]);
u32 memaddr = *(u32*)&binary[dldioffset+0x40];
if (memaddr == 0)
@@ -1389,7 +1391,7 @@ void CartHomebrew::ApplyDLDIPatchAt(u8* binary, u32 dldioffset, const u8* patch,
*(u32*)&binary[writesec_addr+0x04] = 0xE12FFF1E; // bx lr
}
- printf("applied DLDI patch at %08X\n", dldioffset);
+ Log(LogLevel::Debug, "applied DLDI patch at %08X\n", dldioffset);
}
void CartHomebrew::ApplyDLDIPatch(const u8* patch, u32 patchlen, bool readonly)
@@ -1398,7 +1400,7 @@ void CartHomebrew::ApplyDLDIPatch(const u8* patch, u32 patchlen, bool readonly)
*(u32*)&patch[4] != 0x69684320 ||
*(u32*)&patch[8] != 0x006D6873)
{
- printf("bad DLDI patch\n");
+ Log(LogLevel::Error, "bad DLDI patch\n");
return;
}
@@ -1413,7 +1415,7 @@ void CartHomebrew::ApplyDLDIPatch(const u8* patch, u32 patchlen, bool readonly)
*(u32*)&binary[i+4] == 0x69684320 &&
*(u32*)&binary[i+8] == 0x006D6873)
{
- printf("DLDI structure found at %08X (%08X)\n", i, offset+i);
+ Log(LogLevel::Debug, "DLDI structure found at %08X (%08X)\n", i, offset+i);
ApplyDLDIPatchAt(binary, i, patch, patchlen, readonly);
i += patchlen;
}
@@ -1567,13 +1569,13 @@ void DecryptSecureArea(u8* out)
if (!strncmp((const char*)out, "encryObj", 8))
{
- printf("Secure area decryption OK\n");
+ Log(LogLevel::Info, "Secure area decryption OK\n");
*(u32*)&out[0] = 0xE7FFDEFF;
*(u32*)&out[4] = 0xE7FFDEFF;
}
else
{
- printf("Secure area decryption failed\n");
+ Log(LogLevel::Warn, "Secure area decryption failed\n");
for (u32 i = 0; i < 0x800; i += 4)
*(u32*)&out[i] = 0xE7FFDEFF;
}
@@ -1597,7 +1599,7 @@ bool LoadROM(const u8* romdata, u32 romlen)
}
catch (const std::bad_alloc& e)
{
- printf("NDSCart: failed to allocate memory for ROM (%d bytes)\n", CartROMSize);
+ Log(LogLevel::Error, "NDSCart: failed to allocate memory for ROM (%d bytes)\n", CartROMSize);
return false;
}
@@ -1615,7 +1617,7 @@ bool LoadROM(const u8* romdata, u32 romlen)
memcpy(&Banner, CartROM + Header.BannerOffset, bannersize);
}
- printf("Game code: %.4s\n", Header.GameCode);
+ Log(LogLevel::Info, "Game code: %.4s\n", Header.GameCode);
u32 gamecode = (u32)Header.GameCode[3] << 24 |
(u32)Header.GameCode[2] << 16 |
@@ -1629,7 +1631,7 @@ bool LoadROM(const u8* romdata, u32 romlen)
if (!ReadROMParams(gamecode, &romparams))
{
// set defaults
- printf("ROM entry not found\n");
+ Log(LogLevel::Warn, "ROM entry not found\n");
romparams.GameCode = gamecode;
romparams.ROMSize = CartROMSize;
@@ -1639,10 +1641,10 @@ bool LoadROM(const u8* romdata, u32 romlen)
romparams.SaveMemType = 2; // assume EEPROM 64k (TODO FIXME)
}
else
- printf("ROM entry: %08X %08X\n", romparams.ROMSize, romparams.SaveMemType);
+ Log(LogLevel::Info, "ROM entry: %08X %08X\n", romparams.ROMSize, romparams.SaveMemType);
if (romparams.ROMSize != romlen)
- printf("!! bad ROM size %d (expected %d) rounded to %d\n", romlen, romparams.ROMSize, CartROMSize);
+ Log(LogLevel::Warn, "!! bad ROM size %d (expected %d) rounded to %d\n", romlen, romparams.ROMSize, CartROMSize);
// generate a ROM ID
// note: most games don't check the actual value
@@ -1666,14 +1668,14 @@ bool LoadROM(const u8* romdata, u32 romlen)
//CartID = 0x88017FEC;
//CartID = 0x80007FC2; // pokémon typing adventure
- printf("Cart ID: %08X\n", CartID);
+ Log(LogLevel::Info, "Cart ID: %08X\n", CartID);
if (arm9base >= 0x4000 && arm9base < 0x8000)
{
// reencrypt secure area if needed
if (*(u32*)&CartROM[arm9base] == 0xE7FFDEFF && *(u32*)&CartROM[arm9base+0x10] != 0xE7FFDEFF)
{
- printf("Re-encrypting cart secure area\n");
+ Log(LogLevel::Debug, "Re-encrypting cart secure area\n");
strncpy((char*)&CartROM[arm9base], "encryObj", 8);
@@ -1832,10 +1834,10 @@ void WriteROMCnt(u32 val)
if (seed1 & (1ULL << i)) Key2_Y |= (1ULL << (38-i));
}
- printf("seed0: %02X%08X\n", (u32)(seed0>>32), (u32)seed0);
- printf("seed1: %02X%08X\n", (u32)(seed1>>32), (u32)seed1);
- printf("key2 X: %02X%08X\n", (u32)(Key2_X>>32), (u32)Key2_X);
- printf("key2 Y: %02X%08X\n", (u32)(Key2_Y>>32), (u32)Key2_Y);
+ Log(LogLevel::Debug, "seed0: %02X%08X\n", (u32)(seed0>>32), (u32)seed0);
+ Log(LogLevel::Debug, "seed1: %02X%08X\n", (u32)(seed1>>32), (u32)seed1);
+ Log(LogLevel::Debug, "key2 X: %02X%08X\n", (u32)(Key2_X>>32), (u32)Key2_X);
+ Log(LogLevel::Debug, "key2 Y: %02X%08X\n", (u32)(Key2_Y>>32), (u32)Key2_Y);
}
// transfers will only start when bit31 changes from 0 to 1
@@ -1872,7 +1874,7 @@ void WriteROMCnt(u32 val)
TransferDir = Cart->ROMCommandStart(TransferCmd, TransferData, TransferLen);
if ((datasize > 0) && (((ROMCnt >> 30) & 0x1) != TransferDir))
- printf("NDSCART: !! BAD TRANSFER DIRECTION FOR CMD %02X, DIR=%d, ROMCNT=%08X\n", ROMCommand[0], TransferDir, ROMCnt);
+ Log(LogLevel::Debug, "NDSCART: !! BAD TRANSFER DIRECTION FOR CMD %02X, DIR=%d, ROMCNT=%08X\n", ROMCommand[0], TransferDir, ROMCnt);
ROMCnt &= ~(1<<23);
@@ -1967,7 +1969,7 @@ void WriteSPICnt(u16 val)
// in this case, the transfer continues until the end, even if bit13 or bit15 are cleared
// if the transfer speed is changed, the transfer continues at the new speed (TODO)
if (SPICnt & (1<<7))
- printf("!! CHANGING AUXSPICNT DURING TRANSFER: %04X\n", val);
+ Log(LogLevel::Debug, "!! CHANGING AUXSPICNT DURING TRANSFER: %04X\n", val);
}
void SPITransferDone(u32 param)
diff --git a/src/OpenGLSupport.cpp b/src/OpenGLSupport.cpp
index aee107a..958930d 100644
--- a/src/OpenGLSupport.cpp
+++ b/src/OpenGLSupport.cpp
@@ -18,6 +18,8 @@
#include "OpenGLSupport.h"
+using Platform::Log;
+using Platform::LogLevel;
namespace OpenGL
{
@@ -39,8 +41,8 @@ bool BuildShaderProgram(const char* vs, const char* fs, GLuint* ids, const char*
if (res < 1) res = 1024;
char* log = new char[res+1];
glGetShaderInfoLog(ids[0], res+1, NULL, log);
- printf("OpenGL: failed to compile vertex shader %s: %s\n", name, log);
- printf("shader source:\n--\n%s\n--\n", vs);
+ Log(LogLevel::Error, "OpenGL: failed to compile vertex shader %s: %s\n", name, log);
+ Log(LogLevel::Debug, "shader source:\n--\n%s\n--\n", vs);
delete[] log;
glDeleteShader(ids[0]);
@@ -60,7 +62,7 @@ bool BuildShaderProgram(const char* vs, const char* fs, GLuint* ids, const char*
if (res < 1) res = 1024;
char* log = new char[res+1];
glGetShaderInfoLog(ids[1], res+1, NULL, log);
- printf("OpenGL: failed to compile fragment shader %s: %s\n", name, log);
+ Log(LogLevel::Error, "OpenGL: failed to compile fragment shader %s: %s\n", name, log);
//printf("shader source:\n--\n%s\n--\n", fs);
delete[] log;
@@ -100,7 +102,7 @@ bool LinkShaderProgram(GLuint* ids)
if (res < 1) res = 1024;
char* log = new char[res+1];
glGetProgramInfoLog(ids[2], res+1, NULL, log);
- printf("OpenGL: failed to link shader program: %s\n", log);
+ Log(LogLevel::Error, "OpenGL: failed to link shader program: %s\n", log);
delete[] log;
glDeleteProgram(ids[2]);
diff --git a/src/Platform.h b/src/Platform.h
index f2997ef..2227ffc 100644
--- a/src/Platform.h
+++ b/src/Platform.h
@@ -128,6 +128,16 @@ inline bool LocalFileExists(std::string name)
return true;
}
+enum LogLevel
+{
+ Debug,
+ Info,
+ Warn,
+ Error,
+};
+
+void Log(LogLevel level, const char* fmt, ...);
+
struct Thread;
Thread* Thread_Create(std::function<void()> func);
void Thread_Free(Thread* thread);
diff --git a/src/RTC.cpp b/src/RTC.cpp
index 1c02cbb..a5340f4 100644
--- a/src/RTC.cpp
+++ b/src/RTC.cpp
@@ -19,11 +19,13 @@
// Required by MinGW to enable localtime_r in time.h
#define _POSIX_THREAD_SAFE_FUNCTIONS
-#include <stdio.h>
#include <string.h>
#include <time.h>
#include "RTC.h"
+#include "Platform.h"
+using Platform::Log;
+using Platform::LogLevel;
namespace RTC
{
@@ -186,7 +188,7 @@ void ByteIn(u8 val)
case 0x40:
if (InputPos == 1) StatusReg2 = val;
- if (StatusReg2 & 0x4F) printf("RTC INTERRUPT ON: %02X\n", StatusReg2);
+ if (StatusReg2 & 0x4F) Log(LogLevel::Debug, "RTC INTERRUPT ON: %02X\n", StatusReg2);
break;
case 0x20:
diff --git a/src/SPI.cpp b/src/SPI.cpp
index e990b3a..ca67234 100644
--- a/src/SPI.cpp
+++ b/src/SPI.cpp
@@ -29,6 +29,8 @@
#include "DSi_SPI_TSC.h"
#include "Platform.h"
+using Platform::Log;
+using Platform::LogLevel;
namespace SPI_Firmware
{
@@ -96,7 +98,7 @@ u32 FixFirmwareLength(u32 originalLength)
{
if (originalLength != 0x20000 && originalLength != 0x40000 && originalLength != 0x80000)
{
- printf("Bad firmware size %d, ", originalLength);
+ Log(LogLevel::Warn, "Bad firmware size %d, ", originalLength);
// pick the nearest power-of-two length
originalLength |= (originalLength >> 1);
@@ -110,7 +112,7 @@ u32 FixFirmwareLength(u32 originalLength)
if (originalLength > 0x80000) originalLength = 0x80000;
else if (originalLength < 0x20000) originalLength = 0x20000;
- printf("assuming %d\n", originalLength);
+ Log(LogLevel::Debug, "assuming %d\n", originalLength);
}
return originalLength;
}
@@ -286,7 +288,7 @@ void LoadFirmwareFromFile(FILE* f, bool makecopy)
}
else
{
- printf("Could not write firmware backup!\n");
+ Log(LogLevel::Error, "Could not write firmware backup!\n");
}
}
else
@@ -348,7 +350,7 @@ void Reset()
}
if (!f)
{
- printf("Firmware not found! Generating default firmware.\n");
+ Log(LogLevel::Warn,"Firmware not found! Generating default firmware.\n");
FirmwarePath = "";
}
else
@@ -425,17 +427,17 @@ void Reset()
}
}
- printf("MAC: %02X:%02X:%02X:%02X:%02X:%02X\n",
+ Log(LogLevel::Info, "MAC: %02X:%02X:%02X:%02X:%02X:%02X\n",
Firmware[0x36], Firmware[0x37], Firmware[0x38],
Firmware[0x39], Firmware[0x3A], Firmware[0x3B]);
// verify shit
- printf("FW: WIFI CRC16 = %s\n", VerifyCRC16(0x0000, 0x2C, *(u16*)&Firmware[0x2C], 0x2A)?"GOOD":"BAD");
- printf("FW: AP1 CRC16 = %s\n", VerifyCRC16(0x0000, 0x7FA00&FirmwareMask, 0xFE, 0x7FAFE&FirmwareMask)?"GOOD":"BAD");
- printf("FW: AP2 CRC16 = %s\n", VerifyCRC16(0x0000, 0x7FB00&FirmwareMask, 0xFE, 0x7FBFE&FirmwareMask)?"GOOD":"BAD");
- printf("FW: AP3 CRC16 = %s\n", VerifyCRC16(0x0000, 0x7FC00&FirmwareMask, 0xFE, 0x7FCFE&FirmwareMask)?"GOOD":"BAD");
- printf("FW: USER0 CRC16 = %s\n", VerifyCRC16(0xFFFF, 0x7FE00&FirmwareMask, 0x70, 0x7FE72&FirmwareMask)?"GOOD":"BAD");
- printf("FW: USER1 CRC16 = %s\n", VerifyCRC16(0xFFFF, 0x7FF00&FirmwareMask, 0x70, 0x7FF72&FirmwareMask)?"GOOD":"BAD");
+ Log(LogLevel::Debug, "FW: WIFI CRC16 = %s\n", VerifyCRC16(0x0000, 0x2C, *(u16*)&Firmware[0x2C], 0x2A)?"GOOD":"BAD");
+ Log(LogLevel::Debug, "FW: AP1 CRC16 = %s\n", VerifyCRC16(0x0000, 0x7FA00&FirmwareMask, 0xFE, 0x7FAFE&FirmwareMask)?"GOOD":"BAD");
+ Log(LogLevel::Debug, "FW: AP2 CRC16 = %s\n", VerifyCRC16(0x0000, 0x7FB00&FirmwareMask, 0xFE, 0x7FBFE&FirmwareMask)?"GOOD":"BAD");
+ Log(LogLevel::Debug, "FW: AP3 CRC16 = %s\n", VerifyCRC16(0x0000, 0x7FC00&FirmwareMask, 0xFE, 0x7FCFE&FirmwareMask)?"GOOD":"BAD");
+ Log(LogLevel::Debug, "FW: USER0 CRC16 = %s\n", VerifyCRC16(0xFFFF, 0x7FE00&FirmwareMask, 0x70, 0x7FE72&FirmwareMask)?"GOOD":"BAD");
+ Log(LogLevel::Debug, "FW: USER1 CRC16 = %s\n", VerifyCRC16(0xFFFF, 0x7FF00&FirmwareMask, 0x70, 0x7FF72&FirmwareMask)?"GOOD":"BAD");
Hold = 0;
CurCmd = 0;
@@ -585,7 +587,7 @@ void Write(u8 val, u32 hold)
break;
default:
- printf("unknown firmware SPI command %02X\n", CurCmd);
+ Log(LogLevel::Warn, "unknown firmware SPI command %02X\n", CurCmd);
Data = 0xFF;
break;
}
@@ -937,8 +939,8 @@ void WriteCnt(u16 val)
// TODO: presumably the transfer speed can be changed during a transfer
// like with the NDSCart SPI interface
Cnt = (Cnt & 0x0080) | (val & 0xCF03);
- if (val & 0x0400) printf("!! CRAPOED 16BIT SPI MODE\n");
- if (Cnt & (1<<7)) printf("!! CHANGING SPICNT DURING TRANSFER: %04X\n", val);
+ if (val & 0x0400) Log(LogLevel::Warn, "!! CRAPOED 16BIT SPI MODE\n");
+ if (Cnt & (1<<7)) Log(LogLevel::Warn, "!! CHANGING SPICNT DURING TRANSFER: %04X\n", val);
}
void TransferDone(u32 param)
@@ -983,7 +985,7 @@ void WriteData(u8 val)
else
SPI_TSC::Write(val, Cnt&(1<<11));
break;
- default: printf("SPI to unknown device %04X %02X\n", Cnt, val); break;
+ default: Log(LogLevel::Warn, "SPI to unknown device %04X %02X\n", Cnt, val); break;
}
// SPI transfers one bit per cycle -> 8 cycles per byte
diff --git a/src/SPU.cpp b/src/SPU.cpp
index 9f245a2..734590e 100644
--- a/src/SPU.cpp
+++ b/src/SPU.cpp
@@ -24,6 +24,9 @@
#include "DSi.h"
#include "SPU.h"
+using Platform::Log;
+using Platform::LogLevel;
+
// SPU TODO
// * capture addition modes, overflow bugs
@@ -1006,7 +1009,7 @@ u8 Read8(u32 addr)
}
}
- printf("unknown SPU read8 %08X\n", addr);
+ Log(LogLevel::Warn, "unknown SPU read8 %08X\n", addr);
return 0;
}
@@ -1033,7 +1036,7 @@ u16 Read16(u32 addr)
}
}
- printf("unknown SPU read16 %08X\n", addr);
+ Log(LogLevel::Warn, "unknown SPU read16 %08X\n", addr);
return 0;
}
@@ -1062,7 +1065,7 @@ u32 Read32(u32 addr)
}
}
- printf("unknown SPU read32 %08X\n", addr);
+ Log(LogLevel::Warn, "unknown SPU read32 %08X\n", addr);
return 0;
}
@@ -1095,16 +1098,16 @@ void Write8(u32 addr, u8 val)
case 0x04000508:
Capture[0]->SetCnt(val);
- if (val & 0x03) printf("!! UNSUPPORTED SPU CAPTURE MODE %02X\n", val);
+ if (val & 0x03) Log(LogLevel::Warn, "!! UNSUPPORTED SPU CAPTURE MODE %02X\n", val);
return;
case 0x04000509:
Capture[1]->SetCnt(val);
- if (val & 0x03) printf("!! UNSUPPORTED SPU CAPTURE MODE %02X\n", val);
+ if (val & 0x03) Log(LogLevel::Warn, "!! UNSUPPORTED SPU CAPTURE MODE %02X\n", val);
return;
}
}
- printf("unknown SPU write8 %08X %02X\n", addr, val);
+ Log(LogLevel::Warn, "unknown SPU write8 %08X %02X\n", addr, val);
}
void Write16(u32 addr, u16 val)
@@ -1145,7 +1148,7 @@ void Write16(u32 addr, u16 val)
case 0x04000508:
Capture[0]->SetCnt(val & 0xFF);
Capture[1]->SetCnt(val >> 8);
- if (val & 0x0303) printf("!! UNSUPPORTED SPU CAPTURE MODE %04X\n", val);
+ if (val & 0x0303) Log(LogLevel::Warn, "!! UNSUPPORTED SPU CAPTURE MODE %04X\n", val);
return;
case 0x04000514: Capture[0]->SetLength(val); return;
@@ -1153,7 +1156,7 @@ void Write16(u32 addr, u16 val)
}
}
- printf("unknown SPU write16 %08X %04X\n", addr, val);
+ Log(LogLevel::Warn, "unknown SPU write16 %08X %04X\n", addr, val);
}
void Write32(u32 addr, u32 val)
@@ -1193,7 +1196,7 @@ void Write32(u32 addr, u32 val)
case 0x04000508:
Capture[0]->SetCnt(val & 0xFF);
Capture[1]->SetCnt(val >> 8);
- if (val & 0x0303) printf("!! UNSUPPORTED SPU CAPTURE MODE %04X\n", val);
+ if (val & 0x0303) Log(LogLevel::Warn, "!! UNSUPPORTED SPU CAPTURE MODE %04X\n", val);
return;
case 0x04000510: Capture[0]->SetDstAddr(val); return;
diff --git a/src/Savestate.cpp b/src/Savestate.cpp
index 9128939..7a09617 100644
--- a/src/Savestate.cpp
+++ b/src/Savestate.cpp
@@ -20,6 +20,9 @@
#include "Savestate.h"
#include "Platform.h"
+using Platform::Log;
+using Platform::LogLevel;
+
/*
Savestate format
@@ -58,7 +61,7 @@ Savestate::Savestate(std::string filename, bool save)
file = Platform::OpenLocalFile(filename, "wb");
if (!file)
{
- printf("savestate: file %s doesn't exist\n", filename.c_str());
+ Log(LogLevel::Error, "savestate: file %s doesn't exist\n", filename.c_str());
Error = true;
return;
}
@@ -77,7 +80,7 @@ Savestate::Savestate(std::string filename, bool save)
file = Platform::OpenFile(filename, "rb");
if (!file)
{
- printf("savestate: file %s doesn't exist\n", filename.c_str());
+ Log(LogLevel::Error, "savestate: file %s doesn't exist\n", filename.c_str());
Error = true;
return;
}
@@ -92,7 +95,7 @@ Savestate::Savestate(std::string filename, bool save)
fread(&buf, 4, 1, file);
if (buf != ((u32*)magic)[0])
{
- printf("savestate: invalid magic %08X\n", buf);
+ Log(LogLevel::Error, "savestate: invalid magic %08X\n", buf);
Error = true;
return;
}
@@ -103,7 +106,7 @@ Savestate::Savestate(std::string filename, bool save)
fread(&VersionMajor, 2, 1, file);
if (VersionMajor != SAVESTATE_MAJOR)
{
- printf("savestate: bad version major %d, expecting %d\n", VersionMajor, SAVESTATE_MAJOR);
+ Log(LogLevel::Error, "savestate: bad version major %d, expecting %d\n", VersionMajor, SAVESTATE_MAJOR);
Error = true;
return;
}
@@ -111,7 +114,7 @@ Savestate::Savestate(std::string filename, bool save)
fread(&VersionMinor, 2, 1, file);
if (VersionMinor > SAVESTATE_MINOR)
{
- printf("savestate: state from the future, %d > %d\n", VersionMinor, SAVESTATE_MINOR);
+ Log(LogLevel::Error, "savestate: state from the future, %d > %d\n", VersionMinor, SAVESTATE_MINOR);
Error = true;
return;
}
@@ -120,7 +123,7 @@ Savestate::Savestate(std::string filename, bool save)
fread(&buf, 4, 1, file);
if (buf != len)
{
- printf("savestate: bad length %d\n", buf);
+ Log(LogLevel::Error, "savestate: bad length %d\n", buf);
Error = true;
return;
}
@@ -192,7 +195,7 @@ void Savestate::Section(const char* magic)
{
if (buf == 0)
{
- printf("savestate: section %s not found. blarg\n", magic);
+ Log(LogLevel::Error, "savestate: section %s not found. blarg\n", magic);
return;
}
diff --git a/src/Wifi.cpp b/src/Wifi.cpp
index 5373187..e2a7271 100644
--- a/src/Wifi.cpp
+++ b/src/Wifi.cpp
@@ -26,6 +26,8 @@
#include "ARM.h"
#include "GPU.h"
+using Platform::Log;
+using Platform::LogLevel;
namespace Wifi
{
@@ -33,7 +35,7 @@ namespace Wifi
//#define WIFI_LOG printf
#define WIFI_LOG(...) {}
-#define PRINT_MAC(pf, mac) printf("%s: %02X:%02X:%02X:%02X:%02X:%02X\n", pf, (mac)[0], (mac)[1], (mac)[2], (mac)[3], (mac)[4], (mac)[5]);
+#define PRINT_MAC(pf, mac) Log(LogLevel::Debug, "%s: %02X:%02X:%02X:%02X:%02X:%02X\n", pf, (mac)[0], (mac)[1], (mac)[2], (mac)[3], (mac)[4], (mac)[5]);
u8 RAM[0x2000];
u16 IO[0x1000>>1];
@@ -223,7 +225,7 @@ void Reset()
IOPORT(0x000) = 0xC340; // DSi has the modern DS-wifi variant
else
{
- printf("wifi: unknown console type %02X\n", console);
+ Log(LogLevel::Warn, "wifi: unknown console type %02X\n", console);
IOPORT(0x000) = 0x1440;
}
@@ -370,7 +372,7 @@ void UpdatePowerOn()
PowerOn = on;
if (on)
{
- printf("WIFI: ON\n");
+ Log(LogLevel::Info, "WIFI: ON\n");
ScheduleTimer(true);
@@ -378,7 +380,7 @@ void UpdatePowerOn()
}
else
{
- printf("WIFI: OFF\n");
+ Log(LogLevel::Info, "WIFI: OFF\n");
NDS::CancelEvent(NDS::Event_Wifi);
@@ -434,7 +436,7 @@ void SetIRQ14(int source) // 0=USCOMPARE 1=BEACONCOUNT 2=forced
SetIRQ(14);
if (source == 2)
- printf("wifi: weird forced IRQ14\n");
+ Log(LogLevel::Debug, "wifi: weird forced IRQ14\n");
IOPORT(W_BeaconCount2) = 0xFFFF;
IOPORT(W_TXReqRead) &= 0xFFF2;
@@ -533,7 +535,7 @@ void StartTX_LocN(int nslot, int loc)
TXSlot* slot = &TXSlots[nslot];
if (IOPORT(W_TXSlotLoc1 + (loc*4)) & 0x7000)
- printf("wifi: unusual loc%d bits set %04X\n", loc, IOPORT(W_TXSlotLoc1 + (loc*4)));
+ Log(LogLevel::Warn, "wifi: unusual loc%d bits set %04X\n", loc, IOPORT(W_TXSlotLoc1 + (loc*4)));
slot->Addr = (IOPORT(W_TXSlotLoc1 + (loc*4)) & 0x0FFF) << 1;
slot->Length = *(u16*)&RAM[slot->Addr + 0xA] & 0x3FFF;
@@ -553,7 +555,7 @@ void StartTX_Cmd()
// TODO: cancel the transfer if there isn't enough time left (check CMDCOUNT)
if (IOPORT(W_TXSlotCmd) & 0x3000)
- printf("wifi: !! unusual TXSLOT_CMD bits set %04X\n", IOPORT(W_TXSlotCmd));
+ Log(LogLevel::Warn,"wifi: !! unusual TXSLOT_CMD bits set %04X\n", IOPORT(W_TXSlotCmd));
slot->Addr = (IOPORT(W_TXSlotCmd) & 0x0FFF) << 1;
slot->Length = *(u16*)&RAM[slot->Addr + 0xA] & 0x3FFF;
@@ -872,7 +874,7 @@ bool ProcessTX(TXSlot* slot, int num)
}
if ((num != 5) && (RAM[slot->Addr+4] > 0))
- printf("SLOT %d RETRY COUNTER %d\n", num, RAM[slot->Addr+4]);
+ Log(LogLevel::Debug, "SLOT %d RETRY COUNTER %d\n", num, RAM[slot->Addr+4]);
// set TX addr
IOPORT(W_RXTXAddr) = slot->Addr >> 1;
@@ -909,13 +911,13 @@ bool ProcessTX(TXSlot* slot, int num)
if ((framectl & 0x00FF) == 0x0010)
{
u16 aid = *(u16*)&RAM[slot->Addr + 0xC + 24 + 4];
- if (aid) printf("[HOST] syncing client %04X, sync=%016llX\n", aid, USTimestamp);
+ if (aid) Log(LogLevel::Debug, "[HOST] syncing client %04X, sync=%016llX\n", aid, USTimestamp);
}
else if ((framectl & 0x00FF) == 0x00C0)
{
if (IsMPClient)
{
- printf("[CLIENT] deauth\n");
+ Log(LogLevel::Info, "[CLIENT] deauth\n");
IsMPClient = false;
}
}
@@ -1478,7 +1480,7 @@ bool CheckRX(int type) // 0=regular 1=MP replies 2=MP host frames
framelen = *(u16*)&RXBuffer[10];
if (framelen != rxlen-12)
{
- printf("bad frame length %d/%d\n", framelen, rxlen-12);
+ Log(LogLevel::Error, "bad frame length %d/%d\n", framelen, rxlen-12);
continue;
}
@@ -1515,7 +1517,7 @@ bool CheckRX(int type) // 0=regular 1=MP replies 2=MP host frames
if (aid)
{
- printf("[CLIENT %01X] host sync=%016llX\n", aid&0xF, timestamp);
+ Log(LogLevel::Debug, "[CLIENT %01X] host sync=%016llX\n", aid&0xF, timestamp);
IsMPClient = true;
USTimestamp = timestamp;
@@ -1745,7 +1747,7 @@ void USTimer(u32 param)
// TODO: properly check the crossing of the read cursor
// (for example, if it is outside of the RX buffer)
- printf("wifi: RX buffer full (buf=%04X/%04X rd=%04X wr=%04X rxtx=%04X power=%04X com=%d rxcnt=%04X filter=%04X/%04X frame=%04X/%04X len=%d)\n",
+ Log(LogLevel::Debug, "wifi: RX buffer full (buf=%04X/%04X rd=%04X wr=%04X rxtx=%04X power=%04X com=%d rxcnt=%04X filter=%04X/%04X frame=%04X/%04X len=%d)\n",
(IOPORT(W_RXBufBegin)>>1)&0xFFF, (IOPORT(W_RXBufEnd)>>1)&0xFFF,
IOPORT(W_RXBufReadCursor), IOPORT(W_RXBufWriteCursor),
IOPORT(W_RXTXAddr), IOPORT(W_PowerState), ComStatus,
@@ -1845,7 +1847,7 @@ u16 Read(u32 addr)
case W_BBRead:
if ((IOPORT(W_BBCnt) & 0xF000) != 0x6000)
{
- printf("WIFI: bad BB read, CNT=%04X\n", IOPORT(W_BBCnt));
+ Log(LogLevel::Error, "WIFI: bad BB read, CNT=%04X\n", IOPORT(W_BBCnt));
return 0;
}
return BBRegs[IOPORT(W_BBCnt) & 0xFF];
@@ -2007,7 +2009,7 @@ void Write(u32 addr, u16 val)
return;
case W_IFSet:
IOPORT(W_IF) |= (val & 0xFBFF);
- printf("wifi: force-setting IF %04X\n", val);
+ Log(LogLevel::Debug, "wifi: force-setting IF %04X\n", val);
return;
case W_AIDLow:
@@ -2135,11 +2137,11 @@ void Write(u32 addr, u16 val)
FireTX();
}
val &= 0xFF0E;
- if (val & 0x7FFF) printf("wifi: unknown RXCNT bits set %04X\n", val);
+ if (val & 0x7FFF) Log(LogLevel::Warn, "wifi: unknown RXCNT bits set %04X\n", val);
break;
case W_RXBufDataRead:
- printf("wifi: writing to RXBUF_DATA_READ. wat\n");
+ Log(LogLevel::Warn, "wifi: writing to RXBUF_DATA_READ. wat\n");
if (IOPORT(W_RXBufCount) > 0)
{
IOPORT(W_RXBufCount)--;
@@ -2176,7 +2178,7 @@ void Write(u32 addr, u16 val)
// checkme: any bits affecting the beacon slot?
if (val & 0x0040) IOPORT(W_TXSlotReply2) &= 0x7FFF;
if (val & 0x0080) IOPORT(W_TXSlotReply1) &= 0x7FFF;
- if ((val & 0xFF30) && (val != 0xFFFF)) printf("unusual TXSLOTRESET %04X\n", val);
+ if ((val & 0xFF30) && (val != 0xFFFF)) Log(LogLevel::Warn, "unusual TXSLOTRESET %04X\n", val);
val = 0; // checkme (write-only port)
break;
diff --git a/src/WifiAP.cpp b/src/WifiAP.cpp
index 5351639..898ee16 100644
--- a/src/WifiAP.cpp
+++ b/src/WifiAP.cpp
@@ -27,6 +27,9 @@
#include <stddef.h>
#endif
+using Platform::Log;
+using Platform::LogLevel;
+
namespace WifiAP
{
@@ -137,7 +140,7 @@ int HandleManagementFrame(u8* data, int len)
if (RXNum)
{
- printf("wifiAP: can't reply!!\n");
+ Log(LogLevel::Warn, "wifiAP: can't reply!!\n");
return 0;
}
@@ -155,12 +158,12 @@ int HandleManagementFrame(u8* data, int len)
if (ClientStatus != 1)
{
- printf("wifiAP: bad assoc request, needs auth prior\n");
+ Log(LogLevel::Error, "wifiAP: bad assoc request, needs auth prior\n");
return 0;
}
ClientStatus = 2;
- printf("wifiAP: client associated\n");
+ Log(LogLevel::Info, "wifiAP: client associated\n");
PWRITE_16(p, 0x0010);
PWRITE_16(p, 0x0000); // duration??
@@ -210,7 +213,7 @@ int HandleManagementFrame(u8* data, int len)
return 0;
ClientStatus = 1;
- printf("wifiAP: client deassociated\n");
+ Log(LogLevel::Info, "wifiAP: client deassociated\n");
PWRITE_16(p, 0x00A0);
PWRITE_16(p, 0x0000); // duration??
@@ -232,7 +235,7 @@ int HandleManagementFrame(u8* data, int len)
return 0;
ClientStatus = 1;
- printf("wifiAP: client authenticated\n");
+ Log(LogLevel::Info, "wifiAP: client authenticated\n");
PWRITE_16(p, 0x00B0);
PWRITE_16(p, 0x0000); // duration??
@@ -256,7 +259,7 @@ int HandleManagementFrame(u8* data, int len)
return 0;
ClientStatus = 0;
- printf("wifiAP: client deauthenticated\n");
+ Log(LogLevel::Info, "wifiAP: client deauthenticated\n");
PWRITE_16(p, 0x00C0);
PWRITE_16(p, 0x0000); // duration??
@@ -273,7 +276,7 @@ int HandleManagementFrame(u8* data, int len)
return len;
default:
- printf("wifiAP: unknown management frame type %X\n", (framectl>>4)&0xF);
+ Log(LogLevel::Warn, "wifiAP: unknown management frame type %X\n", (framectl>>4)&0xF);
return 0;
}
}
@@ -297,7 +300,7 @@ int SendPacket(u8* data, int len)
{
if ((framectl & 0x0300) != 0x0100)
{
- printf("wifiAP: got data frame with bad fromDS/toDS bits %04X\n", framectl);
+ Log(LogLevel::Error, "wifiAP: got data frame with bad fromDS/toDS bits %04X\n", framectl);
return 0;
}
@@ -307,7 +310,7 @@ int SendPacket(u8* data, int len)
{
if (ClientStatus != 2)
{
- printf("wifiAP: trying to send shit without being associated\n");
+ Log(LogLevel::Warn, "wifiAP: trying to send shit without being associated\n");
return 0;
}
diff --git a/src/frontend/qt_sdl/ArchiveUtil.cpp b/src/frontend/qt_sdl/ArchiveUtil.cpp
index fff1a94..b025aa8 100644
--- a/src/frontend/qt_sdl/ArchiveUtil.cpp
+++ b/src/frontend/qt_sdl/ArchiveUtil.cpp
@@ -19,6 +19,9 @@
#include "ArchiveUtil.h"
#include "Platform.h"
+using Platform::Log;
+using Platform::LogLevel;
+
namespace Archive
{
@@ -106,7 +109,7 @@ QVector<QString> ExtractFileFromArchive(QString path, QString wantedFile, QByteA
if (bytesRead < 0)
{
- printf("Error whilst reading archive: %s", archive_error_string(a));
+ Log(LogLevel::Error, "Error whilst reading archive: %s", archive_error_string(a));
return QVector<QString> {"Err", archive_error_string(a)};
}
diff --git a/src/frontend/qt_sdl/CLI.cpp b/src/frontend/qt_sdl/CLI.cpp
index 58e386e..9c19d79 100644
--- a/src/frontend/qt_sdl/CLI.cpp
+++ b/src/frontend/qt_sdl/CLI.cpp
@@ -25,6 +25,10 @@
#include <QStringList>
#include "CLI.h"
+#include "Platform.h"
+
+using Platform::Log;
+using Platform::LogLevel;
namespace CLI
{
@@ -55,7 +59,7 @@ CommandLineOptions* ManageArgs(QApplication& melon)
switch (posargs.size())
{
default:
- printf("Too many positional arguments; ignoring 3 onwards\n");
+ Log(LogLevel::Warn, "Too many positional arguments; ignoring 3 onwards\n");
case 2:
options->gbaRomPath = posargs[1];
case 1:
@@ -79,7 +83,7 @@ CommandLineOptions* ManageArgs(QApplication& melon)
}
else
{
- printf("ERROR: -b/--boot only accepts auto/always/never as arguments\n");
+ Log(LogLevel::Error, "ERROR: -b/--boot only accepts auto/always/never as arguments\n");
exit(1);
}
diff --git a/src/frontend/qt_sdl/CheatsDialog.cpp b/src/frontend/qt_sdl/CheatsDialog.cpp
index 4537df3..b15fab7 100644
--- a/src/frontend/qt_sdl/CheatsDialog.cpp
+++ b/src/frontend/qt_sdl/CheatsDialog.cpp
@@ -29,6 +29,8 @@
#include "CheatsDialog.h"
#include "ui_CheatsDialog.h"
+using Platform::Log;
+using Platform::LogLevel;
CheatsDialog* CheatsDialog::currentDlg = nullptr;
@@ -150,7 +152,7 @@ void CheatsDialog::on_btnNewARCode_clicked()
}
else
{
- printf("what?? :(\n");
+ Log(LogLevel::Warn, "what?? :(\n");
return;
}
diff --git a/src/frontend/qt_sdl/InputConfig/MapButton.h b/src/frontend/qt_sdl/InputConfig/MapButton.h
index afefed7..f90fa3f 100644
--- a/src/frontend/qt_sdl/InputConfig/MapButton.h
+++ b/src/frontend/qt_sdl/InputConfig/MapButton.h
@@ -24,6 +24,7 @@
#include <SDL2/SDL.h>
#include "Input.h"
+#include "Platform.h"
class KeyMapButton : public QPushButton
{
@@ -51,7 +52,7 @@ protected:
{
if (!isChecked()) return QPushButton::keyPressEvent(event);
- printf("KEY PRESSED = %08X %08X | %08X %08X %08X\n", event->key(), (int)event->modifiers(), event->nativeVirtualKey(), event->nativeModifiers(), event->nativeScanCode());
+ Platform::Log(Platform::Debug, "KEY PRESSED = %08X %08X | %08X %08X %08X\n", event->key(), (int)event->modifiers(), event->nativeVirtualKey(), event->nativeModifiers(), event->nativeScanCode());
int key = event->key();
int mod = event->modifiers();
diff --git a/src/frontend/qt_sdl/LAN_PCap.cpp b/src/frontend/qt_sdl/LAN_PCap.cpp
index 86c218f..2a04e70 100644
--- a/src/frontend/qt_sdl/LAN_PCap.cpp
+++ b/src/frontend/qt_sdl/LAN_PCap.cpp
@@ -26,6 +26,7 @@
#include "../Wifi.h"
#include "LAN_PCap.h"
#include "Config.h"
+#include "Platform.h"
#ifdef __WIN32__
#include <iphlpapi.h>
@@ -41,6 +42,8 @@
#endif
#endif
+using Platform::Log;
+using Platform::LogLevel;
// welp
#ifndef PCAP_OPENFLAG_PROMISCUOUS
@@ -136,14 +139,14 @@ bool Init(bool open_adapter)
continue;
}
- printf("PCap: lib %s, init successful\n", PCapLibNames[i]);
+ Log(LogLevel::Info, "PCap: lib %s, init successful\n", PCapLibNames[i]);
PCapLib = lib;
break;
}
if (PCapLib == NULL)
{
- printf("PCap: init failed\n");
+ Log(LogLevel::Error, "PCap: init failed\n");
return false;
}
}
@@ -155,7 +158,7 @@ bool Init(bool open_adapter)
ret = pcap_findalldevs(&alldevs, errbuf);
if (ret < 0 || alldevs == NULL)
{
- printf("PCap: no devices available\n");
+ Log(LogLevel::Warn, "PCap: no devices available\n");
return false;
}
@@ -202,7 +205,7 @@ bool Init(bool open_adapter)
}
if (uret != ERROR_SUCCESS)
{
- printf("GetAdaptersAddresses() shat itself: %08X\n", uret);
+ Log(LogLevel::Error, "GetAdaptersAddresses() shat itself: %08X\n", uret);
return false;
}
@@ -226,7 +229,7 @@ bool Init(bool open_adapter)
if (addr->PhysicalAddressLength != 6)
{
- printf("weird MAC addr length %d for %s\n", addr->PhysicalAddressLength, addr->AdapterName);
+ Log(LogLevel::Warn, "weird MAC addr length %d for %s\n", addr->PhysicalAddressLength, addr->AdapterName);
}
else
memcpy(adata->MAC, addr->PhysicalAddress, 6);
@@ -255,7 +258,7 @@ bool Init(bool open_adapter)
struct ifaddrs* addrs;
if (getifaddrs(&addrs) != 0)
{
- printf("getifaddrs() shat itself :(\n");
+ Log(LogLevel::Error, "getifaddrs() shat itself :(\n");
return false;
}
@@ -273,7 +276,7 @@ bool Init(bool open_adapter)
if (!curaddr->ifa_addr)
{
- printf("Device (%s) does not have an address :/\n", curaddr->ifa_name);
+ Log(LogLevel::Error, "Device (%s) does not have an address :/\n", curaddr->ifa_name);
curaddr = curaddr->ifa_next;
continue;
}
@@ -289,7 +292,7 @@ bool Init(bool open_adapter)
{
struct sockaddr_ll* sa = (sockaddr_ll*)curaddr->ifa_addr;
if (sa->sll_halen != 6)
- printf("weird MAC length %d for %s\n", sa->sll_halen, curaddr->ifa_name);
+ Log(LogLevel::Warn, "weird MAC length %d for %s\n", sa->sll_halen, curaddr->ifa_name);
else
memcpy(adata->MAC, sa->sll_addr, 6);
}
@@ -298,7 +301,7 @@ bool Init(bool open_adapter)
{
struct sockaddr_dl* sa = (sockaddr_dl*)curaddr->ifa_addr;
if (sa->sdl_alen != 6)
- printf("weird MAC length %d for %s\n", sa->sdl_alen, curaddr->ifa_name);
+ Log(LogLevel::Warn, "weird MAC length %d for %s\n", sa->sdl_alen, curaddr->ifa_name);
else
memcpy(adata->MAC, LLADDR(sa), 6);
}
@@ -326,7 +329,7 @@ bool Init(bool open_adapter)
PCapAdapter = pcap_open_live(dev->name, 2048, PCAP_OPENFLAG_PROMISCUOUS, 1, errbuf);
if (!PCapAdapter)
{
- printf("PCap: failed to open adapter %s\n", errbuf);
+ Log(LogLevel::Error, "PCap: failed to open adapter %s\n", errbuf);
return false;
}
@@ -334,7 +337,7 @@ bool Init(bool open_adapter)
if (pcap_setnonblock(PCapAdapter, 1, errbuf) < 0)
{
- printf("PCap: failed to set nonblocking mode\n");
+ Log(LogLevel::Error, "PCap: failed to set nonblocking mode\n");
pcap_close(PCapAdapter); PCapAdapter = NULL;
return false;
}
@@ -376,7 +379,7 @@ int SendPacket(u8* data, int len)
if (len > 2048)
{
- printf("LAN_SendPacket: error: packet too long (%d)\n", len);
+ Log(LogLevel::Error, "LAN_SendPacket: error: packet too long (%d)\n", len);
return 0;
}
diff --git a/src/frontend/qt_sdl/LocalMP.cpp b/src/frontend/qt_sdl/LocalMP.cpp
index fb7ef7a..31801b7 100644
--- a/src/frontend/qt_sdl/LocalMP.cpp
+++ b/src/frontend/qt_sdl/LocalMP.cpp
@@ -36,7 +36,10 @@
#include "Config.h"
#include "LocalMP.h"
+#include "Platform.h"
+using Platform::Log;
+using Platform::LogLevel;
namespace LocalMP
{
@@ -239,10 +242,10 @@ bool Init()
if (!MPQueue->attach())
{
- printf("MP sharedmem doesn't exist. creating\n");
+ Log(LogLevel::Info, "MP sharedmem doesn't exist. creating\n");
if (!MPQueue->create(kQueueSize))
{
- printf("MP sharedmem create failed :(\n");
+ Log(LogLevel::Error, "MP sharedmem create failed :(\n");
return false;
}
@@ -285,7 +288,7 @@ bool Init()
LastHostID = -1;
- printf("MP comm init OK, instance ID %d\n", InstanceID);
+ Log(LogLevel::Info, "MP comm init OK, instance ID %d\n", InstanceID);
RecvTimeout = 25;
@@ -478,7 +481,7 @@ int RecvPacketGeneric(u8* packet, bool block, u64* timestamp)
if (pktheader.Magic != 0x4946494E)
{
- printf("PACKET FIFO OVERFLOW\n");
+ Log(LogLevel::Warn, "PACKET FIFO OVERFLOW\n");
PacketReadOffset = header->PacketWriteOffset;
SemReset(InstanceID);
MPQueue->unlock();
@@ -590,7 +593,7 @@ u16 RecvReplies(u8* packets, u64 timestamp, u16 aidmask)
if (pktheader.Magic != 0x4946494E)
{
- printf("REPLY FIFO OVERFLOW\n");
+ Log(LogLevel::Warn, "REPLY FIFO OVERFLOW\n");
ReplyReadOffset = header->ReplyWriteOffset;
SemReset(16+InstanceID);
MPQueue->unlock();
diff --git a/src/frontend/qt_sdl/Platform.cpp b/src/frontend/qt_sdl/Platform.cpp
index f9eaf42..6b48335 100644
--- a/src/frontend/qt_sdl/Platform.cpp
+++ b/src/frontend/qt_sdl/Platform.cpp
@@ -60,10 +60,10 @@ void IPCInit()
if (!IPCBuffer->attach())
{
- printf("IPC sharedmem doesn't exist. creating\n");
+ Log(LogLevel::Info, "IPC sharedmem doesn't exist. creating\n");
if (!IPCBuffer->create(1024))
{
- printf("IPC sharedmem create failed :(\n");
+ Log(LogLevel::Error, "IPC sharedmem create failed :(\n");
delete IPCBuffer;
IPCBuffer = nullptr;
return;
@@ -88,7 +88,7 @@ void IPCInit()
}
IPCBuffer->unlock();
- printf("IPC: instance ID %d\n", IPCInstanceID);
+ Log(LogLevel::Info, "IPC: instance ID %d\n", IPCInstanceID);
}
void IPCDeInit()
@@ -349,6 +349,17 @@ FILE* OpenLocalFile(std::string path, std::string mode)
return OpenFile(fullpath.toStdString(), mode, mode[0] != 'w');
}
+void Log(LogLevel level, const char* fmt, ...)
+{
+ if (fmt == nullptr)
+ return;
+
+ va_list args;
+ va_start(args, fmt);
+ vprintf(fmt, args);
+ va_end(args);
+}
+
Thread* Thread_Create(std::function<void()> func)
{
QThread* t = QThread::create(func);
diff --git a/src/frontend/qt_sdl/SaveManager.cpp b/src/frontend/qt_sdl/SaveManager.cpp
index d9e2138..31d2a68 100644
--- a/src/frontend/qt_sdl/SaveManager.cpp
+++ b/src/frontend/qt_sdl/SaveManager.cpp
@@ -22,6 +22,8 @@
#include "SaveManager.h"
#include "Platform.h"
+using Platform::Log;
+using Platform::LogLevel;
SaveManager::SaveManager(std::string path) : QThread()
{
@@ -122,7 +124,7 @@ void SaveManager::CheckFlush()
SecondaryBufferLock->lock();
- printf("SaveManager: Flush requested\n");
+ Log(LogLevel::Info, "SaveManager: Flush requested\n");
if (SecondaryBufferLength != Length)
{
@@ -178,7 +180,7 @@ void SaveManager::FlushSecondaryBuffer(u8* dst, u32 dstLength)
FILE* f = Platform::OpenFile(Path, "wb");
if (f)
{
- printf("SaveManager: Written\n");
+ Log(LogLevel::Info, "SaveManager: Written\n");
fwrite(SecondaryBuffer, SecondaryBufferLength, 1, f);
fclose(f);
}
diff --git a/src/frontend/qt_sdl/TitleManagerDialog.cpp b/src/frontend/qt_sdl/TitleManagerDialog.cpp
index 7b54313..72d19ec 100644
--- a/src/frontend/qt_sdl/TitleManagerDialog.cpp
+++ b/src/frontend/qt_sdl/TitleManagerDialog.cpp
@@ -30,6 +30,8 @@
#include "ui_TitleManagerDialog.h"
#include "ui_TitleImportDialog.h"
+using Platform::Log;
+using Platform::LogLevel;
bool TitleManagerDialog::NANDInited = false;
TitleManagerDialog* TitleManagerDialog::currentDlg = nullptr;
@@ -262,7 +264,7 @@ void TitleManagerDialog::onImportTitleData()
QListWidgetItem* cur = ui->lstTitleList->currentItem();
if (!cur)
{
- printf("what??\n");
+ Log(LogLevel::Error, "what??\n");
return;
}
@@ -283,7 +285,7 @@ void TitleManagerDialog::onImportTitleData()
wantedsize = cur->data(Qt::UserRole+3).toUInt();
break;
default:
- printf("what??\n");
+ Log(LogLevel::Warn, "what??\n");
return;
}
@@ -332,7 +334,7 @@ void TitleManagerDialog::onExportTitleData()
QListWidgetItem* cur = ui->lstTitleList->currentItem();
if (!cur)
{
- printf("what??\n");
+ Log(LogLevel::Error, "what??\n");
return;
}
@@ -357,7 +359,7 @@ void TitleManagerDialog::onExportTitleData()
wantedsize = cur->data(Qt::UserRole+3).toUInt();
break;
default:
- printf("what??\n");
+ Log(LogLevel::Warn, "what??\n");
return;
}