Fire effect

Basic and Machine Language

Moderator: Moderators

Kananga
Vic 20 Afficionado
Posts: 317
Joined: Mon Mar 08, 2010 2:11 pm

Fire effect

Postby Kananga » Sat Nov 19, 2011 12:48 pm

After two months of "serious" programming for the FE3 RAM Disk, I needed a break and had a go at implementing the fire effect from C-64 version on the VIC-20.
It uses custom characters to display dithered colours, so it was not too difficult to adopt it for the VIC-20. And it runs on the unexpanded Vic.

Then I put some bloat in by adding a (slow) scroller and playback of a digitized sound sample. (needs 24K RAM)

Have fun with my first "intro"!

Source code
Buy the new Bug-Wizard, the first 100 bugs are free!

User avatar
Wilson
Vic 20 Enthusiast
Posts: 156
Joined: Mon Sep 28, 2009 7:19 am

Postby Wilson » Sat Nov 19, 2011 7:41 pm

Yay! I liked this a lot.
edit: Oops, should've read the readme :mrgreen:
The expanded version is great! It has a very cozy vibe. Perfect for the season. Thanks, Kananga. :)

User avatar
Boray
Musical Smurf
Posts: 4032
Joined: Mon May 03, 2004 10:47 am

Postby Boray » Sun Nov 20, 2011 6:33 am

Hmmm.... Where is the .prg?
PRG Starter - a VICE helper / Vic Software (Boray Gammon, SD2IEC music player, Vic Disk Menu, Tribbles, Mega Omega, How Many 8K etc.)

Kananga
Vic 20 Afficionado
Posts: 317
Joined: Mon Mar 08, 2010 2:11 pm

Postby Kananga » Sun Nov 20, 2011 10:17 am

Boray wrote:Hmmm.... Where is the .prg?

here :)
Buy the new Bug-Wizard, the first 100 bugs are free!

User avatar
Boray
Musical Smurf
Posts: 4032
Joined: Mon May 03, 2004 10:47 am

Postby Boray » Sun Nov 20, 2011 4:52 pm

Cool
PRG Starter - a VICE helper / Vic Software (Boray Gammon, SD2IEC music player, Vic Disk Menu, Tribbles, Mega Omega, How Many 8K etc.)

User avatar
joshuadenmark
Big Mover
Posts: 925
Joined: Sat Oct 23, 2010 11:32 am
Location: Denmark
Occupation: Copier technician

Postby joshuadenmark » Mon Nov 21, 2011 6:15 am

Hi Kananga

Thanks for sharing this awesome fire demo, liked it alot :D
Kind regards, Peter.
____________________________________________________
In need of a wiki logon - PM me

User avatar
orion70
Meteo VIC
Posts: 3328
Joined: Thu Feb 02, 2006 4:45 am
Location: Piacenza, Italy
Occupation: Biologist

Postby orion70 » Mon Nov 21, 2011 6:55 am

Me too, will try it on the real VIC tonight... :)

Kananga
Vic 20 Afficionado
Posts: 317
Joined: Mon Mar 08, 2010 2:11 pm

Postby Kananga » Mon Nov 21, 2011 1:33 pm

Thank you all, but I did not do much.
Just took this fire demo for C-64, Jeff's font and put it together.

BTW, if anybody got an idea how to make computing the fire faster, I'd really appreciate to read it :)

It takes way more time than a screen refresh and therefore I did not bother to sync it with vertical retrace in the unexpanded version. The principle is quite easy:

seed the bottom line with new (pseudo-random) characters
for each screen position do (starting from top)
add the character value and the three characters below it
subtract 3 and divide by 4
write the value to the current position

custom characters are filled with patterns for increasing heat,
i.e. 0 is black/empty, 1 has a few red dots, ... more yellow added ... up to character 63 (so the sum of 4 characters is less than 256)

Simple but nice to watch.
Buy the new Bug-Wizard, the first 100 bugs are free!

User avatar
orion70
Meteo VIC
Posts: 3328
Joined: Thu Feb 02, 2006 4:45 am
Location: Piacenza, Italy
Occupation: Biologist

Postby orion70 » Mon Nov 21, 2011 2:01 pm

Kananga wrote:Simple but nice to watch.

...like all good programs for the VIC :) . Great effect also on the real machine.

User avatar
Mike
Herr VC
Posts: 3079
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Postby Mike » Mon Nov 21, 2011 2:15 pm

Kananga wrote:BTW, if anybody got an idea how to make computing the fire faster, I'd really appreciate to read it :)

This table based routine takes 34 cycles (+ some extra ones, when a page is crossed) for each character:

Code: Select all

.loop
 CLC                    ;  2
 LDA base,Y             ;  4
 ADC base+offset-1,Y    ;  4
 ADC base+offset  ,Y    ;  4
 ADC base+offset+1,Y    ;  4
 TAX                    ;  2
 LDA table,X            ;  4
 STA base,Y             ;  5
 INY                    ;  2
 BNE loop               ;  3
-----------------------------------
                          34 cycles

Greetings,

Michael

Kananga
Vic 20 Afficionado
Posts: 317
Joined: Mon Mar 08, 2010 2:11 pm

Postby Kananga » Tue Nov 22, 2011 1:22 am

Mike wrote:This table based routine takes 34 cycles (+ some extra ones, when a page is crossed) for each character:

Code: Select all

.loop
 CLC                    ;  2
 LDA base,Y             ;  4
 ADC base+offset-1,Y    ;  4
 ADC base+offset  ,Y    ;  4
 ADC base+offset+1,Y    ;  4
 TAX                    ;  2
 LDA table,X            ;  4
 STA base,Y             ;  5
 INY                    ;  2
 BNE loop               ;  3
-----------------------------------
                          34 cycles


Thanks! :)

In order to get rid of the cycles for indirect ZP-based addressing, you need this routine four times (Screen memory spreads over 4 pages), giving ~34000 cycles. Screen refresh happens approx. every 22000 cycles (PAL). For the version with the scroll text, I have left out one page of video RAM, which still results in ~26000 cycles.

It is perhaps not doable in under 22K cycles without reducing the screen size.
Buy the new Bug-Wizard, the first 100 bugs are free!

User avatar
Mike
Herr VC
Posts: 3079
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Postby Mike » Tue Nov 22, 2011 3:33 pm

Kananga wrote:It is perhaps not doable in under 22K cycles without reducing the screen size.

You could also try to do the effect with double-height characters.

User avatar
Kweepa
Vic 20 Scientist
Posts: 1110
Joined: Fri Jan 04, 2008 5:11 pm
Location: Austin, Texas
Occupation: Game maker

Postby Kweepa » Tue Nov 22, 2011 4:58 pm

You can move the CLC out of the loop since the ADCs are guaranteed not to overflow.
You can use LSR/LSR instead of TAX/LDA tab,X which is 2 cycles less, if you can put up with some noise (!) in the fire from not clearing the carry. Might actually be preferable.
You could also put all four updates inside the same loop with different base values, to save 15*256 cycles on loop checking. There might be an obvious artifact at each page boundary though, I'm not sure.
I make that 256*(3*25 + 30) = 26880 full screen.
Leaving out one page makes it 256*(2*25 + 30) = 20480.

[EDIT: ah, I misunderstood the algorithm. Still, some of these ideas are valid... just not the LSR/LSR...

256*(2*27 + 32) = 22016. So close! Unrolling again...
128*(5*27 + 32) = 21376. Phew! Unrolling again...
64*(11*27 + 32) = 21056.
A full unroll would be 20736, so this is a good balance.]

[EDIT 2: I tested this, and didn't see any obvious artifacts. Whee!]

Kananga
Vic 20 Afficionado
Posts: 317
Joined: Mon Mar 08, 2010 2:11 pm

Postby Kananga » Wed Nov 23, 2011 1:54 am

Kweepa wrote:256*(2*27 + 32) = 22016. So close! Unrolling again...
128*(5*27 + 32) = 21376. Phew! Unrolling again...
64*(11*27 + 32) = 21056.
A full unroll would be 20736, so this is a good balance.]

[EDIT 2: I tested this, and didn't see any obvious artifacts. Whee!]

Great! :D
Buy the new Bug-Wizard, the first 100 bugs are free!

User avatar
Jeff-20
Denial Founder
Posts: 5452
Joined: Wed Dec 31, 1969 6:00 pm

Postby Jeff-20 » Wed Nov 23, 2011 3:49 am

I'm just amazed by this. I don't remember my font being so large... and multicolor... and smoothly scrolling pixel by pixel. Great demo!
High Scores, Links, and Jeff's Basic Games page.


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 1 guest