Path: blob/main/misc/emulator/xnes/snes9x/jma/lzma.h
28798 views
/*1Copyright (C) 2005-2006 NSRT Team ( http://nsrt.edgeemu.com )2Copyright (C) 2002 Andrea Mazzoleni ( http://advancemame.sf.net )3Copyright (C) 2001-4 Igor Pavlov ( http://www.7-zip.org )45This library is free software; you can redistribute it and/or6modify it under the terms of the GNU Lesser General Public7License version 2.1 as published by the Free Software Foundation.89This library is distributed in the hope that it will be useful,10but WITHOUT ANY WARRANTY; without even the implied warranty of11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU12Lesser General Public License for more details.1314You should have received a copy of the GNU Lesser General Public15License along with this library; if not, write to the Free Software16Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA17*/1819#include "lencoder.h"2021#ifndef __LZMA_H22#define __LZMA_H2324namespace NCompress {25namespace NLZMA {2627const UINT32 kNumRepDistances = 4;2829const BYTE kNumStates = 12;3031const BYTE kLiteralNextStates[kNumStates] = {0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 4, 5};32const BYTE kMatchNextStates[kNumStates] = {7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10};33const BYTE kRepNextStates[kNumStates] = {8, 8, 8, 8, 8, 8, 8, 11, 11, 11, 11, 11};34const BYTE kShortRepNextStates[kNumStates]= {9, 9, 9, 9, 9, 9, 9, 11, 11, 11, 11, 11};3536class CState37{38public:39BYTE m_Index;40void Init()41{ m_Index = 0; }42void UpdateChar()43{ m_Index = kLiteralNextStates[m_Index]; }44void UpdateMatch()45{ m_Index = kMatchNextStates[m_Index]; }46void UpdateRep()47{ m_Index = kRepNextStates[m_Index]; }48void UpdateShortRep()49{ m_Index = kShortRepNextStates[m_Index]; }50};5152class CBaseCoder53{54protected:55CState m_State;56BYTE m_PreviousByte;57bool m_PeviousIsMatch;58UINT32 m_RepDistances[kNumRepDistances];59void Init()60{61m_State.Init();62m_PreviousByte = 0;63m_PeviousIsMatch = false;64for(UINT32 i = 0 ; i < kNumRepDistances; i++)65m_RepDistances[i] = 0;66}67};6869const int kNumPosSlotBits = 6;70const int kDicLogSizeMax = 28;71const int kDistTableSizeMax = kDicLogSizeMax * 2;7273extern UINT32 kDistStart[kDistTableSizeMax];74const BYTE kDistDirectBits[kDistTableSizeMax] =75{760, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,7710, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19,7820, 20, 21, 21, 22, 22, 23, 23, 24, 24, 25, 25, 26, 2679};8081const UINT32 kNumLenToPosStates = 4;82inline UINT32 GetLenToPosState(UINT32 aLen)83{84aLen -= 2;85if (aLen < kNumLenToPosStates)86return aLen;87return kNumLenToPosStates - 1;88}8990const int kMatchMinLen = 2;9192const int kMatchMaxLen = kMatchMinLen + NLength::kNumSymbolsTotal - 1;9394const int kNumAlignBits = 4;95const int kAlignTableSize = 1 << kNumAlignBits;96const UINT32 kAlignMask = (kAlignTableSize - 1);9798const int kStartPosModelIndex = 4;99const int kEndPosModelIndex = 14;100const int kNumPosModels = kEndPosModelIndex - kStartPosModelIndex;101102const int kNumFullDistances = 1 << (kEndPosModelIndex / 2);103104105const int kMainChoiceLiteralIndex = 0;106const int kMainChoiceMatchIndex = 1;107108const int kMatchChoiceDistanceIndex= 0;109const int kMatchChoiceRepetitionIndex = 1;110111const int kNumMoveBitsForMainChoice = 5;112const int kNumMoveBitsForPosCoders = 5;113114const int kNumMoveBitsForAlignCoders = 5;115116const int kNumMoveBitsForPosSlotCoder = 5;117118const int kNumLitPosStatesBitsEncodingMax = 4;119const int kNumLitContextBitsMax = 8;120121}}122123#endif124125126