--- BasiliskII/src/audio.cpp 2001/07/11 19:26:13 1.9 +++ BasiliskII/src/audio.cpp 2008/01/01 09:40:31 1.16 @@ -1,8 +1,8 @@ /* * audio.cpp - Audio support * - * Basilisk II (C) 1997-2001 Christian Bauer - * Portions (C) 1997-1999 Marc Hellwig + * Basilisk II (C) 1997-2008 Christian Bauer + * Portions written by Marc Hellwig * * 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 @@ -134,18 +134,6 @@ static int32 AudioGetInfo(uint32 infoPtr WriteMacInt32(infoPtr, audio_get_speaker_volume()); break; - case siHeadphoneMute: - WriteMacInt16(infoPtr, 0); - break; - - case siHeadphoneVolume: - WriteMacInt32(infoPtr, 0x01000100); - break; - - case siHeadphoneVolumeSteps: - WriteMacInt16(infoPtr, 13); - break; - case siHardwareMute: WriteMacInt16(infoPtr, audio_get_main_mute()); break; @@ -155,13 +143,24 @@ static int32 AudioGetInfo(uint32 infoPtr break; case siHardwareVolumeSteps: - WriteMacInt16(infoPtr, 13); + WriteMacInt16(infoPtr, 7); break; case siHardwareBusy: WriteMacInt16(infoPtr, AudioStatus.num_sources != 0); break; + case siHardwareFormat: + WriteMacInt32(infoPtr + scd_flags, 0); + WriteMacInt32(infoPtr + scd_format, AudioStatus.sample_size == 16 ? FOURCC('t','w','o','s') : FOURCC('r','a','w',' ')); + WriteMacInt16(infoPtr + scd_numChannels, AudioStatus.channels); + WriteMacInt16(infoPtr + scd_sampleSize, AudioStatus.sample_size); + WriteMacInt32(infoPtr + scd_sampleRate, AudioStatus.sample_rate); + WriteMacInt32(infoPtr + scd_sampleCount, audio_frames_per_block); + WriteMacInt32(infoPtr + scd_buffer, 0); + WriteMacInt32(infoPtr + scd_reserved, 0); + break; + default: // Delegate to Apple Mixer if (AudioStatus.mixer == 0) return badComponentSelector; @@ -242,10 +241,6 @@ static int32 AudioSetInfo(uint32 infoPtr audio_set_speaker_volume(infoPtr); break; - case siHeadphoneMute: - case siHeadphoneVolume: - break; - case siHardwareMute: audio_set_main_mute((uint16)infoPtr); break; @@ -279,15 +274,19 @@ int32 AudioDispatch(uint32 params, uint3 D(bug("AudioDispatch params %08lx (size %d), what %d\n", params, ReadMacInt8(params + cp_paramSize), (int16)ReadMacInt16(params + cp_what))); M68kRegisters r; uint32 p = params + cp_params; + int16 selector = (int16)ReadMacInt16(params + cp_what); + + switch (selector) { - switch ((int16)ReadMacInt16(params + cp_what)) { - // Basic component functions + // General component functions case kComponentOpenSelect: if (audio_data == 0) { // Allocate global data area r.d[0] = SIZEOF_adat; - Execute68kTrap(0xa71e, &r); // NewPtrSysClear() + Execute68kTrap(0xa040, &r); // ResrvMem() + r.d[0] = SIZEOF_adat; + Execute68kTrap(0xa31e, &r); // NewPtrClear() if (r.a[0] == 0) return memFullErr; audio_data = r.a[0]; @@ -374,6 +373,18 @@ int32 AudioDispatch(uint32 params, uint3 WriteMacInt16(p, 0xa82a); p += 2; // ComponentDispatch WriteMacInt16(p, 0x201f); p += 2; // move.l (sp)+,d0 WriteMacInt16(p, M68K_RTS); p += 2; // rts + if (p - audio_data != adatStartSource) + goto adat_error; + WriteMacInt16(p, 0x598f); p += 2; // subq.l #4,sp + WriteMacInt16(p, 0x2f09); p += 2; // move.l a1,-(sp) + WriteMacInt16(p, 0x3f00); p += 2; // move.w d0,-(sp) + WriteMacInt16(p, 0x2f08); p += 2; // move.l a0,-(sp) + WriteMacInt16(p, 0x2f3c); p += 2; // move.l #$00060105,-(sp) + WriteMacInt32(p, 0x00060105); p+= 4; + WriteMacInt16(p, 0x7000); p += 2; // moveq #0,d0 + WriteMacInt16(p, 0xa82a); p += 2; // ComponentDispatch + WriteMacInt16(p, 0x201f); p += 2; // move.l (sp)+,d0 + WriteMacInt16(p, M68K_RTS); p += 2; // rts if (p - audio_data != adatData) goto adat_error; } @@ -387,29 +398,50 @@ adat_error: printf("FATAL: audio compone QuitEmulator(); return openErr; - case kComponentCanDoSelect: - case kComponentRegisterSelect: - return noErr; - - case kComponentVersionSelect: - return 0x00010003; - case kComponentCloseSelect: open_count--; if (open_count == 0) { - if (AudioStatus.mixer) { - // Close Apple Mixer - r.a[0] = AudioStatus.mixer; - Execute68k(audio_data + adatCloseMixer, &r); - AudioStatus.mixer = 0; - return r.d[0]; + if (audio_data) { + if (AudioStatus.mixer) { + // Close Apple Mixer + r.a[0] = AudioStatus.mixer; + Execute68k(audio_data + adatCloseMixer, &r); + AudioStatus.mixer = 0; + return r.d[0]; + } + r.a[0] = audio_data; + Execute68kTrap(0xa01f, &r); // DisposePtr() + audio_data = 0; } AudioStatus.num_sources = 0; audio_exit_stream(); } return noErr; - // Sound component functions + case kComponentCanDoSelect: + switch ((int16)ReadMacInt16(p)) { + case kComponentOpenSelect: + case kComponentCloseSelect: + case kComponentCanDoSelect: + case kComponentVersionSelect: + case kComponentRegisterSelect: + case kSoundComponentInitOutputDeviceSelect: + case kSoundComponentGetSourceSelect: + case kSoundComponentGetInfoSelect: + case kSoundComponentSetInfoSelect: + case kSoundComponentStartSourceSelect: + return 1; + default: + return 0; + } + + case kComponentVersionSelect: + return 0x00010003; + + case kComponentRegisterSelect: + return noErr; + + // Sound component functions (not delegated) case kSoundComponentInitOutputDeviceSelect: D(bug(" InitOutputDevice\n")); if (!audio_open) @@ -437,6 +469,12 @@ adat_error: printf("FATAL: audio compone D(bug(" OpenMixer() returns %08lx, mixer %08lx\n", r.d[0], AudioStatus.mixer)); return r.d[0]; + case kSoundComponentGetSourceSelect: + D(bug(" GetSource source %08lx\n", ReadMacInt32(p))); + WriteMacInt32(ReadMacInt32(p), AudioStatus.mixer); + return noErr; + + // Sound component functions (delegated) case kSoundComponentAddSourceSelect: D(bug(" AddSource\n")); AudioStatus.num_sources++; @@ -447,6 +485,22 @@ adat_error: printf("FATAL: audio compone AudioStatus.num_sources--; goto delegate; + case kSoundComponentGetInfoSelect: + return AudioGetInfo(ReadMacInt32(p), ReadMacInt32(p + 4), ReadMacInt32(p + 8)); + + case kSoundComponentSetInfoSelect: + return AudioSetInfo(ReadMacInt32(p), ReadMacInt32(p + 4), ReadMacInt32(p + 8)); + + case kSoundComponentStartSourceSelect: + D(bug(" StartSource count %d\n", ReadMacInt16(p + 4))); + D(bug(" starting Apple Mixer\n")); + r.d[0] = ReadMacInt16(p + 4); + r.a[0] = ReadMacInt32(p); + r.a[1] = AudioStatus.mixer; + Execute68k(audio_data + adatStartSource, &r); + D(bug(" returns %08lx\n", r.d[0])); + return noErr; + case kSoundComponentStopSourceSelect: D(bug(" StopSource\n")); goto delegate; @@ -461,18 +515,8 @@ delegate: // Delegate call to Apple Mixe D(bug(" returns %08lx\n", r.d[0])); return r.d[0]; - case kSoundComponentStartSourceSelect: - D(bug(" StartSource\n")); - return noErr; - - case kSoundComponentGetInfoSelect: - return AudioGetInfo(ReadMacInt32(p), ReadMacInt32(p + 4), ReadMacInt32(p + 8)); - - case kSoundComponentSetInfoSelect: - return AudioSetInfo(ReadMacInt32(p), ReadMacInt32(p + 4), ReadMacInt32(p + 8)); - case kSoundComponentPlaySourceBufferSelect: - D(bug(" PlaySourceBuffer\n")); + D(bug(" PlaySourceBuffer flags %08lx\n", ReadMacInt32(p))); r.d[0] = ReadMacInt32(p); r.a[0] = ReadMacInt32(p + 4); r.a[1] = ReadMacInt32(p + 8); @@ -482,7 +526,10 @@ delegate: // Delegate call to Apple Mixe return r.d[0]; default: - return badComponentSelector; + if (selector >= 0x100) + goto delegate; + else + return badComponentSelector; } } @@ -564,29 +611,29 @@ int16 SoundInStatus(uint32 pb, uint32 dc case siDeviceIcon: { M68kRegisters r; - static const uint16 proc[] = { - 0x558f, // subq.l #2,sp - 0xa994, // CurResFile - 0x4267, // clr.w -(sp) - 0xa998, // UseResFile - 0x598f, // subq.l #4,sp - 0x4879, 0x4943, 0x4e23, // move.l #'ICN#',-(sp) - 0x3f3c, 0xbf76, // move.w #-16522,-(sp) - 0xa9a0, // GetResource - 0x245f, // move.l (sp)+,a2 - 0xa998, // UseResFile - 0x200a, // move.l a2,d0 - 0x6604, // bne 1 - 0x7000, // moveq #0,d0 - M68K_RTS, - 0x2f0a, //1 move.l a2,-(sp) - 0xa992, // DetachResource - 0x204a, // move.l a2,a0 - 0xa04a, // HNoPurge - 0x7001, // moveq #1,d0 - M68K_RTS + static const uint8 proc[] = { + 0x55, 0x8f, // subq.l #2,sp + 0xa9, 0x94, // CurResFile + 0x42, 0x67, // clr.w -(sp) + 0xa9, 0x98, // UseResFile + 0x59, 0x8f, // subq.l #4,sp + 0x48, 0x79, 0x49, 0x43, 0x4e, 0x23, // move.l #'ICN#',-(sp) + 0x3f, 0x3c, 0xbf, 0x76, // move.w #-16522,-(sp) + 0xa9, 0xa0, // GetResource + 0x24, 0x5f, // move.l (sp)+,a2 + 0xa9, 0x98, // UseResFile + 0x20, 0x0a, // move.l a2,d0 + 0x66, 0x04, // bne 1 + 0x70, 0x00, // moveq #0,d0 + M68K_RTS >> 8, M68K_RTS & 0xff, + 0x2f, 0x0a, //1 move.l a2,-(sp) + 0xa9, 0x92, // DetachResource + 0x20, 0x4a, // move.l a2,a0 + 0xa0, 0x4a, // HNoPurge + 0x70, 0x01, // moveq #1,d0 + M68K_RTS >> 8, M68K_RTS & 0xff }; - Execute68k((uint32)proc, &r); + Execute68k(Host2MacAddr((uint8 *)proc), &r); if (r.d[0]) { param[0] = 4; // Length of returned data param[1] = r.a[2]; // Handle to icon suite