#include #include "platform.h" #if (GAME == 4) // These are needed for the game startup code, which needs to be part of // the same translation unit in this game... #include "pc98.h" #include "libs/kaja/kaja.h" #endif #include "master.hpp" #include "th04/score.h" #if (GAME == 5) #include "th05/resident.hpp" #else #include "th04/resident.hpp" #endif #include "th04/formats/cfg.hpp" extern "C" { #include "th04/snd/snd.h" } #if (GAME == 5) #undef CFG_FN extern const char CFG_FN[]; #endif #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(); }