Should I simplify my blog code?
Moderator: Moderators
Should I simplify my blog code?
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?
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?
nesdoug.com -- blog/tutorial on programming for the NES
Re: Should I simplify my blog code?
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.
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?
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.
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?
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...
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.
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); }
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.
Last edited by dougeff on Tue Mar 28, 2017 5:26 pm, edited 1 time in total.
nesdoug.com -- blog/tutorial on programming for the NES
Re: Should I simplify my blog code?
Every neslib I've seen has used NTADR to do this: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.
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?
It's cool that you can highlight specific lines on github with a #L
I'm learning lots today
I'm learning lots today
nesdoug.com -- blog/tutorial on programming for the NES
Re: Should I simplify my blog code?
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?
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.
nesdoug.com -- blog/tutorial on programming for the NES
Re: Should I simplify my blog code?
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.
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?
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.sdustmop wrote:Every neslib I've seen has used NTADR to do this: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.
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.
Interestingly...the neslib.s from the 2015 examples is different from
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.
nesdoug.com -- blog/tutorial on programming for the NES
Re: Should I simplify my blog code?
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.
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.
-
- Posts: 102
- Joined: Fri Dec 27, 2013 4:28 pm
Re: Should I simplify my blog code?
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.
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?
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
https://github.com/peterhellberg/nesdev ... s_examples
Also found source code for SplatooD, which uses neslib / cc65.
https://github.com/SplatooD/splatood
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.hybrid approach, where you use neslib
nesdoug.com -- blog/tutorial on programming for the NES
Re: Should I simplify my blog code?
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?
Just promise us that you won't put global data in .h files like these examples dodougeff 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
My games: http://www.bitethechili.com