From 4ddd60433dad7246bf3fad199c8d4e3da87b5c47 Mon Sep 17 00:00:00 2001 From: adrianrfreedman Date: Tue, 29 Sep 2026 16:46:50 +0300 Subject: [PATCH] Add RTC_DAY_CYCLE constant for the 140-day RTC wrap (#1267) --- constants/misc_constants.asm | 3 +++ engine/events/battle_tower/battle_tower.asm | 2 +- engine/rtc/rtc.asm | 2 +- home/time.asm | 12 ++++++------ 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/constants/misc_constants.asm b/constants/misc_constants.asm index e2a92f717..365cc242f 100644 --- a/constants/misc_constants.asm +++ b/constants/misc_constants.asm @@ -29,6 +29,9 @@ DEF SAVE_CHECK_VALUE_2 EQU 127 ; RTC halted check value DEF RTC_HALT_VALUE EQU $1234 +; the RTC day count wraps after 20 weeks, preserving the day of the week +DEF RTC_DAY_CYCLE EQU 20 * 7 + ; time of day boundaries DEF MORN_HOUR EQU 4 ; 4 AM DEF DAY_HOUR EQU 10 ; 10 AM diff --git a/engine/events/battle_tower/battle_tower.asm b/engine/events/battle_tower/battle_tower.asm index b78b4aaf7..0aa4e1f99 100644 --- a/engine/events/battle_tower/battle_tower.asm +++ b/engine/events/battle_tower/battle_tower.asm @@ -1110,7 +1110,7 @@ BattleTowerAction_17: .asm_170849 ld hl, wCurDay - ld a, 140 + ld a, RTC_DAY_CYCLE sub c add [hl] cp 11 diff --git a/engine/rtc/rtc.asm b/engine/rtc/rtc.asm index a3a9e6f5e..8e4aae053 100644 --- a/engine/rtc/rtc.asm +++ b/engine/rtc/rtc.asm @@ -185,7 +185,7 @@ _InitTime:: sbc [hl] dec hl jr nc, .okay_days - add 140 + add RTC_DAY_CYCLE ld c, 7 call SimpleDivide diff --git a/home/time.asm b/home/time.asm index e6f8ad64e..d35d5cd05 100644 --- a/home/time.asm +++ b/home/time.asm @@ -82,12 +82,12 @@ FixDays:: ; mod twice since bit 8 (DH) was set ldh a, [hRTCDayLo] .modh - sub 140 + sub RTC_DAY_CYCLE jr nc, .modh .modl - sub 140 + sub RTC_DAY_CYCLE jr nc, .modl - add 140 + add RTC_DAY_CYCLE ; update dl ldh [hRTCDayLo], a @@ -99,14 +99,14 @@ FixDays:: .daylo ; quit if fewer than 140 days have passed ldh a, [hRTCDayLo] - cp 140 + cp RTC_DAY_CYCLE jr c, .quit ; mod 140 .mod - sub 140 + sub RTC_DAY_CYCLE jr nc, .mod - add 140 + add RTC_DAY_CYCLE ; update dl ldh [hRTCDayLo], a