How to save BASIC programs as PETSCII

Tutorials and help articles.

Articles will be approved by our staff before posting. This is to ensure that the community gets the highest quality possible content.
Post Reply
TomXP411
Posts: 1731
Joined: Tue May 19, 2020 8:49 pm

How to save BASIC programs as PETSCII

Post by TomXP411 »

Kelli217 reminded me of how we used to do this, back in the day:

As you know, BASIC programs are stored in tokenized format. That means that commands like PRINT are stored as numbers, like 153. Line numbers are stored as 16-bit integers, and each line starts with a 2 byte pointer to the next line and ends with a null (0) character. So all that is to say - you can't just print or view a BASIC program in something like Notepad.

The solution is to do this at the READY prompt:

Code: Select all

OPEN 8,8,8,"MYPROG.BAS,S,W"
CMD 8
LIST
PRINT#8
CLOSE 8
Walking through this, one statement at a time:
the OPEN statement just opens a file for writing.
CMD changes the default output channel from the screen to the disk drive (device 8.)
LIST outputs the program as text, rather than tokens.
PRINT#8 ensures that the buffer has been purged. (this may not be a thing now, but there was a bug on the C64 that cut things off if you didn't do this.)
CLOSE 8 closes the sequential file, resetting the command channel back to the screen.

Since this is a feature of the BASIC ROM, this will work both on the emulator and on real hardware. So this is a convenient way to export your listings for posting on the Internet or printing from your PC.
User avatar
desertfish
Posts: 1041
Joined: Tue Aug 25, 2020 8:27 pm
Location: Netherlands

Re: How to save BASIC programs as PETSCII

Post by desertfish »

You can also launch the emualtor with "-echo" command line option and then it writes all text on the screen also to the standard output in the console :)
Post Reply