Creating CP/M Disk Images using MAME, Socat and Kermit

From GlassTTY
Jump to: navigation, search

Introduction

This article describes a simple and fun means to populate CP/M disk images from the local machine using the MAME emulator and a few tools. For the example here I am using a macOS (Mojave 10.14.2) emulating an Apple II+ with an MS Softcard, however, I suspect this approach could be used with any CPM system that MAME could emulate. Similarly, the instructions here could be used as a guide for configuring a Linux or Windows system.

The basic idea is to use socat, to connect the localhost port 2023 to a bash shell on the local machine and use MAME to emulating an Apple II CP/M machine with a Super Serial Card hooked up to that port. Once this is done Kermit can be used to transfer files from macOS to Apple II disk images. Simple, retro and fun.

In case you are not familiar with Kermit, it is a communications protocol that can be used to transfer files between systems. This example makes use of Kermit-80 running on the Apple II under CP/M and C-Kermit running on macOS in order to transfer files. Kermit-80 includes a VT52 terminal emulator,making the whole process quite simple.

The article makes use of the following;

  • The MAME emulator (https://www.mamedev.org/) to emulate an Apple II+ with Microsoft Softcard.
  • Kermit-80 (Apple II) and C-Kermit (macOS) to transfer files fbetween the machines.
  • Socat, the General Bidirectional Pipe Handler to allow the MAME emulator to connect to the shell of the host machine.

Please note that in this article the brew package manager (https://brew.sh/) is used to install the various components on macOS.

Installing MAME, Socat and C-Kermit on macOS

The article Using MAME to Emulate the Apple II+ describes how to install MAME and emulate the Apple II+.

C-Kermit can be installed on macOS using brew as shown below.

  $ brew install c-kermit

In addition, the utility socat also needs to be available. On linux machines this may already be installed otherwise the distributions package manager should be able to sort this out. For macOS brew can be used to install socat e.g.

   $ brew install socat

Once this is complete a simple shell command can be created to launch MAME and socat see #Running MAME. However, before launching MAME a few disk images are required.

Folder Hierarchy

There are many ways to configure MAME, for this Article I have used a simple folder structure im home drive to store the cpm disk images to be used and the machine config file. The structure I have used can be created as follows.

   $ mkdir ~/mame
   $ mkdir ~/mame/cfg
   $ mkdir ~/mame/cpm

Copy the Kermit-80 and blank disk images to ~/mame/cpm directory. These images are available from the link below.

https://glasstty.com/wiki/images/3/35/Kermit.zip

Copy the following configuration to a file called apple2p.cfg stored in the ~/mame/cfg directory. Make sure that the directory paths are correct for the current user.

   <?xml version="1.0"?>
   <mameconfig version="10">
       <system name="apple2p">
           <input>
               <port tag=":sl2:ssc:ssc_rs232:null_modem:RS232_RXBAUD" type="CONFIG" mask="255" defvalue="7" value="4" />
               <port tag=":sl2:ssc:ssc_rs232:null_modem:RS232_TXBAUD" type="CONFIG" mask="255" defvalue="7" value="4" />
           </input>
           <image_directories>
               <device instance="bitbanger" directory="/Users/johnnewcombe/mame/" />
               <device instance="floppydisk1" directory="/Users/johnnewcombe/mame/cpm/" />
               <device instance="floppydisk2" directory="/Users/johnnewcombe/mame/cpm/" />
               <device instance="cassette" directory="/Users/johnnewcombe/mame" />
           </image_directories>
       </system>
   </mameconfig>

Running MAME

Create the following bash script and place in the MAME directory ~/mame. In this example, the file is called cpm.sh.

   #!/bin/bash
   
   # Move to the MAME directory
   cd mame0195-64bit
   
   # Launch socat, this will connect the localhost port 2023 to bash shell on the local machine
   socat tcp-l:2023,reuseaddr,fork exec:/bin/bash,pty,setsid,setpgid,stderr,ctty &
   # Start MAME with a serial port hooked up to the localhost port 2023, i.e. the bash shell provided by socat
   mame apple2p -noreadconfig -skip_gameinfo -verbose -uimodekey CAPSLOCK -window -nomax -sl2 ssc -sl2:ssc:ssc_rs232 null_modem -bitbanger socket.127.0.0.1:2023 -sl3 videoterm -sl4 softcard -flop1 "./cpm/kermit.dsk" -flop2 "./cpm/blank_1.dsk" 
   
   # Remove any socat process
   killall socat

Ensure that the script is executable. For example if the script were named cpm.sh, the following command could be used.

   $ chmod 755 ~/mame/cpm.sh

MAME can now be started by navigating to the ~/mame directory and executing the following.

   $ ./cpm.sh

If all goes well both the 40 col and 80 col screens will be shown side by side and CPM will boot from disk A.

Kermit

Kermit can be run on the Apple II by executing the following command.

   $ KER411
   

This should present the Kermit prompt e.g.

   Kermit 80 0A:>

The Apple II system does not have a complete ASCII keyboard, as a result it is important that the escape sequence used to return to the local Kermit prompt can actually be entered. This can be acomplished with the following command.

   Kermit 80 0A:> SET ESCAPE

This will prompt for the escape character, press / (Forward Slash). It will now be possible to return to the the local kermit prompt when connected to a remote computer using Ctrl-/ C (Control plus the forward slash character, followed by C).

Set the connection speed and connect, e.g.

   Kermit 80 0A:> SET SPEED 1200
   Kermit 80 0A:> CONNECT 

This should connect you to the bash shell of the local macOS machine via socat.

   bash-3.2 $ 
   

From there c-kermit can be run.

   $ kermit
   

This should give you the remote Kermit prompt.

   C-Kermit>

Files can be transferred in either direction using Kermit, the simplest way is to use server mode. At the remote Kermit prompt enter the server command e.g.

   C-Kermit> SERVER

Kermit should respond as follows:

   KERMIT READY TO SERVE...

Return to the local (Apple II) kermit prompt with the command Ctrl-/ C (Control plus the forward slash character, followed by C).

   Kermit 80 0A:>

At this prompt it is possible to enter remote commands such as CD, DIR and so on e.g.

   Kermit 80 0A:> REMOTE DIR

Binary or text mode can be set, note that the remote command is followed by a local command e.g

   Kermit 80 0A:> REMOTE SET FILE TYPE BINARY
   Kermit 80 0A:> SET FILE-MODE BINARY

Or...

   Kermit 80 0A:> REMOTE SET FILE TYPE TEXT
   Kermit 80 0A:> SET FILE-MODE BINARY

To down load or upload files the GEDT or SEND commands can be used e.g.

   Kermit 80 0A:> GET BBCBASIC.COM

Progress will beshown as follows.

   Kermit-80 v4.11 [Apple II Cp/M]
   
   Number of packets: 201
   Number of retries: 0
   Filename: BBCBASIC.COM
   
   Receiving...

To end the session the BYE command can be used.

   Kermit 80 0A:> BYE