home *** CD-ROM | disk | FTP | other *** search
/ PC Underground / UNDERGROUND.ISO / doom / source / _math.asm < prev    next >
Encoding:
Assembly Source File  |  1995-02-05  |  20.7 KB  |  849 lines

  1. ;-----------------------------------------------------------------------------
  2. ; 9bit fixed point vector math - DOS 16bit realmode (Turbo Pascal version)
  3. ; Copyright (c) 1994,95 by J.E. Hoffmann
  4. ; All rights reserved
  5. ;-----------------------------------------------------------------------------
  6.   TITLE _MATH.ASM
  7.  
  8.  
  9.   MODEL SMALL
  10.  
  11.  
  12.   IDEAL
  13.   NOJUMPS
  14.   LOCALS @@
  15.  
  16.  
  17.   DATASEG
  18.  
  19.  
  20.     BitSqrtTbl \
  21.       dw 1,2,2,3,5,7,10,14,20,28,39,55,78,111,157,222,314,443,627,887,1254
  22.       dw 1774,2508,3547,5017,7094,10033,14189,20066,28378,40132,56756
  23.  
  24.     SinTable \
  25.       DW 00000h, 00006h, 0000Dh, 00013h, 00019h, 0001Fh, 00026h, 0002Ch, 00032h, 00038h, 0003Fh, 00045h, 0004Bh, 00051h, 00058h, 0005Eh
  26.       DW 00064h, 0006Ah, 00070h, 00076h, 0007Ch, 00082h, 00089h, 0008Fh, 00095h, 0009Bh, 000A1h, 000A7h, 000ACh, 000B2h, 000B8h, 000BEh
  27.       DW 000C4h, 000CAh, 000CFh, 000D5h, 000DBh, 000E1h, 000E6h, 000ECh, 000F1h, 000F7h, 000FCh, 00102h, 00107h, 0010Dh, 00112h, 00117h
  28.       DW 0011Ch, 00122h, 00127h, 0012Ch, 00131h, 00136h, 0013Bh, 00140h, 00145h, 0014Ah, 0014Eh, 00153h, 00158h, 0015Ch, 00161h, 00166h
  29.       DW 0016Ah, 0016Eh, 00173h, 00177h, 0017Bh, 00180h, 00184h, 00188h, 0018Ch, 00190h, 00194h, 00197h, 0019Bh, 0019Fh, 001A3h, 001A6h
  30.       DW 001AAh, 001ADh, 001B1h, 001B4h, 001B7h, 001BAh, 001BDh, 001C1h, 001C4h, 001C6h, 001C9h, 001CCh, 001CFh, 001D1h, 001D4h, 001D7h
  31.       DW 001D9h, 001DBh, 001DEh, 001E0h, 001E2h, 001E4h, 001E6h, 001E8h, 001EAh, 001ECh, 001EDh, 001EFh, 001F1h, 001F2h, 001F4h, 001F5h
  32.       DW 001F6h, 001F7h, 001F8h, 001F9h, 001FAh, 001FBh, 001FCh, 001FDh, 001FEh, 001FEh, 001FFh, 001FFh, 001FFh, 00200h, 00200h, 00200h
  33.       DW 00200h
  34.  
  35.  
  36.   CODESEG
  37.  
  38.  
  39.   PUBLIC VecZero
  40.   PUBLIC Vec
  41.   PUBLIC UnVec
  42.   PUBLIC VecAdd
  43.   PUBLIC VecSub
  44.   PUBLIC VecDot
  45.   PUBLIC VecCross
  46.   PUBLIC VecDistance
  47.   PUBLIC VecLen
  48.   PUBLIC VecScalMul
  49.   PUBLIC VecNormalize
  50.  
  51.   PUBLIC Zero
  52.   PUBLIC Cross
  53.   PUBLIC Transform
  54.   PUBLIC Rotate
  55.   PUBLIC Create
  56.  
  57.   PUBLIC VecAdd2D
  58.   PUBLIC VecSub2D
  59.  
  60.  
  61.   P386N
  62.  
  63.  
  64.  
  65. ;----------------------------------------------------------------------------
  66. ; function FixSin(bx) :eax;
  67. ;----------------------------------------------------------------------------
  68.   PROC FixSin NEAR
  69.        and    bx,1FFh
  70.        cmp    bx,256
  71.        jge    @@21
  72.        cmp    bx,128
  73.        jng    @@11
  74.        neg    bx
  75.        add    bx,256
  76.   @@11:
  77.        shl    bx,1
  78.        mov    ax,[bx+SinTable]
  79.        cwde
  80.        ret
  81.   @@21:
  82.        sub    bx,256
  83.        cmp    bx,128
  84.        jnge   @@22
  85.        neg    bx
  86.        add    bx,256
  87.   @@22:
  88.        shl    bx,1
  89.        mov    ax,[bx+SinTable]
  90.        neg    ax
  91.        cwde
  92.        ret
  93.   ENDP
  94.  
  95.  
  96.  
  97. ;----------------------------------------------------------------------------
  98. ; function FixCos(bx) :eax;
  99. ;----------------------------------------------------------------------------
  100.   PROC FixCos NEAR
  101.        add    bx,128
  102.        jmp    FixSin
  103.   ENDP
  104.  
  105.  
  106.  
  107. ;----------------------------------------------------------------------------
  108. ; function FixSqrt(A:eax) :eax
  109. ;----------------------------------------------------------------------------
  110.   PROC FixSqrt FAR
  111.        mov    edi,eax
  112.        xor    ecx,ecx
  113.        bsr    ebx,edi
  114.        jz     @@12
  115.        shl    bx,1
  116.        movzx  eax,[bx+BitSqrtTbl]
  117.   @@11:
  118.        xor    edx,edx
  119.        mov    ebx,ecx
  120.        mov    ecx,eax
  121.        mov    eax,edi
  122.        div    ecx
  123.        add    eax,ecx
  124.        shr    eax,1
  125.        cmp    eax,ecx
  126.        je     @@12
  127.        cmp    eax,ebx
  128.        jne    @@11
  129.   @@12:
  130.        mov    eax,ecx
  131.        ret
  132.   ENDP
  133.  
  134.  
  135.  
  136. ;≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
  137. ; procedure VecZero(var C :T3D);
  138. ;≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
  139.   PROC VecZero FAR
  140.        ARG C:DWord = @@return
  141.        enter  0,0
  142.        cld
  143.        les    di,[C]
  144.        xor    eax,eax
  145.        stosd
  146.        stosd
  147.        stosd
  148.        leave
  149.        ret    @@return
  150.   ENDP
  151.  
  152.  
  153.  
  154. ;≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
  155. ; procedure Vec(vx,vy,vz :LongInt; var C :T3D);
  156. ;≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
  157.   PROC Vec FAR
  158.        ARG C:DWord, vz:DWord, vy:DWord, vx:DWord = @@return
  159.        enter  0,0
  160.        cld
  161.        les    di,[C]
  162.        mov    eax,[vx]
  163.        stosd
  164.        mov    eax,[vy]
  165.        stosd
  166.        mov    eax,[vz]
  167.        stosd
  168.        leave
  169.        ret    @@return
  170.   ENDP
  171.  
  172.  
  173.  
  174. ;≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
  175. ; procedure UnVec(A :T3D; var vx,vy,vz :LongInt);
  176. ;≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
  177.   PROC UnVec FAR
  178.        ARG vz:DWord, vy:DWord, vx:DWord, A:DWord = @@return
  179.        enter  0,0
  180.        cld
  181.        push   ds
  182.        lds    si,[A]
  183.        lodsd
  184.        les    di,[vx]
  185.        mov    [es:di],eax
  186.        lodsd
  187.        les    di,[vy]
  188.        mov    [es:di],eax
  189.        lodsd
  190.        les    di,[vz]
  191.        mov    [es:di],eax
  192.        pop    ds
  193.        leave
  194.        ret    @@return
  195.   ENDP
  196.  
  197.  
  198.  
  199. ;≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
  200. ; procedure VecAdd(A,B :T3D; var C :T3D);
  201. ;≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
  202.   PROC VecAdd FAR
  203.        ARG C:DWord, B:DWord, A:DWord = @@return
  204.        enter  0,0
  205.        cld
  206.        push   ds
  207.        lds    si,[A]
  208.        lgs    bx,[B]
  209.        les    di,[C]
  210.        lodsd
  211.        add    eax,[gs:bx]
  212.        stosd
  213.        lodsd
  214.        add    eax,[gs:bx+4]
  215.        stosd
  216.        lodsd
  217.        add    eax,[gs:bx+8]
  218.        stosd
  219.        pop    ds
  220.        leave
  221.        ret    @@return
  222.   ENDP
  223.  
  224.  
  225.  
  226. ;≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
  227. ; procedure VecSub(A,B :T3D; var C :T3D);
  228. ;≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
  229.   PROC VecSub FAR
  230.        ARG C:DWord, B:DWord, A:DWord = @@return
  231.        enter  0,0
  232.        cld
  233.        push   ds
  234.        lds    si,[A]
  235.        lgs    bx,[B]
  236.        les    di,[C]
  237.        lodsd
  238.        sub    eax,[gs:bx]
  239.        stosd
  240.        lodsd
  241.        sub    eax,[gs:bx+4]
  242.        stosd
  243.        lodsd
  244.        sub    eax,[gs:bx+8]
  245.        stosd
  246.        pop    ds
  247.        leave
  248.        ret    @@return
  249.   ENDP
  250.  
  251.  
  252.  
  253. ;≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
  254. ; function VecDot(A,B :T3D) :LongInt;
  255. ;≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
  256.   PROC VecDot FAR
  257.        ARG B:DWord, A:DWord = @@return
  258.        enter  0,0
  259.        push   ds
  260.        lds    si,[A]
  261.        les    di,[B]
  262.        lodsd
  263.        imul   [DWORD PTR es:di+4]
  264.        shrd   eax,edx,9
  265.        mov    ecx,eax
  266.        lodsd
  267.        imul   [DWORD PTR es:di+4]
  268.        shrd   eax,edx,9
  269.        add    ecx,eax
  270.        lodsd
  271.        imul   [DWORD PTR es:di+8]
  272.        shrd   eax,edx,9
  273.        add    ecx,eax
  274.        mov    ax,cx
  275.        rol    ecx,16
  276.        mov    dx,cx
  277.        pop    ds
  278.        leave
  279.        ret    @@return
  280.   ENDP
  281.  
  282.  
  283.  
  284. ;≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
  285. ; procedure VecCross(A,B :T3D; var C :T3D);
  286. ;≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
  287.   PROC VecCross FAR
  288.        ARG C:DWord, B:DWord, A:DWord = @@return
  289.        enter  0,0
  290.        push   ds
  291.        lds    si,[A]
  292.        les    di,[B]
  293.        lgs    bx,[C]
  294.        mov    eax,[si+4]
  295.        imul   [DWORD PTR es:di+8]
  296.        shrd   eax,edx,9
  297.        mov    ecx,eax
  298.        mov    eax,[si+8]
  299.        imul   [DWORD PTR es:di+4]
  300.        shrd   eax,edx,9
  301.        sub    ecx,eax
  302.        mov    [gs:bx],ecx
  303.        mov    eax,[si+8]
  304.        imul   [DWORD PTR es:di]
  305.        shrd   eax,edx,9
  306.        mov    ecx,eax
  307.        mov    eax,[si]
  308.        imul   [DWORD PTR es:di+8]
  309.        shrd   eax,edx,9
  310.        sub    ecx,eax
  311.        mov    [gs:bx+4],ecx
  312.        mov    eax,[si]
  313.        imul   [DWORD PTR es:di+4]
  314.        shrd   eax,edx,9
  315.        mov    ecx,eax
  316.        mov    eax,[si+4]
  317.        imul   [DWORD PTR es:di]
  318.        shrd   eax,edx,9
  319.        sub    ecx,eax
  320.        mov    [gs:bx+8],ecx
  321.        pop    ds
  322.        leave
  323.        ret    @@return
  324.   ENDP
  325.  
  326.  
  327.  
  328. ;≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
  329. ; function VecDistance(A :T3D) :LongInt;
  330. ;≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
  331.   PROC VecDistance FAR
  332.        ARG A:DWord = @@return
  333.        enter  0,0
  334.        push   ds
  335.        lds    si,[A]
  336.        lodsd
  337.        or     eax,eax
  338.        jns    @@11
  339.        neg    eax
  340.   @@11:
  341.        mul    eax
  342.        shrd   eax,edx,9
  343.        mov    ecx,eax
  344.        lodsd
  345.        or     eax,eax
  346.        jns    @@12
  347.        neg    eax
  348.   @@12:
  349.        mul    eax
  350.        shrd   eax,edx,9
  351.        add    ecx,eax
  352.        lodsd
  353.        or     eax,eax
  354.        jns    @@13
  355.        neg    eax
  356.   @@13:
  357.        mul    eax
  358.        shrd   eax,edx,9
  359.        add    ecx,eax
  360.        mov    ax,cx
  361.        rol    ecx,16
  362.        mov    dx,cx
  363.        pop    ds
  364.        leave
  365.        ret    @@return
  366.   ENDP
  367.  
  368.  
  369.  
  370. ;≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
  371. ; function VecLen(A :T3D) :LongInt;
  372. ;≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
  373.   PROC VecLen FAR
  374.        ARG A:DWord = @@return
  375.        enter  0,0
  376.        push   ds
  377.        lds    si,[A]
  378.        lodsd
  379.        or     eax,eax
  380.        jns    @@11
  381.        neg    eax
  382.   @@11:
  383.        mul    eax
  384.        shrd   eax,edx,9
  385.        mov    ecx,eax
  386.        lodsd
  387.        or     eax,eax
  388.        jns    @@12
  389.        neg    eax
  390.   @@12:
  391.        mul    eax
  392.        shrd   eax,edx,9
  393.        add    ecx,eax
  394.        lodsd
  395.        or     eax,eax
  396.        jns    @@13
  397.        neg    eax
  398.   @@13:
  399.        mul    eax
  400.        shrd   eax,edx,9
  401.        add    eax,ecx
  402.        shl    eax,1
  403.        call   FixSqrt
  404.        shl    eax,4
  405.        rol    eax,16
  406.        mov    dx,ax
  407.        rol    eax,16
  408.        pop    ds
  409.        leave
  410.        ret    @@return
  411.   ENDP
  412.  
  413.  
  414.  
  415. ;≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
  416. ; procedure VecScalMul(k :LongInt; A :T3D; var C :T3D);
  417. ;≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
  418.   PROC VecScalMul FAR
  419.        ARG C:DWord, A:DWord, k:DWord = @@return
  420.        enter  0,0
  421.        push   ds
  422.        lds    si,[A]
  423.        les    di,[C]
  424.        lodsd
  425.        imul   [k]
  426.        shrd   eax,edx,9
  427.        stosd
  428.        lodsd
  429.        imul   [k]
  430.        shrd   eax,edx,9
  431.        stosd
  432.        lodsd
  433.        imul   [k]
  434.        shrd   eax,edx,9
  435.        stosd
  436.        pop    ds
  437.        leave
  438.        ret    @@return
  439.   ENDP
  440.  
  441.  
  442.  
  443. ;≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
  444. ; procedure VecNormalize(var C :T3D);
  445. ;≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
  446.   PROC VecNormalize FAR
  447.        ARG C:DWord = @@return
  448.        enter  0,0
  449.        push   [C]
  450.        call   VecLen
  451.        mov    ecx,eax
  452.        les    di,[C]
  453.        mov    eax,[es:di]
  454.        cdq
  455.        shld   edx,eax,9
  456.        shl    eax,9
  457.        idiv   ecx
  458.        stosd
  459.        mov    eax,[es:di]
  460.        cdq
  461.        shld   edx,eax,9
  462.        shl    eax,9
  463.        idiv   ecx
  464.        stosd
  465.        mov    eax,[es:di]
  466.        cdq
  467.        shld   edx,eax,9
  468.        shl    eax,9
  469.        idiv   ecx
  470.        stosd
  471.        leave
  472.        ret    @@return
  473.   ENDP
  474.  
  475.  
  476.  
  477. ;≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
  478. ; procedure Zero(var C :TMatrix);
  479. ;≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
  480.   PROC Zero FAR
  481.        ARG C :DWord = @@return
  482.        enter  0,0
  483.        les    di,[C]
  484.        xor    eax,eax
  485.        mov    cx,(4*4*4)/4
  486.        repne  stosd
  487.        leave
  488.        ret    @@return
  489.   ENDP
  490.  
  491.  
  492.  
  493. ;≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
  494. ; procedure Cross(var A,B :TMatrix; var C :TMatrix);
  495. ;≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
  496.   PROC Cross FAR
  497.        ARG C:DWord, B:DWord, A:DWord = @@return
  498.        LOCAL i:Word, j :Word = @@local
  499.        enter  @@local,0
  500.        mov    [i],3
  501.   @@11:
  502.        mov    [j],3
  503.   @@21:
  504.        mov    bx,[j]
  505.        shl    bx,2
  506.        les    di,[B]
  507.        add    di,bx
  508.        mov    bx,[i]
  509.        shl    bx,4
  510.        lfs    si,[A]
  511.        add    si,bx
  512.        xor    ebx,ebx
  513.        mov    cx,4
  514.   @@31:
  515.        mov    eax,[fs:si]
  516.        imul   [DWORD PTR es:di]
  517.        shrd   eax,edx,9
  518.        add    ebx,eax
  519.        add    si,4
  520.        add    di,16
  521.        loop   @@31
  522.        les    di,[C]
  523.        mov    ax,[j]
  524.        shl    ax,2
  525.        add    di,ax
  526.        mov    ax,[i]
  527.        shl    ax,4
  528.        add    di,ax
  529.        mov    [es:di],ebx
  530.        dec    [j]
  531.        jns    @@21
  532.        dec    [i]
  533.        jns    @@11
  534.        leave
  535.        ret    @@return
  536.   ENDP
  537.  
  538.  
  539.  
  540. ;≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
  541. ; procedure Transform(A :T3D; M :TMatrix; var C :T3D);
  542. ;≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
  543.   PROC Transform FAR
  544.        ARG C:DWord, M:DWord, A:DWord = @@return
  545.        enter  0,0
  546.        lfs    si,[A]
  547.        lgs    bx,[M]
  548.        les    di,[C]
  549.        mov    cx,3
  550.   @@11:
  551.        push   cx
  552.        mov    eax,[fs:si]
  553.        imul   [DWORD PTR gs:bx]
  554.        shrd   eax,edx,9
  555.        mov    ecx,eax
  556.        mov    eax,[fs:si+4]
  557.        imul   [DWORD PTR gs:bx+4]
  558.        shrd   eax,edx,9
  559.        add    ecx,eax
  560.        mov    eax,[fs:si+8]
  561.        imul   [DWORD PTR gs:bx+8]
  562.        shrd   eax,edx,9
  563.        add    ecx,eax
  564.        add    ecx,[DWORD PTR gs:bx+12]
  565.        mov    [es:di],ecx
  566.        add    di,4
  567.        add    bx,16
  568.        pop    cx
  569.        loop   @@11
  570.        leave
  571.        ret    @@return
  572.   ENDP
  573.  
  574.  
  575.  
  576. ;≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
  577. ; procedure Rotate(rx,ry,rz :Integer; var R :TMatrix);
  578. ;≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
  579.   PROC Rotate FAR
  580.        ARG R:DWord, rz:Word, ry:Word, rx:Word = @@return
  581.        LOCAL SinX:DWord,SinY:DWord,SinZ:DWord,CosX:DWord,CosY:DWord,CosZ:DWord,A:DWord,B:DWord = @@local
  582.        enter  @@local,0
  583.        les    di,[R]
  584.        push   di
  585.        mov    cx,(4*4*4)/4
  586.        xor    eax,eax
  587.        repne  stosd
  588.        pop    di
  589.  
  590.        mov    bx,[rx]
  591.        call   FixSin
  592.        mov    [SinX],eax
  593.        mov    bx,[rx]
  594.        call   FixCos
  595.        mov    [CosX],eax
  596.        mov    bx,[ry]
  597.        call   FixSin
  598.        mov    [SinY],eax
  599.        mov    bx,[ry]
  600.        call   FixCos
  601.        mov    [CosY],eax
  602.        mov    bx,[rz]
  603.        call   FixSin
  604.        mov    [SinZ],eax
  605.        mov    bx,[rz]
  606.        call   FixCos
  607.        mov    [CosZ],eax
  608.  
  609.        imul   [SinY]
  610.        shrd   eax,edx,9
  611.        mov    [A],eax
  612.        mov    eax,[SinZ]
  613.        imul   [SinY]
  614.        shrd   eax,edx,9
  615.        mov    [B],eax
  616.        mov    eax,[CosZ]
  617.        imul   [CosY]
  618.        shrd   eax,edx,9
  619.        mov    [es:di],eax
  620.        mov    eax,[A]
  621.        imul   [SinX]
  622.        shrd   eax,edx,9
  623.        mov    ebx,eax
  624.        mov    eax,[SinZ]
  625.        imul   [CosX]
  626.        shrd   eax,edx,9
  627.        sub    ebx,eax
  628.        mov    [es:di+4],ebx
  629.        mov    eax,[A]
  630.        imul   [CosX]
  631.        shrd   eax,edx,9
  632.        mov    ebx,eax
  633.        mov    eax,[SinZ]
  634.        imul   [SinX]
  635.        shrd   eax,edx,9
  636.        add    eax,ebx
  637.        mov    [es:di+8],eax
  638.        mov    eax,[SinZ]
  639.        imul   [CosY]
  640.        shrd   eax,edx,9
  641.        mov    [es:di+16],eax
  642.        mov    eax,[B]
  643.        imul   [SinX]
  644.        shrd   eax,edx,9
  645.        mov    ebx,eax
  646.        mov    eax,[CosZ]
  647.        imul   [CosX]
  648.        shrd   eax,edx,9
  649.        add    eax,ebx
  650.        mov    [es:di+20],eax
  651.        mov    eax,[B]
  652.        imul   [CosX]
  653.        shrd   eax,edx,9
  654.        mov    ebx,eax
  655.        mov    eax,[CosZ]
  656.        imul   [SinX]
  657.        shrd   eax,edx,9
  658.        sub    ebx,eax
  659.        mov    [es:di+24],ebx
  660.        mov    eax,[SinY]
  661.        neg    eax
  662.        mov    [es:di+32],eax
  663.        mov    eax,[CosY]
  664.        imul   [SinX]
  665.        shrd   eax,edx,9
  666.        mov    [es:di+36],eax
  667.        mov    eax,[CosY]
  668.        imul   [CosX]
  669.        shrd   eax,edx,9
  670.        mov    [es:di+40],eax
  671.        mov    eax,200h
  672.        mov    [es:di+60],eax
  673.        leave
  674.        ret    @@return
  675.   ENDP
  676.  
  677.  
  678.  
  679. ;≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
  680. ; procedure Create(tx,ty,tz, sx,sy,sz :LongInt; rx,ry,rz :Integer; var M :TMatrix);
  681. ;≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
  682.   PROC Create FAR
  683.        ARG M:DWord, rz:Word, ry:Word, rx:Word, sz:DWord, sy:DWord, sx:DWord, tz:DWord, ty:DWord, tx:DWord = @@return
  684.        LOCAL SinX:DWord,SinY:DWord,SinZ:DWord,CosX:DWord,CosY:DWord,CosZ:DWord,A:DWord,B:DWord = @@local
  685.        enter  @@local,0
  686.        les    di,[M]
  687.        push   di
  688.        mov    cx,(4*4*4)/4
  689.        xor    eax,eax
  690.        repne  stosd
  691.        pop    di
  692.  
  693.        mov    bx,[rx]
  694.        call   FixSin
  695.        mov    [SinX],eax
  696.        mov    bx,[rx]
  697.        call   FixCos
  698.        mov    [CosX],eax
  699.        mov    bx,[ry]
  700.        call   FixSin
  701.        mov    [SinY],eax
  702.        mov    bx,[ry]
  703.        call   FixCos
  704.        mov    [CosY],eax
  705.        mov    bx,[rz]
  706.        call   FixSin
  707.        mov    [SinZ],eax
  708.        mov    bx,[rz]
  709.        call   FixCos
  710.        mov    [CosZ],eax
  711.  
  712.        imul   [SinY]
  713.        shrd   eax,edx,9
  714.        mov    [A],eax
  715.        mov    eax,[SinZ]
  716.        imul   [SinY]
  717.        shrd   eax,edx,9
  718.        mov    [B],eax
  719.        mov    eax,[CosZ]
  720.        imul   [CosY]
  721.        shrd   eax,edx,9
  722.        imul   [sx]
  723.        shrd   eax,edx,9
  724.        mov    [es:di],eax
  725.        mov    eax,[SinZ]
  726.        imul   [CosX]
  727.        shrd   eax,edx,9
  728.        mov    ebx,eax
  729.        mov    eax,[A]
  730.        imul   [SinX]
  731.        shrd   eax,edx,9
  732.        sub    eax,ebx
  733.        imul   [sx]
  734.        shrd   eax,edx,9
  735.        mov    [es:di+4],eax
  736.        mov    eax,[A]
  737.        imul   [CosX]
  738.        shrd   eax,edx,9
  739.        mov    ebx,eax
  740.        mov    eax,[SinZ]
  741.        imul   [SinX]
  742.        shrd   eax,edx,9
  743.        add    eax,ebx
  744.        imul   [sx]
  745.        shrd   eax,edx,9
  746.        mov    [es:di+8],eax
  747.        mov    eax,[SinZ]
  748.        imul   [CosY]
  749.        shrd   eax,edx,9
  750.        imul   [sy]
  751.        shrd   eax,edx,9
  752.        mov    [es:di+16],eax
  753.        mov    eax,[B]
  754.        imul   [SinX]
  755.        shrd   eax,edx,9
  756.        mov    ebx,eax
  757.        mov    eax,[CosZ]
  758.        imul   [CosX]
  759.        shrd   eax,edx,9
  760.        add    eax,ebx
  761.        imul   [sy]
  762.        shrd   eax,edx,9
  763.        mov    [es:di+20],eax
  764.        mov    eax,[CosZ]
  765.        imul   [SinX]
  766.        shrd   eax,edx,9
  767.        mov    ebx,eax
  768.        mov    eax,[B]
  769.        imul   [CosX]
  770.        shrd   eax,edx,9
  771.        sub    eax,ebx
  772.        imul   [sy]
  773.        shrd   eax,edx,9
  774.        mov    [es:di+24],eax
  775.        mov    eax,[SinY]
  776.        neg    eax
  777.        imul   [sz]
  778.        shrd   eax,edx,9
  779.        mov    [es:di+32],eax
  780.        mov    eax,[CosY]
  781.        imul   [SinX]
  782.        shrd   eax,edx,9
  783.        imul   [sz]
  784.        shrd   eax,edx,9
  785.        mov    [es:di+36],eax
  786.        mov    eax,[CosY]
  787.        imul   [CosX]
  788.        shrd   eax,edx,9
  789.        imul   [sz]
  790.        shrd   eax,edx,9
  791.        mov    [es:di+40],eax
  792.        mov    eax,[tx]
  793.        imul   [sx]
  794.        shrd   eax,edx,9
  795.        mov    [es:di+12],eax
  796.        mov    eax,[ty]
  797.        imul   [sy]
  798.        shrd   eax,edx,9
  799.        mov    [es:di+28],eax
  800.        mov    eax,[tz]
  801.        imul   [sz]
  802.        shrd   eax,edx,9
  803.        mov    [es:di+44],eax
  804.        mov    eax,200h
  805.        mov    [es:di+60],eax
  806.        leave
  807.        ret    @@return
  808.   ENDP
  809.  
  810.  
  811.  
  812. ;≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
  813. ; procedure VecAdd2D(A,B :T2D; var C :T2D);
  814. ;≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
  815.   PROC VecAdd2D FAR
  816.        ARG C:DWord, B:DWord, A:DWord = @@return
  817.        enter  0,0
  818.        les    di,[C]
  819.        mov    ax,[WORD PTR A]
  820.        add    ax,[WORD PTR B]
  821.        stosw
  822.        mov    ax,[WORD PTR A+2]
  823.        add    ax,[WORD PTR B+2]
  824.        stosw
  825.        leave
  826.        ret    @@return
  827.   ENDP
  828.  
  829.  
  830.  
  831. ;≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
  832. ; procedure VecSub2D(A,B :T2D; var C :T2D);
  833. ;≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
  834.   PROC VecSub2D FAR
  835.        ARG C:DWord, B:DWord, A:DWord = @@return
  836.        enter  0,0
  837.        les    di,[C]
  838.        mov    ax,[WORD PTR A]
  839.        sub    ax,[WORD PTR B]
  840.        stosw
  841.        mov    ax,[WORD PTR A+2]
  842.        sub    ax,[WORD PTR B+2]
  843.        stosw
  844.        leave
  845.        ret    @@return
  846.   ENDP
  847.   END
  848.  
  849.