4 * The low level driver for the GUS Midi Interface.
6 * Copyright by Hannu Savolainen 1993
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
10 * met: 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 2.
12 * Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
20 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * $DragonFly: src/sys/dev/sound/isa/i386/gus/Attic/gus_midi.c,v 1.2 2003/08/07 21:17:12 dillon Exp $
31 #include <i386/isa/sound/sound_config.h>
33 #if defined(CONFIG_GUS) && defined(CONFIG_MIDI)
36 static int midi_busy = 0, input_opened = 0;
38 static int output_used = 0;
39 static volatile unsigned char gus_midi_control;
41 static void (*midi_input_intr) (int dev, unsigned char data);
43 static unsigned char tmp_queue[256];
44 static volatile int qlen;
45 static volatile unsigned char qhead, qtail;
46 extern int gus_base, gus_irq, gus_dma;
47 extern sound_os_info *gus_osp;
49 #define GUS_MIDI_STATUS() inb( u_MidiStatus)
52 gus_midi_open(int dev, int mode,
53 void (*input) (int dev, unsigned char data),
54 void (*output) (int dev)
59 printf("GUS: Midi busy\n");
62 outb(u_MidiControl, MIDI_RESET);
68 if (mode == OPEN_READ || mode == OPEN_READWRITE) {
69 gus_midi_control |= MIDI_ENABLE_RCV;
72 if (mode == OPEN_WRITE || mode == OPEN_READWRITE) {
73 gus_midi_control |= MIDI_ENABLE_XMIT;
75 outb(u_MidiControl, gus_midi_control); /* Enable */
78 qlen = qhead = qtail = output_used = 0;
79 midi_input_intr = input;
85 dump_to_midi(unsigned char midi_byte)
94 if (GUS_MIDI_STATUS() & MIDI_XMIT_EMPTY) {
96 outb(u_MidiData, midi_byte);
99 * Enable Midi xmit interrupts (again)
101 gus_midi_control |= MIDI_ENABLE_XMIT;
102 outb(u_MidiControl, gus_midi_control);
110 gus_midi_close(int dev)
113 * Reset FIFO pointers, disable intrs
116 outb(u_MidiControl, MIDI_RESET);
121 gus_midi_out(int dev, unsigned char midi_byte)
127 * Drain the local queue first
132 while (qlen && dump_to_midi(tmp_queue[qhead])) {
140 * Output the byte if the local queue is empty.
144 if (dump_to_midi(midi_byte))
148 * Put to the local queue
152 return 0; /* Local queue full */
156 tmp_queue[qtail] = midi_byte;
166 gus_midi_start_read(int dev)
172 gus_midi_end_read(int dev)
178 gus_midi_ioctl(int dev, unsigned cmd, ioctl_arg arg)
184 gus_midi_kick(int dev)
189 gus_midi_buffer_status(int dev)
198 if (qlen && dump_to_midi(tmp_queue[qhead])) {
204 return (qlen > 0) | !(GUS_MIDI_STATUS() & MIDI_XMIT_EMPTY);
207 #define MIDI_SYNTH_NAME "Gravis Ultrasound Midi"
208 #define MIDI_SYNTH_CAPS SYNTH_CAP_INPUT
209 #include <i386/isa/sound/midi_synth.h>
211 static struct midi_operations gus_midi_operations =
213 {"Gravis UltraSound Midi", 0, 0, SNDCARD_GUS},
224 gus_midi_buffer_status,
231 if (num_midis >= MAX_MIDI_DEV) {
232 printf("Sound: Too many midi devices detected\n");
235 outb(u_MidiControl, MIDI_RESET);
237 std_midi_synth.midi_dev = my_dev = num_midis;
238 midi_devs[num_midis++] = &gus_midi_operations;
243 gus_midi_interrupt(int dummy)
245 unsigned char stat, data;
250 stat = GUS_MIDI_STATUS();
252 if (stat & MIDI_RCV_FULL) {
253 data = inb(u_MidiData);
255 midi_input_intr(my_dev, data);
257 if (stat & MIDI_XMIT_EMPTY) {
258 while (qlen && dump_to_midi(tmp_queue[qhead])) {
265 * Disable Midi output interrupts, since no data in
268 gus_midi_control &= ~MIDI_ENABLE_XMIT;
269 outb(u_MidiControl, gus_midi_control);