]> Chaos Git - corbenik/corbenik.git/commitdiff
Move common sources to a dedicated directory
authorJon Feldman <chaos.kagami@gmail.com>
Sun, 22 Jan 2017 16:37:56 +0000 (11:37 -0500)
committerJon Feldman <chaos.kagami@gmail.com>
Sun, 22 Jan 2017 16:37:56 +0000 (11:37 -0500)
boot/Makefile.am
common/lzss.c [moved from include/lzss.c with 70% similarity]
include/lzss.h [new file with mode: 0644]
loader/Makefile
loader/source/loader.c

index b8e1e77e7d27a6649a1cb8ea27d2446270d6edd8..6e7ae4eb4712ad1a31a8778a7317a0299bc5b3a8 100644 (file)
@@ -25,4 +25,4 @@ corbenik_SOURCES = \
        patch/reboot.c patch/svc.c patch/module.c patch/emunand.c \
        std/fs.c std/draw.c std/memory.c std/abort.c \
        firm/util.c firm/keys.c firm/firmlaunch.c firm/version.c firm/firm.c firm/decryptor.c \
-       configback/file-dat.c
+       configback/file-dat.c ../common/lzss.c
similarity index 70%
rename from include/lzss.c
rename to common/lzss.c
index c2f02ded9da5f6d63350b8277b3fae56af23f238..b0418faa80077a9e213240154fd6f14ef5dafce6 100644 (file)
@@ -1,13 +1,21 @@
-#ifndef __LZSS_H
-#define __LZSS_H
+#include <stdint.h>
 
-static int
-lzss_decompress(u8 *buffer)
+
+int
+lzss_decompress(uint8_t *buffer)
 {
     // This WAS originally a decompilation in @yifan_lu's repo; it was rewritten
     // for readability following ctrtool's namings.
+
+    // This implementation is particularly interesting in that it's an in-place
+    // decompressor.
+
+    // LZSS is performed in the reverse direction,
+    // and the last four bytes are the decompressed size.
+    // Presumably, Nintendo did as such so decompression can occur in-place without need for temporary buffers.
+
     unsigned int decompSize, v15;
-    u8 *compressEndOff, *index, *stopIndex;
+    uint8_t *compressEndOff, *index, *stopIndex;
     char control;
     int v9, v13, v14, v16;
     int ret = 0;
@@ -16,8 +24,8 @@ lzss_decompress(u8 *buffer)
         return 0;
 
     // v1=decompressedSize, v2=compressedSize, v3=index, v4=stopIndex
-    decompSize = *((u32 *)buffer - 2);
-    compressEndOff = &buffer[*((u32 *)buffer - 1)];
+    decompSize = *((uint32_t *)buffer - 2);
+    compressEndOff = &buffer[*((uint32_t *)buffer - 1)];
     index = &buffer[-(decompSize >> 24)]; // FIXME - The integer negation is due
                                           // to a compiler optimization. It's
                                           // probably okay, but...
@@ -32,7 +40,7 @@ lzss_decompress(u8 *buffer)
                 v13 = *(index - 1);
                 v14 = *(index - 2);
                 index -= 2;
-                v15 = ((v14 | (v13 << 8)) & 0xFFFF0FFF) + 2;
+                v15 = (((unsigned int)v14 | ((unsigned int)v13 << 8)) & 0xFFFF0FFF) + 2;
                 v16 = v13 + 32;
                 do {
                     ret = compressEndOff[v15];
@@ -52,5 +60,3 @@ lzss_decompress(u8 *buffer)
 
     return ret;
 }
-
-#endif
diff --git a/include/lzss.h b/include/lzss.h
new file mode 100644 (file)
index 0000000..ab3cbde
--- /dev/null
@@ -0,0 +1,6 @@
+#ifndef __LZSS_H
+#define __LZSS_H
+
+int lzss_decompress(uint8_t *buffer);
+
+#endif
index e3dbd85e16261fbd22822d9b4a9d96a1c40dad7c..5db3812b415511a8b6d66075fc2aeeb5cf8ed844 100644 (file)
@@ -33,7 +33,7 @@ endif
 #---------------------------------------------------------------------------------
 TARGET         :=      loader
 BUILD          :=      build
-SOURCES                :=      source source/patch
+SOURCES                :=      source ../common
 DATA           :=      data
 INCLUDES       :=      include
 
index 1573084636bf9db2090f08fb38760659c74cca1b..f0fdf346f4080b1eebeb4f3893c66a404881b028 100644 (file)
@@ -1,6 +1,6 @@
 #include <3ds.h>
 #include "patcher.h"
-#include <lzss.c>
+#include <lzss.h>
 #include <string.h>
 #include <stdio.h>
 #include <stdlib.h>