home *** CD-ROM | disk | FTP | other *** search
/ The Equalizer BBS / equalizer-bbs-collection_2004.zip / equalizer-bbs-collection / DEMOSCENE-STUFF / IBYTES02.ZIP / SRC_HI!.ZIP / FASTFX.ASM < prev    next >
Assembly Source File  |  1994-08-08  |  12KB  |  703 lines

  1.         ideal
  2.         p386
  3.         model    large,pascal
  4.  
  5. TTEST        =    0
  6.  
  7. MY_FX_SEQ    =    1
  8.  
  9. USUALVGA    =    0
  10.  
  11. NCOLORS        =    8
  12.  
  13. NPOINTS        =    200;128;256*3/2
  14.  
  15.  
  16. PSEG        equ    DGROUP
  17.  
  18. MACRO    udata
  19.         ;ufardata    
  20.         udataseg
  21. ENDM
  22. MACRO    code
  23.         codeseg    FFX
  24. ENDM
  25.  
  26. public        set_fast_fx
  27. public        draw_fast_fx
  28. public        next_fast_fx
  29.  
  30.         code
  31.  
  32. ; -- set_fast_fx -----------------------------------------------
  33. ;
  34. MAXROTSPEED    =    4096*1/5
  35. ROTSPEEDSHIFT    =    6
  36. ROTACCELLERATE    =    3
  37.         udata
  38. fastfx_color    db    ?
  39.         db    ?    ; Used as align 2
  40. rotate_time    dw    ?    ; Rotate picture variables
  41. rotate_speed    dw    ?
  42. rotate_accel    dw    ?
  43. ROTCENTER_RAD    =    25    ; Radius where rotation occurs
  44. CROTTIMESTEP    =    20
  45. crot_time    dw    ?    ; Rotate center time
  46.  
  47. WEIGHTSHIFT    =    8
  48. MAXWEIGHT    =    1 shl WEIGHTSHIFT
  49. PAUSETIME    =    50
  50. fx0_weight    dw    ?
  51. fx0_proc    dw    ?
  52. fx1_weight    dw    ?
  53. fx1_proc    dw    ?
  54. pause_time    dw    ?
  55. chg_radius    dw    ?
  56. chg_rad_step    dw    ?
  57. randomnumb    dw    ?
  58.  
  59. fx_zoom    dd    ?
  60. fx_zstep    dd    ?
  61. DOWNZOOM    =    _FRACMUL*3/4
  62. UPZOOM        =    _FRACMUL+_FRACMUL/4
  63.         code
  64. proc        set_fast_fx    far
  65.     push    ds
  66.     mov    ax,PSEG
  67.     mov    ds,ax
  68.     assume    ds:PSEG
  69.     xor    eax,eax
  70.     mov    [rotate_time],ax
  71.     mov    [rotate_speed],ax
  72.     mov    [crot_time],ax
  73.     mov    [rotate_accel],ROTACCELLERATE
  74.     mov    [pause_time],PAUSETIME
  75.     mov    [fx0_weight],MAXWEIGHT
  76.     mov    [fx_zoom],_FRACMUL
  77.     mov    [fx_zstep],-_FRACMUL/256
  78.     mov    [fx1_weight],ax
  79. IF    MY_FX_SEQ eq 0
  80.     push    ds
  81.     xor    ax,ax
  82.     mov    ds,ax
  83.     mov    ax,[ds:46ch]
  84.     pop    ds
  85. ELSE
  86.     xor    ax,ax
  87. ENDIF
  88.     mov    [randomnumb],ax
  89.     call    get_rand_fx
  90.     mov    [fx0_proc],ax
  91.     call    get_rand_fx
  92.     mov    [fx1_proc],ax
  93.     mov    [chg_radius],_FRACMUL/2
  94.     mov    [chg_rad_step],4
  95.     pop    ds
  96.     assume    ds:nothing
  97.     ret
  98. endp        set_fast_fx
  99. ; -- get_rand_fx -----------------------------------------------
  100. ;
  101. label        different_fx    word
  102. IF    MY_FX_SEQ
  103. dw    _8_fx0,cycloid_4_fx,spiral_fx,square_fx,_8_fx0,_o_fx
  104. dw    cycloid_9_fx,cycloid_1_fx,_8_fx
  105. dw    0
  106. ELSE
  107. dw    cycloid_4_fx,cycloid_9_fx,_8_fx,spiral_fx,_8_fx0,_o_fx,square_fx,cycloid_1_fx
  108. ENDIF
  109. max_fx_number    =    ($-different_fx)/2
  110. proc        get_rand_fx    near
  111.         assume    ds:PSEG
  112. IF    MY_FX_SEQ eq 0
  113.     imul    ax,[randomnumb],133
  114.     add    ax,1
  115.     mov    [randomnumb],ax
  116.     xchg    al,ah
  117.     xor    dx,dx
  118.     mov    cx,max_fx_number
  119.     div    cx
  120.     movzx    edx,dx
  121.     mov    ax,[different_fx+edx*2]
  122. ELSE
  123. @@agen:
  124.     movzx    edx,[randomnumb]
  125.     add    [randomnumb],2
  126.     mov    ax,[different_fx+edx]
  127.     or    ax,ax
  128.     jnz    @@10
  129.     mov    [randomnumb],0
  130.     jmp    @@agen
  131. @@10:
  132. ENDIF
  133.     assume    ds:NOTHING
  134.     ret
  135. endp        get_rand_fx
  136.  
  137. ; -- draw_fast_fx ----------------------------------------------
  138. ;
  139.         code
  140. proc        draw_fast_fx    far
  141.     pushad
  142.     push    ds es fs gs
  143.     mov    bx,PSEG
  144.     mov    ds,bx
  145.     mov    es,bx
  146.     assume    ds:PSEG,es:PSEG
  147.     call    clear_page
  148.     push    ax
  149.     call    compute_fx_points
  150.     pop    es
  151.     call    draw_fx_points
  152.     pop    gs fs es ds
  153.     popad
  154.     nop    ; Just for case
  155.     ret
  156. endp        draw_fast_fx
  157. ; -- next_fast_fx ----------------------------------------------
  158. ;
  159. proc        next_fast_fx    far
  160.     push    ds es
  161.     mov    ax,PSEG
  162.     mov    ds,ax
  163.     mov    es,ax
  164.     call    next_rotate_time
  165.     call    next_weights
  166.     call    next_radius
  167.     call    next_zoom
  168.     pop    es ds
  169.     ret
  170. endp        next_fast_fx
  171. ; -- next_rotate_time ------------------------------------------
  172. ;
  173. proc        next_rotate_time    near
  174.     mov    ax,[rotate_speed]
  175.     add    ax,[rotate_accel]
  176.     cwd
  177.     xor    ax,dx
  178.     sub    ax,dx
  179.     cmp    ax,MAXROTSPEED
  180.     jb    @@1
  181.     neg    [rotate_accel]
  182. @@1:
  183.     xor    ax,dx
  184.     sub    ax,dx
  185.     mov    [rotate_speed],ax
  186.     sar    ax,ROTSPEEDSHIFT
  187.     add    [rotate_time],ax
  188.     add    [crot_time],CROTTIMESTEP
  189.     ret
  190. endp        next_rotate_time
  191. ; -- new_fx ----------------------------------------------------
  192. ;
  193. proc        new_fx    near
  194.     mov    [fx0_weight],MAXWEIGHT
  195.     mov    [fx1_weight],0
  196.     mov    ax,[fx1_proc]
  197.     mov    [fx0_proc],ax
  198.     call    get_rand_fx
  199.     mov    [fx1_proc],ax
  200.     ret
  201. endp        new_fx
  202. ; -- next_weights ----------------------------------------------
  203. ;
  204. proc        next_weights    near
  205.     cmp    [pause_time],0
  206.     je    @@work
  207.     ; Wait a lot show second fx
  208.     dec    [pause_time]
  209.     jnz    @@exit
  210.     ; Get new FX for show
  211.     jmp    @@exit
  212. @@work:
  213.     inc    [fx1_weight]
  214.     dec    [fx0_weight]
  215.     jnz    @@exit
  216.     ; Out of weight for first FX - pause the second
  217.     call    new_fx
  218.     mov    [pause_time],PAUSETIME
  219. @@exit:
  220.     ret
  221. endp        next_weights
  222. ; -- next_radius -----------------------------------------------
  223. ;
  224. proc        next_radius    near
  225.     xor    cx,cx
  226.     mov    ax,[chg_rad_step]
  227.     add    ax,[chg_radius]
  228.     jg    @@1
  229.     xor    ax,ax    ; Zero anyway
  230.     inc    cx
  231. @@1:
  232.     cmp    ax,_FRACMUL
  233.     jl    @@2
  234.     inc    cx
  235.     mov    ax,_FRACMUL
  236. @@2:
  237.     mov    [chg_radius],ax
  238.     jcxz    @@keepstep
  239.     neg    [chg_rad_step]
  240. @@keepstep:
  241.     ret
  242. endp        next_radius
  243. ; -- next_zoom -------------------------------------------------
  244. ;
  245. proc        next_zoom    near
  246.     mov    eax,[fx_zoom]
  247.     add    eax,[fx_zstep]
  248.     cmp    eax,UPZOOM
  249.     jae    @@20
  250.     cmp    eax,DOWNZOOM
  251.     jg    @@10
  252. @@20:
  253.     neg    [fx_zstep]
  254. @@10:
  255.     mov    [fx_zoom],eax
  256.     ret
  257. endp        next_zoom
  258.  
  259. ; -- clear_page ------------------------------------------------
  260. ;
  261. proc        clear_page    near
  262.     cld
  263.     push    es ax
  264.     mov    es,ax
  265.     xor    di,di
  266.     IF    USUALVGA
  267.     mov    cx,64000/4
  268.     ELSE
  269.     mov    dx,03c4h
  270.     mov    ax,0f02h
  271.     out    dx,ax
  272.     mov    cx,64000/4/4
  273.     ENDIF
  274.     xor    eax,eax
  275.     rep    stosd
  276.     pop    ax es
  277.     ret
  278. endp        clear_page
  279. ; -- compute_fx_points -----------------------------------------
  280. ;
  281.         udata
  282. diff_centerx    dw    ?
  283. diff_centery    dw    ?
  284. fx_points    dw    NPOINTS*2 dup(?)
  285.         code
  286. label        sine_table    word
  287. include    "sinetbl.inc"
  288. proc        compute_fx_points    near
  289.     mov    bx,[crot_time]
  290.     shr    bx,1
  291.     and    bx,_TWOPI-1
  292.     add    bx,bx
  293.     movsx    eax,[bx+sine_table]
  294.     mov    ecx,ROTCENTER_RAD
  295.     imul    ecx
  296.     sar    eax,_FRACBITS
  297.     mov    [diff_centerx],ax
  298.     sub    bx,_TWOPI/4*2
  299.     neg    bx
  300.     and    bx,(_TWOPI-1)*2
  301.     movsx    eax,[bx+sine_table]
  302.     imul    ecx
  303.     sar    eax,_FRACBITS
  304.     mov    [diff_centery],ax
  305. ; --------------
  306.     mov    di,offset fx_points
  307.     push    di
  308.     xor    ebp,ebp
  309. @@loop0:
  310.     push    di
  311.     call    [fx0_proc]
  312. MACRO    testdraw    color
  313. IF    TTEST
  314.     push    ax bx es
  315.     mov    cx,0a000h
  316.     mov    es,cx
  317.     mov    cl,color
  318.     add    ax,320/2
  319.     add    bx,200/2
  320.     call    draw_point
  321.     pop    es bx ax
  322. ENDIF
  323. ENDM
  324.     testdraw    0
  325.     pop    di
  326.     mov    [di],ax
  327.     mov    [di+2],bx
  328.     add    di,4
  329.     inc    bp
  330.     cmp    bp,NPOINTS
  331.     jb    @@loop0
  332.     pop    di
  333. ; --------------
  334. IF    1
  335.     xor    ebp,ebp
  336. @@loop1:
  337.     push    di
  338.     call    [fx1_proc]
  339. testdraw    1
  340.     pop    di
  341.     push    ebp
  342.     movsx    esi,[fx0_weight]
  343.     movsx    ebp,[fx1_weight]
  344.     movsx    eax,ax
  345.     imul    ebp
  346.     mov    ecx,eax
  347.     movsx    eax,[word di]
  348.     imul    esi
  349.     add    eax,ecx
  350.     sar    eax,WEIGHTSHIFT
  351.     mov    [di],ax
  352.     movsx    eax,bx
  353.     imul    ebp
  354.     mov    ecx,eax
  355.     movsx    eax,[word di+2]
  356.     imul    esi
  357.     add    eax,ecx
  358.     sar    eax,WEIGHTSHIFT
  359.     mov    [di+2],ax
  360.     pop    ebp
  361.     add    di,4
  362.     inc    bp
  363.     cmp    bp,NPOINTS
  364.     jb    @@loop1
  365. ENDIF
  366. ; --------------
  367.     xor    ebp,ebp
  368.     mov    bx,[rotate_time]
  369.     and    bx,_TWOPI-1
  370.     add    bx,bx
  371.     movsx    esi,[sine_table+bx]    ; ESI-sine
  372.     sub    bx,_TWOPI/4*2
  373.     neg    bx
  374.     and    bx,(_TWOPI-1)*2
  375.     movsx    edi,[sine_table+bx]    ; EDI-cosine
  376. @@rotloop:
  377.     movsx    ecx,[word ds:ebp*4+fx_points+2]
  378.     movsx    eax,[word ds:ebp*4+fx_points]
  379.     imul    edi
  380.     mov    ebx,eax
  381.     mov    eax,esi
  382.     imul    ecx
  383.     sub    ebx,eax
  384.     sar    ebx,_FRACBITS
  385.     xchg    [word ds:ebp*4+fx_points],bx
  386.     movsx    eax,bx
  387.     imul    esi
  388.     mov    ebx,eax
  389.     mov    eax,edi
  390.     imul    ecx
  391.     add    eax,ebx
  392.     sar    eax,_FRACBITS
  393.     mov    [word ds:ebp*4+fx_points+2],ax
  394.     inc    bp
  395.     cmp    bp,NPOINTS
  396.     jnz    @@rotloop
  397.     ret
  398. endp        compute_fx_points
  399.  
  400. ; -- cycloid_9_fx ----------------------------------------------
  401. ;
  402. C14INRAD    =    50
  403. C14OUTRAD    =    18
  404. proc        cycloid_9_fx    near
  405.     mov    edx,_TWOPI*2*10
  406. _all_cycloids:
  407.     movzx    eax,bp
  408.     mul    edx
  409.     mov    ecx,NPOINTS
  410.     div    ecx
  411.     mov    ebx,eax
  412.     and    ebx,_TWOPI-1
  413.     movsx    eax,[ebx*2+sine_table]
  414.     mov    ecx,C14OUTRAD
  415.     imul    ecx
  416.     mov    esi,eax    ; TX'=OUTRAD*sin((nrays+1)*realtime)
  417.     sub    bx,_TWOPI/4
  418.     neg    bx
  419.     and    bx,_TWOPI-1
  420.     movsx    eax,[ebx*2+sine_table]
  421.     imul    ecx
  422.     mov    edi,eax    ; TY'
  423.     mov    ax,_TWOPI
  424.     mul    bp
  425.     mov    cx,NPOINTS
  426.     div    cx
  427.     mov    bx,ax
  428.     movsx    eax,[ebx*2+sine_table]
  429.     mov    cx,C14INRAD
  430.     imul    ecx
  431.     add    esi,eax
  432.     sub    bx,_TWOPI/4
  433.     neg    bx
  434.     and    bx,_TWOPI-1
  435.     movsx    eax,[ebx*2+sine_table]
  436.     imul    ecx
  437.     add    edi,eax
  438.     sar    esi,_FRACBITS
  439.     sar    edi,_FRACBITS
  440.     mov    ax,si
  441.     mov    bx,di
  442.     ret
  443. endp        cycloid_9_fx
  444.  
  445. ; -- cycloid_4_fx ----------------------------------------------
  446. ;
  447. proc        cycloid_4_fx    near
  448.     mov    edx,_TWOPI*5*2
  449.     jmp    _all_cycloids
  450. endp        cycloid_4_fx
  451. ; -- cycloid_1_fx ----------------------------------------------
  452. ;
  453. proc        cycloid_1_fx    near
  454.     mov    edx,_TWOPI*2*4
  455.     jmp    _all_cycloids
  456. endp        cycloid_1_fx
  457.  
  458. ; -- spiral_fx -------------------------------------------------
  459. ;
  460. SPINRAD        =    0
  461. SPDIFRAD    =    70
  462. proc        spiral_fx    near
  463.     mov    eax,SPDIFRAD*_FRACMUL
  464.     movzx    edx,bp
  465.     mul    edx
  466.     mov    ebx,NPOINTS
  467.     div    ebx
  468.     add    eax,SPINRAD*_FRACMUL
  469.     mov    ecx,eax
  470.     movzx    eax,bp
  471.     mov    edx,_TWOPI
  472.     mul    edx
  473.     div    ebx
  474.     mov    ebx,eax
  475.     movsx    eax,[ebx*2+sine_table]
  476.     imul    ecx
  477.     shrd    eax,edx,_FRACBITS
  478.     sar    eax,_FRACBITS
  479.     push    ax
  480.     sub    bx,_TWOPI/4
  481.     neg    bx
  482.     and    bx,_TWOPI-1
  483.     movsx    eax,[ebx*2+sine_table]
  484.     imul    ecx
  485.     shrd    eax,edx,_FRACBITS
  486.     mov    ebx,eax
  487.     pop    ax
  488.     sar    ebx,_FRACBITS
  489.     ret
  490. endp        spiral_fx
  491.  
  492. ; -- _o_fx -----------------------------------------------------
  493. ;
  494. CIRCRAD        =    60
  495. proc        _o_fx    near
  496.     mov    cx,NPOINTS
  497.     mov    ax,_TWOPI
  498.     mul    bp
  499.     div    cx
  500.     movzx    ebx,ax
  501.     movsx    eax,[ebx*2+sine_table]
  502.     mov    ecx,CIRCRAD
  503.     imul    ecx
  504.     push    eax
  505.     sub    bx,_TWOPI/4
  506.     neg    bx
  507.     and    bx,_TWOPI-1
  508.     movsx    eax,[ebx*2+sine_table]
  509.     imul    ecx
  510.     sar    eax,_FRACBITS
  511.     xchg    bx,ax
  512.     pop    eax
  513.     sar    eax,_FRACBITS
  514.     ret
  515. endp        _o_fx
  516. ; -- _8_fx -----------------------------------------------------
  517. ;
  518. _8XRAD        =    80
  519. _8YRAD        =    60
  520. proc        _8_fx    near
  521.     movzx    eax,bp
  522.     mov    edx,_TWOPI
  523.     mul    edx
  524.     mov    ecx,NPOINTS
  525.     div    ecx
  526.     mov    esi,eax
  527.     and    esi,_TWOPI-1
  528.     movsx    eax,[esi*2+sine_table]
  529.     mov    edx,_8YRAD
  530.     imul    edx
  531.     shrd    eax,edx,_FRACBITS
  532.     mov    bx,ax
  533.     imul    si,3
  534.     sub    si,_TWOPI/2/2
  535.     neg    si
  536.     and    esi,_TWOPI-1
  537.     movsx    eax,[esi*2+sine_table]
  538.     mov    edx,_8XRAD
  539.     imul    edx
  540.     shrd    eax,edx,_FRACBITS
  541.     ret
  542. endp        _8_fx
  543. ; -- _8_fx0 -----------------------------------------------------
  544. ;
  545. _8XRAD0        =    45
  546. _8YRAD        =    60
  547. proc        _8_fx0    near
  548.     movzx    eax,bp
  549.     mov    edx,_TWOPI
  550.     mul    edx
  551.     mov    ecx,NPOINTS
  552.     div    ecx
  553.     mov    esi,eax
  554.     and    esi,_TWOPI-1
  555.     push    esi
  556.     imul    si,4
  557.     and    si,_TWOPI-1
  558.     movsx    eax,[esi*2+sine_table]
  559.     mov    edx,_8XRAD0
  560.     imul    edx
  561.     mov    ecx,eax
  562.     add    ecx,_8XRAD0*_FRACMUL
  563.     pop    esi
  564.     push    esi
  565.     sub    si,_TWOPI/2/2
  566.     neg    si
  567.     and    si,_TWOPI-1
  568.     movsx    eax,[esi*2+sine_table]
  569.     imul    ecx
  570.     shrd    eax,edx,_FRACBITS*2
  571.     mov    bx,ax
  572.     pop    esi
  573.     movsx    eax,[esi*2+sine_table]
  574.     imul    ecx
  575.     shrd    eax,edx,_FRACBITS*2
  576.     ret
  577. endp        _8_fx0
  578. ; -- square_fx -------------------------------------------------
  579. ;
  580. proc        square_fx    near
  581.     add    ax,NPOINTS/2/4
  582.     mov    ax,bp
  583.     mov    cx,NPOINTS/4
  584.     xor    dx,dx
  585.     div    cx
  586.     mov    bx,ax
  587.     mov    ax,100
  588.     mul    dx
  589.     div    cx
  590.     xchg    ax,dx
  591.     add    bx,bx
  592.     jmp    [bx+@@jumps]
  593. @@jumps    dw    @@1_1,@@_1_1,@@_11,@@11,@@1_1
  594. @@1_1:
  595.     mov    ax,50
  596.     mov    bx,-50
  597.     sub    ax,dx
  598.     jmp    @@comm
  599. @@11:
  600.     mov    ax,50
  601.     mov    bx,50
  602.     sub    bx,dx
  603.     jmp    @@comm
  604. @@_11:
  605.     mov    ax,-50
  606.     mov    bx,50
  607.     add    ax,dx
  608.     jmp    @@comm
  609. @@_1_1:
  610.     mov    ax,-50
  611.     mov    bx,-50
  612.     add    bx,dx
  613. @@comm:
  614.     ret
  615. endp        square_fx
  616.  
  617. ; **************************************************************
  618. ; -- draw_point ------------------------------------------------
  619. ;
  620. proc        draw_point    near
  621.     IF    USUALVGA
  622.     imul    di,bx,320
  623.     add    di,ax
  624.     mov    al,cl
  625.     inc    ax
  626.     mov    ah,al
  627.     mov    [es:di+320],ax
  628.     stosw
  629.     ELSE
  630. ;    cmp    ax,160
  631.     cmp    ax,319
  632.     ja    @@exit
  633.     mov    di,ax
  634. ;    shr    di,1
  635.     shr    di,2
  636.     imul    bx,bx,320/2/2
  637.     add    di,bx
  638. ;    and    eax,1
  639.     and    eax,3
  640.     mov    al,[eax+@@masks]
  641.     out    dx,al
  642.     mov    ax,cx
  643.     inc    ax
  644.     stosb
  645. ;    mov    [es:di-1+50h],al
  646.     ENDIF
  647. @@exit:
  648.     ret
  649. @@masks    db    1,2,4,8;
  650. ;@@masks    db    3,0c0h
  651. endp        draw_point
  652.  
  653. ; -- draw_fx_points --------------------------------------------
  654. ;
  655. proc        draw_fx_points    far
  656.     movzx    ax,[fastfx_color]
  657.     push    ax
  658.     xor    ebp,ebp
  659.     mov    cx,ax
  660.     IF    USUALVGA eq 0
  661.     mov    dx,03c4h
  662.     mov    al,2
  663.     out    dx,al
  664.     inc    dx
  665.     ENDIF
  666.     mov    si,[word  fx_zoom]
  667. @@loop:
  668.     push    dx
  669.     mov    ax,[ds:ebp*4+fx_points]
  670.     imul    si
  671.     shrd    ax,dx,_FRACBITS
  672.     add    ax,[diff_centerx]
  673.     add    ax,320/2;/2
  674.     push    ax
  675.     mov    ax,[ds:ebp*4+fx_points+2]
  676.     imul    si
  677.     shrd    ax,dx,_FRACBITS
  678.     mov    bx,[diff_centery]
  679.     add    bx,ax
  680.     add    bx,200/2;/2
  681.     pop    ax
  682.     pop    dx
  683.     push    cx
  684.     shr    cx,1
  685.     call    draw_point
  686.     pop    cx
  687.     inc    cx
  688.     cmp    cl,NCOLORS*2
  689.     sbb    al,al
  690.     and    cl,al
  691.     inc    bp
  692.     cmp    bp,NPOINTS
  693.     jb    @@loop
  694.     pop    ax
  695.     inc    ax
  696.     cmp    al,NCOLORS*2
  697.     sbb    ah,ah
  698.     and    al,ah
  699.     mov    [fastfx_color],al
  700.     ret
  701. endp        draw_fx_points
  702.  
  703.         end