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
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.