-
Notifications
You must be signed in to change notification settings - Fork 2
/
save.c
98 lines (90 loc) · 2.45 KB
/
save.c
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
#include "save.h"
#ifndef NO_RAM
u32 dword_030053B0; // 030053B0
// TODO: Correct signatures (instead of (void))
u8 flash_timeout_reached_zero; // 03007410
void (*flash_read_byte_funcptr)(void); // 03007414
void (*flash_c_verify)(void); // 03007418
void (*flash_c_write_block)(void); // 0300741C
void (*flash_c_ptr_metrics)(void); // 03007420
void (*flash_c_fp0)(void); // 03007424
u16 word_3007428; // 03007428
void (*flash_c_erase_all)(void); // 0300742C
void (*flash_c_erase_block)(u8); // 03007430
void (*flash_c_f14)(void); // 03007434
#else
extern u32 dword_030053B0; // 030053B0
#endif
// 0804C1F0
void save_serialize_pokemon() {
struct pokemon_extended *dst = sav1i->party_pokemon;
struct pokemon_extended *src = party_player;
sav1i->num_party_pokemon = party_player_count;
memcpy(dst, src, 6*sizeof(struct pokemon_extended));
}
// 0804C230
void save_deserialize_pokemon() {
struct pokemon_extended *dst = party_player;
struct pokemon_extended *src = sav1i->party_pokemon;
sav1i->num_party_pokemon = party_player_count;
memcpy(dst, src, 6*sizeof(struct pokemon_extended));
}
// 0804C270
void save_serialize_npcs() {
struct npc_state *dst = sav1i->npc_states;
struct npc_state *src = npc_states;
memcpy(dst, src, MAX_NPCS*sizeof(struct npc_state));
}
// 0804C2B8
void save_deserialize_npcs() {
struct npc_state *dst = sav1i->npc_states;
struct npc_state *src = npc_states;
memcpy(dst, src, MAX_NPCS*sizeof(struct npc_state));
}
// 0804C300
void save_serialize_game() {
save_serialize_pokemon();
save_serialize_npcs();
}
// 0804C310
void save_deserialize_game() {
save_deserialize_pokemon();
save_deserialize_npcs();
}
// 080DA248
void save_game(u8 mode) {
// mode:
// 0 normal save
// 4 save newly started game
void *vblank_backup = super.vblank_callback;
super.vblank_callback = NULL;
sub_80DA1D4();
switch (mode) {
case 1:
save_serialize_game();
for (u8 i=0; i<4; i++)
save_write_to_flash(i, &dword_030053B0);
break;
case 2:
save_serialize_game();
save_write_to_flash(0, &dword_030053B0);
break;
case 4:
for (u8 i=0x1C; i<0x20; i++)
(*flash_c_erase_block)(i);
save_serialize_game();
save_write_to_flash(0xFFFF, &dword_030053B0);
break;
case 5:
for (u8 i=0x1C; i<0x20; i++)
(*flash_c_erase_block)(i);
case 3:
if (sub_8054EC4(0xA) <= 0x3E6)
sub_8054E90(0xA);
default:
save_serialize_game();
save_write_to_flash(0xFFFF, &dword_030053B0);
break;
}
super.vblank_callback = vblank_backup;
}