comparison 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
comparison
equal deleted inserted replaced
307:8e816bba2ff7 308:f8344bc4fd61
1 #include <sys/types.h>
2 #include <stdio.h>
3 #include <stdint.h>
4 #include <stdlib.h>
5 #include "coffout.h"
6
7 static FILE *outF;
8
9 static void
10 write16(val)
11 unsigned val;
12 {
13 putc(val, outF);
14 putc(val >> 8, outF);
15 }
16
17 static void
18 write32(val)
19 unsigned val;
20 {
21 putc(val, outF);
22 putc(val >> 8, outF);
23 putc(val >> 16, outF);
24 putc(val >> 24, outF);
25 }
26
27 emit_coff_output(filename, sections, nsect)
28 char *filename;
29 struct coff_section *sections;
30 unsigned nsect;
31 {
32 uint32_t dataptr;
33 unsigned n;
34 char section_name[32];
35
36 outF = fopen(filename, "w");
37 if (!outF) {
38 perror(filename);
39 exit(1);
40 }
41 write16(0x00C1);
42 write16(nsect);
43 write32(0);
44 write32(0);
45 write32(0);
46 write16(0);
47 write16(0x0117);
48 write16(0x0098);
49 dataptr = 0x22 + 0x28 * nsect;
50 for (n = 0; n < nsect; n++) {
51 sprintf(section_name, "chunk%03u", n);
52 fwrite(section_name, 1, 8, outF);
53 write32(sections[n].addr);
54 write32(sections[n].addr);
55 write32(sections[n].size);
56 write32(dataptr);
57 dataptr += sections[n].size << 1;
58 write32(0);
59 write32(0);
60 write32(0);
61 write16(sections[n].flags);
62 putc(0, outF);
63 putc(sections[n].mempage, outF);
64 }
65 for (n = 0; n < nsect; n++)
66 fwrite(sections[n].data, 2, sections[n].size, outF);
67 fclose(outF);
68 return(0);
69 }