[Decompilation] [th01] REYHI*.DAT saving

Now with POSIX file I/O in both executables. And the confirmation that
the name array is indeed exclusively accessed per-byte.

Part of P0093, funded by Ember2528.
This commit is contained in:
nmlgc 2020-05-18 21:29:12 +02:00
parent 6e0c33a8bf
commit bbef9b0bdb
10 changed files with 75 additions and 352 deletions

View File

@ -530,3 +530,48 @@ regist_input_ret_t regist_on_input(
}
return RI_REGULAR;
}
#if (BINARY == 'E')
inline void scoredat_free(void)
#else
void scoredat_free(void)
#endif
{
delete[] scoredat_names;
delete[] scoredat_stages;
delete[] scoredat_routes;
delete[] scoredat_points;
}
void scoredat_save(void)
{
extern const char SCOREDAT_FN_EASY_2[];
extern const char SCOREDAT_FN_NORMAL_2[];
extern const char SCOREDAT_FN_HARD_2[];
extern const char SCOREDAT_FN_LUNATIC_2[];
extern const char SCOREDAT_FOPEN_WB[];
struct hack {
char x[sizeof(SCOREDAT_MAGIC)];
};
#undef SCOREDAT_MAGIC
extern const hack SCOREDAT_MAGIC;
FILE* fp;
const hack magic = SCOREDAT_MAGIC;
char fn[16];
scoredat_fn(fn, 2);
if( (fp = fopen(fn, SCOREDAT_FOPEN_WB)) == NULL) {
return;
}
write(fileno(fp), magic.x, sizeof(SCOREDAT_MAGIC) - 1);
for(int i = 0; i < SCOREDAT_NAMES_SIZE; i++) {
scoredat_names[i] = scoredat_name_byte_encode(scoredat_names[i]);
}
write(fileno(fp), scoredat_names, SCOREDAT_NAMES_SIZE);
write(fileno(fp), scoredat_points, sizeof(uint32_t) * SCOREDAT_PLACES);
write(fileno(fp), scoredat_stages, sizeof(int16_t) * SCOREDAT_PLACES);
write(fileno(fp), scoredat_routes, sizeof(twobyte_t) * SCOREDAT_PLACES);
fclose(fp);
}

View File

@ -54,4 +54,10 @@ if BINARY eq 'E'
_ALPHABET_KANJI_FMT_4 db '%c%c',0
_REGIST_STRING_FMT_0 db '%s',0
_REGIST_STRING_FMT_1 db '%s',0
_SCOREDAT_FN_EASY_2 db 'REYHIES.DAT',0
_SCOREDAT_FN_NORMAL_2 db 'REYHINO.DAT',0
_SCOREDAT_FN_HARD_2 db 'REYHIHA.DAT',0
_SCOREDAT_FN_LUNATIC_2 db 'REYHILU.DAT',0
endif
public _SCOREDAT_FOPEN_WB
_SCOREDAT_FOPEN_WB db 'wb',0

View File

@ -1,7 +1,8 @@
public _REGIST_NAME_BLANK, _REGIST_NAME_SPACES
public _REGIST_NAME_BLANK, _REGIST_NAME_SPACES, _SCOREDAT_MAGIC
_REGIST_NAME_BLANK db '________',0
if BINARY eq 'M'
public _regist_jump_to_enter
_regist_jump_to_enter db 0
endif
_REGIST_NAME_SPACES db '        ',0
_SCOREDAT_MAGIC db 'HISCORE',0

View File

@ -1,7 +1,7 @@
void scoredat_name_get(int place, char str[SCOREDAT_NAME_BYTES + 1])
{
for(int i = 0; i < SCOREDAT_NAME_BYTES; i++) {
str[i] = scoredat_name_byte((place * SCOREDAT_NAME_BYTES) + i);
str[i] = scoredat_names[(place * SCOREDAT_NAME_BYTES) + i];
}
str[SCOREDAT_NAME_BYTES] = '\0';
}

View File

@ -4,6 +4,7 @@
// Actually creates slightly different assembly compared to sizeof() on a
// int8_t array!
#define SCOREDAT_NAME_BYTES (SCOREDAT_NAME_KANJI * 2)
#define SCOREDAT_NAMES_SIZE (SCOREDAT_PLACES * SCOREDAT_NAME_BYTES)
#define SCOREDAT_ROUTE_LEN 2
#define SCOREDAT_CLEARED 40
@ -34,17 +35,11 @@ struct scoredat_t {
twobyte_t route[SCOREDAT_PLACES];
};
extern scoredat_name_t* scoredat_names;
extern int8_t* scoredat_names; // Yeah, technically a scoredat_name_t.
extern int16_t* scoredat_stages;
extern uint32_t* scoredat_points;
extern twobyte_t* scoredat_routes;
// Byte-wise access to [scoredat_names].
inline int8_t& scoredat_name_byte(size_t byte)
{
return reinterpret_cast<char *>(scoredat_names)[byte];
}
// Byte-wise access to [scoredat_routes].
inline int8_t& scoredat_route_byte(int place, int byte)
{

View File

@ -112,20 +112,19 @@ int scoredat_load()
return 1;
}
scoredat_names = new scoredat_name_t[SCOREDAT_PLACES];
scoredat_names = new int8_t[SCOREDAT_NAMES_SIZE];
scoredat_stages = new int16_t[SCOREDAT_PLACES];
scoredat_routes = new twobyte_t[SCOREDAT_PLACES];
scoredat_points = new uint32_t[SCOREDAT_PLACES];
scoredat_read(scoredat_names, sizeof(scoredat_name_t) * SCOREDAT_PLACES);
scoredat_read(scoredat_names, SCOREDAT_NAMES_SIZE);
scoredat_read(scoredat_points, sizeof(uint32_t) * SCOREDAT_PLACES);
scoredat_read(scoredat_stages, sizeof(int16_t) * SCOREDAT_PLACES);
scoredat_read(scoredat_routes, sizeof(twobyte_t) * SCOREDAT_PLACES);
scoredat_close();
for(int i = 0; i < sizeof(scoredat_name_t) * SCOREDAT_PLACES; i++) {
scoredat_name_byte(i) =
scoredat_name_byte_decode(scoredat_name_byte(i));
for(int i = 0; i < SCOREDAT_NAMES_SIZE; i++) {
scoredat_names[i] = scoredat_name_byte_decode(scoredat_names[i]);
}
scoredat_sti();
return 0;

View File

@ -1,9 +1,9 @@
public _SCOREDAT_ROUTE_NONE, _scoredat_name_default
public _SCOREDAT_MAGIC_0, _SCOREDAT_MAGIC_1
public _SCOREDAT_FN_EASY_0, _SCOREDAT_FN_EASY_1
public _SCOREDAT_FN_NORMAL_0, _SCOREDAT_FN_NORMAL_1
public _SCOREDAT_FN_HARD_0, _SCOREDAT_FN_HARD_1
public _SCOREDAT_FN_LUNATIC_0, _SCOREDAT_FN_LUNATIC_1
public _SCOREDAT_FN_EASY_0, _SCOREDAT_FN_EASY_1, _SCOREDAT_FN_EASY_2
public _SCOREDAT_FN_NORMAL_0, _SCOREDAT_FN_NORMAL_1, _SCOREDAT_FN_NORMAL_2
public _SCOREDAT_FN_HARD_0, _SCOREDAT_FN_HARD_1, _SCOREDAT_FN_HARD_2
public _SCOREDAT_FN_LUNATIC_0, _SCOREDAT_FN_LUNATIC_1, _SCOREDAT_FN_LUNATIC_2
_SCOREDAT_ROUTE_NONE db '–ł',0
_scoredat_name_default db '“Ś•ű<E280A2>ščË<C48D>Ů“`<60>@<40>@',0
@ -28,12 +28,16 @@ if BINARY eq 'E'
else
_SCOREDAT_MAGIC_1 label byte
_SCOREDAT_MAGIC_0 db 'HISCORE',0
_SCOREDAT_FN_EASY_2 label byte
_SCOREDAT_FN_EASY_1 label byte
_SCOREDAT_FN_EASY_0 db 'REYHIES.DAT',0
_SCOREDAT_FN_NORMAL_2 label byte
_SCOREDAT_FN_NORMAL_1 label byte
_SCOREDAT_FN_NORMAL_0 db 'REYHINO.DAT',0
_SCOREDAT_FN_HARD_2 label byte
_SCOREDAT_FN_HARD_1 label byte
_SCOREDAT_FN_HARD_0 db 'REYHIHA.DAT',0
_SCOREDAT_FN_LUNATIC_2 label byte
_SCOREDAT_FN_LUNATIC_1 label byte
_SCOREDAT_FN_LUNATIC_0 db 'REYHILU.DAT',0
endif

View File

@ -6,6 +6,8 @@
#pragma option -3 -Z -d
extern "C" {
#include <io.h>
#include <stdio.h>
#include "ReC98.h"
#include "th01/ranks.h"
#include "th01/hardware/graph.h"

View File

@ -42,9 +42,7 @@ include th01/th01.inc
extern _exit:proc
extern _farfree:proc
extern _farmalloc:proc
extern _fclose:proc
extern _filelength:proc
extern _fopen:proc
extern _int86:proc
extern _intdosx:proc
extern _memcmp:proc
@ -57,7 +55,6 @@ include th01/th01.inc
extern _strcmp:proc
extern _strcpy:proc
extern _vsprintf:proc
extern _write:proc
fuuin_02 group fuuin_02_TEXT, fuuin_02__TEXT
@ -373,12 +370,12 @@ fuuin_01_TEXT ends
fuuin_02_TEXT segment byte public 'CODE' use16
extern _input_sense:proc
extern _input_reset_sense:proc
extern _scoredat_name_byte_encode:proc
extern _scoredat_load:proc
extern _scoredat_name_get:proc
extern _alphabet_put_initial:proc
extern _regist_put_initial:proc
extern _regist_on_input:proc
extern _scoredat_save:proc
fuuin_02_TEXT ends
fuuin_02__TEXT segment byte public 'CODE' use16
@ -388,160 +385,6 @@ fuuin_02__TEXT segment byte public 'CODE' use16
; Attributes: bp-based frame
sub_B40E proc far
dest = byte ptr -1Ch
var_C = byte ptr -0Ch
stream = dword ptr -4
enter 1Ch, 0
push si
lea ax, [bp+var_C]
push ss
push ax
push ds
push offset aHiscore_0 ; "HISCORE"
mov cx, 8
call SCOPY@
mov al, _rank
mov ah, 0
mov bx, ax
cmp bx, RANK_LUNATIC
ja short loc_B45C
add bx, bx
jmp cs:off_B533[bx]
loc_B437:
push ds
push offset aReyhies_dat_1 ; "REYHIES.DAT"
jmp short loc_B44D
; ---------------------------------------------------------------------------
loc_B43D:
push ds
push offset aReyhino_dat_1 ; "REYHINO.DAT"
jmp short loc_B44D
; ---------------------------------------------------------------------------
loc_B443:
push ds
push offset aReyhiha_dat_1 ; "REYHIHA.DAT"
jmp short loc_B44D
; ---------------------------------------------------------------------------
loc_B449:
push ds
push offset aReyhilu_dat_1 ; "REYHILU.DAT"
loc_B44D:
push ss
lea ax, [bp+dest]
push ax ; dest
call _strcpy
add sp, 8
jmp short $+2
loc_B45C:
push ds
push offset aWb_0 ; "wb"
push ss
lea ax, [bp+dest]
push ax ; path
call _fopen
add sp, 8
mov word ptr [bp+stream+2], dx
mov word ptr [bp+stream], ax
or ax, dx
jnz short loc_B47A
jmp loc_B530
; ---------------------------------------------------------------------------
loc_B47A:
push 7
push ss
lea ax, [bp+var_C]
push ax
les bx, [bp+stream]
mov al, es:[bx+4]
cbw
push ax
call _write
add sp, 8
xor si, si
jmp short loc_B4AF
; ---------------------------------------------------------------------------
loc_B496:
les bx, _scoredat_names
add bx, si
mov al, es:[bx]
call fuuin_02:_scoredat_name_byte_encode pascal, ax
pop cx
les bx, _scoredat_names
add bx, si
mov es:[bx], al
inc si
loc_B4AF:
cmp si, size scoredat_names_t
jl short loc_B496
push size scoredat_names_t
push word ptr _scoredat_names+2
push word ptr _scoredat_names
les bx, [bp+stream]
mov al, es:[bx+4]
cbw
push ax
call _write
add sp, 8
push size scoredat_points_t
push word ptr _scoredat_points+2
push word ptr _scoredat_points
les bx, [bp+stream]
mov al, es:[bx+4]
cbw
push ax
call _write
add sp, 8
push size scoredat_stages_t
push word ptr _scoredat_stages+2
push word ptr _scoredat_stages
les bx, [bp+stream]
mov al, es:[bx+4]
cbw
push ax
call _write
add sp, 8
push size scoredat_routes_t
push word ptr _scoredat_routes+2
push word ptr _scoredat_routes
les bx, [bp+stream]
mov al, es:[bx+4]
cbw
push ax
call _write
add sp, 8
push word ptr [bp+stream+2]
push word ptr [bp+stream] ; stream
call _fclose
add sp, 4
loc_B530:
pop si
leave
retf
sub_B40E endp
; ---------------------------------------------------------------------------
off_B533 dw offset loc_B437
dw offset loc_B43D
dw offset loc_B443
dw offset loc_B449
; =============== S U B R O U T I N E =======================================
; Attributes: bp-based frame
sub_B53B proc far
@@entered_name = byte ptr -18h
@ -633,7 +476,7 @@ loc_B5B4:
loc_B5CB:
cmp si, SCOREDAT_NAME_BYTES
jl short loc_B5B4
call sub_B40E
call _scoredat_save
pop di
pop si
leave
@ -2698,7 +2541,6 @@ include th01/hardware/input_main_end[data].asm
include th01/hiscore/alphabet_syms[data].asm
include th01/hardware/grppfnfx_ptrs[data].asm
include th01/hiscore/regist_name[data].asm
aHiscore_0 db 'HISCORE',0
off_12C1E dd aB@gcbGwbB@
; " イージー "
dd aB@gmbGGlb@ ; " ノーマル "
@ -2707,13 +2549,6 @@ off_12C1E dd aB@gcbGwbB@
include th01/hardware/grppfnfx[data].asm
include th01/hiscore/scorelod[data].asm
include th01/hiscore/regist[data].asm
aReyhies_dat_1 db 'REYHIES.DAT',0
aReyhino_dat_1 db 'REYHINO.DAT',0
aReyhiha_dat_1 db 'REYHIHA.DAT',0
; char aReyhilu_dat_1[]
aReyhilu_dat_1 db 'REYHILU.DAT',0
; char aWb_0[]
aWb_0 db 'wb',0
aB@gcbGwbB@ db ' イージー ',0
aB@gmbGGlb@ db ' ノーマル ',0
aB@gnbGhb@b@ db ' ハード  ',0

View File

@ -49,9 +49,7 @@ include th01/th01.inc
extern _farheapcheck:proc
extern _farheapchecknode:proc
extern _farmalloc:proc
extern _fclose:proc
extern _filelength:proc
extern _fopen:proc
extern _int86:proc
extern _intdosx:proc
extern _kbhit:proc
@ -65,7 +63,6 @@ include th01/th01.inc
extern _strcpy:proc
extern _toupper:proc
extern _vsprintf:proc
extern _write:proc
main_01 group main_01_TEXT, main_01__TEXT
main_19 group main_19_TEXT, main_19__TEXT
@ -8414,7 +8411,6 @@ main_18_TEXT ends
; Segment type: Pure code
main_19_TEXT segment byte public 'CODE' use16
extern _scoredat_name_byte_encode:proc
extern _scoredat_load:proc
extern _scoredat_hiscore_get:proc
extern _scoredat_name_get:proc
@ -8425,166 +8421,8 @@ main_19__TEXT segment byte public 'CODE' use16
extern _alphabet_put_initial:proc
extern _regist_put_initial:proc
extern _regist_on_input:proc
; =============== S U B R O U T I N E =======================================
; Attributes: bp-based frame
public _scoredat_free
_scoredat_free proc far
push bp
mov bp, sp
call @$bdla$qnv c, large [_scoredat_names]
call @$bdla$qnv c, large [_scoredat_stages]
call @$bdla$qnv c, large [_scoredat_routes]
call @$bdla$qnv c, large [_scoredat_points]
pop bp
retf
_scoredat_free endp
; =============== S U B R O U T I N E =======================================
; Attributes: bp-based frame
sub_146F3 proc far
dest = byte ptr -1Ch
var_C = byte ptr -0Ch
stream = dword ptr -4
enter 1Ch, 0
push si
lea ax, [bp+var_C]
push ss
push ax
push ds
push offset aHiscore_0 ; "HISCORE"
mov cx, 8
call SCOPY@
mov al, _rank
cbw
mov bx, ax
cmp bx, RANK_LUNATIC
ja short loc_1473E
add bx, bx
jmp cs:off_14806[bx]
loc_1471B:
push ds
push offset _SCOREDAT_FN_EASY_0 ; "REYHIES.DAT"
jmp short loc_14731
; ---------------------------------------------------------------------------
loc_14721:
push ds
push offset _SCOREDAT_FN_NORMAL_0 ; "REYHINO.DAT"
jmp short loc_14731
; ---------------------------------------------------------------------------
loc_14727:
push ds
push offset _SCOREDAT_FN_HARD_0 ; "REYHIHA.DAT"
jmp short loc_14731
; ---------------------------------------------------------------------------
loc_1472D:
push ds
push offset _SCOREDAT_FN_LUNATIC_0 ; "REYHILU.DAT"
loc_14731:
push ss
lea ax, [bp+dest]
push ax ; dest
call _strcpy
add sp, 8
loc_1473E:
push ds
push offset aWB ; "wb"
push ss
lea ax, [bp+dest]
push ax ; path
call _fopen
add sp, 8
mov word ptr [bp+stream+2], dx
mov word ptr [bp+stream], ax
or ax, dx
jz loc_14803
push 7
push ss
lea ax, [bp+var_C]
push ax
les bx, [bp+stream]
mov al, es:[bx+4]
cbw
push ax
call _write
add sp, 8
xor si, si
jmp short loc_14790
; ---------------------------------------------------------------------------
loc_14777:
les bx, _scoredat_names
add bx, si
mov al, es:[bx]
call main_19:_scoredat_name_byte_encode stdcall, ax
pop cx
les bx, _scoredat_names
add bx, si
mov es:[bx], al
inc si
loc_14790:
cmp si, size scoredat_names_t
jl short loc_14777
push size scoredat_names_t
pushd [_scoredat_names]
les bx, [bp+stream]
mov al, es:[bx+4]
cbw
push ax
call _write
add sp, 8
push size scoredat_points_t
pushd [_scoredat_points]
les bx, [bp+stream]
mov al, es:[bx+4]
cbw
push ax
call _write
add sp, 8
push size scoredat_stages_t
pushd [_scoredat_stages]
les bx, [bp+stream]
mov al, es:[bx+4]
cbw
push ax
call _write
add sp, 8
push size scoredat_routes_t
pushd [_scoredat_routes]
les bx, [bp+stream]
mov al, es:[bx+4]
cbw
push ax
call _write
add sp, 8
pushd [bp+stream] ; stream
call _fclose
add sp, 4
loc_14803:
pop si
leave
retf
sub_146F3 endp
; ---------------------------------------------------------------------------
off_14806 dw offset loc_1471B
dw offset loc_14721
dw offset loc_14727
dw offset loc_1472D
extern _scoredat_free:proc
extern _scoredat_save:proc
; =============== S U B R O U T I N E =======================================
@ -8673,7 +8511,7 @@ loc_1488F:
loc_148A6:
cmp si, SCOREDAT_NAME_BYTES
jl short loc_1488F
call sub_146F3
call _scoredat_save
pop di
pop si
leave
@ -59726,7 +59564,6 @@ aVgvivfb@vyb@vj db '
db 0
include th01/hiscore/alphabet_syms[data].asm
include th01/hiscore/regist_name[data].asm
aHiscore_0 db 'HISCORE',0
off_358A3 dd aB@gcbGwbB@
; " イージー "
dd aB@gmbGGlb@ ; " ノーマル "
@ -59734,7 +59571,6 @@ off_358A3 dd aB@gcbGwbB@
dd aGlgigegbgbgn ; "ルナティック"
include th01/hiscore/scorelod[data].asm
include th01/hiscore/regist[data].asm
aWB db 'wb',0
aB@gcbGwbB@ db ' イージー ',0
aB@gmbGGlb@ db ' ノーマル ',0
aB@gnbGhb@b@ db ' ハード  ',0