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
|
|
|
*/
|
|
|
|
|
|
|
|
#include "Supermodel.h"
|
|
|
|
|
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
|
|
|
|
|
|
|
/******************************************************************************
|
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))
|
|
|
|
{
|
|
|
|
sampleBankLo = &sampleROM[0xA00000];
|
|
|
|
sampleBankHi = &sampleROM[0xE00000];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sampleBankLo = &sampleROM[0x200000];
|
|
|
|
sampleBankHi = &sampleROM[0x600000];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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];
|
|
|
|
|
|
|
|
case 0x8: // Sample ROM (low 2MB, fixed): 800000-9FFFFF
|
|
|
|
case 0x9:
|
|
|
|
return sampleROM[(a&0x1FFFFF)^1];
|
|
|
|
|
|
|
|
case 0xA: // Sample ROM (bank): A00000-DFFFFF
|
|
|
|
case 0xB:
|
|
|
|
case 0xC:
|
|
|
|
case 0xD:
|
|
|
|
return sampleBankLo[(a-0xA00000)^1];
|
|
|
|
|
|
|
|
case 0xE: // Sample ROM (bank): E00000-FFFFFF
|
|
|
|
case 0xF:
|
|
|
|
return sampleBankHi[(a&0x1FFFFF)^1];
|
|
|
|
|
|
|
|
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-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 *(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];
|
|
|
|
|
|
|
|
case 0x8: // Sample ROM (low 2MB, fixed): 800000-9FFFFF
|
|
|
|
case 0x9:
|
|
|
|
return *(UINT16 *) &sampleROM[a&0x1FFFFF];
|
|
|
|
|
|
|
|
case 0xA: // Sample ROM (bank): A00000-DFFFFF
|
|
|
|
case 0xB:
|
|
|
|
case 0xC:
|
|
|
|
case 0xD:
|
|
|
|
return *(UINT16 *) &sampleBankLo[a-0xA00000];
|
|
|
|
|
|
|
|
case 0xE: // Sample ROM (bank): E00000-FFFFFF
|
|
|
|
case 0xF:
|
|
|
|
return *(UINT16 *) &sampleBankHi[a&0x1FFFFF];
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
case 0x8: // Sample ROM (low 2MB, fixed): 800000-9FFFFF
|
|
|
|
case 0x9:
|
|
|
|
hi = *(UINT16 *) &sampleROM[a&0x1FFFFF];
|
|
|
|
lo = *(UINT16 *) &sampleROM[(a+2)&0x1FFFFF];
|
|
|
|
return (hi<<16)|lo;
|
|
|
|
|
|
|
|
case 0xA: // Sample ROM (bank): A00000-DFFFFF
|
|
|
|
case 0xB:
|
|
|
|
case 0xC:
|
|
|
|
case 0xD:
|
|
|
|
hi = *(UINT16 *) &sampleBankLo[a-0xA00000];
|
|
|
|
lo = *(UINT16 *) &sampleBankLo[a+2-0xA00000];
|
|
|
|
return (hi<<16)|lo;
|
|
|
|
|
|
|
|
case 0xE: // Sample ROM (bank): E00000-FFFFFF
|
|
|
|
case 0xF:
|
|
|
|
hi = *(UINT16 *) &sampleBankHi[a&0x1FFFFF];
|
|
|
|
lo = *(UINT16 *) &sampleBankHi[(a+2)&0x1FFFFF];
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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
|
2011-09-14 06:16:22 +00:00
|
|
|
if (g_Config.emulateSound)
|
2011-08-19 20:43:07 +00:00
|
|
|
{
|
|
|
|
M68KSetContext(&M68K);
|
|
|
|
SCSP_Update();
|
|
|
|
M68KGetContext(&M68K);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
memset(audioL, 0, 44100/60*sizeof(INT16));
|
|
|
|
memset(audioR, 0, 44100/60*sizeof(INT16));
|
|
|
|
}
|
2011-07-31 02:37:31 +00:00
|
|
|
|
|
|
|
// Run DSB and mix with existing audio
|
|
|
|
if (NULL != DSB)
|
|
|
|
DSB->RunFrame(audioL, audioR);
|
2011-07-20 21:14:00 +00:00
|
|
|
|
|
|
|
// Output the audio buffers
|
2011-09-12 05:43:37 +00:00
|
|
|
bool bufferFull = OutputAudio(44100/60, audioL, audioR);
|
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;
|
|
|
|
for (int i = 0; i < 44100/60; i++)
|
2011-07-31 02:37:31 +00:00
|
|
|
{
|
|
|
|
s = audioL[i];
|
2011-04-24 01:14:00 +00:00
|
|
|
fwrite(&s, sizeof(INT16), 1, soundFP); // left channel
|
2011-07-31 02:37:31 +00:00
|
|
|
s = audioR[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
|
|
|
// Offsets of memory regions within sound board's pool
|
2011-08-15 05:59:33 +00:00
|
|
|
#define OFFSET_RAM1 0 // 1 MB SCSP1 RAM
|
|
|
|
#define OFFSET_RAM2 0x100000 // 1 MB SCSP2 RAM
|
|
|
|
#define OFFSET_AUDIO_LEFT 0x200000 // 1470 bytes (16 bits, 44.1 KHz, 1/60th second) left audio channel
|
|
|
|
#define OFFSET_AUDIO_RIGHT 0x2005BE // 1470 bytes right audio channel
|
|
|
|
#define MEMORY_POOL_SIZE (0x100000 + 0x100000 + 0x5BE + 0x5BE)
|
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];
|
2011-07-31 02:37:31 +00:00
|
|
|
audioL = (INT16 *) &memoryPool[OFFSET_AUDIO_LEFT];
|
|
|
|
audioR = (INT16 *) &memoryPool[OFFSET_AUDIO_RIGHT];
|
2011-04-24 01:14:00 +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
|
2011-07-31 02:37:31 +00:00
|
|
|
SCSP_SetBuffers(audioL, audioR, 44100/60);
|
|
|
|
SCSP_SetCB(SCSP68KRunCallback, SCSP68KIRQCallback);
|
2011-09-14 07:38:56 +00:00
|
|
|
if (OKAY != SCSP_Init(2))
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-04-24 01:14:00 +00:00
|
|
|
CSoundBoard::CSoundBoard(void)
|
|
|
|
{
|
2011-07-31 02:37:31 +00:00
|
|
|
DSB = NULL;
|
2011-04-24 01:14:00 +00:00
|
|
|
memoryPool = NULL;
|
|
|
|
ram1 = NULL;
|
|
|
|
ram2 = NULL;
|
2011-07-31 02:37:31 +00:00
|
|
|
audioL = NULL;
|
|
|
|
audioR = NULL;
|
|
|
|
soundROM = NULL;
|
|
|
|
sampleROM = NULL;
|
2011-04-24 01:14:00 +00:00
|
|
|
|
|
|
|
DebugLog("Built Sound Board\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void Reverse16(UINT8 *buf, unsigned size)
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
UINT8 tmp;
|
|
|
|
|
|
|
|
for (i = 0; i < size; i += 2)
|
|
|
|
{
|
|
|
|
tmp = buf[i+0];
|
|
|
|
buf[i+0] = buf[i+1];
|
|
|
|
buf[i+1] = tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2011-07-31 02:37:31 +00:00
|
|
|
audioL = NULL;
|
|
|
|
audioR = NULL;
|
|
|
|
soundROM = NULL;
|
|
|
|
sampleROM = NULL;
|
|
|
|
|
2011-04-24 01:14:00 +00:00
|
|
|
DebugLog("Destroyed Sound Board\n");
|
|
|
|
}
|