diff options
author | Juan J. Martinez <jjm@usebox.net> | 2023-08-10 12:09:06 +0100 |
---|---|---|
committer | Juan J. Martinez <jjm@usebox.net> | 2023-08-10 12:09:06 +0100 |
commit | cd2296358a03ab9ca4d6c017262735eaa63b5fdb (patch) | |
tree | ae8f4c39e5936556a93a9468b98e4eb7eecdadca /src | |
parent | b26a8cb5ba0c6d4e766ea0de3505fe39e542ee5e (diff) | |
download | gold-mine-run-1.1.tar.gz gold-mine-run-1.1.zip |
Don't use the "nos" driver1.1
This fixes:
- crash when exiting after running the game with the no sound (nos)
driver
- occasional "pauses" when running the game with no sound
Diffstat (limited to 'src')
-rw-r--r-- | src/main.c | 7 | ||||
-rw-r--r-- | src/sound.c | 34 | ||||
-rw-r--r-- | src/sound.h | 2 |
3 files changed, 29 insertions, 14 deletions
@@ -14,7 +14,7 @@ #include "game.h" #define GAME_NAME "Gold Mine Run!" -#define GAME_VERSION "1.0 (2023-08-08)" +#define GAME_VERSION "1.1 (2023-08-10)" #define GAME_URL "https://www.usebox.net/jjm/gold-mine-run/" /* disable paging because our int handlers are written in C */ @@ -66,7 +66,7 @@ int main(int argc, char *argv[]) } } - if (!sound_init(nosound)) + if (!nosound && !sound_init()) { fprintf(stderr, "ERROR: failed to init sound\n"); return 1; @@ -80,7 +80,8 @@ int main(int argc, char *argv[]) control_init(); /* to update mikmod */ - timer_user_fn(sound_update); + if (!nosound) + timer_user_fn(sound_update); /* set VGA 320x200, 256 col */ if (!set_mode(0x13)) diff --git a/src/sound.c b/src/sound.c index a3f38b8..bf0c7be 100644 --- a/src/sound.c +++ b/src/sound.c @@ -26,18 +26,16 @@ static Efx efx[EFX_CNT] = { NULL, (const char *)binary_death_efx_start, (size_t)&binary_death_efx_size}, }; +static uint8_t has_sound = 0; static uint8_t cur = 0; static uint32_t voice = 0; - static MODULE *music = NULL; -uint8_t sound_init(uint8_t nosound) +uint8_t sound_init() { MikMod_InitThreads(); - if (!nosound) - MikMod_RegisterDriver(&drv_sb); - MikMod_RegisterDriver(&drv_nos); + MikMod_RegisterDriver(&drv_sb); MikMod_RegisterLoader(&load_it); md_mode |= DMODE_SOFT_SNDFX | DMODE_SOFT_MUSIC; @@ -47,7 +45,8 @@ uint8_t sound_init(uint8_t nosound) md_mixfreq = 22050; if (MikMod_Init(NULL)) - return 0; + /* has_sound is 0 */ + return 1; for (uint8_t i = 0; i < EFX_CNT; i++) { @@ -67,6 +66,7 @@ uint8_t sound_init(uint8_t nosound) Player_Start(music); MikMod_EnableOutput(); + has_sound = 1; return 1; } @@ -76,6 +76,10 @@ volatile static uint8_t divider = 0; * counter and updating 1 in 20 interrupts */ void sound_update() { + /* we shouldn't call this anyway */ + if (!has_sound) + return; + if (++divider == 20) { divider = 0; @@ -85,17 +89,23 @@ void sound_update() void sound_mute() { - MikMod_DisableOutput(); + if (has_sound) + MikMod_DisableOutput(); } void sound_unmute() { - MikMod_EnableOutput(); + if (has_sound) + MikMod_EnableOutput(); } void sound_free() { - MikMod_DisableOutput(); + if (!has_sound) + return; + + if (MikMod_Active()) + MikMod_DisableOutput(); if (music) Player_Free(music); @@ -109,11 +119,15 @@ void sound_free() void sound_music_pattern(uint16_t pat) { - Player_SetPosition(pat); + if (has_sound) + Player_SetPosition(pat); } void sound_play_efx(uint8_t efxno) { + if (!has_sound) + return; + if (cur > efxno && !Voice_Stopped(voice)) return; diff --git a/src/sound.h b/src/sound.h index 2446b68..4e1085d 100644 --- a/src/sound.h +++ b/src/sound.h @@ -19,7 +19,7 @@ enum { #define PAT_GAMEOVER 4 #define PAT_PLAY 5 -uint8_t sound_init(uint8_t nosound); +uint8_t sound_init(); void sound_free(); void sound_update(); |