1 |
|
/* |
2 |
|
* audio.cpp - Audio support |
3 |
|
* |
4 |
< |
* Basilisk II (C) 1997-2001 Christian Bauer |
5 |
< |
* Portions (C) 1997-1999 Marc Hellwig |
4 |
> |
* Basilisk II (C) 1997-2004 Christian Bauer |
5 |
> |
* Portions written by Marc Hellwig |
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 |
134 |
|
WriteMacInt32(infoPtr, audio_get_speaker_volume()); |
135 |
|
break; |
136 |
|
|
137 |
– |
case siHeadphoneMute: |
138 |
– |
WriteMacInt16(infoPtr, 0); |
139 |
– |
break; |
140 |
– |
|
141 |
– |
case siHeadphoneVolume: |
142 |
– |
WriteMacInt32(infoPtr, 0x01000100); |
143 |
– |
break; |
144 |
– |
|
145 |
– |
case siHeadphoneVolumeSteps: |
146 |
– |
WriteMacInt16(infoPtr, 13); |
147 |
– |
break; |
148 |
– |
|
137 |
|
case siHardwareMute: |
138 |
|
WriteMacInt16(infoPtr, audio_get_main_mute()); |
139 |
|
break; |
143 |
|
break; |
144 |
|
|
145 |
|
case siHardwareVolumeSteps: |
146 |
< |
WriteMacInt16(infoPtr, 13); |
146 |
> |
WriteMacInt16(infoPtr, 7); |
147 |
|
break; |
148 |
|
|
149 |
|
case siHardwareBusy: |
150 |
|
WriteMacInt16(infoPtr, AudioStatus.num_sources != 0); |
151 |
|
break; |
152 |
|
|
153 |
+ |
case siHardwareFormat: |
154 |
+ |
WriteMacInt32(infoPtr + scd_flags, 0); |
155 |
+ |
WriteMacInt32(infoPtr + scd_format, AudioStatus.sample_size == 16 ? FOURCC('t','w','o','s') : FOURCC('r','a','w',' ')); |
156 |
+ |
WriteMacInt16(infoPtr + scd_numChannels, AudioStatus.channels); |
157 |
+ |
WriteMacInt16(infoPtr + scd_sampleSize, AudioStatus.sample_size); |
158 |
+ |
WriteMacInt32(infoPtr + scd_sampleRate, AudioStatus.sample_rate); |
159 |
+ |
WriteMacInt32(infoPtr + scd_sampleCount, audio_frames_per_block); |
160 |
+ |
WriteMacInt32(infoPtr + scd_buffer, 0); |
161 |
+ |
WriteMacInt32(infoPtr + scd_reserved, 0); |
162 |
+ |
break; |
163 |
+ |
|
164 |
|
default: // Delegate to Apple Mixer |
165 |
|
if (AudioStatus.mixer == 0) |
166 |
|
return badComponentSelector; |
241 |
|
audio_set_speaker_volume(infoPtr); |
242 |
|
break; |
243 |
|
|
245 |
– |
case siHeadphoneMute: |
246 |
– |
case siHeadphoneVolume: |
247 |
– |
break; |
248 |
– |
|
244 |
|
case siHardwareMute: |
245 |
|
audio_set_main_mute((uint16)infoPtr); |
246 |
|
break; |
274 |
|
D(bug("AudioDispatch params %08lx (size %d), what %d\n", params, ReadMacInt8(params + cp_paramSize), (int16)ReadMacInt16(params + cp_what))); |
275 |
|
M68kRegisters r; |
276 |
|
uint32 p = params + cp_params; |
277 |
+ |
int16 selector = (int16)ReadMacInt16(params + cp_what); |
278 |
+ |
|
279 |
+ |
switch (selector) { |
280 |
|
|
281 |
< |
switch ((int16)ReadMacInt16(params + cp_what)) { |
284 |
< |
// Basic component functions |
281 |
> |
// General component functions |
282 |
|
case kComponentOpenSelect: |
283 |
|
if (audio_data == 0) { |
284 |
|
|
285 |
|
// Allocate global data area |
286 |
|
r.d[0] = SIZEOF_adat; |
287 |
< |
Execute68kTrap(0xa71e, &r); // NewPtrSysClear() |
287 |
> |
Execute68kTrap(0xa040, &r); // ResrvMem() |
288 |
> |
r.d[0] = SIZEOF_adat; |
289 |
> |
Execute68kTrap(0xa31e, &r); // NewPtrClear() |
290 |
|
if (r.a[0] == 0) |
291 |
|
return memFullErr; |
292 |
|
audio_data = r.a[0]; |
373 |
|
WriteMacInt16(p, 0xa82a); p += 2; // ComponentDispatch |
374 |
|
WriteMacInt16(p, 0x201f); p += 2; // move.l (sp)+,d0 |
375 |
|
WriteMacInt16(p, M68K_RTS); p += 2; // rts |
376 |
+ |
if (p - audio_data != adatStartSource) |
377 |
+ |
goto adat_error; |
378 |
+ |
WriteMacInt16(p, 0x598f); p += 2; // subq.l #4,sp |
379 |
+ |
WriteMacInt16(p, 0x2f09); p += 2; // move.l a1,-(sp) |
380 |
+ |
WriteMacInt16(p, 0x3f00); p += 2; // move.w d0,-(sp) |
381 |
+ |
WriteMacInt16(p, 0x2f08); p += 2; // move.l a0,-(sp) |
382 |
+ |
WriteMacInt16(p, 0x2f3c); p += 2; // move.l #$00060105,-(sp) |
383 |
+ |
WriteMacInt32(p, 0x00060105); p+= 4; |
384 |
+ |
WriteMacInt16(p, 0x7000); p += 2; // moveq #0,d0 |
385 |
+ |
WriteMacInt16(p, 0xa82a); p += 2; // ComponentDispatch |
386 |
+ |
WriteMacInt16(p, 0x201f); p += 2; // move.l (sp)+,d0 |
387 |
+ |
WriteMacInt16(p, M68K_RTS); p += 2; // rts |
388 |
|
if (p - audio_data != adatData) |
389 |
|
goto adat_error; |
390 |
|
} |
398 |
|
QuitEmulator(); |
399 |
|
return openErr; |
400 |
|
|
390 |
– |
case kComponentCanDoSelect: |
391 |
– |
case kComponentRegisterSelect: |
392 |
– |
return noErr; |
393 |
– |
|
394 |
– |
case kComponentVersionSelect: |
395 |
– |
return 0x00010003; |
396 |
– |
|
401 |
|
case kComponentCloseSelect: |
402 |
|
open_count--; |
403 |
|
if (open_count == 0) { |
404 |
< |
if (AudioStatus.mixer) { |
405 |
< |
// Close Apple Mixer |
406 |
< |
r.a[0] = AudioStatus.mixer; |
407 |
< |
Execute68k(audio_data + adatCloseMixer, &r); |
408 |
< |
AudioStatus.mixer = 0; |
409 |
< |
return r.d[0]; |
404 |
> |
if (audio_data) { |
405 |
> |
if (AudioStatus.mixer) { |
406 |
> |
// Close Apple Mixer |
407 |
> |
r.a[0] = AudioStatus.mixer; |
408 |
> |
Execute68k(audio_data + adatCloseMixer, &r); |
409 |
> |
AudioStatus.mixer = 0; |
410 |
> |
return r.d[0]; |
411 |
> |
} |
412 |
> |
r.a[0] = audio_data; |
413 |
> |
Execute68kTrap(0xa01f, &r); // DisposePtr() |
414 |
> |
audio_data = 0; |
415 |
|
} |
416 |
|
AudioStatus.num_sources = 0; |
417 |
|
audio_exit_stream(); |
418 |
|
} |
419 |
|
return noErr; |
420 |
|
|
421 |
< |
// Sound component functions |
421 |
> |
case kComponentCanDoSelect: |
422 |
> |
switch ((int16)ReadMacInt16(p)) { |
423 |
> |
case kComponentOpenSelect: |
424 |
> |
case kComponentCloseSelect: |
425 |
> |
case kComponentCanDoSelect: |
426 |
> |
case kComponentVersionSelect: |
427 |
> |
case kComponentRegisterSelect: |
428 |
> |
case kSoundComponentInitOutputDeviceSelect: |
429 |
> |
case kSoundComponentGetSourceSelect: |
430 |
> |
case kSoundComponentGetInfoSelect: |
431 |
> |
case kSoundComponentSetInfoSelect: |
432 |
> |
case kSoundComponentStartSourceSelect: |
433 |
> |
return 1; |
434 |
> |
default: |
435 |
> |
return 0; |
436 |
> |
} |
437 |
> |
|
438 |
> |
case kComponentVersionSelect: |
439 |
> |
return 0x00010003; |
440 |
> |
|
441 |
> |
case kComponentRegisterSelect: |
442 |
> |
return noErr; |
443 |
> |
|
444 |
> |
// Sound component functions (not delegated) |
445 |
|
case kSoundComponentInitOutputDeviceSelect: |
446 |
|
D(bug(" InitOutputDevice\n")); |
447 |
|
if (!audio_open) |
469 |
|
D(bug(" OpenMixer() returns %08lx, mixer %08lx\n", r.d[0], AudioStatus.mixer)); |
470 |
|
return r.d[0]; |
471 |
|
|
472 |
+ |
case kSoundComponentGetSourceSelect: |
473 |
+ |
D(bug(" GetSource source %08lx\n", ReadMacInt32(p))); |
474 |
+ |
WriteMacInt32(ReadMacInt32(p), AudioStatus.mixer); |
475 |
+ |
return noErr; |
476 |
+ |
|
477 |
+ |
// Sound component functions (delegated) |
478 |
|
case kSoundComponentAddSourceSelect: |
479 |
|
D(bug(" AddSource\n")); |
480 |
|
AudioStatus.num_sources++; |
485 |
|
AudioStatus.num_sources--; |
486 |
|
goto delegate; |
487 |
|
|
488 |
+ |
case kSoundComponentGetInfoSelect: |
489 |
+ |
return AudioGetInfo(ReadMacInt32(p), ReadMacInt32(p + 4), ReadMacInt32(p + 8)); |
490 |
+ |
|
491 |
+ |
case kSoundComponentSetInfoSelect: |
492 |
+ |
return AudioSetInfo(ReadMacInt32(p), ReadMacInt32(p + 4), ReadMacInt32(p + 8)); |
493 |
+ |
|
494 |
+ |
case kSoundComponentStartSourceSelect: |
495 |
+ |
D(bug(" StartSource count %d\n", ReadMacInt16(p + 4))); |
496 |
+ |
D(bug(" starting Apple Mixer\n")); |
497 |
+ |
r.d[0] = ReadMacInt16(p + 4); |
498 |
+ |
r.a[0] = ReadMacInt32(p); |
499 |
+ |
r.a[1] = AudioStatus.mixer; |
500 |
+ |
Execute68k(audio_data + adatStartSource, &r); |
501 |
+ |
D(bug(" returns %08lx\n", r.d[0])); |
502 |
+ |
return noErr; |
503 |
+ |
|
504 |
|
case kSoundComponentStopSourceSelect: |
505 |
|
D(bug(" StopSource\n")); |
506 |
|
goto delegate; |
515 |
|
D(bug(" returns %08lx\n", r.d[0])); |
516 |
|
return r.d[0]; |
517 |
|
|
464 |
– |
case kSoundComponentStartSourceSelect: |
465 |
– |
D(bug(" StartSource\n")); |
466 |
– |
return noErr; |
467 |
– |
|
468 |
– |
case kSoundComponentGetInfoSelect: |
469 |
– |
return AudioGetInfo(ReadMacInt32(p), ReadMacInt32(p + 4), ReadMacInt32(p + 8)); |
470 |
– |
|
471 |
– |
case kSoundComponentSetInfoSelect: |
472 |
– |
return AudioSetInfo(ReadMacInt32(p), ReadMacInt32(p + 4), ReadMacInt32(p + 8)); |
473 |
– |
|
518 |
|
case kSoundComponentPlaySourceBufferSelect: |
519 |
< |
D(bug(" PlaySourceBuffer\n")); |
519 |
> |
D(bug(" PlaySourceBuffer flags %08lx\n", ReadMacInt32(p))); |
520 |
|
r.d[0] = ReadMacInt32(p); |
521 |
|
r.a[0] = ReadMacInt32(p + 4); |
522 |
|
r.a[1] = ReadMacInt32(p + 8); |
526 |
|
return r.d[0]; |
527 |
|
|
528 |
|
default: |
529 |
< |
return badComponentSelector; |
529 |
> |
if (selector >= 0x100) |
530 |
> |
goto delegate; |
531 |
> |
else |
532 |
> |
return badComponentSelector; |
533 |
|
} |
534 |
|
} |
535 |
|
|
611 |
|
|
612 |
|
case siDeviceIcon: { |
613 |
|
M68kRegisters r; |
614 |
< |
static const uint16 proc[] = { |
615 |
< |
0x558f, // subq.l #2,sp |
616 |
< |
0xa994, // CurResFile |
617 |
< |
0x4267, // clr.w -(sp) |
618 |
< |
0xa998, // UseResFile |
619 |
< |
0x598f, // subq.l #4,sp |
620 |
< |
0x4879, 0x4943, 0x4e23, // move.l #'ICN#',-(sp) |
621 |
< |
0x3f3c, 0xbf76, // move.w #-16522,-(sp) |
622 |
< |
0xa9a0, // GetResource |
623 |
< |
0x245f, // move.l (sp)+,a2 |
624 |
< |
0xa998, // UseResFile |
625 |
< |
0x200a, // move.l a2,d0 |
626 |
< |
0x6604, // bne 1 |
627 |
< |
0x7000, // moveq #0,d0 |
628 |
< |
M68K_RTS, |
629 |
< |
0x2f0a, //1 move.l a2,-(sp) |
630 |
< |
0xa992, // DetachResource |
631 |
< |
0x204a, // move.l a2,a0 |
632 |
< |
0xa04a, // HNoPurge |
633 |
< |
0x7001, // moveq #1,d0 |
634 |
< |
M68K_RTS |
614 |
> |
static const uint8 proc[] = { |
615 |
> |
0x55, 0x8f, // subq.l #2,sp |
616 |
> |
0xa9, 0x94, // CurResFile |
617 |
> |
0x42, 0x67, // clr.w -(sp) |
618 |
> |
0xa9, 0x98, // UseResFile |
619 |
> |
0x59, 0x8f, // subq.l #4,sp |
620 |
> |
0x48, 0x79, 0x49, 0x43, 0x4e, 0x23, // move.l #'ICN#',-(sp) |
621 |
> |
0x3f, 0x3c, 0xbf, 0x76, // move.w #-16522,-(sp) |
622 |
> |
0xa9, 0xa0, // GetResource |
623 |
> |
0x24, 0x5f, // move.l (sp)+,a2 |
624 |
> |
0xa9, 0x98, // UseResFile |
625 |
> |
0x20, 0x0a, // move.l a2,d0 |
626 |
> |
0x66, 0x04, // bne 1 |
627 |
> |
0x70, 0x00, // moveq #0,d0 |
628 |
> |
M68K_RTS >> 8, M68K_RTS & 0xff, |
629 |
> |
0x2f, 0x0a, //1 move.l a2,-(sp) |
630 |
> |
0xa9, 0x92, // DetachResource |
631 |
> |
0x20, 0x4a, // move.l a2,a0 |
632 |
> |
0xa0, 0x4a, // HNoPurge |
633 |
> |
0x70, 0x01, // moveq #1,d0 |
634 |
> |
M68K_RTS >> 8, M68K_RTS & 0xff |
635 |
|
}; |
636 |
|
Execute68k((uint32)proc, &r); |
637 |
|
if (r.d[0]) { |