diff dspanal/coffout.c @ 308:f8344bc4fd61

dspanal: char2coff utility written, compiles
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 28 Oct 2019 05:20:50 +0000
parents
children 493f73198267
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dspanal/coffout.c	Mon Oct 28 05:20:50 2019 +0000
@@ -0,0 +1,69 @@
+#include <sys/types.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include "coffout.h"
+
+static FILE *outF;
+
+static void
+write16(val)
+	unsigned val;
+{
+	putc(val, outF);
+	putc(val >> 8, outF);
+}
+
+static void
+write32(val)
+	unsigned val;
+{
+	putc(val, outF);
+	putc(val >> 8, outF);
+	putc(val >> 16, outF);
+	putc(val >> 24, outF);
+}
+
+emit_coff_output(filename, sections, nsect)
+	char *filename;
+	struct coff_section *sections;
+	unsigned nsect;
+{
+	uint32_t dataptr;
+	unsigned n;
+	char section_name[32];
+
+	outF = fopen(filename, "w");
+	if (!outF) {
+		perror(filename);
+		exit(1);
+	}
+	write16(0x00C1);
+	write16(nsect);
+	write32(0);
+	write32(0);
+	write32(0);
+	write16(0);
+	write16(0x0117);
+	write16(0x0098);
+	dataptr = 0x22 + 0x28 * nsect;
+	for (n = 0; n < nsect; n++) {
+		sprintf(section_name, "chunk%03u", n);
+		fwrite(section_name, 1, 8, outF);
+		write32(sections[n].addr);
+		write32(sections[n].addr);
+		write32(sections[n].size);
+		write32(dataptr);
+		dataptr += sections[n].size << 1;
+		write32(0);
+		write32(0);
+		write32(0);
+		write16(sections[n].flags);
+		putc(0, outF);
+		putc(sections[n].mempage, outF);
+	}
+	for (n = 0; n < nsect; n++)
+		fwrite(sections[n].data, 2, sections[n].size, outF);
+	fclose(outF);
+	return(0);
+}