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

  1. ;=============================================================================
  2. ; cplasma - Real Color plasma clouds demo.
  3. ;                                                     File created: 9-28-93
  4. ;                                                    Last modified: 9-28-93
  5. ; Description:
  6. ;   This file implements the real color plasma demostration using the
  7. ;   plasma routines and palette rotation using the VGA 320x200x256 mode.
  8. ;
  9. ; Portability:
  10. ;  Requires Turbo Assembler 3.2 or better to be assembler.
  11. ;  Dependent on the IBM PC 286 and the VGA graphics card.
  12. ;=============================================================================
  13.  
  14.                 .model  small,pascal
  15.                  jumps
  16.                 .286
  17.  
  18.                 global  DrawPlasma:proc        ; in PLASMA.ASM file.
  19.                 global  ColorPlasma:proc
  20.  
  21. ;===================== Demo equates and data =================================
  22.  
  23. TIMEOUT         equ     70 * 6                  ; 6 seconds timeout.
  24.  
  25.                 .data
  26.  
  27. Palette         db      768 dup (?)             ; hold the palette.
  28. FadePalette     db      768 dup (?)             ; hold the faded palette.
  29. Fade            db      ?                       ; fade level.
  30. EscKey          db      ?                       ; true if ESC pressed.
  31. Timer           dw      ?                       ; timer counter.
  32.  
  33. ;========================== Demo routines ====================================
  34.  
  35.                 .code
  36.  
  37. ;-----------------------------------------------------------------------------
  38. ; WaitVRT - Waits the Vertical Retrace Period.
  39. ;-----------------------------------------------------------------------------
  40.  
  41. WaitVRT         proc near
  42.  
  43.                 push    ax
  44.                 push    dx
  45.                 mov     dx,3DAh
  46. WaitVRT1:       in      al,dx
  47.                 test    al,8
  48.                 jz      WaitVRT1
  49. WaitVRT2:       in      al,dx
  50.                 test    al,8
  51.                 jnz     WaitVRT2
  52.                 pop     dx
  53.                 pop     ax
  54.                 ret
  55.  
  56. WaitVRT         endp
  57.  
  58. ;-----------------------------------------------------------------------------
  59. ; SetPalette - set the 256 entries of the VGA color palette.
  60. ; In:
  61. ;   DS:SI - Palette structure address.
  62. ;-----------------------------------------------------------------------------
  63.  
  64. SetPalette      proc near
  65.  
  66.                 mov     cx,768
  67.                 mov     dx,3C8h
  68.                 xor     al,al
  69.                 out     dx,al
  70.                 mov     dx,3DAh
  71. WaitVR1:        in      al,dx
  72.                 test    al,8
  73.                 jz      WaitVR1
  74.                 mov     dx,3C9h
  75.                 rep     outsb
  76. WaitVR2:        in      al,dx
  77.                 test    al,8
  78.                 jnz     WaitVR2
  79.                 ret
  80.  
  81. SetPalette      endp
  82.  
  83. ;-----------------------------------------------------------------------------
  84. ; ColorPlasma - Performs the demonstration.
  85. ; In:
  86. ;   DS - Data segment.
  87. ;-----------------------------------------------------------------------------
  88.  
  89. ColorPlasma      proc
  90.  
  91.                 mov     ax,0013h                ; set 320x200x256 mode.
  92.                 int     10h
  93.  
  94.                 mov     [Fade],0                ; setup variables.
  95.                 mov     [EscKey],0
  96.                 mov     [Timer],0
  97.  
  98.                 lea     di,[FadePalette]        ; clear fade palette.
  99.                 mov     ax,ds
  100.                 mov     es,ax
  101.                 mov     cx,768
  102.                 xor     ax,ax
  103.                 cld
  104.                 rep     stosb
  105.                 lea     si,[FadePalette]
  106.                 call    SetPalette              ; set black palette.
  107.  
  108. GenPalette:     lea     di,[Palette]            ; generation of the
  109.                 xor     cx,cx                   ; plasma palette.
  110. GP0:            mov     al,63
  111.                 mov     ah,cl
  112.                 mov     bl,al
  113.                 sub     bl,cl
  114.                 mov     [di+0],al
  115.                 mov     [di+1],ah
  116.                 mov     [di+2],bl
  117.                 add     di,3
  118.                 inc     cx
  119.                 cmp     cx,64
  120.                 jb      Gp0
  121.  
  122.                 xor     cx,cx
  123. Gp1:            mov     al,63
  124.                 sub     al,cl
  125.                 mov     ah,63
  126.                 mov     bl,cl
  127.                 mov     [di+0],al
  128.                 mov     [di+1],ah
  129.                 mov     [di+2],bl
  130.                 add     di,3
  131.                 inc     cx
  132.                 cmp     cx,64
  133.                 jb      Gp1
  134.  
  135.                 xor     cx,cx
  136. Gp2:            mov     al,0
  137.                 mov     ah,63
  138.                 sub     ah,cl
  139.                 mov     bl,63
  140.                 mov     [di+0],al
  141.                 mov     [di+1],ah
  142.                 mov     [di+2],bl
  143.                 add     di,3
  144.                 inc     cx
  145.                 cmp     cx,64
  146.                 jb      Gp2
  147.  
  148.                 xor     cx,cx
  149. Gp3:            mov     al,cl
  150.                 mov     ah,0
  151.                 mov     bl,63
  152.                 mov     [di+0],al
  153.                 mov     [di+1],ah
  154.                 mov     [di+2],bl
  155.                 add     di,3
  156.                 inc     cx
  157.                 cmp     cx,64
  158.                 jb      Gp3
  159.  
  160.                 ; draw plasma onto VGA screen.
  161.  
  162.                 call    DrawPlasma,30,36,290,164,01234h,0A000h
  163.  
  164.                 mov     ax,ds
  165.                 mov     es,ax
  166.                 cld
  167.  
  168. PlasmaLoop:     test    [Timer],1               ; decreases the rot speed.
  169.                 jne     DontRotate
  170.                 lea     bx,[Palette]            ; rotate the palette.
  171.                 mov     si,bx
  172.                 mov     di,bx
  173.                 add     si,9
  174.                 mov     cx,768-9
  175.                 rep     movsb
  176.                 mov     si,bx
  177.                 mov     cx,9
  178.                 rep     movsb
  179.                 mov     di,bx
  180.                 xor     al,al
  181.                 mov     cx,9
  182.                 rep     stosb
  183. DontRotate:
  184.  
  185.                 cmp     [EscKey],0              ; change the fade level.
  186.                 jne     FadeOut
  187. FadeIn:         mov     bl,[Fade]
  188.                 cmp     bl,128
  189.                 jae     FadeInOut
  190.                 inc     [Fade]
  191.                 jmp     FadeInOut
  192.  
  193. FadeOut:        mov     bl,[Fade]
  194.                 cmp     bl,0
  195.                 jbe     FadeInOut
  196.                 dec     [Fade]
  197.  
  198. FadeInOut:      lea     si,[Palette]            ; set fade palette using
  199.                 lea     di,[FadePalette]        ; the current fade level
  200.                 mov     cx,768                  ; and plasma palette.
  201. FadeLoop:       lodsb
  202.                 mul     bl
  203.                 shr     ax,7
  204.                 stosb
  205.                 loop    FadeLoop
  206.  
  207.                 lea     si,[FadePalette]        ; set VGA fade-palette.
  208.                 call    SetPalette
  209.  
  210.                 mov     ah,1                    ; if any key pressed,
  211.                 int     16h
  212.                 jz      CheckTimer
  213.                 mov     ah,0
  214.                 int     16h
  215.                 jmp     BeginFadeOut
  216.  
  217. CheckTimer:     inc     [Timer]                 ; or timeout...
  218.                 cmp     [Timer],TIMEOUT
  219.                 jb      CheckExit
  220.  
  221. BeginFadeOut:   inc     [EscKey]                ; start fade-out and exit.
  222.  
  223. CheckExit:      cmp     [Fade],0                ; if fade-out is done
  224.                 jne     PlasmaLoop              ; then quit.
  225.  
  226.                 mov     ax,0003h                ; restore 80x25x16 text mode.
  227.                 int     10h
  228.  
  229.                 ret
  230.  
  231. ColorPlasma      endp
  232.  
  233.  
  234.                 end
  235.