-
Notifications
You must be signed in to change notification settings - Fork 2
/
LZWD2.ASM
211 lines (190 loc) · 5.91 KB
/
LZWD2.ASM
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
;
; Lempel-Ziv Welch Decompression routine
;
; Copyright (C) 1994 by Roman Cramar
;
.186
jumps
OutByte macro
mov es,OutputSeg
mov byte ptr es:[bp],al
inc bp
endm
DATA segment 'DATA'
extrn InputOffs : word
extrn InputSeg : word
extrn Temp_offs : word
extrn Temp_seg : word
extrn OutPutSeg : word
extrn le6A : word
extrn le6C : word
extrn le6E : word
extrn le70 : word
extrn le72 : word
extrn le74 : word
extrn le78 : word
extrn le7A_0 : word
extrn le7A_2 : word
extrn le7A_4 : word
extrn le7A_6 : word
extrn le82a : word
extrn le82b : word
extrn OutPutOffs2: word
extrn le76 : byte
extrn le77 : byte
DATA ends
CODE segment
assume cs:CODE, ds:DATA
public LZWDecompr
;Decompress - decompresses data compressed by Lempel-Ziv Welch method.
; BX:AX - Pointer to temporary buffer (17K min.).
; DX:CX - Pointer to compressed data.
; DI:SI - Pointer to buffer to decompress.
; Exit: AX - size of decompressed data.
LZWDecompr proc near
push bp
mov Temp_offs, ax
mov Temp_seg, bx
mov InputOffs, cx
mov InputSeg, dx
mov bp, si
mov OutPutOffs2,si
mov OutputSeg, di
call LZWDecomp
mov ax,bp
sub ax,OutPutOffs2
pop bp
ret
LZWDecompr endp
LZWDecomp proc near
push si
push di
mov le72,0
mov le78,9
mov le70,102h
mov le74,200h
xor ax,ax
mov le6a,ax
mov le6c,ax
mov le6e,ax
mov le76,al
mov le77,al
mov le82a,ax
mov le82b,ax
mov le7a_0,1FFh
mov le7a_2,3FFh
mov le7a_4,7FFh
mov le7a_6,0FFFh
le58b: call GetNextCode
cmp ax,101h
jnz le596
jmp le63b
le596: cmp ax,100h
jnz le5b5
call InitTable
call GetNextCode
mov le6a,ax
mov le6c,ax
mov le77,al
mov le76,al
mov al,le77
OutByte
jmp le58b
le5b5: mov le6a,ax
mov le6e,ax
cmp ax,le70
jb t2
mov ax,le6c
mov le6a,ax
mov al,le76
push ax
inc le72
t2: cmp le6a,0ffh
jbe le5f6
les si,dword ptr temp_offs
mov bx,le6a
shl bx,1
add bx,le6a
mov al,es:[bx+si+2]
push ax
inc le72
mov ax,es:[bx+si]
mov le6a,ax
jmp t2
le5f6: mov ax,le6a
mov le76,al
mov le77,al
push ax
inc le72
mov cx,le72
jcxz le610
t1: pop ax
OutByte
loop t1
le610: mov le72,0
call AddInTable
mov ax,le6e
mov le6c,ax
mov bx,le70
cmp bx,le74
jl le638
cmp byte ptr ds:le78,0ch
jz le638
inc byte ptr ds:le78
shl le74,1
le638: jmp le58b
le63b: pop di
pop si
ret
InitTable proc near
mov byte ptr ds:le78,9
mov le74,200h
mov le70,102h
ret
InitTable endp
GetNextCode proc near
mov bx,le82a
mov ax,le82b
add bx,le78
adc ax,0
xchg bx,le82a
xchg ax,Le82b
mov cx,bx
and cx,7 ;!!!!!
shr ax,1
rcr bx,1
shr ax,1
rcr bx,1
shr ax,1
rcr bx,1
les si,dword ptr InputOffs
mov ax,es:[bx+si]
mov dl,es:[bx+si+2]
or cx,cx
jz GetCode2
GetCode1: shr dl,1
rcr ax,1
loop GetCode1
GetCode2: mov bx,le78
sub bx,9
shl bx,1
and ax,[bx+le7a_0]
ret
GetNextCode endp
AddInTable proc near
push si
mov bx,le70
shl bx,1
add bx,le70
les si,dword ptr temp_offs
mov al,le77
mov es:[bx+si+2],al
mov ax,le6c
mov es:[bx+si],ax
inc le70
pop si
ret
AddInTable endp
LZWDecomp endp
CODE ends
end