comparison loadtools/audump.c @ 852:8a89a42baa70

fc-loadtool tfc139-audio-dump hack implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 09 Oct 2021 21:24:51 +0000
parents loadtools/ltmisc.c@dfe6ba3611cd
children
comparison
equal deleted inserted replaced
851:526a8cfbbfd8 852:8a89a42baa70
1 /*
2 * This module implements the tfc139-audio-dump command in fc-loadtool,
3 * which is a special hack for reverse engineering of Compal audio configs.
4 * This hack command is named so because it will only produce interesting
5 * output if fc-loadtool has been entered via tfc139, i.e., breaking into
6 * a running Compal firmware.
7 */
8
9 #include <sys/types.h>
10 #include <stdio.h>
11 #include <stdint.h>
12 #include <stdlib.h>
13 #include <string.h>
14 #include <strings.h>
15
16 extern char target_response_line[];
17
18 do_abbr(page, reg, retptr)
19 unsigned page, reg;
20 uint16_t *retptr;
21 {
22 char page_arg[8], reg_arg[8], *argv[4];
23 int stat;
24 char *strtoul_endp;
25
26 sprintf(page_arg, "%u", page);
27 sprintf(reg_arg, "%u", reg);
28 argv[0] = "abbr";
29 argv[1] = page_arg;
30 argv[2] = reg_arg;
31 argv[3] = 0;
32 tpinterf_make_cmd(argv);
33 if (tpinterf_send_cmd() < 0)
34 return(-1);
35 stat = tpinterf_capture_output_oneline(1);
36 if (stat != 1) {
37 errout: fprintf(stderr, "error: malformed response to abbr command\n");
38 return(-1);
39 }
40 if (strlen(target_response_line) != 3)
41 goto errout;
42 *retptr = strtoul(target_response_line, &strtoul_endp, 16);
43 if (strtoul_endp != target_response_line + 3)
44 goto errout;
45 return(0);
46 }
47
48 cmd_tfc139_audio_dump(argc, argv)
49 char **argv;
50 {
51 uint16_t data[31];
52 int i, stat;
53 FILE *of;
54
55 if (argv[1]) {
56 of = fopen(argv[1], "w");
57 if (!of) {
58 perror(argv[1]);
59 return(-1);
60 }
61 } else
62 of = stdout;
63 /* read d_aec_ctrl */
64 stat = do_r16(0xFFD00238, data);
65 if (stat) {
66 bad_read: if (argv[1])
67 fclose(of);
68 return(stat);
69 }
70 fprintf(of, "d_aec_ctrl: 0x%04X\n", (int) data[0]);
71 /* read new AEC parameter words */
72 for (i = 0; i < 8; i++) {
73 stat = do_r16(0xFFD0084A + (i << 1), data + i);
74 if (stat)
75 goto bad_read;
76 }
77 fputs("New AEC params:", of);
78 for (i = 0; i < 8; i++)
79 fprintf(of, " 0x%04X", (int) data[i]);
80 putc('\n', of);
81 putc('\n', of);
82 /* read UL FIR coeffs */
83 for (i = 0; i < 31; i++) {
84 stat = do_r16(0xFFD00908 + (i << 1), data + i);
85 if (stat)
86 goto bad_read;
87 }
88 fputs("Uplink FIR coefficients:\n", of);
89 for (i = 0; i < 31; i++) {
90 if (i == 0 || i == 8 || i == 16 || i == 24)
91 putc('\n', of);
92 else
93 putc(' ', of);
94 fprintf(of, "0x%04X", (int) data[i]);
95 }
96 putc('\n', of);
97 putc('\n', of);
98 /* read DL FIR coeffs */
99 for (i = 0; i < 31; i++) {
100 stat = do_r16(0xFFD00946 + (i << 1), data + i);
101 if (stat)
102 goto bad_read;
103 }
104 fputs("Downlink FIR coefficients:\n", of);
105 for (i = 0; i < 31; i++) {
106 if (i == 0 || i == 8 || i == 16 || i == 24)
107 putc('\n', of);
108 else
109 putc(' ', of);
110 fprintf(of, "0x%04X", (int) data[i]);
111 }
112 putc('\n', of);
113 putc('\n', of);
114 /* read ABB VBC registers */
115 stat = do_abbr(1, 8, data);
116 if (stat)
117 goto bad_read;
118 fprintf(of, "VBCTRL1: 0x%03X\n", (int) data[0]);
119 stat = do_abbr(1, 11, data);
120 if (stat)
121 goto bad_read;
122 fprintf(of, "VBCTRL2: 0x%03X\n", (int) data[0]);
123 stat = do_abbr(1, 10, data);
124 if (stat)
125 goto bad_read;
126 fprintf(of, "VBPOP: 0x%03X\n", (int) data[0]);
127 stat = do_abbr(1, 7, data);
128 if (stat)
129 goto bad_read;
130 fprintf(of, "VBUCTRL: 0x%03X\n", (int) data[0]);
131 stat = do_abbr(0, 6, data);
132 if (stat)
133 goto bad_read;
134 fprintf(of, "VBDCTRL: 0x%03X\n", (int) data[0]);
135 /* done */
136 if (argv[1])
137 fclose(of);
138 return(0);
139 }