Advertisement
Moolah60

Dongwu Senlin Date Decoder

Oct 19th, 2022
1,023
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 31.23 KB | None | 0 0
  1. /******************************************************************************
  2.  
  3.                             Online C Compiler.
  4.                 Code, Compile, Run and Debug C program online.
  5. Write your code in this editor and press "Run" button to compile and execute it.
  6.  
  7. *******************************************************************************/
  8.  
  9. #include <stdio.h>
  10.  
  11. typedef unsigned char u8;
  12. typedef unsigned short u16;
  13.  
  14. typedef int BOOL;
  15. #define FALSE 0
  16. #define TRUE 1
  17.  
  18. typedef u8 unchar;
  19. typedef u16 unshort;
  20.  
  21. typedef struct{
  22.     u8  sec;    /* second 0-59 */
  23.     u8  min;    /* minute 0-59 */
  24.     u8  hour;   /* hour   0-23 */
  25.     u8  day;    /* day    1-31 */
  26.     u8  week;   /* week   0-6(sun,mon,..,sat) */
  27.     u8  month;  /* month  1-12 */
  28.     u16 year;   /* year 1901-2099 */
  29. } OSRTCTime;
  30.  
  31. typedef OSRTCTime        lbRTC_time_c;
  32. typedef u8               lbRTC_ss_t;
  33. typedef u8               lbRTC_mm_t;
  34. typedef u8               lbRTC_hh_t;
  35. typedef u8               lbRTC_DD_t;
  36. typedef u8               lbRTC_WW_t;
  37. typedef u8               lbRTC_MM_t;
  38. typedef u16              lbRTC_YY_t;
  39.  
  40. enum {
  41.     JANUARY = 1,
  42.     FEBRUARY,
  43.     MARCH,
  44.     APRIL,
  45.     MAY,
  46.     JUNE,
  47.     JULY,
  48.     AUGUST,
  49.     SEPTEMBER,
  50.     OCTOBER,
  51.     NOVEMBER,
  52.     DECEMBER,
  53.  
  54.     TWELVEMONTH
  55. };
  56.  
  57. enum {
  58.     DAY_01 = 1, DAY_02, DAY_03, DAY_04,
  59.     DAY_05, DAY_06, DAY_07, DAY_08, DAY_09,
  60.     DAY_10, DAY_11, DAY_12, DAY_13, DAY_14,
  61.     DAY_15, DAY_16, DAY_17, DAY_18, DAY_19,
  62.     DAY_20, DAY_21, DAY_22, DAY_23, DAY_24,
  63.     DAY_25, DAY_26, DAY_27, DAY_28, DAY_29,
  64.     DAY_30, DAY_31
  65. };
  66.  
  67. /*
  68.  *  曜日
  69.  */
  70. enum {
  71.     SUNDAY,
  72.     MONDAY,
  73.     TUESDAY,
  74.     WEDNESDAY,
  75.     THURSDAY,
  76.     FRIDAY,
  77.     SATURDAY,
  78.  
  79.     SEVENDAYS_IN_A_WEEK
  80. };
  81.  
  82. /*
  83.  *  時間
  84.  */
  85. enum {
  86.     TIME_00, TIME_01, TIME_02, TIME_03, TIME_04, TIME_05,
  87.     TIME_06, TIME_07, TIME_08, TIME_09, TIME_10, TIME_11,
  88.     TIME_12, TIME_13, TIME_14, TIME_15, TIME_16, TIME_17,
  89.     TIME_18, TIME_19, TIME_20, TIME_21, TIME_22, TIME_23,
  90.     TIME_ED
  91. };
  92.  
  93. enum rtc_month {
  94.     lbRTC_JANUARY = 1,             /* 1月 */
  95.     lbRTC_FEBRUARY,                /* 2月 */
  96.     lbRTC_MARCH,                   /* 3月 */
  97.     lbRTC_APRIL,                   /* 4月 */
  98.     lbRTC_MAY,                     /* 5月 */
  99.     lbRTC_JUNE,                    /* 6月 */
  100.     lbRTC_JULY,                    /* 7月 */
  101.     lbRTC_AUGUST,                  /* 8月 */
  102.     lbRTC_SEPTEMBER,               /* 9月 */
  103.     lbRTC_OCTOBER,                 /* 10月 */
  104.     lbRTC_NOVEMBER,                /* 11月 */
  105.     lbRTC_DECEMBER,                /* 12月 */
  106.     lbRTC_MONTH_NUM = lbRTC_DECEMBER
  107. };
  108. /* 年 */
  109. enum rtc_yesr {
  110.     lbRTC_NORMAL_YEAR,             /* 通常年 */
  111.     lbRTC_LEAP_YEAR,               /* 閏年 */
  112.     lbRTC_MODE
  113. };
  114. /* 時間と秒 */
  115. enum rtc_hour_and_minute_seccond {
  116.     lbRTC_HOURS = 24,              /* 一日の時間数 */
  117.     lbRTC_MINUTES = 60,            /* 1時間の分数 */
  118.     lbRTC_SECCONDS = 60            /* 1分の秒数 */
  119. };
  120.  
  121. #define lbRk_YEAR_MIN 2000
  122. #define lbRk_YEAR_MAX 2032
  123. #define lbRk_YEAR_NUM ((lbRk_YEAR_MAX - lbRk_YEAR_MIN) + 1)
  124.  
  125. #define lbRk_KYUU_MONTH_START 1
  126. #define lbRk_KYUU_MONTH_END 12
  127. #define lbRk_KYUU_LEAP_MONTH 13
  128.  
  129. #define day_of_week(day)          ((day) & 0x07)     /* 曜日ゲット */
  130. #define cycle_of_week(day)        (((day) & 0x78) >> 3) /* 何週目か? */
  131.  
  132. /* flag */
  133. #define EV_FLG_WDAY               (0x01)  /* 曜日 */
  134. #define EV_FLG_WEEKLY             (0x02)  /* 毎週 */
  135. #define EV_FLG_MONTHLY            (0x04)  /* 毎月 */
  136. #define EV_FLG_JPOLD              (0x08)  /* 旧暦 */
  137. /* alias */
  138. #define EV_DATE_MONTH_DAY         (0x00)  /* ?月?日 */
  139. #define EV_DATE_MONTH_N_WDAY      (0x01)  /* ?月第n?曜日 */
  140. #define EV_DATE_MONTH_WEEKLY      (0x03)  /* ?月毎週?曜日 */
  141. #define EV_DATE_DAY               (0x04)  /* 毎月?日 */
  142. #define EV_DATE_N_WDAY            (0x05)  /* 毎月第n?曜日 */
  143. #define EV_DATE_WEEKLY            (0x07)  /* 毎月毎週?曜日 */
  144. #define EV_DATE_JP_MONTH_DAY      (0x08)  /* 旧暦?月?日 */
  145.  
  146. #define EV_SPDATE_EVERYMONTH   (50)
  147. #define EV_SPDATE_LASTDAY      (99)
  148.  
  149.  
  150. /*
  151. ** 曜日 ** */
  152. #define EV_WEEK_SUNDAY    (0)
  153. #define EV_WEEK_MONDAY    (1)
  154. #define EV_WEEK_TUESDAY   (2)
  155. #define EV_WEEK_WEDNESDAY (3)
  156. #define EV_WEEK_THURSDAY  (4)
  157. #define EV_WEEK_FRIDAY    (5)
  158. #define EV_WEEK_SATURDAY  (6)
  159. #define EV_WEEK_ANYDAY    (7)  /* 何曜日でも */
  160.  
  161.  
  162. /*
  163. ** 第?週 ** */
  164. #define EV_WEEK_FIRST     (0x01)
  165. #define EV_WEEK_SECOND    (0x02)
  166. #define EV_WEEK_THIRD     (0x03)
  167. #define EV_WEEK_FOURTH    (0x04)
  168. #define EV_WEEK_FIFTH     (0x05)
  169. #define EV_WEEK_LAST      (0x0f)  /* 最終?曜日 */
  170. #define EV_WEEK_EVELY     (0x09)  /* 毎週 */
  171.  
  172. /*
  173. ** セーブレジスタ ** */
  174. #define EV_SAVE_TODAY        ( 0)
  175. #define EV_SAVE_LASTPLAYDAY  ( 1)
  176. #define EV_SAVE_BIRTHDAY     ( 2)
  177. #define EV_SAVE_SPECIAL0     ( 3)
  178. #define EV_SAVE_SPECIAL1     ( 4)
  179. #define EV_SAVE_SPECIAL2     ( 5)
  180. #define EV_SAVE_WEEKLY0      ( 6)
  181. #define EV_SAVE_SPECIAL3     ( 7)
  182.  
  183. #define lbRTC_MAX_YEAR   2099
  184. #define lbRTC_MAX_MONTH  12
  185. #define lbRTC_MAX_DAY    31
  186. #define lbRTC_MAX_HOUR   23
  187. #define lbRTC_MAX_MINUTE 59
  188. #define lbRTC_MAX_SECOND 59
  189.  
  190. #define lbRTC_MIN_YEAR   1901
  191. #define lbRTC_MIN_MONTH  1
  192. #define lbRTC_MIN_DAY    1
  193. #define lbRTC_MIN_HOUR   0
  194. #define lbRTC_MIN_MINUTE 0
  195. #define lbRTC_MIN_SECOND 0
  196.  
  197. #define to_ev_month_day(month, day) ((u16)((month << 8) | (day)))
  198.  
  199. /*
  200.  *  年・月・日のみの日付データ
  201.  */
  202. typedef struct  year_month_day_data {
  203.     lbRTC_YY_t  year;
  204.     lbRTC_MM_t  month;
  205.     lbRTC_DD_t  day;
  206. } lbRTC_ymd_c;
  207.  
  208. typedef struct _event_date_data_ {
  209.     char  month, day, flag, hour;
  210. } evdate_t;
  211.  
  212. typedef union _event_schedule_date_ {
  213.     evdate_t d;               /* 日付時間 */
  214.     unsigned short v, f;      /* インテル互換なし */
  215.     unsigned long lv;
  216. } evdate_u;
  217.  
  218. typedef struct _event_schedule_ {
  219.     evdate_u  day[2];
  220.     short  f, type;
  221. } EvSchedule;
  222.  
  223. #define ZCommonGet(m) m
  224.  
  225. typedef struct {
  226.     OSRTCTime rtcTime;
  227. } TIME_c;
  228.  
  229. static TIME_c time = {
  230.     {
  231.       0, // sec
  232.       0, // min
  233.       0, // hour
  234.       18, // day
  235.       0, // week
  236.       9, // month
  237.       2022 // year
  238.     }
  239. };
  240.  
  241. /* Conversion table -- holds modern calendar {month, day} pairs to convert from Japanese Lunar date to Modern date */
  242. static unchar l_lbRk_ConvertTable[][lbRk_KYUU_LEAP_MONTH][2] = {
  243.     {{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}},
  244.     {{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}},
  245.     {{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}},
  246.     {{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}},
  247.     {{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}},
  248.     {{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}},
  249.     {{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}},
  250.     {{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}},
  251.     {{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}},
  252.     {{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}},
  253.     {{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}},
  254.     {{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}},
  255.     {{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}},
  256.     {{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}},
  257.     {{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}},
  258.     {{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}},
  259.     {{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}},
  260.     {{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}},
  261.     {{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}},
  262.     {{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}},
  263.     {{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}},
  264.     {{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}},
  265.     {{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}},
  266.     {{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}},
  267.     {{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}},
  268.     {{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}},
  269.     {{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}},
  270.     {{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}},
  271.     {{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}},
  272.     {{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}},
  273.     {{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}},
  274.     {{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}},
  275.     {{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}}
  276. };
  277.  
  278. static int l_lbRk_leapdays[] = {
  279.     0, 29, 0, 0, 29, 0, 29, 0,
  280.     0, 29, 0, 0, 30, 0, 29, 0,
  281.     0, 29, 0, 0, 29, 0, 0, 30,
  282.     0, 29, 0, 0, 29, 0, 0, 30,
  283.     0
  284. };
  285.  
  286. static lbRTC_DD_t weekday1st[lbRTC_MAX_MONTH + 1];
  287.  
  288. extern lbRTC_DD_t lbRk_SeirekiDays(lbRTC_YY_t year, lbRTC_MM_t month) {
  289.     static lbRTC_DD_t t_seiyo_days_tbl[][lbRTC_MONTH_NUM + 1] = {
  290.         {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, /* Standard days for each month */
  291.         {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31} /* Days for each month during leap year */
  292.     };
  293.     return t_seiyo_days_tbl[(year & 3) == 0][month];
  294. }
  295.  
  296. static unchar* lbRk_ToSeiyoMonthAndDay(lbRTC_YY_t year, int month) {
  297.     return l_lbRk_ConvertTable[year - lbRk_YEAR_MIN][month - 1];
  298. }
  299.  
  300. extern int lbRk_KyuurekiLeapDays(lbRTC_YY_t year) {
  301.     return l_lbRk_leapdays[year - lbRk_YEAR_MIN];
  302. }
  303.  
  304. extern int lbRk_IsKyuurekiLeapYear(lbRTC_YY_t year) {
  305.     return l_lbRk_leapdays[year - lbRk_YEAR_MIN] != 0 ? TRUE : FALSE;
  306. }
  307.  
  308. static int lbRk_IsLeapMonth(lbRTC_MM_t month) {
  309.     return month == lbRk_KYUU_LEAP_MONTH ? TRUE : FALSE;
  310. }
  311.  
  312. static int lbRk_IsLeapOnNextMonth(lbRTC_YY_t year, int month) {
  313.     return lbRk_ToSeiyoMonthAndDay(year, month)[0] + 1 == l_lbRk_ConvertTable[year - lbRk_YEAR_MIN][lbRk_KYUU_LEAP_MONTH - 1][0];
  314. }
  315.  
  316. extern int lbRk_KyuurekiDays(lbRTC_YY_t year, int month) {
  317.     unchar* seiyo_month_day = lbRk_ToSeiyoMonthAndDay(year, month);
  318.     if (lbRk_IsLeapMonth(month) == TRUE) {
  319.         return lbRk_KyuurekiLeapDays(year);
  320.     }
  321.  
  322.     unchar* next_seiyo_month_day;
  323.     if (month == lbRk_KYUU_MONTH_END) {
  324.         next_seiyo_month_day = lbRk_ToSeiyoMonthAndDay(year + 1, lbRk_KYUU_MONTH_START);
  325.     }
  326.     else {
  327.         next_seiyo_month_day = lbRk_IsLeapOnNextMonth(year, month) == TRUE ?
  328.             lbRk_ToSeiyoMonthAndDay(year, lbRk_KYUU_LEAP_MONTH) :
  329.             lbRk_ToSeiyoMonthAndDay(year, month + 1);
  330.     }
  331.    
  332.     if (next_seiyo_month_day[0] == seiyo_month_day[0]) {
  333.         return next_seiyo_month_day[1] - seiyo_month_day[1];
  334.     }
  335.  
  336.     if (month > seiyo_month_day[0]) year++;
  337.     int days = lbRk_SeirekiDays(year, seiyo_month_day[0]) - seiyo_month_day[1]; /* Days in standard month - conversion days */
  338.     if (next_seiyo_month_day[0] - seiyo_month_day[0] > 1) {
  339.         days += lbRk_SeirekiDays(year, seiyo_month_day[0] + 1);
  340.     }
  341.     days += next_seiyo_month_day[1];
  342.     return days;
  343. }
  344.  
  345. /* Japanese Lunar Calendar -> Modern Calendar */
  346. extern int lbRk_ToSeiyouReki(lbRTC_ymd_c* dst, lbRTC_ymd_c* src) {
  347.     if (src->year == 0 || src->year > lbRk_YEAR_MAX) {
  348.         return FALSE; /* Year out of bounds */
  349.     }
  350.     if (src->month > lbRk_KYUU_LEAP_MONTH) {
  351.         return FALSE; /* Month out of bounds */
  352.     }
  353.     if (lbRk_IsKyuurekiLeapYear(src->year) == FALSE) {
  354.         if (src->month > lbRk_KYUU_MONTH_END) {
  355.             return FALSE; /* Month out of bounds, leap month excluded */
  356.         }
  357.     }
  358.     if (lbRk_KyuurekiDays(src->year, src->month) < src->day) {
  359.         return FALSE; /* Day out of bounds */
  360.     }
  361.     unchar* seiyo_month_day = lbRk_ToSeiyoMonthAndDay(src->year, src->month);
  362.     lbRTC_YY_t year = src->year;
  363.     lbRTC_MM_t month = seiyo_month_day[0];
  364.     lbRTC_DD_t day = (seiyo_month_day[1] + src->day) - 1;
  365.  
  366.     lbRTC_DD_t seireki_days = lbRk_SeirekiDays(year, month);
  367.     if (day > seireki_days) {
  368.         month++;
  369.         day -= seireki_days;
  370.         if (month > lbRTC_MONTH_NUM) {
  371.             month = 1; /* This is almost certainly a bug. There should be a year++ here. */
  372.         }
  373.     }
  374.  
  375.     if (src->month > month) {
  376.         if (src->month != lbRk_KYUU_LEAP_MONTH) {
  377.             year++; /* Add a year if we aren't on the leap month. */
  378.         }
  379.     }
  380.  
  381.     dst->year = year;
  382.     dst->month = month;
  383.     dst->day = day;
  384. }
  385.  
  386. static u16 kyu2sei(evdate_u* kyu_date) {
  387.     lbRTC_ymd_c dst;
  388.     lbRTC_ymd_c src = { ZCommonGet(time.rtcTime.year), kyu_date->d.month, kyu_date->d.day };
  389.     lbRk_ToSeiyouReki(&dst, &src);
  390.     return (unsigned short)((dst.month << 8) | dst.day);
  391. }
  392.  
  393. static lbRTC_DD_t last_day_of_month(lbRTC_MM_t month) {
  394.     static lbRTC_DD_t last_day[] = {
  395.         31, 28, 31, 30,
  396.         31, 30, 31, 31,
  397.         30, 31, 30, 31
  398.     };
  399.  
  400.     if (month == FEBRUARY) {
  401.         lbRTC_YY_t year = ZCommonGet(time.rtcTime.year);
  402.         return (year & 3) == 0 && (year % 100) != 0 && (year % 400) == 0 ? 28 : 29; /* Leap year day for Feb */
  403.     }
  404.     return last_day[month - 1];
  405. }
  406.  
  407. static lbRTC_DD_t m_weekday2day(lbRTC_MM_t month, lbRTC_DD_t day) {
  408.     int week_cycle = cycle_of_week(day);
  409.     /* NOTE: EVELY is a misspelling of EVERY */
  410.     if (week_cycle == EV_WEEK_EVELY) {
  411.         lbRTC_MM_t current_month = ZCommonGet(time.rtcTime.month);
  412.         if (current_month < month) {
  413.             week_cycle = EV_WEEK_FIRST;
  414.         }
  415.         else if (current_month > month) {
  416.             week_cycle = EV_WEEK_LAST;
  417.         }
  418.         else {
  419.             week_cycle = 0; /* No additional processing */
  420.             printf("Day this week\n");
  421.             return (ZCommonGet(time.rtcTime.day) - ZCommonGet(time.rtcTime.week)) + (day & EV_WEEK_ANYDAY); /* Day this week */
  422.         }
  423.     }
  424.  
  425.     if (week_cycle == EV_WEEK_LAST) {
  426.         day &= EV_WEEK_ANYDAY;
  427.         lbRTC_DD_t last_day = last_day_of_month(month);
  428.         lbRTC_DD_t adj = (weekday1st[month] + last_day - 1) % EV_WEEK_ANYDAY;
  429.         return adj < day
  430.             ? ((last_day - adj) + day) - EV_WEEK_ANYDAY
  431.             : (last_day - adj) + day;
  432.     }
  433.  
  434.     if (week_cycle != 0) {
  435.         lbRTC_DD_t first = weekday1st[month];
  436.         day &= EV_WEEK_ANYDAY;
  437.         return day < first
  438.             ? ((week_cycle * EV_WEEK_ANYDAY + day) - first) + 1
  439.             : ((week_cycle * EV_WEEK_ANYDAY + day) - first) - 6;
  440.     }
  441.  
  442.     return 0; /* This should never happen */
  443. }
  444.  
  445. static evdate_u decode_date(evdate_u* enc_date) {
  446.     evdate_u date;
  447.     date.d.month = enc_date->d.month;
  448.    
  449.     /* Check for event that happens month */
  450.     if (date.d.month == EV_SPDATE_EVERYMONTH) {
  451.         date.d.month = ZCommonGet(time.rtcTime.month);
  452.     }
  453.     date.d.day = enc_date->d.day;
  454.    
  455.     /* Check for last day of month event */
  456.     if (date.d.day == EV_SPDATE_LASTDAY) {
  457.         date.d.day = last_day_of_month(date.d.month);
  458.     }
  459.    
  460.     /* Check if the event's date is a "cached" day in the game save */
  461.     if (date.d.month > EV_SPDATE_LASTDAY) {
  462.         //date.v = SaveGet(event.xday[date.d.month - 100]); /* Save data is month-day pairing */
  463.         date.v = 0;
  464.         printf("Date's month-day combo is in save event!\n");
  465.     }
  466.    
  467.     date.d.flag = enc_date->d.flag;
  468.     date.d.hour = enc_date->d.hour;
  469.  
  470.     /* Check if the event's hour is a "cached" time in the game save */
  471.     if ((date.d.hour & 0x20) != 0) {
  472.         date.d.hour = 0;
  473.         printf("Date's hour is in save event!\n");
  474.         //date.d.hour = (char)SaveGet(event.xday[date.d.hour & 0x1F]) | (date.d.hour & 0xC0);
  475.     }
  476.  
  477.       /* Check if date is Japanese Lunar Calendar format */
  478.   if (date.d.month >= 80) {
  479.     date.d.month -= 80;
  480.  
  481.     if (date.d.month < lbRk_KYUU_LEAP_MONTH) {
  482.       date.v = kyu2sei(&date); /* Standard Lunar conversion */
  483.       date.v = (u16)((date.v >> 8) | (date.v << 8)); // LE
  484.     } else {
  485.       /* Calculate Lunar New Year */
  486.       evdate_u lunar_newyear;
  487.       lunar_newyear.d.month = lbRk_KYUU_MONTH_START;
  488.       lunar_newyear.d.day = DAY_01;
  489.       lunar_newyear.d.flag = 0;
  490.       lunar_newyear.d.flag = TIME_00;
  491.  
  492.       /* Lunar New Year date conversion */
  493.       lunar_newyear.v = kyu2sei(&lunar_newyear);
  494.       u16 compare = lunar_newyear.v;
  495.       lunar_newyear.v = (u16)((lunar_newyear.v >> 8) | (lunar_newyear.v << 8)); // LE
  496.       if (date.d.day == DAY_30) {
  497.         if (compare != to_ev_month_day(FEBRUARY, DAY_01)) {
  498.           date.d.month = lunar_newyear.d.month;
  499.           date.d.day = lunar_newyear.d.day - 1;
  500.         } else {
  501.           date.d.day = DAY_31;
  502.           date.d.month = JANUARY;
  503.         }
  504.       } else if (date.d.day == DAY_29) {
  505.         if (compare == to_ev_month_day(FEBRUARY, DAY_02)) {
  506.           date.d.day = DAY_31;
  507.           date.d.month = JANUARY;
  508.         } else if (compare == to_ev_month_day(FEBRUARY, DAY_01)) {
  509.           date.d.day = DAY_30;
  510.           date.d.month = JANUARY;
  511.         } else {
  512.           date.d.month = lunar_newyear.d.month;
  513.           date.d.day = lunar_newyear.d.day - 2;
  514.         }
  515.       } else if (date.d.day == DAY_25) {
  516.         if (compare == to_ev_month_day(FEBRUARY, DAY_05)) {
  517.           date.d.day = DAY_31;
  518.           date.d.month = JANUARY;
  519.         } else if (compare == to_ev_month_day(FEBRUARY, DAY_04)) {
  520.           date.d.day = DAY_30;
  521.           date.d.month = JANUARY;
  522.         } else if (compare == to_ev_month_day(FEBRUARY, DAY_03)) {
  523.           date.d.day = DAY_29;
  524.           date.d.month = JANUARY;
  525.         } else if (compare == to_ev_month_day(FEBRUARY, DAY_02)) {
  526.           date.d.day = DAY_28;
  527.           date.d.month = JANUARY;
  528.         } else if (compare == to_ev_month_day(FEBRUARY, DAY_01)) {
  529.           date.d.day = DAY_27;
  530.           date.d.month = JANUARY;
  531.         } else if (compare == to_ev_month_day(JANUARY, DAY_05)) {
  532.           date.d.day = DAY_31;
  533.           date.d.month = DECEMBER;
  534.         } else if (compare == to_ev_month_day(JANUARY, DAY_04)) {
  535.           date.d.day = DAY_30;
  536.           date.d.month = DECEMBER;
  537.         } else if (compare == to_ev_month_day(JANUARY, DAY_03)) {
  538.           date.d.day = DAY_29;
  539.           date.d.month = DECEMBER;
  540.         } else if (compare == to_ev_month_day(JANUARY, DAY_02)) {
  541.           date.d.day = DAY_28;
  542.           date.d.month = DECEMBER;
  543.         } else if (compare == to_ev_month_day(JANUARY, DAY_01)) {
  544.           date.d.day = DAY_27;
  545.           date.d.month = DECEMBER;
  546.         } else {
  547.           date.d.day = lunar_newyear.d.day - 5;
  548.           date.d.month = lunar_newyear.d.month;
  549.         }
  550.       }
  551.     }
  552.   }
  553.  
  554.     /* Check for day of week event */
  555.     if ((date.d.day & 0x80) != 0) {
  556.         date.d.day = m_weekday2day(date.d.month, date.d.day);
  557.     }
  558.  
  559.     return date;
  560. }
  561.  
  562. const char* event_names[] = {
  563.     "APP_ADMIRE_MOON",
  564.     "APP_AUTUMN_FIELD_DAY",
  565.     "APP_AUTUMN_FISHING",
  566.     "APP_A_HAPPY_NEW_YEAR",
  567.     "APP_CHILDRENS_DAY",
  568.     "APP_CHRISTMAS",
  569.     "APP_COUNT_DOWN",
  570.     "APP_FD_BASKET_SHOOTING",
  571.     "APP_FD_CALISTHENICS",
  572.     "APP_FD_TUG_OF_WAR",
  573.     "APP_FD_WALK_RACE",
  574.     "APP_FIREWORKS",
  575.     "APP_FLOWER_VIEWING",
  576.     "APP_HALLOWEEN",
  577.     "APP_KAMAKURA",
  578.     "APP_MATSUTAKE",
  579.     "APP_RADIO_CALISTHENICS",
  580.     "APP_SNOWMAN",
  581.     "APP_SPRING_FIELD_DAY",
  582.     "APP_ST_VALENTINE",
  583.     "APP_SUMMER_FISHING",
  584.     "APP_WATER_MOON13",
  585.     "APP_WATER_MOON15",
  586.     "APP_WHITE_DAY",
  587.     "FLG_CARP_PENNANT",
  588.     "FLG_CHERRY_BLOSSOM",
  589.     "FLG_CHRISTMASSONG",
  590.     "FLG_FATHER_DAY",
  591.     "FLG_MOTHER_DAY",
  592.     "FS_BIRTHDAY",
  593.     "FS_DOWNING",
  594.     "FS_KABU_PEDDLER",
  595.     "FS_LOTTERY",
  596.     "FS_STAFFROLL",
  597.     "HBL_BROKER",
  598.     "HBL_SHOP",
  599.     "RMR_ADMIRE_MOON_0",
  600.     "RMR_ADMIRE_MOON_1",
  601.     "RMR_AUTUMN_FIELD_DAY",
  602.     "RMR_AUTUMN_FISHING_0",
  603.     "RMR_AUTUMN_FISHING_1",
  604.     "RMR_A_HAPPY_NEW_YEAR",
  605.     "RMR_CHILDRENS_DAY_0",
  606.     "RMR_CHILDRENS_DAY_1",
  607.     "RMR_CHRISTMAS",
  608.     "RMR_COUNT_DOWN",
  609.     "RMR_FIREWORKS_0",
  610.     "RMR_FIREWORKS_1",
  611.     "RMR_FLOWER_VIEWING_0",
  612.     "RMR_FLOWER_VIEWING_1",
  613.     "RMR_HALLOWEEN",
  614.     "RMR_KAMAKURA",
  615.     "RMR_MATSUTAKE_0",
  616.     "RMR_MATSUTAKE_1",
  617.     "RMR_RADIO_CALISTHENICS_0",
  618.     "RMR_RADIO_CALISTHENICS_1",
  619.     "RMR_SPRING_FIELD_DAY",
  620.     "RMR_ST_VALENTINE",
  621.     "RMR_SUMMER_FISHING_0",
  622.     "RMR_SUMMER_FISHING_1",
  623.     "RMR_WHITE_DAY",
  624.     "SPC_ARTIST",
  625.     "SPC_BROKER",
  626.     "SPC_DESIGNER",
  627.     "SPC_GYPSY",
  628.     "SPC_SHOP",
  629.     "SPC_SILK",
  630.     "WEZ_FINE_DAY",
  631.     "WEZ_SNOW_DAY",
  632.     "ZFS_MISTERY_PACKAGE",
  633.     "SCHEDULE_NO_END",
  634. };
  635.  
  636. int main()
  637. {
  638.     EvSchedule evs[] = {
  639.         {{{0x67, 0x00, 0x00, 0x40},{0x68, 0x00, 0x00, 0x27}}, 0x0000, 0x0023},
  640.         {{{0x68, 0x00, 0x00, 0x00},{0x68, 0x00, 0x00, 0x17}}, 0x0000, 0x0041},
  641.         {{{0x68, 0x00, 0x00, 0x46},{0x69, 0x00, 0x00, 0x05}}, 0x0000, 0x003f},
  642.         {{{0x67, 0x00, 0x00, 0x40},{0x68, 0x00, 0x00, 0x11}}, 0x0000, 0x0022},
  643.         {{{0x68, 0x00, 0x00, 0x52},{0x69, 0x00, 0x00, 0x11}}, 0x0000, 0x003e},
  644.         {{{0x68, 0x00, 0x00, 0x46},{0x69, 0x00, 0x00, 0x05}}, 0x0000, 0x003d},
  645.         {{{0x68, 0x00, 0x00, 0x46},{0x69, 0x00, 0x00, 0x05}}, 0x0000, 0x0042},
  646.         {{{0x68, 0x00, 0x00, 0x55},{0x69, 0x00, 0x00, 0x14}}, 0x0000, 0x0040},
  647.         {{{0x32, 0xc8, 0x00, 0x06},{0x32, 0xc8, 0x00, 0x0b}}, 0x0000, 0x001f},
  648.         {{{0x32, 0xce, 0x00, 0x14},{0x32, 0xce, 0x00, 0x17}}, 0x0000, 0x0021},
  649.         {{{0x6a, 0x00, 0x00, 0x06},{0x6a, 0x00, 0x00, 0x16}}, 0x0000, 0x001e},
  650.         {{{0x32, 0x63, 0x00, 0x00},{0x32, 0x63, 0x00, 0x17}}, 0x0000, 0x0020},
  651.         {{{0x01, 0x01, 0x00, 0x00},{0x01, 0x03, 0x00, 0x17}}, 0x0000, 0x0045},
  652.         {{{0x66, 0x00, 0x00, 0x00},{0x66, 0x00, 0x00, 0x17}}, 0x0000, 0x001d},
  653.         {{{0x51, 0x01, 0x00, 0x06},{0x51, 0x01, 0x00, 0x0a}}, 0x0000, 0x0003},
  654.         {{{0x5d, 0x19, 0x00, 0x00},{0x5d, 0x1d, 0x00, 0x17}}, 0x0000, 0x0029},
  655.         {{{0x01, 0x02, 0x00, 0x8a},{0x02, 0x17, 0x00, 0x15}}, 0x0000, 0x000e},
  656.         {{{0x01, 0x02, 0x00, 0x40},{0x02, 0x17, 0x00, 0x14}}, 0x0000, 0x0033},
  657.         {{{0x0c, 0x19, 0x00, 0x00},{0x02, 0x11, 0x00, 0x17}}, 0x0000, 0x0011},
  658.         {{{0x02, 0x0e, 0x00, 0x4a},{0x02, 0x0e, 0x00, 0x09}}, 0x0000, 0x0013},
  659.         {{{0x02, 0x01, 0x00, 0x00},{0x02, 0x0d, 0x00, 0x17}}, 0x0000, 0x0039},
  660.         {{{0x04, 0x03, 0x00, 0x00},{0x04, 0x08, 0x00, 0x17}}, 0x0000, 0x0019},
  661.         {{{0x05, 0x90, 0x00, 0x00},{0x05, 0x90, 0x00, 0x17}}, 0x0000, 0x001c},
  662.         {{{0x06, 0x98, 0x00, 0x00},{0x06, 0x98, 0x00, 0x17}}, 0x0000, 0x001b},
  663.         {{{0x04, 0x05, 0x00, 0x0a},{0x04, 0x07, 0x00, 0x15}}, 0x0000, 0x000c},
  664.         {{{0x03, 0x0f, 0x00, 0x00},{0x03, 0x1f, 0x00, 0x17}}, 0x0000, 0x0030},
  665.         {{{0x04, 0x01, 0x00, 0x00},{0x04, 0x04, 0x00, 0x17}}, 0x0000, 0x0031},
  666.         {{{0x04, 0x14, 0x00, 0x09},{0x04, 0x14, 0x00, 0x10}}, 0x0000, 0x0012},
  667.         {{{0x04, 0x14, 0x00, 0x09},{0x04, 0x14, 0x00, 0x0a}}, 0x0000, 0x0008},
  668.         {{{0x04, 0x14, 0x00, 0x0b},{0x04, 0x14, 0x00, 0x0c}}, 0x0000, 0x000a},
  669.         {{{0x04, 0x14, 0x00, 0x0d},{0x04, 0x14, 0x00, 0x0e}}, 0x0000, 0x0007},
  670.         {{{0x04, 0x14, 0x00, 0x0f},{0x04, 0x14, 0x00, 0x10}}, 0x0000, 0x0009},
  671.         {{{0x04, 0x09, 0x00, 0x00},{0x04, 0x13, 0x00, 0x17}}, 0x0000, 0x0038},
  672.         {{{0x04, 0x14, 0x00, 0x00},{0x04, 0x14, 0x00, 0x17}}, 0x0000, 0x0043},
  673.         {{{0x06, 0xc8, 0x00, 0x06},{0x06, 0xc8, 0x00, 0x11}}, 0x0000, 0x0014},
  674.         {{{0x05, 0x0f, 0x00, 0x00},{0x05, 0x1f, 0x00, 0x17}}, 0x0000, 0x003a},
  675.         {{{0x06, 0x01, 0x00, 0x40},{0x06, 0xf8, 0x00, 0x00}}, 0x0000, 0x003b},
  676.         {{{0x0c, 0x01, 0x00, 0x86},{0x0c, 0x1f, 0x00, 0x86}}, 0x0000, 0x0010},
  677.         {{{0x0b, 0x0f, 0x00, 0x00},{0x0b, 0x1e, 0x00, 0x17}}, 0x0000, 0x0036},
  678.         {{{0x0c, 0x1a, 0x00, 0x00},{0x0c, 0x1f, 0x00, 0x17}}, 0x0000, 0x0036},
  679.         {{{0x5d, 0x1e, 0x00, 0x57},{0x51, 0x01, 0x00, 0x00}}, 0x0000, 0x000b},
  680.         {{{0x51, 0x01, 0x00, 0x57},{0x51, 0x02, 0x00, 0x00}}, 0x0000, 0x000b},
  681.         {{{0x51, 0x02, 0x00, 0x57},{0x51, 0x03, 0x00, 0x00}}, 0x0000, 0x000b},
  682.         {{{0x51, 0x03, 0x00, 0x57},{0x51, 0x04, 0x00, 0x00}}, 0x0000, 0x000b},
  683.         {{{0x51, 0x04, 0x00, 0x57},{0x51, 0x05, 0x00, 0x00}}, 0x0000, 0x000b},
  684.         {{{0x51, 0x05, 0x00, 0x57},{0x51, 0x06, 0x00, 0x00}}, 0x0000, 0x000b},
  685.         {{{0x5d, 0x19, 0x00, 0x00},{0x5d, 0x1d, 0x00, 0x17}}, 0x0000, 0x002e},
  686.         {{{0x51, 0x01, 0x00, 0x00},{0x51, 0x05, 0x00, 0x17}}, 0x0000, 0x002f},
  687.         {{{0x08, 0xce, 0x00, 0x00},{0x08, 0xce, 0x00, 0x17}}, 0x0000, 0x0043},
  688.         {{{0x58, 0x0f, 0x00, 0x12},{0x58, 0x0f, 0x00, 0x14}}, 0x0000, 0x0016},
  689.         {{{0x58, 0x0f, 0x00, 0x13},{0x58, 0x0f, 0x00, 0x13}}, 0x0000, 0x0000},
  690.         {{{0x58, 0x08, 0x00, 0x00},{0x58, 0x0e, 0x00, 0x17}}, 0x0000, 0x0024},
  691.         {{{0x58, 0x0f, 0x00, 0x00},{0x58, 0x0f, 0x00, 0x17}}, 0x0000, 0x0043},
  692.         {{{0x59, 0x0d, 0x00, 0x00},{0x59, 0x0d, 0x00, 0x17}}, 0x0000, 0x0043},
  693.         {{{0x0a, 0x91, 0x00, 0x09},{0x0a, 0x91, 0x00, 0x10}}, 0x0000, 0x0001},
  694.         {{{0x0a, 0x91, 0x00, 0x09},{0x0a, 0x91, 0x00, 0x0a}}, 0x0000, 0x0008},
  695.         {{{0x0a, 0x91, 0x00, 0x0b},{0x0a, 0x91, 0x00, 0x0c}}, 0x0000, 0x000a},
  696.         {{{0x0a, 0x91, 0x00, 0x0d},{0x0a, 0x91, 0x00, 0x0e}}, 0x0000, 0x0007},
  697.         {{{0x0a, 0x91, 0x00, 0x0f},{0x0a, 0x91, 0x00, 0x10}}, 0x0000, 0x0009},
  698.         {{{0x0a, 0x01, 0x00, 0x40},{0x0a, 0x91, 0x00, 0x00}}, 0x0000, 0x0026},
  699.         {{{0x0a, 0x91, 0x00, 0x00},{0x0a, 0x91, 0x00, 0x17}}, 0x0000, 0x0043},
  700.         {{{0x0a, 0x0f, 0x00, 0x00},{0x0a, 0x19, 0x00, 0x17}}, 0x0000, 0x000f},
  701.         {{{0x0a, 0x0a, 0x00, 0x00},{0x0a, 0x0e, 0x00, 0x17}}, 0x0000, 0x0034},
  702.         {{{0x0a, 0x0f, 0x00, 0x00},{0x0a, 0x19, 0x00, 0x17}}, 0x0000, 0x0035},
  703.         {{{0x0a, 0x1f, 0x00, 0x52},{0x0b, 0x01, 0x00, 0x00}}, 0x0000, 0x000d},
  704.         {{{0x0a, 0x01, 0x00, 0x00},{0x0a, 0x1e, 0x00, 0x17}}, 0x0000, 0x0032},
  705.         {{{0x0a, 0x1f, 0x00, 0x00},{0x0a, 0x1f, 0x00, 0x17}}, 0x0000, 0x0043},
  706.         {{{0x0b, 0xc8, 0x00, 0x06},{0x0b, 0xc8, 0x00, 0x11}}, 0x0000, 0x0002},
  707.         {{{0x0a, 0x0f, 0x00, 0x00},{0x0a, 0x1f, 0x00, 0x17}}, 0x0000, 0x0027},
  708.         {{{0x0b, 0x01, 0x00, 0x40},{0x0b, 0xf8, 0x00, 0x00}}, 0x0000, 0x0028},
  709.         {{{0x0c, 0x18, 0x00, 0x54},{0x0c, 0x19, 0x00, 0x00}}, 0x0000, 0x0005},
  710.         {{{0x0c, 0x18, 0x00, 0x00},{0x0c, 0x18, 0x00, 0x17}}, 0x0000, 0x001a},
  711.         {{{0x0c, 0x18, 0x00, 0x00},{0x0c, 0x18, 0x00, 0x17}}, 0x0000, 0x0044},
  712.         {{{0x0c, 0x0a, 0x00, 0x00},{0x0c, 0x17, 0x00, 0x17}}, 0x0000, 0x002c},
  713.         {{{0x0c, 0x1f, 0x00, 0x57},{0x01, 0x01, 0x00, 0x00}}, 0x0000, 0x0006},
  714.         {{{0x0c, 0x19, 0x00, 0x00},{0x0c, 0x1e, 0x00, 0x17}}, 0x0000, 0x002d},
  715.         {{{0x0c, 0x1f, 0x00, 0x00},{0x0c, 0x1f, 0x00, 0x17}}, 0x0000, 0x0043}
  716.     };
  717.    
  718.     for (int i = 0; i < 77; i++) {
  719.         EvSchedule* t = evs + i;
  720.         evdate_u t2 = decode_date(&t->day[0]);
  721.         evdate_u t2_e = decode_date(&t->day[1]);
  722.        
  723.         if ((t2.d.hour & 0x80) != 0) {
  724.             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);
  725.         }
  726.         else if ((t2.d.hour & 0x40) != 0) {
  727.             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);
  728.         }
  729.         else {
  730.             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);
  731.         }
  732.     }
  733.  
  734.     return 0;
  735. }
  736.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement