FreeCalypso > hg > freecalypso-reveng
annotate compal/melody-extr/extr-table.c @ 400:5377f91aea97
compal/boot/c123-boot.disasm: annotate with symbols
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 14 Jan 2023 09:47:46 +0000 |
parents | a40557e5b35f |
children |
rev | line source |
---|---|
391
a40557e5b35f
compal/melody-extr: wrote table extractor
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
a40557e5b35f
compal/melody-extr: wrote table extractor
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This program extracts the table of built-in melodies from a Mot C1xx |
a40557e5b35f
compal/melody-extr: wrote table extractor
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * fw image, the table that is called ringToneInfo_s[] in the special |
a40557e5b35f
compal/melody-extr: wrote table extractor
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 * fw version with symbols. |
a40557e5b35f
compal/melody-extr: wrote table extractor
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 */ |
a40557e5b35f
compal/melody-extr: wrote table extractor
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 |
a40557e5b35f
compal/melody-extr: wrote table extractor
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <sys/types.h> |
a40557e5b35f
compal/melody-extr: wrote table extractor
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdio.h> |
a40557e5b35f
compal/melody-extr: wrote table extractor
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <stdlib.h> |
a40557e5b35f
compal/melody-extr: wrote table extractor
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 |
a40557e5b35f
compal/melody-extr: wrote table extractor
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 FILE *binf; |
a40557e5b35f
compal/melody-extr: wrote table extractor
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 |
a40557e5b35f
compal/melody-extr: wrote table extractor
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 static void |
a40557e5b35f
compal/melody-extr: wrote table extractor
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 open_and_seek_input(binfname, offset_arg) |
a40557e5b35f
compal/melody-extr: wrote table extractor
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 char *binfname, *offset_arg; |
a40557e5b35f
compal/melody-extr: wrote table extractor
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 { |
a40557e5b35f
compal/melody-extr: wrote table extractor
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 u_long offset; |
a40557e5b35f
compal/melody-extr: wrote table extractor
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 |
a40557e5b35f
compal/melody-extr: wrote table extractor
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 binf = fopen(binfname, "r"); |
a40557e5b35f
compal/melody-extr: wrote table extractor
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 if (!binf) { |
a40557e5b35f
compal/melody-extr: wrote table extractor
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 perror(binfname); |
a40557e5b35f
compal/melody-extr: wrote table extractor
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 exit(1); |
a40557e5b35f
compal/melody-extr: wrote table extractor
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 } |
a40557e5b35f
compal/melody-extr: wrote table extractor
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 offset = strtoul(offset_arg, 0, 0); |
a40557e5b35f
compal/melody-extr: wrote table extractor
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 fseek(binf, offset, SEEK_SET); |
a40557e5b35f
compal/melody-extr: wrote table extractor
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 } |
a40557e5b35f
compal/melody-extr: wrote table extractor
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 |
a40557e5b35f
compal/melody-extr: wrote table extractor
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 static unsigned |
a40557e5b35f
compal/melody-extr: wrote table extractor
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 extr_32le(bin) |
a40557e5b35f
compal/melody-extr: wrote table extractor
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 u_char *bin; |
a40557e5b35f
compal/melody-extr: wrote table extractor
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 { |
a40557e5b35f
compal/melody-extr: wrote table extractor
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 return (bin[0]) | (bin[1] << 8) | (bin[2] << 16) | (bin[3] << 24); |
a40557e5b35f
compal/melody-extr: wrote table extractor
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 } |
a40557e5b35f
compal/melody-extr: wrote table extractor
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 |
a40557e5b35f
compal/melody-extr: wrote table extractor
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 static void |
a40557e5b35f
compal/melody-extr: wrote table extractor
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 process_record(idx) |
a40557e5b35f
compal/melody-extr: wrote table extractor
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 unsigned idx; |
a40557e5b35f
compal/melody-extr: wrote table extractor
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 { |
a40557e5b35f
compal/melody-extr: wrote table extractor
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 u_char record[16]; |
a40557e5b35f
compal/melody-extr: wrote table extractor
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 unsigned addr, nent, time_fudge; |
a40557e5b35f
compal/melody-extr: wrote table extractor
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 int freq_offset; |
a40557e5b35f
compal/melody-extr: wrote table extractor
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 |
a40557e5b35f
compal/melody-extr: wrote table extractor
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 if (fread(&record, sizeof record, 1, binf) != 1) { |
a40557e5b35f
compal/melody-extr: wrote table extractor
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 fprintf(stderr, "error reading from binary file\n"); |
a40557e5b35f
compal/melody-extr: wrote table extractor
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 exit(1); |
a40557e5b35f
compal/melody-extr: wrote table extractor
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 } |
a40557e5b35f
compal/melody-extr: wrote table extractor
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 addr = extr_32le(record); |
a40557e5b35f
compal/melody-extr: wrote table extractor
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 nent = extr_32le(record + 4); |
a40557e5b35f
compal/melody-extr: wrote table extractor
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 freq_offset = extr_32le(record + 8); |
a40557e5b35f
compal/melody-extr: wrote table extractor
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 time_fudge = extr_32le(record + 12); |
a40557e5b35f
compal/melody-extr: wrote table extractor
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 printf("%u\t0x%06X\t%u\t%d\t%u\n", idx, addr, nent, freq_offset, |
a40557e5b35f
compal/melody-extr: wrote table extractor
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 time_fudge); |
a40557e5b35f
compal/melody-extr: wrote table extractor
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 } |
a40557e5b35f
compal/melody-extr: wrote table extractor
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 |
a40557e5b35f
compal/melody-extr: wrote table extractor
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 main(argc, argv) |
a40557e5b35f
compal/melody-extr: wrote table extractor
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 char **argv; |
a40557e5b35f
compal/melody-extr: wrote table extractor
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 { |
a40557e5b35f
compal/melody-extr: wrote table extractor
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 unsigned n, num_entries; |
a40557e5b35f
compal/melody-extr: wrote table extractor
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 |
a40557e5b35f
compal/melody-extr: wrote table extractor
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 if (argc != 4) { |
a40557e5b35f
compal/melody-extr: wrote table extractor
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 fprintf(stderr, "usage: %s fw-image-file offset num-entries\n", |
a40557e5b35f
compal/melody-extr: wrote table extractor
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 argv[0]); |
a40557e5b35f
compal/melody-extr: wrote table extractor
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 exit(1); |
a40557e5b35f
compal/melody-extr: wrote table extractor
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 } |
a40557e5b35f
compal/melody-extr: wrote table extractor
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 open_and_seek_input(argv[1], argv[2]); |
a40557e5b35f
compal/melody-extr: wrote table extractor
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 num_entries = strtoul(argv[3], 0, 0); |
a40557e5b35f
compal/melody-extr: wrote table extractor
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 for (n = 0; n < num_entries; n++) |
a40557e5b35f
compal/melody-extr: wrote table extractor
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 process_record(n + 1); |
a40557e5b35f
compal/melody-extr: wrote table extractor
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 exit(0); |
a40557e5b35f
compal/melody-extr: wrote table extractor
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 } |