User:ENusbaum/sandbox

The MajorBBS Emulation Project (MBBSEmu) is an open source, cross-platform Emulator for modules original compiled for The Major BBS and Worldgroup by Galacticomm. MBBSEmu provides both an internal x86 Emulator and a compatibility layer which translates MajorBBS systems calls into internally emulated routines.

Development
MBBSEmu started initial development in November 2019 as an expansion of the functionality provided by MBBSDASM, a general purpose NE .DLL disassembler with custom support for Major BBS and Worldgroup specific system calls. During initial development of the expanded disassembler, it became apparent that if a system could be put in place similar to DOSBox where an emulated CPU is provided as well as a process for translating and emulating system calls, then a fully featured emulator could be created that could execute Major BBS modules without the need of the host software.

On December 7th, 2019 first public announcement of the project as well as the first publicly released prototype was posted to Reddit.

The initial public Alpha release was announced and published on January 2nd, 2020 to Reddit. Development continued throughout 2020 with the support of a Patreon project, which was setup to allow the community to financially support continued development of The MajorBBS Emulation Project. Throughout development, several former Galacticomm ISV's made contributions of resources and source code to the project in order to assist with development of MBBSEmu.

On August 11th, 2020 it was announced on Reddit that MBBSEmu was now released as an Open Source project on GitHub under the terms of the MIT License. With the transition to a community managed Open Source project, the Patreon was closed with the Patreon news updates being saved to the MBBSEmu Wiki.

Features
MBBSEmu is a command-line program, configured either by a set of command line arguments or by editing a JSON configuration file.

The MajorBBS Emulation Project aims to be fully compatible with all Major BBS and Worldgroup Modules which are compatible with The Major BBS 6.25 (and earlier) or Worldgroup 2.0 (and earlier). MBBSEmu tries to replicate the experience of using The Major BBS as accurately as possible.

MBBSEmu offers users several methods of running Modules, some of which are exclusive to MBBSEmu:
 * Telnet - Multiple Users are able to connect and play together on a configured port via Telnet
 * rlogin - Users from other Bulletin Board Systems are able to login to MBBSEmu or directly enter a module via Rlogin
 * Console - Local, single player functionality emulating all ANSI and Telnet graphics directly from the command line

Hardware Emulation
MBBSEmu is a full x86 system emulator that provides BIOS interrupts and also contains an emulated DOS API. When a Module compiled for The Major BBS or Worldgroup is opened, several things happen to prepare the Module for execution within an Emulated environment:
 * 1) The Module DLL header is parsed and loaded
 * 2) A full, dedicated, addressable 16-bit Memory Space is allocated for the Module
 * 3) CODE & DATA Segments are loaded from the DLL file into Memory
 * 4) Relocation Records are read from the DLL relocation table and patched into the CODE & DATA Segments
 * 5) References in the Imported Name Table are redirected to reference the internal Compatibility Layer
 * 6) Initial Entry Point is identified

Code is executed by identifying a DLL entry point and executing the disassembled x86 Assembly starting at the specified address through the emulated x86 Processor. The Module code is executed exactly as it was compiled, with no modification to the logic or execution path at runtime within MBBSEmu.

MajorBBS / Worldgroup Emulation
Modules are compiled and linked using the Galacticomm SDK as DLLs. Inside these DLLs are references in the Imported Name Table for functions available at runtime through the hosted environment. References to these functions are saved in the Relocation Records and are patched at runtime by MBBSEmu.

The x86 Assembler CALL FAR Opcodes that reference these Imported Functions are remapped to custom memory addresses which inform the emulator that it is accessing an emulated call. When executed, these functions turn control over to the Emulator for execution of the emulated Imported Function before passing control back to the emulated x86 Processor for continued execution.

While the Galacticomm SDK lists over 1,300 Functions available for Import, only a minority of these Functions are used by Modules.

Btrieve Emulation
MBBSEmu supports full emulation of the Novell Btrieve API exposed by the Galacticomm SDK as well as the Btrieve .DAT files used by The Major BBS and Worldgroup.

Emulation for Btrieve was implemented by first Reverse Engineering the Btrieve File Format which allowed the data contained within Btrieve .DAT files to be read without the requirement of the Btrieve Driver to be loaded. With access to the data, MBBSEmu then converts all data contained within the Btrieve files into a new SQLite Format, utilizing the database capabilities of SQLite to emulate Btrieve's capabilities. .

Cross Platform
Cross Platform functionality is provided through .NET Core, which allows MBBSEmu to execute on x86-32, x86-64, and ARM based platforms.

Modules written for The Major BBS and Worldgroup were only ever intended to be run within a DOS environment. This means strings that contain File Paths and Names are all assuming the host software is running on a DOS compatible system. Because of this, MBBSEmu has a built in compatibility layer to handle File operations across multiple platforms which requires no modifications to the original Modules.

Modernized Scheduler
The Major BBS and Worldgroup were initially able to support up to 255 lines simultaneously. The method in which Galacticomm accomplished this was to use an event loop which continually ran, polling ports for information as fast as the host CPU was able to. While a novel, albeit highly inefficient, solution at the time, this results now in a single core of a host CPU being spiked at 100% utilization as the event polling is essentially an Infinite loop. This design persists in the latest version of Worldgroup 3.3.

MBBSEmu has overcome this issue by not only implementing a multi-threaded socket model but also an event based scheduler. The event based scheduler runs at set intervals or whenever a Module, or User Action would trigger an event within the system. This results in MBBSEmu being able to host modules with very little CPU utilization on modern hardware.