diff --git a/th02/formats/cfg.h b/th02/formats/cfg.h new file mode 100644 index 00000000..de9d6794 --- /dev/null +++ b/th02/formats/cfg.h @@ -0,0 +1,19 @@ +#pragma option -a1 + +#if GAME == 2 +# define CFG_FN "huuma.cfg" + typedef struct { + int8_t rank; + int8_t bgm_mode; + int8_t bombs; + int8_t lives; + int8_t perf; + } cfg_options_t; +#endif + +typedef struct { + cfg_options_t opts; + void __seg *resident_sgm; + int8_t debug; +} cfg_t; +#pragma option -a. diff --git a/th02/formats/cfg_init.c b/th02/formats/cfg_init.c new file mode 100644 index 00000000..4784bd15 --- /dev/null +++ b/th02/formats/cfg_init.c @@ -0,0 +1,15 @@ +void cfg_init(seg_t resident_sgm) +{ + const char *fn = CFG_FN; + cfg_options_t opts = OPTS_DEFAULT; + int handle = dos_axdx(0x3D02, fn); + if(handle > 0) { + dos_seek(handle, sizeof(opts), SEEK_SET); + } else { + handle = dos_create(fn, _A_ARCH); + dos_write(handle, &opts, sizeof(opts)); + } + dos_write(handle, &resident_sgm, sizeof(resident_sgm)); + dos_write(handle, &debug, sizeof(debug)); + dos_close(handle); +} diff --git a/th02/maine_03.c b/th02/maine_03.c index b0be002b..e0d12bfe 100644 --- a/th02/maine_03.c +++ b/th02/maine_03.c @@ -4,6 +4,7 @@ */ #include "th02\th02.h" +#include "th02/formats/cfg.h" char rank = RANK_NORMAL; char unused_1 = 0; @@ -23,7 +24,7 @@ int pascal cfg_load(void) seg_t resident_sgm; file_ropen(CFG_FN); - file_seek(offsetof(huuma_cfg_t, resident_sgm), 0); + file_seek(offsetof(cfg_t, resident_sgm), 0); file_read(&resident_sgm, sizeof(resident_sgm)); file_close(); if(!resident_sgm) { diff --git a/th02/op_01.c b/th02/op_01.c index cfef792c..1d54bed4 100644 --- a/th02/op_01.c +++ b/th02/op_01.c @@ -7,6 +7,7 @@ #include "libs/kaja/kaja.h" #include "th02/th02.h" #include "th02/initexit.h" +#include "th02/formats/cfg.h" #include "th02/formats/pi.h" #include "th02/snd/snd.h" @@ -40,7 +41,7 @@ void pascal musicroom(void); int cfg_load(void) { - huuma_cfg_t cfg; + cfg_t cfg; const char *cfg_fn = CFG_FN; if(file_exist(cfg_fn)) { @@ -77,7 +78,7 @@ int cfg_load(void) void cfg_save(void) { const char *cfg_fn = CFG_FN; - huuma_cfg_t cfg; + cfg_t cfg; cfg.debug = 0; cfg.opts.rank = rank; @@ -87,7 +88,7 @@ void cfg_save(void) cfg.opts.perf = resident->perf; file_create(cfg_fn); - file_write(&cfg, offsetof(huuma_cfg_t, resident_sgm)); + file_write(&cfg, offsetof(cfg_t, resident_sgm)); file_write(&resident_sgm, sizeof(resident_sgm)); file_write(&cfg.debug, sizeof(cfg.debug)); file_close(); diff --git a/th02/res_init.c b/th02/res_init.c new file mode 100644 index 00000000..3fb58de7 --- /dev/null +++ b/th02/res_init.c @@ -0,0 +1,51 @@ +int main(int argc, const char **argv) +{ + seg_t sgm; + const char *res_id = RES_ID; + int i; + char far *resident_bytes; + + sgm = resdata_exist(res_id, RES_ID_STRLEN, RES_PARASIZE); + dos_puts2("\n\n" LOGO "\n"); + graph_clear(); +#ifdef RES_INIT_TOP + RES_INIT_TOP; +#endif + if(argc == 2) { + #define arg1_is(capital, small) \ + (argv[1][0] == '-' || argv[1][0] == '/') \ + && (argv[1][1] == (capital) || argv[1][1] == (small)) + if(arg1_is('R', 'r')) { + if(!sgm) { + dos_puts2("わたし、まだいませんよぉ\n\n"); + return 1; + } + dos_free(sgm); + dos_puts2("さよなら、また会えたらいいな\n\n"); + return 0; + } else if(arg1_is('D', 'd')) { + debug = 1; + } else { + dos_puts2("そんなオプション付けられても、困るんですけど\n\n"); + sgm = sgm; /* optimization barrier #1 */ + return 1; + } + } + if(sgm) { + dos_puts2("わたし、すでにいますよぉ\n\n"); + argv = argv; /* optimization barrier #2 */ + return 1; + } + sgm = resdata_create(res_id, RES_ID_STRLEN, RES_PARASIZE); + if(!sgm) { + dos_puts2("作れません、わたしの居場所がないの!\n\n"); + return 1; + } + resident_bytes = MK_FP(sgm, 0); + dos_puts2("それでは、よろしくお願いします\n\n"); + for(i = (RES_ID_STRLEN + 1); i < sizeof(resident_t); i++) { + resident_bytes[i] = 0; + } + cfg_init(sgm); + return 0; +} diff --git a/th02/th02.h b/th02/th02.h index c30c935f..10370b6a 100644 --- a/th02/th02.h +++ b/th02/th02.h @@ -151,26 +151,6 @@ void key_delay(void); #define MUSIC_CMT_LINE_LEN 42 #define MUSIC_CMT_LINE_COUNT 20 -// Configuration file -// ------------------ -#define CFG_FN "huuma.cfg" -#pragma option -a1 -typedef struct { - int8_t rank; - int8_t bgm_mode; - int8_t bombs; - int8_t lives; - int8_t perf; -} huuma_options_t; - -typedef struct { - huuma_options_t opts; - void __seg *resident_sgm; - int8_t debug; -} huuma_cfg_t; -#pragma option -a. -// ------------------ - // Resident structure // ------------------ #define RES_ID "MIKOConfig" diff --git a/th02/zun_res1.c b/th02/zun_res1.c index 893900c0..f814ea73 100644 --- a/th02/zun_res1.c +++ b/th02/zun_res1.c @@ -7,88 +7,26 @@ #include #include "th02/th02.h" #include "th02/snd/snd.h" +#include "th02/formats/cfg.h" #pragma option -a1 +int pascal scoredat_verify(void); + char debug = 0; +const cfg_options_t OPTS_DEFAULT = { RANK_NORMAL, SND_BGM_FM, 3, 2, 0 }; -void cfg_write(seg_t resident_sgm) -{ - static const huuma_options_t opts_default = { - RANK_NORMAL, SND_BGM_FM, 3, 2, 0 - }; - static const char HUUMA_CFG[] = CFG_FN; - - const char *fn = HUUMA_CFG; - huuma_options_t opts = opts_default; - int handle = dos_axdx(0x3D02, fn); - if(handle > 0) { - dos_seek(handle, sizeof(opts), SEEK_SET); - } else { - handle = dos_create(fn, _A_ARCH); - dos_write(handle, &opts, sizeof(opts)); - } - dos_write(handle, &resident_sgm, sizeof(resident_sgm)); - dos_write(handle, &debug, sizeof(debug)); - dos_close(handle); -} +#include "th02/formats/cfg_init.c" #define LOGO \ "東方封魔録用  常駐プログラム ZUN_RES.com Version1.01 (c)zun 1997" -int main(int argc, const char **argv) -{ - int pascal scoredat_verify(void); +#define RES_INIT_TOP \ + if(scoredat_verify() == 1) { \ + dos_puts2("ハイスコアファイルがおかしいの、もう一度実行してね。\n"); \ + return 1; \ + } - seg_t sgm; - const char *res_id = RES_ID; - int i; - char far *resident; - - sgm = resdata_exist(res_id, RES_ID_STRLEN, RES_PARASIZE); - dos_puts2("\n\n" LOGO "\n"); - graph_clear(); - if(scoredat_verify() == 1) { - dos_puts2("ハイスコアファイルがおかしいの、もう一度実行してね。\n"); - return 1; - } - if(argc == 2) { - #define arg1_is(capital, small) \ - (argv[1][0] == '-' || argv[1][0] == '/') \ - && (argv[1][1] == (capital) || argv[1][1] == (small)) - if(arg1_is('R', 'r')) { - if(!sgm) { - dos_puts2("わたし、まだいませんよぉ\n\n"); - return 1; - } - dos_free(sgm); - dos_puts2("さよなら、また会えたらいいな\n\n"); - return 0; - } else if(arg1_is('D', 'd')) { - debug = 1; - } else { - dos_puts2("そんなオプション付けられても、困るんですけど\n\n"); - sgm = sgm; /* optimization barrier #1 */ - return 1; - } - } - if(sgm) { - dos_puts2("わたし、すでにいますよぉ\n\n"); - argv = argv; /* optimization barrier #2 */ - return 1; - } - sgm = resdata_create(res_id, RES_ID_STRLEN, RES_PARASIZE); - if(!sgm) { - dos_puts2("作れません、わたしの居場所がないの!\n\n"); - return 1; - } - resident = MK_FP(sgm, 0); - dos_puts2("それでは、よろしくお願いします\n\n"); - for(i = offsetof(resident_t, stage); i < sizeof(resident_t); i++) { - resident[i] = 0; - } - cfg_write(sgm); - return 0; -} +#include "th02/res_init.c" #pragma codestring "\x00"