How to save BASIC programs as PETSCII

Tutorials and help articles.

(Posts require approval. See pinned post.)
Forum rules
Post guides, tutorials, and other instructional content here.

This topic area requires approval, so please be patient while we review content to make sure it fits the expectations for this topic area.

Tech support questions should be asked in Hardware or Software support.
Post Reply
TomXP411
Posts: 1776
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: 1088
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