From 7761f4e804979123f8f6223c5078c921e9ecbf4d Mon Sep 17 00:00:00 2001 From: nmlgc Date: Wed, 28 Apr 2021 18:35:37 +0200 Subject: [PATCH] [Decompilation] [th04] snd_kaja_interrupt() 4 games, 4 different versions of this function. Interestingly, moving the game-specific differences to inline functions makes it obvious that this function was only intended for BGM, not sound effects. Part of P0139, funded by [Anonymous]. --- Makefile.mak | 6 +++--- th02/snd/{kajaint.c => kajaint.cpp} | 13 ++++++++++--- th02/snd_kaja.c | 1 - th02/snd_kaja.cpp | 1 + th03/snd_kaja.c | 1 - th03/snd_kaja.cpp | 1 + th04/snd/kajaint.asm | 21 --------------------- th04/snd_kaja.cpp | 1 + th04_main.asm | 2 +- th04_maine.asm | 2 +- th04_op.asm | 2 +- 11 files changed, 19 insertions(+), 32 deletions(-) rename th02/snd/{kajaint.c => kajaint.cpp} (57%) delete mode 100644 th02/snd_kaja.c create mode 100644 th02/snd_kaja.cpp delete mode 100644 th03/snd_kaja.c create mode 100644 th03/snd_kaja.cpp delete mode 100644 th04/snd/kajaint.asm create mode 100644 th04/snd_kaja.cpp diff --git a/Makefile.mak b/Makefile.mak index 28642333..6fc5e707 100644 --- a/Makefile.mak +++ b/Makefile.mak @@ -133,17 +133,17 @@ bin\th04\res_huma.com: th04\res_huma.cpp $** | masters.lib -bin\th04\op.exe: bin\th04\op.obj th04\m_char.cpp bin\th01\vplanset.obj bin\frmdely1.obj bin\th03\pi_put.obj bin\th03\pi_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\cdg_put.obj bin\th04\exit.obj bin\th04\initop.obj bin\th04\cdg_p_na.obj bin\th04\input_s.obj bin\th04\snd_se_r.obj bin\th04\snd_se.obj bin\th04\egcrect.obj bin\th04\bgimage.obj bin\th04\bgimager.obj bin\th04\cdg_load.obj th04\frmdely2.c +bin\th04\op.exe: bin\th04\op.obj th04\m_char.cpp bin\th01\vplanset.obj bin\frmdely1.obj bin\th03\pi_put.obj bin\th03\pi_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\cdg_put.obj bin\th04\exit.obj bin\th04\initop.obj bin\th04\cdg_p_na.obj bin\th04\input_s.obj bin\th04\snd_se_r.obj bin\th04\snd_se.obj bin\th04\egcrect.obj bin\th04\bgimage.obj bin\th04\bgimager.obj bin\th04\cdg_load.obj th04\frmdely2.c $(CC) $(CFLAGS) $(LARGE_LFLAGS) -DGAME=4 -DBINARY='O' -3 -Z -d -nbin\th04\ -eOP.EXE @&&| $** | -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\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\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\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\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 $(CC) $(CFLAGS) $(LARGE_LFLAGS) -DGAME=4 -DBINARY='E' -Z -nbin\th04\ -eMAINE.EXE @&&| $** | diff --git a/th02/snd/kajaint.c b/th02/snd/kajaint.cpp similarity index 57% rename from th02/snd/kajaint.c rename to th02/snd/kajaint.cpp index 6ceaee1f..737a6469 100644 --- a/th02/snd/kajaint.c +++ b/th02/snd/kajaint.cpp @@ -1,15 +1,20 @@ #pragma option -zCSHARED +extern "C" { #include "platform.h" #include "x86real.h" #include "libs/kaja/kaja.h" -#include "th02/snd/snd.h" +#if (GAME >= 4) + #include "th04/snd/snd.h" +#else + #include "th02/snd/snd.h" +#endif int16_t DEFCONV snd_kaja_interrupt(int16_t ax) { - if(snd_active) { + if(snd_bgm_active()) { _AX = ax; - if(snd_midi_active != true) { + if(snd_bgm_is_fm()) { geninterrupt(PMD); } else { geninterrupt(MMD); @@ -17,3 +22,5 @@ int16_t DEFCONV snd_kaja_interrupt(int16_t ax) } return _AX; } + +} diff --git a/th02/snd_kaja.c b/th02/snd_kaja.c deleted file mode 100644 index eb402374..00000000 --- a/th02/snd_kaja.c +++ /dev/null @@ -1 +0,0 @@ -#include "th02/snd/kajaint.c" diff --git a/th02/snd_kaja.cpp b/th02/snd_kaja.cpp new file mode 100644 index 00000000..093f721a --- /dev/null +++ b/th02/snd_kaja.cpp @@ -0,0 +1 @@ +#include "th02/snd/kajaint.cpp" diff --git a/th03/snd_kaja.c b/th03/snd_kaja.c deleted file mode 100644 index eb402374..00000000 --- a/th03/snd_kaja.c +++ /dev/null @@ -1 +0,0 @@ -#include "th02/snd/kajaint.c" diff --git a/th03/snd_kaja.cpp b/th03/snd_kaja.cpp new file mode 100644 index 00000000..093f721a --- /dev/null +++ b/th03/snd_kaja.cpp @@ -0,0 +1 @@ +#include "th02/snd/kajaint.cpp" diff --git a/th04/snd/kajaint.asm b/th04/snd/kajaint.asm deleted file mode 100644 index 2b6af1bb..00000000 --- a/th04/snd/kajaint.asm +++ /dev/null @@ -1,21 +0,0 @@ -public SND_KAJA_INTERRUPT -snd_kaja_interrupt proc - arg @@ax:word - - push bp - mov bp, sp - cmp _snd_bgm_mode, SND_BGM_OFF - jz short @@ret - mov ax, @@ax - cmp _snd_bgm_mode, SND_BGM_MIDI - jz short @@midi - int 60h - jmp short @@ret - -@@midi: - int 61h - -@@ret: - pop bp - ret 2 -snd_kaja_interrupt endp diff --git a/th04/snd_kaja.cpp b/th04/snd_kaja.cpp new file mode 100644 index 00000000..093f721a --- /dev/null +++ b/th04/snd_kaja.cpp @@ -0,0 +1 @@ +#include "th02/snd/kajaint.cpp" diff --git a/th04_main.asm b/th04_main.asm index 0f369133..70b9d366 100644 --- a/th04_main.asm +++ b/th04_main.asm @@ -12980,10 +12980,10 @@ SHARED segment word public 'CODE' use16 extern VECTOR2_AT:proc extern _snd_pmd_resident:proc extern _snd_mmd_resident:proc + extern SND_KAJA_INTERRUPT:proc SHARED ends SHARED_ segment word public 'CODE' use16 -include th04/snd/kajaint.asm include th04/snd/detmodes.asm include th04/snd/load.asm extern CDG_PUT_8:proc diff --git a/th04_maine.asm b/th04_maine.asm index 7604a532..c659ffeb 100644 --- a/th04_maine.asm +++ b/th04_maine.asm @@ -4590,13 +4590,13 @@ SHARED segment word public 'CODE' use16 extern VECTOR1_AT:proc extern _snd_pmd_resident:proc extern _snd_mmd_resident:proc + extern SND_KAJA_INTERRUPT:proc SHARED ends SHARED_ segment word public 'CODE' use16 assume cs:g_SHARED assume es:nothing, ss:nothing, ds:_DATA, fs:nothing, gs:nothing -include th04/snd/kajaint.asm include th04/snd/detmodes.asm include th03/snd/delaymea.asm db 0 diff --git a/th04_op.asm b/th04_op.asm index 625d040b..f90b45ff 100644 --- a/th04_op.asm +++ b/th04_op.asm @@ -2641,13 +2641,13 @@ SHARED segment word public 'CODE' use16 extern VECTOR1_AT:proc extern _snd_pmd_resident:proc extern _snd_mmd_resident:proc + extern SND_KAJA_INTERRUPT:proc SHARED ends SHARED_ segment word public 'CODE' use16 assume cs:g_SHARED assume es:nothing, ss:nothing, ds:_DATA, fs:nothing, gs:nothing -include th04/snd/kajaint.asm include th04/formats/cdg_put_nocolors.asm include th04/snd/detmodes.asm include th03/snd/delaymea.asm