home *** CD-ROM | disk | FTP | other *** search
/ Virtual Reality Homebrewer's Handbook / vr.iso / vr386 / intsplit.asm < prev    next >
Assembly Source File  |  1996-03-19  |  4KB  |  179 lines

  1.     TITLE    INTSPLIT - Splitting-tree assembly routines (should be private to splits.c)
  2.  
  3.  
  4.     COMMENT    $
  5. /*
  6.  This code is part of the VR-386 project, created by Dave Stampe.
  7.  VR-386 is a desendent of REND386, created by Dave Stampe and
  8.  Bernie Roehl.  Almost all the code has been rewritten by Dave
  9.  Stampre for VR-386.
  10.  
  11.  Copyright (c) 1994 by Dave Stampe:
  12.  May be freely used to write software for release into the public domain
  13.  or for educational use; all commercial endeavours MUST contact Dave Stampe
  14.  (dstampe@psych.toronto.edu) for permission to incorporate any part of
  15.  this software or source code into their products!  Usually there is no
  16.  charge for under 50-100 items for low-cost or shareware products, and terms
  17.  are reasonable.  Any royalties are used for development, so equipment is
  18.  often acceptable payment.
  19.  
  20.  ATTRIBUTION:  If you use any part of this source code or the libraries
  21.  in your projects, you must give attribution to VR-386 and Dave Stampe,
  22.  and any other authors in your documentation, source code, and at startup
  23.  of your program.  Let's keep the freeware ball rolling!
  24.  
  25.  DEVELOPMENT: VR-386 is a effort to develop the process started by
  26.  REND386, improving programmer access by rewriting the code and supplying
  27.  a standard API.  If you write improvements, add new functions rather
  28.  than rewriting current functions.  This will make it possible to
  29.  include you improved code in the next API release.  YOU can help advance
  30.  VR-386.  Comments on the API are welcome.
  31.  
  32.  CONTACT: dstampe@psych.toronto.edu
  33. */
  34.  
  35.  
  36.  
  37. All code in this module by Dave Stampe
  38. Splits are an important part of VR-386: this code makes them work
  39. faster.  Probably not needed for a true 32-bit compiler.
  40.  
  41.         $
  42.  
  43.         .MODEL large
  44.  
  45. include splitdef.inc
  46.  
  47. ;int _which_side(SPLIT *s, long tx,long ty,long tz)
  48. ;{
  49.  
  50.         .CODE INTMATH
  51.  
  52. s    equ    [bp+8]          ; arguments
  53. tx    equ    [bp+12]
  54. ty    equ    [bp+16]
  55. tz    equ    [bp+20]
  56.  
  57. side    equ    [bp-4]        ; locals
  58.  
  59.  
  60.  
  61.  
  62.         PUBLIC    __which_side
  63.  
  64. __which_side     proc    far
  65.  
  66.     .386
  67.     push    ebp
  68.     mov    ebp,esp
  69.     sub    esp,4
  70.     push     ecx
  71.     push     edi
  72.     les     bx,DWORD PTR s
  73.     mov    DWORD PTR side,-1
  74.  
  75.     mov     eax,DWORD PTR es:[bx].split_nx ; dot prod.
  76.     mov     edx,DWORD PTR tx               ; Ns . (t-s)
  77.     sub     edx,DWORD PTR es:[bx].split_x
  78.     imul     edx
  79.     mov     ecx,eax
  80.     mov     edi,edx
  81.     mov     eax,DWORD PTR es:[bx].split_ny
  82.     mov     edx,DWORD PTR ty
  83.     sub     edx,DWORD PTR es:[bx].split_y
  84.     imul     edx
  85.     add     ecx,eax
  86.     adc     edi,edx
  87.     mov     eax,DWORD PTR es:[bx].split_nz
  88.     mov     edx,DWORD PTR tz
  89.     sub     edx,DWORD PTR es:[bx].split_z
  90.     imul     edx
  91.     add     ecx,eax
  92.     adc     edi,edx            ; negative
  93.     jl     alldone
  94.     neg    DWORD PTR side
  95.     or     edi,ecx            ; positive
  96.     jnz     alldone
  97.     mov     WORD PTR side, di  ; zero:
  98. alldone:
  99.     mov    eax,side
  100.     pop     edi
  101.     pop     ecx
  102.     mov    esp,ebp
  103.     pop    ebp
  104.     ret
  105.  
  106. __which_side    endp
  107.  
  108.  
  109.  
  110. ;void *_fast_split_descent(SPLIT *tree, long x, long y, long z, char *type)
  111.  
  112.  
  113. tree    equ    [bp+8]          ; arguments
  114. x    equ    [bp+12]
  115. y    equ    [bp+16]
  116. z    equ    [bp+20]
  117. type    equ    [bp+24]
  118.  
  119.  
  120.     PUBLIC    __fast_split_descent
  121.  
  122. __fast_split_descent    proc    far
  123.  
  124.     .386
  125.     push    ebp
  126.     mov    ebp,esp
  127.     push     esi
  128.     push     ecx
  129.     les     bx,DWORD PTR tree
  130. next:
  131.     or     bx,bx        ; test for NULL ptr
  132.     jz     endtree
  133.     mov     eax,DWORD PTR es:[bx].split_nx ; side-of-surface dot product
  134.     mov     edx,DWORD PTR x
  135.     sub     edx,DWORD PTR es:[bx].split_x
  136.     imul     edx
  137.     mov     esi,eax
  138.     mov     ecx,edx
  139.     mov     eax,DWORD PTR es:[bx].split_ny
  140.     mov     edx,DWORD PTR y
  141.     sub     edx,DWORD PTR es:[bx].split_y
  142.     imul     edx
  143.     add     esi,eax
  144.     adc     ecx,edx
  145.     mov     eax,DWORD PTR es:[bx].split_nz
  146.     mov     edx,DWORD PTR z
  147.     sub     edx,DWORD PTR es:[bx].split_z
  148.     imul     edx
  149.     add     esi,eax
  150.     adc     ecx,edx    ; positive/zero
  151.     jge     right
  152.     mov     al,BYTE PTR es:bx.split_ltype  ; left walk
  153.     les     bx,DWORD PTR es:bx.split_leftptr
  154.     cmp     al,ISSPLIT
  155.     je     next
  156.     jmp     endtree
  157. right:
  158.     mov     al,BYTE PTR es:bx.split_rtype
  159.     les     bx,DWORD PTR es:bx.split_rightptr
  160.     cmp     al,ISSPLIT
  161.     je     next
  162. endtree:
  163.     mov     cl,al
  164.     mov     ax,bx
  165.     mov     dx,es
  166.     les     bx,DWORD PTR type
  167.     mov     es:bx,cl
  168.  
  169.     pop     ecx
  170.     pop     esi
  171.     mov    esp,ebp
  172.     pop    ebp
  173.     ret
  174.  
  175. __fast_split_descent    endp
  176.  
  177.  
  178.     end
  179.