Subversion Repositories Kolibri OS

Rev

Rev 6847 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
6617 IgorA 1
; zutil.asm -- target dependent utility functions for the compression library
2
; Copyright (C) 1995-2005, 2010, 2011, 2012 Jean-loup Gailly.
3
; For conditions of distribution and use, see copyright notice in zlib.inc
4
 
5
align 4
6
z_errmsg dd ze0,ze1,ze2,ze3,ze4,ze5,ze6,ze7,ze8,ze9
7
ze0 db 'need dictionary',0 ;Z_NEED_DICT       2
8
ze1 db 'stream end',0      ;Z_STREAM_END      1
9
ze2 db '',0                ;Z_OK              0
10
ze3 db 'file error',0      ;Z_ERRNO         (-1)
11
ze4 db 'stream error',0    ;Z_STREAM_ERROR  (-2)
12
ze5 db 'data error',0      ;Z_DATA_ERROR    (-3)
13
ze6 db 'insufficient memory',0  ;Z_MEM_ERROR     (-4)
14
ze7 db 'buffer error',0         ;Z_BUF_ERROR     (-5)
15
ze8 db 'incompatible version',0 ;Z_VERSION_ERROR (-6)
16
ze9 db '',0
17
 
18
;const char * ()
19
align 4
20
proc zlibVersion
21
	mov eax,ZLIB_VERSION;
22
	ret
23
endp
24
 
25
;uLong ()
26
align 4
27
proc zlibCompileFlags
28
;    uLong flags;
29
 
30
;    flags = 0;
31
;    switch ((int)(sizeof(uInt))) {
32
;    case 2:     break;
33
;    case 4:     flags += 1;     break;
34
;    case 8:     flags += 2;     break;
35
;    default:    flags += 3;
36
;    }
37
;    switch ((int)(sizeof(uLong))) {
38
;    case 2:     break;
39
;    case 4:     flags += 1 << 2;        break;
40
;    case 8:     flags += 2 << 2;        break;
41
;    default:    flags += 3 << 2;
42
;    }
43
;    switch ((int)(sizeof(voidpf))) {
44
;    case 2:     break;
45
;    case 4:     flags += 1 << 4;        break;
46
;    case 8:     flags += 2 << 4;        break;
47
;    default:    flags += 3 << 4;
48
;    }
49
;    switch ((int)(sizeof(z_off_t))) {
50
;    case 2:     break;
51
;    case 4:     flags += 1 << 6;        break;
52
;    case 8:     flags += 2 << 6;        break;
53
;    default:    flags += 3 << 6;
54
;    }
55
;if DEBUG
56
;    flags += 1 << 8;
57
;end if
58
;#if defined(ASMV) || defined(ASMINF)
59
;    flags += 1 << 9;
60
;end if
61
if ZLIB_WINAPI eq 1
62
;    flags += 1 << 10;
63
end if
64
if BUILDFIXED eq 1
65
;    flags += 1 << 12;
66
end if
67
if DYNAMIC_CRC_TABLE eq 1
68
;    flags += 1 << 13;
69
end if
70
if NO_GZCOMPRESS eq 1
71
;    flags += 1L << 16;
72
end if
73
if NO_GZIP eq 1
74
;    flags += 1L << 17;
75
end if
76
if PKZIP_BUG_WORKAROUND eq 1
77
;    flags += 1L << 20;
78
end if
79
if FASTEST eq 1
80
;    flags += 1L << 21;
81
end if
82
;#if defined(STDC) || defined(Z_HAVE_STDARG_H)
83
;#  ifdef NO_vsnprintf
84
;    flags += 1L << 25;
85
;#    ifdef HAS_vsprintf_void
86
;    flags += 1L << 26;
87
;#    endif
88
;#  else
89
;#    ifdef HAS_vsnprintf_void
90
;    flags += 1L << 26;
91
;#    endif
92
;#  endif
93
;#else
94
;    flags += 1L << 24;
95
;#  ifdef NO_snprintf
96
;    flags += 1L << 25;
97
;#    ifdef HAS_sprintf_void
98
;    flags += 1L << 26;
99
;#    endif
100
;#  else
101
;#    ifdef HAS_snprintf_void
102
;    flags += 1L << 26;
103
;#    endif
104
;#  endif
105
;end if
106
;    return flags;
107
	ret
108
endp
109
 
6851 IgorA 110
;void (char *m)
6617 IgorA 111
align 4
112
proc z_error, m:dword
113
;    fprintf(stderr, "%s\n", m);
114
;    exit(1);
115
	ret
116
endp
117
 
118
; exported to allow conversion of error code to string for compress() and
119
; uncompress()
120
 
6851 IgorA 121
;const char * (int err)
6617 IgorA 122
align 4
6639 IgorA 123
proc zError uses ecx, err:dword
124
	ERR_MSG [err]
125
	mov eax,ecx
6617 IgorA 126
	ret
127
endp
128
 
129
;#ifndef HAVE_MEMCPY
130
 
131
;void (dest, source, len)
6639 IgorA 132
;    Bytef* dest
133
;    const Bytef* source
134
;    uInt  len
6617 IgorA 135
align 4
136
proc zmemcpy uses ecx edi esi, dest:dword, source:dword, len:dword
137
	mov ecx,[len]
6847 IgorA 138
	test ecx,ecx
139
	jz .end0
6617 IgorA 140
		mov edi,[dest]
141
		mov esi,[source]
6847 IgorA 142
		bt ecx,0 ;кратно 2 ?
143
		jnc @f
144
			rep movsb
145
			jmp .end0
146
		@@:
147
		bt ecx,1 ;кратно 4 ?
148
		jnc @f
149
			shr ecx,1
150
			rep movsw
151
			jmp .end0
152
		@@:
153
		shr ecx,2
154
		rep movsd
6617 IgorA 155
	.end0:
156
	ret
157
endp
158
 
159
;int (s1, s2, len)
6639 IgorA 160
;    const Bytef* s1
161
;    const Bytef* s2
162
;    uInt  len
6617 IgorA 163
align 4
164
proc zmemcmp, s1:dword, s2:dword, len:dword
165
;    uInt j;
166
 
167
;    for (j = 0; j < len; j++) {
168
;        if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1;
169
;    }
170
;    return 0;
171
	ret
172
endp
173
 
6851 IgorA 174
;void (Bytef* dest, uInt len)
6617 IgorA 175
align 4
6851 IgorA 176
proc zmemzero uses eax ecx edi, dest:dword, len:dword
177
	mov ecx,[len]
178
	test ecx,ecx
179
	jz .end0
180
		xor eax,eax
181
		mov edi,[dest]
182
		bt ecx,0 ;кратно 2 ?
183
		jnc @f
184
			rep stosb
185
			jmp .end0
186
		@@:
187
		bt ecx,1 ;кратно 4 ?
188
		jnc @f
189
			shr ecx,1
190
			rep stosw
191
			jmp .end0
192
		@@:
193
		shr ecx,2
194
		rep stosd
195
	.end0:
6617 IgorA 196
	ret
197
endp
198
;end if
199
 
200
;voidpf (voidpf opaque, unsigned items, unsigned size)
201
align 4
202
proc zcalloc uses ebx ecx, opaque:dword, items:dword, size:dword
203
	mov ecx,[size]
204
	imul ecx,[items]
205
	mcall SF_SYS_MISC, SSF_MEM_ALLOC
206
	ret
207
endp
208
 
209
;void (voidpf opaque, voidpf ptr)
210
align 4
211
proc zcfree uses eax ebx ecx, opaque:dword, p2ptr:dword
212
	mcall SF_SYS_MISC, SSF_MEM_FREE, [p2ptr]
213
	ret
214
endp
215