From 9c1ded3b0ae8e540177ee0c0baa1f9c8fcf91989 Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Wed, 18 Mar 2009 20:52:11 +0100 Subject: Initial commit of sources --- types.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 types.c (limited to 'types.c') 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 +#include +#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; -- cgit v1.1-32-gdbae