===============================================================================
                          RGFOSSIL v1.04 for Windows
              Revision 5 FOSSIL driver and WinSock engine for DOS BBSes
                         (c) 2026 NewWave Software
===============================================================================

 CONTENTS
   1.  What RGFOSSIL is
   2.  The files
   3.  How it works (the big picture)
   4.  Installing
   5.  Setting up RGTEL (or Net2BBS)
   6.  RGFOSSIL.COM   - the FOSSIL driver
   7.  RGFOSSIL.DLL   - the FOSSIL engine
   8.  RGCOM.EXE      - the WinSock engine
   9.  RGFL.EXE       - dropfiles and Win32 doors (the NFU replacement)
   9a. Non-FOSSIL DOS doors - the virtual COM port (RGFL /V)
  10.  Dropfile layouts written by RGFL
  11.  Complete examples
  12.  Moving from NetFoss
  13.  Troubleshooting
  14.  Diagnostic tools (RGDIAG, RGVDDT, RGNULL)
  15.  Technical reference (FOSSIL functions, IPC names)


===============================================================================
 1. WHAT RGFOSSIL IS
===============================================================================

 DOS BBS software and DOS door games talk to the caller through a FOSSIL
 driver (INT 14h). On a real 1990s BBS the FOSSIL drove a modem. On Windows
 there is no modem - callers arrive by telnet - so something has to pretend
 to be a serial port and pass the bytes to a TCP socket.

 RGFOSSIL does exactly that. It is a switch-for-switch replacement for the
 NetFoss 1.26 package: the same design, the same command lines, the same
 batch file flow, so an existing NetFoss setup moves over by changing paths.

 Requirements
   * 32-bit Windows (XP / Vista / 7 / 8 / 10 32-bit) with NTVDM
     -> the files in BIN\ (RGFOSSIL.COM, RGFOSSIL.DLL, RGCOM.EXE ...), or
     64-bit Windows with NTVDMx64
     -> the files in BIN64\ (RGFOSS64.COM, RGFOSSIL64.DLL, RGCOM64.EXE ...),
        see section 16
   * A telnet server that passes the node number and the socket handle
     (RGTEL or Net2BBS)


===============================================================================
 2. THE FILES
===============================================================================

   RGFOSSIL.COM   DOS TSR, the FOSSIL driver itself (replaces NETFOSS.COM)
   RGFOSSIL.DLL   the FOSSIL engine, loaded into NTVDM (replaces NETFOSS.DLL)
   RGCOM.EXE      WinSock engine - owns the socket (replaces NETCOM.EXE)
   RGCOM.INI      RGCOM settings (same keys as NETCOM.INI)
   RGFL.EXE       dropfile converter / Win32 door launcher (replaces NFU.EXE),
                  and launcher for non-FOSSIL DOS doors (/V, section 9a)
   RGFOSSIL.BAT   node batch file (replaces NF.BAT)
   RGTEL.INI      sample RGTEL configuration for RGFOSSIL
   RGDIAG.EXE     checks that Windows can load RGFOSSIL.DLL
   RGVDDT.COM     checks that NTVDM can load RGFOSSIL.DLL
   RGNULL.DLL     empty test DLL used with RGVDDT

 BIN64\ holds the same set for 64-bit Windows with NTVDMx64 (section 16):
   RGFOSS64.COM   RGFOSSIL64.DLL   RGCOM64.EXE   RGCOM64.INI   RGFL64.EXE
   RGFOSSIL64.BAT RGDIAG64.EXE     RGVDDT64.COM  RGNULL64.DLL  RGTEL.INI

   NetFoss file     RGFOSSIL file
   ------------     -------------
   NETFOSS.COM      RGFOSSIL.COM
   NETFOSS.DLL      RGFOSSIL.DLL
   NETFOS64.COM     RGFOSS64.COM       (64-bit Windows / NTVDMx64)
   NETFOS64.DLL     RGFOSSIL64.DLL     (64-bit Windows / NTVDMx64)
   NETCOM.EXE       RGCOM.EXE  (RGCOM64.EXE on 64-bit Windows)
   NETCOM.INI       RGCOM.INI
   NFU.EXE          RGFL.EXE
   NF.BAT           RGFOSSIL.BAT


===============================================================================
 3. HOW IT WORKS
===============================================================================

   caller --telnet--> RGTEL --starts--> RGFOSSIL.BAT <node> <socket> ...
                                           |
         1. RGFOSSIL.COM /N<node>          |  loads the FOSSIL into this
            (loads RGFOSSIL.DLL into NTVDM)|  console's NTVDM
                                           |
         2. RGCOM.EXE /N<node> /H<socket> TEL2RG.BAT ...
            - telnet setup with the caller
            - runs your BBS batch in the SAME console
            - socket  <--pipes-->  RGFOSSIL.DLL  <--INT 14h-->  BBS / doors
                                           |
         3. RGFOSSIL.COM /U                |  unload when the BBS is done

 * The DOS side (the BBS, DOS doors) only ever sees an ordinary FOSSIL.
 * RGCOM owns the telnet socket. It passes bytes to and from RGFOSSIL.DLL
   through two named pipes, and handles the telnet protocol (IAC codes).
 * When a Win32 (DOOR32) door must run, RGFL asks RGCOM to start it. RGCOM
   owns the socket, so the door can use it directly; the pipes pause until
   the door exits, then everything carries on.
 * Everything is per node, so any number of nodes run side by side.


===============================================================================
 4. INSTALLING
===============================================================================

 1. Create D:\RGFOSSIL (any folder works; the batch file below assumes it)
    and copy all files from BIN\ into it.
    64-bit Windows with NTVDMx64: use BIN64\ instead and follow section 16
    (the steps are the same, only the file names carry "64").

 2. Copy RGFOSSIL.DLL into C:\Windows\System32 as well.
    Use an administrator command prompt:

        copy /y D:\RGFOSSIL\RGFOSSIL.DLL C:\Windows\System32\

    NTVDM finds the DLL by its plain name (System32 first), exactly the way
    it finds NETFOSS.DLL. Keep both copies identical - when you
    update, copy the new DLL to BOTH places. A stale System32 copy is what
    actually runs.

 3. Edit D:\RGFOSSIL\RGFOSSIL.BAT if your folder is not D:\RGFOSSIL.

 4. Point your telnet server at RGFOSSIL.BAT (section 5).

 5. In your BBS setup, use a FOSSIL COM port (COM1 is fine) and any locked
    baud rate. The port number does not matter; each node is kept apart by
    the node number.

 Optional check (plain command prompt, no nodes running):

        cd /d D:\RGFOSSIL
        RGFOSSIL /N9          (prints nothing = loaded OK)
        RGFOSSIL /U           (prints nothing = unloaded OK)


===============================================================================
 5. SETTING UP RGTEL (OR NET2BBS)
===============================================================================

 RGTEL.INI - the lines that matter:

   Command=D:\RGFOSSIL\RGFOSSIL.BAT /N*N /H*H D:\BATCH\TEL2RG.BAT *N *H *I
   StartPath=D:\RGFOSSIL
   Nodes=4
   HighNodeIPs=168.235.108.229, 168.235.86.87, 198.46.217.114

   *N = node number     *H = socket handle     *I = caller IP

 The Command line is: launcher batch, then /N and /H for RGFOSSIL and
 RGCOM, then YOUR BBS batch and its parameters. Your BBS batch receives
 %1 = node, %2 = socket handle, %3 = IP.

 RGTEL also sets two environment variables for every node:
   SOCKET = the socket handle      NFNODE = the node number
 RGFL needs both. (Your batch may set them again - that is fine.)

 Node numbers are chosen by RGTEL, not by RGFOSSIL: normally the lowest
 free node. HighNodeIPs lists callers (for example the fTelnet web proxies)
 that are given the HIGHEST free node instead, so ordinary callers keep
 getting node 1, 2, 3 from the bottom up.

 Net2BBS works the same way; use its Command setting with *N and *H.


===============================================================================
 6. RGFOSSIL.COM - THE FOSSIL DRIVER
===============================================================================

 RGFOSSIL /N{value} [switches]
 Same switches as NETFOSS.COM. Letters may be upper or lower case, and "-"
 works in place of "/".

   /N{value}  Node number. Must match RGCOM's /N. Without /N, the node is
              taken from DOOR32.SYS in the current folder (line 11), then
              the NFNODE environment variable, then node 1 - the same
              order NetFoss uses.

 Anything on the command line that does not start with "/" or "-" (a door
 path, a BAT file name, %2 %3 ...) is skipped, so a line like
 "RGFOSSIL.COM %1 %2 D:\DOORS\LORD\START.BAT" is safe.
   /C{value}  COM mode: talk to real serial port COM{value} instead of RGCOM
              (for a modem or a null-modem line).
   /L{value}  Locked baud rate, e.g. /L38400 or /L115200. Reported to
              programs by FOSSIL function 1Bh; in COM mode it also sets the
              real port speed.
   /S{value}  Slow output: pause 1 ms after every {value} characters.
              /S alone = every 64. Also makes idle status calls yield more
              often.
   /T{value}  I/O timeout: hang up if the caller types nothing for {value}
              minutes.
   /Z{value}  PDZmodem tweak (accepted for compatibility; reserved).
   /D{value}  DESQview time-slicing: emulate the DESQview API so programs
              that "give up time slices" the DESQview way release the CPU
              for {value} ms each time.
   /R         Allow COM release: FOSSIL de-init (05h) closes the real COM
              port so another program can open it (COM mode).
   /X         X00 kluge: X1 = on, X0 = off. When on, an empty receive (02h)
              returns the line status with the timeout bit (X00 style);
              when off it returns 8000h (NetFoss style).
   /I         DOS I/O: I1 = on, I0 = off. When on, plain DOS screen output
              (INT 29h) is also sent to the caller, and the caller's keys
              arrive through the BIOS keyboard (INT 16h). This lets
              non-FOSSIL DOS doors work.
   /F         Fake RIP reply: answer the RIP query (ESC[!) with
              RIPSCRIP015400 so programs believe the caller has RIP.
   /M         Modify: change the settings of the driver already loaded.
   /MR        Modify + reset: like /M, but first return the locked baud
              and slow/PDZ settings to their defaults.
   /U         Uninstall (unload). Refuses if another TSR has hooked the same
              interrupts since.
   /?         Show the switch list.

 Loading is silent. RGFOSSIL.COM prints nothing on success; it only prints
 on an error (or /?). Errorlevel: 0 = OK, 1 = error, 2 = not NTVDM,
 3 = usage shown.

 Error messages
   Can't load RGFOSSIL.DLL (error n) or D:\...\RGFOSSIL.DLL (error n)
        NTVDM would not load the DLL. See section 13.
        n: 1 = load failed, 2 = VDDDispatch missing, 3 = VDDInit missing,
           4 = out of memory / VDD table full
   Node in use            this node number is already loaded somewhere
   Can't open COM port    /C port missing or used by another program
   Can't create node pipes  another copy of this node is still running
   Not NT - ...           not running under NTVDM / NTVDMx64
   RGFOSSIL is not installed   /U or /M with nothing loaded

 Examples
   RGFOSSIL /N1                    node 1, telnet mode
   RGFOSSIL /N2 /L115200           node 2, report 115200 baud
   RGFOSSIL /N3 /I1                node 3, DOS I/O for non-FOSSIL doors
   RGFOSSIL /N1 /T10               hang up after 10 idle minutes
   RGFOSSIL /N1 /D5                DESQview time-slicing, 5 ms per slice
   RGFOSSIL /N4 /C2 /L38400 /R     real COM2 at 38400, release on de-init
   RGFOSSIL /M /S32                change the loaded driver: slow output
   RGFOSSIL /MR                    back to default settings
   RGFOSSIL /U                     unload


===============================================================================
 7. RGFOSSIL.DLL - THE FOSSIL ENGINE
===============================================================================

 RGFOSSIL.DLL is an NTVDM "virtual device driver". RGFOSSIL.COM loads it
 into NTVDM; every FOSSIL call a DOS program makes is handed to it.

 * Keep it in C:\Windows\System32 AND next to RGFOSSIL.COM. RGFOSSIL.COM
   loads it by plain name first (System32) and uses its own folder only as
   a fallback.
 * It needs nothing unusual: only kernel32, user32 and oleaut32.
 * Idle behaviour copies NetFoss: reads and peeks never sleep, and the
   status call sleeps 10 ms once every 4000 idle calls (400 with /S). DOS
   programs that poll in a loop therefore run at full speed - RIP and ANSI
   detection finish instantly - at the cost of CPU while they poll.


===============================================================================
 8. RGCOM.EXE - THE WINSOCK ENGINE
===============================================================================

 RGCOM [/N<node>] [/H<handle>] [/C] [/D<n>] [/B<n>] <command line>
 Same switches as NETCOM.EXE.

   /N<node>     node number (must match RGFOSSIL.COM /N)
   /H<handle>   the telnet socket handle from the server (*H)
   /H-          no socket: local mode, just run the command
   /C           no socket: COM port mode, just run the command
   /D<n>        write delay (same as writedelay= in RGCOM.INI)
   /B<n>        largest block sent at once (same as BufferMax=)
   /S /W        accepted for NETCOM compatibility, ignored

 <command line> is the program or batch to run - normally your BBS batch
 and its parameters. A .BAT or .CMD is run through the command interpreter
 (COMSPEC), so the DOS programs in it share this console and the NTVDM
 where RGFOSSIL is loaded.

 With neither /N nor /H, the node and handle are read from DOOR32.SYS in
 the current directory (line 1 = type, 2 = handle, 11 = node).

 What RGCOM does
   1. Sends the telnet setup NetCom sends: WILL ECHO, DONT ECHO,
      WILL/DO BINARY, WILL/DO SGA. No banner - the caller sees nothing.
   2. Connects to RGFOSSIL.DLL's pipes for the node.
   3. Starts <command line>.
   4. Passes data both ways. From the caller, telnet commands are removed
      and IAC IAC becomes FFh; every other byte (CR, LF, NUL ...) passes
      untouched, so Zmodem and other binary transfers work. To the caller,
      FFh is doubled.
   5. Stops when the BBS exits, the caller disconnects, the BBS drops DTR
      (hang up), or a file STOPNODE.<node> appears in RGCOM's folder
      (e.g. STOPNODE.2 hangs up node 2).
   6. After a hang-up it waits for the BBS to finish its logoff (or kills
      it after ForceClose= seconds), then exits.
   It also runs Win32 doors for RGFL (section 9).

 RGCOM.INI (next to RGCOM.EXE)
   [Settings]
   non-blocking=1   1 = non-blocking socket (default), 0 = blocking,
                    2 = leave the socket as the server gave it
   writedelay=0     ms to pause after each block sent to the caller
   writedelay2=0    ms to pause when a send had to be split (BufferMax)
   BufferMax=2048   largest block sent at once (bytes, up to 8192)
   ForceClose=0     after the caller drops, kill the BBS if it is still
                    running after this many seconds (0 = wait forever)

 Error messages
   Invalid Socket Handle     /H value is not a live socket
   Node already in use       another RGCOM is running this node
   RGCOM can not communicate with RGFOSSIL (load RGFOSSIL.COM /N<n> first)
                             RGFOSSIL.COM for this node was not loaded
   Can't find RGFOSSIL       the DLL's pipes did not answer
   Error executing external application   <command line> could not start
   No Command Line.          nothing to run


===============================================================================
 9. RGFL.EXE - DROPFILES AND WIN32 DOORS (THE NFU REPLACEMENT)
===============================================================================

 RGFL does four jobs for a DOS BBS:
   * Creates DOOR32.SYS from the BBS's DOOR.SYS, so Win32 doors can run.
   * Launches a Win32 (DOOR32) door and waits for it to finish.
   * Converts DOOR.SYS to DORINFO1.DEF or CHAIN.TXT, or rewrites DOOR.SYS
     for local mode.
   * Runs a DOS door that has no FOSSIL support on a virtual COM port
     (/V - section 9a).
 Same parameters as NFU.EXE, so door menu entries only change NFU -> RGFL.

 SYNTAX

   RGFL <path to DOOR.SYS> ["door command line"] [options]

   <path to DOOR.SYS>   the FOLDER holding DOOR.SYS (not the file name).
                        "." = current folder.
                        NULL = don't read or write any dropfile, just launch.
                        COMPORT means the same as NULL.
   "door command line"  the Win32 door and its parameters, IN QUOTES.
                        Leave it out to only create the dropfile.

   Shortcuts inside the door command line:
     $   is replaced by the dropfile folder, with a trailing backslash
     ^   is replaced by the full path of DOOR32.SYS

 OPTIONS

   /C      Create CHAIN.TXT only (WWIV format) instead of DOOR32.SYS
   /D      Create DORINFO1.DEF only instead of DOOR32.SYS
   /M      Only modify DOOR.SYS (rewrite it for local mode - see below)
   /L      Local mode: COM0: and 0 baud in the DOS dropfile. With nothing
           else, rewrites DOOR.SYS. Also works with /C and /D.
   /H      Use the user's handle (alias) instead of the real name
   /Q      Quiet: only error messages
   /R      RIP enable: if DOOR.SYS says RIP, pass RIP on (emulation 3).
           Without /R, a RIP caller is treated as ANSI.
   /YN     Answer a Win32 door's "use ANSI?" question automatically:
           sends Y, or N for a non-ANSI caller
   /K="x"  Type keys into the door when it starts. Macros:
             |   Enter
             !N  user's real name   (!R also works)
             !A  user's alias
             !P  user's password
           Macros are case sensitive.
   /V[n][,irq]
           Run a DOS door that talks to the COM port hardware directly (no
           FOSSIL support) on virtual COM port n, 1-4 (default 1). Optional
           IRQ, e.g. /V3,5. See section 9a.
   /DTR    With /V: let the door hang up the caller by dropping DTR.

 ENVIRONMENT (set by RGTEL/Net2BBS, or in your batch)
   SOCKET   socket handle - written into DOOR32.SYS line 2. Required when
            creating DOOR32.SYS.
   NFNODE   node number - tells RGFL which node's RGCOM to ask to launch
            the door. Required when launching.

 WHAT HAPPENS WHEN A WIN32 DOOR IS LAUNCHED
   1. RGFL writes DOOR32.SYS (unless NULL).
   2. It replaces $ and ^ in the command line.
   3. It sends the command line and the current folder to the RGCOM of
      node %NFNODE%.
   4. RGCOM pauses the FOSSIL pipes and starts the door in the same console
      window, with the socket available to it.
   5. /YN and /K keys are typed into that console.
   6. RGFL waits. When the door exits, RGCOM resumes the pipes and RGFL
      returns to the BBS.

 MESSAGES
   <file> created.            dropfile written
   <file> altered.            DOOR.SYS rewritten (/M or /L)
   Attempting to launch: ...  door being started
   RGFL has completed.        door finished
 Errors (RGFL beeps 3 times, waits, and exits with errorlevel 1):
   RGFL Error: File Not Found: <path>DOOR.SYS
   RGFL Error: Environment Variable %SOCKET% not found!
   Warning:RGFL failed to find %NFNODE% environment variable.
   Door32 command line is aborted.     (no NFNODE, so no launch)
   Invalid Node Number                 NFNODE missing or not 1-3 digits
   RGFL Error: Can't find RGCOM        RGCOM for that node isn't running
   RGFL Error: File Not Found!         the door program couldn't be started
   RGFL Error: Failed to create / Can't write to <file>
 With /V (section 9a):
   RGFL Error: RGFOSSIL node n not found     RGFOSSIL.COM /Nn not loaded, or
                                             System32 has an old RGFOSSIL.DLL
   RGFL Error: RGFOSSIL.DLL is too old for /V   update the System32 copy
   RGFL Error: COMn is owned by Windows ...  use another /V port number
   RGFL Error: /V needs a door command line in quotes

 EXAMPLES

   Create DOOR32.SYS in the node folder and run a Win32 door:
     RGFL C:\RG\NODE1 "D:\DOORS\DARK32\DARK32.EXE /N1"

   Current folder, and hand the door the DOOR32.SYS path with ^:
     RGFL . "D:\DOORS\WORDLE\WORDLE.EXE -D^"
     -> WORDLE.EXE -DC:\RG\NODE1\DOOR32.SYS

   Door that wants the dropfile FOLDER, using $:
     RGFL C:\RG\NODE1 "D:\DOORS\LORD32\LORD32.EXE -P$"
     -> LORD32.EXE -PC:\RG\NODE1\

   Only create DOOR32.SYS (a door that finds it by itself):
     RGFL C:\RG\NODE1

   Door that asks "Use ANSI? (Y/N)" - answer it automatically:
     RGFL . "D:\DOORS\BRE32\BRE32.EXE" /YN

   Type the user's name and Enter at the door's login prompt:
     RGFL . "D:\DOORS\GAME32\GAME32.EXE" /K="!N|"

   Name, Enter, password, Enter:
     RGFL . "D:\DOORS\GAME32\GAME32.EXE" /K="!N|!P|"

   Use the handle instead of the real name:
     RGFL . "D:\DOORS\GAME32\GAME32.EXE" /H

   Pass RIP through for RIP callers:
     RGFL . "D:\DOORS\RIPGAME\RIPGAME.EXE" /R

   Quiet (no messages on the caller's local screen):
     RGFL . "D:\DOORS\DARK32\DARK32.EXE" /Q

   Launch without touching any dropfile (the door makes its own):
     RGFL NULL "D:\DOSBOX\DOSBOXDOOR.BAT"

   Convert for a DOS door that wants DORINFO1.DEF:
     RGFL C:\RG\NODE1 /D
     D:\DOORS\OLDGAME\OLDGAME.EXE C:\RG\NODE1\DORINFO1.DEF

   Convert for a WWIV-style door that wants CHAIN.TXT:
     RGFL C:\RG\NODE1 /C

   Local (sysop) play - rewrite DOOR.SYS to COM0:/0 baud:
     RGFL C:\RG\NODE1 /L
   Local DORINFO1.DEF / CHAIN.TXT:
     RGFL C:\RG\NODE1 /D /L
     RGFL C:\RG\NODE1 /C /L

   As a door menu command line (DOOR.SYS written to the node folder by the
   BBS), the whole entry is simply:
     D:\RGFOSSIL\RGFL C:\RG\NODE%1 "D:\DOORS\DARK32\DARK32.EXE /N%1"


===============================================================================
 9a. NON-FOSSIL DOS DOORS - THE VIRTUAL COM PORT (RGFL /V)
===============================================================================

 Some old DOS doors ignore FOSSIL and program the serial chip directly
 (the 8250/16550 UART at 3F8h, IRQ 4 and so on). On a telnet node there is
 no such chip, so these doors hang or say "no carrier".

 RGFL /V runs such a door with a virtual COM port. RGFOSSIL.DLL emulates a
 16550A UART on the port you choose, and every byte the door sends or
 receives goes through the same path as FOSSIL calls: the node's RGCOM and
 the caller's telnet session. The door's own setup just uses "COM1" (or
 2-4) in UART / direct / hardware mode, NOT FOSSIL.

 SYNTAX
   RGFL /V[n][,irq] "DOS door command line" [/DTR] [options]
   RGFL <path to DOOR.SYS> "DOS door command line" /V[n][,irq] [/DTR] [options]

   With /V the dropfile path can be left out - give just the door command
   line in quotes. (NULL or COMPORT in its place also means "no dropfile".)
   Switches may come before or after the command line.

   /V      virtual COM1 (3F8h, IRQ 4)
   /V2     virtual COM2 (2F8h, IRQ 3)
   /V3     virtual COM3 (3E8h, IRQ 4)
   /V4     virtual COM4 (2E8h, IRQ 3)
   /V3,5   COM3 address with IRQ 5 (IRQ 3 to 15)
   /Bn     line speed in bps, e.g. /B38400. Without it the line runs at the
           baud rate the door programs into the port (never below 19200),
           like a real serial line. /B0 = no limit at all (the 1.03 way).
   /DTR    let the door hang up the caller by dropping DTR. Without it, a
           DTR drop is ignored, because many door kits drop DTR when they
           exit and the caller should return to the BBS, not be cut off.
           Real carrier loss always reaches the door, as a modem-status
           interrupt with DCD dropped.

   /C /D /M /L work as usual, to write the dropfile the door wants first.
   Without them, /V does not write any dropfile and needs no %SOCKET%.
   /Q /YN /K work as usual. $ and ^ in the command line work as usual.

   NFNODE must be set (RGTEL does it), or DOOR.SYS line 4 gives the node.
   RGFL exits with the door's errorlevel.

 EXAMPLES
   DOOR.SYS already written by the BBS in C:\RG\NODE1:
     RGFL C:\RG\NODE1 "D:\DOORS\OTHELLO\OTHELLO.EXE GAME.CFG" /V

   No dropfile handling at all (the usual case):
     RGFL /V1 "D:\DOORS\OTHELLO\OTHELLO.EXE GAME.CFG"

   A door batch file, run from D:\TEMP:
     CD\TEMP
     D:\RGFOSSIL\RGFL /V1 "\RGCOM\BATCH\AC6.BAT"

   A door batch file that wants DORINFO1.DEF:
     RGFL C:\RG\NODE1 /D "D:\DOORS\OLDGAME\START.BAT" /V

   A door that should be able to hang up:
     RGFL . "D:\DOORS\CHAT\CHAT.EXE" /V /DTR

 HOW IT WORKS
   * When RGFOSSIL.COM loads a node, RGFOSSIL.DLL takes over the I/O ports
     of COM1-COM4, but only the ones NTVDM itself is not using. Until a /V
     door runs they read as "no serial port here" (FFh), just like an
     empty port, so other programs see no difference.
   * RGFL /V asks the node's DLL, through the rgfossil_uart_<node> shared
     block, to emulate a 16550A on that port, then runs the door. The door
     runs in the same NTVDM, the one RGFOSSIL is loaded in, just like the
     BBS does. When the door exits, RGFL switches the emulation off again.
   * Emulated: divisor latch, IER, IIR, FIFO control (16550A detection
     works), LCR, MCR, LSR, MSR with delta bits, scratch, and full
     loopback mode, so the doors' UART detection passes. Interrupts arrive
     on the IRQ only while the door sets OUT2, as on real hardware.
   * The line runs at real serial speed both ways: the baud rate the door
     sets on the port (minimum 19200), or /Bn. Output takes its line time
     before the door may send more, as on a real UART, so doors that time
     their screens by the line (Yankee Trader and other QuickBASIC doors)
     no longer run too fast. Input arrives at the same rate, so a pasted
     command script reaches the door as it would from a real modem.
   * Parity and stop bits set by the door are accepted and ignored.

 COM PORTS WINDOWS ALREADY HAS
   If the PC has a real COM port (or a USB serial adapter, NetSerial and
   the like), NTVDM keeps that port number for itself and RGFL says:
     RGFL Error: COM1 is owned by Windows on this PC - use another port,
                 e.g. /V3 or /V4
   Pick a free number and set the door to the same COM port.

===============================================================================
 10. DROPFILE LAYOUTS WRITTEN BY RGFL
===============================================================================

 "DS n" means line n of the BBS's DOOR.SYS.
 Name = DS 10 (real name), or DS 36 (handle) with /H.

 DOOR32.SYS                         DORINFO1.DEF
  1  2  (telnet)                     1  RGFossil (BBS name)
  2  %SOCKET%                        2  sysop first name (DS 35)
  3  baud (DS 2)                     3  sysop last name  (DS 35)
  4  RGFossil (BBS ID)               4  COM port (DS 1, no ':'), or COM0
  5  user record # (DS 26)           5  "<DS 5> BAUD-R,N,8,1",
  6  Name                               or "0 BAUD-R,N,8,1" with /L
  7  handle (DS 36)                  6  0
  8  security level (DS 15)          7  user first name (Name)
  9  minutes left (DS 19)            8  user last name  (Name)
 10  emulation: 0 ASCII, 1 ANSI,     9  location (DS 11)
     3 RIP (only with /R)           10  emulation (0/1/3)
 11  node (DS 4)                    11  security level (DS 15)
                                    12  minutes left (DS 19)

 CHAIN.TXT (WWIV, 32 lines)
  1 user # (DS 26)    2 alias (DS 36)      3 Name        4 Tango
  5 18                6 M                  7 DS 42       8 last on (DS 17)
  9 80               10 lines (DS 21)     11 SL (DS 15) 12 0
 13 0                14 emulation         15 1 (0 with /L)
 16 seconds left (DS 18)  17 C:\WWIV\GFILES\  18 C:\WWIV\DATA\
 19 bbs.log          20 baud (DS 2, 0 with /L)
 21 COM port number (0 with /L)            22 RGFossil
 23 sysop (DS 35)    24 0                 25 0
 26 upload K (DS 48) 27 uploads (DS 28)   28 download K (DS 49)
 29 downloads (DS 29)          30 8N1     31 COM speed (DS 5)
 32 node (DS 4)

 DOOR.SYS with /M or /L: line 1 COM0:, line 2 0, line 10 Name, every other
 line unchanged.

 Differences from NFU 1.26 (deliberate):
   * "RGFossil" where NFU writes "NetFoss".
   * CHAIN.TXT: NFU leaves out line 21, shifting every later field by one.
     RGFL writes all 32 lines.
   * DORINFO1.DEF with /H and a one-word handle: NFU writes a garbage line.
     RGFL writes an empty last name.
   * /K really types the keys (NFU 1.26 accepts /K but never sends them).


===============================================================================
 11. COMPLETE EXAMPLES
===============================================================================

 --- RGFOSSIL.BAT (the node launcher; ships in BIN\) -----------------------

   @echo off
   d:\rgfossil\rgfossil.com %1
   if errorlevel 1 goto loadfail
   d:\rgfossil\rgcom.exe %1 %2 %3 %4 %5 %6 %7 %8 %9
   d:\rgfossil\rgfossil.com /u
   goto end
   :loadfail
   echo.
   echo RGFOSSIL did not load for node %1 - see the message above.
   timeout /t 15
   :end

   RGTEL runs it as:
     RGFOSSIL.BAT /N1 /H228 D:\BATCH\TEL2RG.BAT 1 228 73.174.148.143
   so %1 = /N1 and %2 = /H228 go to RGFOSSIL.COM and RGCOM, and RGCOM runs
   "D:\BATCH\TEL2RG.BAT 1 228 73.174.148.143".

 --- A BBS batch (TEL2RG.BAT style) -----------------------------------------

   @ECHO OFF
   SET SOCKET=%2
   SET NFNODE=%1
   D:
   CD\BBS
   RENEGADE -B57600 -Q -N%1 -IP%3 -T
   IF ERRORLEVEL 2 GOTO NEW_MAIL
   GOTO END
   :NEW_MAIL
   RENEMAIL -S -A
   :END

 --- A local test without a caller ------------------------------------------

   From a plain command prompt:
     D:\RGFOSSIL\RGFOSSIL.BAT /N1 /H- D:\BATCH\TEL2RG.BAT 1 0 127.0.0.1
   /H- runs the batch in local mode, so any error stays on screen.

 --- A real COM port / modem node ------------------------------------------

   d:\rgfossil\rgfossil.com /N5 /C1 /L38400 /R
   d:\rgfossil\rgcom.exe /N5 /C C:\RG\RENEGADE.EXE -N5
   d:\rgfossil\rgfossil.com /u

 --- Win32 BBS running a DOS door ------------------------------------------

   A Win32 BBS (Mystic, Synchronet, EleBBS/W32, ...) already has the
   caller's socket and writes DOOR32.SYS. To run an old DOS door on that
   node, have the BBS run a small batch from the node folder that holds
   DOOR32.SYS, with no /N needed:

   DOSDOOR.BAT (BBS door command: DOSDOOR.BAT D:\DOORS\LORD\START.BAT)
     @echo off
     d:\rgfossil\rgfossil.com
     if errorlevel 1 goto end
     d:\rgfossil\rgcom.exe %1 %2 %3 %4 %5 %6 %7 %8 %9
     d:\rgfossil\rgfossil.com /u
     :end

   RGFOSSIL.COM and RGCOM.EXE both read the node (line 11) and RGCOM reads
   the socket handle (line 2) from DOOR32.SYS in the current folder, so
   they always agree. The door itself just uses the FOSSIL on COM1.

   When the door exits normally, RGCOM leaves the connection open and the
   caller goes straight back to the Win32 BBS - no carrier drop. (A door
   that drops DTR, or a caller who hangs up, still ends the call.)

   If the BBS can pass the node and handle itself, that works as well:
     RGFOSSIL.BAT /N%NODE% /H%HANDLE% D:\DOORS\LORD\START.BAT
   (use your BBS's own codes for node and socket handle).

 --- Hanging up a node from outside ---------------------------------------

   echo x > D:\RGFOSSIL\STOPNODE.2        (hangs up node 2)


===============================================================================
 12. MOVING FROM NETFOSS
===============================================================================

 1. Install as in section 4.
 2. In RGTEL.INI / Net2BBS change
      D:\NETFOSS\NF.BAT        ->  D:\RGFOSSIL\RGFOSSIL.BAT
      StartPath=D:\NETFOSS     ->  StartPath=D:\RGFOSSIL
    Keep the rest of the Command line (/N*N /H*H yourbatch *N *H *I).
 3. In door menus and batches change NFU -> D:\RGFOSSIL\RGFL.
    Parameters stay the same.
 4. If you used NETCOM.INI, copy its [Settings] into RGCOM.INI.
 5. NETFOSS.DLL can stay in System32; it doesn't interfere.

 Behaviour kept from NetFoss on purpose, even where it differs from the
 FOSSIL specification:
   * Receive (02h) returns 8000h at once when nothing is waiting, instead
     of waiting. Doors written for NetFoss rely on this.
   * Idle pacing (section 7).
   * Unknown function numbers return 1954h.
   * Port number DX=00FFh ("no port") is ignored except by init.

 Differences:
   * The pipes, events and mailslots use rgfossil_* names, so an RG node and
     a NetFoss node can run side by side - but RG and NetFoss parts cannot
     be mixed on one node (e.g. NETFOSS.COM + RGCOM).
   * NetSpy / Net2Mon (NetFoss sysop tools) do not see RG nodes.
   * No green banner line is sent to the caller.
   * RGFL dropfile differences are listed in section 10.


===============================================================================
 13. TROUBLESHOOTING
===============================================================================

 The node window flashes and closes / the caller is dropped at once
   RGFOSSIL.BAT keeps the window open 15 seconds when RGFOSSIL.COM fails.
   Read the message there, or run the local test in section 11.

 "Can't load RGFOSSIL.DLL (error 1) ..."
   * Copy RGFOSSIL.DLL into C:\Windows\System32 (administrator prompt).
   * Make sure no ntvdm.exe from an old node is still running (Task
     Manager); a running NTVDM keeps the old DLL locked, so the copy fails.
   * Run RGDIAG and RGVDDT (section 14).

 "Node in use" / "Node already in use"
   An earlier session of that node is still running. Close its window, or
   end the leftover ntvdm.exe / RGCOM.EXE in Task Manager.

 RGTEL log says "Spawn FAILED"
   The first path in Command= is wrong - it must be RGFOSSIL.BAT, followed
   by your BBS batch (section 5).

 A door pauses for seconds at "Checking for RIP" / ANSI detection
   Make sure RGFOSSIL.COM and the System32 RGFOSSIL.DLL are current - the
   old builds slept on every poll. /F makes the driver answer RIP queries
   itself if a door still waits.

 The node window does not close after logoff
   Press Ctrl+C in it. "Terminate batch job?" means the batch was still
   running something; otherwise RGCOM or /U is waiting. Report which.

 Callers get node 2 while node 1 looks free
   RGTEL chooses node numbers. An fTelnet caller holding RGTEL node 1 makes
   the next caller node 2. Use HighNodeIPs= in RGTEL.INI (section 5).

 A Win32 door says "RGFL Error: Can't find RGCOM"
   NFNODE is not set, or is set to a different node than the one RGCOM is
   running. Echo it in your batch:  ECHO NFNODE=%NFNODE%

 A non-FOSSIL DOS door shows output only locally
   If it writes to the screen through DOS: load RGFOSSIL with /I1 (DOS I/O).
   If it wants a COM port (UART / direct / hardware comms): run it with
   RGFL /V (section 9a).

 A /V door hangs at start, or says "no carrier" / "no modem"
   * Check the door is set to the same COM port (and IRQ) as /V.
   * Make sure the System32 RGFOSSIL.DLL is version 1.04 or later.
   * Set the door's comm type to direct/UART, not FOSSIL or Digiboard.


===============================================================================
 14. DIAGNOSTIC TOOLS
===============================================================================

 RGDIAG.EXE  [path\file.dll]          (RGDIAG64.EXE on 64-bit Windows)
   Loads RGFOSSIL.DLL the normal Windows way and shows the real error if it
   fails (126 = a needed DLL is missing, 193 = damaged file, 1114 = DLL
   start-up failed, 5 = access denied). With no parameter it tries the copy
   next to RGDIAG.EXE, then the plain name. It also reads the DLL's header
   and says whether it is a 32-bit or a 64-bit build - error 193 most often
   means the wrong one (RGFOSSIL.DLL where NTVDMx64 needs RGFOSSIL64.DLL).
     RGDIAG
     RGDIAG C:\Windows\System32\RGFOSSIL.DLL

 RGVDDT.COM  <dll> [dispatch-name] [init-name]   (RGVDDT64.COM for NTVDMx64)
   Asks NTVDM itself to load a driver DLL, the same way RGFOSSIL.COM does,
   prints the raw result (AX and carry flag) and, for RGFOSSIL.DLL, whether
   the DLL answers. Then it unloads it again.
     RGVDDT RGFOSSIL.DLL
     RGVDDT C:\WINDOWS\SYSTEM32\RGFOSSIL.DLL
     RGVDDT NETFOSS.DLL NetFoss VDDInit
     RGVDDT RGNULL.DLL
   NTVDM's console output can appear out of order; run one test per line.

 RGNULL.DLL  (RGNULL64.DLL for NTVDMx64)
   An empty driver DLL. If RGVDDT can load RGNULL.DLL but not RGFOSSIL.DLL,
   the problem is inside RGFOSSIL.DLL; if it can load neither, NTVDM is
   refusing Free Pascal DLLs on that machine.


===============================================================================
 15. TECHNICAL REFERENCE
===============================================================================

 FOSSIL functions (INT 14h, AH = function)
   00h  set baud rate (ignored if locked; returns status)
   01h  send character, wait
   02h  receive character: AL = char, or AX = 8000h if none waiting
   03h  status: AH bit0 data waiting, bit5/6 output empty;
                AL bit7 carrier detect
   04h  initialise: returns AX = 1954h, BX = 051Bh
   05h  de-initialise
   06h  DTR: AL = 0 drops DTR (hangs up the caller)
   07h  timer info: AL = 08h, AH = 18 ticks/s, DX = 55 ms
   08h  flush output        09h  purge output      0Ah  purge input
   0Bh  send character, no wait (AX = 1)
   0Ch  peek: AL = next char, or AX = FFFFh
   0Dh  keyboard peek       0Eh  keyboard read
   0Fh  flow control (accepted)
   10h  ^C/^K checking: AX = 1 if ^C/^K arrived since last call
   11h  set cursor          12h  get cursor
   13h  write char (DOS)    14h  watchdog (ignored)
   15h  write char (BIOS)   16h  timer chain (not supported, FFFFh)
   17h  reboot (ignored)
   18h  read block: ES:DI buffer, CX max -> AX bytes read
   19h  write block: ES:DI buffer, CX count -> AX bytes written
   1Ah  break on/off
   1Bh  driver info: 19-byte structure to ES:DI
   1Ch-1Fh  X00 extensions (same as 04h, 05h, 00h, 03h)
   20h  read character, no wait (NetFoss)
   21h  put character into the input buffer (NetFoss)
   23h  sleep AL ms (NetFoss)
   other  AX = 1954h
 The INT 14h entry carries the standard FOSSIL signature 1954h at offset 6
 and the highest function (1Bh) at offset 8.

 Other interrupts
   INT 2Fh AX=1680h   Windows/DPMI idle -> releases the time slice (always)
   INT 15h, INT 21h 2B01h, INT 10h FEh   DESQview API (with /D)
   INT 29h, INT 16h   DOS I/O (with /I1)

 Kernel objects (per node n)
   \\.\pipe\rgfossil\wn           DLL -> RGCOM
   \\.\pipe\rgfossil\rn           RGCOM -> DLL
   rgfossil_nocarrier_n           caller gone (RGCOM -> DLL)
   rgfossil_dtr_n                 hang up (DLL -> RGCOM)
   rgfossil_node_n, rgcom_node_n  node in use
   \\.\mailslot\rgfossil\door32_n RGFL -> RGCOM door launch
   RGFL_D32exitn / RGFL_D32failn  door finished / failed to start
   rgfossil_uart_n                virtual UART control block (RGFL /V -> DLL)

 Virtual UART: RGFOSSIL.DLL hooks the I/O ports of COM1-4 at F0h (those
 NTVDM lets it have) and raises the door's IRQ through NTVDM's virtual PIC.

