Using petcat for cross-developing BASIC programs
The VICE emulator for Commodore computers includes a command-line tool called petcat that can convert between ASCII text files and Commodore BASIC PRG files. It is useful for writing BASIC programs on a modern computer in a text editor, among other things. While VICE does not yet include a MEGA65 emulator, the petcat tool does support creating and reading MEGA65 BASIC programs.
For example, you can write this temperature conversion program in an ASCII text file, like so:
100 print "enter a temperature in degrees fahrenheit:"
110 input f
120 c=(f-32)*5/9
130 print
140 print f;" degrees fahrenheit is ";c;" degrees celsius."
To convert this to a MEGA65 PRG file, use this command:
petcat -w65 -o tempconv.prg -- tempconv.bas
To convert a BASIC PRG back to text:
petcat -65 -o myprog.bas -- myprog.prg
petcat syntax
petcat text files are ASCII text. To fully represent all of the Commodore PETSCII characters that can appear in a BASIC program, including “quoted” control codes in strings, petcat uses a text-based syntax.
Letters, numbers, and punctuation common to both PETSCII and ASCII appear as ASCII. Letters are lowercase.
PETSCII | petcat | Notes |
---|---|---|
|
|
|
|
|
|
|
|
|
Several PETSCII-specific punctuation characters have similar codes as ASCII characters. These appear in petcat listings as their ASCII equivalents.
PETSCII | petcat | Notes |
---|---|---|
|
| See exceptions below for Shift and Mega variants. |
Left arrow |
|
|
Up arrow |
|
|
|
|
|
Graphics characters formed by pressing Shift and a letter are represented by uppercase letters.
PETSCII | petcat | Notes |
---|---|---|
Spade |
| Shift + A |
Heart |
| Shift + S |
Diamond |
| Shift + Z |
Club |
| Shift + X |
All other PETSCII codes use a label syntax in petcat, surrounded by curly brackets: {...}
Shifted non-letter characters are labels with the prefix SHIFT-
. A shifted pound spells out POUND
.
PETSCII | petcat | Notes |
---|---|---|
Thick cross |
| Shift + |
Mid-bar |
| Shift + |
Upper-left triangle |
| Shift + |
All characters accessed by pressing Mega and a character key are labels with the prefix CBM-
.
PETSCII | petcat | Notes |
---|---|---|
Upper-left corner |
| Mega + A |
Upper-right corner |
| Mega + S |
Half-checkerboard |
| Mega + |
The sixteen color control codes have labels similar to their keycap spellings.
PETSCII | petcat | Notes |
---|---|---|
Black |
| Color 0; Ctrl + 1 |
White |
| Color 1; Ctrl + 2 |
Red |
| Color 2; Ctrl + 3 |
Cyan |
| Color 3; Ctrl + 4 |
Purple |
| Color 4; Ctrl + 5 |
Green |
| Color 5; Ctrl + 6 |
Blue |
| Color 6; Ctrl + 7 |
Yellow |
| Color 7; Ctrl + 8 |
Orange |
| Color 8; Mega + 1 |
Brown |
| Color 9; Mega + 2 |
Light red |
| Color 10; Mega + 3 |
Grey 1 |
| Color 11; Mega + 4 |
Grey 2 |
| Color 12; Mega + 5 |
Light green |
| Color 13; Mega + 6 |
Light blue |
| Color 14; Mega + 7 |
Grey 3 |
| Color 15; Mega + 8 |
Other control codes also have named labels. If a control code does not have a named label and can be typed with Ctrl plus a key, it is represented with a label with a CTRL-
prefix.
PETSCII | petcat | Notes |
---|---|---|
Underline on |
|
|
Stop |
|
|
Bell |
|
|
Tab |
|
|
Linefeed |
|
|
Shift enable |
|
|
Shift disable |
|
|
Switch to lowercase |
| Wikipedia’s PETSCII table calls this “text mode.” |
Switch to uppercase |
| Wikipedia’s PETSCII table calls this “graphics.” |
Flashing on |
|
|
Cursor down |
|
|
Cursor up |
|
|
Cursor left |
|
|
Cursor right |
|
|
Reverse on |
| Ctrl + 9 |
Reverse off |
| Ctrl + 0 (zero) |
Home |
|
|
Clear |
| Shift + Home |
Insert |
| Shift + Del |
These PETSCII codes cannot appear as characters in program listings or quoted strings. To include them in a BASIC string in a program, use the CHR$()
function and string concatenation. Useful printable codes:
Return:
CHR$(13)
Delete:
CHR$(20)
Escape:
CHR$(27)
Underline off:
CHR$(130)
Flashing off:
CHR$(143)
petcat source code
You can read the source code for petcat in the VICE source repository.