[Decompilation] [th03/th04/th05] cfg_load_resident_ptr()

Including the pointless DOS I/O variation in TH05's MAIN.EXE.
I'm slowly running out of characters to remove from the first segment
name in that file, though…

Part of P0148, funded by [Anonymous].
This commit is contained in:
nmlgc 2021-07-12 14:28:49 +02:00
parent 06dbb6335c
commit 6333643222
15 changed files with 119 additions and 74 deletions

View File

@ -110,12 +110,12 @@ bin\th03\op.exe: th03\op_01.cpp bin\th03\op.obj bin\exit_dos.obj bin\th01\vplans
$**
|
bin\th03\main.exe: bin\th03\main.obj th03\main_01.cpp bin\th01\vplanset.obj bin\th02\snd_mode.obj bin\th02\snd_pmdr.obj bin\th03\vector2.obj bin\th03\exit.obj bin\th03\vector1.obj bin\frmdely1.obj bin\th03\input_s.obj bin\th02\snd_se_r.obj bin\th03\snd_se.obj bin\th03\snd_kaja.obj bin\th03\initmain.obj bin\th03\pi_load.obj bin\th03\inp_m_w.obj bin\hfliplut.obj th03\mrs.cpp th03\sprite16.cpp
bin\th03\main.exe: bin\th03\main.obj th03\main_01.cpp bin\th03\cfg_lres.obj bin\th01\vplanset.obj bin\th02\snd_mode.obj bin\th02\snd_pmdr.obj bin\th03\vector2.obj bin\th03\exit.obj bin\th03\vector1.obj bin\frmdely1.obj bin\th03\input_s.obj bin\th02\snd_se_r.obj bin\th03\snd_se.obj bin\th03\snd_kaja.obj bin\th03\initmain.obj bin\th03\pi_load.obj bin\th03\inp_m_w.obj bin\hfliplut.obj th03\mrs.cpp th03\sprite16.cpp
$(CC) $(CFLAGS) $(LARGE_LFLAGS) -Z -DGAME=3 -nbin\th03\ -eMAIN.EXE @&&|
$**
|
bin\th03\mainl.exe: bin\th03\mainl.obj bin\th01\vplanset.obj bin\th02\snd_mode.obj bin\th02\snd_pmdr.obj bin\th02\snd_dlyv.obj bin\th02\snd_load.obj bin\th03\vector2.obj bin\th03\exit.obj bin\th03\cdg_put.obj bin\frmdely1.obj bin\th03\input_s.obj bin\th03\pi_put.obj bin\th03\pi_put_i.obj bin\th02\snd_se_r.obj bin\th03\snd_se.obj bin\th03\snd_kaja.obj bin\th03\initmain.obj bin\th03\cdg_load.obj th03\exitmain.cpp bin\th03\grppsafx.obj bin\th03\snd_dlym.obj bin\th03\inp_wait.obj bin\th03\pi_load.obj bin\th03\pi_put_q.obj bin\th03\inp_m_w.obj bin\th03\cdg_p_na.obj bin\hfliplut.obj
bin\th03\mainl.exe: bin\th03\mainl.obj bin\th03\cfg_lres.obj bin\th01\vplanset.obj bin\th02\snd_mode.obj bin\th02\snd_pmdr.obj bin\th02\snd_dlyv.obj bin\th02\snd_load.obj bin\th03\vector2.obj bin\th03\exit.obj bin\th03\cdg_put.obj bin\frmdely1.obj bin\th03\input_s.obj bin\th03\pi_put.obj bin\th03\pi_put_i.obj bin\th02\snd_se_r.obj bin\th03\snd_se.obj bin\th03\snd_kaja.obj bin\th03\initmain.obj bin\th03\cdg_load.obj th03\exitmain.cpp bin\th03\grppsafx.obj bin\th03\snd_dlym.obj bin\th03\inp_wait.obj bin\th03\pi_load.obj bin\th03\pi_put_q.obj bin\th03\inp_m_w.obj bin\th03\cdg_p_na.obj bin\hfliplut.obj
$(CC) $(CFLAGS) $(LARGE_LFLAGS) -DGAME=3 -nbin\th03\ -eMAINL.EXE @&&|
$**
|
@ -138,12 +138,12 @@ bin\th04\op.exe: bin\th04\op.obj th04\m_char.cpp bin\th01\vplanset.obj bin\frmde
$**
|
bin\th04\main.exe: bin\th04\main.obj bin\th04\scoreupd.obj th04\main011.cpp bin\th01\vplanset.obj bin\th03\vector2.obj bin\frmdely1.obj bin\hfliplut.obj th04\mpn_free.cpp bin\th04\input_w.obj th04\mpn_l_i.cpp bin\th04\vector.obj bin\th04\snd_pmdr.obj bin\th04\snd_mmdr.obj bin\th04\snd_kaja.obj bin\th04\snd_mode.obj bin\th04\snd_load.obj bin\th04\cdg_put.obj bin\th04\exit.obj bin\th04\initmain.obj bin\th04\cdg_p_na.obj bin\th04\cdg_p_pr.obj bin\th04\input_s.obj bin\th04\snd_se_r.obj bin\th04\snd_se.obj bin\th04\cdg_load.obj th04\main032.cpp
bin\th04\main.exe: bin\th04\main.obj bin\th04\scoreupd.obj th04\main011.cpp bin\th04\cfg_lres.obj bin\th01\vplanset.obj bin\th03\vector2.obj bin\frmdely1.obj bin\hfliplut.obj th04\mpn_free.cpp bin\th04\input_w.obj th04\mpn_l_i.cpp bin\th04\vector.obj bin\th04\snd_pmdr.obj bin\th04\snd_mmdr.obj bin\th04\snd_kaja.obj bin\th04\snd_mode.obj bin\th04\snd_load.obj bin\th04\cdg_put.obj bin\th04\exit.obj bin\th04\initmain.obj bin\th04\cdg_p_na.obj bin\th04\cdg_p_pr.obj bin\th04\input_s.obj bin\th04\snd_se_r.obj bin\th04\snd_se.obj bin\th04\cdg_load.obj th04\main032.cpp
$(CC) $(CFLAGS) $(LARGE_LFLAGS) -DGAME=4 -DBINARY='M' -3 -Z -nbin\th04\ -eMAIN.EXE @&&|
$**
|
bin\th04\maine.exe: bin\th04\maine.obj th04\maine011.cpp bin\th01\vplanset.obj bin\frmdely1.obj bin\th03\pi_put.obj bin\th04\cdg_put.obj bin\th04\exit.obj bin\th04\initmain.obj bin\th04\input_s.obj bin\th04\snd_se_r.obj bin\th04\snd_se.obj bin\th04\bgimage.obj bin\th04\bgimager.obj bin\th03\pi_load.obj bin\th03\pi_put_q.obj bin\th04\cdg_load.obj bin\hfliplut.obj bin\th04\input_w.obj bin\th04\vector.obj bin\th04\snd_pmdr.obj bin\th04\snd_mmdr.obj bin\th04\snd_kaja.obj bin\th04\snd_mode.obj bin\th04\snd_dlym.obj bin\th04\cdg_p_pl.obj bin\th04\snd_load.obj
bin\th04\maine.exe: bin\th04\maine.obj bin\th04\cfg_lres.obj th04\maine011.cpp bin\th01\vplanset.obj bin\frmdely1.obj bin\th03\pi_put.obj bin\th04\cdg_put.obj bin\th04\exit.obj bin\th04\initmain.obj bin\th04\input_s.obj bin\th04\snd_se_r.obj bin\th04\snd_se.obj bin\th04\bgimage.obj bin\th04\bgimager.obj bin\th03\pi_load.obj bin\th03\pi_put_q.obj bin\th04\cdg_load.obj bin\hfliplut.obj bin\th04\input_w.obj bin\th04\vector.obj bin\th04\snd_pmdr.obj bin\th04\snd_mmdr.obj bin\th04\snd_kaja.obj bin\th04\snd_mode.obj bin\th04\snd_dlym.obj bin\th04\cdg_p_pl.obj bin\th04\snd_load.obj
$(CC) $(CFLAGS) $(LARGE_LFLAGS) -DGAME=4 -DBINARY='E' -Z -nbin\th04\ -eMAINE.EXE @&&|
$**
|
@ -161,12 +161,12 @@ bin\th05\op.exe: th05\op010.cpp bin\th05\op.obj th05\op011.cpp th05\m_char.cpp b
$**
|
bin\th05\main.exe: bin\th05\main.obj th05\main010.cpp th05\main011.cpp th05\p_common.cpp th05\p_reimu.cpp th05\p_marisa.cpp th05\p_mima.cpp th05\p_yuuka.cpp bin\th05\player.obj bin\th05\hud_bar.obj bin\th05\scoreupd.obj th05\main012.cpp th05\main013.cpp bin\th03\vector2.obj bin\hfliplut.obj bin\th04\snd_pmdr.obj bin\th04\snd_mmdr.obj bin\th04\snd_mode.obj bin\th05\bullet.obj bin\th04\cdg_p_na.obj bin\th04\snd_se_r.obj bin\th04\snd_se.obj bin\th05\cdg_put.obj bin\th04\exit.obj bin\th05\vector.obj bin\th05\snd_load.obj bin\th05\snd_kaja.obj bin\th05\initmain.obj bin\th05\input_s.obj bin\th05\inp_h_w.obj bin\th05\frmdelay.obj bin\th04\cdg_load.obj th05\main031.cpp th05\main032.cpp th05\main033.cpp th05\main034.cpp
bin\th05\main.exe: bin\th05\main.obj bin\th05\cfg_lres.obj th05\main010.cpp th05\main011.cpp th05\p_common.cpp th05\p_reimu.cpp th05\p_marisa.cpp th05\p_mima.cpp th05\p_yuuka.cpp bin\th05\player.obj bin\th05\hud_bar.obj bin\th05\scoreupd.obj th05\main012.cpp th05\main013.cpp bin\th03\vector2.obj bin\hfliplut.obj bin\th04\snd_pmdr.obj bin\th04\snd_mmdr.obj bin\th04\snd_mode.obj bin\th05\bullet.obj bin\th04\cdg_p_na.obj bin\th04\snd_se_r.obj bin\th04\snd_se.obj bin\th05\cdg_put.obj bin\th04\exit.obj bin\th05\vector.obj bin\th05\snd_load.obj bin\th05\snd_kaja.obj bin\th05\initmain.obj bin\th05\input_s.obj bin\th05\inp_h_w.obj bin\th05\frmdelay.obj bin\th04\cdg_load.obj th05\main031.cpp th05\main032.cpp th05\main033.cpp th05\main034.cpp
$(CC) $(CFLAGS) $(LARGE_LFLAGS) -3 -Z -DGAME=5 -DBINARY='M' -nbin\th05\ -eMAIN.EXE @&&|
$**
|
bin\th05\maine.exe: bin\th05\maine.obj th05\maine011.cpp th05\regist.cpp th05\staff.cpp bin\th04\cdg_p_na.obj bin\th04\snd_se_r.obj bin\th04\snd_se.obj bin\th04\bgimage.obj bin\th04\exit.obj bin\th05\vector.obj bin\th05\bgimager.obj bin\th05\snd_load.obj bin\th05\snd_kaja.obj bin\th05\pi_cpp_1.obj bin\th05\pi_asm_1.obj bin\th05\pi_cpp_2.obj bin\th05\pi_asm_2.obj bin\th05\initmain.obj bin\th05\input_s.obj bin\th05\inp_h_w.obj bin\th05\snd_dlym.obj bin\th05\frmdelay.obj bin\th04\cdg_load.obj bin\th05\egcrect.obj bin\hfliplut.obj bin\th04\snd_pmdr.obj bin\th04\snd_mmdr.obj bin\th04\snd_mode.obj
bin\th05\maine.exe: bin\th05\maine.obj bin\th04\cfg_lres.obj th05\maine011.cpp th05\regist.cpp th05\staff.cpp bin\th04\cdg_p_na.obj bin\th04\snd_se_r.obj bin\th04\snd_se.obj bin\th04\bgimage.obj bin\th04\exit.obj bin\th05\vector.obj bin\th05\bgimager.obj bin\th05\snd_load.obj bin\th05\snd_kaja.obj bin\th05\pi_cpp_1.obj bin\th05\pi_asm_1.obj bin\th05\pi_cpp_2.obj bin\th05\pi_asm_2.obj bin\th05\initmain.obj bin\th05\input_s.obj bin\th05\inp_h_w.obj bin\th05\snd_dlym.obj bin\th05\frmdelay.obj bin\th04\cdg_load.obj bin\th05\egcrect.obj bin\hfliplut.obj bin\th04\snd_pmdr.obj bin\th04\snd_mmdr.obj bin\th04\snd_mode.obj
$(CC) $(CFLAGS) $(LARGE_LFLAGS) -DGAME=5 -DBINARY='E' -Z -nbin\th05\ -eMAINE.EXE @&&|
$**
|

10
th03/cfg_lres.cpp Normal file
View File

@ -0,0 +1,10 @@
extern "C" {
#include "platform.h"
#include "master.hpp"
#include "th03/common.h"
#include "th03/chars.hpp"
#include "th03/score.h"
#include "th03/resident.hpp"
#include "th03/formats/cfg.hpp"
#include "th03/formats/cfg_lres.cpp"
}

View File

@ -19,13 +19,16 @@ void near pascal cfg_load(void);
// value.
resident_t __seg* near cfg_load_resident_ptr(void);
static inline void cfg_load_and_set_resident(cfg_t &cfg, const char *cfg_fn) {
static inline resident_t __seg* cfg_load_and_set_resident(
cfg_t &cfg, const char *cfg_fn
) {
file_ropen(cfg_fn);
file_read(&cfg, sizeof(cfg));
file_close();
resident_t __seg *resident_seg = cfg.resident;
resident = resident_seg;
return resident_seg;
}
// Saves the .CFG file, without changing its resident segment pointer.

View File

@ -1,22 +0,0 @@
public _cfg_load_resident_ptr
_cfg_load_resident_ptr proc near
@@cfg = cfg_t ptr -(size cfg_t)
enter (size cfg_t), 0
push si
call file_ropen pascal, ds, offset _CFG_FN
push ss
lea ax, [bp+@@cfg]
push ax
push size cfg_t
call file_read
call file_close
mov si, [bp+@@cfg.resident_sgm]
mov word ptr _resident+2, si
mov word ptr _resident, 0
mov ax, si
pop si
leave
retn
_cfg_load_resident_ptr endp

View File

@ -0,0 +1,7 @@
resident_t __seg* near cfg_load_resident_ptr(void)
{
#undef CFG_FN
extern const char CFG_FN[];
cfg_t cfg;
return cfg_load_and_set_resident(cfg, CFG_FN);
}

View File

@ -27,6 +27,8 @@ include libs/sprite16/sprite16.inc
extern _execl:proc
.seq
main_01 group main_0_TEXT, CFG_LRES_TEXT, main_01_TEXT
; ===========================================================================
; Segment type: Pure code
@ -129,8 +131,8 @@ _TEXT ends
; ===========================================================================
; Segment type: Pure code
main_01_TEXT segment word public 'CODE' use16
assume cs:main_01_TEXT
main_0_TEXT segment word public 'CODE' use16
assume cs:main_01
;org 5
assume es:nothing, ss:nothing, ds:_DATA, fs:nothing, gs:nothing
@ -1403,8 +1405,13 @@ sub_A310 endp
; ---------------------------------------------------------------------------
nop
include th03/formats/cfg_lres.asm
db 0
main_0_TEXT ends
CFG_LRES_TEXT segment byte public 'CODE' use16
_cfg_load_resident_ptr procdesc near
CFG_LRES_TEXT ends
main_01_TEXT segment word public 'CODE' use16
; =============== S U B R O U T I N E =======================================

View File

@ -28,6 +28,8 @@ include th01/hardware/grppsafx.inc
extern _memcpy:proc
extern _tolower:proc
mainl_01 group CFG_LRES_TEXT, mainl_01_TEXT
; ===========================================================================
; Segment type: Pure code
@ -129,14 +131,16 @@ _TEXT ends
; ===========================================================================
CFG_LRES_TEXT segment byte public 'CODE' use16
_cfg_load_resident_ptr procdesc near
CFG_LRES_TEXT ends
; Segment type: Pure code
mainl_01_TEXT segment byte public 'CODE' use16
assume cs:mainl_01_TEXT
assume cs:mainl_01
;org 3
assume es:nothing, ss:nothing, ds:_DATA, fs:nothing, gs:nothing
include th03/formats/cfg_lres.asm
; =============== S U B R O U T I N E =======================================
; Attributes: bp-based frame

8
th04/cfg_lres.cpp Normal file
View File

@ -0,0 +1,8 @@
extern "C" {
#include "platform.h"
#include "master.hpp"
#include "th04/score.h"
#include "th04/resident.hpp"
#include "th04/formats/cfg.hpp"
#include "th03/formats/cfg_lres.cpp"
}

View File

@ -44,7 +44,7 @@ include th04/main/enemy/enemy.inc
extern __ctype:byte
.seq
main_01 group main_0_TEXT, main_01_TEXT, main_012_TEXT
main_01 group main_0_TEXT, main_01_TEXT, main_012_TEXT, CFG_LRES_TEXT, main_013_TEXT
g_SHARED group SHARED, SHARED_
main_03 group main_032_TEXT, main_033_TEXT
@ -10777,9 +10777,13 @@ sub_11ECB proc near
pop bp
retn
sub_11ECB endp
main_012_TEXT ends
include th03/formats/cfg_lres.asm
db 0
CFG_LRES_TEXT segment byte public 'CODE' use16
_cfg_load_resident_ptr procdesc near
CFG_LRES_TEXT ends
main_013_TEXT segment word public 'CODE' use16
include th04/main/tile/bb_put.asm
; =============== S U B R O U T I N E =======================================
@ -12813,8 +12817,7 @@ loc_130E9:
leave
retn
gengetsu_fg_render endp
main_012_TEXT ends
main_013_TEXT ends
; ===========================================================================

View File

@ -27,7 +27,7 @@ include th04/hardware/grppsafx.inc
extern _tolower:proc
extern __ctype:byte
maine_01 group maine_01_TEXT, maine_01__TEXT
maine_01 group CFG_LRES_TEXT, maine_01_TEXT, maine_01__TEXT
g_SHARED group SHARED, SHARED_
; ===========================================================================
@ -148,14 +148,16 @@ _TEXT ends
; ===========================================================================
CFG_LRES_TEXT segment byte public 'CODE' use16
_cfg_load_resident_ptr procdesc near
CFG_LRES_TEXT ends
; Segment type: Pure code
maine_01_TEXT segment byte public 'CODE' use16
assume cs:maine_01
;org 9
assume es:nothing, ss:nothing, ds:_DATA, fs:nothing, gs:nothing
include th03/formats/cfg_lres.asm
; =============== S U B R O U T I N E =======================================
; Attributes: bp-based frame

1
th05/cfg_lres.cpp Normal file
View File

@ -0,0 +1 @@
#include "th05/formats/cfg_lres.cpp"

View File

@ -1,24 +0,0 @@
public _cfg_load_resident_ptr
_cfg_load_resident_ptr proc near
mov ax, 3D00h
mov dx, offset _CFG_FN
int 21h ; DOS - 2+ - OPEN DISK FILE WITH HANDLE
; DS:DX -> ASCIZ filename
; AL = access mode
; 0 - read
mov bx, ax
mov ah, 3Fh
mov dx, offset _cfg
mov cx, size cfg_t
int 21h ; DOS - 2+ - READ FROM FILE WITH HANDLE
; BX = file handle, CX = number of bytes to read
; DS:DX -> buffer
mov ah, 3Eh
int 21h ; DOS - 2+ - CLOSE A FILE WITH HANDLE
; BX = file handle
mov ax, _cfg.resident_sgm
mov word ptr _resident+2, ax
mov word ptr _resident, 0
retn
_cfg_load_resident_ptr endp
nop

39
th05/formats/cfg_lres.cpp Normal file
View File

@ -0,0 +1,39 @@
#pragma option -k-
extern "C" {
#include "platform.h"
#include "x86real.h"
#include "master.hpp"
#include "th04/common.h"
#include "th04/score.h"
#include "th05/resident.hpp"
#include "th04/formats/cfg.hpp"
resident_t __seg* near cfg_load_resident_ptr(void)
{
#undef CFG_FN
extern const char CFG_FN[];
extern cfg_t cfg;
// DOS file open
_AX = 0x3D00;
reinterpret_cast<const char near *>(_DX) = CFG_FN;
geninterrupt(0x21);
_BX = _AX;
// DOS file read
_AH = 0x3F;
reinterpret_cast<cfg_t near *>(_DX) = &cfg;
_CX = sizeof(cfg);
geninterrupt(0x21);
// DOS file close
_AH = 0x3E;
geninterrupt(0x21);
resident = cfg.resident;
return cfg.resident;
}
#pragma codestring "\x90"
}

View File

@ -37,7 +37,7 @@ include th05/main/enemy/enemy.inc
extern _strlen:proc
.seq
main_01 group main_TEXT, main__TEXT, main_0_TEXT, main_01_TEXT
main_01 group mai_TEXT, CFG_LRES_TEXT, main_TEXT, main__TEXT, main_0_TEXT, main_01_TEXT
g_SHARED group SHARED, SHARED_
main_03 group main_031_TEXT, main_032_TEXT, main_033_TEXT, main_034_TEXT, main_035_TEXT
@ -312,7 +312,7 @@ _TEXT ends
; ===========================================================================
; Segment type: Pure code
main_TEXT segment word public 'CODE' use16
mai_TEXT segment word public 'CODE' use16
assume cs:main_01
;org 0Dh
assume es:nothing, ss:nothing, ds:_DATA, fs:nothing, gs:nothing
@ -1526,8 +1526,13 @@ loc_BAAA:
pop bp
retn
sub_BA66 endp
mai_TEXT ends
include th05/formats/cfg_lres.asm
CFG_LRES_TEXT segment byte public 'CODE' use16
_cfg_load_resident_ptr procdesc near
CFG_LRES_TEXT ends
main_TEXT segment word public 'CODE' use16
; =============== S U B R O U T I N E =======================================

View File

@ -27,7 +27,7 @@ include th04/hardware/grppsafx.inc
extern _tolower:proc
extern __ctype:byte
maine_01 group maine_01_TEXT, maine_01__TEXT, maine_01___TEXT
maine_01 group CFG_LRES_TEXT, maine_01_TEXT, maine_01__TEXT, maine_01___TEXT
g_SHARED group SHARED, SHARED_
; ===========================================================================
@ -154,14 +154,16 @@ _TEXT ends
; ===========================================================================
CFG_LRES_TEXT segment byte public 'CODE' use16
_cfg_load_resident_ptr procdesc near
CFG_LRES_TEXT ends
; Segment type: Pure code
maine_01_TEXT segment byte public 'CODE' use16
assume cs:maine_01
;org 5
assume es:nothing, ss:nothing, ds:_DATA, fs:nothing, gs:nothing
include th03/formats/cfg_lres.asm
; =============== S U B R O U T I N E =======================================
; Attributes: bp-based frame