3DS: Clean up legacy initialization (fixes #1768)

This commit is contained in:
Vicki Pfau 2020-05-30 19:27:23 -07:00
parent 42fdc758d7
commit 5e5627db54
4 changed files with 13 additions and 85 deletions

View File

@ -40,6 +40,7 @@ Other fixes:
- Qt: Force OpenGL paint engine creation thread (fixes mgba.io/i/1642) - Qt: Force OpenGL paint engine creation thread (fixes mgba.io/i/1642)
- Qt: Fix OpenGL 2.1 support (fixes mgba.io/i/1678) - Qt: Fix OpenGL 2.1 support (fixes mgba.io/i/1678)
Misc: Misc:
- 3DS: Clean up legacy initialization (fixes mgba.io/i/1768)
- Debugger: Keep track of global cycle count - Debugger: Keep track of global cycle count
- FFmpeg: Add looping option for GIF/APNG - FFmpeg: Add looping option for GIF/APNG
- GBA Serialize: Only flunk BIOS check if official BIOS was expected - GBA Serialize: Only flunk BIOS check if official BIOS was expected

View File

@ -1,92 +1,31 @@
/* This code is mostly from ctrulib, which contains the following license: /* Copyright (c) 2013-2020 Jeffrey Pfau
*
This software is provided 'as-is', without any express or implied * This Source Code Form is subject to the terms of the Mozilla Public
warranty. In no event will the authors be held liable for any damages * License, v. 2.0. If a copy of the MPL was not distributed with this
arising from the use of this software. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
* The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software in
a product, an acknowledgment in the product documentation would be
appreciated but is not required.
* Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
* This notice may not be removed or altered from any source distribution.
*/
#include <3ds/archive.h> #include <3ds/archive.h>
#include <3ds/types.h>
#include <3ds/srv.h>
#include <3ds/gfx.h>
#include <3ds/services/apt.h>
#include <3ds/services/fs.h>
#include <3ds/services/hid.h>
#include <3ds/svc.h>
#include <mgba-util/common.h> #include <mgba-util/common.h>
extern char* fake_heap_start; u32 __ctru_heap_size = 0x02400000;
extern char* fake_heap_end; u32 __ctru_linear_heap_size = 0x01400000;
extern u32 __ctru_linear_heap;
extern u32 __ctru_heap;
extern u32 __ctru_heap_size;
extern u32 __ctru_linear_heap_size;
static u32 __custom_heap_size = 0x02400000;
static u32 __custom_linear_heap_size = 0x01400000;
uint32_t* romBuffer = NULL; uint32_t* romBuffer = NULL;
size_t romBufferSize; size_t romBufferSize;
FS_Archive sdmcArchive; FS_Archive sdmcArchive;
bool allocateRomBuffer(void) { __attribute__((constructor)) static void init(void) {
if (romBuffer) { FSUSER_OpenArchive(&sdmcArchive, ARCHIVE_SDMC, fsMakePath(PATH_EMPTY, ""));
return true;
}
romBuffer = malloc(0x02000000); romBuffer = malloc(0x02000000);
if (romBuffer) { if (romBuffer) {
romBufferSize = 0x02000000; romBufferSize = 0x02000000;
return true; return;
} }
romBuffer = malloc(0x01000000); romBuffer = malloc(0x01000000);
if (romBuffer) { if (romBuffer) {
romBufferSize = 0x01000000; romBufferSize = 0x01000000;
return true; return;
} }
return false;
}
void __system_allocateHeaps() {
u32 tmp=0;
__ctru_heap_size = __custom_heap_size;
__ctru_linear_heap_size = __custom_linear_heap_size;
// Allocate the application heap
__ctru_heap = 0x08000000;
svcControlMemory(&tmp, __ctru_heap, 0x0, __ctru_heap_size, MEMOP_ALLOC, MEMPERM_READ | MEMPERM_WRITE);
// Allocate the linear heap
svcControlMemory(&__ctru_linear_heap, 0x0, 0x0, __ctru_linear_heap_size, MEMOP_ALLOC_LINEAR, MEMPERM_READ | MEMPERM_WRITE);
// Set up newlib heap
fake_heap_start = (char*)__ctru_heap;
fake_heap_end = fake_heap_start + __ctru_heap_size;
}
void __appInit(void) {
// Initialize services
srvInit();
aptInit();
hidInit();
fsInit();
archiveMountSdmc();
FSUSER_OpenArchive(&sdmcArchive, ARCHIVE_SDMC, fsMakePath(PATH_EMPTY, ""));
allocateRomBuffer();
} }

View File

@ -109,8 +109,6 @@ static bool sgbCrop = false;
static aptHookCookie cookie; static aptHookCookie cookie;
static bool core2; static bool core2;
extern bool allocateRomBuffer(void);
static bool _initGpu(void) { static bool _initGpu(void) {
if (!C3D_Init(C3D_DEFAULT_CMDBUF_SIZE)) { if (!C3D_Init(C3D_DEFAULT_CMDBUF_SIZE)) {
return false; return false;
@ -809,10 +807,6 @@ int main() {
camera.bufferSize = 0; camera.bufferSize = 0;
camera.cam = SELECT_IN1; camera.cam = SELECT_IN1;
if (!allocateRomBuffer()) {
return 1;
}
aptHook(&cookie, _aptHook, 0); aptHook(&cookie, _aptHook, 0);
ptmuInit(); ptmuInit();

View File

@ -58,9 +58,6 @@ struct PerfOpts {
bool server; bool server;
}; };
#ifdef _3DS
extern bool allocateRomBuffer(void);
#endif
#ifdef __SWITCH__ #ifdef __SWITCH__
TimeType __nx_time_type = TimeType_LocalSystemClock; TimeType __nx_time_type = TimeType_LocalSystemClock;
#endif #endif
@ -84,9 +81,6 @@ int main(int argc, char** argv) {
gfxInitDefault(); gfxInitDefault();
osSetSpeedupEnable(true); osSetSpeedupEnable(true);
consoleInit(GFX_BOTTOM, NULL); consoleInit(GFX_BOTTOM, NULL);
if (!allocateRomBuffer()) {
return 1;
}
#elif defined(__SWITCH__) #elif defined(__SWITCH__)
UNUSED(_mPerfShutdown); UNUSED(_mPerfShutdown);
consoleInit(NULL); consoleInit(NULL);