all repos — mgba @ 5e5627db5474f67fcfca31b9d582747112762e2c

mGBA Game Boy Advance Emulator

3DS: Clean up legacy initialization (fixes #1768)
Vicki Pfau vi@endrift.com
Sat, 30 May 2020 19:27:23 -0700
commit

5e5627db5474f67fcfca31b9d582747112762e2c

parent

42fdc758d788e7608688715f74047e419d9cf9c5

4 files changed, 13 insertions(+), 85 deletions(-)

jump to
M CHANGESCHANGES

@@ -40,6 +40,7 @@ - Debugger: Don't skip undefined instructions when debugger attached

- Qt: Force OpenGL paint engine creation thread (fixes mgba.io/i/1642) - Qt: Fix OpenGL 2.1 support (fixes mgba.io/i/1678) Misc: + - 3DS: Clean up legacy initialization (fixes mgba.io/i/1768) - Debugger: Keep track of global cycle count - FFmpeg: Add looping option for GIF/APNG - GBA Serialize: Only flunk BIOS check if official BIOS was expected
M src/platform/3ds/ctru-heap.csrc/platform/3ds/ctru-heap.c

@@ -1,92 +1,31 @@

-/* This code is mostly from ctrulib, which contains the following license: - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - 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. -*/ - +/* Copyright (c) 2013-2020 Jeffrey Pfau + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #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> -extern char* fake_heap_start; -extern char* fake_heap_end; -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; +u32 __ctru_heap_size = 0x02400000; +u32 __ctru_linear_heap_size = 0x01400000; uint32_t* romBuffer = NULL; size_t romBufferSize; FS_Archive sdmcArchive; -bool allocateRomBuffer(void) { - if (romBuffer) { - return true; - } +__attribute__((constructor)) static void init(void) { + FSUSER_OpenArchive(&sdmcArchive, ARCHIVE_SDMC, fsMakePath(PATH_EMPTY, "")); + romBuffer = malloc(0x02000000); if (romBuffer) { romBufferSize = 0x02000000; - return true; + return; } romBuffer = malloc(0x01000000); if (romBuffer) { 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(); }
M src/platform/3ds/main.csrc/platform/3ds/main.c

@@ -109,8 +109,6 @@

static aptHookCookie cookie; static bool core2; -extern bool allocateRomBuffer(void); - static bool _initGpu(void) { if (!C3D_Init(C3D_DEFAULT_CMDBUF_SIZE)) { return false;

@@ -808,10 +806,6 @@ camera.d.requestImage = _requestImage;

camera.buffer = NULL; camera.bufferSize = 0; camera.cam = SELECT_IN1; - - if (!allocateRomBuffer()) { - return 1; - } aptHook(&cookie, _aptHook, 0);
M src/platform/test/perf-main.csrc/platform/test/perf-main.c

@@ -58,9 +58,6 @@ char* savestate;

bool server; }; -#ifdef _3DS -extern bool allocateRomBuffer(void); -#endif #ifdef __SWITCH__ TimeType __nx_time_type = TimeType_LocalSystemClock; #endif

@@ -84,9 +81,6 @@ UNUSED(_mPerfShutdown);

gfxInitDefault(); osSetSpeedupEnable(true); consoleInit(GFX_BOTTOM, NULL); - if (!allocateRomBuffer()) { - return 1; - } #elif defined(__SWITCH__) UNUSED(_mPerfShutdown); consoleInit(NULL);