misc/libphysfs/lzma/C/Compress/Branch/BranchPPC.c
changeset 13904 99b265e0d1d0
parent 13903 5f819b90d479
child 13905 b172a5d40eee
equal deleted inserted replaced
13903:5f819b90d479 13904:99b265e0d1d0
     1 /* BranchPPC.c */
       
     2 
       
     3 #include "BranchPPC.h"
       
     4 
       
     5 UInt32 PPC_B_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding)
       
     6 {
       
     7   UInt32 i;
       
     8   for (i = 0; i + 4 <= size; i += 4)
       
     9   {
       
    10     /* PowerPC branch 6(48) 24(Offset) 1(Abs) 1(Link) */
       
    11     if ((data[i] >> 2) == 0x12 && 
       
    12     (
       
    13       (data[i + 3] & 3) == 1 
       
    14       /* || (data[i+3] & 3) == 3 */
       
    15       )
       
    16     )
       
    17     {
       
    18       UInt32 src = ((data[i + 0] & 3) << 24) |
       
    19         (data[i + 1] << 16) |
       
    20         (data[i + 2] << 8) |
       
    21         (data[i + 3] & (~3));
       
    22       
       
    23       UInt32 dest;
       
    24       if (encoding)
       
    25         dest = nowPos + i + src;
       
    26       else
       
    27         dest = src - (nowPos + i);
       
    28       data[i + 0] = (Byte)(0x48 | ((dest >> 24) &  0x3));
       
    29       data[i + 1] = (Byte)(dest >> 16);
       
    30       data[i + 2] = (Byte)(dest >> 8);
       
    31       data[i + 3] &= 0x3;
       
    32       data[i + 3] |= dest;
       
    33     }
       
    34   }
       
    35   return i;
       
    36 }