Blame ymfpci/fw_writer.c

Packit Service f0277f
/*
Packit Service f0277f
 * firmware writer for Yamaha DS-1 sound cards
Packit Service f0277f
 * Copyright (c) 2006 Clemens Ladisch <clemens@ladisch.de>
Packit Service f0277f
 *
Packit Service f0277f
 *
Packit Service f0277f
 * Permission to use, copy, modify, and distribute this software for any
Packit Service f0277f
 * purpose with or without fee is hereby granted, provided that the above
Packit Service f0277f
 * copyright notice and this permission notice appear in all copies.
Packit Service f0277f
 *
Packit Service f0277f
 * The software is provided "as is" and the author disclaims all warranties
Packit Service f0277f
 * with regard to this software including all implied warranties of
Packit Service f0277f
 * merchantability and fitness. In no event shall the author be liable for
Packit Service f0277f
 * any special, direct, indirect, or consequential damages or any damages
Packit Service f0277f
 * whatsoever resulting from loss of use, data or profits, whether in an
Packit Service f0277f
 * action of contract, negligence or other tortious action, arising out of
Packit Service f0277f
 * or in connection with the use or performance of this software.
Packit Service f0277f
 */
Packit Service f0277f
Packit Service f0277f
#include <stdio.h>
Packit Service f0277f
#include <stdlib.h>
Packit Service f0277f
Packit Service f0277f
#define YDSXG_DSPLENGTH 0x80
Packit Service f0277f
#define YDSXG_CTRLLENGTH 0x3000
Packit Service f0277f
Packit Service f0277f
#include "hwmcode.c"
Packit Service f0277f
Packit Service f0277f
static void write_file(const char *filename,
Packit Service f0277f
		       const unsigned long data[], size_t size)
Packit Service f0277f
{
Packit Service f0277f
	FILE *f;
Packit Service f0277f
	size_t i;
Packit Service f0277f
Packit Service f0277f
	fprintf(stderr, "writing %s ...\n", filename);
Packit Service f0277f
	f = fopen(filename, "wb");
Packit Service f0277f
	if (!f) {
Packit Service f0277f
		perror("cannot create file");
Packit Service f0277f
		exit(EXIT_FAILURE);
Packit Service f0277f
	}
Packit Service f0277f
	for (i = 0; i < size; ++i) {
Packit Service f0277f
		/* write as little-endian 32-bit values */
Packit Service f0277f
		if (fputc(data[i] & 0xff, f) == EOF ||
Packit Service f0277f
		    fputc((data[i] >> 8) & 0xff, f) == EOF ||
Packit Service f0277f
		    fputc((data[i] >> 16) & 0xff, f) == EOF ||
Packit Service f0277f
		    fputc((data[i] >> 24) & 0xff, f) == EOF)
Packit Service f0277f
			break;
Packit Service f0277f
	}
Packit Service f0277f
	if (ferror(f) || fclose(f) == EOF) {
Packit Service f0277f
		perror("cannot write");
Packit Service f0277f
		exit(EXIT_FAILURE);
Packit Service f0277f
	}
Packit Service f0277f
}
Packit Service f0277f
Packit Service f0277f
int main(void)
Packit Service f0277f
{
Packit Service f0277f
	write_file("ds1_dsp.fw", DspInst, YDSXG_DSPLENGTH / 4);
Packit Service f0277f
	write_file("ds1_ctrl.fw", CntrlInst, YDSXG_CTRLLENGTH / 4);
Packit Service f0277f
	write_file("ds1e_ctrl.fw", CntrlInst1E, YDSXG_CTRLLENGTH / 4);
Packit Service f0277f
	return 0;
Packit Service f0277f
}