Added dual opl2 and opl3 emulation.
Fixed the sample rate config option not being used. Added different soundblaster type options. Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@1699
This commit is contained in:
parent
30e64fda9b
commit
9d26cef41c
8 changed files with 3168 additions and 251 deletions
|
@ -29,9 +29,7 @@
|
|||
Thanks to vdmsound for nice simple way to implement this
|
||||
*/
|
||||
|
||||
namespace MAME {
|
||||
/* Defines */
|
||||
# define logerror(x)
|
||||
# define logerror
|
||||
|
||||
#ifdef _MSC_VER
|
||||
/* Disable recurring warnings */
|
||||
|
@ -39,166 +37,137 @@ namespace MAME {
|
|||
# pragma warning ( disable : 4244 )
|
||||
#endif
|
||||
|
||||
/* Work around ANSI compliance problem (see driver.h) */
|
||||
struct __MALLOCPTR {
|
||||
void* m_ptr;
|
||||
struct __MALLOCPTR {
|
||||
void* m_ptr;
|
||||
|
||||
__MALLOCPTR(void) : m_ptr(NULL) { }
|
||||
__MALLOCPTR(void* src) : m_ptr(src) { }
|
||||
void* operator=(void* rhs) { return (m_ptr = rhs); }
|
||||
operator int*() const { return (int*)m_ptr; }
|
||||
operator int**() const { return (int**)m_ptr; }
|
||||
operator char*() const { return (char*)m_ptr; }
|
||||
};
|
||||
|
||||
/* Bring in the MAME OPL emulation */
|
||||
# define HAS_YM3812 1
|
||||
# include "fmopl.c"
|
||||
|
||||
}
|
||||
|
||||
|
||||
struct OPLTimer_t {
|
||||
bool isEnabled;
|
||||
bool isMasked;
|
||||
bool isOverflowed;
|
||||
Bit64u count;
|
||||
Bit64u base;
|
||||
__MALLOCPTR(void) : m_ptr(NULL) { }
|
||||
__MALLOCPTR(void* src) : m_ptr(src) { }
|
||||
void* operator=(void* rhs) { return (m_ptr = rhs); }
|
||||
operator int*() const { return (int*)m_ptr; }
|
||||
operator int**() const { return (int**)m_ptr; }
|
||||
operator char*() const { return (char*)m_ptr; }
|
||||
};
|
||||
|
||||
static OPLTimer_t timer1,timer2;
|
||||
static Bit8u regsel;
|
||||
namespace OPL2 {
|
||||
#define HAS_YM3812 1
|
||||
#include "fmopl.c"
|
||||
void TimerOver(Bitu val){
|
||||
YM3812TimerOver(val>>8,val & 0xff);
|
||||
}
|
||||
void TimerHandler(int channel,double interval_Sec) {
|
||||
PIC_AddEvent(TimerOver,1000000*interval_Sec,channel);
|
||||
}
|
||||
}
|
||||
#undef OSD_CPU_H
|
||||
#undef TL_TAB_LEN
|
||||
namespace OPL3 {
|
||||
#define HAS_YMF262 1
|
||||
#include "ymf262.c"
|
||||
void TimerOver(Bitu val){
|
||||
YMF262TimerOver(val>>8,val & 0xff);
|
||||
}
|
||||
void TimerHandler(int channel,double interval_Sec) {
|
||||
PIC_AddEvent(TimerOver,1000000*interval_Sec,channel);
|
||||
}
|
||||
}
|
||||
|
||||
#define OPL_INTERNAL_FREQ 3600000 // The OPL operates at 3.6MHz
|
||||
#define OPL_NUM_CHIPS 1 // Number of OPL chips
|
||||
#define OPL_CHIP0 0
|
||||
#define OPL2_INTERNAL_FREQ 3600000 // The OPL2 operates at 3.6MHz
|
||||
#define OPL3_INTERNAL_FREQ 14400000 // The OPL3 operates at 14.4MHz
|
||||
|
||||
static MIXER_Channel * adlib_chan;
|
||||
static struct {
|
||||
bool active;
|
||||
OPL_Mode mode;
|
||||
MIXER_Channel * chan;
|
||||
Bit32u last_used;
|
||||
Bit16s mixbuf[2][128];
|
||||
} opl;
|
||||
|
||||
static void ADLIB_CallBack(Bit8u *stream, Bit32u len) {
|
||||
static void OPL_CallBack(Bit8u *stream, Bit32u len) {
|
||||
/* Check for size to update and check for 1 ms updates to the opl registers */
|
||||
/* Calculate teh machine ms we are at now */
|
||||
|
||||
/* update 1 ms of data */
|
||||
MAME::YM3812UpdateOne(0,(MAME::INT16 *)stream,len);
|
||||
}
|
||||
Bitu i;
|
||||
switch(opl.mode) {
|
||||
case OPL_opl2:
|
||||
OPL2::YM3812UpdateOne(0,(OPL2::INT16 *)stream,len);
|
||||
break;
|
||||
case OPL_opl3:
|
||||
OPL3::YMF262UpdateOne(0,(OPL2::INT16 *)stream,len);
|
||||
break;
|
||||
case OPL_dualopl2:
|
||||
OPL2::YM3812UpdateOne(0,(OPL2::INT16 *)opl.mixbuf[0],len);
|
||||
OPL2::YM3812UpdateOne(1,(OPL2::INT16 *)opl.mixbuf[1],len);
|
||||
for (i=0;i<len;i++) {
|
||||
((Bit16u *)stream)[i*2+0]=opl.mixbuf[0][i];
|
||||
((Bit16u *)stream)[i*2+1]=opl.mixbuf[1][i];
|
||||
}
|
||||
break;
|
||||
|
||||
static Bit8u read_p388(Bit32u port) {
|
||||
Bit8u ret=0;
|
||||
Bit64u micro=PIC_MicroCount();
|
||||
if (timer1.isEnabled) {
|
||||
if ((micro-timer1.base)>timer1.count) {
|
||||
timer1.isOverflowed=true;
|
||||
timer1.base=micro;
|
||||
}
|
||||
if (timer1.isOverflowed || !timer1.isMasked) {
|
||||
ret|=0xc0;
|
||||
}
|
||||
}
|
||||
if (timer2.isEnabled) {
|
||||
if ((micro-timer2.base)>timer2.count) {
|
||||
timer2.isOverflowed=true;
|
||||
timer2.base=micro;
|
||||
}
|
||||
if (timer2.isOverflowed || !timer2.isMasked) {
|
||||
ret|=0xA0;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void write_p388(Bit32u port,Bit8u val) {
|
||||
regsel=val;
|
||||
|
||||
// The following writes this value to ultrasounds equivalent register.
|
||||
// I don't know of any other way to do this
|
||||
IO_Write(0x248,val);
|
||||
}
|
||||
|
||||
static void write_p389(Bit32u port,Bit8u val) {
|
||||
switch (regsel) {
|
||||
case 0x02: /* Timer 1 */
|
||||
timer1.count=val*80;
|
||||
return;
|
||||
case 0x03: /* Timer 2 */
|
||||
timer2.count=val*320;
|
||||
return;
|
||||
case 0x04: /* IRQ clear / mask and Timer enable */
|
||||
if (val&0x80) {
|
||||
timer1.isOverflowed=false;
|
||||
timer2.isOverflowed=false;
|
||||
return;
|
||||
}
|
||||
if (val&0x40) timer1.isMasked=true;
|
||||
else timer1.isMasked=false;
|
||||
|
||||
if (val&1) {
|
||||
timer1.isEnabled=true;
|
||||
timer1.base=PIC_MicroCount();
|
||||
} else timer1.isEnabled=false;
|
||||
if (val&0x20) timer2.isMasked=true;
|
||||
else timer2.isMasked=false;
|
||||
if (val&2) {
|
||||
timer2.isEnabled=true;
|
||||
timer2.base=PIC_MicroCount();
|
||||
} else timer2.isEnabled=false;
|
||||
return;
|
||||
default: /* Normal OPL call queue it */
|
||||
/* Use a little hack to directly write to the register */
|
||||
MAME::OPLWriteReg(MAME::OPL_YM3812[0],regsel,val);
|
||||
if ((PIC_Ticks-opl.last_used)>1000) {
|
||||
MIXER_Enable(opl.chan,false);
|
||||
opl.active=false;
|
||||
}
|
||||
}
|
||||
|
||||
static bool adlib_enabled;
|
||||
Bit8u OPL_Read(Bit32u port) {
|
||||
Bitu addr=port & 3;
|
||||
switch (opl.mode) {
|
||||
case OPL_opl2:
|
||||
return OPL2::YM3812Read(0,addr);
|
||||
case OPL_dualopl2:
|
||||
return OPL2::YM3812Read(addr>>1,addr);
|
||||
case OPL_opl3:
|
||||
return OPL3::YMF262Read(0,addr);
|
||||
}
|
||||
return 0xff;
|
||||
}
|
||||
|
||||
static void ADLIB_Enable(bool enable) {
|
||||
if (enable) {
|
||||
adlib_enabled=true;
|
||||
MIXER_Enable(adlib_chan,true);
|
||||
IO_RegisterWriteHandler(0x388,write_p388,"ADLIB Register select");
|
||||
IO_RegisterWriteHandler(0x389,write_p389,"ADLIB Data Write");
|
||||
IO_RegisterReadHandler(0x388,read_p388,"ADLIB Status");
|
||||
|
||||
IO_RegisterWriteHandler(0x220,write_p388,"ADLIB Register select");
|
||||
IO_RegisterWriteHandler(0x221,write_p389,"ADLIB Data Write");
|
||||
IO_RegisterReadHandler(0x220,read_p388,"ADLIB Status");
|
||||
} else {
|
||||
adlib_enabled=false;
|
||||
MIXER_Enable(adlib_chan,false);
|
||||
IO_FreeWriteHandler(0x220);
|
||||
IO_FreeWriteHandler(0x221);
|
||||
IO_FreeReadHandler(0x220);
|
||||
IO_FreeWriteHandler(0x388);
|
||||
IO_FreeWriteHandler(0x389);
|
||||
IO_FreeReadHandler(0x388);
|
||||
void OPL_Write(Bit32u port,Bit8u val) {
|
||||
opl.last_used=PIC_Ticks;
|
||||
if (!opl.active) {
|
||||
opl.active=true;
|
||||
MIXER_Enable(opl.chan,true);
|
||||
}
|
||||
Bitu addr=port & 3;
|
||||
switch (opl.mode) {
|
||||
case OPL_opl2:
|
||||
OPL2::YM3812Write(0,addr,val);
|
||||
break;
|
||||
case OPL_opl3:
|
||||
OPL3::YMF262Write(0,addr,val);
|
||||
break;
|
||||
case OPL_dualopl2:
|
||||
OPL2::YM3812Write(addr>>1,addr,val);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ADLIB_Init(Section* sec) {
|
||||
void OPL_Init(Section* sec,OPL_Mode oplmode,Bitu rate) {
|
||||
Bitu i;
|
||||
Section_prop * section=static_cast<Section_prop *>(sec);
|
||||
if(!section->Get_bool("adlib")) return;
|
||||
|
||||
timer1.isMasked=true;
|
||||
timer1.base=0;
|
||||
timer1.count=0;
|
||||
timer1.isEnabled=false;
|
||||
timer1.isOverflowed=false;
|
||||
|
||||
timer2.isMasked=true;
|
||||
timer2.base=0;
|
||||
timer2.count=0;
|
||||
timer2.isEnabled=false;
|
||||
timer2.isOverflowed=false;
|
||||
|
||||
#define ADLIB_FREQ 22050
|
||||
if (MAME::YM3812Init(OPL_NUM_CHIPS,OPL_INTERNAL_FREQ,ADLIB_FREQ)) {
|
||||
E_Exit("Can't create adlib OPL Emulator");
|
||||
if (OPL2::YM3812Init(2,OPL2_INTERNAL_FREQ,rate)) {
|
||||
E_Exit("Can't create OPL2 Emulator");
|
||||
};
|
||||
OPL2::YM3812SetTimerHandler(0,OPL2::TimerHandler,0);
|
||||
OPL2::YM3812SetTimerHandler(1,OPL2::TimerHandler,256);
|
||||
if (OPL3::YMF262Init(1,OPL3_INTERNAL_FREQ,rate)) {
|
||||
E_Exit("Can't create OPL3 Emulator");
|
||||
};
|
||||
OPL3::YMF262SetTimerHandler(0,OPL3::TimerHandler,0);
|
||||
for (i=0;i<4;i++) {
|
||||
IO_RegisterWriteHandler(0x388+i,OPL_Write,"OPL Write");
|
||||
IO_RegisterReadHandler(0x388+i,OPL_Read,"OPL read");
|
||||
IO_RegisterWriteHandler(0x220+i,OPL_Write,"OPL Write");
|
||||
IO_RegisterReadHandler(0x220+i,OPL_Read,"OPL read");
|
||||
}
|
||||
opl.active=false;
|
||||
opl.last_used=0;
|
||||
opl.mode=oplmode;
|
||||
|
||||
|
||||
adlib_chan=MIXER_AddChannel(ADLIB_CallBack,ADLIB_FREQ,"ADLIB");
|
||||
MIXER_SetMode(adlib_chan,MIXER_16MONO);
|
||||
ADLIB_Enable(true);
|
||||
opl.chan=MIXER_AddChannel(OPL_CallBack,rate,"ADLIB");
|
||||
MIXER_SetMode(opl.chan,(opl.mode>OPL_opl2) ? MIXER_16STEREO : MIXER_16MONO);
|
||||
MIXER_Enable(opl.chan,false);
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue