Posts tagged cc65

VCSLib, A C Library for the Atari 2600

The previous blog post, “Your 8-bit System is a Weird PDP-11”, discussed several challenges faced when developing in C, especially for the Atari 2600/VCS.

We’ve overcome those challenges as best we can, and now we can introduce VCSLib, a support library for programming the Atari 2600/VCS with CC65.

Let’s take a tour.

Read more ...


Your 8-bit System is a Weird PDP-11

The C programming language is the de facto portable, low-level language. It was written with the PDP-11 minicomputer in mind.

The PDP-11 informed the x86 instruction set, and so in a way, we’re still using them. Today’s computers are so complex that they have to bend over backwards to emulate the simple architecture for which C was designed. It leads some to ask if C is a good fit for modern systems.

Likewise, the PDP-11 doesn’t have a lot in common with 80s arcade games. Game programmers in the 8-bit era wrote code predominantly in assembly language. The C language was around, but mostly in UNIX systems. If anything, they would have been more likely to use a homespun language like Zgrass or even FORTH.

../../_images/pdp11.jpg

Read more ...


Exploring the New 6502 Compiler Based on LLVM

Today, homebrew developers enjoy the convenience of programming the 6502 in C. However, the 6502 is a very different architecture than modern CPUs, and was never designed for C programming.

The 6502 has a small number of 8-bit registers, and limited addressing modes that cannot access the stack efficiently. This makes it difficult to retarget a modern C compiler to the 6502.

In a previous blog post, we explored the process of retargeting a microcontroller C compiler (SDCC) to the 6502. This required development of a brand new code generation backend, which required looking at over 80,000 lines of code. Gabriele Gorla has since improved it to the point where it has been merged into the main SDCC repository.

Read more ...


Retargeting a C Compiler to 6502

I’ve written before about cc65 and some of its optimization challenges. It’s a stable compiler with a robust toolchain, but its code generator doesn’t full advantage of the 6502 when performing 8-bit operations. It places function parameters and many local variables on a separate stack, which requires many calls to helper functions.

I’ve done a survey of 6502 high-level languages, and while many are intriguing, none have the stability and C compatiblity of cc65.

So what’s so hard about the 6502? What’s keeping us from just retargeting a modern C compiler, bringing its powerful optimization routines to 6502? Well, it’s complicated. Like, really complicated.

Read more ...


Optimizing C array lookups for the 6502

Most of the platforms in the IDE that are powerful enough to support a C compiler are Z80-based. The Z80 isn’t the easiest target for C, but at least it has a lot of registers.

While the 6502 only has three 8-bit registers, the 6502 has strengths the Z80 doesn’t, as we’ll see here.

Let’s compare the two dominant C compilers for these CPUs. We’ll compile a function with the CC65 C compiler for the 6502, and then with the SDCC (Small Device C Compiler) for the Z80. We’ll call the function getValue():

Read more ...