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
Save to del.icio.us
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 |
Subscribe!
Auto Save Clipboard Images Redux
Extending SpiderMonkey JavaScript on Windows
Rhino JavaScript to EXE with launch4j
Compiling Rhino JavaScript to Java
Directory Traversal in Rhino JavaScript
A Command-Line MP3 Player for Windows
Auto Save Images from the Clipboard
Java in a Windows EXE with launch4j
An Interview with Tom Zimmer: Forth System Developer
Setting Windows Console Text Colors in C
Tracing XSLT with a Tiny Java Web Server
Yet Another Enhanced Echo Command
A Lightweight Alternative to Windows Shortcuts
An SMTP Server Simulator in Perl
Hiding Batch File Console Windows
Learning Z-80 Assembly Language on the TRS-80
MicroISV on a Shoestring
DadHacker
The Bottom Feeder
Writin' That Code!
The Recursive ISV
The Thomsen Blog
Prototypically Speaking
The Reinvigorated Programmer