home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.ee.lbl.gov
/
2014.05.ftp.ee.lbl.gov.tar
/
ftp.ee.lbl.gov
/
bmd-1.0beta.tar.Z
/
bmd-1.0beta.tar
/
bmd-1.0beta
/
app
/
mtools
/
dx7dump.c
next >
Wrap
C/C++ Source or Header
|
1991-08-27
|
3KB
|
171 lines
/*
* Copyright (c) 1990 Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Lawrence Berkeley Laboratory,
* Berkeley, CA. The name of the University may not be used to
* endorse or promote products derived from this software without
* specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* dx7dump - dump a dx7 bulk patch dump to the serial port
*/
#ifndef lint
static char rcsid[] =
"@(#) $Header: dx7dump.c,v 1.1 91/08/27 00:44:24 mccanne Exp $ (LBL)";
#endif
#include <stdio.h>
#include <sys/file.h>
#include <sys/types.h>
#include <sys/termios.h>
/*
* You need the kernel hack to map B50 to the midi baud rate.
*/
#define B31250 B50
#define PATCHSIZE 4096
void
usage()
{
fprintf(stderr, "usage: dx7dump [-d device] file\n");
exit(1);
}
char *
devname(cp)
char *cp;
{
static char buf[256];
if (cp[0] == '/')
return cp;
sprintf(buf, "/dev/%s", cp);
return buf;
}
void
setbaud(fd, rate)
int fd;
int rate;
{
struct termios tios;
if (ioctl(fd, TCGETS, &tios) < 0) {
perror("TCGETS");
exit(1);
}
tios.c_cflag = CLOCAL|CS8|rate;
if (ioctl(fd, TCSETS, &tios) < 0) {
perror("TCSETS");
exit(1);
}
}
void
wr(fd, cp, len)
int fd;
char *cp;
int len;
{
int cc;
while (len > 0) {
cc = write(fd, cp, len);
if (cc < 0) {
perror("write");
exit(1);
}
len -= cc;
cp += cc;
}
}
void
midi_dump(patch, device)
u_char *patch;
char *device;
{
int i, fd;
int sum = 0;
u_long flags;
u_char header[] = { 0xf0, 0x43, 0x00, 0x09, 0x20, 0x00 };
u_char trailer[] = { 0x00, 0xf7 };
fd = open(device, O_WRONLY);
if (fd < 0) {
perror(device);
exit(1);
}
setbaud(fd, B31250);
wr(fd, header, sizeof(header));
wr(fd, patch, PATCHSIZE);
for (i = 0; i < PATCHSIZE; ++i)
sum -= patch[i];
trailer[0] = sum & 0x7f;
wr(fd, trailer, sizeof(trailer));
close(fd);
}
void
read_binary(fname, bp)
char *fname;
unsigned char *bp;
{
int fd;
fd = open(fname, O_RDONLY);
if (fd < 0) {
perror(fname);
exit(1);
}
if (read(fd, bp, PATCHSIZE) != PATCHSIZE) {
fprintf(stderr, "dx7dump: short file\n");
exit(1);
}
close(fd);
}
int
main(argc, argv)
int argc;
char **argv;
{
int port = 1, c;
char *device = "/dev/ttyb";
u_char buffer[PATCHSIZE];
extern char *optarg;
extern int optind;
while ((c = getopt(argc, argv, "d:")) != -1) {
switch(c) {
case 'd':
device = devname(optarg);
break;
default:
usage();
}
}
if (optind != argc - 1)
usage();
read_binary(argv[optind], (u_char *)buffer);
midi_dump((u_char *)buffer, device);
return 0;
}