[Decompilation] [th03] YUME.NEM: Loading

"I don't need the return value in MAINL.EXE? Let's copy-paste the
function and remove all of its `return` statements then!" :zunpet:

Completes P0172, funded by [Anonymous] and Blue Bolt.
This commit is contained in:
nmlgc 2021-12-25 19:35:50 +01:00
parent 4b7028c9d3
commit 2d5491e4a9
8 changed files with 64 additions and 122 deletions

View File

@ -93,7 +93,7 @@ bin\th03\res_yume.com: th03\res_yume.cpp
$**
| masters.lib
bin\th03\op.exe: th03\op_01.cpp th03\op_02.cpp bin\th03\scoredat.obj bin\th03\op.obj bin\th02\exit_dos.obj bin\th01\vplanset.obj bin\th02\snd_mode.obj bin\th02\snd_pmdr.obj bin\th02\snd_load.obj bin\th03\exit.obj bin\th03\vector1.obj bin\th03\cdg_put.obj bin\th02\frmdely1.obj bin\th03\input_s.obj bin\th03\pi_put.obj bin\th03\snd_kaja.obj bin\th03\initop.obj bin\th03\cdg_load.obj bin\th03\grppsafx.obj bin\th03\pi_load.obj bin\th03\inp_m_w.obj bin\th03\cdg_p_na.obj bin\th03\hfliplut.obj bin\th02\frmdely2.obj
bin\th03\op.exe: th03\op_01.cpp th03\op_02.cpp bin\th03\scoredat.obj th03\op_03.cpp bin\th03\op.obj bin\th02\exit_dos.obj bin\th01\vplanset.obj bin\th02\snd_mode.obj bin\th02\snd_pmdr.obj bin\th02\snd_load.obj bin\th03\exit.obj bin\th03\vector1.obj bin\th03\cdg_put.obj bin\th02\frmdely1.obj bin\th03\input_s.obj bin\th03\pi_put.obj bin\th03\snd_kaja.obj bin\th03\initop.obj bin\th03\cdg_load.obj bin\th03\grppsafx.obj bin\th03\pi_load.obj bin\th03\inp_m_w.obj bin\th03\cdg_p_na.obj bin\th03\hfliplut.obj bin\th02\frmdely2.obj
$(CC) $(CFLAGS) $(LARGE_LFLAGS) -3 -Z -DGAME=3 -DBINARY='O' -nbin\th03\ -eOP.EXE @&&|
$**
|

32
th03/formats/score_ld.cpp Normal file
View File

@ -0,0 +1,32 @@
#if (BINARY == 'L')
#define recreated
#define loaded
void pascal near scoredat_load_and_decode(rank_t rank)
#else
#define recreated true
#define loaded false
bool16 pascal near scoredat_load_and_decode(rank_t rank)
#endif
{
if(!file_exist(SCOREDAT_FN)) {
// Unnecessary, since scoredat_recreate() would also create the file?
file_create(SCOREDAT_FN);
file_close();
scoredat_recreate();
return recreated;
}
file_ropen(SCOREDAT_FN);
file_seek((rank * sizeof(scoredat_section_t)), SEEK_SET);
file_read(&hi, sizeof(scoredat_section_t));
file_close();
scoredat_decode();
if(scoredat_sum_invalid()) {
scoredat_recreate();
return recreated;
}
return loaded;
#undef recreated
#undef loaded
}

View File

@ -2,6 +2,7 @@
#include <stddef.h>
#include "platform.h"
#include "master.hpp"
#include "th01/rank.h"
#include "th03/common.h"
#include "th03/score.h"

View File

@ -51,6 +51,15 @@ extern scoredat_section_t hi;
void near scoredat_decode(void);
#ifdef RANK_H
// Loads the score data for the given [rank] into [hi]. The OP.EXE version
// returns `true` if that data was recreated due to corruption or a
// nonexistent file.
#if (BINARY == 'O')
bool16 pascal near scoredat_load_and_decode(rank_t rank);
#elif (BINARY == 'L')
void pascal near scoredat_load_and_decode(rank_t rank);
#endif
// Calculates the checksum and encrypts [hi] in-place, then saves it to
// the score file under the given [rank]. The MAINL version also sets
// [cleared] based on resident data.

View File

@ -10,4 +10,5 @@
#include "th03/sprites/regi.h"
#include "th03/formats/scoredat.hpp"
#include "th03/formats/score_ld.cpp"
#include "th03/formats/score_es.cpp"

12
th03/op_03.cpp Normal file
View File

@ -0,0 +1,12 @@
#pragma option -zPgroup_01
#include "platform.h"
#include "master.hpp"
#include "th01/rank.h"
#include "th03/common.h"
#include "th03/score.h"
#include "th03/playchar.hpp"
#include "th03/sprites/regi.h"
#include "th03/formats/scoredat.hpp"
#include "th03/formats/score_ld.cpp"

View File

@ -27,7 +27,7 @@ include th03/formats/scoredat.inc
extern _execl:proc
extern _tolower:proc
group_01 group CFG_LRES_TEXT, mainl_01_TEXT, SCOREDAT_TEXT, mainl_02_TEXT, REGIST_TEXT, mainl_03_TEXT
group_01 group CFG_LRES_TEXT, mainl_01_TEXT, SCOREDAT_TEXT, REGIST_TEXT, mainl_03_TEXT
; ===========================================================================
@ -2600,64 +2600,10 @@ sub_AC6E endp
mainl_01_TEXT ends
SCOREDAT_TEXT segment byte public 'CODE' use16
@scoredat_decode$qv procdesc near
@scoredat_recreate$qv procdesc near
@scoredat_sum_invalid$qv procdesc near
@SCOREDAT_LOAD_AND_DECODE$Q6RANK_T procdesc pascal near \
rank:word
SCOREDAT_TEXT ends
mainl_02_TEXT segment byte public 'CODE' use16
; =============== S U B R O U T I N E =======================================
; Attributes: bp-based frame
sub_AE8E proc near
arg_0 = word ptr 4
push bp
mov bp, sp
push ds
push _SCOREDAT_FN
call file_exist
or ax, ax
jnz short loc_AEB0
push ds
push _SCOREDAT_FN
call file_create
call file_close
jmp short loc_AEE9
; ---------------------------------------------------------------------------
loc_AEB0:
push ds
push _SCOREDAT_FN
call file_ropen
mov ax, [bp+arg_0]
imul ax, size scoredat_section_t
movzx eax, ax
push eax
push 0
call file_seek
push ds
push offset _hi
push size scoredat_section_t
call file_read
call file_close
call @scoredat_decode$qv
call @scoredat_sum_invalid$qv
or al, al
jz short loc_AEEC
loc_AEE9:
call @scoredat_recreate$qv
loc_AEEC:
pop bp
retn 2
sub_AE8E endp
mainl_02_TEXT ends
REGIST_TEXT segment byte public 'CODE' use16
@SCOREDAT_ENCODE_AND_SAVE$Q6RANK_T procdesc pascal near \
rank:word
@ -3787,8 +3733,7 @@ sub_B7D2 proc near
les bx, _resident
mov al, es:[bx+resident_t.rank]
mov ah, 0
push ax
call sub_AE8E
call @scoredat_load_and_decode$q6rank_t pascal, ax
les bx, _resident
cmp es:[bx+resident_t.story_stage], STAGE_NONE
jnz short loc_B819

View File

@ -1973,68 +1973,11 @@ op_02_TEXT segment byte public 'CODE' use16
op_02_TEXT ends
SCOREDAT_TEXT segment byte public 'CODE' use16
@scoredat_decode$qv procdesc near
@scoredat_recreate$qv procdesc near
@scoredat_sum_invalid$qv procdesc near
SCOREDAT_TEXT ends
op_03_TEXT segment byte public 'CODE' use16
; =============== S U B R O U T I N E =======================================
; Attributes: bp-based frame
sub_B2F2 proc near
arg_0 = word ptr 4
push bp
mov bp, sp
push ds
push _SCOREDAT_FN
call file_exist
or ax, ax
jnz short loc_B314
push ds
push _SCOREDAT_FN
call file_create
call file_close
jmp short loc_B34D
; ---------------------------------------------------------------------------
loc_B314:
push ds
push _SCOREDAT_FN
call file_ropen
mov ax, [bp+arg_0]
imul ax, size scoredat_section_t
movzx eax, ax
push eax
push 0
call file_seek
push ds
push offset _hi
push size scoredat_section_t
call file_read
call file_close
call @scoredat_decode$qv
call @scoredat_sum_invalid$qv
or al, al
jz short loc_B357
loc_B34D:
call @scoredat_recreate$qv
mov ax, 1
pop bp
retn 2
; ---------------------------------------------------------------------------
loc_B357:
xor ax, ax
pop bp
retn 2
sub_B2F2 endp
@SCOREDAT_LOAD_AND_DECODE$Q6RANK_T procdesc pascal near \
rank:word
; =============== S U B R O U T I N E =======================================
@ -2052,8 +1995,7 @@ var_1 = byte ptr -1
; ---------------------------------------------------------------------------
loc_B36A:
push si
call sub_B2F2
call @scoredat_load_and_decode$q6rank_t pascal, si
or ax, ax
jz short loc_B376
mov al, 7
@ -2069,7 +2011,7 @@ loc_B381:
inc si
loc_B382:
cmp si, 4
cmp si, (RANK_LUNATIC + 1)
jl short loc_B36A
mov al, [bp+var_1]