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