[rec.music.synth] How to download DX7 patches from 'uscd.edu' ????

aesop@milton.acs.washington.edu (Jeff Boscole) (05/28/90)

-------------
We have downloaded the patches from  ucsd.edu  , presumably for the DX7.
The README file present at that 'ftp' site mentions that they can't
be loaded via the Personal Composer librarian, because the headers have
been "stripped off."   We sent mail to the fellow mentioned in the README
file who had made this comment, but have received no reply.  

I therefore pose the question to the net:   How might we try out these
patches?  How might we add the correct headers and download them to the DX7
with the Personal Composer librarian?  Alternatively, are there other
loaders, such as the program 'bp' also mentioned in the README documentation,
which might suffice for the task?

None of the other software also available at the  ucsd.edu  site could
manage to help us out in any way.  

What alternative 'ftp' sites for 'midi' software are present? 

Please reply via E-mail, if you can answer any of these questions.  If
your answer is -very- informative, then please also post to the USENET !!!

:=:

barrett@jhunix.HCF.JHU.EDU (Dan Barrett) (06/02/90)

In article <3758@milton.acs.washington.edu> aesop@milton.u.washington.edu (Jeff Boscole) writes:
>-------------
>We have downloaded the patches from  ucsd.edu  , presumably for the DX7.
>The README file present at that 'ftp' site mentions that they can't
>be loaded via the Personal Composer librarian, because the headers have
>been "stripped off."   We sent mail to the fellow mentioned in the README
>file who had made this comment, but have received no reply.  
>
>I therefore pose the question to the net:   How might we try out these
>patches?

	The README file you saw was probably mine, since I submitted those
patches to ucsd.edu.  (I DID NOT MAKE THE PATCHES, NOR DID I COLLECT THEM
ORIGINALLY.)

	In response to your question, I've whipped up a little program
that adds the DX7 system exclusive headers and the checksum back to the
file.  The syntax is (assuming the program is named "addit"):

		addit oldfile newfile

"newfile" gets the contents of "oldfile", plus the headers and checksum.
"oldfile" itself is UNCHANGED.

	I have not tested this program extensively -- I just wrote it 5
minutes ago.  But that's what you get for free.  :-)  You will need to
compile this program on your favorite computer before you can use it.
It is written in C.

	The important information is really contained in the variable
header[] (the 6 missing header bytes) and the function MakeChecksum() that
calculates the checksum.  Any C programmer should be able to take this code
and spruce it up to make it friendlier.

                                                        Dan

 //////////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
| Dan Barrett, Department of Computer Science      Johns Hopkins University |
| INTERNET:   barrett@cs.jhu.edu           |                                |
| COMPUSERVE: >internet:barrett@cs.jhu.edu | UUCP:   barrett@jhunix.UUCP    |
 \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\/////////////////////////////////////


----------------------------------------------------------------------------
----------------------------------------------------------------------------
/* Here's a little program to take a DX7 patch file whose header and checksum
 * have been stripped off, and replace them.
 *
 * This program has NOT been tested extensively and is NOT robust.
 * It works ONLY if the original file size is 4096 bytes.
 * It is specifically written for files in the ucsd.edu DX7 patch archive.
 *
 * You might need to change the "r" and "w" in the fopen() calls in AddIt()
 * to "rb" and "wb" for computers (like the IBM PC) that need special
 * handling for binary vs. text files.
 *
 * Dan Barrett, barrett@cs.jhu.edu, Public Domain.
 *
 * Usage:  addit oldfile newfile
 */

#include <stdio.h>

typedef unsigned char UBYTE;
 
#define DX_FILESIZE	4096L	/* Size of the patch file. */
#define	EOX		0xF7	/* End of system exclusive. */
#define HEADER_SIZE	6	/* Size of system exclusive header. */

UBYTE header[HEADER_SIZE] = { 0xF0, 67, 0, 9, 16, 0 };

UBYTE MakeChecksum();
void AddIt(), Update();

	
main(argc,argv)
int argc; char *argv[];
{
	if (argc != 3)
	{
		fprintf(stderr, "Syntax:  %s oldfile newfile\n", argv[0]);
		exit(1);
	}
	else
		AddIt(argv[1], argv[2]);

	exit(0);
}

	
UBYTE MakeChecksum(patchData)
/* Given your array of patch data, compute and return the checksum. */
UBYTE patchData[];
{
	UBYTE sum;
	int i;

	sum = 0;
	for (i=0; i<DX_FILESIZE; i++)
		sum = (sum + patchData[i]) % (1 << 8);
	return((UBYTE)((1 << 8) - sum));
}


void AddIt(oldfilename, newfilename)
char *oldfilename, *newfilename;
{
	FILE *old, *new;

	if ((old = fopen(oldfilename, "r")) == NULL)
	{
		fprintf(stderr, "Cannot open %s\n", oldfilename);
		exit(1);
	}
	else if ((new = fopen(newfilename, "w")) == NULL)
	{
		fprintf(stderr, "Cannot write %s\n", newfilename);
		fclose(old);
		exit(1);
	}
	else
	{
		Update(old, new);
		fclose(new);
		fclose(old);
	}
}


void Update(old, new)
FILE *old, *new;
{
	int i, c;
	UBYTE data[DX_FILESIZE];

	for (i=0; i<HEADER_SIZE; i++)	/* Write header to newfile. */
		putc(header[i], new);

	i = 0;
	while ((c = getc(old)) != EOF)	/* Copy old file to new. */
	{
		data[i++] = (UBYTE)c;
		putc(c, new);
	}

	putc(MakeChecksum(data), new);
	putc((UBYTE)0xF7, new);
}