internal bool Code(int dictionarySize, LZ.OutWindow outWindow, RangeCoder.Decoder rangeDecoder)
        {
            int dictionarySizeCheck = Math.Max(dictionarySize, 1);

            outWindow.CopyPending();

            while (outWindow.HasSpace)
            {
                uint posState = (uint)outWindow.Total & m_PosStateMask;
                if (m_IsMatchDecoders[(state.Index << Base.kNumPosStatesBitsMax) + posState].Decode(rangeDecoder) == 0)
                {
                    byte b;
                    byte prevByte = outWindow.GetByte(0);
                    if (!state.IsCharState())
                        b = m_LiteralDecoder.DecodeWithMatchByte(rangeDecoder,
                            (uint)outWindow.Total, prevByte, outWindow.GetByte((int)rep0));
                    else
                        b = m_LiteralDecoder.DecodeNormal(rangeDecoder, (uint)outWindow.Total, prevByte);
                    outWindow.PutByte(b);
                    state.UpdateChar();
                }
                else
                {
                    uint len;
                    if (m_IsRepDecoders[state.Index].Decode(rangeDecoder) == 1)
                    {
                        if (m_IsRepG0Decoders[state.Index].Decode(rangeDecoder) == 0)
                        {
                            if (m_IsRep0LongDecoders[(state.Index << Base.kNumPosStatesBitsMax) + posState].Decode(rangeDecoder) == 0)
                            {
                                state.UpdateShortRep();
                                outWindow.PutByte(outWindow.GetByte((int)rep0));
                                continue;
                            }
                        }
                        else
                        {
                            UInt32 distance;
                            if (m_IsRepG1Decoders[state.Index].Decode(rangeDecoder) == 0)
                            {
                                distance = rep1;
                            }
                            else
                            {
                                if (m_IsRepG2Decoders[state.Index].Decode(rangeDecoder) == 0)
                                    distance = rep2;
                                else
                                {
                                    distance = rep3;
                                    rep3 = rep2;
                                }
                                rep2 = rep1;
                            }
                            rep1 = rep0;
                            rep0 = distance;
                        }
                        len = m_RepLenDecoder.Decode(rangeDecoder, posState) + Base.kMatchMinLen;
                        state.UpdateRep();
                    }
                    else
                    {
                        rep3 = rep2;
                        rep2 = rep1;
                        rep1 = rep0;
                        len = Base.kMatchMinLen + m_LenDecoder.Decode(rangeDecoder, posState);
                        state.UpdateMatch();
                        uint posSlot = m_PosSlotDecoder[Base.GetLenToPosState(len)].Decode(rangeDecoder);
                        if (posSlot >= Base.kStartPosModelIndex)
                        {
                            int numDirectBits = (int)((posSlot >> 1) - 1);
                            rep0 = ((2 | (posSlot & 1)) << numDirectBits);
                            if (posSlot < Base.kEndPosModelIndex)
                                rep0 += BitTreeDecoder.ReverseDecode(m_PosDecoders,
                                        rep0 - posSlot - 1, rangeDecoder, numDirectBits);
                            else
                            {
                                rep0 += (rangeDecoder.DecodeDirectBits(
                                    numDirectBits - Base.kNumAlignBits) << Base.kNumAlignBits);
                                rep0 += m_PosAlignDecoder.ReverseDecode(rangeDecoder);
                            }
                        }
                        else
                            rep0 = posSlot;
                    }
                    if (rep0 >= outWindow.Total || rep0 >= dictionarySizeCheck)
                    {
                        if (rep0 == 0xFFFFFFFF)
                            return true;
                        throw new DataErrorException();
                    }
                    outWindow.CopyBlock((int)rep0, (int)len);
                }
            }
            return false;
        }
Пример #2
0
        private string GetTokenText(string[] list, LZ.Lexer.Token token)
        {
            if (token == null) return "";

            StringBuilder sb = new StringBuilder();
            if (token.EndLocation.Y == token.Location.Y)
            {
                sb.Append(list[token.line - 1]);
            }
            else
            {
                for (int i = token.Location.Y; i < token.EndLocation.Y; i++ )
                {
                    if (i == token.EndLocation.Y - 1)
                    {
                        sb.Append(list[i]);
                    }
                    else
                    {
                        sb.Append(list[i]).Append("\n");
                    }
                }
            }
            int nLen = token.EndLocation.X - token.Location.X;
            string word = nLen <= 0 ? "" : sb.ToString().Substring(token.Location.X - 1, nLen);
            return word;
        }
Пример #3
0
        private string GetTokenText(LZ.Lexer.Token token)
        {
            if (token == null) return "";

            StringBuilder sb = new StringBuilder();
            string word = token.val;
            return word;
        }
Пример #4
0
    public Bitmap Render(GscPalette timePalette)
    {
        byte[] tiles        = Tileset.GetTiles(Game.ROM.Subarray(Blocks, Width * Height), Width);
        byte[] decompressed = LZ.Decompress(Game.ROM.From(Tileset.GFX));

        byte[] gfx = new byte[0xe00];
        Array.Copy(decompressed, 0, gfx, 0, 0x600); // vram bank 1
        if (decompressed.Length > 0x600)
        {
            Array.Copy(decompressed, 0x600, gfx, 0x800, 0x600); // optional vram bank 2
        }

        if (Tileset.Id == 1 || Tileset.Id == 2 || Tileset.Id == 4)
        {
            // Load map group specific roof tiles.
            byte roofIndex = Game.ROM[Game.SYM["MapGroupRoofs"] + Group];
            if (roofIndex != 0xff)
            {
                Array.Copy(Game.ROM.Data, Game.SYM["Roofs"] + roofIndex * 0x90, gfx, 0xa0, 0x90);
            }
        }

        int timeOffset = 0;

        switch (timePalette)
        {
        case GscPalette.Morn: timeOffset = 0; break;

        case GscPalette.Auto:     // TODO: Don't always default to day time?
        case GscPalette.Day: timeOffset = 1; break;

        case GscPalette.Nite: timeOffset = 2; break;

        case GscPalette.Dark: timeOffset = 3; break;
        }

        byte palMapBank;

        if (Game.IsCrystal)
        {
            palMapBank = 0x13;
        }
        else
        {
            palMapBank = 0x02;
        }

        byte[] pixels = new byte[tiles.Length * 16];
        byte[] palMap = new byte[tiles.Length];

        for (int i = 0; i < tiles.Length; i++)
        {
            byte tile = tiles[i];
            Array.Copy(gfx, tile * 16, pixels, i * 16, 16);

            int  bankOffset = tile > 0x60 ? 0x20 : 0;
            byte palType    = Game.ROM[(palMapBank << 16 | Tileset.PalMap) + (tile + bankOffset) / 2];
            if ((tile & 1) == 0)
            {
                palType &= 0xf;
            }
            else
            {
                palType >>= 4;
            }

            palMap[i] = Game.ROM[EnvironmentColorPointer + timeOffset * 8 + palType];
        }

        ushort[] bgPalData   = Game.ROM.From("TilesetBGPalette").ReadLE(168);
        ushort[] roofPalData = Game.ROM.From(Game.SYM["RoofPals"] + Group * 8).ReadLE(4);
        Array.Copy(roofPalData, 0, bgPalData, 6 * 4 + 1, 2);
        Array.Copy(roofPalData, 0, bgPalData, 14 * 4 + 1, 2);
        Array.Copy(roofPalData, 2, bgPalData, 22 * 4 + 1, 2);

        byte[][][] bgPal = new byte[42][][];
        for (int i = 0; i < bgPal.Length; i++)
        {
            bgPal[i] = new byte[4][];
            for (int j = 0; j < 4; j++)
            {
                bgPal[i][j] = new byte[3];

                ushort val = bgPalData[i * 4 + j];
                bgPal[i][j][0] = (byte)(((val) & 0x1f) << 3);
                bgPal[i][j][1] = (byte)(((val >> 5) & 0x1f) << 3);
                bgPal[i][j][2] = (byte)(((val >> 10) & 0x1f) << 3);
            }
        }

        Bitmap bitmap = new Bitmap(Width * 2 * 2 * 8, Height * 2 * 2 * 8);

        bitmap.Unpack2BPP(pixels, bgPal, palMap);
        return(bitmap);
    }
Пример #5
0
 public Comment(LZ.Lexer.CommentType commentType, string comment, Point startPosition, Point endPosition) : base(startPosition, endPosition)
 {
     this.commentType = commentType;
     this.comment = comment;
 }
Пример #6
0
		void InitMatchFinder(LZ.IMatchFinder matchFinder)
		{
			_matchFinder = matchFinder;
		}