#include typedef unsigned char byte; int header[7] = {0xf0, 0x40, 0x00, 0x20, 0x00, 0x04, 0x00}; int request[7] = {0xf0, 0x40, 0x00, 0x00, 0x00, 0x04, 0x00}; int head; #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 - */ /* 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); WAIT(STATPORT, DRR); } int rcv() { int a; int i; loop: WAIT (STATPORT, DSR); i=inp (DATAPORT); if (head && ((byte)i==(byte)0xfe)) goto loop; return (i); } main(argc, argv) int argc; char *argv[]; { FILE *fp; int i; int cksum; int patch; int ch, j; char name[10]; char letter; RstMPU(); if (argc != 3) { printf ("Usage: get \n"); exit(-1); } sscanf (argv[1], "%c%d", &letter, &patch); patch = patch + (letter - 'a')*16 - 1; printf ("Uploading patch %s(%d) to %s...", argv[1], patch, argv[2]); if ((fp = fopen(argv[2], "wb")) == NULL) { printf ("Cannot open %s for writing\n", argv[2]); exit(-1); } for (i=0; i<7; i++) snd (request[i]); snd (patch); snd (0xf7); head = 1; cksum = 0; for (i=0; i<7; i++) { if ((j=rcv()) != (header[i])) printf ("yikes - 0x%x expected, got 0x%x\n", header[i], j); fputc (j, fp); cksum++; } head = 0; i = 0; ch=rcv(); while ((ch & 0xff) != 0xf7) { cksum++; fputc(ch, fp); ch=rcv(); if (i<10) name[i] = ch; i++; } name[10] = 0; if ((byte)ch != (byte)0xf7) printf ("Bum\n"); fputc (ch, fp); cksum++; printf ("\n Done - uploaded %s - received %d bytes\n", name, cksum); fclose (fp); }