Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /******************************************************************************
- Online C Compiler.
- Code, Compile, Run and Debug C program online.
- Write your code in this editor and press "Run" button to compile and execute it.
- *******************************************************************************/
- #include <stdio.h>
- typedef unsigned char u8;
- typedef unsigned short u16;
- typedef int BOOL;
- #define FALSE 0
- #define TRUE 1
- typedef u8 unchar;
- typedef u16 unshort;
- typedef struct{
- u8 sec; /* second 0-59 */
- u8 min; /* minute 0-59 */
- u8 hour; /* hour 0-23 */
- u8 day; /* day 1-31 */
- u8 week; /* week 0-6(sun,mon,..,sat) */
- u8 month; /* month 1-12 */
- u16 year; /* year 1901-2099 */
- } OSRTCTime;
- typedef OSRTCTime lbRTC_time_c;
- typedef u8 lbRTC_ss_t;
- typedef u8 lbRTC_mm_t;
- typedef u8 lbRTC_hh_t;
- typedef u8 lbRTC_DD_t;
- typedef u8 lbRTC_WW_t;
- typedef u8 lbRTC_MM_t;
- typedef u16 lbRTC_YY_t;
- enum {
- JANUARY = 1,
- FEBRUARY,
- MARCH,
- APRIL,
- MAY,
- JUNE,
- JULY,
- AUGUST,
- SEPTEMBER,
- OCTOBER,
- NOVEMBER,
- DECEMBER,
- TWELVEMONTH
- };
- enum {
- DAY_01 = 1, DAY_02, DAY_03, DAY_04,
- DAY_05, DAY_06, DAY_07, DAY_08, DAY_09,
- DAY_10, DAY_11, DAY_12, DAY_13, DAY_14,
- DAY_15, DAY_16, DAY_17, DAY_18, DAY_19,
- DAY_20, DAY_21, DAY_22, DAY_23, DAY_24,
- DAY_25, DAY_26, DAY_27, DAY_28, DAY_29,
- DAY_30, DAY_31
- };
- /*
- * 曜日
- */
- enum {
- SUNDAY,
- MONDAY,
- TUESDAY,
- WEDNESDAY,
- THURSDAY,
- FRIDAY,
- SATURDAY,
- SEVENDAYS_IN_A_WEEK
- };
- /*
- * 時間
- */
- enum {
- TIME_00, TIME_01, TIME_02, TIME_03, TIME_04, TIME_05,
- TIME_06, TIME_07, TIME_08, TIME_09, TIME_10, TIME_11,
- TIME_12, TIME_13, TIME_14, TIME_15, TIME_16, TIME_17,
- TIME_18, TIME_19, TIME_20, TIME_21, TIME_22, TIME_23,
- TIME_ED
- };
- enum rtc_month {
- lbRTC_JANUARY = 1, /* 1月 */
- lbRTC_FEBRUARY, /* 2月 */
- lbRTC_MARCH, /* 3月 */
- lbRTC_APRIL, /* 4月 */
- lbRTC_MAY, /* 5月 */
- lbRTC_JUNE, /* 6月 */
- lbRTC_JULY, /* 7月 */
- lbRTC_AUGUST, /* 8月 */
- lbRTC_SEPTEMBER, /* 9月 */
- lbRTC_OCTOBER, /* 10月 */
- lbRTC_NOVEMBER, /* 11月 */
- lbRTC_DECEMBER, /* 12月 */
- lbRTC_MONTH_NUM = lbRTC_DECEMBER
- };
- /* 年 */
- enum rtc_yesr {
- lbRTC_NORMAL_YEAR, /* 通常年 */
- lbRTC_LEAP_YEAR, /* 閏年 */
- lbRTC_MODE
- };
- /* 時間と秒 */
- enum rtc_hour_and_minute_seccond {
- lbRTC_HOURS = 24, /* 一日の時間数 */
- lbRTC_MINUTES = 60, /* 1時間の分数 */
- lbRTC_SECCONDS = 60 /* 1分の秒数 */
- };
- #define lbRk_YEAR_MIN 2000
- #define lbRk_YEAR_MAX 2032
- #define lbRk_YEAR_NUM ((lbRk_YEAR_MAX - lbRk_YEAR_MIN) + 1)
- #define lbRk_KYUU_MONTH_START 1
- #define lbRk_KYUU_MONTH_END 12
- #define lbRk_KYUU_LEAP_MONTH 13
- #define day_of_week(day) ((day) & 0x07) /* 曜日ゲット */
- #define cycle_of_week(day) (((day) & 0x78) >> 3) /* 何週目か? */
- /* flag */
- #define EV_FLG_WDAY (0x01) /* 曜日 */
- #define EV_FLG_WEEKLY (0x02) /* 毎週 */
- #define EV_FLG_MONTHLY (0x04) /* 毎月 */
- #define EV_FLG_JPOLD (0x08) /* 旧暦 */
- /* alias */
- #define EV_DATE_MONTH_DAY (0x00) /* ?月?日 */
- #define EV_DATE_MONTH_N_WDAY (0x01) /* ?月第n?曜日 */
- #define EV_DATE_MONTH_WEEKLY (0x03) /* ?月毎週?曜日 */
- #define EV_DATE_DAY (0x04) /* 毎月?日 */
- #define EV_DATE_N_WDAY (0x05) /* 毎月第n?曜日 */
- #define EV_DATE_WEEKLY (0x07) /* 毎月毎週?曜日 */
- #define EV_DATE_JP_MONTH_DAY (0x08) /* 旧暦?月?日 */
- #define EV_SPDATE_EVERYMONTH (50)
- #define EV_SPDATE_LASTDAY (99)
- /*
- ** 曜日 ** */
- #define EV_WEEK_SUNDAY (0)
- #define EV_WEEK_MONDAY (1)
- #define EV_WEEK_TUESDAY (2)
- #define EV_WEEK_WEDNESDAY (3)
- #define EV_WEEK_THURSDAY (4)
- #define EV_WEEK_FRIDAY (5)
- #define EV_WEEK_SATURDAY (6)
- #define EV_WEEK_ANYDAY (7) /* 何曜日でも */
- /*
- ** 第?週 ** */
- #define EV_WEEK_FIRST (0x01)
- #define EV_WEEK_SECOND (0x02)
- #define EV_WEEK_THIRD (0x03)
- #define EV_WEEK_FOURTH (0x04)
- #define EV_WEEK_FIFTH (0x05)
- #define EV_WEEK_LAST (0x0f) /* 最終?曜日 */
- #define EV_WEEK_EVELY (0x09) /* 毎週 */
- /*
- ** セーブレジスタ ** */
- #define EV_SAVE_TODAY ( 0)
- #define EV_SAVE_LASTPLAYDAY ( 1)
- #define EV_SAVE_BIRTHDAY ( 2)
- #define EV_SAVE_SPECIAL0 ( 3)
- #define EV_SAVE_SPECIAL1 ( 4)
- #define EV_SAVE_SPECIAL2 ( 5)
- #define EV_SAVE_WEEKLY0 ( 6)
- #define EV_SAVE_SPECIAL3 ( 7)
- #define lbRTC_MAX_YEAR 2099
- #define lbRTC_MAX_MONTH 12
- #define lbRTC_MAX_DAY 31
- #define lbRTC_MAX_HOUR 23
- #define lbRTC_MAX_MINUTE 59
- #define lbRTC_MAX_SECOND 59
- #define lbRTC_MIN_YEAR 1901
- #define lbRTC_MIN_MONTH 1
- #define lbRTC_MIN_DAY 1
- #define lbRTC_MIN_HOUR 0
- #define lbRTC_MIN_MINUTE 0
- #define lbRTC_MIN_SECOND 0
- #define to_ev_month_day(month, day) ((u16)((month << 8) | (day)))
- /*
- * 年・月・日のみの日付データ
- */
- typedef struct year_month_day_data {
- lbRTC_YY_t year;
- lbRTC_MM_t month;
- lbRTC_DD_t day;
- } lbRTC_ymd_c;
- typedef struct _event_date_data_ {
- char month, day, flag, hour;
- } evdate_t;
- typedef union _event_schedule_date_ {
- evdate_t d; /* 日付時間 */
- unsigned short v, f; /* インテル互換なし */
- unsigned long lv;
- } evdate_u;
- typedef struct _event_schedule_ {
- evdate_u day[2];
- short f, type;
- } EvSchedule;
- #define ZCommonGet(m) m
- typedef struct {
- OSRTCTime rtcTime;
- } TIME_c;
- static TIME_c time = {
- {
- 0, // sec
- 0, // min
- 0, // hour
- 18, // day
- 0, // week
- 9, // month
- 2022 // year
- }
- };
- /* Conversion table -- holds modern calendar {month, day} pairs to convert from Japanese Lunar date to Modern date */
- static unchar l_lbRk_ConvertTable[][lbRk_KYUU_LEAP_MONTH][2] = {
- {{0x02, 0x05}, {0x03, 0x06}, {0x04, 0x05}, {0x05, 0x04}, {0x06, 0x02}, {0x07, 0x02}, {0x07, 0x1f}, {0x08, 0x1d}, {0x09, 0x1c}, {0x0a, 0x1b}, {0x0b, 0x1a}, {0x0c, 0x1a}, {0x00, 0x00}},
- {{0x01, 0x18}, {0x02, 0x17}, {0x03, 0x19}, {0x04, 0x18}, {0x06, 0x15}, {0x07, 0x15}, {0x08, 0x13}, {0x09, 0x11}, {0x0a, 0x11}, {0x0b, 0x0f}, {0x0c, 0x0f}, {0x01, 0x0d}, {0x05, 0x17}},
- {{0x02, 0x0c}, {0x03, 0x0e}, {0x04, 0x0d}, {0x05, 0x0c}, {0x06, 0x0b}, {0x07, 0x0a}, {0x08, 0x09}, {0x09, 0x07}, {0x0a, 0x06}, {0x0b, 0x05}, {0x0c, 0x04}, {0x01, 0x03}, {0x00, 0x00}},
- {{0x02, 0x01}, {0x03, 0x03}, {0x04, 0x02}, {0x05, 0x01}, {0x05, 0x1f}, {0x06, 0x1e}, {0x07, 0x1d}, {0x08, 0x1c}, {0x09, 0x1d}, {0x0a, 0x19}, {0x0b, 0x18}, {0x0c, 0x17}, {0x00, 0x00}},
- {{0x01, 0x16}, {0x02, 0x14}, {0x04, 0x13}, {0x05, 0x13}, {0x06, 0x12}, {0x07, 0x11}, {0x08, 0x10}, {0x09, 0x0e}, {0x0a, 0x0e}, {0x0b, 0x0c}, {0x0c, 0x0c}, {0x01, 0x0a}, {0x03, 0x15}},
- {{0x02, 0x09}, {0x03, 0x0a}, {0x04, 0x09}, {0x05, 0x08}, {0x06, 0x07}, {0x07, 0x06}, {0x08, 0x05}, {0x09, 0x04}, {0x0a, 0x03}, {0x0b, 0x02}, {0x0c, 0x02}, {0x0c, 0x1f}, {0x00, 0x00}},
- {{0x01, 0x1d}, {0x02, 0x1c}, {0x03, 0x1d}, {0x04, 0x1c}, {0x05, 0x1b}, {0x06, 0x1a}, {0x07, 0x19}, {0x09, 0x16}, {0x0a, 0x16}, {0x0b, 0x15}, {0x0c, 0x14}, {0x01, 0x13}, {0x08, 0x18}},
- {{0x02, 0x12}, {0x03, 0x13}, {0x04, 0x11}, {0x05, 0x11}, {0x06, 0x0f}, {0x07, 0x0e}, {0x08, 0x0d}, {0x09, 0x0b}, {0x0a, 0x0b}, {0x0b, 0x0a}, {0x0c, 0x0a}, {0x01, 0x08}, {0x00, 0x00}},
- {{0x02, 0x07}, {0x03, 0x08}, {0x04, 0x06}, {0x05, 0x05}, {0x06, 0x04}, {0x07, 0x03}, {0x08, 0x01}, {0x08, 0x1f}, {0x09, 0x1d}, {0x0a, 0x1d}, {0x0b, 0x1c}, {0x0c, 0x1b}, {0x00, 0x00}},
- {{0x01, 0x1a}, {0x02, 0x19}, {0x03, 0x1b}, {0x04, 0x19}, {0x05, 0x18}, {0x07, 0x16}, {0x08, 0x14}, {0x09, 0x13}, {0x0a, 0x12}, {0x0b, 0x11}, {0x0c, 0x10}, {0x01, 0x0f}, {0x06, 0x17}},
- {{0x02, 0x0e}, {0x03, 0x10}, {0x04, 0x0e}, {0x05, 0x0e}, {0x06, 0x0c}, {0x07, 0x0c}, {0x08, 0x0a}, {0x09, 0x08}, {0x0a, 0x08}, {0x0b, 0x06}, {0x0c, 0x06}, {0x01, 0x04}, {0x00, 0x00}},
- {{0x02, 0x03}, {0x03, 0x05}, {0x04, 0x03}, {0x05, 0x03}, {0x06, 0x02}, {0x07, 0x01}, {0x07, 0x1f}, {0x08, 0x1d}, {0x09, 0x1b}, {0x0a, 0x1b}, {0x0b, 0x19}, {0x0c, 0x19}, {0x00, 0x00}},
- {{0x01, 0x17}, {0x02, 0x16}, {0x03, 0x16}, {0x05, 0x15}, {0x06, 0x14}, {0x07, 0x13}, {0x08, 0x12}, {0x09, 0x10}, {0x0a, 0x0f}, {0x0b, 0x0e}, {0x0c, 0x0d}, {0x01, 0x0c}, {0x04, 0x15}},
- {{0x02, 0x0a}, {0x03, 0x0c}, {0x04, 0x0a}, {0x05, 0x0a}, {0x06, 0x09}, {0x07, 0x08}, {0x08, 0x07}, {0x09, 0x05}, {0x0a, 0x05}, {0x0b, 0x03}, {0x0c, 0x03}, {0x01, 0x01}, {0x00, 0x00}},
- {{0x01, 0x1f}, {0x03, 0x01}, {0x03, 0x1f}, {0x04, 0x1d}, {0x05, 0x1d}, {0x06, 0x1b}, {0x07, 0x1b}, {0x08, 0x19}, {0x09, 0x18}, {0x0b, 0x16}, {0x0c, 0x16}, {0x01, 0x14}, {0x0a, 0x18}},
- {{0x02, 0x13}, {0x03, 0x14}, {0x04, 0x13}, {0x05, 0x12}, {0x06, 0x10}, {0x07, 0x10}, {0x08, 0x0e}, {0x09, 0x0d}, {0x0a, 0x0d}, {0x0b, 0x0c}, {0x0c, 0x0b}, {0x01, 0x0a}, {0x00, 0x00}},
- {{0x02, 0x08}, {0x03, 0x09}, {0x04, 0x07}, {0x05, 0x07}, {0x06, 0x05}, {0x07, 0x04}, {0x08, 0x03}, {0x09, 0x01}, {0x0a, 0x01}, {0x0a, 0x1f}, {0x0b, 0x1d}, {0x0c, 0x1d}, {0x00, 0x00}},
- {{0x01, 0x1c}, {0x02, 0x1a}, {0x03, 0x1c}, {0x04, 0x1a}, {0x05, 0x1a}, {0x07, 0x17}, {0x08, 0x16}, {0x09, 0x14}, {0x0a, 0x14}, {0x0b, 0x12}, {0x0c, 0x12}, {0x01, 0x11}, {0x06, 0x18}},
- {{0x02, 0x10}, {0x03, 0x11}, {0x04, 0x10}, {0x05, 0x0f}, {0x06, 0x0e}, {0x07, 0x0d}, {0x08, 0x0b}, {0x09, 0x0a}, {0x0a, 0x09}, {0x0b, 0x08}, {0x0c, 0x1b}, {0x01, 0x06}, {0x00, 0x00}},
- {{0x02, 0x05}, {0x03, 0x07}, {0x04, 0x05}, {0x05, 0x05}, {0x06, 0x03}, {0x07, 0x03}, {0x08, 0x01}, {0x08, 0x1e}, {0x09, 0x1d}, {0x0a, 0x1c}, {0x0b, 0x1b}, {0x0c, 0x1a}, {0x00, 0x00}},
- {{0x01, 0x19}, {0x02, 0x18}, {0x03, 0x18}, {0x04, 0x17}, {0x06, 0x15}, {0x07, 0x15}, {0x08, 0x13}, {0x09, 0x11}, {0x0a, 0x11}, {0x0b, 0x0f}, {0x0c, 0x0f}, {0x01, 0x0d}, {0x05, 0x17}},
- {{0x02, 0x0c}, {0x03, 0x0d}, {0x04, 0x0c}, {0x05, 0x0c}, {0x06, 0x0a}, {0x07, 0x0a}, {0x08, 0x08}, {0x09, 0x07}, {0x0a, 0x06}, {0x0b, 0x05}, {0x0c, 0x04}, {0x01, 0x03}, {0x00, 0x00}},
- {{0x02, 0x01}, {0x03, 0x03}, {0x04, 0x01}, {0x05, 0x01}, {0x05, 0x1e}, {0x06, 0x1d}, {0x07, 0x1d}, {0x08, 0x1b}, {0x09, 0x1a}, {0x0a, 0x19}, {0x0b, 0x18}, {0x0c, 0x17}, {0x00, 0x00}},
- {{0x01, 0x16}, {0x02, 0x14}, {0x03, 0x16}, {0x05, 0x14}, {0x06, 0x12}, {0x07, 0x12}, {0x08, 0x10}, {0x09, 0x0f}, {0x0a, 0x0f}, {0x0b, 0x0d}, {0x0c, 0x0d}, {0x01, 0x0b}, {0x04, 0x14}},
- {{0x02, 0x0a}, {0x03, 0x0a}, {0x04, 0x09}, {0x05, 0x08}, {0x06, 0x06}, {0x07, 0x06}, {0x08, 0x04}, {0x09, 0x03}, {0x0a, 0x03}, {0x0b, 0x01}, {0x0c, 0x01}, {0x0c, 0x1f}, {0x00, 0x00}},
- {{0x01, 0x1d}, {0x02, 0x1c}, {0x03, 0x1d}, {0x04, 0x1c}, {0x05, 0x1b}, {0x06, 0x19}, {0x08, 0x17}, {0x09, 0x16}, {0x0a, 0x15}, {0x0b, 0x14}, {0x0c, 0x14}, {0x01, 0x13}, {0x07, 0x19}},
- {{0x02, 0x11}, {0x03, 0x13}, {0x04, 0x11}, {0x05, 0x11}, {0x06, 0x0f}, {0x07, 0x0e}, {0x08, 0x0d}, {0x09, 0x0b}, {0x0a, 0x0b}, {0x0b, 0x09}, {0x0c, 0x09}, {0x01, 0x08}, {0x00, 0x00}},
- {{0x02, 0x07}, {0x03, 0x08}, {0x04, 0x07}, {0x05, 0x06}, {0x06, 0x05}, {0x07, 0x04}, {0x08, 0x02}, {0x09, 0x01}, {0x09, 0x1e}, {0x0a, 0x1d}, {0x0b, 0x1c}, {0x0c, 0x1c}, {0x00, 0x00}},
- {{0x01, 0x1b}, {0x02, 0x19}, {0x03, 0x1a}, {0x04, 0x19}, {0x05, 0x18}, {0x07, 0x16}, {0x08, 0x14}, {0x09, 0x13}, {0x0a, 0x12}, {0x0b, 0x10}, {0x0c, 0x10}, {0x01, 0x0f}, {0x06, 0x17}},
- {{0x02, 0x0d}, {0x03, 0x0f}, {0x04, 0x0e}, {0x05, 0x0d}, {0x06, 0x0c}, {0x07, 0x0c}, {0x08, 0x0a}, {0x09, 0x08}, {0x0a, 0x08}, {0x0b, 0x06}, {0x0c, 0x05}, {0x01, 0x04}, {0x00, 0x00}},
- {{0x02, 0x03}, {0x03, 0x04}, {0x04, 0x03}, {0x05, 0x02}, {0x06, 0x01}, {0x07, 0x01}, {0x07, 0x1e}, {0x08, 0x1d}, {0x09, 0x1b}, {0x0a, 0x1b}, {0x0b, 0x19}, {0x0c, 0x19}, {0x00, 0x00}},
- {{0x01, 0x17}, {0x02, 0x16}, {0x03, 0x17}, {0x04, 0x16}, {0x06, 0x14}, {0x07, 0x13}, {0x08, 0x12}, {0x09, 0x11}, {0x0a, 0x10}, {0x0b, 0x0f}, {0x0c, 0x0e}, {0x01, 0x0d}, {0x05, 0x15}},
- {{0x02, 0x0b}, {0x03, 0x0c}, {0x04, 0x0a}, {0x05, 0x09}, {0x06, 0x08}, {0x07, 0x07}, {0x08, 0x06}, {0x09, 0x05}, {0x0a, 0x04}, {0x0b, 0x03}, {0x0c, 0x03}, {0x01, 0x01}, {0x00, 0x00}}
- };
- static int l_lbRk_leapdays[] = {
- 0, 29, 0, 0, 29, 0, 29, 0,
- 0, 29, 0, 0, 30, 0, 29, 0,
- 0, 29, 0, 0, 29, 0, 0, 30,
- 0, 29, 0, 0, 29, 0, 0, 30,
- 0
- };
- static lbRTC_DD_t weekday1st[lbRTC_MAX_MONTH + 1];
- extern lbRTC_DD_t lbRk_SeirekiDays(lbRTC_YY_t year, lbRTC_MM_t month) {
- static lbRTC_DD_t t_seiyo_days_tbl[][lbRTC_MONTH_NUM + 1] = {
- {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, /* Standard days for each month */
- {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31} /* Days for each month during leap year */
- };
- return t_seiyo_days_tbl[(year & 3) == 0][month];
- }
- static unchar* lbRk_ToSeiyoMonthAndDay(lbRTC_YY_t year, int month) {
- return l_lbRk_ConvertTable[year - lbRk_YEAR_MIN][month - 1];
- }
- extern int lbRk_KyuurekiLeapDays(lbRTC_YY_t year) {
- return l_lbRk_leapdays[year - lbRk_YEAR_MIN];
- }
- extern int lbRk_IsKyuurekiLeapYear(lbRTC_YY_t year) {
- return l_lbRk_leapdays[year - lbRk_YEAR_MIN] != 0 ? TRUE : FALSE;
- }
- static int lbRk_IsLeapMonth(lbRTC_MM_t month) {
- return month == lbRk_KYUU_LEAP_MONTH ? TRUE : FALSE;
- }
- static int lbRk_IsLeapOnNextMonth(lbRTC_YY_t year, int month) {
- return lbRk_ToSeiyoMonthAndDay(year, month)[0] + 1 == l_lbRk_ConvertTable[year - lbRk_YEAR_MIN][lbRk_KYUU_LEAP_MONTH - 1][0];
- }
- extern int lbRk_KyuurekiDays(lbRTC_YY_t year, int month) {
- unchar* seiyo_month_day = lbRk_ToSeiyoMonthAndDay(year, month);
- if (lbRk_IsLeapMonth(month) == TRUE) {
- return lbRk_KyuurekiLeapDays(year);
- }
- unchar* next_seiyo_month_day;
- if (month == lbRk_KYUU_MONTH_END) {
- next_seiyo_month_day = lbRk_ToSeiyoMonthAndDay(year + 1, lbRk_KYUU_MONTH_START);
- }
- else {
- next_seiyo_month_day = lbRk_IsLeapOnNextMonth(year, month) == TRUE ?
- lbRk_ToSeiyoMonthAndDay(year, lbRk_KYUU_LEAP_MONTH) :
- lbRk_ToSeiyoMonthAndDay(year, month + 1);
- }
- if (next_seiyo_month_day[0] == seiyo_month_day[0]) {
- return next_seiyo_month_day[1] - seiyo_month_day[1];
- }
- if (month > seiyo_month_day[0]) year++;
- int days = lbRk_SeirekiDays(year, seiyo_month_day[0]) - seiyo_month_day[1]; /* Days in standard month - conversion days */
- if (next_seiyo_month_day[0] - seiyo_month_day[0] > 1) {
- days += lbRk_SeirekiDays(year, seiyo_month_day[0] + 1);
- }
- days += next_seiyo_month_day[1];
- return days;
- }
- /* Japanese Lunar Calendar -> Modern Calendar */
- extern int lbRk_ToSeiyouReki(lbRTC_ymd_c* dst, lbRTC_ymd_c* src) {
- if (src->year == 0 || src->year > lbRk_YEAR_MAX) {
- return FALSE; /* Year out of bounds */
- }
- if (src->month > lbRk_KYUU_LEAP_MONTH) {
- return FALSE; /* Month out of bounds */
- }
- if (lbRk_IsKyuurekiLeapYear(src->year) == FALSE) {
- if (src->month > lbRk_KYUU_MONTH_END) {
- return FALSE; /* Month out of bounds, leap month excluded */
- }
- }
- if (lbRk_KyuurekiDays(src->year, src->month) < src->day) {
- return FALSE; /* Day out of bounds */
- }
- unchar* seiyo_month_day = lbRk_ToSeiyoMonthAndDay(src->year, src->month);
- lbRTC_YY_t year = src->year;
- lbRTC_MM_t month = seiyo_month_day[0];
- lbRTC_DD_t day = (seiyo_month_day[1] + src->day) - 1;
- lbRTC_DD_t seireki_days = lbRk_SeirekiDays(year, month);
- if (day > seireki_days) {
- month++;
- day -= seireki_days;
- if (month > lbRTC_MONTH_NUM) {
- month = 1; /* This is almost certainly a bug. There should be a year++ here. */
- }
- }
- if (src->month > month) {
- if (src->month != lbRk_KYUU_LEAP_MONTH) {
- year++; /* Add a year if we aren't on the leap month. */
- }
- }
- dst->year = year;
- dst->month = month;
- dst->day = day;
- }
- static u16 kyu2sei(evdate_u* kyu_date) {
- lbRTC_ymd_c dst;
- lbRTC_ymd_c src = { ZCommonGet(time.rtcTime.year), kyu_date->d.month, kyu_date->d.day };
- lbRk_ToSeiyouReki(&dst, &src);
- return (unsigned short)((dst.month << 8) | dst.day);
- }
- static lbRTC_DD_t last_day_of_month(lbRTC_MM_t month) {
- static lbRTC_DD_t last_day[] = {
- 31, 28, 31, 30,
- 31, 30, 31, 31,
- 30, 31, 30, 31
- };
- if (month == FEBRUARY) {
- lbRTC_YY_t year = ZCommonGet(time.rtcTime.year);
- return (year & 3) == 0 && (year % 100) != 0 && (year % 400) == 0 ? 28 : 29; /* Leap year day for Feb */
- }
- return last_day[month - 1];
- }
- static lbRTC_DD_t m_weekday2day(lbRTC_MM_t month, lbRTC_DD_t day) {
- int week_cycle = cycle_of_week(day);
- /* NOTE: EVELY is a misspelling of EVERY */
- if (week_cycle == EV_WEEK_EVELY) {
- lbRTC_MM_t current_month = ZCommonGet(time.rtcTime.month);
- if (current_month < month) {
- week_cycle = EV_WEEK_FIRST;
- }
- else if (current_month > month) {
- week_cycle = EV_WEEK_LAST;
- }
- else {
- week_cycle = 0; /* No additional processing */
- printf("Day this week\n");
- return (ZCommonGet(time.rtcTime.day) - ZCommonGet(time.rtcTime.week)) + (day & EV_WEEK_ANYDAY); /* Day this week */
- }
- }
- if (week_cycle == EV_WEEK_LAST) {
- day &= EV_WEEK_ANYDAY;
- lbRTC_DD_t last_day = last_day_of_month(month);
- lbRTC_DD_t adj = (weekday1st[month] + last_day - 1) % EV_WEEK_ANYDAY;
- return adj < day
- ? ((last_day - adj) + day) - EV_WEEK_ANYDAY
- : (last_day - adj) + day;
- }
- if (week_cycle != 0) {
- lbRTC_DD_t first = weekday1st[month];
- day &= EV_WEEK_ANYDAY;
- return day < first
- ? ((week_cycle * EV_WEEK_ANYDAY + day) - first) + 1
- : ((week_cycle * EV_WEEK_ANYDAY + day) - first) - 6;
- }
- return 0; /* This should never happen */
- }
- static evdate_u decode_date(evdate_u* enc_date) {
- evdate_u date;
- date.d.month = enc_date->d.month;
- /* Check for event that happens month */
- if (date.d.month == EV_SPDATE_EVERYMONTH) {
- date.d.month = ZCommonGet(time.rtcTime.month);
- }
- date.d.day = enc_date->d.day;
- /* Check for last day of month event */
- if (date.d.day == EV_SPDATE_LASTDAY) {
- date.d.day = last_day_of_month(date.d.month);
- }
- /* Check if the event's date is a "cached" day in the game save */
- if (date.d.month > EV_SPDATE_LASTDAY) {
- //date.v = SaveGet(event.xday[date.d.month - 100]); /* Save data is month-day pairing */
- date.v = 0;
- printf("Date's month-day combo is in save event!\n");
- }
- date.d.flag = enc_date->d.flag;
- date.d.hour = enc_date->d.hour;
- /* Check if the event's hour is a "cached" time in the game save */
- if ((date.d.hour & 0x20) != 0) {
- date.d.hour = 0;
- printf("Date's hour is in save event!\n");
- //date.d.hour = (char)SaveGet(event.xday[date.d.hour & 0x1F]) | (date.d.hour & 0xC0);
- }
- /* Check if date is Japanese Lunar Calendar format */
- if (date.d.month >= 80) {
- date.d.month -= 80;
- if (date.d.month < lbRk_KYUU_LEAP_MONTH) {
- date.v = kyu2sei(&date); /* Standard Lunar conversion */
- date.v = (u16)((date.v >> 8) | (date.v << 8)); // LE
- } else {
- /* Calculate Lunar New Year */
- evdate_u lunar_newyear;
- lunar_newyear.d.month = lbRk_KYUU_MONTH_START;
- lunar_newyear.d.day = DAY_01;
- lunar_newyear.d.flag = 0;
- lunar_newyear.d.flag = TIME_00;
- /* Lunar New Year date conversion */
- lunar_newyear.v = kyu2sei(&lunar_newyear);
- u16 compare = lunar_newyear.v;
- lunar_newyear.v = (u16)((lunar_newyear.v >> 8) | (lunar_newyear.v << 8)); // LE
- if (date.d.day == DAY_30) {
- if (compare != to_ev_month_day(FEBRUARY, DAY_01)) {
- date.d.month = lunar_newyear.d.month;
- date.d.day = lunar_newyear.d.day - 1;
- } else {
- date.d.day = DAY_31;
- date.d.month = JANUARY;
- }
- } else if (date.d.day == DAY_29) {
- if (compare == to_ev_month_day(FEBRUARY, DAY_02)) {
- date.d.day = DAY_31;
- date.d.month = JANUARY;
- } else if (compare == to_ev_month_day(FEBRUARY, DAY_01)) {
- date.d.day = DAY_30;
- date.d.month = JANUARY;
- } else {
- date.d.month = lunar_newyear.d.month;
- date.d.day = lunar_newyear.d.day - 2;
- }
- } else if (date.d.day == DAY_25) {
- if (compare == to_ev_month_day(FEBRUARY, DAY_05)) {
- date.d.day = DAY_31;
- date.d.month = JANUARY;
- } else if (compare == to_ev_month_day(FEBRUARY, DAY_04)) {
- date.d.day = DAY_30;
- date.d.month = JANUARY;
- } else if (compare == to_ev_month_day(FEBRUARY, DAY_03)) {
- date.d.day = DAY_29;
- date.d.month = JANUARY;
- } else if (compare == to_ev_month_day(FEBRUARY, DAY_02)) {
- date.d.day = DAY_28;
- date.d.month = JANUARY;
- } else if (compare == to_ev_month_day(FEBRUARY, DAY_01)) {
- date.d.day = DAY_27;
- date.d.month = JANUARY;
- } else if (compare == to_ev_month_day(JANUARY, DAY_05)) {
- date.d.day = DAY_31;
- date.d.month = DECEMBER;
- } else if (compare == to_ev_month_day(JANUARY, DAY_04)) {
- date.d.day = DAY_30;
- date.d.month = DECEMBER;
- } else if (compare == to_ev_month_day(JANUARY, DAY_03)) {
- date.d.day = DAY_29;
- date.d.month = DECEMBER;
- } else if (compare == to_ev_month_day(JANUARY, DAY_02)) {
- date.d.day = DAY_28;
- date.d.month = DECEMBER;
- } else if (compare == to_ev_month_day(JANUARY, DAY_01)) {
- date.d.day = DAY_27;
- date.d.month = DECEMBER;
- } else {
- date.d.day = lunar_newyear.d.day - 5;
- date.d.month = lunar_newyear.d.month;
- }
- }
- }
- }
- /* Check for day of week event */
- if ((date.d.day & 0x80) != 0) {
- date.d.day = m_weekday2day(date.d.month, date.d.day);
- }
- return date;
- }
- const char* event_names[] = {
- "APP_ADMIRE_MOON",
- "APP_AUTUMN_FIELD_DAY",
- "APP_AUTUMN_FISHING",
- "APP_A_HAPPY_NEW_YEAR",
- "APP_CHILDRENS_DAY",
- "APP_CHRISTMAS",
- "APP_COUNT_DOWN",
- "APP_FD_BASKET_SHOOTING",
- "APP_FD_CALISTHENICS",
- "APP_FD_TUG_OF_WAR",
- "APP_FD_WALK_RACE",
- "APP_FIREWORKS",
- "APP_FLOWER_VIEWING",
- "APP_HALLOWEEN",
- "APP_KAMAKURA",
- "APP_MATSUTAKE",
- "APP_RADIO_CALISTHENICS",
- "APP_SNOWMAN",
- "APP_SPRING_FIELD_DAY",
- "APP_ST_VALENTINE",
- "APP_SUMMER_FISHING",
- "APP_WATER_MOON13",
- "APP_WATER_MOON15",
- "APP_WHITE_DAY",
- "FLG_CARP_PENNANT",
- "FLG_CHERRY_BLOSSOM",
- "FLG_CHRISTMASSONG",
- "FLG_FATHER_DAY",
- "FLG_MOTHER_DAY",
- "FS_BIRTHDAY",
- "FS_DOWNING",
- "FS_KABU_PEDDLER",
- "FS_LOTTERY",
- "FS_STAFFROLL",
- "HBL_BROKER",
- "HBL_SHOP",
- "RMR_ADMIRE_MOON_0",
- "RMR_ADMIRE_MOON_1",
- "RMR_AUTUMN_FIELD_DAY",
- "RMR_AUTUMN_FISHING_0",
- "RMR_AUTUMN_FISHING_1",
- "RMR_A_HAPPY_NEW_YEAR",
- "RMR_CHILDRENS_DAY_0",
- "RMR_CHILDRENS_DAY_1",
- "RMR_CHRISTMAS",
- "RMR_COUNT_DOWN",
- "RMR_FIREWORKS_0",
- "RMR_FIREWORKS_1",
- "RMR_FLOWER_VIEWING_0",
- "RMR_FLOWER_VIEWING_1",
- "RMR_HALLOWEEN",
- "RMR_KAMAKURA",
- "RMR_MATSUTAKE_0",
- "RMR_MATSUTAKE_1",
- "RMR_RADIO_CALISTHENICS_0",
- "RMR_RADIO_CALISTHENICS_1",
- "RMR_SPRING_FIELD_DAY",
- "RMR_ST_VALENTINE",
- "RMR_SUMMER_FISHING_0",
- "RMR_SUMMER_FISHING_1",
- "RMR_WHITE_DAY",
- "SPC_ARTIST",
- "SPC_BROKER",
- "SPC_DESIGNER",
- "SPC_GYPSY",
- "SPC_SHOP",
- "SPC_SILK",
- "WEZ_FINE_DAY",
- "WEZ_SNOW_DAY",
- "ZFS_MISTERY_PACKAGE",
- "SCHEDULE_NO_END",
- };
- int main()
- {
- EvSchedule evs[] = {
- {{{0x67, 0x00, 0x00, 0x40},{0x68, 0x00, 0x00, 0x27}}, 0x0000, 0x0023},
- {{{0x68, 0x00, 0x00, 0x00},{0x68, 0x00, 0x00, 0x17}}, 0x0000, 0x0041},
- {{{0x68, 0x00, 0x00, 0x46},{0x69, 0x00, 0x00, 0x05}}, 0x0000, 0x003f},
- {{{0x67, 0x00, 0x00, 0x40},{0x68, 0x00, 0x00, 0x11}}, 0x0000, 0x0022},
- {{{0x68, 0x00, 0x00, 0x52},{0x69, 0x00, 0x00, 0x11}}, 0x0000, 0x003e},
- {{{0x68, 0x00, 0x00, 0x46},{0x69, 0x00, 0x00, 0x05}}, 0x0000, 0x003d},
- {{{0x68, 0x00, 0x00, 0x46},{0x69, 0x00, 0x00, 0x05}}, 0x0000, 0x0042},
- {{{0x68, 0x00, 0x00, 0x55},{0x69, 0x00, 0x00, 0x14}}, 0x0000, 0x0040},
- {{{0x32, 0xc8, 0x00, 0x06},{0x32, 0xc8, 0x00, 0x0b}}, 0x0000, 0x001f},
- {{{0x32, 0xce, 0x00, 0x14},{0x32, 0xce, 0x00, 0x17}}, 0x0000, 0x0021},
- {{{0x6a, 0x00, 0x00, 0x06},{0x6a, 0x00, 0x00, 0x16}}, 0x0000, 0x001e},
- {{{0x32, 0x63, 0x00, 0x00},{0x32, 0x63, 0x00, 0x17}}, 0x0000, 0x0020},
- {{{0x01, 0x01, 0x00, 0x00},{0x01, 0x03, 0x00, 0x17}}, 0x0000, 0x0045},
- {{{0x66, 0x00, 0x00, 0x00},{0x66, 0x00, 0x00, 0x17}}, 0x0000, 0x001d},
- {{{0x51, 0x01, 0x00, 0x06},{0x51, 0x01, 0x00, 0x0a}}, 0x0000, 0x0003},
- {{{0x5d, 0x19, 0x00, 0x00},{0x5d, 0x1d, 0x00, 0x17}}, 0x0000, 0x0029},
- {{{0x01, 0x02, 0x00, 0x8a},{0x02, 0x17, 0x00, 0x15}}, 0x0000, 0x000e},
- {{{0x01, 0x02, 0x00, 0x40},{0x02, 0x17, 0x00, 0x14}}, 0x0000, 0x0033},
- {{{0x0c, 0x19, 0x00, 0x00},{0x02, 0x11, 0x00, 0x17}}, 0x0000, 0x0011},
- {{{0x02, 0x0e, 0x00, 0x4a},{0x02, 0x0e, 0x00, 0x09}}, 0x0000, 0x0013},
- {{{0x02, 0x01, 0x00, 0x00},{0x02, 0x0d, 0x00, 0x17}}, 0x0000, 0x0039},
- {{{0x04, 0x03, 0x00, 0x00},{0x04, 0x08, 0x00, 0x17}}, 0x0000, 0x0019},
- {{{0x05, 0x90, 0x00, 0x00},{0x05, 0x90, 0x00, 0x17}}, 0x0000, 0x001c},
- {{{0x06, 0x98, 0x00, 0x00},{0x06, 0x98, 0x00, 0x17}}, 0x0000, 0x001b},
- {{{0x04, 0x05, 0x00, 0x0a},{0x04, 0x07, 0x00, 0x15}}, 0x0000, 0x000c},
- {{{0x03, 0x0f, 0x00, 0x00},{0x03, 0x1f, 0x00, 0x17}}, 0x0000, 0x0030},
- {{{0x04, 0x01, 0x00, 0x00},{0x04, 0x04, 0x00, 0x17}}, 0x0000, 0x0031},
- {{{0x04, 0x14, 0x00, 0x09},{0x04, 0x14, 0x00, 0x10}}, 0x0000, 0x0012},
- {{{0x04, 0x14, 0x00, 0x09},{0x04, 0x14, 0x00, 0x0a}}, 0x0000, 0x0008},
- {{{0x04, 0x14, 0x00, 0x0b},{0x04, 0x14, 0x00, 0x0c}}, 0x0000, 0x000a},
- {{{0x04, 0x14, 0x00, 0x0d},{0x04, 0x14, 0x00, 0x0e}}, 0x0000, 0x0007},
- {{{0x04, 0x14, 0x00, 0x0f},{0x04, 0x14, 0x00, 0x10}}, 0x0000, 0x0009},
- {{{0x04, 0x09, 0x00, 0x00},{0x04, 0x13, 0x00, 0x17}}, 0x0000, 0x0038},
- {{{0x04, 0x14, 0x00, 0x00},{0x04, 0x14, 0x00, 0x17}}, 0x0000, 0x0043},
- {{{0x06, 0xc8, 0x00, 0x06},{0x06, 0xc8, 0x00, 0x11}}, 0x0000, 0x0014},
- {{{0x05, 0x0f, 0x00, 0x00},{0x05, 0x1f, 0x00, 0x17}}, 0x0000, 0x003a},
- {{{0x06, 0x01, 0x00, 0x40},{0x06, 0xf8, 0x00, 0x00}}, 0x0000, 0x003b},
- {{{0x0c, 0x01, 0x00, 0x86},{0x0c, 0x1f, 0x00, 0x86}}, 0x0000, 0x0010},
- {{{0x0b, 0x0f, 0x00, 0x00},{0x0b, 0x1e, 0x00, 0x17}}, 0x0000, 0x0036},
- {{{0x0c, 0x1a, 0x00, 0x00},{0x0c, 0x1f, 0x00, 0x17}}, 0x0000, 0x0036},
- {{{0x5d, 0x1e, 0x00, 0x57},{0x51, 0x01, 0x00, 0x00}}, 0x0000, 0x000b},
- {{{0x51, 0x01, 0x00, 0x57},{0x51, 0x02, 0x00, 0x00}}, 0x0000, 0x000b},
- {{{0x51, 0x02, 0x00, 0x57},{0x51, 0x03, 0x00, 0x00}}, 0x0000, 0x000b},
- {{{0x51, 0x03, 0x00, 0x57},{0x51, 0x04, 0x00, 0x00}}, 0x0000, 0x000b},
- {{{0x51, 0x04, 0x00, 0x57},{0x51, 0x05, 0x00, 0x00}}, 0x0000, 0x000b},
- {{{0x51, 0x05, 0x00, 0x57},{0x51, 0x06, 0x00, 0x00}}, 0x0000, 0x000b},
- {{{0x5d, 0x19, 0x00, 0x00},{0x5d, 0x1d, 0x00, 0x17}}, 0x0000, 0x002e},
- {{{0x51, 0x01, 0x00, 0x00},{0x51, 0x05, 0x00, 0x17}}, 0x0000, 0x002f},
- {{{0x08, 0xce, 0x00, 0x00},{0x08, 0xce, 0x00, 0x17}}, 0x0000, 0x0043},
- {{{0x58, 0x0f, 0x00, 0x12},{0x58, 0x0f, 0x00, 0x14}}, 0x0000, 0x0016},
- {{{0x58, 0x0f, 0x00, 0x13},{0x58, 0x0f, 0x00, 0x13}}, 0x0000, 0x0000},
- {{{0x58, 0x08, 0x00, 0x00},{0x58, 0x0e, 0x00, 0x17}}, 0x0000, 0x0024},
- {{{0x58, 0x0f, 0x00, 0x00},{0x58, 0x0f, 0x00, 0x17}}, 0x0000, 0x0043},
- {{{0x59, 0x0d, 0x00, 0x00},{0x59, 0x0d, 0x00, 0x17}}, 0x0000, 0x0043},
- {{{0x0a, 0x91, 0x00, 0x09},{0x0a, 0x91, 0x00, 0x10}}, 0x0000, 0x0001},
- {{{0x0a, 0x91, 0x00, 0x09},{0x0a, 0x91, 0x00, 0x0a}}, 0x0000, 0x0008},
- {{{0x0a, 0x91, 0x00, 0x0b},{0x0a, 0x91, 0x00, 0x0c}}, 0x0000, 0x000a},
- {{{0x0a, 0x91, 0x00, 0x0d},{0x0a, 0x91, 0x00, 0x0e}}, 0x0000, 0x0007},
- {{{0x0a, 0x91, 0x00, 0x0f},{0x0a, 0x91, 0x00, 0x10}}, 0x0000, 0x0009},
- {{{0x0a, 0x01, 0x00, 0x40},{0x0a, 0x91, 0x00, 0x00}}, 0x0000, 0x0026},
- {{{0x0a, 0x91, 0x00, 0x00},{0x0a, 0x91, 0x00, 0x17}}, 0x0000, 0x0043},
- {{{0x0a, 0x0f, 0x00, 0x00},{0x0a, 0x19, 0x00, 0x17}}, 0x0000, 0x000f},
- {{{0x0a, 0x0a, 0x00, 0x00},{0x0a, 0x0e, 0x00, 0x17}}, 0x0000, 0x0034},
- {{{0x0a, 0x0f, 0x00, 0x00},{0x0a, 0x19, 0x00, 0x17}}, 0x0000, 0x0035},
- {{{0x0a, 0x1f, 0x00, 0x52},{0x0b, 0x01, 0x00, 0x00}}, 0x0000, 0x000d},
- {{{0x0a, 0x01, 0x00, 0x00},{0x0a, 0x1e, 0x00, 0x17}}, 0x0000, 0x0032},
- {{{0x0a, 0x1f, 0x00, 0x00},{0x0a, 0x1f, 0x00, 0x17}}, 0x0000, 0x0043},
- {{{0x0b, 0xc8, 0x00, 0x06},{0x0b, 0xc8, 0x00, 0x11}}, 0x0000, 0x0002},
- {{{0x0a, 0x0f, 0x00, 0x00},{0x0a, 0x1f, 0x00, 0x17}}, 0x0000, 0x0027},
- {{{0x0b, 0x01, 0x00, 0x40},{0x0b, 0xf8, 0x00, 0x00}}, 0x0000, 0x0028},
- {{{0x0c, 0x18, 0x00, 0x54},{0x0c, 0x19, 0x00, 0x00}}, 0x0000, 0x0005},
- {{{0x0c, 0x18, 0x00, 0x00},{0x0c, 0x18, 0x00, 0x17}}, 0x0000, 0x001a},
- {{{0x0c, 0x18, 0x00, 0x00},{0x0c, 0x18, 0x00, 0x17}}, 0x0000, 0x0044},
- {{{0x0c, 0x0a, 0x00, 0x00},{0x0c, 0x17, 0x00, 0x17}}, 0x0000, 0x002c},
- {{{0x0c, 0x1f, 0x00, 0x57},{0x01, 0x01, 0x00, 0x00}}, 0x0000, 0x0006},
- {{{0x0c, 0x19, 0x00, 0x00},{0x0c, 0x1e, 0x00, 0x17}}, 0x0000, 0x002d},
- {{{0x0c, 0x1f, 0x00, 0x00},{0x0c, 0x1f, 0x00, 0x17}}, 0x0000, 0x0043}
- };
- for (int i = 0; i < 77; i++) {
- EvSchedule* t = evs + i;
- evdate_u t2 = decode_date(&t->day[0]);
- evdate_u t2_e = decode_date(&t->day[1]);
- if ((t2.d.hour & 0x80) != 0) {
- printf("[%d]: %s:\n\tStart: Current Date @ %02d:00\n\tEnd: Current Date @%02d:59\n", i, event_names[t->type], t2.d.hour & 0x3F, t2_e.d.hour & 0x3F);
- }
- else if ((t2.d.hour & 0x40) != 0) {
- printf("[%d]: %s:\n\tStart: %02d/%02d @ %02d:00\n\tThrough: %02d/%02d @ %02d:59\n", i, event_names[t->type], t2.d.month, t2.d.day, t2.d.hour & 0x3F, t2_e.d.month, t2_e.d.day, t2_e.d.hour);
- }
- else {
- printf("[%d]: %s:\n\tStart: %02d/%02d @ %02d:00\n\tEnd: %02d/%02d @ %02d:59\n", i, event_names[t->type], t2.d.month, t2.d.day, t2.d.hour, t2_e.d.month, t2_e.d.day, t2_e.d.hour);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement