PS2SDK
PS2 Homebrew Libraries
nprintf.c
Go to the documentation of this file.
1 /*
2 # _____ ___ ____ ___ ____
3 # ____| | ____| | | |____|
4 # | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5 #-----------------------------------------------------------------------
6 # Copyright 2001-2004, ps2dev - http://www.ps2dev.org
7 # Licenced under Academic Free License version 2.0
8 # Review ps2sdk README & LICENSE files for further details.
9 */
10 
18 #include "types.h"
19 #include "stdio.h"
20 #include "sysclib.h"
21 #include "thbase.h"
22 #include "intrman.h"
23 #include "sysmem.h"
24 #include "sifman.h"
25 #include "sifcmd.h"
26 
28 #define NPM_PUTS 0x01
29 #define RPC_NPM_USER 0x014d704e
30 
38 static void *naplinkRpcHandler(int cmd, void *buffer, int size)
39 {
40  (void)cmd;
41  (void)size;
42 
43  return buffer;
44 }
45 
47 static SifRpcServerData_t server __attribute((aligned(16)));
48 static SifRpcDataQueue_t queue __attribute((aligned(16)));
49 static unsigned char rpc_buffer[512] __attribute__((__aligned__(4)));
50 
56 static void napThread(void *arg)
57 {
58  int pid;
59 
60  (void)arg;
61 
62  sceSifInitRpc(0);
63  pid = GetThreadId();
64  sceSifSetRpcQueue(&queue, pid);
65  sceSifRegisterRpc(&server, RPC_NPM_USER, naplinkRpcHandler,
66  rpc_buffer, 0, 0, &queue);
67  sceSifRpcLoop(&queue); // Never exits
68  ExitDeleteThread();
69 }
70 
80 int naplinkRpcInit(void)
81 {
82  iop_thread_t th_attr;
83  int ret;
84  int pid;
85 
86  th_attr.attr = 0x02000000;
87  th_attr.option = 0;
88  th_attr.thread = napThread;
89  th_attr.stacksize = 0x800;
90  th_attr.priority = 0x4f;
91 
92  pid = CreateThread(&th_attr);
93  if (pid < 0) {
94  printf("IOP: napRpc createThread failed %d\n", pid);
95  return -1;
96  }
97 
98  ret = StartThread(pid, 0);
99  if (ret < 0) {
100  printf("IOP: napRpc startThread failed %d\n", ret);
101  DeleteThread(pid);
102  return -1;
103  }
104  return 0;
105 }
thbase.h
sifman.h
sysclib.h
naplinkRpcInit
int naplinkRpcInit(void)
Definition: nprintf.c:80
naplinkRpcHandler
static void * naplinkRpcHandler(int cmd, void *buffer, int size)
Definition: nprintf.c:38
stdio.h
_iop_thread
Definition: thbase.h:39
t_SifRpcServerData
Definition: sifrpc-common.h:98
napThread
static void napThread(void *arg)
Definition: nprintf.c:56
t_SifRpcDataQueue
Definition: sifrpc-common.h:153
sysmem.h
__attribute__
Definition: gif_registers.h:38
intrman.h