[Decompilation] [th05] snd_bgm_measure(), snd_delay_until_measure()

Umm… but this can't be in the same translation unit as frame_delay(),
because OP.EXE has cdg_put_nocolors() inbetween, which means we'd have
to compile it twice.

What probably happened there: ZUN originally wrote this in C when
frame_delay() was still next to it, then generated ASM from it,
tinkered with that, and ultimately only linked that ASM into the final
game, with the NOPCALL still in there. That might very well be the one
temporary NOPCALL workaround we can never get rid of…

Oh well, at least we got lucky with the padding, and can keep the
cdg_put_nocolors() decompilation from the last commit.

Part of P0133, funded by [Anonymous].
This commit is contained in:
nmlgc 2021-01-08 19:20:04 +01:00
parent c8160b9f94
commit 4229054137
11 changed files with 48 additions and 72 deletions

View File

@ -150,7 +150,7 @@ bin\th05\res_kso.com: th05\res_kso.cpp
$**
| masters.lib
bin\th05\op.exe: th05\op010.cpp bin\th05\op.obj th05\op011.cpp th05\m_char.cpp th05\cdg_p_nc.cpp bin\th05\frmdelay.obj bin\th04\cdg_load.obj bin\th05\egcrect.obj bin\hfliplut.obj
bin\th05\op.exe: th05\op010.cpp bin\th05\op.obj th05\op011.cpp th05\m_char.cpp bin\th05\snd_dlym.obj th05\cdg_p_nc.cpp bin\th05\frmdelay.obj bin\th04\cdg_load.obj bin\th05\egcrect.obj bin\hfliplut.obj
$(CC) $(CFLAGS) -ml -DGAME=5 -DBINARY='O' -3 -Z -nbin\th05\ -eOP.EXE @&&|
$**
|
@ -160,7 +160,7 @@ bin\th05\main.exe: bin\th05\main.obj th05\main010.cpp th05\main011.cpp th05\p_co
$**
|
bin\th05\maine.exe: bin\th05\maine.obj th05\maine011.cpp th05\regist.cpp th05\staff.cpp bin\th05\frmdelay.obj bin\th04\cdg_load.obj bin\th05\egcrect.obj bin\hfliplut.obj
bin\th05\maine.exe: bin\th05\maine.obj th05\maine011.cpp th05\regist.cpp th05\staff.cpp bin\th05\snd_dlym.obj bin\th05\frmdelay.obj bin\th04\cdg_load.obj bin\th05\egcrect.obj bin\hfliplut.obj
$(CC) $(CFLAGS) -ml -DGAME=5 -DBINARY='E' -Z -nbin\th05\ -eMAINE.EXE @&&|
$**
|

View File

@ -12,9 +12,7 @@ extern "C" {
#endif
#include "th02/snd/measure.hpp"
void pascal snd_delay_until_measure(
unsigned int measure, unsigned int frames_if_no_bgm
)
void pascal snd_delay_until_measure(int measure, unsigned int frames_if_no_bgm)
{
if(!snd_is_active()) {
frame_delay(frames_if_no_bgm);

View File

@ -1,6 +1,4 @@
#include "th02/snd/snd.h"
// Adds a customizable delay to the TH02 version.
void pascal snd_delay_until_measure(
unsigned int measure, unsigned int frames_if_no_bgm
);
void pascal snd_delay_until_measure(int measure, unsigned int frames_if_no_bgm);

View File

@ -1,4 +1,4 @@
#include "th02/snd/snd.h"
#include "th03/snd/snd.h"
typedef enum {
SND_BGM_OFF = 0,

View File

@ -321,8 +321,7 @@ endif
@@more_pyros?:
cmp si, ZUNSOFT_PYRO_COUNT
jl short @@next_pyro
push (2 shl 16)
call snd_delay_until_measure
call snd_delay_until_measure pascal, (2 shl 16)
mov PaletteTone, 100
call palette_show
call super_entry_bfnt pascal, ds, offset aZun02_bft

View File

@ -1,29 +0,0 @@
public SND_DELAY_UNTIL_MEASURE
snd_delay_until_measure proc far
@@frames_if_no_bgm = word ptr 6
@@measure = word ptr 8
push bp
mov bp, sp
push si
@@retry:
call _snd_bgm_measure
mov si, ax
or si, si
jge short @@reached?
push [bp+@@frames_if_no_bgm]
nopcall frame_delay
jmp short @@ret
@@reached?:
cmp si, [bp+@@measure]
jl short @@retry
@@ret:
pop si
pop bp
retf 4
snd_delay_until_measure endp
db 0

37
th05/snd/delaymea.cpp Normal file
View File

@ -0,0 +1,37 @@
#pragma codeseg SHARED_
extern "C" {
#include <dos.h>
#include "platform.h"
#include "libs/kaja/kaja.h"
#include "th02/hardware/frmdelay.h"
#include "th05/snd/snd.h"
#include "th02/snd/measure.hpp"
}
int snd_bgm_measure(void)
{
if(!snd_is_active()) {
return -1;
}
return snd_get_song_measure();
}
void pascal snd_delay_until_measure(int measure, unsigned int frames_if_no_bgm)
{
int measure_cur;
do {
measure_cur = snd_bgm_measure();
if(measure_cur < 0) {
/* TODO: Replace with the decompiled call
* frame_delay(frames_if_no_bgm);
* once the segmentation allows us to, if ever */
__asm {
push frames_if_no_bgm; nop; push cs; call near ptr frame_delay;
}
return;
}
} while(measure_cur < measure);
}
#pragma codestring "\x00"

View File

@ -1,25 +0,0 @@
public _snd_bgm_measure
_snd_bgm_measure proc far
push bp
mov bp, sp
cmp _snd_bgm_mode, SND_BGM_OFF
jnz short @@BGM_is_active
mov ax, -1
pop bp
retf
@@BGM_is_active:
mov ah, KAJA_GET_SONG_MEASURE
cmp _snd_bgm_mode, SND_BGM_MIDI
jz short @@MIDI_is_active
int PMD
jmp short @@ret
@@MIDI_is_active:
mov dx, MMD_TICKS_PER_QUARTER_NOTE * 4
int MMD
@@ret:
pop bp
retf
_snd_bgm_measure endp

1
th05/snd_dlym.cpp Normal file
View File

@ -0,0 +1 @@
#include "th05/snd/delaymea.cpp"

View File

@ -831,9 +831,7 @@ loc_AB4A:
call sub_A7FE
cmp byte_14F8E, 0
jnz loc_AF8F ; default
push [bp+var_2]
push [bp+var_4]
call snd_delay_until_measure
call snd_delay_until_measure pascal, [bp+var_2], [bp+var_4]
jmp loc_AF8F ; default
; ---------------------------------------------------------------------------
@ -7549,8 +7547,8 @@ include th02/initmain.asm
include th04/hardware/input_sense.asm
include th05/hardware/input_held.asm
include th05/hardware/input_wait.asm
include th05/snd/measure.asm
include th05/snd/delaymea.asm
extern _snd_bgm_measure:proc
extern SND_DELAY_UNTIL_MEASURE:proc
extern FRAME_DELAY:proc
extern CDG_LOAD_ALL_NOALPHA:proc
extern CDG_FREE_ALL:proc

View File

@ -2552,8 +2552,7 @@ include th02/initop.asm
include th04/hardware/input_sense.asm
include th05/hardware/input_held.asm
include th05/hardware/input_wait.asm
include th05/snd/measure.asm
include th05/snd/delaymea.asm
extern SND_DELAY_UNTIL_MEASURE:proc
extern CDG_PUT_NOCOLORS_8:proc
extern FRAME_DELAY:proc
extern CDG_LOAD_SINGLE_NOALPHA:proc