C64 Bitmap mode…or not?

I’ve been experimenting a little bit with the bitmap modes on the C64. As mentioned previously there are a choice of high resolution (320×200) or multi-color (160×200) bitmap modes on the C64. There are various pros and cons with these two bitmap modes as well as with using the other character based modes the C64 offers.

Bitmap mode – 2 colours per 8×8 pixel cell

Standard or high resolution bitmap mode shown above has the advantage of giving you the full 8×8 pixels per character cell on the screen but you are limited to only a single foreground and background colour in each 8×8 cell. A full screen uses 8K of memory plus 1K for the colour information.

Multi-color bitmap mode – 4 colours per 8×8 character cell

Multi-color bitmap mode has the advantage of allowing you to have up to 4 colours per 8×8 character cell (one of which is a shared background colour) but has the disadvantage of reducing the horizontal resolution in half, displaying double width pixels. It also uses 9K of memory in total but needs an extra 1K for the additional colour information.

Memory usage for both these modes could likely be reduced by 1-2K by using a split screen mode with a text display at the bottom – think Ultima 2 or any of the many graphic adventure games of the 1980s. Many C64 games used a split screen like this to mix modes on a single screen, saving memory and improving display speed.

My initial tests with these bitmap modes are proving quite slow to display compared to my earlier character based version. This is hardly surprising as drawing a single 16×16 pixel tile on the screen will now involve writing at least 40 bytes to the display (characters and colour information) as opposed to just 8 bytes. I’ll give it some further thought and do some more drawing in the various modes before deciding to see if I feel the additional flexibility is worth the increased memory usage and reduction in speed.

C64 RPG Display Choices

An example of mixing multi-color and high-res characters on a single screen

Since my last post I’ve been experimenting with using the Commodore 64’s multi-color character mode. This mode allows you to display 4 different colours in each 8×8 pixel character cell but with the loss of horizontal resolution. Each “pixel” in multi-color mode is effectively made up of 2 horizontal pixels – this sometimes leads to the slightly “chunky” look of some C64 graphics in games. 1 colour is the background, 2 colours are set universally for each character using registers and the other comes from the C64’s screen colour RAM (one colour per character cell on screen).

A C64 multi-color character – Note the 4×8 “pixels” rather than 8×8

It’s possible to use a mixture of multi-color mode characters with standard high-res characters on a single screen. This is done by setting bit 3 of each character cell’s color memory – the value of this bit determines whether a character on the screen is in standard high-res mode or multi-color mode. The downside of this is that you have a more limited selection of colours. Colour values of 0-7 in the colour RAM will display a high res character, 8-15 a multi-color mode character. This means you can’t use colours 8-15 in your display other than as one of the 3 universal colours – so no light red, shades of gray, light green etc (colours on the right hand side below).

The C64’s 16 colour palette (taken from Pixcen)

I’ve done a bit of experimentation with Pixcen and produced a few sample multi-color tiles but it took me a while to understand how the colour limitations work and I find the loss of horizontal resolution hard to work with, and I have little artistic skill to start with! I also need to work out what my graphics development process is. Pixcen seems to be a good enough utility but I think there may be other tools which might suit me better. Some form of C64 graphic, tile and map editor might be required.

So I have a real balancing act to consider, deciding on whether to use multi-color mode (losing resolution and colour choice) or just stick to using high-res characters but having the limitation of a single colour per cell. I’m aware that I could use one of the C64’s bitmap modes which provides the programmer with control of individual on-screen pixels with greater colour flexibility but from what I’ve read that will use a lot of memory (8K just for the bitmap data) and would potentially be slower than using characters. Let me know your thoughts.

New Developments

Here’s the latest image from my Commodore 64 RPG. I’ve added some additional tiles (from Ultima IV) as placeholders and to give me something to work with whilst coding game functionality.

The Ultima IV tiles and C64 character set are temporary.

Additional placeholder tiles and a basic screen layout

I now need to add some additional maps to the game with working entrances and exits, initially just a town and a dungeon. I need to give some serious thought to map sizes and how I want to manage the wilderness map. Games such as Ultima IV and V would load sections of their wilderness map into memory as required but I’m not sure my map needs to be as large. I’d also like to add some basic combat with those red monsters on the wilderness map and some basic interaction with some example town NPCs.

I’m urgently feeling the need for some map editing tools. Whilst I could create some windows tools for these I’m considering making the tools run on the C64 as there will be a number of similar coding routines. There’s no shortage of things to keep me busy with this project and so far I’ve not run into any serious problems – memory and floppy disk space do concern me though…

Programming in C on the Commodore 64

Since my last post I’ve revisited the CC65 cross compiler which you can use to write C programs on 6502 based systems such as the Commodore 64, Apple II and Atari 8bit.

I had been using CC65 for a few months, sketching out the beginnings of a C64 CRPG but had run into problems managing the memory configuration required for custom graphics. I’d moved onto using CBM PRG Studio and programming in 6502 assembly code which meant my code ran very quick but I was finding was slowing down my development time compared to using C in the past.

Some simple C code for the Commodore 64

Now I’m not much of a programmer in any sense of the word but I probably have the most experience of using the C language overall so I was finding 6502 assembly language time consuming to use and my game development time is very limited and I’m not really trying to do anything fancy technically by the standards of C64 games.

There is a lot of documentation online for CC65 but I was lacking an example of how to do a simple custom character set and use code overlays for swapping code in and out of the C64’s 64K of memory from disk. Most of the famous CRPGs I grew up with such as Ultima and Alternate Reality use this method to make the most of the machine’s limited memory by modern standards. I just couldn’t get this to work and gave up frustrated.

I noticed this week that CC65 had been used to create some of the code in Ultima IV Remastered for the C64. After this I came across a CC65 example online that included both a custom character set and code overlays and worked out how to compile it with a custom linker file. This determines how the memory map for the program is set up and where any external data files or graphic data should go. Once I had this working it was relatively easy to load in my modified character set and recreate my map code in C, display it on the screen and have a player marker move around the example map. I also was able to automate my compilation process with a single key press from within Notepad++ and run the resulting program in the Vice emulator which felt pretty smooth.

A simple map with a (feeble) character graphic player to move around

The main reason I was originally attracted to CC65 was that I love the idea of using C and being able to then reuse the code on other 6502 based platforms as well as modern PCs and operating systems. CC65 also has special support for some systems including the C64 so that you reference the C64 hardware directly within your C code. As CC65 includes a full assembler in its tool chain, you still have the option of using assembly language within your C program where extra performance is needed and tweaking the generated code. I’ll post more about CC65 in a future post; where to get it and provide a brief example and possibly a video of how to do the things I was struggling with in the hope they help others get started.