Blame maestro3/fw_writer.c

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