Originally published on: Sun, 30 Aug 2009 14:08:10 +0000
I now realize it was 25 years ago that I bought my first Commodore 64. Programming it was an obsession. Unfortunately, there were few tolerable compilers for high-level languages back in the day. I had a couple of Pascal compilers and one C compiler, but they were all bound by the C64/1541 serial disk I/O. For the most part, my programming consisted primarily of BASIC and assembly-language ( or ML as it was referred to in the popular magazines of the day. )
In about 1986, I began to attempt to learn C. I had bought one of the Abacus C compilers, but it was just not too friendly. I was mainly learning the C programming language via the venerable K&R book and by poring over code in magazines like Byte and Dr. Dobbs Journal.
My drive to learn C ultimately led me to newer platforms of the day ( an Amiga and an MS-DOS machine. ) That time-frame marked the beginning of the end of my obsession with C64 coding.
Several years ago, I'd heard about the the CC65 C cross-compiler ( see http://www.cc65.org ) : a small C compiler that outputs 6502-family code.
I've seen some posts by people who have done some impressive things with the cross-compiler specifically for the Commodore 64, so I decided to exercise my C knowledge and see how much of my old C64 programming skills have atrophied.
My first CC65 program ( hopefully of many ) is a simple program that will iterate over the 1000 bytes of VIC-II color memory and will increment the values by 1. This 1000-byte change will occur 16 times.
Let's take a look at the code and then a tiny screenshot of what one should see when the code is executed.
colorchange.c
I compiled this program under a Windows command-prompt using the following command-line: cl65 -O -t c64 colorchange.c
The resulting output file colorchange was left in the same directory.
Then, I used VICE to bring up a C64 emulator where I entered the commands:
load "colorchange",8
run
The effect should look like that depicted in the following tiny picture:

Let's take a deeper look at some of code.
char *colors;
colors=(char *)0xd800;
So, colors then points to $d800 ... the default VIC-II color memory location. for(i=0;i<1000;i++) { colors[i]=colors[i]+1; } The above inner-loop iterates 1000 times. The interior line colors[i]=colors[i]+1 first resolves the colors[i] reference on the right side of the equals sign ... effectively PEEKing at the byte at $d800+i. The program then adds one to that value and effectively POKE's it back into the same spot.
So, the loop reads the current color byte, increments it by one, then stores it in the same spot and moves on to the next byte of color memory.
The source and C64 executable files for colorchange can be found here.
http://www.mailsend-online.com/wp/colorchange.zip
Unless otherwise noted, all code and text entries are Copyright ©2009 by James K. Lawless
Views expressed in this blog are those of the author and do not necessary reflect those of the author's employer. Views expressed in the comments are those of the responding individual.

Save to StumbleUpon
Digg it
Save to Reddit
Share on Facebook
Share on Twitter
More bookmarks
| Previous post: | A Simple Media Control Interface Script Processor |
|---|---|
| Next post: | A Scrolling Banner using Canvas and JavaScript |
Click **here**
A JavaScript REPL for Android Devices
A Review of Kevin Mitnick's Book Ghost in the Wires
Play MP3 Files with Python on Windows
Book Review : Using Google App Engine
An Interview with Game Developer James Hague
Understanding TRS-80 CMD Files
Hiding Batch File Console Windows
Stacking Images with PerlMagick
Why Some Web Sites will go Dark on Jan 18th
Book Review : Paull Allen - Idea Man
A 90's Experiment in Online Systems - The U.S. West CommunityLink Service