From cdbd621f9144c226927d67da2125c696936e0550 Mon Sep 17 00:00:00 2001 From: nmlgc Date: Thu, 28 Jan 2021 20:34:05 +0100 Subject: [PATCH] [Separate translation units] [th02] snd_determine_mode() Perfectly decompilable with pseudo-registers. Why did I decide against them in 2015? Part of P0133, funded by [Anonymous]. --- Makefile.mak | 6 +++--- th02/main02_2.cpp | 1 - th02/maine022.cpp | 1 - th02/op_02_2.cpp | 1 - th02/snd/detmode.c | 40 ++++++++++++++++++++++++---------------- th02/snd/snd.h | 6 +++++- th02/snd_mode.c | 1 + 7 files changed, 33 insertions(+), 23 deletions(-) create mode 100644 th02/snd_mode.c diff --git a/Makefile.mak b/Makefile.mak index 4780d2e8..e8bd8e5e 100644 --- a/Makefile.mak +++ b/Makefile.mak @@ -78,17 +78,17 @@ bin\th02\zun_res.com: th02\zun_res1.c th02\zun_res2.c th02\zun_res3.c $** | masters.lib -bin\th02\op.exe: th02\op_01.cpp bin\exit_dos.obj bin\th02\zunerror.obj bin\th02\grppsafx.obj bin\th02\op.obj th02\op_02_1.cpp bin\th02\pi_load.obj bin\th02\grp_rect.obj bin\frmdely2.obj th02\op_02_2.cpp bin\th02\snd_pmdr.obj bin\th02\snd_load.obj bin\th02\pi_put.obj bin\th02\snd_kaja.obj th02\op_02_3.cpp bin\th02\snd_se.obj bin\frmdely1.obj th02\op_03.cpp th02\op_04.cpp th02\op_05.cpp th02\op_06.cpp +bin\th02\op.exe: th02\op_01.cpp bin\exit_dos.obj bin\th02\zunerror.obj bin\th02\grppsafx.obj bin\th02\op.obj th02\op_02_1.cpp bin\th02\pi_load.obj bin\th02\grp_rect.obj bin\frmdely2.obj th02\op_02_2.cpp bin\th02\snd_mode.obj bin\th02\snd_pmdr.obj bin\th02\snd_load.obj bin\th02\pi_put.obj bin\th02\snd_kaja.obj th02\op_02_3.cpp bin\th02\snd_se.obj bin\frmdely1.obj th02\op_03.cpp th02\op_04.cpp th02\op_05.cpp th02\op_06.cpp $(CC) $(CFLAGS) -ml -Z -DGAME=2 -nbin\th02\ -eOP.EXE @&&| $** | -bin\th02\main.exe: bin\th02\main.obj bin\th02\zunerror.obj th02\main02_1.cpp bin\th02\pi_load.obj bin\th02\vector.obj bin\frmdely1.obj th02\main02_2.cpp bin\th02\snd_pmdr.obj bin\th02\snd_dlyv.obj bin\th02\snd_load.obj th02\mptn_i.cpp bin\th02\initmain.obj bin\th02\pi_put.obj bin\th02\snd_kaja.obj bin\th02\snd_dlym.obj bin\th02\snd_se.obj th02\main_03.cpp +bin\th02\main.exe: bin\th02\main.obj bin\th02\zunerror.obj th02\main02_1.cpp bin\th02\pi_load.obj bin\th02\vector.obj bin\frmdely1.obj th02\main02_2.cpp bin\th02\snd_mode.obj bin\th02\snd_pmdr.obj bin\th02\snd_dlyv.obj bin\th02\snd_load.obj th02\mptn_i.cpp bin\th02\initmain.obj bin\th02\pi_put.obj bin\th02\snd_kaja.obj bin\th02\snd_dlym.obj bin\th02\snd_se.obj th02\main_03.cpp $(CC) $(CFLAGS) -ml -Z -DGAME=2 -nbin\th02\ -eMAIN.EXE @&&| $** | -bin\th02\maine.exe: bin\th02\maine.obj bin\th02\grppsafx.obj th02\maine021.cpp bin\th02\pi_load.obj bin\frmdely1.obj th02\maine022.cpp bin\th02\snd_pmdr.obj bin\th02\snd_load.obj bin\th02\initmain.obj bin\th02\pi_put.obj bin\th02\snd_kaja.obj bin\th02\snd_dlym.obj th02\maine_03.c th02\maine_04.cpp th02\maine_05.cpp +bin\th02\maine.exe: bin\th02\maine.obj bin\th02\grppsafx.obj th02\maine021.cpp bin\th02\pi_load.obj bin\frmdely1.obj th02\maine022.cpp bin\th02\snd_mode.obj bin\th02\snd_pmdr.obj bin\th02\snd_load.obj bin\th02\initmain.obj bin\th02\pi_put.obj bin\th02\snd_kaja.obj bin\th02\snd_dlym.obj th02\maine_03.c th02\maine_04.cpp th02\maine_05.cpp $(CC) $(CFLAGS) -ml -3 -Z -DGAME=2 -nbin\th02\ -eMAINE.EXE @&&| $** | diff --git a/th02/main02_2.cpp b/th02/main02_2.cpp index e22ad832..0fdce99d 100644 --- a/th02/main02_2.cpp +++ b/th02/main02_2.cpp @@ -18,5 +18,4 @@ extern "C" { #include "th02/hardware/input.c" #include "th02/exit.c" #include "th02/snd/mmd_res.c" -#include "th02/snd/detmode.c" } diff --git a/th02/maine022.cpp b/th02/maine022.cpp index 5435e16e..dd3afe0f 100644 --- a/th02/maine022.cpp +++ b/th02/maine022.cpp @@ -21,5 +21,4 @@ extern const char pf_fn[] = PF_FN; #include "th02/hardware/input.c" #include "th02/exit.c" #include "th02/snd/mmd_res.c" -#include "th02/snd/detmode.c" } diff --git a/th02/op_02_2.cpp b/th02/op_02_2.cpp index 59f5ad14..0ff73369 100644 --- a/th02/op_02_2.cpp +++ b/th02/op_02_2.cpp @@ -29,5 +29,4 @@ const char pf_fn[] = PF_FN; #pragma codestring "\x00" #include "th02/snd/mmd_res.c" -#include "th02/snd/detmode.c" } diff --git a/th02/snd/detmode.c b/th02/snd/detmode.c index 9ced2988..4a14f371 100644 --- a/th02/snd/detmode.c +++ b/th02/snd/detmode.c @@ -1,16 +1,24 @@ -int snd_determine_mode(void) -{ - __asm mov ah, PMD_GET_DRIVER_VERSION; - __asm int PMD; - _BX = 0; - if(_AL != 0xFF) { - __asm inc bx; - snd_fm_possible = 1; - } else { - __asm mov bl, snd_midi_active; - } - __asm mov snd_active, bl; - return _BX; -} - -#pragma codestring "\x90" +#pragma codeseg SHARED +#pragma option -k- + +#include +#include "platform.h" +#include "libs/kaja/kaja.h" +#include "th02/snd/snd.h" + +bool16 snd_determine_mode(void) +{ + _AH = PMD_GET_DRIVER_VERSION; + geninterrupt(PMD); + _BX = false; + if(_AL != 0xFF) { + _BX++; + snd_fm_possible = true; + } else { + _BL = snd_midi_active; + } + snd_active = _BL; + return _BX; +} + +#pragma codestring "\x90" diff --git a/th02/snd/snd.h b/th02/snd/snd.h index a44aeeea..b1c525f8 100644 --- a/th02/snd/snd.h +++ b/th02/snd/snd.h @@ -31,7 +31,11 @@ bool16 snd_pmd_resident(void); int snd_mmd_resident(void); #endif -int snd_determine_mode(void); +// Checks whether an FM sound source is active, and sets [snd_fm_possible] +// and [snd_active]. In the absence of an FM source, [snd_active] is set to +// [snd_midi_active]. Returns the new value of [snd_active]. +bool16 snd_determine_mode(void); + int16_t DEFCONV snd_kaja_interrupt(int16_t ax); #define snd_kaja_func(func, param) snd_kaja_interrupt((func) << 8 | (param)) diff --git a/th02/snd_mode.c b/th02/snd_mode.c new file mode 100644 index 00000000..007e8f04 --- /dev/null +++ b/th02/snd_mode.c @@ -0,0 +1 @@ +#include "th02/snd/detmode.c"