22#include <sys/unistd.h>
26#define NEWLIB_PORT_AWARE
41#define defaultIODriver { (void *)fioOpen, fioClose, fioRead, FIO_O_RDONLY }
45#ifdef F__config_internals
46ConfigParamT10K g_t10KConfig = {540, TV_SCREEN_43, DATE_YYYYMMDD, LANGUAGE_JAPANESE, 0, 0, 0};
50static inline unsigned char tobcd(
unsigned char dec)
52 return dec + (dec / 10) * 6;
57 time->second = tobcd(time->second);
58 time->minute = tobcd(time->minute);
59 time->hour = tobcd(time->hour);
60 time->day = tobcd(time->day);
61 time->month = tobcd(time->month);
62 time->year = tobcd(time->year);
68#ifdef F_convertfrombcd
69static inline unsigned char frombcd(
unsigned char bcd)
71 return bcd - (bcd >> 4) * 6;
77 time->second = frombcd(time->second);
78 time->minute = frombcd(time->minute);
79 time->hour = frombcd(time->hour);
80 time->day = frombcd(time->day);
81 time->month = frombcd(time->month);
82 time->year = frombcd(time->year);
89static const unsigned char gDaysInMonths[12] = {
90 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
95 unsigned char days_in_months[12];
96 memcpy(days_in_months, gDaysInMonths, 12);
97 if ((time->year & 3) == 0)
98 days_in_months[1] = 29;
102 if (time->day > days_in_months[time->month - 1]) {
107 if (time->month == 13) {
112 if (time->year == 100) {
122 unsigned char days_in_months[12];
123 memcpy(days_in_months, gDaysInMonths, 12);
124 if ((time->year & 3) == 0)
125 days_in_months[1] = 29;
129 if (time->day == 0) {
132 if (time->month == 0) {
142 time->day = days_in_months[time->month - 1];
149 if (time->hour == 24) {
157 if (time->hour == 0) {
164void __adjustTime(
sceCdCLOCK *time,
int offset)
166 convertfrombcd(time);
167 offset += time->minute;
170 while (offset >= 60) {
174 time->minute = offset;
180 time->minute = offset;
186extern void __adjustTime(
sceCdCLOCK *time,
int offset);
196#ifdef F_configGetLanguageWithIODriver
197int configGetLanguageWithIODriver(
_io_driver *driver)
201 if (IsT10KWithIODriver(driver))
202 return g_t10KConfig.language;
204 GetOsdConfigParam(&config);
211#ifdef F_configGetLanguage
215 return configGetLanguageWithIODriver(&driver);
219#ifdef F_configSetLanguageWithIODriver
220void configSetLanguageWithIODriver(
int language,
_io_driver *driver)
225 if (language < LANGUAGE_JAPANESE || language > LANGUAGE_PORTUGUESE)
227 if (IsT10KWithIODriver(driver))
228 g_t10KConfig.language = language;
231 GetOsdConfigParam(&config);
236 SetOsdConfigParam(&config);
240#ifdef F_configSetLanguage
244 configSetLanguageWithIODriver(language, &driver);
248#ifdef F_configGetTvScreenTypeWithIODriver
249int configGetTvScreenTypeWithIODriver(
_io_driver *driver)
253 if (IsT10KWithIODriver(driver))
254 return g_t10KConfig.screenType;
256 GetOsdConfigParam(&config);
261#ifdef F_configGetTvScreenType
265 return configGetTvScreenTypeWithIODriver(&driver);
269#ifdef F_configSetTvScreenTypeWithIODriver
270void configSetTvScreenTypeWithIODriver(
int screenType,
_io_driver *driver)
275 if (screenType < TV_SCREEN_43 || screenType > TV_SCREEN_169)
277 if (IsT10KWithIODriver(driver))
278 g_t10KConfig.screenType = screenType;
281 GetOsdConfigParam(&config);
283 SetOsdConfigParam(&config);
287#ifdef F_configSetTvScreenType
291 configSetTvScreenTypeWithIODriver(screenType, &driver);
295#ifdef F_configGetDateFormatWithIODriver
296int configGetDateFormatWithIODriver(
_io_driver *driver)
301 if (IsT10KWithIODriver(driver))
302 return g_t10KConfig.dateFormat;
304 GetOsdConfigParam(&config);
307 GetOsdConfigParam2(&config2,
sizeof(config2), 0);
312#ifdef F_configGetDateFormat
316 return configGetDateFormatWithIODriver(&driver);
320#ifdef F_configSetDateFormatWithIODriver
321void configSetDateFormatWithIODriver(
int dateFormat,
_io_driver *driver)
327 if (dateFormat < DATE_YYYYMMDD || dateFormat > DATE_DDMMYYYY)
329 if (IsT10KWithIODriver(driver))
330 g_t10KConfig.dateFormat = dateFormat;
333 GetOsdConfigParam(&config);
336 GetOsdConfigParam2(&config2,
sizeof(config2), 0);
338 SetOsdConfigParam2(&config2,
sizeof(config2), 0);
342#ifdef F_configSetDateFormat
346 configSetDateFormatWithIODriver(dateFormat, &driver);
350#ifdef F_configGetTimeFormatWithIODriver
351int configGetTimeFormatWithIODriver(
_io_driver *driver)
356 if (IsT10KWithIODriver(driver))
357 return g_t10KConfig.timeFormat;
359 GetOsdConfigParam(&config);
362 GetOsdConfigParam2(&config2,
sizeof(config2), 0);
367#ifdef F_configGetTimeFormat
371 return configGetTimeFormatWithIODriver(&driver);
375#ifdef F_configSetTimeFormatWithIODriver
376void configSetTimeFormatWithIODriver(
int timeFormat,
_io_driver *driver)
382 if (timeFormat < TIME_24H || timeFormat > TIME_12H)
384 if (IsT10KWithIODriver(driver))
385 g_t10KConfig.timeFormat = timeFormat;
388 GetOsdConfigParam(&config);
391 GetOsdConfigParam2(&config2,
sizeof(config2), 0);
393 SetOsdConfigParam2(&config2,
sizeof(config2), 0);
397#ifdef F_configSetTimeFormat
401 configSetTimeFormatWithIODriver(timeFormat, &driver);
405#ifdef F_configGetTimezoneWithIODriver
406int configGetTimezoneWithIODriver(
_io_driver *driver)
411 if (IsT10KWithIODriver(driver))
413 timezoneOffset = g_t10KConfig.timezoneOffset;
417 GetOsdConfigParam(&config);
420 timezoneOffset = 540;
426 if ((timezoneOffset & 0x400) != 0)
429 timezoneOffset ^= 0x7ff;
433 timezoneOffset *= -1;
437 return timezoneOffset;
441#ifdef F_configGetTimezone
445 return configGetTimezoneWithIODriver(&driver);
449#ifdef F_configSetTimezoneWithIODriver
450void configSetTimezoneWithIODriver(
int timezoneOffset,
_io_driver *driver,
void (*finishedCallback)(
void))
455 if (IsT10KWithIODriver(driver))
456 g_t10KConfig.timezoneOffset = timezoneOffset;
458 GetOsdConfigParam(&config);
463 u32 wantedTimezoneOffset;
466 if (timezoneOffset < 0)
469 wantedTimezoneOffset = -timezoneOffset;
471 wantedTimezoneOffset -= 1;
473 wantedTimezoneOffset ^= 0x7ff;
477 wantedTimezoneOffset = timezoneOffset;
483 SetOsdConfigParam(&config);
484 if (finishedCallback)
489#ifdef F_configSetTimezone
493 configSetTimezoneWithIODriver(timezoneOffset, &driver, NULL);
497#ifdef F_configIsSpdifEnabledWithIODriver
498int configIsSpdifEnabledWithIODriver(
_io_driver *driver)
502 if (IsT10KWithIODriver(driver))
503 return g_t10KConfig.spdifMode ^ 1;
505 GetOsdConfigParam(&config);
510#ifdef F_configIsSpdifEnabled
514 return configIsSpdifEnabledWithIODriver(&driver);
518#ifdef F_configSetSpdifEnabledWithIODriver
519void configSetSpdifEnabledWithIODriver(
int enabled,
_io_driver *driver)
523 if (IsT10KWithIODriver(driver))
524 g_t10KConfig.spdifMode = enabled ^ 1;
526 GetOsdConfigParam(&config);
528 SetOsdConfigParam(&config);
532#ifdef F_configSetSpdifEnabled
536 configSetSpdifEnabledWithIODriver(enabled, &driver);
540#ifdef F_configIsDaylightSavingEnabledWithIODriver
541int configIsDaylightSavingEnabledWithIODriver(
_io_driver *driver)
546 if (IsT10KWithIODriver(driver))
547 return g_t10KConfig.daylightSaving;
549 GetOsdConfigParam(&config);
552 GetOsdConfigParam2(&config2,
sizeof(config2), 0);
558#ifdef F_configIsDaylightSavingEnabled
562 return configIsDaylightSavingEnabledWithIODriver(&driver);
566#ifdef F_configSetDaylightSavingEnabledWithIODriver
567void configSetDaylightSavingEnabledWithIODriver(
int daylightSaving,
_io_driver *driver,
void (*finishedCallback)(
void))
572 if (IsT10KWithIODriver(driver))
573 g_t10KConfig.daylightSaving = daylightSaving;
575 GetOsdConfigParam(&config);
578 GetOsdConfigParam2(&config2,
sizeof(config2), 0);
580 SetOsdConfigParam2(&config2,
sizeof(config2), 0);
581 if (finishedCallback)
586#ifdef F_configSetDaylightSavingEnabled
590 configSetDaylightSavingEnabledWithIODriver(daylightSaving, &driver, NULL);
594#ifdef F_configConvertToGmtTime
597 __adjustTime(time, -540);
601#ifdef F_configConvertToLocalTimeWithIODriver
604 int timezone_offset = configGetTimezoneWithIODriver(driver);
605 int daylight_saving = configIsDaylightSavingEnabledWithIODriver(driver);
606 __adjustTime(time, timezone_offset - 540 + (daylight_saving * 60));
610#ifdef F_configConvertToLocalTime
611void configConvertToLocalTime(
sceCdCLOCK *time)
614 configConvertToLocalTimeWithIODriver(time, &driver);
int IsEarlyJap(ConfigParam config)
void configSetSpdifEnabled(int enabled)
int configGetTvScreenType(void)
void configSetTimeFormat(int timeFormat)
void configSetTimezone(int offset)
int configGetTimezone(void)
int configGetLanguage(void)
void configSetDateFormat(int dateFormat)
void configSetLanguage(int language)
int configGetDateFormat(void)
void configConvertToGmtTime(sceCdCLOCK *time)
int configIsSpdifEnabled(void)
void configSetDaylightSavingEnabled(int enabled)
int configGetTimeFormat(void)
void configSetTvScreenType(int screenType)
int configIsDaylightSavingEnabled(void)