source += (treeSize+1)<<1;
source += ((treeSize+1)<<1)-1;
void BIOS_HuffUnComp(){#ifdef DEV_VERSION  if(systemVerbose & VERBOSE_SWI) {    log("HuffUnComp: 0x%08x,0x%08x (VCOUNT=%d)\n",        reg[0].I,        reg[1].I,        VCOUNT);  }#endif    u32 source = reg[0].I;  u32 dest = reg[1].I;  u32 header = CPUReadMemory(source);  source += 4;  if(((source & 0xe000000) == 0) ||     ((source + ((header >> 8) & 0x1fffff)) & 0xe000000) == 0)    return;      u8 treeSize = CPUReadByte(source++);  u32 treeStart = source;  source += (treeSize+1)<<1;    int len = header >> 8;  u32 mask = 0x80000000;  u32 data = CPUReadMemory(source);  source += 4;  int pos = 0;  u8 rootNode = CPUReadByte(treeStart);  u8 currentNode = rootNode;  bool writeData = false;  int byteShift = 0;  int byteCount = 0;  u32 writeValue = 0;  if((header & 0x0F) == 8) {    while(len > 0) {      // take left      if(pos == 0)        pos++;      else        pos += (((currentNode & 0x3F)+1)<<1);            if(data & mask) {        // right        if(currentNode & 0x40)          writeData = true;        currentNode = CPUReadByte(treeStart+pos+1);      } else {        // left        if(currentNode & 0x80)          writeData = true;        currentNode = CPUReadByte(treeStart+pos);      }            if(writeData) {        writeValue |= (currentNode << byteShift);        byteCount++;        byteShift += 8;        pos = 0;        currentNode = rootNode;        writeData = false;        if(byteCount == 4) {          byteCount = 0;          byteShift = 0;          CPUWriteMemory(dest, writeValue);          writeValue = 0;          dest += 4;          len -= 4;        }      }      mask >>= 1;      if(mask == 0) {        mask = 0x80000000;        data = CPUReadMemory(source);        source += 4;      }    }  } else {    int halfLen = 0;    int value = 0;    while(len > 0) {      // take left      if(pos == 0)        pos++;      else        pos += (((currentNode & 0x3F)+1)<<1);      if((data & mask)) {        // right        if(currentNode & 0x40)          writeData = true;        currentNode = CPUReadByte(treeStart+pos+1);      } else {        // left        if(currentNode & 0x80)          writeData = true;        currentNode = CPUReadByte(treeStart+pos);      }            if(writeData) {        if(halfLen == 0)          value |= currentNode;        else          value |= (currentNode<<4);        halfLen += 4;        if(halfLen == 8) {          writeValue |= (value << byteShift);          byteCount++;          byteShift += 8;                    halfLen = 0;          value = 0;          if(byteCount == 4) {            byteCount = 0;            byteShift = 0;            CPUWriteMemory(dest, writeValue);            dest += 4;            writeValue = 0;            len -= 4;          }        }        pos = 0;        currentNode = rootNode;        writeData = false;      }      mask >>= 1;      if(mask == 0) {        mask = 0x80000000;        data = CPUReadMemory(source);        source += 4;      }    }      }}