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

PETSCII

petcat

Notes

A

a

 

1

1

 

+

+

 

Several PETSCII-specific punctuation characters have similar codes as ASCII characters. These appear in petcat listings as their ASCII equivalents.

PETSCII

petcat

Notes

PETSCII

petcat

Notes

£ (pound)

\

See exceptions below for Shift and Mega variants.

Left arrow

_

 

Up arrow

^

 

π (pi)

~

 

Graphics characters formed by pressing Shift and a letter are represented by uppercase letters.

PETSCII

petcat

Notes

PETSCII

petcat

Notes

Spade

A

Shift + A

Heart

S

Shift + S

Diamond

Z

Shift + Z

Club

X

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

PETSCII

petcat

Notes

Thick cross

{SHIFT-+}

Shift + +

Mid-bar

{SHIFT-*}

Shift + *

Upper-left triangle

{SHIFT-POUND}

Shift + £

All characters accessed by pressing Mega and a character key are labels with the prefix CBM-.

PETSCII

petcat

Notes

PETSCII

petcat

Notes

Upper-left corner

{CBM-A}

Mega + A

Upper-right corner

{CBM-S}

Mega + S

Half-checkerboard

{CBM-POUND}

Mega + £

The sixteen color control codes have labels similar to their keycap spellings.

PETSCII

petcat

Notes

PETSCII

petcat

Notes

Black

{blk}

Color 0; Ctrl + 1

White

{wht}

Color 1; Ctrl + 2

Red

{red}

Color 2; Ctrl + 3

Cyan

{cyan}

Color 3; Ctrl + 4

Purple

{pur}

Color 4; Ctrl + 5

Green

{grn}

Color 5; Ctrl + 6

Blue

{blu}

Color 6; Ctrl + 7

Yellow

{yel}

Color 7; Ctrl + 8

Orange

{orng}

Color 8; Mega + 1

Brown

{brn}

Color 9; Mega + 2

Light red

{lred}

Color 10; Mega + 3

Grey 1

{gry1}

Color 11; Mega + 4

Grey 2

{gry2}

Color 12; Mega + 5

Light green

{lgrn}

Color 13; Mega + 6

Light blue

{lblu}

Color 14; Mega + 7

Grey 3

{gry3}

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

PETSCII

petcat

Notes

Underline on

{CTRL-B}

 

Stop

{stop}

 

Bell

{CTRL-G}

 

Tab

{CTRL-I}

 

Linefeed

{CTRL-J}

 

Shift enable

{ensh}

 

Shift disable

{dish}

 

Switch to lowercase

{swlc}

Wikipedia’s PETSCII table calls this “text mode.”

Switch to uppercase

{swuc}

Wikipedia’s PETSCII table calls this “graphics.”

Flashing on

{CTRL-O}

 

Cursor down

{down}

 

Cursor up

{up}

 

Cursor left

{left}

 

Cursor right

{rght}

 

Reverse on

{rvon}

Ctrl + 9

Reverse off

{rvoff}

Ctrl + 0 (zero)

Home

{home}

 

Clear

{clr}

Shift + Home

Insert

{inst}

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.