annotate ffstools/caltools/fc-add-ramps.c @ 859:e5ef798e2d35

fc-add-ramps new program written, compiles
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 18 Dec 2021 21:15:21 +0000
parents
children 7d4f080f66db
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
859
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This utility reads a tx-ramps table in FreeCalypso ASCII format,
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * sums up each ramp and reports these sums. The intended purpose is
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 * to check if all ramps add up to 128 like they are supposed to.
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 */
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <sys/types.h>
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdio.h>
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdlib.h>
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <string.h>
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <strings.h>
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 u_char data[512];
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 unsigned sums[32];
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 read_input(filename)
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 char *filename;
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 {
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 char *format;
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 if (read_rf_table_ext(filename, data, 1, &format, (unsigned *) 0))
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 exit(1);
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 if (strcmp(format, "tx-ramps")) {
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 fprintf(stderr, "error: %s is not a tx-ramps table\n",
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 filename);
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 exit(1);
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 }
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 }
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 compute_sums()
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 {
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 int i, j;
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 unsigned accum;
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 u_char *dp = data;
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 for (i = 0; i < 32; i++) {
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 accum = 0;
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 for (j = 0; j < 16; j++)
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 accum += *dp++;
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 sums[i] = accum;
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 }
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 }
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 output()
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 {
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 unsigned n;
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 for (n = 0; n < 16; n++) {
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 printf("Template #%u ramp-up sum: %u\n", sums[n*2]);
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 printf("Template #%u ramp-down sum: %u\n", sums[n*2+1]);
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 }
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 }
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 main(argc, argv)
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 char **argv;
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 {
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 if (argc != 2) {
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 fprintf(stderr, "usage: %s tx-ramps-file\n", argv[0]);
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 exit(1);
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 }
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 read_input(argv[1]);
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 compute_sums();
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 output();
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 exit(0);
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 }