Programming NES games in C article

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems.

Moderator: Moderators

User avatar
thefox
Posts: 3139
Joined: Mon Jan 03, 2005 10:36 am
Location: Tampere, Finland
Contact:

Post by thefox »

mic_ wrote: Let's say you split your code/data into separate banks which are compiled and linked separately (to avoid having duplicates of the same stuff for different combinations of banks) and then combined into a .nes file.
In this case (when each source file is compiled+linked separately -> bin) it's not possible/easy. You should compile all the source files to objects, then link those together in a single step for it to be able to resolve everything. If you need duplicate data/code in several banks I would use macros.
Shiru
Posts: 1161
Joined: Sat Jan 23, 2010 11:41 pm

Post by Shiru »

Besides the article, I also wrote a few very simple examples of NES programming in C. They are prebuilt, so you may check them out without compiling, the source code is example1-4.c.

Low level library was updated for these (minor fixes), and Chase code was updated as well.
slobu
Posts: 275
Joined: Tue Jul 12, 2011 10:58 am

Post by slobu »

This is the input from the dead-end users perspective:

The example source gave me more practical knowledge than the article. The comments are enough but with a little more detail could be considered a tutorial in itself. Also, it's easy to make highly concatenated (and obfuscated) lines of code in C. To make a tutorial-by-commented-code some instructions could be broken down for readability.

I guess what I'm saying is that the example source is great and with a little more effort could be a tutorial in itself. :)
User avatar
cpow
NESICIDE developer
Posts: 1097
Joined: Mon Oct 13, 2008 7:55 pm
Location: Minneapolis, MN
Contact:

Post by cpow »

slobu wrote: To make a tutorial-by-commented-code some instructions could be broken down for readability.
I think what you're looking for in this statement is interleaved C/assembly? See the screenshot I posted on the first page of this thread.

If you want to know what assembly is generated for any C statement, no matter how obfuscated the C statement is, mixed-mode debugging is the way to go.
User avatar
jwdonal
Posts: 719
Joined: Sat Jun 27, 2009 11:05 pm
Location: New Mexico, USA
Contact:

Post by jwdonal »

cpow wrote:See the screenshot I posted on the first page of this thread
cpow, that mixed-mode debugging is very cool. nice work!
User avatar
Nioreh
Posts: 115
Joined: Sun Jan 22, 2012 11:46 am
Location: Stockholm, Sweden

Post by Nioreh »

Hi

I am totally new to NES development (started looking into it last week), and this is my first post here. Your article and c library is great. I had my own game up and running in a couple of hours!!! Thank you for this great tutorial!

The code is quite fast, I am doing quite a lot of stuff without slowdown.

Now, if only I had any musical and/or pixel art talent... :D

I will post my game here when it's done.

/Nioreh
Shiru
Posts: 1161
Joined: Sat Jan 23, 2010 11:41 pm

Post by Shiru »

You can find a musician rather easily, there are many musicians who use FamiTracker and would like to make music for a game, even for a freeware one. You can try FamiTracker forums.

Graphics is a more difficult thing, because there aren't too many pixel artists who are able to make good NES graphics and are not busy with pro projects yet (iPhone games etc). Also, there are not many people who are familiar with NES graphics limitations. Anyway, you can try PixelJoint forums.
User avatar
rainwarrior
Posts: 8062
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Post by rainwarrior »

Shiru, reading this article (and some of your source code) has been very inspiring! Thanks for writing and sharing it.
User avatar
Nioreh
Posts: 115
Joined: Sun Jan 22, 2012 11:46 am
Location: Stockholm, Sweden

Post by Nioreh »

Shiru, I tried to download your famitone exporter for FamiTracker, but it gives me a 404. :( Where can I find it?

I decided to try my best at both graphics and audio myself, and I think I am doing ok :)
User avatar
Zepper
Formerly Fx3
Posts: 3264
Joined: Fri Nov 12, 2004 4:59 pm
Location: Brazil
Contact:

Post by Zepper »

Nioreh wrote:Shiru, I tried to download your famitone exporter for FamiTracker, but it gives me a 404. :( Where can I find it?

I decided to try my best at both graphics and audio myself, and I think I am doing ok :)
*aham*
http://famitracker.shoodot.net/downloads.php
Shiru
Posts: 1161
Joined: Sat Jan 23, 2010 11:41 pm

Post by Shiru »

Sorry, my FTP is down by some reason for two days already. FamiTracker page links to my website, there is no separate download.

Here is temporary link for FamiTone.
User avatar
Nioreh
Posts: 115
Joined: Sun Jan 22, 2012 11:46 am
Location: Stockholm, Sweden

Post by Nioreh »

Shiru wrote:Sorry, my FTP is down by some reason for two days already. FamiTracker page links to my website, there is no separate download.

Here is temporary link for FamiTone.
Thanks!

Maybe this is a bit off topic, but I can't get my music files to play correctly with famitone. When I convert it from the text export to .s I get a bunch of these:

"Warning! Note out of supported range, frame 0 row 00 channel 1"

Even if I have nothing on frame 0 row 0 (if channel 1 means square wave 1?).

When I load the music up in my game it is suuuuper slow. Like 1/20 speed or slower. If I use the music from the sample game everything is fine (Fine all the way, export - convert - play).
Shiru
Posts: 1161
Joined: Sat Jan 23, 2010 11:41 pm

Post by Shiru »

I can't guess what is wrong or fix anything without seeing the exported txt file at least.
User avatar
Nioreh
Posts: 115
Joined: Sun Jan 22, 2012 11:46 am
Location: Stockholm, Sweden

Post by Nioreh »

Shiru wrote:I can't guess what is wrong or fix anything without seeing the exported txt file at least.
I'm sorry. It was me being stupid :) (Note A-0 on square wave 2 was the problem).

I think I have found a bug in your library, though. Using pad_poll causes the game to crash when pressing a button at the same time as a direction on the d-pad. (or if pressing both a and b simultaneously)

Edit: I am using it kind of like this:

Code: Select all

j=pad_poll(0);

if(j&PAD_LEFT){
		--px;
	}
else if(j&PAD_RIGHT){
		++px;
	}

Edit 2: This is also happening on your example4.nes if you test it.
Shiru
Posts: 1161
Joined: Sat Jan 23, 2010 11:41 pm

Post by Shiru »

Sorry, I introduced a bug during the latest library update.

My FTP is still down. Here is temporary link to the fixed version (crt0.s and neslib.s are changed), and Chase is updated too (had the bug as well).
Post Reply