diff options
| author | Prakxo <87568477+Prakxo@users.noreply.github.com> | 2024-05-19 18:40:39 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-05-19 09:40:39 -0700 |
| commit | 448405671db5a0c0ffd5d62c04c333d7e3b4e7fc (patch) | |
| tree | 4f76e2b1b83c58bec8bdc72af52fb362d4aa499f | |
| parent | 92911830dc9be365989887e1464bf766e471ed96 (diff) | |
m_time OK (#189)
| -rw-r--r-- | include/6BA500.h | 2 | ||||
| -rw-r--r-- | include/m_common_data.h | 3 | ||||
| -rw-r--r-- | include/m_time.h | 29 | ||||
| -rw-r--r-- | linker_scripts/jp/symbol_addrs_code.txt | 12 | ||||
| -rw-r--r-- | src/code/m_start_data_init.c | 2 | ||||
| -rw-r--r-- | src/code/m_time.c | 248 | ||||
| -rw-r--r-- | yamls/jp/code.yaml | 6 |
7 files changed, 282 insertions, 20 deletions
diff --git a/include/6BA500.h b/include/6BA500.h index e80d8fb..90794fd 100644 --- a/include/6BA500.h +++ b/include/6BA500.h @@ -7,7 +7,7 @@ void func_800968C0_jp(void); // void func_80096B2C_jp(); // void func_80096B4C_jp(); -void func_80096B64_jp(void); +void Kabu_manager(void); // void func_80096BF0_jp(); #endif diff --git a/include/m_common_data.h b/include/m_common_data.h index 20758c6..8cbd825 100644 --- a/include/m_common_data.h +++ b/include/m_common_data.h @@ -90,7 +90,8 @@ typedef struct CommonData { /* 0x0F2A0 */ UNK_TYPE1 unk_0F2A0[0x17C]; /* 0x0F41C */ SnowmanData snowmanData[SNOWMAN_SAVE_COUNT]; /* 0x0F428 */ u64 melody; - /* 0x0F430 */ UNK_TYPE1 unk_F430[0x8]; + /* 0x0F430 */ UNK_TYPE1 unk_F430[0x4]; + /* 0x0F434 */ lbRTC_ymd_t renewTime; /* 0x0F438 */ u8 stationType; /* 0x0F439 */ u8 saveWeather; /* 0x0F440 */ u8 unk_F440[0x2]; diff --git a/include/m_time.h b/include/m_time.h index eb6dc05..f12b565 100644 --- a/include/m_time.h +++ b/include/m_time.h @@ -41,7 +41,7 @@ typedef enum mTM_TERM{ /* 16 */ mTM_TERM_16, /* 17 */ mTM_TERM_17, - /* 18 */ mTM_TERM_NUM + /* 18 */ mTM_TERM_MAX } mTM_TERM; #define mTM_RENEW_TIME_NONE 0 @@ -60,17 +60,17 @@ typedef enum mTM_RENEW_TIME{ #define mTM_MINUTES_IN_HOUR 60 -typedef struct mTM_calendar_term_t { +typedef struct TimeCalendarTerm { /* 0x00 */ lbRTC_month_t month; /* 0x01 */ lbRTC_day_t day; /* 0x02 */ u16 season; - /* 0x04 */ s16 bgitem_profile; - /* 0x06 */ s16 bgitem_bank; -} mTM_calendar_term_t; // size = 0x8 + /* 0x04 */ s16 bgitemProfile; + /* 0x06 */ s16 bgitemBank; +} TimeCalendarTerm; // size = 0x8 -extern lbRTC_time_c mTM_rtcTime_clear_code; -extern lbRTC_ymd_t mTM_rtcTime_ymd_clear_code; -extern lbRTC_time_c mTM_rtcTime_default_code; +extern const lbRTC_time_c mTM_rtcTime_clear_code; +extern const lbRTC_ymd_t mTM_rtcTime_ymd_clear_code; +extern const lbRTC_time_c mTM_rtcTime_default_code; #define mTM_IsTimeCleared(time) (lbRTC_IsEqualTime((time), &mTM_rtcTime_clear_code, lbRTC_CHECK_ALL) == TRUE) #define mTM_AreTimesEqual(t0, t1) (lbRTC_IsEqualTime(t0, t1, lbRTC_CHECK_ALL)) @@ -78,4 +78,17 @@ extern lbRTC_time_c mTM_rtcTime_default_code; #define mTM_CheckCmpYMDEqual(ymd0, ymd1) ((ymd0)->year == (ymd1)->year && (ymd0)->month == (ymd1)->month && (ymd0)->day == (ymd1)->day) #define mTM_CheckCmpYMDClear(ymd0) ((ymd0)->year == mTM_rtcTime_ymd_clear_code.year || (ymd0)->month == mTM_rtcTime_ymd_clear_code.month || (ymd0)->day == mTM_rtcTime_ymd_clear_code.day) +s32 mTM_get_termIdx(void); +void mTM_set_season(void); +void mTM_clear_renew_is(void); +s32 mTM_check_renew_time(u8 flag); +void mTM_off_renew_time(u8 flag); +void mTM_set_renew_is(void); +void mTM_set_renew_time(lbRTC_ymd_t* renewTime, lbRTC_time_c* time); +void mTM_renewal_renew_time(void); +void mTM_disp_time(s32 unused); +s32 mTM_TimestepControl(void); +void mTM_time(void); + + #endif diff --git a/linker_scripts/jp/symbol_addrs_code.txt b/linker_scripts/jp/symbol_addrs_code.txt index 3395c6a..1db2fc8 100644 --- a/linker_scripts/jp/symbol_addrs_code.txt +++ b/linker_scripts/jp/symbol_addrs_code.txt @@ -1708,7 +1708,7 @@ func_80096860_jp = 0x80096860; // type:func func_800968C0_jp = 0x800968C0; // type:func func_80096B2C_jp = 0x80096B2C; // type:func func_80096B4C_jp = 0x80096B4C; // type:func -func_80096B64_jp = 0x80096B64; // type:func +Kabu_manager = 0x80096B64; // type:func func_80096BF0_jp = 0x80096BF0; // type:func mEnv_regist_nature = 0x80096C90; // type:func func_80096CA0_jp = 0x80096CA0; // type:func @@ -3175,16 +3175,16 @@ func_800C98A0_jp = 0x800C98A0; // type:func func_800C9D38_jp = 0x800C9D38; // type:func mTRC_init = 0x800C9F88; // type:func mTRC_move = 0x800CA008; // type:func -func_800CA070_jp = 0x800CA070; // type:func +mTM_get_termIdx = 0x800CA070; // type:func mTM_set_season = 0x800CA1DC; // type:func -func_800CA230_jp = 0x800CA230; // type:func +mTM_clear_renew_is = 0x800CA230; // type:func mTM_check_renew_time = 0x800CA240; // type:func mTM_off_renew_time = 0x800CA278; // type:func -func_800CA2A8_jp = 0x800CA2A8; // type:func +mTM_set_renew_is = 0x800CA2A8; // type:func mTM_set_renew_time = 0x800CA2BC; // type:func mTM_renewal_renew_time = 0x800CA2DC; // type:func -func_800CA350_jp = 0x800CA350; // type:func -func_800CA570_jp = 0x800CA570; // type:func +mTM_disp_time = 0x800CA350; // type:func +mTM_TimestepControl = 0x800CA570; // type:func mTM_time = 0x800CA63C; // type:func set_viewport = 0x800CA8A0; // type:func initView = 0x800CA90C; // type:func diff --git a/src/code/m_start_data_init.c b/src/code/m_start_data_init.c index cb6aa61..7dd776c 100644 --- a/src/code/m_start_data_init.c +++ b/src/code/m_start_data_init.c @@ -400,7 +400,7 @@ void mSDI_StartInitAfter(Game* game, s32 renewalReserveFlag, s32 mallocFlag) { func_80084DA4_jp(); mEv_2nd_init(&game_play->event); mNpc_Grow(); - func_80096B64_jp(); + Kabu_manager(); mNpc_InitNpcData(); mNpc_InitNpcList(); mNpc_SetNpcList(common_data.npclist, common_data.animals, ANIMAL_NUM_MAX, mallocFlag); diff --git a/src/code/m_time.c b/src/code/m_time.c new file mode 100644 index 0000000..f4f4601 --- /dev/null +++ b/src/code/m_time.c @@ -0,0 +1,248 @@ +#include "m_time.h" +#include "zurumode.h" +#include "m_common_data.h" +#include "gfx.h" +#include "gfxalloc.h" +#include "6BA500.h" +#include "game.h" + +s32 debug_disp = FALSE; + +TimeCalendarTerm mTM_calender[mTM_TERM_MAX] = { + { lbRTC_FEBRUARY, 3, mTM_SEASON_WINTER, 0x0050, 0x0025 }, + { lbRTC_FEBRUARY, 17, mTM_SEASON_WINTER, 0x0050, 0x0025 }, + { lbRTC_FEBRUARY, 24, mTM_SEASON_WINTER, 0x0050, 0x0025 }, + { lbRTC_MARCH, 31, mTM_SEASON_SPRING, 0x0001, 0x0004 }, + { lbRTC_APRIL, 8, mTM_SEASON_SPRING, 0x004f, 0x0024 }, + { lbRTC_MAY, 25, mTM_SEASON_SPRING, 0x0001, 0x0004 }, + { lbRTC_JULY, 22, mTM_SEASON_SUMMER, 0x0001, 0x0004 }, + { lbRTC_AUGUST, 31, mTM_SEASON_SUMMER, 0x0001, 0x0004 }, + { lbRTC_SEPTEMBER, 15, mTM_SEASON_SUMMER, 0x0001, 0x0004 }, + { lbRTC_SEPTEMBER, 30, mTM_SEASON_AUTUMN, 0x0001, 0x0004 }, + { lbRTC_OCTOBER, 15, mTM_SEASON_AUTUMN, 0x0001, 0x0004 }, + { lbRTC_OCTOBER, 29, mTM_SEASON_AUTUMN, 0x0001, 0x0004 }, + { lbRTC_NOVEMBER, 12, mTM_SEASON_AUTUMN, 0x0001, 0x0004 }, + { lbRTC_NOVEMBER, 26, mTM_SEASON_AUTUMN, 0x0001, 0x0004 }, + { lbRTC_DECEMBER, 9, mTM_SEASON_AUTUMN, 0x0001, 0x0004 }, + { lbRTC_DECEMBER, 17, mTM_SEASON_WINTER, 0x0051, 0x0026 }, + { lbRTC_DECEMBER, 24, mTM_SEASON_WINTER, 0x0051, 0x0026 }, + { lbRTC_DECEMBER, 31, mTM_SEASON_WINTER, 0x0050, 0x0025 }, +}; + +u8 l_renew_is = mTM_RENEW_TIME_NONE; + +const lbRTC_time_c mTM_rtcTime_clear_code = { + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFFFF, +}; + +const lbRTC_ymd_t mTM_rtcTime_ymd_clear_code = { + 0xFF, + 0xFF, + 0xFF, +}; + +const lbRTC_time_c mTM_rtcTime_default_code = { + 0, 0, 12, 1, lbRTC_SATURDAY, lbRTC_JANUARY, 2000, +}; + +s32 mTM_get_termIdx() { + lbRTC_month_t month = common_data.time.rtcTime.month; + lbRTC_day_t day = common_data.time.rtcTime.day; + TimeCalendarTerm* info = mTM_calender; + u32 term; + + for (term = 0; term < mTM_TERM_MAX; info++, term++) { + if (month < info->month || (month == info->month && day <= info->day)) { + return term; + } + } + + return -1; +} + +void mTM_set_season() { + s32 termIdx = mTM_get_termIdx(); + TimeCalendarTerm* info = mTM_calender + termIdx; + + common_data.time.season = info->season; + common_data.time.termIdx = termIdx; + common_data.time.bgitemProfile = info->bgitemProfile; + common_data.time.bgitemBank = info->bgitemBank; +} + +void mTM_clear_renew_is() { + l_renew_is = mTM_RENEW_TIME_NONE; +} + +s32 mTM_check_renew_time(u8 flag) { + s32 renew = FALSE; + + if (((l_renew_is >> flag) & 1) == 1) { + renew = TRUE; + } + + return renew; +} + +void mTM_off_renew_time(u8 flag) { + l_renew_is &= ~(1 << flag); +} + +void mTM_set_renew_is() { + l_renew_is = mTM_RENEW_TIME_ALL; +} + +void mTM_set_renew_time(lbRTC_ymd_t* renewTime, lbRTC_time_c* time) { + renewTime->year = time->year; + renewTime->month = time->month; + renewTime->day = time->day; +} + +void mTM_renewal_renew_time() { + lbRTC_ymd_t* renewTime = &common_data.renewTime; + lbRTC_time_c* rtcTime = &common_data.time.rtcTime; + + if ((renewTime->year != rtcTime->year) || (renewTime->month != rtcTime->month) || + (renewTime->day != rtcTime->day)) { + mTM_set_renew_time(renewTime, rtcTime); + mTM_set_renew_is(); + } +} + +void mTM_disp_time(UNUSED s32 unused) { + + if (common_data.time.addIdx != 1 && zurumode_flag != 0 && (gamePT->input[1].press.button & A_BUTTON) == A_BUTTON) { + static s32 disp = FALSE; + disp = disp ^ TRUE; + common_data.time.disp = disp; + } + + if (common_data.time.disp == TRUE) { + GraphicsContext* graph = gamePT->gfxCtx; + Gfx* gfxTemp; + Gfx* gfxTemp2; + gfxprint* gfxprintPtr; + gfxprint gfxprint; + + gfxprintPtr = &gfxprint; + + gfxprint_init(gfxprintPtr); + + OPEN_DISPS(graph); + gfxTemp2 = POLY_OPA_DISP; + gfxTemp = gfxopen(gfxTemp2); + + gSPDisplayList(OVERLAY_DISP++, gfxTemp); + + gfxprint_open(gfxprintPtr, gfxTemp); + gfxprint_color(gfxprintPtr, 255, 255, 255, 255); + gfxprint_locate8x8(gfxprintPtr, 3, 3); + gfxprint_printf(gfxprintPtr, "%04d", (common_data.time.rtcTime.year)); + gfxprint_locate8x8(gfxprintPtr, 8, 3); + gfxprint_printf(gfxprintPtr, "%02d/", (common_data.time.rtcTime.month)); + gfxprint_locate8x8(gfxprintPtr, 11, 3); + gfxprint_printf(gfxprintPtr, "%02d", (common_data.time.rtcTime.day)); + gfxprint_locate8x8(gfxprintPtr, 14, 3); + gfxprint_printf(gfxprintPtr, "%02d:", (common_data.time.rtcTime.hour)); + gfxprint_locate8x8(gfxprintPtr, 17, 3); + gfxprint_printf(gfxprintPtr, "%02d", (common_data.time.rtcTime.min)); + gfxprint_locate8x8(gfxprintPtr, 20, 3); + gfxprint_printf(gfxprintPtr, "%02d", (common_data.time.rtcTime.sec)); + + gfxTemp = gfxprint_close(gfxprintPtr); + gSPEndDisplayList(gfxTemp++); + + gfxclose(gfxTemp2, gfxTemp); + + POLY_OPA_DISP = gfxTemp; + + CLOSE_DISPS(graph); + + gfxprint_cleanup(gfxprintPtr); + } +} + +s32 mTM_TimestepControl() { + static s32 id = 0; + static s32 timestep[] = { 240, 480, 960 }; + s32 addSec; + + if (zurumode_flag != 0 && zurumode_flag >= 2 && debug_disp == TRUE && + (gamePT->input[1].press.button & R_TRIG) == R_TRIG) { + if (id < 3) { + common_data.time.rtcCrashed = TRUE; + + common_data.time.addSec = timestep[id]; + + addSec -= 1; + id++; + } else { + common_data.time.rtcCrashed = FALSE; + common_data.time.addIdx = 0; + lbRTC_SetTime(&common_data.time.rtcTime); + + id = 0; + } + } + + return id != 0; +} +void mTM_time() { + u8 day = common_data.time.rtcTime.day; + + mTM_TimestepControl(); + if (common_data.time.rtcEnabled == TRUE && common_data.time.rtcCrashed == FALSE) { + lbRTC_GetTime(&common_data.time.rtcTime); + if ((zurumode_flag != 0) && ((gamePT->input[1].press.button & A_BUTTON) == A_BUTTON)) { + debug_disp ^= TRUE; + } + if (debug_disp == TRUE) { + mTM_disp_time(0); + } + } else { + s32 addSec = common_data.time.addSec; + s32 sec = common_data.time.underSec; + + { + s32 timeAddSec = 0; + sec += addSec; + while (sec >= mTM_SECONDS_IN_MINUTE) { + timeAddSec++; + sec -= mTM_SECONDS_IN_MINUTE; + } + + lbRTC_Add_ss(&common_data.time.rtcTime, timeAddSec); + common_data.time.rtcTime.weekday = lbRTC_Week( + (common_data.time.rtcTime.year), (common_data.time.rtcTime.month), (common_data.time.rtcTime.day)); + } + + common_data.time.underSec = sec; + if ((zurumode_flag != 0) && (gamePT->input[1].press.button & A_BUTTON) == A_BUTTON) { + debug_disp ^= TRUE; + } + if (debug_disp == TRUE) { + mTM_disp_time(sec); + } + } + + { + s32 temp2 = (common_data.time.rtcTime.sec) + (common_data.time.rtcTime.min * mTM_MINUTES_IN_HOUR) + + (common_data.time.rtcTime.hour) * mTM_SECONDS_IN_HOUR; + + common_data.time.nowSec = temp2; + } + + if (common_data.time.rtcTime.day != day) { + Kabu_manager(); + } + + { + s32 temp3 = (common_data.time.rtcTime.min * 60) + (common_data.time.rtcTime.sec); + + common_data.time.radMin = ((temp3 / ((f32)mTM_SECONDS_IN_HOUR)) * 65536.0f); + common_data.time.radHour = + ((((common_data.time.rtcTime.hour) * 3600 + temp3) / ((f32)mTM_SECONDS_IN_HALFDAY)) * 65536.0f); + } + + mTM_renewal_renew_time(); +} diff --git a/yamls/jp/code.yaml b/yamls/jp/code.yaml index 61922c8..13fd372 100644 --- a/yamls/jp/code.yaml +++ b/yamls/jp/code.yaml @@ -82,7 +82,7 @@ - [0x6EC430, c, code/m_snowman] - [0x6EC9E0, asm, code/6EC9E0] - [0x6ECD90, asm, code/6ECD90] - - [0x6EDD10, asm, code/m_time] + - [0x6EDD10, c, code/m_time] - [0x6EE540, c, code/m_view] - [0x6EFC20, asm, code/6EFC20] - [0x6F12E0, asm, code/6F12E0] @@ -173,7 +173,7 @@ - [0x732740, data, code/732740] - [0x732A00, .data, code/m_skin_matrix] - [0x732A40, data, code/732A40] - - [0x732AF0, data, code/m_time] + - [0x732AF0, .data, code/m_time] - [0x732BA0, .data, code/m_view] - [0x732BB0, data, code/732BB0] - [0x732C20, .data, code/audio] @@ -242,7 +242,7 @@ - [0x73B710, .rodata, code/m_snowman] - [0x73B720, rodata, code/m_titledemo] - [0x73B740, rodata, code/73B740] - - [0x73B780, rodata, code/m_time] + - [0x73B780, .rodata, code/m_time] - [0x73B7D0, .rodata, code/m_view] - [0x73B7E0, rodata, code/73B7E0] - [0x73B830, rodata, code/73B830] |
