Advertisement
Guest User

Untitled

a guest
Apr 3rd, 2016
303
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void Decompress(u16 *in, u16 *out, u32 size)
  2. {
  3.     u32 flag = 0x8000, jmp, len = 3;    // 3 assignment shouldn't be needed
  4.     u16 *end = &in[size];
  5.  
  6.     while (in != end)
  7.     {
  8.         // cache next 16 flags
  9.         if (flag & 0x8000) flag = (*in++ << 16) | 1;
  10.  
  11.         // not literal
  12.         if (flag & 0x80000000)
  13.         {
  14.             jmp=*in++;
  15.  
  16.             // length encoded with 5 bits?
  17.             if (jmp & 0xF800)
  18.             {
  19.                 len = jmp >> 11;
  20.                 jmp &= 0x7FF;
  21.             }
  22.             // then it's using 16 bits
  23.             else len = *in++;
  24.  
  25.             // premature end signal
  26.             if (!(jmp | len)) return;
  27.  
  28.             // zero filled RLE case when there's nowhere to jump back
  29.             if (!jmp)
  30.                 while (len > 0) *out++ = 0, len--;
  31.             // jump back & copy from output
  32.             else
  33.             {
  34.                 u16 *bp = &out[-jmp];
  35.                 while (len > 0) *out++ = *bp++, len--;
  36.             }
  37.         }
  38.         // literal, read and write as is
  39.         else *out++ = *in++;
  40.  
  41.         // next flag
  42.         flag <<= 1;
  43.     }
  44. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement