aboutsummaryrefslogtreecommitdiff
path: root/src/NDS.cpp
diff options
context:
space:
mode:
authorJesse Talavera-Greenberg <jesse@jesse.tg>2023-08-18 16:50:57 -0400
committerGitHub <noreply@github.com>2023-08-18 22:50:57 +0200
commitee5567708630441d8d3210e81d6e03d028fb7bbd (patch)
treeab92234123b16ec414d6c0da9bb0716c1b798229 /src/NDS.cpp
parentf454eba3c3243b095f0e6b9ddde3e68b095c5d8d (diff)
Assorted portability enhancements (#1800)
* Introduce some Platform calls for managing dynamic libraries * Add Platform::WriteFATSectors * Introduce some Platform calls for managing dynamic libraries * Add Platform::WriteFATSectors * Change includes of "../types.h" to "types.h" - Makes it easier to directly include these headers in downstream projects * Change an include of "../Wifi.h" to "Wifi.h" * Allow CommonFuncs.cpp to compile on Android * Tidy up some logging calls - Use Platform::Log in LAN_Socket.cpp - Soften some warnings to Debug logs (since they don't necessarily represent problems) * Add Platform::EnterGBAMode - Gracefully stop the emulator if trying to enter GBA mode * Soften some logs that most players won't care about * Soften some more logs * Introduce Platform wrappers for file operations * Fix pointer spacing * Fix more style nits * Log the errno when ftruncate fails * Fix FileSeek offset argument - With an s32 offset, we couldn't access files larger than 2GB * Revise Platform::StopEmu to address feedback - Remove Platform::EnterGBAMode in favor of adding a reason to Platform::StopEmu - Also rename Platform::StopEmu to Platform::SignalStop - Add an optional argument to NDS::Stop - Use the new argument everywhere that the console stops itself * Rename FileGetString to FileReadLine - It conveys the meaning better * Rename FileSeekOrigin::Set to Start - It conveys the meaning better * Change definition of FileGetString to FileReadLine - Oops, almost forgot it * Rename FlushFile to FileFlush - To remain consistent with the other File functions * Add a FileType usage * Fix line break in FileSeekOrigin * Document Platform::DeInit * Clarify that StopReason::Unknown doesn't always mean an error * Move and document FileType::HostFile * Remove Platform::OpenDataFile - Nothing currently uses it * Refactor Platform::OpenFile and Platform::OpenLocalFile to accept a FileMode enum instead of a string - The enum is converted to fopen flags under the hood - The file type is used to decide whether to add the "b" flag - Some helper functions are exposed for the benefit of consistent behavior among frontends - Equivalent behavior is maintained * Fix a tab that should be spaces * Use Windows' 64-bit implementations of fseek/ftell * Move Platform::IsBinaryFile to Platform.cpp - It could vary by frontend * Remove an unused FileType * Rename an enum constant * Document various Platform items * Use Platform::DynamicLibrary to load libandroid - And clean it up at the end * Fix a typo * Pass the correct filetype to FATStorage - Since it can be used for DSI NAND images or for SD cards * Remove Platform::FileType
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]);
}
}