Skip to content

Commit

Permalink
Label the RTC code
Browse files Browse the repository at this point in the history
  • Loading branch information
meithecatte committed Jan 28, 2024
1 parent 947bda6 commit e86e0df
Show file tree
Hide file tree
Showing 41 changed files with 319 additions and 331 deletions.
28 changes: 28 additions & 0 deletions include/rtc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#ifndef POKEPLATINUM_RTC_H
#define POKEPLATINUM_RTC_H


#include <nitro/rtc.h>

enum TimeOfDay {
TOD_MORNING = 0,
TOD_DAY = 1,
TOD_TWILIGHT = 2,
TOD_NIGHT = 3,
TOD_LATE_NIGHT = 4,
};

void InitRTC(void);
void UpdateRTC(void);
void GetCurrentDateTime(RTCDate * date, RTCTime * time);
void GetCurrentTime(RTCTime * time);
void GetCurrentDate(RTCDate * date);
int GetSecondsSinceMidnight(void);
s64 GetTimestamp(void);
int DayNumberForDate(const RTCDate * date);
BOOL IsNight(void);
enum TimeOfDay GetTimeOfDay(void);
enum TimeOfDay TimeOfDayForHour(int hour);
s64 TimeElapsed(s64 since, s64 until);

#endif // POKEPLATINUM_RTC_H
20 changes: 0 additions & 20 deletions include/unk_0201378C.h

This file was deleted.

2 changes: 1 addition & 1 deletion platinum.us/main.lsf
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Static main
Object main.nef.p/src_unk_02012480.c.o
Object main.nef.p/src_unk_02012744.c.o
Object main.nef.p/src_unk_020131EC.c.o
Object main.nef.p/src_unk_0201378C.c.o
Object main.nef.p/src_rtc.c.o
Object main.nef.p/src_unk_02013A04.c.o
Object main.nef.p/src_unk_02013B10.c.o
Object main.nef.p/src_unk_02014000.c.o
Expand Down
8 changes: 4 additions & 4 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "unk_020067E8.h"
#include "unk_0200A9DC.h"
#include "unk_0200F174.h"
#include "unk_0201378C.h"
#include "rtc.h"
#include "unk_02017428.h"
#include "unk_02017728.h"
#include "unk_0201CCF0.h"
Expand Down Expand Up @@ -75,7 +75,7 @@ void NitroMain (void)
sub_02017B70(0);
PM_GetBackLight(&sSavedBacklightState, NULL);
sub_0202419C();
sub_0201378C();
InitRTC();
sub_02000E3C();
sub_02002B7C();

Expand Down Expand Up @@ -144,7 +144,7 @@ void NitroMain (void)
}
}

sub_020137C4();
UpdateRTC();
sub_02017458();
sub_020241CC();
sub_0201CDD4(gCoreSys.unk_24);
Expand Down Expand Up @@ -323,7 +323,7 @@ void InitRNG (void)
RTCTime v1;
u32 v2;

sub_0201384C(&v0, &v1);
GetCurrentDateTime(&v0, &v1);

v2 = v0.year + v0.month * 0x100 * v0.day * 0x10000 + v1.hour * 0x10000 + (v1.minute + v1.second) * 0x1000000 + gCoreSys.frameCounter;

Expand Down
2 changes: 1 addition & 1 deletion src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pokeplatinum_c = files(
'unk_02012480.c',
'unk_02012744.c',
'unk_020131EC.c',
'unk_0201378C.c',
'rtc.c',
'unk_02013A04.c',
'unk_02013B10.c',
'unk_02014000.c',
Expand Down
6 changes: 3 additions & 3 deletions src/overlay005/ov5_021D521C.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "overlay005/struct_ov5_021D5894.h"

#include "unk_02006E3C.h"
#include "unk_0201378C.h"
#include "rtc.h"
#include "heap.h"
#include "unk_0201E0A4.h"
#include "overlay005/ov5_021D521C.h"
Expand Down Expand Up @@ -39,7 +39,7 @@ UnkStruct_ov5_021D538C * ov5_021D521C (UnkStruct_ov5_021D5894 * param0, const u8
v1->unk_00 = ov5_021D53D4(param1, &v1->unk_04);
v1->unk_08 = 0;

v2 = sub_020138C8() / 2;
v2 = GetSecondsSinceMidnight() / 2;

for (v0 = 0; v0 < v1->unk_00; v0++) {
if (v1->unk_04[v0].unk_00 > v2) {
Expand Down Expand Up @@ -74,7 +74,7 @@ void ov5_021D5298 (UnkStruct_ov5_021D538C * param0)

GF_ASSERT(param0);

v4 = sub_020138C8() / 2;
v4 = GetSecondsSinceMidnight() / 2;

if (param0->unk_00 > 1) {
if ((param0->unk_08 - 1) >= 0) {
Expand Down
4 changes: 2 additions & 2 deletions src/overlay005/ov5_021F134C.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "overlay101/struct_ov101_021D86B0.h"

#include "unk_0200D9E8.h"
#include "unk_0201378C.h"
#include "rtc.h"
#include "unk_02061804.h"
#include "unk_020711EC.h"
#include "unk_02073838.h"
Expand Down Expand Up @@ -138,7 +138,7 @@ static void ov5_021F1424 (SysTask * param0, void * param1)
int v0;
UnkStruct_ov5_021F1388 * v1 = param1;

v0 = sub_02013960();
v0 = GetTimeOfDay();

switch (v1->unk_00) {
case 0:
Expand Down
4 changes: 2 additions & 2 deletions src/overlay006/ov6_02240C9C.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include "overlay006/struct_ov6_02242634_sub2.h"

#include "narc.h"
#include "unk_0201378C.h"
#include "rtc.h"
#include "heap.h"
#include "unk_0201D15C.h"
#include "unk_02025E08.h"
Expand Down Expand Up @@ -175,7 +175,7 @@ void ov6_02240C9C (const UnkStruct_ov6_02242634 * param0, int * param1, int * pa
{
int v0;

v0 = sub_02013960();
v0 = GetTimeOfDay();

if ((v0 == 1) || (v0 == 2)) {
(*param1) = param0->unk_48[0];
Expand Down
4 changes: 2 additions & 2 deletions src/overlay006/ov6_022465FC.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "struct_defs/struct_0203CDB0.h"

#include "narc.h"
#include "unk_0201378C.h"
#include "rtc.h"
#include "unk_0201D15C.h"
#include "savedata/save_table.h"
#include "unk_0202E2CC.h"
Expand Down Expand Up @@ -301,7 +301,7 @@ int ov6_02246978 (UnkStruct_0203CDB0 * param0, int param1)
default:
GF_ASSERT(0);
case 0:
switch (sub_02013960()) {
switch (GetTimeOfDay()) {
case 0:
return v1->unk_00;
case 1:
Expand Down
4 changes: 2 additions & 2 deletions src/overlay006/ov6_02246B74.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <nitro.h>
#include <string.h>

#include "unk_0201378C.h"
#include "rtc.h"
#include "overlay006/ov6_02246B74.h"

typedef struct {
Expand Down Expand Up @@ -126,7 +126,7 @@ int ov6_02246B74 (const int param0, const BOOL param1)
return 0;
}

sub_020138A4(&v2);
GetCurrentDate(&v2);

GF_ASSERT(v2.month > 0);
GF_ASSERT(v2.month <= 12);
Expand Down
6 changes: 3 additions & 3 deletions src/overlay026/ov26_022561C0.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "overlay026/struct_ov26_02256404_1.h"

#include "unk_0200D9E8.h"
#include "unk_0201378C.h"
#include "rtc.h"
#include "heap.h"
#include "overlay025/ov25_02253CE0.h"
#include "overlay025/ov25_02255ACC.h"
Expand Down Expand Up @@ -85,7 +85,7 @@ static BOOL ov26_0225621C (UnkStruct_ov26_0225621C * param0, UnkStruct_ov25_0225
param0->unk_07 = 0;
param0->unk_14.unk_0C = 0;

sub_02013880(&(param0->unk_14.unk_00));
GetCurrentTime(&(param0->unk_14.unk_00));

if (param0->unk_14.unk_00.hour >= 24) {
param0->unk_14.unk_00.hour %= 24;
Expand Down Expand Up @@ -203,7 +203,7 @@ static BOOL ov26_02256370 (UnkStruct_ov26_0225621C * param0)
if (ov26_022564CC(param0->unk_24, 1)) {
param0->unk_06 = param0->unk_14.unk_00.minute;
param0->unk_05 = param0->unk_14.unk_00.hour;
sub_02013880(&(param0->unk_14.unk_00));
GetCurrentTime(&(param0->unk_14.unk_00));

if ((param0->unk_06 != param0->unk_14.unk_00.minute) || (param0->unk_05 != param0->unk_14.unk_00.hour)) {
ov26_022564A8(param0->unk_24, 1);
Expand Down
6 changes: 3 additions & 3 deletions src/overlay030/ov30_022561C0.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "overlay030/struct_ov30_022563EC_1.h"

#include "unk_0200D9E8.h"
#include "unk_0201378C.h"
#include "rtc.h"
#include "heap.h"
#include "overlay025/ov25_02253CE0.h"
#include "overlay025/ov25_02255ACC.h"
Expand Down Expand Up @@ -84,7 +84,7 @@ static BOOL ov30_0225621C (UnkStruct_ov30_0225621C * param0, UnkStruct_ov25_0225
param0->unk_06 = 0;
param0->unk_14.unk_0C = 0;

sub_02013880(&(param0->unk_14.unk_00));
GetCurrentTime(&(param0->unk_14.unk_00));

if (param0->unk_14.unk_00.hour >= 24) {
param0->unk_14.unk_00.hour %= 24;
Expand Down Expand Up @@ -201,7 +201,7 @@ static BOOL ov30_02256364 (UnkStruct_ov30_0225621C * param0)

if (ov30_02256488(param0->unk_24, 1)) {
param0->unk_05 = param0->unk_14.unk_00.minute;
sub_02013880(&(param0->unk_14.unk_00));
GetCurrentTime(&(param0->unk_14.unk_00));

if (param0->unk_05 != param0->unk_14.unk_00.minute) {
ov30_02256464(param0->unk_24, 1);
Expand Down
6 changes: 3 additions & 3 deletions src/overlay045/ov45_022561C0.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "overlay045/struct_ov45_022566EC_1.h"

#include "unk_0200D9E8.h"
#include "unk_0201378C.h"
#include "rtc.h"
#include "heap.h"
#include "unk_02056720.h"
#include "overlay025/ov25_02253CE0.h"
Expand Down Expand Up @@ -127,7 +127,7 @@ static void ov45_022562C0 (UnkStruct_ov45_022566EC_1 * param0)
{
RTCTime v0;

sub_02013880(&v0);
GetCurrentTime(&v0);

if (v0.hour >= 24) {
v0.hour %= 24;
Expand Down Expand Up @@ -398,7 +398,7 @@ static BOOL ov45_02256664 (UnkStruct_ov45_022561D4 * param0)
static void ov45_02256668 (UnkStruct_ov45_022561D4 * param0)
{
if (param0->unk_2C == 0) {
sub_02013880(&(param0->unk_20));
GetCurrentTime(&(param0->unk_20));
param0->unk_30 = 1;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/overlay050/ov50_022561C0.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "overlay050/struct_ov50_02256510_1.h"

#include "unk_0200D9E8.h"
#include "unk_0201378C.h"
#include "rtc.h"
#include "heap.h"
#include "unk_02056720.h"
#include "overlay025/ov25_02253CE0.h"
Expand Down Expand Up @@ -115,7 +115,7 @@ static BOOL ov50_0225621C (UnkStruct_ov50_022561D4 * param0, UnkStruct_ov25_0225
};
RTCDate v1;

sub_020138A4(&v1);
GetCurrentDate(&v1);
param0->unk_98 = ov25_02254540(param1);
ov50_022562AC(&(param0->unk_04), param0, &v1);

Expand Down
4 changes: 2 additions & 2 deletions src/overlay065/ov65_0222DCE0.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
#include "unk_0200DA60.h"
#include "unk_0200F174.h"
#include "unk_02012744.h"
#include "unk_0201378C.h"
#include "rtc.h"
#include "unk_02013A04.h"
#include "unk_02017728.h"
#include "heap.h"
Expand Down Expand Up @@ -3822,7 +3822,7 @@ static void ov65_02231A0C (void)
ov4_021D2584(0);

if (ov65_02231A54() == 0) {
if (sub_02013948() == 0) {
if (IsNight() == 0) {
v0 = 1085;
} else {
v0 = 1086;
Expand Down
4 changes: 2 additions & 2 deletions src/overlay067/ov67_0225C700.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#include "unk_0200B358.h"
#include "unk_0200DA60.h"
#include "unk_0200F174.h"
#include "unk_0201378C.h"
#include "rtc.h"
#include "unk_02017728.h"
#include "heap.h"
#include "unk_02018340.h"
Expand Down Expand Up @@ -286,7 +286,7 @@ int ov67_0225C820 (UnkStruct_020067E8 * param0, int * param1)
}

{
v1->unk_0C->unk_00 = sub_020138EC();
v1->unk_0C->unk_00 = GetTimestamp();
}

v1->unk_10 = 1;
Expand Down
4 changes: 2 additions & 2 deletions src/overlay077/ov77_021D6C70.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "spl.h"

#include "unk_0200762C.h"
#include "unk_0201378C.h"
#include "rtc.h"
#include "unk_02014000.h"
#include "heap.h"
#include "unk_02020020.h"
Expand Down Expand Up @@ -120,7 +120,7 @@ void ov77_021D6CFC (UnkStruct_ov77_021D6CFC * param0)
int v6, v7;
RTCTime v8;

sub_02013880(&v8);
GetCurrentTime(&v8);

v6 = (v8.hour * v8.minute + v8.second) & 1;
v7 = v8.second % 3;
Expand Down
4 changes: 2 additions & 2 deletions src/overlay088/ov88_0223B140.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
#include "unk_0200DA60.h"
#include "unk_0200F174.h"
#include "unk_020131EC.h"
#include "unk_0201378C.h"
#include "rtc.h"
#include "unk_02013A04.h"
#include "unk_02017728.h"
#include "heap.h"
Expand Down Expand Up @@ -336,7 +336,7 @@ int ov88_0223B140 (UnkStruct_020067E8 * param0, int * param1)
sub_02038A1C(26, v0->unk_174);
sub_02039734();

if (sub_02013948() == 0) {
if (IsNight() == 0) {
sub_02004550(4, 1085, 1);
sub_02004A84(1085);
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/overlay097/ov97_0222C174.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#include "unk_0200B29C.h"
#include "unk_0200B358.h"
#include "unk_0200DA60.h"
#include "unk_0201378C.h"
#include "rtc.h"
#include "heap.h"
#include "unk_02018340.h"
#include "unk_0201D670.h"
Expand Down Expand Up @@ -840,7 +840,7 @@ static void ov97_0222C974 (UnkStruct_ov97_0222C388 * param0)
v4->unk_34A[1] = 0;
v4->unk_34A[2] = 0;
v4->unk_350 = 0;
sub_020138A4(&v0);
GetCurrentDate(&v0);
v4->unk_354 = RTC_ConvertDateToDay(&v0);

sub_0200B3F0(v2);
Expand Down
Loading

0 comments on commit e86e0df

Please sign in to comment.