1 /* Nitfol - z-machine interpreter using Glk for output.
2 Copyright (C) 1999 Evin Robertson
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 The author can be reached at nitfol@deja.com
22 /* Link this in only if your glk supports sound */
24 #ifdef GLK_MODULE_SOUND
26 static schanid_t channel;
30 channel = glk_schannel_create(0);
35 glk_schannel_destroy(channel);
38 static void set_volume(zword zvolume)
42 case 1: vol = 0x02000; break;
43 case 2: vol = 0x04000; break;
44 case 3: vol = 0x06000; break;
45 case 4: vol = 0x08000; break;
46 case 5: vol = 0x0a000; break;
47 case 6: vol = 0x0c000; break;
48 case 7: vol = 0x0e000; break;
49 case 8: vol = 0x10000; break;
50 case 255: vol = 0x20000; break;
51 default: n_show_error(E_SOUND, "illegal volume", zvolume);
53 glk_schannel_set_volume(channel, vol);
57 void check_sound(event_t moo) /* called from main event loop */
59 if(moo.type == evtype_SoundNotify) {
60 zword dummylocals[16];
62 mop_call(moo.val2, 0, dummylocals, -2); /* add a special stack frame */
63 decode(); /* start interpreting the routine */
70 void op_sound_effect(void)
72 zword number = operand[0], effect = operand[1];
73 zword volume = operand[2], routine = operand[3];
76 if(!glk_gestalt(gestalt_Sound, 0))
88 repeats = (volume >> 8) & 0xff;
98 glk_sound_load_hint(number, 1);
101 glk_schannel_play_ext(channel, number, repeats, routine);
105 glk_schannel_stop(channel);
108 glk_sound_load_hint(number, 0);