templeos-info/public/Wb/Kernel/Compress.HC.HTML

340 lines
34 KiB
Plaintext
Raw Normal View History

2024-03-24 21:24:44 +00:00
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="generator" content="TempleOS V5.03">
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="/style/templeos.css">
<script src="/script/templeos.js"></script>
<style type="text/css">
.cF0{color:#000000;background-color:#ffffff;}
.cF1{color:#0000aa;background-color:#ffffff;}
.cF2{color:#00aa00;background-color:#ffffff;}
.cF3{color:#00aaaa;background-color:#ffffff;}
.cF4{color:#aa0000;background-color:#ffffff;}
.cF5{color:#aa00aa;background-color:#ffffff;}
.cF6{color:#aa5500;background-color:#ffffff;}
.cF7{color:#aaaaaa;background-color:#ffffff;}
.cF8{color:#555555;background-color:#ffffff;}
.cF9{color:#5555ff;background-color:#ffffff;}
.cFA{color:#55ff55;background-color:#ffffff;}
.cFB{color:#55ffff;background-color:#ffffff;}
.cFC{color:#ff5555;background-color:#ffffff;}
.cFD{color:#ff55ff;background-color:#ffffff;}
.cFE{color:#ffff55;background-color:#ffffff;}
.cFF{color:#ffffff;background-color:#ffffff;}
</style>
</head>
<body>
<pre id="content">
<a name="l1"></a><span class=cF2>//See </span><a href="/Wb/Doc/Credits.DD.HTML#l1"><span class=cF4>::/Doc/Credits.DD</span></a><span class=cF2>.</span><span class=cF0>
<a name="l2"></a></span><span class=cF2>//See </span><a href="/Wb/Kernel/KernelA.HH.HTML#l3716"><span class=cF4>CArcCompress</span></a><span class=cF2>, </span><a href="/Wb/Kernel/KernelA.HH.HTML#l3690"><span class=cF4>CArcEntry</span></a><span class=cF2>, and </span><a href="/Wb/Kernel/KernelA.HH.HTML#l3698"><span class=cF4>CArcCtrl</span></a><span class=cF0>
<a name="l3"></a>
<a name="l4"></a></span><span class=cF1>asm</span><span class=cF0> {
<a name="l5"></a></span><span class=cF2>/****</span><span class=cF0>
<a name="l6"></a></span><span class=cF2>U0 ArcEntryGet(CArcCtrl *c)</span><span class=cF0>
<a name="l7"></a></span><span class=cF2>{</span><span class=cF0>
<a name="l8"></a></span><span class=cF2> I64 i;</span><span class=cF0>
<a name="l9"></a></span><span class=cF2> CArcEntry *tmp,*tmp1;</span><span class=cF0>
<a name="l10"></a>
<a name="l11"></a></span><span class=cF2> if (c-&gt;entry_used) {</span><span class=cF0>
<a name="l12"></a></span><span class=cF2> i=c-&gt;free_idx;</span><span class=cF0>
<a name="l13"></a>
<a name="l14"></a></span><span class=cF2> c-&gt;entry_used=FALSE;</span><span class=cF0>
<a name="l15"></a></span><span class=cF2> c-&gt;cur_entry=c-&gt;next_entry;</span><span class=cF0>
<a name="l16"></a></span><span class=cF2> c-&gt;cur_bits_in_use=c-&gt;next_bits_in_use;</span><span class=cF0>
<a name="l17"></a></span><span class=cF2> if (c-&gt;next_bits_in_use&lt;ARC_BITS_MAX) {</span><span class=cF0>
<a name="l18"></a></span><span class=cF2> c-&gt;next_entry = &amp;c-&gt;compress[i++];</span><span class=cF0>
<a name="l19"></a></span><span class=cF2> if (i==c-&gt;free_limit) {</span><span class=cF0>
<a name="l20"></a> </span><span class=cF2>c-&gt;next_bits_in_use++;</span><span class=cF0>
<a name="l21"></a> </span><span class=cF2>c-&gt;free_limit=1&lt;&lt;c-&gt;next_bits_in_use;</span><span class=cF0>
<a name="l22"></a></span><span class=cF2> }</span><span class=cF0>
<a name="l23"></a></span><span class=cF2> } else {</span><span class=cF0>
<a name="l24"></a></span><span class=cF2> do if (++i==c-&gt;free_limit)</span><span class=cF0>
<a name="l25"></a> </span><span class=cF2> i=c-&gt;min_table_entry;</span><span class=cF0>
<a name="l26"></a></span><span class=cF2> while (c-&gt;hash[i]);</span><span class=cF0>
<a name="l27"></a></span><span class=cF2> tmp=&amp;c-&gt;compress[i];</span><span class=cF0>
<a name="l28"></a></span><span class=cF2> c-&gt;next_entry=tmp;</span><span class=cF0>
<a name="l29"></a></span><span class=cF2> tmp1=&amp;c-&gt;hash[tmp-&gt;basecode];</span><span class=cF0>
<a name="l30"></a></span><span class=cF2> while (tmp1) {</span><span class=cF0>
<a name="l31"></a> </span><span class=cF2>if (tmp1-&gt;next==tmp) {</span><span class=cF0>
<a name="l32"></a> </span><span class=cF2> tmp1-&gt;next=tmp-&gt;next;</span><span class=cF0>
<a name="l33"></a> </span><span class=cF2> break;</span><span class=cF0>
<a name="l34"></a> </span><span class=cF2>} else</span><span class=cF0>
<a name="l35"></a> </span><span class=cF2> tmp1=tmp1-&gt;next;</span><span class=cF0>
<a name="l36"></a></span><span class=cF2> }</span><span class=cF0>
<a name="l37"></a></span><span class=cF2> }</span><span class=cF0>
<a name="l38"></a></span><span class=cF2> c-&gt;free_idx=i;</span><span class=cF0>
<a name="l39"></a></span><span class=cF2> }</span><span class=cF0>
<a name="l40"></a></span><span class=cF2>}</span><span class=cF0>
<a name="l41"></a></span><span class=cF2>****/</span><span class=cF0>
<a name="l42"></a></span><span class=cFD>_ARC_ENTRY_GET</span><span class=cF0>::
<a name="l43"></a> </span><span class=cF1>PUSH</span><span class=cF0> </span><span class=cFC>RBP</span><span class=cF0>
<a name="l44"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cFC>RBP</span><span class=cF0>,</span><span class=cFC>RSP</span><span class=cF0>
<a name="l45"></a> </span><span class=cF1>PUSH</span><span class=cF0> </span><span class=cFC>RSI</span><span class=cF0>
<a name="l46"></a> </span><span class=cF1>PUSH</span><span class=cF0> </span><span class=cFC>RDI</span><span class=cF0>
<a name="l47"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cFC>RSI</span><span class=cF0>,</span><span class=cF9>U64</span><span class=cF0> </span><span class=cF3>SF_ARG1</span><span class=cF0>[</span><span class=cFC>RBP</span><span class=cF0>]
<a name="l48"></a> </span><span class=cF1>BTR</span><span class=cF0> </span><span class=cF9>U64</span><span class=cF0> </span><span class=cF9>CArcCtrl</span><span class=cF0>.entry_used[</span><span class=cFC>RSI</span><span class=cF0>],0
<a name="l49"></a> </span><span class=cF1>JNC</span><span class=cF0> </span><span class=cF9>I32</span><span class=cF0> @@30
<a name="l50"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cFC>RDX</span><span class=cF0>,</span><span class=cF9>U64</span><span class=cF0> </span><span class=cF9>CArcCtrl</span><span class=cF0>.free_idx[</span><span class=cFC>RSI</span><span class=cF0>]
<a name="l51"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cFC>RAX</span><span class=cF0>,</span><span class=cF9>U64</span><span class=cF0> </span><span class=cF9>CArcCtrl</span><span class=cF0>.next_entry[</span><span class=cFC>RSI</span><span class=cF0>]
<a name="l52"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cF9>U64</span><span class=cF0> </span><span class=cF9>CArcCtrl</span><span class=cF0>.cur_entry[</span><span class=cFC>RSI</span><span class=cF0>],</span><span class=cFC>RAX</span><span class=cF0>
<a name="l53"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cFC>RCX</span><span class=cF0>,</span><span class=cF9>U64</span><span class=cF0> </span><span class=cF9>CArcCtrl</span><span class=cF0>.next_bits_in_use[</span><span class=cFC>RSI</span><span class=cF0>]
<a name="l54"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cF9>U64</span><span class=cF0> </span><span class=cF9>CArcCtrl</span><span class=cF0>.cur_bits_in_use[</span><span class=cFC>RSI</span><span class=cF0>],</span><span class=cFC>RCX</span><span class=cF0>
<a name="l55"></a> </span><span class=cF1>CMP</span><span class=cF0> </span><span class=cFC>RCX</span><span class=cF0>,</span><span class=cF3>ARC_BITS_MAX</span><span class=cF0>
<a name="l56"></a> </span><span class=cF1>JAE</span><span class=cF0> @@05
<a name="l57"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cFC>RAX</span><span class=cF0>,</span><span class=cFC>RDX</span><span class=cF0>
<a name="l58"></a> </span><span class=cF1>SHL</span><span class=cF0> </span><span class=cFC>RAX</span><span class=cF0>,4
<a name="l59"></a> </span><span class=cF1>LEA</span><span class=cF0> </span><span class=cFC>RAX</span><span class=cF0>,</span><span class=cF9>U64</span><span class=cF0> </span><span class=cF9>CArcCtrl</span><span class=cF0>.compress[</span><span class=cFC>RSI</span><span class=cF0>+</span><span class=cFC>RAX</span><span class=cF0>]
<a name="l60"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cF9>U64</span><span class=cF0> </span><span class=cF9>CArcCtrl</span><span class=cF0>.next_entry[</span><span class=cFC>RSI</span><span class=cF0>],</span><span class=cFC>RAX</span><span class=cF0>
<a name="l61"></a> </span><span class=cF1>INC</span><span class=cF0> </span><span class=cFC>RDX</span><span class=cF0>
<a name="l62"></a> </span><span class=cF1>CMP</span><span class=cF0> </span><span class=cF9>U64</span><span class=cF0> </span><span class=cF9>CArcCtrl</span><span class=cF0>.free_limit[</span><span class=cFC>RSI</span><span class=cF0>],</span><span class=cFC>RDX</span><span class=cF0>
<a name="l63"></a> </span><span class=cF1>JNE</span><span class=cF0> @@25
<a name="l64"></a> </span><span class=cF1>INC</span><span class=cF0> </span><span class=cFC>RCX</span><span class=cF0>
<a name="l65"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cF9>U64</span><span class=cF0> </span><span class=cF9>CArcCtrl</span><span class=cF0>.next_bits_in_use[</span><span class=cFC>RSI</span><span class=cF0>],</span><span class=cFC>RCX</span><span class=cF0>
<a name="l66"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cFC>RAX</span><span class=cF0>,1
<a name="l67"></a> </span><span class=cF1>SHL</span><span class=cF0> </span><span class=cFC>RAX</span><span class=cF0>,</span><span class=cFC>CL</span><span class=cF0>
<a name="l68"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cF9>U64</span><span class=cF0> </span><span class=cF9>CArcCtrl</span><span class=cF0>.free_limit[</span><span class=cFC>RSI</span><span class=cF0>],</span><span class=cFC>RAX</span><span class=cF0>
<a name="l69"></a> </span><span class=cF1>JMP</span><span class=cF0> @@25
<a name="l70"></a>@@05: </span><span class=cF1>INC</span><span class=cF0> </span><span class=cFC>RDX</span><span class=cF0>
<a name="l71"></a> </span><span class=cF1>CMP</span><span class=cF0> </span><span class=cF9>U64</span><span class=cF0> </span><span class=cF9>CArcCtrl</span><span class=cF0>.free_limit[</span><span class=cFC>RSI</span><span class=cF0>],</span><span class=cFC>RDX</span><span class=cF0>
<a name="l72"></a> </span><span class=cF1>JNE</span><span class=cF0> @@10
<a name="l73"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cFC>RDX</span><span class=cF0>,</span><span class=cF9>U64</span><span class=cF0> </span><span class=cF9>CArcCtrl</span><span class=cF0>.min_table_entry[</span><span class=cFC>RSI</span><span class=cF0>]
<a name="l74"></a>@@10: </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cFC>RAX</span><span class=cF0>,</span><span class=cF9>U64</span><span class=cF0> </span><span class=cF9>CArcCtrl</span><span class=cF0>.hash[</span><span class=cFC>RSI</span><span class=cF0>+</span><span class=cFC>RDX</span><span class=cF0>*8]
<a name="l75"></a> </span><span class=cF1>TEST</span><span class=cF0> </span><span class=cFC>RAX</span><span class=cF0>,</span><span class=cFC>RAX</span><span class=cF0>
<a name="l76"></a> </span><span class=cF1>JNZ</span><span class=cF0> @@05
<a name="l77"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cFC>RDI</span><span class=cF0>,</span><span class=cFC>RDX</span><span class=cF0>
<a name="l78"></a> </span><span class=cF1>SHL</span><span class=cF0> </span><span class=cFC>RDI</span><span class=cF0>,4
<a name="l79"></a> </span><span class=cF1>LEA</span><span class=cF0> </span><span class=cFC>RDI</span><span class=cF0>,</span><span class=cF9>U64</span><span class=cF0> </span><span class=cF9>CArcCtrl</span><span class=cF0>.compress[</span><span class=cFC>RSI</span><span class=cF0>+</span><span class=cFC>RDI</span><span class=cF0>]
<a name="l80"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cF9>U32</span><span class=cF0> </span><span class=cF9>CArcCtrl</span><span class=cF0>.next_entry[</span><span class=cFC>RSI</span><span class=cF0>],</span><span class=cFC>EDI</span><span class=cF0>
<a name="l81"></a> </span><span class=cF1>MOVZX</span><span class=cF0> </span><span class=cFC>RBX</span><span class=cF0>,</span><span class=cF9>U16</span><span class=cF0> </span><span class=cF9>CArcEntry</span><span class=cF0>.basecode[</span><span class=cFC>RDI</span><span class=cF0>]
<a name="l82"></a> </span><span class=cF1>LEA</span><span class=cF0> </span><span class=cFC>RCX</span><span class=cF0>,</span><span class=cF9>U64</span><span class=cF0> </span><span class=cF9>CArcCtrl</span><span class=cF0>.hash[</span><span class=cFC>RSI</span><span class=cF0>+</span><span class=cFC>RBX</span><span class=cF0>*8]
<a name="l83"></a>@@15: </span><span class=cF1>TEST</span><span class=cF0> </span><span class=cFC>RCX</span><span class=cF0>,</span><span class=cFC>RCX</span><span class=cF0>
<a name="l84"></a> </span><span class=cF1>JZ</span><span class=cF0> @@25
<a name="l85"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cFC>RAX</span><span class=cF0>,</span><span class=cF9>U64</span><span class=cF0> </span><span class=cF9>CArcEntry</span><span class=cF0>.next[</span><span class=cFC>RCX</span><span class=cF0>]
<a name="l86"></a> </span><span class=cF1>CMP</span><span class=cF0> </span><span class=cFC>RDI</span><span class=cF0>,</span><span class=cFC>RAX</span><span class=cF0>
<a name="l87"></a> </span><span class=cF1>JNE</span><span class=cF0> @@20
<a name="l88"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cFC>RAX</span><span class=cF0>,</span><span class=cF9>U64</span><span class=cF0> </span><span class=cF9>CArcEntry</span><span class=cF0>.next[</span><span class=cFC>RDI</span><span class=cF0>]
<a name="l89"></a> </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cF9>U64</span><span class=cF0> </span><span class=cF9>CArcEntry</span><span class=cF0>.next[</span><span class=cFC>RCX</span><span class=cF0>],</span><span class=cFC>RAX</span><span class=cF0>
<a name="l90"></a> </span><span class=cF1>JMP</span><span class=cF0> @@25
<a name="l91"></a>@@20: </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cFC>RCX</span><span class=cF0>,</span><span class=cFC>RAX</span><span class=cF0>
<a name="l92"></a> </span><span class=cF1>JMP</span><span class=cF0> @@15
<a name="l93"></a>@@25: </span><span class=cF1>MOV</span><span class=cF0> </span><span class=cF9>U64</span><span class=cF0> </span><span class=cF9>CArcCtrl</span><span class=cF0>.free_idx[</span><span class=cFC>RSI</span><span class=cF0>],</span><span class=cFC>RDX</span><span class=cF0>
<a name="l94"></a>@@30: </span><span class=cF1>POP</span><span class=cF0> </span><span class=cFC>RDI</span><span class=cF0>
<a name="l95"></a> </span><span class=cF1>POP</span><span class=cF0> </span><span class=cFC>RSI</span><span class=cF0>
<a name="l96"></a> </span><span class=cF1>POP</span><span class=cF0> </span><span class=cFC>RBP</span><span class=cF0>
<a name="l97"></a> </span><span class=cF1>RET1</span><span class=cF0> 8
<a name="l98"></a>}
<a name="l99"></a>
<a name="l100"></a></span><span class=cF1>_extern</span><span class=cF0> </span><span class=cFD>_ARC_ENTRY_GET</span><span class=cF0> </span><span class=cF1>U0</span><span class=cF0> ArcEntryGet(</span><span class=cF9>CArcCtrl</span><span class=cF0> *c);
<a name="l101"></a>
<a name="l102"></a></span><span class=cF9>I64</span><span class=cF0> </span><span class=cFD>ArcDetermineCompressionType</span><span class=cF0>(</span><span class=cF1>U8</span><span class=cF0> *src,</span><span class=cF9>I64</span><span class=cF0> size)
<a name="l103"></a>{
<a name="l104"></a> </span><span class=cF1>while</span><span class=cF0> (size--)
<a name="l105"></a> </span><span class=cF1>if</span><span class=cF0> (*src++&amp;0x80)
<a name="l106"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>CT_8_BIT</span><span class=cF0>;
<a name="l107"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>CT_7_BIT</span><span class=cF0>;
<a name="l108"></a>}
<a name="l109"></a>
<a name="l110"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>ArcCompressBuf</span><span class=cF0>(</span><span class=cF9>CArcCtrl</span><span class=cF0> *c)
<a name="l111"></a>{</span><span class=cF2>//Use </span><a href="/Wb/Kernel/Compress.HC.HTML#l281"><span class=cF4>CompressBuf</span></a><span class=cF2>() unless doing more than one buf.</span><span class=cF0>
<a name="l112"></a> </span><span class=cF9>CArcEntry</span><span class=cF0> *tmp,*tmp1;
<a name="l113"></a> </span><span class=cF9>I64</span><span class=cF0> ch,basecode;
<a name="l114"></a> </span><span class=cF1>U8</span><span class=cF0> *src_ptr,*src_limit;
<a name="l115"></a>
<a name="l116"></a> src_ptr=c-&gt;src_buf+c-&gt;src_pos;
<a name="l117"></a> src_limit=c-&gt;src_buf+c-&gt;src_size;
<a name="l118"></a>
<a name="l119"></a> </span><span class=cF1>if</span><span class=cF0> (c-&gt;saved_basecode==</span><span class=cF3>U32_MAX</span><span class=cF0>)
<a name="l120"></a> basecode=*src_ptr++;
<a name="l121"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l122"></a> basecode=c-&gt;saved_basecode;
<a name="l123"></a>
<a name="l124"></a> </span><span class=cF1>while</span><span class=cF0> (src_ptr&lt;src_limit &amp;&amp; c-&gt;dst_pos+c-&gt;cur_bits_in_use&lt;=c-&gt;dst_size) </span><span class=cF7>{</span><span class=cF0>
<a name="l125"></a> ArcEntryGet(c);
<a name="l126"></a>ac_start:
<a name="l127"></a> </span><span class=cF1>if</span><span class=cF0> (src_ptr&gt;=src_limit) </span><span class=cF1>goto</span><span class=cF0> ac_done;
<a name="l128"></a> ch=*src_ptr++;
<a name="l129"></a> </span><span class=cF1>if</span><span class=cF0> (tmp=c-&gt;hash[basecode])
<a name="l130"></a> </span><span class=cF1>do</span><span class=cF0> {
<a name="l131"></a> </span><span class=cF1>if</span><span class=cF0> (tmp-&gt;ch==ch) </span><span class=cF7>{</span><span class=cF0>
<a name="l132"></a> basecode=tmp-&amp;c-&gt;compress[0];
<a name="l133"></a> </span><span class=cF1>goto</span><span class=cF0> ac_start;
<a name="l134"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l135"></a> } </span><span class=cF1>while</span><span class=cF0> (tmp=tmp-&gt;next);
<a name="l136"></a>
<a name="l137"></a> </span><span class=cF5>BFieldOrU32</span><span class=cF0>(c-&gt;dst_buf,c-&gt;dst_pos,basecode);
<a name="l138"></a> c-&gt;dst_pos+=c-&gt;cur_bits_in_use;
<a name="l139"></a>
<a name="l140"></a> c-&gt;entry_used=</span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l141"></a> tmp=c-&gt;cur_entry;
<a name="l142"></a> tmp-&gt;basecode=basecode;
<a name="l143"></a> tmp-&gt;ch=ch;
<a name="l144"></a> tmp1=&amp;c-&gt;hash[basecode];
<a name="l145"></a> tmp-&gt;next=tmp1-&gt;next;
<a name="l146"></a> tmp1-&gt;next=tmp;
<a name="l147"></a>
<a name="l148"></a> basecode=ch;
<a name="l149"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l150"></a>ac_done:
<a name="l151"></a> c-&gt;saved_basecode=basecode;
<a name="l152"></a> c-&gt;src_pos=src_ptr-c-&gt;src_buf;
<a name="l153"></a>}
<a name="l154"></a>
<a name="l155"></a></span><span class=cF1>Bool</span><span class=cF0> </span><span class=cF5>ArcFinishCompression</span><span class=cF0>(</span><span class=cF9>CArcCtrl</span><span class=cF0> *c)
<a name="l156"></a>{</span><span class=cF2>//Do closing touch on archivew ctrl struct.</span><span class=cF0>
<a name="l157"></a> </span><span class=cF1>if</span><span class=cF0> (c-&gt;dst_pos+c-&gt;cur_bits_in_use&lt;=c-&gt;dst_size) </span><span class=cF7>{</span><span class=cF0>
<a name="l158"></a> </span><span class=cF5>BFieldOrU32</span><span class=cF0>(c-&gt;dst_buf,c-&gt;dst_pos,c-&gt;saved_basecode);
<a name="l159"></a> c-&gt;dst_pos+=c-&gt;next_bits_in_use;
<a name="l160"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l161"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>else</span><span class=cF0>
<a name="l162"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l163"></a>}
<a name="l164"></a>
<a name="l165"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>ArcExpandBuf</span><span class=cF0>(</span><span class=cF9>CArcCtrl</span><span class=cF0> *c)
<a name="l166"></a>{</span><span class=cF2>//Use </span><a href="/Wb/Kernel/Compress.HC.HTML#l250"><span class=cF4>ExpandBuf</span></a><span class=cF2>() unless you know what you're doing.</span><span class=cF0>
<a name="l167"></a> </span><span class=cF1>U8</span><span class=cF0> *dst_ptr,*dst_limit;
<a name="l168"></a> </span><span class=cF9>I64</span><span class=cF0> basecode,lastcode,code;
<a name="l169"></a> </span><span class=cF9>CArcEntry</span><span class=cF0> *tmp,*tmp1;
<a name="l170"></a>
<a name="l171"></a> dst_ptr=c-&gt;dst_buf+c-&gt;dst_pos;
<a name="l172"></a> dst_limit=c-&gt;dst_buf+c-&gt;dst_size;
<a name="l173"></a>
<a name="l174"></a> </span><span class=cF1>while</span><span class=cF0> (dst_ptr&lt;dst_limit &amp;&amp; c-&gt;stk_ptr!=c-&gt;stk_base)
<a name="l175"></a> *dst_ptr++ = * -- c-&gt;stk_ptr;
<a name="l176"></a>
<a name="l177"></a> </span><span class=cF1>if</span><span class=cF0> (c-&gt;stk_ptr==c-&gt;stk_base &amp;&amp; dst_ptr&lt;dst_limit) </span><span class=cF7>{</span><span class=cF0>
<a name="l178"></a> </span><span class=cF1>if</span><span class=cF0> (c-&gt;saved_basecode==</span><span class=cF3>U32_MAX</span><span class=cF0>) {
<a name="l179"></a> lastcode=</span><span class=cF5>BFieldExtU32</span><span class=cF0>(c-&gt;src_buf,c-&gt;src_pos,
<a name="l180"></a> c-&gt;next_bits_in_use);
<a name="l181"></a> c-&gt;src_pos+=c-&gt;next_bits_in_use;
<a name="l182"></a> *dst_ptr++=lastcode;
<a name="l183"></a> ArcEntryGet(c);
<a name="l184"></a> c-&gt;last_ch=lastcode;
<a name="l185"></a> } </span><span class=cF1>else</span><span class=cF0>
<a name="l186"></a> lastcode=c-&gt;saved_basecode;
<a name="l187"></a> </span><span class=cF1>while</span><span class=cF0> (dst_ptr&lt;dst_limit &amp;&amp; c-&gt;src_pos+c-&gt;next_bits_in_use&lt;=c-&gt;src_size) {
<a name="l188"></a> basecode=</span><span class=cF5>BFieldExtU32</span><span class=cF0>(c-&gt;src_buf,c-&gt;src_pos,
<a name="l189"></a> c-&gt;next_bits_in_use);
<a name="l190"></a> c-&gt;src_pos+=c-&gt;next_bits_in_use;
<a name="l191"></a> </span><span class=cF1>if</span><span class=cF0> (c-&gt;cur_entry==&amp;c-&gt;compress[basecode]) </span><span class=cF7>{</span><span class=cF0>
<a name="l192"></a> *c-&gt;stk_ptr++=c-&gt;last_ch;
<a name="l193"></a> code=lastcode;
<a name="l194"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>else</span><span class=cF0>
<a name="l195"></a> code=basecode;
<a name="l196"></a> </span><span class=cF1>while</span><span class=cF0> (code&gt;=c-&gt;min_table_entry) </span><span class=cF7>{</span><span class=cF0>
<a name="l197"></a> *c-&gt;stk_ptr++=c-&gt;compress[code].ch;
<a name="l198"></a> code=c-&gt;compress[code].basecode;
<a name="l199"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l200"></a> *c-&gt;stk_ptr++=code;
<a name="l201"></a> c-&gt;last_ch=code;
<a name="l202"></a>
<a name="l203"></a> c-&gt;entry_used=</span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l204"></a> tmp=c-&gt;cur_entry;
<a name="l205"></a> tmp-&gt;basecode=lastcode;
<a name="l206"></a> tmp-&gt;ch=c-&gt;last_ch;
<a name="l207"></a> tmp1=&amp;c-&gt;hash[lastcode];
<a name="l208"></a> tmp-&gt;next=tmp1-&gt;next;
<a name="l209"></a> tmp1-&gt;next=tmp;
<a name="l210"></a>
<a name="l211"></a> ArcEntryGet(c);
<a name="l212"></a> </span><span class=cF1>while</span><span class=cF0> (dst_ptr&lt;dst_limit &amp;&amp; c-&gt;stk_ptr!=c-&gt;stk_base)
<a name="l213"></a> *dst_ptr++ = * -- c-&gt;stk_ptr;
<a name="l214"></a> lastcode=basecode;
<a name="l215"></a> }
<a name="l216"></a> c-&gt;saved_basecode=lastcode;
<a name="l217"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l218"></a> c-&gt;dst_pos=dst_ptr-c-&gt;dst_buf;
<a name="l219"></a>}
<a name="l220"></a>
<a name="l221"></a></span><span class=cF9>CArcCtrl</span><span class=cF0> *</span><span class=cF5>ArcCtrlNew</span><span class=cF0>(</span><span class=cF1>Bool</span><span class=cF0> expand,</span><span class=cF9>I64</span><span class=cF0> compression_type=</span><span class=cF3>CT_8_BIT</span><span class=cF0>)
<a name="l222"></a>{</span><span class=cF2>//MAlloc archive ctrl struct.</span><span class=cF0>
<a name="l223"></a> </span><span class=cF9>CArcCtrl</span><span class=cF0> *c;
<a name="l224"></a> c=</span><span class=cF5>CAlloc</span><span class=cF0>(</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>CArcCtrl</span><span class=cF7>)</span><span class=cF0>);
<a name="l225"></a> </span><span class=cF1>if</span><span class=cF0> (expand) </span><span class=cF7>{</span><span class=cF0>
<a name="l226"></a> c-&gt;stk_base=</span><span class=cF5>MAlloc</span><span class=cF0>(1&lt;&lt;</span><span class=cF3>ARC_BITS_MAX</span><span class=cF0>);
<a name="l227"></a> c-&gt;stk_ptr=c-&gt;stk_base;
<a name="l228"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l229"></a> </span><span class=cF1>if</span><span class=cF0> (compression_type==</span><span class=cF3>CT_7_BIT</span><span class=cF0>)
<a name="l230"></a> c-&gt;min_bits=7;
<a name="l231"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l232"></a> c-&gt;min_bits=8;
<a name="l233"></a> c-&gt;min_table_entry=1&lt;&lt;c-&gt;min_bits;
<a name="l234"></a> c-&gt;free_idx=c-&gt;min_table_entry;
<a name="l235"></a> c-&gt;next_bits_in_use=c-&gt;min_bits+1;
<a name="l236"></a> c-&gt;free_limit=1&lt;&lt;c-&gt;next_bits_in_use;
<a name="l237"></a> c-&gt;saved_basecode=</span><span class=cF3>U32_MAX</span><span class=cF0>;
<a name="l238"></a> c-&gt;entry_used=</span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l239"></a> ArcEntryGet(c);
<a name="l240"></a> c-&gt;entry_used=</span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l241"></a> </span><span class=cF1>return</span><span class=cF0> c;
<a name="l242"></a>}
<a name="l243"></a>
<a name="l244"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>ArcCtrlDel</span><span class=cF0>(</span><span class=cF9>CArcCtrl</span><span class=cF0> *c)
<a name="l245"></a>{</span><span class=cF2>//Free archive ctrl struct.</span><span class=cF0>
<a name="l246"></a> </span><span class=cF5>Free</span><span class=cF0>(c-&gt;stk_base);
<a name="l247"></a> </span><span class=cF5>Free</span><span class=cF0>(c);
<a name="l248"></a>}
<a name="l249"></a>
<a name="l250"></a></span><span class=cF1>U8</span><span class=cF0> *</span><span class=cF5>ExpandBuf</span><span class=cF0>(</span><span class=cF9>CArcCompress</span><span class=cF0> *arc,</span><span class=cF9>CTask</span><span class=cF0> *mem_task=</span><span class=cF3>NULL</span><span class=cF0>)
<a name="l251"></a>{</span><span class=cF2>//See </span><a href="/Wb/Demo/Dsk/SerializeTree.HC.HTML#l1"><span class=cF4>::/Demo/Dsk/SerializeTree.HC</span></a><span class=cF2>.</span><span class=cF0>
<a name="l252"></a> </span><span class=cF9>CArcCtrl</span><span class=cF0> *c;
<a name="l253"></a> </span><span class=cF1>U8</span><span class=cF0> *res;
<a name="l254"></a>
<a name="l255"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF7>(</span><span class=cF3>CT_NONE</span><span class=cF0>&lt;=arc-&gt;compression_type&lt;=</span><span class=cF3>CT_8_BIT</span><span class=cF7>)</span><span class=cF0> ||
<a name="l256"></a> arc-&gt;expanded_size&gt;</span><span class=cFB>mem_mapped_space</span><span class=cF0>)
<a name="l257"></a> </span><span class=cF5>throw</span><span class=cF0>(</span><span class=cF6>'Compress'</span><span class=cF0>);
<a name="l258"></a>
<a name="l259"></a> res=</span><span class=cF5>MAlloc</span><span class=cF0>(arc-&gt;expanded_size+1,mem_task);
<a name="l260"></a> res[arc-&gt;expanded_size]=0; </span><span class=cF2>//terminate</span><span class=cF0>
<a name="l261"></a> </span><span class=cF1>switch</span><span class=cF0> [arc-&gt;compression_type] </span><span class=cF7>{</span><span class=cF0>
<a name="l262"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>CT_NONE</span><span class=cF0>:
<a name="l263"></a> </span><span class=cF5>MemCpy</span><span class=cF0>(res,&amp;arc-&gt;body,arc-&gt;expanded_size);
<a name="l264"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l265"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>CT_7_BIT</span><span class=cF0>:
<a name="l266"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>CT_8_BIT</span><span class=cF0>:
<a name="l267"></a> c=</span><span class=cF5>ArcCtrlNew</span><span class=cF0>(</span><span class=cF3>TRUE</span><span class=cF0>,arc-&gt;compression_type);
<a name="l268"></a> c-&gt;src_size=arc-&gt;compressed_size&lt;&lt;3;
<a name="l269"></a> c-&gt;src_pos=</span><span class=cF1>sizeof</span><span class=cF0>(</span><span class=cF9>CArcCompress</span><span class=cF0>)&lt;&lt;3;
<a name="l270"></a> c-&gt;src_buf=arc;
<a name="l271"></a> c-&gt;dst_size=arc-&gt;expanded_size;
<a name="l272"></a> c-&gt;dst_buf=res;
<a name="l273"></a> c-&gt;dst_pos=0;
<a name="l274"></a> </span><span class=cF5>ArcExpandBuf</span><span class=cF0>(c);
<a name="l275"></a> </span><span class=cF5>ArcCtrlDel</span><span class=cF0>(c);
<a name="l276"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l277"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l278"></a> </span><span class=cF1>return</span><span class=cF0> res;
<a name="l279"></a>}
<a name="l280"></a>
<a name="l281"></a></span><span class=cF9>CArcCompress</span><span class=cF0> *</span><span class=cF5>CompressBuf</span><span class=cF0>(</span><span class=cF1>U8</span><span class=cF0> *src,</span><span class=cF9>I64</span><span class=cF0> size,</span><span class=cF9>CTask</span><span class=cF0> *mem_task=</span><span class=cF3>NULL</span><span class=cF0>)
<a name="l282"></a>{</span><span class=cF2>//See </span><a href="/Wb/Demo/Dsk/SerializeTree.HC.HTML#l1"><span class=cF4>::/Demo/Dsk/SerializeTree.HC</span></a><span class=cF2>.</span><span class=cF0>
<a name="l283"></a> </span><span class=cF9>CArcCompress</span><span class=cF0> *arc;
<a name="l284"></a> </span><span class=cF9>I64</span><span class=cF0> size_out,compression_type=</span><span class=cFD>ArcDetermineCompressionType</span><span class=cF0>(src,size);
<a name="l285"></a> </span><span class=cF9>CArcCtrl</span><span class=cF0> *c=</span><span class=cF5>ArcCtrlNew</span><span class=cF0>(</span><span class=cF3>FALSE</span><span class=cF0>,compression_type);
<a name="l286"></a> c-&gt;src_size=size;
<a name="l287"></a> c-&gt;src_buf=src;
<a name="l288"></a> c-&gt;dst_size=(size+</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>CArcCompress</span><span class=cF7>)</span><span class=cF0>)&lt;&lt;3;
<a name="l289"></a> c-&gt;dst_buf=</span><span class=cF5>CAlloc</span><span class=cF0>(c-&gt;dst_size&gt;&gt;3);
<a name="l290"></a> c-&gt;dst_pos=</span><span class=cF1>sizeof</span><span class=cF0>(</span><span class=cF9>CArcCompress</span><span class=cF0>)&lt;&lt;3;
<a name="l291"></a> </span><span class=cF5>ArcCompressBuf</span><span class=cF0>(c);
<a name="l292"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>ArcFinishCompression</span><span class=cF7>(</span><span class=cF0>c</span><span class=cF7>)</span><span class=cF0> &amp;&amp; c-&gt;src_pos==c-&gt;src_size) </span><span class=cF7>{</span><span class=cF0>
<a name="l293"></a> size_out=(c-&gt;dst_pos+7)&gt;&gt;3;
<a name="l294"></a> arc=</span><span class=cF5>MAlloc</span><span class=cF0>(size_out,mem_task);
<a name="l295"></a> </span><span class=cF5>MemCpy</span><span class=cF0>(arc,c-&gt;dst_buf,size_out);
<a name="l296"></a> arc-&gt;compression_type=compression_type;
<a name="l297"></a> arc-&gt;compressed_size=size_out;
<a name="l298"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF7>{</span><span class=cF0>
<a name="l299"></a> arc=</span><span class=cF5>MAlloc</span><span class=cF0>(size+</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>CArcCompress</span><span class=cF7>)</span><span class=cF0>,mem_task);
<a name="l300"></a> </span><span class=cF5>MemCpy</span><span class=cF0>(&amp;arc-&gt;body,src,size);
<a name="l301"></a> arc-&gt;compression_type=</span><span class=cF3>CT_NONE</span><span class=cF0>;
<a name="l302"></a> arc-&gt;compressed_size=size+</span><span class=cF1>sizeof</span><span class=cF0>(</span><span class=cF9>CArcCompress</span><span class=cF0>);
<a name="l303"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l304"></a> arc-&gt;expanded_size=size;
<a name="l305"></a> </span><span class=cF5>Free</span><span class=cF0>(c-&gt;dst_buf);
<a name="l306"></a> </span><span class=cF5>ArcCtrlDel</span><span class=cF0>(c);
<a name="l307"></a> </span><span class=cF1>return</span><span class=cF0> arc;
<a name="l308"></a>}
</span></pre></body>
</html>