changeset 45:59d1d15b6f7e

trau-parse: add -r option for raw frame output
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 13 Sep 2024 17:37:21 +0000
parents b15dfdc62ceb
children f977027774cb
files trau-decode/parse-main.c
diffstat 1 files changed, 40 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/trau-decode/parse-main.c	Fri Sep 13 16:36:31 2024 +0000
+++ b/trau-decode/parse-main.c	Fri Sep 13 17:37:21 2024 +0000
@@ -11,6 +11,7 @@
 #include <strings.h>
 
 static unsigned file_offset;
+static int include_raw;
 
 static enum {
 	HUNT_FOR_0,
@@ -106,11 +107,30 @@
 }
 
 static void
+dump_raw_frame()
+{
+	uint8_t *sp = frame_bits;
+	unsigned n, m, d;
+
+	for (n = 0; n < 80; n++) {
+		d = 0;
+		for (m = 0; m < 4; m++) {
+			d <<= 1;
+			d |= *sp++;
+		}
+		printf("%x", d);
+	}
+	putchar('\n');
+}
+
+static void
 process_frame()
 {
 	unsigned c1_5, c6_11;
 
 	printf("Frame at 0x%x:\n", file_offset - 159);
+	if (include_raw)
+		dump_raw_frame();
 	printf("  C1-C5: %u%u%u%u%u", frame_bits[17], frame_bits[18],
 		frame_bits[19], frame_bits[20], frame_bits[21]);
 	c1_5 = bits_to_num(frame_bits + 17, 5);
@@ -260,20 +280,35 @@
 main(argc, argv)
 	char **argv;
 {
+	char *filename, *subslot_arg;
 	FILE *inf;
 	int subslot, right_shift;
 	int inb;
 
-	if (argc != 3) {
-		fprintf(stderr, "usage: %s binfile subslot\n", argv[0]);
+	switch (argc) {
+	case 3:
+		filename = argv[1];
+		subslot_arg = argv[2];
+		include_raw = 0;
+		break;
+	case 4:
+		if (strcmp(argv[1], "-r"))
+			goto usage;
+		filename = argv[2];
+		subslot_arg = argv[3];
+		include_raw = 1;
+		break;
+	default:
+	usage:
+		fprintf(stderr, "usage: %s [-r] binfile subslot\n", argv[0]);
 		exit(1);
 	}
-	inf = fopen(argv[1], "r");
+	inf = fopen(filename, "r");
 	if (!inf) {
-		perror(argv[1]);
+		perror(filename);
 		exit(1);
 	}
-	subslot = atoi(argv[2]);
+	subslot = atoi(subslot_arg);
 	if (subslot < 0 || subslot > 3) {
 		fprintf(stderr, "error: invalid subslot argument\n");
 		exit(1);