]> Chaos Git - corbenik/corbenik.git/commitdiff
Rename the 0282builder ID and split out lzss
authorchaoskagami <chaos.kagami@gmail.com>
Mon, 23 May 2016 20:12:21 +0000 (16:12 -0400)
committerchaoskagami <chaos.kagami@gmail.com>
Mon, 23 May 2016 20:12:21 +0000 (16:12 -0400)
external/loader/loader.rsf
external/loader/source/loader.c
external/loader/source/lzss.c [new file with mode: 0644]
external/loader/source/lzss.h [new file with mode: 0644]

index dfeeb0eb5367caa17fbfe91a108caa2b3c487572..338bac97061421c32a45d80bfb56133bb76ab86e 100644 (file)
@@ -1,7 +1,9 @@
 BasicInfo:
   Title                   : loader
   CompanyCode             : "00"
-  ProductCode             : 0828builder
+  ProductCode             : injectload
+# The system doesn't actually care about this, 0282builder was
+# likely an artifact of their toolchain. We change it just because.
   ContentType             : Application
   Logo                    : None
 
@@ -112,4 +114,4 @@ AccessControlInfo:
 SystemControlInfo:
   SaveDataSize: 0KB # It doesn't use any save data.
   RemasterVersion: 0
-  StackSize: 0x1000
\ No newline at end of file
+  StackSize: 0x1000
index 6fc32d27989bc339c0106c8ee239d3930f547d8e..3bb93b6730b21f022fe67dd49d482df2eae544f1 100644 (file)
@@ -6,6 +6,7 @@
 #include "fsreg.h"
 #include "pxipm.h"
 #include "srvsys.h"
+#include "lzss.h"
 #include "internal.h"
 
 // TODO - a lot of this is unecessarily verbose and shitty. Clean it up to be tidy.
@@ -31,64 +32,6 @@ static u64 g_cached_prog_handle;
 static exheader_header g_exheader;
 static char g_ret_buf[1024];
 
-// TODO - This doesn't belong in loader.c - It's a decompression function, stuff it in its own file.
-// Not to mention, it is nigh unreadable. Replace it with a more readable version of LZSS.
-// This decompresses in-place.
-
-// end should be 'buffer'
-static int lzss_decompress(u8 *buffer)
-{
-  // This WAS originally a decompilation in @yifan_lu's repo; it was rewritten for readability following ctrtool's namings.
-  unsigned int decompSize, v15;
-  u8 *compressEndOff, *index, *stopIndex;
-  char control;
-  int v9, v13, v14, v16;
-  int ret = 0;
-
-  if ( !buffer ) // Return immediately when buffer is invalid.
-    return 0;
-
-  // v1=decompressedSize, v2=compressedSize, v3=index, v4=stopIndex
-  decompSize     = *((u32 *)buffer - 2);
-  compressEndOff = &buffer[*((u32 *)buffer - 1)];
-  index          = &buffer[-(decompSize >> 24)]; // FIXME - This is not correct code. It's optimized, but incorrect here. Fix it.
-  stopIndex      = &buffer[-(decompSize & 0xFFFFFF)];
-
-  while ( index > stopIndex ) // index > stopIndex
-  {
-    control = *(index-- - 1); // control (just scoping though)
-    for (int i=0; i<8; i++)
-    {
-      if ( control & 0x80 ) // control & 0x80
-      {
-        v13 = *(index - 1);
-        v14 = *(index - 2);
-        index -= 2;
-        v15 = ((v14 | (v13 << 8)) & 0xFFFF0FFF) + 2;
-        v16 = v13 + 32;
-        do
-        {
-          ret = compressEndOff[v15];
-          *(compressEndOff-- - 1) = ret;
-          v16 -= 16;
-        }
-        while ( !(v16 < 0) );
-      }
-      else
-      {
-        v9 = *(index-- - 1);
-        ret = v9;
-        *(compressEndOff-- - 1) = v9;
-      }
-      control *= 2;
-      if ( index <= stopIndex )
-        return ret;
-    }
-  }
-
-  return ret;
-}
-
 static Result allocate_shared_mem(prog_addrs_t *shared, prog_addrs_t *vaddr, int flags)
 {
   // Somehow, we need to allow reallocating.
diff --git a/external/loader/source/lzss.c b/external/loader/source/lzss.c
new file mode 100644 (file)
index 0000000..1b1bc0a
--- /dev/null
@@ -0,0 +1,55 @@
+#include <3ds.h>
+
+int lzss_decompress(u8 *buffer)
+{
+  // This WAS originally a decompilation in @yifan_lu's repo; it was rewritten for readability following ctrtool's namings.
+  // You can thank me for making it more readable if you'd like; I don't really care. Did it for myself.
+  unsigned int decompSize, v15;
+  u8 *compressEndOff, *index, *stopIndex;
+  char control;
+  int v9, v13, v14, v16;
+  int ret = 0;
+
+  if ( !buffer ) // Return immediately when buffer is invalid.
+    return 0;
+
+  // v1=decompressedSize, v2=compressedSize, v3=index, v4=stopIndex
+  decompSize     = *((u32 *)buffer - 2);
+  compressEndOff = &buffer[*((u32 *)buffer - 1)];
+  index          = &buffer[-(decompSize >> 24)]; // FIXME - The integer negation is due to a compiler optimization. It's probably okay, but...
+  stopIndex      = &buffer[-(decompSize & 0xFFFFFF)];
+
+  while ( index > stopIndex ) // index > stopIndex
+  {
+    control = *(index-- - 1); // control (just scoping though)
+    for (int i=0; i<8; i++)
+    {
+      if ( control & 0x80 ) // control & 0x80
+      {
+        v13 = *(index - 1);
+        v14 = *(index - 2);
+        index -= 2;
+        v15 = ((v14 | (v13 << 8)) & 0xFFFF0FFF) + 2;
+        v16 = v13 + 32;
+        do
+        {
+          ret = compressEndOff[v15];
+          *(compressEndOff-- - 1) = ret;
+          v16 -= 16;
+        }
+        while ( !(v16 < 0) );
+      }
+      else
+      {
+        v9 = *(index-- - 1);
+        ret = v9;
+        *(compressEndOff-- - 1) = v9;
+      }
+      control *= 2;
+      if ( index <= stopIndex )
+        return ret;
+    }
+  }
+
+  return ret;
+}
diff --git a/external/loader/source/lzss.h b/external/loader/source/lzss.h
new file mode 100644 (file)
index 0000000..9e99725
--- /dev/null
@@ -0,0 +1,3 @@
+#pragma once
+
+int lzss_decompress(u8 *buffer);