1 /************************************************************************/
2 /*									*/
3 /* ������ɤν���							*/
4 /*									*/
5 /************************************************************************/
6 
7 #include <stdio.h>
8 
9 #include "quasi88.h"
10 #include "initval.h"
11 #include "soundbd.h"
12 
13 #include "pc88cpu.h"
14 #include "pc88main.h"
15 #include "intr.h"
16 
17 #include "snddrv.h"
18 #include "suspend.h"
19 
20 
21 /*
22  * ������ɥܡ���II���б��Ϥ����Ȥ������ø��Ǥ���
23  */
24 
25 
26 int	sound_board     = DEFAULT_SOUND;	/* ������ɥܡ���	*/
27 int	sound_port;				/* ������ɥݡ��Ȥμ���	*/
28 
29 
30 int	intr_sound_enable = 0x00;	/* I/O[31] �����ߥޥ��� SOUND	*/
31 
32 
33 	/* ������ɥܡ��� I �� */
34 
35 int	sound_ENABLE_A = FALSE;		/* TIMER A ������������ɤ��� */
36 int	sound_ENABLE_B = FALSE;		/* TIMER B ������������ɤ��� */
37 
38 int	sound_LOAD_A = FALSE;		/* TIMER A ��ư�������ɤ���	*/
39 int	sound_LOAD_B = FALSE;		/* TIMER B ��ư�������ɤ���	*/
40 
41 int	sound_FLAG_A = 0;		/* FLAG A �ξ���		*/
42 int	sound_FLAG_B = 0;		/* FLAG B �ξ���		*/
43 
44 int	sound_TIMER_A = 0;	/* TIMER A ������� reg[0x24��0x25]	*/
45 int	sound_TIMER_B = 0;	/* TIMER B ������� reg[0x26]		*/
46 
47 int	sound_prescaler = 6;		/* 1/�ץꥹ�����顼 (2,3,6)	*/
48 int	sound_prescaler_sel = 2;	/* �ץꥹ�����顼����		*/
49 
50 byte	sound_reg[0x100];		/* ������ɥܡ��� �쥸����	*/
51 int	sound_reg_select = 0x00;
52 
53 
54 	/* ������ɥܡ��� II �� */
55 
56 int	sound2_MSK_TA   = FALSE;	/* TIMER A �����ߥޥ���	*/
57 int	sound2_MSK_TB   = FALSE;	/* TIMER B �����ߥޥ���	*/
58 int	sound2_MSK_EOS  = FALSE;	/* EOS     �����ߥޥ���	*/
59 int	sound2_MSK_BRDY = FALSE;	/* BRDY    �����ߥޥ���	*/
60 int	sound2_MSK_ZERO = FALSE;	/* ZERO    �����ߥޥ���	*/
61 
62 int	sound2_EN_TA   = 0x01;		/* TIMER A �����ߵ���		*/
63 int	sound2_EN_TB   = 0x02;		/* TIMER B �����ߵ���		*/
64 int	sound2_EN_EOS  = FALSE;		/* EOS     �����ߵ���		*/
65 int	sound2_EN_BRDY = FALSE;		/* BDRY    �����ߵ���		*/
66 int	sound2_EN_ZERO = FALSE;		/* ZERO    �����ߵ���		*/
67 
68 int	sound2_FLAG_EOS    = 0;		/* FLAG EOS  �ξ���		*/
69 int	sound2_FLAG_BRDY   = 0;		/* FLAG BRDY �ξ���		*/
70 int	sound2_FLAG_ZERO   = 0;		/* FLAG ZERO �ξ���		*/
71 int	sound2_FLAG_PCMBSY = 0;		/* FLAG PCMBSY �ξ���		*/
72 
73 
74 
75 byte	sound2_reg[0x100];		/* ������ɥܡ���II �쥸����	*/
76 int	sound2_reg_select = 0x00;
77 
78 
79 	/* ������ɥܡ��� II  ADPCM �� */
80 
81 	byte	*sound2_adpcm = NULL;	/* ADPCM�� DRAM (256KB)		*/
82 
83 static	int	sound2_mem       = 0;	/* ADPCM ���� 1:����������ǽ	*/
84 static	int	sound2_rec       = 0;	/* ADPCM        1:Ͽ�� 0:����	*/
85 	int	sound2_repeat    = 0;	/* ADPCM ��ԡ��ȥץ쥤		*/
86 static	int	sound2_mem_size  = 5;	/* ADPCM �Υ���ñ�� 5 or 2	*/
87 static	int	sound2_record_intr_base = 1;/* ADPCM Ͽ�������ߥ졼��	*/
88 static	int	sound2_replay_intr_base = 1;/* ADPCM ���������ߥ졼��	*/
89 static	int	sound2_start_addr = 0;	/* ADPCM �������ȥ��ɥ쥹	*/
90 static	int	sound2_stop_addr  = 0;	/* ADPCM ���ȥåץ��ɥ쥹	*/
91 static	int	sound2_limit_addr = 0;	/* ADPCM ��ߥåȥ��ɥ쥹	*/
92 static	int	sound2_read_dummy = 2;	/* ADPCM �꡼�ɻ����ߡ�������	*/
93 
94 enum AdpcmStat{
95   ADPCM_HALT,
96   ADPCM_RECORD,
97   ADPCM_REPLAY,
98   ADPCM_WRITE,
99   ADPCM_READ,
100   EndofAdpcmStat
101 };
102 static	int	sound2_stat = 0;	/* ADPCM �ξ���			*/
103 
104 static	int	sound2_data_addr   = 0;	/* ADPCM ������Υ��ɥ쥹	*/
105 	int	sound2_intr_base   = 1;	/* ADPCM �����ߥ졼��		*/
106 static	int	sound2_counter     = 0;	/* ADPCM ����Ͽ��������	*/
107 static	int	sound2_counter_old = 0;
108 
109 	int	sound2_notice_EOS  = FALSE;	/* EOS�����å���������	*/
110 
111 static	int	sound2_delay = 0;	/* �ե饰���٤�			*/
112 
113 
114 /* BEEP��Ϣ���꺢�������꤬�ʤ��� */
115 
116 int	use_cmdsing = TRUE;		/* ���ǡ�CMD SINGͭ��		*/
117 
118 /********************************************************/
119 /* SOUND �����						*/
120 /********************************************************/
sound_board_init(void)121 void	sound_board_init( void )
122 {
123   int	i;
124   for( i=0; i<0x100; i++ ) sound_reg [ i ] = 0x00;
125   for( i=0; i<0x100; i++ ) sound2_reg[ i ] = 0x00;
126   sound_reg[0x0e]=0xff;
127   sound_reg[0x0f]=0xff;
128 
129   intr_sound_enable = 0x00;
130 /*
131   sound_reg[0x24]=0;
132   sound_reg[0x25]=0;
133   sound_reg[0x26]=0;
134   sound_reg[0x27]=0;
135 */
136   sound_reg[0x29]=0x03;		/* �����Ĥ����� 0x00 ���Ȥޤ����ΤǤϡ� */
137 
138   sound_ENABLE_A = FALSE;
139   sound_ENABLE_B = FALSE;
140   sound_LOAD_A   = FALSE;
141   sound_LOAD_B   = FALSE;
142   sound_FLAG_A   = 0;
143   sound_FLAG_B   = 0;
144   sound_TIMER_A  = 0;
145   sound_TIMER_B  = 0;
146 
147   sound_prescaler = 6;
148   sound_prescaler_sel = 2;
149 
150   sound2_MSK_TA = 0x00;
151   sound2_MSK_TB = 0x00;
152   sound2_EN_TA  = 0x01;
153   sound2_EN_TB  = 0x02;
154 
155   sound2_EN_EOS  = FALSE;
156   sound2_EN_BRDY = FALSE;
157   sound2_EN_ZERO = FALSE;
158 
159   sound2_FLAG_EOS    = 0;
160   sound2_FLAG_BRDY   = 0;
161   sound2_FLAG_ZERO   = 0;
162   sound2_FLAG_PCMBSY = 0;
163 
164   sound2_read_dummy = 2;
165 }
166 
167 
168 
169 
170 
171 
172 /************************************************************************/
173 /* ������ɥܡ�����							*/
174 /************************************************************************/
175 
176 /********************************************************/
177 /* �ǡ����������Ϥ���쥸�����λ���			*/
178 /********************************************************/
sound_out_reg(byte data)179 void	sound_out_reg( byte data )
180 {
181   sound_reg_select = data & 0xff;
182 
183   xmame_dev_sound_out_reg( data );
184 }
185 
186 /********************************************************/
187 /* �ǡ�������ꤷ���쥸�����˽���			*/
188 /********************************************************/
sound_out_data(byte data)189 void	sound_out_data( byte data )
190 {
191   static const int pres[4] = { 2, 2, 6, 3 };
192 
193 
194   sound_reg[ sound_reg_select ] = data;
195 
196   xmame_dev_sound_out_data( data );
197 
198 
199   switch( sound_reg_select ){
200 
201 #if 0
202   case 0x07:
203     /*if( verbose_snd ) if( !(data&0xc0) ) printf("SOUND joy %02X\n",data );*/
204     break;
205 #endif
206 
207 
208   case 0x24:
209   case 0x25:
210     sound_TIMER_A = ((int)sound_reg[ 0x24 ]<<2) | (sound_reg[ 0x25 ] & 0x03);
211     interval_work_set_TIMER_A();
212     break;
213 
214   case 0x26:
215     sound_TIMER_B = (int)data;
216     interval_work_set_TIMER_B();
217     break;
218 
219   case 0x27:
220     change_sound_flags( 0x27 );
221 /*printf("%x%x%x%x%x%x%x%x  \n",
222        (data>>7)&1,(data>>6)&1,(data>>5)&1,(data>>4)&1,
223        (data>>3)&1,(data>>2)&1,(data>>1)&1,(data>>0)&1);*/
224     break;
225 
226   case 0x29:
227     if( sound_board==SOUND_II ){
228       change_sound_flags( 0x29 );
229     }
230     break;
231 
232   case 0x2d:
233     if( verbose_snd ) printf("SOUND out %X\n",sound_reg_select);
234     sound_prescaler_sel |= 2;
235     change_sound_prescaler( pres[sound_prescaler_sel] );	/* 6 */
236     break;
237   case 0x2e:
238     if( verbose_snd ) printf("SOUND out %X\n",sound_reg_select);
239     sound_prescaler_sel |= 1;
240     change_sound_prescaler( pres[sound_prescaler_sel] );	/* 3 */
241     break;
242   case 0x2f:
243     if( verbose_snd ) printf("SOUND out %X\n",sound_reg_select);
244     sound_prescaler_sel = 0;
245     change_sound_prescaler( pres[sound_prescaler_sel] );	/* 2 */
246     break;
247 
248   }
249 }
250 
251 
252 /********************************************************/
253 /* ������ɤΥ��ơ�����������				*/
254 /********************************************************/
sound_in_status(void)255 byte	sound_in_status( void )
256 {
257   xmame_dev_sound_in_status();
258 
259   return ( sound_FLAG_B << 1 ) | sound_FLAG_A;	/* ��� ready */
260 
261 }
262 
263 /********************************************************/
264 /* ���ꤷ���쥸���������Ƥ�����				*/
265 /*	flag �� ���ʤ顢�Ĥͤ� SOUND BORD II ����	*/
266 /*	flag �� ���ʤ顢Ƚ��				*/
267 /********************************************************/
sound_in_data(int always_sound_II)268 byte	sound_in_data( int always_sound_II )
269 {
270   xmame_dev_sound_in_data();
271 
272   if      ( sound_reg_select < 0x10 ){		/* 0x00��0x0f �ϥ꡼�ɲ� */
273 
274     return sound_reg[ sound_reg_select ];
275 
276   }else if( sound_reg_select == 0xff ){		/* 0xff �ϡ�SD/SD II ��Ƚ�� */
277 
278     if( always_sound_II ) return 0x01;
279     else{
280       if( sound_port & SD_PORT_46_47 ) return 0x01;
281       else                             return 0x00;
282     }
283 
284   }else{					/* ����¾���ɤ�ʤ� */
285 
286     return 0x00;
287 
288   }
289 }
290 
291 
292 
293 
294 
295 
296 /************************************************************************/
297 /* ������ɥܡ���II��	(���ʤꤤ���ø�)				*/
298 /************************************************************************/
299 
300 /********************************************************/
301 /* �ǡ����������Ϥ���쥸�����λ���			*/
302 /********************************************************/
sound2_out_reg(byte data)303 void	sound2_out_reg( byte data )
304 {
305   sound2_reg_select = data & 0xff;
306 
307   xmame_dev_sound2_out_reg( data );
308 }
309 
310 /********************************************************/
311 /* �ǡ�������ꤷ���쥸�����˽���			*/
312 /********************************************************/
sound2_out_data(byte data)313 void	sound2_out_data( byte data )
314 {
315   int	wk, l;
316 
317   sound2_reg[ sound2_reg_select ] = data;
318 
319   xmame_dev_sound2_out_data( data );
320 
321 /*
322 if( sound2_reg_select==0x08 )
323 printf("[%05x = %04x : %02x] %02x\n",(int)sound2_data_addr,(int)sound2_data_addr>>sound2_mem_size,(int)sound2_data_addr&((1<<sound2_mem_size)-1),(int)data);
324 else
325 if( sound2_reg_select<=0x10 )
326 printf("%02x %02x\n",(int)sound2_reg_select,(int)data);
327 */
328 
329   switch( sound2_reg_select ){
330   case 0x00:					/* ����ȥ��� 1 */
331     sound2_repeat = data & 0x10;
332     sound2_mem    = data & 0x20;
333     sound2_rec    = data & 0x40;
334 
335     if( sound2_FLAG_PCMBSY ){			/* ADPCMư���� */
336       if( !sound2_mem ) sound2_FLAG_PCMBSY = 0;
337     }else{					/* ��ư����    */
338 
339       if( sound2_mem ){
340 
341 	if( data & 0x80 ){				/* Ͽ������ */
342 
343 	  if( sound2_rec ){
344 	    sound2_stat = ADPCM_RECORD;
345 	    sound2_intr_base = sound2_record_intr_base;
346 	  }else{
347 	    sound2_stat = ADPCM_REPLAY;
348 	    sound2_intr_base = sound2_replay_intr_base;
349 	  }
350 	  interval_work_set_BDRY();
351 
352 #define S sound2_start_addr
353 #define E sound2_stop_addr
354 #define L sound2_limit_addr
355 	  if( E == L ){
356 	    if( S < E ) l = E - S;
357 	    else        l = 0x3ffff - S;
358 	  }else{
359 	    if      ( S<E && S<L ){ if( E<L ) l = E - S;	 /* S< E< L */
360 	    			    else      l = 0;		 /* S< L< E */
361 	    }else if( E<S && E<L ){ if( S<L ) l = L - S + E;     /* E< S< L */
362 	    			    else      l = 0x3ffff - S;   /* E< L< S */
363 	    }else  /* L<S && L<E*/{ if( S<E ) l = E - S;         /* L< S< E */
364 				    else      l = 0x3ffff - S;   /* L< E< S */
365 	    }
366 	  }
367 	  if( l ){
368 	    sound2_notice_EOS = TRUE;
369 	    interval_work_set_EOS( l+1 );
370 	  }else{
371 	    sound2_notice_EOS = FALSE;
372 	  }
373 #undef S
374 #undef E
375 #undef L
376 	  sound2_FLAG_PCMBSY = 1;
377 	}else{						/* �ɤ߽� */
378 	  if( sound2_rec ){
379 	    sound2_stat = ADPCM_WRITE;
380 	    /* if( !sound2_MSK_BRDY ) sound2_FLAG_BRDY = 1; */
381 	    sound2_delay |= 0x08;
382 	  }else{
383 	    sound2_stat = ADPCM_READ;
384 	    sound2_read_dummy = 2;
385 	  }
386 	  sound2_data_addr = sound2_start_addr;
387 	}
388       }
389     }
390     if( data & 0x01 ){					/* �ꥻ�å� */
391       sound2_repeat = 0;
392       sound2_FLAG_PCMBSY = 0;
393     }
394     if( !sound2_mem ) sound2_stat = ADPCM_HALT;
395     break;
396 
397   case 0x01:					/* ����ȥ��� 2 */
398     sound2_mem_size = (data & 0x02) ? 5 : 2;
399     break;
400 
401   case 0x02:					/* �������ȥ��ɥ쥹 */
402   case 0x03:
403     sound2_start_addr  = ((int)sound2_reg[ 0x03 ] << 8) | sound2_reg[ 0x02 ];
404     sound2_start_addr  = (sound2_start_addr << sound2_mem_size);
405     sound2_start_addr &= 0x3ffff;
406     sound2_data_addr = sound2_start_addr;
407     break;
408 
409   case 0x04:					/* ���ȥåץ��ɥ쥹 */
410   case 0x05:
411     sound2_stop_addr  = ((int)sound2_reg[ 0x05 ] << 8) | sound2_reg[ 0x04 ];
412     sound2_stop_addr  = ((sound2_stop_addr+1) << sound2_mem_size ) -1;
413     sound2_stop_addr &= 0x3ffff;
414     break;
415 
416   case 0x08:					/* �ǡ��������� */
417     if( sound2_stat==ADPCM_WRITE ){
418 #if 0
419       if( sound2_data_addr != sound2_stop_addr ){
420 	sound2_adpcm[ sound2_data_addr ] = data;
421 /*
422 	if( sound2_data_addr == sound2_limit_addr )
423 	  sound2_data_addr = 0;
424 	else
425 */
426 	  sound2_data_addr = (sound2_data_addr+1) & 0x3ffff;
427 	/* sound2_FLAG_BRDY = sound2_MSK_BRDY ? 0 : 1; */
428 	sound2_delay |= 0x08;
429       }
430       if( sound2_data_addr == sound2_stop_addr ||
431 	  sound2_data_addr == 0x3ffff ){
432 	/* sound2_FLAG_EOS  = sound2_MSK_EOS  ? 0 : 1; */
433 	sound2_delay |= 0x04;
434       }
435 #else
436       if( sound2_data_addr == sound2_stop_addr ||
437 	  sound2_data_addr == 0x3ffff ){
438 	/* sound2_FLAG_EOS  = sound2_MSK_EOS  ? 0 : 1; */
439 	sound2_delay |= 0x04;
440       }
441       sound2_adpcm[ sound2_data_addr ] = data;
442 /*
443       if( sound2_data_addr == sound2_limit_addr )
444 	sound2_data_addr = 0;
445       else
446 */
447 	sound2_data_addr = (sound2_data_addr+1) & 0x3ffff;
448       /* sound2_FLAG_BRDY = sound2_MSK_BRDY ? 0 : 1; */
449       sound2_delay |= 0x08;
450 #endif
451     }
452     break;
453 
454   case 0x0c:					/* ��ߥåȥ��ɥ쥹 */
455   case 0x0d:
456     sound2_limit_addr  = ((int)sound2_reg[ 0x0d ] << 8) | sound2_reg[ 0x0c ];
457     sound2_limit_addr  = ((sound2_limit_addr+1)<< sound2_mem_size ) -1;
458     sound2_limit_addr &= 0x3ffff;
459     break;
460 
461   case 0x06:					/* �ץꥹ������ */
462   case 0x07:
463     wk = (((int)sound2_reg[ 0x07 ]&0x07) << 8) | sound2_reg[ 0x06 ];
464     wk &= 0x7ff;
465     if( wk==0 ) wk = 0x800;
466     sound2_record_intr_base = wk;
467     break;
468 
469   case 0x09:					/* �ǥ륿-N */
470   case 0x0a:
471     wk = ((int)sound2_reg[ 0x0a ] << 8) | sound2_reg[ 0x09 ];
472     if( wk==0 ) wk = 0x10000;
473     sound2_replay_intr_base = 72 * 65536 / wk;
474     break;
475 
476   case 0x10:					/* �����ߥե饰���� */
477     change_sound_flags( 0x10 );
478     break;
479   }
480 }
481 
482 
483 /********************************************************/
484 /* ������ɥܡ���II�Υ��ơ���������			*/
485 /********************************************************/
sound2_in_status(void)486 byte	sound2_in_status( void )
487 {
488   xmame_dev_sound2_in_status();
489 
490   if( sound2_delay & 0x08 ){
491     sound2_delay &= ~0x08;
492     if( !sound2_MSK_BRDY ) sound2_FLAG_BRDY = 1;
493   }
494   if( sound2_delay & 0x04 ){
495     sound2_delay &= ~0x04;
496     if( !sound2_MSK_EOS ) sound2_FLAG_EOS = 1;
497   }
498 
499   /* sound2_FLAG_ZERO ��������ˡ���狼��� */
500 
501   return ( sound2_FLAG_PCMBSY << 5 ) | ( sound2_FLAG_ZERO << 4 ) |
502          ( sound2_FLAG_BRDY << 3 ) | ( sound2_FLAG_EOS << 2 ) |
503 	 ( sound_FLAG_B << 1 ) | sound_FLAG_A;
504 }
505 
506 /********************************************************/
507 /* ���ꤷ���쥸���������Ƥ�����				*/
508 /********************************************************/
sound2_in_data(void)509 byte	sound2_in_data( void )
510 {
511   byte data = 0x00;
512 
513   xmame_dev_sound2_in_data();
514 
515   if( sound2_reg_select==0x08 ){		/* �ǡ����ɤ߽Ф� */
516 
517     if( sound2_stat==ADPCM_READ ){
518       if( sound2_read_dummy ){
519 	sound2_read_dummy --;
520       }else{
521 	if( sound2_data_addr != sound2_stop_addr ){
522 	  data = sound2_adpcm[ sound2_data_addr ];
523 /*
524 	  if( sound2_data_addr == sound2_limit_addr )
525 	    sound2_data_addr = 0;
526 	  else
527 */
528 	    sound2_data_addr = (sound2_data_addr+1) & 0x3ffff;
529 	}
530       }
531       if( sound2_data_addr != sound2_stop_addr ){
532 	sound2_FLAG_BRDY = sound2_MSK_BRDY ? 0 : 1;
533       }
534       return data;
535     }
536 
537   }
538 
539   return 0x00;
540 }
541 
542 
543 
544 
545 
546 
547 
548 /***********************************************************************
549  * ���ơ��ȥ��ɡ����ơ��ȥ�����
550  ************************************************************************/
551 
552 #define	SID	"SND "
553 #define	SID2	"SND2"
554 #define	SID3	"SND3"
555 
556 static	T_SUSPEND_W	suspend_sound_work[] =
557 {
558   { TYPE_256,	sound_reg,	},
559   { TYPE_256,	sound2_reg,	},
560 
561   { TYPE_INT,	&sound_board,		},
562   { TYPE_INT,	&sound_port,		},	/* �ƽ��������Τ����פ��� */
563 
564   { TYPE_INT,	&intr_sound_enable,	},
565   { TYPE_INT,	&sound_ENABLE_A,	},
566   { TYPE_INT,	&sound_ENABLE_B,	},
567   { TYPE_INT,	&sound_LOAD_A,		},
568   { TYPE_INT,	&sound_LOAD_B,		},
569   { TYPE_INT,	&sound_FLAG_A,		},
570   { TYPE_INT,	&sound_FLAG_B,		},
571   { TYPE_INT,	&sound_TIMER_A,		},
572   { TYPE_INT,	&sound_TIMER_B,		},
573   { TYPE_INT,	&sound_prescaler,	},
574   { TYPE_INT,	&sound_reg_select,	},
575 
576   { TYPE_INT,	&sound2_MSK_TA,		},
577   { TYPE_INT,	&sound2_MSK_TB,		},
578   { TYPE_INT,	&sound2_MSK_EOS,	},
579   { TYPE_INT,	&sound2_MSK_BRDY,	},
580   { TYPE_INT,	&sound2_MSK_ZERO,	},
581 
582   { TYPE_INT,	&sound2_EN_TA,		},
583   { TYPE_INT,	&sound2_EN_TB,		},
584   { TYPE_INT,	&sound2_EN_EOS,		},
585   { TYPE_INT,	&sound2_EN_BRDY,	},
586   { TYPE_INT,	&sound2_EN_ZERO,	},
587 
588   { TYPE_INT,	&sound2_FLAG_EOS,	},
589   { TYPE_INT,	&sound2_FLAG_BRDY,	},
590   { TYPE_INT,	&sound2_FLAG_ZERO,	},
591   { TYPE_INT,	&sound2_FLAG_PCMBSY,	},
592 
593   { TYPE_INT,	&sound2_reg_select,	},
594 
595   { TYPE_INT,	&sound2_mem,		},
596   { TYPE_INT,	&sound2_rec,		},
597   { TYPE_INT,	&sound2_repeat,		},
598   { TYPE_INT,	&sound2_mem_size,	},
599   { TYPE_INT,	&sound2_record_intr_base,},
600   { TYPE_INT,	&sound2_replay_intr_base,},
601   { TYPE_INT,	&sound2_start_addr,	},
602   { TYPE_INT,	&sound2_stop_addr,	},
603   { TYPE_INT,	&sound2_limit_addr,	},
604   { TYPE_INT,	&sound2_read_dummy,	},
605   { TYPE_INT,	&sound2_stat,		},
606   { TYPE_INT,	&sound2_data_addr,	},
607   { TYPE_INT,	&sound2_intr_base,	},
608   { TYPE_INT,	&sound2_counter,	},
609   { TYPE_INT,	&sound2_counter_old,	},
610 
611   { TYPE_INT,	&sound2_notice_EOS,	},
612   { TYPE_INT,	&sound2_delay,		},
613 
614   { TYPE_END,	0			},
615 };
616 
617 static	T_SUSPEND_W	suspend_sound_work2[] =
618 {
619   { TYPE_INT,	&sound_prescaler_sel,	},
620   { TYPE_END,	0			},
621 };
622 
623 static	T_SUSPEND_W	suspend_sound_work3[] =
624 {
625   { TYPE_INT,	&use_cmdsing,		},
626   { TYPE_END,	0			},
627 };
628 
629 
630 
statesave_sound(void)631 int	statesave_sound( void )
632 {
633   if( statesave_table( SID, suspend_sound_work ) != STATE_OK ) return FALSE;
634 
635   if( statesave_table( SID2, suspend_sound_work2 ) != STATE_OK ) return FALSE;
636 
637   if( statesave_table( SID3, suspend_sound_work3 ) != STATE_OK ) return FALSE;
638 
639   return TRUE;
640 }
641 
stateload_sound(void)642 int	stateload_sound( void )
643 {
644   if( stateload_table( SID, suspend_sound_work ) != STATE_OK ) return FALSE;
645 
646   if( stateload_table( SID2, suspend_sound_work2 ) != STATE_OK ){
647 
648     /* ��С������ʤ顢�ߤΤ��� */
649 
650     printf( "stateload : Statefile is old. (ver 0.6.0 or 1?)\n" );
651 
652     if      ( sound_prescaler == 6 ) sound_prescaler_sel = 2;
653     else if ( sound_prescaler == 3 ) sound_prescaler_sel = 3;
654     else                      /* 2*/ sound_prescaler_sel = 0;	/* or 1 */
655   }
656 
657   if( stateload_table( SID3, suspend_sound_work3 ) != STATE_OK ){
658 
659     /* ��С������ʤ顢�ߤΤ��� */
660 
661     printf( "stateload : Statefile is old. (ver 0.6.0, 1, 2 or 3?)\n" );
662   }
663 
664   return TRUE;
665 }
666 
667 
668 
669 
670 
671 
672 
673 
674 
675 
676 
677 
678 
679 
680 
681 
682 #ifdef	USE_SOUND
683 
sound_output_after_stateload(void)684 void	sound_output_after_stateload( void )
685 {
686   /* �쥸�塼���κƽ���� */
687   /* ����ʤ�Ǥ��ޤ������Τ������� */
688 
689   const int (*addr)[2];
690   int size;
691 
692   static const int addr_2203[][2] = {
693     { 0x00, 0x0f },
694     { 0x24, 0x28 },
695     { 0x30, 0x3e },
696     { 0x40, 0x4e },
697     { 0x50, 0x5e },
698     { 0x60, 0x6e },
699     { 0x70, 0x7e },
700     { 0x80, 0x8e },
701     { 0x90, 0x9e },
702     { 0xa0, 0xa2 },
703     { 0xa4, 0xa6 },
704     { 0xa8, 0xaa },
705     { 0xac, 0xae },
706     { 0xb0, 0xb2 },
707   };
708   static const int addr_2608[][2] = {
709     { 0x00, 0x0f },
710     { 0x11, 0x12 },
711     { 0x18, 0x1d },
712     { 0x22, 0x22 },
713     { 0x24, 0x29 },
714     { 0x30, 0x3e },
715     { 0x40, 0x4e },
716     { 0x50, 0x5e },
717     { 0x60, 0x6e },
718     { 0x70, 0x7e },
719     { 0x80, 0x8e },
720     { 0x90, 0x9e },
721     { 0xa0, 0xa2 },
722     { 0xa4, 0xa6 },
723     { 0xa8, 0xaa },
724     { 0xac, 0xae },
725     { 0xb0, 0xb2 },
726   /*{ 0xb4, 0xb6 },*/		/* ���Υ쥸������ resume ������Ȳ����� */
727   };
728   static const int addr_2608_2[][2] = {
729     { 0x01, 0x10 },
730     { 0x30, 0x3e },
731     { 0x40, 0x4e },
732     { 0x50, 0x5e },
733     { 0x60, 0x6e },
734     { 0x70, 0x7e },
735     { 0x80, 0x8e },
736     { 0x90, 0x9e },
737     { 0xa0, 0xa2 },
738     { 0xa4, 0xa6 },
739     { 0xa8, 0xaa },
740     { 0xac, 0xae },
741     { 0xb0, 0xb2 },
742     { 0xb4, 0xb6 },
743   };
744 
745   if( xmame_has_sound() ){
746     int	i, j;
747 
748 #if 0
749     {
750       int  vol = xmame_cfg_get_mastervolume();
751       int pvol = xmame_cfg_get_mixer_volume( XMAME_MIXER_PSG );
752       int fvol = xmame_cfg_get_mixer_volume( XMAME_MIXER_FM );
753       int bvol = xmame_cfg_get_mixer_volume( XMAME_MIXER_BEEP );
754 
755 	/* �ߥ塼�� */
756 
757       xmame_cfg_set_mastervolume( 0 );
758       xmame_cfg_set_mixer_volume( XMAME_MIXER_PSG,  0 );
759       xmame_cfg_set_mixer_volume( XMAME_MIXER_FM,   0 );
760       xmame_cfg_set_mixer_volume( XMAME_MIXER_BEEP, 0 );
761     }
762 #endif
763 
764 	/* ������� �쥸�������� (ɬ�פʥݡ��ȤΤ�) */
765 
766     switch( sound_prescaler_sel ){
767     case 0:
768       xmame_dev_sound_out_reg( 0x2f );      xmame_dev_sound_out_data( 0 );
769       break;
770     case 1:
771       xmame_dev_sound_out_reg( 0x2f );      xmame_dev_sound_out_data( 0 );
772       xmame_dev_sound_out_reg( 0x2e );      xmame_dev_sound_out_data( 0 );
773       break;
774     case 3:
775       xmame_dev_sound_out_reg( 0x2e );      xmame_dev_sound_out_data( 0 );
776       break;
777     default:
778       break;
779     }
780 
781 
782     if( sound_board==SOUND_I ){ addr = addr_2203; size = COUNTOF(addr_2203); }
783     else                      { addr = addr_2608; size = COUNTOF(addr_2608); }
784 
785     for( i=0; i<256; i++ ){
786 
787       for( j=0; j<size; j++ ){
788 	if( addr[j][0] <= i  &&  i <= addr[j][1] ){
789 	  xmame_dev_sound_out_reg( i );
790 	  xmame_dev_sound_out_data( sound_reg[ i ] );
791 	  break;
792 	}
793       }
794 
795     }
796 
797     if( sound_board==SOUND_II ){
798       addr = addr_2608_2;
799       size = COUNTOF(addr_2608_2);
800 
801       for( i=0; i<256; i++ ){
802 
803 	for( j=0; j<size; j++ ){
804 	  if( addr[j][0] <= i  &&  i <= addr[j][1] ){
805 	    xmame_dev_sound2_out_reg( i );
806 	    xmame_dev_sound2_out_data( sound2_reg[ i ] );
807 	    break;
808 	  }
809 	}
810 
811       }
812 
813       i = sound2_reg[ 0 ];
814       i &= ~0x80;
815       xmame_dev_sound2_out_reg( 0 );
816       xmame_dev_sound2_out_data( i );
817     }
818 
819 #if 0
820 	/* �������� */
821     {
822       xmame_cfg_set_mastervolume( vol );
823       xmame_cfg_set_mixer_volume( XMAME_MIXER_PSG,  pvol );
824       xmame_cfg_set_mixer_volume( XMAME_MIXER_FM,   fvol );
825       xmame_cfg_set_mixer_volume( XMAME_MIXER_BEEP, bvol );
826     }
827 #endif
828 
829     xmame_dev_beep_cmd_sing(use_cmdsing);
830 
831     if( ctrl_signal & (0x80|0x20) ){
832       xmame_dev_beep_out_data( ctrl_signal );
833     }
834 
835   }
836 
837 }
838 
839 
840 
841 #else
842 
sound_output_after_stateload(void)843 void	sound_output_after_stateload( void )
844 {
845 }
846 
847 #endif
848