Tuesday, August 16, 2016

CP/M on an emulator TRS-80 Model 4P

My TRS-80 Model 4P: You can't really see it but that's CP/M
running off of the FreHD that you also can't really se on top
of the machine.
So as I mentioned in my last blog post, I took an unplanned six-month rectrocomputing siesta.  I had only recently acquired a cool old-but-refurbished TRS-80 Model 4P with a FreHD (an SD-based hard drive emulator) that was already setup to book LS-DOS and CP/M.  Since I'd been wanting to play with CP/M, and I really like the TRS-80 Model 4P, this seemed like a perfect match.  But after some early frustration with trying to transfer CP/M software to the 4P, and with other things coming up IRL, I dropped retrocomputing for a while.

CP/M Emulation

So in my last post, I mentioned that I was kind of itching to do some software project, but due to my current situation, I was really looking for something emulated, not a physical machine.  My TRS-80 Model 4P immediately popped in my head, of course, but my last time I really had problems with emulators.  This was mostly because they wanted me to supply the ROM, but I still didn't have a way to exchange data between my 4P and my Mac.  Well, after some Internet digging (I swear I am the worst googler in the history of humanity), I finally found a working Model 4P ROM.  (Yes, I downloaded the ROM, even though it's copyrighted.  All I can offer is that you trust that I really do own the machine, as evidenced by the photo above.)

So with the 4P ROM in hand, digitally speaking, I tried out the TRS32 emulator first.  Although I'm a Mac person, I do have Windows running both in VMWare and in Boot Camp, so being a Windows-only program isn't necessarily a deal breaker.  And to be honest, it's a good program.  I had a few minor complaints with the interface, but overall it was very functional and easy to setup.  The only real issue I had is that it's shareware, costing $69 to register, and hard drive support was only included in the full version - something I knew I would want, since my 4P had FreHD.  Also, the guy does TRSTools for free, which is a nice little program to read/write TRS-80 floppy disk images.  I'm not opposed to paying for software, and his gift of TRSTools to the community made me even more interested in throwing him some cash, but $70 for an emulator seemed steep to me.

Then I found SDLTRS, an open source cross-platform emulator based on xtrs, an X-Windows emulator.  It is open source, and seems to do everything the full version of TRS32 does, including hard drive support.  The Windows and Linux interfaces are a bit spartan, but the Mac interface is pretty nice, though I wish the Mac supported the same keyboard shortcuts the Windows version does and was a little less mouse-driven.  In any case, it was as easy to get up and running as TRS32 was, and seemed every bit as functional.  So it became an easy choice, and so far I haven't regretted picking SDLTRS over TRS32.

Getting CP/M Running

As you might guess, this was basically just grabbing a disk image, popping it into the virtual floppy drive in SDLTRS, and booting up the VM.  But which CP/M?  There are several for the 4P, the two most common being CP/M Plus and Montezuma Micro's CP/M.  CP/M Plus was limited to CP/M 3.0, and since I already knew I was going with CP/M 2.2, that left only Montezuma's CP/M.  Here's where I got my CP/M image, and in fact most of the CP/M software that I downloaded.

Now before you hop out to that site and start downloading everything like I did, you may want to pause a bit to avoid some mistakes I made.  First, you don't need every CP/M boot disk that's out there.  I just got the last of the Montezuma Micro CP/M boot disks, and that's what I used.  Second, disks will be labeled as either of type COM, DSK, or DMK.  COM means that it's actually going to come as a binary program, not a disk image, so you'll need to copy it to a disk image to run it.  There are two ways to do this, which I'll discuss below.  DSK and DMK are two virtual disk image formats, so either of these are potentially usable in SDLTRS.  However, while SDLTRS does support DMK, I noticed that a lot of them were larger than the 166k floppy drives that the emulated machine supported, so it was hit-or-miss as to whether these worked out of the box.  All the DSK's I downloaded worked without an issue, though, so if something comes in multiple formats, always pick the DSK.  If it does come in DMK only, all is not lost.  It may very well work, so go ahead and try it.  But if it doesn't. the DMK will probably work in TRSTools, so you can copy the files to a temporary directory, then open a blank DSK and copy the files to that.  The DMK may be a larger size than the DSK, so you may have to pick which files you don't need or copy them to multiple DSK images.  I had to do this with the Hard Disk Drivers disk, which was larger than a DSK.  I put the executables on one DSK and the docs on another.  (I'll talk about setting up the hard drive in my next blog post, but at this point, just make sure to grab that disk image.)

Incidentally, I mention using a blank DSK above, but I didn't originally have a blank DSK image.  SDLTRS Floppy Management tools does allow you to create a blank floppy, but I couldn't get these to load once I'd created them, so after a few failed attempts, I gave up with that.  Now TRSTools does say it supports the Montezuma Micro disk format, which it does seem to, but I couldn't see how to create a usable disk image with it.  To get around that, I just made a copy of one of my working DSK image files, opened it in TRSTools, removed all the files, and made sure it was not flagged as write protected.  Then I just renamed it blank.dsk and would just make a copy of this every time I needed a blank floppy.

Now I mentioned above that some software will come as files instead of on DSK or DMK images.  On the download page above I referenced, Zork I could only be downloaded this way, and the first copy of Turbo Pascal 3 I found on another page came as a zip of files.  There are two ways to deal with this.  The first is to use the cpmutils, which is a set of utilities written for xtrs, the base of the SDLTRS emulator, while other way is to use a blank disk image and add them using TRSTools.  

In the SDLTRS distribution is a subdirectory called diskimages, with a disk image called cpmutils.dsk.  Now, annoyingly, this disk image didn't load for me in MM CP/M, but I used TRSTools to copy the files to a usable blank disk image (you can download the result of this here, if you don't want to do this yourself).  This has a bunch of files on it, but the three COM files are EXPORT, IMPORT, and XTRS.  These are special CP/M programs that take advantage of hooks in the emulator to be able to transfer files to and from the local filesystem.  So, for example, to make a disk image for Zork I, all you'd have to do is download the ZORK1.COM file, copy a blank disk image, and then type IMPORT ZORK1.COM ZORK1.COM.  This works in that you don't get any errors, and something is copied, but when I tried to execute ZORK1, it gave me weird, inconsistent results.  (This was after also copying ZORK1.DAT, which you need as well).  When I then used TRSTools to copy the files to a disk image, this worked, so I have to conclude there's some issue with the IMPORT.  If anyone has any clue, please leave a comment.  I should mention, btw, that I did use EXPORT several times successfully, though I wasn't copying any COM files, only text files.

It's too bad that I couldn't get the IMPORT working though.  TRSTools is nice, but as I'm a Mac user, it's a tad of a pain to use.  I use VMWare Fusion to run Windows on my Mac, but I don't usually have that running, and having to switch to the Windows desktop (I don't run the unified desktop because that annoys me too) when I want to use TRSTools bugs me.  But I keep disk images I'm working on in my shared folder between the Mac and Windows VM and that makes it easier.

Building a 4-Drive System

So now that you have a working CP/M system booting off floppy, and a way to transfer files, the last thing I'll mention is about changing your emulated system to a 4-drive system instead of the default 2-drive.  Now as I mentioned in my last blog, I am not very familiar with CP/M, and certainly not familiar with Montezuma CP/M.  So there may be a better way of trying to accomplish what I did.  If so, please let me know in the comments.  But this is what I had to do to get things to work so I could load up disks in four virtual drives.

BTW, if you haven't done so yet, make a copy of the CP/M boot disk image you're going to use.  Also make sure you're working image is not write protected.  This is set in the image file itself, not by the base operating system.  You'll know if it loads in SDLTRS and when you look at the floppy management screen and it has an asterisk beside it.  I didn't see any way to uncheck this in the Windows version, though in the Mac version you can unlock it.  For Windows, you can use TRSTools and just go into Disk Properties under the File menu.

Boot up CP/M and run CONFIG and you'll see the following menu:

Select F for Disk drive definitions and you'll see:

Select 'C' and enter 4 when it asks, "How many drives?"  That should bring you back to the same screen, but showing 4 physical drives instead of 2.  His the ESC key (in SDLTRS, ESC is mapped to the BREAK key and Shift-up arrow is mapped to TRS-80's ESC), and you'll be back at the main menu shown above.

Go ahead and hit 'G' at this point, which will take you to the Disk format definitions menu:

Now you'll notice that you do have four drives defined, A - D, but A and C seem mapped to the same drive, device 0, and B and D to the same device 1.  Now someone who knows more about CP/M may understand this and how to work with this, but for me it just meant I couldn't get and disk images to read correctly in C and D.  So if you're following what I did, select 'C' and you'll see:

The first two options match our new 4-drive disk definitions, but the two DATA format drives don't seem to work, so I set the C and D drives to 'A' to match the two drives that do work.  

Once you've done all that, use ESC to get back to the main menu, and then SAVE THE CONFIG!  It the 'H' option on the main menu.  It's easy to just jump all the way back and forget this; I did it several times.

At that point, hit F10 to reboot and you have a 4-floppy drive system.

In my next post, I'll go through setting up a hard drive for my emulated system.

Tuesday, August 9, 2016

Running silent

As I'm sure no one has noticed, I haven't posted in a while.  I would like to say that I've been so busy with retrocomputing projects that I just haven't had time to post, but the truth would actually be the opposite.  I haven't done anything with retrocomputing for the last four to six months, so I just haven't had anything to post.  There were a number of reasons for me going silent.  My living situation has been in a bit of an upheaval during this time.  I've been sick several times, and my overall energy level has been down (which, for me, is saying quite a bit, since I'm not normally what one would think of energetic in the first place).  And, honestly, I just haven't really been inspired to do anything with retrocomputers.

That started to change about two weeks ago, when I started getting a hankering to do some sort of software project.  I looked around for several things, and started working on a cloud-based web project, until that pissed me off and really sucked away all my interest.  Several other ideas also occurred to me, but finally I decided to come back to the platform I was just getting into when I stopped retrocomputing, the TRS-80 Model 4P.  More specifically, CP/M on the Model 4P.

The Road to CP/M

I used CP/M only briefly back in the day.  When I was a senior in high school, I took a few classes at the local community college, including an introduction to computers which featured CP/M.  I believe they used DEC Rainbows, though I'm fuzzier on that so I could easily be wrong.  But I very clearly remember the cover to the book we used, The CP/M Handbook.  That was it, one semester in one class, and I never used CP/M again.  But being a computer history buff, I read a great deal about CP/M and Gary Kildall and always had a great respect for the man and his contribution to computers.

Before my break, I decided I wanted to explore the world of CP/M, specifically I wanted to do some programming with early Turbo Pascal.  I bought a Kaypro II, but that had a bad second floppy, and Kaypro's CP/M was really built for a two-floppy system.  So I bought a second Kaypro II, which did have two good floppies, though the first one was very slow to load anything.  Also it didn't have the little kickstand that my first Kaypro had, and that bugged me much more than it should have.  So I had the bright idea of putting the good drive from the second machine into the first machine.  I was defeated by two rusted screws, after trying everything I could think of.  The two Kaypro's sit, still disassembled, just a few feet from where I write this, mocking and taunting me.

The Model 4P: A Great CP/M Machine or the Greatest CP/M Machine?

I had read somewhere that the TRS-80 Model 4/4P was an excellent CP/M machine, and I found a nice sale on eBay.  It wasn't the cheapest unit, but the person had cleaned the inside and outside of it, guaranteed that the unit worked, and also included a FreHD unit (a hard drive simulator for the TRS-80 computers using an SD drive, for those who don't know) with the ROM upgraded to take full advantage of it.  As I said, it wasn't the cheapest deal, but just having someone who seemed knowledgeable attest that it is completely functional is worth some extra cash, to those who have experience buying retro computers on eBay.  It even had the latest LSDOS and CP/M as bootable hard disk images on the SD card.  And, sure enough, when I got it it booted up very nicely into both OS's.  The only problem was that while the LSDOS image had a lot of software, the CP/M included the base OS and that was it.  

Well, that's no big deal, thought I.  I can find tons of CP/M software on the net, and I'll just load that up.  Of course, the 4P only has 5.25" drives, and none of my modern machines has a 5.25" drive, so "sneaker net" is out.  Of course, I thought about transferring it through a serial connection, but I couldn't get that to work.  And I couldn't figure out how to transfer anything to the hard drive images on the SD card.  FreHD is a cool device, but the documentation leaves much to be desired.

That's pretty much where I left it, when I began my unplanned, months-long absence from retrocomputing.

In my next post (hopefully within a day or two), I'll follow up with what I'm up to now and what I plan to do.