Disabling auto-refresh of game list by default, as it is causing bugs sometimes
[open-ps2-loader.git] / modules / debug / ps2link / nprintf.c
blob989e9937efdd0c161961d97354ef108f8fd4fcf7
1 /*********************************************************************
2 * Copyright (C) 2003 Tord Lindstrom (pukko@home.se)
3 * This file is subject to the terms and conditions of the PS2Link License.
4 * See the file LICENSE in the main directory of this distribution for more
5 * details.
6 */
8 #include <types.h>
9 #include <thbase.h>
10 #include <sifcmd.h>
11 #include <sysclib.h>
12 #include <stdio.h>
13 #include <ioman.h>
14 #include <intrman.h>
15 #include <loadcore.h>
17 ////////////////////////////////////////////////////////////////////////
18 #define NPM_PUTS 0x01
19 #define RPC_NPM_USER 0x014d704e
21 ////////////////////////////////////////////////////////////////////////
22 static void *
23 naplinkRpcHandler(int cmd, void *buffer, int size)
25 // Only supports npmPrintf of course
26 switch(cmd) {
27 case NPM_PUTS:
28 printf(buffer);
29 break;
30 default:
31 printf("unknown npm rpc call\n");
34 return buffer;
37 ////////////////////////////////////////////////////////////////////////
38 static SifRpcServerData_t server __attribute((aligned(16)));
39 static SifRpcDataQueue_t queue __attribute((aligned(16)));
40 static unsigned char rpc_buffer[512] __attribute((aligned(16)));
42 static void
43 napThread(void *arg)
45 int pid;
47 SifInitRpc(0);
48 pid = GetThreadId();
49 SifSetRpcQueue(&queue, pid);
50 SifRegisterRpc(&server, RPC_NPM_USER, naplinkRpcHandler,
51 rpc_buffer, 0, 0, &queue);
52 SifRpcLoop(&queue); // Never exits
53 ExitDeleteThread();
55 ////////////////////////////////////////////////////////////////////////
56 int
57 naplinkRpcInit(void)
59 struct _iop_thread th_attr;
60 int ret;
61 int pid;
63 th_attr.attr = 0x02000000;
64 th_attr.option = 0;
65 th_attr.thread = napThread;
66 th_attr.stacksize = 0x800;
67 th_attr.priority = 79;
69 pid = CreateThread(&th_attr);
70 if (pid < 0) {
71 printf("IOP: napRpc createThread failed %d\n", pid);
72 return -1;
75 ret = StartThread(pid, 0);
76 if (ret < 0) {
77 printf("IOP: napRpc startThread failed %d\n", ret);
78 DeleteThread(pid);
79 return -1;
81 return 0;