1 /*
2 * sactsound.c: SACT�θ��̲���Ϣ
3 *
4 * Copyright (C) 1997-1998 Masaki Chikama (Wren) <chikama@kasumi.ipl.mech.nagoya-u.ac.jp>
5 * 1998- <masaki-c@is.aist-nara.ac.jp>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 */
22 /* $Id: sactsound.c,v 1.4 2003/08/02 13:10:32 chikama Exp $ */
23
24 #include "config.h"
25
26 #include <stdio.h>
27 #include <string.h>
28 #include <glib.h>
29
30 #include "portab.h"
31 #include "system.h"
32 #include "nact.h"
33 #include "imput.h"
34 #include "sactsound.h"
35 #include "music_client.h"
36 #include "sact.h"
37
38 // slot�ֹ�� 1���� 20�� SACT�Ѥ˻���
39 #define CACHEMAX 20
40 #define SLOTOFFSET 1
41 static int cache[CACHEMAX];
42 static int cachei;
43
44 // ����������̲��Ѥζ����Ƥ��륹��åȤ�õ��
slt_getnext(int no)45 static int slt_getnext(int no) {
46 int indx;
47
48 indx = cachei % CACHEMAX;
49 cache[indx] = no;
50 cachei++;
51 if (cachei == CACHEMAX) cachei = 0;
52 return indx + SLOTOFFSET;
53 }
54
55 // ������ֹ�θ��̲������äƤ��륹��åȤ�õ��
slt_find(int no)56 static int slt_find(int no) {
57 int i;
58
59 for (i = 0; i < CACHEMAX; i++) {
60 if (cache[i] == no) return i + SLOTOFFSET;
61 }
62 return -1;
63 }
64
65 /*
66 SACT ���̲� subsystem �����
67 */
ssnd_init()68 int ssnd_init() {
69 // ch 1-8 ��å���Ȥ��ƻȤ���
70 cachei = 0;
71 return OK;
72 }
73
74 // ������ֹ�θ��̲��������ɤ߹���
ssnd_prepare(int no)75 int ssnd_prepare(int no) {
76 int slot = slt_find(no);
77
78 if (slot == -1) {
79 slot = slt_getnext(no);
80 mus_wav_load(slot, no);
81 }
82
83 return OK;
84 }
85
86 // ������ֹ�θ��̲������
ssnd_play(int no)87 int ssnd_play(int no) {
88 int slot = slt_find(no);
89
90 if (slot == -1) {
91 slot = slt_getnext(no);
92 mus_wav_load(slot, no);
93 }
94 mus_wav_play(slot, 1);
95
96 return OK;
97 }
98
99 // ������ֹ�θ��̲���������
ssnd_stop(int no,int fadetime)100 int ssnd_stop(int no, int fadetime) {
101 int slot = slt_find(no);
102
103 if (slot != -1) {
104 mus_wav_fadeout_start(slot, fadetime, 0, TRUE);
105 cache[slot - SLOTOFFSET] = 0;
106 }
107
108 return OK;
109 }
110
111 // ������ֹ�θ��̲���������λ����Τ��Ԥ�
ssnd_wait(int no)112 int ssnd_wait(int no) {
113 int slot = slt_find(no);
114
115 if (slot != -1) {
116 mus_wav_waitend(slot);
117 cache[slot - SLOTOFFSET] = 0;
118 }
119 return OK;
120 }
121
122 // ����θ��̲�����λ���뤫���������������ޤ��Ԥ�
ssnd_waitkey(int no,int * res)123 int ssnd_waitkey(int no, int *res) {
124 int slot = slt_find(no);
125
126 if (slot == -1) {
127 *res = 0;
128 return OK;
129 }
130
131 if (sact.waitskiplv > 1) {
132 *res = SYS35KEY_RET;
133 return OK;
134 }
135
136 sact.waittype = KEYWAIT_SIMPLE;
137 sact.waitkey = -1;
138
139 while(sact.waitkey == -1 && mus_wav_get_playposition(slot)) {
140 sys_keywait(25, TRUE);
141 }
142
143 if (sact.waitkey == -1) {
144 *res = 0;
145 } else {
146 *res = sact.waitkey;
147 }
148 sact.waittype = KEYWAIT_NONE;
149
150 cache[slot - SLOTOFFSET] = 0;
151
152 return OK;
153 }
154
155 // ���������ͥ��ȿž�������̲��������ɤ߹���
ssnd_prepareLRrev(int no)156 int ssnd_prepareLRrev(int no) {
157 mus_wav_load_lrsw(30, no); // slot �� 30����Ǥ�����
158 return OK;
159 }
160
161 // ���������ͥ��ȿž�������̲������
ssnd_playLRrev(int no)162 int ssnd_playLRrev(int no) {
163 mus_wav_load_lrsw(30, no);
164 mus_wav_play(30, 1);
165
166 return OK;
167 }
168
169 // ������ֹ�θ��̲���¸�ߤ��뤫�ɤ���������å�
ssnd_getlinknum(int no)170 int ssnd_getlinknum(int no) {
171 WARNING("NOT IMPLEMENTED\n");
172 return OK;
173 }
174
175 // ���٤Ƥκ�����θ��̲���������λ����Τ��Ԥ�
ssnd_stopall(int time)176 int ssnd_stopall(int time) {
177 int i;
178
179 for (i = 0; i < CACHEMAX; i++) {
180 if (cache[i] > 0) {
181 mus_wav_fadeout_start(i + SLOTOFFSET, time, 0, TRUE);
182 cache[i] = 0;
183 }
184 }
185 return OK;
186 }
187