Implement & Link lb_rtc.c

This commit is contained in:
Cuyler36
2023-04-01 12:43:47 -04:00
parent 80b4e5c7b0
commit 01f0e0b55a
7 changed files with 1324 additions and 0 deletions
+5
View File
@@ -17,6 +17,11 @@ graph.c:
.text: [0x80405518, 0x80405EC8]
.data: [0x8065ECA8, 0x8065ECB0]
.bss: [0x812F31E8, 0x812F3560]
lb_rtc.c:
.text: [0x80406480, 0x8040752C]
.rodata: [0x806436F8, 0x806437A0]
.data: [0x8065ECD0, 0x8065ECD8]
.bss: [0x812F4CB0, 0x812F4CC0]
zurumode.c:
.text: [0x8040eb38, 0x8040f008]
.bss: [0x812f9670, 0x812f9680]
+33
View File
@@ -10,9 +10,42 @@ extern "C" {
typedef s64 OSTime;
typedef u32 OSTick;
u32 __busclock AT_ADDRESS(0x800000F8);
#define OS_BUS_CLOCK __busclock
#define OS_TIMER_CLOCK (OS_BUS_CLOCK / 4)
#define OSTicksToCycles(ticks) (((ticks) * ((OS_CORE_CLOCK * 2) / OS_TIMER_CLOCK)) / 2)
#define OSTicksToSeconds(ticks) ((ticks) / OS_TIMER_CLOCK)
#define OSTicksToMilliseconds(ticks) ((ticks) / (OS_TIMER_CLOCK / 1000))
#define OSTicksToMicroseconds(ticks) (((ticks)*8) / (OS_TIMER_CLOCK / 125000))
#define OSTicksToNanoseconds(ticks) (((ticks)*8000) / (OS_TIMER_CLOCK / 125000))
#define OSSecondsToTicks(sec) ((sec)*OS_TIMER_CLOCK)
#define OSMillisecondsToTicks(msec) ((msec) * (OS_TIMER_CLOCK / 1000))
#define OSMicrosecondsToTicks(usec) (((usec) * (OS_TIMER_CLOCK / 125000)) / 8)
#define OSNanosecondsToTicks(nsec) (((nsec) * (OS_TIMER_CLOCK / 125000)) / 8000)
OSTime OSGetTime(void);
OSTick OSGetTick(void);
typedef struct OSCalendarTime_s {
int sec;
int min;
int hour;
int mday;
int mon;
int year;
int wday;
int yday;
int msec;
int usec;
} OSCalendarTime;
OSTime OSCalendarTimeToTicks(OSCalendarTime* td);
void OSTicksToCalendarTime(OSTime ticks, OSCalendarTime* td);
#ifdef __cplusplus
}
#endif
+19
View File
@@ -0,0 +1,19 @@
#ifndef LB_REKI_H
#define LB_REKI_H
#include "types.h"
#include "lb_rtc.h"
#ifdef __cplusplus
extern "C" {
#endif
#define lbRk_YEAR_MIN GAME_YEAR_MIN
#define lbRk_YEAR_MAX GAME_YEAR_MAX
#define lbRk_YEAR_COUNT ((lbRk_YEAR_MAX - lbRk_YEAR_MIN) + 1)
#ifdef __cplusplus
}
#endif
#endif
+147
View File
@@ -0,0 +1,147 @@
#ifndef LB_RTC_H
#define LB_RTC_H
#include "types.h"
#include "dolphin/os/OSTime.h"
#ifdef __cplusplus
extern "C" {
#endif
/* TODO: do these have a better header? */
#define GAME_YEAR_MIN 2000 /* Minimum year supported by the game */
#define GAME_YEAR_MAX 2032 /* Maximum year supported by the game */
#define lbRTC_YEAR_MIN 1901
#define lbRTC_YEAR_MAX 2099
typedef u8 lbRTC_sec_t;
typedef u8 lbRTC_min_t;
typedef u8 lbRTC_hour_t;
typedef u8 lbRTC_day_t;
typedef u8 lbRTC_weekday_t;
typedef u8 lbRTC_month_t;
typedef u16 lbRTC_year_t;
typedef struct lbRTC_datetime_s {
lbRTC_sec_t sec;
lbRTC_min_t min;
lbRTC_hour_t hour;
lbRTC_day_t day;
lbRTC_weekday_t weekday;
lbRTC_month_t month;
lbRTC_year_t year;
} lbRTC_time_c; /* Name leaked in lbRTC_time_c_save_data_check */
typedef struct lbRTC_ymd_s {
lbRTC_year_t year;
lbRTC_month_t month;
lbRTC_day_t day;
} lbRTC_ymd_t; /* Name leaked in mTM_ymd_2_time */
enum WEEKDAYS {
lbRTC_WEEKDAYS_BEGIN = 0,
lbRTC_SUNDAY = lbRTC_WEEKDAYS_BEGIN,
lbRTC_MONDAY,
lbRTC_TUESDAY,
lbRTC_WEDNESDAY,
lbRTC_THURSDAY,
lbRTC_FRIDAY,
lbRTC_SATURDAY,
lbRTC_WEEK,
lbRTC_WEEKDAYS_MAX = lbRTC_WEEK
};
enum MONTHS {
lbRTC_MONTHS_BEGIN = 0,
lbRTC_JANUARY = 1,
lbRTC_FEBRUARY,
lbRTC_MARCH,
lbRTC_APRIL,
lbRTC_MAY,
lbRTC_JUNE,
lbRTC_JULY,
lbRTC_AUGUST,
lbRTC_SEPTEMBER,
lbRTC_OCTOBER,
lbRTC_NOVEMBER,
lbRTC_DECEMBER,
lbRTC_MONTHS_MAX = lbRTC_DECEMBER
};
enum RTC_EQUALITY {
lbRTC_LESS = -1,
lbRTC_EQUAL = 0,
lbRTC_OVER = 1
};
enum RTC_EQUALITY_FLAGS {
lbRTC_CHECK_NONE = 0, /* 0x00 */
lbRTC_CHECK_SECONDS = 1 << 0, /* 0x01 */
lbRTC_CHECK_MINUTES = 1 << 1, /* 0x02 */
lbRTC_CHECK_HOURS = 1 << 2, /* 0x04 */
lbRTC_CHECK_WEEKDAYS = 1 << 3, /* 0x08 */
lbRTC_CHECK_DAYS = 1 << 4, /* 0x10 */
lbRTC_CHECK_MONTHS = 1 << 5, /* 0x20 */
lbRTC_CHECK_YEARS = 1 << 6, /* 0x40 */
/* 0x7F */
lbRTC_CHECK_ALL = lbRTC_CHECK_SECONDS |
lbRTC_CHECK_MINUTES |
lbRTC_CHECK_HOURS |
lbRTC_CHECK_WEEKDAYS |
lbRTC_CHECK_DAYS |
lbRTC_CHECK_MONTHS |
lbRTC_CHECK_YEARS
};
extern OSTime lbRTC_HardTime();
extern int lbRTC_IsAbnormal();
extern void lbRTC_Sampling();
extern void lbRTC_SetTime(lbRTC_time_c* time);
extern void lbRTC_GetTime(lbRTC_time_c* time);
extern lbRTC_day_t lbRTC_GetDaysByMonth(lbRTC_year_t year, lbRTC_month_t month);
extern int lbRTC_IsEqualDate(
lbRTC_year_t y0, lbRTC_month_t m0, lbRTC_day_t d0,
lbRTC_year_t y1, lbRTC_month_t m1, lbRTC_day_t d1
);
extern int lbRTC_IsEqualTime(const lbRTC_time_c* t0, const lbRTC_time_c* t1, int flags);
extern int lbRTC_IsOverTime(const lbRTC_time_c* t0, const lbRTC_time_c* t1);
// extern int lbRTC_IsJustAtRTC(const lbRTC_time_c* time, int check_flags);
extern int lbRTC_IsOverRTC(const lbRTC_time_c* time);
extern int lbRTC_IntervalTime(const lbRTC_time_c* time0, const lbRTC_time_c* time1);
extern int lbRTC_GetIntervalDays(const lbRTC_time_c* t0, const lbRTC_time_c* t1);
extern int lbRTC_GetIntervalDays2(const lbRTC_ymd_t* ymd0, const lbRTC_ymd_t* ymd1);
extern void lbRTC_Add_YY(lbRTC_time_c* time, int year);
extern void lbRTC_Add_MM(lbRTC_time_c* time, int month);
extern void lbRTC_Add_DD(lbRTC_time_c* time, int day);
extern void lbRTC_Add_hh(lbRTC_time_c* time, int hour);
extern void lbRTC_Add_mm(lbRTC_time_c* time, int min);
extern void lbRTC_Add_ss(lbRTC_time_c* time, int sec);
extern void lbRTC_Add_Date(lbRTC_time_c* time, const lbRTC_time_c* add_time);
extern void lbRTC_Sub_YY(lbRTC_time_c* time, int year);
extern void lbRTC_Sub_MM(lbRTC_time_c* time, int month);
extern void lbRTC_Sub_DD(lbRTC_time_c* time, int days);
extern void lbRTC_Sub_hh(lbRTC_time_c* time, int hour);
extern void lbRTC_Sub_mm(lbRTC_time_c* time, int min);
extern void lbRTC_Sub_ss(lbRTC_time_c* time, int sec);
// extern void lbRTC_Sub_Date(lbRTC_time_c* time, const lbRTC_time_c* sub_time)
extern lbRTC_weekday_t lbRTC_Week(lbRTC_year_t year, lbRTC_month_t month, lbRTC_day_t day);
extern void lbRTC_TimeCopy(lbRTC_time_c* dst, const lbRTC_time_c* src);
extern int lbRTC_IsValidTime(const lbRTC_time_c* time);
extern int lbRTC_time_c_save_data_check(const lbRTC_time_c* time);
extern int lbRTC_Weekly_day(lbRTC_year_t year, lbRTC_month_t month, int weeks, int weekday);
#define lbRTC_HOURS_PER_DAY 24
#define lbRTC_MINUTES_PER_HOUR 60
#define lbRTC_SECONDS_PER_MINUTE 60
#define lbRTC_IS_LEAPYEAR(year) \
(((year % 4) == 0 && ((year % 100) != 0)) || ((year % 400) == 0))
#ifdef __cplusplus
}
#endif
#endif
+16
View File
@@ -0,0 +1,16 @@
#ifndef M_ACTOR_TYPE_H
#define M_ACTOR_TYPE_H
#include "types.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef u16 mActor_name_t;
#ifdef __cplusplus
}
#endif
#endif
+67
View File
@@ -0,0 +1,67 @@
#ifndef M_COMMON_DATA_H
#define M_COMMON_DATA_H
#include "types.h"
#include "m_actor_type.h"
#include "lb_rtc.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct time_s {
u32 season;
u32 term_idx;
s16 bg_item_profile;
s16 bg_item_bank;
int now_sec;
lbRTC_time_c rtc_time;
s16 rad_min; /* clock hand radial position for mins */
s16 rad_hour; /* clock hand radial position for hours */
u8 time_signal;
u8 under_sec;
u8 disp;
u8 rtc_crashed;
int rtc_enabled;
int add_sec;
int add_idx;
} Time_c;
typedef struct Save_s {
u8 _tmp0[0x22528];
OSTime time_delta;
u8 _tmp1[0x3AD0];
} Save_t;
typedef union save_u {
Save_t save;
u8 raw[0x26000]; /* Temp to force length */
} Save;
typedef struct common_data_s {
/* 0x000000 */ Save save;
/* 0x026000 */ u8 game_1_patu;
/* 0x026001 */ u8 field_type;
/* 0x026002 */ u8 field_draw_type;
/* 0x026003 */ u8 player_no;
/* 0x026004 */ int last_scene_no;
/* 0x026008 */ int player_data_mode;
/* 0x02600C */ u8 _clip[0x104]; /* Temporary, clip is a struct with size 0x104 */
/* 0x026110 */ Time_c time;
} common_data_t;
extern common_data_t common_data;
#define Common_Get(name) (common_data.name)
#define Common_GetPointer(name) (&common_data.name)
#define Common_Set(name, value) (common_data.name = (value))
#define Save_Get(name) (Common_Get(save.save.name))
#define Save_GetPointer(name) (Common_GetPointer(save.save.name))
#define Save_Set(name, value) (Common_Set(save.save.name, value))
#ifdef __cplusplus
}
#endif
#endif
+1037
View File
File diff suppressed because it is too large Load Diff