changeset 391:a40557e5b35f

compal/melody-extr: wrote table extractor
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 01 Apr 2022 05:04:23 +0000
parents 37ee46a0dde7
children 35009c936a4a
files .hgignore compal/melody-extr/Makefile compal/melody-extr/extr-table.c
diffstat 3 files changed, 82 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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$
--- /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
--- /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 <sys/types.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+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);
+}