4

I thought all Atari 2600 games had been programmed in 6502/6507 assembly language (plus whatever activated the Stella sound system), but at a party recently, a friend indicated that some 2600 programmers had actually cross-compiled C code for the 6502. If this is so, which of the 2600 games were in fact written in C, and which compilers were used?

  • 1
    I'm willing to wager that this is not so; 6502 is ill-suited for C because of its limited-range hardware stack, and the 2600 even more so because its memory limit restricts the stack even further than that. But I've no evidence whatsoever. And bataribasic.com seems to run and run. – Tommy Jan 2 at 18:17
  • Not C, but some Atari 2600 homebrew is written in another high-level language called Batari BASIC. Maybe this is what your friend was thinking of? – traal Jan 2 at 18:46
  • 5
    @Tommy You don't need a call stack if you program in a sufficiently limited subset of "C". Keil C51 is not exactly "C", but it's pretty darned close, and it is capable of targeting systems that have only 128 bytes of RAM. It has an option to use activation records that are statically allocated at compile time instead of allocating them from a stack at run-time. – Solomon Slow Jan 2 at 19:38
  • @SolomonSlow the only potential issue (other than recursion, obviously) being that static allocation of activation records may even be a worse thing with only 128 bytes total, as it presumably makes the RAM footprint proportional to the number of functions you've written rather than the complexity of your call chain? – Tommy Jan 2 at 22:30
  • @Tommy: "Static allocation" may involve overlapping the activation records of functions that can not be executing at the same time, given the call graph. – Henning Makholm Jan 3 at 0:30
9

Moste likely your friend was referring to modern time developments, not contemporary games. While today CC65 does deliver acceptable results for every day jobs, the 6502 isn't exactly C-friendly. C does require a certain memory handling - and quite some RAM as well. To program the 2600 with its bare bone 128 Bytes of RAM is already a tough job in Assembly and much less feasible in C.

If at all, I can only see some usage in the area of demo-programming, where next to no RAM data is needed, as such code is not driven by variable and interactive data, but runs straight and unmodified ahead.

So go ahead and call out your friend to give you evidence for his assumption - and what it was exactly about.


BTW: Stella is the code name for the whole 2600 system. The (only) custom chip was called TIA and did not only sound but display as well - under direct CPU control that is.

  • 1
    Wouldn't the 6507 be considered a custom chip? I don't think it was mass produced for anyone other than Atari. But I could be wrong on this. Even though it was a stripped down 6502, I would call that custom. The RIOT, for example, could be considered a common "off the shelf" part as it was made for the purpose of multiple systems. – cbmeeks Jan 2 at 20:21
  • 2
    The 6507 was a standard of the shelf chip. The 6503..07 are 28 pin variations of the 6502 with reduced address pins (A0..11) plus depending on the version a combination of two signals out of A12, RDY, IRQ, NMI, Phi1-Out. The 6507 it an A12+RDY version. While it is true that the very first family manual only listed 6503..05, 06 and 07 where added soon. They where also not only supplied by MOS, but as well standard products of Rockwell and others as a standard product, "off the shelf". It's further true that use in other systems was limited due the missing interrupt capability. – Raffzahn Jan 2 at 20:41
  • IIRC the 6507 was as well used in the Atari 810 Floppy drive, as well as the serial interface. But I may need to check. – Raffzahn Jan 2 at 20:42
  • hmm, @cbmeeks, thinking of it, you might be onto something here. It could well have been that the 6507 was defined as a result to Atari's requirements for the VCS. The console was extreme price sensitive, and a 28 pin CPU does save on all accounts: Lower CPU cost due smaller packageing, as well as on the PCB due less drilling. It is known that there where intense meetings about cost lowerign between Atari and MOS, so it could well be that they added he 6507 especially for Atari. Still, after that it was available to everyone else as standard component. – Raffzahn Jan 2 at 21:17
  • Well, @Raffzahn, a more interesting conversation would be how would Atari have been different if they sprang for a couple more address pins? Imagine easy 16K games with no additional glue logic. Sure, would have been too expensive in the 70's but by mid-80's, a simple inverter and two 16K chips would have made for interesting games for not that much money. – cbmeeks Jan 3 at 16:11
6

Only people who worked for Atari or third-party game developers could say for sure.

For early development, the history of the 2600 and C don't align very well. Atari began design for the first prototypes of the 2600 began in late 1975, shortly after the 6502 was introduced. C made its first appearance anywhere in 1972 and Kernighan and Ritchie wouldn't publish The C Programming Language until 1978, the year after the 2600 was introduced. Compilers in those days were almost always written to be run on their target platforms, and cross-compilation was a rarity if it existed at all. The first known C compiler that isolated code generation enough to make porting it to other platforms was PCC, which didn't make it out of Bell Labs until 1979 as part of Unix V7.

Later development in C would have been a very remote possibility. In 1983, Manx released Aztec C65, a compiler for the Apple II which produced object code that could, in theory be run on the 2600. Manx warns about the trade-offs of trying to run C on a 6502 in its mini-manual (see section 1.6). It's difficult to imagine that compiled C would be a good choice on a target with such limited memory and no frame buffer. The latter required that video be generated in real time by the processor, leaving fewer cycles available for game play and a hard, 33-millisecond deadline to start generating the next frame of video. If you ever saw black bars at the edges of the screen on a 2600, that was a symptom of the deadline being missed.

Recommended reading: Racing the Beam by Montfort and Bogost.

  • Thanks for the tip, the book was great. – Aaron Brick Jan 18 at 18:53
5

C didn't have anywhere near the popularity and ubiquity that it does today. As has been mentioned elsewhere, the 6502 is a crummy target for a C compiler, notably with it's sparse, 8 bit register set.

Recall the sparse architecture of the machine: 128 bytes of RAM and 4K of ROM. A 4K assembly language program, with several 8-bit, and a few 16-bit counters or pointers, is not an arduous amount of code for an assembly language programmer. (Yes, there were banked cartridges later, but most of it was for data rather than actual code.)

One of the key values of a language like C is also portability, something that was simply not a concern here.

Finally, games on systems like the Atari were notorious for their optimizations, and other shenanigans and contortions the developers went through to get their titles crammed in to these creaky, slow boxes. Leveraging the underlying CPU to their full potential required 100% access to it, something that C did not offer. C does not offer access to things like the status registers of the CPU. The coders needed exact cycle timings for certain tasks. Direct access to timers and interrupt handlers, some which may change from scene to scene or even frame to frame. The assembly language developer can write code that "knew" exactly what state it was in at all times, and was coded appropriately.

Any high level value that C could have offered was lost not just in lack of access to the CPU, but also just in terms of longer turn arounds and development cycles. C is expensive to compile compared to assembly, and back then, yes, this mattered. A good macro assembler readily takes the sting of using assembly by letting the developer add in higher level constructs (working with structures, working with collections, looping, branching, etc.) or even small DSLs written in macros.

So, in the end, the cost of C wouldn't have brought enough value to the table for a professional game developer on such limited systems back then.

  • C is compiled by a compiler. Assembly languages are not compiled, they are assembled by an assembler. The difference is that assembly mnemonics map one-to-one with binary opcodes, whereas a compiler has much more work to do than just substituting opcodes for mnemonics. – LawrenceC Jan 18 at 19:33
  • Even without "a good macro assembler", a program that's a few thousand instructions long isn't too bad for working on manually at the CPU instruction level. You can easily get to that point with just a thousand or so lines of reasonably sparse (as opposed to compact) C. The hard part is likely going to be cramming whatever actual logic you need into the available memory anyway, whether one uses C or assembler. – a CVn Jan 22 at 10:06

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.