aboutsummaryrefslogtreecommitdiff
path: root/general.h
diff options
context:
space:
mode:
authorAlex Marshall <SquidMan72@gmail.com>2009-02-05 15:23:41 -0800
committerAlex Marshall <SquidMan72@gmail.com>2009-02-05 15:23:41 -0800
commit6ab309e20733773d0a5039051086a6d86db3b43b (patch)
tree6cac2d4801357cf2d41e02cb4d8a7a2ac9fa46dc /general.h
parent2a42061acef874780127bfe89c3f26dd998c57b6 (diff)
Updated BRLAN info, and made the C side a bit moar modular
Diffstat (limited to '')
-rw-r--r--general.h52
1 files changed, 52 insertions, 0 deletions
diff --git a/general.h b/general.h
new file mode 100644
index 0000000..86370c1
--- /dev/null
+++ b/general.h
@@ -0,0 +1,52 @@
+/*
+ * general.h
+ *
+ *
+ * Created by Alex Marshall on 09/01/30.
+ * Copyright 2009 __MyCompanyName__. All rights reserved.
+ *
+ */
+
+#define fatal(x) printf(x); exit(1)
+
+void LZ77Decompress(void *indata, size_t dlen, u8* ret)
+{
+ int inp = 0;
+ u8* data = (u8*)calloc(dlen + 16, 1);
+ memcpy(data, indata, dlen);
+ int i;
+ u8 bitmask;
+ ret = (u8*)calloc(dlen, 256); // HORRIBLY INEFFICIENT.
+ // FIGURE SOMETHING ELSE OUT
+ int retoff = 0;
+
+ while(inp < dlen) {
+ bitmask = data[inp];
+ inp++;
+
+ for(i = 0; i < 8; i++) {
+ if(bitmask & 0x80) {
+ u8 rep = data[inp];
+ u8 repLength = (rep >> 4) + 3;
+ inp++;
+ u16 repOff = data[inp] | ((rep & 0x0F) << 8);
+ inp++;
+
+ if(repOff <= retoff) {
+ fatal("Offset too high!\nQuitting\n");
+ }
+
+ while(repLength > 0) {
+ ret[retoff] = ret[(retoff - repOff) - 1];
+ repLength--;
+ retoff++;
+ }
+ }else{
+ ret[retoff] = data[inp];
+ retoff++;
+ inp++;
+ }
+ bitmask = bitmask << 1;
+ }
+ }
+}