bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 1 | /* |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 2 | * QEMU Proxy for OPL2/3 emulation by MAME team |
| 3 | * |
| 4 | * Copyright (c) 2004-2005 Vassili Karpov (malc) |
| 5 | * |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | * of this software and associated documentation files (the "Software"), to deal |
| 8 | * in the Software without restriction, including without limitation the rights |
| 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | * copies of the Software, and to permit persons to whom the Software is |
| 11 | * furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in |
| 14 | * all copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 22 | * THE SOFTWARE. |
| 23 | */ |
ths | 9f0683d | 2007-12-02 17:47:33 +0000 | [diff] [blame] | 24 | |
Paolo Bonzini | 83c9f4c | 2013-02-04 15:40:22 +0100 | [diff] [blame] | 25 | #include "hw/hw.h" |
Paolo Bonzini | 0d09e41 | 2013-02-05 17:06:20 +0100 | [diff] [blame] | 26 | #include "hw/audio/audio.h" |
ths | e140e05 | 2007-12-02 17:17:45 +0000 | [diff] [blame] | 27 | #include "audio/audio.h" |
Paolo Bonzini | 0d09e41 | 2013-02-05 17:06:20 +0100 | [diff] [blame] | 28 | #include "hw/isa/isa.h" |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 29 | |
ths | 9f0683d | 2007-12-02 17:47:33 +0000 | [diff] [blame] | 30 | //#define DEBUG |
| 31 | |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 32 | #define ADLIB_KILL_TIMERS 1 |
| 33 | |
Paolo Bonzini | 8c444a1 | 2013-04-18 18:43:57 +0200 | [diff] [blame] | 34 | #ifdef HAS_YMF262 |
| 35 | #define ADLIB_DESC "Yamaha YMF262 (OPL3)" |
| 36 | #else |
| 37 | #define ADLIB_DESC "Yamaha YM3812 (OPL2)" |
| 38 | #endif |
| 39 | |
ths | 9f0683d | 2007-12-02 17:47:33 +0000 | [diff] [blame] | 40 | #ifdef DEBUG |
Paolo Bonzini | 1de7afc | 2012-12-17 18:20:00 +0100 | [diff] [blame] | 41 | #include "qemu/timer.h" |
ths | 9f0683d | 2007-12-02 17:47:33 +0000 | [diff] [blame] | 42 | #endif |
| 43 | |
bellard | fb06518 | 2004-11-09 23:09:44 +0000 | [diff] [blame] | 44 | #define dolog(...) AUD_log ("adlib", __VA_ARGS__) |
| 45 | #ifdef DEBUG |
| 46 | #define ldebug(...) dolog (__VA_ARGS__) |
| 47 | #else |
| 48 | #define ldebug(...) |
| 49 | #endif |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 50 | |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 51 | #ifdef HAS_YMF262 |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 52 | #include "ymf262.h" |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 53 | void YMF262UpdateOneQEMU (int which, INT16 *dst, int length); |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 54 | #define SHIFT 2 |
| 55 | #else |
Paolo Bonzini | 47b43a1 | 2013-03-18 17:36:02 +0100 | [diff] [blame] | 56 | #include "fmopl.h" |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 57 | #define SHIFT 1 |
| 58 | #endif |
| 59 | |
Paolo Bonzini | 8c444a1 | 2013-04-18 18:43:57 +0200 | [diff] [blame] | 60 | #define TYPE_ADLIB "adlib" |
| 61 | #define ADLIB(obj) OBJECT_CHECK(AdlibState, (obj), TYPE_ADLIB) |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 62 | |
| 63 | typedef struct { |
Paolo Bonzini | 8c444a1 | 2013-04-18 18:43:57 +0200 | [diff] [blame] | 64 | ISADevice parent_obj; |
| 65 | |
bellard | c0fe382 | 2005-11-05 18:55:28 +0000 | [diff] [blame] | 66 | QEMUSoundCard card; |
Paolo Bonzini | 8c444a1 | 2013-04-18 18:43:57 +0200 | [diff] [blame] | 67 | uint32_t freq; |
| 68 | uint32_t port; |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 69 | int ticking[2]; |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 70 | int enabled; |
| 71 | int active; |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 72 | int bufpos; |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 73 | #ifdef DEBUG |
| 74 | int64_t exp[2]; |
| 75 | #endif |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 76 | int16_t *mixbuf; |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 77 | uint64_t dexp[2]; |
| 78 | SWVoiceOut *voice; |
| 79 | int left, pos, samples; |
| 80 | QEMUAudioTimeStamp ats; |
| 81 | #ifndef HAS_YMF262 |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 82 | FM_OPL *opl; |
| 83 | #endif |
Kirill Batuzov | 848696b | 2014-04-29 17:38:39 +0400 | [diff] [blame] | 84 | PortioList port_list; |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 85 | } AdlibState; |
| 86 | |
Paolo Bonzini | 8c444a1 | 2013-04-18 18:43:57 +0200 | [diff] [blame] | 87 | static AdlibState *glob_adlib; |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 88 | |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 89 | static void adlib_stop_opl_timer (AdlibState *s, size_t n) |
| 90 | { |
| 91 | #ifdef HAS_YMF262 |
| 92 | YMF262TimerOver (0, n); |
| 93 | #else |
| 94 | OPLTimerOver (s->opl, n); |
| 95 | #endif |
| 96 | s->ticking[n] = 0; |
| 97 | } |
| 98 | |
| 99 | static void adlib_kill_timers (AdlibState *s) |
| 100 | { |
| 101 | size_t i; |
| 102 | |
| 103 | for (i = 0; i < 2; ++i) { |
| 104 | if (s->ticking[i]) { |
| 105 | uint64_t delta; |
| 106 | |
bellard | c0fe382 | 2005-11-05 18:55:28 +0000 | [diff] [blame] | 107 | delta = AUD_get_elapsed_usec_out (s->voice, &s->ats); |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 108 | ldebug ( |
| 109 | "delta = %f dexp = %f expired => %d\n", |
| 110 | delta / 1000000.0, |
| 111 | s->dexp[i] / 1000000.0, |
| 112 | delta >= s->dexp[i] |
| 113 | ); |
| 114 | if (ADLIB_KILL_TIMERS || delta >= s->dexp[i]) { |
| 115 | adlib_stop_opl_timer (s, i); |
| 116 | AUD_init_time_stamp_out (s->voice, &s->ats); |
| 117 | } |
| 118 | } |
| 119 | } |
| 120 | } |
| 121 | |
Nutan Shinde | 8307c29 | 2015-10-07 22:02:54 +0530 | [diff] [blame] | 122 | static void adlib_write(void *opaque, uint32_t nport, uint32_t val) |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 123 | { |
| 124 | AdlibState *s = opaque; |
| 125 | int a = nport & 3; |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 126 | |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 127 | s->active = 1; |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 128 | AUD_set_active_out (s->voice, 1); |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 129 | |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 130 | adlib_kill_timers (s); |
| 131 | |
| 132 | #ifdef HAS_YMF262 |
Hervé Poussineau | e8beeae | 2011-09-18 16:27:23 +0200 | [diff] [blame] | 133 | YMF262Write (0, a, val); |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 134 | #else |
Hervé Poussineau | e8beeae | 2011-09-18 16:27:23 +0200 | [diff] [blame] | 135 | OPLWrite (s->opl, a, val); |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 136 | #endif |
| 137 | } |
| 138 | |
Nutan Shinde | 8307c29 | 2015-10-07 22:02:54 +0530 | [diff] [blame] | 139 | static uint32_t adlib_read(void *opaque, uint32_t nport) |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 140 | { |
| 141 | AdlibState *s = opaque; |
| 142 | uint8_t data; |
| 143 | int a = nport & 3; |
| 144 | |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 145 | adlib_kill_timers (s); |
| 146 | |
| 147 | #ifdef HAS_YMF262 |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 148 | data = YMF262Read (0, a); |
| 149 | #else |
| 150 | data = OPLRead (s->opl, a); |
| 151 | #endif |
| 152 | return data; |
| 153 | } |
| 154 | |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 155 | static void timer_handler (int c, double interval_Sec) |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 156 | { |
Paolo Bonzini | 8c444a1 | 2013-04-18 18:43:57 +0200 | [diff] [blame] | 157 | AdlibState *s = glob_adlib; |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 158 | unsigned n = c & 1; |
| 159 | #ifdef DEBUG |
| 160 | double interval; |
bellard | c0fe382 | 2005-11-05 18:55:28 +0000 | [diff] [blame] | 161 | int64_t exp; |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 162 | #endif |
| 163 | |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 164 | if (interval_Sec == 0.0) { |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 165 | s->ticking[n] = 0; |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 166 | return; |
| 167 | } |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 168 | |
| 169 | s->ticking[n] = 1; |
| 170 | #ifdef DEBUG |
malc | cf4dc46 | 2012-02-07 22:11:04 +0400 | [diff] [blame] | 171 | interval = get_ticks_per_sec () * interval_Sec; |
Alex Bligh | bc72ad6 | 2013-08-21 16:03:08 +0100 | [diff] [blame] | 172 | exp = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + interval; |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 173 | s->exp[n] = exp; |
| 174 | #endif |
| 175 | |
| 176 | s->dexp[n] = interval_Sec * 1000000.0; |
| 177 | AUD_init_time_stamp_out (s->voice, &s->ats); |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | static int write_audio (AdlibState *s, int samples) |
| 181 | { |
| 182 | int net = 0; |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 183 | int pos = s->pos; |
| 184 | |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 185 | while (samples) { |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 186 | int nbytes, wbytes, wsampl; |
| 187 | |
| 188 | nbytes = samples << SHIFT; |
| 189 | wbytes = AUD_write ( |
| 190 | s->voice, |
| 191 | s->mixbuf + (pos << (SHIFT - 1)), |
| 192 | nbytes |
| 193 | ); |
| 194 | |
| 195 | if (wbytes) { |
| 196 | wsampl = wbytes >> SHIFT; |
| 197 | |
| 198 | samples -= wsampl; |
| 199 | pos = (pos + wsampl) % s->samples; |
| 200 | |
| 201 | net += wsampl; |
| 202 | } |
| 203 | else { |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 204 | break; |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 205 | } |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 206 | } |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 207 | |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 208 | return net; |
| 209 | } |
| 210 | |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 211 | static void adlib_callback (void *opaque, int free) |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 212 | { |
| 213 | AdlibState *s = opaque; |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 214 | int samples, net = 0, to_play, written; |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 215 | |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 216 | samples = free >> SHIFT; |
| 217 | if (!(s->active && s->enabled) || !samples) { |
| 218 | return; |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 219 | } |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 220 | |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 221 | to_play = audio_MIN (s->left, samples); |
| 222 | while (to_play) { |
| 223 | written = write_audio (s, to_play); |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 224 | |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 225 | if (written) { |
| 226 | s->left -= written; |
| 227 | samples -= written; |
| 228 | to_play -= written; |
| 229 | s->pos = (s->pos + written) % s->samples; |
| 230 | } |
| 231 | else { |
| 232 | return; |
| 233 | } |
| 234 | } |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 235 | |
| 236 | samples = audio_MIN (samples, s->samples - s->pos); |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 237 | if (!samples) { |
| 238 | return; |
| 239 | } |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 240 | |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 241 | #ifdef HAS_YMF262 |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 242 | YMF262UpdateOneQEMU (0, s->mixbuf + s->pos * 2, samples); |
| 243 | #else |
| 244 | YM3812UpdateOne (s->opl, s->mixbuf + s->pos, samples); |
| 245 | #endif |
| 246 | |
| 247 | while (samples) { |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 248 | written = write_audio (s, samples); |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 249 | |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 250 | if (written) { |
| 251 | net += written; |
| 252 | samples -= written; |
| 253 | s->pos = (s->pos + written) % s->samples; |
| 254 | } |
| 255 | else { |
| 256 | s->left = samples; |
| 257 | return; |
| 258 | } |
| 259 | } |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | static void Adlib_fini (AdlibState *s) |
| 263 | { |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 264 | #ifdef HAS_YMF262 |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 265 | YMF262Shutdown (); |
| 266 | #else |
| 267 | if (s->opl) { |
| 268 | OPLDestroy (s->opl); |
| 269 | s->opl = NULL; |
| 270 | } |
| 271 | #endif |
| 272 | |
Markus Armbruster | fb7da62 | 2014-06-06 18:35:13 +0200 | [diff] [blame] | 273 | g_free(s->mixbuf); |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 274 | |
| 275 | s->active = 0; |
| 276 | s->enabled = 0; |
bellard | c0fe382 | 2005-11-05 18:55:28 +0000 | [diff] [blame] | 277 | AUD_remove_card (&s->card); |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 278 | } |
| 279 | |
Jan Kiszka | a8aec29 | 2013-06-22 08:06:54 +0200 | [diff] [blame] | 280 | static MemoryRegionPortio adlib_portio_list[] = { |
Jan Kiszka | a8aec29 | 2013-06-22 08:06:54 +0200 | [diff] [blame] | 281 | { 0, 4, 1, .read = adlib_read, .write = adlib_write, }, |
| 282 | { 0, 2, 1, .read = adlib_read, .write = adlib_write, }, |
Hervé Poussineau | 2b21fb5 | 2013-08-14 11:49:04 +0200 | [diff] [blame] | 283 | { 0x388, 4, 1, .read = adlib_read, .write = adlib_write, }, |
Jan Kiszka | a8aec29 | 2013-06-22 08:06:54 +0200 | [diff] [blame] | 284 | PORTIO_END_OF_LIST(), |
| 285 | }; |
| 286 | |
Andreas Färber | db895a1 | 2012-11-25 02:37:14 +0100 | [diff] [blame] | 287 | static void adlib_realizefn (DeviceState *dev, Error **errp) |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 288 | { |
Paolo Bonzini | 8c444a1 | 2013-04-18 18:43:57 +0200 | [diff] [blame] | 289 | AdlibState *s = ADLIB(dev); |
malc | 1ea879e | 2008-12-03 22:48:44 +0000 | [diff] [blame] | 290 | struct audsettings as; |
bellard | c0fe382 | 2005-11-05 18:55:28 +0000 | [diff] [blame] | 291 | |
Paolo Bonzini | 8c444a1 | 2013-04-18 18:43:57 +0200 | [diff] [blame] | 292 | if (glob_adlib) { |
Andreas Färber | db895a1 | 2012-11-25 02:37:14 +0100 | [diff] [blame] | 293 | error_setg (errp, "Cannot create more than 1 adlib device"); |
| 294 | return; |
Paolo Bonzini | 8c444a1 | 2013-04-18 18:43:57 +0200 | [diff] [blame] | 295 | } |
| 296 | glob_adlib = s; |
| 297 | |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 298 | #ifdef HAS_YMF262 |
Paolo Bonzini | 8c444a1 | 2013-04-18 18:43:57 +0200 | [diff] [blame] | 299 | if (YMF262Init (1, 14318180, s->freq)) { |
Andreas Färber | db895a1 | 2012-11-25 02:37:14 +0100 | [diff] [blame] | 300 | error_setg (errp, "YMF262Init %d failed", s->freq); |
| 301 | return; |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 302 | } |
| 303 | else { |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 304 | YMF262SetTimerHandler (0, timer_handler, 0); |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 305 | s->enabled = 1; |
| 306 | } |
| 307 | #else |
Paolo Bonzini | 8c444a1 | 2013-04-18 18:43:57 +0200 | [diff] [blame] | 308 | s->opl = OPLCreate (OPL_TYPE_YM3812, 3579545, s->freq); |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 309 | if (!s->opl) { |
Andreas Färber | db895a1 | 2012-11-25 02:37:14 +0100 | [diff] [blame] | 310 | error_setg (errp, "OPLCreate %d failed", s->freq); |
| 311 | return; |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 312 | } |
| 313 | else { |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 314 | OPLSetTimerHandler (s->opl, timer_handler, 0); |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 315 | s->enabled = 1; |
| 316 | } |
| 317 | #endif |
| 318 | |
Paolo Bonzini | 8c444a1 | 2013-04-18 18:43:57 +0200 | [diff] [blame] | 319 | as.freq = s->freq; |
bellard | c0fe382 | 2005-11-05 18:55:28 +0000 | [diff] [blame] | 320 | as.nchannels = SHIFT; |
| 321 | as.fmt = AUD_FMT_S16; |
bellard | d929eba | 2006-07-04 21:47:22 +0000 | [diff] [blame] | 322 | as.endianness = AUDIO_HOST_ENDIANNESS; |
bellard | c0fe382 | 2005-11-05 18:55:28 +0000 | [diff] [blame] | 323 | |
malc | 1a7dafc | 2009-05-14 03:11:35 +0400 | [diff] [blame] | 324 | AUD_register_card ("adlib", &s->card); |
bellard | c0fe382 | 2005-11-05 18:55:28 +0000 | [diff] [blame] | 325 | |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 326 | s->voice = AUD_open_out ( |
bellard | c0fe382 | 2005-11-05 18:55:28 +0000 | [diff] [blame] | 327 | &s->card, |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 328 | s->voice, |
| 329 | "adlib", |
| 330 | s, |
| 331 | adlib_callback, |
bellard | d929eba | 2006-07-04 21:47:22 +0000 | [diff] [blame] | 332 | &as |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 333 | ); |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 334 | if (!s->voice) { |
| 335 | Adlib_fini (s); |
Andreas Färber | db895a1 | 2012-11-25 02:37:14 +0100 | [diff] [blame] | 336 | error_setg (errp, "Initializing audio voice failed"); |
| 337 | return; |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 338 | } |
| 339 | |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 340 | s->samples = AUD_get_buffer_size_out (s->voice) >> SHIFT; |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 341 | s->mixbuf = g_malloc0 (s->samples << SHIFT); |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 342 | |
Paolo Bonzini | 7f0ba7b | 2013-12-02 10:16:18 +0100 | [diff] [blame] | 343 | adlib_portio_list[0].offset = s->port; |
| 344 | adlib_portio_list[1].offset = s->port + 8; |
Kirill Batuzov | 848696b | 2014-04-29 17:38:39 +0400 | [diff] [blame] | 345 | portio_list_init (&s->port_list, OBJECT(s), adlib_portio_list, s, "adlib"); |
| 346 | portio_list_add (&s->port_list, isa_address_space_io(&s->parent_obj), 0); |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 347 | } |
Paolo Bonzini | 8c444a1 | 2013-04-18 18:43:57 +0200 | [diff] [blame] | 348 | |
| 349 | static Property adlib_properties[] = { |
Paolo Bonzini | c7bcc85 | 2014-02-08 11:01:53 +0100 | [diff] [blame] | 350 | DEFINE_PROP_UINT32 ("iobase", AdlibState, port, 0x220), |
Paolo Bonzini | 8c444a1 | 2013-04-18 18:43:57 +0200 | [diff] [blame] | 351 | DEFINE_PROP_UINT32 ("freq", AdlibState, freq, 44100), |
| 352 | DEFINE_PROP_END_OF_LIST (), |
| 353 | }; |
| 354 | |
| 355 | static void adlib_class_initfn (ObjectClass *klass, void *data) |
| 356 | { |
| 357 | DeviceClass *dc = DEVICE_CLASS (klass); |
Andreas Färber | db895a1 | 2012-11-25 02:37:14 +0100 | [diff] [blame] | 358 | |
| 359 | dc->realize = adlib_realizefn; |
Marcel Apfelbaum | 125ee0e | 2013-07-29 17:17:45 +0300 | [diff] [blame] | 360 | set_bit(DEVICE_CATEGORY_SOUND, dc->categories); |
Paolo Bonzini | 8c444a1 | 2013-04-18 18:43:57 +0200 | [diff] [blame] | 361 | dc->desc = ADLIB_DESC; |
| 362 | dc->props = adlib_properties; |
| 363 | } |
| 364 | |
| 365 | static const TypeInfo adlib_info = { |
| 366 | .name = TYPE_ADLIB, |
| 367 | .parent = TYPE_ISA_DEVICE, |
| 368 | .instance_size = sizeof (AdlibState), |
| 369 | .class_init = adlib_class_initfn, |
| 370 | }; |
| 371 | |
Paolo Bonzini | 36cd6f6 | 2013-04-18 18:43:58 +0200 | [diff] [blame] | 372 | static int Adlib_init (ISABus *bus) |
Paolo Bonzini | 8c444a1 | 2013-04-18 18:43:57 +0200 | [diff] [blame] | 373 | { |
| 374 | isa_create_simple (bus, TYPE_ADLIB); |
| 375 | return 0; |
| 376 | } |
| 377 | |
| 378 | static void adlib_register_types (void) |
| 379 | { |
| 380 | type_register_static (&adlib_info); |
Paolo Bonzini | 36cd6f6 | 2013-04-18 18:43:58 +0200 | [diff] [blame] | 381 | isa_register_soundhw("adlib", ADLIB_DESC, Adlib_init); |
Paolo Bonzini | 8c444a1 | 2013-04-18 18:43:57 +0200 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | type_init (adlib_register_types) |