Page 1 of 1

How to save BASIC programs as PETSCII

Posted: Fri Feb 24, 2023 8:43 pm
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.

Re: How to save BASIC programs as PETSCII

Posted: Fri Feb 24, 2023 11:49 pm
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 :)