Update & clean up the sysmodule template

This commit is contained in:
fincs 2020-10-31 19:25:14 +01:00
parent 847bb129e9
commit f252e65ebd
No known key found for this signature in database
GPG Key ID: 62C7609ADA219C60

View File

@ -6,39 +6,51 @@
// Include the main libnx system header, for Switch development // Include the main libnx system header, for Switch development
#include <switch.h> #include <switch.h>
// Size of the inner heap (adjust as necessary).
#define INNER_HEAP_SIZE 0x80000
#ifdef __cplusplus
extern "C" {
#endif
// Sysmodules should not use applet*. // Sysmodules should not use applet*.
u32 __nx_applet_type = AppletType_None; u32 __nx_applet_type = AppletType_None;
// Sysmodules will normally only want to use one FS session. // Sysmodules will normally only want to use one FS session.
u32 __nx_fs_num_sessions = 1; u32 __nx_fs_num_sessions = 1;
// Adjust size as needed. // Newlib heap configuration function (makes malloc/free work).
#define INNER_HEAP_SIZE 0x80000
size_t nx_inner_heap_size = INNER_HEAP_SIZE;
char nx_inner_heap[INNER_HEAP_SIZE];
void __libnx_initheap(void) void __libnx_initheap(void)
{ {
void* addr = nx_inner_heap; static u8 inner_heap[INNER_HEAP_SIZE];
size_t size = nx_inner_heap_size; extern void* fake_heap_start;
extern void* fake_heap_end;
// Newlib // Configure the newlib heap.
extern char* fake_heap_start; fake_heap_start = inner_heap;
extern char* fake_heap_end; fake_heap_end = inner_heap + sizeof(inner_heap);
fake_heap_start = (char*)addr;
fake_heap_end = (char*)addr + size;
} }
// Init/exit services, update as needed. // Service initialization.
void __attribute__((weak)) __appInit(void) void __appInit(void)
{ {
Result rc; Result rc;
// Initialize default services. // Open a service manager session.
rc = smInitialize(); rc = smInitialize();
if (R_FAILED(rc)) if (R_FAILED(rc))
diagAbortWithResult(MAKERESULT(Module_Libnx, LibnxError_InitFail_SM)); diagAbortWithResult(MAKERESULT(Module_Libnx, LibnxError_InitFail_SM));
// Retrieve the current version of Horizon OS.
rc = setsysInitialize();
if (R_SUCCEEDED(rc)) {
SetSysFirmwareVersion fw;
rc = setsysGetFirmwareVersion(&fw);
if (R_SUCCEEDED(rc))
hosversionSet(MAKEHOSVERSION(fw.major, fw.minor, fw.micro));
setsysExit();
}
// Enable this if you want to use HID. // Enable this if you want to use HID.
/*rc = hidInitialize(); /*rc = hidInitialize();
if (R_FAILED(rc)) if (R_FAILED(rc))
@ -51,25 +63,34 @@ void __attribute__((weak)) __appInit(void)
__libnx_init_time();*/ __libnx_init_time();*/
// Disable this if you don't want to use the filesystem.
rc = fsInitialize(); rc = fsInitialize();
if (R_FAILED(rc)) if (R_FAILED(rc))
diagAbortWithResult(MAKERESULT(Module_Libnx, LibnxError_InitFail_FS)); diagAbortWithResult(MAKERESULT(Module_Libnx, LibnxError_InitFail_FS));
// Disable this if you don't want to use the SD card filesystem.
fsdevMountSdmc(); fsdevMountSdmc();
}
void __attribute__((weak)) userAppExit(void); // Add other services you want to use here.
void __attribute__((weak)) __appExit(void) // Close the service manager session.
{
// Cleanup default services.
fsdevUnmountAll();
fsExit();
//timeExit();//Enable this if you want to use time.
//hidExit();// Enable this if you want to use HID.
smExit(); smExit();
} }
// Service deinitialization.
void __appExit(void)
{
// Close extra services you added to __appInit here.
fsdevUnmountAll(); // Disable this if you don't want to use the SD card filesystem.
fsExit(); // Disable this if you don't want to use the filesystem.
//timeExit(); // Enable this if you want to use time.
//hidExit(); // Enable this if you want to use HID.
}
#ifdef __cplusplus
}
#endif
// Main program entrypoint // Main program entrypoint
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {