PS2SDK
PS2 Homebrew Libraries
freepad.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2007 Lukasz Bruun <mail@lukasz.dk>
3  *
4  * See the file LICENSE included with this distribution for licensing terms.
5  */
6 
12 #include "irx.h"
13 #include "types.h"
14 #include "ctype.h"
15 #include "stdio.h"
16 #include "loadcore.h"
17 #include "sysclib.h"
18 #include "sysmem.h"
19 #include "thevent.h"
20 #include "thbase.h"
21 #include "rpcserver.h"
22 #include "freepad.h"
23 
24 extern struct irx_export_table _exp_padman;
25 
26 // TODO: last sdk 3.1.0 and sdk 3.0.3 has PADMAN module version 0x04,0x22
27 // Check what was changed, and maybe port changes.
28 // Note: currently is based on the last XPADMAN from BOOTROM:
29 // 0x03,0x06
30 IRX_ID("padman", 3, 6);
31 
32 extern int padman_init;
33 extern int thpri_hi;
34 extern int thpri_lo;
35 
36 extern int vblank_end;
37 
38 static int ParseParams(int argc, char *argv[])
39 {
40  int new_thpri_hi, new_thpri_lo;
41 
42  new_thpri_hi = PADMAN_THPRI_HI;
43  new_thpri_lo = PADMAN_THPRI_LO;
44 
45  if(argc > 1)
46  {
47  int i;
48 
49  argv++;
50 
51  for(i = 1; i < argc; i++,argv++)
52  {
53  if(strncmp("thpri=", *argv, 6) == 0)
54  {
55  const char *param;
56 
57  //Parse high priority
58  param = &(*argv)[6];
59  if(isdigit(*param))
60  new_thpri_hi = strtol(param, NULL, 10);
61 
62  //Skip value for high priority
63  while(isdigit(*param))
64  param++;
65 
66  //Valid high priority parameter
67  if(new_thpri_hi - 9 < 115)
68  {
69  if(*param == ',')
70  {
71  ++param;
72  //Parse low priority
73  if(isdigit(*param))
74  new_thpri_lo = strtol(param, NULL, 10);
75 
76  if(new_thpri_lo - 9 >= 115)
77  {
78  M_KPRINTF("invalid priority %d\n", new_thpri_lo);
79  return 0;
80  }
81  }
82 
83  if(new_thpri_lo < new_thpri_hi)
84  M_PRINTF("high prio thread must be higher than low prio thread\n");
85  }
86  else
87  {
88  M_KPRINTF("invalid priority %d\n", new_thpri_hi);
89  return 0;
90  }
91  }
92  }
93  }
94 
95  thpri_hi = new_thpri_hi;
96  thpri_lo = new_thpri_lo;
97 
98  return 1;
99 }
100 
101 int _start(int argc, char *argv[])
102 {
103  padman_init = 0;
104  vblank_end = 0;
105  thpri_hi = PADMAN_THPRI_HI;
106  thpri_lo = PADMAN_THPRI_LO;
107 
108  D_PRINTF("Debug Version\n");
109 
110  if(argc >= 2)
111  ParseParams(argc, argv);
112 
113  if(thpri_hi != PADMAN_THPRI_HI || thpri_lo != PADMAN_THPRI_LO)
114  M_PRINTF("thread priority: high=%d, low=%d\n", thpri_hi, thpri_lo);
115 
116  if(RegisterLibraryEntries(&_exp_padman) != 0)
117  {
118  M_PRINTF("RegisterLibraryEntries failed.\n");
119  return MODULE_NO_RESIDENT_END;
120  }
121 
122  if(InitRpcServers(thpri_lo) == 0)
123  {
124  M_PRINTF("Failed to init RPC servers.\n");
125  return MODULE_NO_RESIDENT_END;
126  }
127 
128  printf("Pad Driver for OSD\n");
129 
130  return MODULE_RESIDENT_END;
131 }
132 
133 //This may have been a drop-in replacement for WaitEventFlag, which explains the similar, but unused 3rd and 4th parameters.
134 void WaitClearEvent(int eventflag, u32 bits, int mode, u32 *resbits_out)
135 {
136  u32 resbits;
137 
138  (void)mode;
139  (void)resbits_out;
140 
141  WaitEventFlag(eventflag, bits | EF_EXIT_THREAD, WEF_OR, &resbits);
142 
143  if( resbits & EF_EXIT_THREAD )
144  { //Yes, it's unused. Probably leftover code.
146 
147  ReferThreadStatus(TH_SELF, &tinfo);
148  SetEventFlag(eventflag, EF_EXIT_THREAD);
149  ExitThread();
150  }
151 
152  ClearEventFlag(eventflag, ~bits);
153 }
thbase.h
sysclib.h
TH_SELF
#define TH_SELF
Definition: kernel.h:68
loadcore.h
ctype.h
irx.h
irx_export_table
Definition: irx.h:90
tinfo
Definition: tty.c:47
stdio.h
rpcserver.h
freepad.h
sysmem.h
thevent.h
_iop_thread_status
Definition: thbase.h:68