mirror of
https://github.com/cathery/sys-con.git
synced 2024-10-04 13:29:43 +00:00
Rework main.cpp with stratosphere
This commit is contained in:
parent
345a14d17d
commit
72497b76f1
8
.vscode/c_cpp_properties.json
vendored
8
.vscode/c_cpp_properties.json
vendored
@ -9,11 +9,15 @@
|
|||||||
"${DEVKITPRO}/libnx/include/",
|
"${DEVKITPRO}/libnx/include/",
|
||||||
"source/ControllerLib",
|
"source/ControllerLib",
|
||||||
"source/ControllerSwitch",
|
"source/ControllerSwitch",
|
||||||
"source/inih"
|
"source/inih",
|
||||||
|
"source/libstratosphere/libstratosphere/include",
|
||||||
|
"source/libstratosphere/libvapours/include"
|
||||||
],
|
],
|
||||||
"defines": [
|
"defines": [
|
||||||
"SWITCH",
|
"SWITCH",
|
||||||
"__SWITCH__"
|
"__SWITCH__",
|
||||||
|
"ATMOSPHERE_BOARD_NINTENDO_SWITCH",
|
||||||
|
"ATMOSPHERE_IS_STRATOSPHERE"
|
||||||
],
|
],
|
||||||
"compilerPath": "${DEVKITPRO}/devkitA64/bin/aarch64-none-elf-g++",
|
"compilerPath": "${DEVKITPRO}/devkitA64/bin/aarch64-none-elf-g++",
|
||||||
"cStandard": "c11",
|
"cStandard": "c11",
|
||||||
|
@ -1,107 +1,64 @@
|
|||||||
#include "switch.h"
|
#include "switch.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "mainLoop.h"
|
#include "mainLoop.h"
|
||||||
|
#include <stratosphere.hpp>
|
||||||
|
|
||||||
//CHANGELOG
|
// libnx fake heap initialization
|
||||||
// Fixed an issue where unplugging one controller would unplug others
|
|
||||||
|
|
||||||
//ISSUES:
|
|
||||||
// Kosmos Toolbox doesn't free up the memory associated with the sysmodule due to hiddbgAttachHdlsWorkBuffer() memory not being freed up
|
|
||||||
// After plugging and unplugging a controller for a while, sysmodule stops working
|
|
||||||
// DS3 controller seems to send random inputs
|
|
||||||
|
|
||||||
//TODO:
|
|
||||||
// Shrink unneessary heap memory/stack size used for the sysmodule
|
|
||||||
// Make a config application companion to test controller input and edit various preferences (buttons, deadzones)
|
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
// Adjust size as needed.
|
|
||||||
#define INNER_HEAP_SIZE 0x40'000
|
|
||||||
#ifndef __APPLET__
|
|
||||||
|
|
||||||
u32 __nx_applet_type = AppletType_None;
|
u32 __nx_applet_type = AppletType_None;
|
||||||
|
|
||||||
|
#define INNER_HEAP_SIZE 0x40 * ams::os::MemoryPageSize
|
||||||
size_t nx_inner_heap_size = INNER_HEAP_SIZE;
|
size_t nx_inner_heap_size = INNER_HEAP_SIZE;
|
||||||
char nx_inner_heap[INNER_HEAP_SIZE];
|
char nx_inner_heap[INNER_HEAP_SIZE];
|
||||||
|
|
||||||
void __libnx_initheap(void)
|
void __libnx_initheap(void)
|
||||||
{
|
{
|
||||||
void *addr = nx_inner_heap;
|
|
||||||
size_t size = nx_inner_heap_size;
|
|
||||||
|
|
||||||
// Newlib
|
// Newlib
|
||||||
extern char *fake_heap_start;
|
extern char *fake_heap_start;
|
||||||
extern char *fake_heap_end;
|
extern char *fake_heap_end;
|
||||||
|
|
||||||
fake_heap_start = (char *)addr;
|
fake_heap_start = nx_inner_heap;
|
||||||
fake_heap_end = (char *)addr + size;
|
fake_heap_end = nx_inner_heap + nx_inner_heap_size;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
// libstratosphere variables
|
||||||
|
namespace ams
|
||||||
|
{
|
||||||
|
ncm::ProgramId CurrentProgramId = {0x690000000000000D};
|
||||||
|
namespace result { bool CallFatalOnResultAssertion = false; }
|
||||||
|
}
|
||||||
|
|
||||||
void userAppInit(void)
|
|
||||||
|
extern "C" void __appInit(void)
|
||||||
|
{
|
||||||
|
ams::hos::SetVersionForLibnx();
|
||||||
|
ams::sm::DoWithSession([]
|
||||||
{
|
{
|
||||||
//Seems like every thread on the switch needs to sleep for a little
|
R_ASSERT(timeInitialize());
|
||||||
// or it will block the entire console
|
R_ASSERT(fsInitialize());
|
||||||
//Specifically in Kosmos Toolbox's case, you need to wait about 0.2 sec
|
R_ASSERT(fsdevMountSdmc());
|
||||||
// or it won't let you turn it on/off the sysmodule after a few tries
|
R_ASSERT(hiddbgInitialize());
|
||||||
svcSleepThread(2e+8L);
|
|
||||||
Result rc = 0;
|
|
||||||
rc = hiddbgInitialize();
|
|
||||||
if (R_FAILED(rc))
|
|
||||||
fatalThrow(rc);
|
|
||||||
|
|
||||||
if (hosversionAtLeast(7, 0, 0))
|
if (hosversionAtLeast(7, 0, 0))
|
||||||
{
|
R_ASSERT(hiddbgAttachHdlsWorkBuffer());
|
||||||
rc = hiddbgAttachHdlsWorkBuffer();
|
R_ASSERT(usbHsInitialize());
|
||||||
if (R_FAILED(rc))
|
R_ASSERT(pscmInitialize());
|
||||||
fatalThrow(rc);
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = usbHsInitialize();
|
extern "C" void __appExit(void)
|
||||||
if (R_FAILED(rc))
|
{
|
||||||
fatalThrow(rc);
|
pscmExit();
|
||||||
|
usbHsExit();
|
||||||
rc = pscmInitialize();
|
hiddbgReleaseHdlsWorkBuffer();
|
||||||
if (R_FAILED(rc))
|
hiddbgExit();
|
||||||
fatalThrow(rc);
|
fsdevUnmountAll();
|
||||||
}
|
fsExit();
|
||||||
|
timeExit();
|
||||||
void userAppExit(void)
|
|
||||||
{
|
|
||||||
pscmExit();
|
|
||||||
usbHsExit();
|
|
||||||
hiddbgReleaseHdlsWorkBuffer();
|
|
||||||
hiddbgExit();
|
|
||||||
}
|
|
||||||
|
|
||||||
alignas(16) u8 __nx_exception_stack[0x1000];
|
|
||||||
u64 __nx_exception_stack_size = sizeof(__nx_exception_stack);
|
|
||||||
__attribute__((weak)) u32 __nx_exception_ignoredebug = 1;
|
|
||||||
|
|
||||||
void __libnx_exception_handler(ThreadExceptionDump *ctx)
|
|
||||||
{
|
|
||||||
WriteToLog("Sysmodule crashed with error 0x%x", ctx->error_desc);
|
|
||||||
LockedUpdateConsole();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
Result rc;
|
return mainLoop();
|
||||||
|
|
||||||
#ifdef __APPLET__
|
|
||||||
appletLockExit();
|
|
||||||
consoleInit(nullptr);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
rc = mainLoop();
|
|
||||||
|
|
||||||
#ifdef __APPLET__
|
|
||||||
consoleExit(nullptr);
|
|
||||||
userAppExit();
|
|
||||||
appletUnlockExit();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user