home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Raytrace & Morphing / SOS-RAYTRACE.ISO / programm / source / devel5 / intsplit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-12-07  |  2.6 KB  |  125 lines

  1. /* Splitting-tree assembly routines (should be private to splits.c) */
  2.  
  3. /* Written by Bernie Roehl, June 1992 */
  4. /* Substantially upgraded by Dave Stampe, August '92 */
  5.  
  6. /* Copyright 1992 by Dave Stampe and Bernie Roehl.
  7.      May be freely used to write software for release into the public domain;
  8.      all commercial endeavours MUST contact Bernie Roehl and Dave Stampe
  9.      for permission to incorporate any part of this software into their
  10.      products!
  11.  
  12.      ATTRIBUTION:  If you use any part of this source code or the libraries
  13.      in your projects, you must give attribution to REND386, Dave Stampe,
  14.      and Bernie Roehl in your documentation, source code, and at startup
  15.      of your program.  Let's keep the freeware ball rolling!
  16.  */
  17.  
  18. #pragma inline
  19.  
  20. #include <dos.h>
  21.  
  22. #include "3dstruct.h"
  23. #include "splitdef.h"
  24. #include "splits.h"
  25.  
  26. int _which_side(SPLIT *s, long tx,long ty,long tz)
  27. {
  28.     int sign = -1; /* dot product: > , < , = zero */
  29.  
  30.     asm{
  31.         .386
  32.         push cx
  33.         push di
  34.         les bx,DWORD PTR s
  35.  
  36.         mov eax,DWORD PTR es:[bx].(SPLIT)nx
  37.         mov edx,DWORD PTR tx
  38.         sub edx,DWORD PTR es:[bx].(SPLIT)x
  39.         imul edx
  40.         mov ecx,eax
  41.         mov edi,edx
  42.         mov eax,DWORD PTR es:[bx].(SPLIT)ny
  43.         mov edx,DWORD PTR ty
  44.         sub edx,DWORD PTR es:[bx].(SPLIT)y
  45.         imul edx
  46.         add ecx,eax
  47.         adc edi,edx
  48.         mov eax,DWORD PTR es:[bx].(SPLIT)nz
  49.         mov edx,DWORD PTR tz
  50.         sub edx,DWORD PTR es:[bx].(SPLIT)z
  51.         imul edx
  52.         add ecx,eax
  53.         adc edi,edx
  54.         jl alldone
  55.         neg WORD PTR sign
  56.         or edi,ecx
  57.         jnz alldone
  58.         mov WORD PTR sign, di
  59.     }
  60. alldone:
  61.     asm {
  62.         pop di
  63.         pop cx
  64.         }
  65.     return sign;
  66. }
  67.  
  68.  
  69. void *_fast_split_descent(SPLIT *tree, long x, long y, long z, char *type)
  70. {
  71.     asm {
  72.         push si
  73.         push cx
  74.         les bx,DWORD PTR tree
  75.         }
  76. next:
  77.     asm {
  78.         or bx,bx
  79.         jz endtree
  80.         mov eax,DWORD PTR es:[bx].(SPLIT)nx
  81.         mov edx,DWORD PTR x
  82.         sub edx,DWORD PTR es:[bx].(SPLIT)x
  83.         imul edx
  84.         mov esi,eax
  85.         mov ecx,edx
  86.         mov eax,DWORD PTR es:[bx].(SPLIT)ny
  87.         mov edx,DWORD PTR y
  88.         sub edx,DWORD PTR es:[bx].(SPLIT)y
  89.         imul edx
  90.         add esi,eax
  91.         adc ecx,edx
  92.         mov eax,DWORD PTR es:[bx].(SPLIT)nz
  93.         mov edx,DWORD PTR z
  94.         sub edx,DWORD PTR es:[bx].(SPLIT)z
  95.         imul edx
  96.         add esi,eax
  97.         adc ecx,edx
  98.         jge right
  99.         mov al,BYTE PTR es:bx.(SPLIT)left_type
  100.         les bx,DWORD PTR es:bx.(SPLIT)left
  101.         cmp al,ISSPLIT
  102.         je next
  103.         jmp endtree
  104.         }
  105. right:
  106.     asm {
  107.         mov al,BYTE PTR es:bx.(SPLIT)right_type
  108.         les bx,DWORD PTR es:bx.(SPLIT)right
  109.         cmp al,ISSPLIT
  110.         je next
  111.         }
  112. endtree:
  113.     asm {
  114.         mov cl,al
  115.         mov ax,bx
  116.         mov dx,es
  117.         les bx,DWORD PTR type
  118.         mov es:bx,cl
  119.         pop cx
  120.         pop si
  121.         }
  122.     return; /* the return value is in DX:AX */
  123. }
  124.  
  125.