2009-05-05 21:47:12 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* This program 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 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* $URL$
|
|
|
|
* $Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "sound/fmopl.h"
|
|
|
|
|
|
|
|
#include "sound/softsynth/opl/dosbox.h"
|
|
|
|
#include "sound/softsynth/opl/mame.h"
|
|
|
|
|
2009-05-12 18:42:44 +00:00
|
|
|
#include "common/config-manager.h"
|
|
|
|
|
2009-05-05 21:47:12 +00:00
|
|
|
namespace OPL {
|
|
|
|
|
2009-05-12 18:42:44 +00:00
|
|
|
// Config implementation
|
2009-05-05 21:47:12 +00:00
|
|
|
|
2009-05-12 18:42:44 +00:00
|
|
|
enum OplEmulator {
|
2009-05-12 19:03:54 +00:00
|
|
|
kAuto = 0,
|
2009-05-12 18:53:44 +00:00
|
|
|
kMame = 1,
|
|
|
|
kDOSBox = 2
|
2009-05-12 18:42:44 +00:00
|
|
|
};
|
2009-05-05 21:47:12 +00:00
|
|
|
|
2009-05-12 18:42:44 +00:00
|
|
|
const Config::EmulatorDescription Config::_drivers[] = {
|
2009-05-12 19:03:54 +00:00
|
|
|
{ "auto", "<default>", kAuto, kFlagOpl2 | kFlagDualOpl2 | kFlagOpl3 },
|
2009-05-12 18:42:44 +00:00
|
|
|
{ "mame", "MAME OPL emulator", kMame, kFlagOpl2 },
|
|
|
|
#ifndef DISABLE_DOSBOX_OPL
|
|
|
|
{ "db", "DOSBox OPL emulator (experimental)", kDOSBox, kFlagOpl2 | kFlagDualOpl2 | kFlagOpl3 },
|
2009-05-05 21:47:12 +00:00
|
|
|
#endif
|
2009-05-12 18:42:44 +00:00
|
|
|
{ 0, 0, 0, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
Config::DriverId Config::parse(const Common::String &name) {
|
|
|
|
for (int i = 0; _drivers[i].name; ++i) {
|
|
|
|
if (name.equalsIgnoreCase(_drivers[i].name))
|
|
|
|
return _drivers[i].id;
|
|
|
|
}
|
|
|
|
|
2009-05-12 19:03:54 +00:00
|
|
|
return -1;
|
2009-05-05 21:47:12 +00:00
|
|
|
}
|
|
|
|
|
2009-05-12 18:42:44 +00:00
|
|
|
Config::DriverId Config::detect(OplType type) {
|
|
|
|
uint32 flags = 0;
|
|
|
|
switch (type) {
|
|
|
|
case kOpl2:
|
|
|
|
flags = kFlagOpl2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kDualOpl2:
|
|
|
|
flags = kFlagDualOpl2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kOpl3:
|
|
|
|
flags = kFlagOpl3;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
DriverId drv = parse(ConfMan.get("opl_driver"));
|
|
|
|
|
|
|
|
// When a valid driver is selected, check whether it supports
|
|
|
|
// the requested OPL chip.
|
2009-05-12 19:03:54 +00:00
|
|
|
if (drv != -1 && drv != kAuto) {
|
2009-05-12 18:42:44 +00:00
|
|
|
// If the chip is supported, just use the driver.
|
|
|
|
if ((flags & _drivers[drv].flags))
|
|
|
|
return drv;
|
|
|
|
// When it doesn't support the flags fall back to auto detection
|
2009-05-12 19:03:54 +00:00
|
|
|
else
|
|
|
|
drv = -1;
|
2009-05-12 18:42:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Detect the first matching emulator
|
|
|
|
for (int i = 1; _drivers[i].name; ++i) {
|
|
|
|
if (_drivers[i].flags & flags) {
|
|
|
|
drv = _drivers[i].id;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return drv;
|
|
|
|
}
|
|
|
|
|
|
|
|
OPL *Config::create(DriverId driver, OplType type) {
|
2009-05-12 19:03:54 +00:00
|
|
|
// On invalid driver selection, we try to do some fallback detection
|
|
|
|
if (driver == -1) {
|
|
|
|
warning("Invalid OPL driver selected, trying to detect a fallback emulator");
|
|
|
|
driver = kAuto;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If autodetection is selected, we search for a matching
|
|
|
|
// driver.
|
|
|
|
if (driver == kAuto) {
|
2009-05-12 18:42:44 +00:00
|
|
|
driver = detect(type);
|
|
|
|
|
2009-05-12 19:03:54 +00:00
|
|
|
// No emulator for the specified OPL chip could
|
|
|
|
// be found, thus stop here.
|
|
|
|
if (driver == -1) {
|
|
|
|
warning("No OPL emulator available for type %d", type);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (driver) {
|
2009-05-12 18:42:44 +00:00
|
|
|
case kMame:
|
|
|
|
if (type == kOpl2)
|
|
|
|
return new MAME::OPL();
|
|
|
|
else
|
|
|
|
warning("MAME OPL emulator only supports OPL2 emulation.");
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
#ifndef DISABLE_DOSBOX_OPL
|
|
|
|
case kDOSBox:
|
|
|
|
return new DOSBox::OPL(type);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
default:
|
|
|
|
warning("Unsupported OPL emulator %d", driver);
|
|
|
|
// TODO: Maybe we should add some dummy emulator too, which just outputs
|
|
|
|
// silence as sound?
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OPL::_hasInstance = false;
|
|
|
|
|
2009-05-05 21:47:12 +00:00
|
|
|
} // end of namespace OPL
|
|
|
|
|
|
|
|
void OPLDestroy(FM_OPL *OPL) {
|
|
|
|
delete OPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OPLResetChip(FM_OPL *OPL) {
|
|
|
|
OPL->reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OPLWrite(FM_OPL *OPL, int a, int v) {
|
|
|
|
OPL->write(a, v);
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned char OPLRead(FM_OPL *OPL, int a) {
|
|
|
|
return OPL->read(a);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OPLWriteReg(FM_OPL *OPL, int r, int v) {
|
|
|
|
OPL->writeReg(r, v);
|
|
|
|
}
|
|
|
|
|
|
|
|
void YM3812UpdateOne(FM_OPL *OPL, int16 *buffer, int length) {
|
|
|
|
OPL->readBuffer(buffer, length);
|
|
|
|
}
|
|
|
|
|
|
|
|
FM_OPL *makeAdlibOPL(int rate) {
|
2009-05-12 19:24:04 +00:00
|
|
|
FM_OPL *opl = OPL::Config::create();
|
2009-05-05 21:47:12 +00:00
|
|
|
|
|
|
|
if (opl) {
|
|
|
|
if (!opl->init(rate)) {
|
|
|
|
delete opl;
|
|
|
|
opl = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return opl;
|
|
|
|
}
|
|
|
|
|