Author Topic: Fire in 159b FASM source  (Read 124 times)

0 Members and 1 Guest are viewing this topic.

Offline boogop

  • C= 64
  • **
  • Posts: 66
  • Karma: 42
    • View Profile
Fire in 159b FASM source
« on: October 25, 2018 »
Started this in TASM but switched to FASM because I really should make some kind of attempt to update myself. Originally 170-something bytes, took some work getting it down to 159. Remove the text, pallete rot and exit logic and it should be 97 bytes.

boogop greets: ralf brown's interrupt list lol

Code: [Select]

;▒ 10/2018 by Boogop
;▒  Boring Old Fire in 159 bytes
;▒ Acknowledgements:
;▒ - raven/tektonic,preacher/traction and others for
;▒   the adc idea, really makes it look demo-y
;▒ requirements
;▒ - must have a halloween message referencing dbf
;▒ - fire must not look like suck
;▒ - text shouldn't be white
;▒ - must have appropriate exit logic

org 100h

; in we trust
; assume ax = 0, if not we're in trouble ;)
mov     al,13h                  ; enter classic demo world
int     10h

xchg    al,ah                   ; al=13h,ah=0 after setting video mode. Switch those
                                ; to get the draw string function in ah and save 2 bytes
                                ; setting al=0 uses color attributes in bl
; draw text
mov     bl,128                  ; color index, we'll rotate it later
mov     cl,24                   ; string length
mov     dx,0107h                ; dl=7 dh=1 column 7 row 1
mov     bp,foo
int     10h

; set palette
xor     ax,ax
mov     dx, 3c9h                ; who needs 3c8h!

@redup:                         ; Set colors 0-64, ramp up red
out     dx,al                   ; set red to value in al
xchg    al,ah                   ; green & blue get 0
out     dx,al                   ; the xchg commands seem unavoidable
out     dx,al
xchg    al,ah
inc     ax                      ; 1 byte smaller than inc al
cmp     al,64
jne     @redup

@yellowdn:                      ; we'll add some yellow for the lols
out     dx,al
out     dx,al
xchg    al,ah
out     dx,al
xchg    al,ah
dec     ax
jnz     @yellowdn               ; don't need cmp al,0

push    0a000h                  ; ds:si is smaller than es:di
pop     ds                      ; by about 6 bytes it seems (why??)


; fire
mov     si,(199*320)            ; bottom line, y * xres
mov     cx,320                  ; screen_w
in      al,40h                  ; the better looking prods tend to use
                                ; rng's, but for my purposes 40h does
mov     [ds:si],al              ; just fine
inc     si ; using the ds: prefix isn't necessary
loop    @randline ; but makes things a little clearer
mov     si,(320*20)             ; we're moving forwards through video
                                ; memory, some move backwards. Skip the
                                ; first 20 lines for the text so it doesn't
@draw:                          ; melt
mov     al,[ds:si]              ; add the surrounding pixels
shl     ax,2                    ;
add     al,[ds:si+1]            ;
adc     ah,0                    ; if the carry flag is set, add 1 to ah
add     al,[ds:si+320]          ;
adc     ah,0                    ;
add     al,[ds:si-1]            ;
adc     ah,0
add     al,[ds:si+640]          ; add the pixel 2 rows above for higher flame
adc     ah,0                    ; ah += 0 + cf
shr     ax,3
;or ax,00111101b                ; uncomment for weird effect lol

                                ; don't let al wrap, you get lots of
jz      @nozero                 ; noise on the screen
dec     ax
mov     [ds:si-320],al          ; put the pixel back on the row below
inc     si
jnz     @draw                   ; if it's wrapped to 0 we've reached the end of the screen

inc     bh
mov     dx,3C8h
mov     al,128                  ; rotate palette index 128
out     dx,al
inc     dx
mov     al,bh                   ; increment red & green together
out     dx,al
out     dx,al
sub     al,32                   ; stick blue 32 behind them for great justice
out     dx,al                   ; we could save 2 bytes by making it white but
                                ; that looks like crap

in      al,60h                  ; check keypress
dec     ax                      ; escape key = 01h, dec 01h = 0
jnz     @main                   ; dex ax one byte smaller than dec al

; exit stuff
mov al,03h
int 10h


foo db 'Halloween greets to DBF!'

Challenge Trophies Won: