sm64

A Super Mario 64 decompilation
Log | Files | Refs | README | LICENSE

save_file.h (5739B)


      1 #ifndef SAVE_FILE_H
      2 #define SAVE_FILE_H
      3 
      4 #include <PR/ultratypes.h>
      5 
      6 #include "types.h"
      7 #include "area.h"
      8 
      9 #include "course_table.h"
     10 
     11 #define EEPROM_SIZE 0x200
     12 #define NUM_SAVE_FILES 4
     13 
     14 struct SaveBlockSignature {
     15     u16 magic;
     16     u16 chksum;
     17 };
     18 
     19 struct SaveFile {
     20     // Location of lost cap.
     21     // Note: the coordinates get set, but are never actually used, since the
     22     // cap can always be found in a fixed spot within the course
     23     u8 capLevel;
     24     u8 capArea;
     25     Vec3s capPos;
     26 
     27     u32 flags;
     28 
     29     // Star flags for each course.
     30     // The most significant bit of the byte *following* each course is set if the
     31     // cannon is open.
     32     u8 courseStars[COURSE_COUNT];
     33 
     34     u8 courseCoinScores[COURSE_STAGES_COUNT];
     35 
     36     struct SaveBlockSignature signature;
     37 };
     38 
     39 enum SaveFileIndex {
     40     SAVE_FILE_A,
     41     SAVE_FILE_B,
     42     SAVE_FILE_C,
     43     SAVE_FILE_D
     44 };
     45 
     46 struct MainMenuSaveData {
     47     // Each save file has a 2 bit "age" for each course. The higher this value,
     48     // the older the high score is. This is used for tie-breaking when displaying
     49     // on the high score screen.
     50     u32 coinScoreAges[NUM_SAVE_FILES];
     51     u16 soundMode;
     52 
     53 #ifdef VERSION_EU
     54     u16 language;
     55 #define SUBTRAHEND 8
     56 #else
     57 #define SUBTRAHEND 6
     58 #endif
     59 
     60     // Pad to match the EEPROM size of 0x200 (10 bytes on JP/US, 8 bytes on EU)
     61     u8 filler[EEPROM_SIZE / 2 - SUBTRAHEND - NUM_SAVE_FILES * (4 + sizeof(struct SaveFile))];
     62 
     63     struct SaveBlockSignature signature;
     64 };
     65 
     66 struct SaveBuffer {
     67     // Each of the four save files has two copies. If one is bad, the other is used as a backup.
     68     struct SaveFile files[NUM_SAVE_FILES][2];
     69     // The main menu data has two copies. If one is bad, the other is used as a backup.
     70     struct MainMenuSaveData menuData[2];
     71 };
     72 
     73 extern u8 gLastCompletedCourseNum;
     74 extern u8 gLastCompletedStarNum;
     75 extern s8 sUnusedGotGlobalCoinHiScore;
     76 extern u8 gGotFileCoinHiScore;
     77 extern u8 gCurrCourseStarFlags;
     78 extern u8 gSpecialTripleJump;
     79 extern s8 gLevelToCourseNumTable[];
     80 
     81 // game progress flags
     82 #define SAVE_FLAG_FILE_EXISTS            /* 0x00000001 */ (1 << 0)
     83 #define SAVE_FLAG_HAVE_WING_CAP          /* 0x00000002 */ (1 << 1)
     84 #define SAVE_FLAG_HAVE_METAL_CAP         /* 0x00000004 */ (1 << 2)
     85 #define SAVE_FLAG_HAVE_VANISH_CAP        /* 0x00000008 */ (1 << 3)
     86 #define SAVE_FLAG_HAVE_KEY_1             /* 0x00000010 */ (1 << 4)
     87 #define SAVE_FLAG_HAVE_KEY_2             /* 0x00000020 */ (1 << 5)
     88 #define SAVE_FLAG_UNLOCKED_BASEMENT_DOOR /* 0x00000040 */ (1 << 6)
     89 #define SAVE_FLAG_UNLOCKED_UPSTAIRS_DOOR /* 0x00000080 */ (1 << 7)
     90 #define SAVE_FLAG_DDD_MOVED_BACK         /* 0x00000100 */ (1 << 8)
     91 #define SAVE_FLAG_MOAT_DRAINED           /* 0x00000200 */ (1 << 9)
     92 #define SAVE_FLAG_UNLOCKED_PSS_DOOR      /* 0x00000400 */ (1 << 10)
     93 #define SAVE_FLAG_UNLOCKED_WF_DOOR       /* 0x00000800 */ (1 << 11)
     94 #define SAVE_FLAG_UNLOCKED_CCM_DOOR      /* 0x00001000 */ (1 << 12)
     95 #define SAVE_FLAG_UNLOCKED_JRB_DOOR      /* 0x00002000 */ (1 << 13)
     96 #define SAVE_FLAG_UNLOCKED_BITDW_DOOR    /* 0x00004000 */ (1 << 14)
     97 #define SAVE_FLAG_UNLOCKED_BITFS_DOOR    /* 0x00008000 */ (1 << 15)
     98 #define SAVE_FLAG_CAP_ON_GROUND          /* 0x00010000 */ (1 << 16)
     99 #define SAVE_FLAG_CAP_ON_KLEPTO          /* 0x00020000 */ (1 << 17)
    100 #define SAVE_FLAG_CAP_ON_UKIKI           /* 0x00040000 */ (1 << 18)
    101 #define SAVE_FLAG_CAP_ON_MR_BLIZZARD     /* 0x00080000 */ (1 << 19)
    102 #define SAVE_FLAG_UNLOCKED_50_STAR_DOOR  /* 0x00100000 */ (1 << 20)
    103 #define SAVE_FLAG_COLLECTED_TOAD_STAR_1  /* 0x01000000 */ (1 << 24)
    104 #define SAVE_FLAG_COLLECTED_TOAD_STAR_2  /* 0x02000000 */ (1 << 25)
    105 #define SAVE_FLAG_COLLECTED_TOAD_STAR_3  /* 0x04000000 */ (1 << 26)
    106 #define SAVE_FLAG_COLLECTED_MIPS_STAR_1  /* 0x08000000 */ (1 << 27)
    107 #define SAVE_FLAG_COLLECTED_MIPS_STAR_2  /* 0x10000000 */ (1 << 28)
    108 
    109 #define SAVE_FLAG_TO_STAR_FLAG(cmd) (((cmd) >> 24) & 0x7F)
    110 #define STAR_FLAG_TO_SAVE_FLAG(cmd) ((cmd) << 24)
    111 
    112 // Variable for setting a warp checkpoint.
    113 
    114 // possibly a WarpDest struct where arg is a union. TODO: Check?
    115 struct WarpCheckpoint {
    116     /*0x00*/ u8 actNum;
    117     /*0x01*/ u8 courseNum;
    118     /*0x02*/ u8 levelID;
    119     /*0x03*/ u8 areaNum;
    120     /*0x04*/ u8 warpNode;
    121 };
    122 
    123 extern struct WarpCheckpoint gWarpCheckpoint;
    124 
    125 extern s8 gMainMenuDataModified;
    126 extern s8 gSaveFileModified;
    127 
    128 void save_file_do_save(s32 fileIndex);
    129 void save_file_erase(s32 fileIndex);
    130 BAD_RETURN(s32) save_file_copy(s32 srcFileIndex, s32 destFileIndex);
    131 void save_file_load_all(void);
    132 void save_file_reload(void);
    133 void save_file_collect_star_or_key(s16 coinScore, s16 starIndex);
    134 s32 save_file_exists(s32 fileIndex);
    135 u32 save_file_get_max_coin_score(s32 courseIndex);
    136 s32 save_file_get_course_star_count(s32 fileIndex, s32 courseIndex);
    137 s32 save_file_get_total_star_count(s32 fileIndex, s32 minCourse, s32 maxCourse);
    138 void save_file_set_flags(u32 flags);
    139 void save_file_clear_flags(u32 flags);
    140 u32 save_file_get_flags(void);
    141 u32 save_file_get_star_flags(s32 fileIndex, s32 courseIndex);
    142 void save_file_set_star_flags(s32 fileIndex, s32 courseIndex, u32 starFlags);
    143 s32 save_file_get_course_coin_score(s32 fileIndex, s32 courseIndex);
    144 s32 save_file_is_cannon_unlocked(void);
    145 void save_file_set_cannon_unlocked(void);
    146 void save_file_set_cap_pos(s16 x, s16 y, s16 z);
    147 s32 save_file_get_cap_pos(Vec3s capPos);
    148 void save_file_set_sound_mode(u16 mode);
    149 u16 save_file_get_sound_mode(void);
    150 void save_file_move_cap_to_default_location(void);
    151 
    152 void disable_warp_checkpoint(void);
    153 void check_if_should_set_warp_checkpoint(struct WarpNode *warpNode);
    154 s32 check_warp_checkpoint(struct WarpNode *warpNode);
    155 
    156 #ifdef VERSION_EU
    157 enum EuLanguages {
    158     LANGUAGE_ENGLISH,
    159     LANGUAGE_FRENCH,
    160     LANGUAGE_GERMAN
    161 };
    162 
    163 void eu_set_language(u16 language);
    164 u16 eu_get_language(void);
    165 #endif
    166 
    167 #endif // SAVE_FILE_H