Hidden gems that come with the emulator VICE

If you’ve played a game by emulating a Commodore 64 on a modern personal computer, there’s a good chance that you were using the program called VICE (the Versatile Commodore Emulator).

An average user only ever had to zero in on the x64 binary executable to run it. What are often overlooked and can be very useful to power users are 3 other utilities that come with the emulator:

  • c1541
  • cartconv
  • petcat

The 2 I will explain are c1541 and petcat. Perhaps, I’ll explain cartonv, some other time. All 3 are command line utilities which allow one to do some pretty nifty things related to the C64.

Setup

This article assumes that the reader:

  1. Has some working knowledge of the Commodore 64 and BASIC.
  2. Has downloaded, extracted or installed, and has ran the VICE emulator.
  3. Has basic knowledge of invoking a command line terminal or shell.
  4. Knows how to issue commands and run programs by specifying their name / path while issuing additional command parameters.

It’s a good idea to ensure the directory where x64c1541, and petcat are located are in the system path (so the commands can be issued without specifying their path).

petcat

This utility has a misleading name. I believe it refers to it’s likely origin of PET BASIC (like the Commodore PET computer) and the term ‘concatenate’ (which is probably because of its usage of the standard output file stream).

Regardless, this utility allows one to create Commodore BASIC programs by coding in text files on a ‘modern’ computer and convert them to the native PRG format (to run on a C64).

So, to start off, create a text file called helloworld.bas and fill it with the following BASIC code:

10 print "HELLO WORLD"
20 goto 10

Save this file and issue the following command:

petcat -w2 -o helloworld.prg helloworld.bas

This command will take the helloworld.bas text file and output it to helloworld.prg, recognizing and encoding it in BASIC v2.0. It is important to specify the input file last, after all the other parameters.

NOTE: To learn about other options for this utility, issue the command with –h.

From this point, it is possible to load the hello_world.prg program from within VICE. However, I noticed that, for some reason (please tell me if you know) BASIC programs cannot be invoked with the following command:

x64 hello_world.prg

It is also possible to do the reverse:  convert PRG files to text. Issue the following command:

petcat -o hello_world.bas hello_world.prg

The resulting helloworld.bas will have the text equivalent of helloworld.prg. I noticed it prepends all lines with spaces, which is a little odd. But that’s nothing a little awk and sed or a nice text editor can’t fix in half a second. The plus side to the extra spaces is that it will text align code line numbers nicely.

c1541

Having separate PRG files is kind of nice. However, sometimes it would be nice to package up 1 or more PRG files into a single disk image file (D64). Also, the PRG files which require processing from petcat are likely contained on a disk image file; so, extracting the PRG files from the disk is necessary.

c1541 does just that!

Assuming you have the helloworld.prg file from the petcat example, issue the following command:

c1541 -format diskname,”88 2a” d64 diskname.d64 -write helloworld.prg helloworld

This command will create and format a new disk with the name diskname. The equivalent disk image file will be called diskname.d64. Also, the write parameter adds the helloworld.prg file to the disk and gives it the file name helloworld.

To verify the contents of the new file, issue the command:

c1541 diskname.d64 -list

It should produce the following readout:

0 “diskname ” 88 2a
1 “helloworld” prg
663 blocks free.

It’s actually not necessary to specify any write files when formatting a disk. You can continue to issue commands like:

c1541 -attach diskname.d64 -write helloworld.prg helloworld-backup

It’s possible to extracting single files by name from a disk image, like so:

c1541 -attach diskname.d64 8 -read helloworld helloworld.prg

helloworld.prg is an arbitrary name–it could be anything. Lastly, if you want to quickly extract all the files from a disk, issue the following command:

c1541 -attach diskname.d64 -extract

The resulting files will be named exactly as they are on disk (meaning: no extensions).There are a slew of other things you can do with c1541. I’ll leave it up to the reader to discover them, for now.

Conclusion

These 2 utilities are pretty powerful, especially if they are combined with some crafty shell scripting.

c1541 could be used to automatically extract a collection of files (like BASIC programs) to the local file system, in addition to a lot of other neat packaging for any C64 projects one might have.

petcat could be used to take all those BASIC programs and put them in a format that is easily shared (uploaded or pasted to a website). If you are working on a large project which uses BASIC, it could be leveraged in conjunction with version management like cvssvngit, and so on.

I hope you enjoyed this article. Let me know if you have any questions or comments.

Leave a Reply

Your email address will not be published. Required fields are marked *

*