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

  1.     TITLE    ANIMATE - Animation computations IN ASSEMBLER
  2.  
  3.     COMMENT $
  4.  
  5. /* Support for statmach.c, assembly by Dave Stampe */
  6. /* ported to assembly modules by D. Stampe 12/12/93 */
  7.  
  8.  
  9. /*
  10.  This code is part of the VR-386 project, created by Dave Stampe.
  11.  VR-386 is a desendent of REND386, created by Dave Stampe and
  12.  Bernie Roehl.  Almost all the code has been rewritten by Dave
  13.  Stampre for VR-386.
  14.  
  15.  Copyright (c) 1994 by Dave Stampe:
  16.  May be freely used to write software for release into the public domain
  17.  or for educational use; all commercial endeavours MUST contact Dave Stampe
  18.  (dstampe@psych.toronto.edu) for permission to incorporate any part of
  19.  this software or source code into their products!  Usually there is no
  20.  charge for under 50-100 items for low-cost or shareware products, and terms
  21.  are reasonable.  Any royalties are used for development, so equipment is
  22.  often acceptable payment.
  23.  
  24.  ATTRIBUTION:  If you use any part of this source code or the libraries
  25.  in your projects, you must give attribution to VR-386 and Dave Stampe,
  26.  and any other authors in your documentation, source code, and at startup
  27.  of your program.  Let's keep the freeware ball rolling!
  28.  
  29.  DEVELOPMENT: VR-386 is a effort to develop the process started by
  30.  REND386, improving programmer access by rewriting the code and supplying
  31.  a standard API.  If you write improvements, add new functions rather
  32.  than rewriting current functions.  This will make it possible to
  33.  include you improved code in the next API release.  YOU can help advance
  34.  VR-386.  Comments on the API are welcome.
  35.  
  36.  CONTACT: dstampe@psych.toronto.edu
  37. */
  38.  
  39. This code will be less useful for 32-bit C compilers.  Nonetheless,
  40. it needs 64-bit intermediate results.  It could be redone using the
  41. new function mulmuldiv(), though.
  42.  
  43.  
  44. /* Contact: dstampe@sunee.waterloo.edu */
  45.  
  46.         $
  47.  
  48.     .MODEL large
  49.  
  50.     .DATA
  51.  
  52. include animate.inc
  53.  
  54.     .CODE
  55.     .386
  56.  
  57. ;/***************** SUPPORT FOR STATMACH.C **************/
  58.  
  59.  
  60. ;void scaled_rotate(STATE *s, long *nrx,long *nry,long *nrz, long elpsed, long tps);
  61.  
  62. s    equ    [bp+8]          ; arguments
  63. pnrx    equ    [bp+12]
  64. pnry    equ    [bp+16]
  65. pnrz    equ    [bp+20]
  66. elapsed    equ    [bp+24]         ; elapsed time
  67. tps    equ    [bp+28]         ; ticks per sec: 0 for no scaling
  68.  
  69.     PUBLIC    _scaled_rotate
  70.  
  71. _scaled_rotate     proc    far
  72.  
  73.     .386
  74.     push    ebp
  75.     mov    ebp,esp
  76.     push    ds
  77.     push    di
  78.  
  79.     les    bx,DWORD PTR s
  80.  
  81.     mov    eax,es:[bx].ST_x2    ; get rotate step
  82.     test    DWORD PTR tps,-1        ; any scale?
  83.     je    no_scale_rx
  84.  
  85.     imul    DWORD PTR elapsed       ; scale by time
  86.     idiv    DWORD PTR tps
  87.  
  88. no_scale_rx:
  89.     lds    di,DWORD PTR pnrx       ; get present angle
  90.     add    eax,ds:[di]             ; add in
  91.     cmp    eax,-360*65536          ; clip angle
  92.     jg    nccx
  93.     add    eax,360*65536
  94. nccx:
  95.     cmp    eax,360*65536
  96.     jl    nchx
  97.     sub    eax,360*65536
  98. nchx:
  99.     mov    ds:[di],eax             ; store new angle
  100.  
  101.     mov    eax,es:[bx].ST_y2       ; repeat for Y
  102.     test    DWORD PTR tps,-1
  103.     je    no_scale_ry
  104.  
  105.     imul    DWORD PTR elapsed
  106.     idiv    DWORD PTR tps
  107.  
  108. no_scale_ry:
  109.     lds    di,DWORD PTR pnry
  110.     add    eax,ds:[di]
  111.     cmp    eax,-360*65536
  112.     jg    nccy
  113.     add    eax,360*65536
  114. nccy:
  115.     cmp    eax,360*65536
  116.     jl    nchy
  117.     sub    eax,360*65536
  118. nchy:
  119.     mov    ds:[di],eax
  120.  
  121.     mov    eax,es:[bx].ST_z2
  122.     test    DWORD PTR tps,-1
  123.     je    no_scale_rz
  124.  
  125.     imul    DWORD PTR elapsed
  126.     idiv    DWORD PTR tps
  127.  
  128. no_scale_rz:
  129.     lds    di,DWORD PTR pnrz      ; repeat for Z
  130.     add    eax,ds:[di]
  131.     cmp    eax,-360*65536
  132.     jg    nccz
  133.     add    eax,360*65536
  134. nccz:
  135.     cmp    eax,360*65536
  136.     jl    nchz
  137.     sub    eax,360*65536
  138. nchz:
  139.     mov    ds:[di],eax
  140.  
  141.     pop    di
  142.     pop    ds
  143.     mov    esp,ebp
  144.     pop    ebp
  145.     ret
  146.  
  147. _scaled_rotate    endp
  148.  
  149.  
  150.  
  151.  
  152. ;void scaled_move(STATE *s, long *nx,long *ny,long *nz, long elapsed, long tps);
  153.  
  154.  
  155. s    equ    [bp+8]          ; arguments
  156. pnx    equ    [bp+12]
  157. pny    equ    [bp+16]
  158. pnz    equ    [bp+20]
  159. elapsed    equ    [bp+24]         ; elapsed time
  160. tps    equ    [bp+28]         ; ticks per sec: 0 for no scaling
  161.  
  162.     PUBLIC    _scaled_move
  163.  
  164. _scaled_move     proc    far
  165.  
  166.     .386
  167.     push    ebp
  168.     mov    ebp,esp
  169.     push    ds
  170.     push    di
  171.  
  172.     les    bx,DWORD PTR s
  173.  
  174.     mov      eax,es:[bx].ST_x1
  175.     or    eax,eax
  176.     je    no_x_move
  177.     test    DWORD PTR tps, -1
  178.     je    no_xmove_scale
  179.     imul     DWORD PTR elapsed
  180.     idiv     DWORD PTR tps
  181. no_xmove_scale:
  182.     mov      dl,BYTE PTR es:[bx].ST_xo1
  183.     mov      dh,al
  184.     sar      eax,8
  185.     add      dl,dh
  186.     lds    di,pnx
  187.     adc      ds:[di],eax
  188.     mov      BYTE PTR es:[bx].ST_xo1,dl
  189. no_x_move:
  190.  
  191.     mov      eax,es:[bx].ST_y1
  192.     or    eax,eax
  193.     je    no_y_move
  194.     test    DWORD PTR tps, -1
  195.     je    no_ymove_scale
  196.     imul     DWORD PTR elapsed
  197.     idiv     DWORD PTR tps
  198. no_ymove_scale:
  199.     mov      dl,BYTE PTR es:[bx].ST_yo1
  200.     mov      dh,al
  201.     sar      eax,8
  202.     add      dl,dh
  203.     lds    di,pny
  204.     adc      ds:[di],eax
  205.     mov      BYTE PTR es:[bx].ST_yo1,dl
  206. no_y_move:
  207.  
  208.     mov      eax,es:[bx].ST_z1
  209.     or    eax,eax
  210.     je    no_z_move
  211.     test    DWORD PTR tps, -1
  212.     je    no_zmove_scale
  213.     imul     DWORD PTR elapsed
  214.     idiv     DWORD PTR tps
  215. no_zmove_scale:
  216.     mov      dl,BYTE PTR es:[bx].ST_zo1
  217.     mov      dh,al
  218.     sar      eax,8
  219.     add      dl,dh
  220.     lds    di,pnz
  221.     adc      ds:[di],eax
  222.     mov      BYTE PTR es:[bx].ST_zo1,dl
  223. no_z_move:
  224.  
  225.     pop    di
  226.     pop    ds
  227.     mov    esp,ebp
  228.     pop    ebp
  229.     ret
  230.  
  231. _scaled_move    endp
  232.  
  233.  
  234. ; void scaled_gravity(STATE *s, long elpsed, long tps);
  235.  
  236.  
  237. s    equ    [bp+8]          ; arguments
  238. elapsed    equ    [bp+12]         ; elapsed time
  239. tps    equ    [bp+16]         ; ticks per sec: 0 for no scaling
  240.  
  241.     PUBLIC    _scaled_gravity
  242.  
  243. _scaled_gravity    proc    far
  244.  
  245.     .386
  246.     push    ebp
  247.     mov    ebp,esp
  248.  
  249.     les    bx,DWORD PTR s
  250.  
  251.     mov       eax,es:[bx].ST_x3    ; get gravity acceleration
  252.     or    eax,eax
  253.     je    no_x_gravity         ; none?
  254.  
  255.     imul      DWORD PTR elapsed    ; scale by time
  256.     idiv      DWORD PTR tps
  257.     mov       dl,al                ; underflow integerate
  258.     sar       eax,8
  259.     add       dl,BYTE PTR es:[bx].ST_xo2
  260.     adc       es:[bx].ST_x1,eax
  261.     mov       BYTE PTR es:[bx].ST_xo2,dl    ; add to velocity
  262. no_x_gravity:
  263.  
  264.     mov       eax,es:[bx].ST_y3    ; repeat for y
  265.     or    eax,eax
  266.     je    no_y_gravity
  267.  
  268.     imul      DWORD PTR elapsed
  269.     idiv      DWORD PTR tps
  270.     mov       dl,al
  271.     sar       eax,8
  272.     add       dl,BYTE PTR es:[bx].ST_yo2
  273.     adc       es:[bx].ST_y1,eax
  274.     mov       BYTE PTR es:[bx].ST_yo2,dl
  275. no_y_gravity:
  276.  
  277.     mov       eax,es:[bx].ST_z3    ; repeat for Z
  278.     or    eax,eax
  279.     je    no_z_gravity
  280.  
  281.     imul      DWORD PTR elapsed
  282.     idiv      DWORD PTR tps
  283.     mov       dl,al
  284.     sar       eax,8
  285.     add       dl,BYTE PTR es:[bx].ST_zo2
  286.     adc       es:[bx].ST_z1,eax
  287.     mov       BYTE PTR es:[bx].ST_zo2,dl
  288. no_z_gravity:
  289.  
  290.     mov    esp,ebp
  291.     pop    ebp
  292.     ret
  293.  
  294. _scaled_gravity    endp
  295.  
  296.  
  297.  
  298.     end
  299.  
  300.