Run DOS BBS DoorGames on the Raspberry Pi:
  by Darryl Perry 2016

  This tutorial is intended for BBS sysops who wish to run DOS door games
  on their Raspberry Pi (or other ARM device)

  This tutorial is developed with Mystic BBS as the default BBS to use.  If
  you wish to use another BBS package, you will need to fix up the parts 
  that are specific to the package you wish to use.

How does this work?
  We will be creating an emulated virtual DOS environment from which to run 
  our DOS door games.  To do that, we will be creating a serial port into our 
  VM and attching it to a computer port so that we can communicate via socat.

  Since we can mount host file systems into the DOS VM, we will not need to 
  populate the VM file system with doorgame programs.  This means we only need
  the bare minimum to boot and run the dos environment.

  Each time a door is ran, the script will build a batch file (run.bat) in
  the main bbs directory.  When the VM boots, it will run that run.bat
  batch file to run the doorgame.

These methods have worked for me on the following devices:
  1) Raspberry Pi B+ (
  2) ODROID XU3-Lite (

  The Raspberry Pi B+ is the least robust device I've attemted this with
  and I've had some good success with it.  However, the device is inherently 
  slow, so do not expect high-speed game-play like you do with traditional
  telnet doorgame activity.  I would say that the speed of the display would
  be equivalent to a 1200 Baud modem.

  The ODROID XU3 is a much more robust device and the speed delay seems
  almost unnoticable.

Required packages:
  qemu: apt-get install qemu
  socat: apt-get install socat
  todos: apt-get install tofrodos

Create freedos image:
  We will be creating a FreeDOS image to be used in our VM.

  I find it helpful to follow this howto when creating a FreeDOS image.

  I made my image to be 100MB.  I think that it may be quite a bit 
  larger than I need so you may be able to use something much smaller.

Configure 4DOS:
  Once you have a working FreeDOS VM, you will need to configure the boot 
  files for your needs:

  I find it easier to mount the image onto the local file system, and edit the
  files with VI.  To mount the image:

  1) Create a mount point:
  mkdir /mnt/freedos

  2) mount the image
  sudo mount -t msdos -o loop,offset=32256 ./freedos.img /mnt/freedos

  You can then cd to /mnt/freedos/ and edit your files.  You can also use
  this method for copying files to the DOS filesystem.  Don't forget to 
  unmount the image before running the VM.

  sudo umount /mnt/freedos

  The default boot scripts are C:\FDCONFIG.SYS and C:\FDOS\FDAUTO.BAT.
  The following has worked for me.  You will want to play with your own
  configuration to meet your own needs.


@echo off
SET PATH=%dosdir%\BIN
SET TEMP=%dosdir%\TEMP
alias reboot=fdapm warmboot
alias reset=fdisk /reboot
alias halt=fdapm poweroff
alias shutdown=fdapm poweroff
alias cfg=edit %cfgfile%
alias auto=edit %0

  Note how the batch file ends with CALL D:\RUN.BAT.  RUN.BAT is the 
  dynamically created batch file that gets created each time we run the script.

Setting up the doorgames:
  You will want to run the DOS VM initially, to setup your doorgames.  To do
  that, you just run qemu normally, but with the mounted local file system.
  I've written a simple batch file that will load the VM.

rm /home/bbs/temp${NODE}/run.bat

qemu-system-i386 \
-localtime \
/home/bbs/doors/qemu/freedos.img \
-boot c \
-hdb fat:/home/bbs \
-m 1024 

  If you are running this remotely, from a terminal like putty, you can add the
  -curses flag.  That will give you an interactive shell into the VM.

  The method used for running the VM will mount the /home/bbs directory as 
  the DOS D: drive.  This puts all the BBS subdirectories off of D:.  
  I have my doorgame files in /home/bbs/doors/ on the host filesystem.  
  My LORD directory is at /home/bbs/doors/lord.  When viewed from the DOS VM, 
  it will be located at D:\DOORS\LORD

  The dropfile locations will also be on your D: drive.

  or for node #2:

The working DOORS.SH script:
  This is the script as I have it working for me:

## Pass the parameters for the door and the node.

DOOR=`echo ${DOOR} | tr '[a-z]' '[A-Z]'`

## The linux path for the run.bat file
## The VM will be accessable via a computer port.  I have randomly selected
## 20200 as a base port number to use.  Each node will 'add' to the base 
## number.  IE, Node #1 will be added to 20200 and the result will be
## port 20201 (20200 + 1)
## You may change the base port to any number you wish.
portnum=`expr 20200 + ${NODE}`

case ${DOOR} in
	## Operation OverKill II
		echo "@echo off" > ${gobat}
		echo "D:" >> ${gobat}
		echo "CD \DOORS\OO" >> ${gobat}
		### Use the CALL command when calling a door batch file.
		### If not used, then the door batch file will not return
		### to the RUN.BAT script to complete execution.  If the 
		### RUN.BAT script does not complete execution, then it will
		### not shut down the VM.  It will then just go to a dos
		### prompt and the user will not see it, and will think that
		### the game is hung.
		echo "CALL OOIIDOOR.BAT ${NODE}" >> ${gobat}
	## Legend of the Red Dragon
		echo "@echo off" > ${gobat}
		echo "D:" >> ${gobat}
		echo "CD \DOORS\LORD" >> ${gobat}
		echo "CALL START.BAT ${NODE}" >> ${gobat}
		## Planets: The Exploration of Space
		echo "@echo off" > ${gobat}
		echo "D:" >> ${gobat}
		echo "CD \DOORS\PLAN" >> ${gobat}
		echo "PLANETS.EXE /pD:\TEMP${NODE}" >> ${gobat}
	## Barren Realms Elete
		echo "@echo off" > ${gobat}
		echo "D:" >> ${gobat}
		echo "CD \DOORS\BRE" >> ${gobat}
		echo "SRDOOR" >> ${gobat}
		echo "BRE" >> ${gobat}
	# Space Dynasty
		echo "@echo off" > ${gobat}
		echo "D:" >> ${gobat}
		echo "CD \DOORS\DYNASTY" >> ${gobat}
		echo "DYNASTY D:\TEMP${NODE}\DOOR.SYS" >> ${gobat}
	# NetRunner
		echo "@echo off" > ${gobat}
		echo "D:" >> ${gobat}
		echo "D:\DOORS\bnu\bnu" >> ${gobat}
		echo "CD \DOORS\NETRUN" >> ${gobat}
		echo "NETRUN D:\TEMP{NODE}\DOOR.SYS" >> ${gobat}
## At the end of run.bat, we add this line to gracefully shutdown the VM.
## This will return the user back to the BBS.
echo "C:\FDOS\BIN\FDAPM POWEROFF" >> ${gobat}
## The batch file must be in dos format, or it will not run properly.
todos ${gobat}

### The main QEMU call.
### 1) -localtime to pass the host clock to the VM
### 2) tell it to use the freedos.img
### 3) tell it to boot to the C: drive
### 4) Turn off all displays. Otherwise it will give errors or skewed displays
### 5) How many megabytes of memory to allow for the BM
### 6) Define a serial modem connection and assign a computer port
### 7) Mount the main BBS directory in RW mode
### The qemu call is loaded into the background.  We do this so that we can 
### spawn a concurrent socat process.
qemu-system-i386 \
-localtime \
/home/bbs/doors/qemu/freedos.img \
-boot c \
-display none \
-m 256 \
-serial telnet::${portnum},server,nowait,nodelay \
-hdb fat:rw:/home/bbs > /dev/null 2>&1 &

### Inform the user that it will take several seconds before the game
### loads up.
echo "Loading door... please be patient...."
sleep 3
### socat is used to communicate with the VM's serial modem.
socat -,raw,echo=0 TCP:localhost:${portnum}

if [ -f ${gobat} ]; then
        rm -rf ${gobat}

exit 0

Using the script:
  I use and have developed this method for Mystic BBS.  You will need to make
  appropriate adjustments if you use a different BBS package.

  The script is called from a menu option.  At the time of this writing, 
  Mystic BBS is currently at 1.12a4.  At this time, each door menu option 
  generates a specific dropfile.  Later versions of Mystic (I'm told) will
  have it so there is only one doorgame menu option, and it will generate
  every known dropfile in the user's temp directory.

  For now, you will need to call the proper doorgame menu option for the 
  doorgame it is intending to launch.  I try to use the DOOR.SYS dropfile
  whereever possible.  That Mystic Menu Option is DG.

  The parameters for the script are: DOOR NODE# /DOS

  The /DOS switch is used to create a DOS version of the drop file.  That way
  there is no need to run todos on the dropfile before calling the door. 

  Use %3 of course, as the MCI macro to pass the users' node number.

  Menu: DG
  Data: /home/bbs/doors/qemu/ LORD %3 /DOS

  That's all there is to it.  Your milage may vary.
  Darryl Perry
  Gryphon @ Cyberia BBS