home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / progmisc / fakesrc.zip / PART11 / FLAMES.ASM next >
Assembly Source File  |  1993-11-22  |  13KB  |  411 lines

  1. ;=============================================================================
  2. ; flame.asm - Plasma-Like Flames Demo.
  3. ;                                                    File created: 11/22/93
  4. ; Copyright (c) 1993, Carlos Hasan                  Last modified: 11/22/93
  5. ;
  6. ; Description:
  7. ;  Plasma Like Flames effect based on Vangelis Fire Code.
  8. ;
  9. ; Portability:
  10. ;  Requires Turbo Assembler 3.2 or later to be assembled.
  11. ;  Dependant on the IBM PC 286 or better processor.
  12. ;=============================================================================
  13.  
  14.         ideal
  15.         model   small
  16.         jumps
  17.         p286
  18.  
  19.         dosseg
  20.         stack   1024
  21.         ends
  22.  
  23.         global  FontFAR:byte            ; FLAMES.FNT linked file.
  24.  
  25. ;=========================== VLA Font Header =================================
  26.  
  27. struc   FontHeader
  28.   Magic   db   "VGACH"                  ; Font Signature
  29.   First   db   ?                        ; First Char
  30.   Width   db   ?                        ; Font Width
  31.   Height  db   ?                        ; Font Height
  32.   Total   db   ?                        ; Number of Chars
  33. ends    FontHeader
  34.  
  35. ;======================== Equates and Data Segment ===========================
  36.  
  37. TIMEOUT   equ  70*50                    ; At Least 50 secs
  38. MESGSPEED equ  20                       ; Message Speed in VR Ticks
  39. FLSEED    equ  4                        ; Initial Flames Seed
  40. FLBLANK   equ  100                      ; Ending Flames Seed (Blank Screen)
  41. XDOTS     equ  80                       ; VGA Screen Dimensions
  42. YDOTS     equ  80
  43. HIDDEN    equ  8                        ; Number of Hidden Working Lines
  44.  
  45.         dataseg
  46.  
  47. label   Palette byte                    ; Flames RGB Palette:
  48.         I=0                             ; black to blue
  49.         rept 8
  50.         db   0,0,2*I
  51.         I=I+1
  52.         endm
  53.         I=0                             ; blue to darkred
  54.         rept 8
  55.         db   2*I,0,16-2*I
  56.         I=I+1
  57.         endm
  58.         I=0                             ; darkred to lightred
  59.         rept 24
  60.         db   16+47*I/24,0,0
  61.         I=I+1
  62.         endm
  63.         I=0                             ; lighred to yellow
  64.         rept 32
  65.         db   63,31*I/16,0
  66.         I=I+1
  67.         endm
  68.         I=0                             ; yellow to white
  69.         rept 24
  70.         db   63,63,21*I/8
  71.         I=I+1
  72.         endm
  73.         rept 160                        ; white
  74.         db   63,63,63
  75.         endm
  76.  
  77. Frame        dw   XDOTS*(YDOTS+HIDDEN) dup(?)  ; Flames Frame Buffer
  78. Seed         dw   1234h                 ; Random Seed
  79. FontDataOfs  dw   ?                     ; Font Data Address
  80. FontDataSeg  dw   ?
  81. FontWidths   db   256 dup (?)           ; Font Char Widths
  82. FontFirst    db   ?                     ; Font First Char
  83. FontWidth    db   ?                     ; Font Max Width
  84. FontHeight   db   ?                     ; Font Height
  85. FontSize     dw   ?                     ; Font BitMap Size (=Width*Height)
  86.  
  87. MesgOff      dw   offset TheMessage     ; Message Offset
  88. TheMessage   db   "     FAKE DEMO  CODED BY PELUSA  MUSIC BY NECROS"
  89.              db   "     GREETS GO TO ALL THE PC DEMO PEOPLE..."
  90.              db   "     THANKS FOR WATCHING THIS LAME THING..."
  91.              db   "     SEEING YA........              "
  92.              db   0
  93.  
  94.  
  95. ;============================ Code Segment ===================================
  96.  
  97.         codeseg
  98.  
  99. ;-----------------------------------------------------------------------------
  100. ; SetModeX - Sets VGA Tweaked Mode 80x80x256.
  101. ;-----------------------------------------------------------------------------
  102.  
  103. proc    SetModeX
  104.         mov     ax,0013h                ; Set VGA Linear 320x200x256
  105.         int     10h
  106.         mov     dx,3C4h                 ; Disable Chain-Four
  107.         mov     ax,0604h
  108.         out     dx,ax
  109.         mov     dx,3C4h                 ; Enable Write to All Four Planes
  110.         mov     ax,0F02h
  111.         out     dx,ax
  112.         mov     ax,0A000h               ; Clear Display Memory
  113.         mov     es,ax
  114.         xor     di,di
  115.         xor     ax,ax
  116.         mov     cx,8000h
  117.         cld
  118.         rep     stosw
  119.         mov     dx,3D4h                 ; Reprogram CRT Controller:
  120.         mov     ax,00014h               ; turn off dword mode
  121.         out     dx,ax
  122.         mov     ax,0e317h               ; turn on byte mode
  123.         out     dx,ax
  124.         mov     ax,00409h               ; cell height
  125.         out     dx,ax
  126.         ret
  127. endp    SetModeX
  128.  
  129. ;-----------------------------------------------------------------------------
  130. ; WaitVR - Waits Vertical Retrace.
  131. ;-----------------------------------------------------------------------------
  132.  
  133. proc    WaitVR
  134.         mov     dx,3DAh
  135. WaitStartVR:
  136.         in      al,dx
  137.         test    al,8
  138.         je      WaitStartVR
  139. WaitEndVR:
  140.         in      al,dx
  141.         test    al,8
  142.         jne     WaitEndVR
  143.         ret
  144. endp    WaitVR
  145.  
  146. ;-----------------------------------------------------------------------------
  147. ; LoadFont - Loads the VLA font.
  148. ;-----------------------------------------------------------------------------
  149.  
  150. proc    LoadFont
  151.         mov     ax,SEG FontFAR          ; Load Font File Address
  152.         mov     es,ax
  153.         mov     [FontDataSeg],ax
  154.         mov     [FontDataOfs],Size FontHeader
  155.         mov     al,[es:FontHeader.First] ; Get Font First Char
  156.         mov     [FontFirst],al
  157.         mov     al,[es:FontHeader.Width] ; Get Font Data Size
  158.         mov     ah,[es:FontHeader.Height]
  159.         mov     [FontWidth],al
  160.         mov     [FontHeight],ah
  161.         mul     ah
  162.         mov     [FontSize],ax
  163.         mov     dl,[es:FontHeader.Total]
  164.         xor     dh,dh
  165.         mul     dx
  166.         add     ax,Size FontHeader      ; Copy Font Widths.
  167.         mov     si,ax
  168.         xor     di,di
  169.         mov     cl,[es:FontHeader.Total]
  170.         xor     ch,ch
  171. CopyWidths:
  172.         mov     al,[es:si]
  173.         mov     [FontWidths+di],al
  174.         inc     si
  175.         inc     di
  176.         loop    CopyWidths
  177.         ret
  178. endp    LoadFont
  179.  
  180. ;-----------------------------------------------------------------------------
  181. ; DrawChar - Draw a Font Char.
  182. ; In:
  183. ;  AL = Character Code.
  184. ;  ES:DI = Frame Screen Address.
  185. ;-----------------------------------------------------------------------------
  186.  
  187. proc    DrawChar
  188.         sub     al,[FontFirst]          ; Get Char BitMap Offset
  189.         xor     ah,ah
  190.         mov     bx,ax
  191.         mul     [FontSize]
  192.         add     ax,[FontDataOfs]        ; si = char offset
  193.         mov     si,ax
  194.         mov     dl,[FontWidths+bx]      ; dx = char width
  195.         xor     dh,dh
  196.         mov     cl,[FontHeight]         ; cx = char height
  197.         xor     ch,ch
  198.         mov     al,[FontWidth]          ; bp = font max width
  199.         xor     ah,ah
  200.         mov     bp,ax
  201.  
  202.         mov     ax,XDOTS                ; Draw on Screen Center
  203.         sub     ax,dx
  204.         shr     ax,1
  205.         shl     ax,1
  206.         add     di,XDOTS*(16+YDOTS)
  207.         add     di,ax
  208.  
  209.         push    ds                      ; ds = font data segment
  210.         mov     ds,[FontDataSeg]
  211. DrawCharLoop:
  212.         push    cx
  213.         push    si
  214.         push    di
  215.         xor     ah,ah
  216. DrawPlane1:
  217.         mov     al,[ds:si]
  218.         test    al,al
  219.         je      SkipColor
  220.         mov     al,0FFh
  221.         mov     [es:di],ax
  222. SkipColor:
  223.         add     si,bp
  224.         add     di,XDOTS*2
  225.         loop    DrawPlane1
  226.         pop     di
  227.         pop     si
  228.         pop     cx
  229.         inc     si
  230.         add     di,2
  231.         dec     dx
  232.         jg      DrawCharLoop
  233.         pop     ds
  234.         ret
  235. endp    DrawChar
  236.  
  237. ;-----------------------------------------------------------------------------
  238. ; DrawMesg - Draws the Next Message on the Screen.
  239. ;-----------------------------------------------------------------------------
  240.  
  241. proc    DrawMesg
  242.         pusha
  243.         push    es
  244.         mov     ax,ds                   ; Loads Frame Area Address
  245.         mov     es,ax
  246.         lea     di,[Frame] 
  247.         cld
  248.         mov     si,[MesgOff]
  249.         lodsb
  250.         test    al,al
  251.         stc
  252.         je      DrawMesgExit
  253.         mov     [MesgOff],si
  254.         call    DrawChar
  255.         clc
  256. DrawMesgExit:
  257.         pop     es
  258.         popa
  259.         ret
  260. endp    DrawMesg
  261.  
  262. ;-----------------------------------------------------------------------------
  263. ; Random - Returns a random number of 16 bits.
  264. ;-----------------------------------------------------------------------------
  265.  
  266. proc    Random
  267.         mov     ax,[Seed]
  268.         imul    ax,8905h
  269.         inc     ax
  270.         mov     [Seed],ax
  271.         ret
  272. endp    Random
  273.  
  274. ;-----------------------------------------------------------------------------
  275. ; Flames - Flames Like Screen Animation.
  276. ;-----------------------------------------------------------------------------
  277.  
  278. proc    Flames
  279.         pusha
  280.         push    ds
  281.         push    es
  282.  
  283.         call    SetModeX                ; Sets VGA 80x80x256 graphics mode
  284.  
  285.         call    LoadFont
  286.         mov     [MesgOff],offset TheMessage
  287.  
  288.         call    WaitVR
  289.         lea     si,[Palette]            ; Sets Color Palette
  290.         mov     cx,768
  291.         mov     dx,3C8h
  292.         xor     al,al
  293.         out     dx,al
  294.         inc     dx
  295.         cld
  296.         rep     outsb
  297.         mov     ax,ds                   ; Clears Frame Buffer
  298.         mov     es,ax
  299.         lea     di,[Frame]
  300.         mov     cx,XDOTS*(YDOTS+HIDDEN)
  301.         xor     ax,ax
  302.         rep     stosw
  303.         mov     ax,0A000h               ; Set Display Memory Segment
  304.         mov     es,ax
  305.         mov     bx,FLSEED               ; Loads Flames Seed Factor
  306.         xor     bp,bp                   ; Start Timer Counter
  307.          
  308. FlamesLoop:
  309.         inc     bp                      ; Increase Timer
  310.         call    WaitVR                  ; Wait Vertical Retrace
  311.         lea     si,[Frame]              ; Write Frame to the Screen
  312.         xor     di,di
  313.         mov     cx,XDOTS*YDOTS/2
  314. WriteFrameLoop:
  315.         lodsw
  316.         mov     dl,al
  317.         lodsw
  318.         mov     dh,al
  319.         mov     ax,dx
  320.         stosw
  321.         loop    WriteFrameLoop
  322.  
  323.         cmp     bp,TIMEOUT              ; Don't Draw Message while
  324.         jae     DontDrawMesg            ; Fading out the Flames.
  325.         mov     ax,bp
  326.         xor     dx,dx
  327.         mov     cx,MESGSPEED
  328.         div     cx
  329.         test    dx,dx                   ; Draws Messages...
  330.         jne     DontDrawMesg
  331.         call    DrawMesg
  332.         jnc     DontDrawMesg            ; If no more message text,
  333.         mov     bp,TIMEOUT              ; Start fading out...
  334. DontDrawMesg:
  335.  
  336.         mov     cx,XDOTS*(YDOTS+HIDDEN-2) ; Transform Upper Frame Lines
  337.         lea     si,[Frame+2*XDOTS]
  338. FlamesTransform:
  339.         mov     ax,[ds:si-2]            ; Sets Pixel at (X,Y) like
  340.         add     ax,[ds:si+0]            ; the average of the near four
  341.         add     ax,[ds:si+2]            ; pixels below it:
  342.         add     ax,[ds:si+2*XDOTS]      ; P(X,Y) = (P(X-1,Y+1)+P(X,Y+1)+
  343.         sub     ax,bx                   ;   P(X+1,Y+1)+P(X,Y+2)-Seed)/4
  344.         sar     ax,2
  345.         jge     FlameNotTooLow
  346.         xor     ax,ax
  347. FlameNotTooLow:
  348.         mov     [ds:si-2*XDOTS],ax
  349.         add     si,2
  350.         loop    FlamesTransform
  351.  
  352.         ; Sets New Random Bottom Flames with Colors from 0 to 127.
  353.         lea     si,[Frame+2*XDOTS*(YDOTS+HIDDEN-2)]
  354.         mov     cx,XDOTS
  355.         xor     dx,dx
  356. RandomFlames:
  357.         call    Random                  ; Use Random to Create a New
  358.         test    ax,ax                   ; Flames Bottom Lines
  359.         js      NotNewColor
  360.         call    Random
  361.         mov     dl,al
  362.         and     dl,7Fh
  363. NotNewColor:
  364.         mov     [ds:si],dx
  365.         mov     [ds:si+2*XDOTS],dx
  366.         add     si,2
  367.         loop    RandomFlames
  368.         mov     ah,1                    ; or Any Key Pressed?
  369.         int     16h                     
  370.         je      CheckTimer
  371.         mov     ah,0
  372.         int     16h
  373.         mov     bp,TIMEOUT
  374. CheckTimer:
  375.         cmp     bp,TIMEOUT              ; Timeout?
  376.         jb      FlamesLoop
  377. DecreaseFlames:
  378.         inc     bx                      ; Increase Flames Seed
  379.         cmp     bx,FLBLANK              ; (makes flames more low)
  380.         jbe     FlamesLoop
  381. FlamesExit:
  382.         mov     ax,0003h                ; Set Text Mode 80x25x16
  383.         int     10h
  384.         pop     es
  385.         pop     ds
  386.         popa
  387.         ret
  388. endp    Flames
  389.  
  390. ;-----------------------------------------------------------------------------
  391. ; Start - Startup code called from DOS.
  392. ;-----------------------------------------------------------------------------
  393.  
  394. proc    Start
  395.         mov     ax,@Data                ; Set DS Segment
  396.         mov     ds,ax
  397.         mov     bx,ss                   ; Shrink Program Segment
  398.         mov     ax,es
  399.         sub     bx,ax
  400.         mov     ax,sp
  401.         shr     ax,4
  402.         inc     ax
  403.         add     bx,ax
  404.         mov     ah,4Ah
  405.         call    Flames                  ; Do Flames Demo
  406.         mov     ax,4C00h
  407.         int     21h                     ; Exit to DOS.
  408. endp    Start
  409.  
  410.         end     Start
  411.