mirror of
https://github.com/melonDS-emu/melonDS.git
synced 2025-07-21 05:09:46 -06:00
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
This commit is contained in:

committed by
GitHub

parent
f454eba3c3
commit
ee55677086
39
src/DSi.cpp
39
src/DSi.cpp
@ -43,8 +43,7 @@
|
||||
|
||||
#include "tiny-AES-c/aes.hpp"
|
||||
|
||||
using Platform::Log;
|
||||
using Platform::LogLevel;
|
||||
using namespace Platform;
|
||||
|
||||
namespace DSi
|
||||
{
|
||||
@ -719,13 +718,13 @@ void SoftReset()
|
||||
|
||||
bool LoadBIOS()
|
||||
{
|
||||
FILE* f;
|
||||
Platform::FileHandle* f;
|
||||
u32 i;
|
||||
|
||||
memset(ARM9iBIOS, 0, 0x10000);
|
||||
memset(ARM7iBIOS, 0, 0x10000);
|
||||
|
||||
f = Platform::OpenLocalFile(Platform::GetConfigString(Platform::DSi_BIOS9Path), "rb");
|
||||
f = Platform::OpenLocalFile(Platform::GetConfigString(Platform::DSi_BIOS9Path), FileMode::Read);
|
||||
if (!f)
|
||||
{
|
||||
Log(LogLevel::Warn, "ARM9i BIOS not found\n");
|
||||
@ -735,14 +734,14 @@ bool LoadBIOS()
|
||||
}
|
||||
else
|
||||
{
|
||||
fseek(f, 0, SEEK_SET);
|
||||
fread(ARM9iBIOS, 0x10000, 1, f);
|
||||
FileRewind(f);
|
||||
FileRead(ARM9iBIOS, 0x10000, 1, f);
|
||||
|
||||
Log(LogLevel::Info, "ARM9i BIOS loaded\n");
|
||||
fclose(f);
|
||||
Platform::CloseFile(f);
|
||||
}
|
||||
|
||||
f = Platform::OpenLocalFile(Platform::GetConfigString(Platform::DSi_BIOS7Path), "rb");
|
||||
f = Platform::OpenLocalFile(Platform::GetConfigString(Platform::DSi_BIOS7Path), FileMode::Read);
|
||||
if (!f)
|
||||
{
|
||||
Log(LogLevel::Warn, "ARM7i BIOS not found\n");
|
||||
@ -754,11 +753,11 @@ bool LoadBIOS()
|
||||
{
|
||||
// TODO: check if the first 32 bytes are crapoed
|
||||
|
||||
fseek(f, 0, SEEK_SET);
|
||||
fread(ARM7iBIOS, 0x10000, 1, f);
|
||||
FileRewind(f);
|
||||
FileRead(ARM7iBIOS, 0x10000, 1, f);
|
||||
|
||||
Log(LogLevel::Info, "ARM7i BIOS loaded\n");
|
||||
fclose(f);
|
||||
CloseFile(f);
|
||||
}
|
||||
|
||||
if (!Platform::GetConfigBool(Platform::DSi_FullBIOSBoot))
|
||||
@ -785,7 +784,7 @@ bool LoadNAND()
|
||||
return false;
|
||||
}
|
||||
|
||||
FILE* nand = DSi_NAND::GetFile();
|
||||
FileHandle* nand = DSi_NAND::GetFile();
|
||||
|
||||
// Make sure NWRAM is accessible.
|
||||
// The Bits are set to the startup values in Reset() and we might
|
||||
@ -829,8 +828,8 @@ bool LoadNAND()
|
||||
}
|
||||
else
|
||||
{
|
||||
fseek(nand, 0x220, SEEK_SET);
|
||||
fread(bootparams, 4, 8, nand);
|
||||
FileSeek(nand, 0x220, FileSeekOrigin::Start);
|
||||
FileRead(bootparams, 4, 8, nand);
|
||||
|
||||
Log(LogLevel::Debug, "ARM9: offset=%08X size=%08X RAM=%08X size_aligned=%08X\n",
|
||||
bootparams[0], bootparams[1], bootparams[2], bootparams[3]);
|
||||
@ -843,8 +842,8 @@ bool LoadNAND()
|
||||
MBK[1][8] = 0;
|
||||
|
||||
u32 mbk[12];
|
||||
fseek(nand, 0x380, SEEK_SET);
|
||||
fread(mbk, 4, 12, nand);
|
||||
FileSeek(nand, 0x380, FileSeekOrigin::Start);
|
||||
FileRead(mbk, 4, 12, nand);
|
||||
|
||||
MapNWRAM_A(0, mbk[0] & 0xFF);
|
||||
MapNWRAM_A(1, (mbk[0] >> 8) & 0xFF);
|
||||
@ -898,12 +897,12 @@ bool LoadNAND()
|
||||
|
||||
AES_init_ctx_iv(&ctx, boot2key, boot2iv);
|
||||
|
||||
fseek(nand, bootparams[0], SEEK_SET);
|
||||
FileSeek(nand, bootparams[0], FileSeekOrigin::Start);
|
||||
dstaddr = bootparams[2];
|
||||
for (u32 i = 0; i < bootparams[3]; i += 16)
|
||||
{
|
||||
u8 data[16];
|
||||
fread(data, 16, 1, nand);
|
||||
FileRead(data, 16, 1, nand);
|
||||
|
||||
for (int j = 0; j < 16; j++) tmp[j] = data[15-j];
|
||||
AES_CTR_xcrypt_buffer(&ctx, tmp, 16);
|
||||
@ -923,12 +922,12 @@ bool LoadNAND()
|
||||
|
||||
AES_init_ctx_iv(&ctx, boot2key, boot2iv);
|
||||
|
||||
fseek(nand, bootparams[4], SEEK_SET);
|
||||
FileSeek(nand, bootparams[4], FileSeekOrigin::Start);
|
||||
dstaddr = bootparams[6];
|
||||
for (u32 i = 0; i < bootparams[7]; i += 16)
|
||||
{
|
||||
u8 data[16];
|
||||
fread(data, 16, 1, nand);
|
||||
FileRead(data, 16, 1, nand);
|
||||
|
||||
for (int j = 0; j < 16; j++) tmp[j] = data[15-j];
|
||||
AES_CTR_xcrypt_buffer(&ctx, tmp, 16);
|
||||
|
Reference in New Issue
Block a user