wok view memtest/stuff/unlzsa1.S @ rev 25487

Up exiftool (12.50), foomatic-db (4.0-20221111), lzsa (1.4.0), zlib (1.2.13)
author Pascal Bellard <pascal.bellard@slitaz.org>
date Tue Nov 15 16:20:54 2022 +0000 (17 months ago)
parents
children 2ccf00d9c1cd
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 lodsw
38 cmpw $0x9E7B, %ax // magic
39 jne lzsa1main
40 lodsb
41 cmpb $0, %al // lzsa1
42 jne lzsa1main
43 lzsa1block: // uncompress chunk
44 lodsw // block size
45 xchgw %ax, %cx
46 lodsb
47 # ifndef PACKED_ONLY
48 orb %al, %al
49 jns lzsa1compressed
50 # if !defined(FLAT32) && !defined(FLAT16OUT)
51 movw %cx, %dx
52 andb $0x7F, %ch
53 andw $0x8000, %dx
54 copy32k:
55 call lzsa1movStr
56 xchg %dx, %cx
57 incw %cx
58 loop copy32k
59 # else
60 movsb // copy block
61 copylp:
62 movsb // copy block
63 loop copylp // handle 64K case
64 # endif
65 jmp lzsa1block
66 lzsa1compressed:
67 jne lzsa1chunk // 64Kb block
68 # endif
69 jcxz lzsa1quit // bail if we hit EOD
70 movw %cx, %dx
71 # if !defined(FLAT32) && !defined(FLAT16)
72 xorw %cx, %cx
73 call normalize
74 # endif
75 addw %si, %dx
76 #endif
77 lzsa1chunk: // uncompress chunk
78 lodsb // get token O|LLL|MMMM
79 movb %al, %bl // keep token in bl
80 shrb $4, %al // shift literals length into place
81 movw $LITERALS_RUN_LEN*256+MIN_LITERALS_SIZE, %cx
82 call lzsa1len // %ch = LITERALS_RUN_LEN
83 #if !defined(FLAT32) && !defined(FLAT16OUT)
84 call lzsa1movLit // copy %cx literals from %ds:%si to %es:%di
85 #else
86 rep movsb // copy %cx literals from %ds:%si to %es:%di
87 #endif
88 #ifndef RAW_FORMAT
89 cmpw %dx, %si
90 jae lzsa1block // bail if we hit EOD
91 #endif
92 #ifdef FLAT32
93 orl $-1, %eax
94 #else
95 movb $-1, %ah
96 #endif
97 testb %bl, %bl // check match offset size in token (O bit)
98 jns lzsa1ShortOfs
99 lodsw
100 .byte 0x3C // mask lodsb with cmpb $0xAC, %al
101 lzsa1ShortOfs:
102 lodsb
103 #ifdef RAW_FORMAT
104 orw %ax, %ax
105 jz lzsa1quit // bail if we hit EOD
106 #endif
107 xchg AX, BX // %bx: match offset %ax: original token
108 movw $MATCH_RUN_LEN*256+MIN_MATCH_SIZE, %cx
109 call lzsa1len
110 #if !defined(FLAT32) && !defined(FLAT16OUT)
111 pushw %ds
112 pushw %si
113 movw %di, %si
114 addw %bx, %si
115 movw %es, %ax
116 jc dxok
117 subb $0x10, %ah
118 dxok:
119 movw %ax, %ds
120 call lzsa1movStr // copy string
121 popw %si
122 popw %ds
123 #else
124 xchg AX, SI // save %si
125 lea (BX,DI), SI
126 rep movsb %es:(SI), %es:(DI)
127 xchg AX, SI // restore %si
128 #endif
129 jmp lzsa1chunk
131 lzsa1len: // get length in %ecx
132 andb %ch, %al
133 cbw // clear %ah
134 cmpb %al, %ch
135 jne lzsa1minNumber // S=0-6, L=0-14
136 lodsb
137 addb %cl, %ch
138 addb %ch, %al
139 jnc lzsa1gotNumber // 0-255
140 movb %al, %ah // S=256-1791, L=256-3839 or S=256-511, L=256-511
141 jne lzsa1midNumber
142 lodsw // 0-65535
143 .byte 0x3C // mask lodsb with cmpb $0xAC, %al
144 lzsa1midNumber:
145 lodsb
146 lzsa1gotNumber:
147 xchgw %ax, %cx
148 lzsa1quit:
149 ret
150 lzsa1minNumber:
151 addb %cl, %al
152 xchgw %ax, %cx
153 ret
155 #if !defined(FLAT32) && !defined(FLAT16OUT)
156 # if defined(PARANOIA)
157 lzsa1movlp:
158 decw %ch
159 rep movsb
160 incw %ch
161 # endif
162 normalize:
163 lzsa1movStr:
164 movw %si, %ax
165 andw $0xF, %si
166 shrw $4, %ax
167 movw %ds, %bp
168 addw %ax, %bp
169 movw %bp, %ds
170 lzsa1movLit:
171 movw %di, %ax
172 andw $0xF, %di
173 shrw $4, %ax
174 movw %es, %bp
175 addw %ax, %bp
176 movw %bp, %es
177 # if defined(PARANOIA)
178 cmpb $0xFF, %ch // catch FFFX case
179 je lzsa1movlp
180 # endif
181 rep movsb
182 ret
183 #endif