home *** CD-ROM | disk | FTP | other *** search
/ The Party 1994: Try This At Home / disk_image.bin / source / fakesrc / rplasma.asm < prev    next >
Assembly Source File  |  1993-09-27  |  11KB  |  311 lines

  1. ;=============================================================================
  2. ; rplasma - Runtime real plasma clouds demo.
  3. ;                                                   File created: 9-28-93
  4. ; Copyright (C) 1993, Carlos Hasan                 Last modified: 9-28-93
  5. ;
  6. ; Description:
  7. ;   This file implements a runtime real plasma using sinus overlapping
  8. ;   waves at random speeds using the VGA 320x400x256 mode. Based on the
  9. ;   Vangelis Plasma demo code.
  10. ;
  11. ; Portability:
  12. ;  Requires Turbo Assembler 3.2 or better to be assembler.
  13. ;  Dependent on the IBM PC 286 and the VGA graphics card.
  14. ;=============================================================================
  15.  
  16.                 .model  small,pascal
  17.                 .286
  18.  
  19.                 global  SinusPlasma:proc
  20.  
  21. ;======================= Demo equates and data ===============================
  22.  
  23. TIMEOUT         equ     70 * 6                  ; 6 secs for timeout.
  24.  
  25.                 .data
  26.  
  27.                 include sintable.inc            ; sinus table.
  28.  
  29. Palette         db      768 dup (?)             ; plasma palette.
  30. FadePalette     db      768 dup (?)             ; faded palette.
  31. WavHPos1        db      ?                       ; wave horizontal and
  32. WavHPos2        db      ?                       ; vertical positions
  33. WavVPos1        db      ?                       ; and increments.
  34. WavVPos2        db      ?
  35. WavHAdd1        db      ?                       ; WARNING: the four waves
  36. WavHAdd2        db      ?                       ;  positions must be at
  37. WavVAdd1        db      ?                       ;  consecutive addresses.
  38. WavVAdd2        db      ?
  39. Fade            db      ?                       ; fade level.
  40. Esckey          db      ?                       ; true if key pressed.
  41. Timer           dw      ?                       ; timer counter.
  42.  
  43. ;======================= Demo routines =======================================
  44.  
  45.                 .code
  46.  
  47. ;-----------------------------------------------------------------------------
  48. ; SetPalette - set the 256 entries of the VGA color palette.
  49. ; In:
  50. ;   DS:SI - Palette structure address.
  51. ;-----------------------------------------------------------------------------
  52.  
  53. SetPalette      proc near
  54.  
  55.                 mov     cx,768
  56.                 mov     dx,3C8h
  57.                 xor     al,al
  58.                 out     dx,al
  59.                 mov     dx,3DAh
  60. WaitVRT:        in      al,dx
  61.                 test    al,8
  62.                 jz      WaitVRT
  63.                 mov     dx,3C9h
  64.                 rep     outsb
  65. WaitVRTE:       in      al,dx
  66.                 test    al,8
  67.                 jnz     WaitVRTE
  68.                 ret
  69.  
  70. SetPalette      endp
  71.  
  72. ;-----------------------------------------------------------------------------
  73. ; SinusPlasma - Performs the demonstration.
  74. ; In:
  75. ;   DS - Data segment.
  76. ;-----------------------------------------------------------------------------
  77.  
  78. SinusPlasma     proc
  79.  
  80.                 pusha
  81.                 push    ds
  82.                 push    es
  83.  
  84.                 mov     ax,0013h                ; set 320x200x256 mode.
  85.                 int     10h
  86.  
  87.                 mov     ax,ds                   ; set black palette.
  88.                 mov     es,ax
  89.                 lea     di,[FadePalette]
  90.                 mov     cx,768
  91.                 xor     ax,ax
  92.                 cld
  93.                 rep     stosb
  94.                 lea     si,[FadePalette]
  95.                 call    SetPalette
  96.  
  97.                 mov     dx,3C4h                 ; setup VGA tricky
  98.                 mov     ax,0604h                ; 320x400x256 mode.
  99.                 out     dx,ax
  100.                 mov     ax,0F02h                ; enable 4-planes.
  101.                 out     dx,ax
  102.                 mov     dx,3D4h                 ; disable dword mode
  103.                 mov     ax,0014h
  104.                 out     dx,ax
  105.                 mov     ax,0E317h               ; enable byte mode
  106.                 out     dx,ax
  107.                 mov     ax,0009h                ; dup each scan 1 times
  108.                 out     dx,ax
  109.  
  110.                 mov     ax,0A000h
  111.                 mov     es,ax
  112.                 xor     di,di
  113.                 mov     cx,8000h                ; clear video memory.
  114.                 xor     ax,ax
  115.                 cld
  116.                 rep     stosw
  117.  
  118.                 mov     [Fade],0                ; setup variables.
  119.                 mov     [EscKey],0
  120.                 mov     [Timer],0
  121.  
  122.                 mov     [WavHPos1],0            ; setup wave parameters.
  123.                 mov     [WavHPos2],0
  124.                 mov     [WavVPos1],0
  125.                 mov     [WavVPos2],0
  126.                 mov     [WavHAdd1],2
  127.                 mov     [WavHAdd2],1
  128.                 mov     [WavVAdd1],3
  129.                 mov     [WavVAdd2],4
  130.  
  131. GenPalette:     lea     di,[Palette]            ; generation of the
  132.                 xor     al,al                   ; plasma palette.
  133.                 mov     [di+0],al
  134.                 mov     [di+1],al
  135.                 mov     [di+2],al
  136.                 add     di,3
  137.                 mov     cx,1
  138. GP0:            mov     al,63
  139.                 mov     ah,cl
  140.                 mov     bl,al
  141.                 sub     bl,cl
  142.                 mov     [di+0],al
  143.                 mov     [di+1],ah
  144.                 mov     [di+2],bl
  145.                 add     di,3
  146.                 inc     cx
  147.                 cmp     cx,64
  148.                 jb      Gp0
  149.  
  150.                 xor     cx,cx
  151. Gp1:            mov     al,63
  152.                 sub     al,cl
  153.                 mov     ah,63
  154.                 mov     bl,cl
  155.                 mov     [di+0],al
  156.                 mov     [di+1],ah
  157.                 mov     [di+2],bl
  158.                 add     di,3
  159.                 inc     cx
  160.                 cmp     cx,64
  161.                 jb      Gp1
  162.  
  163.                 xor     cx,cx
  164. Gp2:            mov     al,0
  165.                 mov     ah,63
  166.                 sub     ah,cl
  167.                 mov     bl,63
  168.                 mov     [di+0],al
  169.                 mov     [di+1],ah
  170.                 mov     [di+2],bl
  171.                 add     di,3
  172.                 inc     cx
  173.                 cmp     cx,64
  174.                 jb      Gp2
  175.  
  176.                 xor     cx,cx
  177. Gp3:            mov     al,cl
  178.                 mov     ah,0
  179.                 mov     bl,63
  180.                 mov     [di+0],al
  181.                 mov     [di+1],ah
  182.                 mov     [di+2],bl
  183.                 add     di,3
  184.                 inc     cx
  185.                 cmp     cx,64
  186.                 jb      Gp3
  187.  
  188. PlasmaLoop:     cmp     [EscKey],0              ; change fade level.
  189.                 jne     FadeOut
  190. FadeIn:         mov     bl,[Fade]
  191.                 cmp     bl,64
  192.                 jae     SkipFade
  193.                 inc     [Fade]
  194.                 jmp     FadeInOut
  195. FadeOut:        mov     bl,[Fade]
  196.                 cmp     bl,0
  197.                 jbe     FadeInOut
  198.                 dec     [Fade]
  199.  
  200. FadeInOut:      lea     si,[Palette]            ; set faded palette.
  201.                 lea     di,[FadePalette]
  202.                 mov     cx,768
  203.                 mov     ax,ds
  204.                 mov     es,ax
  205.                 cld
  206. FadeLoop:       lodsb
  207.                 mul     bl
  208.                 shr     ax,6
  209.                 stosb
  210.                 loop    FadeLoop
  211.  
  212. SkipFade:       lea     si,[FadePalette]
  213.                 call    SetPalette
  214.  
  215.                 mov     ax,0A000h
  216.                 mov     es,ax
  217.  
  218.                 lea     si,[SinusTable]
  219.  
  220.                 mov     di,80*100+10            ; top left corner.
  221.  
  222.                 mov     ah,100                  ; 100 lines.
  223.                 mov     cl,[WavVPos1]
  224.                 mov     ch,[WavVPos2]
  225. VertLoop:       push    ax
  226.                 mov     ah,60                   ; 60 columns.
  227.                 mov     dl,[WavHPos1]
  228.                 mov     dh,[WavHPos2]
  229. HorizLoop:      mov     bx,bp                   ; get random value.
  230.                 mov     al,bl
  231.                 xor     bh,bh
  232.                 mov     bl,dl
  233.                 add     al,[bx+si]
  234.                 mov     bl,dh
  235.                 add     al,[bx+si]
  236.                 mov     bl,cl
  237.                 add     al,[bx+si]
  238.                 mov     bl,ch
  239.                 add     al,[bx+si]
  240.                 or      al,1
  241.                 stosb
  242.                 add     dl,1
  243.                 add     dh,3
  244.                 dec     ah
  245.                 jne     HorizLoop
  246.                 add     di,80+20                ; skip scan line.
  247.                 add     cl,7
  248.                 add     ch,3
  249.                 pop     ax
  250.                 dec     ah
  251.                 jne     VertLoop                ; next plasma line.
  252.  
  253.                 inc     bp                      ; get random value.
  254.                 mov     bx,bp
  255.                 xor     bl,bh
  256.                 xor     bl,[di-1]
  257.                 xor     bl,cl
  258.                 xor     bl,dl
  259.                 add     bl,ch
  260.                 add     bl,dh
  261.  
  262.                 test    bl,8                    ; change waves speed.
  263.                 jne     SpeedDown
  264. SpeedUp:        and     bx,3
  265.                 cmp     [WavHAdd1+bx],+7
  266.                 jg      ChangePos
  267.                 inc     [WavHAdd1+bx]
  268.                 jmp     ChangePos
  269. SpeedDown:      and     bx,3
  270.                 cmp     [WavHAdd1+bx],-7
  271.                 jl      ChangePos
  272.                 dec     [WavHAdd1+bx]
  273.  
  274. ChangePos:      mov     al,[WavHAdd1]           ; change waves positions.
  275.                 add     [WavHPos1],al
  276.                 mov     al,[WavHAdd2]
  277.                 add     [WavHPos2],al
  278.                 mov     al,[WavVAdd1]
  279.                 add     [WavVPos1],al
  280.                 mov     al,[WavVAdd2]
  281.                 add     [WavVPos2],al
  282.  
  283.                 mov     ah,1                    ; if any key pressed,
  284.                 int     16h
  285.                 jz      CheckTimer
  286.                 mov     ah,0
  287.                 int     16h
  288.                 jmp     BeginFadeOut
  289.  
  290. CheckTimer:     inc     [Timer]                 ; or timeout,
  291.                 cmp     [Timer],TIMEOUT
  292.                 jb      CheckExit
  293.  
  294. BeginFadeOut:   inc     [EscKey]                ; then fade-out and exit.
  295.  
  296. CheckExit:      cmp     [Fade],0
  297.                 je      PlasmaExit
  298.                 jmp     PlasmaLoop
  299.  
  300. PlasmaExit:     mov     ax,0003h
  301.                 int     10h
  302.  
  303.                 pop     es
  304.                 pop     ds
  305.                 popa
  306.                 ret
  307.  
  308. SinusPlasma     endp
  309.  
  310.                 end
  311.