News for hackers. Stuff that matters.
Re:How to program an NES game in C by simias on Sunday August 13, 2017 @10:23AM (#15003015)
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.

Re:How to program an NES game in C by DSMan195276 on Sunday August 13, 2017 @11:19AM (#15003241)
Yeah, C generally assumes a 'linear' memory space, so memory banks don't really fit into it extremely well.

That said, with a little work you could likely coax the linker into doing a lot of the work for you. You would have to be a little careful though, as code in different banks could not effectively call each-other directly, even though the compiler would likely not yell at you. But you could just organize your code so that the code for each bank is in it's own section, and then tell the linker to link each of those sections at the address that it will be switched in at (Likely the same address for most of them). It might just barf at you, but a linker specifically for systems that do memory banking should have a way to express this.

Re:How to program an NES game in C by digi_owl on Sunday August 13, 2017 @11:48AM (#15003351)
My impression is that the banking was more often used for graphics rather than logic.
Re:How to program an NES game in C by Drakim on Sunday August 13, 2017 @12:18PM (#15003469)
It's used for both. Take for instance Super Mario Bros 3, different banks holds different data for the various enemies, and the same banks also contains the subroutines of logic for those enemies.

That's why, even if you hacked so that Goomba's death behavior should point to the same as that of a Drybones, it would fail as the subroutine for that behavior isn't in the same bank as the Goomba.

Re:How to program an NES game in C by DSMan195276 on Sunday August 13, 2017 @01:25PM (#15003846)
This approach can be used for code and resources. For simpler games it is easier to just not bank the code, but for more resource intensive games you can end up banking code and resources.
Re:How to program an NES game in C by monocasa on Sunday August 13, 2017 @11:37AM (#15003315)
It's just linker magic and tagging sections on everything.

They had the same features up until at least Xbox 360; they're just called 'overlays' on non execute from ROM systems. It doesn't really take an esoteric compiler or environment.

Re:How to program an NES game in C by boomlinde on Monday August 14, 2017 @07:25AM (#15007906)
I believe that cc65 has a good linker that handles once set up for a platform/memory configuration. I don't know how efficient it is, but I bet that manually organizing code and data to minimize cross-page access will be more efficient.

On old (16-bit) x86 you used "far" pointers, which were larger for cross segment access. These were larger and I assume slower since they encoded both the within-segment address and the segment number.

Re:How to program an NES game in C by khedoros1 on Sunday August 13, 2017 @12:31PM (#15003539)
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.
Re:How to program an NES game in C by pjmlp on Sunday August 13, 2017 @04:55PM (#15004883)
Actually it was mostly Assembly code being called from C and Pascal, or via language extensions like virtual registers.
Re:How to program an NES game in C by khedoros1 on Sunday August 13, 2017 @05:36PM (#15005095)
I've been reading the code for Ultima Underworld for a while. A lot of that is written in C, compiled in an early Borland C++ compiler. The C lib covers a few things; it's got some functions for manipulating EMS, and supports some fancy automatic overlay handling. So certainly the functions in the C library are written in assembly, wrapping calls to int67 and such.

And admittedly, it can be hard to see where the hand-coded assembly ends and the compiled C code begins. There are occasional stylistic clues, but I'm generally spending more time figuring out what something does and why it's written than I am which language each piece was coded in. Most of the file and memory handling seems to be done through calls to the C library in that game.

Re:How to program an NES game in C by rofex on Sunday August 13, 2017 @04:16PM (#15004709)
Thanks, TIL about memory banking!