Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Decompilation] [th04/th05] MIKO.CFG loading and saving
Part of P0261, funded by [Anonymous] and Yanga.
- Loading branch information
Showing
11 changed files
with
134 additions
and
177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#include "th04/formats/cfg.cpp" |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
#include <stddef.h> | ||
#include "platform.h" | ||
#include "master.hpp" | ||
#include "th04/score.h" | ||
#if (GAME == 5) | ||
#include "th04/common.h" | ||
#include "th05/resident.hpp" | ||
#else | ||
#include "th04/resident.hpp" | ||
#endif | ||
#include "th04/formats/cfg.hpp" | ||
#include "th04/snd/snd.h" | ||
|
||
#undef CFG_FN | ||
extern const char CFG_FN[]; | ||
|
||
#if (GAME == 4) | ||
bool snd_sel_disabled = false; // ZUN bloat: Unused in this game. | ||
#endif | ||
|
||
inline void cfg_options_update_from_resident(cfg_options_t &opts) { | ||
opts.rank = resident->rank; | ||
opts.lives = resident->cfg_lives; | ||
opts.bombs = resident->cfg_bombs; | ||
opts.bgm_mode = resident->bgm_mode; | ||
opts.se_mode = resident->se_mode; | ||
opts.turbo_mode = resident->turbo_mode; | ||
} | ||
|
||
void near cfg_load(void) | ||
{ | ||
cfg_t cfg; | ||
|
||
cfg_load_and_set_resident(cfg, CFG_FN); | ||
|
||
// TH05 does this in RES_KSO.COM. | ||
#if (GAME == 4) | ||
resident->rank = cfg.opts.rank; | ||
resident->cfg_lives = cfg.opts.lives; | ||
resident->cfg_bombs = cfg.opts.bombs; | ||
resident->bgm_mode = cfg.opts.bgm_mode; | ||
resident->se_mode = cfg.opts.se_mode; | ||
resident->turbo_mode = cfg.opts.turbo_mode; | ||
#endif | ||
|
||
if((resident->cfg_lives > CFG_LIVES_MAX) || (resident->cfg_lives == 0)) { | ||
resident->cfg_lives = CFG_LIVES_DEFAULT; | ||
} | ||
if(resident->cfg_bombs > CFG_BOMBS_MAX) { | ||
resident->cfg_bombs = CFG_BOMBS_MAX; | ||
} | ||
if(resident->bgm_mode >= SND_BGM_MODE_COUNT) { | ||
resident->bgm_mode = SND_BGM_OFF; | ||
} | ||
if(resident->se_mode >= SND_SE_MODE_COUNT) { | ||
resident->se_mode = SND_SE_OFF; | ||
} | ||
} | ||
|
||
void near cfg_save(void) | ||
{ | ||
union { | ||
int8_t sum; | ||
int16_t space; // ZUN bloat | ||
} u1; | ||
cfg_options_t opts; | ||
|
||
file_append(CFG_FN); // We don't write the full file here! | ||
file_seek(0, SEEK_SET); | ||
|
||
cfg_options_update_from_resident(opts); | ||
file_write(&opts, sizeof(cfg_options_t)); | ||
|
||
// Skip over the resident pointer | ||
file_seek(offsetof(cfg_t, opts_sum), SEEK_SET); | ||
|
||
u1.sum = opts.sum(); | ||
file_write(&u1.sum, sizeof(u1.sum)); | ||
file_close(); | ||
} | ||
|
||
void near cfg_save_exit(void) | ||
{ | ||
#if (GAME == 5) | ||
extern const cfg_t cfg_empty; | ||
cfg_t cfg = cfg_empty; | ||
#else | ||
cfg_t cfg = { 0 }; | ||
#endif | ||
|
||
// ZUN landmine: In contrast to the function above, we do write the entire | ||
// structure here. Since file_append() will fail if the file doesn't exist, | ||
// file_create() would have been safer here. | ||
file_append(CFG_FN); | ||
file_seek(0, SEEK_SET); | ||
|
||
cfg_options_update_from_resident(cfg.opts); | ||
cfg.opts_sum = cfg.opts.sum(); | ||
file_write(&cfg, sizeof(cfg)); | ||
file_close(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#include "th04/formats/cfg.cpp" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
public _cfg_empty, _cfg_fn | ||
public _cfg_empty, _CFG_FN | ||
_cfg_empty cfg_t <0> | ||
_cfg_fn db 'MIKO.CFG',0 | ||
_CFG_FN db 'MIKO.CFG',0 |
Oops, something went wrong.