home *** CD-ROM | disk | FTP | other *** search
/ The Party 1994: Try This At Home / disk_image.bin / source / fakesrc / wplasma.asm < prev    next >
Assembly Source File  |  1993-10-20  |  14KB  |  424 lines

  1. ;=============================================================================
  2. ; wplasma - Runtime Sinus Wave Plasma Demostration.
  3. ;                                                   File created: 10-21-93
  4. ; Copyright (C) 1993, Carlos Hasan                 Last modified: 10-21-93
  5. ;
  6. ; Description:
  7. ;   This file implements a runtime real plasma using sinus overlapping
  8. ;   waves at random speeds using the VGA 320x80x256 mode.
  9. ;
  10. ; Portability:
  11. ;  Requires Turbo Assembler 3.2 or better to be assembler.
  12. ;  Dependent on the IBM PC 286 and the VGA graphics card.
  13. ;=============================================================================
  14.  
  15.                 jumps
  16.                 .model  small,pascal
  17.                 .286
  18.  
  19.                 global  WavePlasma:proc
  20.  
  21. ;======================= Demo equates and data ===============================
  22.  
  23. TIMEOUT         equ     70 * 10                 ; at least 10 secs.
  24. MAXHW           equ     32                      ; max horiz wave amount.
  25. MAXVW           equ     64                      ; max vert wave amount.
  26. MAXH            equ     60                      ; horiz wave length.
  27. MAXV            equ     80+MAXHW                ; vert wave length.
  28. SEED            equ     57FEh                   ; randomize.
  29.  
  30.                 .data
  31.  
  32.                 include sintab2.inc             ; sinus table.
  33.  
  34. HWave1          db      MAXH dup (?)            ; horiz waves.
  35. HWave2          db      MAXH dup (?)
  36. VWave1          db      MAXV dup (?)            ; vert waves.
  37. VWave2          db      MAXV dup (?)
  38. HWavPos1        dw      ?                       ; horiz waves pos.
  39. HWavPos2        dw      ?
  40. VWavPos1        dw      ?                       ; vert waves pos.
  41. VWavPos2        dw      ?
  42. HWavInc1        dw      ?                       ; horiz wave speed.
  43. VWavInc1        dw      ?                       ; vert wave speed.
  44. Bitmap          db      256*MAXH+MAXV dup (?)   ; aux plasma buffer.
  45.  
  46. Palette         db      768 dup (?)             ; plasma palette.
  47. FadePalette     db      768 dup (?)             ; faded palette.
  48. Fade            db      ?                       ; fade level.
  49. Esckey          db      ?                       ; true if key pressed.
  50. Timer           dw      ?                       ; timer counter.
  51. RandSeed        dw      ?                       ; Random seed.
  52.  
  53. ;======================= Demo routines =======================================
  54.  
  55.                 .code
  56.  
  57. ;-----------------------------------------------------------------------------
  58. ; Random - Returns a 16-bit random number.
  59. ; Out:
  60. ;  AX - Random number.
  61. ;-----------------------------------------------------------------------------
  62.  
  63. Random          proc near
  64.  
  65.                 mov     ax,[RandSeed]
  66.                 imul    ax,13A7h
  67.                 inc     ax
  68.                 mov     [RandSeed],ax
  69.                 ret
  70.  
  71. Random          endp
  72.  
  73. ;-----------------------------------------------------------------------------
  74. ; WaitVRT - Waits the Vertical Retrace.
  75. ;-----------------------------------------------------------------------------
  76.  
  77. WaitVRT         proc near
  78.  
  79.                 mov     dx,3DAh
  80. WaitVR1:        in      al,dx
  81.                 test    al,8
  82.                 jne     WaitVR1
  83. WaitVR2:        in      al,dx
  84.                 test    al,8
  85.                 je      WaitVR2
  86.                 ret
  87.  
  88. WaitVRT         endp
  89.  
  90. ;-----------------------------------------------------------------------------
  91. ; SetPalette - set the CX entries of the VGA color palette.
  92. ; In:
  93. ;   DS:SI - Palette structure address.
  94. ;   CX    - Number of colors components.
  95. ;-----------------------------------------------------------------------------
  96.  
  97. SetPalette      proc near
  98.  
  99.                 call    WaitVRT
  100.                 mov     dx,3C8h
  101.                 xor     al,al
  102.                 out     dx,al
  103.                 inc     dx
  104.                 rep     outsb
  105.                 ret
  106.  
  107. SetPalette      endp
  108.  
  109. ;-----------------------------------------------------------------------------
  110. ; UpdHWaves - Updates the Horiz Waves.
  111. ;-----------------------------------------------------------------------------
  112.  
  113. UpdHWaves       proc near
  114.  
  115.                 mov     ax,ds
  116.                 mov     es,ax
  117.                 cld
  118.                 lea     si,[HWave1+1]
  119.                 lea     di,[HWave1]
  120.                 mov     cx,MAXH-1
  121.                 rep     movsb
  122.                 mov     si,[HWavPos1]
  123.                 mov     al,[SinusTable+si]
  124.                 sar     al,1
  125.                 stosb
  126.                 add     si,[HWavInc1]
  127.                 cmp     si,360
  128.                 jb      SetHInc
  129.                 sub     si,360
  130. SetHInc:        mov     [HWavPos1],si
  131.                 lea     si,[SinusTable]
  132.                 add     si,[HWavPos2]
  133.                 lea     bx,[HWave1]
  134.                 lea     di,[HWave2]
  135.                 mov     cx,MAXH
  136. UpdHLoop:       lodsb
  137.                 sar     al,1
  138.                 add     al,[bx]
  139.                 sar     al,3
  140.                 add     al,16
  141.                 stosb
  142.                 add     si,3
  143.                 inc     bx
  144.                 loop    UpdHLoop
  145.                 add     [HWavPos2],4
  146.                 cmp     [HWavPos2],360
  147.                 jb      UpdHExit
  148.                 sub     [HWavPos2],360
  149. UpdHExit:       ret
  150.  
  151. UpdHWaves       endp
  152.  
  153. ;-----------------------------------------------------------------------------
  154. ; UpdVWaves - Updates the Vert Waves.
  155. ;-----------------------------------------------------------------------------
  156.  
  157. UpdVWaves       proc near
  158.  
  159.                 mov     ax,ds
  160.                 mov     es,ax
  161.                 cld
  162.                 lea     si,[VWave1+1]
  163.                 lea     di,[VWave1]
  164.                 mov     cx,MAXV-1
  165.                 rep     movsb
  166.                 mov     si,[VWavPos1]
  167.                 mov     al,[SinusTable+si]
  168.                 sar     al,1
  169.                 stosb
  170.                 add     si,[VWavInc1]
  171.                 cmp     si,360
  172.                 jb      SetVInc
  173.                 sub     si,360
  174. SetVInc:        mov     [VWavPos1],si
  175.                 lea     si,[SinusTable]
  176.                 add     si,[VWavPos2]
  177.                 lea     bx,[VWave1]
  178.                 lea     di,[VWave2]
  179.                 mov     cx,MAXV
  180. UpdVLoop:       lodsb
  181.                 sar     al,1
  182.                 add     al,[bx]
  183.                 sar     al,2
  184.                 add     al,32
  185.                 stosb
  186.                 add     si,2
  187.                 inc     bx
  188.                 loop    UpdVLoop
  189.                 inc     [VWavPos2]
  190.                 cmp     [VWavPos2],360
  191.                 jb      UpdVExit
  192.                 sub     [VWavPos2],360
  193. UpdVExit:       ret
  194.  
  195. UpdVWaves       endp
  196.  
  197. ;-----------------------------------------------------------------------------
  198. ; UpdBmp - Updates the Plasma bitmap.
  199. ;-----------------------------------------------------------------------------
  200.  
  201. UpdBmp          proc near
  202.  
  203.                 cld
  204.                 mov     cx,MAXV
  205.                 lea     si,[VWave2]
  206.                 lea     di,[BitMap]
  207. UpBmLoop:       lodsb
  208.                 i=0
  209.                 REPT MAXH
  210.                   inc   al
  211.                   mov   [di+i],al
  212.                   i=i+256
  213.                 ENDM
  214.                 inc     di
  215.                 loop    UpBmLoop
  216.                 ret
  217.  
  218. UpdBmp          endp
  219.  
  220. ;-----------------------------------------------------------------------------
  221. ; PutBmp - Puts into the screen the Plasma bitmap.
  222. ;-----------------------------------------------------------------------------
  223.  
  224. PutBmp          proc near
  225.  
  226.                 cld
  227.                 mov     ax,0A000h
  228.                 mov     es,ax
  229.                 mov     di,80*10
  230.                 lea     dx,[BitMap]
  231.                 lea     si,[HWave2]
  232.                 mov     bl,MAXH
  233.                 xor     ah,ah
  234. PutLoop:        lodsb
  235.                 push    si
  236.                 mov     si,ax
  237.                 add     si,dx
  238.                 mov     cx,40
  239.                 rep     movsw
  240.                 pop     si
  241.                 inc     dh
  242.                 dec     bl
  243.                 jne     PutLoop
  244.                 ret
  245.  
  246. PutBmp          endp
  247.  
  248. ;-----------------------------------------------------------------------------
  249. ; WavePlasma - Performs the demonstration.
  250. ; In:
  251. ;   DS - Data segment.
  252. ;-----------------------------------------------------------------------------
  253.  
  254. WavePlasma      proc
  255.  
  256.                 pusha
  257.                 push    ds
  258.                 push    es
  259.  
  260.                 mov     ax,0013h                ; set 320x200x256 mode.
  261.                 int     10h
  262.  
  263.                 mov     dx,3C4h                 ; disable chain-four
  264.                 mov     al,04h
  265.                 out     dx,al
  266.                 inc     dx
  267.                 in      al,dx
  268.                 and     al,0F7h
  269.                 out     dx,al
  270.                 mov     dx,3C4h                 ; enable all planes
  271.                 mov     ax,0F02h
  272.                 out     dx,ax
  273.                 mov     ax,0A000h               ; clear video memory
  274.                 mov     es,ax
  275.                 xor     di,di
  276.                 xor     ax,ax
  277.                 mov     cx,8000h
  278.                 cld
  279.                 rep     stosw
  280.                 mov     dx,3D4h                 ; normal word addressing
  281.                 mov     al,14h
  282.                 out     dx,al
  283.                 inc     dx
  284.                 in      al,dx
  285.                 and     al,0BFh
  286.                 out     dx,al
  287.                 dec     dx                      ; address output byte mode
  288.                 mov     al,17h
  289.                 out     dx,al
  290.                 inc     dx
  291.                 in      al,dx
  292.                 or      al,40h
  293.                 out     dx,al
  294.                 mov     dx,3D4h                 ; set max scanline.
  295.                 mov     ax,0409h
  296.                 out     dx,ax
  297.  
  298. GenPalette:     lea     di,[Palette]            ; generation of the
  299.                 xor     al,al                   ; plasma palette.
  300.                 mov     [di+0],al
  301.                 mov     [di+1],al
  302.                 mov     [di+2],al
  303.                 add     di,3
  304.                 mov     cx,MAXH+MAXVW
  305.                 xor     ah,ah
  306.                 mov     bl,2
  307. GPLoop:         mov     dl,32
  308.                 mov     al,ah
  309.                 shr     al,1
  310.                 sub     dl,al
  311.                 mov     [di+0],dl
  312.                 mov     dl,16
  313.                 mov     al,ah
  314.                 shr     al,2
  315.                 sub     dl,al
  316.                 mov     [di+1],dl
  317.                 mov     dl,63
  318.                 mov     al,ah
  319.                 shr     al,2
  320.                 sub     dl,al
  321.                 mov     [di+2],dl
  322.                 add     ah,bl
  323.                 cmp     ah,64
  324.                 jb      GPCont
  325.                 neg     bl
  326.                 add     ah,bl
  327.                 add     ah,bl
  328. GPCont:         add     di,3
  329.                 loop    GPLoop
  330.  
  331.                 mov     [Fade],0                ; setup variables.
  332.                 mov     [EscKey],0
  333.                 mov     [Timer],0
  334.                 mov     [RandSeed],SEED
  335.  
  336.                 mov     [HWavPos1],0            ; setup wave parameters.
  337.                 mov     [HWavPos2],0
  338.                 mov     [VWavPos1],0
  339.                 mov     [VWavPos2],0
  340.                 mov     [HWavInc1],1
  341.                 mov     [VWavInc1],7
  342.  
  343.                 mov     cx,MAXV                 ; use enough steps
  344. SetupWaves:     push    cx                      ; to update all the
  345.                 call    UpdHWaves               ; waves entries.
  346.                 call    UpdVWaves
  347.                 pop     cx
  348.                 loop    SetupWaves
  349.  
  350.  
  351. PlasmaLoop:     cmp     [EscKey],0              ; change fade level.
  352.                 jne     FadeOut
  353. FadeIn:         mov     bl,[Fade]
  354.                 cmp     bl,64
  355.                 jae     SkipFade
  356.                 inc     [Fade]
  357.                 jmp     FadeInOut
  358. FadeOut:        mov     bl,[Fade]
  359.                 cmp     bl,0
  360.                 jbe     FadeInOut
  361.                 dec     [Fade]
  362.  
  363. FadeInOut:      lea     si,[Palette]            ; set faded palette.
  364.                 lea     di,[FadePalette]
  365.                 mov     cx,768
  366.                 mov     ax,ds
  367.                 mov     es,ax
  368.                 cld
  369. FadeLoop:       lodsb
  370.                 mul     bl
  371.                 shr     ax,6
  372.                 stosb
  373.                 loop    FadeLoop
  374.  
  375. DoFade:         lea     si,[FadePalette]        ; ensures thats always
  376.                 mov     cx,3*(MAXH+MAXVW+1)     ; waits the VR per frame.
  377.                 call    SetPalette
  378.                 jmp     DoPlasma
  379.  
  380. SkipFade:       call    WaitVRT
  381.  
  382. DoPlasma:       call    UpdHWaves               ; updates horiz waves.
  383.                 call    UpdVWaves               ; updates vert waves.
  384.                 call    UpdBmp                  ; updates bitmap.
  385.                 call    PutBmp                  ; draw plasma.
  386.  
  387.                 call    Random                  ; change wave's speed.
  388.                 and     ax,7
  389.                 add     ax,3
  390.                 mov     [HWavInc1],ax
  391.                 call    Random
  392.                 and     ax,3
  393.                 add     ax,5
  394.                 mov     [VWavInc1],ax
  395.  
  396.                 mov     ah,1                    ; if any key pressed,
  397.                 int     16h
  398.                 jz      CheckTimer
  399.                 mov     ah,0
  400.                 int     16h
  401.                 jmp     BeginFadeOut
  402.  
  403. CheckTimer:     inc     [Timer]                 ; or timeout,
  404.                 cmp     [Timer],TIMEOUT
  405.                 jb      CheckExit
  406.  
  407. BeginFadeOut:   inc     [EscKey]                ; then fade-out and exit.
  408.  
  409. CheckExit:      cmp     [Fade],0
  410.                 je      PlasmaExit
  411.                 jmp     PlasmaLoop
  412.  
  413. PlasmaExit:     mov     ax,0003h
  414.                 int     10h
  415.  
  416.                 pop     es
  417.                 pop     ds
  418.                 popa
  419.                 ret
  420.  
  421. WavePlasma      endp
  422.  
  423.                 end
  424.