summaryrefslogtreecommitdiff
path: root/arm9/src/sav_system_info.c
blob: 6b532b8df467f32916de1641bac789ac526b8a9f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include "global.h"
#include "save_block_2.h"
#include "MI_memory.h"
#include "OS_ownerInfo.h"
#include "RTC_api.h"
#include "RTC_convert.h"
#include "sav_system_info.h"

#pragma thumb on

extern void GF_RTC_CopyDateTime(RTCDate *, RTCTime *);

u32 Sav2_SysInfo_sizeof(void)
{
    return sizeof(struct SavSysInfo);
}

void Sav2_SysInfo_init(struct SavSysInfo * unk)
{
    MI_CpuClearFast(unk, sizeof(struct SavSysInfo));
    Sav2_SysInfo_RTC_init(&unk->rtcInfo);
}

struct SavSysInfo * Sav2_SysInfo_get(struct SaveBlock2 * sav2)
{
    return (struct SavSysInfo *)SavArray_get(sav2, 0);
}

struct UnkSaveStruct_0202376C_sub * Sav2_SysInfo_RTC_get(struct SaveBlock2 * sav2)
{
    return &Sav2_SysInfo_get(sav2)->rtcInfo;
}

void Sav2_SysInfo_InitFromSystem(struct SavSysInfo * unk)
{
    OSOwnerInfo info;
    unk->rtcOffset = OS_GetOwnerRtcOffset();
    OS_GetMacAddress(unk->macAddr);
    OS_GetOwnerInfo(&info);
    unk->birthMonth = info.birthday.month;
    unk->birthDay = info.birthday.day;
}

BOOL Sav2_SysInfo_MacAddressIsMine(struct SavSysInfo * unk)
{
    u8 macAddr[6];
    OS_GetMacAddress(macAddr);
    for (int i = 0; i < 6; i++)
    {
        if (macAddr[i] != unk->macAddr[i])
            return FALSE;
    }
    return TRUE;
}

BOOL Sav2_SysInfo_RTCOffsetIsMine(struct SavSysInfo * unk)
{
    return OS_GetOwnerRtcOffset() == unk->rtcOffset;
}

u8 Sav2_SysInfo_GetBirthMonth(struct SavSysInfo * unk)
{
    return unk->birthMonth;
}

u8 Sav2_SysInfo_GetBirthDay(struct SavSysInfo * unk)
{
    return unk->birthDay;
}

u8 FUN_02023820(struct SavSysInfo * unk)
{
    return unk->field_48;
}

void FUN_02023828(struct SavSysInfo * unk, u8 val)
{
    unk->field_48 = val;
}

u32 FUN_02023830(struct SavSysInfo * unk)
{
    return unk->field_4C;
}

void FUN_02023834(struct SavSysInfo * unk, u32 val)
{
    if (unk->field_4C == 0)
        unk->field_4C = val;
}

void Sav2_SysInfo_RTC_init(struct UnkSaveStruct_0202376C_sub * sub)
{
    sub->field_00 = 1;
    GF_RTC_CopyDateTime(&sub->date, &sub->time);
    sub->daysSinceNitroEpoch = RTC_ConvertDateToDay(&sub->date);
    sub->secondsSinceNitroEpoch = RTC_ConvertDateTimeToSecond(&sub->date, &sub->time);
    sub->field_2C = 0;
    sub->field_34 = 0;
}

BOOL FUN_02023874(struct UnkSaveStruct_0202376C_sub * sub)
{
    return sub->field_34 != 0;
}

void FUN_02023884(struct UnkSaveStruct_0202376C_sub * sub, u32 a1)
{
    if (sub->field_34 > 1440)
        sub->field_34 = 1440;
    if (sub->field_34 < a1)
        sub->field_34 = 0;
    else
        sub->field_34 -= a1;
}

void FUN_020238A4(struct UnkSaveStruct_0202376C_sub * sub)
{
    sub->field_34 = 1440;
    GF_RTC_CopyDateTime(&sub->date, &sub->time);
    sub->daysSinceNitroEpoch = RTC_ConvertDateToDay(&sub->date);
}