1
0
mirror of https://github.com/cathery/sys-con.git synced 2024-07-03 02:18:43 +00:00
sys-con/source/main.cpp
2019-10-31 21:00:42 +03:00

105 lines
2.8 KiB
C++

#include "switch.h"
#include "log.h"
#include "mainLoop.h"
//ISSUES:
// when exiting the applet, only one of the controllers is reset
// in sysmodule, when you go to change the controllers, all the hdl handlers are erased but the code doesn't detect it
// Rumble is currently missing on all controllers
// Kosmos Toolbox doesn't allow this sysmodule to be turned on after turning it off, probably due to heap memory not being freed up
//TODO:
// Figure out and remove unnecessary services initialized on sysmodule init
// Figure out and shirnk unneessary heap memory/stack size used for the sysmodule
// Figure out if you can connect controllers paired through a bluetooth adapter
// Figure out if you can connect controllers through usbDs
// Comment the functions before public release
// Make a config application companion to test controller input and edit various preferences (buttons, deadzones)
extern "C"
{
// Adjust size as needed.
#define INNER_HEAP_SIZE 0x100000
#ifndef __APPLET__
u32 __nx_applet_type = AppletType_None;
size_t nx_inner_heap_size = INNER_HEAP_SIZE;
char nx_inner_heap[INNER_HEAP_SIZE];
void __libnx_initheap(void)
{
void *addr = nx_inner_heap;
size_t size = nx_inner_heap_size;
// Newlib
extern char *fake_heap_start;
extern char *fake_heap_end;
fake_heap_start = (char *)addr;
fake_heap_end = (char *)addr + size;
}
#endif
void __attribute__((weak)) userAppInit(void)
{
//Seems like every thread on the switch needs to sleep for a little
// or it will block the entire console
//Specifically in Kosmos Toolbox's case, you need to wait about 0.2 sec
// or it won't let you turn it on/off the sysmodule after a few tries
svcSleepThread(2e+8L);
Result rc = 0;
rc = hiddbgInitialize();
if (R_FAILED(rc))
fatalSimple(rc);
rc = hiddbgAttachHdlsWorkBuffer();
if (R_FAILED(rc))
fatalSimple(rc);
rc = usbHsInitialize();
if (R_FAILED(rc))
fatalSimple(rc);
rc = usbCommsInitialize();
if (R_FAILED(rc))
fatalSimple(rc);
}
void __attribute__((weak)) userAppExit(void)
{
usbCommsExit();
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 ", ctx->error_desc);
}
}
int main(int argc, char *argv[])
{
Result rc;
#ifdef __APPLET__
consoleInit(nullptr);
#endif
rc = mainLoop();
#ifdef __APPLET__
consoleExit(nullptr);
#endif
return rc;
}