I have quite a bit of computer graphics experience, but most of it is in 3D using APIs like OpenGL. Programming graphics on the Commodore 64 is a completely different experience. The only API is the specifications of the graphics hardware, and timing is of the utmost importance. There are a few techniques I’d like to try out, but you can’t jump into something like this without doing your homework.
The graphics hardware on the C64 is really one chip – the MOS 6567, known as the VIC-II. Designing color video hardware in the early eighties was a tough job because of the timing and bandwidth constraints, and the VIC-II followed the creation of the VIC (of Commodore Vic 20 fame) and several failed graphics projects.
Those constraints also explain why the VIC-II’s graphics formats are so unusual to a modern eye. These days, we’re almost always using bitmapped displays – the screen is described as an array of pixels, and each pixel is defined by 2-4 bytes of color information. While you can do a bitmapped display on the C64 – albeit with an unusual memory layout – there are usually better options.
The graphics modes that are mostly used in C64 programs and games are character-based. The C64 can display 40 rows and 25 columns of text. Rather than storing a bitmap of the screen itself, the C64 stores an array detailing what character to display at each location. Using this technique, you can describe the entire screen using only 1000 bytes of data. A bitmapped display would take at least 8 times that much.
This may not seem immediately useful – how can you make an action game out of a screen full of text? Well, the VIC-II was kind of designed around answering that question, and it has several features that make it all possible:
- Hardware support for smooth scrolling in any direction.
- User-defined character sets, so that you can replace the alphabet with graphical tiles.
- Multi-color modes that allow each tile to contain up to 4 colors.
- Sprites, which are can appear on top of the character-mode graphics and move independently.
Of course, game developers and demo programmers found ways to make the C64 display even more complex graphics, but that’s another story for another day.
Let me close by mentioning one last feature of the VIC-II. While it only takes 1000 characters to describe the character data on a screen, there’s also the question of color. In the simplest case, the C64 has one background color for the entire screen, and an individual foreground color for each character. Those foreground colors – 1000 numbers, each 4 bits in size – are stored in a separate color memory attached to the VIC-II, which will require some special handling later on.
In part 2, I’m going to start on a smooth scrolling routine for the C64, which will highlight why these character-based graphics modes are necessary – and why programming C64 games can be so challenging.