home *** CD-ROM | disk | FTP | other *** search
/ Fractal Creations (Second Edition) / FRACTALS_2E.iso / frasrc.exe / LSYSA.ASM < prev    next >
Assembly Source File  |  1992-01-29  |  4KB  |  218 lines

  1. ; LSYSA.ASM: assembler support routines for optimized L-System code
  2. ; Nicholas Wilt, 11/13/91.
  3. ;
  4.  
  5. .MODEL    MEDIUM,C
  6.  
  7. EXTRN    reverse:BYTE,angle:BYTE,maxangle:BYTE,dmaxangle:BYTE
  8. EXTRN    xpos:DWORD,ypos:DWORD,ssize:DWORD
  9. EXTRN    realangle:DWORD
  10. EXTRN    lsys_Xmin:DWORD,lsys_Xmax:DWORD,lsys_Ymin:DWORD,lsys_Ymax:DWORD
  11. EXTRN    sins:DWORD
  12. EXTRN    coss:DWORD
  13. EXTRN    overflow:WORD
  14.  
  15. .CODE
  16.  
  17. decangle    PROC    NEAR
  18.     mov    al,angle
  19.     or    al,al
  20.     jz    DecAngle0
  21.     dec    angle
  22.     ret
  23. DecAngle0:
  24.     mov    al,dmaxangle
  25.     mov    angle,al
  26.     ret
  27. decangle    ENDP
  28.  
  29. incangle    PROC    NEAR
  30.     mov    al,angle
  31.     inc    al
  32.     cmp    al,maxangle
  33.     jnz    IncWriteAngle
  34.     xor    ax,ax
  35. IncWriteAngle:
  36.     mov    angle,al
  37.     ret
  38. incangle    ENDP
  39.  
  40.     PUBLIC    lsys_doplus
  41.  
  42. lsys_doplus    PROC
  43.     cmp    reverse,0
  44.     jnz    PlusIncAngle
  45.     call    decangle
  46.     ret
  47. PlusIncAngle:
  48.     call    incangle
  49.     ret
  50. lsys_doplus    ENDP
  51.  
  52.     PUBLIC    lsys_dominus
  53.  
  54. lsys_dominus    PROC
  55.     cmp    reverse,0
  56.     jnz    MinusDecAngle
  57.     call    incangle
  58.     ret
  59. MinusDecAngle:
  60.     call    decangle
  61.     ret
  62. lsys_dominus    ENDP
  63.  
  64.     PUBLIC    lsys_doplus_pow2
  65.  
  66. lsys_doplus_pow2    PROC
  67.     mov    al,angle
  68.     cmp    reverse,0
  69.     jnz    Plus2IncAngle
  70.     dec    al
  71.     and    al,dmaxangle
  72.     mov    angle,al
  73.     ret
  74. Plus2IncAngle:
  75.     inc    al
  76.     and    al,dmaxangle
  77.     mov    angle,al
  78.     ret
  79. lsys_doplus_pow2    ENDP
  80.  
  81.     PUBLIC    lsys_dominus_pow2
  82.  
  83. lsys_dominus_pow2     PROC
  84.     mov    al,angle
  85.     cmp    reverse,0
  86.     jz    Minus2IncAngle
  87.     dec    al
  88.     and    al,dmaxangle
  89.     mov    angle,al
  90.     ret
  91. Minus2IncAngle:
  92.     inc    al
  93.     and    al,dmaxangle
  94.     mov    angle,al
  95.     ret
  96. lsys_dominus_pow2     ENDP
  97.  
  98.     PUBLIC    lsys_dopipe_pow2
  99.  
  100. lsys_dopipe_pow2    PROC
  101.     xor    ax,ax
  102.     mov    al,maxangle
  103.     shr    ax,1
  104.     xor    dx,dx
  105.     mov    dl,angle
  106.     add    ax,dx
  107.     and    al,dmaxangle
  108.     mov    angle,al
  109.     ret
  110. lsys_dopipe_pow2    ENDP
  111.  
  112.     PUBLIC    lsys_dobang
  113.  
  114. lsys_dobang    PROC
  115.     mov    al,reverse    ; reverse = ! reverse;
  116.     dec    al        ; -1 if was 0; 0 if was 1
  117.     neg    al        ; 1 if was 0; 0 if was 1
  118.     mov    reverse,al    ;
  119.     ret
  120. lsys_dobang    ENDP
  121.  
  122. ; Some 386-specific leaf functions go here.
  123.  
  124. .386
  125.  
  126.     PUBLIC    lsys_doslash_386
  127.  
  128. lsys_doslash_386    PROC    N:DWORD
  129.     mov    eax,N
  130.     cmp    reverse,0
  131.     jnz    DoSlashDec
  132.     add    realangle,eax
  133.     ret
  134. DoSlashDec:
  135.     sub    realangle,eax
  136.     ret
  137. lsys_doslash_386    ENDP
  138.  
  139.     PUBLIC    lsys_dobslash_386
  140.  
  141. lsys_dobslash_386     PROC     N:DWORD
  142.     mov    eax,N
  143.     cmp    reverse,0
  144.     jz    DoBSlashDec
  145.     add    realangle,eax
  146.     ret
  147. DoBSlashDec:
  148.     sub    realangle,eax
  149.     ret
  150. lsys_dobslash_386     ENDP
  151.  
  152.     PUBLIC    lsys_doat_386
  153.  
  154. lsys_doat_386    PROC    N:DWORD
  155.     mov    eax,ssize    ; Get size
  156.     imul    N        ; Mul by n
  157.     shrd    eax,edx,19    ; Shift right 19 bits
  158.     mov    ssize,eax    ; Save back
  159.     ret
  160. lsys_doat_386    ENDP
  161.  
  162.     PUBLIC    lsys_dosizegf_386
  163.  
  164. lsys_dosizegf_386    PROC
  165.     mov    ecx,ssize    ; Get size; we'll need it twice
  166.     xor    bx,bx        ; BX <- angle*sizeof(int)
  167.     mov    bl,angle    ;
  168.     shl    bx,1        ;
  169.     shl    bx,1        ;
  170.     mov    eax,coss[bx]    ; eax <- coss[angle]
  171.     imul    ecx        ; Mul by size
  172.     shrd    eax,edx,29    ; eax <- multiply(size, coss[angle], 29)
  173.     add    eax,xpos    ;
  174.     jno    nooverfl    ;   check for overflow
  175.     mov    overflow,1    ;    oops - flag the user later
  176. nooverfl: 
  177.     cmp    eax,lsys_Xmax    ; If xpos <= lsys_Xmax,
  178.     jle    GF1        ;   jump
  179.     mov    lsys_Xmax,eax    ;
  180. GF1:    cmp    eax,lsys_Xmin    ; If xpos >= lsys_Xmin
  181.     jge    GF2        ;   jump
  182.     mov    lsys_Xmin,eax    ;
  183. GF2:    mov    xpos,eax    ; Save xpos
  184.     mov    eax,sins[bx]    ; eax <- sins[angle]
  185.     imul    ecx        ;
  186.     shrd    eax,edx,29    ;
  187.     add    eax,ypos    ;
  188.     cmp    eax,lsys_Ymax    ; If ypos <= lsys_Ymax,
  189.     jle    GF3        ;   jump
  190.     mov    lsys_Ymax,eax    ;
  191. GF3:    cmp    eax,lsys_Ymin    ; If ypos >= lsys_Ymin
  192.     jge    GF4        ;   jump
  193.     mov    lsys_Ymin,eax    ;
  194. GF4:    mov    ypos,eax    ;
  195.     ret
  196. lsys_dosizegf_386    ENDP
  197.  
  198.     PUBLIC    lsys_dodrawg_386
  199.  
  200. lsys_dodrawg_386    PROC
  201.     mov    ecx,ssize    ; Because we need it twice
  202.     xor    bx,bx        ; BX <- angle * sizeof(int)
  203.     mov    bl,angle    ;
  204.     shl    bx,1        ;
  205.     shl    bx,1        ;
  206.     mov    eax,coss[bx]    ; eax <- coss[angle]
  207.     imul    ecx        ;
  208.     shrd    eax,edx,29    ;
  209.     add    xpos,eax    ; xpos += size*coss[angle] >> 29
  210.     mov    eax,sins[bx]    ; eax <- sins[angle]
  211.     imul    ecx        ; ypos += size*sins[angle] >> 29
  212.     shrd    eax,edx,29    ;
  213.     add    ypos,eax    ;
  214.     ret            ;
  215. lsys_dodrawg_386    ENDP
  216.  
  217.     END
  218.