ps2sdk  1.1
A collection of Open Source libraries used for developing applications on Sony's PlayStation 2® (PS2).
osd_config.c
Go to the documentation of this file.
1 /*
2 # _____ ___ ____ ___ ____
3 # ____| | ____| | | |____|
4 # | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5 #-----------------------------------------------------------------------
6 # Copyright 2001-2004, ps2dev - http://www.ps2dev.org
7 # Licenced under Academic Free License version 2.0
8 # Review ps2sdk README & LICENSE files for further details.
9 */
10 
18 #include <tamtypes.h>
19 #include <kernel.h>
20 #include <ps2sdkapi.h>
21 #include <stdio.h>
22 #include <sys/fcntl.h>
23 #include <sys/unistd.h>
24 #include <string.h>
25 #include <osd_config.h>
26 
28 typedef struct {
37 
39 extern char g_RomName[];
40 
41 #ifdef F__config_internals
43 
45 char g_RomName[15] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
46 #endif
47 
48 #ifdef F_GetRomName
49 char* GetRomName(char *romname)
50 {
51  int fd;
52 
53  fd = open("rom0:ROMVER", O_RDONLY);
54  read(fd, romname, 14);
55  close(fd);
56  return romname;
57 }
58 #endif
59 
60 #ifdef F_IsT10K
61 int IsT10K(void)
62 {
63  // only read in the romname the first time
64  if(g_RomName[0] == 0)
66  return (g_RomName[4] == 'T') ? 1 : 0;
67 }
68 #endif
69 
70 #ifdef F_IsEarlyJap
71 int IsEarlyJap(ConfigParam config)
72 {
73  return config.version == 0;
74 }
75 #endif
76 
77 #ifdef F_configGetLanguage
78 int configGetLanguage(void)
79 {
80  ConfigParam config;
81 
82  if(IsT10K())
83  return g_t10KConfig.language;
84 
85  GetOsdConfigParam(&config);
86  if(IsEarlyJap(config))
87  return config.japLanguage;
88  return config.language;
89 }
90 #endif
91 
92 #ifdef F_configSetLanguage
93 void configSetLanguage(int language)
94 {
95  ConfigParam config;
96 
97  // make sure language is valid
98  if(language < LANGUAGE_JAPANESE || language > LANGUAGE_PORTUGUESE)
99  return;
100  if(IsT10K())
101  g_t10KConfig.language = language;
102 
103  // set language
104  GetOsdConfigParam(&config);
105  if(IsEarlyJap(config))
106  config.japLanguage = language;
107  else
108  config.language = language;
109  SetOsdConfigParam(&config);
110 }
111 #endif
112 
113 #ifdef F_configGetTvScreenType
114 int configGetTvScreenType(void)
115 {
116  ConfigParam config;
117 
118  if(IsT10K())
119  return g_t10KConfig.screenType;
120 
121  GetOsdConfigParam(&config);
122  return config.screenType;
123 }
124 #endif
125 
126 #ifdef F_configSetTvScreenType
127 void configSetTvScreenType(int screenType)
128 {
129  ConfigParam config;
130 
131  // make sure screen type is valid
132  if(screenType < TV_SCREEN_43 || screenType > TV_SCREEN_169)
133  return;
134  if(IsT10K())
135  g_t10KConfig.screenType = screenType;
136 
137  // set screen type
138  GetOsdConfigParam(&config);
139  config.screenType = screenType;
140  SetOsdConfigParam(&config);
141 }
142 #endif
143 
144 #ifdef F_configGetDateFormat
145 int configGetDateFormat(void)
146 {
147  ConfigParam config;
148  Config2Param config2;
149 
150  if(IsT10K())
151  return g_t10KConfig.dateFormat;
152 
153  GetOsdConfigParam(&config);
154  if(IsEarlyJap(config))
155  return 0;
156  GetOsdConfigParam2(&config2, 1, 1);
157  return config2.dateFormat;
158 }
159 #endif
160 
161 #ifdef F_configSetDateFormat
162 void configSetDateFormat(int dateFormat)
163 {
164  ConfigParam config;
165  Config2Param config2;
166 
167  // make sure date format is valid
168  if(dateFormat < DATE_YYYYMMDD || dateFormat > DATE_DDMMYYYY)
169  return;
170  if(IsT10K())
171  g_t10KConfig.dateFormat = dateFormat;
172 
173  // set date format
174  GetOsdConfigParam(&config);
175  if(IsEarlyJap(config))
176  return;
177  GetOsdConfigParam2(&config2, 1, 1);
178  config2.dateFormat = dateFormat;
179  SetOsdConfigParam2(&config2, 1, 1);
180 }
181 #endif
182 
183 #ifdef F_configGetTimeFormat
184 int configGetTimeFormat(void)
185 {
186  ConfigParam config;
187  Config2Param config2;
188 
189  if(IsT10K())
190  return g_t10KConfig.timeFormat;
191 
192  GetOsdConfigParam(&config);
193  if(IsEarlyJap(config))
194  return 0;
195  GetOsdConfigParam2(&config2, 1, 1);
196  return config2.timeFormat;
197 }
198 #endif
199 
200 #ifdef F_configSetTimeFormat
201 void configSetTimeFormat(int timeFormat)
202 {
203  ConfigParam config;
204  Config2Param config2;
205 
206  // make sure time format is valid
207  if(timeFormat < TIME_24H || timeFormat > TIME_12H)
208  return;
209  if(IsT10K())
210  g_t10KConfig.timeFormat = timeFormat;
211 
212  // set time format
213  GetOsdConfigParam(&config);
214  if(IsEarlyJap(config))
215  return;
216  GetOsdConfigParam2(&config2, 1, 1);
217  config2.timeFormat = timeFormat;
218  SetOsdConfigParam2(&config2, 1, 1);
219 }
220 #endif
221 
222 #ifdef F_configGetTimezone
223 int configGetTimezone(void)
224 {
225  ConfigParam config;
226 
227  if(IsT10K())
229 
230  GetOsdConfigParam(&config);
231  if(IsEarlyJap(config))
232  return 540;
233  return config.timezoneOffset;
234 }
235 #endif
236 
237 #ifdef F_configSetTimezone
238 void configSetTimezone(int timezoneOffset)
239 {
240  ConfigParam config;
241 
242  // set offset from GMT
243  if(IsT10K())
244  g_t10KConfig.timezoneOffset = timezoneOffset;
245 
246  GetOsdConfigParam(&config);
247  if(IsEarlyJap(config))
248  return;
249  config.timezoneOffset = timezoneOffset;
250  SetOsdConfigParam(&config);
252 }
253 #endif
254 
255 #ifdef F_configIsSpdifEnabled
256 int configIsSpdifEnabled(void)
257 {
258  ConfigParam config;
259 
260  if(IsT10K())
261  return g_t10KConfig.spdifMode ^ 1;
262 
263  GetOsdConfigParam(&config);
264  return config.spdifMode ^ 1;
265 }
266 #endif
267 
268 #ifdef F_configSetSpdifEnabled
269 void configSetSpdifEnabled(int enabled)
270 {
271  ConfigParam config;
272 
273  if(IsT10K())
274  g_t10KConfig.spdifMode = enabled ^ 1;
275 
276  GetOsdConfigParam(&config);
277  config.spdifMode = enabled ^ 1;
278  SetOsdConfigParam(&config);
279 }
280 #endif
281 
282 #ifdef F_configIsDaylightSavingEnabled
284 {
285  ConfigParam config;
286  Config2Param config2;
287 
288  if(IsT10K())
290 
291  GetOsdConfigParam(&config);
292  if(IsEarlyJap(config))
293  return 0;
294  GetOsdConfigParam2(&config2, 1, 1);
295 
296  return config2.daylightSaving;
297 }
298 #endif
299 
300 #ifdef F_configSetDaylightSavingEnabled
301 void configSetDaylightSavingEnabled(int daylightSaving)
302 {
303  ConfigParam config;
304  Config2Param config2;
305 
306  if(IsT10K())
307  g_t10KConfig.daylightSaving = daylightSaving;
308 
309  GetOsdConfigParam(&config);
310  if(IsEarlyJap(config))
311  return;
312  GetOsdConfigParam2(&config2, 1, 1);
313  config2.daylightSaving = daylightSaving;
314  SetOsdConfigParam2(&config2, 1, 1);
316 }
317 #endif
318 
319 // the following functions are all used in time conversion
320 
321 #ifdef F_configGetTime
322 unsigned char frombcd(unsigned char bcd)
323 {
324  return bcd - (bcd>>4)*6;
325 }
326 unsigned char tobcd(unsigned char dec)
327 {
328  return dec + (dec/10)*6;
329 }
330 
331 void converttobcd(sceCdCLOCK* time)
332 {
333  time->second= tobcd(time->second);
334  time->minute= tobcd(time->minute);
335  time->hour = tobcd(time->hour);
336  time->day = tobcd(time->day);
337  time->month = tobcd(time->month);
338  time->year = tobcd(time->year);
339 }
341 {
342  time->second= frombcd(time->second);
343  time->minute= frombcd(time->minute);
344  time->hour = frombcd(time->hour);
345  time->day = frombcd(time->day);
346  time->month = frombcd(time->month);
347  time->year = frombcd(time->year);
348 }
349 
350 static const unsigned char gDaysInMonths[12] = {
351  31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
352 };
353 
354 void adddate(sceCdCLOCK* time)
355 {
356  // get the days in each month and fix up feb depending on leap year
357  unsigned char days_in_months[12];
358  memcpy(days_in_months, gDaysInMonths, 12);
359  if((time->year & 3) == 0)
360  days_in_months[1] = 29;
361 
362  // increment the day and check its within the "day of the month" bounds
363  time->day++;
364  if(time->day > days_in_months[time->month - 1])
365  {
366  time->day = 1;
367 
368  // increment the month and check its within the "months in a year" bounds
369  time->month++;
370  if(time->month == 13)
371  {
372  time->month = 1;
373 
374  // check the year and increment it
375  time->year++;
376  if(time->year == 100)
377  {
378  time->year = 0;
379  }
380  }
381  }
382 }
383 void subdate(sceCdCLOCK* time)
384 {
385  // get the days in each month and fix up feb depending on leap year
386  unsigned char days_in_months[12];
387  memcpy(days_in_months, gDaysInMonths, 12);
388  if((time->year & 3) == 0)
389  days_in_months[1] = 29;
390 
391  // decrement the day and check its within the "day of the month" bounds
392  time->day--;
393  if(time->day == 0)
394  {
395  // decrement the month and check its within the "months in a year" bounds
396  time->month--;
397  if(time->month == 0)
398  {
399  time->month = 12;
400 
401  // check the year and decrement it
402  if(time->year == 0)
403  time->year = 99;
404  else
405  time->year--;
406  }
407 
408  time->day = days_in_months[time->month-1];
409  }
410 }
411 
412 void addhour(sceCdCLOCK* time)
413 {
414  time->hour++;
415  if(time->hour == 24)
416  {
417  adddate(time);
418  time->hour = 0;
419  }
420 }
421 void subhour(sceCdCLOCK* time)
422 {
423  if(time->hour == 0)
424  {
425  subdate(time);
426  time->hour = 23;
427  }
428  else
429  time->hour--;
430 }
431 
432 void AdjustTime(sceCdCLOCK* time, int offset)
433 {
435  offset += time->minute;
436 
437  if(offset >= 0)
438  {
439  while(offset >= 60)
440  {
441  addhour(time);
442  offset -= 60;
443  }
444  time->minute = offset;
445  }
446  else
447  {
448  while(offset < 0)
449  {
450  subhour(time);
451  offset += 60;
452  }
453  time->minute = offset;
454  }
455 
456  converttobcd(time);
457 }
458 
460 {
461  AdjustTime(time, -540);
462 }
463 
465 {
466  int timezone_offset = configGetTimezone();
467  int daylight_saving = configIsDaylightSavingEnabled();
468  AdjustTime(time, timezone_offset - 540 + (daylight_saving * 60));
469 }
470 #endif
void SetOsdConfigParam(void *addr)
void GetOsdConfigParam(void *addr)
void GetOsdConfigParam2(void *config, s32 size, s32 offset)
void SetOsdConfigParam2(void *config, s32 size, s32 offset)
u32 time
Definition: libmouse.c:37
char g_RomName[]
ConfigParamT10K g_t10KConfig
int IsEarlyJap(ConfigParam config)
void configSetSpdifEnabled(int enabled)
int configGetTvScreenType(void)
void configSetTimeFormat(int timeFormat)
void configSetTimezone(int offset)
int IsT10K(void)
int configGetTimezone(void)
int configGetLanguage(void)
@ TV_SCREEN_43
Definition: osd_config.h:56
@ TV_SCREEN_169
Definition: osd_config.h:58
void configSetDateFormat(int dateFormat)
void configSetLanguage(int language)
@ DATE_YYYYMMDD
Definition: osd_config.h:69
@ DATE_DDMMYYYY
Definition: osd_config.h:71
@ TIME_12H
Definition: osd_config.h:77
int configGetDateFormat(void)
@ LANGUAGE_JAPANESE
Definition: osd_config.h:34
@ LANGUAGE_PORTUGUESE
Definition: osd_config.h:41
void configConvertToGmtTime(sceCdCLOCK *time)
int configIsSpdifEnabled(void)
void configSetDaylightSavingEnabled(int enabled)
int configGetTimeFormat(void)
char * GetRomName(char *romname)
void configSetTvScreenType(int screenType)
int configIsDaylightSavingEnabled(void)
void configConvertToLocalTime(sceCdCLOCK *time)
void _ps2sdk_timezone_update()
Definition: timezone.c:26
void convertfrombcd(sceCdCLOCK *time)
u32 spdifMode
Definition: osd_config.h:83
u32 screenType
Definition: osd_config.h:85
u32 language
Definition: osd_config.h:95
u32 timezoneOffset
Definition: osd_config.h:97
u32 japLanguage
Definition: osd_config.h:89
unsigned short u16
Definition: tamtypes.h:24
unsigned char u8
Definition: tamtypes.h:23