3 * \ \ \L\ \\//\ \ \//\ \ __ __ _ __ ___
4 * \ \ __ \ \ \ \ \ \ \ /'__`\ /'_ `\/\`'__\/ __`\
5 * \ \ \/\ \ \_\ \_ \_\ \_/\ __//\ \L\ \ \ \//\ \L\ \
6 * \ \_\ \_\/\____\/\____\ \____\ \____ \ \_\\ \____/
7 * \/_/\/_/\/____/\/____/\/____/\/___L\ \/_/ \/___/
10 * By Shawn Hargreaves,
16 * Direct output to an MPU-401 MIDI interface.
18 * Marcel de Kogel fixed my original broken version, so that it now
21 * See readme.txt for copyright information.
26 #error This file should only be used by the djgpp version of Allegro
37 /* external interface to the MPU-401 driver */
38 static int mpu_detect();
39 static int mpu_init(int voices);
40 static void mpu_exit();
41 static void mpu_output(unsigned char data);
43 static char mpu_desc[80] = "not initialised";
46 MIDI_DRIVER midi_mpu401 =
50 0, 0, 0xFFFF, 0, -1, -1,
57 _dummy_adjust_patches,
69 * Waits for the specified bit to clear on the specified port. Returns zero
70 * if it cleared, -1 if it timed out.
72 static inline int wait_for_mpu(int flag, int port)
76 for (timeout=0; timeout<0x7FFF; timeout++)
77 if (!(inportb(port) & flag))
86 * Writes a byte to the MPU-401 midi interface.
88 static void mpu_output(unsigned char data)
90 outportb(_mpu_port, data);
92 wait_for_mpu(0x40, _mpu_port+1);
95 static END_OF_FUNCTION(mpu_output);
100 * Detects the presence of an MPU-401 compatible midi interface.
102 static int mpu_detect()
104 char *blaster = getenv("BLASTER");
106 /* parse BLASTER env */
107 if ((blaster) && (_mpu_port < 0)) {
109 while ((*blaster == ' ') || (*blaster == '\t'))
112 if ((*blaster == 'p') || (*blaster == 'P'))
113 _mpu_port = strtol(blaster+1, NULL, 16);
115 while ((*blaster) && (*blaster != ' ') && (*blaster != '\t'))
120 /* if that didn't work, guess :-) */
124 /* check whether the MPU is there */
125 outportb(_mpu_port+1,0xFF); /* reset the mpu */
127 if (wait_for_mpu(0x40, _mpu_port+1) != 0) { /* wait for ready */
128 strcpy(allegro_error, "MPU-401 not found");
132 sprintf(mpu_desc, "MPU-401 MIDI interface on port %d", _mpu_port);
139 * Initialises the MPU-401 midi interface.
141 static int mpu_init(int voices)
143 outportb(_mpu_port+1, 0x3F); /* put MPU in UART mode */
145 wait_for_mpu (0x80,_mpu_port+1);
147 LOCK_VARIABLE(midi_mpu401);
148 LOCK_VARIABLE(_mpu_port);
149 LOCK_FUNCTION(mpu_output);
157 * Resets the MPU-401 midi interface when we are finished.
159 static void mpu_exit()
161 outportb(_mpu_port+1, 0xFF);