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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
|
#include "global.h"
#include "MI_memory.h"
#include "pokemon.h"
#include "poketch.h"
#pragma thumb on
extern u16 BoxMon_GetAlternateForme(struct BoxPokemon * mon);
static const u8 sMarkingMapInitialPos[][2] = {
{ 0x68, 0x98 },
{ 0x78, 0x98 },
{ 0x88, 0x98 },
{ 0x98, 0x98 },
{ 0xA8, 0x98 },
{ 0xB8, 0x98 },
};
u32 Sav2_Poketch_sizeof(void)
{
return sizeof(struct SavePoketch);
}
void Sav2_Poketch_init(struct SavePoketch * poketch)
{
int i;
for (i = 0; i < 32; i++)
{
poketch->unlockedApps[i] = 0;
}
poketch->numApps = 0;
poketch->selectedApp = 0;
poketch->isGiven = 0;
poketch->color = 0;
poketch->pedometerActive = 0;
poketch->stepCounter = 0;
poketch->alarmActive = 0;
poketch->alarmHour = 0;
poketch->alarmMinute = 0;
poketch->calendarMonth = 1; // January
poketch->calendarFlags = 0;
for (i = 0; i < 6; i++)
{
poketch->markingMapPos[i][0] = sMarkingMapInitialPos[i][0];
poketch->markingMapPos[i][1] = sMarkingMapInitialPos[i][1];
}
for (i = 0; i < 12; i++)
{
poketch->pokemonHistory[i][0] = SPECIES_NONE;
poketch->pokemonHistory[i][1] = 0;
}
poketch->dotArtistEnabled = 0;
Sav2_Poketch_UnlockApp(poketch, POKETCH_DIGITAL_WATCH);
}
void Sav2_Poketch_Give(struct SavePoketch * poketch)
{
poketch->isGiven = TRUE;
}
BOOL Sav2_Poketch_IsGiven(struct SavePoketch * poketch)
{
return poketch->isGiven;
}
u8 Sav2_Poketch_AppIsUnlocked(struct SavePoketch * poketch, PoketchApp app)
{
return poketch->unlockedApps[app];
}
BOOL Sav2_Poketch_UnlockApp(struct SavePoketch * poketch, PoketchApp app)
{
GF_ASSERT(app >= FIRST_POKETCH_APP_ID && app < NUM_POKETCH_APPS);
if (poketch->numApps < NUM_POKETCH_APPS && !poketch->unlockedApps[app])
{
poketch->unlockedApps[app] = TRUE;
poketch->numApps++;
if (app == POKETCH_PEDOMETER) // pedometer
{
poketch->pedometerActive = TRUE;
}
return TRUE;
}
return FALSE;
}
PoketchApp Sav2_Poketch_GetSelectedApp(struct SavePoketch * poketch)
{
return (PoketchApp)poketch->selectedApp;
}
PoketchApp Sav2_Poketch_CycleNextApp(struct SavePoketch * poketch)
{
PoketchApp app = (PoketchApp)poketch->selectedApp;
PoketchApp prev = app;
while (1)
{
if (++app >= NUM_POKETCH_APPS)
app = FIRST_POKETCH_APP_ID;
if (app == prev)
break;
if (poketch->unlockedApps[app])
break;
}
poketch->selectedApp = (s8)app;
return (PoketchApp)poketch->selectedApp;
}
u8 Sav2_Poketch_GetScreenTint(struct SavePoketch * poketch)
{
GF_ASSERT(poketch != NULL);
return poketch->color;
}
void Sav2_Poketch_SetScreenTint(struct SavePoketch * poketch, u32 color)
{
GF_ASSERT(poketch != NULL);
GF_ASSERT(color < 8);
poketch->color = (u8)color;
}
u32 Sav2_Poketch_GetStepCounter(struct SavePoketch * poketch)
{
return poketch->stepCounter;
}
void Sav2_Poketch_SetStepCounter(struct SavePoketch * poketch, u32 steps)
{
if (poketch->pedometerActive)
poketch->stepCounter = steps;
}
BOOL Sav2_Poketch_GetAlarmState(struct SavePoketch * poketch)
{
return poketch->alarmActive;
}
void Sav2_Poketch_GetAlarmSetTime(struct SavePoketch * poketch, u32 * hour_p, u32 * min_p)
{
*hour_p = poketch->alarmHour;
*min_p = poketch->alarmMinute;
}
void Sav2_Poketch_SetAlarm(struct SavePoketch * poketch, BOOL enabled, u32 hour, u32 minute)
{
poketch->alarmActive = enabled;
poketch->alarmHour = hour;
poketch->alarmMinute = minute;
}
void Sav2_Poketch_CalendarDateHighlight(struct SavePoketch * poketch, u32 month, u32 day)
{
if (poketch->calendarMonth == month)
{
poketch->calendarFlags |= (1u << (day - 1));
}
else
{
poketch->calendarMonth = (u8)month;
poketch->calendarFlags = (1u << (day - 1));
}
}
void Sav2_Poketch_CalendarDateUnhighlight(struct SavePoketch * poketch, u32 month, u32 day)
{
if (poketch->calendarMonth == month)
{
poketch->calendarFlags &= ~(1u << (day - 1));
}
else
{
poketch->calendarMonth = (u8)month;
poketch->calendarFlags = 0;
}
}
BOOL Sav2_Poketch_CalendarDateIsHighlighted(struct SavePoketch * poketch, u32 month, u32 day)
{
if (poketch->calendarMonth == month)
{
return (BOOL)((poketch->calendarFlags >> (day - 1)) & 1);
}
else
{
return FALSE;
}
}
void Sav2_Poketch_MarkingMapSetPos(struct SavePoketch * poketch, s32 mark, u8 x, u8 y)
{
GF_ASSERT(mark < 6);
poketch->markingMapPos[mark][0] = x;
poketch->markingMapPos[mark][1] = y;
}
void Sav2_Poketch_MarkingMapGetPos(struct SavePoketch * poketch, s32 mark, u8 * x_p, u8 * y_p)
{
GF_ASSERT(mark < 6);
*x_p = poketch->markingMapPos[mark][0];
*y_p = poketch->markingMapPos[mark][1];
}
u32 Sav2_Poketch_DotArtistIsEnabled(struct SavePoketch * poketch)
{
return poketch->dotArtistEnabled;
}
void Sav2_Poketch_DotArtistGetDrawing(struct SavePoketch * poketch, void * grid)
{
if (poketch->dotArtistEnabled)
{
MI_CpuCopy8(poketch->dotArtistGrid, grid, DOT_ARTIST_SIZE);
}
}
void Sav2_Poketch_DotArtistSetDrawingAndEnable(struct SavePoketch * poketch, void * grid)
{
MI_CpuCopy8(grid, poketch->dotArtistGrid, DOT_ARTIST_SIZE);
poketch->dotArtistEnabled = TRUE;
}
void Sav2_Poketch_PokemonHistoryAddMon(struct SavePoketch * poketch, struct BoxPokemon * mon)
{
int i = Sav2_Poketch_PokemonHistoryGetFirstEmptySlot(poketch);
if (i >= 12)
{
for (i = 0; i < 11; i++)
{
poketch->pokemonHistory[i][0] = poketch->pokemonHistory[i + 1][0];
poketch->pokemonHistory[i][1] = poketch->pokemonHistory[i + 1][1];
}
i = 11;
}
poketch->pokemonHistory[i][0] = (u16)GetBoxMonData(mon, MON_DATA_SPECIES, NULL);
poketch->pokemonHistory[i][1] = BoxMon_GetAlternateForme(mon);
}
int Sav2_Poketch_PokemonHistoryGetFirstEmptySlot(struct SavePoketch * poketch)
{
int i;
for (i = 0; i < 12; i++)
{
if (poketch->pokemonHistory[i][0] == SPECIES_NONE)
return i;
}
return i;
}
void Sav2_Poketch_PokemonHistoryGetSlotN(struct SavePoketch * poketch, s32 i, u32 * species_p, u32 * forme_p)
{
GF_ASSERT(i < 12);
GF_ASSERT(poketch->pokemonHistory[i][0] != SPECIES_NONE);
*species_p = poketch->pokemonHistory[i][0];
*forme_p = poketch->pokemonHistory[i][1];
}
struct SavePoketch * Sav2_Poketch_get(struct SaveBlock2 * sav2)
{
return (struct SavePoketch *)SavArray_get(sav2, 5);
}
|