home *** CD-ROM | disk | FTP | other *** search
/ The Party 1994: Try This At Home / disk_image.bin / source / vexsrc / matrix.asm < prev    next >
Assembly Source File  |  1995-03-29  |  10KB  |  612 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. ;// matrix and vector routines
  22.  
  23. .model large,c
  24. .386
  25. locals
  26.  
  27. extrn ZeroOn:word
  28.  
  29. .data
  30.  
  31. extrn SinTab:dword
  32. sintabsize equ 2048
  33.  
  34. .code
  35.  
  36. public vecmove
  37. public vecscl
  38. public vecadd
  39. public vecsub
  40. public vecmul
  41. public vecsqr
  42. public vecnorm
  43. public vecxmul
  44. public veccopy
  45. public vecxform
  46. public vecxformvec
  47. public vecxlate
  48. public vectsqr
  49. public matscl
  50. public matmul
  51. public matxlate
  52. public makematnorm
  53. public makematxlate
  54. public makematrotx
  55. public makematroty
  56. public makematrotz
  57.  
  58. vecmove proc uses ds si di, r:dword, p:dword, t:dword, l:word
  59.   cld
  60.   les di,r
  61.  
  62.   xor eax,eax
  63.   mov es:[di+0],eax
  64.   mov es:[di+4],eax
  65.   mov es:[di+8],eax
  66.  
  67.   cmp l,1
  68.   jb @@end
  69.   lds si,p
  70.   lodsd
  71.   add es:[di+0],eax
  72.   lodsd
  73.   add es:[di+4],eax
  74.   lodsd
  75.   add es:[di+8],eax
  76.  
  77.   cmp l,2
  78.   jb @@end
  79.   mov ecx,t
  80.   lodsd
  81.   imul ecx
  82.   shrd eax,edx,16
  83.   add es:[di+0],eax
  84.   lodsd
  85.   imul ecx
  86.   shrd eax,edx,16
  87.   add es:[di+4],eax
  88.   lodsd
  89.   imul ecx
  90.   shrd eax,edx,16
  91.   add es:[di+8],eax
  92.  
  93.   cmp l,3
  94.   jb @@end
  95.   mov eax,ecx
  96.   imul eax
  97.   shrd eax,edx,17
  98.   mov ecx,eax
  99.   lodsd
  100.   imul ecx
  101.   shrd eax,edx,16
  102.   add es:[di+0],eax
  103.   lodsd
  104.   imul ecx
  105.   shrd eax,edx,16
  106.   add es:[di+4],eax
  107.   lodsd
  108.   imul ecx
  109.   shrd eax,edx,16
  110.   add es:[di+8],eax
  111.  
  112.   cmp l,4
  113.   jb @@end
  114.   mov eax,ecx
  115.   imul t
  116.   mov ecx,30000h
  117.   idiv ecx
  118.   mov ecx,eax
  119.   lodsd
  120.   imul ecx
  121.   shrd eax,edx,16
  122.   add es:[di+0],eax
  123.   lodsd
  124.   imul ecx
  125.   shrd eax,edx,16
  126.   add es:[di+4],eax
  127.   lodsd
  128.   imul ecx
  129.   shrd eax,edx,16
  130.   add es:[di+8],eax
  131.  
  132. @@end:
  133.   mov ax,di
  134.   mov dx,es
  135.   ret
  136. endp
  137.  
  138. vecscl proc uses ds si di, r:dword, a:dword, b:dword
  139.   cld
  140.   lds si,a
  141.   les di,r
  142.   mov ecx,b
  143.   lodsd
  144.   imul ecx
  145.   shrd eax,edx,16
  146.   stosd
  147.   lodsd
  148.   imul ecx
  149.   shrd eax,edx,16
  150.   stosd
  151.   lodsd
  152.   imul ecx
  153.   shrd eax,edx,16
  154.   stosd
  155.   ret
  156. endp
  157.  
  158. vecadd proc uses ds si di, r:dword, a:dword, b:dword
  159.   cld
  160.   lds si,a
  161.   lfs bx,b
  162.   les di,r
  163.   lodsd
  164.   add eax,fs:[bx+0]
  165.   stosd
  166.   lodsd
  167.   add eax,fs:[bx+4]
  168.   stosd
  169.   lodsd
  170.   add eax,fs:[bx+8]
  171.   stosd
  172.   ret
  173. endp
  174.  
  175. vecsub proc uses ds si di, r:dword, a:dword, b:dword
  176.   cld
  177.   lds si,a
  178.   lfs bx,b
  179.   les di,r
  180.   lodsd
  181.   sub eax,fs:[bx+0]
  182.   stosd
  183.   lodsd
  184.   sub eax,fs:[bx+4]
  185.   stosd
  186.   lodsd
  187.   sub eax,fs:[bx+8]
  188.   stosd
  189.   ret
  190. endp
  191.  
  192. vecmul proc uses si di ds, a:dword, b:dword
  193.   cld
  194.   lds si,a
  195.   les di,b
  196.   lodsd
  197.   imul dword ptr es:[di+0]
  198.   mov ecx,eax
  199.   mov ebx,edx
  200.   lodsd
  201.   imul dword ptr es:[di+4]
  202.   add ecx,eax
  203.   adc ebx,edx
  204.   lodsd
  205.   imul dword ptr es:[di+8]
  206.   add eax,ecx
  207.   adc edx,ebx
  208.   shr eax,16
  209.   ret
  210. endp
  211.  
  212. vecsqr proc uses si ds, a:dword
  213.   cld
  214.   lds si,a
  215.   lodsd
  216.   imul eax
  217.   mov ecx,eax
  218.   mov ebx,edx
  219.   lodsd
  220.   imul eax
  221.   add ecx,eax
  222.   adc ebx,edx
  223.   lodsd
  224.   imul eax
  225.   add eax,ecx
  226.   adc edx,ebx
  227.   shr eax,16
  228.   ret
  229. endp
  230.  
  231. vecnorm proc uses esi edi ds, a:dword
  232.   cld
  233.   lds bx,a
  234.   mov eax,ds:[bx+0]
  235.   imul eax
  236.   mov esi,eax
  237.   mov edi,edx
  238.   mov eax,ds:[bx+4]
  239.   imul eax
  240.   add esi,eax
  241.   adc edi,edx
  242.   mov eax,ds:[bx+8]
  243.   imul eax
  244.   add esi,eax
  245.   adc edi,edx
  246.  
  247.   mov ax,seg ZeroOn
  248.   mov es,ax
  249.   mov ebx,10000h
  250.   mov es:ZeroOn,@@enddiv-@@startdiv
  251.   rept 10
  252.     mov eax,esi
  253.     mov edx,edi
  254.     idiv ebx
  255.     add ebx,eax
  256.     shr ebx,1
  257.   endm
  258. @@break:
  259.   xor eax,eax
  260.   mov edx,1
  261. @@startdiv:
  262.   idiv ebx
  263. @@enddiv:
  264.   mov es:ZeroOn,0
  265.   mov ecx,eax
  266.  
  267.   mov bx,word ptr a
  268.   i=0
  269.   rept 3
  270.     mov eax,ds:[bx+i]
  271.     imul ecx
  272.     shrd eax,edx,16
  273.     mov ds:[bx+i],eax
  274.     i=i+4
  275.   endm
  276.   ret
  277. endp
  278.  
  279. vecxmul proc uses si di ds, r:dword, a:dword, b:dword
  280.   les di,r
  281.   lds si,a
  282.   lfs bx,b
  283.  
  284.   mov eax,ds:[si+8]
  285.   imul dword ptr fs:[bx+4]
  286.   shrd eax,edx,16
  287.   mov ecx,eax
  288.   mov eax,ds:[si+4]
  289.   imul dword ptr fs:[bx+8]
  290.   shrd eax,edx,16
  291.   sub eax,ecx
  292.   stosd
  293.  
  294.   mov eax,ds:[si+0]
  295.   imul dword ptr fs:[bx+8]
  296.   shrd eax,edx,16
  297.   mov ecx,eax
  298.   mov eax,ds:[si+8]
  299.   imul dword ptr fs:[bx+0]
  300.   shrd eax,edx,16
  301.   sub eax,ecx
  302.   stosd
  303.  
  304.   mov eax,ds:[si+4]
  305.   imul dword ptr fs:[bx+0]
  306.   shrd eax,edx,16
  307.   mov ecx,eax
  308.   mov eax,ds:[si+0]
  309.   imul dword ptr fs:[bx+4]
  310.   shrd eax,edx,16
  311.   sub eax,ecx
  312.   stosd
  313.  
  314.   ret
  315. endp
  316.  
  317. veccopy proc uses si di ds, r:dword, v:dword, n:word
  318.   cld
  319.   lds si,v
  320.   les di,r
  321.   mov cx,n
  322.   shl cx,1
  323.   add cx,n
  324.   rep movsd
  325.   ret
  326. endp
  327.  
  328. vxform macro vec
  329.   cld
  330.   lds si,m
  331.   les di,r
  332.   lfs bx,v
  333.  
  334.   cmp n,0
  335.   je @@done
  336. @@loop:
  337.     y=48
  338.     rept 3
  339.       y=y-16
  340.       mov eax,ds:[si+y+0]
  341.       imul dword ptr fs:[bx+0]
  342.       shrd eax,edx,16
  343.       mov ecx,eax
  344.       mov eax,ds:[si+y+4]
  345.       imul dword ptr fs:[bx+4]
  346.       shrd eax,edx,16
  347.       add ecx,eax
  348.       mov eax,ds:[si+y+8]
  349.       imul dword ptr fs:[bx+8]
  350.       shrd eax,edx,16
  351.       add ecx,eax
  352.       if vec
  353.       add ecx,ds:[si+y+12]
  354.       endif
  355.       push ecx
  356.     endm
  357.  
  358.     pop eax
  359.     stosd
  360.     pop eax
  361.     stosd
  362.     pop eax
  363.     stosd
  364.     add bx,12
  365.  
  366.   dec n
  367.   jnz @@loop
  368.  
  369. @@done:
  370.   mov ax,word ptr r
  371.   mov dx,word ptr r+2
  372.   ret
  373. endm
  374.  
  375. vecxform proc uses si di ds, r:dword, v:dword, m:dword, n:word
  376.   vxform 1
  377. endp
  378.  
  379. vecxformvec proc uses si di ds, r:dword, v:dword, m:dword, n:word
  380.   vxform 0
  381. endp
  382.  
  383. vecxlate proc uses di, v:dword, n:word, dv:dword
  384.   cld
  385.   les di,dv
  386.   mov eax,es:[di+0]
  387.   mov ebx,es:[di+4]
  388.   mov edx,es:[di+8]
  389.   les di,v
  390.   mov cx,n
  391.   jcxz @@done
  392. @@loop:
  393.     add es:[di+0],eax
  394.     add es:[di+4],ebx
  395.     add es:[di+8],edx
  396.     add di,12
  397.   loop @@loop
  398. @@done:
  399.   mov ax,word ptr v
  400.   mov dx,es
  401.   ret
  402. endp
  403.  
  404. vectsqr proc uses ds si di, m:dword, v:dword, v4:dword
  405.   cld
  406.   lds si,v
  407.   les di,m
  408.  
  409.   mov ebx,ds:[si+0]
  410.   mov eax,ebx
  411.   imul ebx
  412.   shrd eax,edx,16
  413.   stosd
  414.   mov eax,ds:[si+4]
  415.   imul ebx
  416.   shrd eax,edx,16
  417.   stosd
  418.   mov eax,ds:[si+8]
  419.   imul ebx
  420.   shrd eax,edx,16
  421.   stosd
  422.   mov eax,v4
  423.   imul ebx
  424.   shrd eax,edx,16
  425.   stosd
  426.  
  427.   mov ebx,ds:[si+4]
  428.   mov eax,es:[di-12]
  429.   stosd
  430.   mov eax,ebx
  431.   imul ebx
  432.   shrd eax,edx,16
  433.   stosd
  434.   mov eax,ds:[si+8]
  435.   imul ebx
  436.   shrd eax,edx,16
  437.   stosd
  438.   mov eax,v4
  439.   imul ebx
  440.   shrd eax,edx,16
  441.   stosd
  442.  
  443.   mov ebx,ds:[si+8]
  444.   mov eax,es:[di-24]
  445.   stosd
  446.   mov eax,es:[di-12]
  447.   stosd
  448.   mov eax,ebx
  449.   imul ebx
  450.   shrd eax,edx,16
  451.   stosd
  452.   mov eax,v4
  453.   imul ebx
  454.   shrd eax,edx,16
  455.   stosd
  456.  
  457.   ret
  458. endp
  459.  
  460. matscl proc uses ds si di, r:dword, m:dword, s:dword
  461.   cld
  462.   lds si,m
  463.   les di,r
  464.   mov ebx,s
  465.  
  466.   rept 12
  467.     lodsd
  468.     imul ebx
  469.     shrd eax,edx,16
  470.     stosd
  471.   endm
  472.  
  473.   ret
  474. endp
  475.  
  476. matmul proc uses ds si di, r:dword, a:dword, b:dword
  477.   cld
  478.   lds si,a
  479.   les di,b
  480.  
  481.   y=48
  482.   rept 3
  483.     y=y-16
  484.     x=16
  485.     rept 4
  486.       x=x-4
  487.       mov eax,dword ptr ds:[si+y+0]
  488.       imul dword ptr es:[di+0+x]
  489.       shrd eax,edx,16
  490.       mov ebx,eax
  491.       mov eax,dword ptr ds:[si+y+4]
  492.       imul dword ptr es:[di+16+x]
  493.       shrd eax,edx,16
  494.       add ebx,eax
  495.       mov eax,dword ptr ds:[si+y+8]
  496.       imul dword ptr es:[di+32+x]
  497.       shrd eax,edx,16
  498.       add ebx,eax
  499.       ife x-12
  500.     add ebx,dword ptr ds:[si+y+12]
  501.       endif
  502.       push ebx
  503.     endm
  504.   endm
  505.  
  506.   les di,r
  507.   mov ax,ss
  508.   mov ds,ax
  509.   mov ax,di
  510.   mov si,sp
  511.   mov cx,12
  512.   rep movsd
  513.   add sp,48
  514.   mov dx,es
  515.   ret
  516. endp
  517.  
  518. matxlate proc m:dword, v:dword
  519.   les bx,v
  520.   mov eax,es:[bx+0]
  521.   mov ecx,es:[bx+4]
  522.   mov edx,es:[bx+8]
  523.   les bx,m
  524.   add es:[bx+12],eax
  525.   add es:[bx+28],ecx
  526.   add es:[bx+44],edx
  527.   mov ax,bx
  528.   mov dx,es
  529.   ret
  530. endp
  531.  
  532. makematnorm proc uses di, m:dword
  533.   les di,m
  534.   mov cx,12
  535.   xor eax,eax
  536.   rep stosd
  537.   sub di,48
  538.   mov es:[di+00],65536
  539.   mov es:[di+20],65536
  540.   mov es:[di+40],65536
  541.   mov ax,di
  542.   mov dx,es
  543.   ret
  544. endp
  545.  
  546. makematxlate proc uses esi di, m:dword, v:dword
  547.   les di,v
  548.   mov ebx,es:[di+0]
  549.   mov edx,es:[di+4]
  550.   mov esi,es:[di+8]
  551.   les di,m
  552.   mov cx,12
  553.   xor eax,eax
  554.   rep stosd
  555.   sub di,48
  556.   mov es:[di+00],65536
  557.   mov es:[di+20],65536
  558.   mov es:[di+40],65536
  559.   mov es:[di+12],ebx
  560.   mov es:[di+28],edx
  561.   mov es:[di+44],esi
  562.   mov ax,di
  563.   mov dx,es
  564.   ret
  565. endp
  566.  
  567. makematrot macro ca, cb, sa, sb
  568.   les di,SinTab
  569.   mov ax,a
  570.   and ax,sintabsize-1
  571.   shl ax,2
  572.   add di,ax
  573.   mov ebx,es:[di]
  574.   sub di,ax
  575.   mov ax,a
  576.   add ax,sintabsize shr 2
  577.   and ax,sintabsize-1
  578.   shl ax,2
  579.   add di,ax
  580.   mov edx,es:[di]
  581.   les di,m
  582.   mov cx,12
  583.   xor eax,eax
  584.   rep stosd
  585.   sub di,48
  586.   mov es:[di+00],65536
  587.   mov es:[di+20],65536
  588.   mov es:[di+40],65536
  589.   mov es:[di+ca],edx
  590.   mov es:[di+cb],edx
  591.   mov es:[di+sa],ebx
  592.   neg ebx
  593.   mov es:[di+sb],ebx
  594.   mov ax,di
  595.   mov dx,es
  596.   ret
  597. endm
  598.  
  599. makematrotx proc uses di, m:dword, a:word
  600.   makematrot 20 40 24 36
  601. endp
  602.  
  603. makematroty proc uses di, m:dword, a:word
  604.   makematrot 40 0 32 8
  605. endp
  606.  
  607. makematrotz proc uses di, m:dword, a:word
  608.   makematrot 0 20 4 16
  609. endp
  610.  
  611. end
  612.