2011-04-24 01:14:00 +00:00
|
|
|
/**
|
|
|
|
** Supermodel
|
|
|
|
** A Sega Model 3 Arcade Emulator.
|
2011-09-14 07:38:56 +00:00
|
|
|
** Copyright 2011 Bart Trzynadlowski, Nik Henson
|
2011-04-24 01:14:00 +00:00
|
|
|
**
|
|
|
|
** This file is part of Supermodel.
|
|
|
|
**
|
|
|
|
** Supermodel is free software: you can redistribute it and/or modify it under
|
|
|
|
** the terms of the GNU General Public License as published by the Free
|
|
|
|
** Software Foundation, either version 3 of the License, or (at your option)
|
|
|
|
** any later version.
|
|
|
|
**
|
|
|
|
** Supermodel is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
** FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
** more details.
|
|
|
|
**
|
|
|
|
** You should have received a copy of the GNU General Public License along
|
|
|
|
** with Supermodel. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
**/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* SoundBoard.cpp
|
|
|
|
*
|
|
|
|
* Model 3 sound board. Implementation of the CSoundBoard class. This class can
|
|
|
|
* only be instantiated once because it relies on global variables (the non-OOP
|
2011-07-31 02:37:31 +00:00
|
|
|
* 68K core and an IRQ line).
|
2011-07-16 04:53:12 +00:00
|
|
|
*
|
|
|
|
* Bank Switching
|
|
|
|
* --------------
|
|
|
|
* Banking is not fully understood yet. It is presumed that the low 2MB of the
|
|
|
|
* sample ROMs are not banked (MAME), but this is not guaranteed. Below are
|
|
|
|
* examples of known situations where banking helps (sound names are as they
|
|
|
|
* appear in the sound test menu).
|
|
|
|
*
|
|
|
|
* sound name
|
|
|
|
* ROM Offsets -> Address
|
|
|
|
*
|
|
|
|
* dayto2pe
|
|
|
|
* --------
|
|
|
|
* let's hope he does better
|
|
|
|
* A... -> A... (400001=3E)
|
|
|
|
* doing good i'd say you have a ..
|
|
|
|
* E... -> E... (400001=3D)
|
|
|
|
*
|
|
|
|
* From the above, it appears that when (400001)&10, then:
|
|
|
|
*
|
|
|
|
* ROM A00000-DFFFFF -> A00000-DFFFFF
|
|
|
|
* ROM E00000-FFFFFF -> E00000-FFFFFF
|
|
|
|
*
|
|
|
|
* And when that bit is clear (just use default mapping, upper 6MB of ROM):
|
|
|
|
*
|
|
|
|
* ROM 200000-5FFFFF -> A00000-DFFFFF
|
|
|
|
* ROM 600000-7FFFFF -> E00000-FFFFFF
|
2011-04-24 01:14:00 +00:00
|
|
|
*/
|
|
|
|
|
2021-11-22 17:15:06 +00:00
|
|
|
#include "SoundBoard.h"
|
|
|
|
|
2011-04-24 01:14:00 +00:00
|
|
|
#include "Supermodel.h"
|
2021-11-22 17:15:06 +00:00
|
|
|
#include "OSD/Audio.h"
|
|
|
|
#include "Sound/SCSP.h"
|
2011-04-24 01:14:00 +00:00
|
|
|
|
2011-07-31 02:37:31 +00:00
|
|
|
// DEBUG
|
2011-08-29 16:32:24 +00:00
|
|
|
//#define SUPERMODEL_LOG_AUDIO // define this to log all audio to sound.bin
|
2011-07-31 02:37:31 +00:00
|
|
|
#ifdef SUPERMODEL_LOG_AUDIO
|
2011-04-24 01:14:00 +00:00
|
|
|
static FILE *soundFP;
|
2011-07-31 02:37:31 +00:00
|
|
|
#endif
|
|
|
|
|
2011-04-24 01:14:00 +00:00
|
|
|
|
2022-06-19 16:15:54 +00:00
|
|
|
// Offsets of memory regions within sound board's pool
|
|
|
|
#define OFFSET_RAM1 0 // 1 MB SCSP1 RAM
|
|
|
|
#define OFFSET_RAM2 0x100000 // 1 MB SCSP2 RAM
|
2022-11-03 10:49:35 +00:00
|
|
|
#define LENGTH_CHANNEL_BUFFER (sizeof(float)*NUM_SAMPLES_PER_FRAME) // 2940 bytes (32 bits x 44.1 KHz x 1/60th second)
|
|
|
|
#define OFFSET_AUDIO_FRONTLEFT 0x200000 // 2940 bytes (32 bits, 44.1 KHz, 1/60th second) left audio channel
|
|
|
|
#define OFFSET_AUDIO_FRONTRIGHT (OFFSET_AUDIO_FRONTLEFT + LENGTH_CHANNEL_BUFFER) // 2940 bytes right audio channel
|
|
|
|
#define OFFSET_AUDIO_REARLEFT (OFFSET_AUDIO_FRONTRIGHT + LENGTH_CHANNEL_BUFFER) // 2940 bytes (32 bits, 44.1 KHz, 1/60th second) left audio channel
|
|
|
|
#define OFFSET_AUDIO_REARRIGHT (OFFSET_AUDIO_REARLEFT + LENGTH_CHANNEL_BUFFER) // 2940 bytes right audio channel
|
2022-06-19 16:15:54 +00:00
|
|
|
|
|
|
|
#define MEMORY_POOL_SIZE (0x100000 + 0x100000 + 4*LENGTH_CHANNEL_BUFFER)
|
|
|
|
|
|
|
|
|
2011-04-24 01:14:00 +00:00
|
|
|
/******************************************************************************
|
2011-08-09 18:16:06 +00:00
|
|
|
68K Address Space Handlers
|
2011-04-24 01:14:00 +00:00
|
|
|
******************************************************************************/
|
|
|
|
|
2011-08-09 18:16:06 +00:00
|
|
|
void CSoundBoard::UpdateROMBanks(void)
|
|
|
|
{
|
|
|
|
if ((ctrlReg&0x10))
|
2011-12-23 21:06:45 +00:00
|
|
|
sampleBank = &sampleROM[0x800000];
|
2011-08-09 18:16:06 +00:00
|
|
|
else
|
2011-12-23 21:06:45 +00:00
|
|
|
sampleBank = &sampleROM[0x000000];
|
2011-08-09 18:16:06 +00:00
|
|
|
}
|
|
|
|
|
2011-07-31 02:37:31 +00:00
|
|
|
UINT8 CSoundBoard::Read8(UINT32 a)
|
2011-07-12 04:57:12 +00:00
|
|
|
{
|
2011-07-31 02:37:31 +00:00
|
|
|
switch ((a>>20)&0xF)
|
|
|
|
{
|
|
|
|
case 0x0: // SCSP RAM 1 (master): 000000-0FFFFF
|
|
|
|
return ram1[a^1];
|
2011-07-12 04:57:12 +00:00
|
|
|
|
2011-07-31 02:37:31 +00:00
|
|
|
case 0x1: // SCSP registers (master): 100000-10FFFF (unlike real hardware, we mirror up to 1FFFFF)
|
2011-07-12 04:57:12 +00:00
|
|
|
return SCSP_Master_r8(a);
|
|
|
|
|
2011-07-31 02:37:31 +00:00
|
|
|
case 0x2: // SCSP RAM 2 (slave): 200000-2FFFFF
|
|
|
|
return ram2[(a&0x0FFFFF)^1];
|
|
|
|
|
|
|
|
case 0x3: // SCSP registers (slave): 300000-30FFFF (unlike real hardware, we mirror up to 3FFFFF)
|
2011-07-12 04:57:12 +00:00
|
|
|
return SCSP_Slave_r8(a);
|
|
|
|
|
2011-07-31 02:37:31 +00:00
|
|
|
case 0x6: // Program ROM: 600000-67FFFF (unlike real hardware, we mirror up to 6FFFFF here)
|
|
|
|
return soundROM[(a&0x07FFFF)^1];
|
|
|
|
|
2011-12-23 21:06:45 +00:00
|
|
|
case 0x8: // Sample ROM bank: 800000-FFFFFF
|
|
|
|
case 0x9:
|
|
|
|
case 0xA:
|
2011-07-31 02:37:31 +00:00
|
|
|
case 0xB:
|
|
|
|
case 0xC:
|
|
|
|
case 0xD:
|
2011-12-23 21:06:45 +00:00
|
|
|
case 0xE:
|
2011-07-31 02:37:31 +00:00
|
|
|
case 0xF:
|
2011-12-23 21:06:45 +00:00
|
|
|
return sampleBank[(a&0x7FFFFF)^1];
|
2011-07-31 02:37:31 +00:00
|
|
|
|
|
|
|
default:
|
2011-09-08 17:58:25 +00:00
|
|
|
//printf("68K: Unknown read8 %06X\n", a);
|
2011-07-31 02:37:31 +00:00
|
|
|
break;
|
2011-07-12 04:57:12 +00:00
|
|
|
}
|
2011-07-31 02:37:31 +00:00
|
|
|
|
|
|
|
return 0;
|
2011-04-24 01:14:00 +00:00
|
|
|
}
|
|
|
|
|
2011-07-31 02:37:31 +00:00
|
|
|
UINT16 CSoundBoard::Read16(UINT32 a)
|
2011-12-23 21:06:45 +00:00
|
|
|
{
|
2011-07-31 02:37:31 +00:00
|
|
|
switch ((a>>20)&0xF)
|
|
|
|
{
|
|
|
|
case 0x0: // SCSP RAM 1 (master): 000000-0FFFFF
|
|
|
|
return *(UINT16 *) &ram1[a];
|
2011-07-12 04:57:12 +00:00
|
|
|
|
2011-07-31 02:37:31 +00:00
|
|
|
case 0x1: // SCSP registers (master): 100000-10FFFF
|
2011-07-12 04:57:12 +00:00
|
|
|
return SCSP_Master_r16(a);
|
|
|
|
|
2011-07-31 02:37:31 +00:00
|
|
|
case 0x2: // SCSP RAM 2 (slave): 200000-2FFFFF
|
|
|
|
return *(UINT16 *) &ram2[a&0x0FFFFF];
|
|
|
|
|
|
|
|
case 0x3: // SCSP registers (slave): 300000-30FFFF
|
2011-07-12 04:57:12 +00:00
|
|
|
return SCSP_Slave_r16(a);
|
|
|
|
|
2011-07-31 02:37:31 +00:00
|
|
|
case 0x6: // Program ROM: 600000-67FFFF
|
|
|
|
return *(UINT16 *) &soundROM[a&0x07FFFF];
|
|
|
|
|
2011-12-23 21:06:45 +00:00
|
|
|
case 0x8: // Sample ROM bank: 800000-FFFFFF
|
|
|
|
case 0x9:
|
|
|
|
case 0xA:
|
2011-07-31 02:37:31 +00:00
|
|
|
case 0xB:
|
|
|
|
case 0xC:
|
|
|
|
case 0xD:
|
2011-12-23 21:06:45 +00:00
|
|
|
case 0xE:
|
2011-07-31 02:37:31 +00:00
|
|
|
case 0xF:
|
2011-12-26 07:15:32 +00:00
|
|
|
return *(UINT16 *) &sampleBank[a&0x7FFFFF];
|
2011-07-31 02:37:31 +00:00
|
|
|
|
|
|
|
default:
|
2011-09-08 17:58:25 +00:00
|
|
|
//printf("68K: Unknown read16 %06X\n", a);
|
2011-07-31 02:37:31 +00:00
|
|
|
break;
|
2011-07-12 04:57:12 +00:00
|
|
|
}
|
2011-07-31 02:37:31 +00:00
|
|
|
|
|
|
|
return 0;
|
2011-04-24 01:14:00 +00:00
|
|
|
}
|
|
|
|
|
2011-07-31 02:37:31 +00:00
|
|
|
UINT32 CSoundBoard::Read32(UINT32 a)
|
|
|
|
{
|
|
|
|
UINT32 hi, lo;
|
2011-07-12 04:57:12 +00:00
|
|
|
|
2011-07-31 02:37:31 +00:00
|
|
|
switch ((a>>20)&0xF)
|
|
|
|
{
|
|
|
|
case 0x0: // SCSP RAM 1 (master): 000000-0FFFFF
|
|
|
|
hi = *(UINT16 *) &ram1[a];
|
|
|
|
lo = *(UINT16 *) &ram1[a+2]; // TODO: clamp? Possible bounds hazard.
|
|
|
|
return (hi<<16)|lo;
|
2011-07-12 04:57:12 +00:00
|
|
|
|
2011-07-31 02:37:31 +00:00
|
|
|
case 0x1: // SCSP registers (master): 100000-10FFFF
|
2011-07-12 04:57:12 +00:00
|
|
|
return SCSP_Master_r32(a);
|
|
|
|
|
2011-07-31 02:37:31 +00:00
|
|
|
case 0x2: // SCSP RAM 2 (slave): 200000-2FFFFF
|
|
|
|
hi = *(UINT16 *) &ram2[a&0x0FFFFF];
|
|
|
|
lo = *(UINT16 *) &ram2[(a+2)&0x0FFFFF];
|
|
|
|
return (hi<<16)|lo;
|
|
|
|
|
|
|
|
case 0x3: // SCSP registers (slave): 300000-30FFFF
|
2011-07-12 04:57:12 +00:00
|
|
|
return SCSP_Slave_r32(a);
|
|
|
|
|
2011-07-31 02:37:31 +00:00
|
|
|
case 0x6: // Program ROM: 600000-67FFFF
|
|
|
|
hi = *(UINT16 *) &soundROM[a&0x07FFFF];
|
|
|
|
lo = *(UINT16 *) &soundROM[(a+2)&0x07FFFF];
|
|
|
|
return (hi<<16)|lo;
|
2011-12-23 21:06:45 +00:00
|
|
|
|
|
|
|
case 0x8: // Sample ROM bank: 800000-FFFFFF
|
|
|
|
case 0x9:
|
|
|
|
case 0xA:
|
2011-07-31 02:37:31 +00:00
|
|
|
case 0xB:
|
|
|
|
case 0xC:
|
|
|
|
case 0xD:
|
2011-12-23 21:06:45 +00:00
|
|
|
case 0xE:
|
2011-07-31 02:37:31 +00:00
|
|
|
case 0xF:
|
2011-12-23 21:06:45 +00:00
|
|
|
hi = *(UINT16 *) &sampleBank[a&0x7FFFFF];
|
|
|
|
lo = *(UINT16 *) &sampleBank[(a+2)&0x7FFFFF];
|
2011-07-31 02:37:31 +00:00
|
|
|
return (hi<<16)|lo;
|
|
|
|
|
|
|
|
default:
|
2011-09-08 17:58:25 +00:00
|
|
|
//printf("68K: Unknown read32 %06X\n", a);
|
2011-07-31 02:37:31 +00:00
|
|
|
break;
|
2011-07-12 04:57:12 +00:00
|
|
|
}
|
2011-07-31 02:37:31 +00:00
|
|
|
|
|
|
|
return 0;
|
2011-04-24 01:14:00 +00:00
|
|
|
}
|
|
|
|
|
2011-07-31 02:37:31 +00:00
|
|
|
void CSoundBoard::Write8(unsigned int a,unsigned char d)
|
2011-07-12 04:57:12 +00:00
|
|
|
{
|
2011-07-31 02:37:31 +00:00
|
|
|
switch ((a>>20)&0xF)
|
|
|
|
{
|
|
|
|
case 0x0: // SCSP RAM 1 (master): 000000-0FFFFF
|
|
|
|
ram1[a^1] = d;
|
|
|
|
break;
|
2011-07-12 04:57:12 +00:00
|
|
|
|
2011-07-31 02:37:31 +00:00
|
|
|
case 0x1: // SCSP registers (master): 100000-10FFFF
|
2011-07-12 04:57:12 +00:00
|
|
|
SCSP_Master_w8(a,d);
|
2011-07-31 02:37:31 +00:00
|
|
|
break;
|
2011-07-12 04:57:12 +00:00
|
|
|
|
2011-07-31 02:37:31 +00:00
|
|
|
case 0x2: // SCSP RAM 2 (slave): 200000-2FFFFF
|
|
|
|
ram2[(a&0x0FFFFF)^1] = d;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x3: // SCSP registers (slave): 300000-30FFFF
|
2011-07-12 04:57:12 +00:00
|
|
|
SCSP_Slave_w8(a,d);
|
2011-07-31 02:37:31 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
if (a == 0x400001)
|
2011-07-16 04:53:12 +00:00
|
|
|
{
|
2011-08-09 18:16:06 +00:00
|
|
|
ctrlReg = d;
|
|
|
|
UpdateROMBanks();
|
2011-07-16 04:53:12 +00:00
|
|
|
}
|
2011-09-08 17:58:25 +00:00
|
|
|
//else
|
|
|
|
// printf("68K: Unknown write8 %06X=%02X\n", a, d);
|
2011-07-31 02:37:31 +00:00
|
|
|
break;
|
2011-07-16 04:53:12 +00:00
|
|
|
}
|
2011-04-24 01:14:00 +00:00
|
|
|
}
|
|
|
|
|
2011-07-31 02:37:31 +00:00
|
|
|
void CSoundBoard::Write16(unsigned int a,unsigned short d)
|
2011-07-12 04:57:12 +00:00
|
|
|
{
|
2011-07-31 02:37:31 +00:00
|
|
|
switch ((a>>20)&0xF)
|
|
|
|
{
|
|
|
|
case 0x0: // SCSP RAM 1 (master): 000000-0FFFFF
|
|
|
|
*(UINT16 *) &ram1[a] = d;
|
|
|
|
break;
|
2011-07-12 04:57:12 +00:00
|
|
|
|
2011-07-31 02:37:31 +00:00
|
|
|
case 0x1: // SCSP registers (master): 100000-10FFFF
|
2011-07-12 04:57:12 +00:00
|
|
|
SCSP_Master_w16(a,d);
|
2011-07-31 02:37:31 +00:00
|
|
|
break;
|
2011-07-12 04:57:12 +00:00
|
|
|
|
2011-07-31 02:37:31 +00:00
|
|
|
case 0x2: // SCSP RAM 2 (slave): 200000-2FFFFF
|
|
|
|
*(UINT16 *) &ram2[a&0x0FFFFF] = d;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x3: // SCSP registers (slave): 300000-30FFFF
|
2011-07-12 04:57:12 +00:00
|
|
|
SCSP_Slave_w16(a,d);
|
2011-07-31 02:37:31 +00:00
|
|
|
break;
|
2011-07-12 04:57:12 +00:00
|
|
|
|
2011-07-31 02:37:31 +00:00
|
|
|
default:
|
2011-09-08 17:58:25 +00:00
|
|
|
//printf("68K: Unknown write16 %06X=%04X\n", a, d);
|
2011-07-31 02:37:31 +00:00
|
|
|
break;
|
|
|
|
}
|
2011-04-24 01:14:00 +00:00
|
|
|
}
|
|
|
|
|
2011-07-31 02:37:31 +00:00
|
|
|
void CSoundBoard::Write32(unsigned int a,unsigned int d)
|
2011-04-24 01:14:00 +00:00
|
|
|
{
|
2011-07-31 02:37:31 +00:00
|
|
|
switch ((a>>20)&0xF)
|
2011-07-12 04:57:12 +00:00
|
|
|
{
|
2011-07-31 02:37:31 +00:00
|
|
|
case 0x0: // SCSP RAM 1 (master): 000000-0FFFFF
|
|
|
|
*(UINT16 *) &ram1[a] = (d>>16);
|
|
|
|
*(UINT16 *) &ram1[a+2] = (d&0xFFFF);
|
|
|
|
break;
|
2011-07-12 04:57:12 +00:00
|
|
|
|
2011-07-31 02:37:31 +00:00
|
|
|
case 0x1: // SCSP registers (master): 100000-10FFFF
|
2011-07-12 04:57:12 +00:00
|
|
|
SCSP_Master_w32(a,d);
|
2011-07-31 02:37:31 +00:00
|
|
|
break;
|
2011-07-12 04:57:12 +00:00
|
|
|
|
2011-07-31 02:37:31 +00:00
|
|
|
case 0x2: // SCSP RAM 2 (slave): 200000-2FFFFF
|
|
|
|
*(UINT16 *) &ram2[a&0x0FFFFF] = (d>>16);
|
|
|
|
*(UINT16 *) &ram2[(a+2)&0x0FFFFF] = (d&0xFFFF);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x3: // SCSP registers (slave): 300000-30FFFF
|
2011-07-12 04:57:12 +00:00
|
|
|
SCSP_Slave_w32(a,d);
|
2011-07-31 02:37:31 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2011-09-08 17:58:25 +00:00
|
|
|
//printf("68K: Unknown write32 %06X=%08X\n", a, d);
|
2011-07-31 02:37:31 +00:00
|
|
|
break;
|
|
|
|
}
|
2011-04-24 01:14:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************
|
2011-07-12 04:57:12 +00:00
|
|
|
SCSP 68K Callbacks
|
|
|
|
|
2011-07-31 02:37:31 +00:00
|
|
|
The SCSP emulator drives the 68K via callbacks. These have to live outside of
|
|
|
|
the CSoundBoard object for now, unfortunately.
|
2011-04-24 01:14:00 +00:00
|
|
|
******************************************************************************/
|
2011-07-12 04:57:12 +00:00
|
|
|
|
|
|
|
// Status of IRQ pins (IPL2-0) on 68K
|
2011-07-31 02:37:31 +00:00
|
|
|
// TODO: can we get rid of this global variable altogether?
|
2011-07-12 04:57:12 +00:00
|
|
|
static int irqLine = 0;
|
|
|
|
|
2011-07-31 02:37:31 +00:00
|
|
|
// Interrupt acknowledge callback (TODO: don't need this, default behavior in M68K.cpp should be fine)
|
2011-07-12 04:57:12 +00:00
|
|
|
int IRQAck(int irqLevel)
|
|
|
|
{
|
|
|
|
M68KSetIRQ(0);
|
|
|
|
irqLine = 0;
|
|
|
|
return M68K_IRQ_AUTOVECTOR;
|
|
|
|
}
|
2011-04-24 01:14:00 +00:00
|
|
|
|
|
|
|
// SCSP callback for generating IRQs
|
2011-07-12 04:57:12 +00:00
|
|
|
void SCSP68KIRQCallback(int irqLevel)
|
2011-04-24 01:14:00 +00:00
|
|
|
{
|
2011-07-12 04:57:12 +00:00
|
|
|
/*
|
|
|
|
* IRQ arbitration logic: only allow higher priority IRQs to be asserted or
|
|
|
|
* 0 to clear pending IRQ.
|
|
|
|
*/
|
|
|
|
if ((irqLevel>irqLine) || (0==irqLevel))
|
|
|
|
{
|
|
|
|
irqLine = irqLevel;
|
|
|
|
|
|
|
|
}
|
|
|
|
M68KSetIRQ(irqLine);
|
2011-04-24 01:14:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SCSP callback for running the 68K
|
|
|
|
int SCSP68KRunCallback(int numCycles)
|
|
|
|
{
|
2011-08-07 01:07:48 +00:00
|
|
|
return M68KRun(numCycles) - numCycles;
|
2011-04-24 01:14:00 +00:00
|
|
|
}
|
|
|
|
|
2011-07-12 04:57:12 +00:00
|
|
|
|
|
|
|
/******************************************************************************
|
2011-07-31 02:37:31 +00:00
|
|
|
Sound Board Interface
|
2011-07-12 04:57:12 +00:00
|
|
|
******************************************************************************/
|
|
|
|
|
2011-04-24 01:14:00 +00:00
|
|
|
void CSoundBoard::WriteMIDIPort(UINT8 data)
|
|
|
|
{
|
|
|
|
SCSP_MidiIn(data);
|
2011-07-31 02:37:31 +00:00
|
|
|
if (NULL != DSB) // DSB receives all commands as well
|
|
|
|
DSB->SendCommand(data);
|
2011-04-24 01:14:00 +00:00
|
|
|
}
|
|
|
|
|
2023-12-02 18:08:13 +00:00
|
|
|
#ifdef SUPERMODEL_LOG_AUDIO
|
2022-11-03 10:49:35 +00:00
|
|
|
static INT16 ClampINT16(float x)
|
|
|
|
{
|
|
|
|
INT32 xi = (INT32)x;
|
|
|
|
if (xi > INT16_MAX) {
|
|
|
|
xi = INT16_MAX;
|
|
|
|
}
|
|
|
|
if (xi < INT16_MIN) {
|
|
|
|
xi = INT16_MIN;
|
|
|
|
}
|
|
|
|
return (INT16)xi;
|
|
|
|
}
|
2023-12-02 18:08:13 +00:00
|
|
|
#endif
|
2022-11-03 10:49:35 +00:00
|
|
|
|
2011-09-12 05:43:37 +00:00
|
|
|
bool CSoundBoard::RunFrame(void)
|
2011-04-24 01:14:00 +00:00
|
|
|
{
|
2011-07-31 02:37:31 +00:00
|
|
|
// Run sound board first to generate SCSP audio
|
2017-03-27 03:19:15 +00:00
|
|
|
if (m_config["EmulateSound"].ValueAs<bool>())
|
2011-08-19 20:43:07 +00:00
|
|
|
{
|
|
|
|
M68KSetContext(&M68K);
|
|
|
|
SCSP_Update();
|
|
|
|
M68KGetContext(&M68K);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-06-19 16:15:54 +00:00
|
|
|
memset(audioFL, 0, LENGTH_CHANNEL_BUFFER);
|
|
|
|
memset(audioFR, 0, LENGTH_CHANNEL_BUFFER);
|
|
|
|
memset(audioRL, 0, LENGTH_CHANNEL_BUFFER);
|
|
|
|
memset(audioRR, 0, LENGTH_CHANNEL_BUFFER);
|
2011-08-19 20:43:07 +00:00
|
|
|
}
|
2022-06-19 16:15:54 +00:00
|
|
|
|
|
|
|
// Compute sound volume as
|
2022-11-03 10:49:35 +00:00
|
|
|
float soundVol = (float)std::max(0,std::min(200,m_config["SoundVolume"].ValueAs<int>()));
|
|
|
|
soundVol = soundVol * (float)(1.0 / 100.0);
|
2022-06-19 16:15:54 +00:00
|
|
|
|
|
|
|
// Apply sound volume setting to SCSP channels only
|
|
|
|
for (int i = 0; i < NUM_SAMPLES_PER_FRAME; i++) {
|
2022-11-03 10:49:35 +00:00
|
|
|
audioFL[i] *= soundVol;
|
|
|
|
audioFR[i] *= soundVol;
|
|
|
|
audioRL[i] *= soundVol;
|
|
|
|
audioRR[i] *= soundVol;
|
2022-06-19 16:15:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Run DSB and mix with existing audio, apply music volume
|
2022-06-09 21:10:39 +00:00
|
|
|
if (NULL != DSB) {
|
|
|
|
// Will need to mix with proper front, rear channels or both (game specific)
|
|
|
|
bool mixDSBWithFront = true; // Everything to front channels for now
|
|
|
|
// Case "both" not handled for now
|
|
|
|
if (mixDSBWithFront)
|
|
|
|
DSB->RunFrame(audioFL, audioFR);
|
|
|
|
else
|
|
|
|
DSB->RunFrame(audioRL, audioRR);
|
|
|
|
}
|
2011-07-20 21:14:00 +00:00
|
|
|
|
|
|
|
// Output the audio buffers
|
2022-06-19 16:15:54 +00:00
|
|
|
bool bufferFull = OutputAudio(NUM_SAMPLES_PER_FRAME, audioFL, audioFR, audioRL, audioRR, m_config["FlipStereo"].ValueAs<bool>());
|
2011-07-20 21:14:00 +00:00
|
|
|
|
2011-07-31 02:37:31 +00:00
|
|
|
#ifdef SUPERMODEL_LOG_AUDIO
|
2011-04-24 01:14:00 +00:00
|
|
|
// Output to binary file
|
|
|
|
INT16 s;
|
2022-06-19 16:15:54 +00:00
|
|
|
for (int i = 0; i < NUM_SAMPLES_PER_FRAME; i++)
|
2011-07-31 02:37:31 +00:00
|
|
|
{
|
2022-11-03 10:49:35 +00:00
|
|
|
s = ClampINT16(audioFL[i]);
|
|
|
|
fwrite(&s, sizeof(INT16), 1, soundFP); // left channel
|
|
|
|
s = ClampINT16(audioFR[i]);
|
|
|
|
fwrite(&s, sizeof(INT16), 1, soundFP); // right channel
|
|
|
|
s = ClampINT16(audioRL[i]);
|
2011-04-24 01:14:00 +00:00
|
|
|
fwrite(&s, sizeof(INT16), 1, soundFP); // left channel
|
2022-11-03 10:49:35 +00:00
|
|
|
s = ClampINT16(audioRR[i]);
|
2011-04-24 01:14:00 +00:00
|
|
|
fwrite(&s, sizeof(INT16), 1, soundFP); // right channel
|
|
|
|
}
|
2011-09-12 05:43:37 +00:00
|
|
|
#endif // SUPERMODEL_LOG_AUDIO
|
|
|
|
|
|
|
|
return bufferFull;
|
2011-04-24 01:14:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSoundBoard::Reset(void)
|
|
|
|
{
|
2011-09-08 17:58:25 +00:00
|
|
|
// Even if SCSP emulation is disabled, we must reset to establish a valid 68K state
|
2011-07-16 04:53:12 +00:00
|
|
|
memcpy(ram1, soundROM, 16); // copy 68K vector table
|
2011-08-09 18:16:06 +00:00
|
|
|
ctrlReg = 0; // set default banks
|
|
|
|
UpdateROMBanks();
|
2011-07-31 02:37:31 +00:00
|
|
|
M68KSetContext(&M68K);
|
2011-07-12 04:57:12 +00:00
|
|
|
M68KReset();
|
2011-08-15 05:59:33 +00:00
|
|
|
//printf("SBrd PC=%06X\n", M68KGetPC());
|
2011-07-31 02:37:31 +00:00
|
|
|
M68KGetContext(&M68K);
|
|
|
|
if (NULL != DSB)
|
|
|
|
DSB->Reset();
|
2011-04-24 01:14:00 +00:00
|
|
|
DebugLog("Sound Board Reset\n");
|
2011-08-15 05:59:33 +00:00
|
|
|
//printf("PC=%06X\n", M68KGetPC());
|
|
|
|
//M68KSetContext(&M68K);
|
|
|
|
//M68KGetContext(&M68K);
|
|
|
|
//printf("PC=%06X\n", M68KGetPC());
|
2011-04-24 01:14:00 +00:00
|
|
|
}
|
|
|
|
|
2011-08-09 18:16:06 +00:00
|
|
|
void CSoundBoard::SaveState(CBlockFile *SaveState)
|
|
|
|
{
|
|
|
|
SaveState->NewBlock("Sound Board", __FILE__);
|
|
|
|
SaveState->Write(ram1, 0x100000);
|
|
|
|
SaveState->Write(ram2, 0x100000);
|
|
|
|
SaveState->Write(&ctrlReg, sizeof(ctrlReg));
|
|
|
|
|
|
|
|
// All other devices...
|
|
|
|
M68KSetContext(&M68K);
|
|
|
|
M68KSaveState(SaveState, "Sound Board 68K");
|
|
|
|
SCSP_SaveState(SaveState);
|
|
|
|
if (NULL != DSB)
|
|
|
|
DSB->SaveState(SaveState);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSoundBoard::LoadState(CBlockFile *SaveState)
|
|
|
|
{
|
|
|
|
if (OKAY != SaveState->FindBlock("Sound Board"))
|
|
|
|
{
|
2011-09-22 06:11:47 +00:00
|
|
|
ErrorLog("Unable to load sound board state. Save state file is corrupt.");
|
2011-08-09 18:16:06 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SaveState->Read(ram1, 0x100000);
|
|
|
|
SaveState->Read(ram2, 0x100000);
|
|
|
|
SaveState->Read(&ctrlReg, sizeof(ctrlReg));
|
|
|
|
UpdateROMBanks();
|
|
|
|
|
|
|
|
// All other devices
|
|
|
|
M68KSetContext(&M68K); // so we don't lose callback pointers when copying context back
|
|
|
|
M68KLoadState(SaveState, "Sound Board 68K");
|
|
|
|
M68KGetContext(&M68K);
|
|
|
|
SCSP_LoadState(SaveState);
|
|
|
|
if (NULL != DSB)
|
|
|
|
DSB->LoadState(SaveState);
|
|
|
|
}
|
|
|
|
|
2011-04-24 01:14:00 +00:00
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
Configuration, Initialization, and Shutdown
|
|
|
|
******************************************************************************/
|
|
|
|
|
2011-07-31 02:37:31 +00:00
|
|
|
void CSoundBoard::AttachDSB(CDSB *DSBPtr)
|
|
|
|
{
|
|
|
|
DSB = DSBPtr;
|
|
|
|
DebugLog("Sound Board connected to DSB\n");
|
|
|
|
}
|
|
|
|
|
2011-04-24 01:14:00 +00:00
|
|
|
|
2011-09-08 06:34:18 +00:00
|
|
|
bool CSoundBoard::Init(const UINT8 *soundROMPtr, const UINT8 *sampleROMPtr)
|
2011-04-24 01:14:00 +00:00
|
|
|
{
|
|
|
|
float memSizeMB = (float)MEMORY_POOL_SIZE/(float)0x100000;
|
|
|
|
|
|
|
|
// Receive sound ROMs
|
|
|
|
soundROM = soundROMPtr;
|
|
|
|
sampleROM = sampleROMPtr;
|
2011-08-09 18:16:06 +00:00
|
|
|
ctrlReg = 0;
|
|
|
|
UpdateROMBanks();
|
|
|
|
|
2011-04-24 01:14:00 +00:00
|
|
|
// Allocate all memory for RAM
|
|
|
|
memoryPool = new(std::nothrow) UINT8[MEMORY_POOL_SIZE];
|
|
|
|
if (NULL == memoryPool)
|
|
|
|
return ErrorLog("Insufficient memory for sound board (needs %1.1f MB).", memSizeMB);
|
|
|
|
memset(memoryPool, 0, MEMORY_POOL_SIZE);
|
|
|
|
|
|
|
|
// Set up memory pointers
|
2011-07-16 04:53:12 +00:00
|
|
|
ram1 = &memoryPool[OFFSET_RAM1];
|
|
|
|
ram2 = &memoryPool[OFFSET_RAM2];
|
2022-11-03 10:49:35 +00:00
|
|
|
audioFL = (float*)&memoryPool[OFFSET_AUDIO_FRONTLEFT];
|
|
|
|
audioFR = (float*)&memoryPool[OFFSET_AUDIO_FRONTRIGHT];
|
|
|
|
audioRL = (float*)&memoryPool[OFFSET_AUDIO_REARLEFT];
|
|
|
|
audioRR = (float*)&memoryPool[OFFSET_AUDIO_REARRIGHT];
|
2022-06-09 21:10:39 +00:00
|
|
|
|
2011-07-12 04:57:12 +00:00
|
|
|
// Initialize 68K core
|
2011-07-31 02:37:31 +00:00
|
|
|
M68KSetContext(&M68K);
|
2011-07-12 04:57:12 +00:00
|
|
|
M68KInit();
|
2011-07-31 02:37:31 +00:00
|
|
|
M68KAttachBus(this);
|
2011-07-12 04:57:12 +00:00
|
|
|
M68KSetIRQCallback(IRQAck);
|
2011-07-31 02:37:31 +00:00
|
|
|
M68KGetContext(&M68K);
|
2011-07-12 04:57:12 +00:00
|
|
|
|
2011-04-24 01:14:00 +00:00
|
|
|
// Initialize SCSPs
|
2022-06-19 16:15:54 +00:00
|
|
|
SCSP_SetBuffers(audioFL, audioFR, audioRL, audioRR, NUM_SAMPLES_PER_FRAME);
|
2011-07-31 02:37:31 +00:00
|
|
|
SCSP_SetCB(SCSP68KRunCallback, SCSP68KIRQCallback);
|
2017-03-27 03:19:15 +00:00
|
|
|
if (OKAY != SCSP_Init(m_config, 2))
|
2011-09-14 07:38:56 +00:00
|
|
|
return FAIL;
|
2011-04-24 01:14:00 +00:00
|
|
|
SCSP_SetRAM(0, ram1);
|
|
|
|
SCSP_SetRAM(1, ram2);
|
|
|
|
|
|
|
|
// Binary logging
|
2011-07-31 02:37:31 +00:00
|
|
|
#ifdef SUPERMODEL_LOG_AUDIO
|
2011-04-24 01:14:00 +00:00
|
|
|
soundFP = fopen("sound.bin","wb"); // delete existing file
|
|
|
|
fclose(soundFP);
|
|
|
|
soundFP = fopen("sound.bin","ab"); // append mode
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return OKAY;
|
|
|
|
}
|
|
|
|
|
2011-09-15 21:10:38 +00:00
|
|
|
M68KCtx *CSoundBoard::GetM68K(void)
|
|
|
|
{
|
|
|
|
return &M68K;
|
|
|
|
}
|
|
|
|
|
|
|
|
CDSB *CSoundBoard::GetDSB(void)
|
|
|
|
{
|
|
|
|
return DSB;
|
|
|
|
}
|
|
|
|
|
2017-03-27 03:19:15 +00:00
|
|
|
CSoundBoard::CSoundBoard(const Util::Config::Node &config)
|
|
|
|
: m_config(config)
|
2011-04-24 01:14:00 +00:00
|
|
|
{
|
2011-07-31 02:37:31 +00:00
|
|
|
DSB = NULL;
|
2011-04-24 01:14:00 +00:00
|
|
|
memoryPool = NULL;
|
|
|
|
ram1 = NULL;
|
|
|
|
ram2 = NULL;
|
2022-06-09 21:10:39 +00:00
|
|
|
audioFL = NULL;
|
|
|
|
audioFR = NULL;
|
|
|
|
audioRL = NULL;
|
|
|
|
audioRR = NULL;
|
2011-07-31 02:37:31 +00:00
|
|
|
soundROM = NULL;
|
|
|
|
sampleROM = NULL;
|
2011-04-24 01:14:00 +00:00
|
|
|
|
|
|
|
DebugLog("Built Sound Board\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
CSoundBoard::~CSoundBoard(void)
|
|
|
|
{
|
2011-07-31 02:37:31 +00:00
|
|
|
#ifdef SUPERMODEL_LOG_AUDIO
|
2011-04-24 01:14:00 +00:00
|
|
|
// close binary log file
|
|
|
|
fclose(soundFP);
|
2011-07-12 04:57:12 +00:00
|
|
|
#endif
|
2011-04-24 01:14:00 +00:00
|
|
|
|
|
|
|
SCSP_Deinit();
|
|
|
|
|
2011-07-31 02:37:31 +00:00
|
|
|
DSB = NULL;
|
|
|
|
|
2011-04-24 01:14:00 +00:00
|
|
|
if (memoryPool != NULL)
|
|
|
|
{
|
|
|
|
delete [] memoryPool;
|
|
|
|
memoryPool = NULL;
|
|
|
|
}
|
|
|
|
ram1 = NULL;
|
|
|
|
ram2 = NULL;
|
2022-06-09 21:10:39 +00:00
|
|
|
audioFL = NULL;
|
|
|
|
audioFR = NULL;
|
|
|
|
audioRL = NULL;
|
|
|
|
audioRR = NULL;
|
2011-07-31 02:37:31 +00:00
|
|
|
soundROM = NULL;
|
|
|
|
sampleROM = NULL;
|
|
|
|
|
2011-04-24 01:14:00 +00:00
|
|
|
DebugLog("Destroyed Sound Board\n");
|
|
|
|
}
|