# How to get a plain text file version of a CP/M .BAS (M-BASIC) program?

I have an old game (STRTRK.BAS) from my dad's Kaypro 10 that I would like to convert to a plain text file. Basically, what I'm trying to do is get it onto a modern computer in plain text format so I can look at the source code and print it (hardcopy).

This game is accessible on the K10 itself, by starting up OBASIC (an older version of MBASIC, itself a platform independent implementation of BASIC-80).

The source code can be listed once loaded (again, on the actual machine).

My guess is the best route would be to find a CP/M emulator and install a version of CP/M, OBASIC, and the program onto it, but I actually haven't had any luck finding something that will run on a modern Windows 7 setup.

Any ideas?

• Would converting it on the K10 and uploading it through a serial connection be an option? – Thorbjørn Ravn Andersen Apr 27 at 18:03

M-BASIC-80 knows the modifier "A" for the SAVE command - So, you should be able to create a readable ASCII file directly on the Kaypro computer by doing

LOAD "MYPROG.BAS"
LIST
SAVE "MYPROG.TXT",A


If you don't want to mess with old disks on a modern computer (I recommend you don't even start to look into this), your best bet would be to set up a serial RS-232 connection between the Kaypro and your modern machine - A suitable RS-232-USB dongle, a proper cable and a terminal program would suffice.

• On Windows 10, I just downloaded & installed RunCPM and then STRTRK.BAS as linked above, and started MBASIC and loaded the bas and it seems to run. I was also able to save it as ASCCI text. – Michael Harvey Apr 27 at 20:56

It wouldn't happen to be the one that the listing starts/ends like this, would it?

10 'EXPANDED APRIL 1977 BY W.A. BURTON
20 'PIRATED JAN. 1978 BY ZOSO
30 DIM G(8,8),S(8,8),K(3,3)
40 PRINTCHR\$(26)
50 GOSUB 5460
…
6350 IF Q8<0 OR Q8>S THEN GOTO 6340
6360 S=S-Q8:E=E+Q8:PRINT
6370 PRINT E;" UNITS OF ENERGY NOW - TRY AGAIN."
6380 RETURN
6390 RESET


If so, there are lots of copies online, frinstance STRTRK.BAS. The program detokenizes and runs under both OBASIC.COM and MBASIC.COM.

Peter Schorn's Altair 8800 simulator site has emulators and disk images for many versions of CP/M. For instance, I downloaded the CP/M 2 distribution, unpacked it, moved the STRTRK.BAS file to the cpm2 folder and started the emulator with:

altairz80 cpm2


After that, I was able to import the tokenized program with the command R STRTRK.BAS, then loaded MBASIC and the program could be loaded with LOAD "STRTRK.BAS"

• Thanks for all the useful feedback. I ended up going the emulator route for now. This worked well. I downloaded RunCPM and set up some folders for the disks and user areas. I then had to move a copy of OBASIC.COM and STRTRK.BAS to one of the user areas. With the emulator started, I was able to load the code using OBASIC (which detokenizes it) and then use the window's copy and paste functionality to move it over to Notepad to save it as a plain text file. Thanks to scruss, Michael Harvey, and tofro for all the useful information. – dvanaria Apr 28 at 4:41
• I found that STRTRK.BAS opened fine in MBASIC which is already on the "A" "disk" folder provided by the RunCPM guy, then, in MBASIC, I issued SAVE "STRTRK.TXT", A and I was able to open the resulting file directly in Notepad. – Michael Harvey Apr 28 at 6:48
• This is even better (saving with the A flag within the RunCPM emulator). My first attempt I was just copying the text directly from one window and pasting it into another, which resulted in a few spots in the text file that I had to manually edit. Saving within the emulator produces a clean text file. Thanks again. – dvanaria Apr 28 at 22:17

Basic interpreters saved the code in a tokenised form to save space. I found this description of the format used by GW-Basic, a later version of MBASIC. I don't know if the file format changed between the versions, though.

http://justsolve.archiveteam.org/wiki/GW-BASIC_tokenized_file

It wouldn't be too hard to write a bit of code to convert from the byte-codes to text.

• While this might seem a good idea at first, OBASIC/MBASIC and GW-BASIC use different token values. A tokenized CP/M BASIC program will often load into GW-BASIC, but listing it will show that it's riddled with syntax errors – scruss Apr 28 at 22:48
• @scruss I did suspect that might be the case. I couldn't find any info on the MBASIC tokenisation (and as better answers have been provided, it isn't really relevant). – James Random Apr 28 at 23:24
• fair point. I left the note here for future readers to suggest that this approach is a good one from a theoretical point of view, but needs some work for a real implementation. It's a perfectly good answer! – scruss Apr 29 at 1:55