annotate ffstools/caltools/fc-add-ramps.c @ 904:5041bcb8140f

tchtools/fc-vm2hex.c: update header comment for new situation
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 28 Dec 2022 08:41:57 +0000
parents 5efb2832f4c2
children
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
862
5efb2832f4c2 fc-add-ramps: more compacted output
Mychaela Falconia <falcon@freecalypso.org>
parents: 860
diff changeset
48 for (n = 0; n < 16; n++)
5efb2832f4c2 fc-add-ramps: more compacted output
Mychaela Falconia <falcon@freecalypso.org>
parents: 860
diff changeset
49 printf("Template #%u: ramp-up %u, ramp-down %u\n", n,
5efb2832f4c2 fc-add-ramps: more compacted output
Mychaela Falconia <falcon@freecalypso.org>
parents: 860
diff changeset
50 sums[n*2], sums[n*2+1]);
859
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 main(argc, argv)
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 char **argv;
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 {
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 if (argc != 2) {
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 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
58 exit(1);
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 }
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 read_input(argv[1]);
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 compute_sums();
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 output();
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 exit(0);
e5ef798e2d35 fc-add-ramps new program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 }