home *** CD-ROM | disk | FTP | other *** search
/ The Party 1994: Try This At Home / disk_image.bin / source / vexsrc / ints.asm < prev    next >
Assembly Source File  |  1995-03-29  |  3KB  |  182 lines

  1. comment #
  2. /*****************************************************************************
  3.                                   ATTENTION!
  4.                            this source is VOTEWARE,
  5.               you may only use it to the conditions listed below:
  6.  
  7.   -You may modify it, or use parts of it in your own source as long as
  8.     this header stays on top of all files containing this source.
  9.   -You must give proper credit to the author, Niklas Beisert / pascal.
  10.   -You may not use it in commercial productions without the written
  11.     permission of the author.
  12.   -AND MOST IMPORTANT: you have to buy an Assembly '94 CD-ROM
  13.     by Sound Solutions (if you don't have it already) and vote for VEX-InTrO
  14.     in the PC-64k-Intro-Compo! (if you have already sent your voting card,
  15.     buy another one and fill it out CORRECTLY!!!)
  16. *****************************************************************************/
  17. #
  18.  
  19.  
  20.  
  21. ;// 16 bit fixed point routines, takes care of division by zero
  22.  
  23. .model large, c
  24. .386
  25. locals
  26.  
  27. .code
  28.  
  29. public IntMul
  30. public IntSqr
  31. public IntDiv
  32. public IntSqrt
  33. public IntMulDiv
  34. public IntVecMul
  35. public IntVecSqr
  36. public InstallZeroDivide
  37. public DeinstallZeroDivide
  38. public ZeroOn
  39.  
  40. OldZeroDivide dd 0
  41. ZeroOn dw 0
  42.  
  43. IntMul proc a:dword, b:dword
  44.   mov eax,a
  45.   imul b
  46.   shr eax,16
  47.   ret
  48. IntMul endp
  49.  
  50. IntSqr proc a:dword
  51.   mov eax,a
  52.   imul a
  53.   shr eax,16
  54.   ret
  55. IntSqr endp
  56.  
  57. IntDiv proc a:dword, b:dword
  58.   mov eax,a
  59.   mov edx,eax
  60.   shl eax,16
  61.   sar edx,16
  62.   mov cs:ZeroOn,@@enddiv-@@startdiv
  63. @@startdiv:
  64.   idiv b
  65. @@enddiv:
  66.   mov cs:ZeroOn,0
  67.   shld edx,eax,16
  68.   ret
  69. IntDiv endp
  70.  
  71. IntSqrt proc uses esi edi ebx, a:dword
  72.   mov esi,a
  73.   mov edi,esi
  74.   shl esi,16
  75.   sar edi,16
  76.   mov ebx,10000h
  77.   mov cx,12
  78.   mov cs:ZeroOn,@@enddiv-@@startdiv
  79. @@l:
  80.   mov eax,esi
  81.   mov edx,edi
  82. @@startdiv:
  83.   idiv ebx
  84. @@enddiv:
  85.   add ebx,eax
  86.   shr ebx,1
  87.   loop @@l
  88.   mov cs:ZeroOn,0
  89.   mov eax,ebx
  90.   shld edx,eax,16
  91.   ret
  92. IntSqrt endp
  93.  
  94. IntMulDiv proc a:dword, b:dword, c:dword
  95.   mov eax,a
  96.   imul b
  97.   mov cs:ZeroOn,@@enddiv-@@startdiv
  98. @@startdiv:
  99.   idiv c
  100. @@enddiv:
  101.   mov cs:ZeroOn,0
  102.   shld edx,eax,16
  103.   ret
  104. IntMulDiv endp
  105.  
  106. IntVecMul proc uses ds si di, a:dword, b:dword
  107.   lds si,a
  108.   les di,b
  109.   cld
  110.   lodsd
  111.   imul dword ptr es:[di]
  112.   mov ecx,eax
  113.   mov ebx,edx
  114.   lodsd
  115.   imul dword ptr es:[di+4]
  116.   add ecx,eax
  117.   adc ebx,edx
  118.   lodsd
  119.   imul dword ptr es:[di+8]
  120.   add eax,ecx
  121.   adc edx,ebx
  122.   shr eax,16
  123.   ret
  124. IntVecMul endp
  125.  
  126. IntVecSqr proc uses ds si, a:dword
  127.   lds si,a
  128.   lodsd
  129.   imul dword ptr [si-4]
  130.   mov ecx,eax
  131.   mov ebx,edx
  132.   lodsd
  133.   imul dword ptr [si-4]
  134.   add ecx,eax
  135.   adc ebx,edx
  136.   lodsd
  137.   imul dword ptr [si-4]
  138.   add eax,ecx
  139.   adc edx,ebx
  140.   shr eax,16
  141.   ret
  142. IntVecSqr endp
  143.  
  144. InstallZeroDivide proc uses ds
  145.   mov ax,3500h
  146.   int 21h
  147.   mov cs:word ptr OldZeroDivide,bx
  148.   mov cs:word ptr OldZeroDivide+2,es
  149.   mov ax,2500h
  150.   push cs
  151.   pop ds
  152.   mov dx,offset ZeroDivide
  153.   int 21h
  154.   ret
  155. InstallZeroDivide endp
  156.  
  157. DeinstallZeroDivide proc uses ds
  158.   mov ax,2500h
  159.   mov dx,cs:word ptr OldZeroDivide
  160.   mov ds,cs:word ptr OldZeroDivide+2
  161.   int 21h
  162.   ret
  163. DeinstallZeroDivide endp
  164.  
  165. ZeroDivide proc
  166.   cmp cs:ZeroOn,0
  167.   jnz @@correctit
  168.   jmp cs:OldZeroDivide
  169. @@correctit:
  170.   mov eax,7FFFFFFFh
  171.   push bp
  172.   push ax
  173.   mov bp,sp
  174.   mov ax,cs:ZeroOn
  175.   add ss:word ptr [bp+4], ax
  176.   pop ax
  177.   pop bp
  178.   iret
  179. ZeroDivide endp
  180.  
  181. end
  182.