ReC98/th05/res_kso.cpp

110 lines
2.6 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/* ReC98
* -----
* TH05 ZUN.COM -S. Initializes the resident structure and configuration file
* required in order to run TH05.
*/
#include <ReC98.h>
#include "th01/ranks.h"
#include "th04/score.h"
#include "th04/common.h"
#include "th05/resident.hpp"
#include "th04/snd/snd.h"
#include "th04/formats/cfg.h"
char debug = 0;
const cfg_options_t OPTS_DEFAULT = {
RANK_DEFAULT, CFG_LIVES_DEFAULT, CFG_BOMBS_DEFAULT,
SND_BGM_FM26, SND_SE_FM, true
};
char cfg_init(seg_t resident_sgm)
{
const char *fn = CFG_FN;
cfg_options_t opts = OPTS_DEFAULT;
cfg_t cfg_in;
resident_t far *resident = reinterpret_cast<resident_t far *>(
MK_FP(resident_sgm, 0)
);
if(!file_ropen(fn)) {
recreate:
if(!file_create(fn)) {
return 1;
}
file_write(&opts, sizeof(opts));
resident->rank = RANK_DEFAULT;
resident->cfg_lives = CFG_LIVES_DEFAULT;
resident->cfg_bombs = CFG_BOMBS_DEFAULT;
resident->bgm_mode = SND_BGM_FM26;
resident->se_mode = SND_SE_FM;
resident->turbo_mode = true;
} else {
file_read(&cfg_in, sizeof(cfg_in));
file_close();
if((
cfg_in.opts.rank
+ cfg_in.opts.lives
+ cfg_in.opts.bombs
+ cfg_in.opts.bgm_mode
+ cfg_in.opts.se_mode
+ cfg_in.opts.turbo_mode
) != cfg_in.opts_sum) {
goto recreate;
}
resident->rank = cfg_in.opts.rank;
resident->cfg_lives = cfg_in.opts.lives;
resident->cfg_bombs = cfg_in.opts.bombs;
resident->bgm_mode = cfg_in.opts.bgm_mode;
resident->se_mode = cfg_in.opts.se_mode;
resident->turbo_mode = cfg_in.opts.turbo_mode;
if(resident->cfg_lives > CFG_LIVES_MAX || resident->cfg_lives == 0) {
goto recreate;
}
if(resident->cfg_bombs > CFG_BOMBS_MAX) {
goto recreate;
}
if(resident->bgm_mode >= SND_BGM_MODE_COUNT) {
goto recreate;
}
if(resident->se_mode >= SND_SE_MODE_COUNT) {
goto recreate;
}
if(!file_append(fn)) {
return 1;
}
file_seek(offsetof(cfg_t, resident), 0);
}
if(!file_write(&resident_sgm, sizeof(resident_sgm))) {
return 1;
}
file_write(&debug, sizeof(debug));
// Yes, this is uninitialized if the file didn't exist!
file_write(&cfg_in.opts_sum, sizeof(cfg_in.opts_sum));
file_close();
return 0;
}
#define LOGO \
"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Y<EFBFBD>k<EFBFBD>p<EFBFBD>@ <20><EFBFBD>v<EFBFBD><76><EFBFBD>O<EFBFBD><4F><EFBFBD><EFBFBD><EFBFBD>@ Version1.00 (c)zun 1998"
#define ERROR_NOT_RESIDENT "<22>܂<EFBFBD><DC82><EFBFBD><EFBFBD>܂<EFBFBD><DC82><EFBFBD><EFBFBD>悧"
#define REMOVED "<22><><EFBFBD><EFBFBD>ˁ[<5B>A<EFBFBD>܂<EFBFBD><DC82><EFBFBD><EF82A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"
#define INITIALIZED "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>܂<EFBFBD><DC82>܁[<5B><><EFBFBD>B"
#define RES_INIT_BOTTOM { \
if(cfg_init(sgm)) { \
dos_free(sgm); \
dos_puts2("<22>t<EFBFBD>@<40>C<EFBFBD><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߂Ȃ<DF82><C882>́`\n\n"); \
return 1; \
} \
resident = reinterpret_cast<resident_t far *>(resident_bytes); \
if(debug) { \
resident->debug = true; \
} \
}
inline void optimization_barrier_3() {}
#include "th02/res_init.c"