[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].
2021-01-08 18:20:04 +00:00
|
|
|
#include "th03/snd/snd.h"
|
2020-02-22 16:59:46 +00:00
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
SND_BGM_OFF = 0,
|
|
|
|
SND_BGM_FM26 = 1,
|
|
|
|
SND_BGM_FM86 = 2,
|
|
|
|
SND_BGM_MODE_COUNT = 3,
|
|
|
|
SND_BGM_MIDI = 3, // unsupported
|
2021-05-01 09:25:57 +00:00
|
|
|
|
|
|
|
_snd_bgm_mode_t_FORCE_UINT8 = 0xFF
|
2020-02-22 16:59:46 +00:00
|
|
|
} snd_bgm_mode_t;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
SND_SE_OFF = 0,
|
|
|
|
SND_SE_FM = 1,
|
|
|
|
SND_SE_BEEP = 2,
|
|
|
|
SND_SE_MODE_COUNT = 3,
|
2021-05-01 09:25:57 +00:00
|
|
|
|
|
|
|
_snd_se_mode_t_FORCE_INT16 = 0x7FFF
|
2020-02-22 16:59:46 +00:00
|
|
|
} snd_se_mode_t;
|
|
|
|
|
|
|
|
extern unsigned char snd_se_mode;
|
2021-05-01 09:25:57 +00:00
|
|
|
extern snd_bgm_mode_t snd_bgm_mode;
|
2020-02-22 16:59:46 +00:00
|
|
|
|
2020-12-31 16:22:48 +00:00
|
|
|
#ifdef __cplusplus
|
2021-03-25 16:09:57 +00:00
|
|
|
static inline bool snd_bgm_active() {
|
2020-12-31 16:22:48 +00:00
|
|
|
return snd_bgm_mode;
|
|
|
|
}
|
2021-03-25 16:09:57 +00:00
|
|
|
|
|
|
|
static inline bool16 snd_se_active() {
|
|
|
|
return (snd_se_mode != SND_SE_OFF);
|
|
|
|
}
|
2021-07-18 19:58:51 +00:00
|
|
|
|
|
|
|
#ifdef X86REAL_H
|
|
|
|
// MODDERS: Just use [new_se] directly.
|
|
|
|
static inline int16_t snd_get_param(int16_t ¶m) {
|
|
|
|
_BX = _SP;
|
2021-08-24 20:54:10 +00:00
|
|
|
return peek(_SS, (_BX + 4));
|
2021-07-18 19:58:51 +00:00
|
|
|
}
|
|
|
|
#endif
|
2020-12-31 16:22:48 +00:00
|
|
|
#endif
|
|
|
|
|
2020-12-29 20:05:57 +00:00
|
|
|
#define snd_bgm_is_fm() \
|
|
|
|
(snd_bgm_mode != SND_BGM_MIDI)
|
|
|
|
|
2020-02-22 16:59:46 +00:00
|
|
|
// Checks the requested BGM and SE modes against the available hardware and
|
|
|
|
// sets [snd_se_mode] and [snd_bgm_mode] accordingly. Returns [snd_bgm_mode].
|
2021-05-01 09:25:57 +00:00
|
|
|
int pascal snd_determine_modes(int req_bgm_mode, int req_se_mode);
|
2021-02-23 16:46:23 +00:00
|
|
|
|
2021-05-11 21:13:35 +00:00
|
|
|
#if defined(PMD) /* requires kaja.h */
|
2021-05-11 22:49:30 +00:00
|
|
|
// Loads a song ([func] == SND_LOAD_SONG) or a sound effect bank ([func] ==
|
2021-02-23 16:46:23 +00:00
|
|
|
// SND_LOAD_SE) into the respective work buffer of the sound driver. [fn] must
|
|
|
|
// not have any extension. Depending on [snd_bgm_mode], [snd_se_mode], and
|
|
|
|
// game, the following file is loaded:
|
|
|
|
//
|
|
|
|
// | | TH04 | TH05 |
|
|
|
|
// |----------------+------------+-----------|
|
|
|
|
// | [snd_bgm_mode] | [func] = SND_LOAD_SONG |
|
|
|
|
// |----------------+------------+-----------|
|
|
|
|
// | SND_BGM_FM26 | [fn].m26 | [fn].m |
|
|
|
|
// | SND_BGM_FM86 | [fn].m86 | [fn].m2 |
|
|
|
|
// | SND_BGM_MIDI | [fn].mmd | [fn].md | (yes, see TH05's load[data].asm)
|
|
|
|
// |----------------+------------+-----------|
|
|
|
|
// | [snd_se_mode] | [func] = SND_LOAD_SE |
|
|
|
|
// |----------------+------------+-----------|
|
|
|
|
// | SND_SE_FM | [fn].efc | [fn].efc |
|
|
|
|
// | SND_SE_BEEP | [fn].efs | [fn].efs | (using master.lib's BGM driver)
|
|
|
|
//
|
2021-05-06 14:34:27 +00:00
|
|
|
// ZUN bugs and caveats:
|
|
|
|
// • [fn] still needs to be null-terminated.
|
|
|
|
// • The TH04 version does not handle file errors.
|
|
|
|
// • In SND_SE_BEEP mode, the TH04 version requires master.lib's BGM subsystem
|
|
|
|
// to have been initialized before.
|
|
|
|
// • The TH05 version will infinitely loop if neither the file for the current
|
|
|
|
// [snd_bgm_mode] nor "[fn].m" exist.
|
2021-05-11 22:49:30 +00:00
|
|
|
void pascal snd_load(const char fn[SND_FN_LEN], snd_load_func_t func);
|
2021-05-11 21:13:35 +00:00
|
|
|
|
|
|
|
#if defined(__cplusplus) && (GAME == 5)
|
|
|
|
// Refer to TH02's implementation for an explanation of how wrong this is.
|
|
|
|
static inline uint16_t snd_load_size() {
|
|
|
|
return 0xFFFF;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|