[Maintenance] Add a PMD/MMD-independent wrapper for KAJA_GET_SONG_MEASURE

No pseudo-registers in the usage code! Awesome!

Part of P0132, funded by [Anonymous].
This commit is contained in:
nmlgc 2020-12-29 21:05:57 +01:00
parent 3bf078b68c
commit 8ef8f78cc9
4 changed files with 20 additions and 8 deletions

View File

@ -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);
}
}

12
th02/snd/measure.hpp Normal file
View File

@ -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;
}

View File

@ -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);

View File

@ -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);