#include typedef unsigned char byte; #define WAIT( port, flag ) while ( (inp(port)&flag) != 0 ) #define COMDPORT 0x331 /* MPU-401 Command Port on IBM */ #define STATPORT 0x331 /* MPU-401 Status Port on IBM */ #define DATAPORT 0x330 /* MPU-401 Data I/O Port on IBM */ #define DRR 0x40 /* Mask for Data Read Reg. Bit */ #define DSR 0x80 /* Mask for Data Set Ready Bit */ #define ACK 0xFE /* MPU-401 Acknowledge Response */ #define MASKFLIP 0xFF /* WAIT Function Bit Mask XOR */ #define MPURESET 0xFF /* MPU-401 Total Reset Command */ #define UARTMODE 0x3F /* MPU-401 "Dumb UART Mode" */ #define NOTEON1 0x90 /* MIDI Note On for Channel 1 */ #define VELOCITY 64 /* MIDI Medium Key Velocity */ #define NOTEOFF 0 /* 0 Velocity = Note Off */ #define FIRSTNOTE 36 /* First note synth can play */ #define LASTNOTE 96 /* Last note synth can play */ /*************************************************************************** * I N I T I A L I Z A T I O N * ***************************************************************************/ RstMPU() { int a; /* Clear Display */ outp( COMDPORT, MPURESET ); /* Send MPU-401 RESET Command */ a = inp( DATAPORT ); /* Dummy read to clear buffer */ WAIT( STATPORT, DRR ); /* wait for port ready */ outp( COMDPORT, UARTMODE ); /* Set MPU-401 "Dumb UART" Mode */ a = inp(DATAPORT); /* Dummy Read to clear buffer */ WAIT( STATPORT, DSR ); /* Wait for "UART" port ready - */ printf ("Interface init\n"); /* Really crucial! */ } /*************************************************************************** * M A I N P R O G R A M * ***************************************************************************/ snd (i) int i; { int a; outp (DATAPORT, i); a=inp(DATAPORT); /* dummy read */ WAIT (STATPORT, DRR); printf ("0x%02x\b\b\b\b", i); } main(argc, argv) int argc; char *argv[]; { FILE *fp; int i; int cksum; int ch; RstMPU(); if (argc != 2) { printf ("Usage: dload \n"); exit(-1); } printf ("Download %s...", argv[1]); if ((fp = fopen(argv[1], "rb")) == NULL) { printf ("cannot open\n"); exit(-1); } cksum = 0; ch = fgetc(fp); while ((ch & 0xff)!=0xf7) { snd (ch); cksum++; ch = fgetc(fp); } snd ((int)0xF7); cksum++; printf ("\n Done - sent %d bytes\n", cksum); }