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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
27 #define EFFECT_PREPARE 1
30 #define EFFECT_FINISH_WITH 4
32 extern int direct_call (zword);
34 static zword routine = 0;
36 static int next_sample = 0;
37 static int next_volume = 0;
39 static bool locked = FALSE;
40 static bool playing = FALSE;
45 * Initialize sound variables.
49 void init_sound (void)
59 * Call the IO interface to play a sample.
63 static void start_sample (int number, int volume, int repeats, zword eos)
66 static zbyte lh_repeats[] = {
67 0x00, 0x00, 0x00, 0x01, 0xff,
68 0x00, 0x01, 0x01, 0x01, 0x01,
69 0xff, 0x01, 0x01, 0xff, 0x00,
70 0xff, 0xff, 0xff, 0xff, 0xff
73 if (story_id == LURKING_HORROR)
74 repeats = lh_repeats[number];
76 os_start_sample (number, volume, repeats, eos);
86 * Play a sample that has been delayed until the previous sound effect has
87 * finished. This is necessary for two samples in The Lurking Horror that
88 * immediately follow other samples.
92 static void start_next_sample (void)
96 start_sample (next_sample, next_volume, 0, 0);
101 }/* start_next_sample */
106 * Call the Z-code routine which was given as the last parameter of
107 * a sound_effect call. This function may be called from a hardware
108 * interrupt (which requires extremely careful programming).
112 void end_of_sound (void)
115 #if defined(DJGPP) && defined(SOUND_SUPPORT)
116 end_of_sound_flag = 0;
123 if (story_id == LURKING_HORROR)
124 start_next_sample ();
126 direct_call (routine);
133 * z_sound_effect, load / play / stop / discard a sound effect.
135 * zargs[0] = number of bleep (1 or 2) or sample
136 * zargs[1] = operation to perform (samples only)
137 * zargs[2] = repeats and volume (play sample only)
138 * zargs[3] = end-of-sound routine (play sample only, optional)
140 * Note: Volumes range from 1 to 8, volume 255 is the default volume.
141 * Repeats are stored in the high byte, 255 is infinite loop.
145 void z_sound_effect (void)
147 zword number = zargs[0];
148 zword effect = zargs[1];
149 zword volume = zargs[2];
151 /* By default play sound 1 at volume 8 */
155 effect = EFFECT_PLAY;
159 if (number >= 3 || number == 0) {
163 if (story_id == LURKING_HORROR && (number == 9 || number == 16)) {
165 if (effect == EFFECT_PLAY) {
167 next_sample = number;
168 next_volume = volume;
173 start_next_sample ();
175 } else locked = FALSE;
186 os_prepare_sample (number);
189 start_sample (number, lo (volume), hi (volume), (zargc == 4) ? zargs[3] : 0);
192 os_stop_sample (number);
194 case EFFECT_FINISH_WITH:
195 os_finish_with_sample (number);
202 } else os_beep (number);
204 }/* z_sound_effect */