mirror of https://github.com/mgba-emu/mgba.git
3DS: Clean up legacy initialization (fixes #1768)
This commit is contained in:
parent
774aca8462
commit
48006dd83e
1
CHANGES
1
CHANGES
|
@ -22,6 +22,7 @@ Other fixes:
|
|||
- GBA: Reject incorrectly sized BIOSes
|
||||
- Qt: Fix OpenGL 2.1 support (fixes mgba.io/i/1678)
|
||||
Misc:
|
||||
- 3DS: Clean up legacy initialization (fixes mgba.io/i/1768)
|
||||
- GBA Serialize: Only flunk BIOS check if official BIOS was expected
|
||||
- Qt: Disable Replace ROM option when no game loaded
|
||||
- Qt: Defer texture updates until frame is drawn (fixes mgba.io/i/1590)
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -109,8 +109,6 @@ static bool sgbCrop = false;
|
|||
static aptHookCookie cookie;
|
||||
static bool core2;
|
||||
|
||||
extern bool allocateRomBuffer(void);
|
||||
|
||||
static bool _initGpu(void) {
|
||||
if (!C3D_Init(C3D_DEFAULT_CMDBUF_SIZE)) {
|
||||
return false;
|
||||
|
@ -809,10 +807,6 @@ int main() {
|
|||
camera.bufferSize = 0;
|
||||
camera.cam = SELECT_IN1;
|
||||
|
||||
if (!allocateRomBuffer()) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
aptHook(&cookie, _aptHook, 0);
|
||||
|
||||
ptmuInit();
|
||||
|
|
|
@ -50,9 +50,6 @@ struct PerfOpts {
|
|||
bool server;
|
||||
};
|
||||
|
||||
#ifdef _3DS
|
||||
extern bool allocateRomBuffer(void);
|
||||
#endif
|
||||
#ifdef __SWITCH__
|
||||
TimeType __nx_time_type = TimeType_LocalSystemClock;
|
||||
#endif
|
||||
|
@ -76,9 +73,6 @@ int main(int argc, char** argv) {
|
|||
gfxInitDefault();
|
||||
osSetSpeedupEnable(true);
|
||||
consoleInit(GFX_BOTTOM, NULL);
|
||||
if (!allocateRomBuffer()) {
|
||||
return 1;
|
||||
}
|
||||
#elif defined(__SWITCH__)
|
||||
UNUSED(_mPerfShutdown);
|
||||
consoleInit(NULL);
|
||||
|
|
Loading…
Reference in New Issue