Ludum Dare

A place where you can keep others updated about your NES-related projects through screenshots, videos or information in general.

Moderator: Moderators

User avatar
thefox
Posts: 3134
Joined: Mon Jan 03, 2005 10:36 am
Location: 🇫🇮
Contact:

Re: Ludum Dare

Post by thefox »

Deja vu: viewtopic.php?p=155070#p155070

Were you using some kind of a template code to start the project? If so, it might be worth fixing it at the source.
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: fo.aspekt.fi
User avatar
rainwarrior
Posts: 8734
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Ludum Dare

Post by rainwarrior »

While you're in there, make sure you're also doing jsr copydata or equivalent in your startup as well.
team_disposable
Posts: 129
Joined: Sat Oct 15, 2016 8:52 am

Re: Ludum Dare

Post by team_disposable »

Ha, I would it say it is precisely because I am not using template code that I am not initializing the stack. Consider it fixed at source!

Looking back at all of the C tutorials, I can see that section in there. Adding it in and the comparison works as expected.

Thanks!

Interestingly, even with the stack initialized, making two index comparisons seems to take up more cycles then assigning one half of the comparison to a var and then making the comparison,

Is it considered bad practice for any reason to do this? As it would seem it only costs me a char I can reuse and has a visible performance benefit.

yes i am using jsr copydata as previously recommended, thanks!
User avatar
rainwarrior
Posts: 8734
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Ludum Dare

Post by rainwarrior »

Just as a quick check, are you using -O as a compiler flag? With CC65 optimization is recommended even when debugging.

There are lots of unfortunate ways that it might generate worse code one way than another. In particular it seems to have problems keeping efficient track of arrays and pointers, especially with 16-bit indexing. (In general advice: use 8-bit types as much as possible, and use array types rather than pointers when possible.)

Anyhow, presuming you've already got optimization turned on, there are often cases where doing things one way or a trivially different way might result in much better or worse (but functionally equivalent) code. This is just an unfortunate fact about this compiler.

Measure the performance of your code frequently; when it makes something unusually slow it'll be easier to figure it out if you've been checking. Whenever something runs unexpectedly slow, take a peek at the assembly.
team_disposable
Posts: 129
Joined: Sat Oct 15, 2016 8:52 am

Re: Ludum Dare

Post by team_disposable »

Yes, I'm compiling with the flags O and i.

I've stuck pretty exclusively to 8 bit variables and constants and it seems to be fairly snappy so far.

For any one else using C, I'd highly recommend having a var you can assign to to avoid a direct array to array comparison. Even with only three enemies on the screen, it seems to be saving a good chunk of cycles. Which, ironically, seems to be because it avoids the C stack.

Thanks for all of the help!
User avatar
chromableedstudios
Posts: 25
Joined: Sat Jun 29, 2013 4:36 am

Re: Ludum Dare

Post by chromableedstudios »

team_disposable wrote: Is there anything in it you where interested in?
I'm just a noob hoping to someday bang out a working nes game and trying to absorb as much source as possible.

Many thanks for your code explanation!
Post Reply