Save files and the save file menu. More...
Go to the source code of this file.
Macros | |
| #define | SAVE_FILE_COUNT 3 |
| #define | SAVE_RECORD_BYTES 0x1000 |
| #define | SAVE_NO_FREE_FILE 999 |
| #define | SAVE_ERROR_READ -2 |
| a record could not be read | |
| #define | SAVE_ERROR_WRITE -3 |
| Writing failed. "Failed to save." (or "Failed to erase."). | |
| #define | SAVE_ERROR_ERASE -4 |
| erasing failed. "Failed to erase." | |
| #define | SAVE_ERROR_NO_FILE -5 |
| no empty file to copy into | |
| #define | SAVE_ERROR_NO_MEMORY -9 |
| No backup memory. "Unable to detect backup memory.". | |
| #define | SUMMARY_DISTANCE(from, to) |
| The distance in bytes from one field of a save summary to another. | |
| #define | SAVE_MENU_SPRITE_SPACING 3 |
| The save file menu shows the chosen file's party as walking sprites in a row, and four Djinn sprites, one for each element, over the file's Djinn counts. | |
| #define | SAVE_MENU_SPRITE_PRIORITY (200 << 4) |
| Scheduler priority of the callbacks that place the sprites every frame. | |
| #define | SUMMARY_LEVEL_X 72 |
| #define | SUMMARY_COINS_X 48 |
| #define | SUMMARY_DRAW_LEVEL UiText_DrawStringInWindow |
| #define | SAVE_MENU_NO_FILE -2 |
| SaveMenu_SelectSlot's result when no file can be chosen in its mode. | |
Enumerations | |
| enum | SaveMenuMode { SAVE_MENU_SAVE , SAVE_MENU_CONTINUE , SAVE_MENU_COPY , SAVE_MENU_ERASE , SAVE_MENU_EXTRA , SAVE_MENU_CLEARED } |
| What the save file menu is choosing a file for, which decides the files the cursor may stop on. More... | |
Functions | |
| void * | Text_FormatPlayTime (s32 frames, u8 *out) |
| Writes the play time frames (at 60 frames a second) into out as hours and minutes, "hhh:mm" with the hours right-aligned in three characters, and returns out. | |
| u32 | SaveState_FindFreeSummarySlot (void) |
| Returns the first save file whose summary shows it empty (level 0), or SAVE_NO_FREE_FILE when all three are in use. | |
| s32 | SaveState_CountRecordsExcludingFlagged (s32 excludeSent) |
| Returns how many save files there are, leaving out those whose summary has its send flag set when excludeSent is nonzero, or SAVE_ERROR_NO_MEMORY when the backup memory cannot be read. | |
| s32 | SaveState_ScanRecordFlags (void) |
| Loads the save file summaries for the title menu and returns how many files there are: plus 100 when every file has its send flag set, or SAVE_ERROR_NO_MEMORY when the backup memory cannot be read. | |
| u32 | SaveState_BuildSummaryHeader (void) |
| Prepares the save buffer for writing: stamps the game state with the time and options, then fills the file summary shown on the file menus (the leader's name, level and class, the play time, area, coins, Djinn of each element, the party, the send flag and how many of game flags 48-127 are set) and its checksum, the sum of the 968 words from gGameFlagBytes on. | |
| s16 | SaveState_WriteCurrentSlotPair (void) |
| Saves the game to the current file (gSaveSlot): builds the summary and writes both halves of the save buffer. | |
| s32 | SaveState_WriteSlotPair (s32 file) |
| Writes both halves of the save buffer, as they are, to save file file. | |
| s32 | SaveState_ProcessSelectedSlot (void) |
| Writes the 64-byte save stamp (gSaveStamp, which lies in the first half of the save buffer) into the current file's first record, leaving the rest of the record as it was saved. | |
| UNUSED s32 | SaveState_ConfirmAndProcessSelectedSlot (void) |
| Asks whether to save over the current file and, on Yes, writes the save stamp into it (SaveState_ProcessSelectedSlot) and says so. | |
| s32 | SaveState_CopySlotPair (void) |
| The file menu's Copy: lets the player choose a file, reads both of its records into the save buffer and writes them to the first empty file. | |
| s32 | SaveState_DeleteSelectedSlot (void) |
| The file menu's Erase: lets the player choose a file, asks whether to erase it and on Yes deletes both of its records. | |
| void | PaletteGlow_UpdateSine (void) |
| A scheduler callback that makes colours 8-11 of BG palette 14 glow: each follows a sine wave of the frame counter, eight frames behind the one before. | |
| void | PaletteGlow_Start (void) |
| Starts the palette glow (PaletteGlow_UpdateSine) in the scheduler. | |
| void | PaletteGlow_Stop (void) |
| void | UiWindow_FillTilemapRect (struct UiWindow *window, s32 x, s32 y, s32 width, s32 height) |
| Fills the width x height tile rectangle at (x, y) inside window, clipped to the screen as UiWindow_SetTileAttributeBitRect clips, with the blank tile entry 0xe006 of the UI tilemap. | |
| void | SaveMenu_ShowPartySprites (struct UiWindow *window, s32 x, s32 y, struct SaveSummary *summary) |
| Shows the party of save file summary (up to four members) as sprites in a row from tile (x, y) inside window, and starts placing them every frame (SaveMenu_PlacePartySprites). | |
| void | SaveMenu_HidePartySprites (void) |
| Stops placing the party sprites of the save file menu and releases them. | |
| void | SaveMenu_PlacePartySprites (void) |
| A scheduler callback: draws each party sprite of the save file menu at its place and scale for this frame. | |
| void | SaveMenu_ShowDjinnSprites (struct UiWindow *window, s32 x, s32 y) |
| Shows the four Djinn sprites, one for each element, in a row from tile (x, y) inside window, and starts placing them every frame (SaveMenu_PlaceDjinnSprites). | |
| void | SaveMenu_HideDjinnSprites (void) |
| Stops placing the Djinn sprites of the save file menu and releases them. | |
| void | SaveMenu_PlaceDjinnSprites (void) |
| A scheduler callback: draws each Djinn sprite of the save file menu at its place, at scale 1.0, for this frame. | |
| void | SaveMenu_DrawDjinnCounts (struct UiWindow *window, struct SaveSummary *summary) |
| Draws the Djinn counts of save file summary, one for each element, two digits each, 24 pixels apart on row 16 of window, under the Djinn sprites. | |
| void | SaveMenu_DrawFileSummary (struct UiWindow *window, struct SaveSummary *summary) |
| Draws the summary of save file summary into window: the leader's name, level and class, the play time and the coins. | |
| s32 | SaveMenu_SelectSlot (s32 selectedFile, s32 menuMode) |
| s32 | Save_WriteSelectedSlot (void) |
| The Save command: lets the player choose a file (the current one first), asks whether to save over it when it has data, then saves the game to it, object table included, and makes it the current file. | |
| s32 | SaveState_LoadRecordIntoWork (s32 mode) |
| Lets the player choose a file in save menu mode (see SaveMenuMode) and loads it into the save buffer as the current file, restoring its play time and options. | |
| s32 | Resource_LoadFixedBlockBIntoFreeSlot (void) |
| Loads the pointing hand cursor's tiles (gResource_FixedBlockBTiles, 128 bytes) into a free VRAM slot and returns the slot. | |
Save files and the save file menu.
Part of battle_command.c, the menu object, compiled only through it.
Definition in file save.c.
| #define SAVE_FILE_COUNT 3 |
Definition at line 10 of file save.c.
Referenced by Save_WriteSelectedSlot(), SaveMenu_SelectSlot(), SaveState_CopySlotPair(), SaveState_CountRecordsExcludingFlagged(), SaveState_DeleteSelectedSlot(), SaveState_FindFreeSummarySlot(), SaveState_LoadRecordIntoWork(), SaveState_LoadSummaryRecords(), SaveState_ScanRecordFlags(), SaveState_WriteCurrentSlotPair(), and SaveState_WriteSlotPair().
| #define SAVE_RECORD_BYTES 0x1000 |
Definition at line 11 of file save.c.
Referenced by Save_WriteSelectedSlot(), SaveState_CopySlotPair(), SaveState_LoadRecordIntoWork(), SaveState_ProcessSelectedSlot(), SaveState_WriteCurrentSlotPair(), and SaveState_WriteSlotPair().
| #define SAVE_NO_FREE_FILE 999 |
Definition at line 12 of file save.c.
Referenced by SaveState_CopySlotPair(), and SaveState_FindFreeSummarySlot().
| #define SAVE_ERROR_READ -2 |
a record could not be read
Definition at line 15 of file save.c.
Referenced by SaveState_CopySlotPair(), SaveState_LoadRecordIntoWork(), and SaveState_ProcessSelectedSlot().
| #define SAVE_ERROR_WRITE -3 |
Writing failed. "Failed to save." (or "Failed to erase.").
Definition at line 17 of file save.c.
Referenced by Save_WriteSelectedSlot(), SaveState_CopySlotPair(), SaveState_ProcessSelectedSlot(), SaveState_WriteCurrentSlotPair(), and SaveState_WriteSlotPair().
| #define SAVE_ERROR_ERASE -4 |
erasing failed. "Failed to erase."
Definition at line 18 of file save.c.
Referenced by SaveState_DeleteSelectedSlot().
| #define SAVE_ERROR_NO_FILE -5 |
no empty file to copy into
Definition at line 19 of file save.c.
Referenced by SaveState_CopySlotPair().
| #define SAVE_ERROR_NO_MEMORY -9 |
No backup memory. "Unable to detect backup memory.".
Definition at line 21 of file save.c.
Referenced by Save_WriteSelectedSlot(), SaveState_CopySlotPair(), SaveState_CountRecordsExcludingFlagged(), SaveState_DeleteSelectedSlot(), SaveState_LoadRecordIntoWork(), SaveState_ProcessSelectedSlot(), SaveState_ScanRecordFlags(), SaveState_WriteCurrentSlotPair(), and SaveState_WriteSlotPair().
| #define SUMMARY_DISTANCE | ( | from, | |
| to ) |
The distance in bytes from one field of a save summary to another.
Definition at line 102 of file save.c.
Referenced by SaveState_ScanRecordFlags().
| #define SAVE_MENU_SPRITE_SPACING 3 |
The save file menu shows the chosen file's party as walking sprites in a row, and four Djinn sprites, one for each element, over the file's Djinn counts.
Each sprite stands three tiles (24 pixels) from the one before.
Definition at line 588 of file save.c.
Referenced by SaveMenu_DrawDjinnCounts(), SaveMenu_ShowDjinnSprites(), and SaveMenu_ShowPartySprites().
| #define SAVE_MENU_SPRITE_PRIORITY (200 << 4) |
Scheduler priority of the callbacks that place the sprites every frame.
Definition at line 590 of file save.c.
Referenced by SaveMenu_ShowDjinnSprites().
| #define SUMMARY_LEVEL_X 72 |
Definition at line 761 of file save.c.
Referenced by SaveMenu_DrawFileSummary().
| #define SUMMARY_COINS_X 48 |
Definition at line 762 of file save.c.
Referenced by SaveMenu_DrawFileSummary().
| #define SUMMARY_DRAW_LEVEL UiText_DrawStringInWindow |
Definition at line 763 of file save.c.
Referenced by SaveMenu_DrawFileSummary().
| #define SAVE_MENU_NO_FILE -2 |
SaveMenu_SelectSlot's result when no file can be chosen in its mode.
Definition at line 824 of file save.c.
Referenced by SaveMenu_SelectSlot().
| enum SaveMenuMode |
What the save file menu is choosing a file for, which decides the files the cursor may stop on.
Writes the play time frames (at 60 frames a second) into out as hours and minutes, "hhh:mm" with the hours right-aligned in three characters, and returns out.
The time stops at 999:59.
Definition at line 26 of file save.c.
Referenced by SaveMenu_DrawFileSummary(), and Text_FormatPlayTime().
| u32 SaveState_FindFreeSummarySlot | ( | void | ) |
Returns the first save file whose summary shows it empty (level 0), or SAVE_NO_FREE_FILE when all three are in use.
The summaries must be loaded.
Definition at line 65 of file save.c.
Referenced by SaveState_CopySlotPair(), and SaveState_FindFreeSummarySlot().
Returns how many save files there are, leaving out those whose summary has its send flag set when excludeSent is nonzero, or SAVE_ERROR_NO_MEMORY when the backup memory cannot be read.
Definition at line 80 of file save.c.
Referenced by Sanctum_ChooseRestartOption(), and SaveState_CountRecordsExcludingFlagged().
| s32 SaveState_ScanRecordFlags | ( | void | ) |
Loads the save file summaries for the title menu and returns how many files there are: plus 100 when every file has its send flag set, or SAVE_ERROR_NO_MEMORY when the backup memory cannot be read.
Sets gTitleExtraOptionEnabled when a file has any of game flags 48-127 set, and gTitleSendOptionEnabled when a file has its send flag set and R and Left are held.
Definition at line 111 of file save.c.
Referenced by Menu_SelectSaveSlotAction(), SaveMenu_Run(), SaveState_ScanRecordFlags(), and Title_Run().
| u32 SaveState_BuildSummaryHeader | ( | void | ) |
Prepares the save buffer for writing: stamps the game state with the time and options, then fills the file summary shown on the file menus (the leader's name, level and class, the play time, area, coins, Djinn of each element, the party, the send flag and how many of game flags 48-127 are set) and its checksum, the sum of the 968 words from gGameFlagBytes on.
Returns the checksum.
Definition at line 159 of file save.c.
Referenced by Save_WriteSelectedSlot(), SaveState_BuildSummaryHeader(), and SaveState_WriteCurrentSlotPair().
| s16 SaveState_WriteCurrentSlotPair | ( | void | ) |
Saves the game to the current file (gSaveSlot): builds the summary and writes both halves of the save buffer.
Returns 0, gSaveSlot itself (-1) when no file is chosen, or a SAVE_ERROR_* after showing its message.
Definition at line 245 of file save.c.
Referenced by SaveState_WriteCurrentSlotPair().
Writes both halves of the save buffer, as they are, to save file file.
Returns 0, or a SAVE_ERROR_* after showing its message.
Definition at line 281 of file save.c.
Referenced by SaveState_WriteSlotPair().
| s32 SaveState_ProcessSelectedSlot | ( | void | ) |
Writes the 64-byte save stamp (gSaveStamp, which lies in the first half of the save buffer) into the current file's first record, leaving the rest of the record as it was saved.
Returns 0, -1 when no file is chosen, or a SAVE_ERROR_* after showing its message.
Definition at line 308 of file save.c.
Referenced by LinkLobby_SaveBattleResults(), LinkLobby_SaveMonsterBattleResults(), SaveState_ConfirmAndProcessSelectedSlot(), and SaveState_ProcessSelectedSlot().
Asks whether to save over the current file and, on Yes, writes the save stamp into it (SaveState_ProcessSelectedSlot) and says so.
"OK to save over this file?" and "Your game was saved." Returns that result. Nothing calls it.
Definition at line 347 of file save.c.
Referenced by SaveState_ConfirmAndProcessSelectedSlot().
| s32 SaveState_CopySlotPair | ( | void | ) |
The file menu's Copy: lets the player choose a file, reads both of its records into the save buffer and writes them to the first empty file.
Returns 0, -1 when cancelled, or a SAVE_ERROR_* after showing its message (the game says "Failed to erase." both when no file is empty and when the write fails).
Definition at line 377 of file save.c.
Referenced by SaveMenu_Run(), and SaveState_CopySlotPair().
| s32 SaveState_DeleteSelectedSlot | ( | void | ) |
The file menu's Erase: lets the player choose a file, asks whether to erase it and on Yes deletes both of its records.
"OK to erase this?" Returns 0 (also when the player answers No), -1 when cancelled, or a SAVE_ERROR_* after showing its message.
Definition at line 429 of file save.c.
Referenced by SaveMenu_Run(), and SaveState_DeleteSelectedSlot().
| void PaletteGlow_UpdateSine | ( | void | ) |
A scheduler callback that makes colours 8-11 of BG palette 14 glow: each follows a sine wave of the frame counter, eight frames behind the one before.
With s the sine from -1 to 1, the colour is red 22 + 2s, green 16 + s and blue 20 + s (of 31).
Definition at line 473 of file save.c.
Referenced by PaletteGlow_Start(), PaletteGlow_Stop(), and PaletteGlow_UpdateSine().
| void PaletteGlow_Start | ( | void | ) |
Starts the palette glow (PaletteGlow_UpdateSine) in the scheduler.
Definition at line 527 of file save.c.
Referenced by PaletteGlow_Start(), and SaveMenu_SelectSlot().
| void PaletteGlow_Stop | ( | void | ) |
Definition at line 531 of file save.c.
Referenced by PaletteGlow_Stop().
Fills the width x height tile rectangle at (x, y) inside window, clipped to the screen as UiWindow_SetTileAttributeBitRect clips, with the blank tile entry 0xe006 of the UI tilemap.
Definition at line 538 of file save.c.
Referenced by SaveMenu_SelectSlot(), and UiWindow_FillTilemapRect().
| void SaveMenu_ShowPartySprites | ( | struct UiWindow * | window, |
| s32 | x, | ||
| s32 | y, | ||
| struct SaveSummary * | summary ) |
Shows the party of save file summary (up to four members) as sprites in a row from tile (x, y) inside window, and starts placing them every frame (SaveMenu_PlacePartySprites).
Definition at line 595 of file save.c.
Referenced by SaveMenu_SelectSlot(), and SaveMenu_ShowPartySprites().
| void SaveMenu_HidePartySprites | ( | void | ) |
Stops placing the party sprites of the save file menu and releases them.
Definition at line 625 of file save.c.
Referenced by SaveMenu_HidePartySprites(), and SaveMenu_SelectSlot().
| void SaveMenu_PlacePartySprites | ( | void | ) |
A scheduler callback: draws each party sprite of the save file menu at its place and scale for this frame.
Definition at line 640 of file save.c.
Referenced by SaveMenu_HidePartySprites(), SaveMenu_PlacePartySprites(), and SaveMenu_ShowPartySprites().
Shows the four Djinn sprites, one for each element, in a row from tile (x, y) inside window, and starts placing them every frame (SaveMenu_PlaceDjinnSprites).
Does nothing when window is NULL.
Definition at line 669 of file save.c.
Referenced by SaveMenu_SelectSlot(), and SaveMenu_ShowDjinnSprites().
| void SaveMenu_HideDjinnSprites | ( | void | ) |
Stops placing the Djinn sprites of the save file menu and releases them.
Definition at line 696 of file save.c.
Referenced by SaveMenu_HideDjinnSprites(), and SaveMenu_SelectSlot().
| void SaveMenu_PlaceDjinnSprites | ( | void | ) |
A scheduler callback: draws each Djinn sprite of the save file menu at its place, at scale 1.0, for this frame.
Definition at line 711 of file save.c.
Referenced by SaveMenu_HideDjinnSprites(), SaveMenu_PlaceDjinnSprites(), and SaveMenu_ShowDjinnSprites().
| void SaveMenu_DrawDjinnCounts | ( | struct UiWindow * | window, |
| struct SaveSummary * | summary ) |
Draws the Djinn counts of save file summary, one for each element, two digits each, 24 pixels apart on row 16 of window, under the Djinn sprites.
Does nothing when window is NULL.
Definition at line 740 of file save.c.
Referenced by SaveMenu_DrawDjinnCounts(), and SaveMenu_SelectSlot().
| void SaveMenu_DrawFileSummary | ( | struct UiWindow * | window, |
| struct SaveSummary * | summary ) |
Draws the summary of save file summary into window: the leader's name, level and class, the play time and the coins.
Does nothing when window is 0.
Definition at line 769 of file save.c.
Referenced by SaveMenu_DrawFileSummary(), and SaveMenu_SelectSlot().
Definition at line 834 of file save.c.
Referenced by Save_WriteSelectedSlot(), SaveMenu_SelectSlot(), SaveState_CopySlotPair(), SaveState_DeleteSelectedSlot(), and SaveState_LoadRecordIntoWork().
| s32 Save_WriteSelectedSlot | ( | void | ) |
The Save command: lets the player choose a file (the current one first), asks whether to save over it when it has data, then saves the game to it, object table included, and makes it the current file.
The question is "OK to save over this file?" Returns 0 (also when the player answers No), -1 when cancelled, or a SAVE_ERROR_* after showing its message.
Definition at line 1174 of file save.c.
Referenced by Menu_RunWorkspaceResultLoop(), Save_WriteSelectedSlot(), and SaveMenu_Run().
Lets the player choose a file in save menu mode (see SaveMenuMode) and loads it into the save buffer as the current file, restoring its play time and options.
Returns 0, -1 when cancelled, or a SAVE_ERROR_* after showing its message.
Definition at line 1232 of file save.c.
Referenced by SaveMenu_Run(), and SaveState_LoadRecordIntoWork().
| s32 Resource_LoadFixedBlockBIntoFreeSlot | ( | void | ) |
Loads the pointing hand cursor's tiles (gResource_FixedBlockBTiles, 128 bytes) into a free VRAM slot and returns the slot.
Definition at line 1269 of file save.c.
Referenced by Colosso_EnsureMarkerSlot(), and Resource_LoadFixedBlockBIntoFreeSlot().