summaryrefslogtreecommitdiffstats
path: root/types.c
diff options
context:
space:
mode:
Diffstat (limited to 'types.c')
-rw-r--r--types.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/types.c b/types.c
new file mode 100644
index 0000000..7cf13c4
--- /dev/null
+++ b/types.c
@@ -0,0 +1,50 @@
+/**
+ * types.c
+ */
+
+#include <stdio.h>
+#include <limits.h>
+#include "types.h"
+
+u16 be16(const u8 *p) {
+ return (p[0] << 8) | p[1];
+}
+
+u32 be32(const u8 *p) {
+ return (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3];
+}
+
+u64 be64(const u8 *p) {
+ return ((u64)be32(p) << 32) | be32(p + 4);
+}
+
+void wbe16(u8 *p, u16 x) {
+ p[0] = x >> 8;
+ p[1] = x;
+}
+
+void wbe32(u8 *p, u32 x) {
+ wbe16(p, x >> 16);
+ wbe16(p + 2, x);
+}
+
+void wbe64(u8 *p, u64 x) {
+ wbe32(p, x >> 32);
+ wbe32(p + 4, x);
+}
+
+void hexdump(u8 *x, u32 n) {
+ u32 i, j;
+
+ for (i = 0; i < n; i += 16) {
+ fprintf(stderr, "%04x:", i);
+ for (j = 0; j < 16 && i + j < n; j++) {
+ if ((j & 3) == 0)
+ fprintf(stderr, " ");
+ fprintf(stderr, "%02x", *x++);
+ }
+ fprintf(stderr, "\n");
+ }
+}
+
+const u32 WII_BLOCK_SIZE = 1024*128;