aboutsummaryrefslogtreecommitdiff
path: root/src/tools/mkgenome.c
diff options
context:
space:
mode:
authorGravatar Moon Flower <moonflower@elhenney.local> 2026-10-12 08:46:23 +0330
committerGravatar Moon Flower <moonflower@elhenney.local> 2026-10-12 08:46:23 +0330
commitecc350ca5c2eb50be8309c5f14f8bf0d87db9a02 (patch)
tree70e0af76a1b13affff7c6cc8aac7b3e6ef960478 /src/tools/mkgenome.c
a
Diffstat (limited to 'src/tools/mkgenome.c')
-rw-r--r--src/tools/mkgenome.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/tools/mkgenome.c b/src/tools/mkgenome.c
new file mode 100644
index 0000000..bb2e787
--- /dev/null
+++ b/src/tools/mkgenome.c
@@ -0,0 +1,31 @@
+/* turns a genome image (little-endian 64-bit words on stdin, as written by
+ src/tools/build.zc) into genome.h */
+#include <stdio.h>
+#include <stdint.h>
+#ifdef _WIN32
+#include <fcntl.h>
+#include <io.h>
+#endif
+#include "memmap.h"
+int main(void)
+{
+#ifdef _WIN32
+ _setmode(_fileno(stdin), _O_BINARY);
+ _setmode(_fileno(stdout), _O_BINARY);
+#endif
+ unsigned char b[8]; int n = 0; size_t got;
+ printf("#define GORG %d\nstatic const int64_t genome[] = {", GORG);
+ while ((got = fread(b, 1, 8, stdin)) == 8) {
+ uint64_t u = (uint64_t)b[0] | (uint64_t)b[1] << 8 | (uint64_t)b[2] << 16 | (uint64_t)b[3] << 24
+ | (uint64_t)b[4] << 32 | (uint64_t)b[5] << 40 | (uint64_t)b[6] << 48 | (uint64_t)b[7] << 56;
+ if ((n == 0 && u != (uint64_t)FTOP * 2 + 1) ||
+ (n == 1 && u != (uint64_t)ZFP * 2 + 1) || (n == 2 && u != 4)) {
+ fprintf(stderr, "mkgenome: input is not a genome for this map\n"); return 1;
+ }
+ printf("%s%lld", !n ? "\n" : n % 12 ? "," : ",\n", (long long)u);
+ n++;
+ }
+ if (got || ferror(stdin) || n < 7) { fprintf(stderr, "mkgenome: incomplete genome\n"); return 1; }
+ printf("\n};\n#define GLEN %d\n", n);
+ return n ? 0 : 1;
+}