From 891cc88300a7870a86958b988ecdd78217de3949 Mon Sep 17 00:00:00 2001 From: Timo Korvola Date: Sat, 3 Mar 2018 20:59:22 +0200 Subject: [PATCH] end_of_sound now maybe works. Went back to end_of_sound taking no args, so sound.c got reverted. Should be easier on DOS frotz, which I never attempted to fix. Made interpret call os_tick, as SDL front end expects (WinFrotz also has os_tick). os_tick calls end_of_sound as appropriate. Added os_tick to the other front ends. In dumb it does nothing, in curses it handles resizes. --- src/common/frotz.h | 8 +++++++- src/common/process.c | 5 +++-- src/common/sound.c | 5 ++++- src/curses/ux_input.c | 14 ++++++++++---- src/dumb/dumb_input.c | 7 +++++-- src/sdl/sf_sound.c | 10 ++++++---- 6 files changed, 35 insertions(+), 14 deletions(-) diff --git a/src/common/frotz.h b/src/common/frotz.h index b2f8e6b..bfa287e 100644 --- a/src/common/frotz.h +++ b/src/common/frotz.h @@ -750,7 +750,7 @@ void branch (bool); void storeb (zword, zbyte); void storew (zword, zword); -void end_of_sound (zword routine); +void end_of_sound (void); int completion (const zchar *buffer, zchar *result); @@ -800,6 +800,12 @@ void os_init_setup (void); void os_warn (const char *, ...); void os_quit (void); +/** + * Called regularly by the interpreter, at least every few instructions + * (only when interpreting: e.g., not when waiting for input). + */ +void os_tick (void); + /* Front ends call this if the terminal size changes. */ void resize_screen(void); diff --git a/src/common/process.c b/src/common/process.c index c542b13..9187b0b 100644 --- a/src/common/process.c +++ b/src/common/process.c @@ -306,10 +306,11 @@ void interpret (void) } #if defined(DJGPP) && defined(SOUND_SUPPORT) - if (end_of_sound_flag) - end_of_sound (); + if (end_of_sound_flag) + end_of_sound (); #endif + os_tick(); } while (finished == 0); finished--; diff --git a/src/common/sound.c b/src/common/sound.c index 2998734..e5e29e7 100644 --- a/src/common/sound.c +++ b/src/common/sound.c @@ -31,6 +31,8 @@ extern int direct_call (zword); +static zword routine = 0; + static int next_sample = 0; static int next_volume = 0; @@ -74,6 +76,7 @@ static void start_sample (int number, int volume, int repeats, zword eos) os_start_sample (number, volume, repeats, eos); + routine = eos; playing = TRUE; }/* start_sample */ @@ -106,7 +109,7 @@ static void start_next_sample (void) * interrupt (which requires extremely careful programming). * */ -void end_of_sound (zword routine) +void end_of_sound (void) { #if defined(DJGPP) && defined(SOUND_SUPPORT) end_of_sound_flag = 0; diff --git a/src/curses/ux_input.c b/src/curses/ux_input.c index b3e9032..00cd934 100644 --- a/src/curses/ux_input.c +++ b/src/curses/ux_input.c @@ -133,6 +133,15 @@ static int timeout_to_ms() #endif +void os_tick() +{ + while (terminal_resized) { + terminal_resized = 0; + unix_resize_display(); + } +} + + /* * unix_read_char * @@ -155,10 +164,7 @@ static int unix_read_char(int extkeys) /* Wait with select so that we get interrupted on SIGWINCH. */ FD_ZERO(&rsel); FD_SET(fd, &rsel); - while (terminal_resized) { - terminal_resized = 0; - unix_resize_display(); - } + os_tick(); refresh(); t_left = timeout_left(&tval) ? &tval : NULL; sel = select(fd + 1, &rsel, NULL, NULL, t_left); diff --git a/src/dumb/dumb_input.c b/src/dumb/dumb_input.c index 10e36cd..81c4e8d 100644 --- a/src/dumb/dumb_input.c +++ b/src/dumb/dumb_input.c @@ -19,10 +19,10 @@ * Or visit http://www.fsf.org/ */ -#include "dumb_frotz.h" - #include +#include "dumb_frotz.h" + f_setup_t f_setup; static char runtime_usage[] = @@ -476,3 +476,6 @@ zword os_read_mouse(void) /* NOT IMPLEMENTED */ return 0; } + +void os_tick() +{} diff --git a/src/sdl/sf_sound.c b/src/sdl/sf_sound.c index 1ffdc66..ac9c0ed 100644 --- a/src/sdl/sf_sound.c +++ b/src/sdl/sf_sound.c @@ -335,8 +335,10 @@ void os_start_sample(int number, int volume, int repeats, zword eos) // NOTE: geteffect may return an already loaded effect e = geteffect(number); if (!e) return; - if (e->type == SFX_TYPE) stopsample(); - else stopmodule(); + if (e->type == SFX_TYPE) + stopsample(); + else + stopmodule(); if (repeats < 1) repeats = 1; if (repeats == 255) repeats = -1; if (volume < 0) volume = 0; @@ -389,7 +391,7 @@ void sf_checksound() if (e_sfx->eos) { end_of_sound_flag = 1; - end_of_sound(e_sfx->eos); + end_of_sound(); } } if ((e_mod) && (e_mod->ended)) @@ -398,7 +400,7 @@ void sf_checksound() if (e_mod->eos) { end_of_sound_flag = 1; - end_of_sound(e_mod->eos); + end_of_sound(); } } } -- 2.34.1