2024-04-28 23:51:08 +00:00
|
|
|
// 2nd part of ZUN_RES.COM. Verifies HUUHI.DAT and initializes the high score
|
|
|
|
// lists.
|
2020-02-21 21:10:47 +00:00
|
|
|
|
2020-10-01 14:34:46 +00:00
|
|
|
#pragma option -O- -k-
|
|
|
|
|
2021-01-26 15:33:06 +00:00
|
|
|
#include <dos.h>
|
2022-03-12 23:14:12 +00:00
|
|
|
#include "platform.h"
|
2021-01-26 15:33:06 +00:00
|
|
|
#include "master.hpp"
|
2022-03-12 22:54:37 +00:00
|
|
|
#include "th01/rank.h"
|
2024-01-17 08:03:39 +00:00
|
|
|
#include "th02/formats/scoredat.hpp"
|
2024-04-28 23:51:08 +00:00
|
|
|
#include "th02/gaiji/gaiji.h"
|
2020-02-21 21:10:47 +00:00
|
|
|
|
|
|
|
scoredat_section_t hi;
|
|
|
|
|
|
|
|
void pascal scoredat_recreate(void);
|
|
|
|
void pascal near scoredat_load(void);
|
|
|
|
|
|
|
|
const char *SCOREDAT_FN = "huuhi.dat";
|
|
|
|
unsigned char g_name_first_sum = 0;
|
|
|
|
unsigned char stage_sum = 0;
|
2022-08-15 17:15:40 +00:00
|
|
|
unsigned char unused_2 = 0; // ZUN bloat
|
2020-02-21 21:10:47 +00:00
|
|
|
long score_sum = 0;
|
2021-12-17 21:19:17 +00:00
|
|
|
long section_sum = 0;
|
2024-04-28 23:51:08 +00:00
|
|
|
int8_t rank;
|
2020-02-21 21:10:47 +00:00
|
|
|
|
2024-01-17 08:03:39 +00:00
|
|
|
// ZUN bloat: Needed to circumvent 16-bit promotion in a single comparison.
|
|
|
|
inline int8_t rank_count(void) {
|
|
|
|
return RANK_COUNT;
|
|
|
|
}
|
|
|
|
|
2020-02-21 21:10:47 +00:00
|
|
|
int pascal scoredat_verify(void)
|
|
|
|
{
|
|
|
|
if(!file_exist(SCOREDAT_FN)) {
|
|
|
|
scoredat_recreate();
|
|
|
|
} else {
|
2024-01-17 08:03:39 +00:00
|
|
|
for(rank = 0; rank < rank_count(); rank++) {
|
2022-08-15 17:15:40 +00:00
|
|
|
register int unused; // ZUN bloat
|
2020-02-21 21:10:47 +00:00
|
|
|
register int i;
|
|
|
|
|
|
|
|
scoredat_load();
|
|
|
|
_AL = 0;
|
|
|
|
g_name_first_sum = _AL;
|
|
|
|
stage_sum = _AL;
|
|
|
|
_AX = 0;
|
2022-02-12 16:29:37 +00:00
|
|
|
asm {
|
2020-02-21 21:10:47 +00:00
|
|
|
mov word ptr score_sum + 0, ax
|
|
|
|
mov word ptr score_sum + 2, ax
|
2021-12-17 21:19:17 +00:00
|
|
|
mov word ptr section_sum + 0, ax
|
|
|
|
mov word ptr section_sum + 2, ax
|
2020-02-21 21:10:47 +00:00
|
|
|
}
|
|
|
|
for(i = 0; i < sizeof(hi.score); i++) {
|
2022-08-09 01:24:33 +00:00
|
|
|
section_sum += *((uint8_t *)(&hi.score) + i);
|
2020-02-21 21:10:47 +00:00
|
|
|
}
|
|
|
|
for(i = 0; i < SCOREDAT_PLACES; i++) {
|
2021-12-17 21:19:17 +00:00
|
|
|
score_sum += hi.score.score[i];
|
2020-02-21 21:10:47 +00:00
|
|
|
g_name_first_sum += hi.score.g_name[i][0];
|
|
|
|
stage_sum += hi.score.stage[i];
|
|
|
|
}
|
|
|
|
if(
|
2021-12-17 21:19:17 +00:00
|
|
|
score_sum != hi.score.score_sum
|
2020-02-21 21:10:47 +00:00
|
|
|
|| g_name_first_sum != hi.score.g_name_first_sum
|
|
|
|
|| stage_sum != hi.score.stage_sum
|
2021-12-17 21:19:17 +00:00
|
|
|
|| section_sum != hi.section_sum
|
2020-02-21 21:10:47 +00:00
|
|
|
) {
|
2024-01-17 08:03:39 +00:00
|
|
|
goto remove;
|
2020-02-21 21:10:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
2024-01-17 08:03:39 +00:00
|
|
|
|
|
|
|
remove:
|
2020-02-21 21:10:47 +00:00
|
|
|
file_delete(SCOREDAT_FN);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma codestring "\x90"
|
2024-04-28 23:51:08 +00:00
|
|
|
#pragma option -O -k
|
|
|
|
|
|
|
|
// Slightly differs from the same function in MAINE.EXE!
|
|
|
|
// And seriously, I wasted half a week trying to figure out how to get these
|
|
|
|
// exact same instructions out of the compiler, and it just didn't work.
|
|
|
|
void pascal scoredat_defaults_set(void)
|
|
|
|
{
|
|
|
|
_SI = 0;
|
|
|
|
_DI = 1000 * SCOREDAT_PLACES;
|
|
|
|
goto place_loop;
|
|
|
|
|
|
|
|
place_set:
|
|
|
|
hi.score.cleared = 0;
|
|
|
|
hi.score.score[_SI] = _DI;
|
|
|
|
_DI -= 1000;
|
|
|
|
hi.score.stage[_SI] = 5 - ((int)_SI >> 1);
|
|
|
|
_BX = _SI;
|
|
|
|
asm {
|
|
|
|
imul bx, bx, 7
|
|
|
|
mov cx, 6
|
|
|
|
|
|
|
|
name_loop:
|
|
|
|
mov byte ptr hi.(scoredat_section_t)score.g_name[bx], gs_BULLET
|
|
|
|
inc bx
|
|
|
|
loop name_loop
|
|
|
|
mov byte ptr hi.(scoredat_section_t)score.g_name[bx], 0
|
|
|
|
}
|
|
|
|
_BX = _SI;
|
|
|
|
_BX <<= 2;
|
|
|
|
asm {
|
|
|
|
mov word ptr hi.(scoredat_section_t)score.date[bx].da_year, 1900
|
|
|
|
mov byte ptr hi.(scoredat_section_t)score.date[bx].da_day, 1
|
|
|
|
mov byte ptr hi.(scoredat_section_t)score.date[bx].da_mon, 1
|
|
|
|
mov byte ptr hi.(scoredat_section_t)score.shottype[si], 1
|
|
|
|
inc si
|
|
|
|
|
|
|
|
place_loop:
|
|
|
|
cmp si, SCOREDAT_PLACES
|
|
|
|
jge end
|
|
|
|
jmp place_set
|
|
|
|
}
|
|
|
|
end:
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "th02/scoreenc.c"
|
|
|
|
|
|
|
|
void pascal scoredat_create(void)
|
|
|
|
{
|
|
|
|
SCOREDAT_ENCODE();
|
|
|
|
file_create(SCOREDAT_FN);
|
|
|
|
file_write(&hi, sizeof(hi));
|
|
|
|
file_write(&hi, sizeof(hi));
|
|
|
|
file_write(&hi, sizeof(hi));
|
|
|
|
file_write(&hi, sizeof(hi));
|
|
|
|
file_write(&hi, sizeof(hi));
|
|
|
|
file_close();
|
|
|
|
}
|
|
|
|
|
|
|
|
void pascal scoredat_recreate(void)
|
|
|
|
{
|
|
|
|
scoredat_defaults_set();
|
|
|
|
scoredat_create();
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "th02/scorelod.c"
|