wok view plop/stuff/unlzsa1.S @ rev 25504

Update some web_site / wget_url
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sun Feb 05 09:28:51 2023 +0000 (17 months ago)
parents
children 20c2ee666646
line source
1 // Lzsa1Decode:
2 #ifndef FLAT32
3 // input ds:si=inStream, es:di=outStream
4 // output outStream[], ds:si, es:di
5 .code16
6 #define AX %ax
7 #define BX %bx
8 #define SI %si
9 #define DI %di
10 #else
11 // input esi=inStream, edi=outStream
12 // output outStream[], ds:esi, es:edi
13 .code32
14 #define AX %eax
15 #define BX %ebx
16 #define SI %esi
17 #define DI %edi
18 #endif
20 MATCH_RUN_LEN = 15
21 LITERALS_RUN_LEN = 7
22 MIN_MATCH_SIZE = 3
23 MIN_LITERALS_SIZE = 0
25 #define PACKED_ONLY // assume no copy block, optional
26 //#define PARANOIA // cover rare cases, optional
28 lzsa1main:
29 #ifdef PARANOIA
30 cld
31 #endif
32 #ifndef RAW_FORMAT
33 # if defined(PARANOIA) && !defined(FLAT32) && !defined(FLAT16)
34 xorw %cx, %cx
35 call normalize
36 # endif
37 # ifndef NO_LZSA1_HEADER
38 lodsw
39 cmpw $0x9E7B, %ax // magic
40 jne lzsa1main
41 lodsb
42 cmpb $0, %al // lzsa1
43 jne lzsa1main
44 # endif
45 lzsa1block: // uncompress chunk
46 lodsw // block size
47 xchgw %ax, %cx
48 lodsb
49 # ifndef PACKED_ONLY
50 orb %al, %al
51 jns lzsa1compressed
52 # if !defined(FLAT32) && !defined(FLAT16OUT)
53 movw %cx, %dx
54 movb $0, %cl
55 movb $0, %dh
56 copytail:
57 call lzsa1movStr
58 xchg %dx, %cx
59 incw %cx
60 loop copytail
61 # else
62 movsb // copy block
63 copylp:
64 movsb // copy block
65 loop copylp // handle 64K case
66 # endif
67 jmp lzsa1block
68 lzsa1compressed:
69 jne lzsa1chunk // 64Kb block
70 # endif
71 jcxz lzsa1quit // bail if we hit EOD
72 pushw %cx
73 # if !defined(FLAT32) && !defined(FLAT16)
74 xorw %cx, %cx
75 call normalize
76 # define NeedNormalize
77 # endif
78 popw %dx
79 addw %si, %dx
80 #endif
81 lzsa1chunk: // uncompress chunk
82 lodsb // get token O|LLL|MMMM
83 movb %al, %bl // keep token in bl
84 shrb $4, %al // shift literals length into place
85 movw $LITERALS_RUN_LEN*256+MIN_LITERALS_SIZE, %cx
86 call lzsa1len // %ch = LITERALS_RUN_LEN
87 #if defined(NeedNormalize)
88 call lzsa1movLit // copy %cx literals from %ds:%si to %es:%di
89 #else
90 rep movsb // copy %cx literals from %ds:%si to %es:%di
91 #endif
92 #ifndef RAW_FORMAT
93 cmpw %dx, %si
94 jae lzsa1block // bail if we hit EOD
95 #endif
96 #ifdef FLAT32
97 orl $-1, %eax
98 #else
99 movb $-1, %ah
100 #endif
101 testb %bl, %bl // check match offset size in token (O bit)
102 jns lzsa1ShortOfs
103 lodsw
104 .byte 0x3C // mask lodsb with cmpb $0xAC, %al
105 lzsa1ShortOfs:
106 lodsb
107 #ifdef RAW_FORMAT
108 orw %ax, %ax
109 jz lzsa1quit // bail if we hit EOD
110 #endif
111 xchg AX, BX // %bx: match offset %ax: original token
112 movw $MATCH_RUN_LEN*256+MIN_MATCH_SIZE, %cx
113 call lzsa1len
114 #if !defined(FLAT32) && !defined(FLAT16OUT)
115 pushw %ds
116 pushw %si
117 movw %di, %si
118 addw %bx, %si
119 movw %es, %ax
120 jc axok
121 subb $0x10, %ah
122 axok:
123 .macro norm reg
124 movw %si, \reg
125 subw %si, %dx
126 andw $0xF, %si
127 addw %si, %dx
128 shrw $4, \reg
129 addw \reg, %ax
130 movw %ax, %ds
131 movw %di, \reg
132 andw $0xF, %di
133 shrw $4, \reg
134 movw %es, %ax
135 addw \reg, %ax
136 movw %ax, %es
137 .endm
138 pushw %dx
139 # if defined(NeedNormalize) || defined(PARANOIA)
140 call lzsa1movStr // copy string
141 # else
142 norm %bp
143 rep movsb
144 # endif
145 popw %dx
146 popw %si
147 popw %ds
148 #else
149 xchg AX, SI // save %si
150 lea (BX,DI), SI
151 rep movsb %es:(SI), %es:(DI)
152 xchg AX, SI // restore %si
153 #endif
154 jmp lzsa1chunk
156 lzsa1len: // get length in %ecx
157 andb %ch, %al
158 cbw // clear %ah
159 cmpb %ch, %al
160 jne lzsa1minNumber // S=0-6, L=0-14
161 lodsb
162 addb %ch, %cl
163 lzsa1minNumber:
164 addb %cl, %al
165 jnc lzsa1gotNumber // 0-255
166 movb %al, %ah // S=256-1791, L=256-3839 or S=256-511, L=256-511
167 jne lzsa1midNumber
168 lodsw // 0-65535
169 .byte 0x3C // mask lodsb with cmpb $0xAC, %al
170 lzsa1midNumber:
171 lodsb
172 lzsa1gotNumber:
173 xchgw %ax, %cx
174 lzsa1quit:
175 ret
177 #if defined(NeedNormalize) || defined(PARANOIA)
178 # if defined(PARANOIA)
179 lzsa1movlp:
180 decw %ch
181 rep movsb
182 incw %ch
183 # endif
184 normalize:
185 lzsa1movLit:
186 movw %ds, %ax
187 lzsa1movStr:
188 norm %bp
189 # if defined(PARANOIA)
190 cmpb $0xFF, %ch // catch FFFX case
191 je lzsa1movlp
192 # endif
193 rep movsb
194 ret
195 #endif