Live data from Hacker News

How to program an NES game in C

nesdoug.com

41–50 of 70 posts

Re: How to program an NES game in C

#41

Earlier quoted context omitted.

If you're not using the value you can't “want it”. There is only one sane way to interpret the following two expressions statements (in C), and it is that they are equal. g++; ++g;

Well, no, you can do stupid code like: if(g++) { //do something } Which obviously will do something if g was non-zero before incrementing it by one. It's a really poor way of writing code, but I have seen it done.

They said 'if you're not using the value', and you've presented an example where they are using the value, so you're criticism doesn't apply in the case they're talking about.

Re: How to program an NES game in C

#42
post #39
post #29

How did they actually make NES games? By that I mean, what types of computers were they using for creating NES games? Other 6502-based computers? Could they run the NES games on there? Or did they have to burn to a cart to test things every time? How did they design graphics? Was it basically graph paper, which then they translated into sprites by hand?

I might be wrong but I seem to remember the Sharp X68000 being a preferred platform in the early days? https://en.wikipedia.org/wiki/X68000

That has a release date years after the NES and seems to have been similar to and used as a development platform for 68k-based arcades. It's completely different hardware, much more powerful than a NES but too slow to sensibly emulate one.

Re: How to program an NES game in C

#43
post #29

How did they actually make NES games? By that I mean, what types of computers were they using for creating NES games? Other 6502-based computers? Could they run the NES games on there? Or did they have to burn to a cart to test things every time? How did they design graphics? Was it basically graph paper, which then they translated into sprites by hand?

Not a NES game, but HAL Laboratory used a Twin Famicom-based system to develop Kirby's Dreamland (GB) using just a trackball as an input device: http://sourcegaming.info/2017/04/19/kirbys-development-secre...

Re: How to program an NES game in C

#44

IMHO a 6502 is too limited to be effectively programmed in C; even this part of the article gives all the limitations: https://nesdoug.com/2015/11/15/2-how-cc65-works/ With this important note: "clean unaltered C code will compile into very slow code that takes up too much of the limited memory space." In other words, "C" written for such a CPU will be in a vastly different style from more "normal" C, so that it migh…

Does c65 turn structs into parallel arrays? If you have something like struct Monster { unsigned char hitPoints; unsigned char damage; unsigned char shieldLevel; char* name; }; static Monster s_monsters[] = { { 5, 1, 0, "orc", }, { 50, 10, 5, "dragon", }, { 10, 3, 1, "goblin", }, }; that's a no-no on 6502. You generally need to store those in parallel byte arrays including the string pointer's upper and lower bytes e…

Didn't John Carmack use structures rather than parallel arrays even in Apple II assembly? Source: one of his old .plan files, reproduced verbatim in _Masters of Doom_

Edit: Found it online here: https://github.com/ESWAT/john-carmack-plan-archive/blob/mast...

Re: How to program an NES game in C

#45
post #8

Yeah, making an NES game is on my bucket list. I'm very new at (complex) programming, but I think I might just do it in assembly. If you're going to run a marathon, why not actually do a triathlon?

Might be easier (but just as much fun) to whet your palate by creating a pico-8 game first: https://www.lexaloffle.com/pico-8.php

I'd beg to differ. Interpreted lua on a 4GHz pc with 4G of ram is not like compiled C on a 8bit micro. Avr dev or arduino could be arguably closer.

Re: How to program an NES game in C

#46
post #36

> All NES assembers are command line programs. What does that mean? It has no graphic user interface. Who the hell is this written for?

I find a lot of these homebrew and ROM hacking documents are written for an enthusiast that might not necessarily have a background in software development.

At first I found it a little disorienting because the technical level of the writing would fluctuate, but at the same time I can appreciate it being accessible for someone who might not know much about programming.

Re: How to program an NES game in C

#47
post #3

IMHO a 6502 is too limited to be effectively programmed in C; even this part of the article gives all the limitations: https://nesdoug.com/2015/11/15/2-how-cc65-works/ With this important note: "clean unaltered C code will compile into very slow code that takes up too much of the limited memory space." In other words, "C" written for such a CPU will be in a vastly different style from more "normal" C, so that it migh…

I feel like handling ROM banking would be the most challenging part of coding in C. You have to swap portions of your program in and out constantly (unless you manage to fit it all in a single bank). It seems hard to abstract that efficiently from a high level language. I heard there were C compilers for the Game Boy as well but as far I know they were never widely used.

Thanks, TIL about memory banking!

Re: How to program an NES game in C

#48
post #29

How did they actually make NES games? By that I mean, what types of computers were they using for creating NES games? Other 6502-based computers? Could they run the NES games on there? Or did they have to burn to a cart to test things every time? How did they design graphics? Was it basically graph paper, which then they translated into sprites by hand?

Here you can see some developer pictures. The computers are HP 64000. The light pen/sprite program looks very interesting.

http://i.kinja-img.com/gawker-media/image/upload/s--09WfR60x...

Re: How to program an NES game in C

#49
post #14

Earlier quoted context omitted.

A 8080 has a linear 64K address space, like the 8085 and the Z80. Perhaps you were thinking of 8086? In any case, 64K address space is not the real limiter with a 6502 --- it's other things, like the tiny number of registers, relative shortage of 16-bit addressing modes, and fixed(!) 256-byte stack which make it difficult to program in C. Even the 6800, with its 16-bit index and stack pointer registers, would be easi…

Yeah, I thought 8086 also had segments, did not bother to cross-check it.

Oops, another typo, I meant 8080.

Re: How to program an NES game in C

#50
post #3

Earlier quoted context omitted.

I feel like handling ROM banking would be the most challenging part of coding in C. You have to swap portions of your program in and out constantly (unless you manage to fit it all in a single bank). It seems hard to abstract that efficiently from a high level language. I heard there were C compilers for the Game Boy as well but as far I know they were never widely used.

C programmers used to handle banks of EMS RAM, on the PC. Ditto with program overlays. I'd assume that NES ROM banks could be handled similarly.

Actually it was mostly Assembly code being called from C and Pascal, or via language extensions like virtual registers.
Post reply on HN