Merge pull request #47 from spolsley/master

Restoring sound DRVR patch for New World ROMs
This commit is contained in:
kanjitalk755 2020-09-12 19:03:03 +09:00 committed by GitHub
commit 3cf23176f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 128 additions and 46 deletions

View File

@ -53,6 +53,9 @@ static int open_count = 0; // Open/close nesting count
bool AudioAvailable = false; // Flag: audio output available (from the software point of view) bool AudioAvailable = false; // Flag: audio output available (from the software point of view)
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
/* /*
* Reset audio emulation * Reset audio emulation
@ -603,6 +606,25 @@ int16 SoundInControl(uint32 pb, uint32 dce)
return noErr; return noErr;
} }
case siInputSource: {
SoundInSource = ReadMacInt16(pb + csParam + 4);
return noErr;
}
case siPlayThruOnOff: {
SoundInPlaythrough = ReadMacInt16(pb + csParam + 4);
return noErr;
}
case siOptionsDialog: {
return noErr;
}
case siInputGain: {
SoundInGain = ReadMacInt32(pb + csParam + 4);
return noErr;
}
default: default:
return -231; // siUnknownInfoType return -231; // siUnknownInfoType
} }
@ -622,12 +644,11 @@ int16 SoundInStatus(uint32 pb, uint32 dce) // A0 points to Device Manager parame
// two choices on return // two choices on return
// 1: if under 18 bytes, place # of bytes at (pb+csParam) and write from (pb+csParam+4) on // 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 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 uint32 bufferptr = ReadMacInt32(pb + csParam + 4); // 4-byte address to the buffer in vm memory
switch (selector) { switch (selector) {
//#if 0
case siDeviceName: { // return name in STR255 format case siDeviceName: { // return name in STR255 format
const uint8 str[] = { // size 9 const uint8 str[] = { // size 9
0x08, // 1-byte length 0x08, // 1-byte length
@ -636,16 +657,35 @@ int16 SoundInStatus(uint32 pb, uint32 dce) // A0 points to Device Manager parame
0x74, 0x2d, // t- 0x74, 0x2d, // t-
0x69, 0x6e // in 0x69, 0x6e // in
}; };
WriteMacInt32(pb + csParam, 0); // response will directly be written into buffer // const uint8 str[] = { // size 12
// vm_memcpy(bufferptr, str, 9); // 0x0b, // 1-byte length
memcpy(Mac2HostAddr(bufferptr),str,9); // 0x53, 0x68, // Sh
// 0x65, 0x65, // ee
// 0x70, 0x73, // ps
// 0x68, 0x61, // ha
// 0x76, 0x65, // ve
// 0x72 // r
// };
WriteMacInt32(pb + csParam, 0); // response will be written directly into buffer
Host2Mac_memcpy(bufferptr, str, sizeof(str));
return noErr; return noErr;
} }
case siDeviceIcon: { 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(pb + csParam, 0);
WriteMacInt32(bufferptr, CDROMIconAddr);
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);
Host2Mac_memcpy(sp, CDROMIcon, sizeof(CDROMIcon));
return noErr; return noErr;
// 68k code causes crash in sheep and link error in basilisk // 68k code causes crash in sheep and link error in basilisk
@ -682,54 +722,100 @@ int16 SoundInStatus(uint32 pb, uint32 dce) // A0 points to Device Manager parame
} }
case siInputSource: { case siInputSource: {
// return -231 if only 1 or index if more // return -231 if only 1 or index of current source if more
return -231;
WriteMacInt32(pb + csParam, 2);
// WriteMacInt32(pb + csParam, 4); WriteMacInt16(pb + csParam + 4, SoundInSource); // index of selected source
// WriteMacInt32(pb + csParam + 4, 1); // index 1 return noErr;
// 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 if only 1 or handle to STR# resource if more
return -231;
// const uint8 str[] = { const uint8 str[] = {
// 0x00, 0x02, // 2-byte count of #strings 0x00, 0x02, // 2-byte count of #strings
// 0x0b, // byte size indicator (up to 255 length supported) // byte size indicator (up to 255 length supported)
// 0x49, 0x6e, // start of string in ASCII, In 0x0a, // size is 10
// 0x74, 0x65, // te 0x4d, 0x69, // Mi
// 0x72, 0x6e, // rn 0x63, 0x72, // cr
// 0x61, 0x6c, // al 0x6f, 0x70, // op
// 0x20, 0x43, // C 0x68, 0x6f, // ho
// 0x44, // D 0x6e, 0x65, // ne
// 0x0a, // size is 10 0x0b, // size is 11
// 0x4d, 0x69, // Mi 0x49, 0x6e, // start of string in ASCII, In
// 0x63, 0x72, // cr 0x74, 0x65, // te
// 0x6f, 0x70, // op 0x72, 0x6e, // rn
// 0x68, 0x6f, // ho 0x61, 0x6c, // al
// 0x6e, 0x65, // ne 0x20, 0x43, // C
// }; 0x44, // D
// };
// WriteMacInt32(pb + csParam, 0);
// vm_memcpy(bufferptr, str, 25); WriteMacInt32(pb + csParam, 0);
// return noErr;
M68kRegisters r;
r.d[0] = sizeof(str);
Execute68kTrap(0xa122, &r); // NewHandle()
uint32 h = r.a[0];
if (h == 0)
return memFullErr;
WriteMacInt32(bufferptr, h);
uint32 sp = ReadMacInt32(h);
Host2Mac_memcpy(sp, str, sizeof(str));
return noErr;
} }
case siOptionsDialog: { case siOptionsDialog: {
// 0 if no options box supported and 1 if so // 0 if no options box supported and 1 if so
WriteMacInt32(pb + csParam, 4); WriteMacInt32(pb + csParam, 2); // response not in buffer, need to copy integer
WriteMacInt32(pb + csParam + 4, 0); WriteMacInt16(pb + csParam + 4, 1); // Integer data type
return noErr; return noErr;
} }
case siPlayThruOnOff: { case siPlayThruOnOff: {
// playthrough volume, 0 is off and 7 is max // playthrough volume, 0 is off and 7 is max
WriteMacInt32(pb + csParam, 4); WriteMacInt32(pb + csParam, 2);
WriteMacInt32(pb + csParam + 4, 0); WriteMacInt16(pb + csParam + 4, SoundInPlaythrough);
return noErr; return noErr;
} }
//#endif
case siNumberChannels: {
// 1 is mono and 2 is stereo
WriteMacInt32(pb + csParam, 2);
WriteMacInt16(pb + csParam + 4, 2);
return noErr;
}
case siSampleRate: {
WriteMacInt32(pb + csParam, 0);
WriteMacInt32(bufferptr, 0xac440000); // 44100.00000 Hz, of Fixed data type
return noErr;
}
case siSampleRateAvailable: {
WriteMacInt32(pb + csParam, 0);
M68kRegisters r;
r.d[0] = 4;
Execute68kTrap(0xa122, &r); // NewHandle()
uint32 h = r.a[0];
if (h == 0)
return memFullErr;
WriteMacInt16(bufferptr, 1); // 1 sample rate available
WriteMacInt32(bufferptr + 2, h); // handle to sample rate list
uint32 sp = ReadMacInt32(h);
WriteMacInt32(sp, 0xac440000); // 44100.00000 Hz, of Fixed data type
return noErr;
}
case siInputGain: {
WriteMacInt32(pb + csParam, 4);
WriteMacInt32(pb + csParam + 4, SoundInGain);
return noErr;
}
default: default:
return -231; // siUnknownInfoType return -231; // siUnknownInfoType
} }

View File

@ -82,6 +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 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 siInputSourceNames = FOURCC('s','n','a','m'); // sound input source names
const uint32 siInputSource = FOURCC('s','o','u','r'); // sound input source selector const uint32 siInputSource = FOURCC('s','o','u','r'); // 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 siOptionsDialog = FOURCC('o','p','t','d'); // display options dialog box
const uint32 siPlayThruOnOff = FOURCC('p','l','t','h'); // play-through state const uint32 siPlayThruOnOff = FOURCC('p','l','t','h'); // play-through state
const uint32 siInitializeDriver = FOURCC('i','n','i','t'); // open sound input device const uint32 siInitializeDriver = FOURCC('i','n','i','t'); // open sound input device

View File

@ -31,7 +31,6 @@ enum {
ROMTYPE_NEWWORLD ROMTYPE_NEWWORLD
}; };
extern int ROMType; extern int ROMType;
extern bool SoundPatchFlag;
extern bool DecodeROM(uint8 *data, uint32 size); extern bool DecodeROM(uint8 *data, uint32 size);
extern bool PatchROM(void); extern bool PatchROM(void);

View File

@ -67,7 +67,6 @@ const uint32 ADDR_MAP_PATCH_SPACE = 0x2fd140;
// Global variables // Global variables
int ROMType; // ROM type int ROMType; // ROM type
bool SoundPatchFlag;
static uint32 sony_offset; // Offset of .Sony driver resource static uint32 sony_offset; // Offset of .Sony driver resource
// Prototypes // Prototypes
@ -694,8 +693,6 @@ bool PatchROM(void)
ROMType = ROMTYPE_NEWWORLD; ROMType = ROMTYPE_NEWWORLD;
else else
return false; return false;
SoundPatchFlag = ROMType == ROMTYPE_NEWWORLD && !PrefsFindBool("ignoresegv");
// Check that other ROM addresses point to really free regions // Check that other ROM addresses point to really free regions
if (!check_rom_patch_space(CHECK_LOAD_PATCH_SPACE, 0x40)) if (!check_rom_patch_space(CHECK_LOAD_PATCH_SPACE, 0x40))

View File

@ -517,12 +517,11 @@ void CheckLoad(uint32 type, int16 id, uint16 *p, uint32 size)
D(bug(" patch applied\n")); D(bug(" patch applied\n"));
} }
} else if (SoundPatchFlag && type == FOURCC('D','R','V','R') && (id == -16501 || id == -16500)) { } 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")); D(bug("DRVR -16501/-16500 found\n"));
// Install sound input driver // Install sound input driver
memcpy(p, sound_input_driver, sizeof(sound_input_driver)); memcpy(p, sound_input_driver, sizeof(sound_input_driver));
D(bug(" patch 1 applied\n")); D(bug(" patch 1 applied\n"));
} else if (type == FOURCC('I','N','I','T') && id == 1 && size == (2416 >> 1)) { } else if (type == FOURCC('I','N','I','T') && id == 1 && size == (2416 >> 1)) {
D(bug("INIT 1 (size 2416) found\n")); D(bug("INIT 1 (size 2416) found\n"));
size >>= 1; size >>= 1;