Super Mario 64 Source
A Super Mario 64 decompilation, brought to you by a bunch of clever folks.
save_file.h
Go to the documentation of this file.
1 #ifndef _SAVE_FILE_H_
2 #define _SAVE_FILE_H_
3 
4 #include "types.h"
5 #include "area.h"
6 
7 #define EEPROM_SIZE 0x200
8 #define NUM_SAVE_FILES 4
9 
11 {
14 };
15 
16 struct SaveFile
17 {
18  // Location of lost cap.
19  // Note: the coordinates get set, but are never actually used, since the
20  // cap can always be found in a fixed spot within the course
24 
26 
27  // Star flags for each course.
28  // The most significant bit of the byte *following* each course is set if the
29  // cannon is open.
30  u8 courseStars[COURSE_COUNT];
31 
32  u8 courseCoinScores[COURSE_STAGES_COUNT];
33 
34  struct SaveBlockSignature signature;
35 };
36 
38 {
39  // Each save file has a 2 bit "age" for each course. The higher this value,
40  // the older the high score is. This is used for tie-breaking when displaying
41  // on the high score screen.
42  u32 coinScoreAges[NUM_SAVE_FILES];
44 
45 #ifdef VERSION_EU
46  u16 language;
47 #define SUBTRAHEND 8
48 #else
49 #define SUBTRAHEND 6
50 #endif
51 
52  // Pad to match the EEPROM size of 0x200 (10 bytes on JP/US, 8 bytes on EU)
53  u8 filler[EEPROM_SIZE / 2 - SUBTRAHEND - NUM_SAVE_FILES * (4 + sizeof(struct SaveFile))];
54 
55  struct SaveBlockSignature signature;
56 };
57 
58 struct SaveBuffer
59 {
60  // Each of the four save files has two copies. If one is bad, the other is used as a backup.
61  struct SaveFile files[NUM_SAVE_FILES][2];
62  // The main menu data has two copies. If one is bad, the other is used as a backup.
63  struct MainMenuSaveData menuData[2];
64 };
65 
66 struct WarpNode;
67 
71 extern u8 gGotFileCoinHiScore;
73 extern u8 gSpecialTripleJump;
74 extern s8 gLevelToCourseNumTable[];
75 
76 // game progress flags
77 #define SAVE_FLAG_FILE_EXISTS /* 0x000001 */ (1 << 0)
78 #define SAVE_FLAG_HAVE_WING_CAP /* 0x000002 */ (1 << 1)
79 #define SAVE_FLAG_HAVE_METAL_CAP /* 0x000004 */ (1 << 2)
80 #define SAVE_FLAG_HAVE_VANISH_CAP /* 0x000008 */ (1 << 3)
81 #define SAVE_FLAG_HAVE_KEY_1 /* 0x000010 */ (1 << 4)
82 #define SAVE_FLAG_HAVE_KEY_2 /* 0x000020 */ (1 << 5)
83 #define SAVE_FLAG_UNLOCKED_BASEMENT_DOOR /* 0x000040 */ (1 << 6)
84 #define SAVE_FLAG_UNLOCKED_UPSTAIRS_DOOR /* 0x000080 */ (1 << 7)
85 #define SAVE_FLAG_DDD_MOVED_BACK /* 0x000100 */ (1 << 8)
86 #define SAVE_FLAG_MOAT_DRAINED /* 0x000200 */ (1 << 9)
87 #define SAVE_FLAG_UNLOCKED_PSS_DOOR /* 0x000400 */ (1 << 10)
88 #define SAVE_FLAG_UNLOCKED_WF_DOOR /* 0x000800 */ (1 << 11)
89 #define SAVE_FLAG_UNLOCKED_CCM_DOOR /* 0x001000 */ (1 << 12)
90 #define SAVE_FLAG_UNLOCKED_JRB_DOOR /* 0x002000 */ (1 << 13)
91 #define SAVE_FLAG_UNLOCKED_BITDW_DOOR /* 0x004000 */ (1 << 14)
92 #define SAVE_FLAG_UNLOCKED_BITFS_DOOR /* 0x008000 */ (1 << 15)
93 #define SAVE_FLAG_CAP_ON_GROUND /* 0x010000 */ (1 << 16)
94 #define SAVE_FLAG_CAP_ON_KLEPTO /* 0x020000 */ (1 << 17)
95 #define SAVE_FLAG_CAP_ON_UKIKI /* 0x040000 */ (1 << 18)
96 #define SAVE_FLAG_CAP_ON_MR_BLIZZARD /* 0x080000 */ (1 << 19)
97 #define SAVE_FLAG_UNLOCKED_50_STAR_DOOR /* 0x100000 */ (1 << 20)
98 
99 // Variable for setting a warp checkpoint.
100 
101 // possibly a WarpDest struct where arg is a union. TODO: Check?
103  /*0x00*/ u8 actNum;
104  /*0x01*/ u8 courseNum;
105  /*0x02*/ u8 levelID;
106  /*0x03*/ u8 areaNum;
107  /*0x04*/ u8 warpNode;
108 };
109 
110 extern struct WarpCheckpoint gWarpCheckpoint;
111 
113 extern s8 gSaveFileModified;
114 
115 void save_file_do_save(s32 fileIndex);
116 void save_file_erase(s32 fileIndex);
117 void save_file_copy(s32 srcFileIndex, s32 destFileIndex);
118 void save_file_load_all(void);
119 void save_file_reload(void);
120 void save_file_collect_star_or_key(s16 coinScore, s16 starIndex);
121 s32 save_file_exists(s32 fileIndex);
123 s32 save_file_get_course_star_count(s32 fileIndex, s32 courseIndex);
124 s32 save_file_get_total_star_count(s32 fileIndex, s32 minCourse, s32 maxCourse);
125 void save_file_set_flags(s32 flags);
126 void save_file_clear_flags(s32 flags);
128 s32 save_file_get_star_flags(s32 fileIndex, s32 courseIndex);
129 void save_file_set_star_flags(s32 fileIndex, s32 courseIndex, s32 starFlags);
130 s32 save_file_get_course_coin_score(s32 fileIndex, s32 courseIndex);
133 void save_file_set_cap_pos(s16 x, s16 y, s16 z);
135 void save_file_set_sound_mode(u16 mode);
138 
139 void disable_warp_checkpoint(void);
142 
143 #ifdef VERSION_EU
144 #define LANGUAGE_ENGLISH 0
145 #define LANGUAGE_FRENCH 1
146 #define LANGUAGE_GERMAN 2
147 
148 void eu_set_language(u16 language);
149 u16 eu_get_language(void);
150 #endif
151 
152 #endif
void save_file_erase(s32 fileIndex)
Definition: save_file.c:289
Definition: save_file.h:16
void save_file_set_star_flags(s32 fileIndex, s32 courseIndex, s32 starFlags)
Add to the bitset of obtained stars in the specified course.
Definition: save_file.c:519
s32 save_file_get_cap_pos(Vec3s capPos)
Definition: save_file.c:558
signed char s8
Definition: ultratypes.h:11
void save_file_collect_star_or_key(s16 coinScore, s16 starIndex)
Update the current save file after collecting a star or a key.
Definition: save_file.c:380
unsigned short int u16
Definition: ultratypes.h:14
Definition: save_file.h:37
s32 save_file_get_star_flags(s32 fileIndex, s32 courseIndex)
Return the bitset of obtained stars in the specified course.
Definition: save_file.c:504
s32 save_file_exists(s32 fileIndex)
Definition: save_file.c:429
signed short int s16
Definition: ultratypes.h:13
void save_file_copy(s32 srcFileIndex, s32 destFileIndex)
Definition: save_file.c:297
u32 save_file_get_max_coin_score(s32 courseIndex)
Get the maximum coin score across all files for a course.
Definition: save_file.c:438
void save_file_set_flags(s32 flags)
Definition: save_file.c:483
Definition: save_file.h:58
u8 capLevel
Definition: save_file.h:21
s8 gSaveFileModified
Definition: save_file.c:22
void save_file_reload(void)
Reload the current save file from its backup copy, which is effectively a a cached copy of what has b...
Definition: save_file.c:364
void save_file_set_cannon_unlocked(void)
Sets the cannon status to unlocked in the current course.
Definition: save_file.c:543
u8 gSpecialTripleJump
Definition: save_file.c:30
u8 gGotFileCoinHiScore
Definition: save_file.c:27
void save_file_clear_flags(s32 flags)
Definition: save_file.c:488
s32 check_warp_checkpoint(struct WarpNode *a)
Checks to see if a checkpoint is properly active or not.
Definition: save_file.c:636
u16 save_file_get_sound_mode(void)
Definition: save_file.c:578
s16 Vec3s[3]
Definition: types.h:24
#define SUBTRAHEND
Definition: save_file.h:49
u8 actNum
Definition: save_file.h:103
#define EEPROM_SIZE
Definition: save_file.h:7
u8 courseNum
Definition: save_file.h:104
Definition: area.h:29
u8 levelID
Definition: save_file.h:105
Definition: area.h:95
at end of structure union member declaration In standard C each member declaration must be terminated by a
Definition: err.english.cc:690
Vec3s capPos
Definition: save_file.h:23
Definition: save_file.h:10
#define NUM_SAVE_FILES
Definition: save_file.h:8
u8 areaNum
Definition: save_file.h:106
void check_if_should_set_warp_checkpoint(struct WarpNode *a)
Checks the upper bit of the WarpNode->destLevel byte to see if the game should set a warp checkpoint...
Definition: save_file.c:620
s32 save_file_get_flags(void)
Definition: save_file.c:494
Definition: save_file.h:102
s32 save_file_get_total_star_count(s32 fileIndex, s32 minCourse, s32 maxCourse)
Definition: save_file.c:472
void save_file_set_sound_mode(u16 mode)
Definition: save_file.c:570
void save_file_set_cap_pos(s16 x, s16 y, s16 z)
Definition: save_file.c:549
u16 magic
Definition: save_file.h:12
u8 gLastCompletedStarNum
Definition: save_file.c:25
u32 flags
Definition: save_file.h:25
s8 gMainMenuDataModified
Definition: save_file.c:21
s32 save_file_is_cannon_unlocked(void)
Return TRUE if the cannon is unlocked in the current course.
Definition: save_file.c:536
u8 capArea
Definition: save_file.h:22
u8 gCurrCourseStarFlags
Definition: save_file.c:28
void disable_warp_checkpoint(void)
Definition: save_file.c:611
u16 chksum
Definition: save_file.h:13
s32 save_file_get_course_star_count(s32 fileIndex, s32 courseIndex)
Definition: save_file.c:459
void save_file_move_cap_to_default_location(void)
Definition: save_file.c:582
void save_file_load_all(void)
Definition: save_file.c:308
u8 warpNode
Definition: save_file.h:107
s32 save_file_get_course_coin_score(s32 fileIndex, s32 courseIndex)
Definition: save_file.c:529
unsigned char u8
Definition: ultratypes.h:12
u16 soundMode
Definition: save_file.h:43
u8 gLastCompletedCourseNum
Definition: save_file.c:24
signed int s32
Definition: ultratypes.h:15
struct WarpCheckpoint gWarpCheckpoint
Definition: save_file.c:19
void save_file_do_save(s32 fileIndex)
Definition: save_file.c:270
Definition: area.h:44
s8 gLevelToCourseNumTable[]
Definition: save_file.c:32
unsigned int u32
Definition: ultratypes.h:16
s8 sUnusedGotGlobalCoinHiScore
Definition: save_file.c:26