1 /*-------------------------------------------------------------
3 conf.c -- SYSCONF support
8 This software is provided 'as-is', without any express or implied
9 warranty. In no event will the authors be held liable for any
10 damages arising from the use of this software.
12 Permission is granted to anyone to use this software for any
13 purpose, including commercial applications, and to alter it and
14 redistribute it freely, subject to the following restrictions:
16 1. The origin of this software must not be misrepresented; you
17 must not claim that you wrote the original software. If you use
18 this software in a product, an acknowledgment in the product
19 documentation would be appreciated but is not required.
21 2. Altered source versions must be plainly marked as such, and
22 must not be misrepresented as being the original software.
24 3. This notice may not be removed or altered from any source
27 -------------------------------------------------------------*/
36 #include "processor.h"
40 static int __conf_inited
= 0;
41 static u8 __conf_buffer
[0x4000] ATTRIBUTE_ALIGN(32);
42 static char __conf_txt_buffer
[0x101] ATTRIBUTE_ALIGN(32);
44 static const char __conf_file
[] ATTRIBUTE_ALIGN(32) = "/shared2/sys/SYSCONF";
45 static const char __conf_txt_file
[] ATTRIBUTE_ALIGN(32) = "/title/00000001/00000002/data/setting.txt";
47 void __CONF_DecryptTextBuffer(void)
52 for(i
=0; i
<0x100; i
++) {
53 __conf_txt_buffer
[i
] ^= key
& 0xff;
54 key
= (key
<<1) | (key
>>31);
63 if(__conf_inited
) return 0;
65 fd
= IOS_Open(__conf_file
,1);
68 memset(__conf_buffer
,0,0x4000);
69 memset(__conf_txt_buffer
,0,0x101);
71 ret
= IOS_Read(fd
, __conf_buffer
, 0x4000);
73 if(ret
!= 0x4000) return CONF_EBADFILE
;
75 fd
= IOS_Open(__conf_txt_file
,1);
78 ret
= IOS_Read(fd
, __conf_txt_buffer
, 0x100);
80 if(ret
!= 0x100) return CONF_EBADFILE
;
82 if(memcmp(__conf_buffer
, "SCv0", 4)) return CONF_EBADFILE
;
84 __CONF_DecryptTextBuffer();
90 int __CONF_GetTxt(const char *name
, char *buf
, int length
)
92 char *line
= __conf_txt_buffer
;
95 int nlen
= strlen(name
);
97 if(!__conf_inited
) return CONF_ENOTINIT
;
99 while(line
< (__conf_txt_buffer
+0x100) ) {
100 delim
= strchr(line
, '=');
101 if(delim
&& ((delim
- line
) == nlen
) && !memcmp(name
, line
, nlen
)) {
103 end
= strchr(line
, '\r');
107 memcpy(buf
, delim
, slen
);
117 while(line
< (__conf_txt_buffer
+0x100) && *line
++ != '\n');
122 u8
*__CONF_Find(const char *name
)
126 int nlen
= strlen(name
);
127 count
= *((u16
*)(&__conf_buffer
[4]));
128 offset
= (u16
*)&__conf_buffer
[6];
131 if((nlen
== ((__conf_buffer
[*offset
]&0x0F)+1)) && !memcmp(name
, &__conf_buffer
[*offset
+1], nlen
))
132 return &__conf_buffer
[*offset
];
138 s32
CONF_GetLength(const char *name
)
142 if(!__conf_inited
) return CONF_ENOTINIT
;
144 entry
= __CONF_Find(name
);
145 if(!entry
) return CONF_ENOENT
;
149 return *((u16
*)&entry
[strlen(name
)+1]) + 1;
151 return entry
[strlen(name
)+1] + 1;
161 return CONF_ENOTIMPL
;
165 int CONF_GetType(const char *name
)
168 if(!__conf_inited
) return CONF_ENOTINIT
;
170 entry
= __CONF_Find(name
);
171 if(!entry
) return CONF_ENOENT
;
176 s32
CONF_Get(const char *name
, void *buffer
, u32 length
)
180 if(!__conf_inited
) return CONF_ENOTINIT
;
182 entry
= __CONF_Find(name
);
183 if(!entry
) return CONF_ENOENT
;
185 len
= CONF_GetLength(name
);
186 if(len
<0) return len
;
187 if(len
>length
) return CONF_ETOOBIG
;
191 memcpy(buffer
, &entry
[strlen(name
)+3], len
);
193 case CONF_SMALLARRAY
:
194 memcpy(buffer
, &entry
[strlen(name
)+2], len
);
200 memset(buffer
, 0, length
);
201 memcpy(buffer
, &entry
[strlen(name
)+1], len
);
204 return CONF_ENOTIMPL
;
209 s32
CONF_GetShutdownMode(void)
211 u8 idleconf
[2] = {0,0};
214 res
= CONF_Get("IPL.IDL", idleconf
, 2);
215 if(res
<0) return res
;
216 if(res
!=2) return CONF_EBADVALUE
;
220 s32
CONF_GetIdleLedMode(void)
223 u8 idleconf
[2] = {0,0};
224 res
= CONF_Get("IPL.IDL", idleconf
, 2);
225 if(res
<0) return res
;
226 if(res
!=2) return CONF_EBADVALUE
;
230 s32
CONF_GetProgressiveScan(void)
234 res
= CONF_Get("IPL.PGS", &val
, 1);
235 if(res
<0) return res
;
236 if(res
!=1) return CONF_EBADVALUE
;
240 s32
CONF_GetEuRGB60(void)
244 res
= CONF_Get("IPL.E60", &val
, 1);
245 if(res
<0) return res
;
246 if(res
!=1) return CONF_EBADVALUE
;
250 s32
CONF_GetIRSensitivity(void)
254 res
= CONF_Get("BT.SENS", &val
, 4);
255 if(res
<0) return res
;
256 if(res
!=4) return CONF_EBADVALUE
;
260 s32
CONF_GetSensorBarPosition(void)
264 res
= CONF_Get("BT.BAR", &val
, 1);
265 if(res
<0) return res
;
266 if(res
!=1) return CONF_EBADVALUE
;
270 s32
CONF_GetPadSpeakerVolume(void)
274 res
= CONF_Get("BT.SPKV", &val
, 1);
275 if(res
<0) return res
;
276 if(res
!=1) return CONF_EBADVALUE
;
280 s32
CONF_GetPadMotorMode(void)
284 res
= CONF_Get("BT.MOT", &val
, 1);
285 if(res
<0) return res
;
286 if(res
!=1) return CONF_EBADVALUE
;
290 s32
CONF_GetSoundMode(void)
294 res
= CONF_Get("IPL.SND", &val
, 1);
295 if(res
<0) return res
;
296 if(res
!=1) return CONF_EBADVALUE
;
300 s32
CONF_GetLanguage(void)
304 res
= CONF_Get("IPL.LNG", &val
, 1);
305 if(res
<0) return res
;
306 if(res
!=1) return CONF_EBADVALUE
;
310 s32
CONF_GetCounterBias(u32
*bias
)
313 res
= CONF_Get("IPL.CB", bias
, 4);
314 if(res
<0) return res
;
315 if(res
!=4) return CONF_EBADVALUE
;
319 s32
CONF_GetScreenSaverMode(void)
323 res
= CONF_Get("IPL.SSV", &val
, 1);
324 if(res
<0) return res
;
325 if(res
!=1) return CONF_EBADVALUE
;
329 s32
CONF_GetDisplayOffsetH(s8
*offset
)
332 res
= CONF_Get("IPL.DH", offset
, 1);
333 if(res
<0) return res
;
334 if(res
!=1) return CONF_EBADVALUE
;
338 s32
CONF_GetPadDevices(conf_pads
*pads
)
342 res
= CONF_Get("BT.DINF", pads
, sizeof(conf_pads
));
343 if(res
< 0) return res
;
344 if(res
< sizeof(conf_pads
)) return CONF_EBADVALUE
;
348 s32
CONF_GetNickName(u8
*nickname
)
353 res
= CONF_Get("IPL.NIK", buf
, 0x16);
354 if(res
< 0) return res
;
355 if((res
!= 0x16) || (!buf
[0])) return CONF_EBADVALUE
;
358 nickname
[i
] = buf
[i
];
364 s32
CONF_GetAspectRatio(void)
369 res
= CONF_Get("IPL.AR", &val
, 1);
370 if(res
< 0) return res
;
371 if(res
!=1) return CONF_EBADVALUE
;
375 s32
CONF_GetEULA(void)
380 res
= CONF_Get("IPL.EULA", &val
, 1);
381 if(res
< 0) return res
;
382 if(res
!=1) return CONF_EBADVALUE
;
386 s32
CONF_GetParentalPassword(s8
*password
)
391 res
= CONF_Get("IPL.PC", buf
, 0x4A);
392 if(res
< 0) return res
;
393 if(res
!=1) return CONF_EBADVALUE
;
395 memcpy(password
, buf
+3, 4);
401 s32
CONF_GetParentalAnswer(s8
*answer
)
406 res
= CONF_Get("IPL.PC", buf
, 0x4A);
407 if(res
< 0) return res
;
408 if(res
!=1) return CONF_EBADVALUE
;
410 memcpy(answer
, buf
+8, 32);
416 s32
CONF_GetWiiConnect24(void)
421 res
= CONF_Get("NET.WCFG", &val
, 4);
422 if(res
< 0) return res
;
423 if(res
!=4) return CONF_EBADVALUE
;
427 s32
CONF_GetRegion(void)
432 res
= __CONF_GetTxt("GAME", buf
, 3);
433 if(res
< 0) return res
;
434 if(!strcmp(buf
, "JP")) return CONF_REGION_JP
;
435 if(!strcmp(buf
, "US")) return CONF_REGION_US
;
436 if(!strcmp(buf
, "EU")) return CONF_REGION_EU
;
437 if(!strcmp(buf
, "KR")) return CONF_REGION_KR
;
438 if(!strcmp(buf
, "CN")) return CONF_REGION_CN
;
439 return CONF_EBADVALUE
;
442 s32
CONF_GetArea(void)
447 res
= __CONF_GetTxt("AREA", buf
, 4);
448 if(res
< 0) return res
;
449 if(!strcmp(buf
, "JPN")) return CONF_AREA_JPN
;
450 if(!strcmp(buf
, "USA")) return CONF_AREA_USA
;
451 if(!strcmp(buf
, "EUR")) return CONF_AREA_EUR
;
452 if(!strcmp(buf
, "AUS")) return CONF_AREA_AUS
;
453 if(!strcmp(buf
, "BRA")) return CONF_AREA_BRA
;
454 if(!strcmp(buf
, "TWN")) return CONF_AREA_TWN
;
455 if(!strcmp(buf
, "ROC")) return CONF_AREA_ROC
;
456 if(!strcmp(buf
, "KOR")) return CONF_AREA_KOR
;
457 if(!strcmp(buf
, "HKG")) return CONF_AREA_HKG
;
458 if(!strcmp(buf
, "ASI")) return CONF_AREA_ASI
;
459 if(!strcmp(buf
, "LTN")) return CONF_AREA_LTN
;
460 if(!strcmp(buf
, "SAF")) return CONF_AREA_SAF
;
461 if(!strcmp(buf
, "CHN")) return CONF_AREA_CHN
;
462 return CONF_EBADVALUE
;
465 s32
CONF_GetVideo(void)
470 res
= __CONF_GetTxt("VIDEO", buf
, 5);
471 if(res
< 0) return res
;
472 if(!strcmp(buf
, "NTSC")) return CONF_VIDEO_NTSC
;
473 if(!strcmp(buf
, "PAL")) return CONF_VIDEO_PAL
;
474 if(!strcmp(buf
, "MPAL")) return CONF_VIDEO_MPAL
;
475 return CONF_EBADVALUE
;