Transferring a BASIC program from C64 to CX16
-
- Posts: 140
- Joined: Tue Jul 21, 2020 10:08 pm
Transferring a BASIC program from C64 to CX16
Hi
Apologies if this has been covered elsewhere, but my searches didn't yield anything useful.
I've been developing a compiler on my C64, written in BASIC, and I want to move it to the CX16 environment. I'm a MAC guy so the obvious tools folks might suggest just don't seem to have MAC versions or equivalents. I really don't want to print it out and then manually type it in to the CX16 environment... well, at least, not all of it!
I'm running emulator r43. Any suggestions/pointers gratefully received!
Cheers
Martin
Apologies if this has been covered elsewhere, but my searches didn't yield anything useful.
I've been developing a compiler on my C64, written in BASIC, and I want to move it to the CX16 environment. I'm a MAC guy so the obvious tools folks might suggest just don't seem to have MAC versions or equivalents. I really don't want to print it out and then manually type it in to the CX16 environment... well, at least, not all of it!
I'm running emulator r43. Any suggestions/pointers gratefully received!
Cheers
Martin
Re: Transferring a BASIC program from C64 to CX16
I take it you've got the original program stored as a tokenized BASIC program for the C64.
The Commander X16 uses the same tokenization as the C64. It might be possible to load the C64 program file as is on the X16. I would try that first. To test this you need to store the program file in the host file system or on an SD card image so that you can LOAD it in the X16 emulator.
If this doesn't work, you can convert the C64 program to a plain text file. Here's a video of a guy doing that: https://www.youtube.com/watch?v=javD5O5hlEc
He uses some VICE tools, c1541 and petcat to get this done.
A BASIC program stored as plain text can be imported in the emulator by launching it with the -bas switch, for example "x16emu -bas MYGREATBASICPROGRAM.BAS".
You can also open up the plain text version of the BASIC program in a text editor on the host system and copy the content of the file. It is possible to paste it into the emulator with Cmd+V on a Mac.
The Commander X16 uses the same tokenization as the C64. It might be possible to load the C64 program file as is on the X16. I would try that first. To test this you need to store the program file in the host file system or on an SD card image so that you can LOAD it in the X16 emulator.
If this doesn't work, you can convert the C64 program to a plain text file. Here's a video of a guy doing that: https://www.youtube.com/watch?v=javD5O5hlEc
He uses some VICE tools, c1541 and petcat to get this done.
A BASIC program stored as plain text can be imported in the emulator by launching it with the -bas switch, for example "x16emu -bas MYGREATBASICPROGRAM.BAS".
You can also open up the plain text version of the BASIC program in a text editor on the host system and copy the content of the file. It is possible to paste it into the emulator with Cmd+V on a Mac.
Re: Transferring a BASIC program from C64 to CX16
What storage devices do you have for your C64?
Things like SD2IEC will both allow you to save loose files outside of a disk image, and since SD2IEC reads full size SD cards, you don't really need to convert anything. Just save the file to the SD card and then pop that SD card into your Mac.
Things like SD2IEC will both allow you to save loose files outside of a disk image, and since SD2IEC reads full size SD cards, you don't really need to convert anything. Just save the file to the SD card and then pop that SD card into your Mac.
Re: Transferring a BASIC program from C64 to CX16
There is one more thing one has to do before one can load a C64 BASIC program, that was converted to text using petcat, using x16emu -bas, and that is to convert lower case to upper and vice versa:
That can be done using:
or
The reason is that petcat doesn't fully convert PETSCII to ASCII, and that PETSCII has flipped upper and lower cases in PETSCII-LC mode, which is perhaps most common when programming, but in PETSCII-UC mode it's non flipped, but has graphics characters for the lower case.
petcat adds spaces before line numbers and those can be removed using:
I used petcat (VICE 3.7) and that uses LF line endings (at least in Linux), but in earlier versions petcat used CR line endings, because that is the native text format of C64. Apple II and macOS 9 and earlier also used CR line endings. You can convert line endings, if necessary, using mac2unix:
You may need to use mac2unix directly after petcat if perl and sed can't handle line endings with CR.
petcat also converts control codes in strings to some text (e.g. "{orng}"), and those would need to be converted to e.g. \X81 for orange. I have no automatic solution for this conversion. I usually don't use control characters in text strings and instead write e.g. CHR$($81) or CHR$(129) outside strings. The petcat named control codes:
Putting it all together:
or
Not my video, but an interesting video about the subject:
Tokenize/De-tokenize Commodore Basic Programs Using petcat
That can be done using:
Code: Select all
cat program.bas | perl -pe 'y/[a-z][A-Z]/[A-Z][a-z]/' > program2.bas
Code: Select all
cat program.bas | sed -e 'y/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz/' > program2.bas
petcat adds spaces before line numbers and those can be removed using:
Code: Select all
sed 's/^ *//' program2.bas > program3.bas
Code: Select all
mac2unix -n program3.bas program4.bas
petcat also converts control codes in strings to some text (e.g. "{orng}"), and those would need to be converted to e.g. \X81 for orange. I have no automatic solution for this conversion. I usually don't use control characters in text strings and instead write e.g. CHR$($81) or CHR$(129) outside strings. The petcat named control codes:
Code: Select all
003 $03 {stop}
005 $05 {wht}
008 $08 {dish}
009 $09 {ensh}
014 $0e {swlc}
017 $11 {down}
018 $12 {rvon}
019 $13 {home}
027 $1b {esc}
028 $1c {red}
029 $1d {rght}
030 $1e {grn}
031 $1f {blu}
129 $81 {orng}
142 $8e {swuc}
144 $90 {blk}
145 $91 {up}
146 $92 {rvof}
147 $93 {clr}
148 $94 {inst}
149 $95 {brn}
150 $96 {lred}
151 $97 {gry1}
152 $98 {gry2}
153 $99 {lgrn}
154 $9a {lblu}
155 $9b {gry3}
156 $9c {pur}
157 $9d {left}
158 $9e {yel}
159 $9f {cyn}
Code: Select all
petcat -nh -2 -- program.prg | perl -pe 'y/[a-z][A-Z]/[A-Z][a-z]/' | sed 's/^ *//' > PROGRAM.BAS
Code: Select all
petcat -nh -2 -- program.prg | mac2unix | perl -pe 'y/[a-z][A-Z]/[A-Z][a-z]/' | sed 's/^ *//' > PROGRAM.BAS
Tokenize/De-tokenize Commodore Basic Programs Using petcat
-
- Posts: 140
- Joined: Tue Jul 21, 2020 10:08 pm
Re: Transferring a BASIC program from C64 to CX16
Thanks Stefan. I do have the original in tokenised form on my C64 - actually I have it running on VICE at the moment as I don't have the desk space just now to have all my kit setup. My challenge I guess is in saving it somewhere that is not a .D64 image as it looks like the CX16 doesn't 'do' .D64 images.Stefan wrote: ↑Fri Jun 23, 2023 8:01 am I take it you've got the original program stored as a tokenized BASIC program for the C64.
The Commander X16 uses the same tokenization as the C64. It might be possible to load the C64 program file as is on the X16. I would try that first. To test this you need to store the program file in the host file system or on an SD card image so that you can LOAD it in the X16 emulator.
Yep, good idea - the first challenge being to get it out of VICE as a text file and not stuck in a .D64 image.
BTW, I've tried the OPEN 1, 8, 2..... CMD 1.... LIST etc trick to list the program out to a text file in the C64/VICE environment - it doesn't work for me - I know you have to disable the True Drive Emulation feature, but when I do that then my version of VICE (downloaded it just a few days ago) won't attach any drives at all!
If you have any pointers on overcoming these 2 challenges above, I'd be very grateful.
Cheers
Martin
-
- Posts: 140
- Joined: Tue Jul 21, 2020 10:08 pm
Re: Transferring a BASIC program from C64 to CX16
Ah - I have a Pi1541 thingy - I hadn't thought of that... and an older copy of the program (but not too different) already on the SD card that's in it... Cheers!TomXP411 wrote: ↑Fri Jun 23, 2023 4:48 pm What storage devices do you have for your C64?
Things like SD2IEC will both allow you to save loose files outside of a disk image, and since SD2IEC reads full size SD cards, you don't really need to convert anything. Just save the file to the SD card and then pop that SD card into your Mac.
-
- Posts: 140
- Joined: Tue Jul 21, 2020 10:08 pm
Re: Transferring a BASIC program from C64 to CX16
Thanks everybody - I've sorted it with a combo of all of your suggestions - once I got it in to text and all uppercase (thanks to the pet cat prog etc) then I opened it in a text editor on my Mac and copy/pasted it in to the CX16 emulator - had some issues as with the various {} expansions some lines were too long for BASIC 2 - I had maybe 6 or 7 of those total - I'll soon have those sorted!
So, thanks again one & all!
Cheers
Martin
So, thanks again one & all!
Cheers
Martin
Re: Transferring a BASIC program from C64 to CX16
You should be able to just load the PRG file directly into the emulator; you don't need to convert it.