Skip to content

Native v86 Emulation

ENiGMA½ includes a built-in x86/DOS emulator powered by v86 — a JavaScript x86 emulator that runs entirely within Node.js. The v86_door module boots a FreeDOS disk image and bridges COM1 directly to the user’s connection, with no external emulator installed on the server.


  1. ENiGMA½ generates the appropriate drop file for the user (DORINFO, DOOR.SYS, etc.)
  2. The drop file is written into a small in-memory FAT12 floppy image — no temp files on disk
  3. v86 boots the op-supplied FreeDOS disk image from the hard drive (C:)
  4. The drop file floppy is mounted as A: in FreeDOS
  5. The door’s AUTOEXEC.BAT copies the drop file from A: and launches the game
  6. COM1 serial I/O is bridged directly between v86 and the user’s connection
  7. When the door exits and FreeDOS powers off, the session ends cleanly
  8. When a session ends, however it ends, the image is written back to its file (see When writes reach the image file)

v86 requires SeaBIOS and a VGA BIOS image. The ENiGMA½ installer (misc/install.sh) downloads these automatically to misc/v86_bios/. To download manually:

Terminal window
mkdir -p misc/v86_bios
curl -fL https://github.com/copy/v86/raw/master/bios/seabios.bin -o misc/v86_bios/seabios.bin
curl -fL https://github.com/copy/v86/raw/master/bios/vgabios.bin -o misc/v86_bios/vgabios.bin

You need a raw FreeDOS disk image (.img) with your door game pre-installed. Raw .img images are fully compatible between QEMU, DOSBox-X, and v86 — set up your image with QEMU or DOSBox-X, then point v86_door at it on the production server.


ItemRequiredDescription
nameYesDoor name. Used as a key for tracking concurrent sessions.
imageYesPath to the raw FreeDOS disk image (.img).
dropFileTypeNoDrop file to generate and inject onto the A: floppy: DORINFO, DOOR, or DOOR32. Omit if the door needs no drop file. The connection is always reported as serial — the guest sees COM1.
runBatchNoMulti-line batch script written to A:\RUN.BAT at runtime. Supports variable substitution. See One Image, Multiple Doors.
nodeMaxNoMax concurrent sessions. 0 = unlimited.
tooManyArtNoArt spec to display when nodeMax is exceeded.
memoryMbNoGuest RAM in MB. Default: 64.
biosPathNoPath to SeaBIOS image. Default: misc/v86_bios/seabios.bin.
vgaBiosPathNoPath to VGA BIOS image. Default: misc/v86_bios/vgabios.bin.
disconnectGraceSecondsNoAfter a hangup, time-up or other move away from the door, how long the door gets to save and exit once carrier is dropped on COM1, 0 to 3600 (fractions allowed). 0 stops the emulator at once. The door’s slot (nodeMax) stays taken until it exits or this runs out. See When the caller leaves mid-game. Default: 30.
startTimeoutSecondsNoHow long the guest has to write its first byte to COM1, 0 to 3600 (fractions allowed). If nothing arrives in time the emulator is stopped, a warning naming the image is logged, and the caller is told the door could not be started and goes back to the previous menu. 0 waits for ever. Raise it, or set 0, for a door that runs long maintenance before it writes anything (some do on their first run each day): stopping one mid-way can leave its files half-written. See When the door does not start. Default: 120.
dropFileTypeFilename on A:
DORINFODORINFOx.DEF (x = node-based suffix per spec)
DOORDOOR.SYS
DOOR32door32.sys

When runBatch is set, ENiGMA replaces the following variables before writing RUN.BAT:

VariableDescriptionExample
{dropFile}Drop file filenameDORINFO1.DEF
{node}Node number1
{baud}Baud rate57600

Single-player door (PimpWars):

doorPimpWars: {
desc: Playing PimpWars
module: v86_door
config: {
name: PimpWars
image: /path/to/images/freedos_doors.img
dropFileType: DORINFO
nodeMax: 1
tooManyArt: DOORMANY
runBatch:
'''
@ECHO OFF
C:\FOSSIL\X00.SYS
COPY A:\{dropFile} C:\DOORS\PW\
CD C:\DOORS\PW
PW.EXE {node}
ECHO Returning to BBS, please wait... > COM1
'''
}
}

Multi-node door with shared game state (TradeWars 2002):

doorTradeWars2002: {
desc: TradeWars 2002
module: v86_door
config: {
name: TradeWars2002
image: /path/to/images/tw2002.img
dropFileType: DORINFO
nodeMax: 4
tooManyArt: DOORMANY
runBatch:
'''
@ECHO OFF
C:\FOSSIL\X00.SYS
C:\FREEDOS\BIN\SHARE.COM
COPY A:\{dropFile} C:\DOORS\TW2\{dropFile}
CD C:\DOORS\TW2
TW2.EXE
C:\FREEDOS\BIN\FDAPM POWEROFF
'''
}
}

Your disk image must contain:

  • A working FreeDOS installation
  • Your door game(s) installed (e.g. C:\DOORS\PIMPWARS\)
  • Optionally, a FOSSIL driver such as X00 — required by most classic DOS doors
  • An AUTOEXEC.BAT (or FDAUTO.BAT) that calls A:\RUN.BAT and powers off

Set up your image’s AUTOEXEC.BAT once. ENiGMA writes RUN.BAT to A: at runtime with the door-specific launch commands:

Terminal window
CALL A:\RUN.BAT
ECHO Shutting down, please wait... > COM1
FDAPM POWEROFF
  • CALL A:\RUN.BAT — executes the per-door launch script ENiGMA injects at runtime
  • ECHO ... > COM1 — sends a message to the user’s terminal while FreeDOS shuts down (can take a few seconds)
  • FDAPM POWEROFF — shuts FreeDOS down cleanly; placed after the CALL so it always fires even if the door crashes

Because RUN.BAT is generated at runtime, a single FreeDOS image can host multiple doors. Each door has its own menu entry pointing at the same image path with a different runBatch:

doorPimpWars: {
module: v86_door
config: {
name: PimpWars
image: /path/to/images/freedos_doors.img
dropFileType: DORINFO
nodeMax: 1
runBatch:
'''
COPY A:\{dropFile} C:\DOORS\PW\
C:\FOSSIL\X00.SYS
CD C:\DOORS\PW
PW.EXE {node}
ECHO Returning to BBS, please wait... > COM1
'''
}
}
doorSmurfCombat: {
module: v86_door
config: {
name: SmurfCombat
image: /path/to/images/freedos_doors.img // same image
dropFileType: DOOR
nodeMax: 1
runBatch:
'''
COPY A:\{dropFile} C:\DOORS\SMURF\
C:\FOSSIL\X00.SYS
CD C:\DOORS\SMURF
SMURF.EXE {node}
ECHO Returning to BBS, please wait... > COM1
'''
}
}

A session ends from the BBS side when the caller hangs up, when their time for the day runs out, or when anything else moves them on to another menu (an idle logoff, say). In each case the caller is detached from the door at once: nothing more the door writes reaches their terminal, and nothing they type reaches the door. A caller whose time is up goes straight to the time-up logoff screen.

The door is then told the line is gone, as a modem would tell it: ENiGMA½ drops carrier (DCD) on COM1, and the door gets disconnectGraceSeconds (30 by default) to save the player and exit. A door that reads COM1 through a FOSSIL driver such as X00 sees the carrier loss and handles it as it would on a real BBS. The session ends as soon as the emulator stops, so put FDAPM POWEROFF after the door in AUTOEXEC.BAT (see AUTOEXEC.BAT Convention): ENiGMA½ notices the powered-off guest within about a second. In testing, a FreeDOS guest set up this way had stopped about 12 seconds after carrier was dropped. A door that ignores carrier keeps running until the grace runs out and is then stopped. Either way the image is written back once the emulator has stopped, as described below.

  • The door’s slot stays taken during the grace, and so does the shared image: with nodeMax: 1, a caller who drops and dials straight back in may be told the door is busy until the door has exited. With nodeMax above 1, or 0 (unlimited), that caller starts a second guest on the same image while the first is still saving; use nodeMax: 1 for a door that keeps per-player state without locking, as the note on shared images above recommends.
  • A door that has not written anything to COM1 yet (still booting) gets no grace; it is stopped at once.
  • When the server shuts down, any grace still running is ended and the emulator stopped at once.
  • The caller’s time in the door is counted until they leave it, not until the grace ends.
  • Set disconnectGraceSeconds: 0 to stop the emulator at once, as before 0.6.0.

The caller sees a Loading <name>... spinner until the guest writes its first byte to COM1. If it writes nothing within startTimeoutSeconds (120 by default), the session is ended: a bad image, a BIOS file that loads but does not work, or a RUN.BAT that hangs before the door says anything. The log has a warning naming the image (v86 door wrote nothing to COM1 within 120 s; ending it), and the caller sees <name> could not be started. Please let the sysop know., a pause, and the previous menu. The same message is shown whenever the door cannot be started or ends before its first byte: a config problem (no name or image, an unsupported dropFileType), a missing BIOS or image file, an image that cannot be read, an emulator that cannot start, or a guest that halts or powers off without writing anything. Each is logged as a warning naming the problem. A caller who has hung up or whose time is up is shown nothing, and a caller turned away by nodeMax sees only the busy message (or tooManyArt). A healthy image boots to its first byte in a few seconds; allow more on a busy or small server.

While any session uses an image, ENiGMA½ works on a copy of it in memory, and writes that copy back over the file in place each time a session ends: when the door exits, when the caller hangs up or runs out of time, or when the emulator stops for any other reason. A door stopped before it has saved (it ignored carrier for longer than disconnectGraceSeconds, or the grace was 0) loses what it was still holding in memory (or in a DOS disk cache), as on a real BBS when a door is killed; what it had already written to the disk is kept. When the server shuts down, running sessions are ended and their images written back, with up to 5 seconds allowed for it (see Stopping).

When the last session using an image ends, ENiGMA½ keeps the copy for 10 minutes, so the next session starts without loading the image again; after that it lets go of it. A session that starts on a kept copy first checks the file: if it has changed on disk in the meantime (with oputil v86, say), it is read again. A write that fails (a full disk, a permissions problem) is logged, and the copy is kept, however long the door stays idle, until a later session’s end (or the server shutting down) writes it successfully; if the file was changed on disk in the meantime, the copy wins and a warning is logged.

Most classic DOS doors use the FOSSIL serial interface for COM1 I/O. If your door fails to start or falls back to local mode, a FOSSIL driver is needed. X00 works well with v86.

A FOSSIL driver also passes carrier loss on to the door: when the caller hangs up, ENiGMA½ drops DCD on COM1 and the door sees it through the FOSSIL, so it can save and exit (see When the caller leaves mid-game).

Load it from runBatch (per-door, recommended) rather than FDCONFIG.SYS (global):

Terminal window
C:\FOSSIL\X00.SYS

Or in FDCONFIG.SYS if all doors on the image need it:

DEVICE=C:\FOSSIL\X00.SYS

Creating and Configuring Images with oputil v86

Section titled “Creating and Configuring Images with oputil v86”

ENiGMA½ ships two oputil subcommands for working with disk images without needing QEMU or DOSBox-X installed on the server:

oputil.js v86 console <image.img> Boot and wire COM1 to this terminal (interactive)
oputil.js v86 desktop <image.img> Boot in a full VGA browser session

console — best for doors that output entirely through COM1 (most doors). Use CTTY COM1 in the image’s FDAUTO.BAT to redirect all I/O. Ctrl+] exits and saves changes back to the image file automatically.

desktop — boots the image in a small local HTTP server and opens your browser to a full VGA canvas. Use this for setup programs that write directly to VGA (e.g. door configuration wizards). Click Save Image to write changes back to the image file on the server — no browser download dialog appears.

Terminal window
# Interactive COM1 terminal
node core/oputil/oputil_main.js v86 console /path/to/tw2002.img
# Full VGA browser session (opens browser automatically)
node core/oputil/oputil_main.js v86 desktop /path/to/tw2002.img --port 18086

See also: oputil.js fat for listing and copying files into images without booting them.

Terminal window
# Create a 500MB raw image
qemu-img create -f raw freedos_mygame.img 500M
# Install FreeDOS (boot from CD)
qemu-system-i386 -hda freedos_mygame.img -cdrom FD14CD.iso -boot d
# Boot into FreeDOS to install your door
qemu-system-i386 -hda freedos_mygame.img
# Transfer files from host using QEMU's vfat driver — files appear on D:
qemu-system-i386 -hda freedos_mygame.img -hdb fat:/path/to/door/files

DOSBox-X is a graphical alternative for image setup on Windows, macOS, and Linux. See the DOSBox-X documentation for imgmount.

FreeDOS Boot Configuration for Fast Startup

Section titled “FreeDOS Boot Configuration for Fast Startup”

For ~5 second boot times, configure FreeDOS to use Emergency Mode (no memory managers, no networking). In FDCONFIG.SYS:

MENUDEFAULT=5,0

Ensure the 5? config block loads your FOSSIL driver:

5?DEVICE=C:\FOSSIL\X00.SYS
5?SHELL=C:\FreeDOS\BIN\COMMAND.COM C:\FreeDOS\BIN /E:1024 /P=C:\FDAUTO.BAT