Subversion Repositories Kolibri OS

Rev

Rev 6639 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  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.  
  110. ;void (m)
  111. ;    char *m
  112. align 4
  113. proc z_error, m:dword
  114. ;    fprintf(stderr, "%s\n", m);
  115. ;    exit(1);
  116.         ret
  117. endp
  118.  
  119. ; exported to allow conversion of error code to string for compress() and
  120. ; uncompress()
  121.  
  122. ;const char * (err)
  123. ;    int err
  124. align 4
  125. proc zError uses ecx, err:dword
  126.         ERR_MSG [err]
  127.         mov eax,ecx
  128.         ret
  129. endp
  130.  
  131. ;#ifndef HAVE_MEMCPY
  132.  
  133. ;void (dest, source, len)
  134. ;    Bytef* dest
  135. ;    const Bytef* source
  136. ;    uInt  len
  137. align 4
  138. proc zmemcpy uses ecx edi esi, dest:dword, source:dword, len:dword
  139.         mov ecx,[len]
  140.         test ecx,ecx
  141.         jz .end0
  142.                 mov edi,[dest]
  143.                 mov esi,[source]
  144.                 bt ecx,0 ;кратно 2 ?
  145.                 jnc @f
  146.                         rep movsb
  147.                         jmp .end0
  148.                 @@:
  149.                 bt ecx,1 ;кратно 4 ?
  150.                 jnc @f
  151.                         shr ecx,1
  152.                         rep movsw
  153.                         jmp .end0
  154.                 @@:
  155.                 shr ecx,2
  156.                 rep movsd
  157.         .end0:
  158.         ret
  159. endp
  160.  
  161. ;int (s1, s2, len)
  162. ;    const Bytef* s1
  163. ;    const Bytef* s2
  164. ;    uInt  len
  165. align 4
  166. proc zmemcmp, s1:dword, s2:dword, len:dword
  167. ;    uInt j;
  168.  
  169. ;    for (j = 0; j < len; j++) {
  170. ;        if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1;
  171. ;    }
  172. ;    return 0;
  173.         ret
  174. endp
  175.  
  176. ;void (dest, len)
  177. ;    Bytef* dest
  178. ;    uInt  len
  179. align 4
  180. proc zmemzero, dest:dword, len:dword
  181. ;    if (len == 0) return;
  182. ;    do {
  183. ;        *dest++ = 0;  /* ??? to be unrolled */
  184. ;    } while (--len != 0);
  185.         ret
  186. endp
  187. ;end if
  188.  
  189. ;voidpf (voidpf opaque, unsigned items, unsigned size)
  190. align 4
  191. proc zcalloc uses ebx ecx, opaque:dword, items:dword, size:dword
  192.         mov ecx,[size]
  193.         imul ecx,[items]
  194.         mcall SF_SYS_MISC, SSF_MEM_ALLOC
  195.         ret
  196. endp
  197.  
  198. ;void (voidpf opaque, voidpf ptr)
  199. align 4
  200. proc zcfree uses eax ebx ecx, opaque:dword, p2ptr:dword
  201.         mcall SF_SYS_MISC, SSF_MEM_FREE, [p2ptr]
  202.         ret
  203. endp
  204.  
  205.