# HG changeset patch # User Mychaela Falconia # Date 1648789463 0 # Node ID a40557e5b35fbcf8c493893cf5e1f6d126c02dc4 # Parent 37ee46a0dde7efd6939f5c42a4ca1862e96e426c compal/melody-extr: wrote table extractor diff -r 37ee46a0dde7 -r a40557e5b35f .hgignore --- a/.hgignore Fri Apr 01 04:30:44 2022 +0000 +++ b/.hgignore Fri Apr 01 05:04:23 2022 +0000 @@ -19,6 +19,7 @@ ^compal/c139-tfboot\. ^compal/c140-boot\. ^compal/c156-boot\. +^compal/melody-extr/extr-table$ ^compal/osmovoodoo ^dspanal/char2bin$ diff -r 37ee46a0dde7 -r a40557e5b35f compal/melody-extr/Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/compal/melody-extr/Makefile Fri Apr 01 05:04:23 2022 +0000 @@ -0,0 +1,11 @@ +CC= gcc +CFLAGS= -O2 +PROGS= extr-table + +all: ${PROGS} + +extr-table: extr-table.c + ${CC} ${CFLAGS} -o $@ $@.c + +clean: + rm -f ${PROGS} *.o *errs *.out diff -r 37ee46a0dde7 -r a40557e5b35f compal/melody-extr/extr-table.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/compal/melody-extr/extr-table.c Fri Apr 01 05:04:23 2022 +0000 @@ -0,0 +1,70 @@ +/* + * This program extracts the table of built-in melodies from a Mot C1xx + * fw image, the table that is called ringToneInfo_s[] in the special + * fw version with symbols. + */ + +#include +#include +#include + +FILE *binf; + +static void +open_and_seek_input(binfname, offset_arg) + char *binfname, *offset_arg; +{ + u_long offset; + + binf = fopen(binfname, "r"); + if (!binf) { + perror(binfname); + exit(1); + } + offset = strtoul(offset_arg, 0, 0); + fseek(binf, offset, SEEK_SET); +} + +static unsigned +extr_32le(bin) + u_char *bin; +{ + return (bin[0]) | (bin[1] << 8) | (bin[2] << 16) | (bin[3] << 24); +} + +static void +process_record(idx) + unsigned idx; +{ + u_char record[16]; + unsigned addr, nent, time_fudge; + int freq_offset; + + if (fread(&record, sizeof record, 1, binf) != 1) { + fprintf(stderr, "error reading from binary file\n"); + exit(1); + } + addr = extr_32le(record); + nent = extr_32le(record + 4); + freq_offset = extr_32le(record + 8); + time_fudge = extr_32le(record + 12); + printf("%u\t0x%06X\t%u\t%d\t%u\n", idx, addr, nent, freq_offset, + time_fudge); +} + +main(argc, argv) + char **argv; +{ + unsigned n, num_entries; + + if (argc != 4) { + fprintf(stderr, "usage: %s fw-image-file offset num-entries\n", + argv[0]); + exit(1); + } + open_and_seek_input(argv[1], argv[2]); + num_entries = strtoul(argv[3], 0, 0); + for (n = 0; n < num_entries; n++) + process_record(n + 1); + exit(0); +}