diff --git a/th02/snd/delaymea.cpp b/th02/snd/delaymea.cpp index c516b64d..c44ef13d 100644 --- a/th02/snd/delaymea.cpp +++ b/th02/snd/delaymea.cpp @@ -6,6 +6,7 @@ extern "C" { #include "libs/kaja/kaja.h" #include "th02/hardware/frmdelay.h" #include "th02/snd/snd.h" +#include "th02/snd/measure.hpp" void snd_delay_until_measure(int measure) { @@ -15,14 +16,7 @@ void snd_delay_until_measure(int measure) } do { frame_delay(1); - _AH = KAJA_GET_SONG_MEASURE; - if(snd_midi_active != 1) { - geninterrupt(PMD); - } else { - _DX = (MMD_TICKS_PER_QUARTER_NOTE * 4); // yes, hardcoded to 4/4 - geninterrupt(MMD); - } - } while(_AX < measure); + } while(snd_get_song_measure() < measure); } } diff --git a/th02/snd/measure.hpp b/th02/snd/measure.hpp new file mode 100644 index 00000000..740d7ca1 --- /dev/null +++ b/th02/snd/measure.hpp @@ -0,0 +1,12 @@ +// Wrapper around KAJA_GET_SONG_MEASURE, using PMD or MMD depending on which +// driver is active. +static inline uint16_t snd_get_song_measure(void) { + _AH = KAJA_GET_SONG_MEASURE; + if(snd_bgm_is_fm()) { + geninterrupt(PMD); + } else { + _DX = (MMD_TICKS_PER_QUARTER_NOTE * 4); // yes, hardcoded to 4/4 + geninterrupt(MMD); + } + return _AX; +} diff --git a/th02/snd/snd.h b/th02/snd/snd.h index db2e98b8..828f6e16 100644 --- a/th02/snd/snd.h +++ b/th02/snd/snd.h @@ -12,6 +12,9 @@ extern bool snd_midi_possible; extern bool snd_active; extern bool snd_midi_active; extern bool snd_fm_possible; + + #define snd_bgm_is_fm() \ + (snd_midi_active != true) #endif int snd_pmd_resident(void); diff --git a/th04/snd/snd.h b/th04/snd/snd.h index 710634c0..328f9762 100644 --- a/th04/snd/snd.h +++ b/th04/snd/snd.h @@ -18,6 +18,9 @@ typedef enum { extern unsigned char snd_se_mode; extern unsigned char snd_bgm_mode; +#define snd_bgm_is_fm() \ + (snd_bgm_mode != SND_BGM_MIDI) + // 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]. unsigned char pascal snd_determine_modes(int req_bgm_mode, int req_se_mode);