-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsound.c
113 lines (92 loc) · 2.68 KB
/
sound.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/* Nitfol - z-machine interpreter using Glk for output.
Copyright (C) 1999 Evin Robertson
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
The author can be reached at nitfol@deja.com
*/
#include "nitfol.h"
/* Link this in only if your glk supports sound */
#ifdef GLK_MODULE_SOUND
static schanid_t channel;
void init_sound(void)
{
channel = glk_schannel_create(0);
}
void kill_sound(void)
{
glk_schannel_destroy(channel);
}
static void set_volume(zword zvolume)
{
glui32 vol;
switch(zvolume) {
case 1: vol = 0x02000; break;
case 2: vol = 0x04000; break;
case 3: vol = 0x06000; break;
case 4: vol = 0x08000; break;
case 5: vol = 0x0a000; break;
case 6: vol = 0x0c000; break;
case 7: vol = 0x0e000; break;
case 8: vol = 0x10000; break;
case 255: vol = 0x20000; break;
default: n_show_error(E_SOUND, "illegal volume", zvolume);
}
glk_schannel_set_volume(channel, vol);
}
void check_sound(event_t moo) /* called from main event loop */
{
if(moo.type == evtype_SoundNotify) {
zword dummylocals[16];
in_timer = TRUE;
mop_call(moo.val2, 0, dummylocals, -2); /* add a special stack frame */
decode(); /* start interpreting the routine */
in_timer = FALSE;
exit_decoder = FALSE;
}
}
void op_sound_effect(void)
{
zword number = operand[0], effect = operand[1];
zword volume = operand[2], routine = operand[3];
glui32 repeats;
if(!glk_gestalt(gestalt_Sound, 0))
return;
if(numoperands < 1)
number = 1;
if(numoperands < 2)
effect = 2;
if(numoperands < 3)
volume = 8;
if(numoperands < 4)
routine = 0;
repeats = (volume >> 8) & 0xff;
if(repeats == 0xff)
repeats = 0xffffffff;
else
repeats++;
volume &= 0xff;
switch(effect) {
case 1:
glk_sound_load_hint(number, 1);
break;
case 2:
glk_schannel_play_ext(channel, number, repeats, routine);
set_volume(volume);
break;
case 3:
glk_schannel_stop(channel);
break;
case 4:
glk_sound_load_hint(number, 0);
}
}
#endif