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.

Making a CRPG on the Commodore 64

I’m starting to put together my notes for a new project – part original game, part game programming video / blog tutorial. I’ve been planning this for the last couple of years and it will be an enjoyable change of pace from Alternate Reality X development.

 

 

As you may know I grew up playing CRPGs on the Commodore 64 so have many fond memories of those days spent exploring the lands of Britannia in Ultima IV, skulking round the streets of The Bards Tale and of course finding unique new treasures in the depths of Alternate Reality: The Dungeon.

I recently had a lot of fun doing a bit of BASIC programming using a Windows based program called CBM PRG Studio – this provides an IDE for rapid C64 development in both BASIC and assembly language as well as offering integrated tools for graphic and music creation.  Used in conjunction with the Vice emulator it’s a pleasant way to program for this classic machine. I’m also planning to dip into other tools such as native assemblers and possibly even some cross assemblers and cross compilers.

Of course you won’t need a Commodore 64 to follow the series or play the various versions of the game. Depending on how the game comes along I’m not ruling out a version which will run on current operating systems as well. The intention is to start small explaining the basics of the machine and its display, use of the built in character set and PETSCII characters before moving onto user defined characters and multi character tiles more akin to Ultima and other classic CRPGs from the era.

In case you haven’t heard about it there was a recent successful Kickstarter called “Unknown Realm” which is for the C64 and PC and looks good. In case you’re wondering I was planning some C64 CRPG development when I bought my Programmers Reference Guide a couple of years back 🙂 You can read more “Unknown Realm” below:

https://www.kickstarter.com/projects/stirringdragongames/unknown-realm-an-8bit-rpg-for-pc-and-commodore-64

Don’t worry about my new project slowing down ARX development. I’m planning small incremental changes as to how the series and game develop which I don’t anticipate will be particularly time consuming compared to a typical ARX release. I hope you’ll enjoy it.