Page 1 of 4

Should I simplify my blog code?

Posted: Sun Mar 26, 2017 2:56 pm
by dougeff
I recently saw someone elses (very small) example code of C for cc65 for NES... they did things in a way that the user, basically, doesn't need to understand anything under the hood. Hiding 2006/2007 writes in hidden function definitions, for example.

Personally, I like to understand everything that is going on, but I suppose a casual user, who just wants to make a simple game, might prefer to know nothing about the inner workings of the PPU.

This seems to me, to be a more modern approach. The library takes care of technical details, the programmer can focus on the game.

Thoughts?

Re: Should I simplify my blog code?

Posted: Sun Mar 26, 2017 4:21 pm
by Pokun
Personally I'm with you that I don't want to include anything I don't fully understand, so I think it's good if both types of tutorials are out there. I prefer to at least know how the code I'm using works, so no libraries, but I don't need to know every little hardware detail under the hood (although I try to learn that too to a degree).

However, although a tutorial that explains everything, doesn't need explain everything the moment they are introduced, as long as it tells the reader that it is something necessary that will be explained later.
For example the Nerdy Nights doesn't explain the init code, leaving the reader wondering why there's suddenly extra code in the source file that the tutorial didn't mention and even seems to contradict what it said.

Re: Should I simplify my blog code?

Posted: Mon Mar 27, 2017 10:45 am
by slobu
I stick to higher level languages because it allows me to focus on game logic and prototyping ideas easily.

I kinda failed to even get a basic program working in NESICIDE. So, hardware details are nice but a distant priority/motivator.

Re: Should I simplify my blog code?

Posted: Tue Mar 28, 2017 5:05 pm
by dougeff
Thanks for the replies.

This was the example code I saw, that made me think I could have made it MUCH easier...

https://github.com/algofoogle/nes-gamed ... ello-nes.c

Especially lines like this...

Code: Select all

/* Write a byte to a given address: */
#define poke(addr, data)        (*((unsigned char*)addr) = data)

/* Write a pair of bytes to the PPU VRAM Address 2. */
#define ppu_2(a, b)             { poke(PPU_VRAM_ADDR2, a); poke(PPU_VRAM_ADDR2, b); }
I wouldn't use this 'poke' stuff, but it's interesting. I was thinking of something like set_ppu_address (x,y) where the definition somehow converts the x,y coordinates AT COMPILE TIME into writes to $2006.

The user would then only have to use set_ppu_address() and never worry about PPU addresses.

Or, perhaps, everything should be buffered, and written during V-blank. So people won't have to worry about timing things, just an automated system, that buffers all writes, and auto-writes it during NMI routine.

Hmm.

Edit, actually, the very next line of code above...

#define ppu_set_cursor(x, y) ppu_2(0x20+((y)>>3), ((y)<<5)+(x))

Would do what I said.

Re: Should I simplify my blog code?

Posted: Tue Mar 28, 2017 5:13 pm
by dustmop
dougeff wrote:I wouldn't use this 'poke' stuff, but it's interesting. I was thinking of something like set_ppu_address (x,y) where the definition somehow converts the x,y coordinates AT COMPILE TIME into writes to $2006.
Every neslib I've seen has used NTADR to do this:

https://github.com/jmk/cc65-nes-example ... mple1.c#L9

I like to use PPU_DATA and PPU_ADDR in my C projects to simplify memory-mapped registers:

https://github.com/dustmop/annotatecc65 ... e/common.h

In general, macros are dangerous, but can be super useful for readability if used carefully.

Re: Should I simplify my blog code?

Posted: Tue Mar 28, 2017 5:29 pm
by dougeff
It's cool that you can highlight specific lines on github with a #L

I'm learning lots today :D

Re: Should I simplify my blog code?

Posted: Tue Mar 28, 2017 5:37 pm
by dustmop
If you click on the line-numbers on the left-side of the code display, it sends your browser to the line-highlighted link. No need to memorize the anchor or anything!

Re: Should I simplify my blog code?

Posted: Tue Mar 28, 2017 5:47 pm
by dougeff
I was very reluctant to use Shiru's neslib in my example code. For one thing, I'm not sure I understand it 100% fully. Another thing. I'm pretty sure Shiru hates me. A lot.

Re: Should I simplify my blog code?

Posted: Wed Mar 29, 2017 2:38 am
by na_th_an
Neslib is pretty straightforward, is well built, simple, barebones, yet it manages to conceal all the fiddly stuff. But it's there anyways and easily modifiable if you know what you are doing. So it was great for my beginnings and also great now that I have a proper understanding of the system. So easily tweakable. I like it.

I think it's great for beginners 'cause it solves all the fiddly stuff, and still great for intermediates and advanced coders, 'cause the fiddly stuff is easily modifiable. It was pretty straightforward to make it work in UNROM, MMC1 and MMC3, for example.

Re: Should I simplify my blog code?

Posted: Mon Apr 03, 2017 7:42 pm
by dougeff
dustmop wrote:
dougeff wrote:I wouldn't use this 'poke' stuff, but it's interesting. I was thinking of something like set_ppu_address (x,y) where the definition somehow converts the x,y coordinates AT COMPILE TIME into writes to $2006.
Every neslib I've seen has used NTADR to do this:

https://github.com/jmk/cc65-nes-example ... mple1.c#L9

I like to use PPU_DATA and PPU_ADDR in my C projects to simplify memory-mapped registers:

https://github.com/dustmop/annotatecc65 ... e/common.h

In general, macros are dangerous, but can be super useful for readability if used carefully.
The 'cc65-nes-examples' github you linked to is an outdated version. The newer version is from 2015. It has more example code and a completely different neslib.s

Interestingly...the neslib.s from the 2015 examples is different from the example in Chase and different from other Shiru source code (Zooming secretary)

EDIT - I think the newest examples uses the same as the newest Chase source neslib.s, and I think that is what dustmop and na_th_an are using. Nevermind.


Na_th_an / dustmop, which version of neslib.s do you use? It seems that Chase is the most recent version.

Re: Should I simplify my blog code?

Posted: Tue Apr 04, 2017 4:56 am
by na_th_an
My base version comes from this revised version repackaged for the "new" cc65 (current active branch) by lidnariq.

Calima maintains an enhaced version with some fixes.

My own UNROM version is here. I have created simple MMC1 and MMC3 versions but haven't released them yet.

Re: Should I simplify my blog code?

Posted: Thu Apr 06, 2017 10:53 am
by cppchriscpp
I'm definitely a fan of having the little details in there. I like what I've seen of your tutorials, (disclaimer: I haven't read all that much) because of those nitty-gritty details. I may be biased due to already using 6502 assembly a lot, however.

At the same time, neslib is awesome, and makes working in C a bit more enjoyable. Neslib made it much easier to bootstrap some examples of my most recent project. It also made those examples more readable - at least as far as using my library goes, as I was able to abstract the system details away.

It seems to me like there's room on the internet and a use for both. I guess it's a question of which experience you want to provide - quickly bootstrapping a working NES game, or giving the user the tools to understand and tinker with everything going on in their game.

This is admittedly not a fully-formed thought - could you do some sort of a hybrid approach, where you use neslib, but also have info boxes that explain the macros/etc for anyone that's inclined to read them? Or maybe even just links to the source for where to see things?


Unrelated note, I didn't realize how many people already had neslib-based bootstrap repos. I'm partway through making an mmc1 example for myself. (Mainly want to use it for ludum dare in a couple weeks) I still probably will, but nice to see more examples coming out. It gives people options for getting started. For example, my typical setup involves using makefiles, a lot of integration with vs code, and automatic circleci builds/releases of every pushed commit. (I only recently figured that last one out; check out my nesnet project if you want an example!) I can see people wanting something simpler or just different.

Re: Should I simplify my blog code?

Posted: Thu Apr 06, 2017 9:37 pm
by dougeff
This gentleman has the newer example code (Shiru) on his github

https://github.com/peterhellberg/nesdev ... s_examples

Also found source code for SplatooD, which uses neslib / cc65.

https://github.com/SplatooD/splatood

hybrid approach, where you use neslib
I might try to use a modified (expanded) version of neslib. Now that I've looked into it, I do think I understand it 99%. Some of the functions could be changed a bit. I'm not a fan of the current controller read functions, for example.

Re: Should I simplify my blog code?

Posted: Fri Apr 07, 2017 2:14 am
by na_th_an
As for the main topic, I appreciate that you get low in the mud in the tutorials from your site. They have been quite helpful for me, specially undestanding how scrolling works in a lower level (neslib hides this) or understanding MMC3's IRQs.

Re: Should I simplify my blog code?

Posted: Fri Apr 07, 2017 1:53 pm
by gauauu
dougeff wrote:This gentleman has the newer example code (Shiru) on his github

https://github.com/peterhellberg/nesdev ... s_examples

Also found source code for SplatooD, which uses neslib / cc65.

https://github.com/SplatooD/splatood
Just promise us that you won't put global data in .h files like these examples do :shock: