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