Sunday, April 03, 2011

C64: How to get BASIC programs into Vice/x64

One issue one will encounter when trying to develop C64 applications is the problem of getting BASIC programs into Vice. Vice support direct loading of PRG files, which are in essence BASIC programs, but those are the tokenized in-memory representation of BASIC files, not raw ASCII text files. On Windows there is an easy workaround, one can just copy&paste the BASIC source into the Vice interpreter, on Linux there doesn't seem to be a way to copy&paste text between Vice and the regular Linux userland.

The solution however is easy, "petcat" which comes with Vice is a BASIC tokenizer that will convert a ASCII text BASIC file into a PRG that can be read by the emulator. So to create a first simple BASIC program one uses a file with the content of:

10 print "hello world"
20 goto 10

And then the command:

$ petcat -w2 -o outfile.prg infile.bas

The "-w2" switch marks the program as V2 BASIC, the default that comes with the C64. Once the PRG is generated one can start it with:

$ x64 outfile.prg

It can also be saved with the usual:


inside Vice when an empty disk image (can be created from within the emulator) is attached.

A little warning: Upper/lowercase do matter a lot here, all the BASIC commands have to be written in lowercase, if they are written in uppercase they will be confused for other commands, this is due to the C64 BASIC's uses some uppercase characters (which are not really upper case characters, special symbols in PETSCII) as shorthand for the full text commands.

PS: For full disk image creation from Linux there is the program "c1541", again part of Vice.

No comments: