]> Chaos Git - corbenik/ctrulib.git/commitdiff
NS: Added API
authoridunoe <idunoe@asia.com>
Mon, 27 Oct 2014 05:17:34 +0000 (13:17 +0800)
committeridunoe <idunoe@asia.com>
Mon, 27 Oct 2014 05:17:34 +0000 (13:17 +0800)
libctru/include/3ds/services/ns.h [new file with mode: 0644]
libctru/source/services/ns.c [new file with mode: 0644]

diff --git a/libctru/include/3ds/services/ns.h b/libctru/include/3ds/services/ns.h
new file mode 100644 (file)
index 0000000..beb702e
--- /dev/null
@@ -0,0 +1,21 @@
+#pragma once
+
+/*
+       Requires access to "ns:s" service
+*/
+
+Result nsInit();
+Result nsExit();
+
+/* NS_LaunchTitle()
+  titleid                      TitleId of title to launch, if 0, gamecard assumed
+  launch_flags         use if you know of any
+  procid                       ptr to where the process id of the launched title will be written to, leave a NULL, if you don't care
+*/
+Result NS_LaunchTitle(u64 titleid, u32 launch_flags, u32 *procid);
+
+/* NS_RebootToTitle()
+  mediatype                    mediatype for title
+  titleid                      TitleId of title to launch
+*/
+Result NS_RebootToTitle(u8 mediatype, u64 titleid);
\ No newline at end of file
diff --git a/libctru/source/services/ns.c b/libctru/source/services/ns.c
new file mode 100644 (file)
index 0000000..ffd7294
--- /dev/null
@@ -0,0 +1,50 @@
+#include <stdlib.h>
+#include <3ds.h>
+
+static Handle nsHandle;
+
+Result nsInit()
+{
+       return srvGetServiceHandle(&nsHandle, "ns:s");  
+}
+
+Result nsExit()
+{
+       return svcCloseHandle(nsHandle);
+}
+
+Result NS_LaunchTitle(u64 titleid, u32 launch_flags, u32 *procid)
+{
+       Result ret = 0;
+       u32 *cmdbuf = getThreadCommandBuffer();
+
+       cmdbuf[0] = 0x000200C0;
+       cmdbuf[1] = titleid & 0xffffffff;
+       cmdbuf[2] = (titleid >> 32) & 0xffffffff;
+       cmdbuf[3] = launch_flags;
+       
+       if((ret = svcSendSyncRequest(nsHandle))!=0)return ret;
+
+       if(procid != NULL)
+               *procid = cmdbuf[2];
+       
+       return (Result)cmdbuf[1];
+}
+
+Result NS_RebootToTitle(u8 mediatype, u64 titleid)
+{
+       Result ret = 0;
+       u32 *cmdbuf = getThreadCommandBuffer();
+
+       cmdbuf[0] = 0x00100180;
+       cmdbuf[1] = 0x1;
+       cmdbuf[2] = titleid & 0xffffffff;
+       cmdbuf[3] = (titleid >> 32) & 0xffffffff;
+       cmdbuf[4] = mediatype;
+       cmdbuf[5] = 0x0; // reserved
+       cmdbuf[6] = 0x0;
+       
+       if((ret = svcSendSyncRequest(nsHandle))!=0)return ret;
+
+       return (Result)cmdbuf[1];
+}
\ No newline at end of file