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

Update some web_site/wget_url
author Pascal Bellard <pascal.bellard@slitaz.org>
date Tue Jul 11 10:40:23 2023 +0000 (11 months ago)
parents 20c2ee666646
children be3de88419e0
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 .macro shrclw cnt,obj
29 #ifdef ONLY8086
30 movb \cnt, %cl
31 shrw %cl, \obj
32 #else
33 shrw \cnt, \obj
34 #endif
35 .endm
37 #ifdef FLAT16OUT
38 #define RAW_FORMAT
39 #endif
40 lzsa1main:
41 #ifdef PARANOIA
42 cld
43 #endif
44 #ifndef RAW_FORMAT
45 # ifndef NO_LZSA1_HEADER
46 lodsw
47 cmpw $0x9E7B, %ax // magic
48 jne lzsa1main
49 lodsb
50 // cmpb $0, %al // lzsa1
51 // jne lzsa1main
52 # endif
53 xorw %ax, %ax
54 xchgw %ax, %di
55 shrclw $4, %ax
56 jmp lzsa1blockz // %di *MUST* be paragraph aligned
57 # ifndef PACKED_ONLY
58 lzsa1copy:
59 movsb // handle 64K case
60 decw %cx
61 rep movsb // copy block
62 # endif
63 lzsa1block: // uncompress chunk
64 movw $0x1000, %ax
65 lzsa1blockz:
66 movw %es, %bx
67 addw %ax, %bx
68 movw %bx, %es
69 # ifndef FLAT16
70 movw %si, %ax
71 andw $0xf, %si
72 shrclw $4, %ax
73 movw %ds, %bx
74 addw %ax, %bx
75 movw %bx, %ds
76 # endif
77 lodsw // block size
78 xchgw %ax, %cx
79 movw %cx, %dx
80 lodsb
81 # ifndef PACKED_ONLY
82 orb %al, %al
83 js lzsa1copy
84 jne lzsa1full // 64Kb block
85 # endif
86 jcxz lzsa1quit // bail if we hit EOD
87 lzsa1full:
88 addw %si, %dx
89 #endif
90 lzsa1chunk: // uncompress chunk
91 lodsb // get token O|LLL|MMMM
92 movb %al, %bl // keep token in bl
93 shrclw $4, %ax // shift literals length into place
94 movw $LITERALS_RUN_LEN+256*MIN_LITERALS_SIZE, %cx
95 call lzsa1len // %ch = LITERALS_RUN_LEN
96 rep movsb // copy %cx literals from %ds:%si to %es:%di
97 #ifndef RAW_FORMAT
98 cmpw %dx, %si
99 je lzsa1block // bail if we hit EOD
100 #endif
101 #ifdef FLAT32
102 orl $-1, %eax
103 #endif
104 testb %bl, %bl // check match offset size in token (O bit)
105 js lzsa1LongOfs
106 #ifndef FLAT32
107 movb $-1, %ah // set offset bits 15-8 to 1
108 #endif
109 lodsb
110 .byte 0x3C // mask lodsw with cmpb $0xAD, %al
111 lzsa1LongOfs:
112 lodsw
113 xchg AX, BX // %bx: match offset %ax: original token
114 movw $MATCH_RUN_LEN+256*MIN_MATCH_SIZE, %cx
115 call lzsa1len
116 #ifdef RAW_FORMAT
117 jcxz lzsa1quit // bail if we hit EOD
118 #endif
120 #if !defined(FLAT16OUT) && !defined(FLAT32)
121 xchg AX, SI // save %si
122 lea (BX,DI), SI
123 pushw %ds
124 movw %es, %bp
125 cmpw %si, %di
126 jnc lzsa1sameSeg
127 pushw %si
128 shrclw $4, %si
129 lea -4096(%bp,%si), %bp
130 popw %si
131 andw $0xF, %si
132 lzsa1sameSeg:
133 movw %bp, %ds
134 # ifdef FASTFILL
135 cmp $-FASTFILL,BX
136 jae lzsa1fast
137 # endif
138 rep movsb
139 lzsa1chunkz:
140 popw %ds
141 #else
142 # ifdef FASTFILL
143 cmp $-FASTFILL,BX
144 jae lzsa1fast
145 # endif
146 xchg AX, SI // save %si
147 lea (BX,DI), SI
148 rep movsb %es:(SI), %es:(DI)
149 #define lzsa1chunkz lzsa1chunk
150 #endif
151 xchg AX, SI // restore %si
152 jmp lzsa1chunk
153 #ifdef FASTFILL
154 lzsa1fast:
155 # if FASTFILL == 1
156 # if !defined(FLAT16OUT) && !defined(FLAT32)
157 lodsb
158 # else
159 movb %es:(BX,DI), %al
160 # endif
161 rep stosb
162 # endif
163 # if FASTFILL == 2
164 # if !defined(FLAT16OUT) && !defined(FLAT32)
165 lodsw
166 # else
167 movw %es:(BX,DI), %ax
168 # endif
169 je lzsa1fastword
170 movb %ah, %al
171 lzsa1fastword:
172 shr $1, CX
173 rep stosw
174 jnc lzsa1chunkz
175 stosb
176 # endif
177 jmp lzsa1chunkz
178 #endif
180 lzsa1len: // get length in %ecx
181 andb %cl, %al
182 cbw // clear %ah
183 cmpb %al, %cl
184 jne lzsa1minNumber // S=0-6, L=0-14 %cx = %ch + %al if (%al & %cl != %cl)
185 addb %al, %ch
186 lodsb
187 lzsa1minNumber:
188 addb %ch, %al
189 jnc lzsa1gotNumber // 0-255 %cx = %ch + %cl + byte if (%al & %cl == %cl && %ch + %cl + byte < 0x100)
190 movb %al, %ah // S=256-1791, L=256-4607 or S=256-511, L=256-511
191 jne lzsa1midNumber
192 lodsw // 0-65535 %cx = word if (%al & %cl == %cl && %ch + %cl + byte == 0x100)
193 .byte 0x3C // mask lodsb with cmpb $0xAC, %al
194 lzsa1midNumber:
195 lodsb // %cx = (%ch + %cl + byte)*256 + byte2 if (%al & %cl == %cl && %ch + %cl + byte > 0x100)
196 lzsa1gotNumber:
197 xchgw %ax, %cx
198 lzsa1quit:
199 ret