1 /* sound.c - Sound effect function
2 * Copyright (c) 1995-1997 Stefan Jokisch
4 * This file is part of Frotz.
6 * Frotz is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * Frotz is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
27 #define EFFECT_PREPARE 1
30 #define EFFECT_FINISH_WITH 4
32 extern int direct_call (zword);
34 static int next_sample = 0;
35 static int next_volume = 0;
37 static bool locked = FALSE;
38 static bool playing = FALSE;
43 * Initialize sound variables.
47 void init_sound (void)
57 * Call the IO interface to play a sample.
61 static void start_sample (int number, int volume, int repeats, zword eos)
64 static zbyte lh_repeats[] = {
65 0x00, 0x00, 0x00, 0x01, 0xff,
66 0x00, 0x01, 0x01, 0x01, 0x01,
67 0xff, 0x01, 0x01, 0xff, 0x00,
68 0xff, 0xff, 0xff, 0xff, 0xff
71 if (story_id == LURKING_HORROR)
72 repeats = lh_repeats[number];
74 os_start_sample (number, volume, repeats, eos);
83 * Play a sample that has been delayed until the previous sound effect has
84 * finished. This is necessary for two samples in The Lurking Horror that
85 * immediately follow other samples.
89 static void start_next_sample (void)
93 start_sample (next_sample, next_volume, 0, 0);
98 }/* start_next_sample */
103 * Call the Z-code routine which was given as the last parameter of
104 * a sound_effect call. This function may be called from a hardware
105 * interrupt (which requires extremely careful programming).
109 void end_of_sound (zword routine)
112 #if defined(DJGPP) && defined(SOUND_SUPPORT)
113 end_of_sound_flag = 0;
120 if (story_id == LURKING_HORROR)
121 start_next_sample ();
123 direct_call (routine);
130 * z_sound_effect, load / play / stop / discard a sound effect.
132 * zargs[0] = number of bleep (1 or 2) or sample
133 * zargs[1] = operation to perform (samples only)
134 * zargs[2] = repeats and volume (play sample only)
135 * zargs[3] = end-of-sound routine (play sample only, optional)
137 * Note: Volumes range from 1 to 8, volume 255 is the default volume.
138 * Repeats are stored in the high byte, 255 is infinite loop.
142 void z_sound_effect (void)
144 zword number = zargs[0];
145 zword effect = zargs[1];
146 zword volume = zargs[2];
151 effect = EFFECT_PLAY;
155 if (number >= 3 || number == 0) {
159 if (story_id == LURKING_HORROR && (number == 9 || number == 16)) {
161 if (effect == EFFECT_PLAY) {
163 next_sample = number;
164 next_volume = volume;
169 start_next_sample ();
171 } else locked = FALSE;
182 os_prepare_sample (number);
185 start_sample (number, lo (volume), hi (volume), (zargc == 4) ? zargs[3] : 0);
188 os_stop_sample (number);
190 case EFFECT_FINISH_WITH:
191 os_finish_with_sample (number);
198 } else os_beep (number);
200 }/* z_sound_effect */