

NES Programming Tutorials - rsigrest
http://nintendoage.com/forum/messageview.cfm?catid=22&threadid=7155

======
JeremyMorgan
This is the thing I've been waiting for since I was 12

------
emmett9001
These are excellent, I've recently been following them as a hobby project. My
results so far are here :)
[https://github.com/emmett9001/pong_nes](https://github.com/emmett9001/pong_nes)

~~~
rsigrest
Awesome! I'm planning on doing a similar thing soon.

------
sjtgraham
IIRC there is a C compiler (cc65) that targets 6502, AFAIK it's a dead project
:(

Anyone know anything about writing NES programs in C? Writing a NES game
really appeals to me, but 6502 ASM does not!

~~~
ANTSANTS
Shiru is the only person I know of that wrote anything interesting in C for
the NES. Here are his thoughts on the experience:

[http://shiru.untergrund.net/articles/programming_nes_games_i...](http://shiru.untergrund.net/articles/programming_nes_games_in_c.htm)

[http://forums.nesdev.com/viewtopic.php?f=2&t=8493](http://forums.nesdev.com/viewtopic.php?f=2&t=8493)

Take note of the "Optimization" section. The C you have to write for cc65 to
generate a somewhat acceptable program is very... unidiomatic. C's machine
model does not map well to 8-bit micros at all.

You can't write a game for the NES or any of these old consoles entirely in C,
some parts simply will not be fast enough to fit into tiny timing windows. At
the very least, your interrupt routines (updating sound, graphics, and
possibly scanline "raster effects") will have to be written in assembly. Game
logic has a bit more leeway, but you'd still run the risk of taking too long
and losing frames with an unoptimized program. Given that, it may still be a
productivity win to use C to "script" some optimized assembly language to make
a simple game (kinda like how modern game engines use languages like Lua to
script optimized C++), but I don't think you can get very far if you're just
using C as a crutch to avoid understanding the 6502.

I think 6502 assembly isn't as hard as it sounds (it's fun!), but if that
thought really turns you off, others have been much more successful with the C
+ optimized assembly libraries approach in the Sega Genesis/Mega Drive scene,
where the standard dev tools are an older version of the GNU binutils + gcc
for C projects. The 68000 is much more amenable to being targeted by a C
compiler than a 6502 is.

[http://gendev.spritesmind.net/forum/viewtopic.php?t=14](http://gendev.spritesmind.net/forum/viewtopic.php?t=14)

[http://gendev.spritesmind.net/forum/viewtopic.php?t=1373](http://gendev.spritesmind.net/forum/viewtopic.php?t=1373)

EDIT: Also, from experience writing some simple demo programs for the NES, I
think understanding the PPU and writing a program that can be bank-switched
effectively dwarfs the challenge of learning to program in assembly language.

~~~
jevinskie
I suppose it depends on the CPU. GCC can generate high quality, compact code
for the 8-bit AVR. Of course, AVR was designed for C, it has 32 registers and
good indexing modes.

------
mrcactu5
What is the point of learning 6502 now?

I've wanted to try writing for NES. Learning 6502 seems like a fun
intellectual exercise - certainly the most fun way to learn assembly.

Even if I could write NES code, I probably can't find working NES hardware to
test it on. There are emulators, at which point I may as well write in another
language.

~~~
ANTSANTS
Why do people have Renaissance fairs, use film cameras, paint instead of using
Photoshop, etc? Why do anything? It's fine if it doesn't interest you, but
it's not like you need a practical reason to have fun making something.

>Even if I could write NES code, I probably can't find working NES hardware to
test it on.

NESes themselves are readily available. Flashcarts like the PowerPak and the
Everdrive-N8 are somewhat expensive, but not outrageously so. Some people also
gut old games or buy repro PCBs to create test cartridges with somewhat
easily-rewritable EEPROMs.

>There are emulators, at which point I may as well write in another language.

As long as you periodically test on the real deal, I fail to see how this
would be a problem. It's certainly faster to load a ROM in an emulator than it
is to copy it to an SD card or rewrite an EEPROM. Not to mention, there are
obvious advantages to having access to a software debugger.

------
acuozzo
Also be sure to check out [http://nesdev.com/](http://nesdev.com/)

------
skcin7
I have a little NES programming experience. The 6502 assembler I use is
NESASM, which is also the one those tutorials recommend. There are others
called Asm6 and CA65 that I haven't tried.

The syntax that each assembler recognizes is slightly different so source code
that assembles properly in one assembler may not assemble properly in another.
This is something to watch out for when looking at code examples on the
nesdev.com forums.

HAVE FUN with NES programming! :) I've only ever made simple programs.
However, the only limits are your imagination. The homebrew game "Battle Kid:
Fortress of Peril" was created recently, which is one of the best NES games in
my opinion.

------
laaph
This is interesting, as I was recently asked to teach 6502 programming for the
purpose of programming the NES (I never have programmed an NES, my (limited)
background in assembly language was for the Apple II).

After much searching, it seems a lot of the materials are poorly organized
despite the wikis and such out there. This set of tutorials by far the most
approachable and understandable material to go from not knowing much about the
NES to being able to get Mario to move around.

------
sejje
Just don't read the comment thread, it will hurt your brain.

~~~
Vaskivo
Stuff that hurts your brain is the kind of stuff that's fun to dive into.
Except empty swimming pools :)

~~~
tsumnia
I think he means the deeper in the comments you go, the closer it becomes an
'e-peen' measuring contest. But the first post is the only thing you should
dive into.

~~~
skcin7
I became a member of that site when it started; "e-peen measuring contest" is
an accurate way to describe it.

------
jimzvz
Sounds like fun. Perhaps a productive way to procrastinate.

------
taopao
YES! I'm so grateful that these guys scooped up all this useful info into one
place.

