3DS: Adjust heap sizes to allow for 32MB ROM loads

This commit is contained in:
Jeffrey Pfau 2015-08-26 23:09:49 -07:00
parent 15037950f0
commit fee9fc688f
3 changed files with 110 additions and 12 deletions

View File

@ -38,6 +38,12 @@ static void GBABreakpoint(struct ARMCore* cpu, int immediate);
static bool _setSoftwareBreakpoint(struct ARMDebugger*, uint32_t address, enum ExecutionMode mode, uint32_t* opcode); static bool _setSoftwareBreakpoint(struct ARMDebugger*, uint32_t address, enum ExecutionMode mode, uint32_t* opcode);
static bool _clearSoftwareBreakpoint(struct ARMDebugger*, uint32_t address, enum ExecutionMode mode, uint32_t opcode); static bool _clearSoftwareBreakpoint(struct ARMDebugger*, uint32_t address, enum ExecutionMode mode, uint32_t opcode);
#ifdef _3DS
extern uint32_t* romBuffer;
extern size_t romBufferSize;
#endif
void GBACreate(struct GBA* gba) { void GBACreate(struct GBA* gba) {
gba->d.id = GBA_COMPONENT_MAGIC; gba->d.id = GBA_COMPONENT_MAGIC;
gba->d.init = GBAInit; gba->d.init = GBAInit;
@ -110,7 +116,9 @@ void GBAUnloadROM(struct GBA* gba) {
gba->memory.rom = 0; gba->memory.rom = 0;
if (gba->romVf) { if (gba->romVf) {
#ifndef _3DS
gba->romVf->unmap(gba->romVf, gba->pristineRom, gba->pristineRomSize); gba->romVf->unmap(gba->romVf, gba->pristineRom, gba->pristineRomSize);
#endif
gba->pristineRom = 0; gba->pristineRom = 0;
gba->romVf = 0; gba->romVf = 0;
} }
@ -396,7 +404,15 @@ bool GBALoadROM(struct GBA* gba, struct VFile* vf, struct VFile* sav, const char
if (gba->pristineRomSize > SIZE_CART0) { if (gba->pristineRomSize > SIZE_CART0) {
gba->pristineRomSize = SIZE_CART0; gba->pristineRomSize = SIZE_CART0;
} }
#ifdef _3DS
gba->pristineRom = 0;
if (gba->pristineRomSize <= romBufferSize) {
gba->pristineRom = romBuffer;
vf->read(vf, romBuffer, gba->pristineRomSize);
}
#else
gba->pristineRom = vf->map(vf, gba->pristineRomSize, MAP_READ); gba->pristineRom = vf->map(vf, gba->pristineRomSize, MAP_READ);
#endif
if (!gba->pristineRom) { if (!gba->pristineRom) {
GBALog(gba, GBA_LOG_WARN, "Couldn't map ROM"); GBALog(gba, GBA_LOG_WARN, "Couldn't map ROM");
return false; return false;

View File

@ -0,0 +1,89 @@
/* 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.
*/
#include <3ds/types.h>
#include <3ds/svc.h>
extern char* fake_heap_start;
extern char* fake_heap_end;
u32 __linear_heap;
u32 __heapBase;
static u32 __heap_size = 0x03000000;
static u32 __linear_heap_size = 0x00800000;
extern void (*__system_retAddr)(void);
void __destroy_handle_list(void);
void __appExit();
void __libc_fini_array(void);
uint32_t* romBuffer;
size_t romBufferSize;
bool allocateRomBuffer(void) {
romBuffer = malloc(0x02000000);
if (romBuffer) {
romBufferSize = 0x02000000;
return true;
}
romBuffer = malloc(0x01000000);
if (romBuffer) {
romBufferSize = 0x01000000;
return true;
}
return false;
}
void __system_allocateHeaps() {
u32 tmp=0;
// Allocate the application heap
__heapBase = 0x08000000;
svcControlMemory(&tmp, __heapBase, 0x0, __heap_size, MEMOP_ALLOC, MEMPERM_READ | MEMPERM_WRITE);
// Allocate the linear heap
svcControlMemory(&__linear_heap, 0x0, 0x0, __linear_heap_size, MEMOP_ALLOC_LINEAR, MEMPERM_READ | MEMPERM_WRITE);
// Set up newlib heap
fake_heap_start = (char*)__heapBase;
fake_heap_end = fake_heap_start + __heap_size;
}
void __attribute__((noreturn)) __libctru_exit(int rc)
{
u32 tmp=0;
// Unmap the linear heap
svcControlMemory(&tmp, __linear_heap, 0x0, __linear_heap_size, MEMOP_FREE, 0x0);
// Unmap the application heap
svcControlMemory(&tmp, __heapBase, 0x0, __heap_size, MEMOP_FREE, 0x0);
// Close some handles
__destroy_handle_list();
// Jump to the loader if it provided a callback
if (__system_retAddr)
__system_retAddr();
// Since above did not jump, end this process
svcExitProcess();
}

View File

@ -19,6 +19,7 @@
FS_archive sdmcArchive; FS_archive sdmcArchive;
extern bool allocateRomBuffer(void);
static void GBA3DSLog(struct GBAThread* thread, enum GBALogLevel level, const char* format, va_list args); static void GBA3DSLog(struct GBAThread* thread, enum GBALogLevel level, const char* format, va_list args);
static Handle logFile; static Handle logFile;
@ -60,11 +61,10 @@ static int _pollInput(void) {
int main() { int main() {
struct GBAContext context; struct GBAContext context;
srvInit();
aptInit(); if (!allocateRomBuffer()) {
hidInit(0); return 1;
fsInit(); }
sdmcInit();
sf2d_init(); sf2d_init();
sf2d_set_clear_color(0); sf2d_set_clear_color(0);
@ -146,13 +146,6 @@ cleanup:
sf2d_free_texture(tex); sf2d_free_texture(tex);
sf2d_fini(); sf2d_fini();
sdmcExit();
fsExit();
gfxExit();
hidExit();
aptExit();
srvExit();
return 0; return 0;
} }