Advertisement
mrkite

256-byte fire

May 16th, 2011
1,078
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; This was my submission for the 1996 EFNet #coders 256-byte fire competition
  2. ; Obviously it was targeted toward 16-bit realmode DOS.
  3.  
  4.  
  5.         .model  tiny
  6.         .386
  7.  
  8.         .data
  9.  
  10. cnt     dw      0               ;this is for timing the ending clear
  11. fireof  dw      81              ;this is for the ending clear
  12. rand1   dw     1234h
  13. rand2   dw     4321h
  14. pad     dd      0               ;pad it to 256 bytes
  15.  
  16.         .code
  17.  
  18.         org     100h
  19. main    proc
  20. start:
  21.  
  22.         ;;;set the video mode;;;
  23.  
  24.         mov     ax,13h
  25.         int     10h
  26.         mov     dx,3c4h
  27.         mov     ax,604h
  28.         out     dx,ax
  29.         mov     ax,0f02h
  30.         out     dx,ax
  31.         mov     dx,3d4h
  32.         mov     ax,14h
  33.         out     dx,ax
  34.         mov     ax,0e317h
  35.         out     dx,ax
  36.         mov     al,9
  37.         out     dx,al
  38.         inc     dx
  39.         in      al,dx
  40.         and     al,0e0h
  41.         add     al,7
  42.         out     dx,al
  43.  
  44.         ;;;set the palette;;;
  45.         mov     dx,3c8h
  46.  
  47.         xor     ax,ax
  48.         out     dx,al
  49.         inc     dx
  50.         mov     cx,128
  51. pallp:
  52.         push    ax
  53.         shr     al,1
  54.         out     dx,al
  55.         shr     al,2
  56.         out     dx,al
  57.         shr     al,1
  58.         out     dx,al
  59.         pop     ax
  60.         inc     al
  61.         loop    pallp
  62.  
  63.         push    0a000h
  64.         pop     es
  65.  
  66.         ;;;main loop;;;
  67.  
  68. firelp:
  69.         mov     cx,4399
  70.         mov     di,80
  71. bufr1:
  72.         mov     ax,es:[di-1]            ;angle the flame
  73.         add     al,ah
  74.         shr     al,1                    ;average top two
  75.         mov     bx,es:[di+80]
  76.         add     bl,bh
  77.         shr     bl,1                    ;average bottom two
  78.         add     al,bl
  79.         shr     al,1                    ;average top/bottom
  80.         jz      bufr2
  81.         dec     al
  82.         jz      bufr2
  83.         dec     al
  84. bufr2:
  85.         mov     bx,di
  86.         sub     bx,fireof
  87.         mov     es:[bx],al
  88.  
  89.         inc     di
  90.         loop    bufr1
  91.  
  92.         cmp     cnt,0
  93.         jg      blowflame
  94.  
  95.         mov     ah,1
  96.         int     16h
  97.         jz      ok
  98.         inc     cnt
  99. ok:
  100.         xor     dl,dl
  101.         mov     di,4320
  102.         mov     cx,80
  103. newline:
  104.  
  105.         ;;;get random;;;
  106.         in      al,40h
  107.         add     ax,rand1
  108.         mov     bx,ax
  109.         add     ax,rand2
  110.         mov     rand2,bx
  111.  
  112.         xchg    al,ah
  113.         mov     rand1,ax
  114.  
  115.         and     al,1
  116.         dec     al
  117.         mov     dl,al
  118.  
  119.         mov     es:[di],dl
  120.         mov     es:[di+80],dl
  121.         inc     di
  122.         loop    newline
  123.         jmp     doloop
  124. blowflame:
  125.         inc     cnt
  126.         cmp     cnt,50  ;kill flame?
  127.         jge     killflame
  128.         dec     fireof
  129.         jmp     doloop
  130. killflame:
  131.         xor     ax,ax
  132.         mov     di,4320
  133.         mov     cx,80
  134.  
  135. fllp:
  136.         mov     es:[di],ax
  137.         add     di,2
  138.         dec     cx
  139.         jne     fllp
  140. doloop:
  141.         mov     dx,3dah
  142. vt:     in      al,dx
  143.         test    al,8
  144.         jnz     vt
  145. nvt:    in      al,dx
  146.         test    al,8
  147.         jz      nvt
  148.  
  149.         cmp     cnt,60  ;quit?
  150.         jne     firelp
  151.  
  152.         mov     ax,3
  153.         int     10h
  154.         mov     ax,4c00h
  155.         int     21h
  156. main    endp
  157.  
  158.         end     start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement