home *** CD-ROM | disk | FTP | other *** search
/ ST-Computer Leser 2002 January / STC_CD_01_2002.iso / SCENE / IMATROLL / SRC / FLAME.S < prev    next >
Text File  |  2001-12-11  |  5KB  |  190 lines

  1. ; Flame concept : 
  2. ; To generate the glow
  3. ; Fill the bottom 2 lines with random numbers
  4. ;
  5. ;    for  x = 0 to 2*screenwidth-1:
  6. ;             screen[(screenheight-2)*screenwidth] := random(255);
  7. ;
  8.  
  9.     Section    Text
  10.  
  11. ;
  12. ; Init routine to create text effects (I'M A & TROLL)
  13. ;
  14. Init_Flame1:    lea     FlameText1,a1    ; text to display
  15.         lea    ImgBufferTC,a0    ; destination buffer (320x100)
  16.         bsr    display_text    ; generate text
  17.         
  18.         lea    ImgBufferTC,a0    ; reload buffer at the beginning
  19.         lea    ImgBuffer1,a2    ; this buffer will contains the text (160x100)
  20.         bsr    Init_Flame        ; call flame init
  21.  
  22.         rts
  23.  
  24. ;
  25. ; Init routine2
  26. ;
  27. Init_Flame2:    lea     FlameText2,a1    ; same for second text
  28.         lea    ImgBufferTC,a0
  29.         bsr    display_text    ; generate text
  30.         
  31.         lea    ImgBufferTC,a0
  32.         lea    ImgBuffer2,a2
  33.         bsr    Init_Flame
  34.  
  35.         rts
  36. ;
  37. ; 320*240to160*100 routine (TC->TC)
  38. ; a2 = ImgBuffer destination
  39. ; a1 = text data    
  40.  
  41.  
  42. Init_Flame:        moveq    #99,d1        ; 100 pixels height
  43. .loopy:
  44.         moveq    #9,d2        ; 10*16 pixels width = 160 pixels
  45. .loopx:        
  46.         REPT    16        ; copy first 16 pixels from TC buffer to small buffer 
  47.         move.w    (a0)+,(a2)+
  48.         ENDR
  49.  
  50.         dbra    d2,.loopx
  51.         adda.l    #320,a0        ; forget last 160 right pixels
  52.         dbra    d1,.loopy
  53.  
  54.         rts
  55. ;
  56. ; Entry point routine to display Text1 in Flame effect
  57. ;
  58. Text_Flames1:
  59.         tas    logo1_flag        ; test and set to display the text one time only
  60.         bne.s    FlameCredits    ; if set, go directly to the flame routine
  61.         lea    ImgBuffer1,a1
  62.         move.w    #0,logo2_flag
  63.         bra.s    DisplayText        ; else display the text before the flame effect
  64.  
  65. logo1_flag        dc.w    0
  66.  
  67. ;
  68. ; Entry point routine to display Text2 in Flame effect
  69. ;
  70.  
  71. Text_Flames2:
  72.         tas    logo2_flag        ; test & set
  73.         bne.s    FlameCredits    
  74.         lea    ImgBuffer2,a1
  75.         move.w    #0,logo1_flag
  76.         bra.s    DisplayText
  77.  
  78. logo2_flag        dc.w    0
  79.  
  80. ;
  81. ; Add the 'Text' in the Flame buffer (160x100) 
  82. ;
  83.  
  84. DisplayText        lea    FireBuffer,a0    ; Flame buffer (160x100)
  85.     
  86.         move.w    #160*100/2,d0    ; logo 160*100 in TC (/2 for longwords)
  87. .loopDisp:
  88.         move.l    (a1)+,d1        ; get 2 pixels  
  89.         or.l    d1,(a0)+          ; copy pixels to screen_adr
  90.         dbra    d0,.loopDisp    ; loop
  91.  
  92. ;
  93. ; Generate random blue pixels on the bottom of the buffer to create new flames
  94. ;
  95.  
  96. FlameCredits:    
  97.         move.w    #319,d0        ; plot 2 lines of rnd pixels
  98. .noimg        lea    FireBuffer+320*120,a0    ; go to last line-2 to fill the 2 hidden lines (321 & 322)
  99. .loop1:        move.l    seedFlame,d1
  100.         rol.l       d1,d1        ; generate new rnd
  101.         addq.l      #5,d1
  102.         move.l    d1,seedFlame    ; save it
  103.         andi.w     #$3fff,d1        ; generate 14 bits color
  104.     
  105.  
  106.         move.w    d1,(a0)+        ; put this random blue pixel on this line
  107.  
  108.         dbra    d0,.loop1
  109. ;
  110. ; Flame algo...
  111. ;
  112. ;    for  x = screenwidth to screenwidth*(screenheight-1)-1:
  113. ;             color = screen[x]+screen[x-1]+screen[x+1]+screen[x+screenwidth]
  114. ;             color /= 4 (color shr 2)
  115. ;
  116. ;             color -= 1;
  117. ;
  118. ;             screen[x-screenwidth] = color
  119. ;
  120.  
  121.  
  122.         lea    FireBuffer+320,a0    ; apply effect on the visible area + 2 hidden lines (160*2)
  123.         move.l    #160*120-1,d0    ; for d0=160*120-1 to 0
  124.  
  125. .loop2:        move.w    (a0)+,d1        ; d1=color at x    
  126.         add.w    (a0),d1        ; d1=d1+color at x+1         
  127.         add.w    -4(a0),d1        ; d1=d1+color at x-1        
  128.         add.w    320-2(a0),d1    ; d1=d1+color at x+scrwidth
  129.  
  130.         lsr.w    #2,d1        ; d1=d1/4
  131. ;        beq.s     .overflow        
  132.         sub.w    #250,d1        ; d1=d1-250
  133.         bpl.s    .overflow        ; if <0
  134.         moveq    #0,d1        ; d1 = 0
  135. .overflow:        move.w    d1,-320-2(a0)    ; else plot d1 one line before     
  136.  
  137.         subq.l      #1,d0        ; d0--
  138.         ;tst.l       d0
  139.         bpl.s       .loop2        ; next d0
  140.         
  141. ;
  142. ; at this point all pixels in the buffer are processed
  143. ;
  144.         lea    FireBuffer,a0    ; the flame buffer
  145.         move.l    screen_adr,a1    ; the screen
  146.  
  147.         moveq.w    #119,d0        ; loop for cols
  148.  
  149. .loopCol        move.w    #159,d1        ; loop for rows
  150.         
  151. .loopRow        move.w    (a0)+,d2         ; get pixel from buffer, generate blue color from 14 bits value
  152.         moveq    #9,d3        ; d3=9, lsr can't use immediate >8
  153.         lsr    d3,d2        ; pixel value=value/512 -> get a 5bits value = blue value
  154.         move    d2,d3        ; d3=lw(d2) -> only the lower word is filled
  155.         swap    d3        ; exchange words in d3 to save the blue pixel
  156.         move    d2,d3        ; d3=(lw(d2),lw(d2)) = 2 blue pixels in each word 
  157.         
  158.         move.l    d3,(a1)+        ; copy them 2 times(1 long = 2 words = 2 pixels)
  159.  
  160.         move.l    d3,636(a1)        ; copy them on the next scanlines (we use a quarter screen buffer 160x100)
  161.  
  162.         dbra    d1,.loopRow        ; do it for the whole width (160x2 pixels = 320)
  163.  
  164.         adda.l    #640,a1        ; skip one scanline (already filled)
  165.  
  166.         dbra    d0,.loopCol        ; restart for the next row+1
  167.  
  168.         rts
  169.  
  170.     Section    Data
  171.  
  172. seedFlame:        dc.l    012345678
  173. FlameText1:        dc.w    0,30,4
  174.         dc.b    "I",93,"M",94,"A",0
  175.         EVEN
  176. FlameText2:        dc.w    0,30,4
  177.         dc.b    "TROLL",0
  178.         EVEN
  179.  
  180.     Section     BSS
  181.  
  182. FireBuffer:        ds.w    160*122
  183. ImgBuffer1:        ds.w    160*100
  184. ImgBuffer2:        ds.w    160*100
  185. ImgBufferTC:    ds.w    320*100
  186.  
  187.  
  188.     Section    Text
  189.  
  190.