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

Add libgnt
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Nov 19 17:37:48 2022 +0000 (17 months ago)
parents 2ccf00d9c1cd
children 7f7bd3c9775e
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 movw %cx, %dx
73 # if !defined(FLAT32) && !defined(FLAT16)
74 xorw %cx, %cx
75 call normalize
76 # define NeedNormalize
77 # endif
78 addw %si, %dx
79 #endif
80 lzsa1chunk: // uncompress chunk
81 lodsb // get token O|LLL|MMMM
82 movb %al, %bl // keep token in bl
83 shrb $4, %al // shift literals length into place
84 movw $LITERALS_RUN_LEN*256+MIN_LITERALS_SIZE, %cx
85 call lzsa1len // %ch = LITERALS_RUN_LEN
86 #if defined(NeedNormalize) && defined(PARANOIA)
87 call lzsa1movLit // copy %cx literals from %ds:%si to %es:%di
88 #else
89 rep movsb // copy %cx literals from %ds:%si to %es:%di
90 #endif
91 #ifndef RAW_FORMAT
92 cmpw %dx, %si
93 jae lzsa1block // bail if we hit EOD
94 #endif
95 #ifdef FLAT32
96 orl $-1, %eax
97 #else
98 movb $-1, %ah
99 #endif
100 testb %bl, %bl // check match offset size in token (O bit)
101 jns lzsa1ShortOfs
102 lodsw
103 .byte 0x3C // mask lodsb with cmpb $0xAC, %al
104 lzsa1ShortOfs:
105 lodsb
106 #ifdef RAW_FORMAT
107 orw %ax, %ax
108 jz lzsa1quit // bail if we hit EOD
109 #endif
110 xchg AX, BX // %bx: match offset %ax: original token
111 movw $MATCH_RUN_LEN*256+MIN_MATCH_SIZE, %cx
112 call lzsa1len
113 #if !defined(FLAT32) && !defined(FLAT16OUT)
114 pushw %ds
115 pushw %si
116 movw %di, %si
117 addw %bx, %si
118 movw %es, %ax
119 jc axok
120 subb $0x10, %ah
121 axok:
122 .macro norm reg
123 movw %si, \reg
124 andw $0xF, %si
125 shrw $4, \reg
126 addw \reg, %ax
127 movw %ax, %ds
128 lzsa1movLit:
129 movw %di, \reg
130 andw $0xF, %di
131 shrw $4, \reg
132 movw %es, %ax
133 addw \reg, %ax
134 movw %ax, %es
135 .endm
136 # if defined(NeedNormalize) || defined(PARANOIA)
137 call lzsa1movStr // copy string
138 # else
139 norm %bp
140 rep movsb
141 # endif
142 popw %si
143 popw %ds
144 #else
145 xchg AX, SI // save %si
146 lea (BX,DI), SI
147 rep movsb %es:(SI), %es:(DI)
148 xchg AX, SI // restore %si
149 #endif
150 jmp lzsa1chunk
152 lzsa1len: // get length in %ecx
153 andb %ch, %al
154 cbw // clear %ah
155 cmpb %ch, %al
156 jne lzsa1minNumber // S=0-6, L=0-14
157 lodsb
158 addb %ch, %cl
159 lzsa1minNumber:
160 addb %cl, %al
161 jnc lzsa1gotNumber // 0-255
162 movb %al, %ah // S=256-1791, L=256-3839 or S=256-511, L=256-511
163 jne lzsa1midNumber
164 lodsw // 0-65535
165 .byte 0x3C // mask lodsb with cmpb $0xAC, %al
166 lzsa1midNumber:
167 lodsb
168 lzsa1gotNumber:
169 xchgw %ax, %cx
170 lzsa1quit:
171 ret
173 #if defined(NeedNormalize) || defined(PARANOIA)
174 # if defined(PARANOIA)
175 lzsa1movlp:
176 decw %ch
177 rep movsb
178 incw %ch
179 # endif
180 normalize:
181 movw %ds, %bp
182 lzsa1movStr:
183 norm %bp
184 # if defined(PARANOIA)
185 cmpb $0xFF, %ch // catch FFFX case
186 je lzsa1movlp
187 # endif
188 rep movsb
189 ret
190 #endif