summaryrefslogtreecommitdiff
path: root/src/bin/xi/xi2path.h
diff options
context:
space:
mode:
authorJari Vetoniemi <mailroxas@gmail.com>2017-04-20 16:49:35 +0300
committerJari Vetoniemi <mailroxas@gmail.com>2017-05-01 22:58:22 +0300
commit29086b1d12a2c28cffdbfbf0b3990a7bd75506b9 (patch)
tree8acd48bc30932812744c0adb102d7a7add494357 /src/bin/xi/xi2path.h
parent76b8c9e03c97b16d9ff97f3b79c0ecbff0f5e7f2 (diff)
work in progress
Diffstat (limited to 'src/bin/xi/xi2path.h')
-rw-r--r--src/bin/xi/xi2path.h35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/bin/xi/xi2path.h b/src/bin/xi/xi2path.h
new file mode 100644
index 0000000..954c554
--- /dev/null
+++ b/src/bin/xi/xi2path.h
@@ -0,0 +1,35 @@
+#pragma once
+
+#include <stdio.h>
+#include <assert.h>
+#include <stdint.h>
+
+static inline void
+xi2path(char out[12], const uint16_t id)
+{
+ // Forms path like: section/id.DAT, from 16bit id.
+ // First 7 bits are used for DAT and rest of the bits for ROM section.
+ //
+ // e.g. ID of 1000 would look like 11101000 00000011 in binary.
+ // RDDDDDDD RRRRRRRR
+ //
+ // In the above graph, 'R' bits form the ROM section (7) and 'D' bits form the DAT (104).
+ // Thus maximum DAT and ROM section IDs are 127 and 511 respectively (65535 as decimal).
+
+ snprintf(out, 12, "%u/%u.DAT", id >> 7, id & 0x7F);
+}
+
+static inline void
+xi2rompath(char out[18], const uint8_t rom, const uint16_t id)
+{
+ assert(rom <= 9);
+
+ char path[12];
+ xi2path(path, id);
+
+ if (rom > 1) {
+ snprintf(out, 18, "ROM%u/%s", rom, path);
+ } else {
+ snprintf(out, 18, "ROM/%s", path);
+ }
+}