changeset 54:8deebf9c410a

d144: "decompile" binary input format into ASCII
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 25 Sep 2024 04:32:32 +0000
parents c93ecd225b7f
children 08738993b4e7
files .hgignore d144/Makefile d144/edata-input-decomp.c
diffstat 3 files changed, 66 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Wed Sep 25 03:50:11 2024 +0000
+++ b/.hgignore	Wed Sep 25 04:32:32 2024 +0000
@@ -2,8 +2,10 @@
 
 \.[oa]$
 
+^d144/d144-ul-input\.asc$
 ^d144/d144-ul-input\.bin$
 ^d144/edata-input-compile$
+^d144/edata-input-decomp$
 
 ^tfo/find-is-hdr$
 ^tfo/tfo-trace-msg$
--- a/d144/Makefile	Wed Sep 25 03:50:11 2024 +0000
+++ b/d144/Makefile	Wed Sep 25 04:32:32 2024 +0000
@@ -1,15 +1,21 @@
 CC=	gcc
 CFLAGS=	-O2
-PROGS=	edata-input-compile
-DATA=	d144-ul-input.bin
+PROGS=	edata-input-compile edata-input-decomp
+DATA=	d144-ul-input.bin d144-ul-input.asc
 
 all:	${PROGS} ${DATA}
 
 edata-input-compile:	edata-input-compile.c
 	${CC} ${CFLAGS} -o $@ $@.c
 
+edata-input-decomp:	edata-input-decomp.c
+	${CC} ${CFLAGS} -o $@ $@.c
+
 d144-ul-input.bin:	edata-input-compile ul-input
 	./edata-input-compile ul-input $@
 
+d144-ul-input.asc:	edata-input-decomp d144-ul-input.bin
+	./edata-input-decomp d144-ul-input.bin $@
+
 clean:
 	rm -f *.o ${PROGS} ${DATA}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/d144/edata-input-decomp.c	Wed Sep 25 04:32:32 2024 +0000
@@ -0,0 +1,56 @@
+/*
+ * This program reads an E-data compiled binary file (the kind intended
+ * as input to itt-ater-16) and converts it into ASCII form.  The ASCII
+ * output from this program is not in the same format as input to
+ * edata-input-compile, but it is a more compact ASCII-based format
+ * that will be useful for unit tests on the future sw implementation
+ * of RAA' function.
+ */
+
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+
+main(argc, argv)
+	char **argv;
+{
+	FILE *binf, *outf;
+	uint8_t frame[38];
+	int rc;
+	unsigned n;
+
+	if (argc < 2 || argc > 3) {
+		fprintf(stderr, "usage: %s input.bin [output.asc]\n", argv[0]);
+		exit(1);
+	}
+	binf = fopen(argv[1], "r");
+	if (!binf) {
+		perror(argv[1]);
+		exit(1);
+	}
+	if (argc > 2) {
+		outf = fopen(argv[2], "w");
+		if (!outf) {
+			perror(argv[2]);
+			exit(1);
+		}
+	} else
+		outf = stdout;
+	for (;;) {
+		rc = fread(frame, 1, 38, binf);
+		if (!rc)
+			break;
+		if (rc != 38) {
+inv_input:		fprintf(stderr, "error: %s is not in expected format\n",
+				argv[1]);
+			exit(1);
+		}
+		if (frame[0] != 0xD4)
+			goto inv_input;
+		fprintf(outf, "%u%u ", (frame[1] & 2) >> 1, frame[1] & 1);
+		for (n = 0; n < 36; n++)
+			fprintf(outf, "%02x", frame[n+2]);
+		putc('\n', outf);
+	}
+	exit(0);
+}