* THE SOFTWARE.
*/
+#include "qemu/osdep.h"
+#include "qapi/error.h"
#include "hw/hw.h"
-#include "hw/audio/audio.h"
+#include "hw/audio/soundhw.h"
#include "audio/audio.h"
#include "hw/isa/isa.h"
#define ADLIB_KILL_TIMERS 1
-#ifdef HAS_YMF262
-#define ADLIB_DESC "Yamaha YMF262 (OPL3)"
-#else
#define ADLIB_DESC "Yamaha YM3812 (OPL2)"
-#endif
#ifdef DEBUG
#include "qemu/timer.h"
#define ldebug(...)
#endif
-#ifdef HAS_YMF262
-#include "ymf262.h"
-void YMF262UpdateOneQEMU (int which, INT16 *dst, int length);
-#define SHIFT 2
-#else
#include "fmopl.h"
#define SHIFT 1
-#endif
-
-#define IO_READ_PROTO(name) \
- uint32_t name (void *opaque, uint32_t nport)
-#define IO_WRITE_PROTO(name) \
- void name (void *opaque, uint32_t nport, uint32_t val)
#define TYPE_ADLIB "adlib"
#define ADLIB(obj) OBJECT_CHECK(AdlibState, (obj), TYPE_ADLIB)
SWVoiceOut *voice;
int left, pos, samples;
QEMUAudioTimeStamp ats;
-#ifndef HAS_YMF262
FM_OPL *opl;
-#endif
+ PortioList port_list;
} AdlibState;
-static AdlibState *glob_adlib;
-
static void adlib_stop_opl_timer (AdlibState *s, size_t n)
{
-#ifdef HAS_YMF262
- YMF262TimerOver (0, n);
-#else
OPLTimerOver (s->opl, n);
-#endif
s->ticking[n] = 0;
}
}
}
-static IO_WRITE_PROTO (adlib_write)
+static void adlib_write(void *opaque, uint32_t nport, uint32_t val)
{
AdlibState *s = opaque;
int a = nport & 3;
adlib_kill_timers (s);
-#ifdef HAS_YMF262
- YMF262Write (0, a, val);
-#else
OPLWrite (s->opl, a, val);
-#endif
}
-static IO_READ_PROTO (adlib_read)
+static uint32_t adlib_read(void *opaque, uint32_t nport)
{
AdlibState *s = opaque;
uint8_t data;
int a = nport & 3;
adlib_kill_timers (s);
-
-#ifdef HAS_YMF262
- data = YMF262Read (0, a);
-#else
data = OPLRead (s->opl, a);
-#endif
+
return data;
}
-static void timer_handler (int c, double interval_Sec)
+static void timer_handler (void *opaque, int c, double interval_Sec)
{
- AdlibState *s = glob_adlib;
+ AdlibState *s = opaque;
unsigned n = c & 1;
#ifdef DEBUG
double interval;
s->ticking[n] = 1;
#ifdef DEBUG
- interval = get_ticks_per_sec () * interval_Sec;
- exp = qemu_get_clock_ns (vm_clock) + interval;
+ interval = NANOSECONDS_PER_SECOND * interval_Sec;
+ exp = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + interval;
s->exp[n] = exp;
#endif
return;
}
-#ifdef HAS_YMF262
- YMF262UpdateOneQEMU (0, s->mixbuf + s->pos * 2, samples);
-#else
YM3812UpdateOne (s->opl, s->mixbuf + s->pos, samples);
-#endif
while (samples) {
written = write_audio (s, samples);
static void Adlib_fini (AdlibState *s)
{
-#ifdef HAS_YMF262
- YMF262Shutdown ();
-#else
if (s->opl) {
OPLDestroy (s->opl);
s->opl = NULL;
}
-#endif
- if (s->mixbuf) {
- g_free (s->mixbuf);
- }
+ g_free(s->mixbuf);
s->active = 0;
s->enabled = 0;
}
static MemoryRegionPortio adlib_portio_list[] = {
- { 0x388, 4, 1, .read = adlib_read, .write = adlib_write, },
{ 0, 4, 1, .read = adlib_read, .write = adlib_write, },
{ 0, 2, 1, .read = adlib_read, .write = adlib_write, },
+ { 0x388, 4, 1, .read = adlib_read, .write = adlib_write, },
PORTIO_END_OF_LIST(),
};
static void adlib_realizefn (DeviceState *dev, Error **errp)
{
AdlibState *s = ADLIB(dev);
- PortioList *port_list = g_new(PortioList, 1);
struct audsettings as;
- if (glob_adlib) {
- error_setg (errp, "Cannot create more than 1 adlib device");
- return;
- }
- glob_adlib = s;
-
-#ifdef HAS_YMF262
- if (YMF262Init (1, 14318180, s->freq)) {
- error_setg (errp, "YMF262Init %d failed", s->freq);
- return;
- }
- else {
- YMF262SetTimerHandler (0, timer_handler, 0);
- s->enabled = 1;
- }
-#else
- s->opl = OPLCreate (OPL_TYPE_YM3812, 3579545, s->freq);
+ s->opl = OPLCreate (3579545, s->freq);
if (!s->opl) {
error_setg (errp, "OPLCreate %d failed", s->freq);
return;
}
else {
- OPLSetTimerHandler (s->opl, timer_handler, 0);
+ OPLSetTimerHandler(s->opl, timer_handler, s);
s->enabled = 1;
}
-#endif
as.freq = s->freq;
as.nchannels = SHIFT;
s->samples = AUD_get_buffer_size_out (s->voice) >> SHIFT;
s->mixbuf = g_malloc0 (s->samples << SHIFT);
- adlib_portio_list[1].offset = s->port;
- adlib_portio_list[2].offset = s->port + 8;
- portio_list_init (port_list, OBJECT(s), adlib_portio_list, s, "adlib");
- portio_list_add (port_list, isa_address_space_io(&s->parent_obj), 0);
+ adlib_portio_list[0].offset = s->port;
+ adlib_portio_list[1].offset = s->port + 8;
+ portio_list_init (&s->port_list, OBJECT(s), adlib_portio_list, s, "adlib");
+ portio_list_add (&s->port_list, isa_address_space_io(&s->parent_obj), 0);
}
static Property adlib_properties[] = {
- DEFINE_PROP_HEX32 ("iobase", AdlibState, port, 0x220),
+ DEFINE_PROP_UINT32 ("iobase", AdlibState, port, 0x220),
DEFINE_PROP_UINT32 ("freq", AdlibState, freq, 44100),
DEFINE_PROP_END_OF_LIST (),
};