petcat is a utility provided with the VICE Commodore emulator that you can use to convert Basic source code contained in ASCII text files to .PRG files or vice versa. It is also able to convert ASCII text files to and from PETSCII .SEQ files. This makes it a great utility for cross-development purposes.
Convert Basic Source Code in an ASCII Text File to a .PRG File
If the input file is Basic source code stored as an ASCII file then petcat will tokenize this to create a .PRG file as its output. Blank lines will be ignored, but the Basic keywords should be in lowercase because of they way that Commodore Basic stores them. If, for example, you used lI
in your Basic source code it would be converted to list
.
In the following example we specify tokenizing with Basic v7.0 using the -w70
switch and the output file with -o program.prg
. The --
switch tells petcat to stop processing command line switches and the file to convert is program.bas
at the end.
$ petcat -w70 -o program.prg -- program.bas
Convert a .PRG File to an ASCII Text File
If the input file is a .PRG file then petcat will de-tokenize this to create an ASCII text file as its output.
In the following example we specify de-tokenizing Basic v2.0 using the -2
switch and the output file with -o program.bas
. The --
switch tells petcat to stop processing command line switches and the file to convert is program.prg
at the end.
$ petcat -2 -o program.bas -- program.prg
Basic Versions
petcat supports many different flavours of Basic that came as standard with 8-bit Commodore computers as well many extended and alternative Basics. Further options are listed in the VICE manual. Below are the options used to specify the standard flavours of Basic. These are used after the -w
switch if you want to tokenize and without if you want to de-tokenize.
Option | Version | Computers |
---|---|---|
1p | Basic v1.0 | PET |
2 | Basic v2.0 | C64/VIC20/PET |
3 | Basic v3.5 | C16/C116/Plus/4 |
40 | Basic v4.0 | PET/CBM2 |
70 | Basic v7.0 | C128 |
Unprintable / Special Characters
Commodore Basic programs can contain characters that aren't printable in ASCII, so petcat uses a set of mnemonics to encode these. Below are some of the most commonly used.
Mnemonic | Explanation |
---|---|
{blk} | Colour: black |
{wht} | Colour: white |
{red} | Colour: red |
{cyn} | Colour: cyan |
{pur} | Colour: purple |
{grn} | Colour: green |
{blu} | Colour: blue |
{yel} | Colour: yellow |
{orng} | Colour: orange |
{brn} | Colour: brown |
{lred} | Colour: light red |
{lgrn} | Colour: light green |
{lblu} | Colour: light blue |
{gry1} | Colour: grey1 |
{gry2} | Colour: grey2 |
{gry3} | Colour: grey3 |
{rvon} | Control: reverse on |
{rvof} | Control: reverse off |
{clr} | Control: clear screen |
{home} | Control: home |
{inst} | Control: insert |
{del} | Control: delete |
{up} | Cursor: up |
{down} | Cursor: down |
{left} | Cursor: left |
{rght} | Cursor: right |
Example Using the Mnemonics
The following example clears the screen using the {clr}
mnemonic and then prints a line of black text using {blk}
followed by a line of red text using {red}
, finally it finishes the program by changing the text colour to blue using {blu}
.
10 print "{clr}"
20 print "{blk}this text is black"
30 print "{red}this text is red"
40 print "{blu}"
Autostarting a .PRG in VICE
VICE allows you to autostart a .PRG file by putting it on the command-line. You may need to use the -basicload
switch (depending on how AutostartBasicLoad
is set in your config) to load it using ,8
instead of ,8,1
. The following will autostart the basic program, program.prg
, using VICE's VIC-20 emulator.
$ xvic -basicload program.prg &
Video Demonstrating petcat
You can see petcat being used in the following video: