SAM: Clean up before merge

This commit is contained in:
tomcw
2015-04-09 22:54:26 +01:00
parent feccde41bf
commit c052d10d2f
6 changed files with 80 additions and 75 deletions

View File

@@ -42,56 +42,52 @@
//
static BYTE __stdcall IOWrite_SAM(WORD pc, WORD addr, BYTE bWrite, BYTE d, ULONG nCyclesLeft)
static BYTE __stdcall IOWrite_SAM(WORD pc, WORD addr, BYTE bWrite, BYTE d, ULONG nCyclesLeft)
{
// Emulate audio from a SAM / 8 bit DAC card
// Only supportable if AppleWin is using WAVE output
//
// This works by using the existing speaker handling but then
// replacing the speaker audio with the 8 bit samples from the DAC
// before they get sent out to the soundcard buffer, whilst
// audio samples are being written to the SAM.
//
// Whilst very unusual, it is possible to intermingle use of SAM and the apple
// speaker. This is crudely supported with g_quieterSpeaker making the Apple
// speaker produce quieter clicks which will be crudely intermingled
// with the SAM data. The mute gets reset after the speaker code detects
// silence.
// Emulate audio from a SAM / 8 bit DAC card
// Only supportable if AppleWin is using WAVE output
//
// This works by using the existing speaker handling but then
// replacing the speaker audio with the 8 bit samples from the DAC
// before they get sent out to the soundcard buffer, whilst
// audio samples are being written to the SAM.
//
// Whilst very unusual, it is possible to intermingle use of SAM and the apple
// speaker. This is crudely supported with g_bQuieterSpeaker making the Apple
// speaker produce quieter clicks which will be crudely intermingled
// with the SAM data. The mute gets reset after the speaker code detects
// silence.
byte mb_res;
if (soundtype != SOUND_WAVE)
return MemReadFloatingBus(nCyclesLeft);
if (soundtype == SOUND_WAVE)
{
// use existing speaker code to bring timing up to date
mb_res = SpkrToggle(pc, addr, bWrite, d, nCyclesLeft);
// use existing speaker code to bring timing up to date
BYTE res = SpkrToggle(pc, addr, bWrite, d, nCyclesLeft);
// The DAC in the SAM uses unsigned 8 bit samples
// The WAV data that g_nSpeakerData is loaded into is a signed short
//
// We convert unsigned 8 bit to signed by toggling the most significant bit
//
// SAM card WAV driver SAM WAV
// 0xFF 255 0x7f 127 _ FF 7F
// 0x81 129 0x01 1 / \
// 0x80 128 0x00 0 / \ /80 00
// 0x7f 127 0xFF -1 \_/
// 0x00 0 0x80 -128 00 80
//
// SAM is 8 bit, PC WAV is 16 so shift audio to the MSB (<< 8)
// The DAC in the SAM uses unsigned 8 bit samples
// The WAV data that g_nSpeakerData is loaded into is a signed short
//
// We convert unsigned 8 bit to signed by toggling the most significant bit
//
// SAM card WAV driver SAM WAV
// 0xFF 255 0x7f 127 _ FF 7F
// 0x81 129 0x01 1 / \
// 0x80 128 0x00 0 / \ /80 00
// 0x7f 127 0xFF -1 \_/
// 0x00 0 0x80 -128 00 80
//
// SAM is 8 bit, PC WAV is 16 so shift audio to the MSB (<< 8)
g_nSpeakerData = (d ^ 0x80) << 8;
g_nSpeakerData = (d ^ 0x80) << 8;
// make speaker quieter so eg: a metronome click through the
// Apple speaker is softer vs. the analogue SAM output.
g_quieterSpeaker = 1;
}
else
mb_res = MemReadFloatingBus(nCyclesLeft);
// make speaker quieter so eg: a metronome click through the
// Apple speaker is softer vs. the analogue SAM output.
g_bQuieterSpeaker = true;
return mb_res;
return res;
}
void ConfigureSAM(LPBYTE pCxRomPeripheral, UINT uSlot)
{
RegisterIoHandler(uSlot,IO_Null,IOWrite_SAM,IO_Null,IO_Null, NULL, NULL);
{
RegisterIoHandler(uSlot, IO_Null, IOWrite_SAM, IO_Null, IO_Null, NULL, NULL);
}