Limitiation or compromise if write program in c

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems. See the NESdev wiki for more information.

Moderator: Moderators

Garth
Posts: 246
Joined: Wed Nov 30, 2016 4:45 pm
Location: Southern California
Contact:

Re: Limitiation or compromise if write program in c

Post by Garth »

dougeff wrote:Passing arguments to functions is incredibly slow for the 6502.
In what way did you have in mind? I cover parameter-passing via stacks in chapter 6 of the 6502 stacks treatise. The efficiency shows through more in the listings for recursive functions in chapter 15.
http://WilsonMinesCo.com/ lots of 6502 resources
lidnariq
Posts: 11429
Joined: Sun Apr 13, 2008 11:12 am

Re: Limitiation or compromise if write program in c

Post by lidnariq »

Unfortunately, we're talking about the default cc65 software stack.

Everything that's not explicitly global, static, or {local and compiled with --static-locals} gets put on the stack, and when every single variable involves stack manipulation it's an awful lot of added computational overhead.
Garth
Posts: 246
Joined: Wed Nov 30, 2016 4:45 pm
Location: Southern California
Contact:

Re: Limitiation or compromise if write program in c

Post by Garth »

Got it.
http://WilsonMinesCo.com/ lots of 6502 resources
na_th_an
Posts: 558
Joined: Mon May 27, 2013 9:40 am

Re: Limitiation or compromise if write program in c

Post by na_th_an »

If you really need functions with parameters so your code is less of a mess, and you can afford a bit of overhead, have a set of multi-purpose global variables (and be careful ;) ) and copy the parameters to the globals at the beginning of your function.

Anyways, I have a set of multi-purpose global variables and 75% of the "strange bugs" I spend hours fetching have to do with it :lol: :lol: :lol: :lol:
User avatar
Banshaku
Posts: 2417
Joined: Tue Jun 24, 2008 8:38 pm
Location: Japan
Contact:

Re: Limitiation or compromise if write program in c

Post by Banshaku »

DRW wrote: Something like "Nekketsu Kakutou Densetsu"?
I like Kunio games but this was not what I had in mind. I want the game to be fast, no dept in the screen so you have to move from platform to platform very fast and attack the other player(s).

I did a quick search to try to find back the screenshot that inspired the idea and I think it was the game Towerfall on the ouya. I only saw a screenshot of (maybe) that game and I like the limited scope of the screen but I'm not sure if this is exactly what I had in mind since I never saw the gameplay so it may be similar.

I want to create characters with different skill set (strengths, speed, range, size etc) that can battle in a limited stage. Some passage would allow you to go from top to bottom (or left to right depending of the stage selected), there would be traps, part that help you move faster etc. You can kick-jump on wall to go higher, use the environment to move or attack, etc. That could be a good small project to create a code base for bigger projects.

Now that there is a windows version of towerfall (didn't know about that) I may give it a try and look at some of the video online and check if this is what I had in mind or not.
na_th_an wrote:Anyways, I have a set of multi-purpose global variables and 75% of the "strange bugs" I spend hours fetching have to do with it :lol: :lol: :lol: :lol:
I remember that trying parameters that way in assembler too many bugs came out because of that. I guess I will to figure out the balance of usability and how buggy it may become because of such feature.
User avatar
DRW
Posts: 2225
Joined: Sat Sep 07, 2013 2:59 pm

Re: Limitiation or compromise if write program in c

Post by DRW »

na_th_an wrote:Anyways, I have a set of multi-purpose global variables and 75% of the "strange bugs" I spend hours fetching have to do with it :lol: :lol: :lol: :lol:
Here's a hint: Mark the function name with the highest number of variable that is used.

If you use var1, var2 and var3 in the function, call your function MyFunction_var3.
This way, any function that calls MyFunction_var3 knows that it shouldn't use var1, var2 and var3 if it wants those values to remain consistent before and after the function call.

Of course, this also counts for outer functions. If MyOtherFunction doesn't use any variables itself, but calls MyFunction_var3, then of course you have to rename it MyOtherFunction_var3 so that any code that calls this function knows that var1, var2 and var3 are used somewhere inside.
My game "City Trouble":
Gameplay video: https://youtu.be/Eee0yurkIW4
Download (ROM, manual, artworks): http://www.denny-r-walter.de/city.html
User avatar
DRW
Posts: 2225
Joined: Sat Sep 07, 2013 2:59 pm

Re: Limitiation or compromise if write program in c

Post by DRW »

@Banshaku:

O.k., so in this case, you first have to write a general platformer engine and then a way for the characters to attack each other.

Advantage: You can use the same basic engine to program a platform fighting game and also a common sidescroller jump'n'run.
My game "City Trouble":
Gameplay video: https://youtu.be/Eee0yurkIW4
Download (ROM, manual, artworks): http://www.denny-r-walter.de/city.html
na_th_an
Posts: 558
Joined: Mon May 27, 2013 9:40 am

Re: Limitiation or compromise if write program in c

Post by na_th_an »

DRW wrote:
na_th_an wrote:Anyways, I have a set of multi-purpose global variables and 75% of the "strange bugs" I spend hours fetching have to do with it :lol: :lol: :lol: :lol:
Here's a hint: Mark the function name with the highest number of variable that is used.

If you use var1, var2 and var3 in the function, call your function MyFunction_var3.
This way, any function that calls MyFunction_var3 knows that it shouldn't use var1, var2 and var3 if it wants those values to remain consistent before and after the function call.

Of course, this also counts for outer functions. If MyOtherFunction doesn't use any variables itself, but calls MyFunction_var3, then of course you have to rename it MyOtherFunction_var3 so that any code that calls this function knows that var1, var2 and var3 are used somewhere inside.
Now that's a great idea, thanks. I'll try and come up with a nomenclature for my next project.
User avatar
dustmop
Posts: 136
Joined: Wed Oct 16, 2013 7:55 am

Re: Limitiation or compromise if write program in c

Post by dustmop »

dougeff wrote:
How do you debug the C code of an NES game?
cc65 command line directive --add-source
I built a tool on top of this, called annotatecc65, that adds the original C source into FCEUX's debugger, which makes debugging very straight-forward. I'm interested if anyone has tried it out and found it useful.

https://github.com/dustmop/annotatecc65
na_th_an
Posts: 558
Joined: Mon May 27, 2013 9:40 am

Re: Limitiation or compromise if write program in c

Post by na_th_an »

How come I didn't know this? This will come extremely handy, thanks!
User avatar
dustmop
Posts: 136
Joined: Wed Oct 16, 2013 7:55 am

Re: Limitiation or compromise if write program in c

Post by dustmop »

na_th_an wrote:This will come extremely handy, thanks!
Cool! Welcome! If you have any questions or issues please feel free to DM me or file a github issue.
User avatar
dougeff
Posts: 3078
Joined: Fri May 08, 2015 7:17 pm

Re: Limitiation or compromise if write program in c

Post by dougeff »

nice!
nesdoug.com -- blog/tutorial on programming for the NES
na_th_an
Posts: 558
Joined: Mon May 27, 2013 9:40 am

Re: Limitiation or compromise if write program in c

Post by na_th_an »

All I have to say is that I used it today and it was bliss. Great job!
User avatar
GradualGames
Posts: 1106
Joined: Sun Nov 09, 2008 9:18 pm
Location: Pennsylvania, USA
Contact:

Re: Limitiation or compromise if write program in c

Post by GradualGames »

I made an earnest attempt over a 3 month period to adapt to C in early 2016 or so, for my current project. While I can imagine smarter folks benefiting from it, I just couldn't get used to it. I had too many weird problems I didn't know how to solve. Either something with syntax, or I didn't understand whether something allocated ram or rom, or I just had to bastardize the C language so horribly and mangle it beyond comprehension I might as well be coding in asm anyway. And finally, I attempted to write a metasprite routine in C, and drawing a large 18 sprite metasprite took a frame and a half. Rewriting the same routine in assembly and drawing the same large sprite took about 1/10th of a frame. Obviously nobody would write a metasprite routine in C to begin with, but that difference in speed was so alarming I became afraid that I would run into performance issues way more often than I'd like if I adopted C. I'm also terrible at reading code and if there's ever a problem, I really didn't want to pore over the code cc65 generates...OH! And things like sub pixel precision, like 8.8 velocities added on 8.8.8 coordinates? That comes out so naturally in asm. The pointer math or other workarounds one must do in C are rather unpleasant.

The bottom line for me though is the "feeling" of coding in assembly just makes me happier, period. Totally irrational, perhaps, but that's a good enough reason for a hobby where nothing matters but whether one is happy anyway.

Use what you like, not trying to discourage anyone from using C, I think it's really awesome it's being used so well by many excellent fellow homebrew devs.
Garth
Posts: 246
Joined: Wed Nov 30, 2016 4:45 pm
Location: Southern California
Contact:

Re: Limitiation or compromise if write program in c

Post by Garth »

GradualGames, I had those problems and a lot more. I have partly come to the opinion that even for intelligent people, which programming language approach works best for a person depends partly on what kind of brain they're born with. For me, Forth was a natural. My enjoyment of assembly has also increased in recent years as I have done more to raise the level of the language, using macros to make nestable program structures. I really cannot understand how anyone could go for C.
http://WilsonMinesCo.com/ lots of 6502 resources
Post Reply