4 static int iobase = 0x330;
6 #define MPU_PORT_DATA iobase
7 #define MPU_PORT_STAT (iobase | 1)
8 #define MPU_PORT_CMD (iobase | 1)
10 #define MPU_STAT_ORDY 0x40
11 #define MPU_STAT_IRDY 0x80
14 #define MPU_CMD_RESET 0xff
15 #define MPU_CMD_UARTMODE 0x3f
17 #define MIDI_CMD_NOTEON 0x90
18 #define MIDI_CMD_NOTEOFF 0x80
19 #define MIDI_CMD_CHANMSG 0xb0
20 #define MIDI_CMD_CHPROG 0xc0
22 #define MIDI_CHANMSG_NOTESOFF 0x7b
24 int midi_init(int port)
28 if(midi_send_cmd(MPU_CMD_RESET) == -1) {
31 if(midi_send_cmd(MPU_CMD_UARTMODE) == -1) {
38 void midi_shutdown(void)
41 midi_send_cmd(MPU_CMD_RESET);
44 void midi_note(int chan, int note, int vel)
47 midi_send_data(MIDI_CMD_NOTEON | chan);
49 midi_send_data(MIDI_CMD_NOTEOFF | chan);
55 void midi_chprog(int chan, int prog)
57 midi_send_data(MIDI_CMD_CHPROG | chan);
61 void midi_alloff(void)
63 midi_send_data(MIDI_CMD_CHANMSG);
64 midi_send_data(MIDI_CHANMSG_NOTESOFF);
67 static int wait_ordy(void)
70 for(i=0; i<1024; i++) {
71 if((inp(MPU_PORT_STAT) & MPU_STAT_ORDY) == 0) {
78 int midi_send_cmd(int cmd)
80 if(wait_ordy() == -1) {
83 outp(MPU_PORT_CMD, cmd);
87 int midi_send_data(int data)
89 if(wait_ordy() == -1) {
92 outp(MPU_PORT_DATA, data);