1
0
Fork 0

New adlib interface allowing for different emulation backends

Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@3299
This commit is contained in:
Sjoerd van der Berg 2009-02-03 19:20:30 +00:00
parent d25daebcb9
commit 9b70d00853
3 changed files with 496 additions and 177 deletions

121
src/hardware/adlib.h Normal file
View file

@ -0,0 +1,121 @@
#ifndef DOSBOX_ADLIB_H
#define DOSBOX_ADLIB_H
#include "dosbox.h"
#include "mixer.h"
#include "pic.h"
namespace Adlib {
struct Timer {
double start;
double delay;
bool enabled, overflow, masked;
Bit8u counter;
Timer() {
masked = false;
overflow = false;
enabled = false;
counter = 0;
delay = 0;
}
//Call update before making any further changes
void Update( double time ) {
if ( !enabled || !delay )
return;
double deltaStart = time - start;
//Only set the overflow flag when not masked
if ( deltaStart >= 0 && !masked ) {
overflow = 1;
}
}
//On a reset make sure the start is in sync with the next cycle
void Reset(const double& time ) {
overflow = false;
if ( !delay || !enabled )
return;
double delta = (time - start);
double rem = fmod( delta, delay );
double next = delay - rem;
start = time + next;
}
void Stop( ) {
enabled = false;
}
void Start( const double& time, Bits scale ) {
//Don't enable again
if ( enabled ) {
return;
}
enabled = true;
delay = 0.001 * (256 - counter ) * scale;
start = time + delay;
}
};
struct Chip {
//Last selected register
Timer timer[2];
//Check for it being a write to the timer
bool Write( Bit32u addr, Bit8u val );
//Read the current timer state, will use current double
Bit8u Read( );
};
//The type of handler this is
typedef enum {
MODE_OPL2,
MODE_DUALOPL2,
MODE_OPL3,
} Mode;
class Handler {
public:
//Write an address to a chip, returns the address the chip sets
virtual Bit32u WriteAddr( Bit32u port, Bit8u val ) = 0;
//Write to a specific register in the chip
virtual void WriteReg( Bit32u addr, Bit8u val ) = 0;
//Generate a certain amount of samples
virtual void Generate( MixerChannel* chan, Bitu samples ) = 0;
//Initialize at a specific sample rate and mode
virtual void Init( Bitu rate ) = 0;
};
//The cache for 2 chips or an opl3
typedef Bit8u RegisterCache[512];
//Internal class used for dro capturing
class Capture;
class Module {
//Mode we're running in
Mode mode;
//Last selected address in the chip for the different modes
union {
Bit32u normal;
Bit8u dual[2];
} reg;
void CacheWrite( Bit32u reg, Bit8u val );
void DualWrite( Bit8u index, Bit8u reg, Bit8u val );
public:
MixerChannel* chan;
Bit32u lastUsed; //Ticks when adlib was last used to turn of mixing after a few second
Handler* handler; //Handler that will generate the sound
RegisterCache cache;
Capture* capture;
Chip chip[2];
//Handle port writes
void PortWrite( Bitu port, Bitu val, Bitu iolen );
Bitu PortRead( Bitu port, Bitu iolen );
void Init( Mode m );
Module();
};
}; //Adlib namespace
#endif