2010. január 23.

Cross platform development for C=64 - Part I

Lately I felt I need to develop something new to my old favorite for the Commodore 64. I decided that I will set up a cross development platform to be able to use my favorite modern tools.

I started with searching the internet for goods. I realized with pleasure that a lot of information can be found related this old computer but I was looking for specific things at first, namely a good emulator, a cross compiler for assembly language, and tools.

I was programming in assembly for C=64 back in time when I had enough of the slow BASIC on it, so I assumed I will have my development up and running in no time. I also got used to the (almost) perfect development tools I use now days, like Visual Studio, and also got used to the elegant object oriented languages like C#, Delphi, and source controls like Team Foundation Server or SVN.

First I need an emulator: I decided to use WinVICE 2.1 which is free, has built in machine code monitor, and good command line argument capabilities. It accurately emulates C=64, is fast, and friendly to developers (f.e.: it knows a lot of disk/tape/prg formats, lurking around in the C=64 emulation community).

I have also found a great compiler with even greater macro capabilities which was written in Java, and is a command line tool. I decided to use Kick Assembler 3.0 further on. For editing one can use any kind of editor, capable to save to ASCII/Win western code page. (yep, UTF-8 is not supported). Windows has a “great” built-in editor, named Notepad.

Setting up the development environment

Since everything can be accessed from command line the idea to use BAT files was quite straightforward. I created a BAT to actually build my application, “build.bat”:
@echo off
call settings.bat
echo ===================================
echo Build started for "%project%"...
echo -----------------------------------
echo.>"%target%.debug"
call compile.bat %project% %target%
echo break .%entryPoint%>>"%target%.debug"
echo.
echo Finished @
time /T
echo ===================================
Having the “setup.bat” SET the used cmd variables, like “target”, “entryPoint”, and so on… The “compile.bat” is even more simple:
@echo off
echo Compiling "%1.asm"....
echo -----------------------------------
"%kickass%" "%1.asm" -vicesymbols -o "%2.prg"
echo load_labels "%1.vs">>"%target%.debug"
echo ===================================
Note that the “kickass” cmd parameter is the path to the compiler, and the –vicesymbols parameter of it: machine code monitor in VICE can load a symbol file, which makes the reading of the code much easier! Also note the echo line with “load_labels” in it, which appends to the file with extension “.debug”. This file contains VICE MCM commands. Also note, that the build batch file appends the same debug file with a break . VICE command.

If build succeeds, you will have your “.prg” file, which is directly loadable into VICE from command line. Let’s see the “debug.bat”:
@echo off
call settings.bat
"%vice%" -autostart %target%.prg +confirmexit -moncommands %target%.debug
Isn’t it simple? It directs the emulator, to auto start our compiled prg file, and load and execute the commands in the debug file with the MCM (which in fact contains a break command with the program’s start address, so you are set up to debug your code from start!).

In part II I will show you how one can use Visual Studio without modifications, to build and run your program in emulator.

In part III you will learn how to add Kick Assembler color coding to Visual Studio.