diff libcommon/hexdump.c @ 0:f7145c77b7fb

starting libcommon: factored out of fc-simtool
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 11 Feb 2021 22:28:45 +0000
parents
children f1836c8d36cb
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libcommon/hexdump.c	Thu Feb 11 22:28:45 2021 +0000
@@ -0,0 +1,36 @@
+#include <sys/types.h>
+#include <stdio.h>
+#include "simresp.h"
+
+display_sim_resp_in_hex()
+{
+	unsigned off, cc, n, c;
+
+	for (off = 0; off < sim_resp_data_len; off += cc) {
+		printf("%02X:", off);
+		cc = 16;
+		if (sim_resp_data_len - off < cc)
+			cc = sim_resp_data_len - off;
+		for (n = 0; n < 16; n++) {
+			if (n == 0 || n == 8)
+				putchar(' ');
+			putchar(' ');
+			if (n < cc)
+				printf("%02X", sim_resp_data[off + n]);
+			else {
+				putchar(' ');
+				putchar(' ');
+			}
+		}
+		putchar(' ');
+		putchar(' ');
+		for (n = 0; n < cc; n++) {
+			c = sim_resp_data[off + n];
+			if (c < 0x20 || c > 0x7E)
+				c = '.';
+			putchar(c);
+		}
+		putchar('\n');
+	}
+	return(0);
+}