This source file includes following definitions.
- core_hook_task_create
- core_hook_task_delete
- spytask
- task_start_hook
- remount_filesystem
- task_fs
- capt_seq_hook
- movie_record_hook
- my_ncmp
- createHook
- deleteHook
- startup
- get_vbatt_min
- get_vbatt_max
- get_effective_focal_length
- get_focal_length
- get_zoom_x
- rec_mode_active
- hook_tyWriteOrig
- cam_console_init
1 #define VBATT_DEFAULT_MIN (3500)
2 #define VBATT_DEFAULT_MAX (4100)
3
4 #include "lolevel.h"
5 #include "platform.h"
6 #include "core.h"
7 #include "keyboard.h"
8
9
10 extern long link_bss_start;
11 extern long link_bss_end;
12 extern void boot();
13 extern void mykbd_task(long ua, long ub, long uc, long ud, long ue, long uf);
14 extern void kbd_process_task(long ua, long ub, long uc, long ud, long ue, long uf);
15
16 static void core_hook_task_create(__attribute__ ((unused))void *tcb)
17 {
18 }
19
20 static void core_hook_task_delete(void *tcb)
21 {
22 char *name = (char*)(*(long*)((char*)tcb+0x34));
23 if (strcmp(name,"tInitFileM")==0) core_spytask_can_start();
24 }
25
26 static int stop_hooking;
27
28 static void (*taskprev)(
29 long p0, long p1, long p2, long p3, long p4,
30 long p5, long p6, long p7, long p8, long p9);
31
32 static void (*taskfsprev)(
33 long p0, long p1, long p2, long p3, long p4,
34 long p5, long p6, long p7, long p8, long p9);
35
36
37
38 void spytask(long ua, long ub, long uc, long ud, long ue, long uf)
39 {
40 (void)ua; (void)ub; (void)uc; (void)ud; (void)ue; (void)uf;
41 core_spytask();
42 }
43
44
45 static void task_start_hook(
46 long p0, long p1, long p2, long p3, long p4,
47 long p5, long p6, long p7, long p8, long p9)
48 {
49 _CreateTask("SpyTask", 0x19, 0x2000, spytask, 0);
50
51
52 _CreateTask("SpyTask2", 0x18, 0x2000, kbd_process_task, 0);
53
54 taskprev(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9 );
55 }
56
57 static void remount_filesystem()
58 {
59 _Unmount_FileSystem();
60 _Mount_FileSystem();
61 }
62
63 static void task_fs(
64 long p0, long p1, long p2, long p3, long p4,
65 long p5, long p6, long p7, long p8, long p9)
66 {
67 remount_filesystem();
68 taskfsprev(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9 );
69 }
70
71
72 static void capt_seq_hook(
73 long p0, long p1, long p2, long p3, long p4,
74 long p5, long p6, long p7, long p8, long p9)
75 {
76 (void)p0; (void)p1; (void)p2; (void)p3; (void)p4; (void)p5; (void)p6; (void)p7; (void)p8; (void)p9;
77 capt_seq_task();
78 }
79
80 static void movie_record_hook(
81 long p0, long p1, long p2, long p3, long p4,
82 long p5, long p6, long p7, long p8, long p9)
83 {
84 (void)p0; (void)p1; (void)p2; (void)p3; (void)p4; (void)p5; (void)p6; (void)p7; (void)p8; (void)p9;
85 movie_record_task();
86 }
87
88
89
90 static int my_ncmp(const char *s1, const char *s2, long len)
91 {
92 int i;
93 for (i=0;i<len;i++)
94 {
95 if (s1[i] != s2[i])
96 return 1;
97 }
98 return 0;
99 }
100
101 void createHook (void *pNewTcb)
102 {
103 char *name = (char*)(*(long*)((char*)pNewTcb+0x34));
104 long *entry = (long*)((char*)pNewTcb+0x74);
105
106
107
108
109 if (!stop_hooking){
110
111 taskprev = (void*)(*entry);
112 *entry = (long)task_start_hook;
113 stop_hooking = 1;
114
115 }else{
116
117
118
119 if (my_ncmp(name, "tSwitchChe", 10) == 0){
120 *entry = (long)mykbd_task;
121 }
122
123
124 if (my_ncmp(name, "tInitFileM", 10) == 0){
125 taskfsprev = (void*)(*entry);
126 *entry = (long)task_fs;
127 }
128
129
130 if (my_ncmp(name, "tCaptSeqTa", 10) == 0){
131 *entry = (long)capt_seq_hook;
132 }
133
134
135 if (my_ncmp(name, "tMovieRecT", 10) == 0){
136 *entry = (long)movie_record_hook;
137 }
138
139 core_hook_task_create(pNewTcb);
140 }
141 }
142
143 void deleteHook (void *pTcb)
144 {
145 core_hook_task_delete(pTcb);
146 }
147
148 void startup()
149 {
150 long *bss = &link_bss_start;
151
152
153 if ((long)&link_bss_end > (MEMISOSTART + MEMISOSIZE)) {
154 started();
155 shutdown();
156 }
157
158
159 while (bss<&link_bss_end)
160 *bss++ = 0;
161
162
163
164
165
166
167
168
169 #if 0
170 long *ptr;
171 for (ptr=(void*)MEMBASEADDR;((long)ptr)<MEMISOSTART;ptr+=4)
172 {
173 ptr[0]=0x55555555;
174 ptr[1]=0x55555555;
175 ptr[2]=0x55555555;
176 ptr[3]=0x55555555;
177 }
178 #endif
179
180 boot();
181 }
182
183 long get_vbatt_min()
184 {
185 return 3500;
186 }
187
188 long get_vbatt_max()
189 {
190 return 4100;
191 }
192
193
194 #define NUM_FL 7
195 #define NUM_DATA 3
196 extern int focus_len_table[NUM_FL*NUM_DATA];
197
198
199
200
201
202
203 #define CF_EFL 3500
204 #define CF_EFL_DIV 580
205
206 const int zoom_points = NUM_FL;
207
208 int get_effective_focal_length(int zp) {
209 return (CF_EFL*get_focal_length(zp))/CF_EFL_DIV;
210 }
211
212 int get_focal_length(int zp) {
213 if (zp < 0) zp = 0;
214 else if (zp >= NUM_FL) zp = NUM_FL-1;
215 return focus_len_table[zp*NUM_DATA];
216 }
217
218 int get_zoom_x(int zp) {
219 return get_focal_length(zp)*10/focus_len_table[0];
220 }
221
222
223 int rec_mode_active(void) {
224
225 return (playrec_mode==1);
226 }
227
228 #if 0
229
230 #define DEV_HDR_WRITE_OFFSET (0x14C/4)
231
232 typedef int DEV_HDR;
233
234 int (*_tyWriteOrig)(DEV_HDR *hdr, char *buf, int len);
235
236
237 int hook_tyWriteOrig(DEV_HDR *hdr, char *buf, int len)
238 {
239
240 FILE *fd = fopen("A/stdout.txt", "a");
241 if (fd) {
242 fwrite(buf, 1, len, fd);
243 fclose(fd);
244 }
245
246 return _tyWriteOrig(hdr, buf, len);
247
248 }
249
250 void cam_console_init()
251 {
252 DEV_HDR *DRV_struct;
253
254 DRV_struct = _iosDevFind("/tyCo/0", 0);
255
256 _tyWriteOrig = (void*)DRV_struct[DEV_HDR_WRITE_OFFSET];
257
258 FILE *fd = fopen("A/chdklog.txt", "a");
259 if (fd) {
260
261
262 char buf[256];
263 int buflen = sprintf(buf, "DRV_struct: %x, _tyWriteOrig: %x\n", DRV_struct, _tyWriteOrig);
264 fwrite(buf, 1, buflen, fd);
265 }
266
267 FILE *fdout = fopen("A/stdout.txt", "r");
268 if (fdout)
269 {
270 DRV_struct[DEV_HDR_WRITE_OFFSET] = (int)hook_tyWriteOrig;
271 fclose(fdout);
272
273 fwrite("tyWrite replaced, camera log enabled\n", 1, sizeof("tyWrite replaced, camera log enabled\n"), fd);
274 }
275
276 if (fd)
277 {
278 fclose(fd);
279 }
280
281 }
282 xx
283 #endif