1 /*
2  * cmds.c  SYSTEM35 S command
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: cmds.c,v 1.33 2002/12/31 04:11:19 chikama Exp $ */
23 
24 #include <stdio.h>
25 #include "portab.h"
26 #include "xsystem35.h"
27 #include "music_client.h"
28 
29 /* �Ѥˤ���� �۾亮�ʥꥪ�к� */
30 static boolean dummy_pcm_in_play = FALSE;
31 /* Ʈ���Ի�II �۾亮�ʥꥪ�к� */
32 boolean dummy_pcm_su_flag = FALSE;
33 /* ���� cdrom �� loop ��� */
34 static int next_cdrom_loopcnt = 0;
35 
commandSS()36 void commandSS() {
37 	/* ���ڱ��դ��Ϥ���ʣãĤΤߡ�*/
38 	int num = getCaliValue();
39 	static int pre = 0;
40 
41 	DEBUG_COMMAND("SS %d:\n",num);
42 
43 	if (num == 0) {
44 		mus_cdrom_stop();
45 	} else {
46 		if (pre != num) {
47 			mus_cdrom_stop();
48 			mus_cdrom_start(num + 1, next_cdrom_loopcnt);
49 		}
50 	}
51 
52 	next_cdrom_loopcnt = 0;
53 	pre = num;
54 }
55 
commandSC()56 void commandSC() {
57 	/* �ãĤΥץ쥤��Υ������������� */
58 	int *var = getCaliVariable();
59 	cd_time info;
60 
61 	mus_cdrom_get_playposition(&info);
62 	if (info.t == 999) {
63 		*var++ = 999;
64 	} else {
65 		*var++ = info.t - 1;
66 	}
67 	*var++ = info.m;
68 	*var++ = info.s;
69 	*var++ = info.f;
70 
71 	DEBUG_COMMAND("SC %p:\n",var);
72 }
73 
commandSD()74 void commandSD() {
75 	/* ���ڱ��դ��Ϥ���ʥǥե���Ȥϣãġݣģ���*/
76 	int num1 = getCaliValue();
77 	int num2 = getCaliValue();
78 
79 	DEBUG_COMMAND_YET("SD %d,%d:\n",num1,num2);
80 }
81 
commandSR()82 void commandSR() {
83 	/* ���ڱ��վ�����֤� (CD,MIDI)
84 	   num   = �ǥХ����λ��� (0=CD , 1=MIDI)
85 	   var   = ���ն��ֹ� (0�λ��ϱ��������)
86 	   var+1 = �롼�ײ��
87 	   var+2 = ���հ���
88 	   var+3 = �ե����ɥ�����������
89 	*/
90 	/* Hushaby ���� SR,c,P:���ѹ����� */
91 	int num, *var;
92 	int c = sl_getcAt(sl_getIndex());
93 	if (c < 0x40) {
94 		num = sl_getc();
95 	} else {
96 		num  = getCaliValue();
97 	}
98 	var = getCaliVariable();
99 
100 	if (num == 0) {
101 		cd_time info;
102 		mus_cdrom_get_playposition(&info);
103 		if (info.t == 999) {
104 			*var = 0;
105 		} else {
106 			*var = info.t - 1;
107 		}
108 	} else {
109 		midiplaystate st;
110 		mus_midi_get_playposition(&st);
111 		*var = st.play_no;
112 	}
113 
114 	DEBUG_COMMAND("SR %d,%p:\n",num, var);
115 }
116 
commandSL()117 void commandSL() {
118 	/* ���β��ڤΥ롼�ײ������ꤹ�� */
119 	int num = getCaliValue();
120 
121 	next_cdrom_loopcnt = num;
122 
123 	DEBUG_COMMAND("SL %d:\n",num);
124 }
125 
commandSI()126 void commandSI() {
127 	/* ���ꤷ����������³���֤� var �˼��� */
128 	int type = sys_getc();
129 	int *var = getCaliVariable();
130 
131 	if (type == 0) {        /* MIDI */
132 		*var = mus_midi_get_state()  == TRUE ? 1 : 0;
133 	} else if (type == 1) { /* PCM */
134 		*var = mus_pcm_get_state()   == TRUE ? 1 : 0;
135 	} else if (type == 2) { /* CD */
136 		*var = mus_cdrom_get_state() == TRUE ? 1 : 0;
137 	}
138 
139 	DEBUG_COMMAND("SI %d,%d:\n",type,*var);
140 }
141 
commandSG()142 void commandSG() {
143 	/* MIDI���� */
144 	static int loopcnt = 0;
145 	int sw  = sys_getc();
146 	int num, fnum, *var;
147 	midiplaystate st;
148 
149 	switch(sw) {
150 	case 0:
151 		/* ������Σͣɣģɤ���ߤ��� */
152 		num = getCaliValue();
153 		mus_midi_stop();
154 		DEBUG_COMMAND("SG0 %d:\n", num);
155 		break;
156 	case 1:
157 		/* �ͣɣģɤ���դ��� */
158 		num = getCaliValue();
159 		if (num == 0) {
160 			mus_midi_stop();
161 		} else {
162 			mus_midi_stop();
163 			mus_midi_start(num, loopcnt);
164 		}
165 		DEBUG_COMMAND("SG1 %d:\n", num);
166 		break;
167 	case 2:
168 		/* �ͣɣģɱ��հ��֤�1/100��ñ�̤Ǽ������� */
169 		var = getCaliVariable();
170 		mus_midi_get_playposition(&st);
171 		*var = st.loc_ms / 10;
172 		DEBUG_COMMAND("SG2 %p:\n", var);
173 		break;
174 	case 3:
175 		num = getCaliValue();
176 		if (num == 0) {
177 			/* ������Σͣɣģɤ�����ߤ��� */
178 			mus_midi_pause();
179 		} else {
180 			/* ��������Σͣɣģɤΰ����ߤ������� */
181 			mus_midi_unpause();
182 		}
183 		DEBUG_COMMAND("SG3 %d:\n", num);
184 		break;
185 	case 4:
186 		num = getCaliValue();
187 		/* ����SG1���ޥ�ɤǤ�MIDI���դη����֤�������� */
188 		loopcnt = num;
189 		DEBUG_COMMAND("SG4 %d:\n", num);
190 		break;
191 	case 5:
192 		fnum = getCaliValue() & 0x7f;
193 		num  = getCaliValue();
194 		mus_midi_set_flag(0, fnum, num);
195 
196 		DEBUG_COMMAND("SG5 %d,%d:\n", fnum, num);
197 		break;
198 	case 6:
199 		fnum = getCaliValue() & 0x7f;
200 		num  = getCaliValue();
201 		mus_midi_set_flag(1, fnum, num);
202 
203 		DEBUG_COMMAND("SG6 %d,%d:\n", fnum, num);
204 		break;
205 	case 7:
206 		fnum = getCaliValue() & 0x7f;
207 		var  = getCaliVariable();
208 		*var = mus_midi_get_flag(0, fnum);
209 
210 		DEBUG_COMMAND("SG7 %d,%d:\n", fnum, *var);
211 		break;
212 	case 8: {
213 		fnum = getCaliValue() & 0x7f;
214 		var  = getCaliVariable();
215 		*var = mus_midi_get_flag(1, fnum);
216 		DEBUG_COMMAND("SG8 %d,%p:\n", fnum, var);
217 		break;
218 	}
219 	default:
220 		SYSERROR("Unknown SG command %d\n", sw);
221 		break;
222 	}
223 }
224 
commandSP()225 void commandSP() {
226 	/* �Уãͥǡ�������դ��� */
227 	int no = getCaliValue();
228 	int loop = getCaliValue();
229 
230 	DEBUG_COMMAND("SP %d,%d:\n",no,loop);
231 
232 	if (!mus_pcm_get_state()) {
233 		dummy_pcm_in_play = TRUE;
234 	}
235 
236 	/* ???? */
237 	if (no == 0) {
238 		mus_pcm_stop(0);
239 	} else {
240 		mus_pcm_start(no, loop);
241 	}
242 }
243 
commandST()244 void commandST() {
245 	/* �Уãͥǡ����α��դ���ߤ��롣 */
246 	int time = getCaliValue();
247 
248 	DEBUG_COMMAND("ST %d:\n",time);
249 
250 	if (!mus_pcm_get_state()) {
251 		dummy_pcm_in_play = FALSE;
252 	}
253 	mus_pcm_stop(time);
254 }
255 
commandSU()256 void commandSU() {
257 	/* �Уãͤα��վ��֤��ѿ� var1 , var2 ���֤� */
258 	int *var1 = getCaliVariable();
259 	int *var2 = getCaliVariable();
260 
261 	if (!mus_pcm_get_state()) {
262 		*var1 = dummy_pcm_in_play ? 1 : 0;
263 		*var2 = 0;
264 		if (dummy_pcm_in_play) dummy_pcm_in_play = FALSE;
265 	} else {
266 		*var1 = mus_pcm_get_playposition(var2);
267 		/* XXX for panyon_new */
268 	        if (*var2 == 0){
269 			*var1 = dummy_pcm_in_play ? TRUE : FALSE;
270             		dummy_pcm_in_play = dummy_pcm_in_play ? FALSE : TRUE;
271         	}
272 	}
273 	if (dummy_pcm_su_flag) {
274 		*var1 = *var2 = 0;
275 	}
276 
277 	DEBUG_COMMAND("SU %d,%d:\n",*var1, *var2);
278 }
279 
commandSQ()280 void commandSQ() {
281 	/* �����̡��ΣУãͥǡ�����������Ʊ��դ��� */
282 	int noL  = getCaliValue();
283 	int noR  = getCaliValue();
284 	int loop = getCaliValue();
285 
286 	DEBUG_COMMAND("SQ %d,%d,%d:\n", noL, noR, loop);
287 
288 	if (!mus_pcm_get_state()) {
289 		dummy_pcm_in_play = TRUE;
290 	}
291 
292 	if( noL<1 || noR<1 ) {
293 		mus_pcm_stop(0);
294 		return;
295 	}
296 	mus_pcm_mix(noL, noR, loop);
297 	return;
298 }
299 
commandSO()300 void commandSO() {
301 	// �УãͥǥХ����Υ��ݡ��Ⱦ�������
302 	int *var = getCaliVariable();
303 
304 	DEBUG_COMMAND_YET("SO %p:\n",var);
305 }
306 
commandSW()307 void commandSW() {
308 	/* ����ǡ������������ս���뤫�����å����롥*/
309 	int *var    = getCaliVariable();
310 	int channel = getCaliValue();
311 	int Srate   = getCaliValue();
312 	int bit     = getCaliValue();
313 
314 	if (mus_pcm_get_state()) {
315 		int rate = Srate == 11 ? 11025 : Srate == 22 ? 22050 : Srate == 44 ? 44100 : 8000;
316 		boolean able;
317 		int ret;
318 
319 		ret = mus_pcm_check_ability(bit, rate, channel, &able);
320 		if (ret < 0) {
321 			*var = 0;
322 		} else {
323 			*var = (able ? 2 : 1);
324 		}
325 	} else {
326 		*var = 0;
327 	}
328 
329 	DEBUG_COMMAND("SW %p,%d,%d,%d:\n",var, channel, Srate, bit);
330 }
331 
commandSM()332 void commandSM() {
333 	/* �Уãͥǡ���������˾褻�롣*/
334 	int no = getCaliValue();
335 	DEBUG_COMMAND("SM %d:\n",no);
336 
337 	mus_pcm_load(no);
338 }
339 
commandSX()340 void commandSX() {
341 	int device = sys_getc();
342 	int sw     = sys_getc();
343 
344 	switch(sw) {
345 	case 1: {
346 		/* �ե����� */
347 		int time   = getCaliValue();
348 		int volume = getCaliValue();
349 		int stop   = getCaliValue();
350 		mus_mixer_fadeout_start(device, time, volume, stop);
351 		DEBUG_COMMAND("SX %d,%d,%d,%d,%d:\n", device, sw, time, volume, stop);
352 		break;
353 	}
354 	case 2: {
355 		/* �ե����ɽ�λ��ǧ */
356 		int *var   = getCaliVariable();
357 		boolean st;
358 		st = mus_mixer_fadeout_get_state(device);
359 		*var = (st ? 0 : 1);
360 		DEBUG_COMMAND("SX %d,%d:\n", device, sw);
361 		break;
362 	}
363 	case 3: {
364 		/*  �ե����ɶ�����λ */
365 		mus_mixer_fadeout_stop(device);
366 		DEBUG_COMMAND("SX %d,%d:\n", device, sw);
367 		break;
368 	}
369 	case 4: {
370 		/* �ܥ�塼����� */
371 		int *var   = getCaliVariable();
372 		*var = mus_mixer_get_level(device);
373 		DEBUG_COMMAND("SX %d,%d:\n", device, sw);
374 		break;
375 	}
376 	default:
377 		SYSERROR("Unknown SX command\n");
378 	}
379 }
380