aboutsummaryrefslogtreecommitdiff
path: root/src/NDS.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/NDS.cpp')
-rw-r--r--src/NDS.cpp100
1 files changed, 66 insertions, 34 deletions
diff --git a/src/NDS.cpp b/src/NDS.cpp
index 5caaaee..b329c10 100644
--- a/src/NDS.cpp
+++ b/src/NDS.cpp
@@ -45,8 +45,7 @@
#include "DSi_Camera.h"
#include "DSi_DSP.h"
-using Platform::Log;
-using Platform::LogLevel;
+using namespace Platform;
namespace NDS
{
@@ -509,7 +508,7 @@ void SetupDirectBoot(const std::string& romname)
void Reset()
{
- FILE* f;
+ Platform::FileHandle* f;
u32 i;
#ifdef JIT_ENABLED
@@ -527,7 +526,7 @@ void Reset()
if (Platform::GetConfigBool(Platform::ExternalBIOSEnable))
{
- f = Platform::OpenLocalFile(Platform::GetConfigString(Platform::BIOS9Path), "rb");
+ f = Platform::OpenLocalFile(Platform::GetConfigString(Platform::BIOS9Path), FileMode::Read);
if (!f)
{
Log(LogLevel::Warn, "ARM9 BIOS not found\n");
@@ -537,14 +536,14 @@ void Reset()
}
else
{
- fseek(f, 0, SEEK_SET);
- fread(ARM9BIOS, 0x1000, 1, f);
+ FileRewind(f);
+ FileRead(ARM9BIOS, 0x1000, 1, f);
Log(LogLevel::Info, "ARM9 BIOS loaded\n");
- fclose(f);
+ Platform::CloseFile(f);
}
- f = Platform::OpenLocalFile(Platform::GetConfigString(Platform::BIOS7Path), "rb");
+ f = Platform::OpenLocalFile(Platform::GetConfigString(Platform::BIOS7Path), FileMode::Read);
if (!f)
{
Log(LogLevel::Warn, "ARM7 BIOS not found\n");
@@ -554,11 +553,11 @@ void Reset()
}
else
{
- fseek(f, 0, SEEK_SET);
- fread(ARM7BIOS, 0x4000, 1, f);
+ FileRewind(f);
+ FileRead(ARM7BIOS, 0x4000, 1, f);
Log(LogLevel::Info, "ARM7 BIOS loaded\n");
- fclose(f);
+ Platform::CloseFile(f);
}
}
else
@@ -694,11 +693,44 @@ void Start()
Running = true;
}
-void Stop()
+static const char* StopReasonName(Platform::StopReason reason)
{
- Log(LogLevel::Info, "Stopping: shutdown\n");
+ switch (reason)
+ {
+ case Platform::StopReason::External:
+ return "External";
+ case Platform::StopReason::PowerOff:
+ return "PowerOff";
+ case Platform::StopReason::GBAModeNotSupported:
+ return "GBAModeNotSupported";
+ case Platform::StopReason::BadExceptionRegion:
+ return "BadExceptionRegion";
+ default:
+ return "Unknown";
+ }
+}
+
+void Stop(Platform::StopReason reason)
+{
+ Platform::LogLevel level;
+ switch (reason)
+ {
+ case Platform::StopReason::External:
+ case Platform::StopReason::PowerOff:
+ level = LogLevel::Info;
+ break;
+ case Platform::StopReason::GBAModeNotSupported:
+ case Platform::StopReason::BadExceptionRegion:
+ level = LogLevel::Error;
+ break;
+ default:
+ level = LogLevel::Warn;
+ break;
+ }
+
+ Log(level, "Stopping emulated console (Reason: %s)\n", StopReasonName(reason));
Running = false;
- Platform::StopEmu();
+ Platform::SignalStop(reason);
GPU::Stop();
SPU::Stop();
@@ -2105,7 +2137,7 @@ u8 ARM9Read8(u32 addr)
return GBACart::SRAMRead(addr);
}
- Log(LogLevel::Warn, "unknown arm9 read8 %08X\n", addr);
+ Log(LogLevel::Debug, "unknown arm9 read8 %08X\n", addr);
return 0;
}
@@ -2272,7 +2304,7 @@ void ARM9Write8(u32 addr, u8 val)
return;
}
- Log(LogLevel::Warn, "unknown arm9 write8 %08X %02X\n", addr, val);
+ Log(LogLevel::Debug, "unknown arm9 write8 %08X %02X\n", addr, val);
}
void ARM9Write16(u32 addr, u16 val)
@@ -2504,7 +2536,7 @@ u8 ARM7Read8(u32 addr)
return GBACart::SRAMRead(addr);
}
- Log(LogLevel::Warn, "unknown arm7 read8 %08X %08X %08X/%08X\n", addr, ARM7->R[15], ARM7->R[0], ARM7->R[1]);
+ Log(LogLevel::Debug, "unknown arm7 read8 %08X %08X %08X/%08X\n", addr, ARM7->R[15], ARM7->R[0], ARM7->R[1]);
return 0;
}
@@ -2570,7 +2602,7 @@ u16 ARM7Read16(u32 addr)
(GBACart::SRAMRead(addr+1) << 8);
}
- Log(LogLevel::Warn, "unknown arm7 read16 %08X %08X\n", addr, ARM7->R[15]);
+ Log(LogLevel::Debug, "unknown arm7 read16 %08X %08X\n", addr, ARM7->R[15]);
return 0;
}
@@ -2707,7 +2739,7 @@ void ARM7Write8(u32 addr, u8 val)
//if (ARM7->R[15] > 0x00002F30) // ARM7 BIOS bug
if (addr >= 0x01000000)
- Log(LogLevel::Warn, "unknown arm7 write8 %08X %02X @ %08X\n", addr, val, ARM7->R[15]);
+ Log(LogLevel::Debug, "unknown arm7 write8 %08X %02X @ %08X\n", addr, val, ARM7->R[15]);
}
void ARM7Write16(u32 addr, u16 val)
@@ -2787,7 +2819,7 @@ void ARM7Write16(u32 addr, u16 val)
}
if (addr >= 0x01000000)
- Log(LogLevel::Warn, "unknown arm7 write16 %08X %04X @ %08X\n", addr, val, ARM7->R[15]);
+ Log(LogLevel::Debug, "unknown arm7 write16 %08X %04X @ %08X\n", addr, val, ARM7->R[15]);
}
void ARM7Write32(u32 addr, u32 val)
@@ -2871,7 +2903,7 @@ void ARM7Write32(u32 addr, u32 val)
}
if (addr >= 0x01000000)
- Log(LogLevel::Warn, "unknown arm7 write32 %08X %08X @ %08X\n", addr, val, ARM7->R[15]);
+ Log(LogLevel::Debug, "unknown arm7 write32 %08X %08X @ %08X\n", addr, val, ARM7->R[15]);
}
bool ARM7GetMemRegion(u32 addr, bool write, MemRegion* region)
@@ -3032,7 +3064,7 @@ u8 ARM9IORead8(u32 addr)
}
if ((addr & 0xFFFFF000) != 0x04004000)
- Log(LogLevel::Warn, "unknown ARM9 IO read8 %08X %08X\n", addr, ARM9->R[15]);
+ Log(LogLevel::Debug, "unknown ARM9 IO read8 %08X %08X\n", addr, ARM9->R[15]);
return 0;
}
@@ -3179,7 +3211,7 @@ u16 ARM9IORead16(u32 addr)
}
if ((addr & 0xFFFFF000) != 0x04004000)
- Log(LogLevel::Warn, "unknown ARM9 IO read16 %08X %08X\n", addr, ARM9->R[15]);
+ Log(LogLevel::Debug, "unknown ARM9 IO read16 %08X %08X\n", addr, ARM9->R[15]);
return 0;
}
@@ -3323,7 +3355,7 @@ u32 ARM9IORead32(u32 addr)
}
if ((addr & 0xFFFFF000) != 0x04004000)
- Log(LogLevel::Warn, "unknown ARM9 IO read32 %08X %08X\n", addr, ARM9->R[15]);
+ Log(LogLevel::Debug, "unknown ARM9 IO read32 %08X %08X\n", addr, ARM9->R[15]);
return 0;
}
@@ -3404,7 +3436,7 @@ void ARM9IOWrite8(u32 addr, u8 val)
return;
}
- Log(LogLevel::Warn, "unknown ARM9 IO write8 %08X %02X %08X\n", addr, val, ARM9->R[15]);
+ Log(LogLevel::Debug, "unknown ARM9 IO write8 %08X %02X %08X\n", addr, val, ARM9->R[15]);
}
void ARM9IOWrite16(u32 addr, u16 val)
@@ -3588,7 +3620,7 @@ void ARM9IOWrite16(u32 addr, u16 val)
return;
}
- Log(LogLevel::Warn, "unknown ARM9 IO write16 %08X %04X %08X\n", addr, val, ARM9->R[15]);
+ Log(LogLevel::Debug, "unknown ARM9 IO write16 %08X %04X %08X\n", addr, val, ARM9->R[15]);
}
void ARM9IOWrite32(u32 addr, u32 val)
@@ -3786,7 +3818,7 @@ void ARM9IOWrite32(u32 addr, u32 val)
return;
}
- Log(LogLevel::Warn, "unknown ARM9 IO write32 %08X %08X %08X\n", addr, val, ARM9->R[15]);
+ Log(LogLevel::Debug, "unknown ARM9 IO write32 %08X %08X %08X\n", addr, val, ARM9->R[15]);
}
@@ -3860,7 +3892,7 @@ u8 ARM7IORead8(u32 addr)
}
if ((addr & 0xFFFFF000) != 0x04004000)
- Log(LogLevel::Warn, "unknown ARM7 IO read8 %08X %08X\n", addr, ARM7->R[15]);
+ Log(LogLevel::Debug, "unknown ARM7 IO read8 %08X %08X\n", addr, ARM7->R[15]);
return 0;
}
@@ -3954,7 +3986,7 @@ u16 ARM7IORead16(u32 addr)
}
if ((addr & 0xFFFFF000) != 0x04004000)
- Log(LogLevel::Warn, "unknown ARM7 IO read16 %08X %08X\n", addr, ARM7->R[15]);
+ Log(LogLevel::Debug, "unknown ARM7 IO read16 %08X %08X\n", addr, ARM7->R[15]);
return 0;
}
@@ -4055,7 +4087,7 @@ u32 ARM7IORead32(u32 addr)
}
if ((addr & 0xFFFFF000) != 0x04004000)
- Log(LogLevel::Warn, "unknown ARM7 IO read32 %08X %08X\n", addr, ARM7->R[15]);
+ Log(LogLevel::Debug, "unknown ARM7 IO read32 %08X %08X\n", addr, ARM7->R[15]);
return 0;
}
@@ -4121,7 +4153,7 @@ void ARM7IOWrite8(u32 addr, u8 val)
case 0x04000301:
val &= 0xC0;
- if (val == 0x40) Log(LogLevel::Warn, "!! GBA MODE NOT SUPPORTED\n");
+ if (val == 0x40) Stop(StopReason::GBAModeNotSupported);
else if (val == 0x80) ARM7->Halt(1);
else if (val == 0xC0) EnterSleepMode();
return;
@@ -4133,7 +4165,7 @@ void ARM7IOWrite8(u32 addr, u8 val)
return;
}
- Log(LogLevel::Warn, "unknown ARM7 IO write8 %08X %02X %08X\n", addr, val, ARM7->R[15]);
+ Log(LogLevel::Debug, "unknown ARM7 IO write8 %08X %02X %08X\n", addr, val, ARM7->R[15]);
}
void ARM7IOWrite16(u32 addr, u16 val)
@@ -4288,7 +4320,7 @@ void ARM7IOWrite16(u32 addr, u16 val)
return;
}
- Log(LogLevel::Warn, "unknown ARM7 IO write16 %08X %04X %08X\n", addr, val, ARM7->R[15]);
+ Log(LogLevel::Debug, "unknown ARM7 IO write16 %08X %04X %08X\n", addr, val, ARM7->R[15]);
}
void ARM7IOWrite32(u32 addr, u32 val)
@@ -4422,7 +4454,7 @@ void ARM7IOWrite32(u32 addr, u32 val)
return;
}
- Log(LogLevel::Warn, "unknown ARM7 IO write32 %08X %08X %08X\n", addr, val, ARM7->R[15]);
+ Log(LogLevel::Debug, "unknown ARM7 IO write32 %08X %08X %08X\n", addr, val, ARM7->R[15]);
}
}