#include "util.h" #include void set_time(const struct tm *time) { boot_SetDate(time->tm_mday, time->tm_mon, time->tm_year + 1900); boot_SetTime(time->tm_sec, time->tm_min, time->tm_hour); } #define CLOCKFLAGS 0x3F #define IS24HOUR 2 bool is_clock_24h(void) { uint8_t *flags = (void*)0xD00080; return !!(flags[CLOCKFLAGS] & (1 << IS24HOUR)); } int mod(int a, int b) { int r = a % b; return r < 0 ? r + b : r; } uint8_t get_exact_day(const struct month_relative_day *mrday, uint8_t month, uint24_t year) { if(mrday->is_exact_day) { return mrday->exact_day; } else { struct tm tm = {.tm_mday = 1, .tm_mon = month, .tm_year = year}; time_t t = mktime(&tm); uint8_t weekday = localtime(&t)->tm_wday; return 1 + mod(mrday->weekday - weekday, 7) + 7 * (mrday->weeknum - 1); } } long lmax(long a, long b) { if(a > b) return a; else return b; }