mirror of
https://github.com/kanjitalk755/macemu.git
synced 2025-01-10 18:29:44 +00:00
Cleaner soundin driver implementation
This commit is contained in:
parent
177555e0d1
commit
2a904af8e7
@ -33,7 +33,6 @@
|
||||
#include "audio_defs.h"
|
||||
#include "user_strings.h"
|
||||
#include "cdrom.h"
|
||||
#include "vm_alloc.h"
|
||||
|
||||
#define DEBUG 0
|
||||
#include "debug.h"
|
||||
@ -54,8 +53,6 @@ static int open_count = 0; // Open/close nesting count
|
||||
|
||||
bool AudioAvailable = false; // Flag: audio output available (from the software point of view)
|
||||
|
||||
uint32 SoundInNameAddr;
|
||||
uint32 SoundInSourcesAddr;
|
||||
int SoundInSource = 2;
|
||||
int SoundInPlaythrough = 7;
|
||||
int SoundInGain = 65536; // FIXED 4-byte from 0.5 to 1.5; this is middle value (1) as int
|
||||
@ -647,12 +644,11 @@ int16 SoundInStatus(uint32 pb, uint32 dce) // A0 points to Device Manager parame
|
||||
|
||||
// two choices on return
|
||||
// 1: if under 18 bytes, place # of bytes at (pb+csParam) and write from (pb+csParam+4) on
|
||||
// 2: if over 18 bytes, place 0 at (pb+csParam) and directly write into buffer pointed to by bufferptr
|
||||
// 2: if over 18 bytes, place 0 at (pb+csParam) and directly write into address pointed to by (pb+csParam+4)
|
||||
uint32 selector = ReadMacInt32(pb + csParam); // 4-byte selector (should match via FOURCC above)
|
||||
uint32 bufferptr = ReadMacInt32(pb + csParam + 4); // 4-byte address to the buffer in vm memory
|
||||
|
||||
switch (selector) {
|
||||
//#if 0
|
||||
case siDeviceName: { // return name in STR255 format
|
||||
const uint8 str[] = { // size 9
|
||||
0x08, // 1-byte length
|
||||
@ -662,7 +658,7 @@ int16 SoundInStatus(uint32 pb, uint32 dce) // A0 points to Device Manager parame
|
||||
0x69, 0x6e // in
|
||||
};
|
||||
// const uint8 str[] = { // size 12
|
||||
// 0x0b, // 1-byte length
|
||||
// 0x0b, // 1-byte length
|
||||
// 0x53, 0x68, // Sh
|
||||
// 0x65, 0x65, // ee
|
||||
// 0x70, 0x73, // ps
|
||||
@ -670,33 +666,26 @@ int16 SoundInStatus(uint32 pb, uint32 dce) // A0 points to Device Manager parame
|
||||
// 0x76, 0x65, // ve
|
||||
// 0x72 // r
|
||||
// };
|
||||
WriteMacInt32(pb + csParam, 0); // response will directly be written into buffer
|
||||
// vm_memcpy(bufferptr, str, 9);
|
||||
// memcpy(Mac2HostAddr(bufferptr),str,9);
|
||||
|
||||
WriteMacInt32(pb + csParam, 0); // response will be written directly into buffer
|
||||
vm_memcpy(bufferptr, str, sizeof(str));
|
||||
// memcpy(Mac2HostAddr(bufferptr),str,sizeof(str));
|
||||
|
||||
// WriteMacInt32(pb + csParam, sizeof(str));
|
||||
// uint8* virtual_addr = (uint8*) vm_acquire(sizeof(str));
|
||||
// memcpy((uint8*) virtual_addr, str, sizeof(str));
|
||||
// WriteMacInt32(bufferptr, Host2MacAddr(virtual_addr));
|
||||
// WriteMacInt32(ReadMacInt32(bufferptr), SoundInNameAddr);
|
||||
|
||||
// vm_memcpy(bufferptr, SoundInNameAddr, 12);
|
||||
|
||||
// uint32 virtual_addr = Mac_sysalloc(sizeof(str));
|
||||
// Host2Mac_memcpy(virtual_addr, str, sizeof(str));
|
||||
// WriteMacInt32(bufferptr, virtual_addr);
|
||||
|
||||
return noErr;
|
||||
}
|
||||
|
||||
case siDeviceIcon: {
|
||||
// Borrow ICN resource from cd rom driver, just a hack since loading a true ICN would be better
|
||||
// todo: add soundin ICN, borrow from CD ROM for now
|
||||
WriteMacInt32(pb + csParam, 0);
|
||||
WriteMacInt32(bufferptr, CDROMIconAddr);
|
||||
// vm_memcpy(bufferptr, CDROMIconAddr, sizeof(CDROMIcon));
|
||||
|
||||
M68kRegisters r;
|
||||
r.d[0] = sizeof(CDROMIcon);
|
||||
Execute68kTrap(0xa122, &r); // NewHandle()
|
||||
uint32 h = r.a[0];
|
||||
if (h == 0)
|
||||
return memFullErr;
|
||||
WriteMacInt32(bufferptr, h);
|
||||
uint32 sp = ReadMacInt32(h);
|
||||
vm_memcpy(sp, CDROMIcon, sizeof(CDROMIcon));
|
||||
|
||||
return noErr;
|
||||
|
||||
// 68k code causes crash in sheep and link error in basilisk
|
||||
@ -733,21 +722,20 @@ int16 SoundInStatus(uint32 pb, uint32 dce) // A0 points to Device Manager parame
|
||||
}
|
||||
|
||||
case siInputSource: {
|
||||
// return -231 if only 1 or index if more
|
||||
// return -231;
|
||||
|
||||
// return -231 if only 1 or index of current source if more
|
||||
|
||||
WriteMacInt32(pb + csParam, 2);
|
||||
WriteMacInt16(pb + csParam + 4, SoundInSource); // index of selected source
|
||||
return noErr;
|
||||
}
|
||||
|
||||
case siInputSourceNames: { // list of sources in STR# resource format
|
||||
case siInputSourceNames: {
|
||||
// return -231 if only 1 or handle to STR# resource if more
|
||||
// return -231;
|
||||
|
||||
const uint8 str[] = {
|
||||
0x00, 0x02, // 2-byte count of #strings
|
||||
0x0a, // byte size indicator (up to 255 length supported)
|
||||
// byte size indicator (up to 255 length supported)
|
||||
0x0a, // size is 10
|
||||
0x4d, 0x69, // Mi
|
||||
0x63, 0x72, // cr
|
||||
0x6f, 0x70, // op
|
||||
@ -761,36 +749,26 @@ int16 SoundInStatus(uint32 pb, uint32 dce) // A0 points to Device Manager parame
|
||||
0x20, 0x43, // C
|
||||
0x44, // D
|
||||
};
|
||||
//
|
||||
|
||||
WriteMacInt32(pb + csParam, 0);
|
||||
// vm_memcpy(bufferptr, str, 25);
|
||||
|
||||
// vm_memcpy(bufferptr, SoundInSourcesAddr, sizeof(str));
|
||||
// WriteMacInt32(bufferptr, SoundInSourcesAddr);
|
||||
|
||||
// WriteMacInt32(ReadMacInt32(bufferptr),SoundInSourcesAddr);
|
||||
|
||||
|
||||
M68kRegisters r;
|
||||
// r.d[0] = audio_channel_counts.size() * 2;
|
||||
r.d[0] = sizeof(str);
|
||||
Execute68kTrap(0xa122, &r); // NewHandle()
|
||||
uint32 h = r.a[0];
|
||||
if (h == 0)
|
||||
return memFullErr;
|
||||
// WriteMacInt16(infoPtr + sil_count, audio_channel_counts.size());
|
||||
WriteMacInt32(bufferptr, h);
|
||||
uint32 sp = ReadMacInt32(h);
|
||||
vm_memcpy(sp, str, sizeof(str));
|
||||
// for (unsigned i=0; i<audio_channel_counts.size(); i++)
|
||||
// WriteMacInt16(sp + i*2, audio_channel_counts[i]);
|
||||
|
||||
return noErr;
|
||||
}
|
||||
|
||||
case siOptionsDialog: {
|
||||
// 0 if no options box supported and 1 if so
|
||||
WriteMacInt32(pb + csParam, 2);
|
||||
WriteMacInt16(pb + csParam + 4, 1);
|
||||
WriteMacInt32(pb + csParam, 2); // response not in buffer, need to copy integer
|
||||
WriteMacInt16(pb + csParam + 4, 1); // Integer data type
|
||||
return noErr;
|
||||
}
|
||||
|
||||
@ -809,12 +787,8 @@ int16 SoundInStatus(uint32 pb, uint32 dce) // A0 points to Device Manager parame
|
||||
}
|
||||
|
||||
case siSampleRate: {
|
||||
// const uint8 samp[] = {
|
||||
// 0xac, 0x44, 0x00, 0x00
|
||||
// };
|
||||
WriteMacInt32(pb + csParam, 0);
|
||||
// memcpy(Mac2HostAddr(bufferptr),samp,sizeof(samp));
|
||||
WriteMacInt32(bufferptr, 0xac440000);
|
||||
WriteMacInt32(bufferptr, 0xac440000); // 44100.00000 Hz, of Fixed data type
|
||||
return noErr;
|
||||
}
|
||||
|
||||
@ -822,10 +796,10 @@ int16 SoundInStatus(uint32 pb, uint32 dce) // A0 points to Device Manager parame
|
||||
WriteMacInt32(pb + csParam, 0);
|
||||
|
||||
uint32 virtual_addr = Mac_sysalloc(4);
|
||||
WriteMacInt32(virtual_addr, 0xac440000);
|
||||
WriteMacInt32(virtual_addr, 0xac440000); // 44100.00000 Hz, of Fixed data type
|
||||
|
||||
WriteMacInt16(bufferptr, 1);
|
||||
WriteMacInt32(bufferptr + 2, virtual_addr);
|
||||
WriteMacInt16(bufferptr, 1); // 1 sample rate available
|
||||
WriteMacInt32(bufferptr + 2, virtual_addr); // handle to the sample rate list
|
||||
return noErr;
|
||||
}
|
||||
|
||||
@ -836,7 +810,6 @@ int16 SoundInStatus(uint32 pb, uint32 dce) // A0 points to Device Manager parame
|
||||
}
|
||||
|
||||
|
||||
//#endif
|
||||
default:
|
||||
return -231; // siUnknownInfoType
|
||||
}
|
||||
|
@ -37,9 +37,6 @@ extern int16 SoundInControl(uint32 pb, uint32 dce);
|
||||
extern int16 SoundInStatus(uint32 pb, uint32 dce);
|
||||
extern int16 SoundInClose(uint32 pb, uint32 dce);
|
||||
|
||||
extern uint32 SoundInNameAddr; // Address of SoundIn patched name
|
||||
extern uint32 SoundInSourcesAddr; // Address of SoundIn patched source list
|
||||
|
||||
// System specific and internal functions/data
|
||||
extern void AudioInit(void);
|
||||
extern void AudioExit(void);
|
||||
|
@ -82,7 +82,7 @@ const uint32 siDeviceName = FOURCC('n','a','m','e'); // sound input name
|
||||
const uint32 siDeviceIcon = FOURCC('i','c','o','n'); // sound input icon resource location
|
||||
const uint32 siInputSourceNames = FOURCC('s','n','a','m'); // sound input source names
|
||||
const uint32 siInputSource = FOURCC('s','o','u','r'); // sound input source selector
|
||||
const uint32 siInputGain = FOURCC('g','a','i','n'); // sound input source selector
|
||||
const uint32 siInputGain = FOURCC('g','a','i','n'); // sound input gain
|
||||
const uint32 siOptionsDialog = FOURCC('o','p','t','d'); // display options dialog box
|
||||
const uint32 siPlayThruOnOff = FOURCC('p','l','t','h'); // play-through state
|
||||
const uint32 siInitializeDriver = FOURCC('i','n','i','t'); // open sound input device
|
||||
|
@ -86,35 +86,6 @@ static const uint8 sound_input_driver[] = { // .AppleSoundInput driver header
|
||||
M68K_EMUL_OP_SOUNDIN_CLOSE >> 8, M68K_EMUL_OP_SOUNDIN_CLOSE & 0xff,
|
||||
0x4e, 0x75, // rts
|
||||
};
|
||||
static const uint8 sound_input_resources[] = {
|
||||
// DRVR resources
|
||||
// Name
|
||||
0x0b, // 1-byte length
|
||||
0x53, 0x68, // Sh
|
||||
0x65, 0x65, // ee
|
||||
0x70, 0x73, // ps
|
||||
0x68, 0x61, // ha
|
||||
0x76, 0x65, // ve
|
||||
0x72, // r
|
||||
|
||||
// Source list
|
||||
0x00, 0x02, // 2-byte count of #strings
|
||||
0x0b, // byte size indicator (up to 255 length supported)
|
||||
0x49, 0x6e, // start of string in ASCII, In
|
||||
0x74, 0x65, // te
|
||||
0x72, 0x6e, // rn
|
||||
0x61, 0x6c, // al
|
||||
0x20, 0x43, // C
|
||||
0x44, // D
|
||||
0x0a, // size is 10
|
||||
0x4d, 0x69, // Mi
|
||||
0x63, 0x72, // cr
|
||||
0x6f, 0x70, // op
|
||||
0x68, 0x6f, // ho
|
||||
0x6e, 0x65, // ne
|
||||
|
||||
};
|
||||
bool audio_patched = false;
|
||||
|
||||
/*
|
||||
* Search resource for byte string, return offset (or 0)
|
||||
@ -545,16 +516,10 @@ void CheckLoad(uint32 type, int16 id, uint16 *p, uint32 size)
|
||||
D(bug(" patch applied\n"));
|
||||
}
|
||||
|
||||
} else if (type == FOURCC('D','R','V','R') && (id == -16501 || id == -16500)) { // -16500 will patch over native sound input driver and traps out to code in audio.cpp
|
||||
} else if (type == FOURCC('D','R','V','R') && (id == -16501 || id == -16500)) { // patch over native sound input driver and trap out to code in audio.cpp
|
||||
D(bug("DRVR -16501/-16500 found\n"));
|
||||
// Install sound input driver
|
||||
vm_memcpy(Host2MacAddr((uint8 *) p), sound_input_driver, sizeof(sound_input_driver));
|
||||
vm_memcpy(Host2MacAddr((uint8 *) p) + sizeof(sound_input_driver), sound_input_resources, sizeof(sound_input_resources));
|
||||
if (!audio_patched) {
|
||||
SoundInNameAddr = Host2MacAddr((uint8 *) p) + sizeof(sound_input_driver);
|
||||
SoundInSourcesAddr = Host2MacAddr((uint8 *) p) + sizeof(sound_input_driver) + 12;
|
||||
audio_patched = true;
|
||||
}
|
||||
D(bug(" patch 1 applied\n"));
|
||||
} else if (type == FOURCC('I','N','I','T') && id == 1 && size == (2416 >> 1)) {
|
||||
D(bug("INIT 1 (size 2416) found\n"));
|
||||
|
Loading…
x
Reference in New Issue
Block a user