Exploring Lei Jun’s Elegant 1994 Assembly TSR: RAMinit Source Code
This article presents the complete 1994 assembly source of Lei Jun’s RAMinit TSR program, explains its historical context, describes its hot‑key removal logic, interrupt hooking, environment backup and restoration, and details the low‑level XMS/EMS memory management routines.
Background
In 2011 a WeChat post shared a complete assembly program written by Lei Jun in 1994, titled RAMinit . The code was praised for its high quality, with comments noting that few modern programmers could produce such elegant low‑level code. The author of the article re‑posted the full source, providing context and a brief narrative about the program’s origin.
Source Code Overview
The listing begins with revision metadata, copyright information, and a description of the program’s purpose: pressing a hotkey removes all TSR (Terminate‑and‑Stay‑Resident) programs after the current one. The code is organized into sections for constants, data definitions, macro utilities, the main entry point, interrupt handlers, and various helper routines.
; RI.ASM Revision 2.12 [ July 12, 1994 ]
Revision equ 'V2.12 '
; RAMinit Release 2.0
; Copyright (c) 1989-1994 by Yellow Rose Software Co.
; Written by Mr. Leijun
;
; Function:
; Press HotKey to remove all TSR program after this program
;
; ..........................................................................
; Removed Softwares by RI:
; SPDOS v6.0F, WPS v3.0F, Game Busters III, IV, NETX (Novell 3.11)
; PC-CACHE, Norton Cache, Microsoft SmartDrv, SideKick 1.56A
; MOUSE Driver, Crazy (Monochrome simulate CGA program)
; RAMBIOS v2.0, 386MAX Version 6.01
; ..........................................................................
; No cancel softwares:
; Windows 3.1 MSD
; ; No removed TSR softwares:
; MS-DOS fastopen, Buffers, Files ... (QEMM 6.0)
; QCache (386MAX 6.01)
; COMMENT
; V2.04 Use mouse driver software reset function to initiation mouse
; 2/17/1993 by Mr. Lei and Mr. Feng
; ...Key Routines
The program defines several core procedures:
HotKey Status Test : Detects which modifier keys (Ctrl, Alt, Shift) are pressed and combines them into a hotkey mask.
Interrupt Handlers ( newINT9, newINT2F, newINT1C): Replace the original DOS interrupt vectors, check the hotkey state, and either forward the interrupt to the original handler or invoke removal logic.
RemoveTSR : Switches to a dedicated stack, disables interrupts, and calls a series of restoration functions to clean up the environment before terminating.
Backup/Restore Routines : Save and later restore BIOS data, memory control blocks (MCBs), device driver chains, CVT (Conventional Memory) structures, and XMS/EMS status.
Hotkey Handling
The hotkey is configurable via command‑line options. The mask is built from bits representing left/right Ctrl, Alt, and Shift. An auxiliary hotkey (default “X”) can be added. When the hotkey combination is detected, the program either removes other TSRs ( /CLS option) or removes itself and all TSRs ( /RET option).
Interrupt Vector Management
During initialization the program installs new interrupt vectors using DOS INT 21h services (functions 35h/25h). It stores the original segment:offset pairs for INT 9, INT 2F, and INT 1C, allowing it to forward calls or restore the original vectors when the TSR is unloaded.
Memory Management (XMS/EMS)
The code detects the presence of XMS and EMS services. For XMS it uses INT 2Fh functions 4300h/4310h to obtain the XMS control entry point, then provides wrappers ( XMS_alloc, XMS_lock, XMS_free, etc.). For EMS it attempts to open EMMXXXX0 via DOS file services to determine whether the EMS driver is available, and records the status for later cleanup.
Utility Functions
Various helper routines implement low‑level operations such as:
Reading the real‑time clock ( GetRealTime).
Controlling the PC speaker ( Beep).
Manipulating the 8259 interrupt controller ( Init8259, Enable8259).
Printing colored strings on the screen ( ColorPrintStr, ColorDisplayStr).
Conclusion
The RAMinit TSR showcases sophisticated DOS‑level programming techniques from the early 1990s, including hotkey detection, interrupt vector replacement, environment backup, and interaction with extended memory managers. Its source provides a valuable historical example for developers interested in low‑level assembly, legacy DOS internals, and the evolution of system utilities.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
ITPUB
Official ITPUB account sharing technical insights, community news, and exciting events.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
