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 | |
Peter Maydell | 6086a56 | 2016-01-18 17:33:52 +0000 | [diff] [blame] | 25 | #include "qemu/osdep.h" |
Markus Armbruster | da34e65 | 2016-03-14 09:01:28 +0100 | [diff] [blame] | 26 | #include "qapi/error.h" |
Markus Armbruster | 0b8fa32 | 2019-05-23 16:35:07 +0200 | [diff] [blame] | 27 | #include "qemu/module.h" |
Eduardo Habkost | 8a824e4 | 2017-05-08 17:57:35 -0300 | [diff] [blame] | 28 | #include "hw/audio/soundhw.h" |
ths | e140e05 | 2007-12-02 17:17:45 +0000 | [diff] [blame] | 29 | #include "audio/audio.h" |
Paolo Bonzini | 0d09e41 | 2013-02-05 17:06:20 +0100 | [diff] [blame] | 30 | #include "hw/isa/isa.h" |
Markus Armbruster | a27bd6c | 2019-08-12 07:23:51 +0200 | [diff] [blame] | 31 | #include "hw/qdev-properties.h" |
Eduardo Habkost | db1015e | 2020-09-03 16:43:22 -0400 | [diff] [blame] | 32 | #include "qom/object.h" |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 33 | |
ths | 9f0683d | 2007-12-02 17:47:33 +0000 | [diff] [blame] | 34 | //#define DEBUG |
| 35 | |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 36 | #define ADLIB_KILL_TIMERS 1 |
| 37 | |
Paolo Bonzini | 8c444a1 | 2013-04-18 18:43:57 +0200 | [diff] [blame] | 38 | #define ADLIB_DESC "Yamaha YM3812 (OPL2)" |
Paolo Bonzini | 8c444a1 | 2013-04-18 18:43:57 +0200 | [diff] [blame] | 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 | |
Paolo Bonzini | 47b43a1 | 2013-03-18 17:36:02 +0100 | [diff] [blame] | 51 | #include "fmopl.h" |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 52 | #define SHIFT 1 |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 53 | |
Paolo Bonzini | 8c444a1 | 2013-04-18 18:43:57 +0200 | [diff] [blame] | 54 | #define TYPE_ADLIB "adlib" |
Eduardo Habkost | 8063396 | 2020-09-16 14:25:19 -0400 | [diff] [blame] | 55 | OBJECT_DECLARE_SIMPLE_TYPE(AdlibState, ADLIB) |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 56 | |
Eduardo Habkost | db1015e | 2020-09-03 16:43:22 -0400 | [diff] [blame] | 57 | struct AdlibState { |
Paolo Bonzini | 8c444a1 | 2013-04-18 18:43:57 +0200 | [diff] [blame] | 58 | ISADevice parent_obj; |
| 59 | |
bellard | c0fe382 | 2005-11-05 18:55:28 +0000 | [diff] [blame] | 60 | QEMUSoundCard card; |
Paolo Bonzini | 8c444a1 | 2013-04-18 18:43:57 +0200 | [diff] [blame] | 61 | uint32_t freq; |
| 62 | uint32_t port; |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 63 | int ticking[2]; |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 64 | int enabled; |
| 65 | int active; |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 66 | int bufpos; |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 67 | #ifdef DEBUG |
| 68 | int64_t exp[2]; |
| 69 | #endif |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 70 | int16_t *mixbuf; |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 71 | uint64_t dexp[2]; |
| 72 | SWVoiceOut *voice; |
| 73 | int left, pos, samples; |
| 74 | QEMUAudioTimeStamp ats; |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 75 | FM_OPL *opl; |
Kirill Batuzov | 848696b | 2014-04-29 17:38:39 +0400 | [diff] [blame] | 76 | PortioList port_list; |
Eduardo Habkost | db1015e | 2020-09-03 16:43:22 -0400 | [diff] [blame] | 77 | }; |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 78 | |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 79 | static void adlib_stop_opl_timer (AdlibState *s, size_t n) |
| 80 | { |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 81 | OPLTimerOver (s->opl, n); |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 82 | s->ticking[n] = 0; |
| 83 | } |
| 84 | |
| 85 | static void adlib_kill_timers (AdlibState *s) |
| 86 | { |
| 87 | size_t i; |
| 88 | |
| 89 | for (i = 0; i < 2; ++i) { |
| 90 | if (s->ticking[i]) { |
| 91 | uint64_t delta; |
| 92 | |
bellard | c0fe382 | 2005-11-05 18:55:28 +0000 | [diff] [blame] | 93 | delta = AUD_get_elapsed_usec_out (s->voice, &s->ats); |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 94 | ldebug ( |
| 95 | "delta = %f dexp = %f expired => %d\n", |
| 96 | delta / 1000000.0, |
| 97 | s->dexp[i] / 1000000.0, |
| 98 | delta >= s->dexp[i] |
| 99 | ); |
| 100 | if (ADLIB_KILL_TIMERS || delta >= s->dexp[i]) { |
| 101 | adlib_stop_opl_timer (s, i); |
| 102 | AUD_init_time_stamp_out (s->voice, &s->ats); |
| 103 | } |
| 104 | } |
| 105 | } |
| 106 | } |
| 107 | |
Nutan Shinde | 8307c29 | 2015-10-07 22:02:54 +0530 | [diff] [blame] | 108 | static void adlib_write(void *opaque, uint32_t nport, uint32_t val) |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 109 | { |
| 110 | AdlibState *s = opaque; |
| 111 | int a = nport & 3; |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 112 | |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 113 | s->active = 1; |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 114 | AUD_set_active_out (s->voice, 1); |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 115 | |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 116 | adlib_kill_timers (s); |
| 117 | |
Hervé Poussineau | e8beeae | 2011-09-18 16:27:23 +0200 | [diff] [blame] | 118 | OPLWrite (s->opl, a, val); |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 119 | } |
| 120 | |
Nutan Shinde | 8307c29 | 2015-10-07 22:02:54 +0530 | [diff] [blame] | 121 | static uint32_t adlib_read(void *opaque, uint32_t nport) |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 122 | { |
| 123 | AdlibState *s = opaque; |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 124 | int a = nport & 3; |
| 125 | |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 126 | adlib_kill_timers (s); |
Simran Singhal | b3ac2b9 | 2020-04-01 22:23:14 +0530 | [diff] [blame] | 127 | return OPLRead (s->opl, a); |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 128 | } |
| 129 | |
Hervé Poussineau | c57fbf5 | 2017-06-21 06:34:00 +0200 | [diff] [blame] | 130 | static void timer_handler (void *opaque, int c, double interval_Sec) |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 131 | { |
Hervé Poussineau | 639b49e | 2017-06-21 06:34:01 +0200 | [diff] [blame] | 132 | AdlibState *s = opaque; |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 133 | unsigned n = c & 1; |
| 134 | #ifdef DEBUG |
| 135 | double interval; |
bellard | c0fe382 | 2005-11-05 18:55:28 +0000 | [diff] [blame] | 136 | int64_t exp; |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 137 | #endif |
| 138 | |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 139 | if (interval_Sec == 0.0) { |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 140 | s->ticking[n] = 0; |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 141 | return; |
| 142 | } |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 143 | |
| 144 | s->ticking[n] = 1; |
| 145 | #ifdef DEBUG |
Rutuja Shah | 73bcb24 | 2016-03-21 21:32:30 +0530 | [diff] [blame] | 146 | interval = NANOSECONDS_PER_SECOND * interval_Sec; |
Alex Bligh | bc72ad6 | 2013-08-21 16:03:08 +0100 | [diff] [blame] | 147 | exp = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + interval; |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 148 | s->exp[n] = exp; |
| 149 | #endif |
| 150 | |
| 151 | s->dexp[n] = interval_Sec * 1000000.0; |
| 152 | AUD_init_time_stamp_out (s->voice, &s->ats); |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | static int write_audio (AdlibState *s, int samples) |
| 156 | { |
| 157 | int net = 0; |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 158 | int pos = s->pos; |
| 159 | |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 160 | while (samples) { |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 161 | int nbytes, wbytes, wsampl; |
| 162 | |
| 163 | nbytes = samples << SHIFT; |
| 164 | wbytes = AUD_write ( |
| 165 | s->voice, |
| 166 | s->mixbuf + (pos << (SHIFT - 1)), |
| 167 | nbytes |
| 168 | ); |
| 169 | |
| 170 | if (wbytes) { |
| 171 | wsampl = wbytes >> SHIFT; |
| 172 | |
| 173 | samples -= wsampl; |
| 174 | pos = (pos + wsampl) % s->samples; |
| 175 | |
| 176 | net += wsampl; |
| 177 | } |
| 178 | else { |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 179 | break; |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 180 | } |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 181 | } |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 182 | |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 183 | return net; |
| 184 | } |
| 185 | |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 186 | static void adlib_callback (void *opaque, int free) |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 187 | { |
| 188 | AdlibState *s = opaque; |
Richard Henderson | 79fe9e4 | 2021-07-12 19:57:41 +0000 | [diff] [blame] | 189 | int samples, to_play, written; |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 190 | |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 191 | samples = free >> SHIFT; |
| 192 | if (!(s->active && s->enabled) || !samples) { |
| 193 | return; |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 194 | } |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 195 | |
Kővágó, Zoltán | 5893591 | 2019-08-19 01:06:54 +0200 | [diff] [blame] | 196 | to_play = MIN (s->left, samples); |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 197 | while (to_play) { |
| 198 | written = write_audio (s, to_play); |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 199 | |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 200 | if (written) { |
| 201 | s->left -= written; |
| 202 | samples -= written; |
| 203 | to_play -= written; |
| 204 | s->pos = (s->pos + written) % s->samples; |
| 205 | } |
| 206 | else { |
| 207 | return; |
| 208 | } |
| 209 | } |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 210 | |
Kővágó, Zoltán | 5893591 | 2019-08-19 01:06:54 +0200 | [diff] [blame] | 211 | samples = MIN (samples, s->samples - s->pos); |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 212 | if (!samples) { |
| 213 | return; |
| 214 | } |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 215 | |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 216 | YM3812UpdateOne (s->opl, s->mixbuf + s->pos, samples); |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 217 | |
| 218 | while (samples) { |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 219 | written = write_audio (s, samples); |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 220 | |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 221 | if (written) { |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 222 | samples -= written; |
| 223 | s->pos = (s->pos + written) % s->samples; |
| 224 | } |
| 225 | else { |
| 226 | s->left = samples; |
| 227 | return; |
| 228 | } |
| 229 | } |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | static void Adlib_fini (AdlibState *s) |
| 233 | { |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 234 | if (s->opl) { |
| 235 | OPLDestroy (s->opl); |
| 236 | s->opl = NULL; |
| 237 | } |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 238 | |
Markus Armbruster | fb7da62 | 2014-06-06 18:35:13 +0200 | [diff] [blame] | 239 | g_free(s->mixbuf); |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 240 | |
| 241 | s->active = 0; |
| 242 | s->enabled = 0; |
bellard | c0fe382 | 2005-11-05 18:55:28 +0000 | [diff] [blame] | 243 | AUD_remove_card (&s->card); |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 244 | } |
| 245 | |
Jan Kiszka | a8aec29 | 2013-06-22 08:06:54 +0200 | [diff] [blame] | 246 | static MemoryRegionPortio adlib_portio_list[] = { |
Jan Kiszka | a8aec29 | 2013-06-22 08:06:54 +0200 | [diff] [blame] | 247 | { 0, 4, 1, .read = adlib_read, .write = adlib_write, }, |
| 248 | { 0, 2, 1, .read = adlib_read, .write = adlib_write, }, |
Hervé Poussineau | 2b21fb5 | 2013-08-14 11:49:04 +0200 | [diff] [blame] | 249 | { 0x388, 4, 1, .read = adlib_read, .write = adlib_write, }, |
Jan Kiszka | a8aec29 | 2013-06-22 08:06:54 +0200 | [diff] [blame] | 250 | PORTIO_END_OF_LIST(), |
| 251 | }; |
| 252 | |
Andreas Färber | db895a1 | 2012-11-25 02:37:14 +0100 | [diff] [blame] | 253 | static void adlib_realizefn (DeviceState *dev, Error **errp) |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 254 | { |
Paolo Bonzini | 8c444a1 | 2013-04-18 18:43:57 +0200 | [diff] [blame] | 255 | AdlibState *s = ADLIB(dev); |
malc | 1ea879e | 2008-12-03 22:48:44 +0000 | [diff] [blame] | 256 | struct audsettings as; |
bellard | c0fe382 | 2005-11-05 18:55:28 +0000 | [diff] [blame] | 257 | |
Juan Quintela | 8f7e2c2 | 2017-04-26 00:37:26 +0200 | [diff] [blame] | 258 | s->opl = OPLCreate (3579545, s->freq); |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 259 | if (!s->opl) { |
Andreas Färber | db895a1 | 2012-11-25 02:37:14 +0100 | [diff] [blame] | 260 | error_setg (errp, "OPLCreate %d failed", s->freq); |
| 261 | return; |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 262 | } |
| 263 | else { |
Hervé Poussineau | 639b49e | 2017-06-21 06:34:01 +0200 | [diff] [blame] | 264 | OPLSetTimerHandler(s->opl, timer_handler, s); |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 265 | s->enabled = 1; |
| 266 | } |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 267 | |
Paolo Bonzini | 8c444a1 | 2013-04-18 18:43:57 +0200 | [diff] [blame] | 268 | as.freq = s->freq; |
bellard | c0fe382 | 2005-11-05 18:55:28 +0000 | [diff] [blame] | 269 | as.nchannels = SHIFT; |
Kővágó, Zoltán | 85bc585 | 2019-03-08 23:34:13 +0100 | [diff] [blame] | 270 | as.fmt = AUDIO_FORMAT_S16; |
bellard | d929eba | 2006-07-04 21:47:22 +0000 | [diff] [blame] | 271 | as.endianness = AUDIO_HOST_ENDIANNESS; |
bellard | c0fe382 | 2005-11-05 18:55:28 +0000 | [diff] [blame] | 272 | |
malc | 1a7dafc | 2009-05-14 03:11:35 +0400 | [diff] [blame] | 273 | AUD_register_card ("adlib", &s->card); |
bellard | c0fe382 | 2005-11-05 18:55:28 +0000 | [diff] [blame] | 274 | |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 275 | s->voice = AUD_open_out ( |
bellard | c0fe382 | 2005-11-05 18:55:28 +0000 | [diff] [blame] | 276 | &s->card, |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 277 | s->voice, |
| 278 | "adlib", |
| 279 | s, |
| 280 | adlib_callback, |
bellard | d929eba | 2006-07-04 21:47:22 +0000 | [diff] [blame] | 281 | &as |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 282 | ); |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 283 | if (!s->voice) { |
| 284 | Adlib_fini (s); |
Andreas Färber | db895a1 | 2012-11-25 02:37:14 +0100 | [diff] [blame] | 285 | error_setg (errp, "Initializing audio voice failed"); |
| 286 | return; |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 287 | } |
| 288 | |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 289 | s->samples = AUD_get_buffer_size_out (s->voice) >> SHIFT; |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 290 | s->mixbuf = g_malloc0 (s->samples << SHIFT); |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 291 | |
Paolo Bonzini | 7f0ba7b | 2013-12-02 10:16:18 +0100 | [diff] [blame] | 292 | adlib_portio_list[0].offset = s->port; |
| 293 | adlib_portio_list[1].offset = s->port + 8; |
Kirill Batuzov | 848696b | 2014-04-29 17:38:39 +0400 | [diff] [blame] | 294 | portio_list_init (&s->port_list, OBJECT(s), adlib_portio_list, s, "adlib"); |
| 295 | 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] | 296 | } |
Paolo Bonzini | 8c444a1 | 2013-04-18 18:43:57 +0200 | [diff] [blame] | 297 | |
| 298 | static Property adlib_properties[] = { |
Kővágó, Zoltán | 88e47b9 | 2019-08-19 01:06:49 +0200 | [diff] [blame] | 299 | DEFINE_AUDIO_PROPERTIES(AdlibState, card), |
Paolo Bonzini | c7bcc85 | 2014-02-08 11:01:53 +0100 | [diff] [blame] | 300 | DEFINE_PROP_UINT32 ("iobase", AdlibState, port, 0x220), |
Paolo Bonzini | 8c444a1 | 2013-04-18 18:43:57 +0200 | [diff] [blame] | 301 | DEFINE_PROP_UINT32 ("freq", AdlibState, freq, 44100), |
| 302 | DEFINE_PROP_END_OF_LIST (), |
| 303 | }; |
| 304 | |
| 305 | static void adlib_class_initfn (ObjectClass *klass, void *data) |
| 306 | { |
| 307 | DeviceClass *dc = DEVICE_CLASS (klass); |
Andreas Färber | db895a1 | 2012-11-25 02:37:14 +0100 | [diff] [blame] | 308 | |
| 309 | dc->realize = adlib_realizefn; |
Marcel Apfelbaum | 125ee0e | 2013-07-29 17:17:45 +0300 | [diff] [blame] | 310 | set_bit(DEVICE_CATEGORY_SOUND, dc->categories); |
Paolo Bonzini | 8c444a1 | 2013-04-18 18:43:57 +0200 | [diff] [blame] | 311 | dc->desc = ADLIB_DESC; |
Marc-André Lureau | 4f67d30 | 2020-01-10 19:30:32 +0400 | [diff] [blame] | 312 | device_class_set_props(dc, adlib_properties); |
Paolo Bonzini | 8c444a1 | 2013-04-18 18:43:57 +0200 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | static const TypeInfo adlib_info = { |
| 316 | .name = TYPE_ADLIB, |
| 317 | .parent = TYPE_ISA_DEVICE, |
| 318 | .instance_size = sizeof (AdlibState), |
| 319 | .class_init = adlib_class_initfn, |
| 320 | }; |
| 321 | |
Paolo Bonzini | 8c444a1 | 2013-04-18 18:43:57 +0200 | [diff] [blame] | 322 | static void adlib_register_types (void) |
| 323 | { |
| 324 | type_register_static (&adlib_info); |
Gerd Hoffmann | 86388a3 | 2020-07-02 15:25:11 +0200 | [diff] [blame] | 325 | deprecated_register_soundhw("adlib", ADLIB_DESC, 1, TYPE_ADLIB); |
Paolo Bonzini | 8c444a1 | 2013-04-18 18:43:57 +0200 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | type_init (adlib_register_types) |