if (cdata >= rom.length()) { return new int[]{-8, cdata - start + 1}; }
    private static int[] _decomp(int cdata, byte[] buffer, int maxlen,        AbstractRom rom)    {        if (EbHackModule.bitrevs == null)            initBitrevs();        int start = cdata;        int bpos = 0, bpos2 = 0;        byte tmp;        while (rom.read(cdata) != 0xFF)        {            int cmdtype = rom.read(cdata) >> 5;            int len = (rom.read(cdata) & 0x1F) + 1;            if (cmdtype == 7)            {                cmdtype = (rom.read(cdata) & 0x1C) >> 2;                len = ((rom.read(cdata) & 3) << 8) + rom.read(cdata + 1) + 1;                cdata++;            }            if (bpos + len > maxlen || bpos + len < 0)                return new int[]{-1, cdata - start + 1};            cdata++;            if (cmdtype >= 4)            {                bpos2 = (rom.read(cdata) << 8) + rom.read(cdata + 1);                if (bpos2 >= maxlen || bpos2 < 0)                    return new int[]{-2, cdata - start + 1};                cdata += 2;            }            switch (cmdtype)            {                case 0: // uncompressed ?                    System.arraycopy(rom.readByte(cdata, len), 0, buffer, bpos,                        len);                    bpos += len;                    cdata += len;                    // for (int i = 0; i < len; i++)                    // {                    // buffer[bpos++] = rom.readByte(cdata++);                    // }                    break;                case 1: // RLE ?                    Arrays.fill(buffer, bpos, bpos + len, rom.readByte(cdata));                    bpos += len;                    // for (int i = 0; i < len; i++)                    // {                    // buffer[bpos++] = rom.readByte(cdata);                    // }                    cdata++;                    break;                case 2: // ??? TODO way to do this with Arrays?                    if (bpos + 2 * len > maxlen || bpos < 0)                        return new int[]{-3, cdata - start + 1};                    while (len-- != 0)                    {                        buffer[bpos++] = rom.readByte(cdata);                        buffer[bpos++] = rom.readByte(cdata + 1);                    }                    cdata += 2;                    break;                case 3: // each byte is one more than previous ?                    tmp = rom.readByte(cdata++);                    while (len-- != 0)                        buffer[bpos++] = tmp++;                    break;                case 4: // use previous data ?                    if (bpos2 + len > maxlen || bpos2 < 0)                        return new int[]{-4, cdata - start + 1};                    System.arraycopy(buffer, bpos2, buffer, bpos, len);                    bpos += len;                    // for (int i = 0; i < len; i++)                    // {                    // buffer[bpos++] = buffer[bpos2 + i];                    // }                    break;                case 5:                    if (bpos2 + len > maxlen || bpos2 < 0)                        return new int[]{-5, cdata - start + 1};                    while (len-- != 0)                    {                        // tmp = buffer[bpos2++];                        // /* reverse the bits */                        // tmp =                        // (byte) (((tmp >> 1) & 0x55) | ((tmp << 1) & 0xAA));                        // tmp =                        // (byte) (((tmp >> 2) & 0x33) | ((tmp << 2) & 0xCC));                        // tmp =                        // (byte) (((tmp >> 4) & 0x0F) | ((tmp << 4) & 0xF0));                        // buffer[bpos++] = tmp;                        buffer[bpos++] = bitrevs[buffer[bpos2++] & 0xff];                    }                    break;                case 6:                    if (bpos2 - len + 1 < 0)                        return new int[]{-6, cdata - start + 1};                    while (len-- != 0)                        buffer[bpos++] = buffer[bpos2--];                    break;                case 7:                    return new int[]{-7, cdata - start + 1};            }        }        return new int[]{bpos, cdata - start + 1};    }